[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[0e1846] | 5 | /* |
---|
[e2f1c7] | 6 | * ABSTRACT: interpreter: LIB and help |
---|
[0e1846] | 7 | */ |
---|
| 8 | |
---|
| 9 | //#include <stdlib.h> |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include <string.h> |
---|
[c4041ef] | 12 | #include <ctype.h> |
---|
[cd6b45] | 13 | #include <sys/stat.h> |
---|
[0e1846] | 14 | |
---|
[b1dfaf] | 15 | #include <kernel/mod2.h> |
---|
[599326] | 16 | #include <Singular/static.h> |
---|
| 17 | #include <Singular/tok.h> |
---|
| 18 | #include <kernel/options.h> |
---|
| 19 | #include <Singular/ipid.h> |
---|
[b1dfaf] | 20 | #include <omalloc/omalloc.h> |
---|
[599326] | 21 | #include <kernel/febase.h> |
---|
| 22 | #include <kernel/ring.h> |
---|
| 23 | #include <Singular/subexpr.h> |
---|
| 24 | #include <Singular/ipshell.h> |
---|
| 25 | #include <Singular/lists.h> |
---|
[cd6b45] | 26 | |
---|
[2ff076] | 27 | #if SIZEOF_LONG == 8 |
---|
| 28 | #define SI_MAX_NEST 500 |
---|
[b78b73] | 29 | #elif defined(ix86_Win) |
---|
| 30 | #define SI_MAX_NEST 480 |
---|
[2ff076] | 31 | #else |
---|
| 32 | #define SI_MAX_NEST 1000 |
---|
| 33 | #endif |
---|
| 34 | |
---|
[01d9463] | 35 | #if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin) |
---|
[1cb879] | 36 | # define MODULE_SUFFIX bundle |
---|
| 37 | #elif defined(ix86_Win) |
---|
| 38 | # define MODULE_SUFFIX dll |
---|
| 39 | #else |
---|
| 40 | # define MODULE_SUFFIX so |
---|
| 41 | #endif |
---|
| 42 | |
---|
| 43 | #define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX) |
---|
| 44 | |
---|
| 45 | |
---|
[24590f] | 46 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[c858fc2] | 47 | BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport); |
---|
[24590f] | 48 | #endif |
---|
[730df2] | 49 | |
---|
[5480da] | 50 | #ifdef HAVE_LIBPARSER |
---|
| 51 | # include "libparse.h" |
---|
[c4bbf1f] | 52 | #else /* HAVE_LIBPARSER */ |
---|
[889f6e] | 53 | procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname, |
---|
| 54 | const char *procname, int line, long pos, BOOLEAN pstatic=FALSE); |
---|
[5480da] | 55 | #endif /* HAVE_LIBPARSER */ |
---|
[573da6] | 56 | #define NS_LRING (procstack->cRing) |
---|
[0e1846] | 57 | |
---|
[85e68dd] | 58 | extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval, |
---|
[b6e51b] | 59 | short nToktype, short nPos); |
---|
| 60 | |
---|
[599326] | 61 | #include <kernel/mod_raw.h> |
---|
[cd6b45] | 62 | |
---|
[6a51ef] | 63 | #ifdef HAVE_LIBPARSER |
---|
| 64 | void yylprestart (FILE *input_file ); |
---|
| 65 | int current_pos(int i=0); |
---|
| 66 | extern int yylp_errno; |
---|
| 67 | extern int yylplineno; |
---|
| 68 | extern char *yylp_errlist[]; |
---|
| 69 | void print_init(); |
---|
| 70 | libstackv library_stack; |
---|
| 71 | #endif |
---|
[2ba9a6] | 72 | |
---|
[c4041ef] | 73 | //int IsCmd(char *n, int tok); |
---|
[8edd35] | 74 | char mytolower(char c); |
---|
| 75 | |
---|
[50cbdc] | 76 | /*2 |
---|
| 77 | * return TRUE if the libray libname is already loaded |
---|
| 78 | */ |
---|
| 79 | BOOLEAN iiGetLibStatus(char *lib) |
---|
| 80 | { |
---|
| 81 | idhdl hl; |
---|
| 82 | |
---|
[a3bc95e] | 83 | char *plib = iiConvName(lib); |
---|
| 84 | hl = basePack->idroot->get(plib,0); |
---|
[42c4e6] | 85 | omFree(plib); |
---|
[a3bc95e] | 86 | if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD)) |
---|
| 87 | { |
---|
| 88 | return FALSE; |
---|
| 89 | } |
---|
| 90 | return (strcmp(lib,IDPACKAGE(hl)->libname)==0); |
---|
[50cbdc] | 91 | } |
---|
[cd6b45] | 92 | |
---|
[0e1846] | 93 | /*2 |
---|
| 94 | * find the library of an proc: |
---|
[2ba9a6] | 95 | * => return (pi->libname) |
---|
[0e1846] | 96 | */ |
---|
[2ba9a6] | 97 | char * iiGetLibName(procinfov pi) |
---|
[0e1846] | 98 | { |
---|
[f2dff02] | 99 | return pi->libname; |
---|
[0e1846] | 100 | } |
---|
[f2dff02] | 101 | |
---|
[0e1846] | 102 | /*2 |
---|
| 103 | * given a line 'proc[ ]+{name}[ \t]*' |
---|
| 104 | * return a pointer to name and set the end of '\0' |
---|
| 105 | * changes the input! |
---|
| 106 | * returns: e: pointer to 'end of name' |
---|
| 107 | * ct: changed char at the end of s |
---|
| 108 | */ |
---|
| 109 | char* iiProcName(char *buf, char & ct, char* &e) |
---|
| 110 | { |
---|
| 111 | char *s=buf+5; |
---|
| 112 | while (*s==' ') s++; |
---|
| 113 | e=s+1; |
---|
| 114 | while ((*e>' ') && (*e!='(')) e++; |
---|
| 115 | ct=*e; |
---|
| 116 | *e='\0'; |
---|
| 117 | return s; |
---|
| 118 | } |
---|
[057e93c] | 119 | |
---|
[0e1846] | 120 | /*2 |
---|
| 121 | * given a line with args, return the argstr |
---|
| 122 | */ |
---|
| 123 | char * iiProcArgs(char *e,BOOLEAN withParenth) |
---|
| 124 | { |
---|
[33e521] | 125 | while ((*e==' ') || (*e=='\t') || (*e=='(')) e++; |
---|
[0e1846] | 126 | if (*e<' ') |
---|
| 127 | { |
---|
| 128 | if (withParenth) |
---|
| 129 | { |
---|
| 130 | // no argument list, allow list # |
---|
[c232af] | 131 | return omStrDup("parameter list #;"); |
---|
[0e1846] | 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | // empty list |
---|
[c232af] | 136 | return omStrDup(""); |
---|
[0e1846] | 137 | } |
---|
| 138 | } |
---|
| 139 | BOOLEAN in_args; |
---|
| 140 | BOOLEAN args_found; |
---|
| 141 | char *s; |
---|
[f2dff02] | 142 | char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc |
---|
| 143 | int argstrlen=127; |
---|
[0e1846] | 144 | *argstr='\0'; |
---|
[938688] | 145 | int par=0; |
---|
[0e1846] | 146 | do |
---|
| 147 | { |
---|
| 148 | args_found=FALSE; |
---|
| 149 | s=e; // set s to the starting point of the arg |
---|
| 150 | // and search for the end |
---|
[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); |
---|
[6b4ff12] | 281 | char *dummy=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 | } |
---|
| 295 | |
---|
| 296 | /*2 |
---|
[057e93c] | 297 | * start a proc |
---|
[0e1846] | 298 | * parameters are built as exprlist |
---|
[057e93c] | 299 | * TODO:interrupt |
---|
| 300 | * return FALSE on success, TRUE if an error occurs |
---|
[0e1846] | 301 | */ |
---|
[057e93c] | 302 | BOOLEAN iiPStart(idhdl pn, sleftv * v) |
---|
[0e1846] | 303 | { |
---|
[42c4e6] | 304 | procinfov pi=NULL; |
---|
[057e93c] | 305 | int old_echo=si_echo; |
---|
[42c4e6] | 306 | BOOLEAN err=FALSE; |
---|
[64d729] | 307 | char save_flags=0; |
---|
[0e1846] | 308 | |
---|
| 309 | /* init febase ======================================== */ |
---|
[057e93c] | 310 | /* we do not enter this case if filename != NULL !! */ |
---|
| 311 | if (pn!=NULL) |
---|
[0e1846] | 312 | { |
---|
[057e93c] | 313 | pi = IDPROC(pn); |
---|
| 314 | if(pi!=NULL) |
---|
[0e1846] | 315 | { |
---|
[64d729] | 316 | save_flags=pi->trace_flag; |
---|
[057e93c] | 317 | if( pi->data.s.body==NULL ) |
---|
[0e1846] | 318 | { |
---|
[64d729] | 319 | iiGetLibProcBuffer(pi); |
---|
| 320 | if (pi->data.s.body==NULL) return TRUE; |
---|
[0e1846] | 321 | } |
---|
[f09b51] | 322 | // omUpdateInfo(); |
---|
| 323 | // int m=om_Info.UsedBytes; |
---|
| 324 | // Print("proc %s, mem=%d\n",IDID(pn),m); |
---|
[c232af] | 325 | newBuffer( omStrDup(pi->data.s.body), BT_proc, |
---|
[64d729] | 326 | pi, pi->data.s.body_lineno-(v!=NULL) ); |
---|
[0e1846] | 327 | } |
---|
| 328 | } |
---|
| 329 | /* generate argument list ======================================*/ |
---|
| 330 | if (v!=NULL) |
---|
| 331 | { |
---|
[c232af] | 332 | iiCurrArgs=(leftv)omAllocBin(sleftv_bin); |
---|
[0e1846] | 333 | memcpy(iiCurrArgs,v,sizeof(sleftv)); |
---|
| 334 | memset(v,0,sizeof(sleftv)); |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
| 338 | iiCurrArgs=NULL; |
---|
| 339 | } |
---|
[f71681] | 340 | iiCurrProc=pn; |
---|
[0e1846] | 341 | /* start interpreter ======================================*/ |
---|
[057e93c] | 342 | myynest++; |
---|
[2ff076] | 343 | if (myynest > SI_MAX_NEST) |
---|
[e0749e8] | 344 | { |
---|
[2ff076] | 345 | WerrorS("nesting too deep"); |
---|
[e0749e8] | 346 | err=TRUE; |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | err=yyparse(); |
---|
[5c5638] | 351 | #ifndef NDEBUG |
---|
[e0749e8] | 352 | checkall(); |
---|
[3b1a83c] | 353 | #endif |
---|
[e0749e8] | 354 | if (sLastPrinted.rtyp!=0) |
---|
| 355 | { |
---|
| 356 | sLastPrinted.CleanUp(); |
---|
| 357 | } |
---|
| 358 | //Print("kill locals for %s (level %d)\n",IDID(pn),myynest); |
---|
| 359 | killlocals(myynest); |
---|
[5c5638] | 360 | #ifndef NDEBUG |
---|
[e0749e8] | 361 | checkall(); |
---|
[3b1a83c] | 362 | #endif |
---|
[e0749e8] | 363 | //Print("end kill locals for %s (%d)\n",IDID(pn),myynest); |
---|
| 364 | } |
---|
[057e93c] | 365 | myynest--; |
---|
| 366 | si_echo=old_echo; |
---|
[64d729] | 367 | if (pi!=NULL) |
---|
| 368 | pi->trace_flag=save_flags; |
---|
[f09b51] | 369 | // omUpdateInfo(); |
---|
| 370 | // int m=om_Info.UsedBytes; |
---|
| 371 | // Print("exit %s, mem=%d\n",IDID(pn),m); |
---|
[0e1846] | 372 | return err; |
---|
| 373 | } |
---|
| 374 | |
---|
[77ff8e] | 375 | #ifdef USE_IILOCALRING |
---|
[a3bc95e] | 376 | ring *iiLocalRing; |
---|
[77ff8e] | 377 | #endif |
---|
[a3bc95e] | 378 | sleftv *iiRETURNEXPR; |
---|
[0e1846] | 379 | int iiRETURNEXPR_len=0; |
---|
| 380 | |
---|
| 381 | #ifdef RDEBUG |
---|
| 382 | static void iiShowLevRings() |
---|
| 383 | { |
---|
| 384 | int i; |
---|
[a3bc95e] | 385 | #ifdef USE_IILOCALRING |
---|
[9bc0b8] | 386 | for (i=0;i<=myynest;i++) |
---|
[0e1846] | 387 | { |
---|
| 388 | Print("lev %d:",i); |
---|
| 389 | if (iiLocalRing[i]==NULL) PrintS("NULL"); |
---|
[e9fdf6] | 390 | else Print("%lx",(long)iiLocalRing[i]); |
---|
[6f83c3d] | 391 | PrintLn(); |
---|
[0e1846] | 392 | } |
---|
[77ff8e] | 393 | #endif |
---|
[3b1a83c] | 394 | #if 0 |
---|
[a3bc95e] | 395 | i=myynest; |
---|
| 396 | proclevel *p=procstack; |
---|
| 397 | while (p!=NULL) |
---|
[77ff8e] | 398 | { |
---|
[a3bc95e] | 399 | Print("lev %d:",i); |
---|
[573da6] | 400 | if (p->cRingHdl==NULL) PrintS("NULL"); |
---|
| 401 | else Print("%s",IDID(p->cRingHdl)); |
---|
[a3bc95e] | 402 | PrintLn(); |
---|
| 403 | p=p->next; |
---|
[77ff8e] | 404 | } |
---|
[a3bc95e] | 405 | #endif |
---|
[0e1846] | 406 | if (currRing==NULL) PrintS("curr:NULL\n"); |
---|
[e9fdf6] | 407 | else Print ("curr:%lx\n",(long)currRing); |
---|
[0e1846] | 408 | } |
---|
[bd4cb92] | 409 | #endif /* RDEBUG */ |
---|
[0e1846] | 410 | |
---|
| 411 | static void iiCheckNest() |
---|
| 412 | { |
---|
| 413 | if (myynest >= iiRETURNEXPR_len-1) |
---|
| 414 | { |
---|
[c232af] | 415 | iiRETURNEXPR=(sleftv *)omreallocSize(iiRETURNEXPR, |
---|
[0e1846] | 416 | iiRETURNEXPR_len*sizeof(sleftv), |
---|
| 417 | (iiRETURNEXPR_len+16)*sizeof(sleftv)); |
---|
[ec7aac] | 418 | omMarkAsStaticAddr(iiRETURNEXPR); |
---|
[8b96123] | 419 | memset(&(iiRETURNEXPR[iiRETURNEXPR_len]),0,16*sizeof(sleftv)); |
---|
[0a3ddd] | 420 | #ifdef USE_IILOCALRING |
---|
[c232af] | 421 | iiLocalRing=(ring *)omreallocSize(iiLocalRing, |
---|
[0e1846] | 422 | iiRETURNEXPR_len*sizeof(ring), |
---|
| 423 | (iiRETURNEXPR_len+16)*sizeof(ring)); |
---|
[8b96123] | 424 | memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring)); |
---|
[77ff8e] | 425 | #endif |
---|
[0e1846] | 426 | iiRETURNEXPR_len+=16; |
---|
| 427 | } |
---|
| 428 | } |
---|
[a3bc95e] | 429 | sleftv * iiMake_proc(idhdl pn, package pack, sleftv* sl) |
---|
[0e1846] | 430 | { |
---|
| 431 | int err; |
---|
[2ba9a6] | 432 | procinfov pi = IDPROC(pn); |
---|
[bcd557] | 433 | if(pi->is_static && myynest==0) |
---|
| 434 | { |
---|
[5480da] | 435 | Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.", |
---|
[ed3c47] | 436 | pi->libname, pi->procname); |
---|
[5480da] | 437 | return NULL; |
---|
| 438 | } |
---|
[0e1846] | 439 | iiCheckNest(); |
---|
[77ff8e] | 440 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 441 | iiLocalRing[myynest]=currRing; |
---|
[9bc0b8] | 442 | //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn)); |
---|
[77ff8e] | 443 | #endif |
---|
[0e1846] | 444 | iiRETURNEXPR[myynest+1].Init(); |
---|
[a3bc95e] | 445 | procstack->push(pi->procname); |
---|
[50a84c] | 446 | if ((traceit&TRACE_SHOW_PROC) |
---|
| 447 | || (pi->trace_flag&TRACE_SHOW_PROC)) |
---|
[0e1846] | 448 | { |
---|
[fca547] | 449 | if (traceit&TRACE_SHOW_LINENO) PrintLn(); |
---|
| 450 | Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest); |
---|
[0e1846] | 451 | } |
---|
| 452 | #ifdef RDEBUG |
---|
| 453 | if (traceit&TRACE_SHOW_RINGS) iiShowLevRings(); |
---|
| 454 | #endif |
---|
[057e93c] | 455 | switch (pi->language) |
---|
| 456 | { |
---|
[de5fe1] | 457 | default: |
---|
| 458 | case LANG_NONE: |
---|
| 459 | WerrorS("undefined proc"); |
---|
[77ff8e] | 460 | err=TRUE; |
---|
| 461 | break; |
---|
[6f83c3d] | 462 | |
---|
[77ff8e] | 463 | case LANG_SINGULAR: |
---|
[a3bc95e] | 464 | if ((pi->pack!=NULL)&&(currPack!=pi->pack)) |
---|
| 465 | { |
---|
| 466 | currPack=pi->pack; |
---|
[8b96123] | 467 | iiCheckPack(currPack); |
---|
[a3bc95e] | 468 | currPackHdl=packFindHdl(currPack); |
---|
| 469 | //Print("set pack=%s\n",IDID(currPackHdl)); |
---|
| 470 | } |
---|
| 471 | else if ((pack!=NULL)&&(currPack!=pack)) |
---|
| 472 | { |
---|
| 473 | currPack=pack; |
---|
[8b96123] | 474 | iiCheckPack(currPack); |
---|
[a3bc95e] | 475 | currPackHdl=packFindHdl(currPack); |
---|
[873d82] | 476 | //Print("set pack=%s\n",IDID(currPackHdl)); |
---|
[a3bc95e] | 477 | } |
---|
[77ff8e] | 478 | err=iiPStart(pn,sl); |
---|
| 479 | break; |
---|
| 480 | case LANG_C: |
---|
[c232af] | 481 | leftv res = (leftv)omAlloc0Bin(sleftv_bin); |
---|
[77ff8e] | 482 | err = (pi->data.o.function)(res, sl); |
---|
| 483 | iiRETURNEXPR[myynest+1].Copy(res); |
---|
[c232af] | 484 | omFreeBin((ADDRESS)res, sleftv_bin); |
---|
[77ff8e] | 485 | break; |
---|
[2ba9a6] | 486 | } |
---|
[50a84c] | 487 | if ((traceit&TRACE_SHOW_PROC) |
---|
| 488 | || (pi->trace_flag&TRACE_SHOW_PROC)) |
---|
[0e1846] | 489 | { |
---|
[fca547] | 490 | if (traceit&TRACE_SHOW_LINENO) PrintLn(); |
---|
| 491 | Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest); |
---|
[0e1846] | 492 | } |
---|
[9bc0b8] | 493 | //char *n="NULL"; |
---|
| 494 | //if (currRingHdl!=NULL) n=IDID(currRingHdl); |
---|
| 495 | //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn)); |
---|
[0e1846] | 496 | #ifdef RDEBUG |
---|
| 497 | if (traceit&TRACE_SHOW_RINGS) iiShowLevRings(); |
---|
| 498 | #endif |
---|
| 499 | if (err) |
---|
| 500 | { |
---|
| 501 | iiRETURNEXPR[myynest+1].CleanUp(); |
---|
[355f86] | 502 | //iiRETURNEXPR[myynest+1].Init(); //done by CleanUp |
---|
[0e1846] | 503 | } |
---|
[77ff8e] | 504 | #ifdef USE_IILOCALRING |
---|
[3b1a83c] | 505 | #if 0 |
---|
[573da6] | 506 | if(procstack->cRing != iiLocalRing[myynest]) Print("iiMake_proc: 1 ring not saved procs:%x, iiLocal:%x\n",procstack->cRing, iiLocalRing[myynest]); |
---|
[3b1a83c] | 507 | #endif |
---|
[0e1846] | 508 | if (iiLocalRing[myynest] != currRing) |
---|
| 509 | { |
---|
[9bc0b8] | 510 | if (currRing!=NULL) |
---|
[31a392] | 511 | { |
---|
[9bc0b8] | 512 | if (((iiRETURNEXPR[myynest+1].Typ()>BEGIN_RING) |
---|
| 513 | && (iiRETURNEXPR[myynest+1].Typ()<END_RING)) |
---|
| 514 | || ((iiRETURNEXPR[myynest+1].Typ()==LIST_CMD) |
---|
| 515 | && (lRingDependend((lists)iiRETURNEXPR[myynest+1].Data())))) |
---|
| 516 | { |
---|
| 517 | //idhdl hn; |
---|
[85e68dd] | 518 | const char *n; |
---|
| 519 | const char *o; |
---|
[9bc0b8] | 520 | idhdl nh=NULL, oh=NULL; |
---|
| 521 | if (iiLocalRing[myynest]!=NULL) |
---|
| 522 | oh=rFindHdl(iiLocalRing[myynest],NULL, NULL); |
---|
| 523 | if (oh!=NULL) o=oh->id; |
---|
| 524 | else o="none"; |
---|
| 525 | if (currRing!=NULL) |
---|
| 526 | nh=rFindHdl(currRing,NULL, NULL); |
---|
| 527 | if (nh!=NULL) n=nh->id; |
---|
| 528 | else n="none"; |
---|
| 529 | Werror("ring change during procedure call: %s -> %s (level %d)",o,n,myynest); |
---|
| 530 | iiRETURNEXPR[myynest+1].CleanUp(); |
---|
| 531 | err=TRUE; |
---|
| 532 | } |
---|
[0e1846] | 533 | } |
---|
[9f12b01] | 534 | currRing=iiLocalRing[myynest]; |
---|
[3b1a83c] | 535 | } |
---|
[9bc0b8] | 536 | if ((currRing==NULL) |
---|
| 537 | && (currRingHdl!=NULL)) |
---|
| 538 | currRing=IDRING(currRingHdl); |
---|
| 539 | else |
---|
[3b1a83c] | 540 | if ((currRing!=NULL) && |
---|
[9f12b01] | 541 | ((currRingHdl==NULL)||(IDRING(currRingHdl)!=currRing) |
---|
| 542 | ||(IDLEV(currRingHdl)>=myynest))) |
---|
[3b1a83c] | 543 | { |
---|
| 544 | rSetHdl(rFindHdl(currRing,NULL, NULL)); |
---|
| 545 | iiLocalRing[myynest]=NULL; |
---|
[77ff8e] | 546 | } |
---|
| 547 | #else /* USE_IILOCALRING */ |
---|
[573da6] | 548 | if (procstack->cRing != currRing) |
---|
[a3bc95e] | 549 | { |
---|
[573da6] | 550 | //if (procstack->cRingHdl!=NULL) |
---|
| 551 | //Print("procstack:%s,",IDID(procstack->cRingHdl)); |
---|
[a3bc95e] | 552 | //if (currRingHdl!=NULL) |
---|
| 553 | //Print(" curr:%s\n",IDID(currRingHdl)); |
---|
[573da6] | 554 | //Print("pr:%x, curr: %x\n",procstack->cRing,currRing); |
---|
[a3bc95e] | 555 | if (((iiRETURNEXPR[myynest+1].Typ()>BEGIN_RING) |
---|
| 556 | && (iiRETURNEXPR[myynest+1].Typ()<END_RING)) |
---|
| 557 | || ((iiRETURNEXPR[myynest+1].Typ()==LIST_CMD) |
---|
| 558 | && (lRingDependend((lists)iiRETURNEXPR[myynest+1].Data())))) |
---|
| 559 | { |
---|
| 560 | //idhdl hn; |
---|
| 561 | char *n; |
---|
| 562 | char *o; |
---|
[573da6] | 563 | if (procstack->cRing!=NULL) |
---|
[a3bc95e] | 564 | { |
---|
| 565 | //PrintS("reset ring\n"); |
---|
[573da6] | 566 | procstack->cRingHdl=rFindHdl(procstack->cRing,NULL, NULL); |
---|
| 567 | if (procstack->cRingHdl==NULL) |
---|
| 568 | procstack->cRingHdl= |
---|
| 569 | rFindHdl(procstack->cRing,NULL,procstack->currPack->idroot); |
---|
| 570 | if (procstack->cRingHdl==NULL) |
---|
| 571 | procstack->cRingHdl= |
---|
| 572 | rFindHdl(procstack->cRing,NULL,basePack->idroot); |
---|
| 573 | o=IDID(procstack->cRingHdl); |
---|
| 574 | currRing=procstack->cRing; |
---|
| 575 | currRingHdl=procstack->cRingHdl; |
---|
[a3bc95e] | 576 | } |
---|
| 577 | else o="none"; |
---|
| 578 | if (currRing!=NULL) n=IDID(currRingHdl); |
---|
| 579 | else n="none"; |
---|
| 580 | if (currRing==NULL) |
---|
| 581 | { |
---|
| 582 | Werror("ring change during procedure call: %s -> %s",o,n); |
---|
| 583 | iiRETURNEXPR[myynest+1].CleanUp(); |
---|
| 584 | err=TRUE; |
---|
| 585 | } |
---|
| 586 | } |
---|
[573da6] | 587 | if (procstack->cRingHdl!=NULL) |
---|
[a3bc95e] | 588 | { |
---|
[573da6] | 589 | rSetHdl(procstack->cRingHdl); |
---|
[a3bc95e] | 590 | } |
---|
| 591 | else |
---|
| 592 | { currRingHdl=NULL; currRing=NULL; } |
---|
| 593 | } |
---|
| 594 | #endif /* USE_IILOCALRING */ |
---|
[0e1846] | 595 | if (iiCurrArgs!=NULL) |
---|
| 596 | { |
---|
[bcd557] | 597 | if (!err) Warn("too many arguments for %s",IDID(pn)); |
---|
[0e1846] | 598 | iiCurrArgs->CleanUp(); |
---|
[c232af] | 599 | omFreeBin((ADDRESS)iiCurrArgs, sleftv_bin); |
---|
[0e1846] | 600 | iiCurrArgs=NULL; |
---|
| 601 | } |
---|
[a3bc95e] | 602 | procstack->pop(); |
---|
[bcd557] | 603 | if (err) |
---|
| 604 | return NULL; |
---|
[0e1846] | 605 | return &iiRETURNEXPR[myynest+1]; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | /*2 |
---|
| 609 | * start an example (as a proc), |
---|
| 610 | * destroys the string 'example' |
---|
| 611 | */ |
---|
[057e93c] | 612 | BOOLEAN iiEStart(char* example, procinfo *pi) |
---|
[0e1846] | 613 | { |
---|
| 614 | BOOLEAN err; |
---|
[057e93c] | 615 | int old_echo=si_echo; |
---|
[0e1846] | 616 | |
---|
[4e4ece7] | 617 | newBuffer( example, BT_example, pi, |
---|
[c04b94] | 618 | (pi != NULL ? pi->data.s.example_lineno: 0)); |
---|
| 619 | |
---|
[0e1846] | 620 | iiCheckNest(); |
---|
[a3bc95e] | 621 | procstack->push(example); |
---|
[77ff8e] | 622 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 623 | iiLocalRing[myynest]=currRing; |
---|
[77ff8e] | 624 | #endif |
---|
[0e1846] | 625 | if (traceit&TRACE_SHOW_PROC) |
---|
| 626 | { |
---|
| 627 | if (traceit&TRACE_SHOW_LINENO) printf("\n"); |
---|
| 628 | printf("entering example (level %d)\n",myynest); |
---|
| 629 | } |
---|
| 630 | myynest++; |
---|
[8c242f] | 631 | iiRETURNEXPR[myynest].Init(); |
---|
[0e1846] | 632 | err=yyparse(); |
---|
[b89cf5d] | 633 | if (sLastPrinted.rtyp!=0) |
---|
| 634 | { |
---|
| 635 | sLastPrinted.CleanUp(); |
---|
[355f86] | 636 | //memset(&sLastPrinted,0,sizeof(sleftv)); //done by CleanUp |
---|
[b89cf5d] | 637 | } |
---|
[0e1846] | 638 | killlocals(myynest); |
---|
| 639 | myynest--; |
---|
[057e93c] | 640 | si_echo=old_echo; |
---|
[0e1846] | 641 | if (traceit&TRACE_SHOW_PROC) |
---|
| 642 | { |
---|
| 643 | if (traceit&TRACE_SHOW_LINENO) printf("\n"); |
---|
| 644 | printf("leaving -example- (level %d)\n",myynest); |
---|
| 645 | } |
---|
[77ff8e] | 646 | #ifdef USE_IILOCALRING |
---|
[0e1846] | 647 | if (iiLocalRing[myynest] != currRing) |
---|
| 648 | { |
---|
| 649 | if (iiLocalRing[myynest]!=NULL) |
---|
| 650 | { |
---|
[cf42ab1] | 651 | rSetHdl(rFindHdl(iiLocalRing[myynest],NULL, NULL)); |
---|
[0e1846] | 652 | iiLocalRing[myynest]=NULL; |
---|
| 653 | } |
---|
| 654 | else |
---|
| 655 | { |
---|
| 656 | currRingHdl=NULL; |
---|
| 657 | currRing=NULL; |
---|
| 658 | } |
---|
| 659 | } |
---|
[77ff8e] | 660 | #else /* USE_IILOCALRING */ |
---|
[a3bc95e] | 661 | #endif /* USE_IILOCALRING */ |
---|
[77ff8e] | 662 | if (NS_LRING != currRing) |
---|
| 663 | { |
---|
| 664 | if (NS_LRING!=NULL) |
---|
| 665 | { |
---|
[573da6] | 666 | idhdl rh=procstack->cRingHdl; |
---|
[bd4cb92] | 667 | if ((rh==NULL)||(IDRING(rh)!=NS_LRING)) |
---|
| 668 | rh=rFindHdl(NS_LRING,NULL, NULL); |
---|
| 669 | rSetHdl(rh); |
---|
[77ff8e] | 670 | } |
---|
| 671 | else |
---|
| 672 | { |
---|
| 673 | currRingHdl=NULL; |
---|
| 674 | currRing=NULL; |
---|
| 675 | } |
---|
| 676 | } |
---|
[a3bc95e] | 677 | //#endif /* USE_IILOCALRING */ |
---|
| 678 | procstack->pop(); |
---|
[0e1846] | 679 | return err; |
---|
| 680 | } |
---|
| 681 | |
---|
[8edd35] | 682 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[85e68dd] | 683 | BOOLEAN iiTryLoadLib(leftv v, const char *id) |
---|
[8edd35] | 684 | { |
---|
| 685 | BOOLEAN LoadResult = TRUE; |
---|
| 686 | char libnamebuf[128]; |
---|
[c232af] | 687 | char *libname = (char *)omAlloc(strlen(id)+5); |
---|
[85e68dd] | 688 | const char *suffix[] = { "", ".lib", ".so", ".sl", NULL }; |
---|
[8edd35] | 689 | int i = 0; |
---|
| 690 | FILE *fp; |
---|
| 691 | package pack; |
---|
| 692 | idhdl packhdl; |
---|
| 693 | lib_types LT; |
---|
| 694 | |
---|
[743c32] | 695 | for(i=0; suffix[i] != NULL; i++) |
---|
| 696 | { |
---|
[8edd35] | 697 | sprintf(libname, "%s%s", id, suffix[i]); |
---|
| 698 | *libname = mytolower(*libname); |
---|
[2166892] | 699 | if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND) |
---|
[743c32] | 700 | { |
---|
[2166892] | 701 | char *s=omStrDup(libname); |
---|
| 702 | char libnamebuf[256]; |
---|
| 703 | |
---|
| 704 | if (LT==LT_SINGULAR) |
---|
[22ed4c] | 705 | LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE); |
---|
[24590f] | 706 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[2166892] | 707 | else if ((LT==LT_ELF) || (LT==LT_HPUX)) |
---|
| 708 | LoadResult = load_modules(s,libnamebuf,FALSE); |
---|
[24590f] | 709 | #endif |
---|
[2166892] | 710 | if(!LoadResult ) |
---|
[743c32] | 711 | { |
---|
[8edd35] | 712 | v->name = iiConvName(libname); |
---|
| 713 | break; |
---|
| 714 | } |
---|
| 715 | } |
---|
| 716 | } |
---|
[c232af] | 717 | omFree(libname); |
---|
[8edd35] | 718 | return LoadResult; |
---|
| 719 | } |
---|
| 720 | |
---|
[1d1101] | 721 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[50cbdc] | 722 | /* check, if library lib has already been loaded |
---|
[698457] | 723 | if yes, writes filename of lib into where and returns TRUE, |
---|
| 724 | no, returns FALSE |
---|
| 725 | */ |
---|
| 726 | BOOLEAN iiLocateLib(const char* lib, char* where) |
---|
| 727 | { |
---|
| 728 | idhdl hl; |
---|
[4e4ece7] | 729 | |
---|
[5121f6] | 730 | char *p; |
---|
[50cbdc] | 731 | |
---|
[5af2f9] | 732 | hl = IDROOT->get("LIB", 0); |
---|
[5121f6] | 733 | if (hl == NULL || (p=strstr(IDSTRING(hl), lib)) == NULL) return FALSE; |
---|
| 734 | if ((p!=IDSTRING(hl)) && (*(p-1)!=',')) return FALSE; |
---|
[4e4ece7] | 735 | |
---|
[698457] | 736 | if (strstr(IDSTRING(hl), ",") == NULL) |
---|
| 737 | { |
---|
| 738 | strcpy(where, IDSTRING(hl)); |
---|
| 739 | } |
---|
| 740 | else |
---|
| 741 | { |
---|
[c232af] | 742 | char* tmp = omStrDup(IDSTRING(hl)); |
---|
[698457] | 743 | char* tok = strtok(tmp, ","); |
---|
| 744 | do |
---|
| 745 | { |
---|
| 746 | if (strstr(tok, lib) != NULL) break; |
---|
| 747 | tok = strtok(NULL, ","); |
---|
| 748 | } |
---|
| 749 | while (tok != NULL); |
---|
| 750 | assume(tok != NULL); |
---|
| 751 | strcpy(where, tok); |
---|
[c232af] | 752 | omFree(tmp); |
---|
[698457] | 753 | } |
---|
| 754 | return TRUE; |
---|
| 755 | } |
---|
[4e4ece7] | 756 | |
---|
[22ed4c] | 757 | BOOLEAN iiLibCmd( char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force ) |
---|
[0e1846] | 758 | { |
---|
| 759 | char libnamebuf[128]; |
---|
[42c4e6] | 760 | procinfov pi; |
---|
[1bd25e] | 761 | idhdl h; |
---|
[a3bc95e] | 762 | idhdl pl; |
---|
[1bd25e] | 763 | idhdl hl; |
---|
[2ba9a6] | 764 | long pos = 0L; |
---|
[a3bc95e] | 765 | char *plib = iiConvName(newlib); |
---|
[dfc6b54] | 766 | FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror ); |
---|
[42c4e6] | 767 | int lines = 1; |
---|
| 768 | BOOLEAN LoadResult = TRUE; |
---|
| 769 | |
---|
[0e1846] | 770 | if (fp==NULL) |
---|
| 771 | { |
---|
| 772 | return TRUE; |
---|
| 773 | } |
---|
[a3bc95e] | 774 | pl = basePack->idroot->get(plib,0); |
---|
| 775 | if (pl==NULL) |
---|
| 776 | { |
---|
[3b1a83c] | 777 | pl = enterid( plib,0, PACKAGE_CMD, |
---|
[a3bc95e] | 778 | &(basePack->idroot), TRUE ); |
---|
| 779 | IDPACKAGE(pl)->language = LANG_SINGULAR; |
---|
| 780 | IDPACKAGE(pl)->libname=omStrDup(newlib); |
---|
| 781 | } |
---|
| 782 | else |
---|
| 783 | { |
---|
| 784 | if(IDTYP(pl)!=PACKAGE_CMD) |
---|
| 785 | { |
---|
[7a949a] | 786 | WarnS("not of type package."); |
---|
[a3bc95e] | 787 | fclose(fp); |
---|
| 788 | return TRUE; |
---|
| 789 | } |
---|
[22ed4c] | 790 | if (!force) return FALSE; |
---|
[a3bc95e] | 791 | } |
---|
[22ed4c] | 792 | LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror); |
---|
[a3bc95e] | 793 | omFree((ADDRESS)newlib); |
---|
| 794 | |
---|
| 795 | if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE; |
---|
[c232af] | 796 | omFree((ADDRESS)plib); |
---|
[a3bc95e] | 797 | |
---|
[21fa0b] | 798 | return LoadResult; |
---|
[8edd35] | 799 | } |
---|
[c3cb95] | 800 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[31a392] | 801 | static void iiCleanProcs(idhdl &root) |
---|
[c3cb95] | 802 | { |
---|
[2bb771] | 803 | idhdl prev=NULL; |
---|
[c3cb95] | 804 | loop |
---|
| 805 | { |
---|
| 806 | if (root==NULL) return; |
---|
| 807 | if (IDTYP(root)==PROC_CMD) |
---|
| 808 | { |
---|
[560432] | 809 | procinfo *pi=(procinfo*)IDDATA(root); |
---|
[c3cb95] | 810 | if ((pi->language == LANG_SINGULAR) |
---|
| 811 | && (pi->data.s.body_start == 0L)) |
---|
| 812 | { |
---|
| 813 | // procinfo data incorrect: |
---|
| 814 | // - no proc body can start at the beginning of the file |
---|
[560432] | 815 | killhdl(root); |
---|
[2bb771] | 816 | if (prev==NULL) |
---|
[bd4cb92] | 817 | root=IDROOT; |
---|
[2bb771] | 818 | else |
---|
| 819 | { |
---|
| 820 | root=prev; |
---|
| 821 | prev=NULL; |
---|
| 822 | } |
---|
| 823 | continue; |
---|
[c3cb95] | 824 | } |
---|
| 825 | } |
---|
[2bb771] | 826 | prev=root; |
---|
[c3cb95] | 827 | root=IDNEXT(root); |
---|
| 828 | } |
---|
| 829 | } |
---|
[42c4e6] | 830 | static void iiRunInit(package p) |
---|
| 831 | { |
---|
[31a392] | 832 | idhdl h=p->idroot->get("mod_init",0); |
---|
| 833 | if (h==NULL) return; |
---|
| 834 | if (IDTYP(h)==PROC_CMD) |
---|
[42c4e6] | 835 | { |
---|
[31a392] | 836 | int save=yylineno; |
---|
| 837 | myynest++; |
---|
| 838 | procinfo *pi=(procinfo*)IDDATA(h); |
---|
| 839 | //PrintS("mod_init found\n"); |
---|
| 840 | iiMake_proc(h,p,NULL); |
---|
| 841 | myynest--; |
---|
| 842 | yylineno=save; |
---|
[42c4e6] | 843 | } |
---|
| 844 | } |
---|
[8edd35] | 845 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[bf4ff72] | 846 | BOOLEAN iiLoadLIB(FILE *fp, char *libnamebuf, char*newlib, |
---|
[8edd35] | 847 | idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror) |
---|
| 848 | { |
---|
[6a51ef] | 849 | extern FILE *yylpin; |
---|
| 850 | libstackv ls_start = library_stack; |
---|
[5480da] | 851 | lib_style_types lib_style; |
---|
[6a51ef] | 852 | |
---|
| 853 | yylpin = fp; |
---|
[4e4ece7] | 854 | #if YYLPDEBUG > 1 |
---|
[6a51ef] | 855 | print_init(); |
---|
[4e4ece7] | 856 | #endif |
---|
[799ce1] | 857 | extern int lpverbose; |
---|
[4e4ece7] | 858 | if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1; |
---|
| 859 | else lpverbose=0; |
---|
[2f8028] | 860 | // yylplex sets also text_buffer |
---|
| 861 | if (text_buffer!=NULL) *text_buffer='\0'; |
---|
[d3e630] | 862 | yylplex(newlib, libnamebuf, &lib_style, pl, autoexport); |
---|
[805b06c] | 863 | if(yylp_errno) |
---|
| 864 | { |
---|
[6a51ef] | 865 | Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno, |
---|
[5c8eae0] | 866 | current_pos(0)); |
---|
[805b06c] | 867 | if(yylp_errno==YYLP_BAD_CHAR) |
---|
| 868 | { |
---|
[60a3add] | 869 | Werror(yylp_errlist[yylp_errno], *text_buffer, yylplineno); |
---|
[c232af] | 870 | omFree((ADDRESS)text_buffer); |
---|
[9a11fe] | 871 | text_buffer=NULL; |
---|
[805b06c] | 872 | } |
---|
| 873 | else |
---|
[60a3add] | 874 | Werror(yylp_errlist[yylp_errno], yylplineno); |
---|
[6a51ef] | 875 | Werror("Cannot load library,... aborting."); |
---|
| 876 | reinit_yylp(); |
---|
| 877 | fclose( yylpin ); |
---|
[bd4cb92] | 878 | iiCleanProcs(IDROOT); |
---|
[6a51ef] | 879 | return TRUE; |
---|
[5c8eae0] | 880 | } |
---|
[4e4ece7] | 881 | if (BVERBOSE(V_LOAD_LIB)) |
---|
| 882 | Print( "// ** loaded %s %s\n", libnamebuf, text_buffer); |
---|
[805b06c] | 883 | if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB))) |
---|
| 884 | { |
---|
[40706c] | 885 | Warn( "library %s has old format. This format is still accepted,", newlib); |
---|
| 886 | Warn( "but for functionality you may wish to change to the new"); |
---|
| 887 | Warn( "format. Please refer to the manual for further information."); |
---|
[0a3ddd] | 888 | } |
---|
[6a51ef] | 889 | reinit_yylp(); |
---|
| 890 | fclose( yylpin ); |
---|
[dae004] | 891 | fp = NULL; |
---|
[42c4e6] | 892 | iiRunInit(IDPACKAGE(pl)); |
---|
[64d729] | 893 | |
---|
[6a51ef] | 894 | { |
---|
| 895 | libstackv ls; |
---|
[805b06c] | 896 | for(ls = library_stack; (ls != NULL) && (ls != ls_start); ) |
---|
| 897 | { |
---|
| 898 | if(ls->to_be_done) |
---|
| 899 | { |
---|
[5c8eae0] | 900 | ls->to_be_done=FALSE; |
---|
[22ed4c] | 901 | iiLibCmd(ls->get(),autoexport,tellerror,FALSE); |
---|
[5c8eae0] | 902 | ls = ls->pop(newlib); |
---|
[6a51ef] | 903 | } |
---|
| 904 | } |
---|
| 905 | #if 0 |
---|
[6f83c3d] | 906 | PrintS("--------------------\n"); |
---|
| 907 | for(ls = library_stack; ls != NULL; ls = ls->next) |
---|
| 908 | { |
---|
[6a51ef] | 909 | Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(), |
---|
| 910 | ls->to_be_done ? "not loaded" : "loaded"); |
---|
| 911 | } |
---|
[6f83c3d] | 912 | PrintS("--------------------\n"); |
---|
[6a51ef] | 913 | #endif |
---|
| 914 | } |
---|
[21fa0b] | 915 | |
---|
[dae004] | 916 | if(fp != NULL) fclose(fp); |
---|
[0e1846] | 917 | return FALSE; |
---|
| 918 | } |
---|
| 919 | |
---|
[8edd35] | 920 | |
---|
[1d1101] | 921 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[85e68dd] | 922 | procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname, |
---|
| 923 | const char *procname, int line, long pos, BOOLEAN pstatic) |
---|
[2ba9a6] | 924 | { |
---|
[c232af] | 925 | pi->libname = omStrDup(libname); |
---|
[2ba9a6] | 926 | |
---|
[057e93c] | 927 | if( strcmp(procname,"_init")==0) |
---|
| 928 | { |
---|
[805b06c] | 929 | pi->procname = iiConvName(libname); |
---|
| 930 | } |
---|
| 931 | else |
---|
[c232af] | 932 | pi->procname = omStrDup(procname); |
---|
[2ba9a6] | 933 | pi->language = LANG_SINGULAR; |
---|
| 934 | pi->ref = 1; |
---|
[a3bc95e] | 935 | pi->pack = NULL; |
---|
[6a51ef] | 936 | pi->is_static = pstatic; |
---|
[2ba9a6] | 937 | pi->data.s.proc_start = pos; |
---|
[46d09b] | 938 | pi->data.s.def_end = 0L; |
---|
[2ba9a6] | 939 | pi->data.s.help_start = 0L; |
---|
[6be769] | 940 | pi->data.s.help_end = 0L; |
---|
[2ba9a6] | 941 | pi->data.s.body_start = 0L; |
---|
| 942 | pi->data.s.body_end = 0L; |
---|
| 943 | pi->data.s.example_start = 0L; |
---|
| 944 | pi->data.s.proc_lineno = line; |
---|
| 945 | pi->data.s.body_lineno = 0; |
---|
| 946 | pi->data.s.example_lineno = 0; |
---|
| 947 | pi->data.s.body = NULL; |
---|
[847cad] | 948 | pi->data.s.help_chksum = 0; |
---|
[2ba9a6] | 949 | return(pi); |
---|
| 950 | } |
---|
| 951 | |
---|
[1d1101] | 952 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
| 953 | int iiAddCproc(char *libname, char *procname, BOOLEAN pstatic, |
---|
[ed3c47] | 954 | BOOLEAN(*func)(leftv res, leftv v)) |
---|
[1d1101] | 955 | { |
---|
| 956 | procinfov pi; |
---|
| 957 | idhdl h; |
---|
| 958 | |
---|
[3b1a83c] | 959 | h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE); |
---|
[6f83c3d] | 960 | if ( h!= NULL ) |
---|
| 961 | { |
---|
[1d1101] | 962 | pi = IDPROC(h); |
---|
[c232af] | 963 | pi->libname = omStrDup(libname); |
---|
| 964 | pi->procname = omStrDup(procname); |
---|
[1d1101] | 965 | pi->language = LANG_C; |
---|
| 966 | pi->ref = 1; |
---|
| 967 | pi->is_static = pstatic; |
---|
| 968 | pi->data.o.function = func; |
---|
| 969 | return(1); |
---|
[6f83c3d] | 970 | } |
---|
| 971 | else |
---|
| 972 | { |
---|
| 973 | PrintS("iiAddCproc: failed.\n"); |
---|
[1d1101] | 974 | } |
---|
| 975 | return(0); |
---|
| 976 | } |
---|
[cd6b45] | 977 | |
---|
[b90cc8] | 978 | #ifdef HAVE_DYNAMIC_LOADING |
---|
[c858fc2] | 979 | int iiAddCprocTop(char *libname, char *procname, BOOLEAN pstatic, |
---|
| 980 | BOOLEAN(*func)(leftv res, leftv v)) |
---|
| 981 | { |
---|
| 982 | int r=iiAddCproc(libname,procname,pstatic,func); |
---|
| 983 | package s=currPack; |
---|
| 984 | currPack=basePack; |
---|
| 985 | if (r) r=iiAddCproc(libname,procname,pstatic,func); |
---|
| 986 | currPack=s; |
---|
| 987 | return r; |
---|
| 988 | } |
---|
| 989 | |
---|
[cd6b45] | 990 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[c858fc2] | 991 | BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport) |
---|
[cd6b45] | 992 | { |
---|
[4eb5b5] | 993 | #ifdef HAVE_STATIC |
---|
| 994 | WerrorS("mod_init: static version can not load modules"); |
---|
| 995 | return TRUE; |
---|
| 996 | #else |
---|
[cd6b45] | 997 | int iiAddCproc(char *libname, char *procname, BOOLEAN pstatic, |
---|
| 998 | BOOLEAN(*func)(leftv res, leftv v)); |
---|
[bf4997] | 999 | typedef int (*fktn_t)(int(*iiAddCproc)(char *libname, char *procname, |
---|
[cd6b45] | 1000 | BOOLEAN pstatic, |
---|
| 1001 | BOOLEAN(*func)(leftv res, leftv v))); |
---|
[b6e51b] | 1002 | typedef int (*fktn2_t)(SModulFunctions*); |
---|
| 1003 | fktn2_t fktn; |
---|
[cd6b45] | 1004 | idhdl pl; |
---|
| 1005 | char *plib = iiConvName(newlib); |
---|
| 1006 | BOOLEAN RET=TRUE; |
---|
| 1007 | int token; |
---|
| 1008 | char FullName[256]; |
---|
[64d729] | 1009 | |
---|
[a3dfd97] | 1010 | memset(FullName,0,256); |
---|
| 1011 | |
---|
[cd6b45] | 1012 | if( *fullname != '/' && *fullname != '.' ) |
---|
| 1013 | sprintf(FullName, "./%s", newlib); |
---|
[a3dfd97] | 1014 | else strncpy(FullName, fullname,255); |
---|
[64d729] | 1015 | |
---|
[cd6b45] | 1016 | |
---|
[bf4997] | 1017 | if(IsCmd(plib, token)) |
---|
[cd6b45] | 1018 | { |
---|
| 1019 | Werror("'%s' is resered identifier\n", plib); |
---|
| 1020 | goto load_modules_end; |
---|
| 1021 | } |
---|
[1bd25e] | 1022 | pl = IDROOT->get(plib,0); |
---|
[cd6b45] | 1023 | if (pl==NULL) |
---|
| 1024 | { |
---|
[3b1a83c] | 1025 | pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, |
---|
[1bd25e] | 1026 | TRUE ); |
---|
[cd6b45] | 1027 | IDPACKAGE(pl)->language = LANG_C; |
---|
[c232af] | 1028 | IDPACKAGE(pl)->libname=omStrDup(newlib); |
---|
[cd6b45] | 1029 | } |
---|
| 1030 | else |
---|
| 1031 | { |
---|
| 1032 | if(IDTYP(pl)!=PACKAGE_CMD) |
---|
| 1033 | { |
---|
[7a949a] | 1034 | Warn("not of type package."); |
---|
[64d729] | 1035 | goto load_modules_end; |
---|
[cd6b45] | 1036 | } |
---|
| 1037 | } |
---|
[7497447] | 1038 | if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL) |
---|
[cd6b45] | 1039 | { |
---|
[46ef83] | 1040 | Werror("dynl_open failed:%s", dynl_error()); |
---|
[cd6b45] | 1041 | Werror("%s not found", newlib); |
---|
[64d729] | 1042 | goto load_modules_end; |
---|
[cd6b45] | 1043 | } |
---|
| 1044 | else |
---|
| 1045 | { |
---|
[b6e51b] | 1046 | SModulFunctions sModulFunctions; |
---|
[31a392] | 1047 | |
---|
[a3dfd97] | 1048 | package s=currPack; |
---|
| 1049 | currPack=IDPACKAGE(pl); |
---|
[b6e51b] | 1050 | fktn = (fktn2_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init"); |
---|
[c858fc2] | 1051 | if( fktn!= NULL) |
---|
| 1052 | { |
---|
[b6e51b] | 1053 | sModulFunctions.iiArithAddCmd = iiArithAddCmd; |
---|
| 1054 | if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop; |
---|
| 1055 | else sModulFunctions.iiAddCproc = iiAddCproc; |
---|
| 1056 | (*fktn)(&sModulFunctions); |
---|
[c858fc2] | 1057 | } |
---|
[1fb78b] | 1058 | else Werror("mod_init: %s\n", dynl_error()); |
---|
[cd6b45] | 1059 | if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", fullname); |
---|
[a3dfd97] | 1060 | currPack->loaded=1; |
---|
| 1061 | currPack=s; |
---|
[cd6b45] | 1062 | } |
---|
| 1063 | RET=FALSE; |
---|
| 1064 | |
---|
| 1065 | load_modules_end: |
---|
| 1066 | return RET; |
---|
[31a392] | 1067 | #endif /*STATIC */ |
---|
[cd6b45] | 1068 | } |
---|
[1cb879] | 1069 | |
---|
| 1070 | // loads a dynamic module from the binary path and returns a named function |
---|
| 1071 | // returns NULL, if something fails |
---|
| 1072 | void* binary_module_function(const char* newlib, const char* funcname) |
---|
| 1073 | { |
---|
| 1074 | void* result = NULL; |
---|
| 1075 | |
---|
| 1076 | #ifdef HAVE_STATIC |
---|
| 1077 | WerrorS("static version can not load function from dynamic modules"); |
---|
| 1078 | #else |
---|
| 1079 | const char* bin_dir = feGetResource('b'); |
---|
| 1080 | if (!bin_dir) { return NULL; } |
---|
| 1081 | |
---|
| 1082 | char path_name[MAXPATHLEN]; |
---|
| 1083 | sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING); |
---|
| 1084 | |
---|
| 1085 | void* openlib = dynl_open(path_name); |
---|
| 1086 | if(!openlib) |
---|
| 1087 | { |
---|
| 1088 | Werror("dynl_open of %s failed:%s", path_name, dynl_error()); |
---|
| 1089 | return NULL; |
---|
| 1090 | } |
---|
| 1091 | result = dynl_sym(openlib, funcname); |
---|
| 1092 | if (!result) Werror("%s: %s\n", funcname, dynl_error()); |
---|
| 1093 | #endif |
---|
| 1094 | |
---|
| 1095 | return result; |
---|
| 1096 | } |
---|
| 1097 | |
---|
[1d1101] | 1098 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
| 1099 | |
---|
[2ba9a6] | 1100 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[77ff8e] | 1101 | char mytoupper(char c) |
---|
| 1102 | { |
---|
| 1103 | if(c>=97 && c<=(97+26)) c-=32; |
---|
| 1104 | return(c); |
---|
| 1105 | } |
---|
| 1106 | |
---|
[8edd35] | 1107 | char mytolower(char c) |
---|
| 1108 | { |
---|
| 1109 | if(c>=65 && c<=(65+26)) c+=32; |
---|
| 1110 | return(c); |
---|
| 1111 | } |
---|
| 1112 | |
---|
[77ff8e] | 1113 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[75c0dc] | 1114 | //#if defined(WINNT) |
---|
| 1115 | //# define FS_SEP '\\' |
---|
| 1116 | //#else |
---|
| 1117 | //# define FS_SEP '/' |
---|
| 1118 | //#endif |
---|
[77ff8e] | 1119 | |
---|
[f43a74] | 1120 | char *iiConvName(const char *libname) |
---|
[2ba9a6] | 1121 | { |
---|
[c232af] | 1122 | char *tmpname = omStrDup(libname); |
---|
[9c35ef] | 1123 | char *p = strrchr(tmpname, DIR_SEP); |
---|
[ed3c47] | 1124 | char *r; |
---|
[77ff8e] | 1125 | if(p==NULL) p = tmpname; |
---|
| 1126 | else p++; |
---|
[08c2d6] | 1127 | r = (char *)strchr(p, '.'); |
---|
[77ff8e] | 1128 | if( r!= NULL) *r = '\0'; |
---|
[c232af] | 1129 | r = omStrDup(p); |
---|
[77ff8e] | 1130 | *r = mytoupper(*r); |
---|
| 1131 | // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r); |
---|
[c232af] | 1132 | omFree((ADDRESS)tmpname); |
---|
[6f83c3d] | 1133 | |
---|
[77ff8e] | 1134 | return(r); |
---|
[2ba9a6] | 1135 | } |
---|
| 1136 | |
---|
| 1137 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[c599b4] | 1138 | #if 0 /* debug only */ |
---|
[fca547] | 1139 | void piShowProcList() |
---|
[2ba9a6] | 1140 | { |
---|
| 1141 | idhdl h; |
---|
| 1142 | procinfo *proc; |
---|
| 1143 | char *name; |
---|
| 1144 | |
---|
| 1145 | Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function", |
---|
[13e3243] | 1146 | "line", "start", "line", "body", "line", "example"); |
---|
[46d09b] | 1147 | for(h = IDROOT; h != NULL; h = IDNEXT(h)) |
---|
[057e93c] | 1148 | { |
---|
| 1149 | if(IDTYP(h) == PROC_CMD) |
---|
| 1150 | { |
---|
[2ba9a6] | 1151 | proc = IDPROC(h); |
---|
[057e93c] | 1152 | if(strcmp(proc->procname, IDID(h))!=0) |
---|
| 1153 | { |
---|
[c232af] | 1154 | name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4); |
---|
[13e3243] | 1155 | sprintf(name, "%s -> %s", IDID(h), proc->procname); |
---|
[46d09b] | 1156 | Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name); |
---|
[c232af] | 1157 | omFree((ADDRESS)name); |
---|
[0077d9d] | 1158 | } |
---|
| 1159 | else |
---|
[46d09b] | 1160 | Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, |
---|
| 1161 | proc->procname); |
---|
[13e3243] | 1162 | if(proc->language==LANG_SINGULAR) |
---|
| 1163 | Print("line %4d,%-5ld %4d,%-5ld %4d,%-5ld\n", |
---|
[2ba9a6] | 1164 | proc->data.s.proc_lineno, proc->data.s.proc_start, |
---|
| 1165 | proc->data.s.body_lineno, proc->data.s.body_start, |
---|
| 1166 | proc->data.s.example_lineno, proc->data.s.example_start); |
---|
[0077d9d] | 1167 | else if(proc->language==LANG_C) |
---|
| 1168 | Print("type: object\n"); |
---|
[2ba9a6] | 1169 | } |
---|
| 1170 | } |
---|
| 1171 | } |
---|
[c599b4] | 1172 | #endif |
---|
[2ba9a6] | 1173 | |
---|
| 1174 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
[fca547] | 1175 | //char *iiLineNo(char *procname, int lineno) |
---|
| 1176 | //{ |
---|
| 1177 | // char buf[256]; |
---|
| 1178 | // idhdl pn = ggetid(procname); |
---|
| 1179 | // procinfo *pi = IDPROC(pn); |
---|
| 1180 | // |
---|
| 1181 | // sprintf(buf, "%s %3d\0", procname, lineno); |
---|
| 1182 | // //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname, |
---|
| 1183 | // // lineno + pi->data.s.body_lineno); |
---|
| 1184 | // return(buf); |
---|
| 1185 | //} |
---|
[6a51ef] | 1186 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
| 1187 | #ifdef HAVE_LIBPARSER |
---|
| 1188 | void libstack::push(char *p, char *libname) |
---|
| 1189 | { |
---|
| 1190 | libstackv lp; |
---|
[50cbdc] | 1191 | if( !iiGetLibStatus(libname)) |
---|
[743c32] | 1192 | { |
---|
| 1193 | for(lp = this;lp!=NULL;lp=lp->next) |
---|
| 1194 | { |
---|
[6a51ef] | 1195 | if(strcmp(lp->get(), libname)==0) break; |
---|
| 1196 | } |
---|
[743c32] | 1197 | if(lp==NULL) |
---|
| 1198 | { |
---|
[c232af] | 1199 | libstackv ls = (libstack *)omAlloc0Bin(libstack_bin); |
---|
[6a51ef] | 1200 | ls->next = this; |
---|
[c232af] | 1201 | ls->libname = omStrDup(libname); |
---|
[6a51ef] | 1202 | ls->to_be_done = TRUE; |
---|
| 1203 | if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0; |
---|
| 1204 | library_stack = ls; |
---|
[5c8eae0] | 1205 | } |
---|
[6a51ef] | 1206 | } |
---|
| 1207 | } |
---|
| 1208 | |
---|
| 1209 | libstackv libstack::pop(char *p) |
---|
| 1210 | { |
---|
| 1211 | libstackv ls = this; |
---|
[c232af] | 1212 | //omFree((ADDRESS)ls->libname); |
---|
[6a51ef] | 1213 | library_stack = ls->next; |
---|
[c232af] | 1214 | omFreeBin((ADDRESS)ls, libstack_bin); |
---|
[6a51ef] | 1215 | return(library_stack); |
---|
| 1216 | } |
---|
| 1217 | |
---|
| 1218 | #endif /* HAVE_LIBPARSER */ |
---|
| 1219 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|