Go to the source code of this file.
|
|
Definition at line 83 of file l_script.c. |
|
|
Definition at line 1242 of file l_script.c.
|
|
|
Definition at line 1289 of file l_script.c. References fp, fseek(), ftell(), SEEK_END, and SEEK_SET. Referenced by LoadScriptFile(). 01290 {
01291 int pos;
01292 int end;
01293
01294 pos = ftell(fp);
01295 fseek(fp, 0, SEEK_END);
01296 end = ftell(fp);
01297 fseek(fp, pos, SEEK_SET);
01298
01299 return end;
01300 } //end of the function FileLength
|
Here is the call graph for this function:

|
|
Definition at line 1413 of file l_script.c. References FreeMemory(), and script. Referenced by AAS_ParseBSPEntities(), FreeSource(), HL_ParseEntities(), PC_DefineFromString(), PC_ReadSourceToken(), Q1_ParseEntities(), Q2_LoadMapFile(), Q2_ParseEntities(), Q3_ParseEntities(), and Sin_ParseEntities(). 01414 {
01415 #ifdef PUNCTABLE
01416 if (script->punctuationtable) FreeMemory(script->punctuationtable);
01417 #endif //PUNCTABLE
01418 FreeMemory(script);
01419 } //end of the function FreeScript
|
Here is the call graph for this function:

