summary refs log tree commit diff stats
path: root/tools/niminst
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-06-13 12:06:04 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-06-13 12:18:44 +0200
commit7e8c9eda45b887b13f4354fcb25fe39708478cc3 (patch)
tree410c2d3a0136237958c261e5e6ff1b3508a232c5 /tools/niminst
parent112cde69c84012f28bed0eedc83c1e521baf285f (diff)
downloadNim-7e8c9eda45b887b13f4354fcb25fe39708478cc3.tar.gz
more niminst fixes
Diffstat (limited to 'tools/niminst')
-rw-r--r--tools/niminst/niminst.nim40
1 files changed, 30 insertions, 10 deletions
diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim
index b2983b23b..eb2cb64a3 100644
--- a/tools/niminst/niminst.nim
+++ b/tools/niminst/niminst.nim
@@ -202,14 +202,34 @@ proc parseCmdLine(c: var ConfigData) =
   if c.infile.len == 0: quit(Usage)
   if c.mainfile.len == 0: c.mainfile = changeFileExt(c.infile, "nim")
 
-proc ignoreFile(f, root: string, allowHtml: bool): bool =
+proc eqT(a, b: string; t: proc (a: char): char{.nimcall.}): bool =
+  ## equality under a transformation ``t``. candidate for the stdlib?
+  var i = 0
+  var j = 0
+  while i < a.len and j < b.len:
+    let aa = t a[i]
+    let bb = t b[j]
+    if aa == '\0':
+      inc i
+      if bb == '\0': inc j
+    elif bb == '\0': inc j
+    else:
+      if aa != bb: return false
+      inc i
+      inc j
+  result = i >= a.len and j >= b.len
+
+proc tPath(c: char): char =
+  if c == '\\': '/'
+  else: c
+
+proc ignoreFile(f, explicit: string, allowHtml: bool): bool =
   let (_, name, ext) = splitFile(f)
   let html = if not allowHtml: ".html" else: ""
-  let explicit = splitPath(root).tail
-  result = (ext in ["", ".exe", ".idx"] or
-            ext == html or name[0] == '.') and name & ext != explicit
+  result = (ext in ["", ".exe", ".idx", ".o", ".obj", ".dylib"] or
+            ext == html or name[0] == '.') and not eqT(f, explicit, tPath)
 
-proc walkDirRecursively(s: var seq[string], root: string,
+proc walkDirRecursively(s: var seq[string], root, explicit: string,
                         allowHtml: bool) =
   let tail = splitPath(root).tail
   if tail == "nimcache" or tail[0] == '.':
@@ -221,22 +241,22 @@ proc walkDirRecursively(s: var seq[string], root: string,
     else:
       case k
       of pcFile, pcLinkToFile:
-        if not ignoreFile(f, root, allowHtml):
+        if not ignoreFile(f, explicit, allowHtml):
           add(s, unixToNativePath(f))
       of pcDir:
-        walkDirRecursively(s, f, allowHtml)
+        walkDirRecursively(s, f, explicit, allowHtml)
       of pcLinkToDir: discard
 
 proc addFiles(s: var seq[string], patterns: seq[string]) =
   for p in items(patterns):
     if existsDir(p):
-      walkDirRecursively(s, p, false)
+      walkDirRecursively(s, p, p, false)
     else:
       var i = 0
       for f in walkFiles(p):
         if existsDir(f):
-          walkDirRecursively(s, f, false)
-        elif not ignoreFile(f, p, false):
+          walkDirRecursively(s, f, p, false)
+        elif not ignoreFile(f, f, false):
           add(s, unixToNativePath(f))
           inc(i)
       if i == 0: echo("[Warning] No file found that matches: " & p)