source: git/Singular/gentable.cc @ 702175

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