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