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