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