Ignore:
Timestamp:
Sep 8, 1999, 9:30:10 AM (26 years ago)
Author:
bird
Message:

New options. Will now handle 'internal' functions correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/impdef/ImpDef.cpp

    r842 r867  
    1 /* $Id: ImpDef.cpp,v 1.2 1999-09-05 22:10:26 bird Exp $ */
     1/* $Id: ImpDef.cpp,v 1.3 1999-09-08 07:30:09 bird Exp $ */
    22/*
    33 * ImpDef - Create export file which use internal names and ordinals.
     
    1313#include <stdio.h>
    1414#include <string.h>
     15#include <stdlib.h>
    1516#include "ImpDef.h"
    1617#include "kFileFormatBase.h"
     
    3940    char   *pszInput = NULL;
    4041    char   *pszOutput = NULL;
    41     OPTIONS options = {TRUE, FALSE};
     42    OPTIONS options = {TRUE, ORD_START_INTERNAL_FUNCTIONS, FALSE, TRUE};
    4243
    4344    /**************************************************************************
     
    4647    *           -S<[+]|->    Similar to exported. (stdcall)
    4748    *           -O<[+]|->    Remove OS2 prefix on APIs.
     49    *           -I:<num>     Start ordinal number of internal functions.
     50    *           -F<[+]|->    Export intname for internal stdcall functions.
    4851    **************************************************************************/
    4952    if (argc == 1)
     
    6467                case 'O':
    6568                    options.fRemoveOS2APIPrefix = argv[argi][2] != '-';
     69                    break;
     70
     71                case 'i':
     72                case 'I':
     73                    if (strlen(argv[argi]) >= 3)
     74                    {
     75                        options.ulOrdStartInternalFunctions = atol(&argv[argi][3]);
     76                        if (options.ulOrdStartInternalFunctions == 0)
     77                            fprintf(stderr, "warning: internal functions starts at ordinal 0!\n");
     78                    }
     79                    else
     80                    {
     81                        fprintf(stderr, "incorrect parameter -I:<ord>. (argi=%d, argv[argi]=%s)\n", argi, argv[argi]);
     82                        fFatal = TRUE;
     83                    }
     84                    break;
     85
     86                case 'f':
     87                case 'F':
     88                    options.fInternalFnExportStdCallsIntName = argv[argi][2] != '-';
    6689                    break;
    6790
     
    123146           "syntax: ImpDef.exe [-h|-?] [-S] <infile> <outfile>\n"
    124147           "    -h or -?      Syntax help. (this)\n"
    125            "    -O<[+]|->     Remove OS2 prefix on APIs.  default: O-\n"
    126            "    -S<[+]|->     Similar to exported name.   default: S+\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"
    127152           "    infile        Name of input file\n"
    128153           "    outfile       Name of output file\n"
     
    134159           "   -O+ has no effect on stdcall functions when -S+ is set. -S+ has higher\n"
    135160           "   precedence than -O+.\n"
    136            "   -O+ only removes the OS2 prefix from internal names.\n"
     161           "   -O+ only removes the OS2 prefix from internal names.\n",
     162           ORD_START_INTERNAL_FUNCTIONS
    137163           );
    138164}
     
    201227
    202228                        /* real work */
    203                         if (pOptions->fSimilarToExported || pOptions->fRemoveOS2APIPrefix)
    204                             pszName = generateExportName(&export, &szName[0], pOptions);
    205                         else if (export.achIntName[0] != '\0')
    206                             pszName = &export.achIntName[0];
    207                         else if (export.achName[0] != '\0')
    208                             pszName = &export.achName[0];
     229                        pszName = generateExportName(&export, &szName[0], pOptions);
    209230
    210231                        fprintf(phOutput, "    %-*s  @%ld\n", 40, pszName, export.ulOrdinal);
     
    238259/**
    239260 * Generate export names according to options defines.
    240  * fSimilarToExported only applies to stdcall functions.
     261 * fSimilarToExported only applies to stdcall API functions.
    241262 * fRemoveOS2APIPrefix only applies to APIs.
    242263 * fRemoveOS2APIPrefix have no effect on stdcall functions when fSimilarToExported is set.
     
    252273static char *generateExportName(const PEXPORTENTRY pExport, char *pszBuffer, const POPTIONS pOptions)
    253274{
    254     if (pOptions->fSimilarToExported)
    255     {
    256         if (pExport->achIntName[0] != '\0')
    257         {
    258             char *pszAt = strchr(&pExport->achIntName[0], '@');
    259             if (pszAt != NULL && pExport->achIntName[0] == '_' && pExport->achName[0] != '"')
    260             {   /* stdcall - merge */
    261                 strcpy(pszBuffer, "_");
    262                 /* test for "reserved" definition file names (like HeapSize) in original def-file. */
    263                 if (pExport->achName[0] != '"')
    264                     strcat(pszBuffer, &pExport->achName[0]);
    265                 else
    266                 {
    267                     strcat(pszBuffer, &pExport->achName[1]);
    268                     pszBuffer[strlen(pszBuffer)-1] = '\0'; //remove tail '"'
    269                 }
    270 
    271                 strcat(pszBuffer, pszAt);
    272             }
    273             else
    274             {   /* not a stdcall - no merge but check for OS2prefix */
    275                 if (pOptions->fRemoveOS2APIPrefix && pExport->ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
    276                 {
    277                     int i = 0;
    278                     char *psz = pszBuffer;
    279                     if (pExport->achIntName[i] == '_')
    280                         *psz++ = pExport->achIntName[i++];
    281                     if (strncmp(&pExport->achIntName[i], "OS2", 3) == 0)
    282                         i += 3;
    283                     strcpy(psz, &pExport->achIntName[i]);
     275    if (pExport->ulOrdinal < pOptions->ulOrdStartInternalFunctions)
     276    {
     277        /* API */
     278        if (pOptions->fSimilarToExported)
     279        {
     280            if (pExport->achIntName[0] != '\0')
     281            {
     282                char *pszAt = strchr(&pExport->achIntName[0], '@');
     283                if (pszAt != NULL && pExport->achIntName[0] == '_' && pExport->achName[0] != '"')
     284                {   /* stdcall - merge */
     285                    strcpy(pszBuffer, "_");
     286                    /* test for "reserved" definition file names (like HeapSize) in original def-file. */
     287                    if (pExport->achName[0] != '"')
     288                        strcat(pszBuffer, &pExport->achName[0]);
     289                    else
     290                    {
     291                        strcat(pszBuffer, &pExport->achName[1]);
     292                        pszBuffer[strlen(pszBuffer)-1] = '\0'; //remove tail '"'
     293                    }
     294
     295                    strcat(pszBuffer, pszAt);
    284296                }
    285297                else
    286                     strcpy(pszBuffer, &pExport->achIntName[0]);
    287             }
     298                {   /* not a stdcall - no merge but check for OS2prefix */
     299                    if (pOptions->fRemoveOS2APIPrefix)
     300                    {
     301                        int i = 0;
     302                        char *psz = pszBuffer;
     303                        if (pExport->achIntName[i] == '_')
     304                            *psz++ = pExport->achIntName[i++];
     305                        if (strncmp(&pExport->achIntName[i], "OS2", 3) == 0)
     306                            i += 3;
     307                        strcpy(psz, &pExport->achIntName[i]);
     308                    }
     309                    else
     310                        strcpy(pszBuffer, &pExport->achIntName[0]);
     311                }
     312            }
     313            else
     314                strcpy(pszBuffer, &pExport->achName[0]);
     315        }
     316        else if (pOptions->fRemoveOS2APIPrefix)
     317        {   /* removes OS2 prefix */
     318            if (pExport->achIntName[0] != '\0')
     319            {
     320                int i = 0;
     321                char *psz = pszBuffer;
     322                if (pExport->achIntName[i] == '_')
     323                    *psz++ = pExport->achIntName[i++];
     324                if (strncmp(&pExport->achIntName[i], "OS2", 3) == 0)
     325                    i += 3;
     326                strcpy(psz, &pExport->achIntName[i]);
     327            }
     328            else
     329                strcpy(pszBuffer, &pExport->achName[0]);
    288330        }
    289331        else
    290             strcpy(pszBuffer, &pExport->achName[0]);
    291     }
    292     else if (pOptions->fRemoveOS2APIPrefix && pExport->ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
    293     {   /* removes OS2 prefix */
    294         if (pExport->achIntName[0] != '\0')
    295         {
    296             int i = 0;
    297             char *psz = pszBuffer;
    298             if (pExport->achIntName[i] == '_')
    299                 *psz++ = pExport->achIntName[i++];
    300             if (strncmp(&pExport->achIntName[i], "OS2", 3) == 0)
    301                 i += 3;
    302             strcpy(psz, &pExport->achIntName[i]);
    303         }
    304         else
    305             strcpy(pszBuffer, &pExport->achName[0]);
     332            if (pExport->achIntName[0] != '\0')
     333                strcpy(pszBuffer, &pExport->achIntName[0]);
     334            else
     335                strcpy(pszBuffer, &pExport->achName[0]);
    306336    }
    307337    else
    308         if (pExport->achIntName[0] != '\0')
     338    {   /* non-API functions */
     339        if ((pExport->achName[0] == '\0' || (pOptions->fInternalFnExportStdCallsIntName && strchr(&pExport->achIntName[0], '@')))
     340            && pExport->achIntName[0] != '\0'
     341            )
    309342            strcpy(pszBuffer, &pExport->achIntName[0]);
    310343        else
    311344            strcpy(pszBuffer, &pExport->achName[0]);
     345    }
    312346
    313347    return pszBuffer;
Note: See TracChangeset for help on using the changeset viewer.