- Timestamp:
- Sep 27, 2006, 7:46:28 PM (18 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 1e35790dc0937f1166846848cf844b2811aa49f0
- Parents:
- 2245326a4cf500727c77d96a854a05d93f0cd772
- Location:
- modules/modgen
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/modgen/creat_top.cc
r224532 rb6e51b 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: creat_top.cc,v 1.2 4 2006-06-25 16:06:19 motsakExp $ */4 /* $Id: creat_top.cc,v 1.25 2006-09-27 17:46:27 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 122 122 fprintf(fp, "#line @d \"%s.cc\"\n", module->name); 123 123 fprintf(fp, "extern \"C\" {\n"); 124 #if 0 124 125 fprintf(fp, "int mod_init(\n int (*iiAddCproc)("); 125 126 #if 1 … … 128 129 #endif 129 130 fprintf(fp, ")\n )\n{\n"); 131 #else 132 fprintf(fp, "int mod_init(\n SModulFunctions* psModulFunctions"); 133 fprintf(fp, "\n )\n{\n"); 134 #endif 130 135 fprintf(fp, " idhdl h;\n"); 131 136 fprintf(fp, " char * tempstr;\n"); -
modules/modgen/main.cc
r224532 rb6e51b 60 60 moddef module_def; 61 61 62 extern int iiInitArithmetic(); 62 63 int init_modgen( 63 64 moddefv module_def, … … 159 160 } 160 161 162 iiInitArithmetic(); 161 163 if(init_modgen(&module_def, argv[optind])) return 1; 162 164 init_type_conv(); -
modules/modgen/misc.cc
r224532 rb6e51b 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: misc.cc,v 1.2 5 2006-04-06 19:37:00 anneExp $ */4 /* $Id: misc.cc,v 1.26 2006-09-27 17:46:27 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 35 35 #endif 36 36 37 typedef struct { 38 unsigned long nCmdUsed; /**< number of commands used */ 39 unsigned long nCmdAllocated; /**< number of commands-slots allocated */ 40 unsigned long nLastIdentifier; 41 cmdnames *sCmds; /**< array of existing commands */ 42 43 #ifndef GENTABLE 44 struct sValCmd1 *psValCmd1; 45 struct sValCmd2 *psValCmd2; 46 struct sValCmd3 *psValCmd3; 47 struct sValCmdM *psValCmdM; 48 #endif /* GENTABLE */ 49 } SArithBase; 50 51 52 /*---------------------------------------------------------------------* 53 * File scope Variables (Variables share by several functions in 54 * the same file ) 55 * 56 *---------------------------------------------------------------------*/ 57 static SArithBase sArithBase; /**< Base entry for arithmetic */ 58 37 59 char *DYNAinclude[] = { 38 60 "", … … 54 76 #define SELF_CMD MAX_TOK+1 55 77 78 /*---------------------------------------------------------------------* 79 * Extern Functions declarations 80 * 81 *---------------------------------------------------------------------*/ 82 static int _gentable_sort_cmds(const void *a, const void *b); 83 extern int iiArithRemoveCmd(char *szName); 84 extern int iiArithAddCmd(char *szName, short nAlias, short nTokval, 85 short nToktype, short nPos=-1); 56 86 extern void enter_id(FILE *fp, idtyp t, char *name, char *value, 57 87 int lineno, char *file); … … 78 108 int an=1; 79 109 int i,v; 80 int en= LAST_IDENTIFIER;110 int en=sArithBase.nLastIdentifier; 81 111 82 112 if( strcmp(n, "SELF") == 0) { … … 92 122 } 93 123 94 loop124 for(an=0; an<sArithBase.nCmdUsed; ) 95 125 { 96 126 if(an>=en-1) 97 127 { 98 if (strcmp(n, cmds[an].name) == 0)128 if (strcmp(n, sArithBase.sCmds[an].name) == 0) 99 129 { 100 130 i=an; 101 131 break; 102 132 } 103 else if ( strcmp(n, cmds[en].name) == 0)133 else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0)) 104 134 { 105 135 i=en; … … 112 142 } 113 143 i=(an+en)/2; 114 v=strcmp(n,cmds[i].name); 144 if (*n < *(sArithBase.sCmds[i].name)) 145 { 146 en=i-1; 147 } 148 else if (*n > *(sArithBase.sCmds[i].name)) 149 { 150 an=i+1; 151 } 152 else 153 { 154 v=strcmp(n,sArithBase.sCmds[i].name); 115 155 if(v<0) 116 156 { 117 en=i;157 en=i-1; 118 158 } 119 159 else if(v>0) 120 160 { 121 an=i;161 an=i+1; 122 162 } 123 163 else /*v==0*/ … … 126 166 } 127 167 } 128 lastreserved=cmds[i].name; 129 tok=cmds[i].tokval; 130 if(cmds[i].alias==2) 131 { 168 } 169 lastreserved=sArithBase.sCmds[i].name; 170 tok=sArithBase.sCmds[i].tokval; 171 if(sArithBase.sCmds[i].alias==2) 172 { 132 173 if(trace)printf("outdated identifier `%s` used - please change your code", 133 cmds[i].name); 134 cmds[i].alias=1; 135 } 136 #if 0 137 if (!expected_parms) 138 { 139 switch (tok) 140 { 141 case IDEAL_CMD: 142 case INT_CMD: 143 case INTVEC_CMD: 144 case MAP_CMD: 145 case MATRIX_CMD: 146 case MODUL_CMD: 147 case POLY_CMD: 148 case PROC_CMD: 149 case RING_CMD: 150 case STRING_CMD: 151 cmdtok = tok; 152 break; 153 } 154 } 155 #endif 174 sArithBase.sCmds[i].name); 175 sArithBase.sCmds[i].alias=1; 176 } 177 156 178 logx("IsCmd: [%d] %s\n", tok, n); 157 179 158 if( ( cmds[i].toktype==ROOT_DECL) ||159 ( cmds[i].toktype==ROOT_DECL_LIST) ||160 ( cmds[i].toktype==RING_DECL) ||161 ( cmds[i].toktype==IDEAL_CMD) ||162 ( cmds[i].toktype==INTMAT_CMD) ||163 ( cmds[i].toktype==MODUL_CMD) ||164 ( cmds[i].toktype==MATRIX_CMD))// ||165 // ((c mds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD)))166 return cmds[i].toktype;180 if( (sArithBase.sCmds[i].toktype==ROOT_DECL) || 181 (sArithBase.sCmds[i].toktype==ROOT_DECL_LIST) || 182 (sArithBase.sCmds[i].toktype==RING_DECL) || 183 (sArithBase.sCmds[i].toktype==IDEAL_CMD) || 184 (sArithBase.sCmds[i].toktype==INTMAT_CMD) || 185 (sArithBase.sCmds[i].toktype==MODUL_CMD) || 186 (sArithBase.sCmds[i].toktype==MATRIX_CMD))// || 187 // ((csArithBase.sCds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD))) 188 return sArithBase.sCmds[i].toktype; 167 189 return 0; 168 190 } 191 169 192 170 193 char * decl2str(int n, char *name) … … 434 457 printf("->%s, %s\n", module->procs[proccnt].procname, 435 458 module->procs[proccnt].funcname); 436 fprintf(module->modfp, " iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",459 fprintf(module->modfp, " psModulFunctions->iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n", 437 460 module->name, module->procs[proccnt].procname, 438 461 module->procs[proccnt].is_static ? "TRUE" : "FALSE", … … 616 639 617 640 /*========================================================================*/ 641 /*---------------------------------------------------------------------*/ 642 /** 643 * @brief compares to entry of cmdsname-list 644 645 @param[in] a 646 @param[in] b 647 648 @return <ReturnValue> 649 **/ 650 /*---------------------------------------------------------------------*/ 651 static int _gentable_sort_cmds( 652 const void *a, 653 const void *b 654 ) 655 { 656 cmdnames *pCmdL = (cmdnames*)a; 657 cmdnames *pCmdR = (cmdnames*)b; 658 659 if(a==NULL || b==NULL) return 0; 660 661 /* empty entries goes to the end of the list for later reuse */ 662 if(pCmdL->name==NULL) return 1; 663 if(pCmdR->name==NULL) return -1; 664 665 /* $INVALID$ must come first */ 666 if(strcmp(pCmdL->name, "$INVALID$")==0) return -1; 667 if(strcmp(pCmdR->name, "$INVALID$")==0) return 1; 668 669 /* tokval=-1 are reserved names at the end */ 670 if( (pCmdL->tokval==-1) && pCmdR->tokval==-1) 671 return strcmp(pCmdL->name, pCmdR->name); 672 673 /* pCmdL->tokval==-1, pCmdL goes at the end */ 674 if(pCmdL->tokval==-1) return 1; 675 /* pCmdR->tokval==-1, pCmdR goes at the end */ 676 if(pCmdR->tokval==-1) return -1; 677 678 return strcmp(pCmdL->name, pCmdR->name); 679 } 680 681 /*---------------------------------------------------------------------*/ 682 /** 683 * @brief initialisation of arithmetic structured data 684 685 @retval 0 on success 686 687 **/ 688 /*---------------------------------------------------------------------*/ 689 int iiInitArithmetic() 690 { 691 int i; 692 //printf("iiInitArithmetic()\n"); 693 #ifndef GENTABLE 694 memset(&sArithBase, 0, sizeof(sArithBase)); 695 iiInitCmdName(); 696 /* fix last-identifier */ 697 #endif /* !GENTABLE */ 698 } 699 700 int iiArithFindCmd(const char *szName) 701 { 702 int an=0; 703 int i = 0,v = 0; 704 #ifndef GENTABLE 705 int en=sArithBase.nLastIdentifier; 706 707 for(an=0; an<sArithBase.nCmdUsed; ) { 708 if(an>=en-1) { 709 if (strcmp(szName, sArithBase.sCmds[an].name) == 0) { 710 //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name); 711 return an; 712 } else if (strcmp(szName, sArithBase.sCmds[en].name) == 0) 713 { 714 //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name); 715 return en; 716 } 717 else 718 { 719 //Print("RET- 1\n"); 720 return -1; 721 } 722 } 723 i=(an+en)/2; 724 if (*szName < *(sArithBase.sCmds[i].name)) { 725 en=i-1; 726 } 727 else if (*szName > *(sArithBase.sCmds[i].name)) 728 { 729 an=i+1; 730 } 731 else 732 { 733 v=strcmp(szName,sArithBase.sCmds[i].name); 734 if(v<0) 735 { 736 en=i-1; 737 } 738 else if(v>0) 739 { 740 an=i+1; 741 } 742 else /*v==0*/ 743 { 744 //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name); 745 return i; 746 } 747 } 748 } 749 //if(i>=0 && i<sArithBase.nCmdUsed) 750 // return i; 751 //Print("RET-2\n"); 752 return -2; 753 #else 754 return 0; 755 #endif 756 } 757 758 int iiArithAddCmd( 759 char *szName, 760 short nAlias, 761 short nTokval, 762 short nToktype, 763 short nPos 764 ) 765 { 766 //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias, 767 // nTokval, nToktype, nPos); 768 if(nPos>=0) { 769 if(nPos>=sArithBase.nCmdAllocated) return -1; 770 if(szName!=NULL) sArithBase.sCmds[nPos].name = strdup(szName); 771 else sArithBase.sCmds[nPos].name = NULL; 772 sArithBase.sCmds[nPos].alias = nAlias; 773 sArithBase.sCmds[nPos].tokval = nTokval; 774 sArithBase.sCmds[nPos].toktype = nToktype; 775 sArithBase.nCmdUsed++; 776 //if(nTokval>0) sArithBase.nLastIdentifier++; 777 } else { 778 if(szName==NULL) return -1; 779 int nIndex = iiArithFindCmd(szName); 780 if(nIndex>=0) { 781 printf("'%s' already exists at %d\n", szName, nIndex); 782 return -1; 783 } 784 785 if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated) { 786 /* needs to create new slots */ 787 unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames); 788 sArithBase.sCmds = (cmdnames *)realloc(sArithBase.sCmds, nSize); 789 if(sArithBase.sCmds==NULL) return -1; 790 sArithBase.nCmdAllocated++; 791 } 792 /* still free slots available */ 793 sArithBase.sCmds[sArithBase.nCmdUsed].name = strdup(szName); 794 sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias; 795 sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval; 796 sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype; 797 sArithBase.nCmdUsed++; 798 799 qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames), 800 (&_gentable_sort_cmds)); 801 for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1; 802 sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) { 803 if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break; 804 } 805 //Print("L=%d\n", sArithBase.nLastIdentifier); 806 } 807 return 0; 808 } 809 -
modules/modgen/proc.cc
r224532 rb6e51b 1 1 /* 2 * $Id: proc.cc,v 1.2 5 2006-06-25 16:19:16 motsakExp $2 * $Id: proc.cc,v 1.26 2006-09-27 17:46:28 Singular Exp $ 3 3 */ 4 4 … … 53 53 /* write call to add procname to list */ 54 54 fprintf(module->modfp, 55 " iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",55 " psModulFunctions->iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n", 56 56 proc->procname, 57 57 proc->is_static ? "TRUE" : "FALSE", … … 524 524 /*========================================================================*/ 525 525 void write_help( 526 moddefv module,526 moddefv pModule, 527 527 procdefv pi 528 528 ) … … 530 530 unsigned int i; 531 531 if(pi->help_string!=NULL) { 532 fprintf( module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,533 module->filename);534 fprintf( module->fmtfp2, " enter_id(\"%s_help\",", pi->procname);535 fprintf( module->fmtfp2, " \"");532 fprintf(pModule->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other, 533 pModule->filename); 534 fprintf(pModule->fmtfp2, " enter_id(\"%s_help\",", pi->procname); 535 fprintf(pModule->fmtfp2, " \""); 536 536 for(i=0; i<strlen(pi->help_string); i++) { 537 if(pi->help_string[i]=='\n') fprintf( module->fmtfp2,"\\n");538 else fprintf( module->fmtfp2,"%c", pi->help_string[i]);539 } 540 fprintf( module->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string);537 if(pi->help_string[i]=='\n') fprintf(pModule->fmtfp2,"\\n"); 538 else fprintf(pModule->fmtfp2,"%c", pi->help_string[i]); 539 } 540 fprintf(pModule->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string); 541 541 } 542 542 } -
modules/modgen/scanner.cc
r224532 rb6e51b 3 3 4 4 /* Scanner skeleton version: 5 * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1. 2 2006-06-23 15:41:38 Singular Exp $5 * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $ 6 6 */ 7 7 … … 703 703 * Computer Algebra System SINGULAR * 704 704 ****************************************/ 705 /* $Id: scanner.cc,v 1. 2 2006-06-23 15:41:38 Singular Exp $ */705 /* $Id: scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $ */ 706 706 #include <stdio.h> 707 707 #include <string.h>
Note: See TracChangeset
for help on using the changeset viewer.