[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
[e2f1c7] | 5 | * ABSTRACT: interpreter: LIB and help |
---|
[0e1846] | 6 | */ |
---|
| 7 | |
---|
| 8 | //#include <stdlib.h> |
---|
| 9 | #include <stdio.h> |
---|
| 10 | #include <string.h> |
---|
[c4041ef] | 11 | #include <ctype.h> |
---|
[cd6b45] | 12 | #include <sys/stat.h> |
---|
[0e1846] | 13 | |
---|
[762407] | 14 | #include "config.h" |
---|
[b1dfaf] | 15 | #include <kernel/mod2.h> |
---|
[599326] | 16 | #include <Singular/tok.h> |
---|
[0fb34ba] | 17 | #include <misc/options.h> |
---|
[599326] | 18 | #include <Singular/ipid.h> |
---|
[b1dfaf] | 19 | #include <omalloc/omalloc.h> |
---|
[599326] | 20 | #include <kernel/febase.h> |
---|
[0fb34ba] | 21 | #include <polys/monomials/ring.h> |
---|
[599326] | 22 | #include <Singular/subexpr.h> |
---|
| 23 | #include <Singular/ipshell.h> |
---|
| 24 | #include <Singular/lists.h> |
---|
[cd6b45] | 25 | |
---|
[2ff076] | 26 | #if SIZEOF_LONG == 8 |
---|
| 27 | #define SI_MAX_NEST 500 |
---|
[b78b73] | 28 | #elif defined(ix86_Win) |
---|
| 29 | #define SI_MAX_NEST 480 |
---|
[2ff076] | 30 | #else |
---|
| 31 | #define SI_MAX_NEST 1000 |
---|
| 32 | #endif |
---|
| 33 | |
---|
[01d9463] | 34 | #if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin) |
---|
[1cb879] | 35 | # define MODULE_SUFFIX bundle |
---|
| 36 | #elif defined(ix86_Win) |
---|
| 37 | # define MODULE_SUFFIX dll |
---|
| 38 | #else |
---|
| 39 | # define MODULE_SUFFIX so |
---|
| 40 | #endif |
---|
| 41 | |
---|
| 42 | #define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX) |
---|
| 43 | |
---|
| 44 | |
---|
[24590f] | 45 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[c858fc2] | 46 | BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport); |
---|
[24590f] | 47 | #endif |
---|
[730df2] | 48 | |
---|
[5480da] | 49 | #ifdef HAVE_LIBPARSER |
---|
| 50 | # include "libparse.h" |
---|
[c4bbf1f] | 51 | #else /* HAVE_LIBPARSER */ |
---|
[889f6e] | 52 | procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname, |
---|
| 53 | const char *procname, int line, long pos, BOOLEAN pstatic=FALSE); |
---|
[5480da] | 54 | #endif /* HAVE_LIBPARSER */ |
---|
[573da6] | 55 | #define NS_LRING (procstack->cRing) |
---|
[0e1846] | 56 | |
---|
[85e68dd] | 57 | extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval, |
---|
[b6e51b] | 58 | short nToktype, short nPos); |
---|
| 59 | |
---|
[0fb34ba] | 60 | #include <polys/mod_raw.h> |
---|
[cd6b45] | 61 | |
---|
[6a51ef] | 62 | #ifdef HAVE_LIBPARSER |
---|
| 63 | void yylprestart (FILE *input_file ); |
---|
| 64 | int current_pos(int i=0); |
---|
| 65 | extern int yylp_errno; |
---|
| 66 | extern int yylplineno; |
---|
| 67 | extern char *yylp_errlist[]; |
---|
| 68 | void print_init(); |
---|
| 69 | libstackv library_stack; |
---|
| 70 | #endif |
---|
[2ba9a6] | 71 | |
---|
[c4041ef] | 72 | //int IsCmd(char *n, int tok); |
---|
[8edd35] | 73 | char mytolower(char c); |
---|
| 74 | |
---|
[50cbdc] | 75 | /*2 |
---|
| 76 | * return TRUE if the libray libname is already loaded |
---|
| 77 | */ |
---|
| 78 | BOOLEAN iiGetLibStatus(char *lib) |
---|
| 79 | { |
---|
| 80 | idhdl hl; |
---|
| 81 | |
---|
[a3bc95e] | 82 | char *plib = iiConvName(lib); |
---|
| 83 | hl = basePack->idroot->get(plib,0); |
---|
[42c4e6] | 84 | omFree(plib); |
---|
[a3bc95e] | 85 | if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD)) |
---|
| 86 | { |
---|
| 87 | return FALSE; |
---|
| 88 | } |
---|
| 89 | return (strcmp(lib,IDPACKAGE(hl)->libname)==0); |
---|
[50cbdc] | 90 | } |
---|
[cd6b45] | 91 | |
---|
[0e1846] | 92 | /*2 |
---|
| 93 | * find the library of an proc: |
---|
[2ba9a6] | 94 | * => return (pi->libname) |
---|
[0e1846] | 95 | */ |
---|
[2ba9a6] | 96 | char * iiGetLibName(procinfov pi) |
---|
[0e1846] | 97 | { |
---|
[f2dff02] | 98 | return pi->libname; |
---|
[0e1846] | 99 | } |
---|
[f2dff02] | 100 | |
---|
[0e1846] | 101 | /*2 |
---|
| 102 | * given a line 'proc[ ]+{name}[ \t]*' |
---|
| 103 | * return a pointer to name and set the end of '\0' |
---|
| 104 | * changes the input! |
---|
| 105 | * returns: e: pointer to 'end of name' |
---|
| 106 | * ct: changed char at the end of s |
---|
| 107 | */ |
---|
| 108 | char* iiProcName(char *buf, char & ct, char* &e) |
---|
| 109 | { |
---|
| 110 | char *s=buf+5; |
---|
| 111 | while (*s==' ') s++; |
---|
| 112 | e=s+1; |
---|
| 113 | while ((*e>' ') && (*e!='(')) e++; |
---|
| 114 | ct=*e; |
---|
| 115 | *e='\0'; |
---|
| 116 | return s; |
---|
| 117 | } |
---|
[057e93c] | 118 | |
---|
[0e1846] | 119 | /*2 |
---|
| 120 | * given a line with args, return the argstr |
---|
| 121 | */ |
---|
| 122 | char * iiProcArgs(char *e,BOOLEAN withParenth) |
---|
| 123 | { |
---|
[33e521] | 124 | while ((*e==' ') || (*e=='\t') || (*e=='(')) e++; |
---|
[0e1846] | 125 | if (*e<' ') |
---|
| 126 | { |
---|
| 127 | if (withParenth) |
---|
| 128 | { |
---|
| 129 | // no argument list, allow list # |
---|
[c232af] | 130 | return omStrDup("parameter list #;"); |
---|
[0e1846] | 131 | } |
---|
| 132 | else |
---|
| 133 | { |
---|
| 134 | // empty list |
---|
[c232af] | 135 | return omStrDup(""); |
---|
[0e1846] | 136 | } |
---|
| 137 | } |
---|
| 138 | BOOLEAN in_args; |
---|
| 139 | BOOLEAN args_found; |
---|
| 140 | char *s; |
---|
[f2dff02] | 141 | char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc |
---|
| 142 | int argstrlen=127; |
---|
[0e1846] | 143 | *argstr='\0'; |
---|
[938688] | 144 | int par=0; |
---|
[0e1846] | 145 | do |
---|
| 146 | { |
---|
| 147 | args_found=FALSE; |
---|
| 148 | s=e; // set s to the starting point of the arg |
---|
| 149 | // and search for the end |
---|
[db34980] | 150 | while(*s==' ') s++; e=s; // skip leading paces |
---|
[938688] | 151 | while ((*e!=',') |
---|
| 152 | &&((par!=0) || (*e!=')')) |
---|
| 153 | &&(*e!='\0')) |
---|
[0e1846] | 154 | { |
---|
[938688] | 155 | if (*e=='(') par++; |
---|
| 156 | else if (*e==')') par--; |
---|
[0e1846] | 157 | args_found=args_found || (*e>' '); |
---|
| 158 | e++; |
---|
| 159 | } |
---|
| 160 | in_args=(*e==','); |
---|
| 161 | if (args_found) |
---|
| 162 | { |
---|
| 163 | *e='\0'; |
---|
[474fb0f] | 164 | // check for space: |
---|
[24c186a] | 165 | if ((int)strlen(argstr)+12 /* parameter + ;*/ +(int)strlen(s)>= argstrlen) |
---|
[474fb0f] | 166 | { |
---|
| 167 | argstrlen*=2; |
---|
[c232af] | 168 | char *a=(char *)omAlloc( argstrlen); |
---|
[474fb0f] | 169 | strcpy(a,argstr); |
---|
[c232af] | 170 | omFree((ADDRESS)argstr); |
---|
[474fb0f] | 171 | argstr=a; |
---|
| 172 | } |
---|
[0e1846] | 173 | // copy the result to argstr |
---|
[ea947e] | 174 | if(strncmp(s,"alias ",6)!=0) |
---|
| 175 | { |
---|
| 176 | strcat(argstr,"parameter "); |
---|
| 177 | } |
---|
[0e1846] | 178 | strcat(argstr,s); |
---|
[0348347] | 179 | strcat(argstr,"; "); |
---|
[0e1846] | 180 | e++; // e was pointing to ',' |
---|
| 181 | } |
---|
| 182 | } while (in_args); |
---|
| 183 | return argstr; |
---|
| 184 | } |
---|
[2ba9a6] | 185 | |
---|
[0e1846] | 186 | /*2 |
---|
| 187 | * locate `procname` in lib `libname` and find the part `part`: |
---|
| 188 | * part=0: help, between, but excluding the line "proc ..." and "{...": |
---|
[2ba9a6] | 189 | * => return |
---|
[0e1846] | 190 | * part=1: body, between "{ ..." and "}", including the 1. line, w/o "{" |
---|
[2ba9a6] | 191 | * => set pi->data.s.body, return NULL |
---|
[0e1846] | 192 | * part=2: example, between, but excluding the line "exapmle {..." and "}": |
---|
| 193 | * => return |
---|
| 194 | */ |
---|
[2ba9a6] | 195 | char* iiGetLibProcBuffer(procinfo *pi, int part ) |
---|
[0e1846] | 196 | { |
---|
[2ba9a6] | 197 | char buf[256], *s = NULL, *p; |
---|
| 198 | long procbuflen; |
---|
[bcd557] | 199 | |
---|
[2ba9a6] | 200 | FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE ); |
---|
[0e1846] | 201 | if (fp==NULL) |
---|
| 202 | { |
---|
| 203 | return NULL; |
---|
| 204 | } |
---|
| 205 | |
---|
[2ba9a6] | 206 | fseek(fp, pi->data.s.proc_start, SEEK_SET); |
---|
[057e93c] | 207 | if(part==0) |
---|
| 208 | { // load help string |
---|
[7fd611] | 209 | int i, offset=0; |
---|
[6be769] | 210 | long head = pi->data.s.def_end - pi->data.s.proc_start; |
---|
| 211 | procbuflen = pi->data.s.help_end - pi->data.s.help_start; |
---|
[09ab91d] | 212 | if (procbuflen<5) |
---|
[ce21e4a] | 213 | { |
---|
| 214 | fclose(fp); |
---|
[09ab91d] | 215 | return NULL; // help part does not exist |
---|
[ce21e4a] | 216 | } |
---|
[2ba9a6] | 217 | //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start, |
---|
| 218 | // pi->data.s.proc_start, procbuflen); |
---|
[c232af] | 219 | s = (char *)omAlloc(procbuflen+head+3); |
---|
[6be769] | 220 | myfread(s, head, 1, fp); |
---|
| 221 | s[head] = '\n'; |
---|
| 222 | fseek(fp, pi->data.s.help_start, SEEK_SET); |
---|
| 223 | myfread(s+head+1, procbuflen, 1, fp); |
---|
[ce21e4a] | 224 | fclose(fp); |
---|
[6be769] | 225 | s[procbuflen+head+1] = '\n'; |
---|
| 226 | s[procbuflen+head+2] = '\0'; |
---|
[7fd611] | 227 | offset=0; |
---|
[743c32] | 228 | for(i=0;i<=procbuflen+head+2; i++) |
---|
| 229 | { |
---|
[7fd611] | 230 | if(s[i]=='\\' && |
---|
[743c32] | 231 | (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\')) |
---|
| 232 | { |
---|
[7fd611] | 233 | i++; |
---|
| 234 | offset++; |
---|
| 235 | } |
---|
| 236 | if(offset>0) s[i-offset] = s[i]; |
---|
| 237 | } |
---|
[2ba9a6] | 238 | return(s); |
---|
| 239 | } |
---|
[09ab91d] | 240 | else if(part==1) |
---|
| 241 | { // load proc part - must exist |
---|
[6a51ef] | 242 | procbuflen = pi->data.s.def_end - pi->data.s.proc_start; |
---|
[873d82] | 243 | char *ss=(char *)omAlloc(procbuflen+2); |
---|
[6a51ef] | 244 | //fgets(buf, sizeof(buf), fp); |
---|
[873d82] | 245 | myfread( ss, procbuflen, 1, fp); |
---|
[2ba9a6] | 246 | char ct; |
---|
| 247 | char *e; |
---|
[873d82] | 248 | s=iiProcName(ss,ct,e); |
---|
[2ba9a6] | 249 | char *argstr=NULL; |
---|
| 250 | *e=ct; |
---|
| 251 | argstr=iiProcArgs(e,TRUE); |
---|
[752a5a] | 252 | |
---|
| 253 | assume(pi->data.s.body_end > pi->data.s.body_start); |
---|
| 254 | |
---|
[2ba9a6] | 255 | procbuflen = pi->data.s.body_end - pi->data.s.body_start; |
---|
[c232af] | 256 | pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+ |
---|
[13e3243] | 257 | strlen(pi->libname) ); |
---|
[2ba9a6] | 258 | //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end, |
---|
| 259 | // pi->data.s.body_start, procbuflen); |
---|
[752a5a] | 260 | assume(pi->data.s.body != NULL); |
---|
[2ba9a6] | 261 | fseek(fp, pi->data.s.body_start, SEEK_SET); |
---|
| 262 | strcpy(pi->data.s.body,argstr); |
---|
[d5f35ac] | 263 | myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp); |
---|
[ce21e4a] | 264 | fclose( fp ); |
---|
[2ba9a6] | 265 | procbuflen+=strlen(argstr); |
---|
[c232af] | 266 | omFree(argstr); |
---|
[873d82] | 267 | omFree(ss); |
---|
[2ba9a6] | 268 | pi->data.s.body[procbuflen] = '\0'; |
---|
[057e93c] | 269 | strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" ); |
---|
[2ba9a6] | 270 | strcat( pi->data.s.body+procbuflen+13,pi->libname); |
---|
[08c2d6] | 271 | s=(char *)strchr(pi->data.s.body,'{'); |
---|
[2ba9a6] | 272 | if (s!=NULL) *s=' '; |
---|
| 273 | return NULL; |
---|
| 274 | } |
---|
[09ab91d] | 275 | else if(part==2) |
---|
| 276 | { // example |
---|
| 277 | if ( pi->data.s.example_lineno == 0) |
---|
| 278 | return NULL; // example part does not exist |
---|
| 279 | // load example |
---|
[2ba9a6] | 280 | fseek(fp, pi->data.s.example_start, SEEK_SET); |
---|
[6909cfb] | 281 | /*char *dummy=*/ (void) fgets(buf, sizeof(buf), fp); // skip line with "example" |
---|
[2ba9a6] | 282 | procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf); |
---|
| 283 | //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end, |
---|
| 284 | // pi->data.s.example_start, procbuflen); |
---|
[c232af] | 285 | s = (char *)omAlloc(procbuflen+14); |
---|
[d5f35ac] | 286 | myfread(s, procbuflen, 1, fp); |
---|
[2ba9a6] | 287 | s[procbuflen] = '\0'; |
---|
[057e93c] | 288 | strcat(s+procbuflen-3, "\n;return();\n\n" ); |
---|
[08c2d6] | 289 | p=(char *)strchr(s,'{'); |
---|
[1d1101] | 290 | if (p!=NULL) *p=' '; |
---|
[2ba9a6] | 291 | return(s); |
---|
[0e1846] | 292 | } |
---|
| 293 | return NULL; |
---|
| 294 | } |
---|
[016648] | 295 | #ifndef LIBSINGULAR |
---|
| 296 | // see below: |
---|
| 297 | struct soptionStruct |
---|
| 298 | { |
---|
| 299 | const char * name; |
---|
| 300 | unsigned setval; |
---|
| 301 | unsigned resetval; |
---|
| 302 | }; |
---|
| 303 | extern struct soptionStruct optionStruct[]; |
---|
| 304 | extern struct soptionStruct verboseStruct[]; |
---|
| 305 | #endif |
---|
[0e1846] | 306 | |
---|
[a71a00] | 307 | BOOLEAN iiAllStart(procinfov pi, char *p,feBufferTypes t, int l) |
---|
| 308 | { |
---|
| 309 | newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/, |
---|
| 310 | pi, l ); |
---|
[9875202] | 311 | #ifndef LIBSINGULAR |
---|
| 312 | // see below: |
---|
[271d25] | 313 | BITSET save1=(test & ~TEST_RINGDEP_OPTS); |
---|
| 314 | BITSET save2=verbose; |
---|
[9875202] | 315 | #endif |
---|
[a71a00] | 316 | BOOLEAN err=yyparse(); |
---|
| 317 | if (sLastPrinted.rtyp!=0) |
---|
| 318 | { |
---|
| 319 | sLastPrinted.CleanUp(); |
---|
| 320 | } |
---|
[9875202] | 321 | #ifndef LIBSINGULAR |
---|
[016648] | 322 | // the access to optionStruct and verboseStruct do not work |
---|
[9875202] | 323 | // on x86_64-Linux for pic-code |
---|
[271d25] | 324 | BITSET save11= ( test & ~TEST_RINGDEP_OPTS); |
---|
[65eb96f] | 325 | if ((TEST_V_ALLWARN) && |
---|
| 326 | (t==BT_proc) && |
---|
[271d25] | 327 | ((save1!=save11)||(save2!=verbose)) && |
---|
[65eb96f] | 328 | (pi->libname!=NULL) && (pi->libname[0]!='\0')) |
---|
| 329 | { |
---|
| 330 | Warn("option changed in proc %s from %s",pi->procname,pi->libname); |
---|
| 331 | int i; |
---|
| 332 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
| 333 | { |
---|
| 334 | if ((optionStruct[i].setval & save11) |
---|
| 335 | && (!(optionStruct[i].setval & save1))) |
---|
| 336 | { |
---|
| 337 | Print(" +%s",optionStruct[i].name); |
---|
| 338 | } |
---|
| 339 | if (!(optionStruct[i].setval & save11) |
---|
| 340 | && ((optionStruct[i].setval & save1))) |
---|
| 341 | { |
---|
| 342 | Print(" -%s",optionStruct[i].name); |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
| 346 | { |
---|
[271d25] | 347 | if ((verboseStruct[i].setval & verbose) |
---|
[65eb96f] | 348 | && (!(verboseStruct[i].setval & save2))) |
---|
| 349 | { |
---|
| 350 | Print(" +%s",verboseStruct[i].name); |
---|
| 351 | } |
---|
[271d25] | 352 | if (!(verboseStruct[i].setval & verbose) |
---|
[65eb96f] | 353 | && ((verboseStruct[i].setval & save2))) |
---|
| 354 | { |
---|
| 355 | Print(" -%s",verboseStruct[i].name); |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | PrintLn(); |
---|
| 359 | } |
---|
[9875202] | 360 | #endif |
---|
[a71a00] | 361 | return err; |
---|
| 362 | } |
---|
[0e1846] | 363 | /*2 |
---|
[057e93c] | 364 | * start a proc |
---|
[0e1846] | 365 | * parameters are built as exprlist |
---|
[057e93c] | 366 | * TODO:interrupt |
---|
| 367 | * return FALSE on success, TRUE if an error occurs |
---|
[0e1846] | 368 | */ |
---|
[057e93c] | 369 | BOOLEAN iiPStart(idhdl pn, sleftv * v) |
---|
[0e1846] | 370 | { |
---|
[42c4e6] | 371 | procinfov pi=NULL; |
---|
[057e93c] | 372 | int old_echo=si_echo; |
---|
[42c4e6] | 373 | BOOLEAN err=FALSE; |
---|
[64d729] | 374 | char save_flags=0; |
---|
[0e1846] | 375 | |
---|
| 376 | /* init febase ======================================== */ |
---|
[057e93c] | 377 | /* we do not enter this case if filename != NULL !! */ |
---|
| 378 | if (pn!=NULL) |
---|
[0e1846] | 379 | { |
---|
[057e93c] | 380 | pi = IDPROC(pn); |
---|
| 381 | if(pi!=NULL) |
---|
[0e1846] | 382 | { |
---|
[64d729] | 383 | save_flags=pi->trace_flag; |
---|
[057e93c] | 384 | if( pi->data.s.body==NULL ) |
---|
[0e1846] | 385 | { |
---|
[64d729] | 386 | iiGetLibProcBuffer(pi); |
---|
| 387 | if (pi->data.s.body==NULL) return TRUE; |
---|
[0e1846] | 388 | } |
---|
[f09b51] | 389 | // omUpdateInfo(); |
---|
| 390 | // int m=om_Info.UsedBytes; |
---|
| 391 | // Print("proc %s, mem=%d\n",IDID(pn),m); |
---|
[0e1846] | 392 | } |
---|
| 393 | } |
---|
[a71a00] | 394 | else return TRUE; |
---|
[0e1846] | 395 | /* generate argument list ======================================*/ |
---|
| 396 | if (v!=NULL) |
---|
| 397 | { |
---|
[c232af] | 398 | iiCurrArgs=(leftv)omAllocBin(sleftv_bin); |
---|
[0e1846] | 399 | memcpy(iiCurrArgs,v,sizeof(sleftv)); |
---|
| 400 | memset(v,0,sizeof(sleftv)); |
---|
| 401 | } |
---|
| 402 | else |
---|
| 403 | { |
---|
| 404 | iiCurrArgs=NULL; |
---|
| 405 | } |
---|
[f71681] | 406 | iiCurrProc=pn; |
---|
[0e1846] | 407 | /* start interpreter ======================================*/ |
---|
[057e93c] | 408 | myynest++; |
---|
[2ff076] | 409 | if (myynest > SI_MAX_NEST) |
---|
[e0749e8] | 410 | { |
---|
[2ff076] | 411 | WerrorS("nesting too deep"); |
---|
[e0749e8] | 412 | err=TRUE; |
---|
| 413 | } |
---|
| 414 | else |
---|
| 415 | { |
---|
[a71a00] | 416 | err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL)); |
---|
| 417 | |
---|
[e0749e8] | 418 | //Print("kill locals for %s (level %d)\n",IDID(pn),myynest); |
---|
| 419 | killlocals(myynest); |
---|
[5c5638] | 420 | #ifndef NDEBUG |
---|
[e0749e8] | 421 | checkall(); |
---|
[3b1a83c] | 422 | #endif |
---|
[e0749e8] | 423 | //Print("end kill locals for %s (%d)\n",IDID(pn),myynest); |
---|
| 424 | } |
---|
[057e93c] | 425 | myynest--; |
---|
| 426 | si_echo=old_echo; |
---|
[64d729] | 427 | if (pi!=NULL) |
---|
| 428 | pi->trace_flag=save_flags; |
---|
[f09b51] | 429 | // omUpdateInfo(); |
---|
| 430 | // int m=om_Info.UsedBytes; |
---|
| 431 | // Print("exit %s, mem=%d\n",IDID(pn),m); |
---|
[0e1846] | 432 | return err; |
---|
| 433 | } |
---|
| 434 | |
---|
[77ff8e] | 435 | #ifdef USE_IILOCALRING |
---|
[a3bc95e] | 436 | ring *iiLocalRing; |
---|
[77ff8e] | 437 | #endif |
---|
[f92a39] | 438 | sleftv iiRETURNEXPR; |
---|
[0e1846] | 439 | int iiRETURNEXPR_len=0; |
---|
| 440 | |
---|
| 441 | #ifdef RDEBUG |
---|
| 442 | static void iiShowLevRings() |
---|
| 443 | { |
---|
| 444 | int i; |
---|
[a3bc95e] | 445 | #ifdef USE_IILOCALRING |
---|
[9bc0b8] | 446 | for (i=0;i<=myynest;i++) |
---|
[0e1846] | 447 | { |
---|
| 448 | Print("lev %d:",i); |
---|
| 449 | if (iiLocalRing[i]==NULL) PrintS("NULL"); |
---|
[e9fdf6] | 450 | else Print("%lx",(long)iiLocalRing[i]); |
---|
[6f83c3d] | 451 | PrintLn(); |
---|
[0e1846] | 452 | } |
---|
[77ff8e] | 453 | #endif |
---|
[3b1a83c] | 454 | #if 0 |
---|
[a3bc95e] | 455 | i=myynest; |
---|
| 456 | proclevel *p=procstack; |
---|
| 457 | while (p!=NULL) |
---|
[77ff8e] | 458 | { |
---|
[a3bc95e] | 459 | Print("lev %d:",i); |
---|
[573da6] | 460 | if (p->cRingHdl==NULL) PrintS("NULL"); |
---|
| 461 | else Print("%s",IDID(p->cRingHdl)); |
---|
[a3bc95e] | 462 | PrintLn(); |
---|
| 463 | p=p->next; |
---|
[77ff8e] | 464 | } |
---|
[a3bc95e] | 465 | #endif |
---|
[0e1846] | 466 | if (currRing==NULL) PrintS("curr:NULL\n"); |
---|
[e9fdf6] | 467 | else Print ("curr:%lx\n",(long)currRing); |
---|
[0e1846] | 468 | } |
---|
[bd4cb92] | 469 | #endif /* RDEBUG */ |
---|
[0e1846] | 470 | |
---|
| 471 | static void iiCheckNest() |
---|
| 472 | { |
---|
| 473 | if (myynest >= iiRETURNEXPR_len-1) |
---|
| 474 | { |
---|
[0a3ddd] | 475 | #ifdef USE_IILOCALRING |
---|
[c232af] | 476 | iiLocalRing=(ring *)omreallocSize(iiLocalRing, |
---|
[0e1846] | 477 | iiRETURNEXPR_len*sizeof(ring), |
---|
| 478 | (iiRETURNEXPR_len+16)*sizeof(ring)); |
---|
[8b96123] | 479 | memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring)); |
---|
[77ff8e] | 480 | #endif |
---|
[0e1846] | 481 | iiRETURNEXPR_len+=16; |
---|
| 482 | } |
---|
| 483 | } |
---|
[5edb77] | 484 | BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv* sl) |
---|
[0e1846] | 485 | { |
---|
| 486 | int err; |
---|
[2ba9a6] | 487 | procinfov pi = IDPROC(pn); |
---|
[bcd557] | 488 | if(pi->is_static && myynest==0) |
---|
| 489 | { |
---|
[5480da] | 490 | Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.", |
---|
[ed3c47] | 491 | pi->libname, pi->procname); |
---|
[5edb77] | 492 | return TRUE; |
---|
[5480da] | 493 | } |
---|
[0e1846] | 494 | iiCheckNest(); |
---|
[77ff8e] | 495 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 496 | iiLocalRing[myynest]=currRing; |
---|
[9bc0b8] | 497 | //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn)); |
---|
[77ff8e] | 498 | #endif |
---|
[f92a39] | 499 | iiRETURNEXPR.Init(); |
---|
[a3bc95e] | 500 | procstack->push(pi->procname); |
---|
[50a84c] | 501 | if ((traceit&TRACE_SHOW_PROC) |
---|
| 502 | || (pi->trace_flag&TRACE_SHOW_PROC)) |
---|
[0e1846] | 503 | { |
---|
[fca547] | 504 | if (traceit&TRACE_SHOW_LINENO) PrintLn(); |
---|
| 505 | Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest); |
---|
[0e1846] | 506 | } |
---|
| 507 | #ifdef RDEBUG |
---|
| 508 | if (traceit&TRACE_SHOW_RINGS) iiShowLevRings(); |
---|
| 509 | #endif |
---|
[057e93c] | 510 | switch (pi->language) |
---|
| 511 | { |
---|
[de5fe1] | 512 | default: |
---|
| 513 | case LANG_NONE: |
---|
| 514 | WerrorS("undefined proc"); |
---|
[77ff8e] | 515 | err=TRUE; |
---|
| 516 | break; |
---|
[6f83c3d] | 517 | |
---|
[77ff8e] | 518 | case LANG_SINGULAR: |
---|
[a3bc95e] | 519 | if ((pi->pack!=NULL)&&(currPack!=pi->pack)) |
---|
| 520 | { |
---|
| 521 | currPack=pi->pack; |
---|
[8b96123] | 522 | iiCheckPack(currPack); |
---|
[a3bc95e] | 523 | currPackHdl=packFindHdl(currPack); |
---|
| 524 | //Print("set pack=%s\n",IDID(currPackHdl)); |
---|
| 525 | } |
---|
| 526 | else if ((pack!=NULL)&&(currPack!=pack)) |
---|
| 527 | { |
---|
| 528 | currPack=pack; |
---|
[8b96123] | 529 | iiCheckPack(currPack); |
---|
[a3bc95e] | 530 | currPackHdl=packFindHdl(currPack); |
---|
[873d82] | 531 | //Print("set pack=%s\n",IDID(currPackHdl)); |
---|
[a3bc95e] | 532 | } |
---|
[77ff8e] | 533 | err=iiPStart(pn,sl); |
---|
| 534 | break; |
---|
| 535 | case LANG_C: |
---|
[c232af] | 536 | leftv res = (leftv)omAlloc0Bin(sleftv_bin); |
---|
[77ff8e] | 537 | err = (pi->data.o.function)(res, sl); |
---|
[f92a39] | 538 | iiRETURNEXPR.Copy(res); |
---|
[c232af] | 539 | omFreeBin((ADDRESS)res, sleftv_bin); |
---|
[77ff8e] | 540 | break; |
---|
[2ba9a6] | 541 | } |
---|
[50a84c] | 542 | if ((traceit&TRACE_SHOW_PROC) |
---|
| 543 | || (pi->trace_flag&TRACE_SHOW_PROC)) |
---|
[0e1846] | 544 | { |
---|
[fca547] | 545 | if (traceit&TRACE_SHOW_LINENO) PrintLn(); |
---|
| 546 | Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest); |
---|
[0e1846] | 547 | } |
---|
[9bc0b8] | 548 | //char *n="NULL"; |
---|
| 549 | //if (currRingHdl!=NULL) n=IDID(currRingHdl); |
---|
| 550 | //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn)); |
---|
[0e1846] | 551 | #ifdef RDEBUG |
---|
| 552 | if (traceit&TRACE_SHOW_RINGS) iiShowLevRings(); |
---|
| 553 | #endif |
---|
| 554 | if (err) |
---|
| 555 | { |
---|
[f92a39] | 556 | iiRETURNEXPR.CleanUp(); |
---|
| 557 | //iiRETURNEXPR.Init(); //done by CleanUp |
---|
[0e1846] | 558 | } |
---|
[77ff8e] | 559 | #ifdef USE_IILOCALRING |
---|
[3b1a83c] | 560 | #if 0 |
---|
[573da6] | 561 | if(procstack->cRing != iiLocalRing[myynest]) Print("iiMake_proc: 1 ring not saved procs:%x, iiLocal:%x\n",procstack->cRing, iiLocalRing[myynest]); |
---|
[3b1a83c] | 562 | #endif |
---|
[0e1846] | 563 | if (iiLocalRing[myynest] != currRing) |
---|
| 564 | { |
---|
[9bc0b8] | 565 | if (currRing!=NULL) |
---|
[31a392] | 566 | { |
---|
[f92a39] | 567 | if (((iiRETURNEXPR.Typ()>BEGIN_RING) |
---|
| 568 | && (iiRETURNEXPR.Typ()<END_RING)) |
---|
| 569 | || ((iiRETURNEXPR.Typ()==LIST_CMD) |
---|
| 570 | && (lRingDependend((lists)iiRETURNEXPR.Data())))) |
---|
[9bc0b8] | 571 | { |
---|
| 572 | //idhdl hn; |
---|
[85e68dd] | 573 | const char *n; |
---|
| 574 | const char *o; |
---|
[9bc0b8] | 575 | idhdl nh=NULL, oh=NULL; |
---|
| 576 | if (iiLocalRing[myynest]!=NULL) |
---|
| 577 | oh=rFindHdl(iiLocalRing[myynest],NULL, NULL); |
---|
| 578 | if (oh!=NULL) o=oh->id; |
---|
| 579 | else o="none"; |
---|
| 580 | if (currRing!=NULL) |
---|
| 581 | nh=rFindHdl(currRing,NULL, NULL); |
---|
| 582 | if (nh!=NULL) n=nh->id; |
---|
| 583 | else n="none"; |
---|
| 584 | Werror("ring change during procedure call: %s -> %s (level %d)",o,n,myynest); |
---|
[f92a39] | 585 | iiRETURNEXPR.CleanUp(); |
---|
[9bc0b8] | 586 | err=TRUE; |
---|
| 587 | } |
---|
[0e1846] | 588 | } |
---|
[9f12b01] | 589 | currRing=iiLocalRing[myynest]; |
---|
[3b1a83c] | 590 | } |
---|
[9bc0b8] | 591 | if ((currRing==NULL) |
---|
| 592 | && (currRingHdl!=NULL)) |
---|
| 593 | currRing=IDRING(currRingHdl); |
---|
| 594 | else |
---|
[3b1a83c] | 595 | if ((currRing!=NULL) && |
---|
[9f12b01] | 596 | ((currRingHdl==NULL)||(IDRING(currRingHdl)!=currRing) |
---|
| 597 | ||(IDLEV(currRingHdl)>=myynest))) |
---|
[3b1a83c] | 598 | { |
---|
| 599 | rSetHdl(rFindHdl(currRing,NULL, NULL)); |
---|
| 600 | iiLocalRing[myynest]=NULL; |
---|
[77ff8e] | 601 | } |
---|
| 602 | #else /* USE_IILOCALRING */ |
---|
[573da6] | 603 | if (procstack->cRing != currRing) |
---|
[a3bc95e] | 604 | { |
---|
[573da6] | 605 | //if (procstack->cRingHdl!=NULL) |
---|
| 606 | //Print("procstack:%s,",IDID(procstack->cRingHdl)); |
---|
[a3bc95e] | 607 | //if (currRingHdl!=NULL) |
---|
| 608 | //Print(" curr:%s\n",IDID(currRingHdl)); |
---|
[573da6] | 609 | //Print("pr:%x, curr: %x\n",procstack->cRing,currRing); |
---|
[f92a39] | 610 | if (((iiRETURNEXPR.Typ()>BEGIN_RING) |
---|
| 611 | && (iiRETURNEXPR.Typ()<END_RING)) |
---|
| 612 | || ((iiRETURNEXPR.Typ()==LIST_CMD) |
---|
| 613 | && (lRingDependend((lists)iiRETURNEXPR.Data())))) |
---|
[a3bc95e] | 614 | { |
---|
| 615 | //idhdl hn; |
---|
| 616 | char *n; |
---|
| 617 | char *o; |
---|
[573da6] | 618 | if (procstack->cRing!=NULL) |
---|
[a3bc95e] | 619 | { |
---|
| 620 | //PrintS("reset ring\n"); |
---|
[573da6] | 621 | procstack->cRingHdl=rFindHdl(procstack->cRing,NULL, NULL); |
---|
| 622 | if (procstack->cRingHdl==NULL) |
---|
| 623 | procstack->cRingHdl= |
---|
| 624 | rFindHdl(procstack->cRing,NULL,procstack->currPack->idroot); |
---|
| 625 | if (procstack->cRingHdl==NULL) |
---|
| 626 | procstack->cRingHdl= |
---|
| 627 | rFindHdl(procstack->cRing,NULL,basePack->idroot); |
---|
| 628 | o=IDID(procstack->cRingHdl); |
---|
| 629 | currRing=procstack->cRing; |
---|
| 630 | currRingHdl=procstack->cRingHdl; |
---|
[a3bc95e] | 631 | } |
---|
| 632 | else o="none"; |
---|
| 633 | if (currRing!=NULL) n=IDID(currRingHdl); |
---|
| 634 | else n="none"; |
---|
| 635 | if (currRing==NULL) |
---|
| 636 | { |
---|
| 637 | Werror("ring change during procedure call: %s -> %s",o,n); |
---|
[f92a39] | 638 | iiRETURNEXPR.CleanUp(); |
---|
[a3bc95e] | 639 | err=TRUE; |
---|
| 640 | } |
---|
| 641 | } |
---|
[573da6] | 642 | if (procstack->cRingHdl!=NULL) |
---|
[a3bc95e] | 643 | { |
---|
[573da6] | 644 | rSetHdl(procstack->cRingHdl); |
---|
[a3bc95e] | 645 | } |
---|
| 646 | else |
---|
| 647 | { currRingHdl=NULL; currRing=NULL; } |
---|
| 648 | } |
---|
| 649 | #endif /* USE_IILOCALRING */ |
---|
[0e1846] | 650 | if (iiCurrArgs!=NULL) |
---|
| 651 | { |
---|
[bcd557] | 652 | if (!err) Warn("too many arguments for %s",IDID(pn)); |
---|
[0e1846] | 653 | iiCurrArgs->CleanUp(); |
---|
[c232af] | 654 | omFreeBin((ADDRESS)iiCurrArgs, sleftv_bin); |
---|
[0e1846] | 655 | iiCurrArgs=NULL; |
---|
| 656 | } |
---|
[a3bc95e] | 657 | procstack->pop(); |
---|
[bcd557] | 658 | if (err) |
---|
[5edb77] | 659 | return TRUE; |
---|
| 660 | return FALSE; |
---|
[0e1846] | 661 | } |
---|
| 662 | |
---|
| 663 | /*2 |
---|
| 664 | * start an example (as a proc), |
---|
| 665 | * destroys the string 'example' |
---|
| 666 | */ |
---|
[057e93c] | 667 | BOOLEAN iiEStart(char* example, procinfo *pi) |
---|
[0e1846] | 668 | { |
---|
| 669 | BOOLEAN err; |
---|
[057e93c] | 670 | int old_echo=si_echo; |
---|
[0e1846] | 671 | |
---|
| 672 | iiCheckNest(); |
---|
[a3bc95e] | 673 | procstack->push(example); |
---|
[77ff8e] | 674 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 675 | iiLocalRing[myynest]=currRing; |
---|
[77ff8e] | 676 | #endif |
---|
[0e1846] | 677 | if (traceit&TRACE_SHOW_PROC) |
---|
| 678 | { |
---|
| 679 | if (traceit&TRACE_SHOW_LINENO) printf("\n"); |
---|
| 680 | printf("entering example (level %d)\n",myynest); |
---|
| 681 | } |
---|
| 682 | myynest++; |
---|
[a71a00] | 683 | |
---|
| 684 | err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0)); |
---|
| 685 | |
---|
[0e1846] | 686 | killlocals(myynest); |
---|
| 687 | myynest--; |
---|
[057e93c] | 688 | si_echo=old_echo; |
---|
[0e1846] | 689 | if (traceit&TRACE_SHOW_PROC) |
---|
| 690 | { |
---|
| 691 | if (traceit&TRACE_SHOW_LINENO) printf("\n"); |
---|
| 692 | printf("leaving -example- (level %d)\n",myynest); |
---|
| 693 | } |
---|
[77ff8e] | 694 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 695 | if (iiLocalRing[myynest] != currRing) |
---|
| 696 | { |
---|
| 697 | if (iiLocalRing[myynest]!=NULL) |
---|
| 698 | { |
---|
[cf42ab1] | 699 | rSetHdl(rFindHdl(iiLocalRing[myynest],NULL, NULL)); |
---|
[0e1846] | 700 | iiLocalRing[myynest]=NULL; |
---|
| 701 | } |
---|
| 702 | else |
---|
| 703 | { |
---|
| 704 | currRingHdl=NULL; |
---|
| 705 | currRing=NULL; |
---|
| 706 | } |
---|
| 707 | } |
---|
[77ff8e] | 708 | #else /* USE_IILOCALRING */ |
---|
[a3bc95e] | 709 | #endif /* USE_IILOCALRING */ |
---|
[77ff8e] | 710 | if (NS_LRING != currRing) |
---|
| 711 | { |
---|
| 712 | if (NS_LRING!=NULL) |
---|
| 713 | { |
---|
[573da6] | 714 | idhdl rh=procstack->cRingHdl; |
---|
[bd4cb92] | 715 | if ((rh==NULL)||(IDRING(rh)!=NS_LRING)) |
---|
| 716 | rh=rFindHdl(NS_LRING,NULL, NULL); |
---|
| 717 | rSetHdl(rh); |
---|
[77ff8e] | 718 | } |
---|
| 719 | else |
---|
| 720 | { |
---|
| 721 | currRingHdl=NULL; |
---|
| 722 | currRing=NULL; |
---|
| 723 | } |
---|
| 724 | } |
---|
[a3bc95e] | 725 | //#endif /* USE_IILOCALRING */ |
---|
| 726 | procstack->pop(); |
---|
[0e1846] | 727 | return err; |
---|
| 728 | } |
---|
| 729 | |
---|
[57dcd6] | 730 | int huhu_mod_init(SModulFunctions*){ return 0; } |
---|
| 731 | |
---|
| 732 | #define SI_GET_BUILTIN_MOD_INIT(name) \ |
---|
| 733 | int name##_mod_init(SModulFunctions*); \ |
---|
| 734 | if (strcmp(libname, #name ".so") == 0) { return name##_mod_init; } |
---|
| 735 | |
---|
| 736 | |
---|
| 737 | SModulFunc_t |
---|
| 738 | iiGetBuiltinModInit(char* libname) |
---|
| 739 | { |
---|
| 740 | SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT) |
---|
| 741 | |
---|
| 742 | return NULL; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | |
---|
| 746 | #undef SI_GET_BUILTIN_MOD_INIT |
---|
| 747 | |
---|
| 748 | |
---|
[8edd35] | 749 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[85e68dd] | 750 | BOOLEAN iiTryLoadLib(leftv v, const char *id) |
---|
[8edd35] | 751 | { |
---|
| 752 | BOOLEAN LoadResult = TRUE; |
---|
| 753 | char libnamebuf[128]; |
---|
[c232af] | 754 | char *libname = (char *)omAlloc(strlen(id)+5); |
---|
[85e68dd] | 755 | const char *suffix[] = { "", ".lib", ".so", ".sl", NULL }; |
---|
[8edd35] | 756 | int i = 0; |
---|
[6909cfb] | 757 | // FILE *fp; |
---|
| 758 | // package pack; |
---|
| 759 | // idhdl packhdl; |
---|
[8edd35] | 760 | lib_types LT; |
---|
[743c32] | 761 | for(i=0; suffix[i] != NULL; i++) |
---|
| 762 | { |
---|
[8edd35] | 763 | sprintf(libname, "%s%s", id, suffix[i]); |
---|
| 764 | *libname = mytolower(*libname); |
---|
[2166892] | 765 | if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND) |
---|
[743c32] | 766 | { |
---|
[2166892] | 767 | char *s=omStrDup(libname); |
---|
| 768 | char libnamebuf[256]; |
---|
| 769 | |
---|
| 770 | if (LT==LT_SINGULAR) |
---|
[22ed4c] | 771 | LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE); |
---|
[24590f] | 772 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[2166892] | 773 | else if ((LT==LT_ELF) || (LT==LT_HPUX)) |
---|
| 774 | LoadResult = load_modules(s,libnamebuf,FALSE); |
---|
[24590f] | 775 | #endif |
---|
[801d2b] | 776 | else if (LT==LT_BUILTIN) |
---|
| 777 | { |
---|
[57dcd6] | 778 | LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s)); |
---|
[801d2b] | 779 | } |
---|
[2166892] | 780 | if(!LoadResult ) |
---|
[743c32] | 781 | { |
---|
[8edd35] | 782 | v->name = iiConvName(libname); |
---|
| 783 | break; |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | } |
---|
[c232af] | 787 | omFree(libname); |
---|
[8edd35] | 788 | return LoadResult; |
---|
| 789 | } |
---|
| 790 | |
---|
[1d1101] | 791 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[50cbdc] | 792 | /* check, if library lib has already been loaded |
---|
[698457] | 793 | if yes, writes filename of lib into where and returns TRUE, |
---|
| 794 | no, returns FALSE |
---|
| 795 | */ |
---|
| 796 | BOOLEAN iiLocateLib(const char* lib, char* where) |
---|
| 797 | { |
---|
| 798 | idhdl hl; |
---|
[4e4ece7] | 799 | |
---|
[5121f6] | 800 | char *p; |
---|
[50cbdc] | 801 | |
---|
[5af2f9] | 802 | hl = IDROOT->get("LIB", 0); |
---|
[5121f6] | 803 | if (hl == NULL || (p=strstr(IDSTRING(hl), lib)) == NULL) return FALSE; |
---|
| 804 | if ((p!=IDSTRING(hl)) && (*(p-1)!=',')) return FALSE; |
---|
[4e4ece7] | 805 | |
---|
[698457] | 806 | if (strstr(IDSTRING(hl), ",") == NULL) |
---|
| 807 | { |
---|
| 808 | strcpy(where, IDSTRING(hl)); |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
[c232af] | 812 | char* tmp = omStrDup(IDSTRING(hl)); |
---|
[698457] | 813 | char* tok = strtok(tmp, ","); |
---|
| 814 | do |
---|
| 815 | { |
---|
| 816 | if (strstr(tok, lib) != NULL) break; |
---|
| 817 | tok = strtok(NULL, ","); |
---|
| 818 | } |
---|
| 819 | while (tok != NULL); |
---|
| 820 | assume(tok != NULL); |
---|
| 821 | strcpy(where, tok); |
---|
[c232af] | 822 | omFree(tmp); |
---|
[698457] | 823 | } |
---|
| 824 | return TRUE; |
---|
| 825 | } |
---|
[4e4ece7] | 826 | |
---|
[22ed4c] | 827 | BOOLEAN iiLibCmd( char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force ) |
---|
[0e1846] | 828 | { |
---|
| 829 | char libnamebuf[128]; |
---|
[6909cfb] | 830 | // procinfov pi; |
---|
| 831 | // idhdl h; |
---|
[a3bc95e] | 832 | idhdl pl; |
---|
[6909cfb] | 833 | // idhdl hl; |
---|
| 834 | // long pos = 0L; |
---|
[a3bc95e] | 835 | char *plib = iiConvName(newlib); |
---|
[dfc6b54] | 836 | FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror ); |
---|
[6909cfb] | 837 | // int lines = 1; |
---|
[42c4e6] | 838 | BOOLEAN LoadResult = TRUE; |
---|
| 839 | |
---|
[0e1846] | 840 | if (fp==NULL) |
---|
| 841 | { |
---|
| 842 | return TRUE; |
---|
| 843 | } |
---|
[a3bc95e] | 844 | pl = basePack->idroot->get(plib,0); |
---|
| 845 | if (pl==NULL) |
---|
| 846 | { |
---|
[3b1a83c] | 847 | pl = enterid( plib,0, PACKAGE_CMD, |
---|
[a3bc95e] | 848 | &(basePack->idroot), TRUE ); |
---|
| 849 | IDPACKAGE(pl)->language = LANG_SINGULAR; |
---|
| 850 | IDPACKAGE(pl)->libname=omStrDup(newlib); |
---|
| 851 | } |
---|
| 852 | else |
---|
| 853 | { |
---|
| 854 | if(IDTYP(pl)!=PACKAGE_CMD) |
---|
| 855 | { |
---|
[7a949a] | 856 | WarnS("not of type package."); |
---|
[a3bc95e] | 857 | fclose(fp); |
---|
| 858 | return TRUE; |
---|
| 859 | } |
---|
[22ed4c] | 860 | if (!force) return FALSE; |
---|
[a3bc95e] | 861 | } |
---|
[22ed4c] | 862 | LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror); |
---|
[a3bc95e] | 863 | omFree((ADDRESS)newlib); |
---|
| 864 | |
---|
| 865 | if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE; |
---|
[c232af] | 866 | omFree((ADDRESS)plib); |
---|
[a3bc95e] | 867 | |
---|
[21fa0b] | 868 | return LoadResult; |
---|
[8edd35] | 869 | } |
---|
[c3cb95] | 870 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[31a392] | 871 | static void iiCleanProcs(idhdl &root) |
---|
[c3cb95] | 872 | { |
---|
[2bb771] | 873 | idhdl prev=NULL; |
---|
[c3cb95] | 874 | loop |
---|
| 875 | { |
---|
| 876 | if (root==NULL) return; |
---|
| 877 | if (IDTYP(root)==PROC_CMD) |
---|
| 878 | { |
---|
[560432] | 879 | procinfo *pi=(procinfo*)IDDATA(root); |
---|
[c3cb95] | 880 | if ((pi->language == LANG_SINGULAR) |
---|
| 881 | && (pi->data.s.body_start == 0L)) |
---|
| 882 | { |
---|
| 883 | // procinfo data incorrect: |
---|
| 884 | // - no proc body can start at the beginning of the file |
---|
[560432] | 885 | killhdl(root); |
---|
[2bb771] | 886 | if (prev==NULL) |
---|
[bd4cb92] | 887 | root=IDROOT; |
---|
[2bb771] | 888 | else |
---|
| 889 | { |
---|
| 890 | root=prev; |
---|
| 891 | prev=NULL; |
---|
| 892 | } |
---|
| 893 | continue; |
---|
[c3cb95] | 894 | } |
---|
| 895 | } |
---|
[2bb771] | 896 | prev=root; |
---|
[c3cb95] | 897 | root=IDNEXT(root); |
---|
| 898 | } |
---|
| 899 | } |
---|
[42c4e6] | 900 | static void iiRunInit(package p) |
---|
| 901 | { |
---|
[31a392] | 902 | idhdl h=p->idroot->get("mod_init",0); |
---|
| 903 | if (h==NULL) return; |
---|
| 904 | if (IDTYP(h)==PROC_CMD) |
---|
[42c4e6] | 905 | { |
---|
[31a392] | 906 | int save=yylineno; |
---|
| 907 | myynest++; |
---|
[6909cfb] | 908 | // procinfo *pi=(procinfo*)IDDATA(h); |
---|
[31a392] | 909 | //PrintS("mod_init found\n"); |
---|
| 910 | iiMake_proc(h,p,NULL); |
---|
| 911 | myynest--; |
---|
| 912 | yylineno=save; |
---|
[42c4e6] | 913 | } |
---|
| 914 | } |
---|
[8edd35] | 915 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[3621e73] | 916 | BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, char*newlib, |
---|
[8edd35] | 917 | idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror) |
---|
| 918 | { |
---|
[6a51ef] | 919 | extern FILE *yylpin; |
---|
| 920 | libstackv ls_start = library_stack; |
---|
[5480da] | 921 | lib_style_types lib_style; |
---|
[6a51ef] | 922 | |
---|
| 923 | yylpin = fp; |
---|
[4e4ece7] | 924 | #if YYLPDEBUG > 1 |
---|
[6a51ef] | 925 | print_init(); |
---|
[4e4ece7] | 926 | #endif |
---|
[799ce1] | 927 | extern int lpverbose; |
---|
[4e4ece7] | 928 | if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1; |
---|
| 929 | else lpverbose=0; |
---|
[2f8028] | 930 | // yylplex sets also text_buffer |
---|
| 931 | if (text_buffer!=NULL) *text_buffer='\0'; |
---|
[d3e630] | 932 | yylplex(newlib, libnamebuf, &lib_style, pl, autoexport); |
---|
[805b06c] | 933 | if(yylp_errno) |
---|
| 934 | { |
---|
[6a51ef] | 935 | Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno, |
---|
[5c8eae0] | 936 | current_pos(0)); |
---|
[805b06c] | 937 | if(yylp_errno==YYLP_BAD_CHAR) |
---|
| 938 | { |
---|
[60a3add] | 939 | Werror(yylp_errlist[yylp_errno], *text_buffer, yylplineno); |
---|
[c232af] | 940 | omFree((ADDRESS)text_buffer); |
---|
[9a11fe] | 941 | text_buffer=NULL; |
---|
[805b06c] | 942 | } |
---|
| 943 | else |
---|
[60a3add] | 944 | Werror(yylp_errlist[yylp_errno], yylplineno); |
---|
[6a51ef] | 945 | Werror("Cannot load library,... aborting."); |
---|
| 946 | reinit_yylp(); |
---|
| 947 | fclose( yylpin ); |
---|
[bd4cb92] | 948 | iiCleanProcs(IDROOT); |
---|
[6a51ef] | 949 | return TRUE; |
---|
[5c8eae0] | 950 | } |
---|
[4e4ece7] | 951 | if (BVERBOSE(V_LOAD_LIB)) |
---|
| 952 | Print( "// ** loaded %s %s\n", libnamebuf, text_buffer); |
---|
[805b06c] | 953 | if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB))) |
---|
| 954 | { |
---|
[40706c] | 955 | Warn( "library %s has old format. This format is still accepted,", newlib); |
---|
| 956 | Warn( "but for functionality you may wish to change to the new"); |
---|
| 957 | Warn( "format. Please refer to the manual for further information."); |
---|
[0a3ddd] | 958 | } |
---|
[6a51ef] | 959 | reinit_yylp(); |
---|
| 960 | fclose( yylpin ); |
---|
[dae004] | 961 | fp = NULL; |
---|
[42c4e6] | 962 | iiRunInit(IDPACKAGE(pl)); |
---|
[64d729] | 963 | |
---|
[6a51ef] | 964 | { |
---|
| 965 | libstackv ls; |
---|
[805b06c] | 966 | for(ls = library_stack; (ls != NULL) && (ls != ls_start); ) |
---|
| 967 | { |
---|
| 968 | if(ls->to_be_done) |
---|
| 969 | { |
---|
[5c8eae0] | 970 | ls->to_be_done=FALSE; |
---|
[22ed4c] | 971 | iiLibCmd(ls->get(),autoexport,tellerror,FALSE); |
---|
[5c8eae0] | 972 | ls = ls->pop(newlib); |
---|
[6a51ef] | 973 | } |
---|
| 974 | } |
---|
| 975 | #if 0 |
---|
[6f83c3d] | 976 | PrintS("--------------------\n"); |
---|
| 977 | for(ls = library_stack; ls != NULL; ls = ls->next) |
---|
| 978 | { |
---|
[6a51ef] | 979 | Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(), |
---|
| 980 | ls->to_be_done ? "not loaded" : "loaded"); |
---|
| 981 | } |
---|
[6f83c3d] | 982 | PrintS("--------------------\n"); |
---|
[6a51ef] | 983 | #endif |
---|
| 984 | } |
---|
[21fa0b] | 985 | |
---|
[dae004] | 986 | if(fp != NULL) fclose(fp); |
---|
[0e1846] | 987 | return FALSE; |
---|
| 988 | } |
---|
| 989 | |
---|
[8edd35] | 990 | |
---|
[1d1101] | 991 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[85e68dd] | 992 | procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname, |
---|
| 993 | const char *procname, int line, long pos, BOOLEAN pstatic) |
---|
[2ba9a6] | 994 | { |
---|
[c232af] | 995 | pi->libname = omStrDup(libname); |
---|
[2ba9a6] | 996 | |
---|
[057e93c] | 997 | if( strcmp(procname,"_init")==0) |
---|
| 998 | { |
---|
[805b06c] | 999 | pi->procname = iiConvName(libname); |
---|
| 1000 | } |
---|
| 1001 | else |
---|
[c232af] | 1002 | pi->procname = omStrDup(procname); |
---|
[2ba9a6] | 1003 | pi->language = LANG_SINGULAR; |
---|
| 1004 | pi->ref = 1; |
---|
[a3bc95e] | 1005 | pi->pack = NULL; |
---|
[6a51ef] | 1006 | pi->is_static = pstatic; |
---|
[2ba9a6] | 1007 | pi->data.s.proc_start = pos; |
---|
[46d09b] | 1008 | pi->data.s.def_end = 0L; |
---|
[2ba9a6] | 1009 | pi->data.s.help_start = 0L; |
---|
[6be769] | 1010 | pi->data.s.help_end = 0L; |
---|
[2ba9a6] | 1011 | pi->data.s.body_start = 0L; |
---|
| 1012 | pi->data.s.body_end = 0L; |
---|
| 1013 | pi->data.s.example_start = 0L; |
---|
| 1014 | pi->data.s.proc_lineno = line; |
---|
| 1015 | pi->data.s.body_lineno = 0; |
---|
| 1016 | pi->data.s.example_lineno = 0; |
---|
| 1017 | pi->data.s.body = NULL; |
---|
[847cad] | 1018 | pi->data.s.help_chksum = 0; |
---|
[2ba9a6] | 1019 | return(pi); |
---|
| 1020 | } |
---|
| 1021 | |
---|
[fe72e1] | 1022 | #if 0 |
---|
| 1023 | // TODO!? |
---|
| 1024 | procinfo *iiInitSingularProcinfo(procinfo* pi, const char *libname, |
---|
| 1025 | const char *procname, int line, long pos, |
---|
| 1026 | BOOLEAN pstatic /*= FALSE*/) |
---|
| 1027 | { |
---|
| 1028 | pi->libname = (char *)malloc(strlen(libname)+1); |
---|
| 1029 | memcpy(pi->libname, libname, strlen(libname)); |
---|
| 1030 | *(pi->libname+strlen(libname)) = '\0'; |
---|
| 1031 | |
---|
| 1032 | pi->procname = (char *)malloc(strlen(procname)+1); |
---|
| 1033 | strcpy(pi->procname, procname/*, strlen(procname)*/); |
---|
| 1034 | pi->language = LANG_SINGULAR; |
---|
| 1035 | pi->ref = 1; |
---|
| 1036 | pi->is_static = pstatic; |
---|
| 1037 | pi->data.s.proc_start = pos; |
---|
| 1038 | pi->data.s.def_end = 0L; |
---|
| 1039 | pi->data.s.help_start = 0L; |
---|
| 1040 | pi->data.s.body_start = 0L; |
---|
| 1041 | pi->data.s.body_end = 0L; |
---|
| 1042 | pi->data.s.example_start = 0L; |
---|
| 1043 | pi->data.s.proc_lineno = line; |
---|
| 1044 | pi->data.s.body_lineno = 0; |
---|
| 1045 | pi->data.s.example_lineno = 0; |
---|
| 1046 | pi->data.s.body = NULL; |
---|
| 1047 | pi->data.s.help_chksum = 0; |
---|
| 1048 | return(pi); |
---|
| 1049 | } |
---|
| 1050 | #endif |
---|
| 1051 | |
---|
[1d1101] | 1052 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[ce0ca7] | 1053 | int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, |
---|
[ed3c47] | 1054 | BOOLEAN(*func)(leftv res, leftv v)) |
---|
[1d1101] | 1055 | { |
---|
| 1056 | procinfov pi; |
---|
| 1057 | idhdl h; |
---|
| 1058 | |
---|
[36d920] | 1059 | #ifndef NDEBUG |
---|
| 1060 | int dummy; |
---|
| 1061 | if (IsCmd(procname,dummy)) |
---|
| 1062 | { |
---|
| 1063 | Werror(">>%s< is a reserved name",procname); |
---|
| 1064 | return 0; |
---|
| 1065 | } |
---|
| 1066 | #endif |
---|
| 1067 | |
---|
[3b1a83c] | 1068 | h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE); |
---|
[6f83c3d] | 1069 | if ( h!= NULL ) |
---|
| 1070 | { |
---|
[1d1101] | 1071 | pi = IDPROC(h); |
---|
[c232af] | 1072 | pi->libname = omStrDup(libname); |
---|
| 1073 | pi->procname = omStrDup(procname); |
---|
[1d1101] | 1074 | pi->language = LANG_C; |
---|
| 1075 | pi->ref = 1; |
---|
| 1076 | pi->is_static = pstatic; |
---|
| 1077 | pi->data.o.function = func; |
---|
| 1078 | return(1); |
---|
[6f83c3d] | 1079 | } |
---|
| 1080 | else |
---|
| 1081 | { |
---|
| 1082 | PrintS("iiAddCproc: failed.\n"); |
---|
[1d1101] | 1083 | } |
---|
| 1084 | return(0); |
---|
| 1085 | } |
---|
[cd6b45] | 1086 | |
---|
[ce0ca7] | 1087 | int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, |
---|
[c858fc2] | 1088 | BOOLEAN(*func)(leftv res, leftv v)) |
---|
| 1089 | { |
---|
| 1090 | int r=iiAddCproc(libname,procname,pstatic,func); |
---|
| 1091 | package s=currPack; |
---|
| 1092 | currPack=basePack; |
---|
| 1093 | if (r) r=iiAddCproc(libname,procname,pstatic,func); |
---|
| 1094 | currPack=s; |
---|
| 1095 | return r; |
---|
| 1096 | } |
---|
| 1097 | |
---|
[cd6b45] | 1098 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[825fb7] | 1099 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[c858fc2] | 1100 | BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport) |
---|
[cd6b45] | 1101 | { |
---|
[4eb5b5] | 1102 | #ifdef HAVE_STATIC |
---|
| 1103 | WerrorS("mod_init: static version can not load modules"); |
---|
| 1104 | return TRUE; |
---|
| 1105 | #else |
---|
[ce0ca7] | 1106 | typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname, |
---|
[cd6b45] | 1107 | BOOLEAN pstatic, |
---|
| 1108 | BOOLEAN(*func)(leftv res, leftv v))); |
---|
[801d2b] | 1109 | SModulFunc_t fktn; |
---|
[cd6b45] | 1110 | idhdl pl; |
---|
| 1111 | char *plib = iiConvName(newlib); |
---|
| 1112 | BOOLEAN RET=TRUE; |
---|
| 1113 | int token; |
---|
| 1114 | char FullName[256]; |
---|
[64d729] | 1115 | |
---|
[a3dfd97] | 1116 | memset(FullName,0,256); |
---|
| 1117 | |
---|
[cd6b45] | 1118 | if( *fullname != '/' && *fullname != '.' ) |
---|
| 1119 | sprintf(FullName, "./%s", newlib); |
---|
[a3dfd97] | 1120 | else strncpy(FullName, fullname,255); |
---|
[64d729] | 1121 | |
---|
[cd6b45] | 1122 | |
---|
[bf4997] | 1123 | if(IsCmd(plib, token)) |
---|
[cd6b45] | 1124 | { |
---|
| 1125 | Werror("'%s' is resered identifier\n", plib); |
---|
| 1126 | goto load_modules_end; |
---|
| 1127 | } |
---|
[1bd25e] | 1128 | pl = IDROOT->get(plib,0); |
---|
[cd6b45] | 1129 | if (pl==NULL) |
---|
| 1130 | { |
---|
[3b1a83c] | 1131 | pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, |
---|
[1bd25e] | 1132 | TRUE ); |
---|
[cd6b45] | 1133 | IDPACKAGE(pl)->language = LANG_C; |
---|
[c232af] | 1134 | IDPACKAGE(pl)->libname=omStrDup(newlib); |
---|
[cd6b45] | 1135 | } |
---|
| 1136 | else |
---|
| 1137 | { |
---|
| 1138 | if(IDTYP(pl)!=PACKAGE_CMD) |
---|
| 1139 | { |
---|
[7a949a] | 1140 | Warn("not of type package."); |
---|
[64d729] | 1141 | goto load_modules_end; |
---|
[cd6b45] | 1142 | } |
---|
| 1143 | } |
---|
[f4399e] | 1144 | if (dynl_check_opened(FullName)) { |
---|
| 1145 | if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname); |
---|
| 1146 | return FALSE; |
---|
| 1147 | } |
---|
[7497447] | 1148 | if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL) |
---|
[cd6b45] | 1149 | { |
---|
[46ef83] | 1150 | Werror("dynl_open failed:%s", dynl_error()); |
---|
[cd6b45] | 1151 | Werror("%s not found", newlib); |
---|
[64d729] | 1152 | goto load_modules_end; |
---|
[cd6b45] | 1153 | } |
---|
| 1154 | else |
---|
| 1155 | { |
---|
[b6e51b] | 1156 | SModulFunctions sModulFunctions; |
---|
[31a392] | 1157 | |
---|
[a3dfd97] | 1158 | package s=currPack; |
---|
| 1159 | currPack=IDPACKAGE(pl); |
---|
[801d2b] | 1160 | fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init"); |
---|
[c858fc2] | 1161 | if( fktn!= NULL) |
---|
| 1162 | { |
---|
[b6e51b] | 1163 | sModulFunctions.iiArithAddCmd = iiArithAddCmd; |
---|
| 1164 | if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop; |
---|
| 1165 | else sModulFunctions.iiAddCproc = iiAddCproc; |
---|
| 1166 | (*fktn)(&sModulFunctions); |
---|
[c858fc2] | 1167 | } |
---|
[1fb78b] | 1168 | else Werror("mod_init: %s\n", dynl_error()); |
---|
[cd6b45] | 1169 | if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", fullname); |
---|
[a3dfd97] | 1170 | currPack->loaded=1; |
---|
| 1171 | currPack=s; |
---|
[cd6b45] | 1172 | } |
---|
| 1173 | RET=FALSE; |
---|
| 1174 | |
---|
| 1175 | load_modules_end: |
---|
| 1176 | return RET; |
---|
[31a392] | 1177 | #endif /*STATIC */ |
---|
[cd6b45] | 1178 | } |
---|
[825fb7] | 1179 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
[801d2b] | 1180 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
| 1181 | BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init) |
---|
| 1182 | { |
---|
| 1183 | int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, |
---|
| 1184 | BOOLEAN(*func)(leftv res, leftv v)); |
---|
| 1185 | typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname, |
---|
| 1186 | BOOLEAN pstatic, |
---|
| 1187 | BOOLEAN(*func)(leftv res, leftv v))); |
---|
[6909cfb] | 1188 | // SModulFunc_t fktn; |
---|
[801d2b] | 1189 | idhdl pl; |
---|
| 1190 | char *plib = iiConvName(newlib); |
---|
[6909cfb] | 1191 | // BOOLEAN RET=TRUE; |
---|
| 1192 | // int token; |
---|
[801d2b] | 1193 | |
---|
| 1194 | pl = IDROOT->get(plib,0); |
---|
[f4399e] | 1195 | if (pl!=NULL) |
---|
[801d2b] | 1196 | { |
---|
[f4399e] | 1197 | if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib); |
---|
| 1198 | omFree(plib); |
---|
| 1199 | return FALSE; |
---|
[801d2b] | 1200 | } |
---|
[f4399e] | 1201 | |
---|
| 1202 | pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, |
---|
| 1203 | TRUE ); |
---|
| 1204 | IDPACKAGE(pl)->language = LANG_C; |
---|
| 1205 | IDPACKAGE(pl)->libname=omStrDup(newlib); |
---|
| 1206 | |
---|
[801d2b] | 1207 | IDPACKAGE(pl)->handle=(void *)NULL; |
---|
| 1208 | SModulFunctions sModulFunctions; |
---|
| 1209 | |
---|
| 1210 | package s=currPack; |
---|
| 1211 | currPack=IDPACKAGE(pl); |
---|
| 1212 | if( init!= NULL) |
---|
| 1213 | { |
---|
| 1214 | sModulFunctions.iiArithAddCmd = iiArithAddCmd; |
---|
| 1215 | if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop; |
---|
| 1216 | else sModulFunctions.iiAddCproc = iiAddCproc; |
---|
| 1217 | (*init)(&sModulFunctions); |
---|
| 1218 | } |
---|
[57dcd6] | 1219 | if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib); |
---|
[801d2b] | 1220 | currPack->loaded=1; |
---|
| 1221 | currPack=s; |
---|
| 1222 | |
---|
| 1223 | return FALSE; |
---|
| 1224 | } |
---|
| 1225 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[36d920] | 1226 | void module_help_main(const char *newlib,const char *help) |
---|
[801d2b] | 1227 | { |
---|
| 1228 | char *plib = iiConvName(newlib); |
---|
[36d920] | 1229 | idhdl pl = basePack->idroot->get(plib,0); |
---|
[801d2b] | 1230 | if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD)) |
---|
[36d920] | 1231 | Werror(">>%s<< is not a package (trying to add package help)",plib); |
---|
[801d2b] | 1232 | else |
---|
| 1233 | { |
---|
| 1234 | package s=currPack; |
---|
| 1235 | currPack=IDPACKAGE(pl); |
---|
| 1236 | idhdl h=enterid(omStrDup("info"),0,STRING_CMD,&IDROOT,FALSE); |
---|
| 1237 | IDSTRING(h)=omStrDup(help); |
---|
| 1238 | currPack=s; |
---|
| 1239 | } |
---|
| 1240 | } |
---|
[36d920] | 1241 | void module_help_proc(const char *newlib,const char *p, const char *help) |
---|
[801d2b] | 1242 | { |
---|
| 1243 | char *plib = iiConvName(newlib); |
---|
[36d920] | 1244 | idhdl pl = basePack->idroot->get(plib,0); |
---|
[801d2b] | 1245 | if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD)) |
---|
[36d920] | 1246 | Werror(">>%s<< is not a package(trying to add help for %s)",plib,p); |
---|
[801d2b] | 1247 | else |
---|
| 1248 | { |
---|
| 1249 | package s=currPack; |
---|
| 1250 | currPack=IDPACKAGE(pl); |
---|
| 1251 | char buff[256]; |
---|
| 1252 | buff[255]='\0'; |
---|
| 1253 | strncpy(buff,p,255); |
---|
| 1254 | strncat(buff,"_help",255-strlen(p)); |
---|
| 1255 | idhdl h=enterid(omStrDup(buff),0,STRING_CMD,&IDROOT,FALSE); |
---|
| 1256 | IDSTRING(h)=omStrDup(help); |
---|
| 1257 | currPack=s; |
---|
| 1258 | } |
---|
| 1259 | } |
---|
| 1260 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[1cb879] | 1261 | |
---|
| 1262 | // loads a dynamic module from the binary path and returns a named function |
---|
| 1263 | // returns NULL, if something fails |
---|
| 1264 | void* binary_module_function(const char* newlib, const char* funcname) |
---|
| 1265 | { |
---|
| 1266 | void* result = NULL; |
---|
| 1267 | |
---|
[825fb7] | 1268 | #if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING) |
---|
[1cb879] | 1269 | WerrorS("static version can not load function from dynamic modules"); |
---|
| 1270 | #else |
---|
| 1271 | const char* bin_dir = feGetResource('b'); |
---|
| 1272 | if (!bin_dir) { return NULL; } |
---|
[a71a00] | 1273 | |
---|
| 1274 | char path_name[MAXPATHLEN]; |
---|
[1cb879] | 1275 | sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING); |
---|
| 1276 | |
---|
| 1277 | void* openlib = dynl_open(path_name); |
---|
| 1278 | if(!openlib) |
---|
| 1279 | { |
---|
| 1280 | Werror("dynl_open of %s failed:%s", path_name, dynl_error()); |
---|
| 1281 | return NULL; |
---|
| 1282 | } |
---|
| 1283 | result = dynl_sym(openlib, funcname); |
---|
| 1284 | if (!result) Werror("%s: %s\n", funcname, dynl_error()); |
---|
| 1285 | #endif |
---|
| 1286 | |
---|
| 1287 | return result; |
---|
| 1288 | } |
---|
| 1289 | |
---|
[1d1101] | 1290 | |
---|
[2ba9a6] | 1291 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[77ff8e] | 1292 | char mytoupper(char c) |
---|
| 1293 | { |
---|
| 1294 | if(c>=97 && c<=(97+26)) c-=32; |
---|
| 1295 | return(c); |
---|
| 1296 | } |
---|
| 1297 | |
---|
[8edd35] | 1298 | char mytolower(char c) |
---|
| 1299 | { |
---|
| 1300 | if(c>=65 && c<=(65+26)) c+=32; |
---|
| 1301 | return(c); |
---|
| 1302 | } |
---|
| 1303 | |
---|
[77ff8e] | 1304 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[75c0dc] | 1305 | //#if defined(WINNT) |
---|
| 1306 | //# define FS_SEP '\\' |
---|
| 1307 | //#else |
---|
| 1308 | //# define FS_SEP '/' |
---|
| 1309 | //#endif |
---|
[77ff8e] | 1310 | |
---|
[f43a74] | 1311 | char *iiConvName(const char *libname) |
---|
[2ba9a6] | 1312 | { |
---|
[c232af] | 1313 | char *tmpname = omStrDup(libname); |
---|
[9c35ef] | 1314 | char *p = strrchr(tmpname, DIR_SEP); |
---|
[ed3c47] | 1315 | char *r; |
---|
[77ff8e] | 1316 | if(p==NULL) p = tmpname; |
---|
| 1317 | else p++; |
---|
[08c2d6] | 1318 | r = (char *)strchr(p, '.'); |
---|
[77ff8e] | 1319 | if( r!= NULL) *r = '\0'; |
---|
[c232af] | 1320 | r = omStrDup(p); |
---|
[77ff8e] | 1321 | *r = mytoupper(*r); |
---|
| 1322 | // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r); |
---|
[c232af] | 1323 | omFree((ADDRESS)tmpname); |
---|
[6f83c3d] | 1324 | |
---|
[77ff8e] | 1325 | return(r); |
---|
[2ba9a6] | 1326 | } |
---|
| 1327 | |
---|
| 1328 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[c599b4] | 1329 | #if 0 /* debug only */ |
---|
[fca547] | 1330 | void piShowProcList() |
---|
[2ba9a6] | 1331 | { |
---|
| 1332 | idhdl h; |
---|
| 1333 | procinfo *proc; |
---|
| 1334 | char *name; |
---|
| 1335 | |
---|
| 1336 | Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function", |
---|
[13e3243] | 1337 | "line", "start", "line", "body", "line", "example"); |
---|
[46d09b] | 1338 | for(h = IDROOT; h != NULL; h = IDNEXT(h)) |
---|
[057e93c] | 1339 | { |
---|
| 1340 | if(IDTYP(h) == PROC_CMD) |
---|
| 1341 | { |
---|
[2ba9a6] | 1342 | proc = IDPROC(h); |
---|
[057e93c] | 1343 | if(strcmp(proc->procname, IDID(h))!=0) |
---|
| 1344 | { |
---|
[c232af] | 1345 | name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4); |
---|
[13e3243] | 1346 | sprintf(name, "%s -> %s", IDID(h), proc->procname); |
---|
[46d09b] | 1347 | Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name); |
---|
[c232af] | 1348 | omFree((ADDRESS)name); |
---|
[0077d9d] | 1349 | } |
---|
| 1350 | else |
---|
[46d09b] | 1351 | Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, |
---|
| 1352 | proc->procname); |
---|
[13e3243] | 1353 | if(proc->language==LANG_SINGULAR) |
---|
| 1354 | Print("line %4d,%-5ld %4d,%-5ld %4d,%-5ld\n", |
---|
[2ba9a6] | 1355 | proc->data.s.proc_lineno, proc->data.s.proc_start, |
---|
| 1356 | proc->data.s.body_lineno, proc->data.s.body_start, |
---|
| 1357 | proc->data.s.example_lineno, proc->data.s.example_start); |
---|
[0077d9d] | 1358 | else if(proc->language==LANG_C) |
---|
| 1359 | Print("type: object\n"); |
---|
[2ba9a6] | 1360 | } |
---|
| 1361 | } |
---|
| 1362 | } |
---|
[c599b4] | 1363 | #endif |
---|
[2ba9a6] | 1364 | |
---|
| 1365 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[fca547] | 1366 | //char *iiLineNo(char *procname, int lineno) |
---|
| 1367 | //{ |
---|
| 1368 | // char buf[256]; |
---|
| 1369 | // idhdl pn = ggetid(procname); |
---|
| 1370 | // procinfo *pi = IDPROC(pn); |
---|
| 1371 | // |
---|
| 1372 | // sprintf(buf, "%s %3d\0", procname, lineno); |
---|
| 1373 | // //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname, |
---|
| 1374 | // // lineno + pi->data.s.body_lineno); |
---|
| 1375 | // return(buf); |
---|
| 1376 | //} |
---|
[6a51ef] | 1377 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
| 1378 | #ifdef HAVE_LIBPARSER |
---|
[2e4ec14] | 1379 | void libstack::push(char */*p*/, char *libn) |
---|
[6a51ef] | 1380 | { |
---|
| 1381 | libstackv lp; |
---|
[5f4463] | 1382 | if( !iiGetLibStatus(libn)) |
---|
[743c32] | 1383 | { |
---|
| 1384 | for(lp = this;lp!=NULL;lp=lp->next) |
---|
| 1385 | { |
---|
[5f4463] | 1386 | if(strcmp(lp->get(), libn)==0) break; |
---|
[6a51ef] | 1387 | } |
---|
[743c32] | 1388 | if(lp==NULL) |
---|
| 1389 | { |
---|
[c232af] | 1390 | libstackv ls = (libstack *)omAlloc0Bin(libstack_bin); |
---|
[6a51ef] | 1391 | ls->next = this; |
---|
[5f4463] | 1392 | ls->libname = omStrDup(libn); |
---|
[6a51ef] | 1393 | ls->to_be_done = TRUE; |
---|
| 1394 | if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0; |
---|
| 1395 | library_stack = ls; |
---|
[5c8eae0] | 1396 | } |
---|
[6a51ef] | 1397 | } |
---|
| 1398 | } |
---|
| 1399 | |
---|
[2e4ec14] | 1400 | libstackv libstack::pop(char */*p*/) |
---|
[6a51ef] | 1401 | { |
---|
| 1402 | libstackv ls = this; |
---|
[c232af] | 1403 | //omFree((ADDRESS)ls->libname); |
---|
[6a51ef] | 1404 | library_stack = ls->next; |
---|
[c232af] | 1405 | omFreeBin((ADDRESS)ls, libstack_bin); |
---|
[6a51ef] | 1406 | return(library_stack); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | #endif /* HAVE_LIBPARSER */ |
---|
| 1410 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|