source: git/Singular/gentable.cc @ 3fd9575

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