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