source: git/Singular/gentable.cc @ 88dc1d

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