l_precomp.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. /*****************************************************************************
  19. * name: l_precomp.h
  20. *
  21. * desc: pre compiler
  22. *
  23. * $Archive: /source/code/botlib/l_precomp.h $
  24. *
  25. *****************************************************************************/
  26. #ifndef MAX_PATH
  27. #define MAX_PATH MAX_QPATH
  28. #endif
  29. #ifndef PATH_SEPERATORSTR
  30. #if defined(WIN32)|defined(_WIN32)|defined(__NT__)|defined(__WINDOWS__)|defined(__WINDOWS_386__)
  31. #define PATHSEPERATOR_STR "\\"
  32. #else
  33. #define PATHSEPERATOR_STR "/"
  34. #endif
  35. #endif
  36. #ifndef PATH_SEPERATORCHAR
  37. #if defined(WIN32)|defined(_WIN32)|defined(__NT__)|defined(__WINDOWS__)|defined(__WINDOWS_386__)
  38. #define PATHSEPERATOR_CHAR '\\'
  39. #else
  40. #define PATHSEPERATOR_CHAR '/'
  41. #endif
  42. #endif
  43. #if defined(BSPC) && !defined(QDECL)
  44. #define QDECL
  45. #endif
  46. #define DEFINE_FIXED 0x0001
  47. #define BUILTIN_LINE 1
  48. #define BUILTIN_FILE 2
  49. #define BUILTIN_DATE 3
  50. #define BUILTIN_TIME 4
  51. #define BUILTIN_STDC 5
  52. #define INDENT_IF 0x0001
  53. #define INDENT_ELSE 0x0002
  54. #define INDENT_ELIF 0x0004
  55. #define INDENT_IFDEF 0x0008
  56. #define INDENT_IFNDEF 0x0010
  57. //macro definitions
  58. typedef struct define_s
  59. {
  60. char *name; //define name
  61. int flags; //define flags
  62. int builtin; // > 0 if builtin define
  63. int numparms; //number of define parameters
  64. token_t *parms; //define parameters
  65. token_t *tokens; //macro tokens (possibly containing parm tokens)
  66. struct define_s *next; //next defined macro in a list
  67. struct define_s *hashnext; //next define in the hash chain
  68. } define_t;
  69. //indents
  70. //used for conditional compilation directives:
  71. //#if, #else, #elif, #ifdef, #ifndef
  72. typedef struct indent_s
  73. {
  74. int type; //indent type
  75. int skip; //true if skipping current indent
  76. script_t *script; //script the indent was in
  77. struct indent_s *next; //next indent on the indent stack
  78. } indent_t;
  79. //source file
  80. typedef struct source_s
  81. {
  82. char filename[1024]; //file name of the script
  83. char includepath[1024]; //path to include files
  84. punctuation_t *punctuations; //punctuations to use
  85. script_t *scriptstack; //stack with scripts of the source
  86. token_t *tokens; //tokens to read first
  87. define_t *defines; //list with macro definitions
  88. define_t **definehash; //hash chain with defines
  89. indent_t *indentstack; //stack with indents
  90. int skip; // > 0 if skipping conditional code
  91. token_t token; //last read token
  92. } source_t;
  93. //read a token from the source
  94. int PC_ReadToken(source_t *source, token_t *token);
  95. //expect a certain token
  96. int PC_ExpectTokenString(source_t *source, char *string);
  97. //expect a certain token type
  98. int PC_ExpectTokenType(source_t *source, int type, int subtype, token_t *token);
  99. //expect a token
  100. int PC_ExpectAnyToken(source_t *source, token_t *token);
  101. //returns true when the token is available
  102. int PC_CheckTokenString(source_t *source, char *string);
  103. //returns true an reads the token when a token with the given type is available
  104. int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token);
  105. //skip tokens until the given token string is read
  106. int PC_SkipUntilString(source_t *source, char *string);
  107. //unread the last token read from the script
  108. void PC_UnreadLastToken(source_t *source);
  109. //unread the given token
  110. void PC_UnreadToken(source_t *source, token_t *token);
  111. //read a token only if on the same line, lines are concatenated with a slash
  112. int PC_ReadLine(source_t *source, token_t *token);
  113. //returns true if there was a white space in front of the token
  114. int PC_WhiteSpaceBeforeToken(token_t *token);
  115. //add a define to the source
  116. int PC_AddDefine(source_t *source, char *string);
  117. //add a globals define that will be added to all opened sources
  118. int PC_AddGlobalDefine(char *string);
  119. //remove the given global define
  120. int PC_RemoveGlobalDefine(char *name);
  121. //remove all globals defines
  122. void PC_RemoveAllGlobalDefines(void);
  123. //add builtin defines
  124. void PC_AddBuiltinDefines(source_t *source);
  125. //set the source include path
  126. void PC_SetIncludePath(source_t *source, char *path);
  127. //set the punction set
  128. void PC_SetPunctuations(source_t *source, punctuation_t *p);
  129. //set the base folder to load files from
  130. void PC_SetBaseFolder(char *path);
  131. //load a source file
  132. source_t *LoadSourceFile(const char *filename);
  133. //load a source from memory
  134. source_t *LoadSourceMemory(char *ptr, int length, char *name);
  135. //free the given source
  136. void FreeSource(source_t *source);
  137. //print a source error
  138. void QDECL SourceError(source_t *source, char *str, ...);
  139. //print a source warning
  140. void QDECL SourceWarning(source_t *source, char *str, ...);
  141. #ifdef BSPC
  142. // some of BSPC source does include game/q_shared.h and some does not
  143. // we define pc_token_s pc_token_t if needed (yes, it's ugly)
  144. #ifndef __Q_SHARED_H
  145. #define MAX_TOKENLENGTH 1024
  146. typedef struct pc_token_s
  147. {
  148. int type;
  149. int subtype;
  150. int intvalue;
  151. float floatvalue;
  152. char string[MAX_TOKENLENGTH];
  153. } pc_token_t;
  154. #endif //!_Q_SHARED_H
  155. #endif //BSPC
  156. //
  157. int PC_LoadSourceHandle(const char *filename);
  158. int PC_FreeSourceHandle(int handle);
  159. int PC_ReadTokenHandle(int handle, pc_token_t *pc_token);
  160. int PC_SourceFileAndLine(int handle, char *filename, int *line);
  161. void PC_CheckOpenSourceHandles(void);