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