1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: generate iparith.inc etc. |
---|
6 | */ |
---|
7 | |
---|
8 | #include <stdlib.h> |
---|
9 | #include <string.h> |
---|
10 | #include <ctype.h> |
---|
11 | #include <stdio.h> |
---|
12 | #include <time.h> |
---|
13 | #include <unistd.h> |
---|
14 | #include <sys/types.h> |
---|
15 | #include <sys/stat.h> |
---|
16 | |
---|
17 | // need global defines: |
---|
18 | #include "kernel/mod2.h" |
---|
19 | // need to include all tokens: *_CMD: |
---|
20 | #include "grammar.h" |
---|
21 | #include "tok.h" |
---|
22 | |
---|
23 | // to produce convert_table.texi for doc: |
---|
24 | #define CONVERT_TABLE 1 |
---|
25 | |
---|
26 | // bits 0,1 for PLURAL |
---|
27 | #define NO_PLURAL 0 |
---|
28 | #define ALLOW_PLURAL 1 |
---|
29 | #define COMM_PLURAL 2 |
---|
30 | #define PLURAL_MASK 3 |
---|
31 | |
---|
32 | // bit 2 for RING-CF |
---|
33 | #define ALLOW_RING 4 |
---|
34 | #define NO_RING 0 |
---|
35 | |
---|
36 | // bit 3 for zerodivisors |
---|
37 | #define NO_ZERODIVISOR 8 |
---|
38 | #define ALLOW_ZERODIVISOR 0 |
---|
39 | #define ZERODIVISOR_MASK 8 |
---|
40 | |
---|
41 | // bit 4 for warning, if used at toplevel |
---|
42 | #define WARN_RING 16 |
---|
43 | |
---|
44 | /*=============== types =====================*/ |
---|
45 | struct _scmdnames |
---|
46 | { |
---|
47 | const char *name; |
---|
48 | short alias; |
---|
49 | short tokval; |
---|
50 | short toktype; |
---|
51 | }; |
---|
52 | typedef struct _scmdnames cmdnames; |
---|
53 | |
---|
54 | |
---|
55 | struct sValCmd2 |
---|
56 | { |
---|
57 | int p; |
---|
58 | short cmd; |
---|
59 | short res; |
---|
60 | short arg1; |
---|
61 | short arg2; |
---|
62 | short valid_for; |
---|
63 | }; |
---|
64 | struct sValCmd1 |
---|
65 | { |
---|
66 | int p; |
---|
67 | short cmd; |
---|
68 | short res; |
---|
69 | short arg; |
---|
70 | short valid_for; |
---|
71 | }; |
---|
72 | struct sValCmd3 |
---|
73 | { |
---|
74 | int p; |
---|
75 | short cmd; |
---|
76 | short res; |
---|
77 | short arg1; |
---|
78 | short arg2; |
---|
79 | short arg3; |
---|
80 | short valid_for; |
---|
81 | }; |
---|
82 | struct sValCmdM |
---|
83 | { |
---|
84 | int p; |
---|
85 | short cmd; |
---|
86 | short res; |
---|
87 | short number_of_args; /* -1: any, -2: any >0, .. */ |
---|
88 | short valid_for; |
---|
89 | }; |
---|
90 | struct sValAssign_sys |
---|
91 | { |
---|
92 | int p; |
---|
93 | short res; |
---|
94 | short arg; |
---|
95 | }; |
---|
96 | |
---|
97 | struct sValAssign |
---|
98 | { |
---|
99 | int p; |
---|
100 | short res; |
---|
101 | short arg; |
---|
102 | }; |
---|
103 | |
---|
104 | struct sConvertTypes |
---|
105 | { |
---|
106 | int i_typ; |
---|
107 | int o_typ; |
---|
108 | int p; |
---|
109 | int pl; |
---|
110 | }; |
---|
111 | |
---|
112 | |
---|
113 | #define jjWRONG 1 |
---|
114 | #define jjWRONG2 1 |
---|
115 | #define jjWRONG3 1 |
---|
116 | |
---|
117 | #define D(A) 2 |
---|
118 | #define NULL_VAL 0 |
---|
119 | #define IPARITH |
---|
120 | #define GENTABLE |
---|
121 | #define IPCONV |
---|
122 | #define IPASSIGN |
---|
123 | |
---|
124 | #include "table.h" |
---|
125 | |
---|
126 | const char * Tok2Cmdname(int tok) |
---|
127 | { |
---|
128 | int i = 0; |
---|
129 | if (tok < 0) |
---|
130 | { |
---|
131 | return cmds[0].name; |
---|
132 | } |
---|
133 | if (tok==COMMAND) return "command"; |
---|
134 | if (tok==ANY_TYPE) return "any_type"; |
---|
135 | if (tok==NONE) return "nothing"; |
---|
136 | //if (tok==IFBREAK) return "if_break"; |
---|
137 | //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys"; |
---|
138 | //if (tok==ORDER_VECTOR) return "ordering"; |
---|
139 | //if (tok==REF_VAR) return "ref"; |
---|
140 | //if (tok==OBJECT) return "object"; |
---|
141 | //if (tok==PRINT_EXPR) return "print_expr"; |
---|
142 | if (tok==IDHDL) return "identifier"; |
---|
143 | // we do not blackbox objects during table generation: |
---|
144 | //if (tok>MAX_TOK) return getBlackboxName(tok); |
---|
145 | while (cmds[i].tokval!=0) |
---|
146 | { |
---|
147 | if ((cmds[i].tokval == tok)&&(cmds[i].alias==0)) |
---|
148 | { |
---|
149 | return cmds[i].name; |
---|
150 | } |
---|
151 | i++; |
---|
152 | } |
---|
153 | return cmds[0].name; |
---|
154 | } |
---|
155 | /*---------------------------------------------------------------------*/ |
---|
156 | /** |
---|
157 | * @brief compares to entry of cmdsname-list |
---|
158 | |
---|
159 | @param[in] a |
---|
160 | @param[in] b |
---|
161 | |
---|
162 | @return <ReturnValue> |
---|
163 | **/ |
---|
164 | /*---------------------------------------------------------------------*/ |
---|
165 | static int _gentable_sort_cmds( const void *a, const void *b ) |
---|
166 | { |
---|
167 | cmdnames *pCmdL = (cmdnames*)a; |
---|
168 | cmdnames *pCmdR = (cmdnames*)b; |
---|
169 | |
---|
170 | if(a==NULL || b==NULL) return 0; |
---|
171 | |
---|
172 | /* empty entries goes to the end of the list for later reuse */ |
---|
173 | if(pCmdL->name==NULL) return 1; |
---|
174 | if(pCmdR->name==NULL) return -1; |
---|
175 | |
---|
176 | /* $INVALID$ must come first */ |
---|
177 | if(strcmp(pCmdL->name, "$INVALID$")==0) return -1; |
---|
178 | if(strcmp(pCmdR->name, "$INVALID$")==0) return 1; |
---|
179 | |
---|
180 | /* tokval=-1 are reserved names at the end */ |
---|
181 | if (pCmdL->tokval==-1) |
---|
182 | { |
---|
183 | if (pCmdR->tokval==-1) |
---|
184 | return strcmp(pCmdL->name, pCmdR->name); |
---|
185 | /* pCmdL->tokval==-1, pCmdL goes at the end */ |
---|
186 | return 1; |
---|
187 | } |
---|
188 | /* pCmdR->tokval==-1, pCmdR goes at the end */ |
---|
189 | if(pCmdR->tokval==-1) return -1; |
---|
190 | |
---|
191 | return strcmp(pCmdL->name, pCmdR->name); |
---|
192 | } |
---|
193 | |
---|
194 | static int _texi_sort_cmds( const void *a, const void *b ) |
---|
195 | { |
---|
196 | cmdnames *pCmdL = (cmdnames*)a; |
---|
197 | cmdnames *pCmdR = (cmdnames*)b; |
---|
198 | |
---|
199 | if(a==NULL || b==NULL) return 0; |
---|
200 | |
---|
201 | /* empty entries goes to the end of the list for later reuse */ |
---|
202 | if(pCmdL->name==NULL) return 1; |
---|
203 | if(pCmdR->name==NULL) return -1; |
---|
204 | |
---|
205 | /* $INVALID$ must come first */ |
---|
206 | if(strcmp(pCmdL->name, "$INVALID$")==0) return -1; |
---|
207 | if(strcmp(pCmdR->name, "$INVALID$")==0) return 1; |
---|
208 | char *ls=strdup(pCmdL->name); |
---|
209 | char *rs=strdup(pCmdR->name); |
---|
210 | char *s=ls; |
---|
211 | while (*s) { *s=tolower(*s); s++; } |
---|
212 | s=rs; |
---|
213 | while (*s) { *s=tolower(*s); s++; } |
---|
214 | |
---|
215 | /* tokval=-1 are reserved names at the end */ |
---|
216 | if (pCmdL->tokval==-1) |
---|
217 | { |
---|
218 | if (pCmdR->tokval==-1) |
---|
219 | { int r=strcmp(ls,rs); free(ls); free(rs); return r; } |
---|
220 | /* pCmdL->tokval==-1, pCmdL goes at the end */ |
---|
221 | free(ls);free(rs); |
---|
222 | return 1; |
---|
223 | } |
---|
224 | /* pCmdR->tokval==-1, pCmdR goes at the end */ |
---|
225 | if(pCmdR->tokval==-1) |
---|
226 | { free(ls);free(rs);return -1;} |
---|
227 | |
---|
228 | { int r=strcmp(ls,rs); free(ls); free(rs); return r; } |
---|
229 | } |
---|
230 | |
---|
231 | /*generic*/ |
---|
232 | const char * iiTwoOps(int t) |
---|
233 | { |
---|
234 | if (t<127) |
---|
235 | { |
---|
236 | static char ch[2]; |
---|
237 | switch (t) |
---|
238 | { |
---|
239 | case '&': |
---|
240 | return "and"; |
---|
241 | case '|': |
---|
242 | return "or"; |
---|
243 | default: |
---|
244 | ch[0]=t; |
---|
245 | ch[1]='\0'; |
---|
246 | return ch; |
---|
247 | } |
---|
248 | } |
---|
249 | switch (t) |
---|
250 | { |
---|
251 | case COLONCOLON: return "::"; |
---|
252 | case DOTDOT: return ".."; |
---|
253 | //case PLUSEQUAL: return "+="; |
---|
254 | //case MINUSEQUAL: return "-="; |
---|
255 | case MINUSMINUS: return "--"; |
---|
256 | case PLUSPLUS: return "++"; |
---|
257 | case EQUAL_EQUAL: return "=="; |
---|
258 | case LE: return "<="; |
---|
259 | case GE: return ">="; |
---|
260 | case NOTEQUAL: return "<>"; |
---|
261 | default: return Tok2Cmdname(t); |
---|
262 | } |
---|
263 | } |
---|
264 | // |
---|
265 | // automatic conversions: |
---|
266 | // |
---|
267 | /*2 |
---|
268 | * try to convert 'inputType' in 'outputType' |
---|
269 | * return 0 on failure, an index (<>0) on success |
---|
270 | */ |
---|
271 | int iiTestConvert (int inputType, int outputType) |
---|
272 | { |
---|
273 | if ((inputType==outputType) |
---|
274 | || (outputType==DEF_CMD) |
---|
275 | || (outputType==IDHDL) |
---|
276 | || (outputType==ANY_TYPE)) |
---|
277 | { |
---|
278 | return -1; |
---|
279 | } |
---|
280 | |
---|
281 | // search the list |
---|
282 | int i=0; |
---|
283 | while (dConvertTypes[i].i_typ!=0) |
---|
284 | { |
---|
285 | if((dConvertTypes[i].i_typ==inputType) |
---|
286 | &&(dConvertTypes[i].o_typ==outputType)) |
---|
287 | { |
---|
288 | //Print("test convert %d to %d (%s -> %s):%d\n",inputType,outputType, |
---|
289 | //Tok2Cmdname(inputType), Tok2Cmdname(outputType),i+1); |
---|
290 | return i+1; |
---|
291 | } |
---|
292 | i++; |
---|
293 | } |
---|
294 | //Print("test convert %d to %d (%s -> %s):0\n",inputType,outputType, |
---|
295 | // Tok2Cmdname(inputType), Tok2Cmdname(outputType)); |
---|
296 | return 0; |
---|
297 | } |
---|
298 | char *iparith_inc; |
---|
299 | void ttGen1() |
---|
300 | { |
---|
301 | iparith_inc=strdup("iparith.xxxxxx"); |
---|
302 | int pid=getpid(); |
---|
303 | iparith_inc[8]=(pid %10)+'0'; pid/=10; |
---|
304 | iparith_inc[9]=(pid %10)+'0'; pid/=10; |
---|
305 | iparith_inc[10]=(pid %10)+'0'; pid/=10; |
---|
306 | iparith_inc[11]=(pid %10)+'0'; pid/=10; |
---|
307 | iparith_inc[12]=(pid %10)+'0'; pid/=10; |
---|
308 | iparith_inc[13]=(pid %10)+'0'; |
---|
309 | FILE *outfile = fopen(iparith_inc,"w"); |
---|
310 | int i,j,l1=0,l2=0; |
---|
311 | fprintf(outfile, |
---|
312 | "/****************************************\n" |
---|
313 | "* Computer Algebra System SINGULAR *\n" |
---|
314 | "****************************************/\n\n"); |
---|
315 | /*-------------------------------------------------------------------*/ |
---|
316 | fprintf(outfile,"// syntax table for Singular\n//\n"); |
---|
317 | fprintf(outfile,"// - search for an exact match of the argument types\n"); |
---|
318 | fprintf(outfile,"// - otherwise search for the first possibility\n"); |
---|
319 | fprintf(outfile,"// with converted types of the arguments\n"); |
---|
320 | fprintf(outfile,"// - otherwise report an error\n//\n"); |
---|
321 | |
---|
322 | int op; |
---|
323 | i=0; |
---|
324 | while ((op=dArith1[i].cmd)!=0) |
---|
325 | { |
---|
326 | if (dArith1[i].p==jjWRONG) |
---|
327 | fprintf(outfile,"// DUMMY "); |
---|
328 | const char *s = iiTwoOps(op); |
---|
329 | fprintf(outfile,"// operation: %s (%s) -> %s\n", |
---|
330 | s, |
---|
331 | Tok2Cmdname(dArith1[i].arg), |
---|
332 | Tok2Cmdname(dArith1[i].res)); |
---|
333 | i++; |
---|
334 | } |
---|
335 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
336 | i=0; |
---|
337 | while ((op=dArith2[i].cmd)!=0) |
---|
338 | { |
---|
339 | if (dArith2[i].p==jjWRONG2) |
---|
340 | fprintf(outfile,"// DUMMY "); |
---|
341 | const char *s = iiTwoOps(op); |
---|
342 | fprintf(outfile,"// operation: %s (%s, %s) -> %s\n", |
---|
343 | s, |
---|
344 | Tok2Cmdname(dArith2[i].arg1), |
---|
345 | Tok2Cmdname(dArith2[i].arg2), |
---|
346 | Tok2Cmdname(dArith2[i].res)); |
---|
347 | i++; |
---|
348 | } |
---|
349 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
350 | i=0; |
---|
351 | while ((op=dArith3[i].cmd)!=0) |
---|
352 | { |
---|
353 | const char *s = iiTwoOps(op); |
---|
354 | if (dArith3[i].p==jjWRONG3) |
---|
355 | fprintf(outfile,"// DUMMY "); |
---|
356 | fprintf(outfile,"// operation: %s (%s, %s, %s) -> %s\n", |
---|
357 | s, |
---|
358 | Tok2Cmdname(dArith3[i].arg1), |
---|
359 | Tok2Cmdname(dArith3[i].arg2), |
---|
360 | Tok2Cmdname(dArith3[i].arg3), |
---|
361 | Tok2Cmdname(dArith3[i].res)); |
---|
362 | i++; |
---|
363 | } |
---|
364 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
365 | i=0; |
---|
366 | while ((op=dArithM[i].cmd)!=0) |
---|
367 | { |
---|
368 | const char *s = iiTwoOps(op); |
---|
369 | fprintf(outfile,"// operation: %s (...) -> %s", |
---|
370 | s, |
---|
371 | Tok2Cmdname(dArithM[i].res)); |
---|
372 | switch(dArithM[i].number_of_args) |
---|
373 | { |
---|
374 | case -2: |
---|
375 | fprintf(outfile," ( number of arguments >0 )\n"); |
---|
376 | break; |
---|
377 | case -1: |
---|
378 | fprintf(outfile," ( any number of arguments )\n"); |
---|
379 | break; |
---|
380 | default: |
---|
381 | fprintf(outfile," ( %d arguments )\n",dArithM[i].number_of_args); |
---|
382 | break; |
---|
383 | } |
---|
384 | i++; |
---|
385 | } |
---|
386 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
387 | i=0; |
---|
388 | while ((op=dAssign[i].res)!=0) |
---|
389 | { |
---|
390 | fprintf(outfile,"// assign: %s = %s\n", |
---|
391 | Tok2Cmdname(op/*dAssign[i].res*/), |
---|
392 | Tok2Cmdname(dAssign[i].arg)); |
---|
393 | i++; |
---|
394 | } |
---|
395 | /*-------------------------------------------------------------------*/ |
---|
396 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
397 | #ifdef CONVERT_TABLE |
---|
398 | FILE *doctable=fopen("convert_table.texi","w"); |
---|
399 | fprintf(doctable,"@multitable @columnfractions .05 .18 .81\n"); |
---|
400 | int doc_nr=1; |
---|
401 | #endif |
---|
402 | for (j=257;j<=MAX_TOK+1;j++) |
---|
403 | { |
---|
404 | for(i=257;i<=MAX_TOK+1;i++) |
---|
405 | { |
---|
406 | if ((i!=j) && (j!=IDHDL) && (j!=DEF_CMD) && (j!=ANY_TYPE) |
---|
407 | && iiTestConvert(i,j)) |
---|
408 | { |
---|
409 | fprintf(outfile,"// convert %s -> %s\n", |
---|
410 | Tok2Cmdname(i), Tok2Cmdname(j)); |
---|
411 | #ifdef CONVERT_TABLE |
---|
412 | fprintf(doctable, |
---|
413 | "@item\n@ %d. @tab @code{%s} @tab @expansion{} @code{%s}\n", |
---|
414 | doc_nr,Tok2Cmdname(i),Tok2Cmdname(j)); |
---|
415 | doc_nr++; |
---|
416 | #endif |
---|
417 | if (j==ANY_TYPE) break; |
---|
418 | } |
---|
419 | } |
---|
420 | } |
---|
421 | #ifdef CONVERT_TABLE |
---|
422 | fprintf(doctable,"@end multitable\n"); |
---|
423 | fclose(doctable); |
---|
424 | #endif |
---|
425 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
426 | char ops[]="=><+*/[.^,%(;"; |
---|
427 | for(i=0;ops[i]!='\0';i++) |
---|
428 | fprintf(outfile,"// token %d : %c\n", (int)ops[i], ops[i]); |
---|
429 | for (i=257;i<=MAX_TOK;i++) |
---|
430 | { |
---|
431 | const char *s=iiTwoOps(i); |
---|
432 | if (s[0]!='$') |
---|
433 | { |
---|
434 | fprintf(outfile,"// token %d : %s\n", i, s); |
---|
435 | } |
---|
436 | } |
---|
437 | /*-------------------------------------------------------------------*/ |
---|
438 | fprintf(outfile,"/*--max. token: %d, gr: %d --*/\n",MAX_TOK,UMINUS); |
---|
439 | /*-------------------------------------------------------------------*/ |
---|
440 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
441 | fprintf(outfile, |
---|
442 | "struct sValCmdTab dArithTab1[]=\n" |
---|
443 | "{\n"); |
---|
444 | for (j=1;j<=MAX_TOK+1;j++) |
---|
445 | { |
---|
446 | for(i=0;dArith1[i].cmd!=0;i++) |
---|
447 | { |
---|
448 | if (dArith1[i].cmd==j) |
---|
449 | { |
---|
450 | fprintf(outfile," { %d,%d },\n",j,i); |
---|
451 | l1++; |
---|
452 | break; |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | fprintf(outfile," { 10000,0 }\n};\n"); |
---|
457 | fprintf(outfile,"#define JJTAB1LEN %d\n",l1); |
---|
458 | /*-------------------------------------------------------------------*/ |
---|
459 | fprintf(outfile, |
---|
460 | "struct sValCmdTab dArithTab2[]=\n" |
---|
461 | "{\n"); |
---|
462 | for (j=1;j<=MAX_TOK+1;j++) |
---|
463 | { |
---|
464 | for(i=0;dArith2[i].cmd!=0;i++) |
---|
465 | { |
---|
466 | if (dArith2[i].cmd==j) |
---|
467 | { |
---|
468 | fprintf(outfile," { %d,%d },\n",j,i); |
---|
469 | l2++; |
---|
470 | break; |
---|
471 | } |
---|
472 | } |
---|
473 | } |
---|
474 | fprintf(outfile," { 10000,0 }\n};\n"); |
---|
475 | fprintf(outfile,"#define JJTAB2LEN %d\n",l2); |
---|
476 | fclose(outfile); |
---|
477 | } |
---|
478 | /*---------------------------------------------------------------------*/ |
---|
479 | /** |
---|
480 | * @brief generate cmds initialisation |
---|
481 | **/ |
---|
482 | /*---------------------------------------------------------------------*/ |
---|
483 | |
---|
484 | void ttGen2b() |
---|
485 | { |
---|
486 | int cmd_size = (sizeof(cmds)/sizeof(cmdnames))-1; |
---|
487 | |
---|
488 | FILE *outfile = fopen(iparith_inc,"a"); |
---|
489 | fprintf(outfile, |
---|
490 | "/****************************************\n" |
---|
491 | "* Computer Algebra System SINGULAR *\n" |
---|
492 | "****************************************/\n\n"); |
---|
493 | /*-------------------------------------------------------------------*/ |
---|
494 | fprintf(outfile,"// identifier table for Singular\n//\n"); |
---|
495 | |
---|
496 | fprintf( |
---|
497 | outfile, |
---|
498 | "#ifdef MODULE_GENERATOR\n" |
---|
499 | "#define omAlloc0(A) malloc(A)\n" |
---|
500 | "#endif\n" |
---|
501 | "void iiInitCmdName()\n{\n" |
---|
502 | " sArithBase.nCmdUsed = 0;\n" |
---|
503 | " sArithBase.nCmdAllocated = %d;\n" |
---|
504 | " sArithBase.sCmds = (cmdnames*)omAlloc0(sArithBase.nCmdAllocated*sizeof(cmdnames));\n" |
---|
505 | "\n" |
---|
506 | " // name-string alias tokval toktype index\n", |
---|
507 | cmd_size); |
---|
508 | int m=0; |
---|
509 | int id_nr=0; |
---|
510 | |
---|
511 | qsort(&cmds, cmd_size, sizeof(cmdnames), (&_gentable_sort_cmds)); |
---|
512 | |
---|
513 | for(m=0; m<cmd_size; m++) |
---|
514 | { |
---|
515 | if(cmds[m].tokval>0) id_nr++; |
---|
516 | fprintf(outfile," iiArithAddCmd(\"%s\", %*d, %3d, ",cmds[m].name, |
---|
517 | (int)(20-strlen(cmds[m].name)), |
---|
518 | cmds[m].alias, |
---|
519 | cmds[m].tokval); |
---|
520 | switch(cmds[m].toktype) |
---|
521 | { |
---|
522 | case CMD_1: fprintf(outfile,"CMD_1"); break; |
---|
523 | case CMD_2: fprintf(outfile,"CMD_2"); break; |
---|
524 | case CMD_3: fprintf(outfile,"CMD_3"); break; |
---|
525 | case CMD_12: fprintf(outfile,"CMD_12"); break; |
---|
526 | case CMD_123 : fprintf(outfile,"CMD_123"); break; |
---|
527 | case CMD_23: fprintf(outfile,"CMD_23"); break; |
---|
528 | case CMD_M: fprintf(outfile,"CMD_M"); break; |
---|
529 | case SYSVAR: fprintf(outfile,"SYSVAR"); break; |
---|
530 | case ROOT_DECL: fprintf(outfile,"ROOT_DECL"); break; |
---|
531 | case ROOT_DECL_LIST: fprintf(outfile,"ROOT_DECL_LIST"); break; |
---|
532 | case RING_DECL: fprintf(outfile,"RING_DECL"); break; |
---|
533 | case NONE: fprintf(outfile,"NONE"); break; |
---|
534 | default: |
---|
535 | if((cmds[m].toktype>' ') &&(cmds[m].toktype<127)) |
---|
536 | { |
---|
537 | fprintf(outfile,"'%c'",cmds[m].toktype); |
---|
538 | } |
---|
539 | else |
---|
540 | { |
---|
541 | fprintf(outfile,"%d",cmds[m].toktype); |
---|
542 | } |
---|
543 | break; |
---|
544 | #if 0 |
---|
545 | fprintf(outfile," iiArithAddCmd(\"%s\", %*d, -1, 0 );\n", |
---|
546 | cmds[m].name, 20-strlen(cmds[m].name), |
---|
547 | 0/*cmds[m].alias*/ |
---|
548 | /*-1 cmds[m].tokval*/ |
---|
549 | /*0 cmds[m].toktype*/); |
---|
550 | #endif |
---|
551 | } |
---|
552 | fprintf(outfile,", %d);\n", m); |
---|
553 | } |
---|
554 | fprintf(outfile, "/* end of list marker */\n"); |
---|
555 | fprintf(outfile, |
---|
556 | " sArithBase.nLastIdentifier = %d;\n", |
---|
557 | id_nr); |
---|
558 | |
---|
559 | |
---|
560 | fprintf(outfile, |
---|
561 | "}\n" |
---|
562 | "#define LAST_IDENTIFIER %d\n" |
---|
563 | ,id_nr); |
---|
564 | fclose(outfile); |
---|
565 | } |
---|
566 | int is_ref_cmd(cmdnames *c) |
---|
567 | { |
---|
568 | if( c->tokval==0) return 0; |
---|
569 | if (c->alias > 0) return 0; |
---|
570 | if ((c->toktype==CMD_1) |
---|
571 | || (c->toktype==CMD_2) |
---|
572 | || (c->toktype==CMD_3) |
---|
573 | || (c->toktype==CMD_M) |
---|
574 | || (c->toktype==CMD_12) |
---|
575 | || (c->toktype==CMD_13) |
---|
576 | || (c->toktype==CMD_23) |
---|
577 | || (c->toktype==CMD_123)) return 1; |
---|
578 | return 0; |
---|
579 | } |
---|
580 | void ttGen2c() |
---|
581 | { |
---|
582 | int cmd_size = (sizeof(cmds)/sizeof(cmdnames))-1; |
---|
583 | |
---|
584 | FILE *outfile = fopen("reference_table.texi","w"); |
---|
585 | fprintf(outfile, "@menu\n"); |
---|
586 | /*-------------------------------------------------------------------*/ |
---|
587 | qsort(&cmds, cmd_size, sizeof(cmdnames), (&_texi_sort_cmds)); |
---|
588 | |
---|
589 | int m; |
---|
590 | for(m=0; m<cmd_size; m++) |
---|
591 | { |
---|
592 | // assume that cmds[0].tokval== -1 and all others with tokval -1 at the end |
---|
593 | if(is_ref_cmd(&(cmds[m]))) |
---|
594 | { |
---|
595 | fprintf(outfile,"* %s::\n",cmds[m].name); |
---|
596 | } |
---|
597 | } |
---|
598 | fprintf(outfile, "@end menu\n@c ---------------------------\n"); |
---|
599 | for(m=0; m<cmd_size; m++) |
---|
600 | { |
---|
601 | // assume that cmds[0].tokval== -1 and all others with tokval -1 at the end |
---|
602 | if(is_ref_cmd(&(cmds[m]))) |
---|
603 | { |
---|
604 | fprintf(outfile,"@node %s,",cmds[m].name); |
---|
605 | // next: |
---|
606 | int mm=m-1; |
---|
607 | while((mm>0)&& (is_ref_cmd(&cmds[mm]))) mm--; |
---|
608 | if((mm>0)&& (is_ref_cmd(&cmds[mm]))) |
---|
609 | fprintf(outfile,"%s,",cmds[mm].name); |
---|
610 | else |
---|
611 | fprintf(outfile,","); |
---|
612 | // prev: |
---|
613 | mm=m+1; |
---|
614 | while((mm>0)&& (is_ref_cmd(&cmds[mm]))) mm++; |
---|
615 | if((mm>0)&& (is_ref_cmd(&cmds[mm]))) |
---|
616 | fprintf(outfile,"%s,",cmds[m-1].name); |
---|
617 | else |
---|
618 | fprintf(outfile,","); |
---|
619 | // up:, and header |
---|
620 | fprintf(outfile,"Functions\n" |
---|
621 | "@subsection %s\n" |
---|
622 | "@cindex %s\n",cmds[m].name,cmds[m].name); |
---|
623 | fprintf(outfile,"@include %s.part\n",cmds[m].name); |
---|
624 | char partName[50]; |
---|
625 | sprintf(partName,"%s.part",cmds[m].name); |
---|
626 | struct stat buf; |
---|
627 | if (lstat(partName,&buf)!=0) |
---|
628 | { |
---|
629 | int op,i; |
---|
630 | int only_field=0,only_comm=0,no_zerodiv=0; |
---|
631 | FILE *part=fopen(partName,"w"); |
---|
632 | fprintf(part,"@table @code\n@item @strong{Syntax:}\n"); |
---|
633 | if ((cmds[m].toktype==CMD_1) |
---|
634 | || (cmds[m].toktype==CMD_12) |
---|
635 | || (cmds[m].toktype==CMD_13) |
---|
636 | || (cmds[m].toktype==CMD_123)) |
---|
637 | { |
---|
638 | op= cmds[m].tokval; |
---|
639 | i=0; |
---|
640 | while ((dArith1[i].cmd!=op) && (dArith1[i].cmd!=0)) i++; |
---|
641 | while (dArith1[i].cmd==op) |
---|
642 | { |
---|
643 | if (dArith1[i].p!=jjWRONG) |
---|
644 | { |
---|
645 | fprintf(part,"@code{%s (} %s @code{)}\n",cmds[m].name,Tok2Cmdname(dArith1[i].arg)); |
---|
646 | fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith1[i].res)); |
---|
647 | if ((dArith1[i].valid_for & ALLOW_PLURAL)==0) |
---|
648 | only_comm=1; |
---|
649 | if ((dArith1[i].valid_for & ALLOW_RING)==0) |
---|
650 | only_field=1; |
---|
651 | if ((dArith1[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR) |
---|
652 | no_zerodiv=1; |
---|
653 | } |
---|
654 | i++; |
---|
655 | } |
---|
656 | } |
---|
657 | if ((cmds[m].toktype==CMD_23) |
---|
658 | || (cmds[m].toktype==CMD_12) |
---|
659 | || (cmds[m].toktype==CMD_2) |
---|
660 | || (cmds[m].toktype==CMD_123)) |
---|
661 | { |
---|
662 | op= cmds[m].tokval; |
---|
663 | i=0; |
---|
664 | while ((dArith2[i].cmd!=op) && (dArith2[i].cmd!=0)) i++; |
---|
665 | while (dArith2[i].cmd==op) |
---|
666 | { |
---|
667 | if (dArith2[i].p!=jjWRONG) |
---|
668 | { |
---|
669 | fprintf(part,"@code{%s (} %s, %s @code{)}\n",cmds[m].name,Tok2Cmdname(dArith2[i].arg1),Tok2Cmdname(dArith2[i].arg2)); |
---|
670 | fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith2[i].res)); |
---|
671 | if ((dArith2[i].valid_for & ALLOW_PLURAL)==0) |
---|
672 | only_comm=1; |
---|
673 | if ((dArith2[i].valid_for & ALLOW_RING)==0) |
---|
674 | only_field=1; |
---|
675 | if ((dArith2[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR) |
---|
676 | no_zerodiv=1; |
---|
677 | } |
---|
678 | i++; |
---|
679 | } |
---|
680 | } |
---|
681 | if ((cmds[m].toktype==CMD_23) |
---|
682 | || (cmds[m].toktype==CMD_13) |
---|
683 | || (cmds[m].toktype==CMD_3) |
---|
684 | || (cmds[m].toktype==CMD_123)) |
---|
685 | { |
---|
686 | op= cmds[m].tokval; |
---|
687 | i=0; |
---|
688 | while ((dArith3[i].cmd!=op) && (dArith3[i].cmd!=0)) i++; |
---|
689 | while (dArith3[i].cmd==op) |
---|
690 | { |
---|
691 | if (dArith3[i].p!=jjWRONG) |
---|
692 | { |
---|
693 | fprintf(part,"@code{%s (} %s, %s, %s @code{)}\n",cmds[m].name, |
---|
694 | Tok2Cmdname(dArith3[i].arg1), |
---|
695 | Tok2Cmdname(dArith3[i].arg2), |
---|
696 | Tok2Cmdname(dArith3[i].arg3)); |
---|
697 | fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith3[i].res)); |
---|
698 | if ((dArith3[i].valid_for & ALLOW_PLURAL)==0) |
---|
699 | only_comm=1; |
---|
700 | if ((dArith3[i].valid_for & ALLOW_RING)==0) |
---|
701 | only_field=1; |
---|
702 | if ((dArith3[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR) |
---|
703 | no_zerodiv=1; |
---|
704 | } |
---|
705 | i++; |
---|
706 | } |
---|
707 | } |
---|
708 | if (cmds[m].toktype==CMD_M) |
---|
709 | { |
---|
710 | op= cmds[m].tokval; |
---|
711 | i=0; |
---|
712 | while ((dArithM[i].cmd!=op) && (dArithM[i].cmd!=0)) i++; |
---|
713 | while (dArithM[i].cmd==op) |
---|
714 | { |
---|
715 | if (dArithM[i].p!=jjWRONG) |
---|
716 | { |
---|
717 | fprintf(part,"@code{%s (} ... @code{)}\n",cmds[m].name); |
---|
718 | fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArithM[i].res)); |
---|
719 | if ((dArithM[i].valid_for & ALLOW_PLURAL)==0) |
---|
720 | only_comm=1; |
---|
721 | if ((dArithM[i].valid_for & ALLOW_RING)==0) |
---|
722 | only_field=1; |
---|
723 | if ((dArithM[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR) |
---|
724 | no_zerodiv=1; |
---|
725 | } |
---|
726 | i++; |
---|
727 | } |
---|
728 | } |
---|
729 | if (only_comm) |
---|
730 | fprintf(part,"@item @strong{Remark:}\n" |
---|
731 | "only for commutive polynomial rings\n"); |
---|
732 | if (only_field) |
---|
733 | fprintf(part,"@item @strong{Remark:}\n" |
---|
734 | "only for polynomial rings over fields\n"); |
---|
735 | if (no_zerodiv) |
---|
736 | fprintf(part,"@item @strong{Remark:}\n" |
---|
737 | "only for polynomial rings over domains\n"); |
---|
738 | fprintf(part,"@item @strong{Purpose:}\n" |
---|
739 | "@item @strong{Example:}\n" |
---|
740 | "@smallexample\n" |
---|
741 | "@c example\n" |
---|
742 | "@c example\n" |
---|
743 | "@end smallexample\n" |
---|
744 | "@c ref\n" |
---|
745 | "@c See\n" |
---|
746 | "@c ref{....};\n" |
---|
747 | "@c ref{....}.\n" |
---|
748 | "@c ref\n"); |
---|
749 | fclose(part); |
---|
750 | } |
---|
751 | } |
---|
752 | } |
---|
753 | fclose(outfile); |
---|
754 | } |
---|
755 | /*-------------------------------------------------------------------*/ |
---|
756 | void ttGen4() |
---|
757 | { |
---|
758 | FILE *outfile = fopen("plural_cmd.xx","w"); |
---|
759 | int i; |
---|
760 | const char *old_s=""; |
---|
761 | fprintf(outfile, |
---|
762 | "@c *****************************************\n" |
---|
763 | "@c * Computer Algebra System SINGULAR *\n" |
---|
764 | "@c *****************************************\n\n"); |
---|
765 | /*-------------------------------------------------------------------*/ |
---|
766 | fprintf(outfile,"@multicolumn .45 .45\n"); |
---|
767 | int op; |
---|
768 | i=0; |
---|
769 | while ((op=dArith1[i].cmd)!=0) |
---|
770 | { |
---|
771 | if (dArith1[i].p!=jjWRONG) |
---|
772 | { |
---|
773 | const char *s = iiTwoOps(op); |
---|
774 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
775 | { |
---|
776 | old_s=s; |
---|
777 | #ifdef HAVE_PLURAL |
---|
778 | switch (dArith1[i].valid_for & PLURAL_MASK) |
---|
779 | { |
---|
780 | case NO_PLURAL: |
---|
781 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
782 | break; |
---|
783 | case ALLOW_PLURAL: |
---|
784 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
785 | break; |
---|
786 | case COMM_PLURAL: |
---|
787 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
788 | break; |
---|
789 | } |
---|
790 | #endif |
---|
791 | #ifdef HAVE_RINGS |
---|
792 | #endif |
---|
793 | } |
---|
794 | } |
---|
795 | i++; |
---|
796 | } |
---|
797 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
798 | i=0; |
---|
799 | while ((op=dArith2[i].cmd)!=0) |
---|
800 | { |
---|
801 | if (dArith2[i].p!=jjWRONG2) |
---|
802 | { |
---|
803 | const char *s = iiTwoOps(op); |
---|
804 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
805 | { |
---|
806 | old_s=s; |
---|
807 | #ifdef HAVE_PLURAL |
---|
808 | switch (dArith2[i].valid_for & PLURAL_MASK) |
---|
809 | { |
---|
810 | case NO_PLURAL: |
---|
811 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
812 | break; |
---|
813 | case ALLOW_PLURAL: |
---|
814 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
815 | break; |
---|
816 | case COMM_PLURAL: |
---|
817 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
818 | break; |
---|
819 | } |
---|
820 | #endif |
---|
821 | #ifdef HAVE_RINGS |
---|
822 | #endif |
---|
823 | } |
---|
824 | } |
---|
825 | i++; |
---|
826 | } |
---|
827 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
828 | i=0; |
---|
829 | while ((op=dArith3[i].cmd)!=0) |
---|
830 | { |
---|
831 | const char *s = iiTwoOps(op); |
---|
832 | if (dArith3[i].p!=jjWRONG3) |
---|
833 | { |
---|
834 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
835 | { |
---|
836 | old_s=s; |
---|
837 | #ifdef HAVE_PLURAL |
---|
838 | switch (dArith3[i].valid_for & PLURAL_MASK) |
---|
839 | { |
---|
840 | case NO_PLURAL: |
---|
841 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
842 | break; |
---|
843 | case ALLOW_PLURAL: |
---|
844 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
845 | break; |
---|
846 | case COMM_PLURAL: |
---|
847 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
848 | break; |
---|
849 | } |
---|
850 | #endif |
---|
851 | #ifdef HAVE_RINGS |
---|
852 | #endif |
---|
853 | } |
---|
854 | } |
---|
855 | i++; |
---|
856 | } |
---|
857 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
858 | i=0; |
---|
859 | while ((op=dArithM[i].cmd)!=0) |
---|
860 | { |
---|
861 | const char *s = iiTwoOps(op); |
---|
862 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
863 | { |
---|
864 | old_s=s; |
---|
865 | #ifdef HAVE_PLURAL |
---|
866 | switch (dArithM[i].valid_for & PLURAL_MASK) |
---|
867 | { |
---|
868 | case NO_PLURAL: |
---|
869 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
870 | break; |
---|
871 | case ALLOW_PLURAL: |
---|
872 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
873 | break; |
---|
874 | case COMM_PLURAL: |
---|
875 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
876 | break; |
---|
877 | } |
---|
878 | #endif |
---|
879 | #ifdef HAVE_RINGS |
---|
880 | #endif |
---|
881 | } |
---|
882 | i++; |
---|
883 | } |
---|
884 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
885 | fprintf(outfile,"@end table\n"); |
---|
886 | fclose(outfile); |
---|
887 | rename("plural_cmd.xx","plural_cmd.inc"); |
---|
888 | } |
---|
889 | /*-------------------------------------------------------------------*/ |
---|
890 | |
---|
891 | int main(int argc, char** argv) |
---|
892 | { |
---|
893 | if (argc>1) |
---|
894 | { |
---|
895 | ttGen4(); |
---|
896 | ttGen2c(); |
---|
897 | } |
---|
898 | else |
---|
899 | { |
---|
900 | ttGen1(); |
---|
901 | ttGen2b(); |
---|
902 | rename(iparith_inc,"iparith.inc"); |
---|
903 | } |
---|
904 | return 0; |
---|
905 | } |
---|