Changeset abd1c2 in git for Singular/febase.cc


Ignore:
Timestamp:
Jun 5, 1998, 11:39:34 AM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c51762f18dfacf5d060608511226b47283868578
Parents:
757550da97af1df30c4f0816a21fd54dc54c26c0
Message:
* hannes: added feExpandPath (for WINNT)


git-svn-id: file:///usr/local/Singular/svn/trunk@2079 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/febase.cc

    r757550 rabd1c2  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: febase.cc,v 1.45 1998-06-04 17:20:54 Singular Exp $ */
     4/* $Id: febase.cc,v 1.46 1998-06-05 09:39:34 Singular Exp $ */
    55/*
    66* ABSTRACT: i/o system
     
    4646#ifndef MAXPATHLEN
    4747#define MAXPATHLEN 1024
     48#endif
     49
     50#ifndef MAXNAMLEN
     51#define MAXNAMLEN MAXPATHLEN
    4852#endif
    4953
     
    168172
    169173// Return the file search path for singular w.r.t. the following steps:
    170 // 1.) SINGULARPATH Env Variable 
     174// 1.) SINGULARPATH Env Variable
    171175// 2.) bindir/LIB
    172176// 3.) bindir/LIB/VERSION
     
    175179// 6.) ROOT_DIR/Singular/LIB/
    176180// 7.) ROOT_DIR/Singular/LIB/VERSION
    177 // 8.) Go through all dirs and remove duplicates dirs resp. 
     181// 8.) Go through all dirs and remove duplicates dirs resp.
    178182//     those which do not exist
    179183static char* feGetSearchPath(const char* bindir)
    180 {   
     184{
    181185  char *env = NULL, *path, *opath;
    182186  int plength = 0, tmp;
    183  
     187
    184188#ifdef MSDOS
    185189    env=getenv("SPATH");
     
    196200      plength += 4*strlen(bindir);
    197201
    198     plength += 2*strlen(SINGULAR_ROOT_DIR) 
     202    plength += 2*strlen(SINGULAR_ROOT_DIR)
    199203      + 3*(strlen(S_VERSION1) + 1)
    200       + 24         + 36          + 12       + 6          + 7; 
     204      + 24         + 36          + 12       + 6          + 7;
    201205      // == 6*/LIB + 4*/Singular + 2*/../.. + for colons + some room to breath
    202  
     206
    203207    opath = (char*) AllocL(plength*sizeof(char));
    204208    path = opath;
    205  
     209
    206210    if (env != NULL)
    207211    {
     
    213217      *(path +1) = '\0';
    214218      printf("Got from env var: %s\n", opath);
    215 #endif     
    216     }
    217  
     219#endif
     220    }
     221
    218222    if (bindir != NULL)
    219223    {
     
    230234      path += strlen(path);
    231235    }
    232    
     236
    233237    sprintf(path, "%s/Singular/LIB%c%sSingular/LIB/%s",
    234238            SINGULAR_ROOT_DIR, FS_SEP,
     
    236240#ifdef PATH_DEBUG
    237241    printf("From rootdir: %s\n", path);
    238 #endif   
     242#endif
    239243    return CleanUpPath(opath);
    240244}
     
    266270    hlpdir[0]=hlpdir[2];
    267271    hlpdir[1]=':';
    268     mystrcpy(hlpdir+2,hlpdir+3); 
     272    mystrcpy(hlpdir+2,hlpdir+3);
    269273  }
    270274  return hlpdir;
     
    283287  printf("Search for singular.hlp\n");
    284288#endif
    285  
     289
    286290  if (bindir != NULL)
    287291  {
     
    289293#ifdef PATH_DEBUG
    290294    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    291 #endif   
     295#endif
    292296    if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    293297
     
    295299#ifdef PATH_DEBUG
    296300    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    297 #endif   
     301#endif
    298302    if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    299303
     
    301305#ifdef PATH_DEBUG
    302306    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    303 #endif   
     307#endif
    304308    if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    305309
     
    307311#ifdef PATH_DEBUG
    308312    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    309 #endif   
     313#endif
    310314    if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    311315
     
    313317#ifdef PATH_DEBUG
    314318    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    315 #endif   
     319#endif
    316320    if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    317321
     
    319323 #ifdef PATH_DEBUG
    320324    printf("trying %s -- %s\n", hlpfile, ( access(hlpfile, R_OK) ? "no" : "yes"));
    321 #endif   
     325#endif
    322326   if (! access(hlpfile, R_OK)) return feFixFileName(hlpfile);
    323327  }
     
    344348  sprintf(infoprog, "%s/%s", SINGULAR_BIN_DIR, INFOPROG);
    345349  if (! access(infoprog, X_OK)) return mstrdup(infoprog);
    346  
     350
    347351#ifdef HAVE_INFO
    348352  sprintf(infoprog, "%s", HAVE_INFO);
     
    354358}
    355359
     360#ifdef WINNT
     361// add utility function of Cygwin32:
     362extern "C" int posix_path_list_p (const char *path);
     363#endif
     364
     365void feExpandPath(char *dir)
     366{
     367  char *path=getenv("PATH");
     368  char buf[MAXNAMLEN];
     369  if (path==NULL)
     370  {
     371    strcpy(buf,dir);
     372  }
     373  else
     374  {
     375    #ifdef WINNT
     376    char path_delim = posix_path_list_p (path) ? ':' : ';';
     377    #else
     378    char path_delim=FS_SEP;
     379    #endif
     380    sprintf(buf,"%s%c%s",path,path_delim,dir);
     381  }
     382  setenv("PATH",buf,1);
     383}
    356384//
    357385// public routines
     
    360388{
    361389  feArgv0 = mstrdup(argv0);
     390  #ifdef WINNT
     391  feExtendPath(feGetBinDir()); // can only be called after setting feArgv0
     392  feExtendPath(SINGULAR_BIN_DIR);
     393  #endif
    362394}
    363395
     
    404436                                + 100);
    405437  char *infofile = feGetInfoFile();
    406  
     438
    407439  if (what != NULL && strcmp(what, "index") != 0)
    408440    sprintf(feInfoCall,
    409             "%s %s %s Index %s", 
    410             feGetInfoProgram(), 
     441            "%s %s %s Index %s",
     442            feGetInfoProgram(),
    411443            (*infofile != '\0' ? "-f" : ""),
    412             (*infofile != '\0' ? infofile : "Singular"), 
     444            (*infofile != '\0' ? infofile : "Singular"),
    413445            what);
    414446  else
    415447    sprintf(feInfoCall,
    416             "%s %s %s", 
    417             feGetInfoProgram(), 
     448            "%s %s %s",
     449            feGetInfoProgram(),
    418450            (*infofile != '\0' ? "-f" : ""),
    419451            (*infofile != '\0' ? infofile : "Singular"));
     
    421453#ifdef PATH_DEBUG
    422454  printf("Info call with: %s \n", feInfoCall);
    423 #endif 
     455#endif
    424456  return feInfoCall;
    425457}
     
    445477#ifdef PATH_DEBUG
    446478  printf("Entered CleanUpPath with: %s\n", path);
    447 #endif 
     479#endif
    448480  if (path == NULL) return path;
    449481
     
    451483  char* opath = path;
    452484  char** path_comps;
    453  
     485
    454486  for (; *path != '\0'; path++)
    455487  {
    456488    if (*path == FS_SEP) n_comps++;
    457489  }
    458  
     490
    459491
    460492  path_comps = (char**) AllocL(n_comps*sizeof(char*));
     
    462494  path=opath;
    463495  i = 1;
    464  
     496
    465497  if (i < n_comps)
    466498  {
     
    477509    }
    478510  }
    479  
     511
    480512  for (i=0; i<n_comps; i++)
    481513    path_comps[i] = CleanUpName(path_comps[i]);
     
    486518  printf("\n");
    487519#endif
    488  
     520
    489521  for (i=0; i<n_comps;)
    490522  {
     
    492524    if (access(path_comps[i], X_OK))
    493525      printf("remove %d:%s -- can not access\n", i, path_comps[i]);
    494 #endif   
     526#endif
    495527    if ( ! access(path_comps[i], X_OK))
    496528    {
     
    503535#ifdef PATH_DEBUG
    504536          printf("remove %d:%s -- equal to %d:%s\n", j, path_comps[j], i, path_comps[i]);
    505 #endif         
     537#endif
    506538          j = i+1;
    507539          break;
    508540        }
    509541      }
    510       if (j == i) 
     542      if (j == i)
    511543      {
    512544        i++;
     
    540572{
    541573  char* fn, *s;
    542  
     574
    543575  for (fn = fname; *fn != '\0'; fn++)
    544576  {
     
    10641096  int i;
    10651097  BOOLEAN done = FALSE;
    1066  
     1098
    10671099  for (i=0;;i++)
    10681100  {
     
    10711103    if (mode[i] == 'b') done = TRUE;
    10721104  }
    1073  
     1105
    10741106  if (! done)
    10751107  {
Note: See TracChangeset for help on using the changeset viewer.