|
|
Definition at line 1207 of file l_script.c. References script. 01208 {
01209 return script->flags;
01210 } //end of the function GetScriptFlags
|
|
|
Definition at line 1308 of file l_script.c. 01309 {
01310 #ifdef BOTLIB
01311 fileHandle_t fp;
01312 char pathname[MAX_QPATH];
01313 #else
01314 FILE *fp;
01315 #endif
01316 int length;
01317 void *buffer;
01318 script_t *script;
01319
01320 #ifdef BOTLIB
01321 if (strlen(basefolder))
01322 Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename);
01323 else
01324 Com_sprintf(pathname, sizeof(pathname), "%s", filename);
01325 length = botimport.FS_FOpenFile( pathname, &fp, FS_READ );
01326 if (!fp) return NULL;
01327 #else
01328 fp = fopen(filename, "rb");
01329 if (!fp) return NULL;
01330
01331 length = FileLength(fp);
01332 #endif
01333
01334 buffer = GetClearedMemory(sizeof(script_t) + length + 1);
01335 script = (script_t *) buffer;
01336 Com_Memset(script, 0, sizeof(script_t));
01337 strcpy(script->filename, filename);
01338 script->buffer = (char *) buffer + sizeof(script_t);
01339 script->buffer[length] = 0;
01340 script->length = length;
01341 //pointer in script buffer
01342 script->script_p = script->buffer;
01343 //pointer in script buffer before reading token
01344 script->lastscript_p = script->buffer;
01345 //pointer to end of script buffer
01346 script->end_p = &script->buffer[length];
01347 //set if there's a token available in script->token
01348 script->tokenavailable = 0;
01349 //
01350 script->line = 1;
01351 script->lastline = 1;
01352 //
01353 SetScriptPunctuations(script, NULL);
01354 //
01355 #ifdef BOTLIB
01356 botimport.FS_Read(script->buffer, length, fp);
01357 botimport.FS_FCloseFile(fp);
01358 #else
01359 if (fread(script->buffer, length, 1, fp) != 1)
01360 {
01361 FreeMemory(buffer);
01362 script = NULL;
01363 } //end if
01364 fclose(fp);
01365 #endif
01366 //
01367 script->length = COM_Compress(script->buffer);
01368
01369 return script;
01370 } //end of the function LoadScriptFile
|
|
||||||||||||||||
|
Definition at line 1377 of file l_script.c. References buffer, script_t::buffer, Com_Memcpy(), Com_Memset(), script_t::end_p, script_t::filename, GetClearedMemory(), length(), script_t::line, name, NULL, ptr(), script, script_t::script_p, script_t, SetScriptPunctuations(), and strcpy(). Referenced by AAS_ParseBSPEntities(), HL_ParseEntities(), LoadSourceMemory(), PC_DefineFromString(), Q1_ParseEntities(), Q2_ParseEntities(), Q3_ParseEntities(), and Sin_ParseEntities(). 01378 {
01379 void *buffer;
01380 script_t *script;
01381
01382 buffer = GetClearedMemory(sizeof(script_t) + length + 1);
01383 script = (script_t *) buffer;
01384 Com_Memset(script, 0, sizeof(script_t));
01385 strcpy(script->filename, name);
01386 script->buffer = (char *) buffer + sizeof(script_t);
01387 script->buffer[length] = 0;
01388 script->length = length;
01389 //pointer in script buffer
01390 script->script_p = script->buffer;
01391 //pointer in script buffer before reading token
01392 script->lastscript_p = script->buffer;
01393 //pointer to end of script buffer
01394 script->end_p = &script->buffer[length];
01395 //set if there's a token available in script->token
01396 script->tokenavailable = 0;
01397 //
01398 script->line = 1;
01399 script->lastline = 1;
01400 //
01401 SetScriptPunctuations(script, NULL);
01402 //
01403 Com_Memcpy(script->buffer, ptr, length);
01404 //
01405 return script;
01406 } //end of the function LoadScriptMemory
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 556 of file l_script.c. References string(). Referenced by PS_ReadNumber(). 00558 {
00559 unsigned long int dotfound = 0;
00560
00561 *intvalue = 0;
00562 *floatvalue = 0;
00563 //floating point number
00564 if (subtype & TT_FLOAT)
00565 {
00566 while(*string)
00567 {
00568 if (*string == '.')
00569 {
00570 if (dotfound) return;
00571 dotfound = 10;
00572 string++;
00573 } //end if
00574 if (dotfound)
00575 {
00576 *floatvalue = *floatvalue + (long double) (*string - '0') /
00577 (long double) dotfound;
00578 dotfound *= 10;
00579 } //end if
00580 else
00581 {
00582 *floatvalue = *floatvalue * 10.0 + (long double) (*string - '0');
00583 } //end else
00584 string++;
00585 } //end while
00586 *intvalue = (unsigned long) *floatvalue;
00587 } //end if
00588 else if (subtype & TT_DECIMAL)
00589 {
00590 while(*string) *intvalue = *intvalue * 10 + (*string++ - '0');
00591 *floatvalue = *intvalue;
00592 } //end else if
00593 else if (subtype & TT_HEX)
00594 {
00595 //step over the leading 0x or 0X
00596 string += 2;
00597 while(*string)
00598 {
00599 *intvalue <<= 4;
00600 if (*string >= 'a' && *string <= 'f') *intvalue += *string - 'a' + 10;
00601 else if (*string >= 'A' && *string <= 'F') *intvalue += *string - 'A' + 10;
00602 else *intvalue += *string - '0';
00603 string++;
00604 } //end while
00605 *floatvalue = *intvalue;
00606 } //end else if
00607 else if (subtype & TT_OCTAL)
00608 {
00609 //step over the first zero
00610 string += 1;
00611 while(*string) *intvalue = (*intvalue << 3) + (*string++ - '0');
00612 *floatvalue = *intvalue;
00613 } //end else if
00614 else if (subtype & TT_BINARY)
00615 {
00616 //step over the leading 0b or 0B
00617 string += 2;
00618 while(*string) *intvalue = (*intvalue << 1) + (*string++ - '0');
00619 *floatvalue = *intvalue;
00620 } //end else if
00621 } //end of the function NumberValue
|
Here is the call graph for this function:

