log-parser.py 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. import sys
  3. opening = False
  4. print("std::string lines[] = {")
  5. def printer(line):
  6. global opening
  7. if opening:
  8. if "[Pause]" in line:
  9. opening = False
  10. else:
  11. return
  12. out = repr(line)
  13. out.replace(r"\\\\", r"\\")
  14. out = out[1:-1]
  15. # print("[", repr(out), "]")
  16. if out.startswith("^\\r#"):
  17. return
  18. print('"', out, '",', sep="")
  19. if "Trade Wars 2002 Win32 module now" in line:
  20. opening = True
  21. filename = sys.argv[1]
  22. with open(filename) as fp:
  23. for line in fp:
  24. if " SL: " in line:
  25. _, part = line.strip().split(" SL: ")
  26. part = part[1:-1]
  27. # print(repr(part))
  28. printer(part)
  29. if " SP: " in line:
  30. _, part = line.strip().split(" SP: ")
  31. part = part[1:-1]
  32. # print("^", repr(part))
  33. printer("^" + part)
  34. if " CI: " in line:
  35. _, part = line.strip().split(" CI: ")
  36. part = part[1:-1]
  37. # print("!", repr(part))
  38. printer("!" + part)
  39. print("};")