Changeset 1485 for trunk/gsdl/lib
- Timestamp:
- 2000-08-31T20:07:53+12:00 (24 years ago)
- Location:
- trunk/gsdl/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/fileutil.cpp
r1476 r1485 280 280 } 281 281 282 // returns the last line (or last 256 characters) 283 // of filename file 282 283 text_t file_tail (const text_t &filename, int numlines) { 284 if (numlines < 1) numlines = 1; 285 int numchars = 256*numlines; 286 287 text_tarray lines; 288 text_t ret; 289 290 char *filenamec = filename.getcstr(); 291 char linec[256]; 292 ifstream file_in (filenamec); 293 delete filenamec; 294 if (file_in) { 295 296 // this should be here to keep things reasonably fast 297 // when there's a long file to tail but I can't work out 298 // how to tell when it's rewound past the beginning of the file 299 // (which causes some problems) 300 301 // file_in.seekg (-numchars, ios::end); 302 303 while (!file_in.eof()) { 304 file_in.getline (linec, 256); 305 ret.setcstr(linec); 306 text_t::const_iterator here = ret.begin(); 307 text_t::const_iterator end = ret.end(); 308 // make sure line has content 309 while (here != end) { 310 if (*here != '\n' && *here != ' ') { 311 lines.push_back (ret); 312 break; 313 } 314 here ++; 315 } 316 } 317 file_in.close(); 318 } 319 320 ret.clear(); 321 int numlinesgot = lines.size(); 322 int sindex = 0; 323 if (numlinesgot > numlines) sindex = numlinesgot - numlines; 324 for (int i = sindex; i < numlinesgot; i++) { 325 ret += lines[i] + "\n"; 326 } 327 328 return ret; 329 } 330 331 // returns the last numlines lines (or last numlines*256 332 // characters) of file 333 /* 284 334 text_t file_tail (const text_t &filename) { 335 285 336 286 337 text_t return_str, tmpstr; 287 338 char *filenamec = filename.getcstr(); 288 339 char linec[256]; 289 290 340 291 341 ifstream file_in (filenamec); … … 313 363 return return_str; 314 364 } 315 365 */ 316 366 #ifdef __WIN32__ 317 367 … … 343 393 344 394 #endif 395 396 // read in file from filename and load into content 397 bool read_file (const text_t &filename, text_t &content) { 398 399 content.clear(); 400 401 char *filenamec = filename.getcstr(); 402 #ifdef GSDL_USE_IOS_H 403 ifstream file_in (filenamec, ios::in | ios::nocreate); 404 #else 405 ifstream file_in (filenamec, ios::in); 406 #endif 407 delete filenamec; 408 409 if (file_in) { 410 char c; 411 file_in.get(c); 412 while (!file_in.eof ()) { 413 content.push_back(c); 414 file_in.get(c); 415 } 416 file_in.close(); 417 } else { 418 return false; 419 } 420 return true; 421 } -
trunk/gsdl/lib/fileutil.h
r1456 r1485 53 53 bool file_copy (const text_t &fromfile, const text_t &tofile); 54 54 55 text_t file_tail (const text_t &filename );55 text_t file_tail (const text_t &filename, int numlines); 56 56 57 57 // returns true if directory created successfully 58 58 bool mk_dir (const text_t &dirname); 59 59 60 bool read_file (const text_t &filename, text_t &content); 61 60 62 #endif
Note:
See TracChangeset
for help on using the changeset viewer.