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