1 // Emacs style mode select -*- C++ -*-
2 //----------------------------------------------------------------------------
3 //
4 // $Id: t_parse.h 1368 2017-11-01 01:17:48Z wesleyjohnson $
5 //
6 // Copyright(C) 2000 Simon Howard
7 // Copyright (C) 2001-2011 by DooM Legacy Team.
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 // $Log: t_parse.h,v $
24 // Revision 1.5  2004/07/27 08:19:37  exl
25 // New fmod, fs functions, bugfix or 2, patrol nodes
26 //
27 // Revision 1.4  2003/05/30 22:44:07  hurdler
28 // add checkcvar function to FS
29 //
30 // Revision 1.3  2001/08/06 23:57:10  stroggonmeth
31 // Removed portal code, improved 3D floors in hardware mode.
32 //
33 // Revision 1.2  2001/03/13 22:14:20  stroggonmeth
34 // Long time no commit. 3D floors, FraggleScript, portals, ect.
35 //
36 // Revision 1.1  2000/11/02 17:57:28  stroggonmeth
37 // FraggleScript files...
38 //
39 //
40 //--------------------------------------------------------------------------
41 
42 
43 #ifndef T_PARSE_H
44 #define T_PARSE_H
45 
46 #include "doomdef.h"
47 #include "p_mobj.h"
48   // doomtype.h, m_fixed.h, mobj_t
49 
50 #define T_MAXTOKENS 128
51 #define TOKENLENGTH 128
52 #define VARIABLESLOTS 16
53 
54 
55 typedef struct fs_array_s fs_array_t;
56 typedef struct script_s   script_t;
57 typedef struct fs_value_s fs_value_t;
58 typedef struct operator_s operator_t;
59 typedef struct fs_variable_s fs_variable_t;
60 
61 
62 
63 struct fs_value_s
64 {
65   int type;
66   union
67   {
68     int32_t  i;
69     fixed_t  f;
70     const char    *s;
71     mobj_t  *mobj;
72     fs_array_t *a;   // arrays
73     char    *labelptr; // goto() label
74   } value;
75 };
76 
77 
78 struct fs_array_s
79 {
80    struct fs_array_s *next; // next array in save list
81    int saveindex;	   // index for saving
82 
83    unsigned int length;	   // number of values currently initialized
84    fs_value_t *values;	   // array of contained values
85 };
86 
87 
88 #define intvalue(v)                                    \
89   ( (v).type == FSVT_string ? atoi((v).value.s) :       \
90     (v).type == FSVT_fixed ? (int)((v).value.f / FRACUNIT) : \
91     (v).type == FSVT_mobj ? -1 : \
92     (v).type == FSVT_array ? -1 : (v).value.i )
93 
94 #if 1
95 // [WDJ] handle FSVT_int directly, not by including duplicate code
96 #define fixedvalue(v)                                         \
97   ( (v).type == FSVT_fixed ? (v).value.f :                     \
98     (v).type == FSVT_string ? (fixed_t)(atof((v).value.s) * FRACUNIT) : \
99     (v).type == FSVT_mobj ? -1*FRACUNIT : \
100     (v).type == FSVT_array ? -1*FRACUNIT : (v).value.i * FRACUNIT )
101 #else
102 #define fixedvalue(v)                                         \
103   ( (v).type == FSVT_fixed ? (v).value.f :                     \
104     (v).type == FSVT_string ? (fixed_t)(atof((v).value.s) * FRACUNIT) : \
105     (v).type == FSVT_mobj ? -1*FRACUNIT : \
106     (v).type == FSVT_array ? -1*FRACUNIT : intvalue(v) * FRACUNIT )
107 #endif
108 
109 
110 
111 const char * stringvalue(fs_value_t v);
112 
113 #include "t_vari.h"
114 #include "t_prepro.h"
115 
116 #define MAXSCRIPTS 256
117 
118 struct script_s
119 {
120   // script data
121 
122   char *data;
123   int scriptnum;  // this script's number
124   int len;
125 
126   // {} sections
127   fs_section_t *sections[SECTIONSLOTS];
128 
129   // variables:
130   fs_variable_t *variables[VARIABLESLOTS];
131 
132   // ptr to the parent script
133   // the parent script is the script above this level
134   // eg. individual linetrigger scripts are children of the levelscript,
135   // which is a child of the global_script
136   script_t *parent;
137 
138   // child scripts.
139   // levelscript holds ptrs to all of the level's scripts
140   // here.
141 
142   script_t *children[MAXSCRIPTS];
143 
144   mobj_t *trigger;        // object which triggered this script
145 
146   //SoM: Used for if/elseif/else statements
147   boolean  lastiftrue;
148 };
149 
150 struct operator_s
151 {
152   char *string;
153   fs_value_t (*handler)(int, int, int); // left, mid, right
154   int direction;
155 };
156 
157 enum
158 {
159   D_forward,
160   D_backward
161 };
162 
163 void run_script(script_t *script);
164 void continue_script(script_t *script, char *continue_point);
165 void parse_include(char *lumpname);
166 void run_statement( void );
167 void script_error(const char *fmt, ...);
168 void wrong_num_arg( const char * funcname, int num_args );
169 void missing_arg( const char * funcname, int min_num_args );
170 void missing_arg_str( const char * funcname, const char * argstr );
171 
172 fs_value_t evaluate_expression(int start, int stop);
173 int find_operator(int start, int stop, const char *value);
174 int find_operator_backwards(int start, int stop, const char *value);
175 
176 /******* tokens **********/
177 
178 typedef enum
179 {
180   TT_name,   // a name, eg 'count1' or 'frag'
181   TT_number,
182   TT_operator,
183   TT_string,
184   TT_unset,
185   TT_function          // function name
186 } tokentype_t;
187 
188 enum    // brace types: where current_section is a { or }
189 {
190   BRACKET_open,
191   BRACKET_close
192 };
193 
194 extern fs_value_t nullvar;
195 extern byte script_debug;
196 
197 extern script_t * fs_current_script;
198 extern mobj_t * fs_trigger_obj;
199 extern int fs_killscript;
200 
201 extern char *tokens[T_MAXTOKENS];
202 extern tokentype_t tokentype[T_MAXTOKENS];
203 extern int num_tokens;
204 // [WDJ] Common fragglescript vars.
205 extern char * fs_src_cp;     // current point reached in parsing
206 extern char * fs_linestart_cp; // start of the current expression
207 extern fs_section_t * fs_current_section;
208 extern fs_section_t * fs_prev_section;
209 extern int fs_bracetype;
210 
211 // the global_script is the root
212 // script and contains only built-in
213 // FraggleScript variables/functions
214 
215 extern script_t global_script;
216 extern script_t hub_script;
217 
218 #endif
219