You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. const fs = require("fs");
  2. const argv = require("yargs")
  3. .usage("mergesymbols -i [input_file] -o [output_file] -s [symbols file]")
  4. .alias("i", "input")
  5. .alias("o", "output")
  6. .alias("s", "symbols")
  7. .help("h")
  8. .epilogue(`Copyright (C) 2018 0kims association
  9. This program comes with ABSOLUTELY NO WARRANTY;
  10. This is free software, and you are welcome to redistribute it
  11. under certain conditions; see the COPYING file in the official
  12. repo directory at https://github.com/iden3/circom `)
  13. .demandOption(["i","o","s"])
  14. .argv;
  15. const inFileName = argv.input;
  16. const outFile = argv.output;
  17. const symbolsFile = argv.symbols;
  18. let symbols;
  19. async function loadSymbols() {
  20. symbols = {};
  21. const symsStr = await fs.promises.readFile(symbolsFile,"utf8");
  22. const lines = symsStr.split("\n");
  23. for (let i=0; i<lines.length; i++) {
  24. const arr = lines[i].split(",");
  25. if (arr.length!=3) continue;
  26. symbols[arr[0]] = arr[2];
  27. }
  28. }
  29. async function run() {
  30. const outLines = [];
  31. await loadSymbols();
  32. const inStr = await fs.promises.readFile(inFileName,"utf8");
  33. const lines = inStr.split("\n");
  34. for (let i=0; i<lines.length; i++) {
  35. const arr = lines[i].split(" --> ");
  36. if (arr.length!=2) continue;
  37. outLines.push(symbols[arr[0]] + " --> " + arr[1]);
  38. }
  39. await fs.promises.writeFile(outFile,outLines.join("\n"), "utf8");
  40. }
  41. run().then(() => {
  42. process.exit(0);
  43. });