diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-08-19 12:31:21 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-08-19 12:31:21 -0500 |
| commit | 1711052eae985e042ab22108f0975d9bb0906abf (patch) | |
| tree | bdca8d43270799b80078420666e1cacef52497fc /src | |
| parent | 7e21b2799eafaad9662bf2d754e94d25eea25100 (diff) | |
| download | nimgen-1711052eae985e042ab22108f0975d9bb0906abf.tar.gz nimgen-1711052eae985e042ab22108f0975d9bb0906abf.zip | |
Add move capability, handle compile duplicate names
Diffstat (limited to 'src')
| -rw-r--r-- | src/nimgen/fileops.nim | 21 | ||||
| -rw-r--r-- | src/nimgen/gencore.nim | 14 | ||||
| -rw-r--r-- | src/nimgen/globals.nim | 1 | ||||
| -rw-r--r-- | src/nimgen/runcfg.nim | 11 |
4 files changed, 38 insertions, 9 deletions
diff --git a/src/nimgen/fileops.nim b/src/nimgen/fileops.nim index 4e8f858..e416cf1 100644 --- a/src/nimgen/fileops.nim +++ b/src/nimgen/fileops.nim @@ -31,14 +31,25 @@ proc append*(file: string, data: string, search="") = if idx != -1: content = content[0..<idy] & data & content[idy..<content.len()] -proc freplace*(file: string, pattern: string, repl="") = +proc freplace*(file: string, pattern: string|Regex, repl="") = withFile(file): - if pattern in content: - content = content.replace(pattern, repl) + content = content.replace(pattern, repl) -proc freplace*(file: string, pattern: Regex, repl="") = +proc move*(file: string, pattern: string|Regex, move: string) = + var tomove: seq[string] = @[] withFile(file): - content = content.replace(pattern, repl) + when pattern is string: + tomove.add(pattern) + + when pattern is Regex: + var ms = content.findAll(pattern) + for i, m in ms: + tomove.add(content[m.group(0)[0]]) + + content = content.replace(pattern, "") + + for i in tomove: + append(file, i, move) proc comment*(file: string, pattern: string, numlines: string) = let diff --git a/src/nimgen/gencore.nim b/src/nimgen/gencore.nim index 000651e..027510c 100644 --- a/src/nimgen/gencore.nim +++ b/src/nimgen/gencore.nim @@ -21,7 +21,19 @@ proc compile*(cpl, flags: string): string = var data = "" proc fcompile(file: string): string = - return "{.compile: \"$#\".}" % file.replace("\\", "/") + let fn = file.splitFile().name + var + ufn = fn + uniq = 1 + while ufn in gCompile: + ufn = fn & $uniq + uniq += 1 + + gCompile.add(ufn) + if fn == ufn: + return "{.compile: \"$#\".}" % file.replace("\\", "/") + else: + return "{.compile: (\"../$#\", \"$#.o\").}" % [file.replace("\\", "/"), ufn] proc dcompile(dir: string) = for f in walkFiles(dir): diff --git a/src/nimgen/globals.nim b/src/nimgen/globals.nim index c371fe2..a83460f 100644 --- a/src/nimgen/globals.nim +++ b/src/nimgen/globals.nim @@ -21,6 +21,7 @@ var gExcludes*: seq[string] = @[] gRenames* = initTable[string, string]() gWildcards* = newConfig() + gCompile*: seq[string] = @[] type c2nimConfigObj* = object diff --git a/src/nimgen/runcfg.nim b/src/nimgen/runcfg.nim index 91e7078..5f04b04 100644 --- a/src/nimgen/runcfg.nim +++ b/src/nimgen/runcfg.nim @@ -63,9 +63,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str gExcludes.delete(gExcludes.find(file)) sfile = file gDoneRecursive.add(sfile) - elif action in @["prepend", "append", "replace", "comment", - "rename", "compile", "dynlib", "pragma", - "pipe"] and sfile != "": + elif action in @["prepend", "append", "replace", "move", "comment", + "rename", "compile", "dynlib", "pragma", "pipe"] and + sfile != "": if action == "prepend": if srch != "": prepend(sfile, cfg[act], cfg[srch]) @@ -81,6 +81,11 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str freplace(sfile, cfg[srch], cfg[act]) elif rgx != "": freplace(sfile, toPattern(cfg[rgx]), cfg[act]) + elif action == "move": + if srch != "": + move(sfile, cfg[srch], cfg[act]) + elif rgx != "": + move(sfile, toPattern(cfg[rgx]), cfg[act]) elif action == "comment": if srch != "": comment(sfile, cfg[srch], cfg[act]) |
