/* ============== PR_LexGrab Deals with counting sequence numbers and replacing frame macros ============== */ void PR_LexGrab (void) { pr_file_p++; // skip the $ if (!PR_SimpleGetToken ()) PR_ParseError ("hanging $"); // check for $frame if (!strcmp (pr_token, "frame")) { PR_ParseFrame (); PR_Lex (); } // ignore other known $commands else if (!strcmp (pr_token, "cd") || !strcmp (pr_token, "origin") || !strcmp (pr_token, "base") || !strcmp (pr_token, "flags") || !strcmp (pr_token, "scale") || !strcmp (pr_token, "skin") ) { // skip to end of line while (PR_SimpleGetToken ()) ; PR_Lex (); } // look for a frame name macro else PR_FindMacro (); }
void PR_ParseFrame (void) { while (PR_SimpleGetToken ()) { strcpy (pr_framemacros[pr_nummacros], pr_token); pr_nummacros++; } }
/* ======================== PR_LexPrecomp parses and executes directives with a leading '#': #define #undef #ifdef #ifndef #else #endif #error #message #pragma message ======================== */ void PR_LexPrecomp (void) { // yeah it isn't quite Precompiler is it? pr_file_p++; // skip the hash if (!PR_SimpleGetToken ()) PR_ParseError ("Q534: Invalid preprocessor command"); // that's not possible if (!strcmp(pr_token, "ifdef")) { if (ifdefdepth > ignoredepth) { // inside another ignored "ifdef"/"ifndef" // -> ignore statements ifdefdepth++; return; } ifdefdepth++; ignoredepth = ifdefdepth; PR_Lex(); if (!PR_FindDefine(pr_token, true)) { // not defined // -> ignore statements until endif or else ignoredepth--; while(ifdefdepth > ignoredepth) PR_Lex(); return; } // defined // -> parse statements PR_Lex(); return; } else if (!strcmp(pr_token, "ifndef")) { if (ifdefdepth > ignoredepth) { // inside another ignored ifdef // -> ignore statements ifdefdepth++; return; } ifdefdepth++; ignoredepth = ifdefdepth; PR_Lex(); if (PR_FindDefine(pr_token, true)) { // defined // -> ignore statements ignoredepth--; while(ifdefdepth > ignoredepth) PR_Lex(); return; } PR_Lex(); return; } else if (!strcmp(pr_token, "endif")) { ifdefdepth--; if (ifdefdepth < 0) PR_ParseError ("Q119: Too many #endifs"); PR_Lex(); return; } else if (!strcmp(pr_token, "else")) { if (ifdefdepth == (ignoredepth + 1)) { // the "ifdef" or "ifndef" part has not been entered // -> parse the statements inside "else" //print("parsing statment %s in else on %s(%ld)", pr_token, s_file + strings, pr_source_line); ignoredepth = ifdefdepth; pr_token_type = tt_name; PR_Lex(); return; } // "ifdef" or "ifndef" part has already been entered // -> ignore statements in "else" part ignoredepth--; while (ifdefdepth > ignoredepth) PR_Lex(); return; } else if (ifdefdepth > ignoredepth) { //print("ignored %s on %s(%ld)", pr_token, s_file + strings, pr_source_line); return; } else if (PR_Check("error")) { if (pr_immediate_type != &type_string && pr_immediate_type != &type_const_string) PR_ParseError ("Q541: Error must be a string"); PR_ParseError ("User Error on %s(%ld): %s", s_file + strings, pr_source_line, pr_immediate_string); PR_Lex(); return; } else if (PR_Check("message")) { if (pr_immediate_type != &type_string && pr_immediate_type != &type_const_string) PR_ParseError ("Q541: Message must be a string"); printf ("Message on %s(%ld): %s\n", s_file + strings, (long)pr_source_line, pr_immediate_string); PR_Lex(); return; } else if (PR_Check("pragma")) { if (PR_Check("message")) { if (pr_immediate_type != &type_string && pr_immediate_type != &type_const_string) PR_ParseError ("Q541: Message must be a string"); printf ("Message on %s(%ld): %s\n", s_file + strings, (long)pr_source_line, pr_immediate_string); PR_Lex(); return; } // unknown pragma directive printf ("Warning on %s(%ld): unknown #pragma \"%s\" (will be ignored)", s_file + strings, (long)pr_source_line, pr_token); // skip to the end of the line while (PR_SimpleGetToken ()) ; PR_Lex(); return; } else if (PR_Check("define")) { char define_name[2048]; if (pr_token_type != tt_name) PR_ParseError ("Q543: #define: Invalid name"); // predefine it: strlcpy (define_name, pr_token, sizeof(define_name)); if (PR_AddDefine (define_name, &type_const_float, NULL, false) <= 0) PR_ParseError ("Q544: #define \"%s\": creation failed", define_name); // get the value of the define PR_Lex(); if (pr_token_type == tt_immediate) { if (pr_immediate_type != &type_float && pr_immediate_type != &type_const_float) PR_ParseError ("Q545: #define \"%s\": Invalid type of value", define_name); // finally fix the define (with given value) if (PR_AddDefine (define_name, pr_immediate_type, &pr_immediate, false) <= 0) PR_ParseError ("Q544: #define \"%s\": creation failed", define_name); PR_Lex(); } else { eval_t value; value._float = 1; // finally fix the define (with default-value) if (PR_AddDefine (define_name, &type_const_float, &value, false) <= 0) PR_ParseError ("Q544: #define \"%s\": creation failed", define_name); } return; } else if (PR_Check("undef")) { if (pr_token_type != tt_name) PR_ParseError ("Q544: #undef: Invalid name"); PR_DelDefine (pr_token, false); PR_Lex(); return; } } // END_FUNC PR_LexPrecomp