source: git/Singular/gentable.cc @ 97dcf5

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