Changeset 1456 for trunk/gsdl/lib
- Timestamp:
- 2000-08-27T23:08:31+12:00 (24 years ago)
- Location:
- trunk/gsdl/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/fileutil.cpp
r1438 r1456 56 56 here++; 57 57 path1.erase(here,path1.end()); 58 58 59 59 // add one final slash 60 60 #ifdef __WIN32__ … … 74 74 75 75 text_t fullpath = path1 + path2; 76 76 77 77 // make sure all the right slashes are used 78 78 here = fullpath.begin(); … … 103 103 } 104 104 105 text_t filename_cat (text_t path1, text_t path2, text_t path3, text_t path4, 106 text_t path5, text_t path6) { 107 return filename_cat(filename_cat(path1,path2,path3,path4,path5),path6); 108 } 109 105 110 // returns true if filename can be opened 106 111 bool file_exists (const text_t &filename) { … … 112 117 #endif 113 118 delete cstr; 114 119 115 120 if (filestream) { 116 121 // file exists … … 118 123 return true; 119 124 } 120 125 121 126 // file does not exist 122 127 return false; … … 132 137 #endif 133 138 delete cstr; 134 139 135 140 if (filestream) { 136 141 // file exists … … 138 143 return true; 139 144 } 140 145 141 146 // file does not exist 142 147 return false; … … 156 161 hSearch = FindFirstFile(dirpath, &FileData); 157 162 delete dirpath; 158 163 159 164 if (hSearch == INVALID_HANDLE_VALUE) { 160 165 return false; … … 172 177 hSearch = FindFirstFile(dirpath, &FileData); 173 178 delete dirpath; 174 179 175 180 if (hSearch == INVALID_HANDLE_VALUE) { 176 181 return false; … … 198 203 199 204 bool directory_exists (const text_t &dirname) { 200 205 201 206 char *tmp = dirname.getcstr(); 202 207 DIR *dirin = opendir (tmp); … … 209 214 210 215 bool read_dir (const text_t &dirname, text_tarray &filelist) { 211 216 212 217 filelist.erase (filelist.begin(), filelist.end()); 213 218 … … 219 224 220 225 dirent *dirp; 221 226 222 227 text_t filename; 223 228 while ((dirp = readdir (dirin)) != NULL) { … … 234 239 235 240 // I'm sure there's a better way to do this - for now I don't have 236 // time to find it though. -- This will probably break compiling 237 // under windows ports of gcc 238 void file_copy (const text_t &fromfile, const text_t &tofile) { 239 240 #ifdef __WIN32__ 241 // time to find it though 242 // returns true if things look like they happened ok 243 bool file_copy (const text_t &fromfile, const text_t &tofile) { 244 241 245 char *fromfilec = fromfile.getcstr(); 242 246 char *tofilec = tofile.getcstr(); 243 CopyFile (fromfilec, tofilec, FALSE); 247 bool fail = false; 248 ifstream from (fromfilec); 249 if (!from) { 250 fail = true; 251 } else { 252 ofstream to (tofilec); 253 if (!to) { 254 fail = true; 255 from.close(); 256 } else { 257 char c; 258 from.get(c); 259 while (!from.eof ()) { 260 to.put(c); 261 from.get(c); 262 } 263 from.close(); 264 to.close(); 265 } 266 } 244 267 delete fromfilec; 245 268 delete tofilec; 246 247 #else 248 text_t cp_cmd = "cp " + fromfile + " " + tofile; 249 char *cp_cmdc = cp_cmd.getcstr(); 250 system (cp_cmdc); 251 delete cp_cmdc; 252 253 #endif 254 } 269 if (fail) return false; 270 return true; 271 } 272 273 /* 274 275 #ifdef __WIN32__ 276 char *fromfilec = fromfile.getcstr(); 277 char *tofilec = tofile.getcstr(); 278 CopyFile (fromfilec, tofilec, FALSE); 279 delete fromfilec; 280 delete tofilec; 281 282 #else 283 text_t cp_cmd = "cp " + fromfile + " " + tofile; 284 char *cp_cmdc = cp_cmd.getcstr(); 285 system (cp_cmdc); 286 delete cp_cmdc; 287 288 #endif 289 */ 255 290 256 291 // returns the last line (or last 256 characters) … … 258 293 text_t file_tail (const text_t &filename) { 259 294 260 text_t return_str ;295 text_t return_str, tmpstr; 261 296 char *filenamec = filename.getcstr(); 297 char linec[256]; 298 262 299 263 300 ifstream file_in (filenamec); 301 delete filenamec; 264 302 if (file_in) { 265 303 file_in.seekg (-256, ios::end); 266 char c; 267 file_in.get(c); 268 while (!file_in.eof()) { 269 if (c == '\n') { 270 file_in.get(c); 271 if (!file_in.eof()) { 272 return_str.clear(); 273 if (c == '\\') return_str.push_back ('\\'); 274 return_str.push_back (c); 275 } 276 } else { 277 if (c == '\\') return_str.push_back ('\\'); 278 return_str.push_back (c); 279 } 280 file_in.get(c); 304 file_in.getline (linec, 256, EOF); 305 file_in.close(); 306 307 tmpstr.setcstr (linec); 308 text_t::const_iterator here = tmpstr.begin(); 309 text_t::const_iterator end = tmpstr.end(); 310 while (here != end) { 311 // handle trailing carriage returns 312 while (*here == '\n') { 313 here++; 314 if (here == end) return return_str; 315 else if (*here != '\n') return_str.clear(); 316 } 317 if (*here == '\\') return_str.push_back ('\\'); 318 return_str.push_back (*here); 319 here ++; 281 320 } 282 file_in.close(); 283 284 } 285 delete filenamec; 321 } 286 322 return return_str; 287 323 } 324 325 // probably need windows version of this 326 #include <sys/stat.h> 327 #include <sys/types.h> 328 #include <fcntl.h> 329 #include <unistd.h> 330 331 // returns true if directory was created successfully 332 bool mk_dir (const text_t &dirname) { 333 mode_t mode = 0777; 334 char *dirnamec = dirname.getcstr(); 335 int rv = mkdir (dirnamec, mode); 336 delete dirnamec; 337 if (rv == 0) return true; 338 return false; 339 } 340 -
trunk/gsdl/lib/fileutil.h
r1437 r1456 37 37 text_t filename_cat (text_t path1, text_t path2, text_t path3, text_t path4, 38 38 text_t path5); 39 text_t filename_cat (text_t path1, text_t path2, text_t path3, text_t path4, 40 text_t path5, text_t path6); 39 41 40 42 // returns true if filename can be opened … … 49 51 bool read_dir (const text_t &dirname, text_tarray &filelist); 50 52 51 voidfile_copy (const text_t &fromfile, const text_t &tofile);53 bool file_copy (const text_t &fromfile, const text_t &tofile); 52 54 53 55 text_t file_tail (const text_t &filename); 54 56 57 // returns true if directory created successfully 58 bool mk_dir (const text_t &dirname); 59 55 60 #endif -
trunk/gsdl/lib/gsdltools.cpp
r1310 r1456 84 84 } 85 85 86 #else 87 void gsdl_system (char *cmd, ostream &logout) { 88 89 if (cmd == NULL) return; 90 int pid = fork(); 91 if (pid == -1) return; 92 if (pid == 0) { 93 // child process 94 char *argv[4]; 95 argv[0] = "sh"; 96 argv[1] = "-c"; 97 argv[2] = cmd; 98 argv[3] = 0; 99 execv("/bin/sh", argv); 100 // exit(127); 101 } 102 } 103 86 104 #endif -
trunk/gsdl/lib/gsdltools.h
r1310 r1456 50 50 // system call and putting the spawned process in the background 51 51 // (e.g. system (funcname options &); 52 #if defined (__WIN32__)52 //#if defined (__WIN32__) 53 53 void gsdl_system (char *cmd, ostream &logout); 54 #endif54 //#endif 55 55 56 56 #endif
Note:
See TracChangeset
for help on using the changeset viewer.