Annotation of capa/capa51/pProj/capaFunction.c, revision 1.10
1.7 albertel 1: /* definition of all capa functions
2: Copyright (C) 1992-2000 Michigan State University
3:
4: The CAPA system is free software; you can redistribute it and/or
1.9 albertel 5: modify it under the terms of the GNU General Public License as
1.7 albertel 6: published by the Free Software Foundation; either version 2 of the
7: License, or (at your option) any later version.
8:
9: The CAPA system is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.9 albertel 12: General Public License for more details.
1.7 albertel 13:
1.9 albertel 14: You should have received a copy of the GNU General Public
1.7 albertel 15: License along with the CAPA system; see the file COPYING. If not,
16: write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.8 albertel 17: Boston, MA 02111-1307, USA.
18:
19: As a special exception, you have permission to link this program
20: with the TtH/TtM library and distribute executables, as long as you
21: follow the requirements of the GNU GPL in regard to all of the
22: software in the executable aside from TtH/TtM.
23: */
1.1 albertel 24:
25: /* =||>>================================================================<<||= */
26: /* 45678901234567890123456789012345678901234567890123456789012345678901234567 */
1.8 albertel 27: /* by Isaac Tsai, 1996, 1997, 1998, 1999, 2000 */
1.1 albertel 28: /* =||>>================================================================<<||= */
29:
30: #include <stdlib.h>
31: #include <string.h>
32: #include <math.h>
33:
34: #include "capaParser.h" /* Symbol_p */
35: #include "capaFunction.h" /* RANDOM_F etc. */
36: #include "capaToken.h"
37: #include "capaCommon.h"
38: #include "ranlib.h"
39:
40: char Parse_class[QUARTER_K];
41: int Parse_set;
42: int Parse_section;
43: char Parse_student_number[MAX_STUDENT_NUMBER+1];
44: char Parse_name[MAX_NAME_CHAR+1];
45: long capaid_plus_gen;
1.3 albertel 46: int managermode;
1.1 albertel 47:
48: extern int Parsemode_f;
49:
50: extern int Lexi_qnum;
51: extern char Opened_filename[MAX_OPENED_FILE][QUARTER_K];
52: extern int Input_idx;
53: extern int Current_line[MAX_OPENED_FILE];
54:
55: extern int Func_idx;
56: extern Symbol FuncStack[MAX_FUNC_NEST];
57:
1.6 albertel 58: #ifdef TTH
59: extern int textohtmldyn(char*,char**,char**,int);
60: char *tth_err;
61: #endif
62:
1.1 albertel 63: /* --------------------------------------------------------------------------- */
64: int
65: match_function(func, argc) char *func; int argc;
66: {
67: if( !strcmp(func,"random") ) return (((argc==2 || argc==3)? RANDOM_F : MIS_ARG_COUNT));
1.5 albertel 68: if( !strcmp(func,"random_normal") ) return ((argc==5)? RANDOM_NORMAL_F : MIS_ARG_COUNT);
1.10 ! albertel 69: if( !strcmp(func,"random_multivariate_normal") ) return ((argc==6)? RANDOM_MULTIVARIATE_NORMAL_F : MIS_ARG_COUNT);
1.5 albertel 70: if( !strcmp(func,"random_beta") ) return ((argc==5)? RANDOM_BETA_F : MIS_ARG_COUNT);
71: if( !strcmp(func,"random_gamma") ) return ((argc==5)? RANDOM_GAMMA_F : MIS_ARG_COUNT);
72: if( !strcmp(func,"random_poisson") ) return ((argc==4)? RANDOM_POISSON_F : MIS_ARG_COUNT);
73: if( !strcmp(func,"random_exponential") ) return ((argc==4)? RANDOM_EXPONENTIAL_F : MIS_ARG_COUNT);
74: if( !strcmp(func,"random_chi") ) return ((argc==4)? RANDOM_CHI_F : MIS_ARG_COUNT);
1.6 albertel 75: if( !strcmp(func,"random_noncentral_chi") ) return ((argc==5)? RANDOM_NONCENTRAL_CHI_F : MIS_ARG_COUNT);
1.1 albertel 76: if( !strcmp(func,"choose") ) return (CHOOSE_F);
77: if( !strcmp(func,"tex") ) return (((argc==2)? TEX_F: MIS_ARG_COUNT));
78: if( !strcmp(func,"var_in_tex") ) return (VAR_IN_TEX_F);
79: if( !strcmp(func,"html") ) return (((argc==1)? HTML_F: MIS_ARG_COUNT));
80: if( !strcmp(func,"web") ) return (((argc==3)? WEB_F: MIS_ARG_COUNT));
81: if( !strcmp(func,"pin") ) return (((argc<2)? PIN_F: MIS_ARG_COUNT));
82: if( !strcmp(func,"capa_id") ) return (((argc<2)? PIN_F: MIS_ARG_COUNT));
83: if( !strcmp(func,"class") ) return (((argc==0)? CLASS_F: MIS_ARG_COUNT));
84: if( !strcmp(func,"section") ) return (((argc==0)? SECTION_F: MIS_ARG_COUNT));
85: if( !strcmp(func,"set") ) return (((argc==0)? SET_F: MIS_ARG_COUNT));
86: if( !strcmp(func,"problem") ) return (((argc==0)? PROBLEM_F: MIS_ARG_COUNT));
87: if( !strcmp(func,"name") ) return (((argc==0)? NAME_F: MIS_ARG_COUNT));
88: if( !strcmp(func,"student_number") ) return (((argc==0)? SNUMBER_F: MIS_ARG_COUNT));
89: if( !strcmp(func,"due_date") ) return (((argc<2)? DUE_DATE_F: MIS_ARG_COUNT));
90: if( !strcmp(func,"due_day") ) return (((argc<2)? DUE_DAY_F: MIS_ARG_COUNT));
91: if( !strcmp(func,"open_date") ) return (((argc<2)? OPEN_DATE_F: MIS_ARG_COUNT));
92: if( !strcmp(func,"answer_date") ) return (((argc<2)? ANSWER_DATE_F: MIS_ARG_COUNT));
93: if( !strcmp(func,"to_string") ) return (((argc==1 || argc==2)? TO_STRING_F: MIS_ARG_COUNT));
94: if( !strcmp(func,"sub_string") ) return (((argc==2 || argc==3)? SUB_STRING_F: MIS_ARG_COUNT));
95: if( !strcmp(func,"strlen") ) return (((argc==1)? STRLEN_F: MIS_ARG_COUNT));
96: if( !strcmp(func,"get_seed") ) return (((argc==0)? GET_SEED_F: MIS_ARG_COUNT));
97: if( !strcmp(func,"set_seed") ) return (((argc==1)? SET_SEED_F: MIS_ARG_COUNT));
1.5 albertel 98: if( !strcmp(func,"init_array") ) return (((argc==1)? INIT_ARRAY_F: MIS_ARG_COUNT));
1.1 albertel 99: if( !strcmp(func,"array_index") ) return (((argc==1)? ARRAY_INDEX_F: MIS_ARG_COUNT));
100: if( !strcmp(func,"array_sorted_index") ) return (((argc==2)? ARRAY_SORTED_INDEX_F: MIS_ARG_COUNT));
101: if( !strcmp(func,"array_max") ) return (((argc==1)? ARRAY_MAX_F: MIS_ARG_COUNT));
102: if( !strcmp(func,"array_min") ) return (((argc==1)? ARRAY_MIN_F: MIS_ARG_COUNT));
103: if( !strcmp(func,"array_moments") ) return (((argc==2)? ARRAY_MOMENTS_F: MIS_ARG_COUNT));
104: if( !strcmp(func,"array_var") ) return (((argc==1)? ARRAY_VARIANCE_F: MIS_ARG_COUNT));
105: if( !strcmp(func,"array_std_dev") ) return (((argc==1)? ARRAY_STD_DEV_F: MIS_ARG_COUNT));
106: if( !strcmp(func,"array_skewness") ) return (((argc==1)? ARRAY_SKEWNESS_F: MIS_ARG_COUNT));
107: if( !strcmp(func,"to_int") ) return (((argc==1)? TO_INT_F: MIS_ARG_COUNT));
108: if( !strcmp(func,"format") ) return (FORMAT_F);
109: if( !strcmp(func,"pick") ) return (((argc> 1)? PICK_F: MIS_ARG_COUNT));
110: if( !strcmp(func,"sin") ) return (((argc==1)? SIN_F: MIS_ARG_COUNT));
111: if( !strcmp(func,"cos") ) return (((argc==1)? COS_F: MIS_ARG_COUNT));
112: if( !strcmp(func,"tan") ) return (((argc==1)? TAN_F: MIS_ARG_COUNT));
113: if( !strcmp(func,"asin") ) return (((argc==1)? ASIN_F: MIS_ARG_COUNT));
114: if( !strcmp(func,"acos") ) return (((argc==1)? ACOS_F: MIS_ARG_COUNT));
115: if( !strcmp(func,"atan") ) return (((argc==1)? ATAN_F: MIS_ARG_COUNT));
116: if( !strcmp(func,"sinh") ) return (((argc==1)? SINH_F: MIS_ARG_COUNT));
117: if( !strcmp(func,"cosh") ) return (((argc==1)? COSH_F: MIS_ARG_COUNT));
118: if( !strcmp(func,"tanh") ) return (((argc==1)? TANH_F: MIS_ARG_COUNT));
119: if( !strcmp(func,"asinh") ) return (((argc==1)? ASINH_F: MIS_ARG_COUNT));
120: if( !strcmp(func,"acosh") ) return (((argc==1)? ACOSH_F: MIS_ARG_COUNT));
121: if( !strcmp(func,"atanh") ) return (((argc==1)? ATANH_F: MIS_ARG_COUNT));
122: if( !strcmp(func,"atan2") ) return (((argc==2)? ATANTWO_F: MIS_ARG_COUNT));
123: if( !strcmp(func,"j0") ) return (((argc==1)? J_ZERO_F: MIS_ARG_COUNT));
124: if( !strcmp(func,"j1") ) return (((argc==1)? J_ONE_F: MIS_ARG_COUNT));
125: if( !strcmp(func,"jn") ) return (((argc==2)? J_N_F: MIS_ARG_COUNT));
126: if( !strcmp(func,"y0") ) return (((argc==1)? Y_ZERO_F: MIS_ARG_COUNT));
127: if( !strcmp(func,"y1") ) return (((argc==1)? Y_ONE_F: MIS_ARG_COUNT));
128: if( !strcmp(func,"yn") ) return (((argc==2)? Y_N_F: MIS_ARG_COUNT));
129: if( !strcmp(func,"log") ) return (((argc==1)? LOG_F: MIS_ARG_COUNT));
130: if( !strcmp(func,"log10") ) return (((argc==1)? LOG_TEN_F: MIS_ARG_COUNT));
131: if( !strcmp(func,"exp") ) return (((argc==1)? EXP_F: MIS_ARG_COUNT));
132: if( !strcmp(func,"pow") ) return (((argc==2)? POW_F: MIS_ARG_COUNT));
133: if( !strcmp(func,"erf") ) return (((argc==1)? ERF_F: MIS_ARG_COUNT));
134: if( !strcmp(func,"erfc") ) return (((argc==1)? ERFC_F: MIS_ARG_COUNT));
135: if( !strcmp(func,"sqrt") ) return (((argc==1)? SQRT_F: MIS_ARG_COUNT));
136: if( !strcmp(func,"min") ) return (MIN_F);
137: if( !strcmp(func,"max") ) return (MAX_F);
138: if( !strcmp(func,"abs") ) return (((argc==1)? ABS_F: MIS_ARG_COUNT));
139: if( !strcmp(func,"floor") ) return (((argc==1)? FLOOR_F: MIS_ARG_COUNT));
140: if( !strcmp(func,"ceil") ) return (((argc==1)? CEIL_F: MIS_ARG_COUNT));
141: if( !strcmp(func,"sgn") ) return (((argc==1)? SGN_F: MIS_ARG_COUNT));
142: if( !strcmp(func,"mod") ) return (((argc==2)? MOD_F: MIS_ARG_COUNT));
143: if( !strcmp(func,"remainder") ) return (((argc==2)? REMAINDER_F: MIS_ARG_COUNT));
144: if( !strcmp(func,"factorial") ) return (((argc==1)? FACTORIAL_F: MIS_ARG_COUNT));
145: if( !strcmp(func,"roundto") ) return (((argc==2)? ROUNDTO_F: MIS_ARG_COUNT));
146: if( !strcmp(func,"eval_formula") ) return (((argc==3)? EVALUATE_F: MIS_ARG_COUNT));
147: if( !strcmp(func,"capa_id_plus") ) return (((argc==1 || argc==2)? CAPAID_PLUS: MIS_ARG_COUNT));
148: if( !strcmp(func,"seat_number") ) return (((argc <2)? SEAT_NUMBER: MIS_ARG_COUNT));
149: if( !strcmp(func,"duration") ) return (((argc==0)? DURATION: MIS_ARG_COUNT));
150: if( !strcmp(func,"is_open") ) return (((argc <2)? IS_OPEN_F: MIS_ARG_COUNT));
151: if( !strcmp(func,"is_due") ) return (((argc <2)? IS_DUE_F: MIS_ARG_COUNT));
152: if( !strcmp(func,"is_answer") ) return (((argc <2)? IS_ANSWER_F: MIS_ARG_COUNT));
1.3 albertel 153: if( !strcmp(func,"correct") ) return (((argc <3)? CORRECT_F: MIS_ARG_COUNT));
154: if( !strcmp(func,"grade") ) return (((argc <3)? GRADE_F: MIS_ARG_COUNT));
155: if( !strcmp(func,"tries") ) return (((argc <3)? TRIES_F: MIS_ARG_COUNT));
156: if( !strcmp(func,"managermode")) return (((argc==0)? MANAGERMODE_F:MIS_ARG_COUNT));
1.1 albertel 157: return (UNKNOWN_F);
158: }
159:
160: /**********************************************************/
161:
162:
163: #ifdef SGN
164: #undef SGN
165: #endif
166: #define SGN(xx) ( (xx) > 0 ? 1 : ( (xx) == 0 ? 0 : -1) )
167:
168:
169: #define MAX_DOUBLE 1.7976931348623157E+308
170: #define MIN_DOUBLE 2.2250738585072014E-308
171:
172: #define INT_DIV 0
173: #define REAL_DIV 1
174: #define INT_LOWER 0
175: #define REAL_LOWER 2
176: #define INT_UPPER 0
177: #define REAL_UPPER 4
178:
179: #define ALL_INTEGER 0
180:
181: int which_set(argc,argp,resultp)
182: int argc;
183: ArgNode_t *argp;
184: Symbol *resultp;
185: {
186: char aline[MAX_BUFFER_SIZE], tmpS[MAX_BUFFER_SIZE];
187: int result=Parse_set;
188: if( argc == 1 ) {
189: if( (FIRST_ARGTYPE(argp) == S_VAR ) ||
190: (FIRST_ARGTYPE(argp) == S_CONSTANT ) ) {
191: sprintf(aline,"<<ARG TYPE MISMATCH>>");
192: resultp->s_type = S_CONSTANT;
193: resultp->s_str = strsave(aline);
194: sprintf(tmpS, "function %s() cannot accept string as argument.\n",
195: FuncStack[Func_idx].s_name);
196: capa_msg(MESSAGE_ERROR,tmpS);
197: result=-1;
198: } else {
199: if( (FIRST_ARGTYPE(argp) == I_VAR ) ||
200: (FIRST_ARGTYPE(argp) == I_CONSTANT ) ) {
201: result = FIRST_ARGINT(argp);
202: } else {
203: result = FIRST_ARGREAL(argp);
204: }
205: }
206: }
207: return result;
208: }
209:
210: Symbol *
211: do_function(func,argc,argp)
212: int func;
213: int argc;
214: ArgNode_t *argp;
215: {
216: Symbol *resultp;
217: ArgNode_t *tmpArgp;
218: char aline[MAX_BUFFER_SIZE], tmpS[MAX_BUFFER_SIZE], fmt_str[FORMAT_STRING_LENG];
219: char num_str[SMALL_LINE_BUFFER],date_str[SMALL_LINE_BUFFER];
220: double tmpA=0.0, tmpB=0.0;
221: int slots, noError, errCode, mo, yy, dd, hh, mm, tmpInt;
222: long rout;
223: char *wday[9] = {"Sat,", "Sun,", "Mon,", "Tue,", "Wed,", "Thr,", "Fri,", "Sat,", "\0"};
1.2 albertel 224: char *month[14] = { "UNKNOWN", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
225: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "\0"};
1.1 albertel 226:
227: resultp = (Symbol *)capa_malloc(1,sizeof(Symbol));
228:
229: switch(func) {
230: case RANDOM_F: { int type_flag=0;
231: double r_lower=0.0, r_upper=1.0, r_division=1.0;
232:
233: errCode = 0; rout = ignlgi();
234: switch( FIRST_ARGTYPE(argp) ) {
235: case I_VAR: case I_CONSTANT: break;
236: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 1); break;
237: case S_VAR: case S_CONSTANT: errCode = 1; break;
238: }
239: switch( SECOND_ARGTYPE(argp) ) {
240: case I_VAR: case I_CONSTANT: break;
241: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 2); break;
242: case S_VAR: case S_CONSTANT: errCode = 2; break;
243: }
244: if( argc == 3 ) {
245: switch( THIRD_ARGTYPE(argp) ) {
246: case I_VAR: case I_CONSTANT: break;
247: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 4); break;
248: case S_VAR: case S_CONSTANT: errCode = 4; break;
249: }
250: }
251: if( errCode == 0 ) {
252: if( argc == 3 ) {
253: switch(type_flag) {
254: case 0: r_division = (double)FIRST_ARGINT(argp);
255: r_upper = (double)SECOND_ARGINT(argp);
256: r_lower = (double)THIRD_ARGINT(argp); break;
257: case 2: r_division = (double)FIRST_ARGINT(argp);
258: r_upper = SECOND_ARGREAL(argp);
259: r_lower = (double)THIRD_ARGINT(argp); break;
260: case 4: r_division = (double)FIRST_ARGINT(argp);
261: r_upper = (double)SECOND_ARGINT(argp);
262: r_lower = THIRD_ARGREAL(argp); break;
263: case 6: r_division = (double)FIRST_ARGINT(argp);
264: r_upper = SECOND_ARGREAL(argp);
265: r_lower = THIRD_ARGREAL(argp); break;
266: case 1: r_division = FIRST_ARGREAL(argp);
267: r_upper = (double)SECOND_ARGINT(argp);
268: r_lower = (double)THIRD_ARGINT(argp); break;
269: case 3: r_division = FIRST_ARGREAL(argp);
270: r_upper = SECOND_ARGREAL(argp);
271: r_lower = (double)THIRD_ARGINT(argp); break;
272: case 5: r_division = FIRST_ARGREAL(argp);
273: r_upper = (double)SECOND_ARGINT(argp);
274: r_lower = THIRD_ARGREAL(argp); break;
275: case 7: r_division = FIRST_ARGREAL(argp);
276: r_upper = SECOND_ARGREAL(argp);
277: r_lower = THIRD_ARGREAL(argp); break;
278: }
279: } else { /* two args */
280: switch(type_flag) {
281: case 0: r_upper = (double)FIRST_ARGINT(argp);
282: r_lower = (double)SECOND_ARGINT(argp); break;
283: case 1: r_upper = FIRST_ARGREAL(argp);
284: r_lower = (double)SECOND_ARGINT(argp); break;
285: case 2: r_upper = (double)FIRST_ARGINT(argp);
286: r_lower = SECOND_ARGREAL(argp); break;
287: case 3: r_upper = FIRST_ARGREAL(argp);
288: r_lower = SECOND_ARGREAL(argp); break;
289: }
290: r_division = 1.0;
291: }
292: if( r_upper >= r_lower ) {
293: slots = 1 + (int)floor( (r_upper - r_lower)/r_division );
294: if( type_flag == 0 ) {
295: resultp->s_type = I_CONSTANT;
296: resultp->s_int = (int)r_lower + ((int)r_division)*(rout % slots );
297: } else {
298: resultp->s_type = R_CONSTANT;
299: resultp->s_real = r_lower + r_division*(double)(rout % slots );
300: }
301: } else {
302: resultp->s_type = S_CONSTANT;
303: resultp->s_str = strsave("<<2ND ARG MUST .GE. 1ST ARG>>");
304: sprintf(tmpS,"random()'s second arg. must be greater than the first arg.\n");
305: capa_msg(MESSAGE_ERROR,tmpS);
306: }
307: } else {
308: resultp->s_type = S_CONSTANT;
309: resultp->s_str = strsave("<<ARG CANNOT BE STRING>>");
310: sprintf(tmpS,"random() cannot accept string as argument.\n");
311: capa_msg(MESSAGE_ERROR,tmpS);
312: }
313: } break;
1.5 albertel 314:
1.1 albertel 315: case CHOOSE_F: { int ii, pick=1;
316: ArgNode_t *tmpArgp;
317:
318: noError = 1;
319: tmpArgp = argp; ii=0;
320: while( ii < argc-1 ) {tmpArgp = tmpArgp->a_next; ii++; }
321: switch( FIRST_ARGTYPE(tmpArgp) ) {
322: case IDENTIFIER:
323: sprintf(tmpS,"The first argument to choose(): \"%s\" has not been defined yet. I will choose the first element.\n",FIRST_ARGNAME(tmpArgp));
324: capa_msg(MESSAGE_ERROR,tmpS);
325: pick = 1;
326: break;
327: case I_VAR: case I_CONSTANT:
328: pick = FIRST_ARGINT(tmpArgp); break;
329: case R_VAR: case R_CONSTANT:
330: pick = (int)FIRST_ARGREAL(tmpArgp);
331: sprintf(tmpS,"The first argument to choose() is a real number: \"%.15g\", it must be an integer, I will use %d instead.\n",FIRST_ARGREAL(tmpArgp),pick);
332: capa_msg(MESSAGE_ERROR,tmpS);
333: break;
334: case S_VAR: case S_CONSTANT:
335: resultp->s_type = S_CONSTANT;
336: resultp->s_str = strsave("CHOOSE: first argument must be an integer");
337: sprintf(tmpS,"The first argument to choose() cannot be a string, I will choose the first element.\n");
338: capa_msg(MESSAGE_ERROR,tmpS);
339: pick = 1;
340: break;
341: }
342: if( noError ) {
343: if( (pick <= 0) || (pick > argc-1) ) {
344: sprintf(tmpS,"The first argument to choose() is out of bounds, tt is %d, but should be in the range [1,%d].\n", pick, argc-1);
345: capa_msg(MESSAGE_ERROR,tmpS);
346: pick = argc-1;
347: } else { pick = argc - pick; }
348: for(ii=1,tmpArgp = argp;(ii < pick)&&(ii < argc-1);ii++) { tmpArgp = tmpArgp->a_next; }
349:
350: resultp->s_type = (tmpArgp->a_sp)->s_type;
351: switch((tmpArgp->a_sp)->s_type) {
352: case IDENTIFIER:
353: sprintf(tmpS,"The variable \"%s\" selected by choose() has not yet been defined.\n",(tmpArgp->a_sp)->s_name);
354: capa_msg(MESSAGE_ERROR,tmpS);
355: resultp->s_type = S_CONSTANT;
356: resultp->s_str = strsave(tmpS);
357: break;
358: case I_VAR: case I_CONSTANT:
359: resultp->s_type = I_CONSTANT;
360: resultp->s_int = (tmpArgp->a_sp)->s_int; break;
361: case R_VAR: case R_CONSTANT:
362: resultp->s_type = R_CONSTANT;
363: resultp->s_real = (tmpArgp->a_sp)->s_real; break;
364: case S_VAR: case S_CONSTANT:
365: resultp->s_type = S_CONSTANT;
366: resultp->s_str = strsave((tmpArgp->a_sp)->s_str); break; /********* */
367: }
368:
369: }
370:
371: } break;
372: case PIN_F: {
373: if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
374: resultp->s_type = I_CONSTANT;
375: resultp->s_int=capa_PIN(Parse_student_number,tmpInt,0);
376: }
377: break;
378: case CLASS_F: {
379: resultp->s_type = S_CONSTANT;
380: if(strlen(Parse_class) != 0 ) {
381: resultp->s_str=strsave(Parse_class);
382: } else {
383: resultp->s_str=strsave("UNKNOWN");
384: }
385: }
386: break;
387: case SECTION_F:{ resultp->s_type = I_CONSTANT;
388: resultp->s_int = Parse_section;
389: } break;
390: case PROBLEM_F:{ resultp->s_type = I_CONSTANT;
391: resultp->s_int= Lexi_qnum+1;
392: } break;
393: case SET_F: { resultp->s_type = I_CONSTANT;
394: resultp->s_int=Parse_set;
395: } break;
396: case NAME_F: {
397: resultp->s_type = S_CONSTANT;
398: resultp->s_str=strsave(Parse_name);
399: } break;
400: case SNUMBER_F: {
401: resultp->s_type = S_CONSTANT;
402: resultp->s_str=strsave(Parse_student_number);
403: } break;
404: case IS_DUE_F:
405: case IS_ANSWER_F:
406: case IS_OPEN_F: {
407: int whichDate=CHECK_OPEN_DATE;
408: if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
409: resultp->s_type = I_CONSTANT;
410: switch(func) {
411: case IS_OPEN_F: whichDate=CHECK_OPEN_DATE;break;
412: case IS_DUE_F: whichDate=CHECK_DUE_DATE;break;
413: case IS_ANSWER_F: whichDate=CHECK_ANS_DATE;break;
414: }
415: if( capa_check_date(whichDate,Parse_student_number,
416: Parse_section,tmpInt) < 0 ) {
417: resultp->s_int = 0;
418: } else {
419: resultp->s_int = 1;
420: }
421: } break;
422: case DUE_DATE_F:
423: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
424: resultp->s_type = S_CONSTANT;
425: if(capa_get_date(CHECK_DUE_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
426: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mo, &dd, &hh, &mm);
427: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
428: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
429: resultp->s_str= strsave(aline);
430: } else {
431: resultp->s_str= strsave("UNKNOWN");
432: }
433: } break;
434: case DUE_DAY_F:
435: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
436: resultp->s_type = S_CONSTANT;
437: if(capa_get_date(CHECK_DUE_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
438: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mm, &dd, &hh, &mm);
439: sprintf(aline, "%s %s %2d, %4d",
440: wday[weekday(yy,mo,dd)], month[mo], dd, yy);
441: resultp->s_str= strsave(aline);
442: } else {
443: resultp->s_str= strsave("UNKNOWN");
444: }
445: } break;
446: case OPEN_DATE_F:
447: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
448: resultp->s_type = S_CONSTANT;
449: if(capa_get_date(CHECK_OPEN_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
450: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mm, &dd, &hh, &mm);
451: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
452: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
453: resultp->s_str= strsave(aline);
454: } else {
455: resultp->s_str= strsave("UNKNOWN");
456: }
457: } break;
458: case ANSWER_DATE_F:
459: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
460: resultp->s_type = S_CONSTANT;
461: if(capa_get_date(CHECK_ANS_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
462: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mo, &dd, &hh, &mm);
463: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
464: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
465: resultp->s_str= strsave(aline);
466: } else {
467: resultp->s_str= strsave("UNKNOWN");
468: }
469: } break;
470: case STRLEN_F: {
471: resultp->s_type = I_CONSTANT;
472: switch( FIRST_ARGTYPE(argp) ) {
473: case I_VAR:
474: case I_CONSTANT:
475: resultp->s_type = S_CONSTANT;
476: sprintf(tmpS,"strlen() only accepts string variable, not integer.\n");
477: capa_msg(MESSAGE_ERROR,tmpS);
478: resultp->s_str=strsave(tmpS);
479: break;
480: case R_VAR:
481: case R_CONSTANT:
482: resultp->s_type = S_CONSTANT;
483: sprintf(tmpS,"strlen() only accepts string variable, not float number.\n");
484: capa_msg(MESSAGE_ERROR,tmpS);
485: resultp->s_str=strsave(tmpS);
486: break;
487: case S_VAR:
488: case S_CONSTANT:
489: resultp->s_int = strlen( FIRST_ARGSTR(argp) );
490: break;
491: case IDENTIFIER:
492: sprintf(tmpS,"Unknown variable, %s, argument to function strlen()\n",argp->a_sp->s_name);
493: capa_msg(MESSAGE_ERROR,tmpS);
494: resultp->s_str=strsave(tmpS);
495: break;
496: }
497: } break;
498: case TO_STRING_F:
499: { char aline[MAX_BUFFER_SIZE],rline[MAX_BUFFER_SIZE];
500:
501: resultp->s_type = S_CONSTANT;
502:
503: if( argc == 1 ) {
504: switch( FIRST_ARGTYPE(argp) ) {
505: case I_VAR:
506: case I_CONSTANT:
507: sprintf(aline,"%ld",FIRST_ARGINT(argp));
508: resultp->s_str = strsave(aline); break;
509: case R_VAR:
510: case R_CONSTANT:
511: sprintf(aline,"%.15g",FIRST_ARGREAL(argp));
512: resultp->s_str = strsave(aline); break;
513: case S_VAR:
514: case S_CONSTANT:
515: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
516: case IDENTIFIER:
517: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_sp->s_name);
518: capa_msg(MESSAGE_ERROR,tmpS);
519: resultp->s_str=strsave(tmpS);
520: break;
521: }
522: } else {
523: switch( FIRST_ARGTYPE(argp) ) {
524: case I_VAR:
525: case I_CONSTANT:
526: case R_VAR:
527: case R_CONSTANT:
528: sprintf(tmpS,
529: "to_string()'s second arg. must be a string.\n");
530: capa_msg(MESSAGE_ERROR,tmpS);
531: sprintf(aline,"%%.15g");
532: break;
533: case S_VAR:
534: case S_CONSTANT:
535: sprintf(aline,"%%%s",FIRST_ARGSTR(argp));
536: break;
537: case IDENTIFIER:
538: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_next->a_sp->s_name);
539: capa_msg(MESSAGE_ERROR,tmpS);
540: resultp->s_str=strsave(tmpS);
541: break;
542:
543: }
544: switch( SECOND_ARGTYPE(argp) ) {
545: case I_VAR:
546: case I_CONSTANT:
547: sprintf(aline,"%ld",SECOND_ARGINT(argp));
548: resultp->s_str = strsave(aline); break;
549: case R_VAR:
550: case R_CONSTANT:
551: sprintf(rline,aline,SECOND_ARGREAL(argp));
552: resultp->s_str = strsave(rline); break;
553: case S_VAR:
554: case S_CONSTANT:
555: resultp->s_str = strsave(SECOND_ARGSTR(argp));
556: break;
557: case IDENTIFIER:
558: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_sp->s_name);
559: capa_msg(MESSAGE_ERROR,tmpS);
560: resultp->s_str=strsave(tmpS);
561: break;
562: }
563: }
564: } break;
565: case SUB_STRING_F: /* sub_string(str, 2), 1 is the first char */
566: /* sub_string(str, 3, 5) means start from the third char and take 5 chars */
567: { int idx=1, leng, rleng=0,ii;
568: char *a_str, *b_str;
569:
570: resultp->s_type = S_CONSTANT;
571: if( argc == 2 ) { /* two arguments format */
572: switch( FIRST_ARGTYPE(argp) ) {
573: case IDENTIFIER:
574: sprintf(tmpS,
575: "sub_string()'s second arg. must be an integer.\n");
576: capa_msg(MESSAGE_ERROR,tmpS);
577: break;
578: case I_VAR:
579: case I_CONSTANT:
580: idx = FIRST_ARGINT(argp);
581: break;
582: case R_VAR:
583: case R_CONSTANT:
584: idx = (int) FIRST_ARGREAL(argp);
585: break;
586: case S_VAR:
587: case S_CONSTANT:
588: sprintf(tmpS,
589: "sub_string()'s second arg. must be an integer.\n");
590: capa_msg(MESSAGE_ERROR,tmpS);
591: break;
592: }
593: switch( SECOND_ARGTYPE(argp) ) {
594: case IDENTIFIER:
595: sprintf(tmpS,
596: "sub_string()'s first arg. is not defined before use.\n");
597: capa_msg(MESSAGE_ERROR,tmpS);
598: break;
599: case I_VAR:
600: case I_CONSTANT:
601: sprintf(tmpS,
602: "sub_string()'s first arg. cannot be an integer.\n");
603: capa_msg(MESSAGE_ERROR,tmpS);
604: break;
605: case R_VAR:
606: case R_CONSTANT:
607: sprintf(tmpS,
608: "sub_string()'s first arg. cannot be a number.\n");
609: capa_msg(MESSAGE_ERROR,tmpS);
610: break;
611: case S_VAR:
612: case S_CONSTANT:
613: a_str = SECOND_ARGSTR(argp);
614: leng = strlen(a_str);
615: if( (idx<1) || (idx > leng) ) {
616: sprintf(tmpS, "sub_string()'s second arg. is out of range.\n");
617: capa_msg(MESSAGE_ERROR,tmpS);
618: idx = 1;
619: }
620: b_str = (char *)&a_str[idx-1];
621: resultp->s_str = strsave(b_str);
622:
623: if( SECOND_ARGTYPE(argp) == S_CONSTANT) {
624: /* freed in free arg_list */
625: /* capa_mfree((char *)SECOND_ARGSTR(argp)); */
626: }
627: break;
628: }
629: } else { /* three arguments format sub_string(string, start, length) */
630: switch( FIRST_ARGTYPE(argp) ) {
631: case IDENTIFIER:
632: sprintf(tmpS,
633: "sub_string()'s third arg. must be an integer.\n");
634: capa_msg(MESSAGE_ERROR,tmpS);
635: break;
636: case I_VAR:
637: case I_CONSTANT:
638: rleng = FIRST_ARGINT(argp);
639: break;
640: case R_VAR:
641: case R_CONSTANT:
642: rleng = (int) FIRST_ARGREAL(argp);
643: break;
644: case S_VAR:
645: case S_CONSTANT:
646: sprintf(tmpS,
647: "sub_string()'s third arg. must be an integer.\n");
648: capa_msg(MESSAGE_ERROR,tmpS);
649: break;
650: }
651: switch( SECOND_ARGTYPE(argp) ) {
652: case IDENTIFIER:
653: sprintf(tmpS,
654: "sub_string()'s second arg. must be an integer.\n");
655: capa_msg(MESSAGE_ERROR,tmpS);
656: break;
657: case I_VAR:
658: case I_CONSTANT:
659: idx = SECOND_ARGINT(argp);
660: break;
661: case R_VAR:
662: case R_CONSTANT:
663: idx = (int) SECOND_ARGREAL(argp);
664: break;
665: case S_VAR:
666: case S_CONSTANT:
667: sprintf(tmpS,
668: "sub_string()'s second arg. must be an integer.\n");
669: capa_msg(MESSAGE_ERROR,tmpS);
670: break;
671: }
672: switch( THIRD_ARGTYPE(argp) ) {
673: case IDENTIFIER:
674: sprintf(tmpS,
675: "sub_string()'s first arg. is not defined before use.\n");
676: capa_msg(MESSAGE_ERROR,tmpS);
677: break;
678: case I_VAR:
679: case I_CONSTANT:
680: sprintf(tmpS,
681: "sub_string()'s first arg. cannot be an integer.\n");
682: capa_msg(MESSAGE_ERROR,tmpS);
683: break;
684: case R_VAR:
685: case R_CONSTANT:
686: sprintf(tmpS,
687: "sub_string()'s first arg. cannot be a number.\n");
688: capa_msg(MESSAGE_ERROR,tmpS);
689: break;
690: case S_VAR:
691: case S_CONSTANT:
692: a_str = THIRD_ARGSTR(argp);
693: leng = strlen(a_str);
694: if( (idx < 1) || (idx > leng) ) {
695: sprintf(tmpS, "sub_string()'s second arg. is out of range.\n");
696: capa_msg(MESSAGE_ERROR,tmpS);
697: idx = 1;
698: }
699: if( (rleng<1) || ((rleng+idx-1) > leng)) {
700:
701: rleng = leng - idx + 1;
702: }
703: b_str = (char *)capa_malloc((rleng+1)*sizeof(char),1);
704: for(ii=idx-1;ii<(rleng+idx-1);ii++) {
705: b_str[ii-idx+1] = a_str[ii];
706: }
707: resultp->s_str = strsave(b_str);
708: capa_mfree(b_str);
709:
710: if( THIRD_ARGTYPE(argp) == S_CONSTANT) {
711: /* handled in free_arglist() */
712: /* capa_mfree((char *)THIRD_ARGSTR(argp)); */
713: }
714: break;
715: }
716: }
717: } break;
718: case PICK_F: { int ii, pick=1;
719: ArgNode_t *tmpArgp;
720:
721: noError = 1;
722: rout = ignlgi();
723: tmpArgp = argp; ii=0;
724: while( ii < argc-1 ) {tmpArgp = tmpArgp->a_next; ii++; }
725: switch( FIRST_ARGTYPE(tmpArgp) ) {
726: case I_VAR:
727: case I_CONSTANT:
728: pick = FIRST_ARGINT(tmpArgp);
729: if( (pick <= 0 ) || (pick > argc-1) ) {
730: noError = 0;
731: resultp->s_type = S_CONSTANT;
732: resultp->s_str = strsave("PICK: first arg out of bound.");
733: }
734: break;
735: case R_VAR:
736: case R_CONSTANT:
737: pick = (int)FIRST_ARGREAL(tmpArgp);
738: if( (pick <= 0 ) || (pick > argc-1) ) {
739: noError = 0;
740: resultp->s_type = S_CONSTANT;
741: resultp->s_str = strsave("PICK: first arg out of bound.");
742: }
743: break;
744: case S_VAR:
745: case S_CONSTANT: noError = 0;
746: resultp->s_type = S_CONSTANT;
747: resultp->s_str = strsave("PICK: first arg must be int");
748: break;
749: }
750: if( noError ) {
751: for( ii=0; ii< pick; ii++) {
752: }
753: }
754: }
755: break;
756: case GET_SEED_F:
757: { long seed1, seed2;
758: char *tmp;
759:
760: getsd(&seed1,&seed2);
761: tmp = (char *)capa_malloc(32,1);
762: sprintf(tmp,"%ld,%ld",seed1,seed2);
763: resultp->s_type = S_CONSTANT;
764: resultp->s_str = strsave(tmp);
765: capa_mfree(tmp);
766: } break;
767: case SET_SEED_F:
768: { long seed1, seed2;
769: int leng;
770:
771: switch( FIRST_ARGTYPE(argp) ) {
772: case I_VAR: case I_CONSTANT: break;
773: case R_VAR: case R_CONSTANT: break;
774: case S_VAR: case S_CONSTANT:
775: leng = strlen(FIRST_ARGSTR(argp));
776: if( (index(FIRST_ARGSTR(argp), ' ') != NULL) ) {
777: sscanf(FIRST_ARGSTR(argp),"%ld,%ld", &seed1, &seed2);
778: setall(seed1,seed2);
779: }
780:
781: break;
782: }
783: resultp->s_type = I_CONSTANT;
784: resultp->s_int = 0;
785: } break;
1.5 albertel 786: /* generate random numbers according to a pre-defined distributions and a seed */
1.10 ! albertel 787: case RANDOM_MULTIVARIATE_NORMAL_F:
! 788: /* random_multivariate_normal(return_array,item_cnt,seed,dimen,mean_vector,covariance_vector) */
! 789: /* the dimension of both mean_vector and covariance_vector should be the same as item_cnt */
! 790: /* It will return item_cnt numbers in standard normal deviate in return_array */
! 791: /* */
! 792: { char *mean_vec_str, *cov_vec_str, *seed_str, *out_vec_str;
! 793: int dimen, item_cnt, tmp_int;
! 794: long tmp_long;
! 795: Symbol *r_p;
! 796:
! 797: errCode = 0;
! 798: switch( FIRST_ARGTYPE(argp) ) { /* parameter one covariance_matrix of size dimen*dimen */
! 799: case I_VAR: case I_CONSTANT:
! 800: case R_VAR: case R_CONSTANT:
! 801: resultp->s_type = S_CONSTANT;
! 802: resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
! 803: sprintf(tmpS,"%s()'s last arg. must be an array name.\n",FuncStack[Func_idx].s_name);
! 804: capa_msg(MESSAGE_ERROR,tmpS);
! 805: errCode = 1;
! 806: break;
! 807: case S_VAR: case S_CONSTANT:
! 808: cov_vec_str = strsave( FIRST_ARGSTR(argp) );
! 809: break;
! 810: case IDENTIFIER:
! 811: cov_vec_str = strsave( FIRST_ARGNAME(argp) );
! 812: /*
! 813: resultp->s_type = S_CONSTANT;
! 814: resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE AN ARRAY WITH DATA>>");
! 815: sprintf(tmpS,"%s()'s last arg. must be an array with data (covariance array).\n",FuncStack[Func_idx].s_name);
! 816: capa_msg(MESSAGE_ERROR,tmpS);
! 817: errCode = 1;
! 818: */
! 819: break;
! 820: }
! 821: if(errCode == 0) {
! 822: switch( SECOND_ARGTYPE(argp) ) { /* parameter two mean_vector */
! 823: case I_VAR: case I_CONSTANT:
! 824: case R_VAR: case R_CONSTANT:
! 825: resultp->s_type = S_CONSTANT;
! 826: resultp->s_str = strsave("<<THE FIFTH ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
! 827: sprintf(tmpS,"%s()'s fifth arg. must be an array name.\n",FuncStack[Func_idx].s_name);
! 828: capa_msg(MESSAGE_ERROR,tmpS);
! 829: errCode = 1;
! 830: break;
! 831: case S_VAR: case S_CONSTANT:
! 832: mean_vec_str = SECOND_ARGSTR(argp);
! 833: break;
! 834: case IDENTIFIER:
! 835: mean_vec_str = SECOND_ARGNAME(argp);
! 836: /*
! 837: resultp->s_type = S_CONSTANT;
! 838: resultp->s_str = strsave("<<THE FIFTH ARG. OF THIS FUNCTION MUST BE AN ARRAY WITH DATA>>");
! 839: sprintf(tmpS,"%s()'s fifth arg. must be an array with data (mean array).\n",FuncStack[Func_idx].s_name);
! 840: capa_msg(MESSAGE_ERROR,tmpS);
! 841: errCode = 1;
! 842: */
! 843: break;
! 844: }
! 845: if(errCode == 0 ) {
! 846: switch( THIRD_ARGTYPE(argp) ) { /* parameter three dimen */
! 847: case I_VAR: case I_CONSTANT:
! 848: dimen = THIRD_ARGINT(argp);
! 849: break;
! 850: case R_VAR: case R_CONSTANT:
! 851: dimen = (int)THIRD_ARGREAL(argp);
! 852: break;
! 853: case S_VAR: case S_CONSTANT:
! 854: case IDENTIFIER:
! 855: resultp->s_type = S_CONSTANT;
! 856: resultp->s_str = strsave("<<THE FOURTH ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
! 857: sprintf(tmpS,"%s()'s fourth arg. must be a number.\n",FuncStack[Func_idx].s_name);
! 858: capa_msg(MESSAGE_ERROR,tmpS);
! 859: errCode = 1;
! 860: break;
! 861: }
! 862: if(errCode == 0 ) { /* parameter four seed */
! 863: switch( FOURTH_ARGTYPE(argp) ) { /* seed */
! 864: case I_VAR: case I_CONSTANT:
! 865: seed_str = (char *)capa_malloc(32,1);
! 866: sprintf(seed_str,"%ld",FOURTH_ARGINT(argp) );
! 867: break;
! 868: case R_VAR: case R_CONSTANT:
! 869: tmp_long = (long)FOURTH_ARGREAL(argp);
! 870: seed_str = (char *)capa_malloc(32,1);
! 871: sprintf(seed_str,"%ld",tmp_long);
! 872: break;
! 873: case S_VAR: case S_CONSTANT:
! 874: seed_str = strsave(FOURTH_ARGSTR(argp));
! 875: break;
! 876: case IDENTIFIER:
! 877: resultp->s_type = S_CONSTANT;
! 878: resultp->s_str = strsave("<<THIRD ARG. OF THIS FUNCTION MUST BE A NUMBER OR STRING>>");
! 879: sprintf(tmpS,"%s()'s third arg. must be a number or a string.\n",FuncStack[Func_idx].s_name);
! 880: capa_msg(MESSAGE_ERROR,tmpS);
! 881: errCode = 1;
! 882: break;
! 883: }
! 884: if(errCode == 0 ) {
! 885: switch( FIFTH_ARGTYPE(argp) ) { /* parameter five item_cnt */
! 886: case I_VAR: case I_CONSTANT:
! 887: item_cnt = FIFTH_ARGINT(argp);
! 888: break;
! 889: case R_VAR: case R_CONSTANT:
! 890: item_cnt = (int)FIFTH_ARGREAL(argp);
! 891: break;
! 892: case S_VAR: case S_CONSTANT:
! 893: case IDENTIFIER:
! 894: resultp->s_type = S_CONSTANT;
! 895: resultp->s_str = strsave("<<SECOND ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
! 896: sprintf(tmpS,"%s()'s second arg. must be a number.\n",FuncStack[Func_idx].s_name);
! 897: capa_msg(MESSAGE_ERROR,tmpS);
! 898: errCode = 1;
! 899: break;
! 900: }
! 901: if(errCode == 0 ) { /* array_name, clear the content of this array first */
! 902: switch( SIXTH_ARGTYPE(argp) ) {
! 903: case I_VAR: case I_CONSTANT:
! 904: case R_VAR: case R_CONSTANT:
! 905: resultp->s_type = S_CONSTANT;
! 906: resultp->s_str = strsave("<<FIRST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
! 907: sprintf(tmpS,"%s()'s first arg. must be a name of an array.\n",FuncStack[Func_idx].s_name);
! 908: capa_msg(MESSAGE_ERROR,tmpS);
! 909: errCode = 1;
! 910: break;
! 911: case S_VAR: case S_CONSTANT:
! 912: tmp_int = free_array(SIXTH_ARGSTR(argp));
! 913:
! 914: out_vec_str= strsave(SIXTH_ARGSTR(argp));
! 915: break;
! 916: case IDENTIFIER:
! 917: tmp_int = free_array(SIXTH_ARGNAME(argp));
! 918:
! 919: out_vec_str= strsave(SIXTH_ARGNAME(argp));
! 920:
! 921: break;
! 922: } /* send switch */
! 923: } /* end if array_name check */
! 924: } /* end if (item_cnt) check */
! 925: } /* end if (seed) check */
! 926: } /* end if (dimen) check */
! 927: } /* end if (mean_vector) check */
! 928: if(errCode == 0 ) { /* all the parameter checks OK */
! 929: r_p = gen_multivariate_normal(out_vec_str,seed_str,item_cnt,dimen,mean_vec_str,cov_vec_str);
! 930: capa_mfree((char *)resultp);
! 931: resultp = r_p;
! 932:
! 933: }
! 934: if( out_vec_str != NULL ) capa_mfree((char *)out_vec_str);
! 935: if( seed_str != NULL ) capa_mfree((char *)seed_str);
! 936: if( mean_vec_str != NULL ) capa_mfree((char *)mean_vec_str);
! 937: if( cov_vec_str != NULL ) capa_mfree((char *)cov_vec_str);
! 938:
! 939: } break;
1.5 albertel 940: case RANDOM_NORMAL_F: /* random_normal(return_array,item_cnt,seed,av,std_dev) */
941: case RANDOM_BETA_F: /* random_beta(return_array,item_cnt,seed,aa,bb) */
942: case RANDOM_GAMMA_F: /* random_gamma(return_array,item_cnt,seed,a,r) */
943: case RANDOM_POISSON_F: /* random_poisson(return_array,item_cnt,seed,mu) */
944: case RANDOM_EXPONENTIAL_F:
945: /* random_exponential(return_array,item_cnt,seed,av) */
946: case RANDOM_CHI_F: /* random_chi(return_array,item_cnt,seed,df) */
947: case RANDOM_NONCENTRAL_CHI_F:
948: /* random_noncentral_chi(return_array,item_cnt,seed,df,xnonc) */
949: /* gen_random_by_selector(output_p,sel,seed,item_cnt,p1,p2) */
950: { int sel, item_cnt, tmp_int;
951: float para1, para2;
952: char *tmp_str;
953: long tmp_long;
954: Symbol *r_p;
955:
956: switch(func) { /* assigns the function selector */
957: case RANDOM_NORMAL_F: sel = NORMAL_DIS; break;
958: case RANDOM_BETA_F: sel = BETA_DIS; break;
959: case RANDOM_GAMMA_F: sel = GAMMA_DIS; break;
960: case RANDOM_POISSON_F: sel = POISSON_DIS; break;
961: case RANDOM_EXPONENTIAL_F: sel = EXPONENTIAL_DIS; break;
962: case RANDOM_CHI_F: sel = CHI_DIS; break;
963: case RANDOM_NONCENTRAL_CHI_F: sel = NONCENTRAL_CHI_DIS; break;
964: }
965: switch(func) {
966: case RANDOM_NORMAL_F:
967: case RANDOM_BETA_F:
968: case RANDOM_GAMMA_F: /* two-parameter functions */
1.6 albertel 969: case RANDOM_NONCENTRAL_CHI_F:
1.5 albertel 970: { errCode = 0;
971: switch( FIRST_ARGTYPE(argp) ) { /* parameter two */
972: case I_VAR: case I_CONSTANT:
973: para2 = (float)FIRST_ARGINT(argp);
974: break;
975: case R_VAR: case R_CONSTANT:
976: para2 = (float)FIRST_ARGREAL(argp);
977: break;
978: case S_VAR: case S_CONSTANT:
979: case IDENTIFIER:
980: resultp->s_type = S_CONSTANT;
981: resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
982: sprintf(tmpS,"%s()'s last arg. must be a number.\n",FuncStack[Func_idx].s_name);
983: capa_msg(MESSAGE_ERROR,tmpS);
984: errCode = 1;
985: break;
986: }
987: if(errCode == 0 ) {
988: switch( SECOND_ARGTYPE(argp) ) { /* parameter one */
989: case I_VAR: case I_CONSTANT:
990: para1 = (float)SECOND_ARGINT(argp);
991: break;
992: case R_VAR: case R_CONSTANT:
993: para1 = (float)SECOND_ARGREAL(argp);
994: break;
995: case S_VAR: case S_CONSTANT:
996: case IDENTIFIER:
997: resultp->s_type = S_CONSTANT;
998: resultp->s_str = strsave("<<FOURTH ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
999: sprintf(tmpS,"%s()'s fourth arg. must be a number.\n",FuncStack[Func_idx].s_name);
1000: capa_msg(MESSAGE_ERROR,tmpS);
1001: errCode = 1;
1002: break;
1003: }
1004: if(errCode == 0 ) {
1005: switch( THIRD_ARGTYPE(argp) ) { /* seed */
1006: case I_VAR: case I_CONSTANT:
1007: tmp_str = (char *)capa_malloc(32,1);
1008: sprintf(tmp_str,"%ld",THIRD_ARGINT(argp) );
1009: break;
1010: case R_VAR: case R_CONSTANT:
1011: tmp_long = (long)THIRD_ARGREAL(argp);
1012: tmp_str = (char *)capa_malloc(32,1);
1013: sprintf(tmp_str,"%ld",tmp_long);
1014: break;
1015: case S_VAR: case S_CONSTANT:
1016: tmp_str = strsave(THIRD_ARGSTR(argp));
1017: break;
1018: case IDENTIFIER:
1019: resultp->s_type = S_CONSTANT;
1020: resultp->s_str = strsave("<<THIRD ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
1021: sprintf(tmpS,"%s()'s third arg. must be a number.\n",FuncStack[Func_idx].s_name);
1022: capa_msg(MESSAGE_ERROR,tmpS);
1023: errCode = 1;
1024: break;
1025: }
1026: if(errCode == 0 ) {
1027: switch( FOURTH_ARGTYPE(argp) ) { /* item_cnt */
1028: case I_VAR: case I_CONSTANT:
1029: item_cnt = FOURTH_ARGINT(argp);
1030: break;
1031: case R_VAR: case R_CONSTANT:
1032: item_cnt = (int)FOURTH_ARGREAL(argp);
1033: break;
1034: case S_VAR: case S_CONSTANT:
1035: case IDENTIFIER:
1036: resultp->s_type = S_CONSTANT;
1037: resultp->s_str = strsave("<<SECOND ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
1038: sprintf(tmpS,"%s()'s second arg. must be a number.\n",FuncStack[Func_idx].s_name);
1039: capa_msg(MESSAGE_ERROR,tmpS);
1040: errCode = 1;
1041: break;
1042: }
1043: if(errCode == 0 ) {
1044: switch( FIFTH_ARGTYPE(argp) ) { /* array_name, clear the content of this array first */
1045: case I_VAR: case I_CONSTANT:
1046: case R_VAR: case R_CONSTANT:
1047: resultp->s_type = S_CONSTANT;
1048: resultp->s_str = strsave("<<FIRST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1049: sprintf(tmpS,"%s()'s first arg. must be a name of an array.\n",FuncStack[Func_idx].s_name);
1050: capa_msg(MESSAGE_ERROR,tmpS);
1051: errCode = 1;
1052: break;
1053: case S_VAR: case S_CONSTANT:
1054: tmp_int = free_array(FIFTH_ARGSTR(argp));
1055: r_p = gen_random_by_selector(FIFTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2);
1056: capa_mfree((char *)resultp);
1057: resultp = r_p;
1058: break;
1059: case IDENTIFIER:
1060: tmp_int = free_array(FIFTH_ARGNAME(argp));
1.6 albertel 1061: r_p = gen_random_by_selector(FIFTH_ARGNAME(argp),sel,tmp_str,item_cnt,para1,para2);
1.5 albertel 1062: capa_mfree((char *)resultp);
1063: resultp = r_p;
1064: break;
1065: }
1066: } /* the fourth argument of this function (item_cnt) */
1067: } /* the third argument of this function (seed) */
1068: } /* the second argument of this function (paramenter one) */
1069: } /* the first argument of this function (parameter two) */
1070:
1071: }
1072: break;
1073: case RANDOM_POISSON_F:
1074: case RANDOM_EXPONENTIAL_F:
1.6 albertel 1075: case RANDOM_CHI_F: /* one parameter functions */
1.5 albertel 1076: { errCode = 0;
1077: switch( FIRST_ARGTYPE(argp) ) { /* parameter one */
1078: case I_VAR: case I_CONSTANT:
1.6 albertel 1079: para1 = (float)FIRST_ARGINT(argp);
1.5 albertel 1080: break;
1081: case R_VAR: case R_CONSTANT:
1.6 albertel 1082: para1 = (float)FIRST_ARGREAL(argp);
1.5 albertel 1083: break;
1084: case S_VAR: case S_CONSTANT:
1085: case IDENTIFIER:
1086: resultp->s_type = S_CONSTANT;
1087: resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
1088: sprintf(tmpS,"%s()'s last arg. must be a number.\n",FuncStack[Func_idx].s_name);
1089: capa_msg(MESSAGE_ERROR,tmpS);
1090: errCode = 1;
1091: break;
1092: }
1093: if(errCode == 0 ) {
1094: switch( SECOND_ARGTYPE(argp) ) { /* seed */
1095: case I_VAR: case I_CONSTANT:
1096: tmp_str = (char *)capa_malloc(32,1);
1097: sprintf(tmp_str,"%ld",SECOND_ARGINT(argp) );
1098: break;
1099: case R_VAR: case R_CONSTANT:
1100: tmp_long = (long)SECOND_ARGREAL(argp);
1101: tmp_str = (char *)capa_malloc(32,1);
1102: sprintf(tmp_str,"%ld",tmp_long);
1103: break;
1104: case S_VAR: case S_CONSTANT:
1105: tmp_str = strsave(SECOND_ARGSTR(argp));
1106: break;
1107: case IDENTIFIER:
1108: resultp->s_type = S_CONSTANT;
1109: resultp->s_str = strsave("<<THIRD ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
1110: sprintf(tmpS,"%s()'s third arg. must be a number.\n",FuncStack[Func_idx].s_name);
1111: capa_msg(MESSAGE_ERROR,tmpS);
1112: errCode = 1;
1113: break;
1114: }
1115: if(errCode == 0 ) {
1116: switch( THIRD_ARGTYPE(argp) ) { /* item_cnt */
1117: case I_VAR: case I_CONSTANT:
1118: item_cnt = THIRD_ARGINT(argp);
1119: break;
1120: case R_VAR: case R_CONSTANT:
1121: item_cnt = (int)THIRD_ARGREAL(argp);
1122: break;
1123: case S_VAR: case S_CONSTANT:
1124: case IDENTIFIER:
1125: resultp->s_type = S_CONSTANT;
1126: resultp->s_str = strsave("<<SECOND ARG. OF THIS FUNCTION MUST BE A NUMBER>>");
1127: sprintf(tmpS,"%s()'s second arg. must be a number.\n",FuncStack[Func_idx].s_name);
1128: capa_msg(MESSAGE_ERROR,tmpS);
1129: errCode = 1;
1130: break;
1131: }
1132: if(errCode == 0 ) {
1133: switch( FOURTH_ARGTYPE(argp) ) { /* array_name, clear the content of this array first */
1134: case I_VAR: case I_CONSTANT:
1135: case R_VAR: case R_CONSTANT:
1136: resultp->s_type = S_CONSTANT;
1137: resultp->s_str = strsave("<<FIRST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1138: sprintf(tmpS,"%s()'s first arg. must be a name of an array.\n",FuncStack[Func_idx].s_name);
1139: capa_msg(MESSAGE_ERROR,tmpS);
1140: errCode = 1;
1141: break;
1142: case S_VAR: case S_CONSTANT:
1143: tmp_int = free_array(FOURTH_ARGSTR(argp));
1144: r_p = gen_random_by_selector(FOURTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2);
1145: capa_mfree((char *)resultp);
1146: resultp = r_p;
1147: break;
1148: case IDENTIFIER:
1149: tmp_int = free_array(FOURTH_ARGNAME(argp));
1.6 albertel 1150: r_p = gen_random_by_selector(FOURTH_ARGNAME(argp),sel,tmp_str,item_cnt,para1,para2);
1.5 albertel 1151: capa_mfree((char *)resultp);
1152: resultp = r_p;
1153: break;
1154: }
1155:
1156: } /* the third argument of this function (seed) */
1157: } /* the second argument of this function (paramenter one) */
1158: } /* the first argument of this function (parameter two) */
1159: }
1160: break;
1161: } /* end second switch */
1162: } break;
1163: case ARRAY_MOMENTS_F: /* */
1.1 albertel 1164: {
1165: char *tmp_input;
1166: Symbol *r_p;
1167:
1168: switch( FIRST_ARGTYPE(argp) ) {
1169: case I_VAR: case I_CONSTANT:
1170: case R_VAR: case R_CONSTANT:
1171: resultp->s_type = S_CONSTANT;
1172: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1173: sprintf(tmpS,"array_moments()'s arg. must be a name of an array.\n");
1174: capa_msg(MESSAGE_ERROR,tmpS);
1175: errCode = 1;
1176: break;
1177: case S_VAR: case S_CONSTANT:
1178: tmp_input = strsave(FIRST_ARGSTR(argp));
1179: errCode = 0;
1180: break;
1181: case IDENTIFIER:
1182: tmp_input = strsave(FIRST_ARGNAME(argp));
1183: errCode = 0;
1184: break;
1185: }
1186: if( errCode == 0 ) {
1187: switch( SECOND_ARGTYPE(argp) ) {
1188: case I_VAR: case I_CONSTANT:
1189: case R_VAR: case R_CONSTANT:
1190: resultp->s_type = S_CONSTANT;
1191: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1192: sprintf(tmpS,"array_moments()'s arg. must be a name of an array.\n");
1193: capa_msg(MESSAGE_ERROR,tmpS);
1194: errCode = 1;
1195: break;
1196: case S_VAR: case S_CONSTANT:
1197: r_p = array_moments(SECOND_ARGSTR(argp),tmp_input);
1198: capa_mfree((char *)tmp_input);
1199: /* fprintf(stdout,"DONE array_moments()\n"); fflush(stdout); */
1200: break;
1201: case IDENTIFIER:
1202: r_p = array_moments(SECOND_ARGNAME(argp),tmp_input);
1203: capa_mfree((char *)tmp_input);
1204:
1205: break;
1206: }
1207: if(errCode == 0 ) {
1208: capa_mfree((char *)resultp);
1209: resultp = r_p;
1210: }
1211: }
1212:
1213: } break;
1214: case ARRAY_SORTED_INDEX_F: /* array_sorted_index(array_name_str, sort_type) */
1215: {
1216: switch( FIRST_ARGTYPE(argp) ) {
1217: case I_VAR: case I_CONSTANT:
1218: switch( FIRST_ARGINT(argp) ) {
1219: case ASCEND_SORT: break;
1220: case DESCEND_SORT: break;
1221: case NUMERICAL_SORT: break;
1222: default: break;
1223: }
1224:
1225: break;
1226: case R_VAR: case R_CONSTANT: break;
1227: case S_VAR: case S_CONSTANT:
1228:
1229:
1230: break;
1231: }
1232: resultp->s_type = S_CONSTANT;
1233: resultp->s_str = strsave("NOT YET");
1234: } break;
1235:
1.4 albertel 1236: case INIT_ARRAY_F:
1237: { int rr;
1238:
1239: switch( FIRST_ARGTYPE(argp) ) {
1240: case I_VAR: case I_CONSTANT:
1241: case R_VAR: case R_CONSTANT:
1242: resultp->s_type = S_CONSTANT;
1243: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1244: sprintf(tmpS,"init_array()'s arg. must be a name of an array.\n");
1245: capa_msg(MESSAGE_ERROR,tmpS);
1246: break;
1247: case S_VAR: case S_CONSTANT: /* allows the use of init_array(array[1]) which array[1]="another" */
1248: rr = free_array(FIRST_ARGSTR(argp));
1249: resultp->s_type = I_CONSTANT;
1250: resultp->s_int = rr;
1251: break;
1252: case IDENTIFIER:
1253: rr = free_array(FIRST_ARGNAME(argp));
1254: resultp->s_type = I_CONSTANT;
1255: resultp->s_int = rr;
1256: break;
1257: }
1258: } break;
1.1 albertel 1259: case ARRAY_MAX_F:
1260: case ARRAY_MIN_F:
1261: { int min;
1262: Symbol *r_p;
1263:
1264: min = ((func==ARRAY_MIN_F)? 1 : 0);
1265: switch( FIRST_ARGTYPE(argp) ) {
1266: case I_VAR: case I_CONSTANT:
1267: case R_VAR: case R_CONSTANT:
1268: resultp->s_type = S_CONSTANT;
1269: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
1270: sprintf(tmpS,"%s()'s arg. must be a name of an array.\n",(min ? "min" : "max"));
1271: capa_msg(MESSAGE_ERROR,tmpS);
1272: break;
1273: case S_VAR: case S_CONSTANT: /* this allows the use of min(array[1]) which array[1]="another" */
1274: r_p = array_min_max(FIRST_ARGSTR(argp),min);
1275: if( r_p == NULL ) { /* array name is not in array tree */
1276: resultp->s_type = S_CONSTANT;
1277: resultp->s_str = strsave("<<STRING ARRAY NAME IS NOT YET DEFINED!>>");
1278: } else {
1279: /*
1280: fprintf(stdout,"min_max():: STR arg. R=%g\n",r_p->s_real); fflush(stdout);
1281: */
1282: capa_mfree((char *)resultp);
1283: resultp = r_p;
1284: }
1285: break;
1286: case IDENTIFIER:
1287: r_p = array_min_max(FIRST_ARGNAME(argp),min);
1288: if( r_p == NULL ) { /* array name is not in array tree */
1289: /* fprintf(stdout,"min_max() return NULL\n"); fflush(stdout); */
1290: resultp->s_type = S_CONSTANT;
1291: resultp->s_str = strsave("<<ARRAY NAME IS NOT YET DEFINED!>>");
1292: } else {
1293: /*
1294: fprintf(stdout,"min_max():: ID arg. R=%g\n",r_p->s_real); fflush(stdout);
1295: */
1296: capa_mfree((char *)resultp);
1297: resultp = r_p;
1298: }
1299: break;
1300: }
1301: } break;
1302: case SIN_F:
1303: case COS_F:
1304: case TAN_F:
1305: case ASIN_F:
1306: case ACOS_F:
1307: case ATAN_F:
1308: case SINH_F:
1309: case COSH_F:
1310: case TANH_F:
1311: case ASINH_F:
1312: case ACOSH_F:
1313: case ATANH_F:
1314: case J_ZERO_F:
1315: case J_ONE_F:
1316: case Y_ZERO_F:
1317: case Y_ONE_F:
1318: case LOG_F:
1319: case LOG_TEN_F:
1320: case EXP_F:
1321: case ERF_F:
1322: case ERFC_F:
1323: case ABS_F:
1324: case SQRT_F:
1325: case FLOOR_F:
1326: case CEIL_F:
1327: case SGN_F:{ if( (FIRST_ARGTYPE(argp) == S_VAR ) || (FIRST_ARGTYPE(argp) == S_CONSTANT ) ) {
1328: sprintf(aline,"<<ARG TYPE MISMATCH>>");
1329: resultp->s_type = S_CONSTANT;
1330: resultp->s_str = strsave(aline);
1331: sprintf(tmpS,"function %s() cannot accept string as argument.\n", FuncStack[Func_idx].s_name);
1332: capa_msg(MESSAGE_ERROR,tmpS);
1333: } else {
1334: if( (FIRST_ARGTYPE(argp) == I_VAR ) || (FIRST_ARGTYPE(argp) == I_CONSTANT ) ) {
1335: tmpA = (double)FIRST_ARGINT(argp);
1336: } else {
1337: tmpA = (double)FIRST_ARGREAL(argp);
1338: }
1339: resultp->s_type = R_CONSTANT;
1340: switch(func) {
1341: case SIN_F: resultp->s_real = sin(tmpA); break;
1342: case COS_F: resultp->s_real = cos(tmpA); break;
1343: case TAN_F: resultp->s_real = tan(tmpA); break;
1344: case ASIN_F: if(fabs(tmpA) <= 1.0) {
1345: resultp->s_real = asin(tmpA);
1346: } else {
1347: resultp->s_type = S_CONSTANT;
1348: sprintf(aline,"<<ARG OUT OF BOUND>>");
1349: resultp->s_str = strsave(aline);
1350: sprintf(tmpS, "asin()'s arg. is not in the range of [-1.0,+1.0].\n");
1351: capa_msg(MESSAGE_ERROR,tmpS);
1352: }
1353: break;
1354: case ACOS_F: if(fabs(tmpA) <= 1.0) {
1355: resultp->s_real = acos(tmpA);
1356: } else {
1357: resultp->s_type = S_CONSTANT;
1358: sprintf(aline,"<<ARG OUT OF BOUND>>");
1359: resultp->s_str = strsave(aline);
1360: sprintf(tmpS,"acos()'s arg. is not in the range of [-1.0,+1.0].\n");
1361: capa_msg(MESSAGE_ERROR,tmpS);
1362: }
1363: break;
1364: case ATAN_F: resultp->s_real = atan(tmpA); break;
1365: case SINH_F: resultp->s_real = sinh(tmpA); break;
1366: case COSH_F: resultp->s_real = cosh(tmpA); break;
1367: case TANH_F: resultp->s_real = tanh(tmpA); break;
1368: case ASINH_F: resultp->s_real = asinh(tmpA); break;
1369: case ACOSH_F: resultp->s_real = acosh(tmpA); break;
1370: case ATANH_F: resultp->s_real = atanh(tmpA); break;
1371: case J_ZERO_F: resultp->s_real = j0(tmpA); break;
1372: case J_ONE_F: resultp->s_real = j1(tmpA); break;
1373: case Y_ZERO_F: resultp->s_real = y0(tmpA); break;
1374: case Y_ONE_F: resultp->s_real = y1(tmpA); break;
1375: case LOG_F: resultp->s_real = log(tmpA); break;
1376: case LOG_TEN_F: resultp->s_real = log10(tmpA); break;
1377: case EXP_F: resultp->s_real = exp(tmpA); break;
1378: case ERF_F: resultp->s_real = erf(tmpA); break;
1379: case ERFC_F: resultp->s_real = erfc(tmpA); break;
1380: case ABS_F: resultp->s_real = fabs(tmpA); break;
1381: case SQRT_F: if( tmpA >= 0.0) {
1382: resultp->s_real = sqrt(tmpA);
1383: } else {
1384: resultp->s_type = S_CONSTANT;
1385: sprintf(aline,"<<ARG OUT OF BOUND>>");
1386: resultp->s_str = strsave(aline);
1387: sprintf(tmpS, "sqrt()'s arg. is not in the range of [0.0,+Inf].\n");
1388: capa_msg(MESSAGE_ERROR,tmpS);
1389: }
1390: break;
1391: case FLOOR_F: resultp->s_type = I_CONSTANT;
1392: resultp->s_int = (long)floor(tmpA); break;
1393: case CEIL_F: resultp->s_type = I_CONSTANT;
1394: resultp->s_int = (long)ceil(tmpA); break;
1395: case SGN_F: resultp->s_type = I_CONSTANT;
1396: resultp->s_int = (int)SGN(tmpA); break;
1397: }
1398: }
1399: }
1400: break;
1401: case ATANTWO_F:
1402: case J_N_F:
1403: case Y_N_F:
1404: case POW_F: { noError = 1;
1405: switch(FIRST_ARGTYPE(argp)) {
1406: case I_VAR:
1407: case I_CONSTANT: tmpA = (double)FIRST_ARGINT(argp); break;
1408: case R_VAR:
1409: case R_CONSTANT: tmpA = FIRST_ARGREAL(argp); break;
1410: case S_VAR:
1411: case S_CONSTANT: noError = 0;
1412: resultp->s_str = strsave("<<MIS TYPE>>");
1413: sprintf(tmpS,"%s()'s second arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1414: capa_msg(MESSAGE_ERROR,tmpS);
1415: break;
1416: }
1417: switch(SECOND_ARGTYPE(argp)) {
1418: case I_VAR:
1419: case I_CONSTANT: tmpB = (double)SECOND_ARGINT(argp); break;
1420: case R_VAR:
1421: case R_CONSTANT: tmpB = SECOND_ARGREAL(argp); break;
1422: case S_VAR:
1423: case S_CONSTANT: noError = 0;
1424: resultp->s_str = strsave("<<MIS TYPE>>");
1425: sprintf(tmpS,"%s()'s first arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1426: capa_msg(MESSAGE_ERROR,tmpS);
1427: break;
1428: }
1429: if ( POW_F == func ) {
1430: if ((!(((double)((int)tmpA)) == tmpA)) && (tmpB < 0.0)) {
1431: resultp->s_str = strsave("<<ARG OUT OF BOUND>>");
1432: sprintf(tmpS,
1433: "%s()'s arguments would result in a complex number.\n",
1434: FuncStack[Func_idx].s_name);
1435: capa_msg(MESSAGE_ERROR,tmpS);
1436: noError=0;
1437: }
1438: }
1439: if(noError) {
1440: resultp->s_type = R_CONSTANT;
1441: switch( func ) {
1442: case J_N_F: resultp->s_real = jn((int)tmpB, tmpA); break;
1443: case Y_N_F: resultp->s_real = yn((int)tmpB, tmpA); break;
1444: case POW_F: resultp->s_real = pow(tmpB, tmpA); break;
1445: case ATANTWO_F: resultp->s_real = atan2(tmpB, tmpA); break;
1446: }
1447: }else {
1448: resultp->s_type = S_CONSTANT;
1449: }
1450:
1451: }
1452: break;
1453: case TEX_F: { if (Parsemode_f != TeX_MODE) {
1.6 albertel 1454: #ifdef TTH
1455: #define CHARLEN 1024*1024
1456: {
1457: char *html;
1458: if ( (Parsemode_f==HTML_MODE) &&
1459: ((SECOND_ARGTYPE(argp) == S_VAR) ||
1460: (SECOND_ARGTYPE(argp) == S_CONSTANT))
1461: ) {
1462: printf("Hi There %s\n",SECOND_ARGSTR(argp));
1463: resultp->s_type = SECOND_ARGTYPE(argp);
1464: if(tth_err) { free(tth_err); tth_err=NULL; }
1465: textohtmldyn(SECOND_ARGSTR(argp),&html,&tth_err,CHARLEN);
1466: if(html) {
1467: resultp->s_str=strsave(html);
1468: capa_mfree(html);
1469: } else {
1470: resultp->s_str=strsave("");
1471: }
1472: break;
1473: }
1474: }
1475: #undef CHARLEN
1476: #endif
1.1 albertel 1477: resultp->s_type = FIRST_ARGTYPE(argp);
1478: switch(FIRST_ARGTYPE(argp)) {
1479: case I_VAR:
1480: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1481: case R_VAR:
1482: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1483: case S_VAR:
1484: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1485: }
1486: } else {
1487: resultp->s_type = SECOND_ARGTYPE(argp);
1488: switch(SECOND_ARGTYPE(argp)) {
1489: case I_VAR:
1490: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1491: case R_VAR:
1492: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1493: case S_VAR:
1494: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1495: }
1496: }
1497: } break;
1498: case VAR_IN_TEX_F:{
1499:
1500: if (Parsemode_f == TeX_MODE) {
1501: resultp->s_type = FIRST_ARGTYPE(argp);
1502:
1503: switch(FIRST_ARGTYPE(argp)) {
1504: case I_VAR:
1505: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1506: case R_VAR:
1507: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1508: case S_VAR:
1509: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1510: }
1511: } else {
1512: resultp->s_type = S_CONSTANT;
1513: resultp->s_str = strsave("");
1514:
1515: }
1516: } break;
1517: case HTML_F: { if (Parsemode_f == HTML_MODE) {
1518: resultp->s_type = FIRST_ARGTYPE(argp);
1519: switch(FIRST_ARGTYPE(argp)) {
1520: case I_VAR:
1521: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1522: case R_VAR:
1523: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1524: case S_VAR:
1525: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1526: }
1527: } else {
1528: resultp->s_type = S_CONSTANT;
1529: resultp->s_str = strsave("");
1530: }
1531: /* printf("HTML:%s\n",resultp->s_str); */
1532: } break;
1533: case WEB_F:
1534: case FORMAT_F: { /* web(ASCII,TeX,HTML) */
1535: if( argc == 3 ) {
1536: switch(Parsemode_f) {
1537: case HTML_MODE: {
1538: resultp->s_type = FIRST_ARGTYPE(argp);
1539: switch(FIRST_ARGTYPE(argp)) {
1540: case I_VAR:
1541: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1542: case R_VAR:
1543: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1544: case S_VAR:
1545: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1546: }
1547: } break;
1548: case TeX_MODE: {
1549: resultp->s_type = SECOND_ARGTYPE(argp);
1550: switch(SECOND_ARGTYPE(argp)) {
1551: case I_VAR:
1552: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1553: case R_VAR:
1554: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1555: case S_VAR:
1556: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1557: }
1558: } break;
1559: default: {
1560: resultp->s_type = THIRD_ARGTYPE(argp);
1561: switch(THIRD_ARGTYPE(argp)) {
1562: case I_VAR:
1563: case I_CONSTANT: resultp->s_int = THIRD_ARGINT(argp); break;
1564: case R_VAR:
1565: case R_CONSTANT: resultp->s_real = THIRD_ARGREAL(argp); break;
1566: case S_VAR:
1567: case S_CONSTANT: resultp->s_str = strsave(THIRD_ARGSTR(argp)); break;
1568: }
1569: } break;
1570: }
1571: } else { /* argc == 2 */
1572: switch(Parsemode_f) {
1573: case TeX_MODE: {
1574: resultp->s_type = FIRST_ARGTYPE(argp);
1575: switch(FIRST_ARGTYPE(argp)) {
1576: case I_VAR:
1577: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1578: case R_VAR:
1579: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1580: case S_VAR:
1581: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1582: }
1583: } break;
1584: default : {
1585: resultp->s_type = SECOND_ARGTYPE(argp);
1586: switch(SECOND_ARGTYPE(argp)) {
1587: case I_VAR:
1588: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1589: case R_VAR:
1590: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1591: case S_VAR:
1592: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1593: }
1594: } break;
1595: }
1596: }
1597: } break;
1598: case FACTORIAL_F: {
1599: int ii;
1600: unsigned long long l_fac;
1601: double d_fac;
1602:
1603: switch(FIRST_ARGTYPE(argp)) {
1604: case I_VAR:
1605: case I_CONSTANT: {
1606: if( FIRST_ARGINT(argp) < 0 ) {
1607: sprintf(aline,"<<FACTORIAL ERROR>>");
1608: resultp->s_type = S_CONSTANT;
1609: resultp->s_str = strsave(aline);
1610: sprintf(tmpS,"%s()'s arg. cannot be less than zero.\n",FuncStack[Func_idx].s_name);
1611: capa_msg(MESSAGE_ERROR,tmpS);
1612: } else {
1613: if( FIRST_ARGINT(argp) <= 20 ) {
1614: resultp->s_type = I_CONSTANT;
1615: l_fac = 1;
1616: for(ii=2; ii <= FIRST_ARGINT(argp); ii++) { l_fac *= ii; }
1617: resultp->s_int = l_fac;
1618: } else {
1619: resultp->s_type = R_CONSTANT;
1620: d_fac = 362880.0;
1621: for(ii=10; ii <= FIRST_ARGINT(argp); ii++) { d_fac *= ii; }
1622: resultp->s_real = d_fac;
1623: }
1624: }
1625: }
1626: break;
1627: case R_VAR:
1628: case R_CONSTANT: {
1629: if( FIRST_ARGREAL(argp) < 0.0 ) {
1630: sprintf(aline,"<<FACTORIAL ERROR>>");
1631: resultp->s_type = S_CONSTANT;
1632: resultp->s_str = strsave(aline);
1633: sprintf(tmpS,"%s()'s arg. cannot be less than zero.\n", FuncStack[Func_idx].s_name);
1634: capa_msg(MESSAGE_ERROR,tmpS);
1635: } else {
1636: if( FIRST_ARGREAL(argp) <= 20.0 ) {
1637: resultp->s_type = I_CONSTANT;
1638: l_fac = 1;
1639: for(ii=2; ii <= FIRST_ARGREAL(argp); ii++) { l_fac *= ii; }
1640: resultp->s_int = l_fac;
1641: } else {
1642: resultp->s_type = R_CONSTANT;
1643: d_fac = 362880.0;
1644: for(ii=10; ii <= FIRST_ARGREAL(argp); ii++) { d_fac *= ii; }
1645: resultp->s_real = d_fac;
1646: }
1647: }
1648: }
1649: break;
1650: case S_VAR:
1651: case S_CONSTANT: {
1652: sprintf(aline,"<<FACTORIAL ERROR>>");
1653: resultp->s_type = S_CONSTANT;
1654: resultp->s_str = strsave(aline);
1655: sprintf(tmpS,"%s()'s arg. cannot be of string type.\n",FuncStack[Func_idx].s_name);
1656: capa_msg(MESSAGE_ERROR,tmpS);
1657: }
1658: break;
1659: }
1660: } break;
1661: case MOD_F: break;
1662: case REMAINDER_F: break;
1663: case MAX_F:
1664: case MIN_F: { int ii, idx, type;
1665:
1666: tmpArgp = argp;
1667: tmpA = ((func == MIN_F)? MAX_DOUBLE : - MAX_DOUBLE);
1668: type = R_CONSTANT; idx = -1;
1669: noError = 1;
1670: for(ii = 0; (ii < argc)&&(noError); ii++) {
1671: switch (FIRST_ARGTYPE(tmpArgp)) {
1672: case I_VAR:
1673: case I_CONSTANT:
1674: if( type == S_CONSTANT) {
1675: sprintf(aline,"<<ARG TYPE>>");
1676: resultp->s_type = S_CONSTANT;
1677: resultp->s_str = strsave(aline);
1678: sprintf(tmpS,"%s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1679: capa_msg(MESSAGE_ERROR,tmpS);
1680: noError = 0;
1681: } else {
1682: switch(func) {
1683: case MIN_F:
1684: if( tmpA <= FIRST_ARGINT(tmpArgp) ) {
1685: } else {
1686: idx = ii; type = I_CONSTANT;
1687: tmpA = (double)FIRST_ARGINT(tmpArgp);
1688: }
1689: break;
1690: case MAX_F:
1691: if( tmpA >= FIRST_ARGINT(tmpArgp) ) {
1692: } else {
1693: idx = ii; type = I_CONSTANT;
1694: tmpA = (double)FIRST_ARGINT(tmpArgp);
1695: }
1696: break;
1697: }
1698: }
1699: break;
1700: case R_VAR:
1701: case R_CONSTANT:
1702: if( type == S_CONSTANT ) {
1703: sprintf(aline,"<<ARG TYPE>>");
1704: resultp->s_type = S_CONSTANT;
1705: resultp->s_str = strsave(aline);
1706: sprintf(tmpS,"%s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1707: capa_msg(MESSAGE_ERROR,tmpS);
1708: noError = 0;
1709: } else {
1710: switch(func) {
1711: case MIN_F:
1712: if( tmpA <= FIRST_ARGREAL(tmpArgp) ) {
1713: } else {
1714: idx = ii; type = R_CONSTANT;
1715: tmpA = FIRST_ARGREAL(tmpArgp);
1716: }
1717: break;
1718: case MAX_F:
1719: if( tmpA >= FIRST_ARGREAL(tmpArgp) ) {
1720: } else {
1721: idx = ii; type = R_CONSTANT;
1722: tmpA = FIRST_ARGREAL(tmpArgp);
1723: }
1724: break;
1725: }
1726: }
1727: break;
1728: case S_VAR:
1729: case S_CONSTANT:
1730: if( (ii != 0)&&(type != S_CONSTANT) ) {
1731: sprintf(aline,"<<ARG TYPE>>");
1732: resultp->s_type = S_CONSTANT;
1733: resultp->s_str = strsave(aline);
1734: sprintf(tmpS," %s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1735: capa_msg(MESSAGE_ERROR,tmpS);
1736: noError = 0;
1737: } else {
1738: if( ii == 0 ) { idx = 0; strcpy(tmpS, FIRST_ARGSTR(tmpArgp)); }
1739: type = S_CONSTANT;
1740: switch( func) {
1741: case MIN_F:
1742: if( strcmp(tmpS, FIRST_ARGSTR(tmpArgp)) <= 0 ) {
1743: } else {
1744: idx = ii;
1745: strcpy(tmpS, FIRST_ARGSTR(tmpArgp));
1746: }
1747: break;
1748: case MAX_F:
1749: if( strcmp(tmpS, FIRST_ARGSTR(tmpArgp)) >= 0 ) {
1750: } else {
1751: idx = ii;
1752: strcpy(tmpS, FIRST_ARGSTR(tmpArgp));
1753: }
1754: break;
1755: }
1756: }
1757: break;
1758: }
1759: tmpArgp = tmpArgp->a_next;
1760: }
1761: if( noError ) {
1762: for(tmpArgp=argp,ii=0; ii<idx; ii++) { tmpArgp=tmpArgp->a_next; }
1763: resultp->s_type = type;
1764: switch(type) {
1765: case I_CONSTANT: resultp->s_int = (tmpArgp->a_sp)->s_int;
1766: break;
1767: case R_CONSTANT: resultp->s_real = (tmpArgp->a_sp)->s_real;
1768: break;
1769: case S_CONSTANT: resultp->s_str = strsave((tmpArgp->a_sp)->s_str);
1770: break;
1771: }
1772: }
1773:
1774: }
1775: break;
1776: case ROUNDTO_F: {
1777: noError = 1; hh = 0; /* reuse integer hh and mm */
1778: switch(FIRST_ARGTYPE(argp)) {
1779: case I_VAR:
1780: case I_CONSTANT: mm = FIRST_ARGINT(argp); break;
1781: case R_VAR:
1782: case R_CONSTANT: mm = (int)FIRST_ARGREAL(argp); break;
1783: case S_VAR:
1784: case S_CONSTANT: noError = 0;
1785: resultp->s_type = S_CONSTANT;
1786: resultp->s_str = strsave("<<MIS TYPE>>");
1787: sprintf(tmpS,
1788: "%s()'s second arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1789: capa_msg(MESSAGE_ERROR,tmpS);
1790: break;
1791: }
1792: switch(SECOND_ARGTYPE(argp)) {
1793: case I_VAR:
1794: case I_CONSTANT: hh = SECOND_ARGINT(argp); break;
1795: case R_VAR:
1796: case R_CONSTANT: tmpA = SECOND_ARGREAL(argp); break;
1797: case S_VAR:
1798: case S_CONSTANT: noError = 0;
1799: resultp->s_type = S_CONSTANT;
1800: resultp->s_str = strsave("<<MIS TYPE>>");
1801: sprintf(tmpS,
1802: "%s()'s first arg. cannot be string.\n",
1803: FuncStack[Func_idx].s_name);
1804: capa_msg(MESSAGE_ERROR,tmpS);
1805: break;
1806: }
1807: if(noError) {
1808: resultp->s_type = R_CONSTANT;
1809: if( hh != 0 ) {
1810: resultp->s_type = I_CONSTANT;
1811: resultp->s_int = hh;
1812: } else {
1813: if ( mm >= 0 ) {
1814: sprintf(fmt_str,"%%.%df",mm);
1815: sprintf(num_str,fmt_str,tmpA);
1816: tmpB = atof(num_str);
1817: resultp->s_real = tmpB;
1818: } else {
1819: sprintf(tmpS,"%s()'s second arg. cannot be negative (%d).\n",
1820: FuncStack[Func_idx].s_name,mm);
1821: capa_msg(MESSAGE_ERROR,tmpS);
1822: resultp->s_real = tmpA; /* not changed */
1823: }
1824: }
1825: }
1826: } break;
1827: case EVALUATE_F: { char *f_str, *v_str, *pt_str, *out_come;
1828: noError = 1;
1829: switch(FIRST_ARGTYPE(argp)) { /* now only accepts string like "0.0,0.1,0.2,0.3,0.4,0.5" */
1830: case I_VAR:
1831: case I_CONSTANT: noError = 0;
1832: resultp->s_type = S_CONSTANT;
1833: resultp->s_str = strsave("<<Evaulate Formula: Pts TYPE incorrect>>");
1834: sprintf(tmpS,
1835: "%s()'s third arg. cannot be integer.\n",FuncStack[Func_idx].s_name);
1836: capa_msg(MESSAGE_ERROR,tmpS);
1837: break;
1838: case R_VAR:
1839: case R_CONSTANT: noError = 0;
1840: resultp->s_type = S_CONSTANT;
1841: resultp->s_str = strsave("<<Evaulate Formula: Pts TYPE incorrect>>");
1842: sprintf(tmpS,
1843: "%s()'s third arg. cannot be integer.\n",FuncStack[Func_idx].s_name);
1844: capa_msg(MESSAGE_ERROR,tmpS);
1845: break;
1846: case S_VAR:
1847: case S_CONSTANT:
1848: pt_str = FIRST_ARGSTR(argp);
1849: break;
1850: }
1851: switch(SECOND_ARGTYPE(argp)) {
1852: case I_VAR:
1853: case I_CONSTANT:
1854: case R_VAR:
1855: case R_CONSTANT: noError = 0;
1856: resultp->s_type = S_CONSTANT;
1857: resultp->s_str = strsave("<<Evaluate Formula: Var list TYPE incorrect>>");
1858: sprintf(tmpS,
1859: "%s()'s second arg. cannot be number.\n",FuncStack[Func_idx].s_name);
1860: capa_msg(MESSAGE_ERROR,tmpS);
1861: break;
1862:
1863: case S_VAR:
1864: case S_CONSTANT: v_str = SECOND_ARGSTR(argp);
1865: break;
1866: }
1867: switch(THIRD_ARGTYPE(argp)) {
1868: case I_VAR:
1869: case I_CONSTANT:
1870: case R_VAR:
1871: case R_CONSTANT: noError = 0;
1872: resultp->s_type = S_CONSTANT;
1873: resultp->s_str = strsave("<<Evaluate Formula: Formula TYPE incorrect>>");
1874: sprintf(tmpS,
1875: "%s()'s first arg. cannot be number.\n",FuncStack[Func_idx].s_name);
1876: capa_msg(MESSAGE_ERROR,tmpS);
1877: break;
1878: case S_VAR:
1879: case S_CONSTANT: f_str = THIRD_ARGSTR(argp);
1880: break;
1881: }
1882: if(noError) {
1883: resultp->s_type = S_CONSTANT;
1884: /* printf("EVALUATE:::%s,%s,%s\n",f_str, v_str, pt_str); */
1885: out_come = eval_formula_range_str(f_str, v_str, pt_str);
1886: if( !out_come ) {
1887: resultp->s_str = strsave("<<Evaluate formula:: NULL>>");
1888: sprintf(tmpS,
1889: "%s() cannot evaluate the formula correctly.\n",FuncStack[Func_idx].s_name);
1890: capa_msg(MESSAGE_ERROR,tmpS);
1891: } else {
1892: resultp->s_str = out_come;
1893: }
1894: }
1895: }
1896: break;
1897: case CAPAID_PLUS:
1898: {
1899: extern Problem_t* FirstProblem_p;
1900: extern Problem_t* LexiProblem_p;
1901: Problem_t* problem;
1902: int num_char,pin;
1903: errCode = 0;
1904: if (argc==1) {
1905: switch( FIRST_ARGTYPE(argp) ) {
1906: case I_VAR: case I_CONSTANT: num_char=FIRST_ARGINT(argp); break;
1907: case R_VAR: case R_CONSTANT: errCode = 1; break;
1908: case S_VAR: case S_CONSTANT: errCode = 1; break;
1909: }
1910: } else {
1911: switch( SECOND_ARGTYPE(argp) ) {
1912: case I_VAR: case I_CONSTANT: num_char=SECOND_ARGINT(argp); break;
1913: case R_VAR: case R_CONSTANT: errCode = 1; break;
1914: case S_VAR: case S_CONSTANT: errCode = 1; break;
1915: }
1916: }
1917:
1918: if( errCode == 0 ) {
1919: if ( FirstProblem_p ) {
1920: problem=FirstProblem_p;
1921: } else {
1922: problem=LexiProblem_p;
1923: }
1924: if (!(problem->capaidplus)) capa_mfree(problem->capaidplus);
1925: if (-1==(tmpInt=which_set(argc-1,argp,resultp))) break;
1926: pin=capa_PIN(Parse_student_number,tmpInt,0);
1927: problem->capaidplus = capa_id_plus(Parse_student_number,
1928: tmpInt,num_char);
1929: resultp->s_type = S_CONSTANT;
1930: resultp->s_str = strsave(problem->capaidplus);
1931: } else {
1932: resultp->s_type = S_CONSTANT;
1933: resultp->s_str = strsave("<<INCORRECT ARGS TO CAPAID_PLUS>>");
1934: }
1935: }
1936: break;
1937: case SEAT_NUMBER:
1938: {
1939: int filenum;
1940: double filedoub;
1941: char *filename;
1942: if ( argc == 1 ) {
1943: switch( FIRST_ARGTYPE(argp)) {
1944: case I_VAR: case I_CONSTANT: filenum=FIRST_ARGINT(argp);
1945: filename=capa_malloc(TMP_LINE_LENGTH,1);
1946: sprintf(filename,"%d",filenum);
1947: break;
1948: case R_VAR: case R_CONSTANT: filedoub=FIRST_ARGREAL(argp);
1949: filename=capa_malloc(TMP_LINE_LENGTH,1);
1950: sprintf(filename,"%f",filedoub);
1951: break;
1952: case S_VAR: case S_CONSTANT:
1953: filename=strsave(FIRST_ARGSTR(argp)); break;
1954: }
1955: } else {
1956: filename=NULL;
1957: }
1958: resultp->s_type = S_CONSTANT;
1959: resultp->s_str = capa_get_seat(Parse_student_number,filename);
1960: if ( filename != NULL ) capa_mfree(filename);
1961: break;
1962: }
1963: case DURATION: { resultp->s_type = I_CONSTANT;
1964: resultp->s_int=capa_get_duration(Parse_student_number,
1965: Parse_section,Parse_set);
1966: } break;
1.3 albertel 1967: case MANAGERMODE_F: { resultp->s_type = I_CONSTANT;
1968: resultp->s_int=managermode;
1969: }break;
1970: case CORRECT_F: {
1971:
1972: }break;
1973:
1974: case TRIES_F: {
1975:
1976: }break;
1977:
1978: case GRADE_F: {
1979:
1980: }break;
1981:
1.1 albertel 1982: case MIS_ARG_COUNT:
1983: { resultp->s_type = S_CONSTANT;
1984: resultp->s_str = strsave("<<ARG COUNT>>");
1.3 albertel 1985: sprintf(tmpS,"%s()'s arg. count is not correct.\n",
1986: FuncStack[Func_idx].s_name);
1.1 albertel 1987: capa_msg(MESSAGE_ERROR,tmpS);
1988: } break;
1989: case UNKNOWN_F:
1990: default: { resultp->s_type = S_CONSTANT;
1991: resultp->s_str = strsave("<<UNKNOWN FUNCTION>>");
1992: sprintf(tmpS,"%s() unknown.\n",FuncStack[Func_idx].s_name);
1993: capa_msg(MESSAGE_ERROR,tmpS);
1994:
1995: } break;
1996: }
1997:
1998: return (resultp);
1999: }
2000:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>