/[ascend]/trunk/tcltk/interface/Driver.c
ViewVC logotype

Diff of /trunk/tcltk/interface/Driver.c

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

revision 2024 by jpye, Wed Apr 29 06:20:28 2009 UTC revision 2025 by jpye, Thu Apr 30 02:15:05 2009 UTC
# Line 454  int AscDriver(int argc, CONST char **arg Line 454  int AscDriver(int argc, CONST char **arg
454  */  */
455  #define OSPATH_PUTENV(VAR,FP) \  #define OSPATH_PUTENV(VAR,FP) \
456      /*CONSOLE_DEBUG("VAR: %s",VAR);*/ \      /*CONSOLE_DEBUG("VAR: %s",VAR);*/ \
457      sprintf(envcmd,"%s=",VAR); \      sprintf(tmp,"%s=",VAR); \
458      ospath_strcat(FP,envcmd,MAX_ENV_VAR_LENGTH); \      ospath_strcat(FP,tmp,MAX_ENV_VAR_LENGTH); \
459      /*CONSOLE_DEBUG("ENVCMD: %s",envcmd);*/ \      /*CONSOLE_DEBUG("TEMP: %s",tmp);*/ \
460      PUTENV(envcmd)      PUTENV(tmp)
461    
462  /**  /**
463      This is a quick macro to send data to Tcl using Tcl_SetVar.      This is a quick macro to send data to Tcl using Tcl_SetVar.
# Line 498  static void printenv(){ Line 498  static void printenv(){
498      <utilities/config.h>. The following comments assume that you      <utilities/config.h>. The following comments assume that you
499      use the usual names for each of these:      use the usual names for each of these:
500    
501      ASCENDDIST defaults to $PROGDIR/@ASC_DATADIR_REL_BIN@ (also in config.h)      For Tcl/Tk the following #defines can be needed:
502      ASCENDTK defaults to $ASCENDDIST/TK (latter is from config.h)          ASCENDDIST
503      ASCENDBITMAPS defaults $ASCENDTK/bitmaps          ASCENDTK_DEFAULT
504      ASCENDLIBRARY defaults to $ASCENDDIST/models          ASCENDLIBRARY_DEFAULT
505            ASCENDSOLVERS_DEFAULT
506    
507            ASC_ABSOLUTE_PATHS
508            ASC_DIST_REL_BIN
509            ASC_TK_REL_DIST
510            ASC_LIBRARY_REL_DIST
511            ASC_SOLVERS_REL_DIST
512    
513        Then, using these, in the case of relative paths, we choose:
514    
515            ASCENDDIST = $PROGDIR/@ASC_DIST_REL_BIN@
516            ASCENDTK = $ASCENDROOT/@ASC_TK_REL_DIST@
517            ASCENDLIBRARY = $ASCENDROOT/@ASC_LIBRARY_REL_DIST@
518            ASCENDSOLVERS = $ASCENDROOT/@ASC_SOLVERS_ROL_DIST@
519    
520      Also check for the existence of the file AscendRC in $ASCENDTK      Also check for the existence of the file AscendRC in $ASCENDTK
521      and if found, export the location of that file to the Tcl      and if found, export the location of that file to the Tcl
# Line 513  static void printenv(){ Line 527  static void printenv(){
527  static void AscCheckEnvironVars(Tcl_Interp *interp,const char *progname){  static void AscCheckEnvironVars(Tcl_Interp *interp,const char *progname){
528      char *distdir, *tkdir, *bitmapsdir, *librarydir, *solversdir;      char *distdir, *tkdir, *bitmapsdir, *librarydir, *solversdir;
529      struct FilePath *fp, *fp1, *distfp, *tkfp, *bitmapsfp, *libraryfp, *solversfp;      struct FilePath *fp, *fp1, *distfp, *tkfp, *bitmapsfp, *libraryfp, *solversfp;
530      char envcmd[MAX_ENV_VAR_LENGTH];      char tmp[MAX_ENV_VAR_LENGTH];
531  # ifndef ASC_ABSOLUTE_PATHS  #if !ASC_ABSOLUTE_PATHS
532      char s1[PATH_MAX];      char s1[PATH_MAX];
533  #endif  #endif
534      int err;      int err;
# Line 549  static void AscCheckEnvironVars(Tcl_Inte Line 563  static void AscCheckEnvironVars(Tcl_Inte
563      if(distdir == NULL){      if(distdir == NULL){
564          CONSOLE_DEBUG("Note: No '" ASC_ENV_DIST "' var defined");          CONSOLE_DEBUG("Note: No '" ASC_ENV_DIST "' var defined");
565    
566  # ifndef ASC_ABSOLUTE_PATHS  #if ASC_ABSOLUTE_PATHS
567            CONSOLE_DEBUG("ASC_ABSOLUTE_PATHS=%d",ASC_ABSOLUTE_PATHS);
568            distfp = ospath_new(ASCENDDIST_DEFAULT);
569            (void)progname;
570    #else
571          /* read the executable's name/relative path.*/          /* read the executable's name/relative path.*/
572          fp = ospath_new(progname);          fp = ospath_new(progname);
573    
# Line 561  static void AscCheckEnvironVars(Tcl_Inte Line 578  static void AscCheckEnvironVars(Tcl_Inte
578          fp1 = ospath_getdir(fp);          fp1 = ospath_getdir(fp);
579          ospath_free(fp);          ospath_free(fp);
580    
581          ospath_strncpy(fp1,s1,PATH_MAX);          /* convert to absolute */
582          /* CONSOLE_DEBUG("DIR = %s",s1); */          fp = ospath_getabs(fp1);
583            ospath_free(fp1);
584    
585          /* append the contents of ASC_DISTDIR_REL_BIN to this path*/          /* append the contents of ASC_DISTDIR_REL_BIN to this path*/
586          fp = ospath_new_noclean(ASC_DISTDIR_REL_BIN);          fp1 = ospath_new_noclean(ASC_DIST_REL_BIN);
         distfp = ospath_concat(fp1,fp);  
         ospath_cleanup(distfp);  
