| 1 | /* $Id: kDef2Wat.cpp,v 1.5 2002-08-25 22:35:46 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Converter for IBM/MS linker definition files (.DEF) to Watcom linker directives and options.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | /*******************************************************************************
|
|---|
| 14 | * Header Files *
|
|---|
| 15 | *******************************************************************************/
|
|---|
| 16 | #include "kTypes.h"
|
|---|
| 17 | #include "kError.h"
|
|---|
| 18 | #include "kFile.h"
|
|---|
| 19 | #include "kFileInterfaces.h"
|
|---|
| 20 | #include "kFileFormatBase.h"
|
|---|
| 21 | #include "kFileDef.h"
|
|---|
| 22 |
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 |
|
|---|
| 26 | /*******************************************************************************
|
|---|
| 27 | * Internal Functions *
|
|---|
| 28 | *******************************************************************************/
|
|---|
| 29 | static void syntax(void);
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * Main function.
|
|---|
| 35 | * Parses arguments and tries to convert files.
|
|---|
| 36 | * @returns 0 on success.
|
|---|
| 37 | * -1 Bad syntax.
|
|---|
| 38 | * -2 Failed to read .DEF file.
|
|---|
| 39 | * -3 Failed to generate output file.
|
|---|
| 40 | * @param See syntax().
|
|---|
| 41 | */
|
|---|
| 42 | int main(int argc, char **argv)
|
|---|
| 43 | {
|
|---|
| 44 | const char *pszInput;
|
|---|
| 45 | const char *pszOutput;
|
|---|
| 46 | const char *pszAppend;
|
|---|
| 47 | const char *pszOS;
|
|---|
| 48 | int enmOS;
|
|---|
| 49 |
|
|---|
| 50 | /* check arguments */
|
|---|
| 51 | if (argc != 4 && argc != 5)
|
|---|
| 52 | {
|
|---|
| 53 | syntax();
|
|---|
| 54 | return -1;
|
|---|
| 55 | }
|
|---|
| 56 | pszOS = argv[1];
|
|---|
| 57 | pszInput = argv[2];
|
|---|
| 58 | pszOutput = argv[3];
|
|---|
| 59 | pszAppend = (argc == 5) ? argv[4] : NULL;
|
|---|
| 60 | if (!stricmp(pszOS, "os2"))
|
|---|
| 61 | enmOS = kFileDef::os2;
|
|---|
| 62 | else if (!stricmp(pszOS, "os2-16"))
|
|---|
| 63 | enmOS = kFileDef::os2v1;
|
|---|
| 64 | else if (!stricmp(pszOS, "dos"))
|
|---|
| 65 | enmOS = kFileDef::dos;
|
|---|
| 66 | else if (!stricmp(pszOS, "win32"))
|
|---|
| 67 | enmOS = kFileDef::win32;
|
|---|
| 68 | else if (!stricmp(pszOS, "win16"))
|
|---|
| 69 | enmOS = kFileDef::win16;
|
|---|
| 70 | else if (!stricmp(pszOS, "nlm"))
|
|---|
| 71 | enmOS = kFileDef::nlm;
|
|---|
| 72 | else if (!stricmp(pszOS, "qnx"))
|
|---|
| 73 | enmOS = kFileDef::qnx;
|
|---|
| 74 | else if (!stricmp(pszOS, "elf"))
|
|---|
| 75 | enmOS = kFileDef::elf;
|
|---|
| 76 | else
|
|---|
| 77 | {
|
|---|
| 78 | printf("Invalid os string '%s'.\n", pszOS);
|
|---|
| 79 | syntax();
|
|---|
| 80 | return -1;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | /*
|
|---|
| 84 | *
|
|---|
| 85 | */
|
|---|
| 86 | try
|
|---|
| 87 | {
|
|---|
| 88 | kFileDef def(new kFile(pszInput));
|
|---|
| 89 | try
|
|---|
| 90 | {
|
|---|
| 91 | kFile OutFile(pszOutput, FALSE);
|
|---|
| 92 | OutFile.end();
|
|---|
| 93 |
|
|---|
| 94 | def.makeWatcomLinkFileAddtion(&OutFile, enmOS);
|
|---|
| 95 | if (pszAppend)
|
|---|
| 96 | {
|
|---|
| 97 | try
|
|---|
| 98 | {
|
|---|
| 99 | kFile AppendFile(pszAppend);
|
|---|
| 100 |
|
|---|
| 101 | OutFile += AppendFile;
|
|---|
| 102 | kFile::StdOut.printf("Successfully converted %s to %s\n", pszInput, pszOutput);
|
|---|
| 103 | }
|
|---|
| 104 | catch (kError err)
|
|---|
| 105 | {
|
|---|
| 106 | kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, err.getErrno());
|
|---|
| 107 | return -3;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 | catch (kError err)
|
|---|
| 112 | {
|
|---|
| 113 | kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
|
|---|
| 114 | return -3;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 | catch (kError err)
|
|---|
| 118 | {
|
|---|
| 119 | kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
|
|---|
| 120 | return -2;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | return 0;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * Writes syntax to stdout.
|
|---|
| 129 | */
|
|---|
| 130 | static void syntax(void)
|
|---|
| 131 | {
|
|---|
| 132 | kFile::StdOut.printf(
|
|---|
| 133 | "kDef2Wat v0.0.1\n"
|
|---|
| 134 | "\n"
|
|---|
| 135 | "syntax: kDef2Wat.exe <os> <def-file> <wlink-file> [extra-file]\n"
|
|---|
| 136 | "\n"
|
|---|
| 137 | "Where:\n"
|
|---|
| 138 | " <os> Target os. os2, os2-16, dos, win32, win16, nlm, qnx or elf.\n"
|
|---|
| 139 | " <def-file> The .DEF file to convert.\n"
|
|---|
| 140 | " <wlink-file> The WLINK directive and option file.\n"
|
|---|
| 141 | " [extra-file] Extra file with directives which should be appended to\n"
|
|---|
| 142 | " the wlink-file\n"
|
|---|
| 143 | "\n"
|
|---|
| 144 | "Copyright (c) 2000-2002 knut st. osmundsen (bird@anduin.net)\n"
|
|---|
| 145 | );
|
|---|
| 146 | }
|
|---|