Changeset 1837 for trunk/gsdl/lib
- Timestamp:
- 2001-01-15T15:21:43+13:00 (23 years ago)
- Location:
- trunk/gsdl/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/fileutil.cpp
r1815 r1837 337 337 } 338 338 339 // This is a fairly quick and nasty attempt at doing a "tail" on 340 // a file (i.e. returning the last numlines lines of filename). 341 // It has one important limitation in that it expects lines to be 342 // 256 characters long on average. 343 // This of course makes it possible that it won't return numlines 344 // lines if there are some very long lines. 345 // It also makes it fairly inefficient as it always reads in 346 // numlines*256 characters which is much more than generally 347 // necessary. 339 // This is a fairly quick and nasty attempt at doing a "tail" on a file 340 // (i.e. returning the last numlines lines of filename). It has one 341 // important limitation in that it expects lines to be linelength 342 // characters long on average. This of course makes it possible that it 343 // won't return numlines lines if there are some lines that are longer than 344 // linelength. It also makes it fairly inefficient as it always reads in 345 // numlines*linelength characters when it most often doesn't need them all. 348 346 // For current needs it's fine though. 349 text_t file_tail (const text_t &filename, int numlines) { 347 // -- Pass a linelength of 0 to use the default linelength (256 chars). 348 text_t file_tail (const text_t &filename, int numlines, int linelength) { 350 349 351 350 if (numlines < 1) numlines = 1; 352 streampos numchars = 256*numlines; 351 if (linelength == 0) linelength = 256; 352 353 streampos numchars = linelength*numlines; 353 354 354 355 text_tarray lines; … … 356 357 357 358 char *filenamec = filename.getcstr(); 358 char linec[ 256];359 char linec[linelength]; 359 360 ifstream file_in (filenamec); 360 361 delete filenamec; … … 366 367 367 368 while (!file_in.eof()) { 368 file_in.getline (linec, 256);369 file_in.getline (linec, linelength); 369 370 ret.setcstr(linec); 370 371 text_t::const_iterator here = ret.begin(); -
trunk/gsdl/lib/fileutil.h
r1739 r1837 56 56 bool file_copy (const text_t &fromfile, const text_t &tofile); 57 57 58 text_t file_tail (const text_t &filename, int numlines );58 text_t file_tail (const text_t &filename, int numlines, int linelength); 59 59 60 60 // returns true if directory created successfully
Note:
See TracChangeset
for help on using the changeset viewer.