| 1 | /* $Id: kDef2Wat.cpp,v 1.2 2001-04-17 00:26:10 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 <os2.h>
|
|---|
| 17 |
|
|---|
| 18 | #include "kFile.h"
|
|---|
| 19 | #include "kFileFormatBase.h"
|
|---|
| 20 | #include "kInterfaces.h"
|
|---|
| 21 | #include "kFileDef.h"
|
|---|
| 22 |
|
|---|
| 23 | /*******************************************************************************
|
|---|
| 24 | * Internal Functions *
|
|---|
| 25 | *******************************************************************************/
|
|---|
| 26 | static void syntax(void);
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | /**
|
|---|
| 31 | * Main function.
|
|---|
| 32 | * Parses arguments and tries to convert files.
|
|---|
| 33 | * @returns 0 on success.
|
|---|
| 34 | * -1 Bad syntax.
|
|---|
| 35 | * -2 Failed to read .DEF file.
|
|---|
| 36 | * -3 Failed to generate output file.
|
|---|
| 37 | * @param See syntax().
|
|---|
| 38 | */
|
|---|
| 39 | int main(int argc, char **argv)
|
|---|
| 40 | {
|
|---|
| 41 | const char *pszInput;
|
|---|
| 42 | const char *pszOutput;
|
|---|
| 43 | const char *pszAppend;
|
|---|
| 44 |
|
|---|
| 45 | /* check arguments */
|
|---|
| 46 | if (argc != 3 && argc != 4)
|
|---|
| 47 | {
|
|---|
| 48 | syntax();
|
|---|
| 49 | return -1;
|
|---|
| 50 | }
|
|---|
| 51 | pszInput = argv[1];
|
|---|
| 52 | pszOutput = argv[2];
|
|---|
| 53 | pszAppend = (argc == 4) ? argv[3] : NULL;
|
|---|
| 54 |
|
|---|
| 55 | /*
|
|---|
| 56 | *
|
|---|
| 57 | */
|
|---|
| 58 | try
|
|---|
| 59 | {
|
|---|
| 60 | kFile InFile(pszInput);
|
|---|
| 61 | kFileDef def(&InFile);
|
|---|
| 62 | try
|
|---|
| 63 | {
|
|---|
| 64 | kFile OutFile(pszOutput, FALSE);
|
|---|
| 65 | OutFile.end();
|
|---|
| 66 |
|
|---|
| 67 | def.makeWatcomLinkFileAddtion(&OutFile);
|
|---|
| 68 | if (pszAppend)
|
|---|
| 69 | {
|
|---|
| 70 | try
|
|---|
| 71 | {
|
|---|
| 72 | kFile AppendFile(pszAppend);
|
|---|
| 73 |
|
|---|
| 74 | OutFile += AppendFile;
|
|---|
| 75 | kFile::StdOut.printf("Successfully converted %s to %s\n", pszInput, pszOutput);
|
|---|
| 76 | }
|
|---|
| 77 | catch (int errorcode)
|
|---|
| 78 | {
|
|---|
| 79 | kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, errorcode);
|
|---|
| 80 | return -3;
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | catch (int errorcode)
|
|---|
| 85 | {
|
|---|
| 86 | kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, errorcode);
|
|---|
| 87 | return -3;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | catch (int errorcode)
|
|---|
| 91 | {
|
|---|
| 92 | kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, errorcode);
|
|---|
| 93 | return -2;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | return 0;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * Writes syntax to stdout.
|
|---|
| 102 | */
|
|---|
| 103 | static void syntax(void)
|
|---|
| 104 | {
|
|---|
| 105 | kFile::StdOut.printf(
|
|---|
| 106 | "kDef2Wat v0.0.0 (untested)\n"
|
|---|
| 107 | "\n"
|
|---|
| 108 | "syntax: kDef2Wat.exe <def-file> <wlink-file> [extra-file]\n"
|
|---|
| 109 | "\n"
|
|---|
| 110 | "Where:\n"
|
|---|
| 111 | " <def-file> The .DEF file to convert.\n"
|
|---|
| 112 | " <wlink-file> The WLINK directive and option file.\n"
|
|---|
| 113 | " [extra-file] Extra file with directives which should be appended to\n"
|
|---|
| 114 | " the wlink-file\n"
|
|---|
| 115 | "\n"
|
|---|
| 116 | "Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
|
|---|
| 117 | );
|
|---|
| 118 | }
|
|---|