makeset.c 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <bdlib/src/Stream.h>
  2. #include <bdlib/src/String.h>
  3. #include <cctype>
  4. #include <algorithm>
  5. #include <cstring>
  6. using namespace std;
  7. int main(int argc, char *argv[]) {
  8. if (argc == 2)
  9. return 1;
  10. bd::Stream file, out;
  11. file.loadFile(argv[1]);
  12. bd::String type, line;
  13. char c;
  14. while (file.tell() < file.length()) {
  15. line = file.getline().chomp();
  16. if (line[0] == '#') continue;
  17. if (line[0] == ':') {
  18. type = line(1);
  19. if (type == "end")
  20. break;
  21. transform(type.begin(), type.end(), type.mdata(), (int(*)(int)) toupper);
  22. type = "DEFAULT_" + type;
  23. out << "#define " << type << " \"\\" << "\n";
  24. } else {
  25. if (!type.length())
  26. continue;
  27. out << line;
  28. c = file.peek()[0];
  29. if (strchr("\n:", c)) {
  30. out << "\"\n\n";
  31. type = "";
  32. } else
  33. out << ",\\\n";
  34. }
  35. }
  36. out.writeFile(argv[2]);
  37. }