|
|
Definition at line 1252 of file l_script.c. References script_t::line, and script.
|
|
||||||||||||
|
Definition at line 1023 of file l_script.c. References PS_ReadToken(), script, script_t::script_p, strcmp(), token_s::string, string(), and token_t. 01024 {
01025 token_t tok;
01026
01027 if (!PS_ReadToken(script, &tok)) return 0;
01028 //if the token is available
01029 if (!strcmp(tok.string, string)) return 1;
01030 //token not available
01031 script->script_p = script->lastscript_p;
01032 return 0;
01033 } //end of the function PS_CheckTokenString
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 1040 of file l_script.c. References Com_Memcpy(), PS_ReadToken(), script, script_t::script_p, token_s::subtype, token, token_t, token_s::type, and type. Referenced by Q2_ParseBrush(). 01041 {
01042 token_t tok;
01043
01044 if (!PS_ReadToken(script, &tok)) return 0;
01045 //if the type matches
01046 if (tok.type == type &&
01047 (tok.subtype & subtype) == subtype)
01048 {
01049 Com_Memcpy(token, &tok, sizeof(token_t));
01050 return 1;
01051 } //end if
01052 //token is not available
01053 script->script_p = script->lastscript_p;
01054 return 0;
01055 } //end of the function PS_CheckTokenType
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 175 of file l_script.c. References Com_Memset(), GetMemory(), i, punctuation_s::next, p, punctuation_s::p, punctuation_t, script, and strlen(). Referenced by SetScriptPunctuations(). 00176 {
00177 int i;
00178 punctuation_t *p, *lastp, *newp;
00179
00180 //get memory for the table
00181 if (!script->punctuationtable) script->punctuationtable = (punctuation_t **)
00182 GetMemory(256 * sizeof(punctuation_t *));
00183 Com_Memset(script->punctuationtable, 0, 256 * sizeof(punctuation_t *));
00184 //add the punctuations in the list to the punctuation table
00185 for (i = 0; punctuations[i].p; i++)
00186 {
00187 newp = &punctuations[i];
00188 lastp = NULL;
00189 //sort the punctuations in this table entry on length (longer punctuations first)
00190 for (p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next)
00191 {
00192 if (strlen(p->p) < strlen(newp->p))
00193 {
00194 newp->next = p;
00195 if (lastp) lastp->next = newp;
00196 else script->punctuationtable[(unsigned int) newp->p[0]] = newp;
00197 break;
00198 } //end if
00199 lastp = p;
00200 } //end for
00201 if (!p)
00202 {
00203 newp->next = NULL;
00204 if (lastp) lastp->next = newp;
00205 else script->punctuationtable[(unsigned int) newp->p[0]] = newp;
00206 } //end if
00207 } //end for
00208 } //end of the function PS_CreatePunctuationTable
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1005 of file l_script.c. References PS_ReadToken(), script, ScriptError(), token, and token_t. Referenced by ParseEpair(), Q2_ParseBrush(), ReadSignedFloat(), and ReadSignedInt(). 01006 {
01007 if (!PS_ReadToken(script, token))
01008 {
01009 ScriptError(script, "couldn't read expected token");
01010 return 0;
01011 } //end if
01012 else
01013 {
01014 return 1;
01015 } //end else
01016 } //end of the function PS_ExpectAnyToken
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 924 of file l_script.c. References PS_ReadToken(), script, ScriptError(), strcmp(), string(), token_s::string, token, and token_t. Referenced by Q2_ParseBrush(). 00925 {
00926 token_t token;
00927
00928 if (!PS_ReadToken(script, &token))
00929 {
00930 ScriptError(script, "couldn't find expected %s", string);
00931 return 0;
00932 } //end if
00933
00934 if (strcmp(token.string, string))
00935 {
00936 ScriptError(script, "expected %s, found %s", string, token.string);
00937 return 0;
00938 } //end if
00939 return 1;
00940 } //end of the function PS_ExpectToken
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 947 of file l_script.c. References PS_ReadToken(), script, ScriptError(), strcat(), strcpy(), token_s::string, token_s::subtype, token, token_t, token_s::type, and type. Referenced by AAS_ParseBSPEntities(), Q2_ParseBrush(), ReadSignedFloat(), and ReadSignedInt(). 00948 {
00949 char str[MAX_TOKEN];
00950
00951 if (!PS_ReadToken(script, token))
00952 {
00953 ScriptError(script, "couldn't read expected token");
00954 return 0;
00955 } //end if
00956
00957 if (token->type != type)
00958 {
00959 if (type == TT_STRING) strcpy(str, "string");
00960 if (type == TT_LITERAL) strcpy(str, "literal");
00961 if (type == TT_NUMBER) strcpy(str, "number");
00962 if (type == TT_NAME) strcpy(str, "name");
00963 if (type == TT_PUNCTUATION) strcpy(str, "punctuation");
00964 ScriptError(script, "expected a %s, found %s", str, token->string);
00965 return 0;
00966 } //end if
00967 if (token->type == TT_NUMBER)
00968 {
00969 if ((token->subtype & subtype) != subtype)
00970 {
00971 if (subtype & TT_DECIMAL) strcpy(str, "decimal");
00972 if (subtype & TT_HEX) strcpy(str, "hex");
00973 if (subtype & TT_OCTAL) strcpy(str, "octal");
00974 if (subtype & TT_BINARY) strcpy(str, "binary");
00975 if (subtype & TT_LONG) strcat(str, " long");
00976 if (subtype & TT_UNSIGNED) strcat(str, " unsigned");
00977 if (subtype & TT_FLOAT) strcat(str, " float");
00978 if (subtype & TT_INTEGER) strcat(str, " integer");
00979 ScriptError(script, "expected %s, found %s", str, token->string);
00980 return 0;
00981 } //end if
00982 } //end if
00983 else if (token->type == TT_PUNCTUATION)
00984 {
00985 if (subtype < 0)
00986 {
00987 ScriptError(script, "BUG: wrong punctuation subtype");
00988 return 0;
00989 } //end if
00990 if (token->subtype != subtype)
00991 {
00992 ScriptError(script, "expected %s, found %s",
00993 script->punctuations[subtype], token->string);
00994 return 0;
00995 } //end if
00996 } //end else if
00997 return 1;
00998 } //end of the function PS_ExpectTokenType
|
Here is the call graph for this function:

