makeset.c 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cctype>
  5. #include <algorithm>
  6. using namespace std;
  7. int main(int argc, char *argv[]) {
  8. if (argc == 2)
  9. return 1;
  10. fstream file;
  11. ofstream out;
  12. file.open(argv[1]);
  13. out.open(argv[2]);
  14. char line[1024] = "";
  15. string type;
  16. char c;
  17. while (file.getline(line, sizeof(line))) {
  18. if (line[0] == ':') {
  19. type = &line[1];
  20. if (type == "end")
  21. break;
  22. transform(type.begin(), type.end(), type.begin(), (int(*)(int)) toupper);
  23. type = "DEFAULT_" + type;
  24. out << "#define " << type << " \"\\" << endl;
  25. } else {
  26. if (!type.length())
  27. continue;
  28. out << line;
  29. c = file.peek();
  30. if (strchr("\n:", c)) {
  31. out << "\"\n" << endl;
  32. type = "";
  33. } else
  34. out << ",\\" << endl;
  35. }
  36. }
  37. file.close();
  38. out.close();
  39. }