mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
progs.src mode added
This commit is contained in:
parent
4c5c615f95
commit
37c4644d85
2 changed files with 83 additions and 8 deletions
9
gmqcc.h
9
gmqcc.h
|
@ -906,6 +906,15 @@ void printmsg (int level, const char *name, size_t line, const char *msgtype, c
|
||||||
void cvprintmsg(lex_ctx ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
|
void cvprintmsg(lex_ctx ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
|
||||||
void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...);
|
void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...);
|
||||||
|
|
||||||
|
/*===================================================================*/
|
||||||
|
/*===================== parser.c commandline ========================*/
|
||||||
|
/*===================================================================*/
|
||||||
|
|
||||||
|
bool parser_init ();
|
||||||
|
bool parser_compile(const char *filename);
|
||||||
|
bool parser_finish (const char *output);
|
||||||
|
void parser_cleanup();
|
||||||
|
|
||||||
/*===================================================================*/
|
/*===================================================================*/
|
||||||
/*======================= main.c commandline ========================*/
|
/*======================= main.c commandline ========================*/
|
||||||
/*===================================================================*/
|
/*===================================================================*/
|
||||||
|
|
82
main.c
82
main.c
|
@ -32,6 +32,8 @@ bool opts_debug = false;
|
||||||
bool opts_memchk = false;
|
bool opts_memchk = false;
|
||||||
bool opts_dump = false;
|
bool opts_dump = false;
|
||||||
|
|
||||||
|
static bool opts_output_wasset = false;
|
||||||
|
|
||||||
typedef struct { char *filename; int type; } argitem;
|
typedef struct { char *filename; int type; } argitem;
|
||||||
VECTOR_MAKE(argitem, items);
|
VECTOR_MAKE(argitem, items);
|
||||||
|
|
||||||
|
@ -259,6 +261,7 @@ static bool options_parse(int argc, char **argv) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
opts_output = argarg;
|
opts_output = argarg;
|
||||||
|
opts_output_wasset = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -286,10 +289,10 @@ static bool options_parse(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* All long options with arguments */
|
/* All long options with arguments */
|
||||||
if (options_long_witharg("output", &argc, &argv, &argarg))
|
if (options_long_witharg("output", &argc, &argv, &argarg)) {
|
||||||
opts_output = argarg;
|
opts_output = argarg;
|
||||||
else
|
opts_output_wasset = true;
|
||||||
{
|
} else {
|
||||||
printf("Unknown parameter: %s\n", argv[0]);
|
printf("Unknown parameter: %s\n", argv[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -329,14 +332,39 @@ static void options_set(uint32_t *flags, size_t idx, bool on)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parser_init();
|
/* returns the line number, or -1 on error */
|
||||||
bool parser_compile(const char *filename);
|
static bool progs_nextline(char **out, FILE *src)
|
||||||
bool parser_finish(const char *output);
|
{
|
||||||
void parser_cleanup();
|
size_t alen;
|
||||||
|
int len;
|
||||||
|
char *line;
|
||||||
|
char *start;
|
||||||
|
char *end;
|
||||||
|
|
||||||
|
line = *out;
|
||||||
|
len = util_getline(&line, &alen, src);
|
||||||
|
if (len == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* start at first non-blank */
|
||||||
|
for (start = line; isspace(*start); ++start) {}
|
||||||
|
/* end at the first non-blank */
|
||||||
|
for (end = start; *end && !isspace(*end); ++end) {}
|
||||||
|
|
||||||
|
*out = line;
|
||||||
|
/* move the actual filename to the beginning */
|
||||||
|
while (start != end) {
|
||||||
|
*line++ = *start++;
|
||||||
|
}
|
||||||
|
*line = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
size_t itr;
|
size_t itr;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
bool opts_output_free = false;
|
||||||
|
|
||||||
app_name = argv[0];
|
app_name = argv[0];
|
||||||
|
|
||||||
/* default options / warn flags */
|
/* default options / warn flags */
|
||||||
|
@ -361,6 +389,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (!parser_init()) {
|
if (!parser_init()) {
|
||||||
printf("failed to initialize parser\n");
|
printf("failed to initialize parser\n");
|
||||||
|
retval = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +414,42 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
parser_finish(opts_output);
|
parser_finish(opts_output);
|
||||||
} else {
|
} else {
|
||||||
printf("Mode: progs.src - not implemented\n");
|
FILE *src;
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
printf("Mode: progs.src\n");
|
||||||
|
src = fopen("progs.src", "rb");
|
||||||
|
if (!src) {
|
||||||
|
printf("failed to open `progs.src` for reading\n");
|
||||||
|
retval = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
line = NULL;
|
||||||
|
if (!progs_nextline(&line, src) || !line[0]) {
|
||||||
|
printf("illformatted progs.src file: expected output filename in first line\n");
|
||||||
|
retval = 1;
|
||||||
|
goto srcdone;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opts_output_wasset) {
|
||||||
|
opts_output = util_strdup(line);
|
||||||
|
opts_output_free = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (progs_nextline(&line, src)) {
|
||||||
|
if (!line[0] || (line[0] == '/' && line[1] == '/'))
|
||||||
|
continue;
|
||||||
|
printf(" src: %s\n", line);
|
||||||
|
if (!parser_compile(line)) {
|
||||||
|
retval = 1;
|
||||||
|
goto srcdone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srcdone:
|
||||||
|
fclose(src);
|
||||||
|
mem_d(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stuff */
|
/* stuff */
|
||||||
|
@ -394,6 +458,8 @@ cleanup:
|
||||||
util_debug("COM", "cleaning ...\n");
|
util_debug("COM", "cleaning ...\n");
|
||||||
|
|
||||||
parser_cleanup();
|
parser_cleanup();
|
||||||
|
if (opts_output_free)
|
||||||
|
mem_d((char*)opts_output);
|
||||||
|
|
||||||
util_meminfo();
|
util_meminfo();
|
||||||
return retval;
|
return retval;
|
||||||
|
|
Loading…
Reference in a new issue