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

options.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS log2lines
00003  * Written by Jan Roeloffzen
00004  *
00005  * - Option init and parsing
00006  */
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <getopt.h>
00012 
00013 #include "util.h"
00014 #include "compat.h"
00015 #include "config.h"
00016 #include "help.h"
00017 #include "log2lines.h"
00018 #include "options.h"
00019 
00020 char *optchars       = "bcd:fFhl:L:mMP:rR:sS:tTuUvz:";
00021 int   opt_buffered   = 0;        // -b
00022 int   opt_help       = 0;        // -h
00023 int   opt_force      = 0;        // -f
00024 int   opt_exit       = 0;        // -e
00025 int   opt_verbose    = 0;        // -v
00026 int   opt_console    = 0;        // -c
00027 int   opt_mark       = 0;        // -m
00028 int   opt_Mark       = 0;        // -M
00029 char *opt_Pipe       = NULL;     // -P
00030 int   opt_quit       = 0;        // -q (cli only)
00031 int   opt_cli        = 0;        // (cli internal)
00032 int   opt_raw        = 0;        // -r
00033 int   opt_stats      = 0;        // -s
00034 int   opt_Source     = 0;        // -S <opt_Source>[+<opt_SrcPlus>][,<sources_path>]
00035 int   opt_SrcPlus    = 0;        // -S <opt_Source>[+<opt_SrcPlus>][,<sources_path>]
00036 int   opt_twice      = 0;        // -t
00037 int   opt_Twice      = 0;        // -T
00038 int   opt_undo       = 0;        // -u
00039 int   opt_redo       = 0;        // -U
00040 char *opt_Revision   = NULL;     // -R
00041 int   opt_Revision_check = 0;    // -R check
00042 char  opt_dir[MAX_PATH];         // -d <opt_dir>
00043 char  opt_logFile[MAX_PATH];     // -l|L <opt_logFile>
00044 char *opt_mod        = NULL;     // -mod for opt_logFile
00045 char  opt_7z[MAX_PATH];          // -z <opt_7z>
00046 char  opt_scanned[LINESIZE];     // all scanned options
00047 char  opt_SourcesPath[LINESIZE]; //sources path
00048 
00049 int optionInit(int argc, const char **argv)
00050 {
00051     int i;
00052     char *s;
00053 
00054     opt_mod = "a";
00055     strcpy(opt_dir, "");
00056     strcpy(opt_logFile, "");
00057     strcpy(opt_7z, CMD_7Z);
00058     strcpy(opt_SourcesPath, "");
00059     if ((s = getenv(SOURCES_ENV)))
00060         strcpy(opt_SourcesPath, s);
00061     revinfo.rev = getRevision(NULL, 1);
00062     revinfo.range = DEF_RANGE;
00063     revinfo.buildrev = getTBRevision(opt_dir);
00064     l2l_dbg(1, "Trunk build revision: %d\n", revinfo.buildrev);
00065 
00066     strcpy(opt_scanned, "");
00067     for (i = 1; i < argc; i++)
00068     {
00069         if ((argv[i][0] == '-') && (i+1 < argc))
00070         {
00071             //Because these arguments can contain spaces we cant use getopt(), a known bug:
00072             switch (argv[i][1])
00073             {
00074             case 'd':
00075                 strcpy(opt_dir, argv[i+1]);
00076                 break;
00077             case 'L':
00078                 opt_mod = "w";
00079                 //fall through
00080             case 'l':
00081                 strcpy(opt_logFile, argv[i+1]);
00082                 break;
00083             case 'P':
00084                 free(opt_Pipe);
00085                 opt_Pipe = malloc(LINESIZE);
00086                 strcpy(opt_Pipe, argv[i+1]);
00087                 break;
00088             case 'z':
00089                 strcpy(opt_7z, argv[i+1]);
00090                 break;
00091             }
00092         }
00093         strcat(opt_scanned, argv[i]);
00094         strcat(opt_scanned, " ");
00095     }
00096 
00097     l2l_dbg(4,"opt_scanned=[%s]\n",opt_scanned);
00098 
00099     return 0;
00100 }
00101 
00102 int optionParse(int argc, const char **argv)
00103 {
00104     int i;
00105     int optCount = 0;
00106     int opt;
00107 
00108     while (-1 != (opt = getopt(argc, (char **const)argv, optchars)))
00109     {
00110         switch (opt)
00111         {
00112         case 'b':
00113             opt_buffered++;
00114             break;
00115         case 'c':
00116             opt_console++;
00117             break;
00118         case 'd':
00119             optCount++;
00120             //just count, see optionInit()
00121             break;
00122         case 'f':
00123             opt_force++;
00124             break;
00125         case 'h':
00126             opt_help++;
00127             usage(1);
00128             return -1;
00129             break;
00130         case 'F':
00131             opt_exit++;
00132             opt_force++;
00133             break;
00134         case 'l':
00135             optCount++;
00136             //just count, see optionInit()
00137             break;
00138         case 'm':
00139             opt_mark++;
00140             break;
00141         case 'M':
00142             opt_Mark++;
00143             break;
00144         case 'r':
00145             opt_raw++;
00146             break;
00147         case 'P':
00148             optCount++;
00149             //just count, see optionInit()
00150             break;
00151         case 'R':
00152             optCount++;
00153             free(opt_Revision);
00154             opt_Revision = malloc(LINESIZE);
00155             sscanf(optarg, "%s", opt_Revision);
00156             if (strcmp(opt_Revision, "check") == 0)
00157                 opt_Revision_check ++;
00158             break;
00159         case 's':
00160             opt_stats++;
00161             break;
00162         case 'S':
00163             optCount++;
00164             i = sscanf(optarg, "%d+%d,%s", &opt_Source, &opt_SrcPlus, opt_SourcesPath);
00165             if (i == 1)
00166                 sscanf(optarg, "%*d,%s", opt_SourcesPath);
00167             l2l_dbg(3, "Sources option parse result: %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath);
00168             if (opt_Source)
00169             {
00170                 /* need to retranslate for source info: */
00171                 opt_undo++;
00172                 opt_redo++;
00173                 opt_Revision_check ++;
00174             }
00175             break;
00176         case 't':
00177             opt_twice++;
00178             break;
00179         case 'T':
00180             opt_twice++;
00181             opt_Twice++;
00182             break;
00183         case 'u':
00184             opt_undo++;
00185             break;
00186         case 'U':
00187             opt_undo++;
00188             opt_redo++;
00189             break;
00190         case 'v':
00191             opt_verbose++;
00192             break;
00193         case 'z':
00194             optCount++;
00195             strcpy(opt_7z, optarg);
00196             break;
00197         default:
00198             usage(0);
00199             return -2;
00200             break;
00201         }
00202         optCount++;
00203     }
00204     if(opt_console)
00205     {
00206         l2l_dbg(2, "Note: use 's' command in console mode. Statistics option disabled\n");
00207         opt_stats = 0;
00208     }
00209     if (opt_SourcesPath[0])
00210     {
00211         strcat(opt_SourcesPath, PATH_STR);
00212     }
00213     if (!opt_dir[0])
00214     {
00215         strcpy(opt_dir, opt_SourcesPath);
00216         strcat(opt_dir, DEF_OPT_DIR);
00217     }
00218 
00219     return optCount;
00220 }
00221 
00222 /* EOF */

Generated on Sun May 27 2012 04:19:17 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.