ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Build Tools [Keyboard Layout Compiler]
00003  * LICENSE:         BSD - See COPYING.BSD in the top level directory
00004  * FILE:            tools/kbdtool/main.c
00005  * PURPOSE:         Main Logic Loop
00006  * PROGRAMMERS:     ReactOS Foundation
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include "kbdtool.h"
00012 
00013 /* GLOBALS ********************************************************************/
00014 
00015 /* Internal tool data */
00016 ULONG gVersion = 3;
00017 ULONG gSubVersion = 40;
00018 
00019 /* Input file */
00020 PCHAR gpszFileName;
00021 FILE* gfpInput;
00022 
00023 /* Command-line parameters */
00024 BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly;
00025 ULONG BuildType;
00026 
00027 /* FUNCTIONS ******************************************************************/
00028 
00029 VOID 
00030 PrintUsage(VOID)
00031 {
00032     /* This is who we are */
00033     printf("\nKbdTool v%d.%02d - convert keyboard text file to C file or a keyboard layout DLL\n\n",
00034            gVersion, gSubVersion);
00035     
00036     /* This is what we do */
00037     printf("Usage: KbdTool [-v] [-n] [-w] [-k] [-n] [-u|a] [-i|x|m|o|s] FILE\n\n");
00038     printf("\t[-?] display this message\n");
00039     printf("\t[-n] no logo or normal build information displayed\n\n");
00040     printf("\t[-a] Uses non-Unicode source files (default)\n");
00041     printf("\t[-u] Uses Unicode source files\n\n");
00042     printf("\t[-v] Verbose diagnostics (and warnings, with -w)\n");
00043     printf("\t[-w] display extended Warnings\n\n");
00044     printf("\t[-x] Builds for x86 (default)\n");
00045     printf("\t[-i] Builds for IA64\n");
00046     printf("\t[-m] Builds for AMD64\n");
00047     printf("\t[-o] Builds for WOW64\n");
00048     printf("\t[-s] Generate Source files (no build)\n\n");
00049     printf("\tFILE The source keyboard file (required)\n\n");
00050     
00051     /* Extra hints */
00052     printf("\t-u/-a are mutually exclusive; kbdutool will use the last one if you specify more than one.\n");
00053     printf("\t-i/-x/-m/-o-s will exhibit the same behavior when than one of them is specified.\n\n");
00054     
00055     /* Quit */
00056     exit(1);
00057     printf("should not be here");
00058 }
00059 
00060 INT
00061 main(INT argc,
00062      PCHAR* argv)
00063 {
00064     ULONG i, ErrorCode, FailureCode;
00065     CHAR Option;
00066     PCHAR OpenFlags;
00067     CHAR BuildOptions[16] = {0};
00068     
00069     /* Loop for parameter */
00070     for (i = 1; i < argc; ++i)
00071     {
00072         if (argv[i][0] != '/' && argv[i][0] != '-')
00073             break;
00074         
00075         if (argv[i][1] && !argv[i][2])
00076             Option = argv[i][1];
00077         else
00078             Option = 0;
00079         
00080         /* Check supported options */
00081         switch (Option)
00082         {
00083             /* ASCII File */
00084             case 'A':
00085             case 'a':
00086                 UnicodeFile = 0;
00087                 break;
00088             
00089             /* UNICODE File */
00090             case 'U':
00091             case 'u':
00092                 UnicodeFile = 1;
00093                 break;
00094             
00095             /* Verbose */
00096             case 'V':
00097             case 'v':
00098                 Verbose = 1;
00099                 break;
00100             
00101             /* No logo */
00102             case 'N':
00103             case 'n':
00104                 NoLogo = 1;
00105                 break;
00106             
00107             /* Fallback driver */
00108             case 'K':
00109             case 'k':
00110                 FallbackDriver = 1;
00111                 break;
00112             
00113             /* Sanity Check */
00114             case 'W':
00115             case 'w':
00116                 SanityCheck = 1;
00117                 break;
00118             
00119             /* Itanium */
00120             case 'I':
00121             case 'i':
00122                 BuildType = 1;
00123                 break;
00124             
00125             /* X86 */
00126             case 'X':
00127             case 'x':
00128                 BuildType = 0;
00129                 break;
00130             
00131             /* AMD64 */
00132             case 'M':
00133             case 'm':
00134                 BuildType = 2;
00135                 break;
00136             
00137             /* WOW64 */
00138             case 'O':
00139             case 'o':
00140                 BuildType = 3;
00141                 break;
00142             
00143             /* Source only */
00144             case 'S':
00145             case 's':
00146                 SourceOnly = 1;
00147                 break;
00148             
00149             default:
00150                 /* If you got here, the options are invalid or missing */
00151                 PrintUsage();
00152                 break;
00153         }
00154     }
00155     
00156     /* Do we have no options? */
00157     if (i == argc) PrintUsage();
00158 
00159     /* Should we announce ourselves? */
00160     if (!NoLogo)
00161     {
00162         /* This is who we are */
00163         printf("\nKbdTool v%d.%02d - convert keyboard text file to C file or a keyboard layout DLL\n\n",
00164                gVersion, gSubVersion);
00165     }
00166     
00167     /* Save the file name */
00168     gpszFileName = argv[i];
00169     
00170     /* Open either as binary or text */
00171     OpenFlags = "rb";
00172     if (!UnicodeFile) OpenFlags = "rt";
00173     
00174     /* Open a handle to the file */
00175     gfpInput = fopen(gpszFileName, OpenFlags);
00176     if (!gfpInput)
00177     {
00178         /* Couldn't open it */
00179         printf("Unable to open '%s' for read.\n", gpszFileName);
00180         exit(1);
00181     }
00182     
00183     /* Should we print out what we're doing? */
00184     if (!NoLogo)
00185     {
00186         /* Are we only building the source files? */
00187         if (SourceOnly)
00188         {
00189             /* Then there's no target architecture */
00190             strcpy(BuildOptions, "source files");
00191         }
00192         else
00193         {
00194             /* Take a look at the target architecture*/
00195             switch (BuildType)
00196             {
00197                 /* Print the appropriate message depending on what was chosen */
00198                 case 0:
00199                     strcpy(BuildOptions, "i386/x86");
00200                     break;                      
00201                 case 1:
00202                     strcpy(BuildOptions, "ia64");
00203                     break;
00204                 case 2:
00205                     strcpy(BuildOptions, "amd64/x64");
00206                     break;
00207                 case 3:
00208                     strcpy(BuildOptions, "wow64");
00209                     break;
00210                 default:
00211                     strcpy(BuildOptions, "unknown purpose");
00212                     break;
00213             }
00214         }
00215         
00216         /* Now inform the user */
00217         printf("Compiling layout information from '%s' for %s.\n", gpszFileName, BuildOptions);
00218     }
00219           
00220     /* Now parse the keywords */
00221     FailureCode = DoParsing();
00222     
00223     /* Should we build? */
00224     if (!(SourceOnly) && !(FallbackDriver)) ErrorCode = 0;//DoBuild();
00225     
00226     /* Did everything work? */
00227     if (FailureCode == 0)
00228     {
00229         /* Tell the user, if he cares */
00230         if (!NoLogo) printf("All tasks completed successfully.\n");
00231     }
00232     else
00233     {
00234         /* Print the failure code */
00235         printf("\n     %13d\n", FailureCode);
00236     }
00237     
00238     /* Return the error code */
00239     return ErrorCode;
00240 }
00241 
00242 /* EOF */

Generated on Sat May 26 2012 04:15:46 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.