makeset.c 933 B

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