summary refs log tree commit diff stats
path: root/tools/nimweb.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tools/nimweb.nim')
-rw-r--r--tools/nimweb.nim164
1 files changed, 80 insertions, 84 deletions
diff --git a/tools/nimweb.nim b/tools/nimweb.nim
index 8744a250e..a98a27a13 100644
--- a/tools/nimweb.nim
+++ b/tools/nimweb.nim
@@ -1,7 +1,7 @@
 #
 #
 #           Nim Website Generator
-#        (c) Copyright 2012 Andreas Rumpf
+#        (c) Copyright 2014 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -13,14 +13,14 @@ import
 
 type
   TKeyValPair = tuple[key, id, val: string]
-  TConfigData = object of TObject
+  TConfigData = object of RootObj
     tabs, links: seq[TKeyValPair]
     doc, srcdoc, srcdoc2, webdoc, pdf: seq[string]
     authors, projectName, projectTitle, logo, infile, outdir, ticker: string
-    vars: PStringTable
-    nimrodArgs: string
+    vars: StringTableRef
+    nimArgs: string
     gitCommit: string
-    quotations: TTable[string, tuple[quote, author: string]]
+    quotations: Table[string, tuple[quote, author: string]]
     numProcessors: int # Set by parallelBuild:n, only works for values > 0.
   TRssItem = object
     year, month, day, title: string
@@ -35,7 +35,7 @@ proc initConfigData(c: var TConfigData) =
   c.pdf = @[]
   c.infile = ""
   c.outdir = ""
-  c.nimrodArgs = "--hint[Conf]:off "
+  c.nimArgs = "--hint[Conf]:off "
   c.authors = ""
   c.projectTitle = ""
   c.projectName = ""
