@@ -125,34 +125,41 @@ Parse_stat MCExpression::get0params(MCScriptPoint &sp)
125125 return PS_NORMAL;
126126}
127127
128+ Parse_stat MCExpression::gettheparam (MCScriptPoint& sp, Boolean single, MCExpression** exp)
129+ {
130+ initpoint (sp);
131+ if (sp.skip_token (SP_FACTOR, TT_OF) != PS_NORMAL)
132+ return PS_NORMAL;
133+ if (sp.parseexp (single, False, exp) != PS_NORMAL)
134+ {
135+ MCperror->add
136+ (PE_FACTOR_BADPARAM, sp);
137+ return PS_ERROR;
138+ }
139+ return PS_NORMAL;
140+ }
141+
128142Parse_stat MCExpression::get0or1param (MCScriptPoint &sp, MCExpression **exp,
129143 Boolean the)
130144{
131145 if (the)
132146 {
133- initpoint (sp);
134- if (sp.skip_token (SP_FACTOR, TT_OF) != PS_NORMAL)
135- return PS_NORMAL;
136- if (sp.parseexp (False, False, exp) != PS_NORMAL)
137- {
138- MCperror->add
139- (PE_FACTOR_BADPARAM, sp);
140- return PS_ERROR;
141- }
147+ return gettheparam (sp, False, exp);
142148 }
143- else
144- {
145- MCExpression *earray[MAX_EXP] ;
146- uint2 ecount = 0 ;
147- if ( getexps (sp, earray, ecount) != PS_NORMAL || ecount > 1 )
148- {
149- freeexps (earray, ecount) ;
150- return PS_ERROR;
151- }
152- else
153- if (ecount == 1 )
154- *exp = earray[0 ];
149+
150+ MCExpression *earray[MAX_EXP];
151+ uint2 ecount = 0 ;
152+ if ( getexps (sp, earray, ecount) != PS_NORMAL || ecount > 1 )
153+ {
154+ freeexps (earray, ecount);
155+ return PS_ERROR ;
156+ }
157+
158+ if (ecount == 1 )
159+ {
160+ *exp = earray[0 ];
155161 }
162+
156163 return PS_NORMAL;
157164}
158165
@@ -161,32 +168,47 @@ Parse_stat MCExpression::get1param(MCScriptPoint &sp, MCExpression **exp,
161168{
162169 if (the)
163170 {
164- initpoint (sp);
165- if (sp.skip_token (SP_FACTOR, TT_OF) != PS_NORMAL)
166- {
167- MCperror->add
168- (PE_FACTOR_NOOF, sp);
169- return PS_ERROR;
170- }
171- if (sp.parseexp (True, False, exp) != PS_NORMAL)
172- {
173- MCperror->add
174- (PE_FACTOR_BADPARAM, sp);
175- return PS_ERROR;
176- }
171+ return gettheparam (sp, True, exp);
177172 }
178- else
173+
174+ MCExpression *earray[MAX_EXP];
175+ uint2 ecount = 0 ;
176+ if (getexps (sp, earray, ecount) != PS_NORMAL || ecount != 1 )
177+ {
178+ freeexps (earray, ecount);
179+ return PS_ERROR;
180+ }
181+
182+ *exp = earray[0 ];
183+
184+ return PS_NORMAL;
185+ }
186+
187+ Parse_stat MCExpression::get0or1or2params (MCScriptPoint &sp, MCExpression **exp1,
188+ MCExpression **exp2, Boolean the)
189+ {
190+ if (the)
179191 {
180- MCExpression *earray[MAX_EXP];
181- uint2 ecount = 0 ;
182- if (getexps (sp, earray, ecount) != PS_NORMAL || ecount != 1 )
183- {
184- freeexps (earray, ecount);
185- return PS_ERROR;
186- }
187- else
188- *exp = earray[0 ];
192+ return gettheparam (sp, False, exp1);
189193 }
194+
195+ MCExpression *earray[MAX_EXP];
196+ uint2 ecount = 0 ;
197+ if (getexps (sp, earray, ecount) != PS_NORMAL || ecount > 2 )
198+ {
199+ freeexps (earray, ecount);
200+ return PS_ERROR;
201+ }
202+
203+ if (ecount > 0 )
204+ {
205+ *exp1 = earray[0 ];
206+ if (ecount > 1 )
207+ {
208+ *exp2 = earray[1 ];
209+ }
210+ }
211+
190212 return PS_NORMAL;
191213}
192214
@@ -195,33 +217,24 @@ Parse_stat MCExpression::get1or2params(MCScriptPoint &sp, MCExpression **exp1,
195217{
196218 if (the)
197219 {
198- initpoint (sp);
199- if (sp.skip_token (SP_FACTOR, TT_OF) != PS_NORMAL)
200- {
201- MCperror->add
202- (PE_FACTOR_NOOF, sp);
203- return PS_ERROR;
204- }
205- if (sp.parseexp (True, False, exp1) != PS_NORMAL)
206- {
207- MCperror->add
208- (PE_FACTOR_BADPARAM, sp);
209- return PS_ERROR;
210- }
211- }
212- else
213- {
214- MCExpression *earray[MAX_EXP];
215- uint2 ecount = 0 ;
216- if (getexps (sp, earray, ecount) != PS_NORMAL || ecount < 1 || ecount > 2 )
217- {
218- freeexps (earray, ecount);
219- return PS_ERROR;
220- }
221- *exp1 = earray[0 ];
222- if (ecount == 2 )
223- *exp2 = earray[1 ];
220+ return gettheparam (sp, True, exp1);
224221 }
222+
223+ MCExpression *earray[MAX_EXP];
224+ uint2 ecount = 0 ;
225+ if (getexps (sp, earray, ecount) != PS_NORMAL || ecount < 1 || ecount > 2 )
226+ {
227+ freeexps (earray, ecount);
228+ return PS_ERROR;
229+ }
230+
231+ *exp1 = earray[0 ];
232+
233+ if (ecount == 2 )
234+ {
235+ *exp2 = earray[1 ];
236+ }
237+
225238 return PS_NORMAL;
226239}
227240
0 commit comments