From 3f4d8f485737d2649eb48d6d75c89cb3a623ed6e Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sun, 22 Jun 2014 00:11:13 +0100 Subject: [PATCH] Add missing config.nim. --- src/babelpkg/config.nim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/babelpkg/config.nim diff --git a/src/babelpkg/config.nim b/src/babelpkg/config.nim new file mode 100644 index 0000000..3e42476 --- /dev/null +++ b/src/babelpkg/config.nim @@ -0,0 +1,38 @@ +# Copyright (C) Dominik Picheta. All rights reserved. +# BSD License. Look at license.txt for more info. +import parsecfg, streams, strutils, os + +import tools + +type + TConfig* = object + babelDir*: string + +proc initConfig(): TConfig = + result.babelDir = getHomeDir() / ".babel" + +proc parseConfig*(): TConfig = + result = initConfig() + let confFile = getConfigDir() / "babel" / "babel.ini" + + var f = newFileStream(confFile, fmRead) + if f != nil: + echo("Reading from config file at ", confFile) + var p: TCfgParser + open(p, f, confFile) + while true: + var e = next(p) + case e.kind + of cfgEof: + break + of cfgSectionStart: discard + of cfgKeyValuePair, cfgOption: + case e.key.normalize + of "babeldir": + result.babelDir = e.value + else: + raise newException(EBabel, "Unable to parse config file:" & + " Unknown key: " & e.key) + of cfgError: + raise newException(EBabel, "Unable to parse config file: " & e.msg) + close(p)