2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
15 * Header for parselo.c
18 * Revision 1.2 2002/06/09 04:41:14 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:12 root
25 * 14 9/13/99 10:40a Mikeb
26 * Bumped up MISSION_TEXT_SIZE from 380000 to 390000 for ships.tbl ship
29 * 13 8/02/99 4:19p Andsager
30 * Bump up MISSION_TEXT_SIZE to 380000 for ships.tbl
32 * 12 5/03/99 10:10a Davidg
33 * DA: Bump Mission_text_size to handle large ship.tbl
35 * 11 2/19/99 11:10a Jasen
36 * Upped MISSION_TEXT_SIZE to 300000 (for souper cap)
38 * 10 2/03/99 6:06p Dave
39 * Groundwork for FS2 PXO usertracker support. Gametracker support next.
41 * 9 1/07/99 1:52p Andsager
42 * Initial check in of Sexp_variables
44 * 8 11/05/98 4:18p Dave
45 * First run nebula support. Beefed up localization a bit. Removed all
46 * conditional compiles for foreign versions. Modified mission file
49 * 7 10/26/98 9:42a Dave
50 * Early flak gun support.
52 * 6 10/22/98 6:14p Dave
53 * Optimized some #includes in Anim folder. Put in the beginnings of
54 * parse/localization support for externalized strings and tstrings.tbl
56 * 5 10/16/98 1:22p Andsager
57 * clean up header files
59 * 4 10/14/98 1:15p Andsager
62 * 3 10/14/98 12:25p Andsager
63 * Cleaned up and removed unnecessary include files
65 * 2 10/07/98 10:53a Dave
68 * 1 10/07/98 10:50a Dave
70 * 54 6/10/98 6:47p Lawrance
71 * Increase allowed mission length to 512, to accommodate longer French
74 * 53 5/20/98 2:27a Sandeep
76 * 52 4/30/98 4:53p John
77 * Restructured and cleaned up cfile code. Added capability to read off
78 * of CD-ROM drive and out of multiple pack files.
80 * 51 4/03/98 10:31a John
81 * Made briefing and debriefing arrays be malloc'd
83 * 50 3/30/98 6:22p Hoffoss
84 * Added a new parsing function.
86 * 49 3/29/98 12:55a Lawrance
87 * Get demo build working with limited set of data.
89 * 48 2/02/98 4:59p Hoffoss
90 * Added a promotion text field to rank.tbl and code to support it in
93 * 47 11/03/97 10:11p Hoffoss
94 * Added new split_str_once() function. Works similar to split_str(),
95 * only it only splits a string into 2 lines.
97 * 46 10/29/97 9:02a Jasen
98 * Raised MISSION_TEXT_SIZE limit to 128000.
100 * 45 10/17/97 3:12p Hoffoss
101 * Added a whitespace elimination function, and utilized it in briefing
104 * 44 10/15/97 4:46p Lawrance
105 * add drop_leading_whitespace() function
107 * 43 10/08/97 4:48p Dave
108 * Moved file id function into missionparse (from parselo). Finished
109 * tracker logging in and out of games. Changed how file checksumming
112 * 42 10/07/97 5:08p Dave
113 * Added file versioning/checksumming for multiplayer situations. Began
114 * master tracker changes for finalized version.
116 * 41 10/01/97 5:07p Hoffoss
117 * Weapon loadout load and save from fsm files added.
119 * 40 9/22/97 5:47p Lawrance
120 * re-write split_str() to allow special control words that don't get
121 * considered as part of printable string
123 * 39 9/09/97 3:39p Sandeep
124 * warning level 4 bugs
126 * 38 8/17/97 12:47p Hoffoss
127 * Changed code so I can force missions to load from the missions
128 * directory regardless of it's extension.
130 * 37 8/13/97 10:54a Hoffoss
131 * Added function to help extract only parts of a mission file.
133 * 36 7/22/97 5:38p Jasen
134 * Fixed bug with sexp error checking code. Wasn't accounting for player
135 * names in ship name lookup.
137 * 35 6/23/97 12:02p Lawrance
138 * move split_str() here, support \n's.
140 * 34 6/11/97 6:14p Hoffoss
141 * Made messages able to be longer.
143 * 33 4/28/97 3:30p Hoffoss
144 * Changed mission saving to not rely on required strings being present in
145 * mission files being overwritten.
147 * 32 4/22/97 4:50p Hoffoss
148 * Added some flexibility to stuff_string().
150 * 31 4/21/97 5:02p Hoffoss
151 * Player/player status editing supported, and both saved and loaded from
154 * 30 3/09/97 2:23p Allender
155 * Major changes to player messaging system. Added messages.tbl. Made
156 * all currently player messages go through new system. Not done yet.
158 * 29 3/04/97 11:19a Lawrance
159 * added stuff_booleanI() that recognizes 1/0 and YES/NO
161 * 28 2/18/97 9:52a Adam
162 * Raised parsing text max size limit (Jason)
164 * 27 1/31/97 12:07p John
165 * Add turret gun type on end of $subsystem line. Changed match_and_find
166 * to return index rather than stuffing it.
168 * 26 1/30/97 5:15p Mike
170 * Better named AI classes.
171 * Optional override of AI class in fsm file.
173 * 25 1/29/97 2:59p Mike
174 * Table-driven support for John's laser rendering.
175 * Null hook for AVI weapons.
177 * 24 1/17/97 3:50p Hoffoss
178 * Fred bug fixes and slight improvements in order to be able to create
181 * 23 12/12/96 3:06p Mike
182 * Fix bug in parsing code created by adding support for optional
183 * terminators in required_string.
185 * 22 12/12/96 2:35p Mike
188 * 21 12/11/96 3:31p Hoffoss
189 * Added support for more flexible ship cargos.
191 * 20 12/09/96 9:47a Hoffoss
192 * Fixed silly error. #define was in wrong file, so I moved it.
194 * 19 12/03/96 2:44p Mike
195 * Support for ship class and ship specific AI abilities: evasion,
196 * courage, patience, accuracy
198 * 18 11/15/96 1:43p Hoffoss
199 * Improvements to the Ship Dialog editor window. It is now an
200 * independant window that updates data correctly.
202 * 17 11/07/96 1:56p Allender
203 * externed function for use in sexp.cpp
205 * 16 10/30/96 9:05a Hoffoss
206 * Expanded mission file max size to 32k
208 * 15 10/29/96 3:28p Allender
209 * added stuff_string_list function.
211 * 14 10/28/96 12:18p Allender
212 * added a couple of functions to deal with getting and moving past
213 * strings on a whitespace only basis (instead ot to EOL)
215 * 13 10/23/96 11:06a Mike
217 * Revision 1.4 1996/09/24 13:50:41 mike
218 * Clean up some low level code in parselo.c.
219 * Add support for Player info in mission.txt.
221 * Revision 1.3 1996/09/23 20:42:03 allender
222 * added filename as parameter to read_mission_text
224 * Revision 1.2 1996/09/23 17:18:39 mike
225 * Split parse.h into parse.h and parselo.h
227 * Revision 1.1 1996/09/23 17:11:36 mike
238 #define MISSION_TEXT_SIZE 390000
240 extern char Mission_text[MISSION_TEXT_SIZE];
241 extern char Mission_text_raw[MISSION_TEXT_SIZE];
243 extern const char *token_found;
244 extern int fred_parse_flag;
245 extern int Token_found_flag;
247 // NOTE: numbered to match original error values
249 PARSE_ERROR_MISSING_TOKEN = 1,
250 PARSE_ERROR_MISSING_TOKEN_EITHER = 2,
251 PARSE_ERROR_MISSING_STRING = 3,
252 PARSE_ERROR_TOO_LONG = 4,
253 PARSE_ERROR_EMPTY_FILENAME = 10,
254 PARSE_ERROR_FILE_NOT_FOUND = 5,
255 PARSE_ERROR_STRING_LIST = 100,
256 PARSE_ERROR_INT_LIST = 6,
257 PARSE_ERROR_VECTOR_PSTART = 11,
258 PARSE_ERROR_VECTOR_PEND = 12
261 #define COMMENT_CHAR (char)';'
262 #define EOF_CHAR (char)-128
263 #define EOLN (char)0x0a
269 #define F_MULTITEXTOLD 5 // needed for backwards compatability with old briefing format
272 #define F_SHIPCHOICE 8
273 #define F_MESSAGE 9 // this is now obsolete for mission messages - all messages in missions should now use $MessageNew and stuff strings as F_MULTITEXT
274 #define F_MULTITEXT 10
276 #define PATHNAME_LENGTH 192
277 #define NAME_LENGTH 32
278 #define SEXP_LENGTH 128
279 #define DATE_LENGTH 32
280 #define TIME_LENGTH 16
281 #define DATE_TIME_LENGTH 48
282 #define NOTES_LENGTH 1024
283 #define MULTITEXT_LENGTH 1024
284 #define FILESPEC_LENGTH 64
285 #define MESSAGE_LENGTH 512
287 #define SHIP_TYPE 0 // used to identify which kind of array to do a search for a name in
288 #define SHIP_INFO_TYPE 1
289 #define WEAPON_LIST_TYPE 2 // to parse an int_list of weapons
290 #define RAW_INTEGER_TYPE 3 // to parse a list of integers
291 #define WEAPON_POOL_TYPE 4
293 #define SEXP_SAVE_MODE 1
294 #define SEXP_ERROR_CHECK_MODE 2
297 extern int is_white_space(char ch);
298 extern void ignore_white_space();
299 extern void drop_trailing_white_space(char *str);
300 extern void drop_leading_white_space(char *str);
301 extern char *drop_white_space(char *str);
304 void ignore_gray_space();
307 extern int get_line_num();
308 extern char *next_tokens();
309 extern void diag_printf(const char *format, ...);
310 extern void error_display(int error_level, const char *format, ...);
313 extern int skip_to_string(const char *pstr, const char *end = NULL);
314 extern int skip_to_start_of_strings(const char *pstr1, const char *pstr2);
315 extern void advance_to_eoln(const char *terminators);
316 extern void skip_token();
319 extern int required_string(const char *pstr);
320 extern int optional_string(const char *pstr);
321 extern int required_string_either(const char *str1, const char *str2);
322 extern int required_string_3(const char *str1, const char *str2, const char *str3);
325 extern void copy_to_eoln(char *outstr, const char *more_terminators, const char *instr, int max);
326 extern void copy_text_until(char *outstr, const char *instr, const char *endstr, int max_chars);
327 extern void stuff_string_white(char *pstr);
328 extern void stuff_string(char *pstr, int type, const char *terminators, int len = 0);
329 extern void stuff_string_line(char *pstr, int len);
331 // Exactly the same as stuff string only Malloc's the buffer.
332 // Supports various FreeSpace primitive types. If 'len' is supplied, it will override
333 // the default string length if using the F_NAME case.
334 char *stuff_and_malloc_string( int type, const char *terminators, int len);
335 extern void stuff_float(float *f);
336 extern void stuff_int(int *i);
337 extern void stuff_byte(ubyte *i);
338 extern int stuff_string_list(char slp[][NAME_LENGTH], int max_strings);
339 extern int stuff_int_list(int *ilp, int max_ints, int lookup_type);
340 extern int stuff_vector_list(vector *vlp, int max_vecs);
341 extern void stuff_vector(vector *vp);
342 extern void stuff_matrix(matrix *mp);
343 extern int string_lookup(const char *str1, const char *strlist[], int max, const char *description = NULL, int say_errors = 0);
344 extern void find_and_stuff(const char *id, int *addr, int f_type, const char *strlist[], int max, const char *description);
345 extern int match_and_stuff(int f_type, const char *strlist[], int max, const char *description);
346 extern void find_and_stuff_or_add(const char *id, int *addr, int f_type, char *strlist[], const int max_strlen, int *total,
347 int max, const char *description);
348 extern int get_string(char *str);
349 extern void stuff_parenthesized_vector(vector *vp);
350 void stuff_boolean(int *i);
351 int check_for_string(const char *pstr);
352 int check_for_string_raw(const char *pstr);
355 extern void init_parse();
356 extern void reset_parse();
357 extern void display_parse_diagnostics();
358 extern void parse_main();
361 extern void mark_int_list(int *ilp, int max_ints, int lookup_type);
362 extern void compact_multitext_string(char *str);
363 extern void read_file_text(const char *filename, int mode = CF_TYPE_ANY );
364 extern void debug_show_mission_text();
365 extern void convert_sexp_to_string(int cur_node, char *outstr, const int outstr_len, int mode);
366 char *split_str_once(char *src, int max_pixel_w);
367 int split_str(const char *src, int max_pixel_w, int *n_chars, char **p_str, int max_lines, char ignore_char = -1);
370 extern int required_string_fred(const char *pstr, const char *end = NULL);
371 extern int required_string_either_fred(const char *str1, const char *str2);
372 extern int optional_string_fred(const char *pstr, const char *end = NULL, const char *end2 = NULL);