|
|
Definition at line 1100 of file l_script.c. References script. 01101 {
01102 if (script->whitespace_p != script->endwhitespace_p)
01103 {
01104 return *script->whitespace_p++;
01105 } //end if
01106 else
01107 {
01108 return 0;
01109 } //end else
01110 } //end of the function PS_NextWhiteSpaceChar
|
|
||||||||||||
|
Definition at line 359 of file l_script.c. References c, ch, i, script, script_t::script_p, ScriptError(), and ScriptWarning(). Referenced by PS_ReadLiteral(), and PS_ReadString(). 00360 {
00361 int c, val, i;
00362
00363 //step over the leading '\\'
00364 script->script_p++;
00365 //determine the escape character
00366 switch(*script->script_p)
00367 {
00368 case '\\': c = '\\'; break;
00369 case 'n': c = '\n'; break;
00370 case 'r': c = '\r'; break;
00371 case 't': c = '\t'; break;
00372 case 'v': c = '\v'; break;
00373 case 'b': c = '\b'; break;
00374 case 'f': c = '\f'; break;
00375 case 'a': c = '\a'; break;
00376 case '\'': c = '\''; break;
00377 case '\"': c = '\"'; break;
00378 case '\?': c = '\?'; break;
00379 case 'x':
00380 {
00381 script->script_p++;
00382 for (i = 0, val = 0; ; i++, script->script_p++)
00383 {
00384 c = *script->script_p;
00385 if (c >= '0' && c <= '9') c = c - '0';
00386 else if (c >= 'A' && c <= 'Z') c = c - 'A' + 10;
00387 else if (c >= 'a' && c <= 'z') c = c - 'a' + 10;
00388 else break;
00389 val = (val << 4) + c;
00390 } //end for
00391 script->script_p--;
00392 if (val > 0xFF)
00393 {
00394 ScriptWarning(script, "too large value in escape character");
00395 val = 0xFF;
00396 } //end if
00397 c = val;
00398 break;
00399 } //end case
00400 default: //NOTE: decimal ASCII code, NOT octal
00401 {
00402 if (*script->script_p < '0' || *script->script_p > '9') ScriptError(script, "unknown escape char");
00403 for (i = 0, val = 0; ; i++, script->script_p++)
00404 {
00405 c = *script->script_p;
00406 if (c >= '0' && c <= '9') c = c - '0';
00407 else break;
00408 val = val * 10 + c;
00409 } //end for
00410 script->script_p--;
00411 if (val > 0xFF)
00412 {
00413 ScriptWarning(script, "too large value in escape character");
00414 val = 0xFF;
00415 } //end if
00416 c = val;
00417 break;
00418 } //end default
00419 } //end switch
00420 //step over the escape character or the last digit of the number
00421 script->script_p++;
00422 //store the escape character
00423 *ch = c;
00424 //succesfully read escape character
00425 return 1;
00426 } //end of the function PS_ReadEscapeCharacter
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 736 of file l_script.c. References PS_ReadEscapeCharacter(), script, script_t::script_p, ScriptError(), ScriptWarning(), token_s::string, token_s::subtype, token, token_t, and token_s::type. 00737 {
00738 token->type = TT_LITERAL;
00739 //first quote
00740 token->string[0] = *script->script_p++;
00741 //check for end of file
00742 if (!*script->script_p)
00743 {
00744 ScriptError(script, "end of file before trailing \'");
00745 return 0;
00746 } //end if
00747 //if it is an escape character
00748 if (*script->script_p == '\\')
00749 {
00750 if (!PS_ReadEscapeCharacter(script, &token->string[1])) return 0;
00751 } //end if
00752 else
00753 {
00754 token->string[1] = *script->script_p++;
00755 } //end else
00756 //check for trailing quote
00757 if (*script->script_p != '\'')
00758 {
00759 ScriptWarning(script, "too many characters in literal, ignored");
00760 while(*script->script_p &&
00761 *script->script_p != '\'' &&
00762 *script->script_p != '\n')
00763 {
00764 script->script_p++;
00765 } //end while
00766 if (*script->script_p == '\'') script->script_p++;
00767 } //end if
00768 //store the trailing quote
00769 token->string[2] = *script->script_p++;
00770 //store trailing zero to end the string
00771 token->string[3] = '\0';
00772 //the sub type is the integer literal value
00773 token->subtype = token->string[1];
00774 //
00775 return 1;
00776 } //end of the function PS_ReadLiteral
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 526 of file l_script.c. References c, MAX_TOKEN, script, script_t::script_p, ScriptError(), token_s::string, token_s::subtype, token, token_t, and token_s::type. Referenced by PS_ReadToken(). 00527 {
00528 int len = 0;
00529 char c;
00530
00531 token->type = TT_NAME;
00532 do
00533 {
00534 token->string[len++] = *script->script_p++;
00535 if (len >= MAX_TOKEN)
00536 {
00537 ScriptError(script, "name longer than MAX_TOKEN = %d", MAX_TOKEN);
00538 return 0;
00539 } //end if
00540 c = *script->script_p;
00541 } while ((c >= 'a' && c <= 'z') ||
00542 (c >= 'A' && c <= 'Z') ||
00543 (c >= '0' && c <= '9') ||
00544 c == '_');
00545 token->string[len] = '\0';
00546 //the sub type is the length of the name
00547 token->subtype = len;
00548 return 1;
00549 } //end of the function PS_ReadName
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 628 of file l_script.c. References c, token_s::floatvalue, i, token_s::intvalue, MAX_TOKEN, NumberValue(), script, script_t::script_p, ScriptError(), token_s::string, token_s::subtype, token, token_t, TT_UNSIGNED, and token_s::type. Referenced by PS_ReadToken(). 00629 {
00630 int len = 0, i;
00631 int octal, dot;
00632 char c;
00633 // unsigned long int intvalue = 0;
00634 // long double floatvalue = 0;
00635
00636 token->type = TT_NUMBER;
00637 //check for a hexadecimal number
00638 if (*script->script_p == '0' &&
00639 (*(script->script_p + 1) == 'x' ||
00640 *(script->script_p + 1) == 'X'))
00641 {
00642 token->string[len++] = *script->script_p++;
00643 token->string[len++] = *script->script_p++;
00644 c = *script->script_p;
00645 //hexadecimal
00646 while((c >= '0' && c <= '9') ||
00647 (c >= 'a' && c <= 'f') ||
00648 (c >= 'A' && c <= 'A'))
00649 {
00650 token->string[len++] = *script->script_p++;
00651 if (len >= MAX_TOKEN)
00652 {
00653 ScriptError(script, "hexadecimal number longer than MAX_TOKEN = %d", MAX_TOKEN);
00654 return 0;
00655 } //end if
00656 c = *script->script_p;
00657 } //end while
00658 token->subtype |= TT_HEX;
00659 } //end if
00660 #ifdef BINARYNUMBERS
00661 //check for a binary number
00662 else if (*script->script_p == '0' &&
00663 (*(script->script_p + 1) == 'b' ||
00664 *(script->script_p + 1) == 'B'))
00665 {
00666 token->string[len++] = *script->script_p++;
00667 token->string[len++] = *script->script_p++;
00668 c = *script->script_p;
00669 //binary
00670 while(c == '0' || c == '1')
00671 {
00672 token->string[len++] = *script->script_p++;
00673 if (len >= MAX_TOKEN)
00674 {
00675 ScriptError(script, "binary number longer than MAX_TOKEN = %d", MAX_TOKEN);
00676 return 0;
00677 } //end if
00678 c = *script->script_p;
00679 } //end while
00680 token->subtype |= TT_BINARY;
00681 } //end if
00682 #endif //BINARYNUMBERS
00683 else //decimal or octal integer or floating point number
00684 {
00685 octal = qfalse;
00686 dot = qfalse;
00687 if (*script->script_p == '0') octal = qtrue;
00688 while(1)
00689 {
00690 c = *script->script_p;
00691 if (c == '.') dot = qtrue;
00692 else if (c == '8' || c == '9') octal = qfalse;
00693 else if (c < '0' || c > '9') break;
00694 token->string[len++] = *script->script_p++;
00695 if (len >= MAX_TOKEN - 1)
00696 {
00697 ScriptError(script, "number longer than MAX_TOKEN = %d", MAX_TOKEN);
00698 return 0;
00699 } //end if
00700 } //end while
00701 if (octal) token->subtype |= TT_OCTAL;
00702 else token->subtype |= TT_DECIMAL;
00703 if (dot) token->subtype |= TT_FLOAT;
00704 } //end else
00705 for (i = 0; i < 2; i++)
00706 {
00707 c = *script->script_p;
00708 //check for a LONG number
00709 if ( (c == 'l' || c == 'L') // bk001204 - brackets
00710 && !(token->subtype & TT_LONG))
00711 {
00712 script->script_p++;
00713 token->subtype |= TT_LONG;
00714 } //end if
00715 //check for an UNSIGNED number
00716 else if ( (c == 'u' || c == 'U') // bk001204 - brackets
00717 && !(token->subtype & (TT_UNSIGNED | TT_FLOAT)))
00718 {
00719 script->script_p++;
00720 token->subtype |= TT_UNSIGNED;
00721 } //end if
00722 } //end for
00723 token->string[len] = '\0';
00724 #ifdef NUMBERVALUE
00725 NumberValue(token->string, token->subtype, &token->intvalue, & |