Implement opening the layout file and printing out the target DLL architecture. Add...
[reactos.git] / reactos / tools / kbdtool / main.c
1 /*
2 * PROJECT: ReactOS Build Tools [Keyboard Layout Compiler]
3 * LICENSE: BSD - See COPYING.BSD in the top level directory
4 * FILE: tools/kbdtool/main.c
5 * PURPOSE: Main Logic Loop
6 * PROGRAMMERS: ReactOS Foundation
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <string.h>
12 #include <stdarg.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include "getopt.h"
16 #include <host/typedefs.h>
17
18 /* GLOBALS ********************************************************************/
19
20 ULONG gVersion = 3;
21 ULONG gSubVersion = 40;
22 BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly;
23 ULONG BuildType;
24 PCHAR gpszFileName;
25 FILE* gfpInput;
26
27 /* FUNCTIONS ******************************************************************/
28
29 void
30 usage()
31 {
32 /* This is who we are */
33 printf("\nKbdTool v%d.%02d - convert keyboard text file to C file or a keyboard layout DLL\n\n",
34 gVersion, gSubVersion);
35
36 /* This is what we do */
37 printf("Usage: KbdTool [-v] [-n] [-w] [-k] [-n] [-u|a] [-i|x|m|o|s] FILE\n\n");
38 printf("\t[-?] display this message\n");
39 printf("\t[-n] no logo or normal build information displayed\n\n");
40 printf("\t[-a] Uses non-Unicode source files (default)\n");
41 printf("\t[-u] Uses Unicode source files\n\n");
42 printf("\t[-v] Verbose diagnostics (and warnings, with -w)\n");
43 printf("\t[-w] display extended Warnings\n\n");
44 printf("\t[-x] Builds for x86 (default)\n");
45 printf("\t[-i] Builds for IA64\n");
46 printf("\t[-m] Builds for AMD64\n");
47 printf("\t[-o] Builds for WOW64\n");
48 printf("\t[-s] Generate Source files (no build)\n\n");
49 printf("\tFILE The source keyboard file (required)\n\n");
50
51 /* Extra hints */
52 printf("\t-u/-a are mutually exclusive; kbdutool will use the last one if you specify more than one.\n");
53 printf("\t-i/-x/-m/-o-s will exhibit the same behavior when than one of them is specified.\n\n");
54
55 /* Quit */
56 _exit(1);
57 printf("should not be here");
58 }
59
60 int
61 main(int argc,
62 char** argv)
63 {
64 CHAR Option;
65 PCHAR OpenFlags;
66 CHAR BuildOptions[16] = {0};
67
68 /* Loop for parameter */
69 while (TRUE)
70 {
71 /* Get the options */
72 Option = getopt(argc, argv, "aAeEiIkKmMnNOosSuUvVwWxX?");
73 if (Option != -1)
74 {
75 /* Check supported options */
76 switch (Option)
77 {
78 /* ASCII File */
79 case 'A':
80 case 'a':
81 UnicodeFile = 0;
82 continue;
83
84 /* UNICODE File */
85 case 'U':
86 case 'u':
87 UnicodeFile = 1;
88 continue;
89
90 /* Verbose */
91 case 'V':
92 case 'v':
93 Verbose = 1;
94 continue;
95
96 /* No logo */
97 case 'N':
98 case 'n':
99 NoLogo = 1;
100 continue;
101
102 /* Fallback driver */
103 case 'K':
104 case 'k':
105 FallbackDriver = 1;
106 continue;
107
108 /* Sanity Check */
109 case 'W':
110 case 'w':
111 SanityCheck = 1;
112 continue;
113
114 /* Itanium */
115 case 'I':
116 case 'i':
117 BuildType = 1;
118 continue;
119
120 /* X86 */
121 case 'X':
122 case 'x':
123 BuildType = 0;
124 continue;
125
126 /* AMD64 */
127 case 'M':
128 case 'm':
129 BuildType = 2;
130 continue;
131
132 /* WOW64 */
133 case 'O':
134 case 'o':
135 BuildType = 3;
136 continue;
137
138 /* Source only */
139 case 'S':
140 case 's':
141 SourceOnly = 1;
142 continue;
143 default:
144 break;
145 }
146
147 /* If you got here, the options are invalid or missing */
148 usage();
149 }
150 break;
151 }
152
153 /* Do we have no options? */
154 if (optind == argc) usage();
155
156 /* Should we announce ourselves? */
157 if (!NoLogo)
158 {
159 /* This is who we are */
160 printf("\nKbdTool v%d.%02d - convert keyboard text file to C file or a keyboard layout DLL\n\n",
161 gVersion, gSubVersion);
162 }
163
164 /* Save the file name */
165 gpszFileName = argv[optind];
166
167 /* Open either as binary or text */
168 OpenFlags = "rb";
169 if (!UnicodeFile) OpenFlags = "rt";
170
171 /* Open a handle to the file */
172 gfpInput = fopen(gpszFileName, OpenFlags);
173 if (!gfpInput)
174 {
175 /* Couldn't open it */
176 printf("Unable to open '%s' for read.\n", gpszFileName);
177 exit(1);
178 }
179
180 /* Should we print out what we're doing? */
181 if (!NoLogo)
182 {
183 /* Are we only building the source files? */
184 if (SourceOnly)
185 {
186 /* Then there's no target architecture */
187 strcpy(BuildOptions, "source files");
188 }
189 else
190 {
191 /* Take a look at the target architecture*/
192 switch (BuildType)
193 {
194 /* Print the appropriate message depending on what was chosen */
195 case 0:
196 strcpy(BuildOptions, "i386/x86");
197 break;
198 case 1:
199 strcpy(BuildOptions, "ia64");
200 break;
201 case 2:
202 strcpy(BuildOptions, "amd64/x64");
203 break;
204 case 3:
205 strcpy(BuildOptions, "wow64");
206 break;
207 default:
208 strcpy(BuildOptions, "unknown purpose");
209 break;
210 }
211 }
212
213 /* Now inform the user */
214 printf("Compiling layout information from '%s' for %s.\n", gpszFileName, BuildOptions);
215 }
216
217 /* Now do something... */
218 printf("Like a rock...\n");
219 exit(0);
220 }
221
222 /* EOF */