Style fixes
This commit is contained in:
parent
5e784f09ef
commit
7fbc8fbcde
3 changed files with 561 additions and 546 deletions
|
|
@ -48,6 +48,8 @@ To see examples of nimgen in action check out the following wrappers:-
|
|||
* download header file
|
||||
* [nimkerberos](https://github.com/genotrance/nimkerberos) - WinKerberos wrapper: [docs](http://nimgen.genotrance.com/nimkerberos)
|
||||
* git sparse checkout
|
||||
* [nimpcre](https://github.com/genotrance/nimpcre) - PCRE wrapper: [docs](http://nimgen.genotrance.com/nimpcre)
|
||||
* git checkout
|
||||
* [nimrax](https://github.com/genotrance/nimrax) - Radix tree wrapper: [docs](http://nimgen.genotrance.com/nimrax)
|
||||
* git checkout
|
||||
* [nimssl](https://github.com/genotrance/nimssl) - OpenSSL wrapper: [docs](http://nimgen.genotrance.com/nimssl)
|
||||
|
|
|
|||
138
nimgen.nim
138
nimgen.nim
|
|
@ -1,26 +1,17 @@
|
|||
import nre
|
||||
import os
|
||||
import ospaths
|
||||
import osproc
|
||||
import parsecfg
|
||||
import pegs
|
||||
import ropes
|
||||
import sequtils
|
||||
import streams
|
||||
import strutils
|
||||
import tables
|
||||
import nre, os, ospaths, osproc, parsecfg, pegs, ropes, sequtils, streams, strutils, tables
|
||||
|
||||
var DONE: seq[string] = @[]
|
||||
var DONE_INLINE: seq[string] = @[]
|
||||
var
|
||||
DONE: seq[string] = @[]
|
||||
DONE_INLINE: seq[string] = @[]
|
||||
|
||||
var CONFIG: Config
|
||||
var FILTER = ""
|
||||
var QUOTES = true
|
||||
var OUTPUT = ""
|
||||
var INCLUDES: seq[string] = @[]
|
||||
var EXCLUDES: seq[string] = @[]
|
||||
var RENAMES = initTable[string, string]()
|
||||
var WILDCARDS = newConfig()
|
||||
CONFIG: Config
|
||||
FILTER = ""
|
||||
QUOTES = true
|
||||
OUTPUT = ""
|
||||
INCLUDES: seq[string] = @[]
|
||||
EXCLUDES: seq[string] = @[]
|
||||
RENAMES = initTable[string, string]()
|
||||
WILDCARDS = newConfig()
|
||||
|
||||
const DOC = """
|
||||
Nimgen is a helper for c2nim to simpilfy and automate the wrapping of C libraries
|
||||
|
|
@ -36,11 +27,13 @@ Options:
|
|||
# Helpers
|
||||
|
||||
proc execProc(cmd: string): string =
|
||||
var p = startProcess(cmd, options = {poStdErrToStdOut, poUsePath, poEvalCommand})
|
||||
|
||||
result = ""
|
||||
var outp = outputStream(p)
|
||||
var line = newStringOfCap(120).TaintedString
|
||||
var
|
||||
p = startProcess(cmd, options = {poStdErrToStdOut, poUsePath, poEvalCommand})
|
||||
|
||||
outp = outputStream(p)
|
||||
line = newStringOfCap(120).TaintedString
|
||||
|
||||
while true:
|
||||
if outp.readLine(line):
|
||||
result.add(line)
|
||||
|
|
@ -66,8 +59,9 @@ proc extractZip(zipfile: string) =
|
|||
discard execProc(cmd % zipfile)
|
||||
|
||||
proc downloadUrl(url: string) =
|
||||
let file = url.extractFilename()
|
||||
let ext = file.splitFile().ext.toLowerAscii()
|
||||
let
|
||||
file = url.extractFilename()
|
||||
ext = file.splitFile().ext.toLowerAscii()
|
||||
|
||||
var cmd = "curl $# -o $#"
|
||||
if defined(Windows):
|
||||
|
|
@ -239,11 +233,15 @@ proc freplace(file: string, pattern: Regex, repl="") =
|
|||
content = content.replace(pattern, repl)
|
||||
|
||||
proc comment(file: string, pattern: string, numlines: string) =
|
||||
let ext = file.splitFile().ext.toLowerAscii()
|
||||
let cmtchar = if ext == ".nim": "#" else: "//"
|
||||
let
|
||||
ext = file.splitFile().ext.toLowerAscii()
|
||||
cmtchar = if ext == ".nim": "#" else: "//"
|
||||
|
||||
withFile(file):
|
||||
var idx = content.find(pattern)
|
||||
var num = 0
|
||||
var
|
||||
idx = content.find(pattern)
|
||||
num = 0
|
||||
|
||||
try:
|
||||
num = numlines.parseInt()
|
||||
except ValueError:
|
||||
|
|
@ -351,10 +349,10 @@ proc getDefines(file: string, inline=false): string =
|
|||
result &= def.captures[0] & "\n"
|
||||
|
||||
proc runPreprocess(file, ppflags, flags: string, inline: bool): string =
|
||||
var pproc = "gcc"
|
||||
if flags.contains("cpp"):
|
||||
pproc = "g++"
|
||||
var cmd = "$# -E $# $#" % [pproc, ppflags, file]
|
||||
var
|
||||
pproc = if flags.contains("cpp"): "g++" else: "gcc"
|
||||
cmd = "$# -E $# $#" % [pproc, ppflags, file]
|
||||
|
||||
for inc in INCLUDES:
|
||||
cmd &= " -I " & inc
|
||||
|
||||
|
|
@ -362,9 +360,11 @@ proc runPreprocess(file, ppflags, flags: string, inline: bool): string =
|
|||
var data = execProc(cmd)
|
||||
|
||||
# Include content only from file
|
||||
var rdata: Rope
|
||||
var start = false
|
||||
var sfile = file.replace("\\", "/")
|
||||
var
|
||||
rdata: Rope
|
||||
start = false
|
||||
sfile = file.replace("\\", "/")
|
||||
|
||||
if inline:
|
||||
sfile = sfile.parentDir()
|
||||
for line in data.splitLines():
|
||||
|
|
@ -389,10 +389,11 @@ proc runPreprocess(file, ppflags, flags: string, inline: bool): string =
|
|||
return $rdata
|
||||
|
||||
proc runCtags(file: string): string =
|
||||
var cmd = "ctags -o - --fields=+S+K --c-kinds=p --file-scope=no " & file
|
||||
var fps = execProc(cmd)
|
||||
var
|
||||
cmd = "ctags -o - --fields=+S+K --c-kinds=p --file-scope=no " & file
|
||||
fps = execProc(cmd)
|
||||
fdata = ""
|
||||
|
||||
var fdata = ""
|
||||
for line in fps.splitLines():
|
||||
var spl = line.split(re"\t")
|
||||
if spl.len() > 4:
|
||||
|
|
@ -449,10 +450,11 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, inline, preprocess, cta
|
|||
if defines and (preprocess or ctags):
|
||||
prepend(cfile, getDefines(file, inline))
|
||||
|
||||
var extflags = ""
|
||||
var passC = ""
|
||||
var outlib = ""
|
||||
var outpragma = ""
|
||||
var
|
||||
extflags = ""
|
||||
passC = ""
|
||||
outlib = ""
|
||||
outpragma = ""
|
||||
|
||||
passC = "import strutils\n"
|
||||
for inc in INCLUDES:
|
||||
|
|
@ -463,13 +465,17 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, inline, preprocess, cta
|
|||
|
||||
let fname = file.splitFile().name.replace(re"[\.\-]", "_")
|
||||
if dynlib.len() != 0:
|
||||
let win = "when defined(Windows):\n"
|
||||
let lin = "when defined(Linux):\n"
|
||||
let osx = "when defined(MacOSX):\n"
|
||||
let
|
||||
win = "when defined(Windows):\n"
|
||||
lin = "when defined(Linux):\n"
|
||||
osx = "when defined(MacOSX):\n"
|
||||
|
||||
var winlib, linlib, osxlib: string = ""
|
||||
for dl in dynlib:
|
||||
let lib = " const dynlib$# = \"$#\"\n" % [fname, dl]
|
||||
let ext = dl.splitFile().ext
|
||||
let
|
||||
lib = " const dynlib$# = \"$#\"\n" % [fname, dl]
|
||||
ext = dl.splitFile().ext
|
||||
|
||||
if ext == ".dll":
|
||||
winlib &= lib
|
||||
elif ext == ".so":
|
||||
|
|
@ -534,8 +540,9 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, inline, preprocess, cta
|
|||
# Processor
|
||||
|
||||
proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||
var cfg = cfgin
|
||||
var sfile = search(file)
|
||||
var
|
||||
cfg = cfgin
|
||||
sfile = search(file)
|
||||
|
||||
for pattern in WILDCARDS.keys():
|
||||
let pat = pattern.replace(".", "\\.").replace("*", ".*").replace("?", ".?")
|
||||
|
|
@ -544,10 +551,12 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
|||
for key in WILDCARDS[pattern].keys():
|
||||
cfg[key & "." & pattern] = WILDCARDS[pattern][key]
|
||||
|
||||
var srch = ""
|
||||
var compile: seq[string] = @[]
|
||||
var dynlib: seq[string] = @[]
|
||||
var pragma: seq[string] = @[]
|
||||
var
|
||||
srch = ""
|
||||
compile: seq[string] = @[]
|
||||
dynlib: seq[string] = @[]
|
||||
pragma: seq[string] = @[]
|
||||
|
||||
for act in cfg.keys():
|
||||
let (action, val) = getKey(act)
|
||||
if val == true:
|
||||
|
|
@ -584,14 +593,15 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
|||
srch = act
|
||||
|
||||
if file.splitFile().ext != ".nim":
|
||||
var recurse = false
|
||||
var inline = false
|
||||
var preprocess = false
|
||||
var ctags = false
|
||||
var defines = false
|
||||
var noprocess = false
|
||||
var flags = "--stdcall"
|
||||
var ppflags = ""
|
||||
var
|
||||
recurse = false
|
||||
inline = false
|
||||
preprocess = false
|
||||
ctags = false
|
||||
defines = false
|
||||
noprocess = false
|
||||
flags = "--stdcall"
|
||||
ppflags = ""
|
||||
|
||||
for act in cfg.keys():
|
||||
if cfg[act] == "true":
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ import distros
|
|||
import ospaths
|
||||
import strutils
|
||||
|
||||
var full = false
|
||||
var comps = @["libsvm", "nim7z", "nimarchive", "nimbass", "nimbigwig", "nimfuzz", "nimrax", "nimssl", "nimssh2"]
|
||||
var
|
||||
full = false
|
||||
comps = @["libsvm", "nim7z", "nimarchive", "nimbass", "nimbigwig", "nimfuzz",
|
||||
"nimpcre", "nimrax", "nimssl", "nimssh2"]
|
||||
|
||||
if detectOs(Windows):
|
||||
comps.add("nimkerberos")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue