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

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

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

revision 1050 by johnpye, Mon Dec 18 05:49:00 2006 UTC revision 1051 by johnpye, Sat Jan 6 04:08:29 2007 UTC
# Line 143  static struct module_t *OpenModuleIntern Line 143  static struct module_t *OpenModuleIntern
143  static void RemoveModule(CONST struct module_t *);  static void RemoveModule(CONST struct module_t *);
144  static struct module_t *SearchForModule(CONST struct module_t *);  static struct module_t *SearchForModule(CONST struct module_t *);
145  static int StoreModule(CONST struct module_t *);  static int StoreModule(CONST struct module_t *);
146  static void WriteWhyNotFound(symchar *,  int);  static void WriteWhyNotFound(char *,  int);
147    
148  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
149    MODULE HANDLING    MODULE HANDLING
# Line 348  struct module_t *OpenModuleInternal(CONS Line 348  struct module_t *OpenModuleInternal(CONS
348    if (keep_string == NULL) {    if (keep_string == NULL) {
349      Asc_ScannerAssignFile(new_module->f,1);      Asc_ScannerAssignFile(new_module->f,1);
350    } else {    } else {
351      assert(new_module->scanbuffer != NULL);      asc_assert(new_module->scanbuffer != NULL);
352      Asc_ScannerAssignString(new_module->scanbuffer,1,1);      Asc_ScannerAssignString(new_module->scanbuffer,1,1);
353    }    }
354    
# Line 398  struct module_t *FindModuleFile(CONST ch Line 398  struct module_t *FindModuleFile(CONST ch
398    int result;                   /* return value when searching for module */    int result;                   /* return value when searching for module */
399    int error;                    /* error number returned by fopen() or stat() */    int error;                    /* error number returned by fopen() or stat() */
400    
401    assert(name != NULL);    asc_assert(name != NULL);
402    assert(status != NULL);    asc_assert(status != NULL);
403      asc_assert(strcmp(name,"")!=0);
404    
405    /*    /*
406      Create space for the module and set its base_name to a "proper"      Create space for the module and set its base_name to a "proper"
# Line 419  struct module_t *FindModuleFile(CONST ch Line 420  struct module_t *FindModuleFile(CONST ch
420      Check to see if a module having the same base_name exists.      Check to see if a module having the same base_name exists.
421      If so, fetch it.      If so, fetch it.
422     */     */
423    dup = SearchForModule( new_module );    dup = SearchForModule(new_module);
424    
425      if(dup){
426        CONSOLE_DEBUG("Duplicate module named '%s' was found"
427          ,SCP(new_module->base_name)
428        );
429      }
430    
431    /*    /*
432      If were we called from RequireModule, return if a module      If we were called from RequireModule, return if a module
433      having this name already exists      having this name already exists
434     */    */
435    if(( do_not_overwrite == TRUE ) && ( dup != NULL )) {    if(( do_not_overwrite == TRUE ) && ( dup != NULL )) {
436      DeleteModule( new_module );      DeleteModule( new_module );
437      *status = 5;      *status = 5;
# Line 453  struct module_t *FindModuleFile(CONST ch Line 460  struct module_t *FindModuleFile(CONST ch
460      a message and exit the function      a message and exit the function
461    */    */
462    if( result == -1 ) {    if( result == -1 ) {
463      WriteWhyNotFound( new_module->filename, error );      CONSOLE_DEBUG("ModuleSearchPath returned -1, name=%s, filename=%s",name,filename);
464        WriteWhyNotFound(name, error);
465      DeleteModule(new_module);      DeleteModule(new_module);
466      *status = -2;      *status = -2;
467      return NULL;      return NULL;
# Line 471  struct module_t *FindModuleFile(CONST ch Line 479  struct module_t *FindModuleFile(CONST ch
479    */    */
480    new_module->filename = AddSymbol(filename);    new_module->filename = AddSymbol(filename);
481    
482    assert(new_module->f != NULL);    asc_assert(new_module->f != NULL);
483    
484    /*    /*
485      If a module having the same base_name does not exist,      If a module having the same base_name does not exist,
# Line 644  struct module_t *CreateStringModule(CONS Line 652  struct module_t *CreateStringModule(CONS
652    int result;                   /* return value when searching for module */    int result;                   /* return value when searching for module */
653  #endif /* use for strings */  #endif /* use for strings */
654    
655    assert(name != NULL);    asc_assert(name != NULL);
656    assert(keep_string != NULL);    asc_assert(keep_string != NULL);
657    assert(status != NULL);    asc_assert(status != NULL);
658    
659    /*    /*
660     *  Create space for the module and set its base_name to a "proper"     *  Create space for the module and set its base_name to a "proper"
# Line 664  struct module_t *CreateStringModule(CONS Line 672  struct module_t *CreateStringModule(CONS
672     *  If so, fetch it.     *  If so, fetch it.
673     */     */
674    dup = SearchForModule( new_module );    dup = SearchForModule( new_module );
675    assert(dup == NULL); /* string modules are to be unique */    asc_assert(dup == NULL); /* string modules are to be unique */
676    /* probably should be ascpanic to avoid mystery messages */    /* probably should be ascpanic to avoid mystery messages */
677    
678  #if USE_FOR_STRINGS  #if USE_FOR_STRINGS
# Line 701  struct module_t *CreateStringModule(CONS Line 709  struct module_t *CreateStringModule(CONS
709     *  a message and exit the function     *  a message and exit the function
710     */     */
711    if( result == -1 ) {    if( result == -1 ) {
712      WriteWhyNotFound( new_module->filename, error );      CONSOLE_DEBUG("ModuleSearchPath returned -1, name=%s, filename=%s",name,filename);
713        WriteWhyNotFound(filename, error );
714      DeleteModule(new_module);      DeleteModule(new_module);
715      *status = -2;      *status = -2;
716      return NULL;      return NULL;
# Line 879  int module_searchpath_test(struct FilePa Line 888  int module_searchpath_test(struct FilePa
888      /*char *tmp;*/      /*char *tmp;*/
889    
890      sd = (struct ModuleSearchData *)searchdata;      sd = (struct ModuleSearchData *)searchdata;
891      assert(sd!=NULL);      asc_assert(sd!=NULL);
892      assert(sd->fp!=NULL);      asc_assert(sd->fp!=NULL);
893    
894    
895      /*      /*
# Line 942  int module_searchpath_test(struct FilePa Line 951  int module_searchpath_test(struct FilePa
951      value of errno will be passed back to the caller in the `error'      value of errno will be passed back to the caller in the `error'
952      argument.      argument.
953    
954        @param name filename to be searched for (in cwd & in search path).
955        @param filename (output) the location of the found file (if found)
956        @param error (output) error code from ModuleStatFile
957        @param m (output) a pointer to the opened module_t object (if found)
958    
959      @return      @return
960          -4  Invalid partial path in parameter 'filename'.          -4  Invalid partial path in parameter 'filename'.
961          -3  Memory error occurred when trying to get PATHENVIRONMENTVAR          -3  Memory error occurred when trying to get PATHENVIRONMENTVAR
# Line 955  int ModuleSearchPath(CONST char *name, Line 969  int ModuleSearchPath(CONST char *name,
969                       struct module_t *m,                       struct module_t *m,
970                       int * CONST error                       int * CONST error
971  ){  ){
     /* register size_t length; */  
     /* int result; */  
     /* int path_entries; */  
     /* int j; */  
     /* register CONST char *t; */  
972      struct FilePath *fp1, *fp2;      struct FilePath *fp1, *fp2;
973      char *tmp;      char *tmp;
974      struct FilePath **sp1 = NULL;      struct FilePath **sp1 = NULL;
975      struct ModuleSearchData sd;      struct ModuleSearchData sd;
976    
977      assert( name != NULL );      asc_assert( name != NULL );
978      assert( filename != NULL );      asc_assert( filename != NULL );
979      assert( m != NULL );      asc_assert( m != NULL );
980      assert( error != NULL );      asc_assert( error != NULL );
981    
982      /* CONSOLE_DEBUG("Launching ModuleSearchPath with '%s'",name); */      /* CONSOLE_DEBUG("Launching ModuleSearchPath with '%s'",name); */
983    
# Line 1020  int ModuleSearchPath(CONST char *name, Line 1029  int ModuleSearchPath(CONST char *name,
1029    
1030          if(fp2==NULL){          if(fp2==NULL){
1031              *error = sd.error;              *error = sd.error;
1032              CONSOLE_DEBUG("File '%s' not found in search path",name);              CONSOLE_DEBUG("File '%s' not found in search path (%d)",name,sd.error);
1033              ospath_searchpath_free(sp1);              ospath_searchpath_free(sp1);
1034              return -1;              return -1;
1035          }          }
1036    
1037          tmp = ospath_str(fp2);          tmp = ospath_str(fp2);
1038          assert(tmp!=NULL);          asc_assert(tmp!=NULL);
1039          /* CONSOLE_DEBUG("Found file in '%s' in search path",tmp); */          /* CONSOLE_DEBUG("Found file in '%s' in search path",tmp); */
1040          ospath_searchpath_free(sp1);          ospath_searchpath_free(sp1);
1041          ospath_free_str(tmp);          ospath_free_str(tmp);
# Line 1049  int ModuleSearchPath(CONST char *name, Line 1058  int ModuleSearchPath(CONST char *name,
1058      not open/stat the file named `filename'.      not open/stat the file named `filename'.
1059  */  */
1060  static  static
1061  void WriteWhyNotFound(symchar *filename, int error)  void WriteWhyNotFound(char *filename, int error)
1062  {  {
1063    switch( error ) {    switch( error ) {
1064    case EACCES:    case EACCES:
1065      ERROR_REPORTER_HERE(ASC_USER_ERROR,      ERROR_REPORTER_HERE(ASC_USER_ERROR,
1066          "File or directory permissions don't allow you to access '%s'.",          "File or directory permissions don't allow you to access '%s'.",
1067          SCP(filename)          filename
1068      );      );
1069      break;      break;
1070    case EFAULT:    case EFAULT:
# Line 1065  void WriteWhyNotFound(symchar *filename, Line 1074  void WriteWhyNotFound(symchar *filename,
1074      break;      break;
1075    case EIO:    case EIO:
1076      ERROR_REPORTER_HERE(ASC_USER_ERROR      ERROR_REPORTER_HERE(ASC_USER_ERROR
1077          ,"I/O error in reading '%s'.",SCP(filename)          ,"I/O error in reading '%s'.",filename
1078      );      );
1079      break;      break;
1080    case ENAMETOOLONG:    case ENAMETOOLONG:
1081      ERROR_REPORTER_HERE(ASC_USER_ERROR      ERROR_REPORTER_HERE(ASC_USER_ERROR
1082          ,"The path for '%s' is too long.",SCP(filename)          ,"The path for '%s' is too long.",filename
1083      );      );
1084      break;      break;
1085    case ENOENT:    case ENOENT:
1086      ERROR_REPORTER_HERE(ASC_USER_ERROR      ERROR_REPORTER_HERE(ASC_USER_ERROR
1087          ,"File '%s' doesn't exist.",SCP(filename)          ,"File '%s' doesn't exist.",filename
1088      );      );
1089      break;      break;
1090    case ENOTDIR:    case ENOTDIR:
1091      ERROR_REPORTER_HERE(ASC_USER_ERROR      ERROR_REPORTER_HERE(ASC_USER_ERROR
1092          ,"A component of the path name '%s' is not a directory.",SCP(filename)          ,"A component of the path name '%s' is not a directory.",filename
1093      );      );
1094      break;      break;
1095  #ifndef __WIN32__  #ifndef __WIN32__
1096    case ELOOP:    case ELOOP:
1097      /*  no symlinks in windows land  */      /*  no symlinks in windows land  */
1098      ERROR_REPORTER_HERE(ASC_USER_ERROR      ERROR_REPORTER_HERE(ASC_USER_ERROR
1099          ,"There are too many symbolic links in '%s'.",SCP(filename)          ,"There are too many symbolic links in '%s'.",filename
1100      );      );
1101      break;      break;
1102  #endif  /*  __WIN32__  */  #endif  /*  __WIN32__  */
# Line 1109  extern int Asc_ModuleCreateAlias(CONST s Line 1118  extern int Asc_ModuleCreateAlias(CONST s
1118    struct module_t *dup;    struct module_t *dup;
1119    char mod_name[PATH_MAX];    char mod_name[PATH_MAX];
1120    
1121    assert( m != NULL );    asc_assert( m != NULL );
1122    
1123    /*    /*
1124     *  Make sure the user gave us good data     *  Make sure the user gave us good data
# Line 1354  void RemoveModule(CONST struct module_t Line 1363  void RemoveModule(CONST struct module_t
1363   *  CmpModulesNameVers() to determine which module return.   *  CmpModulesNameVers() to determine which module return.
1364   */   */
1365  static  static
1366  struct module_t *SearchForModule(CONST struct module_t *m)  struct module_t *SearchForModule(CONST struct module_t *m){
 {  
1367    unsigned long place;    unsigned long place;
1368    
1369    assert(m != NULL);    asc_assert(m != NULL);
1370    
1371    if( g_module_list == NULL ) {    if( g_module_list == NULL ) {
1372      return NULL;      return NULL;
# Line 1383  struct module_t *SearchForModule(CONST s Line 1391  struct module_t *SearchForModule(CONST s
1391   *          && m1->version <= m2->version   *          && m1->version <= m2->version
1392   */   */
1393  static  static
1394  int CmpModulesNameVers(CONST struct module_t *m1, CONST struct module_t *m2)  int CmpModulesNameVers(CONST struct module_t *m1, CONST struct module_t *m2){
 {  
1395    int result;    int result;
1396    
1397    if( (result = CmpSymchar(m1->base_name, m2->base_name)) != 0 ) {    if( (result = CmpSymchar(m1->base_name, m2->base_name)) != 0 ) {
# Line 1420  extern int Asc_CloseCurrentModule(void){ Line 1427  extern int Asc_CloseCurrentModule(void){
1427      fclose(g_current_module->f);      fclose(g_current_module->f);
1428      g_current_module->f = NULL;      g_current_module->f = NULL;
1429    } else {    } else {
1430      assert(g_current_module->s != NULL);      asc_assert(g_current_module->s != NULL);
1431      Asc_ScannerReleaseStringBuffer(g_current_module->scanbuffer);      Asc_ScannerReleaseStringBuffer(g_current_module->scanbuffer);
1432      g_current_module->scanbuffer = NULL;      g_current_module->scanbuffer = NULL;
1433    }    }
# Line 1446  extern int Asc_CloseCurrentModule(void){ Line 1453  extern int Asc_CloseCurrentModule(void){
1453    if (g_current_module->s == NULL) {    if (g_current_module->s == NULL) {
1454      Asc_ScannerAssignFile(g_current_module->f,g_current_module->linenum);      Asc_ScannerAssignFile(g_current_module->f,g_current_module->linenum);
1455    } else {    } else {
1456      assert(g_current_module->scanbuffer != NULL);      asc_assert(g_current_module->scanbuffer != NULL);
1457      Asc_ScannerAssignString(g_current_module->scanbuffer,      Asc_ScannerAssignString(g_current_module->scanbuffer,
1458                              g_current_module->linenum,0);                              g_current_module->linenum,0);
1459    }    }
# Line 1539  unsigned long ModuleNameToInternalNameVe Line 1546  unsigned long ModuleNameToInternalNameVe
1546    unsigned int t;    unsigned int t;
1547    unsigned long vers = ULONG_MAX;    unsigned long vers = ULONG_MAX;
1548    
1549    assert( name != NULL );    asc_assert( name != NULL );
1550    
1551    /*    /*
1552     *  Make sure we got good data     *  Make sure we got good data
# Line 1666  extern struct gl_list_t *Asc_ModuleList( Line 1673  extern struct gl_list_t *Asc_ModuleList(
1673    
1674    
1675  extern void Asc_ModuleWrite(FILE *f, CONST struct module_t *m){  extern void Asc_ModuleWrite(FILE *f, CONST struct module_t *m){
1676    assert(m!=NULL);    asc_assert(m!=NULL);
1677    FPRINTF(f,"MODULE: %s\nFILENAME: %s\n",SCP(m->name),SCP(m->filename));    FPRINTF(f,"MODULE: %s\nFILENAME: %s\n",SCP(m->name),SCP(m->filename));
1678    FPRINTF(f,(m->f!=NULL)?"OPEN\n":"CLOSED\n");    FPRINTF(f,(m->f!=NULL)?"OPEN\n":"CLOSED\n");
1679    FPRINTF(f,"FILE DATE: %s",asctime(localtime( &(m->time_last_modified) )));    FPRINTF(f,"FILE DATE: %s",asctime(localtime( &(m->time_last_modified) )));

Legend:
Removed from v.1050  
changed lines
  Added in v.1051

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