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/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.