/[ascend]/trunk/base/generic/compiler/packages.c
ViewVC logotype

Diff of /trunk/base/generic/compiler/packages.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 863 by johnpye, Tue Sep 26 13:47:27 2006 UTC revision 864 by johnpye, Thu Sep 28 13:39:16 2006 UTC
# Line 49  Line 49 
49  #include "compiler.h"  #include "compiler.h"
50  #include <utilities/ascMalloc.h>  #include <utilities/ascMalloc.h>
51  #include <utilities/ascEnvVar.h>  #include <utilities/ascEnvVar.h>
52  #include <utilities/ascDynaLoad.h>  #include <compiler/importhandler.h>
53    #include <utilities/ascPanic.h>
54  #include <general/list.h>  #include <general/list.h>
55  #include "symtab.h"  #include "symtab.h"
56  #include "fractions.h"  #include "fractions.h"
# Line 120  int Builtins_Init(void) Line 121  int Builtins_Init(void)
121    return result;    return result;
122  }  }
123    
124  int LoadArchiveLibrary(CONST char *partialname, CONST char *initfunc){  /* return 0 on success */
125    int LoadArchiveLibrary(CONST char *partialpath, CONST char *initfunc){
126    
127  #ifdef DYNAMIC_PACKAGES  #ifdef DYNAMIC_PACKAGES
     char *file;  
     char auto_initfunc[PATH_MAX];  
     char *stem;  
128      struct FilePath *fp1;      struct FilePath *fp1;
129      int result;      int result;
130        struct ImportHandler *handler=NULL;
131    
132      /**      /**
133          @TODO          @TODO
# Line 137  int LoadArchiveLibrary(CONST char *parti Line 137  int LoadArchiveLibrary(CONST char *parti
137                should be used to open it, then make the call.                should be used to open it, then make the call.
138      */      */
139    
140      CONSOLE_DEBUG("Searching for external library '%s'",partialname);      CONSOLE_DEBUG("Searching for external library '%s'",partialpath);
141    
142      file = SearchArchiveLibraryPath(partialname, ASC_DEFAULTPATH, PATHENVIRONMENTVAR);      importhandler_createlibrary();
     if(file==NULL){  
         ERROR_REPORTER_HERE(ASC_PROG_WARNING,"'ImportHandler' functionality not yet implemeneted.");  
         ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"External library '%s' not found.",partialname);  
         return 1;  
     }else{  
         /* file was found, and is DLL/SO */  
     }  
143    
144      /* assume that the complete path is now in 'file' */      fp1 = importhandler_findinpath(
145      fp1 = ospath_new_from_posix(partialname);          partialpath, ASC_DEFAULTPATH, PATHENVIRONMENTVAR,&handler
146      stem = ospath_getfilestem(fp1);      );
147      if(stem==NULL){      if(fp1==NULL){
148          ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"What is the stem of named library '%s'???",partialname);          CONSOLE_DEBUG("External library '%s' not found",partialpath);
149          free(stem);          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"External library '%s' not found.",partialpath);
150          ospath_free(fp1);          return 1; /* failure */
         return 1;  
     }  
   
     if(initfunc==NULL){  
         strncpy(auto_initfunc,stem,PATH_MAX);  
         strncat(auto_initfunc,"_register",PATH_MAX-strlen(auto_initfunc));  
         result = Asc_DynamicLoad(file,auto_initfunc);  
     }else{  
         result = Asc_DynamicLoad(file,initfunc);  
151      }      }
152    
153        asc_assert(handler!=NULL);
154        
155        CONSOLE_DEBUG("About to import external library...");
156        /* note the import handler will deal with all the initfunc execution, etc etc */
157        result = (*(handler->importfn))(fp1,initfunc,partialpath);
158      if(result){      if(result){
159          CONSOLE_DEBUG("FAILED TO IMPORT '%s' (error %d)",partialname,result);          CONSOLE_DEBUG("Error %d when importing external library of type '%s'",result,handler->name);
160          result = 1;          ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Error importing external library '%s'",partialpath);
161      }else{          ospath_free(fp1);
162          if(initfunc==NULL){          return 1;
             CONSOLE_DEBUG("Successfully ran '%s' from dynamic package '%s'",auto_initfunc,file);  
         }else{  
             CONSOLE_DEBUG("Successfully ran '%s' from dynamic package '%s'",initfunc,file);  
         }  
163      }      }
164    
     free(stem);  
165      ospath_free(fp1);      ospath_free(fp1);
166      return result;      return 0;
   
167  #else  #else
168    
169      DISUSED_PARAMETER(name); DISUSED_PARAMETER(initfunc);      DISUSED_PARAMETER(name); DISUSED_PARAMETER(initfunc);

Legend:
Removed from v.863  
changed lines
  Added in v.864

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22