587    
588          ospath_strncpy(fp1,s1,PATH_MAX);          distfp = ospath_concat(fp,fp1);
589          /* CONSOLE_DEBUG("DIST = %s",s1); */          ospath_cleanup(distfp);
590            ospath_free(fp1);
591            ospath_free(fp);
592    #endif
593    
 # else  
         CONSOLE_DEBUG("ASC_ABSOLUTE_PATHS=%d",ASC_ABSOLUTE_PATHS);  
         distfp = ospath_new(ASC_DATADIR);  
         (void)progname;  
 # endif  
594          distdir = ospath_str(distfp);          distdir = ospath_str(distfp);
595          /* CONSOLE_DEBUG("GUESSING %s = %s",ASC_ENV_DIST,distdir); */          
596            CONSOLE_DEBUG("Setting distdir %s = %s",ASC_ENV_DIST,distdir);
597          OSPATH_PUTENV(ASC_ENV_DIST,distfp);          OSPATH_PUTENV(ASC_ENV_DIST,distfp);
598          distdir = GETENV(ASC_ENV_DIST);          distdir = GETENV(ASC_ENV_DIST);
599          /* CONSOLE_DEBUG("RETRIEVED %s = %s",ASC_ENV_DIST,distdir); */          /* CONSOLE_DEBUG("RETRIEVED %s = %s",ASC_ENV_DIST,distdir); */
600          printenv();          printenv();
601            ospath_free(distfp);
602      }      }
603    
604      if(tkdir == NULL){      if(tkdir == NULL){
605          /* CONSOLE_DEBUG("USING DEFAULT %s = %s",ASC_ENV_TK,ASC_ENV_TK_DEFAULT); */          /* no env var ASCENDTK... create value from compile-time info */
606          guessedtk=1;          guessedtk=1;
607          tkfp = ospath_new_expand_env(ASC_ENV_TK_DEFAULT, &GETENV);  #if ASC_ABSOLUTE_PATHS
608            tkfp = ospath_new_expand_env(ASCENDTK_DEFAULT, &GETENV);
609    #else
610            fp = ospath_new(ASC_TK_REL_DIST);
611            tkfp = ospath_concat(distdir,fp);
612            ospath_free(fp);
613            ospath_cleanup(tkfp);
614    #endif
615          tkdir = ospath_str(tkfp);          tkdir = ospath_str(tkfp);
   
         ospath_strncpy(tkfp,envcmd,MAX_ENV_VAR_LENGTH);  
         /* CONSOLE_DEBUG("TK = %s",envcmd); */  
   
616          OSPATH_PUTENV(ASC_ENV_TK,tkfp);          OSPATH_PUTENV(ASC_ENV_TK,tkfp);
617      }else{      }else{
618            /* expand env vars in ASCENDTK */
619          tkfp = ospath_new_expand_env(tkdir, &GETENV);          tkfp = ospath_new_expand_env(tkdir, &GETENV);
620          tkdir = ospath_str(tkfp);          tkdir = ospath_str(tkfp);
621          OSPATH_PUTENV(ASC_ENV_TK,tkfp);          OSPATH_PUTENV(ASC_ENV_TK,tkfp);
# Line 607  static void AscCheckEnvironVars(Tcl_Inte Line 627  static void AscCheckEnvironVars(Tcl_Inte
627          bitmapsfp = ospath_new_expand_env("$ASCENDTK/bitmaps", &GETENV);          bitmapsfp = ospath_new_expand_env("$ASCENDTK/bitmaps", &GETENV);
628          OSPATH_PUTENV(ASC_ENV_BITMAPS,bitmapsfp);          OSPATH_PUTENV(ASC_ENV_BITMAPS,bitmapsfp);
629          bitmapsdir = ospath_str(bitmapsfp);          bitmapsdir = ospath_str(bitmapsfp);
630            ospath_free(bitmapsfp);
631      }      }
632    
633      /**      /**
# Line 616  static void AscCheckEnvironVars(Tcl_Inte Line 637  static void AscCheckEnvironVars(Tcl_Inte
637          @TODO Also, what about ASCEND_DEFAULTLIBRARY ?          @TODO Also, what about ASCEND_DEFAULTLIBRARY ?
638      */      */
639      if(librarydir == NULL){      if(librarydir == NULL){
640          /* CONSOLE_DEBUG("NO " ASC_ENV_LIBRARY " VAR DEFINED"); */  #if ASC_ABSOLUTE_PATHS
641          libraryfp = ospath_new_expand_env("$ASCENDDIST/lib/models", &GETENV);          libraryfp = ospath_new(ASCENDLIBARY_DEFAULT);
642    #else
643            libraryfp = ospath_new_expand_env("$ASCENDDIST/" ASC_LIBRARY_REL_DIST, &GETENV);
644    #endif
645          /* CONSOLE_DEBUG("CREATED LIBRARY VAL"); */          /* CONSOLE_DEBUG("CREATED LIBRARY VAL"); */
646          OSPATH_PUTENV(ASC_ENV_LIBRARY,libraryfp);          OSPATH_PUTENV(ASC_ENV_LIBRARY,libraryfp);
647          librarydir = ospath_str(libraryfp);          librarydir = ospath_str(libraryfp);
# Line 625  static void AscCheckEnvironVars(Tcl_Inte Line 649  static void AscCheckEnvironVars(Tcl_Inte
649      }      }
650    
651      if(solversdir == NULL){      if(solversdir == NULL){
652          /* CONSOLE_DEBUG("NO " ASC_ENV_LIBRARY " VAR DEFINED"); */  #if ASC_ABSOLUTE_PATHS
653          solversfp = ospath_new_expand_env("$ASCENDDIST/lib/solvers", &GETENV);          solversfp = ospath_new(ASCENDLIBARY_DEFAULT);
654    #else
655            solversfp = ospath_new_expand_env("$ASCENDDIST/" ASC_SOLVERS_REL_DIST, &GETENV);
656    #endif
657          /* CONSOLE_DEBUG("CREATED SOLVERS VAL"); */          /* CONSOLE_DEBUG("CREATED SOLVERS VAL"); */
658          OSPATH_PUTENV(ASC_ENV_SOLVERS,solversfp);          OSPATH_PUTENV(ASC_ENV_SOLVERS,solversfp);
659          solversdir = ospath_str(solversfp);          solversdir = ospath_str(solversfp);
660          ospath_free(solversfp);          ospath_free(solversfp);
661      }      }
662    
663        CONSOLE_DEBUG("ASCENDDIST = %s",GETENV(ASC_ENV_DIST));
664        CONSOLE_DEBUG("ASCENDTK = %s",GETENV(ASC_ENV_TK));
665        CONSOLE_DEBUG("ASCENDLIBRARY = %s",GETENV(ASC_ENV_LIBRARY));
666        CONSOLE_DEBUG("ASCENDSOLVERS = %s",GETENV(ASC_ENV_SOLVERS));
667    
668    
669      CONSOLE_DEBUG("CHECKING FOR AscendRC FILE");      CONSOLE_DEBUG("CHECKING FOR AscendRC FILE");
670    
671      fp1 = ospath_new("AscendRC");      fp1 = ospath_new("AscendRC");
672      fp = ospath_concat(tkfp,fp1);      fp = ospath_concat(tkfp,fp1);
673      ospath_free(fp1);      ospath_free(fp1);
674        ospath_free(tkfp);
675      f = ospath_fopen(fp,"r");      f = ospath_fopen(fp,"r");
676      if(f==NULL){      if(f==NULL){
677          if(guessedtk){          if(guessedtk){
# Line 658  static void AscCheckEnvironVars(Tcl_Inte Line 692  static void AscCheckEnvironVars(Tcl_Inte
692          /* can't get here, hopefully */          /* can't get here, hopefully */
693      }      }
694      fclose(f);      fclose(f);
     /* reuse 'envcmd' to get the string file location for AscendRC */  
     ospath_strncpy(fp,envcmd,MAX_ENV_VAR_LENGTH);  
     ospath_free(fp);  
695    
696      /* export the value to Tcl/Tk */      /* put AscendRC location in string and export to Tcl */
697      ASC_SEND_TO_TCL(tcl_rcFileName, envcmd);      ospath_strncpy(fp,tmp,MAX_ENV_VAR_LENGTH);
698        ASC_SEND_TO_TCL(tcl_rcFileName, tmp);
699        ospath_free(fp);
700    
701      /* send all the environment variables to Tcl/Tk as well */      /* send all the environment variables to Tcl/Tk as well */
702      ASC_SEND_TO_TCL2(env,ASC_ENV_DIST,distdir);      ASC_SEND_TO_TCL2(env,ASC_ENV_DIST,distdir);

Legend:
Removed from v.2024  
changed lines
  Added in v.2025

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