source: git/Singular/gentable.cc @ 762407

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