Changeset 16895 for gsdl/trunk/common-src
- Timestamp:
- 2008-08-19T14:13:44+12:00 (16 years ago)
- Location:
- gsdl/trunk/common-src/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/common-src/src/lib/gdbmclass.cpp
r15679 r16895 27 27 #include "gsdltools.h" 28 28 #include "gsdlunicode.h" 29 #include "fileutil.h" 30 31 29 32 30 33 … … 44 47 ) 45 48 { 49 46 50 text_t data_location; 47 51 int block_size = 512; … … 63 67 { 64 68 gdbm_mode = GDBM_WRCREAT; 69 } 70 71 if (gdbm_mode == GDBM_READER) { 72 // Looking to read in the database 73 // => check to see if .ldb/.bdb file already there 74 // if not (first time) then generate using txt2db 75 if (!file_exists(filename)) { 76 77 // need to generate architecture native GDBM file using txt2db 78 79 // replace sought after gdbm filename ext with ".txt.gz" 80 81 text_t::const_iterator begin = filename.begin(); 82 text_t::const_iterator end= filename.end(); 83 text_t::const_iterator here = end; 84 85 bool found_ext = false; 86 87 while (here != begin) { 88 if (*here == '.') { 89 found_ext = true; 90 break; 91 } 92 here--; 93 } 94 95 text_t filename_root; 96 97 if (found_ext) { 98 filename_root = substr(begin,here); 99 } 100 else { 101 filename_root = filename; 102 } 103 104 text_t txtgz_filename = filename_root + ".txt.gz"; 105 106 text_t cmd = "gzip --decompress --to-stdout \"" + txtgz_filename + "\""; 107 cmd += " | txt2db \"" + filename + "\""; 108 109 int rv = gsdl_system(cmd, true, cerr); 110 if (rv != 0) { 111 cerr << "Tried to run command \""<<cmd<<"\", but it failed\n"; 112 } 113 } 65 114 } 66 115 -
gsdl/trunk/common-src/src/lib/gsdltools.cpp
r9593 r16895 25 25 26 26 #include "gsdltools.h" 27 #include "fileutil.h" 27 28 28 29 #if defined(__WIN32__) … … 30 31 #include <process.h> 31 32 #endif 33 34 #if !defined (__WIN32__) 35 #include <sys/utsname.h> 36 #include <unistd.h> 37 #endif 38 32 39 33 40 bool littleEndian() { … … 160 167 } 161 168 169 170 static bool gsdl_setenv_done = false; 171 172 bool 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 162 233 // attempts to work out if perl is functional 163 234 bool perl_ok (ostream &logout) { -
gsdl/trunk/common-src/src/lib/gsdltools.h
r8727 r16895 65 65 int gsdl_system (const text_t &cmd, bool sync, ostream &logout); 66 66 67 bool set_gsdl_env_vars (const text_t& gsdlhome) ; 68 67 69 // attempts to work out if perl is functional 68 70 bool perl_ok (ostream &logout);
Note:
See TracChangeset
for help on using the changeset viewer.