source: trunk/tools/common/kDef2Wat.cpp@ 8706

Last change on this file since 8706 was 8360, checked in by bird, 23 years ago

Support for other watcom target OSes.

File size: 4.0 KB
Line 
1/* $Id: kDef2Wat.cpp,v 1.4 2002-05-01 03:58:36 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*******************************************************************************/
29static 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 */
42int 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, "dos"))
63 enmOS = kFileDef::dos;
64 else if (!stricmp(pszOS, "win32"))
65 enmOS = kFileDef::win32;
66 else if (!stricmp(pszOS, "win16"))
67 enmOS = kFileDef::win16;
68 else if (!stricmp(pszOS, "nlm"))
69 enmOS = kFileDef::nlm;
70 else if (!stricmp(pszOS, "qnx"))
71 enmOS = kFileDef::qnx;
72 else if (!stricmp(pszOS, "elf"))
73 enmOS = kFileDef::elf;
74 else
75 {
76 printf("Invalid os string '%s'.\n", pszOS);
77 syntax();
78 return -1;
79 }
80
81 /*
82 *
83 */
84 try
85 {
86 kFileDef def(new kFile(pszInput));
87 try
88 {
89 kFile OutFile(pszOutput, FALSE);
90 OutFile.end();
91
92 def.makeWatcomLinkFileAddtion(&OutFile, enmOS);
93 if (pszAppend)
94 {
95 try
96 {
97 kFile AppendFile(pszAppend);
98
99 OutFile += AppendFile;
100 kFile::StdOut.printf("Successfully converted %s to %s\n", pszInput, pszOutput);
101 }
102 catch (kError err)
103 {
104 kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, err.getErrno());
105 return -3;
106 }
107 }
108 }
109 catch (kError err)
110 {
111 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
112 return -3;
113 }
114 }
115 catch (kError err)
116 {
117 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
118 return -2;
119 }
120
121 return 0;
122}
123
124
125/**
126 * Writes syntax to stdout.
127 */
128static void syntax(void)
129{
130 kFile::StdOut.printf(
131 "kDef2Wat v0.0.1\n"
132 "\n"
133 "syntax: kDef2Wat.exe <os> <def-file> <wlink-file> [extra-file]\n"
134 "\n"
135 "Where:\n"
136 " <os> Target os. os2, dos, win32, win16, nlm, qnx or elf.\n"
137 " <def-file> The .DEF file to convert.\n"
138 " <wlink-file> The WLINK directive and option file.\n"
139 " [extra-file] Extra file with directives which should be appended to\n"
140 " the wlink-file\n"
141 "\n"
142 "Copyright (c) 2000-2002 knut st. osmundsen (bird@anduin.net)\n"
143 );
144}
Note: See TracBrowser for help on using the repository browser.