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