Ignore:
Timestamp:
Oct 3, 2000, 7:42:41 AM (25 years ago)
Author:
bird
Message:

Implemented .Def to WLINK directives/options converter.

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:39 bird Exp $
     1/* $Id: kFile.cpp,v 1.6 2000-10-03 05:42:38 bird Exp $
    22 *
    33 * kFile - Simple (for the time being) file class.
     
    2525#include <stdarg.h>
    2626#include <stdio.h>
     27#include <stdlib.h>
    2728
    2829#include "kFile.h"
     
    245246
    246247/**
     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 */
     259BOOL            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/**
    247298 * Writes <cbBuffer> bytes to the file at the current file position.
    248299 * @returns     success indicator. (TRUE/FALSE)
     
    352403
    353404/**
     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 */
     409kFile &         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/**
    354443 * Seek relative to the current position.
    355444 * @returns     Success indicator.
     
    468557    throw(ERROR_NOT_SUPPORTED); //this method don't currently work! Need to use flag!
    469558    #else
    470     if (!refreshFileStatus())
     559    if (!fReadOnly && !refreshFileStatus())
    471560        return (BOOL)-1;
    472561
    473     return filestatus.cbFile >= offReal; //???
     562    return filestatus.cbFile <= offVirtual; //??? - !!!
    474563    #endif
    475564}
Note: See TracChangeset for help on using the changeset viewer.