mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
parser_compile_file vs parser_compile_string
This commit is contained in:
parent
a84f9483e6
commit
cf1ea01de3
3 changed files with 28 additions and 13 deletions
9
gmqcc.h
9
gmqcc.h
|
@ -939,10 +939,11 @@ 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();
|
||||
bool parser_init ();
|
||||
bool parser_compile_file (const char *filename);
|
||||
bool parser_compile_string(const char *name, const char *str);
|
||||
bool parser_finish (const char *output);
|
||||
void parser_cleanup ();
|
||||
|
||||
/*===================================================================*/
|
||||
/*======================= main.c commandline ========================*/
|
||||
|
|
4
main.c
4
main.c
|
@ -460,7 +460,7 @@ int main(int argc, char **argv) {
|
|||
(items_data[itr].type == TYPE_SRC ? "progs.src" :
|
||||
("unknown"))))));
|
||||
|
||||
if (!parser_compile(items_data[itr].filename)) {
|
||||
if (!parser_compile_file(items_data[itr].filename)) {
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ int main(int argc, char **argv) {
|
|||
if (!line[0] || (line[0] == '/' && line[1] == '/'))
|
||||
continue;
|
||||
printf(" src: %s\n", line);
|
||||
if (!parser_compile(line)) {
|
||||
if (!parser_compile_file(line)) {
|
||||
retval = 1;
|
||||
goto srcdone;
|
||||
}
|
||||
|
|
28
parser.c
28
parser.c
|
@ -2840,14 +2840,8 @@ bool parser_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool parser_compile(const char *filename)
|
||||
bool parser_compile()
|
||||
{
|
||||
parser->lex = lex_open(filename);
|
||||
if (!parser->lex) {
|
||||
printf("failed to open file \"%s\"\n", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* initial lexer/parser state */
|
||||
parser->lex->flags.noops = true;
|
||||
|
||||
|
@ -2878,6 +2872,26 @@ bool parser_compile(const char *filename)
|
|||
return !parser->errors;
|
||||
}
|
||||
|
||||
bool parser_compile_file(const char *filename)
|
||||
{
|
||||
parser->lex = lex_open(filename);
|
||||
if (!parser->lex) {
|
||||
printf("failed to open file \"%s\"\n", filename);
|
||||
return false;
|
||||
}
|
||||
return parser_compile();
|
||||
}
|
||||
|
||||
bool parser_compile_string(const char *name, const char *str)
|
||||
{
|
||||
parser->lex = lex_open_string(str, strlen(str), name);
|
||||
if (!parser->lex) {
|
||||
printf("failed to create lexer for string \"%s\"\n", name);
|
||||
return false;
|
||||
}
|
||||
return parser_compile();
|
||||
}
|
||||
|
||||
void parser_cleanup()
|
||||
{
|
||||
size_t i;
|
||||
|
|
Loading…
Reference in a new issue