14 #include <sys/types.h>
30 #define ALLOW_PLURAL 1
39 #define NO_ZERODIVISOR 8
40 #define ALLOW_ZERODIVISOR 0
41 #define ZERODIVISOR_MASK 8
134 if (tok==
COMMAND)
return "command";
135 if (tok==
ANY_TYPE)
return "any_type";
136 if (tok==
NONE)
return "nothing";
143 if (tok==
IDHDL)
return "identifier";
148 while (
cmds[i].tokval!=0)
150 if ((
cmds[i].tokval == tok)&&(
cmds[i].alias==0))
157 while (
cmds[i].tokval!=0)
159 if (
cmds[i].tokval == tok)
167 sprintf(s,
"(%d)",tok);
185 cmdnames *pCmdL = (cmdnames*)a;
186 cmdnames *pCmdR = (cmdnames*)b;
191 if(pCmdL->name==
NULL)
return 1;
192 if(pCmdR->name==
NULL)
return -1;
195 if(strcmp(pCmdL->name,
"$INVALID$")==0)
return -1;
196 if(strcmp(pCmdR->name,
"$INVALID$")==0)
return 1;
199 if (pCmdL->tokval==-1)
201 if (pCmdR->tokval==-1)
202 return strcmp(pCmdL->name, pCmdR->name);
207 if(pCmdR->tokval==-1)
return -1;
209 return strcmp(pCmdL->name, pCmdR->name);
214 cmdnames *pCmdL = (cmdnames*)a;
215 cmdnames *pCmdR = (cmdnames*)b;
220 if(pCmdL->name==
NULL)
return 1;
221 if(pCmdR->name==
NULL)
return -1;
224 if(strcmp(pCmdL->name,
"$INVALID$")==0)
return -1;
225 if(strcmp(pCmdR->name,
"$INVALID$")==0)
return 1;
226 char *ls=
strdup(pCmdL->name);
227 char *rs=
strdup(pCmdR->name);
229 while (*s) { *s=tolower(*s); s++; }
231 while (*s) { *s=tolower(*s); s++; }
234 if (pCmdL->tokval==-1)
236 if (pCmdR->tokval==-1)
237 {
int r=strcmp(ls,rs);
free(ls);
free(rs);
return r; }
243 if(pCmdR->tokval==-1)
246 {
int r=strcmp(ls,rs);
free(ls);
free(rs);
return r; }
276 case LE:
return "<=";
277 case GE:
return ">=";
292 if ((inputType==outputType)
294 || (outputType==
IDHDL)
331 "/****************************************\n"
332 "* Computer Algebra System SINGULAR *\n"
333 "****************************************/\n\n");
335 fprintf(outfile,
"// syntax table for Singular\n//\n");
336 fprintf(outfile,
"// - search for an exact match of the argument types\n");
337 fprintf(outfile,
"// - otherwise search for the first possibility\n");
338 fprintf(outfile,
"// with converted types of the arguments\n");
339 fprintf(outfile,
"// - otherwise report an error\n//\n");
346 fprintf(outfile,
"// DUMMY ");
348 fprintf(outfile,
"// operation: %s (%s) -> %s\n",
354 fprintf(outfile,
"// WARNING: %s requires currRing\n",s);
358 fprintf(outfile,
"/*---------------------------------------------*/\n");
363 fprintf(outfile,
"// DUMMY ");
365 fprintf(outfile,
"// operation: %s (%s, %s) -> %s\n",
374 fprintf(outfile,
"// WARNING: %s requires currRing\n",s);
378 fprintf(outfile,
"/*---------------------------------------------*/\n");
384 fprintf(outfile,
"// DUMMY ");
385 fprintf(outfile,
"// operation: %s (%s, %s, %s) -> %s\n",
396 fprintf(outfile,
"// WARNING: %s requires currRing\n",s);
400 fprintf(outfile,
"/*---------------------------------------------*/\n");
405 fprintf(outfile,
"// operation: %s (...) -> %s",
408 switch(
dArithM[i].number_of_args)
411 fprintf(outfile,
" ( number of arguments >0 )\n");
414 fprintf(outfile,
" ( any number of arguments )\n");
417 fprintf(outfile,
" ( %d arguments )\n",
dArithM[i].number_of_args);
422 fprintf(outfile,
"/*---------------------------------------------*/\n");
426 fprintf(outfile,
"// assign: %s = %s\n",
432 fprintf(outfile,
"/*---------------------------------------------*/\n");
436 doctable=fopen(
"convert_table.texi",
"w");
437 fprintf(doctable,
"@multitable @columnfractions .05 .18 .81\n");
447 fprintf(outfile,
"// convert %s -> %s\n",
452 "@item\n@ %d. @tab @code{%s} @tab @expansion{} @code{%s}\n",
462 fprintf(doctable,
"@end multitable\n");
465 fprintf(outfile,
"/*---------------------------------------------*/\n");
466 char ops[]=
"=><+*/[.^,%(;";
467 for(i=0;ops[
i]!=
'\0';i++)
468 fprintf(outfile,
"// token %d : %c\n", (
int)ops[i], ops[i]);
474 fprintf(outfile,
"// token %d : %s\n", i, s);
478 fprintf(outfile,
"/*--max. token: %d, gr: %d --*/\n",
MAX_TOK,
UMINUS);
480 fprintf(outfile,
"/*---------------------------------------------*/\n");
482 "struct sValCmdTab dArithTab1[]=\n"
490 fprintf(outfile,
" { %d,%d },\n",j,i);
496 fprintf(outfile,
" { 10000,0 }\n};\n");
497 fprintf(outfile,
"#define JJTAB1LEN %d\n",l1);
500 "struct sValCmdTab dArithTab2[]=\n"
508 fprintf(outfile,
" { %d,%d },\n",j,i);
514 fprintf(outfile,
" { 10000,0 }\n};\n");
515 fprintf(outfile,
"#define JJTAB2LEN %d\n",l2);
526 int cmd_size = (
sizeof(
cmds)/
sizeof(cmdnames))-1;
530 "/****************************************\n"
531 "* Computer Algebra System SINGULAR *\n"
532 "****************************************/\n\n");
534 fprintf(outfile,
"// identifier table for Singular\n//\n");
538 "#ifdef MODULE_GENERATOR\n"
539 "#define omAlloc0(A) malloc(A)\n"
541 "void iiInitCmdName()\n{\n"
542 " sArithBase.nCmdUsed = 0;\n"
543 " sArithBase.nCmdAllocated = %d;\n"
544 " sArithBase.sCmds = (cmdnames*)omAlloc0(sArithBase.nCmdAllocated*sizeof(cmdnames));\n"
546 " // name-string alias tokval toktype index\n",
553 for(m=0; m<cmd_size; m++)
555 if(
cmds[m].tokval>0) id_nr++;
556 fprintf(outfile,
" iiArithAddCmd(\"%s\", %*d, %3d, ",
cmds[m].
name,
557 (
int)(20-strlen(
cmds[m].name)),
560 switch(
cmds[m].toktype)
562 case CMD_1: fprintf(outfile,
"CMD_1");
break;
563 case CMD_2: fprintf(outfile,
"CMD_2");
break;
564 case CMD_3: fprintf(outfile,
"CMD_3");
break;
565 case CMD_12: fprintf(outfile,
"CMD_12");
break;
566 case CMD_123 : fprintf(outfile,
"CMD_123");
break;
567 case CMD_23: fprintf(outfile,
"CMD_23");
break;
568 case CMD_M: fprintf(outfile,
"CMD_M");
break;
569 case SYSVAR: fprintf(outfile,
"SYSVAR");
break;
570 case ROOT_DECL: fprintf(outfile,
"ROOT_DECL");
break;
572 case RING_DECL: fprintf(outfile,
"RING_DECL");
break;
573 case NONE: fprintf(outfile,
"NONE");
break;
575 if((
cmds[m].toktype>
' ') &&(
cmds[m].toktype<127))
577 fprintf(outfile,
"'%c'",
cmds[m].toktype);
581 fprintf(outfile,
"%d",
cmds[m].toktype);
585 fprintf(outfile,
" iiArithAddCmd(\"%s\", %*d, -1, 0 );\n",
586 cmds[m].name, 20-strlen(
cmds[m].name),
592 fprintf(outfile,
", %d);\n", m);
594 fprintf(outfile,
"/* end of list marker */\n");
596 " sArithBase.nLastIdentifier = %d;\n",
602 "#define LAST_IDENTIFIER %d\n"
608 if( c->tokval==0)
return 0;
609 if (c->alias > 0)
return 0;
610 if ((c->toktype==
CMD_1)
611 || (c->toktype==
CMD_2)
612 || (c->toktype==
CMD_3)
613 || (c->toktype==
CMD_M)
617 || (c->toktype==
CMD_123))
return 1;
622 int cmd_size = (
sizeof(
cmds)/
sizeof(cmdnames))-1;
624 FILE *outfile = fopen(
"reference_table.texi",
"w");
625 fprintf(outfile,
"@menu\n");
630 for(m=0; m<cmd_size; m++)
635 fprintf(outfile,
"* %s::\n",
cmds[m].
name);
638 fprintf(outfile,
"@end menu\n@c ---------------------------\n");
639 for(m=0; m<cmd_size; m++)
644 fprintf(outfile,
"@node %s,",
cmds[m].
name);
649 fprintf(outfile,
"%s,",
cmds[mm].name);
651 fprintf(outfile,
",");
656 fprintf(outfile,
"%s,",
cmds[m-1].name);
658 fprintf(outfile,
",");
660 fprintf(outfile,
"Functions\n"
662 "@cindex %s\n",
cmds[m].name,
cmds[m].name);
663 fprintf(outfile,
"@include %s.part\n",
cmds[m].name);
665 sprintf(partName,
"%s.part",
cmds[m].name);
667 if (lstat(partName,&buf)!=0)
670 int only_field=0,only_comm=0,no_zerodiv=0;
671 FILE *part=fopen(partName,
"w");
672 fprintf(part,
"@table @code\n@item @strong{Syntax:}\n");
733 fprintf(part,
"@code{%s (} %s, %s, %s @code{)}\n",
cmds[m].name,
757 fprintf(part,
"@code{%s (} ... @code{)}\n",
cmds[m].name);
770 fprintf(part,
"@item @strong{Remark:}\n"
771 "only for commutive polynomial rings\n");
773 fprintf(part,
"@item @strong{Remark:}\n"
774 "only for polynomial rings over fields\n");
776 fprintf(part,
"@item @strong{Remark:}\n"
777 "only for polynomial rings over domains\n");
778 fprintf(part,
"@item @strong{Purpose:}\n"
779 "@item @strong{Example:}\n"
783 "@end smallexample\n"
798 FILE *outfile = fopen(
"plural_cmd.xx",
"w");
800 const char *old_s=
"";
802 "@c *****************************************\n"
803 "@c * Computer Algebra System SINGULAR *\n"
804 "@c *****************************************\n\n");
806 fprintf(outfile,
"@multicolumn .45 .45\n");
814 if ((s!=
NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0))
821 fprintf(outfile,
"@item @ref{%s} @tab @code{---}\n",s);
824 fprintf(outfile,
"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s);
827 fprintf(outfile,
"@item @ref{%s} @tab %s\n",s,s);
837 fprintf(outfile,
"@c ---------------------------------------------\n");
844 if ((s!=
NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0))
851 fprintf(outfile,
"@item @ref{%s} @tab @code{---}\n",s);
854 fprintf(outfile,
"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s);
857 fprintf(outfile,
"@item @ref{%s} @tab %s\n",s,s);
867 fprintf(outfile,
"@c ---------------------------------------------\n");
874 if ((s!=
NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0))
881 fprintf(outfile,
"@item @ref{%s} @tab @code{---}\n",s);
884 fprintf(outfile,
"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s);
887 fprintf(outfile,
"@item @ref{%s} @tab %s\n",s,s);
897 fprintf(outfile,
"@c ---------------------------------------------\n");
902 if ((s!=
NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0))
909 fprintf(outfile,
"@item @ref{%s} @tab @code{---}\n",s);
912 fprintf(outfile,
"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s);
915 fprintf(outfile,
"@item @ref{%s} @tab %s\n",s,s);
924 fprintf(outfile,
"@c ---------------------------------------------\n");
925 fprintf(outfile,
"@end table\n");
927 rename(
"plural_cmd.xx",
"plural_cmd.inc");
931 int main(
int argc,
char** argv)
int main(int argc, char **argv)
const CanonicalForm int s
int iiTestConvert(int inputType, int outputType)
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
struct sValCmd1 dArith1[]
int produce_convert_table
const char * iiTwoOps(int t)
void * malloc(size_t size)
static int _texi_sort_cmds(const void *a, const void *b)
struct sValCmd3 dArith3[]
struct sValAssign dAssign[]
struct sValCmd2 dArith2[]
struct sValCmdM dArithM[]
struct sConvertTypes dConvertTypes[]
char name(const Variable &v)
void ttGen2b()
generate cmds initialisation
const char * Tok2Cmdname(int tok)
int is_ref_cmd(cmdnames *c)