@@ -58,7 +58,7 @@ const
   version = "0.7"
   usage = "nimweb - Nim Website Generator Version " & version & """
 
-  (c) 2012 Andreas Rumpf
+  (c) 2014 Andreas Rumpf
 Usage:
   nimweb [options] ini-file[.ini] [compile_options]
 Options:
@@ -112,7 +112,7 @@ proc parseCmdLine(c: var TConfigData) =
     case kind
     of cmdArgument:
       c.infile = addFileExt(key, "ini")
-      c.nimrodArgs.add(cmdLineRest(p))
+      c.nimArgs.add(cmdLineRest(p))
       break
     of cmdLongOption, cmdShortOption:
       case normalize(key)
@@ -127,7 +127,7 @@ proc parseCmdLine(c: var TConfigData) =
         try:
           let num = parseInt(val)
           if num != 0: c.numProcessors = num
-        except EInvalidValue:
+        except ValueError:
           quit("invalid numeric value for --parallelBuild")
       of "var":
         var idx = val.find('=')
@@ -155,68 +155,65 @@ proc addFiles(s: var seq[string], dir, ext: string, patterns: seq[string]) =
 
 proc parseIniFile(c: var TConfigData) =
   var
-    p: TCfgParser
+    p: CfgParser
     section: string # current section
   var input = newFileStream(c.infile, fmRead)
-  if input != nil:
-    open(p, input, c.infile)
-    while true:
-      var k = next(p)
-      case k.kind
-      of cfgEof: break
-      of cfgSectionStart:
-        section = normalize(k.section)
-        case section
-        of "project", "links", "tabs", "ticker", "documentation", "var": discard
-        else: echo("[Warning] Skipping unknown section: " & section)
-
-      of cfgKeyValuePair:
-        var v = k.value % c.vars
-        c.vars[k.key] = v
-
-        case section
-        of "project":
-          case normalize(k.key)
-          of "name": c.projectName = v
-          of "title": c.projectTitle = v
-          of "logo": c.logo = v
-          of "authors": c.authors = v
-          else: quit(errorStr(p, "unknown variable: " & k.key))
-        of "var": discard
-        of "links":
-          let valID = v.split(';')
-          add(c.links, (k.key.replace('_', ' '), valID[1], valID[0]))
-        of "tabs": add(c.tabs, (k.key, "", v))
-        of "ticker": c.ticker = v
-        of "documentation":
-          case normalize(k.key)
-          of "doc": addFiles(c.doc, "doc", ".txt", split(v, {';'}))
-          of "pdf": addFiles(c.pdf, "doc", ".txt", split(v, {';'}))
-          of "srcdoc": addFiles(c.srcdoc, "lib", ".nim", split(v, {';'}))
-          of "srcdoc2": addFiles(c.srcdoc2, "lib", ".nim", split(v, {';'}))
-          of "webdoc": addFiles(c.webdoc, "lib", ".nim", split(v, {';'}))
-          of "parallelbuild":
-            try:
-              let num = parseInt(v)
-              if num != 0: c.numProcessors = num
-            except EInvalidValue:
-              quit("invalid numeric value for --parallelBuild in config")
-          else: quit(errorStr(p, "unknown variable: " & k.key))
-        of "quotations":
-          let vSplit = v.split('-')
-          doAssert vSplit.len == 2
-          c.quotations[k.key.normalize] = (vSplit[0], vSplit[1])
-        else: discard
-
-      of cfgOption: quit(errorStr(p, "syntax error"))
-      of cfgError: quit(errorStr(p, k.msg))
-    close(p)
-    if c.projectName.len == 0:
-      c.projectName = changeFileExt(extractFilename(c.infile), "")
-    if c.outdir.len == 0:
-      c.outdir = splitFile(c.infile).dir
-  else:
-    quit("cannot open: " & c.infile)
+  if input == nil: quit("cannot open: " & c.infile)
+  open(p, input, c.infile)
+  while true:
+    var k = next(p)
+    case k.kind
+    of cfgEof: break
+    of cfgSectionStart:
+      section = normalize(k.section)
+      case section
+      of "project", "links", "tabs", "ticker", "documentation", "var": discard
+      else: echo("[Warning] Skipping unknown section: " & section)
+
+    of cfgKeyValuePair:
+      var v = k.value % c.vars
+      c.vars[k.key] = v
+
+      case section
+      of "project":
+        case normalize(k.key)
+        of "name": c.projectName = v
+        of "title": c.projectTitle = v
+        of "logo": c.logo = v
+        of "authors": c.authors = v
+        else: quit(errorStr(p, "unknown variable: " & k.key))
+      of "var": discard
+      of "links":
+        let valID = v.split(';')
+        add(c.links, (k.key.replace('_', ' '), valID[1], valID[0]))
+      of "tabs": add(c.tabs, (k.key, "", v))
+      of "ticker": c.ticker = v
+      of "documentation":
+        case normalize(k.key)
+        of "doc": addFiles(c.doc, "doc", ".txt", split(v, {';'}))
+        of "pdf": addFiles(c.pdf, "doc", ".txt", split(v, {';'}))
+        of "srcdoc": addFiles(c.srcdoc, "lib", ".nim", split(v, {';'}))
+        of "srcdoc2": addFiles(c.srcdoc2, "lib", ".nim", split(v, {';'}))
+        of "webdoc": addFiles(c.webdoc, "lib", ".nim", split(v, {';'}))
+        of "parallelbuild":
+          try:
+            let num = parseInt(v)
+            if num != 0: c.numProcessors = num
+          except ValueError:
+            quit("invalid numeric value for --parallelBuild in config")
+        else: quit(errorStr(p, "unknown variable: " & k.key))
+      of "quotations":
+        let vSplit = v.split('-')
+        doAssert vSplit.len == 2
+        c.quotations[k.key.normalize] = (vSplit[0], vSplit[1])
+      else: discard
+    of cfgOption: quit(errorStr(p, "syntax error"))
+    of cfgError: quit(errorStr(p, k.msg))
+  close(p)
+  if c.projectName.len == 0:
+    c.projectName = changeFileExt(extractFilename(c.infile), "")
+  if c.outdir.len == 0:
+    c.outdir = splitFile(c.infile).dir
   # Ugly hack to override git command output when building private repo.
   if c.vars.hasKey("githash"):
     let githash = c.vars["githash"].strip
@@ -238,8 +235,7 @@ proc mexec(cmds: openarray[string], processors: int) =
   if processors < 2:
     sexec(cmds)
     return
-
-  if 0 != execProcesses(cmds, {poStdErrToStdOut, poParentStreams, poEchoCmd}):
+  if execProcesses(cmds, {poStdErrToStdOut, poParentStreams, poEchoCmd}) != 0:
     echo "external program failed, retrying serial work queue for logs!"
     sexec(cmds)
 
@@ -251,9 +247,9 @@ proc buildDocSamples(c: var TConfigData, destPath: string) =
   ## documentation builders.
   const src = "doc"/"docgen_sample.nim"
   exec("nim doc $# -o:$# $#" %
-    [c.nimrodArgs, destPath / "docgen_sample.html", src])
+    [c.nimArgs, destPath / "docgen_sample.html", src])
   exec("nim doc2 $# -o:$# $#" %
-    [c.nimrodArgs, destPath / "docgen_sample2.html", src])
+    [c.nimArgs, destPath / "docgen_sample2.html", src])
 
 proc buildDoc(c: var TConfigData, destPath: string) =
   # call nim for the documentation:
@@ -262,17 +258,17 @@ proc buildDoc(c: var TConfigData, destPath: string) =
     i = 0
   for d in items(c.doc):
     commands[i] = "nim rst2html $# --docSeeSrcUrl:$# -o:$# --index:on $#" %
-      [c.nimrodArgs, c.gitCommit,
+      [c.nimArgs, c.gitCommit,
       destPath / changeFileExt(splitFile(d).name, "html"), d]
     i.inc
   for d in items(c.srcdoc):
     commands[i] = "nim doc $# --docSeeSrcUrl:$# -o:$# --index:on $#" %
-      [c.nimrodArgs, c.gitCommit,
+      [c.nimArgs, c.gitCommit,
       destPath / changeFileExt(splitFile(d).name, "html"), d]
     i.inc
   for d in items(c.srcdoc2):
     commands[i] = "nim doc2 $# --docSeeSrcUrl:$# -o:$# --index:on $#" %
-      [c.nimrodArgs, c.gitCommit,
+      [c.nimArgs, c.gitCommit,
       destPath / changeFileExt(splitFile(d).name, "html"), d]
     i.inc
 
@@ -284,7 +280,7 @@ proc buildPdfDoc(c: var TConfigData, destPath: string) =
     echo "pdflatex not found; no PDF documentation generated"
   else:
     for d in items(c.pdf):
-      exec("nim rst2tex $# $#" % [c.nimrodArgs, d])
+      exec("nim rst2tex $# $#" % [c.nimArgs, d])
       # call LaTeX twice to get cross references right:
       exec("pdflatex " & changeFileExt(d, "tex"))
       exec("pdflatex " & changeFileExt(d, "tex"))
@@ -303,7 +299,7 @@ proc buildAddDoc(c: var TConfigData, destPath: string) =
   var commands = newSeq[string](c.webdoc.len)
   for i, doc in pairs(c.webdoc):
     commands[i] = "nim doc $# --docSeeSrcUrl:$# -o:$# $#" %
-      [c.nimrodArgs, c.gitCommit,
+      [c.nimArgs, c.gitCommit,
       destPath / changeFileExt(splitFile(doc).name, "html"), doc]
   mexec(commands, c.numProcessors)
 
@@ -311,7 +307,7 @@ proc parseNewsTitles(inputFilename: string): seq[TRssItem] =
   # parses the file for titles and returns them as TRssItem blocks.
   let reYearMonthDayTitle = re(rYearMonthDayTitle)
   var
-    input: TFile
+    input: File
     line = ""
 
   result = @[]
@@ -347,7 +343,7 @@ proc genNewsLink(title: string): string =
 proc generateRss(outputFilename: string, news: seq[TRssItem]) =
   # Given a list of rss items generates an rss overwriting destination.
   var
-    output: TFile
+    output: File
 
   if not open(output, outputFilename, mode = fmWrite):
     quit("Could not write to $1 for rss generation" % [outputFilename])
@@ -396,19 +392,19 @@ proc main(c: var TConfigData) =
   if c.ticker.len > 0:
     try:
       c.ticker = readFile("web" / c.ticker)
-    except EIO:
+    except IOError:
       quit("[Error] cannot open: " & c.ticker)
   for i in 0..c.tabs.len-1:
     var file = c.tabs[i].val
     let rss = if file in ["news", "index"]: extractFilename(rssUrl) else: ""
-    exec(cmd % [c.nimrodArgs, file])
+    exec(cmd % [c.nimArgs, file])
     var temp = "web" / changeFileExt(file, "temp")
     var content: string
     try:
       content = readFile(temp)
-    except EIO:
+    except IOError:
       quit("[Error] cannot open: " & temp)
-    var f: TFile
+    var f: File
     var outfile = "web/upload/$#.html" % file
     if not existsDir("web/upload"):
       createDir("web/upload")