Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.60 KB | None | 0 0
  1. import osproc
  2. import strutils
  3. import sequtils
  4. import os
  5.  
  6. var core = """
  7. import os
  8.  
  9. import nimterop/[build, cimport]
  10.  
  11. static:
  12.  cDebug()
  13.  cSkipSymbol @["filler"] # Skips
  14.  
  15. getHeader("openssl/crypto.h")
  16. const basePath = cryptoPath.parentDir
  17.  
  18. cPlugin:
  19.  import strutils
  20.  
  21.  proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
  22.    sym.name = sym.name.strip(chars = {'_'}).replace("__", "_")
  23.  
  24.    # Replacements here
  25.  
  26. type
  27.  tmp = object
  28.  # Objects here
  29.  
  30. # Starts"""
  31.  
  32. for i in walkFiles("/usr/include/openssl/*.h"):
  33.   if "_mac" notin i:
  34.     core = core & "\ncImport(basePath/\"" & i.split("/")[^1] & "\", dynlib=\"cryptoLPath\")"
  35.  
  36. var fp = commandLineParams()[0]
  37. writeFile(fp, core)
  38.  
  39. while true:
  40.   var r = execProcess("nim c -d:cryptoStd -r " & fp)
  41.  
  42.   if "Error: undeclared identifier: " in r.split("\n")[^2]:
  43.  
  44.     var text = readFile(fp)
  45.     var problem = r.split("\n")[^2].split("'")[^2]
  46.  
  47.     echo problem
  48.     if problem & " = object" notin text:
  49.  
  50.       var tmp = @(text.split("\n"))
  51.       tmp.insert(@["  " & problem & " = object"], tmp.find("  # Objects here"))
  52.  
  53.       writeFile(fp, tmp.join("\n").replace("] # Skips", ",\"" & problem & "\"] # Skips"))
  54.  
  55.   elif " is a stylistic duplicate of identifier " in r.split("\n")[^2]:
  56.     var t1 = r.split("\n")[^2].split("'")[1]
  57.     var t2 = r.split("\n")[^2].split("'")[3]
  58.  
  59.     var text = readFile(fp)
  60.     var tmp = @(text.split("\n"))
  61.     tmp.insert(@["    if sym.name == \"" & t1 & "\":", "      sym.name = \"" & t2 & "\""], tmp.find("    # Replacements here"))
  62.     writeFile(fp, tmp.join("\n"))
  63.  
  64.   else:
  65.     echo r
  66.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement