Annotation of capa/capa51/pProj/capaFunction.c, revision 1.4
1.1 albertel 1:
2: /* =||>>================================================================<<||= */
3: /* 45678901234567890123456789012345678901234567890123456789012345678901234567 */
4: /* copyrighted by Isaac Tsai, 1996, 1997, 1998, 1999, 2000 */
5: /* =||>>================================================================<<||= */
6:
7: #include <stdlib.h>
8: #include <string.h>
9: #include <math.h>
10:
11: #include "capaParser.h" /* Symbol_p */
12: #include "capaFunction.h" /* RANDOM_F etc. */
13: #include "capaToken.h"
14: #include "capaCommon.h"
15: #include "ranlib.h"
16:
17: char Parse_class[QUARTER_K];
18: int Parse_set;
19: int Parse_section;
20: char Parse_student_number[MAX_STUDENT_NUMBER+1];
21: char Parse_name[MAX_NAME_CHAR+1];
22: long capaid_plus_gen;
1.3 albertel 23: int managermode;
1.1 albertel 24:
25: extern int Parsemode_f;
26:
27: extern int Lexi_qnum;
28: extern char Opened_filename[MAX_OPENED_FILE][QUARTER_K];
29: extern int Input_idx;
30: extern int Current_line[MAX_OPENED_FILE];
31:
32: extern int Func_idx;
33: extern Symbol FuncStack[MAX_FUNC_NEST];
34:
35: /* --------------------------------------------------------------------------- */
36: int
37: match_function(func, argc) char *func; int argc;
38: {
39: if( !strcmp(func,"random") ) return (((argc==2 || argc==3)? RANDOM_F : MIS_ARG_COUNT));
1.4 ! albertel 40: if( !strcmp(func,"random_normal") ) return (((argc==2 || argc==3)? RANDOM_NORMAL_F : MIS_ARG_COUNT));
! 41: if( !strcmp(func,"random_exponential") ) return (((argc==2 || argc==3)? RANDOM_EXPONENTIAL_F : MIS_ARG_COUNT));
! 42: if( !strcmp(func,"random_beta") ) return (((argc==2 || argc==3)? RANDOM_BETA_F : MIS_ARG_COUNT));
1.1 albertel 43: if( !strcmp(func,"choose") ) return (CHOOSE_F);
44: if( !strcmp(func,"tex") ) return (((argc==2)? TEX_F: MIS_ARG_COUNT));
45: if( !strcmp(func,"var_in_tex") ) return (VAR_IN_TEX_F);
46: if( !strcmp(func,"html") ) return (((argc==1)? HTML_F: MIS_ARG_COUNT));
47: if( !strcmp(func,"web") ) return (((argc==3)? WEB_F: MIS_ARG_COUNT));
48: if( !strcmp(func,"pin") ) return (((argc<2)? PIN_F: MIS_ARG_COUNT));
49: if( !strcmp(func,"capa_id") ) return (((argc<2)? PIN_F: MIS_ARG_COUNT));
50: if( !strcmp(func,"class") ) return (((argc==0)? CLASS_F: MIS_ARG_COUNT));
51: if( !strcmp(func,"section") ) return (((argc==0)? SECTION_F: MIS_ARG_COUNT));
52: if( !strcmp(func,"set") ) return (((argc==0)? SET_F: MIS_ARG_COUNT));
53: if( !strcmp(func,"problem") ) return (((argc==0)? PROBLEM_F: MIS_ARG_COUNT));
54: if( !strcmp(func,"name") ) return (((argc==0)? NAME_F: MIS_ARG_COUNT));
55: if( !strcmp(func,"student_number") ) return (((argc==0)? SNUMBER_F: MIS_ARG_COUNT));
56: if( !strcmp(func,"due_date") ) return (((argc<2)? DUE_DATE_F: MIS_ARG_COUNT));
57: if( !strcmp(func,"due_day") ) return (((argc<2)? DUE_DAY_F: MIS_ARG_COUNT));
58: if( !strcmp(func,"open_date") ) return (((argc<2)? OPEN_DATE_F: MIS_ARG_COUNT));
59: if( !strcmp(func,"answer_date") ) return (((argc<2)? ANSWER_DATE_F: MIS_ARG_COUNT));
60: if( !strcmp(func,"to_string") ) return (((argc==1 || argc==2)? TO_STRING_F: MIS_ARG_COUNT));
61: if( !strcmp(func,"sub_string") ) return (((argc==2 || argc==3)? SUB_STRING_F: MIS_ARG_COUNT));
62: if( !strcmp(func,"strlen") ) return (((argc==1)? STRLEN_F: MIS_ARG_COUNT));
63: if( !strcmp(func,"get_seed") ) return (((argc==0)? GET_SEED_F: MIS_ARG_COUNT));
64: if( !strcmp(func,"set_seed") ) return (((argc==1)? SET_SEED_F: MIS_ARG_COUNT));
1.4 ! albertel 65: if( !strcmp(func,"init_array") ) return (((argc==1)? INIT_ARRAY_F: MIS_ARG_COUNT));
1.1 albertel 66: if( !strcmp(func,"array_index") ) return (((argc==1)? ARRAY_INDEX_F: MIS_ARG_COUNT));
67: if( !strcmp(func,"array_sorted_index") ) return (((argc==2)? ARRAY_SORTED_INDEX_F: MIS_ARG_COUNT));
68: if( !strcmp(func,"array_max") ) return (((argc==1)? ARRAY_MAX_F: MIS_ARG_COUNT));
69: if( !strcmp(func,"array_min") ) return (((argc==1)? ARRAY_MIN_F: MIS_ARG_COUNT));
70: if( !strcmp(func,"array_moments") ) return (((argc==2)? ARRAY_MOMENTS_F: MIS_ARG_COUNT));
71: if( !strcmp(func,"array_var") ) return (((argc==1)? ARRAY_VARIANCE_F: MIS_ARG_COUNT));
72: if( !strcmp(func,"array_std_dev") ) return (((argc==1)? ARRAY_STD_DEV_F: MIS_ARG_COUNT));
73: if( !strcmp(func,"array_skewness") ) return (((argc==1)? ARRAY_SKEWNESS_F: MIS_ARG_COUNT));
74: if( !strcmp(func,"to_int") ) return (((argc==1)? TO_INT_F: MIS_ARG_COUNT));
75: if( !strcmp(func,"format") ) return (FORMAT_F);
76: if( !strcmp(func,"pick") ) return (((argc> 1)? PICK_F: MIS_ARG_COUNT));
77: if( !strcmp(func,"sin") ) return (((argc==1)? SIN_F: MIS_ARG_COUNT));
78: if( !strcmp(func,"cos") ) return (((argc==1)? COS_F: MIS_ARG_COUNT));
79: if( !strcmp(func,"tan") ) return (((argc==1)? TAN_F: MIS_ARG_COUNT));
80: if( !strcmp(func,"asin") ) return (((argc==1)? ASIN_F: MIS_ARG_COUNT));
81: if( !strcmp(func,"acos") ) return (((argc==1)? ACOS_F: MIS_ARG_COUNT));
82: if( !strcmp(func,"atan") ) return (((argc==1)? ATAN_F: MIS_ARG_COUNT));
83: if( !strcmp(func,"sinh") ) return (((argc==1)? SINH_F: MIS_ARG_COUNT));
84: if( !strcmp(func,"cosh") ) return (((argc==1)? COSH_F: MIS_ARG_COUNT));
85: if( !strcmp(func,"tanh") ) return (((argc==1)? TANH_F: MIS_ARG_COUNT));
86: if( !strcmp(func,"asinh") ) return (((argc==1)? ASINH_F: MIS_ARG_COUNT));
87: if( !strcmp(func,"acosh") ) return (((argc==1)? ACOSH_F: MIS_ARG_COUNT));
88: if( !strcmp(func,"atanh") ) return (((argc==1)? ATANH_F: MIS_ARG_COUNT));
89: if( !strcmp(func,"atan2") ) return (((argc==2)? ATANTWO_F: MIS_ARG_COUNT));
90: if( !strcmp(func,"j0") ) return (((argc==1)? J_ZERO_F: MIS_ARG_COUNT));
91: if( !strcmp(func,"j1") ) return (((argc==1)? J_ONE_F: MIS_ARG_COUNT));
92: if( !strcmp(func,"jn") ) return (((argc==2)? J_N_F: MIS_ARG_COUNT));
93: if( !strcmp(func,"y0") ) return (((argc==1)? Y_ZERO_F: MIS_ARG_COUNT));
94: if( !strcmp(func,"y1") ) return (((argc==1)? Y_ONE_F: MIS_ARG_COUNT));
95: if( !strcmp(func,"yn") ) return (((argc==2)? Y_N_F: MIS_ARG_COUNT));
96: if( !strcmp(func,"log") ) return (((argc==1)? LOG_F: MIS_ARG_COUNT));
97: if( !strcmp(func,"log10") ) return (((argc==1)? LOG_TEN_F: MIS_ARG_COUNT));
98: if( !strcmp(func,"exp") ) return (((argc==1)? EXP_F: MIS_ARG_COUNT));
99: if( !strcmp(func,"pow") ) return (((argc==2)? POW_F: MIS_ARG_COUNT));
100: if( !strcmp(func,"erf") ) return (((argc==1)? ERF_F: MIS_ARG_COUNT));
101: if( !strcmp(func,"erfc") ) return (((argc==1)? ERFC_F: MIS_ARG_COUNT));
102: if( !strcmp(func,"sqrt") ) return (((argc==1)? SQRT_F: MIS_ARG_COUNT));
103: if( !strcmp(func,"min") ) return (MIN_F);
104: if( !strcmp(func,"max") ) return (MAX_F);
105: if( !strcmp(func,"abs") ) return (((argc==1)? ABS_F: MIS_ARG_COUNT));
106: if( !strcmp(func,"floor") ) return (((argc==1)? FLOOR_F: MIS_ARG_COUNT));
107: if( !strcmp(func,"ceil") ) return (((argc==1)? CEIL_F: MIS_ARG_COUNT));
108: if( !strcmp(func,"sgn") ) return (((argc==1)? SGN_F: MIS_ARG_COUNT));
109: if( !strcmp(func,"mod") ) return (((argc==2)? MOD_F: MIS_ARG_COUNT));
110: if( !strcmp(func,"remainder") ) return (((argc==2)? REMAINDER_F: MIS_ARG_COUNT));
111: if( !strcmp(func,"factorial") ) return (((argc==1)? FACTORIAL_F: MIS_ARG_COUNT));
112: if( !strcmp(func,"roundto") ) return (((argc==2)? ROUNDTO_F: MIS_ARG_COUNT));
113: if( !strcmp(func,"eval_formula") ) return (((argc==3)? EVALUATE_F: MIS_ARG_COUNT));
114: if( !strcmp(func,"capa_id_plus") ) return (((argc==1 || argc==2)? CAPAID_PLUS: MIS_ARG_COUNT));
115: if( !strcmp(func,"seat_number") ) return (((argc <2)? SEAT_NUMBER: MIS_ARG_COUNT));
116: if( !strcmp(func,"duration") ) return (((argc==0)? DURATION: MIS_ARG_COUNT));
117: if( !strcmp(func,"is_open") ) return (((argc <2)? IS_OPEN_F: MIS_ARG_COUNT));
118: if( !strcmp(func,"is_due") ) return (((argc <2)? IS_DUE_F: MIS_ARG_COUNT));
119: if( !strcmp(func,"is_answer") ) return (((argc <2)? IS_ANSWER_F: MIS_ARG_COUNT));
1.3 albertel 120: if( !strcmp(func,"correct") ) return (((argc <3)? CORRECT_F: MIS_ARG_COUNT));
121: if( !strcmp(func,"grade") ) return (((argc <3)? GRADE_F: MIS_ARG_COUNT));
122: if( !strcmp(func,"tries") ) return (((argc <3)? TRIES_F: MIS_ARG_COUNT));
123: if( !strcmp(func,"managermode")) return (((argc==0)? MANAGERMODE_F:MIS_ARG_COUNT));
1.1 albertel 124: return (UNKNOWN_F);
125: }
126:
127: /**********************************************************/
128:
129:
130: #ifdef SGN
131: #undef SGN
132: #endif
133: #define SGN(xx) ( (xx) > 0 ? 1 : ( (xx) == 0 ? 0 : -1) )
134:
135:
136: #define MAX_DOUBLE 1.7976931348623157E+308
137: #define MIN_DOUBLE 2.2250738585072014E-308
138:
139: #define INT_DIV 0
140: #define REAL_DIV 1
141: #define INT_LOWER 0
142: #define REAL_LOWER 2
143: #define INT_UPPER 0
144: #define REAL_UPPER 4
145:
146: #define ALL_INTEGER 0
147:
148: int which_set(argc,argp,resultp)
149: int argc;
150: ArgNode_t *argp;
151: Symbol *resultp;
152: {
153: char aline[MAX_BUFFER_SIZE], tmpS[MAX_BUFFER_SIZE];
154: int result=Parse_set;
155: if( argc == 1 ) {
156: if( (FIRST_ARGTYPE(argp) == S_VAR ) ||
157: (FIRST_ARGTYPE(argp) == S_CONSTANT ) ) {
158: sprintf(aline,"<<ARG TYPE MISMATCH>>");
159: resultp->s_type = S_CONSTANT;
160: resultp->s_str = strsave(aline);
161: sprintf(tmpS, "function %s() cannot accept string as argument.\n",
162: FuncStack[Func_idx].s_name);
163: capa_msg(MESSAGE_ERROR,tmpS);
164: result=-1;
165: } else {
166: if( (FIRST_ARGTYPE(argp) == I_VAR ) ||
167: (FIRST_ARGTYPE(argp) == I_CONSTANT ) ) {
168: result = FIRST_ARGINT(argp);
169: } else {
170: result = FIRST_ARGREAL(argp);
171: }
172: }
173: }
174: return result;
175: }
176:
177: Symbol *
178: do_function(func,argc,argp)
179: int func;
180: int argc;
181: ArgNode_t *argp;
182: {
183: Symbol *resultp;
184: ArgNode_t *tmpArgp;
185: char aline[MAX_BUFFER_SIZE], tmpS[MAX_BUFFER_SIZE], fmt_str[FORMAT_STRING_LENG];
186: char num_str[SMALL_LINE_BUFFER],date_str[SMALL_LINE_BUFFER];
187: double tmpA=0.0, tmpB=0.0;
188: int slots, noError, errCode, mo, yy, dd, hh, mm, tmpInt;
189: long rout;
190: char *wday[9] = {"Sat,", "Sun,", "Mon,", "Tue,", "Wed,", "Thr,", "Fri,", "Sat,", "\0"};
1.2 albertel 191: char *month[14] = { "UNKNOWN", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
192: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "\0"};
1.1 albertel 193:
194: resultp = (Symbol *)capa_malloc(1,sizeof(Symbol));
195:
196: switch(func) {
197: case RANDOM_F: { int type_flag=0;
198: double r_lower=0.0, r_upper=1.0, r_division=1.0;
199:
200: errCode = 0; rout = ignlgi();
201: switch( FIRST_ARGTYPE(argp) ) {
202: case I_VAR: case I_CONSTANT: break;
203: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 1); break;
204: case S_VAR: case S_CONSTANT: errCode = 1; break;
205: }
206: switch( SECOND_ARGTYPE(argp) ) {
207: case I_VAR: case I_CONSTANT: break;
208: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 2); break;
209: case S_VAR: case S_CONSTANT: errCode = 2; break;
210: }
211: if( argc == 3 ) {
212: switch( THIRD_ARGTYPE(argp) ) {
213: case I_VAR: case I_CONSTANT: break;
214: case R_VAR: case R_CONSTANT: type_flag = (type_flag | 4); break;
215: case S_VAR: case S_CONSTANT: errCode = 4; break;
216: }
217: }
218: if( errCode == 0 ) {
219: if( argc == 3 ) {
220: switch(type_flag) {
221: case 0: r_division = (double)FIRST_ARGINT(argp);
222: r_upper = (double)SECOND_ARGINT(argp);
223: r_lower = (double)THIRD_ARGINT(argp); break;
224: case 2: r_division = (double)FIRST_ARGINT(argp);
225: r_upper = SECOND_ARGREAL(argp);
226: r_lower = (double)THIRD_ARGINT(argp); break;
227: case 4: r_division = (double)FIRST_ARGINT(argp);
228: r_upper = (double)SECOND_ARGINT(argp);
229: r_lower = THIRD_ARGREAL(argp); break;
230: case 6: r_division = (double)FIRST_ARGINT(argp);
231: r_upper = SECOND_ARGREAL(argp);
232: r_lower = THIRD_ARGREAL(argp); break;
233: case 1: r_division = FIRST_ARGREAL(argp);
234: r_upper = (double)SECOND_ARGINT(argp);
235: r_lower = (double)THIRD_ARGINT(argp); break;
236: case 3: r_division = FIRST_ARGREAL(argp);
237: r_upper = SECOND_ARGREAL(argp);
238: r_lower = (double)THIRD_ARGINT(argp); break;
239: case 5: r_division = FIRST_ARGREAL(argp);
240: r_upper = (double)SECOND_ARGINT(argp);
241: r_lower = THIRD_ARGREAL(argp); break;
242: case 7: r_division = FIRST_ARGREAL(argp);
243: r_upper = SECOND_ARGREAL(argp);
244: r_lower = THIRD_ARGREAL(argp); break;
245: }
246: } else { /* two args */
247: switch(type_flag) {
248: case 0: r_upper = (double)FIRST_ARGINT(argp);
249: r_lower = (double)SECOND_ARGINT(argp); break;
250: case 1: r_upper = FIRST_ARGREAL(argp);
251: r_lower = (double)SECOND_ARGINT(argp); break;
252: case 2: r_upper = (double)FIRST_ARGINT(argp);
253: r_lower = SECOND_ARGREAL(argp); break;
254: case 3: r_upper = FIRST_ARGREAL(argp);
255: r_lower = SECOND_ARGREAL(argp); break;
256: }
257: r_division = 1.0;
258: }
259: if( r_upper >= r_lower ) {
260: slots = 1 + (int)floor( (r_upper - r_lower)/r_division );
261: if( type_flag == 0 ) {
262: resultp->s_type = I_CONSTANT;
263: resultp->s_int = (int)r_lower + ((int)r_division)*(rout % slots );
264: } else {
265: resultp->s_type = R_CONSTANT;
266: resultp->s_real = r_lower + r_division*(double)(rout % slots );
267: }
268: } else {
269: resultp->s_type = S_CONSTANT;
270: resultp->s_str = strsave("<<2ND ARG MUST .GE. 1ST ARG>>");
271: sprintf(tmpS,"random()'s second arg. must be greater than the first arg.\n");
272: capa_msg(MESSAGE_ERROR,tmpS);
273: }
274: } else {
275: resultp->s_type = S_CONSTANT;
276: resultp->s_str = strsave("<<ARG CANNOT BE STRING>>");
277: sprintf(tmpS,"random() cannot accept string as argument.\n");
278: capa_msg(MESSAGE_ERROR,tmpS);
279: }
280: } break;
281: case CHOOSE_F: { int ii, pick=1;
282: ArgNode_t *tmpArgp;
283:
284: noError = 1;
285: tmpArgp = argp; ii=0;
286: while( ii < argc-1 ) {tmpArgp = tmpArgp->a_next; ii++; }
287: switch( FIRST_ARGTYPE(tmpArgp) ) {
288: case IDENTIFIER:
289: sprintf(tmpS,"The first argument to choose(): \"%s\" has not been defined yet. I will choose the first element.\n",FIRST_ARGNAME(tmpArgp));
290: capa_msg(MESSAGE_ERROR,tmpS);
291: pick = 1;
292: break;
293: case I_VAR: case I_CONSTANT:
294: pick = FIRST_ARGINT(tmpArgp); break;
295: case R_VAR: case R_CONSTANT:
296: pick = (int)FIRST_ARGREAL(tmpArgp);
297: 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);
298: capa_msg(MESSAGE_ERROR,tmpS);
299: break;
300: case S_VAR: case S_CONSTANT:
301: resultp->s_type = S_CONSTANT;
302: resultp->s_str = strsave("CHOOSE: first argument must be an integer");
303: sprintf(tmpS,"The first argument to choose() cannot be a string, I will choose the first element.\n");
304: capa_msg(MESSAGE_ERROR,tmpS);
305: pick = 1;
306: break;
307: }
308: if( noError ) {
309: if( (pick <= 0) || (pick > argc-1) ) {
310: 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);
311: capa_msg(MESSAGE_ERROR,tmpS);
312: pick = argc-1;
313: } else { pick = argc - pick; }
314: for(ii=1,tmpArgp = argp;(ii < pick)&&(ii < argc-1);ii++) { tmpArgp = tmpArgp->a_next; }
315:
316: resultp->s_type = (tmpArgp->a_sp)->s_type;
317: switch((tmpArgp->a_sp)->s_type) {
318: case IDENTIFIER:
319: sprintf(tmpS,"The variable \"%s\" selected by choose() has not yet been defined.\n",(tmpArgp->a_sp)->s_name);
320: capa_msg(MESSAGE_ERROR,tmpS);
321: resultp->s_type = S_CONSTANT;
322: resultp->s_str = strsave(tmpS);
323: break;
324: case I_VAR: case I_CONSTANT:
325: resultp->s_type = I_CONSTANT;
326: resultp->s_int = (tmpArgp->a_sp)->s_int; break;
327: case R_VAR: case R_CONSTANT:
328: resultp->s_type = R_CONSTANT;
329: resultp->s_real = (tmpArgp->a_sp)->s_real; break;
330: case S_VAR: case S_CONSTANT:
331: resultp->s_type = S_CONSTANT;
332: resultp->s_str = strsave((tmpArgp->a_sp)->s_str); break; /********* */
333: }
334:
335: }
336:
337: } break;
338: case PIN_F: {
339: if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
340: resultp->s_type = I_CONSTANT;
341: resultp->s_int=capa_PIN(Parse_student_number,tmpInt,0);
342: }
343: break;
344: case CLASS_F: {
345: resultp->s_type = S_CONSTANT;
346: if(strlen(Parse_class) != 0 ) {
347: resultp->s_str=strsave(Parse_class);
348: } else {
349: resultp->s_str=strsave("UNKNOWN");
350: }
351: }
352: break;
353: case SECTION_F:{ resultp->s_type = I_CONSTANT;
354: resultp->s_int = Parse_section;
355: } break;
356: case PROBLEM_F:{ resultp->s_type = I_CONSTANT;
357: resultp->s_int= Lexi_qnum+1;
358: } break;
359: case SET_F: { resultp->s_type = I_CONSTANT;
360: resultp->s_int=Parse_set;
361: } break;
362: case NAME_F: {
363: resultp->s_type = S_CONSTANT;
364: resultp->s_str=strsave(Parse_name);
365: } break;
366: case SNUMBER_F: {
367: resultp->s_type = S_CONSTANT;
368: resultp->s_str=strsave(Parse_student_number);
369: } break;
370: case IS_DUE_F:
371: case IS_ANSWER_F:
372: case IS_OPEN_F: {
373: int whichDate=CHECK_OPEN_DATE;
374: if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
375: resultp->s_type = I_CONSTANT;
376: switch(func) {
377: case IS_OPEN_F: whichDate=CHECK_OPEN_DATE;break;
378: case IS_DUE_F: whichDate=CHECK_DUE_DATE;break;
379: case IS_ANSWER_F: whichDate=CHECK_ANS_DATE;break;
380: }
381: if( capa_check_date(whichDate,Parse_student_number,
382: Parse_section,tmpInt) < 0 ) {
383: resultp->s_int = 0;
384: } else {
385: resultp->s_int = 1;
386: }
387: } break;
388: case DUE_DATE_F:
389: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
390: resultp->s_type = S_CONSTANT;
391: if(capa_get_date(CHECK_DUE_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
392: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mo, &dd, &hh, &mm);
393: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
394: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
395: resultp->s_str= strsave(aline);
396: } else {
397: resultp->s_str= strsave("UNKNOWN");
398: }
399: } break;
400: case DUE_DAY_F:
401: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
402: resultp->s_type = S_CONSTANT;
403: if(capa_get_date(CHECK_DUE_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
404: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mm, &dd, &hh, &mm);
405: sprintf(aline, "%s %s %2d, %4d",
406: wday[weekday(yy,mo,dd)], month[mo], dd, yy);
407: resultp->s_str= strsave(aline);
408: } else {
409: resultp->s_str= strsave("UNKNOWN");
410: }
411: } break;
412: case OPEN_DATE_F:
413: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
414: resultp->s_type = S_CONSTANT;
415: if(capa_get_date(CHECK_OPEN_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
416: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mm, &dd, &hh, &mm);
417: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
418: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
419: resultp->s_str= strsave(aline);
420: } else {
421: resultp->s_str= strsave("UNKNOWN");
422: }
423: } break;
424: case ANSWER_DATE_F:
425: { if (-1==(tmpInt=which_set(argc,argp,resultp))) break;
426: resultp->s_type = S_CONSTANT;
427: if(capa_get_date(CHECK_ANS_DATE,Parse_student_number,Parse_section,tmpInt,date_str) > 0 ) {
428: sscanf(date_str,"%4d/%2d/%2d %2d:%2d",&yy, &mo, &dd, &hh, &mm);
429: sprintf(aline, "%s %s %2d, %4d at %02d:%02d",
430: wday[weekday(yy,mo,dd)], month[mo], dd, yy, hh, mm);
431: resultp->s_str= strsave(aline);
432: } else {
433: resultp->s_str= strsave("UNKNOWN");
434: }
435: } break;
436: case STRLEN_F: {
437: resultp->s_type = I_CONSTANT;
438: switch( FIRST_ARGTYPE(argp) ) {
439: case I_VAR:
440: case I_CONSTANT:
441: resultp->s_type = S_CONSTANT;
442: sprintf(tmpS,"strlen() only accepts string variable, not integer.\n");
443: capa_msg(MESSAGE_ERROR,tmpS);
444: resultp->s_str=strsave(tmpS);
445: break;
446: case R_VAR:
447: case R_CONSTANT:
448: resultp->s_type = S_CONSTANT;
449: sprintf(tmpS,"strlen() only accepts string variable, not float number.\n");
450: capa_msg(MESSAGE_ERROR,tmpS);
451: resultp->s_str=strsave(tmpS);
452: break;
453: case S_VAR:
454: case S_CONSTANT:
455: resultp->s_int = strlen( FIRST_ARGSTR(argp) );
456: break;
457: case IDENTIFIER:
458: sprintf(tmpS,"Unknown variable, %s, argument to function strlen()\n",argp->a_sp->s_name);
459: capa_msg(MESSAGE_ERROR,tmpS);
460: resultp->s_str=strsave(tmpS);
461: break;
462: }
463: } break;
464: case TO_STRING_F:
465: { char aline[MAX_BUFFER_SIZE],rline[MAX_BUFFER_SIZE];
466:
467: resultp->s_type = S_CONSTANT;
468:
469: if( argc == 1 ) {
470: switch( FIRST_ARGTYPE(argp) ) {
471: case I_VAR:
472: case I_CONSTANT:
473: sprintf(aline,"%ld",FIRST_ARGINT(argp));
474: resultp->s_str = strsave(aline); break;
475: case R_VAR:
476: case R_CONSTANT:
477: sprintf(aline,"%.15g",FIRST_ARGREAL(argp));
478: resultp->s_str = strsave(aline); break;
479: case S_VAR:
480: case S_CONSTANT:
481: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
482: case IDENTIFIER:
483: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_sp->s_name);
484: capa_msg(MESSAGE_ERROR,tmpS);
485: resultp->s_str=strsave(tmpS);
486: break;
487: }
488: } else {
489: switch( FIRST_ARGTYPE(argp) ) {
490: case I_VAR:
491: case I_CONSTANT:
492: case R_VAR:
493: case R_CONSTANT:
494: sprintf(tmpS,
495: "to_string()'s second arg. must be a string.\n");
496: capa_msg(MESSAGE_ERROR,tmpS);
497: sprintf(aline,"%%.15g");
498: break;
499: case S_VAR:
500: case S_CONSTANT:
501: sprintf(aline,"%%%s",FIRST_ARGSTR(argp));
502: break;
503: case IDENTIFIER:
504: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_next->a_sp->s_name);
505: capa_msg(MESSAGE_ERROR,tmpS);
506: resultp->s_str=strsave(tmpS);
507: break;
508:
509: }
510: switch( SECOND_ARGTYPE(argp) ) {
511: case I_VAR:
512: case I_CONSTANT:
513: sprintf(aline,"%ld",SECOND_ARGINT(argp));
514: resultp->s_str = strsave(aline); break;
515: case R_VAR:
516: case R_CONSTANT:
517: sprintf(rline,aline,SECOND_ARGREAL(argp));
518: resultp->s_str = strsave(rline); break;
519: case S_VAR:
520: case S_CONSTANT:
521: resultp->s_str = strsave(SECOND_ARGSTR(argp));
522: break;
523: case IDENTIFIER:
524: sprintf(tmpS,"Unknown variable, %s, argument to function to_string()\n",argp->a_sp->s_name);
525: capa_msg(MESSAGE_ERROR,tmpS);
526: resultp->s_str=strsave(tmpS);
527: break;
528: }
529: }
530: } break;
531: case SUB_STRING_F: /* sub_string(str, 2), 1 is the first char */
532: /* sub_string(str, 3, 5) means start from the third char and take 5 chars */
533: { int idx=1, leng, rleng=0,ii;
534: char *a_str, *b_str;
535:
536: resultp->s_type = S_CONSTANT;
537: if( argc == 2 ) { /* two arguments format */
538: switch( FIRST_ARGTYPE(argp) ) {
539: case IDENTIFIER:
540: sprintf(tmpS,
541: "sub_string()'s second arg. must be an integer.\n");
542: capa_msg(MESSAGE_ERROR,tmpS);
543: break;
544: case I_VAR:
545: case I_CONSTANT:
546: idx = FIRST_ARGINT(argp);
547: break;
548: case R_VAR:
549: case R_CONSTANT:
550: idx = (int) FIRST_ARGREAL(argp);
551: break;
552: case S_VAR:
553: case S_CONSTANT:
554: sprintf(tmpS,
555: "sub_string()'s second arg. must be an integer.\n");
556: capa_msg(MESSAGE_ERROR,tmpS);
557: break;
558: }
559: switch( SECOND_ARGTYPE(argp) ) {
560: case IDENTIFIER:
561: sprintf(tmpS,
562: "sub_string()'s first arg. is not defined before use.\n");
563: capa_msg(MESSAGE_ERROR,tmpS);
564: break;
565: case I_VAR:
566: case I_CONSTANT:
567: sprintf(tmpS,
568: "sub_string()'s first arg. cannot be an integer.\n");
569: capa_msg(MESSAGE_ERROR,tmpS);
570: break;
571: case R_VAR:
572: case R_CONSTANT:
573: sprintf(tmpS,
574: "sub_string()'s first arg. cannot be a number.\n");
575: capa_msg(MESSAGE_ERROR,tmpS);
576: break;
577: case S_VAR:
578: case S_CONSTANT:
579: a_str = SECOND_ARGSTR(argp);
580: leng = strlen(a_str);
581: if( (idx<1) || (idx > leng) ) {
582: sprintf(tmpS, "sub_string()'s second arg. is out of range.\n");
583: capa_msg(MESSAGE_ERROR,tmpS);
584: idx = 1;
585: }
586: b_str = (char *)&a_str[idx-1];
587: resultp->s_str = strsave(b_str);
588:
589: if( SECOND_ARGTYPE(argp) == S_CONSTANT) {
590: /* freed in free arg_list */
591: /* capa_mfree((char *)SECOND_ARGSTR(argp)); */
592: }
593: break;
594: }
595: } else { /* three arguments format sub_string(string, start, length) */
596: switch( FIRST_ARGTYPE(argp) ) {
597: case IDENTIFIER:
598: sprintf(tmpS,
599: "sub_string()'s third arg. must be an integer.\n");
600: capa_msg(MESSAGE_ERROR,tmpS);
601: break;
602: case I_VAR:
603: case I_CONSTANT:
604: rleng = FIRST_ARGINT(argp);
605: break;
606: case R_VAR:
607: case R_CONSTANT:
608: rleng = (int) FIRST_ARGREAL(argp);
609: break;
610: case S_VAR:
611: case S_CONSTANT:
612: sprintf(tmpS,
613: "sub_string()'s third arg. must be an integer.\n");
614: capa_msg(MESSAGE_ERROR,tmpS);
615: break;
616: }
617: switch( SECOND_ARGTYPE(argp) ) {
618: case IDENTIFIER:
619: sprintf(tmpS,
620: "sub_string()'s second arg. must be an integer.\n");
621: capa_msg(MESSAGE_ERROR,tmpS);
622: break;
623: case I_VAR:
624: case I_CONSTANT:
625: idx = SECOND_ARGINT(argp);
626: break;
627: case R_VAR:
628: case R_CONSTANT:
629: idx = (int) SECOND_ARGREAL(argp);
630: break;
631: case S_VAR:
632: case S_CONSTANT:
633: sprintf(tmpS,
634: "sub_string()'s second arg. must be an integer.\n");
635: capa_msg(MESSAGE_ERROR,tmpS);
636: break;
637: }
638: switch( THIRD_ARGTYPE(argp) ) {
639: case IDENTIFIER:
640: sprintf(tmpS,
641: "sub_string()'s first arg. is not defined before use.\n");
642: capa_msg(MESSAGE_ERROR,tmpS);
643: break;
644: case I_VAR:
645: case I_CONSTANT:
646: sprintf(tmpS,
647: "sub_string()'s first arg. cannot be an integer.\n");
648: capa_msg(MESSAGE_ERROR,tmpS);
649: break;
650: case R_VAR:
651: case R_CONSTANT:
652: sprintf(tmpS,
653: "sub_string()'s first arg. cannot be a number.\n");
654: capa_msg(MESSAGE_ERROR,tmpS);
655: break;
656: case S_VAR:
657: case S_CONSTANT:
658: a_str = THIRD_ARGSTR(argp);
659: leng = strlen(a_str);
660: if( (idx < 1) || (idx > leng) ) {
661: sprintf(tmpS, "sub_string()'s second arg. is out of range.\n");
662: capa_msg(MESSAGE_ERROR,tmpS);
663: idx = 1;
664: }
665: if( (rleng<1) || ((rleng+idx-1) > leng)) {
666:
667: rleng = leng - idx + 1;
668: }
669: b_str = (char *)capa_malloc((rleng+1)*sizeof(char),1);
670: for(ii=idx-1;ii<(rleng+idx-1);ii++) {
671: b_str[ii-idx+1] = a_str[ii];
672: }
673: resultp->s_str = strsave(b_str);
674: capa_mfree(b_str);
675:
676: if( THIRD_ARGTYPE(argp) == S_CONSTANT) {
677: /* handled in free_arglist() */
678: /* capa_mfree((char *)THIRD_ARGSTR(argp)); */
679: }
680: break;
681: }
682: }
683: } break;
684: case PICK_F: { int ii, pick=1;
685: ArgNode_t *tmpArgp;
686:
687: noError = 1;
688: rout = ignlgi();
689: tmpArgp = argp; ii=0;
690: while( ii < argc-1 ) {tmpArgp = tmpArgp->a_next; ii++; }
691: switch( FIRST_ARGTYPE(tmpArgp) ) {
692: case I_VAR:
693: case I_CONSTANT:
694: pick = FIRST_ARGINT(tmpArgp);
695: if( (pick <= 0 ) || (pick > argc-1) ) {
696: noError = 0;
697: resultp->s_type = S_CONSTANT;
698: resultp->s_str = strsave("PICK: first arg out of bound.");
699: }
700: break;
701: case R_VAR:
702: case R_CONSTANT:
703: pick = (int)FIRST_ARGREAL(tmpArgp);
704: if( (pick <= 0 ) || (pick > argc-1) ) {
705: noError = 0;
706: resultp->s_type = S_CONSTANT;
707: resultp->s_str = strsave("PICK: first arg out of bound.");
708: }
709: break;
710: case S_VAR:
711: case S_CONSTANT: noError = 0;
712: resultp->s_type = S_CONSTANT;
713: resultp->s_str = strsave("PICK: first arg must be int");
714: break;
715: }
716: if( noError ) {
717: for( ii=0; ii< pick; ii++) {
718: }
719: }
720: }
721: break;
722: case GET_SEED_F:
723: { long seed1, seed2;
724: char *tmp;
725:
726: getsd(&seed1,&seed2);
727: tmp = (char *)capa_malloc(32,1);
728: sprintf(tmp,"%ld,%ld",seed1,seed2);
729: resultp->s_type = S_CONSTANT;
730: resultp->s_str = strsave(tmp);
731: capa_mfree(tmp);
732: } break;
733: case SET_SEED_F:
734: { long seed1, seed2;
735: int leng;
736:
737: switch( FIRST_ARGTYPE(argp) ) {
738: case I_VAR: case I_CONSTANT: break;
739: case R_VAR: case R_CONSTANT: break;
740: case S_VAR: case S_CONSTANT:
741: leng = strlen(FIRST_ARGSTR(argp));
742: if( (index(FIRST_ARGSTR(argp), ' ') != NULL) ) {
743: sscanf(FIRST_ARGSTR(argp),"%ld,%ld", &seed1, &seed2);
744: setall(seed1,seed2);
745: }
746:
747: break;
748: }
749: resultp->s_type = I_CONSTANT;
750: resultp->s_int = 0;
751: } break;
752: case ARRAY_MOMENTS_F: /* it */
753: {
754: char *tmp_input;
755: Symbol *r_p;
756:
757: switch( FIRST_ARGTYPE(argp) ) {
758: case I_VAR: case I_CONSTANT:
759: case R_VAR: case R_CONSTANT:
760: resultp->s_type = S_CONSTANT;
761: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
762: sprintf(tmpS,"array_moments()'s arg. must be a name of an array.\n");
763: capa_msg(MESSAGE_ERROR,tmpS);
764: errCode = 1;
765: break;
766: case S_VAR: case S_CONSTANT:
767: tmp_input = strsave(FIRST_ARGSTR(argp));
768: errCode = 0;
769: break;
770: case IDENTIFIER:
771: tmp_input = strsave(FIRST_ARGNAME(argp));
772: errCode = 0;
773: break;
774: }
775: if( errCode == 0 ) {
776: switch( SECOND_ARGTYPE(argp) ) {
777: case I_VAR: case I_CONSTANT:
778: case R_VAR: case R_CONSTANT:
779: resultp->s_type = S_CONSTANT;
780: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
781: sprintf(tmpS,"array_moments()'s arg. must be a name of an array.\n");
782: capa_msg(MESSAGE_ERROR,tmpS);
783: errCode = 1;
784: break;
785: case S_VAR: case S_CONSTANT:
786: r_p = array_moments(SECOND_ARGSTR(argp),tmp_input);
787: capa_mfree((char *)tmp_input);
788: /* fprintf(stdout,"DONE array_moments()\n"); fflush(stdout); */
789: break;
790: case IDENTIFIER:
791: r_p = array_moments(SECOND_ARGNAME(argp),tmp_input);
792: capa_mfree((char *)tmp_input);
793:
794: break;
795: }
796: if(errCode == 0 ) {
797: capa_mfree((char *)resultp);
798: resultp = r_p;
799: }
800: }
801:
802: } break;
803: case ARRAY_SORTED_INDEX_F: /* array_sorted_index(array_name_str, sort_type) */
804: {
805: switch( FIRST_ARGTYPE(argp) ) {
806: case I_VAR: case I_CONSTANT:
807: switch( FIRST_ARGINT(argp) ) {
808: case ASCEND_SORT: break;
809: case DESCEND_SORT: break;
810: case NUMERICAL_SORT: break;
811: default: break;
812: }
813:
814: break;
815: case R_VAR: case R_CONSTANT: break;
816: case S_VAR: case S_CONSTANT:
817:
818:
819: break;
820: }
821: resultp->s_type = S_CONSTANT;
822: resultp->s_str = strsave("NOT YET");
823: } break;
824:
1.4 ! albertel 825: case INIT_ARRAY_F:
! 826: { int rr;
! 827:
! 828: switch( FIRST_ARGTYPE(argp) ) {
! 829: case I_VAR: case I_CONSTANT:
! 830: case R_VAR: case R_CONSTANT:
! 831: resultp->s_type = S_CONSTANT;
! 832: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
! 833: sprintf(tmpS,"init_array()'s arg. must be a name of an array.\n");
! 834: capa_msg(MESSAGE_ERROR,tmpS);
! 835: break;
! 836: case S_VAR: case S_CONSTANT: /* allows the use of init_array(array[1]) which array[1]="another" */
! 837: rr = free_array(FIRST_ARGSTR(argp));
! 838: resultp->s_type = I_CONSTANT;
! 839: resultp->s_int = rr;
! 840: break;
! 841: case IDENTIFIER:
! 842: rr = free_array(FIRST_ARGNAME(argp));
! 843: resultp->s_type = I_CONSTANT;
! 844: resultp->s_int = rr;
! 845: break;
! 846: }
! 847: } break;
1.1 albertel 848: case ARRAY_MAX_F:
849: case ARRAY_MIN_F:
850: { int min;
851: Symbol *r_p;
852:
853: min = ((func==ARRAY_MIN_F)? 1 : 0);
854: switch( FIRST_ARGTYPE(argp) ) {
855: case I_VAR: case I_CONSTANT:
856: case R_VAR: case R_CONSTANT:
857: resultp->s_type = S_CONSTANT;
858: resultp->s_str = strsave("<<ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>");
859: sprintf(tmpS,"%s()'s arg. must be a name of an array.\n",(min ? "min" : "max"));
860: capa_msg(MESSAGE_ERROR,tmpS);
861: break;
862: case S_VAR: case S_CONSTANT: /* this allows the use of min(array[1]) which array[1]="another" */
863: r_p = array_min_max(FIRST_ARGSTR(argp),min);
864: if( r_p == NULL ) { /* array name is not in array tree */
865: resultp->s_type = S_CONSTANT;
866: resultp->s_str = strsave("<<STRING ARRAY NAME IS NOT YET DEFINED!>>");
867: } else {
868: /*
869: fprintf(stdout,"min_max():: STR arg. R=%g\n",r_p->s_real); fflush(stdout);
870: */
871: capa_mfree((char *)resultp);
872: resultp = r_p;
873: }
874: break;
875: case IDENTIFIER:
876: r_p = array_min_max(FIRST_ARGNAME(argp),min);
877: if( r_p == NULL ) { /* array name is not in array tree */
878: /* fprintf(stdout,"min_max() return NULL\n"); fflush(stdout); */
879: resultp->s_type = S_CONSTANT;
880: resultp->s_str = strsave("<<ARRAY NAME IS NOT YET DEFINED!>>");
881: } else {
882: /*
883: fprintf(stdout,"min_max():: ID arg. R=%g\n",r_p->s_real); fflush(stdout);
884: */
885: capa_mfree((char *)resultp);
886: resultp = r_p;
887: }
888: break;
889: }
890: } break;
891: case SIN_F:
892: case COS_F:
893: case TAN_F:
894: case ASIN_F:
895: case ACOS_F:
896: case ATAN_F:
897: case SINH_F:
898: case COSH_F:
899: case TANH_F:
900: case ASINH_F:
901: case ACOSH_F:
902: case ATANH_F:
903: case J_ZERO_F:
904: case J_ONE_F:
905: case Y_ZERO_F:
906: case Y_ONE_F:
907: case LOG_F:
908: case LOG_TEN_F:
909: case EXP_F:
910: case ERF_F:
911: case ERFC_F:
912: case ABS_F:
913: case SQRT_F:
914: case FLOOR_F:
915: case CEIL_F:
916: case SGN_F:{ if( (FIRST_ARGTYPE(argp) == S_VAR ) || (FIRST_ARGTYPE(argp) == S_CONSTANT ) ) {
917: sprintf(aline,"<<ARG TYPE MISMATCH>>");
918: resultp->s_type = S_CONSTANT;
919: resultp->s_str = strsave(aline);
920: sprintf(tmpS,"function %s() cannot accept string as argument.\n", FuncStack[Func_idx].s_name);
921: capa_msg(MESSAGE_ERROR,tmpS);
922: } else {
923: if( (FIRST_ARGTYPE(argp) == I_VAR ) || (FIRST_ARGTYPE(argp) == I_CONSTANT ) ) {
924: tmpA = (double)FIRST_ARGINT(argp);
925: } else {
926: tmpA = (double)FIRST_ARGREAL(argp);
927: }
928: resultp->s_type = R_CONSTANT;
929: switch(func) {
930: case SIN_F: resultp->s_real = sin(tmpA); break;
931: case COS_F: resultp->s_real = cos(tmpA); break;
932: case TAN_F: resultp->s_real = tan(tmpA); break;
933: case ASIN_F: if(fabs(tmpA) <= 1.0) {
934: resultp->s_real = asin(tmpA);
935: } else {
936: resultp->s_type = S_CONSTANT;
937: sprintf(aline,"<<ARG OUT OF BOUND>>");
938: resultp->s_str = strsave(aline);
939: sprintf(tmpS, "asin()'s arg. is not in the range of [-1.0,+1.0].\n");
940: capa_msg(MESSAGE_ERROR,tmpS);
941: }
942: break;
943: case ACOS_F: if(fabs(tmpA) <= 1.0) {
944: resultp->s_real = acos(tmpA);
945: } else {
946: resultp->s_type = S_CONSTANT;
947: sprintf(aline,"<<ARG OUT OF BOUND>>");
948: resultp->s_str = strsave(aline);
949: sprintf(tmpS,"acos()'s arg. is not in the range of [-1.0,+1.0].\n");
950: capa_msg(MESSAGE_ERROR,tmpS);
951: }
952: break;
953: case ATAN_F: resultp->s_real = atan(tmpA); break;
954: case SINH_F: resultp->s_real = sinh(tmpA); break;
955: case COSH_F: resultp->s_real = cosh(tmpA); break;
956: case TANH_F: resultp->s_real = tanh(tmpA); break;
957: case ASINH_F: resultp->s_real = asinh(tmpA); break;
958: case ACOSH_F: resultp->s_real = acosh(tmpA); break;
959: case ATANH_F: resultp->s_real = atanh(tmpA); break;
960: case J_ZERO_F: resultp->s_real = j0(tmpA); break;
961: case J_ONE_F: resultp->s_real = j1(tmpA); break;
962: case Y_ZERO_F: resultp->s_real = y0(tmpA); break;
963: case Y_ONE_F: resultp->s_real = y1(tmpA); break;
964: case LOG_F: resultp->s_real = log(tmpA); break;
965: case LOG_TEN_F: resultp->s_real = log10(tmpA); break;
966: case EXP_F: resultp->s_real = exp(tmpA); break;
967: case ERF_F: resultp->s_real = erf(tmpA); break;
968: case ERFC_F: resultp->s_real = erfc(tmpA); break;
969: case ABS_F: resultp->s_real = fabs(tmpA); break;
970: case SQRT_F: if( tmpA >= 0.0) {
971: resultp->s_real = sqrt(tmpA);
972: } else {
973: resultp->s_type = S_CONSTANT;
974: sprintf(aline,"<<ARG OUT OF BOUND>>");
975: resultp->s_str = strsave(aline);
976: sprintf(tmpS, "sqrt()'s arg. is not in the range of [0.0,+Inf].\n");
977: capa_msg(MESSAGE_ERROR,tmpS);
978: }
979: break;
980: case FLOOR_F: resultp->s_type = I_CONSTANT;
981: resultp->s_int = (long)floor(tmpA); break;
982: case CEIL_F: resultp->s_type = I_CONSTANT;
983: resultp->s_int = (long)ceil(tmpA); break;
984: case SGN_F: resultp->s_type = I_CONSTANT;
985: resultp->s_int = (int)SGN(tmpA); break;
986: }
987: }
988: }
989: break;
990: case ATANTWO_F:
991: case J_N_F:
992: case Y_N_F:
993: case POW_F: { noError = 1;
994: switch(FIRST_ARGTYPE(argp)) {
995: case I_VAR:
996: case I_CONSTANT: tmpA = (double)FIRST_ARGINT(argp); break;
997: case R_VAR:
998: case R_CONSTANT: tmpA = FIRST_ARGREAL(argp); break;
999: case S_VAR:
1000: case S_CONSTANT: noError = 0;
1001: resultp->s_str = strsave("<<MIS TYPE>>");
1002: sprintf(tmpS,"%s()'s second arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1003: capa_msg(MESSAGE_ERROR,tmpS);
1004: break;
1005: }
1006: switch(SECOND_ARGTYPE(argp)) {
1007: case I_VAR:
1008: case I_CONSTANT: tmpB = (double)SECOND_ARGINT(argp); break;
1009: case R_VAR:
1010: case R_CONSTANT: tmpB = SECOND_ARGREAL(argp); break;
1011: case S_VAR:
1012: case S_CONSTANT: noError = 0;
1013: resultp->s_str = strsave("<<MIS TYPE>>");
1014: sprintf(tmpS,"%s()'s first arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1015: capa_msg(MESSAGE_ERROR,tmpS);
1016: break;
1017: }
1018: if ( POW_F == func ) {
1019: if ((!(((double)((int)tmpA)) == tmpA)) && (tmpB < 0.0)) {
1020: resultp->s_str = strsave("<<ARG OUT OF BOUND>>");
1021: sprintf(tmpS,
1022: "%s()'s arguments would result in a complex number.\n",
1023: FuncStack[Func_idx].s_name);
1024: capa_msg(MESSAGE_ERROR,tmpS);
1025: noError=0;
1026: }
1027: }
1028: if(noError) {
1029: resultp->s_type = R_CONSTANT;
1030: switch( func ) {
1031: case J_N_F: resultp->s_real = jn((int)tmpB, tmpA); break;
1032: case Y_N_F: resultp->s_real = yn((int)tmpB, tmpA); break;
1033: case POW_F: resultp->s_real = pow(tmpB, tmpA); break;
1034: case ATANTWO_F: resultp->s_real = atan2(tmpB, tmpA); break;
1035: }
1036: }else {
1037: resultp->s_type = S_CONSTANT;
1038: }
1039:
1040: }
1041: break;
1042: case TEX_F: { if (Parsemode_f != TeX_MODE) {
1043: resultp->s_type = FIRST_ARGTYPE(argp);
1044: switch(FIRST_ARGTYPE(argp)) {
1045: case I_VAR:
1046: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1047: case R_VAR:
1048: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1049: case S_VAR:
1050: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1051: }
1052: } else {
1053: resultp->s_type = SECOND_ARGTYPE(argp);
1054: switch(SECOND_ARGTYPE(argp)) {
1055: case I_VAR:
1056: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1057: case R_VAR:
1058: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1059: case S_VAR:
1060: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1061: }
1062: }
1063: } break;
1064: case VAR_IN_TEX_F:{
1065:
1066: if (Parsemode_f == TeX_MODE) {
1067: resultp->s_type = FIRST_ARGTYPE(argp);
1068:
1069: switch(FIRST_ARGTYPE(argp)) {
1070: case I_VAR:
1071: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1072: case R_VAR:
1073: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1074: case S_VAR:
1075: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1076: }
1077: } else {
1078: resultp->s_type = S_CONSTANT;
1079: resultp->s_str = strsave("");
1080:
1081: }
1082: } break;
1083: case HTML_F: { if (Parsemode_f == HTML_MODE) {
1084: resultp->s_type = FIRST_ARGTYPE(argp);
1085: switch(FIRST_ARGTYPE(argp)) {
1086: case I_VAR:
1087: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1088: case R_VAR:
1089: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1090: case S_VAR:
1091: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1092: }
1093: } else {
1094: resultp->s_type = S_CONSTANT;
1095: resultp->s_str = strsave("");
1096: }
1097: /* printf("HTML:%s\n",resultp->s_str); */
1098: } break;
1099: case WEB_F:
1100: case FORMAT_F: { /* web(ASCII,TeX,HTML) */
1101: if( argc == 3 ) {
1102: switch(Parsemode_f) {
1103: case HTML_MODE: {
1104: resultp->s_type = FIRST_ARGTYPE(argp);
1105: switch(FIRST_ARGTYPE(argp)) {
1106: case I_VAR:
1107: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1108: case R_VAR:
1109: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1110: case S_VAR:
1111: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1112: }
1113: } break;
1114: case TeX_MODE: {
1115: resultp->s_type = SECOND_ARGTYPE(argp);
1116: switch(SECOND_ARGTYPE(argp)) {
1117: case I_VAR:
1118: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1119: case R_VAR:
1120: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1121: case S_VAR:
1122: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1123: }
1124: } break;
1125: default: {
1126: resultp->s_type = THIRD_ARGTYPE(argp);
1127: switch(THIRD_ARGTYPE(argp)) {
1128: case I_VAR:
1129: case I_CONSTANT: resultp->s_int = THIRD_ARGINT(argp); break;
1130: case R_VAR:
1131: case R_CONSTANT: resultp->s_real = THIRD_ARGREAL(argp); break;
1132: case S_VAR:
1133: case S_CONSTANT: resultp->s_str = strsave(THIRD_ARGSTR(argp)); break;
1134: }
1135: } break;
1136: }
1137: } else { /* argc == 2 */
1138: switch(Parsemode_f) {
1139: case TeX_MODE: {
1140: resultp->s_type = FIRST_ARGTYPE(argp);
1141: switch(FIRST_ARGTYPE(argp)) {
1142: case I_VAR:
1143: case I_CONSTANT: resultp->s_int = FIRST_ARGINT(argp); break;
1144: case R_VAR:
1145: case R_CONSTANT: resultp->s_real = FIRST_ARGREAL(argp); break;
1146: case S_VAR:
1147: case S_CONSTANT: resultp->s_str = strsave(FIRST_ARGSTR(argp)); break;
1148: }
1149: } break;
1150: default : {
1151: resultp->s_type = SECOND_ARGTYPE(argp);
1152: switch(SECOND_ARGTYPE(argp)) {
1153: case I_VAR:
1154: case I_CONSTANT: resultp->s_int = SECOND_ARGINT(argp); break;
1155: case R_VAR:
1156: case R_CONSTANT: resultp->s_real = SECOND_ARGREAL(argp); break;
1157: case S_VAR:
1158: case S_CONSTANT: resultp->s_str = strsave(SECOND_ARGSTR(argp)); break;
1159: }
1160: } break;
1161: }
1162: }
1163: } break;
1164: case FACTORIAL_F: {
1165: int ii;
1166: unsigned long long l_fac;
1167: double d_fac;
1168:
1169: switch(FIRST_ARGTYPE(argp)) {
1170: case I_VAR:
1171: case I_CONSTANT: {
1172: if( FIRST_ARGINT(argp) < 0 ) {
1173: sprintf(aline,"<<FACTORIAL ERROR>>");
1174: resultp->s_type = S_CONSTANT;
1175: resultp->s_str = strsave(aline);
1176: sprintf(tmpS,"%s()'s arg. cannot be less than zero.\n",FuncStack[Func_idx].s_name);
1177: capa_msg(MESSAGE_ERROR,tmpS);
1178: } else {
1179: if( FIRST_ARGINT(argp) <= 20 ) {
1180: resultp->s_type = I_CONSTANT;
1181: l_fac = 1;
1182: for(ii=2; ii <= FIRST_ARGINT(argp); ii++) { l_fac *= ii; }
1183: resultp->s_int = l_fac;
1184: } else {
1185: resultp->s_type = R_CONSTANT;
1186: d_fac = 362880.0;
1187: for(ii=10; ii <= FIRST_ARGINT(argp); ii++) { d_fac *= ii; }
1188: resultp->s_real = d_fac;
1189: }
1190: }
1191: }
1192: break;
1193: case R_VAR:
1194: case R_CONSTANT: {
1195: if( FIRST_ARGREAL(argp) < 0.0 ) {
1196: sprintf(aline,"<<FACTORIAL ERROR>>");
1197: resultp->s_type = S_CONSTANT;
1198: resultp->s_str = strsave(aline);
1199: sprintf(tmpS,"%s()'s arg. cannot be less than zero.\n", FuncStack[Func_idx].s_name);
1200: capa_msg(MESSAGE_ERROR,tmpS);
1201: } else {
1202: if( FIRST_ARGREAL(argp) <= 20.0 ) {
1203: resultp->s_type = I_CONSTANT;
1204: l_fac = 1;
1205: for(ii=2; ii <= FIRST_ARGREAL(argp); ii++) { l_fac *= ii; }
1206: resultp->s_int = l_fac;
1207: } else {
1208: resultp->s_type = R_CONSTANT;
1209: d_fac = 362880.0;
1210: for(ii=10; ii <= FIRST_ARGREAL(argp); ii++) { d_fac *= ii; }
1211: resultp->s_real = d_fac;
1212: }
1213: }
1214: }
1215: break;
1216: case S_VAR:
1217: case S_CONSTANT: {
1218: sprintf(aline,"<<FACTORIAL ERROR>>");
1219: resultp->s_type = S_CONSTANT;
1220: resultp->s_str = strsave(aline);
1221: sprintf(tmpS,"%s()'s arg. cannot be of string type.\n",FuncStack[Func_idx].s_name);
1222: capa_msg(MESSAGE_ERROR,tmpS);
1223: }
1224: break;
1225: }
1226: } break;
1227: case MOD_F: break;
1228: case REMAINDER_F: break;
1229: case MAX_F:
1230: case MIN_F: { int ii, idx, type;
1231:
1232: tmpArgp = argp;
1233: tmpA = ((func == MIN_F)? MAX_DOUBLE : - MAX_DOUBLE);
1234: type = R_CONSTANT; idx = -1;
1235: noError = 1;
1236: for(ii = 0; (ii < argc)&&(noError); ii++) {
1237: switch (FIRST_ARGTYPE(tmpArgp)) {
1238: case I_VAR:
1239: case I_CONSTANT:
1240: if( type == S_CONSTANT) {
1241: sprintf(aline,"<<ARG TYPE>>");
1242: resultp->s_type = S_CONSTANT;
1243: resultp->s_str = strsave(aline);
1244: sprintf(tmpS,"%s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1245: capa_msg(MESSAGE_ERROR,tmpS);
1246: noError = 0;
1247: } else {
1248: switch(func) {
1249: case MIN_F:
1250: if( tmpA <= FIRST_ARGINT(tmpArgp) ) {
1251: } else {
1252: idx = ii; type = I_CONSTANT;
1253: tmpA = (double)FIRST_ARGINT(tmpArgp);
1254: }
1255: break;
1256: case MAX_F:
1257: if( tmpA >= FIRST_ARGINT(tmpArgp) ) {
1258: } else {
1259: idx = ii; type = I_CONSTANT;
1260: tmpA = (double)FIRST_ARGINT(tmpArgp);
1261: }
1262: break;
1263: }
1264: }
1265: break;
1266: case R_VAR:
1267: case R_CONSTANT:
1268: if( type == S_CONSTANT ) {
1269: sprintf(aline,"<<ARG TYPE>>");
1270: resultp->s_type = S_CONSTANT;
1271: resultp->s_str = strsave(aline);
1272: sprintf(tmpS,"%s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1273: capa_msg(MESSAGE_ERROR,tmpS);
1274: noError = 0;
1275: } else {
1276: switch(func) {
1277: case MIN_F:
1278: if( tmpA <= FIRST_ARGREAL(tmpArgp) ) {
1279: } else {
1280: idx = ii; type = R_CONSTANT;
1281: tmpA = FIRST_ARGREAL(tmpArgp);
1282: }
1283: break;
1284: case MAX_F:
1285: if( tmpA >= FIRST_ARGREAL(tmpArgp) ) {
1286: } else {
1287: idx = ii; type = R_CONSTANT;
1288: tmpA = FIRST_ARGREAL(tmpArgp);
1289: }
1290: break;
1291: }
1292: }
1293: break;
1294: case S_VAR:
1295: case S_CONSTANT:
1296: if( (ii != 0)&&(type != S_CONSTANT) ) {
1297: sprintf(aline,"<<ARG TYPE>>");
1298: resultp->s_type = S_CONSTANT;
1299: resultp->s_str = strsave(aline);
1300: sprintf(tmpS," %s()'s arg. type cannot mix string with int or real.\n",FuncStack[Func_idx].s_name);
1301: capa_msg(MESSAGE_ERROR,tmpS);
1302: noError = 0;
1303: } else {
1304: if( ii == 0 ) { idx = 0; strcpy(tmpS, FIRST_ARGSTR(tmpArgp)); }
1305: type = S_CONSTANT;
1306: switch( func) {
1307: case MIN_F:
1308: if( strcmp(tmpS, FIRST_ARGSTR(tmpArgp)) <= 0 ) {
1309: } else {
1310: idx = ii;
1311: strcpy(tmpS, FIRST_ARGSTR(tmpArgp));
1312: }
1313: break;
1314: case MAX_F:
1315: if( strcmp(tmpS, FIRST_ARGSTR(tmpArgp)) >= 0 ) {
1316: } else {
1317: idx = ii;
1318: strcpy(tmpS, FIRST_ARGSTR(tmpArgp));
1319: }
1320: break;
1321: }
1322: }
1323: break;
1324: }
1325: tmpArgp = tmpArgp->a_next;
1326: }
1327: if( noError ) {
1328: for(tmpArgp=argp,ii=0; ii<idx; ii++) { tmpArgp=tmpArgp->a_next; }
1329: resultp->s_type = type;
1330: switch(type) {
1331: case I_CONSTANT: resultp->s_int = (tmpArgp->a_sp)->s_int;
1332: break;
1333: case R_CONSTANT: resultp->s_real = (tmpArgp->a_sp)->s_real;
1334: break;
1335: case S_CONSTANT: resultp->s_str = strsave((tmpArgp->a_sp)->s_str);
1336: break;
1337: }
1338: }
1339:
1340: }
1341: break;
1342: case ROUNDTO_F: {
1343: noError = 1; hh = 0; /* reuse integer hh and mm */
1344: switch(FIRST_ARGTYPE(argp)) {
1345: case I_VAR:
1346: case I_CONSTANT: mm = FIRST_ARGINT(argp); break;
1347: case R_VAR:
1348: case R_CONSTANT: mm = (int)FIRST_ARGREAL(argp); break;
1349: case S_VAR:
1350: case S_CONSTANT: noError = 0;
1351: resultp->s_type = S_CONSTANT;
1352: resultp->s_str = strsave("<<MIS TYPE>>");
1353: sprintf(tmpS,
1354: "%s()'s second arg. cannot be string.\n",FuncStack[Func_idx].s_name);
1355: capa_msg(MESSAGE_ERROR,tmpS);
1356: break;
1357: }
1358: switch(SECOND_ARGTYPE(argp)) {
1359: case I_VAR:
1360: case I_CONSTANT: hh = SECOND_ARGINT(argp); break;
1361: case R_VAR:
1362: case R_CONSTANT: tmpA = SECOND_ARGREAL(argp); break;
1363: case S_VAR:
1364: case S_CONSTANT: noError = 0;
1365: resultp->s_type = S_CONSTANT;
1366: resultp->s_str = strsave("<<MIS TYPE>>");
1367: sprintf(tmpS,
1368: "%s()'s first arg. cannot be string.\n",
1369: FuncStack[Func_idx].s_name);
1370: capa_msg(MESSAGE_ERROR,tmpS);
1371: break;
1372: }
1373: if(noError) {
1374: resultp->s_type = R_CONSTANT;
1375: if( hh != 0 ) {
1376: resultp->s_type = I_CONSTANT;
1377: resultp->s_int = hh;
1378: } else {
1379: if ( mm >= 0 ) {
1380: sprintf(fmt_str,"%%.%df",mm);
1381: sprintf(num_str,fmt_str,tmpA);
1382: tmpB = atof(num_str);
1383: resultp->s_real = tmpB;
1384: } else {
1385: sprintf(tmpS,"%s()'s second arg. cannot be negative (%d).\n",
1386: FuncStack[Func_idx].s_name,mm);
1387: capa_msg(MESSAGE_ERROR,tmpS);
1388: resultp->s_real = tmpA; /* not changed */
1389: }
1390: }
1391: }
1392: } break;
1393: case EVALUATE_F: { char *f_str, *v_str, *pt_str, *out_come;
1394: noError = 1;
1395: switch(FIRST_ARGTYPE(argp)) { /* now only accepts string like "0.0,0.1,0.2,0.3,0.4,0.5" */
1396: case I_VAR:
1397: case I_CONSTANT: noError = 0;
1398: resultp->s_type = S_CONSTANT;
1399: resultp->s_str = strsave("<<Evaulate Formula: Pts TYPE incorrect>>");
1400: sprintf(tmpS,
1401: "%s()'s third arg. cannot be integer.\n",FuncStack[Func_idx].s_name);
1402: capa_msg(MESSAGE_ERROR,tmpS);
1403: break;
1404: case R_VAR:
1405: case R_CONSTANT: noError = 0;
1406: resultp->s_type = S_CONSTANT;
1407: resultp->s_str = strsave("<<Evaulate Formula: Pts TYPE incorrect>>");
1408: sprintf(tmpS,
1409: "%s()'s third arg. cannot be integer.\n",FuncStack[Func_idx].s_name);
1410: capa_msg(MESSAGE_ERROR,tmpS);
1411: break;
1412: case S_VAR:
1413: case S_CONSTANT:
1414: pt_str = FIRST_ARGSTR(argp);
1415: break;
1416: }
1417: switch(SECOND_ARGTYPE(argp)) {
1418: case I_VAR:
1419: case I_CONSTANT:
1420: case R_VAR:
1421: case R_CONSTANT: noError = 0;
1422: resultp->s_type = S_CONSTANT;
1423: resultp->s_str = strsave("<<Evaluate Formula: Var list TYPE incorrect>>");
1424: sprintf(tmpS,
1425: "%s()'s second arg. cannot be number.\n",FuncStack[Func_idx].s_name);
1426: capa_msg(MESSAGE_ERROR,tmpS);
1427: break;
1428:
1429: case S_VAR:
1430: case S_CONSTANT: v_str = SECOND_ARGSTR(argp);
1431: break;
1432: }
1433: switch(THIRD_ARGTYPE(argp)) {
1434: case I_VAR:
1435: case I_CONSTANT:
1436: case R_VAR:
1437: case R_CONSTANT: noError = 0;
1438: resultp->s_type = S_CONSTANT;
1439: resultp->s_str = strsave("<<Evaluate Formula: Formula TYPE incorrect>>");
1440: sprintf(tmpS,
1441: "%s()'s first arg. cannot be number.\n",FuncStack[Func_idx].s_name);
1442: capa_msg(MESSAGE_ERROR,tmpS);
1443: break;
1444: case S_VAR:
1445: case S_CONSTANT: f_str = THIRD_ARGSTR(argp);
1446: break;
1447: }
1448: if(noError) {
1449: resultp->s_type = S_CONSTANT;
1450: /* printf("EVALUATE:::%s,%s,%s\n",f_str, v_str, pt_str); */
1451: out_come = eval_formula_range_str(f_str, v_str, pt_str);
1452: if( !out_come ) {
1453: resultp->s_str = strsave("<<Evaluate formula:: NULL>>");
1454: sprintf(tmpS,
1455: "%s() cannot evaluate the formula correctly.\n",FuncStack[Func_idx].s_name);
1456: capa_msg(MESSAGE_ERROR,tmpS);
1457: } else {
1458: resultp->s_str = out_come;
1459: }
1460: }
1461: }
1462: break;
1463: case CAPAID_PLUS:
1464: {
1465: extern Problem_t* FirstProblem_p;
1466: extern Problem_t* LexiProblem_p;
1467: Problem_t* problem;
1468: int num_char,pin;
1469: errCode = 0;
1470: if (argc==1) {
1471: switch( FIRST_ARGTYPE(argp) ) {
1472: case I_VAR: case I_CONSTANT: num_char=FIRST_ARGINT(argp); break;
1473: case R_VAR: case R_CONSTANT: errCode = 1; break;
1474: case S_VAR: case S_CONSTANT: errCode = 1; break;
1475: }
1476: } else {
1477: switch( SECOND_ARGTYPE(argp) ) {
1478: case I_VAR: case I_CONSTANT: num_char=SECOND_ARGINT(argp); break;
1479: case R_VAR: case R_CONSTANT: errCode = 1; break;
1480: case S_VAR: case S_CONSTANT: errCode = 1; break;
1481: }
1482: }
1483:
1484: if( errCode == 0 ) {
1485: if ( FirstProblem_p ) {
1486: problem=FirstProblem_p;
1487: } else {
1488: problem=LexiProblem_p;
1489: }
1490: if (!(problem->capaidplus)) capa_mfree(problem->capaidplus);
1491: if (-1==(tmpInt=which_set(argc-1,argp,resultp))) break;
1492: pin=capa_PIN(Parse_student_number,tmpInt,0);
1493: problem->capaidplus = capa_id_plus(Parse_student_number,
1494: tmpInt,num_char);
1495: resultp->s_type = S_CONSTANT;
1496: resultp->s_str = strsave(problem->capaidplus);
1497: } else {
1498: resultp->s_type = S_CONSTANT;
1499: resultp->s_str = strsave("<<INCORRECT ARGS TO CAPAID_PLUS>>");
1500: }
1501: }
1502: break;
1503: case SEAT_NUMBER:
1504: {
1505: int filenum;
1506: double filedoub;
1507: char *filename;
1508: if ( argc == 1 ) {
1509: switch( FIRST_ARGTYPE(argp)) {
1510: case I_VAR: case I_CONSTANT: filenum=FIRST_ARGINT(argp);
1511: filename=capa_malloc(TMP_LINE_LENGTH,1);
1512: sprintf(filename,"%d",filenum);
1513: break;
1514: case R_VAR: case R_CONSTANT: filedoub=FIRST_ARGREAL(argp);
1515: filename=capa_malloc(TMP_LINE_LENGTH,1);
1516: sprintf(filename,"%f",filedoub);
1517: break;
1518: case S_VAR: case S_CONSTANT:
1519: filename=strsave(FIRST_ARGSTR(argp)); break;
1520: }
1521: } else {
1522: filename=NULL;
1523: }
1524: resultp->s_type = S_CONSTANT;
1525: resultp->s_str = capa_get_seat(Parse_student_number,filename);
1526: if ( filename != NULL ) capa_mfree(filename);
1527: break;
1528: }
1529: case DURATION: { resultp->s_type = I_CONSTANT;
1530: resultp->s_int=capa_get_duration(Parse_student_number,
1531: Parse_section,Parse_set);
1532: } break;
1.3 albertel 1533: case MANAGERMODE_F: { resultp->s_type = I_CONSTANT;
1534: resultp->s_int=managermode;
1535: }break;
1536: case CORRECT_F: {
1537:
1538: }break;
1539:
1540: case TRIES_F: {
1541:
1542: }break;
1543:
1544: case GRADE_F: {
1545:
1546: }break;
1547:
1.1 albertel 1548: case MIS_ARG_COUNT:
1549: { resultp->s_type = S_CONSTANT;
1550: resultp->s_str = strsave("<<ARG COUNT>>");
1.3 albertel 1551: sprintf(tmpS,"%s()'s arg. count is not correct.\n",
1552: FuncStack[Func_idx].s_name);
1.1 albertel 1553: capa_msg(MESSAGE_ERROR,tmpS);
1554: } break;
1555: case UNKNOWN_F:
1556: default: { resultp->s_type = S_CONSTANT;
1557: resultp->s_str = strsave("<<UNKNOWN FUNCTION>>");
1558: sprintf(tmpS,"%s() unknown.\n",FuncStack[Func_idx].s_name);
1559: capa_msg(MESSAGE_ERROR,tmpS);
1560:
1561: } break;
1562: }
1563:
1564: return (resultp);
1565: }
1566:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>