Ignore:
Timestamp:
2008-08-19T14:13:44+12:00 (16 years ago)
Author:
davidb
Message:

Runtime code can now support GDBM database being provided as a gzipped txt file, which is platform independant. If the required .ldb (or .bdb) isn't there than the runtime system executes txt2db to generate it. The rest of the code then works as before

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/common-src/src/lib/gsdltools.cpp

    r9593 r16895  
    2525
    2626#include "gsdltools.h"
     27#include "fileutil.h"
    2728
    2829#if defined(__WIN32__)
     
    3031#include <process.h>
    3132#endif
     33
     34#if !defined (__WIN32__)
     35#include <sys/utsname.h>
     36#include <unistd.h>
     37#endif
     38
    3239
    3340bool littleEndian() {
     
    160167}
    161168
     169
     170static bool gsdl_setenv_done = false;
     171
     172bool set_gsdl_env_vars (const text_t& gsdlhome)
     173{
     174  if (gsdl_setenv_done) { return true; }
     175
     176  // set up GSDLOS, GSDLHOME and PATH environment variables
     177
     178  text_t gsdlos, path;
     179  unsigned int path_separator = ':';
     180
     181#if defined (__WIN32__)
     182  gsdlos = "windows";
     183  path_separator = ';';
     184
     185  path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;");
     186
     187#else
     188  struct utsname *buf = new struct utsname();
     189  int i = uname (buf);
     190  if (i == -1) gsdlos = "linux"; // uname failed, default to linux
     191  else gsdlos.setcstr (buf->sysname);
     192  delete buf;
     193  lc (gsdlos);
     194#endif
     195
     196  // according to getenv documentation (after a bit of digging), *getenv*
     197  // is responsible for the char* pointer returned, so no need for us
     198  // to free it (in fact that would be a mistake!)
     199
     200  char* orig_pathc = getenv ("PATH");
     201  path += filename_cat (gsdlhome, "bin", gsdlos);
     202  path.push_back (path_separator);
     203  path += filename_cat (gsdlhome, "bin", "script");
     204  if (orig_pathc != NULL) {
     205    path.push_back (path_separator);
     206    path += orig_pathc;
     207  } 
     208
     209  // these will be cleaned up in the destructor
     210  char* gsdlosc = gsdlos.getcstr();
     211  char* gsdlhomec = gsdlhome.getcstr();
     212  char* pathc = path.getcstr();
     213 
     214  if ((setenv("GSDLOS",gsdlosc,1)!=0)
     215      || (setenv("GSDLHOME",gsdlhomec,1)!=0)
     216      || (setenv("PATH",pathc,1)!=0))
     217    {
     218      perror("Setting Greenstone environment variables");
     219      return false;
     220    }
     221
     222  delete [] gsdlosc;
     223  delete [] gsdlhomec;
     224  delete [] pathc;
     225
     226  gsdl_setenv_done = true;
     227
     228  return true;
     229}
     230
     231
     232
    162233// attempts to work out if perl is functional
    163234bool perl_ok (ostream &logout) {
Note: See TracChangeset for help on using the changeset viewer.