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