Ignore:
Timestamp:
Feb 24, 2002, 3:47:28 AM (24 years ago)
Author:
bird
Message:

New kFile* classes; now in sync with os2tools.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/common/kFileDef.cpp

    r5531 r8003  
    1 /*
     1/* $Id: kFileDef.cpp,v 1.8 2002-02-24 02:47:25 bird Exp $
     2 *
    23 * kFileDef - Definition files.
    34 *
    4  * Copyright (c) 1999 knut st. osmundsen
     5 * Copyright (c) 1999-2001 knut st. osmundsen
    56 *
    67 */
     
    2122*   Header Files                                                               *
    2223*******************************************************************************/
    23 #include <os2.h>
    2424#include <stdio.h>
    2525#include <string.h>
    2626#include <stdlib.h>
    27 #include <assert.h>
    28 
     27
     28#include "kTypes.h"
     29#include "kError.h"
    2930#include "kFile.h"
    3031#include "kFileFormatBase.h"
    31 #include "kInterfaces.h"
     32#include "kFileInterfaces.h"
    3233#include "kFileDef.h"
     34
    3335
    3436/*******************************************************************************
     
    4345*   Internal Functions                                                         *
    4446*******************************************************************************/
    45 static char *dupeString(const char *psz, BOOL fSkipFirstWord = FALSE);
     47static char *dupeString(const char *psz, KBOOL fSkipFirstWord = FALSE);
    4648static char *trim(char *psz);
    4749static char *ltrim(const char *psz);
     
    5759 * @param   fSkipFirstWord  Skips the first word before duplicating the string.
    5860 */
    59 static char *dupeString(const char *psz, BOOL fSkipFirstWord/* = FALSE*/)
     61static char *dupeString(const char *psz, KBOOL fSkipFirstWord/* = FALSE*/)
    6062{
    6163    char *pszDupe;
     
    117119
    118120
    119 kFileDef::kFileDef(kFile *pFile) throw(int)
    120     :pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL),
     121kFileDef::kFileDef(kFile *pFile) :
     122    kFileFormatBase(pFile),
     123    pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL),
    121124    pszExeType(NULL), pszHeapSize(NULL), pszOld(NULL), pszProtmode(NULL), pszStackSize(NULL),
    122125    pszStub(NULL), pSegments(NULL), pImports(NULL), pExports(NULL),
     
    125128    chAppType(kFileDef::unknown)
    126129{
    127     /* determin file size */
    128 
    129     if (pFile->start())
    130     {
    131         try
    132         {
    133             this->read(pFile);
    134         }
    135         catch (int err)
    136         {
    137             throw (err);
    138         }
    139     }
    140     else
    141         throw (0x001);
    142 }
     130    pFile->setThrowOnErrors();
     131    pFile->start();
     132    read(pFile);
     133        }
    143134
    144135
     
    191182 * @remark  throws errorcode on error (TODO: errorhandling)
    192183 */
    193 void kFileDef::read(kFile *pFile) throw (int)
     184void kFileDef::read(kFile *pFile)
    194185{
    195186    char *pszTmp;
     
    201192    while (psz != NULL)
    202193    {
    203         BOOL fNext = TRUE;
     194        KBOOL  fNext = TRUE;
    204195
    205196        /* if-switch */
    206197        if (StringCase(psz, "LIBRARY"))
    207198        {
    208             if (pszType != NULL) throw (0x101);
     199            if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT));
    209200            pszType = dupeString(psz);
    210201            fLibrary = TRUE;
    211202            if (!setModuleName())
    212                 throw (0x107);
     203                throw (kError(kError::DEF_BAD_LIBRARY_STATEMENT));
    213204            fInitInstance = stristr(pszType, "INITINSTANCE") != NULL;
    214205            fInitGlobal   = stristr(pszType, "INITGLOBAL")   != NULL || !fInitInstance;
     
    218209        else if (StringCase(psz, "NAME"))
    219210        {
    220             if (pszType != NULL) throw (0x101);
     211            if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT));
    221212            pszType = dupeString(psz);
    222213            fProgram = TRUE;
     
    233224        else if (StringCase(psz, "PHYSICAL DEVICE")) //gap is fixed to one space, this may be fixed in readln.
    234225        {
    235             if (pszType != NULL) throw (0x101);
     226            if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT));
    236227            pszType = dupeString(psz);
    237228            fPhysicalDevice = TRUE;
     
    240231        else if (StringCase(psz, "VIRTUAL DEVICE")) //gap is fixed to one space, this may be fixed in readln.
    241232        {
    242             if (pszType != NULL) throw (0x101);
     233            if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT));
    243234            pszType = dupeString(psz);
    244235            fVirtualDevice = TRUE;
     
    301292                {
    302293                    (**ppi).ulOrdinal = strtol(psz, &pszTmp, 0);
    303                     if (psz ==pszTmp) throw(0x102);
     294                    if (psz ==pszTmp) throw (kError(kError::DEF_BAD_IMPORT));
    304295                }
    305296                else
     
    355346                        psz = pszTmp + 1;
    356347                        (**ppe).ulOrdinal = strtol(psz, &pszTmp, 0);
    357                         if (pszTmp == psz) throw (0x103);
     348                        if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT));
    358349                        psz = trim(pszTmp);
    359350
     
    380371                    {   /* 2 */
    381372                        (**ppe).cParam = strtol(psz, &pszTmp, 0);
    382                         if (pszTmp == psz) throw (0x104);
     373                        if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT));
    383374                    }
    384375                }
     
    391382        }
    392383        else
    393             throw(0x105);
     384            throw (kError(kError::DEF_UNKOWN_VERB));
    394385
    395386        /* next ? */
     
    400391    /* sanity check */
    401392    if (pszType == NULL)
    402         throw ((int)0x106);
     393        throw (kError(kError::DEF_NO_MODULE_STATEMENT));
    403394}
    404395
     
    412403 * @remark    tabs are expanded. string is trimmed. comments removed.
    413404 */
    414 char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (int)
     405char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer)
    415406{
    416407    int i;
     
    420411    {
    421412        /* read line */
    422         if (!pFile->readln(pszBuffer, cbBuffer))
     413        if (pFile->readln(pszBuffer, cbBuffer))
    423414        {
    424415            if (!pFile->isEOF())
    425                 throw (0x201);
    426             return FALSE;
     416                throw (kError(pFile->getLastError()));
     417            return NULL;
    427418        }
    428419
     
    472463 * @remark    TODO - we are going to check WORDS.
    473464 */
    474 BOOL kFileDef::isKeyword(const char *psz)
     465KBOOL kFileDef::isKeyword(const char *psz)
    475466{
    476467    return  psz != NULL
     
    503494 * @remark    Assumes that pszBuffer is large enough.
    504495 */
    505 BOOL  kFileDef::setModuleName(void)
     496KBOOL  kFileDef::setModuleName(void)
    506497{
    507498    char *pszEnd;
    508499    char *pszStart;
    509500
    510     assert(pszType);
     501    kASSERT(pszType);
    511502
    512503    /* skip the first word */
     
    534525 * @param   cchBuffer   Size of the buffer (defaults to 260 chars).
    535526 */
    536 BOOL  kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)
     527KBOOL  kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)
    537528{
    538529    int cch;
     
    554545 * @param     pExport  Pointer to export structure.
    555546 */
    556 BOOL kFileDef::exportFindFirst(kExportEntry *pExport)
     547KBOOL kFileDef::exportFindFirst(kExportEntry *pExport)
    557548{
    558549    if (pExports != NULL && pExport != NULL)
     
    581572 * @param     pExport  Pointer to export structure.
    582573 */
    583 BOOL kFileDef::exportFindNext(kExportEntry *pExport)
     574KBOOL kFileDef::exportFindNext(kExportEntry *pExport)
    584575{
    585576    if (pExport != NULL && pExport->pv != NULL)
     
    624615 * @remark  stub
    625616 */
    626 BOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)
    627 {
    628     assert(!"not implemented.");
     617KBOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)
     618{
     619    kASSERT(!"not implemented.");
    629620    ulOrdinal = ulOrdinal;
    630621    pExport = pExport;
     
    639630 * @remark  stub
    640631 */
    641 BOOL kFileDef::exportLookup(const char *  pszName, kExportEntry *pExport)
    642 {
    643     assert(!"not implemented.");
     632KBOOL kFileDef::exportLookup(const char *  pszName, kExportEntry *pExport)
     633{
     634    kASSERT(!"not implemented.");
    644635    pszName = pszName;
    645636    pExport = pExport;
     
    658649 * @remark
    659650 */
    660 BOOL  kFileDef::makeWatcomLinkFileAddtion(kFile *pFile) throw(int)
     651KBOOL kFileDef::makeWatcomLinkFileAddtion(kFile *pOut)
    661652{
    662653    PDEFSEGMENT pSeg;
    663654    PDEFIMPORT  pImp;
    664655    PDEFEXPORT  pExp;
    665     pFile->setThrowOnErrors();
     656    pOut->setThrowOnErrors();
    666657
    667658    /*
    668659     * Write a little remark first to tell that converted stuff starts here.
    669660     */
    670     pFile->printf("#\n# Directives generated from .DEF-file.\n#\n");
     661    pOut->printf("#\n# Directives generated from .DEF-file.\n#\n");
    671662
    672663    /* Format - Module type */
    673     pFile->printf("FORMAT OS2 LX %s %s %s\n",
     664    pOut->printf("FORMAT OS2 LX %s %s %s\n",
    674665                  fLibrary                               ? "DLL" :
    675666                    (fProgram ? (chAppType == pm         ? "PM"
     
    684675    /* Module name */
    685676    if (pszModName)
    686         pFile->printf("OPTION MODNAME=%s\n", pszModName);
     677        pOut->printf("OPTION MODNAME=%s\n", pszModName);
    687678
    688679    /* Description */
    689680    if (pszDescription)
    690         pFile->printf("OPTION DESCRIPTION '%s'\n", pszDescription);
     681        pOut->printf("OPTION DESCRIPTION '%s'\n", pszDescription);
    691682
    692683    /* Base */
    693684    if (pszBase)
    694         pFile->printf("OPTION OFFSET=%s\n", pszBase);
     685        pOut->printf("OPTION OFFSET=%s\n", pszBase);
    695686
    696687    /* Stub */
    697688    if (pszStub)
    698         pFile->printf("OPTION STUB='%s'\n", pszStub);
     689        pOut->printf("OPTION STUB='%s'\n", pszStub);
    699690
    700691    /* Old */
    701692    if (pszOld)
    702         pFile->printf("OPTION OLDLIBRARY=%s\n", pszOld);
     693        pOut->printf("OPTION OLDLIBRARY=%s\n", pszOld);
    703694
    704695    /* Protected mode */
    705696    if (pszProtmode)
    706         pFile->printf("OPTION PROTMODE\n", pszProtmode);
     697        pOut->printf("OPTION PROTMODE\n", pszProtmode);
    707698
    708699    /* Stacksize */
    709700    if (pszStackSize)
    710         pFile->printf("OPTION STACK=%s\n", pszStackSize);
     701        pOut->printf("OPTION STACK=%s\n", pszStackSize);
    711702
    712703    /* HeapSize */
    713704    if (pszHeapSize)
    714         pFile->printf("OPTION HEAPSIZE=%s\n", pszHeapSize);
     705        pOut->printf("OPTION HEAPSIZE=%s\n", pszHeapSize);
    715706
    716707    /* Code  -  not supported */
     
    724715    while (pSeg != NULL)
    725716    {
    726         pFile->printf("SEGMENT %s\n", pSeg->psz);
     717        pOut->printf("SEGMENT %s\n", pSeg->psz);
    727718        pSeg = pSeg->pNext;
    728719    }
     
    735726    {
    736727        if (pImp->pszName == NULL)
    737             pFile->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal);
     728            pOut->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal);
    738729        else
    739             pFile->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName);
     730            pOut->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName);
    740731        pImp = pImp->pNext;
    741732    }
     
    747738    while (pExp != NULL)
    748739    {
    749         pFile->printf("EXPORT '%s'", pExp->pszName);
     740        pOut->printf("EXPORT '%s'", pExp->pszName);
    750741        if (pExp->ulOrdinal != ~0UL)
    751             pFile->printf(".%d", pExp->ulOrdinal);
     742            pOut->printf(".%d", pExp->ulOrdinal);
    752743        if (pExp->pszIntName)
    753             pFile->printf("='%s'", pExp->pszIntName);
     744            pOut->printf("='%s'", pExp->pszIntName);
    754745        if (pExp->fResident)
    755             pFile->printf(" RESIDENT");
     746            pOut->printf(" RESIDENT");
    756747        if (pExp->cParam != ~0UL)
    757             pFile->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */
    758         pFile->printf("\n");
     748            pOut->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */
     749        pOut->printf("\n");
    759750        pExp = pExp->pNext;
    760751    }
Note: See TracChangeset for help on using the changeset viewer.