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