Add move capability, handle compile duplicate names
This commit is contained in:
parent
7e21b2799e
commit
1711052eae
6 changed files with 42 additions and 11 deletions
|
|
@ -189,6 +189,8 @@ The following keys apply to library source code (before processing) and generate
|
||||||
|
|
||||||
```replace``` = string value to replace search string in file. Regex captures can be referred to using $1, $2, etc.
|
```replace``` = string value to replace search string in file. Regex captures can be referred to using $1, $2, etc.
|
||||||
|
|
||||||
|
```move``` = search string providing context for location to move the results of a preceding search or regex match
|
||||||
|
|
||||||
```comment``` = number of lines to comment from search location
|
```comment``` = number of lines to comment from search location
|
||||||
|
|
||||||
The following key only applies before processing and allows renaming the generated .nim files as required to enable successful wrapping. This may be for organizational purposes or to prevent usage of non-nim supported strings in module names (E.g. first letter is a number). Destination is relative to output directory if defined.
|
The following key only applies before processing and allows renaming the generated .nim files as required to enable successful wrapping. This may be for organizational purposes or to prevent usage of non-nim supported strings in module names (E.g. first letter is a number). Destination is relative to output directory if defined.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
author = "genotrance"
|
author = "genotrance"
|
||||||
description = "c2nim helper to simplify and automate the wrapping of C libraries"
|
description = "c2nim helper to simplify and automate the wrapping of C libraries"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,26 @@ proc append*(file: string, data: string, search="") =
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
content = content[0..<idy] & data & content[idy..<content.len()]
|
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)
|
|
||||||
|
|
||||||
proc freplace*(file: string, pattern: Regex, repl="") =
|
|
||||||
withFile(file):
|
withFile(file):
|
||||||
content = content.replace(pattern, repl)
|
content = content.replace(pattern, repl)
|
||||||
|
|
||||||
|
proc move*(file: string, pattern: string|Regex, move: string) =
|
||||||
|
var tomove: seq[string] = @[]
|
||||||
|
withFile(file):
|
||||||
|
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) =
|
proc comment*(file: string, pattern: string, numlines: string) =
|
||||||
let
|
let
|
||||||
ext = file.splitFile().ext.toLowerAscii()
|
ext = file.splitFile().ext.toLowerAscii()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,19 @@ proc compile*(cpl, flags: string): string =
|
||||||
var data = ""
|
var data = ""
|
||||||
|
|
||||||
proc fcompile(file: string): string =
|
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) =
|
proc dcompile(dir: string) =
|
||||||
for f in walkFiles(dir):
|
for f in walkFiles(dir):
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ var
|
||||||
gExcludes*: seq[string] = @[]
|
gExcludes*: seq[string] = @[]
|
||||||
gRenames* = initTable[string, string]()
|
gRenames* = initTable[string, string]()
|
||||||
gWildcards* = newConfig()
|
gWildcards* = newConfig()
|
||||||
|
gCompile*: seq[string] = @[]
|
||||||
|
|
||||||
type
|
type
|
||||||
c2nimConfigObj* = object
|
c2nimConfigObj* = object
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
|
||||||
gExcludes.delete(gExcludes.find(file))
|
gExcludes.delete(gExcludes.find(file))
|
||||||
sfile = file
|
sfile = file
|
||||||
gDoneRecursive.add(sfile)
|
gDoneRecursive.add(sfile)
|
||||||
elif action in @["prepend", "append", "replace", "comment",
|
elif action in @["prepend", "append", "replace", "move", "comment",
|
||||||
"rename", "compile", "dynlib", "pragma",
|
"rename", "compile", "dynlib", "pragma", "pipe"] and
|
||||||
"pipe"] and sfile != "":
|
sfile != "":
|
||||||
if action == "prepend":
|
if action == "prepend":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
prepend(sfile, cfg[act], cfg[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])
|
freplace(sfile, cfg[srch], cfg[act])
|
||||||
elif rgx != "":
|
elif rgx != "":
|
||||||
freplace(sfile, toPattern(cfg[rgx]), cfg[act])
|
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":
|
elif action == "comment":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
comment(sfile, cfg[srch], cfg[act])
|
comment(sfile, cfg[srch], cfg[act])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue