Merge branch 'lua_versions' into main/rendor-staging
[ryzomcore.git] / ryzom / tools / pd_parser / main.cpp
blobbbd9cc8bc0a680e59e63de5602cb4380db2667f6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "parser.h"
19 #include "templatizer.h"
21 using namespace std;
22 using namespace NLMISC;
24 extern CTemplatizer Templatizer;
26 int main(int argc, char **argv)
28 new CApplicationContext;
30 string inputfile;
32 uint arg;
33 for (arg=1; (sint)arg<argc; ++arg)
35 if (strcmp(argv[arg], "-hauto") == 0)
37 GenerateHAuto = true;
39 else if (strcmp(argv[arg], "-dbgmsg") == 0)
41 VerboseMode = true;
42 GenerateDebugMessages = true;
44 else if (strcmp(argv[arg], "-onlylogs") == 0)
46 GenerateOnlyLogs = true;
48 else
50 inputfile = argv[arg];
54 if (inputfile.empty())
56 nlwarning("Error: missing input file(s)");
57 exit(EXIT_FAILURE);
61 if (argc == 3)
63 string templateFile = argv[2];
65 NLMISC::CIFile f;
66 if (!f.open(templateFile))
68 nlwarning("Error: failed to open template input file '%s'", templateFile.c_str());
69 exit(EXIT_FAILURE);
71 else
73 uint size = f.getFileSize();
74 char *buffer = new char[size+1];
75 f.serialBuffer((uint8*)buffer, size);
76 buffer[size] = '\0';
77 f.close();
79 if (!Templatizer.build(buffer))
81 nlwarning("Error: failed to parse template input file '%s'", templateFile.c_str());
82 //exit(EXIT_FAILURE);
86 else
88 Templatizer.build("root{}");
92 Templatizer.build("root{}");
94 CParseNode *main = parse(inputfile);
96 GenerateCpp = true;
97 //VerboseMode = true;
99 if (main)
101 main->execute();
102 //Templatizer.eval();
105 printf("Code generation done");
107 return 0;
110 if (argc != 2)
112 nlwarning("Error: missing input file(s)");
113 exit(EXIT_FAILURE);
116 if (!Templatizer.build("root{}"))
118 exit(EXIT_FAILURE);
122 CParseNode *main = parse(argv[1]);
124 GenerateCpp = true;
125 VerboseMode = true;
127 if (main)
129 main->execute();
132 return 0;