ReactOS  0.4.12-dev-918-g6c6e7b8
main.c
Go to the documentation of this file.
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 */
18 
19 /* Input file */
22 
23 /* Command-line parameters */
26 
27 /* FUNCTIONS ******************************************************************/
28 
29 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",
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
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",
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 */
signed char * PCHAR
Definition: retypes.h:7
BOOLEAN NoLogo
Definition: main.c:24
static int argc
Definition: ServiceArgs.c:12
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
VOID PrintUsage(VOID)
Definition: main.c:30
char CHAR
Definition: xmlstorage.h:175
BOOLEAN Verbose
Definition: main.c:24
ULONG gSubVersion
Definition: main.c:17
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOLEAN SourceOnly
Definition: main.c:24
BOOLEAN FallbackDriver
Definition: main.c:24
unsigned char BOOLEAN
BOOLEAN UnicodeFile
Definition: main.c:24
char gVersion[]
Definition: init.c:22
FILE * gfpInput
Definition: main.c:21
ULONG DoParsing(VOID)
Definition: parser.c:972
int main(int argc, const char *argv[])
Definition: main.c:122
ULONG BuildType
Definition: main.c:25
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
BOOLEAN SanityCheck
Definition: main.c:24
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
void exit(int exitcode)
Definition: _exit.c:33
PCHAR gpszFileName
Definition: main.c:20
#define printf
Definition: config.h:203