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