Create the AHCI branch for Aman's work
[reactos.git] / sdk / 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 "kbdtool.h"
12
13 /* GLOBALS ********************************************************************/
14
15 /* Internal tool data */
16 ULONG gVersion = 3;
17 ULONG gSubVersion = 40;
18
19 /* Input file */
20 PCHAR gpszFileName;
21 FILE* gfpInput;
22
23 /* Command-line parameters */
24 BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly;
25 ULONG BuildType;
26
27 /* FUNCTIONS ******************************************************************/
28
29 VOID
30 PrintUsage(VOID)
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 PCHAR* argv)
63 {
64 ULONG i, ErrorCode, FailureCode;
65 CHAR Option;
66 PCHAR OpenFlags;
67 CHAR BuildOptions[16] = {0};
68
69 /* Loop for parameter */
70 for (i = 1; i < argc; ++i)
71 {
72 if (argv[i][0] != '/' && argv[i][0] != '-')
73 break;
74
75 if (argv[i][1] && !argv[i][2])
76 Option = argv[i][1];
77 else
78 Option = 0;
79
80 /* Check supported options */
81 switch (Option)
82 {
83 /* ASCII File */
84 case 'A':
85 case 'a':
86 UnicodeFile = 0;
87 break;
88
89 /* UNICODE File */
90 case 'U':
91 case 'u':
92 UnicodeFile = 1;
93 break;
94
95 /* Verbose */
96 case 'V':
97 case 'v':
98 Verbose = 1;
99 break;
100
101 /* No logo */
102 case 'N':
103 case 'n':
104 NoLogo = 1;
105 break;
106
107 /* Fallback driver */
108 case 'K':
109 case 'k':
110 FallbackDriver = 1;
111 break;
112
113 /* Sanity Check */
114 case 'W':
115 case 'w':
116 SanityCheck = 1;
117 break;
118
119 /* Itanium */
120 case 'I':
121 case 'i':
122 BuildType = 1;
123 break;
124
125 /* X86 */
126 case 'X':
127 case 'x':
128 BuildType = 0;
129 break;
130
131 /* AMD64 */
132 case 'M':
133 case 'm':
134 BuildType = 2;
135 break;
136
137 /* WOW64 */
138 case 'O':
139 case 'o':
140 BuildType = 3;
141 break;
142
143 /* Source only */
144 case 'S':
145 case 's':
146 SourceOnly = 1;
147 break;
148
149 default:
150 /* If you got here, the options are invalid or missing */
151 PrintUsage();
152 break;
153 }
154 }
155
156 /* Do we have no options? */
157 if (i == argc) PrintUsage();
158
159 /* Should we announce ourselves? */
160 if (!NoLogo)
161 {
162 /* This is who we are */
163 printf("\nKbdTool v%d.%02d - convert keyboard text file to C file or a keyboard layout DLL\n\n",
164 gVersion, gSubVersion);
165 }
166
167 /* Save the file name */
168 gpszFileName = argv[i];
169
170 /* Open either as binary or text */
171 OpenFlags = "rb";
172 if (!UnicodeFile) OpenFlags = "rt";
173
174 /* Open a handle to the file */
175 gfpInput = fopen(gpszFileName, OpenFlags);
176 if (!gfpInput)
177 {
178 /* Couldn't open it */
179 printf("Unable to open '%s' for read.\n", gpszFileName);
180 exit(1);
181 }
182
183 /* Should we print out what we're doing? */
184 if (!NoLogo)
185 {
186 /* Are we only building the source files? */
187 if (SourceOnly)
188 {
189 /* Then there's no target architecture */
190 strcpy(BuildOptions, "source files");
191 }
192 else
193 {
194 /* Take a look at the target architecture*/
195 switch (BuildType)
196 {
197 /* Print the appropriate message depending on what was chosen */
198 case 0:
199 strcpy(BuildOptions, "i386/x86");
200 break;
201 case 1:
202 strcpy(BuildOptions, "ia64");
203 break;
204 case 2:
205 strcpy(BuildOptions, "amd64/x64");
206 break;
207 case 3:
208 strcpy(BuildOptions, "wow64");
209 break;
210 default:
211 strcpy(BuildOptions, "unknown purpose");
212 break;
213 }
214 }
215
216 /* Now inform the user */
217 printf("Compiling layout information from '%s' for %s.\n", gpszFileName, BuildOptions);
218 }
219
220 /* Now parse the keywords */
221 FailureCode = DoParsing();
222
223 /* Should we build? */
224 if (!(SourceOnly) && !(FallbackDriver)) ErrorCode = 0;//DoBuild();
225
226 /* Did everything work? */
227 if (FailureCode == 0)
228 {
229 /* Tell the user, if he cares */
230 if (!NoLogo) printf("All tasks completed successfully.\n");
231 }
232 else
233 {
234 /* Print the failure code */
235 printf("\n %13d\n", FailureCode);
236 }
237
238 /* Return the error code */
239 return ErrorCode;
240 }
241
242 /* EOF */