p≡p engine fork for my own dirty testing of stuff
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.

102 lines
2.5 KiB

  1. #!/usr/bin/env python3
  2. # Note to python wizzes - I am not trying to be clever or efficient here. This
  3. # is a convenience tool for ridiculous engine debugging fun, and I don't write
  4. # python often. I am definitely not a member of the religion. YMMV, etc.
  5. #
  6. # If you break this, you buy it.
  7. #
  8. import sys
  9. import argparse
  10. def parse_enum_line(line, ct, r):
  11. line = line.strip()
  12. if (line.startswith("//") or line == ""):
  13. return
  14. parts = []
  15. if (ct):
  16. temp = line.split(",")
  17. if len(temp) == 0:
  18. return
  19. else:
  20. parts = temp[0].split()
  21. else:
  22. parts = line.split()
  23. if len(parts) < 3 or parts[1] != '=':
  24. return
  25. if r and not parts[0].startswith("PEP_rating"):
  26. return
  27. elif ct and not parts[0].startswith("PEP_ct_"):
  28. return
  29. elif not ct and not r and not parts[0].startswith("PEP_"):
  30. return
  31. key = int(parts[2].strip(','), 0)
  32. value = parts[0]
  33. valueDict[key] = value
  34. def get_error(code):
  35. try:
  36. error = valueDict[code]
  37. except:
  38. print("Hah buddy! You wish!")
  39. exit(-1)
  40. print(str(code) + " -> " + error)
  41. parser = argparse.ArgumentParser()
  42. parser.add_argument("value", type=int)
  43. parser.add_argument("--comm_type", "-ct", help="number represents a comm type", action='store_true')
  44. parser.add_argument("--rating", "-r", help="number represents a rating", action='store_true')
  45. args = parser.parse_args()
  46. error_val = args.value
  47. input_fname = ""
  48. if not args.rating:
  49. input_fname = "src/pEpEngine.h"
  50. else:
  51. input_fname = "src/message_api.h"
  52. print(input_fname)
  53. pEp_error = not (args.rating or args.comm_type)
  54. file = open(input_fname, 'r')
  55. content = file.readlines()
  56. file.close()
  57. inStruct = False
  58. valueDict = dict()
  59. # This is super fragile. C'est la vie.
  60. # If another struct is added first, expect chaos! ;)
  61. #
  62. for line in content:
  63. if args.rating:
  64. if line.startswith("} PEP_rating;"):
  65. break
  66. elif args.comm_type:
  67. if line.startswith("} PEP_comm_type;"):
  68. break
  69. elif line.startswith("} PEP_STATUS;"):
  70. break
  71. if not inStruct:
  72. if (args.rating and not line.startswith("typedef enum _PEP_rating {")) or \
  73. (args.comm_type and not line.startswith("typedef enum _PEP_comm_type {")) or \
  74. (pEp_error and not line.startswith("typedef enum {")):
  75. continue
  76. else:
  77. inStruct = True
  78. continue
  79. parse_enum_line(line, args.comm_type, args.rating)
  80. get_error(error_val)