mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-24 04:41:25 +00:00
Handling output file, writing output file
This commit is contained in:
parent
79753d05bd
commit
75812d486a
2 changed files with 78 additions and 5 deletions
76
main.c
76
main.c
|
@ -22,14 +22,82 @@
|
|||
*/
|
||||
#include "gmqcc.h"
|
||||
|
||||
bool parser_compile(const char *filename);
|
||||
static const char *output = "progs.dat";
|
||||
static const char *input = NULL;
|
||||
|
||||
#define OptReq(opt, body) \
|
||||
case opt: \
|
||||
if (argv[0][2]) argarg = argv[0]+2; \
|
||||
else { \
|
||||
if (argc < 2) { \
|
||||
printf("option -%c requires an argument\n", opt); \
|
||||
exit(1); \
|
||||
} \
|
||||
argarg = argv[1]; \
|
||||
--argc; \
|
||||
++argv; \
|
||||
} \
|
||||
do { body } while (0); \
|
||||
break;
|
||||
|
||||
#define LongReq(opt, body) \
|
||||
if (!strcmp(argv[0], opt)) { \
|
||||
if (argc < 2) { \
|
||||
printf("option " opt " requires an argument\n"); \
|
||||
exit(1); \
|
||||
} \
|
||||
argarg = argv[1]; \
|
||||
--argc; \
|
||||
++argv; \
|
||||
do { body } while (0); \
|
||||
break; \
|
||||
} else if (!strncmp(argv[0], opt "=", sizeof(opt "="))) \
|
||||
{ \
|
||||
argarg = argv[0] + sizeof(opt "="); \
|
||||
do { body } while (0); \
|
||||
break; \
|
||||
}
|
||||
|
||||
bool parser_compile(const char *filename, const char *datfile);
|
||||
int main(int argc, char **argv) {
|
||||
const char *argarg;
|
||||
char opt;
|
||||
|
||||
util_debug("COM", "starting ...\n");
|
||||
|
||||
if (argc == 2) {
|
||||
if (!parser_compile(argv[1])) {
|
||||
printf("There were compile errors\n");
|
||||
--argc;
|
||||
++argv;
|
||||
while (argc > 0) {
|
||||
if (argv[0][0] == '-') {
|
||||
opt = argv[0][1];
|
||||
switch (opt)
|
||||
{
|
||||
OptReq('o', output = argarg; );
|
||||
case '-':
|
||||
LongReq("--output", output = argarg; );
|
||||
default:
|
||||
printf("Unrecognized option: %s\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input) {
|
||||
printf("Onlyh 1 input file allowed\n");
|
||||
exit(1);
|
||||
}
|
||||
input = argv[0];
|
||||
}
|
||||
--argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
if (!input) {
|
||||
printf("must specify an input file\n");
|
||||
}
|
||||
|
||||
if (!parser_compile(input, output)) {
|
||||
printf("There were compile errors\n");
|
||||
}
|
||||
|
||||
util_debug("COM", "cleaning ...\n");
|
||||
|
|
7
parser.c
7
parser.c
|
@ -1056,7 +1056,7 @@ static bool parser_do(parser_t *parser)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool parser_compile(const char *filename)
|
||||
bool parser_compile(const char *filename, const char *datfile)
|
||||
{
|
||||
size_t i;
|
||||
parser_t *parser;
|
||||
|
@ -1135,6 +1135,11 @@ bool parser_compile(const char *filename)
|
|||
|
||||
ir_builder_dump(ir, printf);
|
||||
|
||||
if (!ir_builder_generate(ir, datfile))
|
||||
printf("*** failed to generate output file\n");
|
||||
|
||||
ir_builder_delete(ir);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < parser->globals_count; ++i) {
|
||||
ast_value_delete(parser->globals[i]);
|
||||
|
|
Loading…
Reference in a new issue