source: git/Singular/gentable.cc @ 4a51c1

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