source: trunk/tools/common/kDef2Wat.cpp

Last change on this file was 9132, checked in by bird, 23 years ago

Support for os2-16 (NE executables).
Corrected bad modulename for PHYSICAL DEVICE and VIRTUAL DEVICE.

File size: 4.0 KB
RevLine 
[9132]1/* $Id: kDef2Wat.cpp,v 1.5 2002-08-25 22:35:46 bird Exp $
[4402]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*******************************************************************************/
[8003]16#include "kTypes.h"
17#include "kError.h"
[4402]18#include "kFile.h"
[8003]19#include "kFileInterfaces.h"
[4402]20#include "kFileFormatBase.h"
21#include "kFileDef.h"
22
[8360]23#include <stdio.h>
24#include <string.h>
25
[4402]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;
[8360]47 const char *pszOS;
48 int enmOS;
[4402]49
50 /* check arguments */
[8360]51 if (argc != 4 && argc != 5)
[4402]52 {
53 syntax();
54 return -1;
55 }
[8360]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;
[9132]62 else if (!stricmp(pszOS, "os2-16"))
63 enmOS = kFileDef::os2v1;
[8360]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 }
[4402]82
83 /*
84 *
85 */
86 try
87 {
[8003]88 kFileDef def(new kFile(pszInput));
[4402]89 try
90 {
91 kFile OutFile(pszOutput, FALSE);
92 OutFile.end();
93
[8360]94 def.makeWatcomLinkFileAddtion(&OutFile, enmOS);
[4402]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 }
[8003]104 catch (kError err)
[4402]105 {
[8003]106 kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, err.getErrno());
[4402]107 return -3;
108 }
109 }
110 }
[8003]111 catch (kError err)
[4402]112 {
[8003]113 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
[4402]114 return -3;
115 }
116 }
[8003]117 catch (kError err)
[4402]118 {
[8003]119 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno());
[4402]120 return -2;
121 }
122
123 return 0;
124}
125
126
127/**
128 * Writes syntax to stdout.
129 */
130static void syntax(void)
131{
132 kFile::StdOut.printf(
[8360]133 "kDef2Wat v0.0.1\n"
[4402]134 "\n"
[8360]135 "syntax: kDef2Wat.exe <os> <def-file> <wlink-file> [extra-file]\n"
[4402]136 "\n"
137 "Where:\n"
[9132]138 " <os> Target os. os2, os2-16, dos, win32, win16, nlm, qnx or elf.\n"
[4402]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"
[8360]144 "Copyright (c) 2000-2002 knut st. osmundsen (bird@anduin.net)\n"
[4402]145 );
146}
Note: See TracBrowser for help on using the repository browser.