source: git/Singular/gentable.cc @ 9f7665

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