source: git/Singular/gentable.cc @ 9b12fce

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