Changeset 4402 for trunk/tools/common/kFile.cpp
- Timestamp:
- Oct 3, 2000, 7:42:41 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.cpp
r4358 r4402 1 /* $Id: kFile.cpp,v 1. 5 2000-10-02 04:01:39bird Exp $1 /* $Id: kFile.cpp,v 1.6 2000-10-03 05:42:38 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 25 25 #include <stdarg.h> 26 26 #include <stdio.h> 27 #include <stdlib.h> 27 28 28 29 #include "kFile.h" … … 245 246 246 247 /** 248 * Reads a single line from the file into the given buffer. 249 * Newline is stripped! 250 * @returns Success indicator. 251 * @param pszBuffer Pointer to string buffer. 252 * Will hold a zero-string upon successful return. 253 * @param cchBuffer Buffer size. 254 * @sketch 255 * @status partially implemented. 256 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 257 * @remark Should implemented buffered read ASAP! 258 */ 259 BOOL kFile::readln(char *pszBuffer, long cchBuffer) throw (int) 260 { 261 char *psz; 262 long cbRead = min(max((long)filestatus.cbFile - (long)offVirtual, 0), cchBuffer-1); 263 264 /* 265 * Read full buffer length or remining part of file into the buffer. 266 * Look for line end. 267 * Found lineend: cut buffer there and rewind file back to that point (but skipping the newline). 268 */ 269 if (cbRead == 0 || !read(pszBuffer, cbRead) ) 270 return FALSE; 271 272 pszBuffer[cbRead] = '\0'; 273 274 psz = strpbrk(pszBuffer, "\r\n"); 275 if (psz != NULL) 276 { 277 cbRead -= psz - pszBuffer; 278 if (*psz == '\r') 279 { 280 if (psz[1] == '\n') 281 cbRead -= 2; 282 else 283 cbRead--; 284 } 285 else if (*psz == '\n') 286 cbRead--; 287 288 *psz = '\0'; 289 290 return move(-cbRead); 291 } 292 293 return TRUE; 294 } 295 296 297 /** 247 298 * Writes <cbBuffer> bytes to the file at the current file position. 248 299 * @returns success indicator. (TRUE/FALSE) … … 352 403 353 404 /** 405 * Appends the AppendFile to this file. 406 * @returns Reference to this file. 407 * @param AppendFile Reference to the file we're to append. 408 */ 409 kFile & kFile::operator+=(kFile &AppendFile) 410 { 411 long cb; 412 char * pachBuffer = new char[1024*256]; 413 long pos = AppendFile.getPos(); 414 BOOL fAppend = AppendFile.fThrowErrors; 415 BOOL fThis = fThrowErrors; 416 417 setThrowOnErrors(); 418 AppendFile.setThrowOnErrors(); 419 420 end(); 421 AppendFile.start(); 422 AppendFile.refreshFileStatus(); 423 424 cb = min(1024*256, AppendFile.filestatus.cbFile); 425 while (cb > 0) 426 { 427 AppendFile.read(pachBuffer, cb); 428 write(pachBuffer, cb); 429 cb = min(1024*256, (long)AppendFile.filestatus.cbFile - (long)AppendFile.offVirtual); 430 } 431 432 delete pachBuffer; 433 AppendFile.set(pos); 434 AppendFile.fThrowErrors = fAppend; 435 fThrowErrors = fThis; 436 437 return *this; 438 } 439 440 441 442 /** 354 443 * Seek relative to the current position. 355 444 * @returns Success indicator. … … 468 557 throw(ERROR_NOT_SUPPORTED); //this method don't currently work! Need to use flag! 469 558 #else 470 if (! refreshFileStatus())559 if (!fReadOnly && !refreshFileStatus()) 471 560 return (BOOL)-1; 472 561 473 return filestatus.cbFile >= offReal; //???562 return filestatus.cbFile <= offVirtual; //??? - !!! 474 563 #endif 475 564 }
Note:
See TracChangeset
for help on using the changeset viewer.