Changeset 4402 for trunk/tools


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

Implemented .Def to WLINK directives/options converter.

Location:
trunk/tools
Files:
1 added
7 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}
  • trunk/tools/common/kFile.h

    r4358 r4402  
    1 /* $Id: kFile.h,v 1.5 2000-10-02 04:01:39 bird Exp $
     1/* $Id: kFile.h,v 1.6 2000-10-03 05:42:38 bird Exp $
    22 *
    33 * kFile - Simple (for the time being) file class.
     
    5454    BOOL            readAt(void *pvBuffer, long cbBuffer, long off) throw(int);
    5555    void *          readFile() throw(int);
     56    BOOL            readln(char *pszBuffer, long cchBuffer);
    5657
    5758    BOOL            write(void *pvBuffer, long cbBuffer) throw(int);
     
    6162
    6263    BOOL            setSize(unsigned long cbFile = ~0UL);
     64
     65    kFile &         operator+=(kFile &AppendFile);
    6366
    6467    /** @cat File seek methods */
  • trunk/tools/common/kFileDef.cpp

    r2759 r4402  
    1818#include <string.h>
    1919#include <stdlib.h>
    20 
     20#include <assert.h>
     21
     22#include "kFile.h"
    2123#include "kFileFormatBase.h"
    2224#include "kFileDef.h"
     
    2628*   Internal Functions                                                         *
    2729*******************************************************************************/
    28 static char *dupeString(const char *psz);
     30static char *dupeString(const char *psz, BOOL fSkipFirstWord = FALSE);
    2931static char *trim(char *psz);
     32static char *ltrim(const char *psz);
    3033static char *removeFnutts(char *pszStr);
     34inline char  upcase(char ch);
     35static char *stristr(const char *pszStr, const char *pszSubStr);
     36
    3137
    3238/**
    3339 * Duplicates a string.
    34  * @returns   Pointer to stringcopy. Remeber to delete this!
    35  * @param     psz  Pointer to string to duplicate.
    36  */
    37 static char *dupeString(const char *psz)
     40 * @returns Pointer to stringcopy. Remeber to delete this!
     41 * @param   psz             Pointer to string to duplicate.
     42 * @param   fSkipFirstWord  Skips the first word before duplicating the string.
     43 */
     44static char *dupeString(const char *psz, BOOL fSkipFirstWord/* = FALSE*/)
    3845{
    3946    char *pszDupe;
    4047    if (psz == NULL)
    4148        return NULL;
     49
     50    if (fSkipFirstWord)
     51    {
     52        while (*psz != ' ' && *psz != '\t' && *psz != '\n' && *psz != '\r' && *psz != '\0')
     53            psz++;
     54        psz = ltrim(psz);
     55    }
     56
    4257    pszDupe = new char[strlen(psz)+1];
    43     return strcpy(pszDupe, psz);
     58    strcpy(pszDupe, psz);
     59    if (fSkipFirstWord)
     60        return removeFnutts(pszDupe);
     61    return pszDupe;
    4462}
    4563
     
    5674    if (psz == NULL)
    5775        return NULL;
    58     while (*psz == ' ')
     76    while (*psz == ' ' || *psz == '\t')
    5977        psz++;
    6078    i = strlen(psz) - 1;
    61     while (i >= 0 && psz[i] == ' ')
     79    while (i >= 0 && (psz[i] == ' ' || psz[i] == '\t'))
    6280        i--;
    6381    psz[i+1] = '\0';
     
    6684
    6785
    68 kFileDef::kFileDef(FILE *phFile) throw(int)
    69     :pszType(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL),
     86/**
     87 * Trims a string, that is removing blank spaces at start and end.
     88 * @returns   Pointer to first non-blank char.
     89 * @param     psz  Pointer to string.
     90 * @result    Blank at end of string is removed. ('\0' is moved to the left.)
     91 */
     92static char *ltrim(const char *psz)
     93{
     94    if (psz == NULL)
     95        return NULL;
     96
     97    while (*psz == ' ' || *psz == '\t')
     98        psz++;
     99    return (char *)psz;
     100}
     101
     102
     103
     104kFileDef::kFileDef(kFile *pFile) throw(int)
     105    :pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL),
    70106    pszExeType(NULL), pszHeapSize(NULL), pszOld(NULL), pszProtmode(NULL), pszStackSize(NULL),
    71     pszStub(NULL), pSegments(NULL), pImports(NULL), pExports(NULL)
     107    pszStub(NULL), pSegments(NULL), pImports(NULL), pExports(NULL),
     108    fProgram(FALSE), fLibrary(FALSE), fPhysicalDevice(FALSE), fVirtualDevice(FALSE),
     109    fInitInstance(FALSE), fTermInstance(FALSE), fInitGlobal(FALSE), fTermGlobal(FALSE),
     110    chAppType(kFileDef::unknown)
    72111{
    73112    /* determin file size */
    74     if (!fseek(phFile, 0, SEEK_SET))
    75     {
    76         this->read(phFile);
     113
     114    if (pFile->start())
     115    {
     116        this->read(pFile);
    77117    }
    78118    else
     
    126166/**
    127167 * Read/parse the Definition file.
    128  * @param     phFile  Handle to file.
    129  * @remark    throws errorcode on error (TODO: errorhandling)
    130  */
    131 void kFileDef::read(FILE *phFile) throw (int)
     168 * @param   pFile   Pointer to fileobject.
     169 * @remark  throws errorcode on error (TODO: errorhandling)
     170 */
     171void kFileDef::read(kFile *pFile) throw (int)
    132172{
    133173    char *pszTmp;
     
    136176
    137177    /* readloop */
    138     psz = readln(phFile, &szBuffer[0], sizeof(szBuffer));
     178    psz = readln(pFile, &szBuffer[0], sizeof(szBuffer));
    139179    while (psz != NULL)
    140180    {
     
    146186            if (pszType != NULL) throw (0x101);
    147187            pszType = dupeString(psz);
     188            fLibrary = TRUE;
     189            if (!setModuleName())
     190                throw (0x107);
     191            fInitInstance = stristr(pszType, "INITINSTANCE") != NULL;
     192            fInitGlobal   = stristr(pszType, "INITGLOBAL")   != NULL || !fInitInstance;
     193            fTermInstance = stristr(pszType, "TERMINSTANCE") != NULL;
     194            fTermGlobal   = stristr(pszType, "TERMGLOBAL")   != NULL || !fTermInstance;
    148195        }
    149196        else if (StringCase(psz, "NAME"))
     
    151198            if (pszType != NULL) throw (0x101);
    152199            pszType = dupeString(psz);
     200            fProgram = TRUE;
     201            setModuleName();
     202            if (stristr(pszType, "WINDOWAPI"))
     203                chAppType = kFileDef::pm;
     204            else if (stristr(pszType, "NOTWINDOWCOMPAT"))
     205                chAppType = kFileDef::fullscreen;
     206            else if (stristr(pszType, "WINDOWCOMPAT"))
     207                chAppType = kFileDef::pmvio;
     208            else
     209                chAppType = kFileDef::unknown;
    153210        }
    154211        else if (StringCase(psz, "PHYSICAL DEVICE")) //gap is fixed to one space, this may be fixed in readln.
     
    156213            if (pszType != NULL) throw (0x101);
    157214            pszType = dupeString(psz);
     215            fPhysicalDevice = TRUE;
     216            setModuleName();
    158217        }
    159218        else if (StringCase(psz, "VIRTUAL DEVICE")) //gap is fixed to one space, this may be fixed in readln.
     
    161220            if (pszType != NULL) throw (0x101);
    162221            pszType = dupeString(psz);
     222            fVirtualDevice = TRUE;
     223            setModuleName();
    163224        }
    164225        else if (StringCase(psz, "BASE"))
    165             pszBase = dupeString(psz);
     226            pszBase = dupeString(psz, TRUE);
    166227        else if (StringCase(psz, "CODE"))
    167             pszCode = dupeString(psz);
     228            pszCode = dupeString(psz, TRUE);
    168229        else if (StringCase(psz, "DATA"))
    169             pszData = dupeString(psz);
     230            pszData = dupeString(psz, TRUE);
    170231        else if (StringCase(psz, "DESCRIPTION"))
    171             pszDescription = dupeString(psz);
     232            pszDescription = dupeString(psz, TRUE);
    172233        else if (StringCase(psz, "EXETYPE"))
    173             pszExeType = dupeString(psz);
     234            pszExeType = dupeString(psz, TRUE);
    174235        else if (StringCase(psz, "HEAPSIZE"))
    175             pszHeapSize = dupeString(psz);
     236            pszHeapSize = dupeString(psz, TRUE);
    176237        else if (StringCase(psz, "OLD"))
    177             pszOld = dupeString(psz);
     238            pszOld = dupeString(psz, TRUE);
    178239        else if (StringCase(psz, "PROTMODE"))
    179             pszProtmode = dupeString(psz);
     240            pszProtmode = dupeString(psz, TRUE);
    180241        else if (StringCase(psz, "STACKSIZE"))
    181             pszStackSize = dupeString(psz);
     242            pszStackSize = dupeString(psz, TRUE);
    182243        else if (StringCase(psz, "STUB"))
    183             pszStub = dupeString(psz);
     244            pszStub = dupeString(psz, TRUE);
    184245        else if (StringCase(psz, "SEGMENTS"))
    185246        {
    186247            PDEFSEGMENT *pps = &pSegments;
    187             while (!isKeyword(psz = readln(phFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
     248            while (!isKeyword(psz = readln(pFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
    188249            {
    189250                *pps = new DEFSEGMENT; memset(*pps, 0, sizeof(**pps));
     
    196257        {
    197258            PDEFIMPORT *ppi = &pImports;
    198             while (!isKeyword(psz = readln(phFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
     259            while (!isKeyword(psz = readln(pFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
    199260            {
    200261                //DOSCALL1.154 or DosQueryHeaderInfo = DOSCALL1.154
     
    229290        {
    230291            PDEFEXPORT *ppe = &pExports;
    231             while (!isKeyword(psz = readln(phFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
     292            while (!isKeyword(psz = readln(pFile, &szBuffer[0], sizeof(szBuffer))) && psz != NULL)
    232293            {
    233294                /* CloseHandle = CloseHandle@4 @1234 RESIDENTNAME 2 */
     
    312373        /* next ? */
    313374        if (fNext)
    314             psz = readln(phFile, &szBuffer[0], sizeof(szBuffer));
     375            psz = readln(pFile, &szBuffer[0], sizeof(szBuffer));
    315376    }
    316377
    317378    /* sanity check */
    318379    if (pszType == NULL)
    319         throw (0x106);
     380        throw ((int)0x106);
    320381}
    321382
     
    324385 * Reads first meaning full line from a file into a buffer.
    325386 * @returns   Pointer to buffer on success;  NULL on error.
    326  * @param     phFile     Filea handle.
     387 * @param     pFile      Pointer to fileobject to read line from.
    327388 * @param     pszBuffer  Pointer to buffer.
    328389 * @param     cbBuffer   Size of buffer.
    329390 * @remark    tabs are expanded. string is trimmed. comments removed.
    330391 */
    331 char *kFileDef::readln(FILE *phFile, char *pszBuffer, int cbBuffer) throw (int)
     392char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (int)
    332393{
    333394    int i;
     
    337398    {
    338399        /* read line */
    339         if (!fgets(pszBuffer, cbBuffer, phFile))
    340         {
    341             if (feof(phFile))
    342                 return FALSE;
    343             else
     400        if (!pFile->readln(pszBuffer, cbBuffer))
     401        {
     402            if (!pFile->isEOF())
    344403                throw (0x201);
     404            return FALSE;
    345405        }
    346406
     
    378438                memmove(pszBuffer, &pszBuffer[i], cch + 1);
    379439        }
    380     } while ((*pszBuffer == ';' || cch == 0) && !feof(phFile));
     440    } while ((*pszBuffer == ';' || cch == 0) && !pFile->isEOF());
    381441
    382442    return !(*pszBuffer == ';' || cch == 0) ? pszBuffer : NULL;
     
    416476
    417477/**
    418  * Queries the module name.
     478 * Extracts the module name from the pszType string.
    419479 * @returns   Success indicator.
    420480 * @param     pszBuffer  Pointer to string buffer which is to hold the module name upon return.
    421481 * @remark    Assumes that pszBuffer is large enough.
    422482 */
     483BOOL  kFileDef::setModuleName(void)
     484{
     485    char *pszEnd;
     486    char *pszStart;
     487
     488    assert(pszType);
     489
     490    /* skip the first word */
     491    pszStart = strpbrk(pszType, " \t");
     492    if (pszStart != NULL)
     493    {
     494        pszStart = ltrim(pszStart);
     495        pszEnd = strpbrk(pszStart, " \t");
     496        if (pszEnd == NULL)
     497            pszEnd = pszStart + strlen(pszEnd);
     498        pszModName = new char[pszEnd - pszStart + 1];
     499        memcpy(pszModName, pszStart, pszEnd - pszStart);
     500        pszModName[pszEnd - pszStart] = '\0';
     501    }
     502    else
     503        return !StringCase(pszType, "LIBRARY");
     504    return TRUE;
     505}
     506
     507
     508/**
     509 * Query for the module name.
     510 * @returns   Success indicator. TRUE / FALSE.
     511 * @param     pszBuffer  Pointer to buffer which to put the name into.
     512 */
    423513BOOL  kFileDef::queryModuleName(char *pszBuffer)
    424514{
    425     char *psz;
    426 
    427     if (pszType != NULL && StringCase(pszType, "LIBRARY"))
    428     {
    429         psz = pszType + sizeof("LIBRARY") - 1;
    430         while (*psz == ' ')
    431             psz++;
    432         while (*psz != '\0' && *psz != ' ')
    433             *pszBuffer++ = *psz++;
    434         *pszBuffer = '\0';
    435     }
    436     else
     515    if (pszModName == NULL)
    437516        return FALSE;
     517
     518    strcpy(pszBuffer, pszModName);
     519
    438520    return TRUE;
    439521}
     
    497579
    498580/**
     581 * Make a Watcom Linker parameter file addtition of this definition file.
     582 * @returns Success indicator.
     583 * @param   pFile   File which we're to write to (append).
     584 *                  Appends at current posistion.
     585 * @sketch
     586 * @status
     587 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     588 * @remark
     589 */
     590BOOL  kFileDef::makeWatcomLinkFileAddtion(kFile *pFile) throw(int)
     591{
     592    PDEFSEGMENT pSeg;
     593    PDEFIMPORT  pImp;
     594    PDEFEXPORT  pExp;
     595    pFile->setThrowOnErrors();
     596
     597    /*
     598     * Write a little remark first to tell that converted stuff starts here.
     599     */
     600    pFile->printf("#\n# Directives generated from .DEF-file.\n#\n");
     601
     602    /* Format - Module type */
     603    pFile->printf("FORMAT OS2 LX %s %s %s\n",
     604                  fLibrary                               ? "DLL" :
     605                    (fProgram ? (chAppType == pm         ? "PM"
     606                              : (chAppType == fullscreen ? "FULLSCREEN"
     607                                                         : "PMCOMPATIBLE"))
     608                    : (fVirtualDevice                    ? "VIRTDEVICE"
     609                                                         : "PHYSDEVICE" )),
     610                  fLibrary ? (fInitGlobal ? "INITGLOBAL" : "INITINSTANCE") : "",
     611                  fLibrary ? (fTermGlobal ? "TERMGLOBAL" : "TERMINSTANCE") : "");
     612
     613
     614    /* Module name */
     615    if (pszModName)
     616        pFile->printf("OPTION MODNAME=%s\n", pszModName);
     617
     618    /* Description */
     619    if (pszDescription)
     620        pFile->printf("OPTION DESCRIPTION '%s'\n", pszDescription);
     621
     622    /* Base */
     623    if (pszBase)
     624        pFile->printf("OPTION OFFSET=%s\n", pszBase);
     625
     626    /* Stub */
     627    if (pszStub)
     628        pFile->printf("OPTION STUB='%s'\n", pszStub);
     629
     630    /* Old */
     631    if (pszOld)
     632        pFile->printf("OPTION OLDLIBRARY=%s\n", pszOld);
     633
     634    /* Protected mode */
     635    if (pszProtmode)
     636        pFile->printf("OPTION PROTMODE\n", pszProtmode);
     637
     638    /* Stacksize */
     639    if (pszStackSize)
     640        pFile->printf("OPTION STACK=%s\n", pszStackSize);
     641
     642    /* HeapSize */
     643    if (pszHeapSize)
     644        pFile->printf("OPTION HEAPSIZE=%s\n", pszHeapSize);
     645
     646    /* Code  -  not supported */
     647
     648    /* Data  -  not supported */
     649
     650    /*
     651     * Segments.
     652     */
     653    pSeg = pSegments;
     654    while (pSeg != NULL)
     655    {
     656        pFile->printf("SEGMENT %s\n", pSeg->psz);
     657        pSeg = pSeg->pNext;
     658    }
     659
     660    /*
     661     * Imports.
     662     */
     663    pImp = pImports;
     664    while (pImp != NULL)
     665    {
     666        if (pImp->pszName == NULL)
     667            pFile->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal);
     668        else
     669            pFile->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName);
     670        pImp = pImp->pNext;
     671    }
     672
     673    /*
     674     * Exports.
     675     */
     676    pExp = pExports;
     677    while (pExp != NULL)
     678    {
     679        pFile->printf("EXPORT '%s'", pExp->pszName);
     680        if (pExp->ulOrdinal != ~0UL)
     681            pFile->printf(".%d", pExp->ulOrdinal);
     682        if (pExp->pszIntName)
     683            pFile->printf("='%s'", pExp->pszIntName);
     684        if (pExp->fResident)
     685            pFile->printf(" RESIDENT");
     686        if (pExp->cParam != ~0UL)
     687            pFile->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */
     688        pFile->printf("\n");
     689        pExp = pExp->pNext;
     690    }
     691
     692    return TRUE;
     693}
     694
     695
     696
     697
     698/**
    499699 * Removes '"' and ''' at start and end of the string.
    500700 * @returns     pszStr!
     
    514714    return pszStr;
    515715}
     716
     717
     718/**
     719 * Upcases a char.
     720 * @returns   Upper case of the char given in ch.
     721 * @param     ch  Char to capitalize.
     722 */
     723inline char upcase(char ch)
     724{
     725    return ch >= 'a' && ch <= 'z' ? (char)(ch - ('a' - 'A')) : ch;
     726}
     727
     728
     729/**
     730 * Searches for a substring in a string.
     731 * @returns   Pointer to start of substring when found, NULL when not found.
     732 * @param     pszStr     String to be searched.
     733 * @param     pszSubStr  String to be searched.
     734 * @remark    Depends on the upcase function.
     735 */
     736static char *stristr(const char *pszStr, const char *pszSubStr)
     737{
     738    int cchSubStr = strlen(pszSubStr);
     739    int i = 0;
     740
     741    while (*pszStr != '\0' && i < cchSubStr)
     742    {
     743        i = 0;
     744        while (i < cchSubStr && pszStr[i] != '\0' &&
     745               (upcase(pszStr[i]) == upcase(pszSubStr[i])))
     746            i++;
     747        pszStr++;
     748    }
     749
     750    return (char*)(*pszStr != '\0' ? pszStr - 1 : NULL);
     751}
     752
  • trunk/tools/common/kFileDef.h

    r824 r4402  
    5151    char               *pszIntName;
    5252    BOOL                fResident;
    53     ULONG               cParam;
     53    unsigned long       cParam;
    5454    struct _DefExport  *pNext;
    5555} DEFEXPORT, *PDEFEXPORT;
     
    6666        /**@cat pointers to different sections */
    6767        char *pszType;
     68        BOOL  fProgram;
     69        BOOL  fLibrary;
     70        BOOL  fPhysicalDevice;
     71        BOOL  fVirtualDevice;
     72        BOOL  fInitInstance;
     73        BOOL  fTermInstance;
     74        BOOL  fInitGlobal;
     75        BOOL  fTermGlobal;
     76        char *pszModName;
     77        char  chAppType;
     78
    6879        char *pszBase;
    6980        char *pszCode;
     
    8394
    8495        /**@cat internal functions */
    85         void  read(FILE *phFile) throw (int);
    86         char *readln(FILE *phFile, char *pszBuffer, int cbBuffer) throw (int);
     96        void  read(kFile *pFile) throw (int);
     97        char *readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (int);
    8798        BOOL  isKeyword(const char *psz);
     99        BOOL  setModuleName(void);
    88100
    89101    public:
    90102        /**@cat Constructor/Destructor */
    91         kFileDef(FILE *phFile) throw(int);
     103        kFileDef(kFile *pFile) throw(int);
    92104        virtual ~kFileDef();
    93105
     
    97109        BOOL        findNextExport(PEXPORTENTRY pExport);
    98110        BOOL        isDef() const                { return TRUE;}
     111        char const *queryModuleName(void) const  { return pszModName;     }
    99112        char const *queryType(void) const        { return pszType;        }
    100113        char const *queryBase(void) const        { return pszBase;        }
     
    108121        char const *queryStackSize(void) const   { return pszStackSize;   }
    109122        char const *queryStub(void) const        { return pszStub;        }
     123
     124        /**@cat Operations */
     125        BOOL        makeWatcomLinkFileAddtion(kFile *pFile) throw(int);
     126
     127        enum {fullscreen = 0, pmvio = 2, pm = 3, unknown = 255};
    110128};
    111129
  • trunk/tools/common/makefile

    r4358 r4402  
    1 # $Id: makefile,v 1.6 2000-10-02 04:01:40 bird Exp $
     1# $Id: makefile,v 1.7 2000-10-03 05:42:39 bird Exp $
    22
    33#
     
    2424
    2525
    26 needed: commonicc.lib
     26needed: commonicc.lib $(PDWIN32_TOOLS)\kDef2Wat.exe
    2727
    2828
     
    3939    @$(MAKE_CMD) OMF=1 -f makefile.gcc
    4040
    41 kDump.exe: dummy
     41
     42$(PDWIN32_TOOLS)\kDump.exe $(OBJDIR)\kDump.exe kDump.exe: dummy
    4243    -@echo $@
    43     @$(MAKE_CMD) -f makefile.icc kDump.exe
     44    @$(MAKE_CMD) -f makefile.icc $@
     45
     46
     47$(PDWIN32_TOOLS)\kDef2Wat.exe $(OBJDIR)\kDef2Wat.exe kDef2Wat.exe: dummy
     48    -@echo $@
     49    @$(MAKE_CMD) -f makefile.icc $@
    4450
    4551
  • trunk/tools/common/makefile.icc

    r4358 r4402  
    1 # $Id: makefile.icc,v 1.11 2000-10-02 04:01:40 bird Exp $
     1# $Id: makefile.icc,v 1.12 2000-10-03 05:42:40 bird Exp $
    22
    33#
     
    1010
    1111# Directory macros.
    12 PDWIN32_INCLUDE = ..\..\include
    13 PDWIN32_BIN     = ..\..\bin\$(OBJDIR)
    14 PDWIN32_LIB     = ..\..\lib
    15 PDWIN32_TOOLS   = ..\bin
    1612PDWIN32_TCOMMON = ..\common
    1713
     
    2420
    2521# Compiler, tools, and interference rules.
    26 !include $(PDWIN32_INCLUDE)\pdwin32.mk
     22!include ..\..\include\pdwin32.mk
    2723
    2824
    2925# Addjust common definitions...
    3026CFLAGS   = $(CFLAGS)   -Wall+ppt-ppc-inl-cnv-gnr-vft-
    31 CXXFLAGS = $(CXXFLAGS) -Wall+ppt-ppc-inl-cnv-gnr-vft-
     27CXXFLAGS = $(CXXFLAGS) -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gx-
    3228
    3329
     
    6157
    6258# kDump
    63 kDump.exe: $(OBJDIR)\kDump.exe
     59kDump.exe $(PDWIN32_TOOLS)\kDump.exe: $(OBJDIR)\kDump.exe
    6460    $(CP) $** $@
    6561
    6662$(OBJDIR)\kDump.exe: commonicc.lib $(OBJDIR)\kDump.obj
    6763    $(LD) $(LDFLAGS) -Fe$@ $** $(RTLLIB) OS2386.LIB
     64
     65# kDef2Wat.exe
     66kDef2Wat.exe $(PDWIN32_TOOLS)\kDef2Wat.exe: $(OBJDIR)\kDef2Wat.exe
     67    $(CP) $** $@
     68
     69$(OBJDIR)\kDef2Wat.exe: commonicc.lib $(OBJDIR)\kDef2Wat.obj
     70    $(LD) $(LDFLAGS) -Fe$@ $** $(RTLLIB) OS2386.LIB
     71
    6872
    6973
  • trunk/tools/impdef/ImpDef.cpp

    r867 r4402  
    1 /* $Id: ImpDef.cpp,v 1.3 1999-09-08 07:30:09 bird Exp $ */
     1/* $Id: ImpDef.cpp,v 1.4 2000-10-03 05:42:41 bird Exp $ */
    22/*
    33 * ImpDef - Create export file which use internal names and ordinals.
     
    1515#include <stdlib.h>
    1616#include "ImpDef.h"
     17#include "kFile.h"
    1718#include "kFileFormatBase.h"
    1819#include "kFileDef.h"
     
    7576                        options.ulOrdStartInternalFunctions = atol(&argv[argi][3]);
    7677                        if (options.ulOrdStartInternalFunctions == 0)
    77                             fprintf(stderr, "warning: internal functions starts at ordinal 0!\n");
     78                            kFile::StdErr.printf("warning: internal functions starts at ordinal 0!\n");
    7879                    }
    7980                    else
    8081                    {
    81                         fprintf(stderr, "incorrect parameter -I:<ord>. (argi=%d, argv[argi]=%s)\n", argi, argv[argi]);
     82                        kFile::StdErr.printf("incorrect parameter -I:<ord>. (argi=%d, argv[argi]=%s)\n", argi, argv[argi]);
    8283                        fFatal = TRUE;
    8384                    }
     
    9697
    9798                default:
    98                     fprintf(stderr, "incorrect parameter. (argi=%d, argv[argi]=%s)\n", argi, argv[argi]);
     99                    kFile::StdErr.printf("incorrect parameter. (argi=%d, argv[argi]=%s)\n", argi, argv[argi]);
    99100                    fFatal = TRUE;
    100101                    break;
     
    109110            else
    110111            {
    111                 fprintf(stderr, "To many files are specified!\n");
     112                kFile::StdErr.printf("To many files are specified!\n");
    112113                fFatal = TRUE;
    113114            }
     
    119120    {
    120121        fFatal = TRUE;
    121         fprintf(stderr, "Missing input file.\n");
     122        kFile::StdErr.printf("Missing input file.\n");
    122123    }
    123124    else if (pszOutput == NULL)
    124125    {
    125126        fFatal = TRUE;
    126         fprintf(stderr, "Missing output file.\n");
     127        kFile::StdErr.printf("Missing output file.\n");
    127128    }
    128129
     
    141142static void syntax(void)
    142143{
    143     printf("\n"
    144            "ImpDef - Creates internal import definition file\n"
    145            "------------------------------------------------\n"
    146            "syntax: ImpDef.exe [-h|-?] [-S] <infile> <outfile>\n"
    147            "    -h or -?      Syntax help. (this)\n"
    148            "    -F<[+]|->     Fix! Export int.name for int.functions. default: F+\n"
    149            "    -I:<ord>      Start of internal function.  default: I:%d\n"
    150            "    -O<[+]|->     Remove OS2 prefix on APIs.   default: O-\n"
    151            "    -S<[+]|->     Similar to exported name.    default: S+\n"
    152            "    infile        Name of input file\n"
    153            "    outfile       Name of output file\n"
    154            "\n"
    155            "Notes:\n"
    156            "   -S+ only works on stdcall functions (having '@' in the internal name).\n"
    157            "   -S+ takes the '_' and the '@..' parts from the internal name and adds it\n"
    158            "   to the exported name. This way the OS2 prefix is removed.\n"
    159            "   -O+ has no effect on stdcall functions when -S+ is set. -S+ has higher\n"
    160            "   precedence than -O+.\n"
    161            "   -O+ only removes the OS2 prefix from internal names.\n",
    162            ORD_START_INTERNAL_FUNCTIONS
    163            );
     144    kFile::StdOut.printf(
     145        "\n"
     146        "ImpDef - Creates internal import definition file\n"
     147        "------------------------------------------------\n"
     148        "syntax: ImpDef.exe [-h|-?] [-S] <infile> <outfile>\n"
     149        "    -h or -?      Syntax help. (this)\n"
     150        "    -F<[+]|->     Fix! Export int.name for int.functions. default: F+\n"
     151        "    -I:<ord>      Start of internal function.  default: I:%d\n"
     152        "    -O<[+]|->     Remove OS2 prefix on APIs.   default: O-\n"
     153        "    -S<[+]|->     Similar to exported name.    default: S+\n"
     154        "    infile        Name of input file\n"
     155        "    outfile       Name of output file\n"
     156        "\n"
     157        "Notes:\n"
     158        "   -S+ only works on stdcall functions (having '@' in the internal name).\n"
     159        "   -S+ takes the '_' and the '@..' parts from the internal name and adds it\n"
     160        "   to the exported name. This way the OS2 prefix is removed.\n"
     161        "   -O+ has no effect on stdcall functions when -S+ is set. -S+ has higher\n"
     162        "   precedence than -O+.\n"
     163        "   -O+ only removes the OS2 prefix from internal names.\n",
     164        ORD_START_INTERNAL_FUNCTIONS
     165        );
    164166}
    165167
     
    179181static long processFile(const char *pszInput, const char *pszOutput, const POPTIONS pOptions)
    180182{
    181     FILE *phInput;
    182     FILE *phOutput;
    183183    long lRc = 0;
    184184
    185     phInput = fopen(pszInput, "rb");
    186     if (phInput != NULL)
    187     {
     185    try
     186    {
     187        kFile Input(pszInput);
    188188        try
    189189        {
    190             kFileDef DefFile(phInput);
    191             phOutput = fopen(pszOutput, "w");
    192             if (phOutput != NULL)
     190            kFileDef DefFile(&Input);
     191            try
    193192            {
    194193                EXPORTENTRY export;
     194                kFile Output(pszOutput, FALSE);
    195195
    196196                /* generate LIBRARY line */
    197                 fputs(";Internal export definition file - autogenerated by ImpDef.", phOutput);
    198                 fputc('\n', phOutput);
    199                 fputs(DefFile.queryType(), phOutput);
    200                 fputc('\n', phOutput);
     197                Output.printf(
     198                    ";Internal export definition file - autogenerated by ImpDef.\n"
     199                    "%s\n",
     200                    DefFile.queryType());
     201
     202                /* Description line */
    201203                if (DefFile.queryDescription())
    202                 {
    203                     fputs(DefFile.queryDescription(), phOutput);
    204                     fputc('\n', phOutput);
    205                 }
     204                    Output.printf("DESCRIPTION %s\n", DefFile.queryDescription());
     205
     206                /* Exports */
    206207                if (DefFile.findFirstExport(&export))
    207208                {
    208                     fputs("EXPORTS\n", phOutput);
     209                    Output.printf("EXPORTS\n");
    209210                    do
    210211                    {
     
    215216                        if (export.achName[0] == '\0')
    216217                        {
    217                             fprintf(stderr, "Warning export name is missing.\n");
    218                             fprintf(stderr, "info:\texport.achIntName=%s\n\texport.achName=%s\n\texport.ulOrdinal=%ld\n", export.achIntName, export.achName, export.ulOrdinal);
     218                            kFile::StdErr.printf(
     219                                "Warning export name is missing.\n"
     220                                "info:\texport.achIntName=%s\n\texport.achName=%s\n\texport.ulOrdinal=%ld\n",
     221                                export.achIntName, export.achName, export.ulOrdinal);
    219222                            continue;
    220223                        }
    221224                        if (export.ulOrdinal == ~0UL)
    222225                        {
    223                             fprintf(stderr, "warning: export is missing ordinal value. Export is ignored\n");
    224                             fprintf(stderr, "info:\texport.achIntName=%s\n\texport.achName=%s\n\texport.ulOrdinal=%ld\n", export.achIntName, export.achName, export.ulOrdinal);
     226                            kFile::StdErr.printf(
     227                                "warning: export is missing ordinal value. Export is ignored\n"
     228                                "info:\texport.achIntName=%s\n\texport.achName=%s\n\texport.ulOrdinal=%ld\n",
     229                                    export.achIntName, export.achName, export.ulOrdinal);
    225230                            continue;
    226231                        }
     
    229234                        pszName = generateExportName(&export, &szName[0], pOptions);
    230235
    231                         fprintf(phOutput, "    %-*s  @%ld\n", 40, pszName, export.ulOrdinal);
     236                        Output.printf("    %-*s  @%ld\n", 40, pszName, export.ulOrdinal);
    232237                    } while (DefFile.findNextExport(&export));
    233238                }
    234                 fclose(phOutput);
    235             }
    236             else
    237             {
    238                 fprintf(stderr, "error creating output file, '%s'\n", pszOutput);
     239            }
     240            catch (int errorcode)
     241            {
     242                kFile::StdErr.printf("error creating output file, '%s', errorcode 0x%x\n", pszOutput, errorcode);
    239243                lRc = -4;
    240244            }
     
    242246        catch (int errorcode)
    243247        {
    244             fprintf(stderr, "%s is not a valid def file, errorcode 0x%x\n", pszInput, errorcode);
     248            kFile::StdErr.printf("%s is not a valid def file, errorcode 0x%x\n", pszInput, errorcode);
    245249            lRc = -3;
    246250        }
    247         fclose(phInput);
    248     }
    249     else
    250     {
    251         fprintf(stderr, "error openining inputfile, '%s'\n", pszInput);
     251    }
     252    catch (int errorcode)
     253    {
     254        kFile::StdErr.printf( "error openining inputfile, '%s', errorcode 0x%x\n", pszInput, errorcode);
    252255        lRc = -2;
    253256    }
Note: See TracChangeset for help on using the changeset viewer.