Changeset 1813 for trunk/gsdl/lib
- Timestamp:
- 2000-12-19T16:54:36+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/fileutil.cpp
r1782 r1813 212 212 // freeing this memory can cause a runtime error on some (particularly 213 213 // debug) versions of VC++ 214 delete dirpath;214 // delete dirpath; 215 215 216 216 if (hSearch == INVALID_HANDLE_VALUE) { … … 335 335 } 336 336 337 337 // This is a fairly quick and nasty attempt at doing a "tail" on 338 // a file (i.e. returning the last numlines lines of filename). 339 // It has one important limitation in that it expects lines to be 340 // 256 characters long on average. 341 // This of course makes it possible that it won't return numlines 342 // lines if there are some very long lines. 343 // It also makes it fairly inefficient as it always reads in 344 // numlines*256 characters which is much more than generally 345 // necessary. 346 // For current needs it's fine though. 338 347 text_t file_tail (const text_t &filename, int numlines) { 348 339 349 if (numlines < 1) numlines = 1; 340 intnumchars = 256*numlines;350 streampos numchars = 256*numlines; 341 351 342 352 text_tarray lines; … … 348 358 delete filenamec; 349 359 if (file_in) { 350 351 // this should be here to keep things reasonably fast 352 // when there's a long file to tail but I can't work out 353 // how to tell when it's rewound past the beginning of the file 354 // (which causes some problems) 355 356 // file_in.seekg (-numchars, ios::end); 360 file_in.seekg (0, ios::end); 361 streampos file_length = file_in.tellg(); 362 if (file_length < numchars) numchars = file_length; 363 file_in.seekg (-numchars, ios::end); 357 364 358 365 while (!file_in.eof()) { … … 384 391 } 385 392 386 // returns the last numlines lines (or last numlines*256387 // characters) of file388 /*389 text_t file_tail (const text_t &filename) {390 391 392 text_t return_str, tmpstr;393 char *filenamec = filename.getcstr();394 char linec[256];395 396 ifstream file_in (filenamec);397 delete filenamec;398 if (file_in) {399 file_in.seekg (-256, ios::end);400 file_in.getline (linec, 256, EOF);401 file_in.close();402 403 tmpstr.setcstr (linec);404 text_t::const_iterator here = tmpstr.begin();405 text_t::const_iterator end = tmpstr.end();406 while (here != end) {407 // handle trailing carriage returns408 while (*here == '\n') {409 here++;410 if (here == end) return return_str;411 else if (*here != '\n') return_str.clear();412 }413 if (*here == '\\') return_str.push_back ('\\');414 return_str.push_back (*here);415 here ++;416 }417 }418 return return_str;419 }420 */421 393 #ifdef __WIN32__ 422 394
Note:
See TracChangeset
for help on using the changeset viewer.