makeset.c 899 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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] == ':') {
  20. type = &line[1];
  21. if (type == "end")
  22. break;
  23. transform(type.begin(), type.end(), type.begin(), (int(*)(int)) toupper);
  24. type = "DEFAULT_" + type;
  25. out << "#define " << type << " \"\\" << endl;
  26. } else {
  27. if (!type.length())
  28. continue;
  29. out << line;
  30. c = file.peek();
  31. if (strchr("\n:", c)) {
  32. out << "\"\n" << endl;
  33. type = "";
  34. } else
  35. out << ",\\" << endl;
  36. }
  37. }
  38. file.close();
  39. out.close();
  40. }