| 53 | |
| 54 | |
| 55 | static void run(int argc, const char* argv[]) |
| 56 | { |
| 57 | if (argc < 4) |
| 58 | throw runtime_error(paramError()); |
| 59 | |
| 60 | string inFilename(argv[1]); |
| 61 | string outFormat(argv[2]); |
| 62 | string outFilename(argv[3]); |
| 63 | |
| 64 | Lexer lexer(inFilename); |
| 65 | |
| 66 | Parser parser(&lexer); |
| 67 | parser.parse(); |
| 68 | |
| 69 | auto_ptr<Generator> generator; |
| 70 | |
| 71 | if (outFormat == "c++") |
| 72 | { |
| 73 | if (argc < 7) |
| 74 | throw runtime_error(paramError("c++", "headerGuard className prefix")); |
| 75 | |
| 76 | string headerGuard(argv[4]); |
| 77 | string className(argv[5]); |
| 78 | string prefix(argv[6]); |
| 79 | |
| 80 | generator.reset(new CppGenerator(outFilename, prefix, &parser, headerGuard, className)); |
| 81 | } |
| 82 | else if (outFormat == "c-header") |
| 83 | { |
| 84 | if (argc < 6) |
| 85 | throw runtime_error(paramError("c-header", "headerGuard prefix [macro]")); |
| 86 | |
| 87 | string headerGuard(argv[4]); |
| 88 | string prefix(argv[5]); |
| 89 | string macro; |
| 90 | if (argc == 7) |
| 91 | macro = argv[6]; |
| 92 | |
| 93 | generator.reset(new CHeaderGenerator(outFilename, prefix, &parser, headerGuard, macro)); |
| 94 | } |
| 95 | else if (outFormat == "c-impl") |
| 96 | { |
| 97 | if (argc < 6) |
| 98 | throw runtime_error(paramError("c-impl", "includeFilename prefix")); |
| 99 | |
| 100 | string includeFilename(argv[4]); |
| 101 | string prefix(argv[5]); |
| 102 | |
| 103 | generator.reset(new CImplGenerator(outFilename, prefix, &parser, includeFilename)); |
| 104 | } |
| 105 | else if (outFormat == "pascal") |
| 106 | { |
| 107 | if (argc < 5) |
| 108 | throw runtime_error(paramError("pascal", "--uses uses --interfaceFile interfaces-file " |
| 109 | "--implementationFile implementation-file --exceptionClass class-name --prefix prefix --functionsFile functions-file")); |
| 110 | |
| 111 | string unitName(argv[4]); |
| 112 | |