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