* ReactOS log2lines
* Written by Jan Roeloffzen
*
* - Option init and parsing
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "util.h"
#include "compat.h"
#include "config.h"
#include "help.h"
#include "log2lines.h"
#include "options.h"
char *optchars = "bcd:fFhl:L:mMP:rsS:tTuUvz:";
int opt_buffered = 0;
int opt_help = 0;
int opt_force = 0;
int opt_exit = 0;
int opt_verbose = 0;
int opt_console = 0;
int opt_mark = 0;
int opt_Mark = 0;
char *opt_Pipe = NULL;
int opt_quit = 0;
int opt_cli = 0;
int opt_raw = 0;
int opt_stats = 0;
int opt_Source = 0;
int opt_SrcPlus = 0;
int opt_twice = 0;
int opt_Twice = 0;
int opt_undo = 0;
int opt_redo = 0;
char opt_dir[PATH_MAX];
char opt_logFile[PATH_MAX];
char *opt_mod = NULL;
char opt_7z[PATH_MAX];
char opt_scanned[LINESIZE];
char opt_SourcesPath[LINESIZE];
In such case, the help is shown */
int optionInit(int argc, const char **argv)
{
int i;
char *s;
opt_mod = "a";
strcpy(opt_dir, "");
strcpy(opt_logFile, "");
strcpy(opt_7z, CMD_7Z);
strcpy(opt_SourcesPath, "");
if ((s = getenv(SOURCES_ENV)))
strcpy(opt_SourcesPath, s);
strcpy(opt_scanned, "");
if ((argc == 1) ||
((argc == 2) && (argv[1][0] == '/') && (argv[1][1] == '?')))
{
opt_help++;
usage(1);
return -1;
}
for (i = 1; i < argc; i++)
{
if ((argv[i][0] == '-') && (i+1 < argc))
{
switch (argv[i][1])
{
case 'd':
strcpy(opt_dir, argv[i+1]);
break;
case 'L':
opt_mod = "w";
case 'l':
strcpy(opt_logFile, argv[i+1]);
break;
case 'P':
if (!opt_Pipe)
opt_Pipe = malloc(LINESIZE);
strcpy(opt_Pipe, argv[i+1]);
break;
case 'z':
strcpy(opt_7z, argv[i+1]);
break;
}
}
strcat(opt_scanned, argv[i]);
strcat(opt_scanned, " ");
}
l2l_dbg(4,"opt_scanned=[%s]\n",opt_scanned);
return 0;
}
int optionParse(int argc, const char **argv)
{
int i;
int optCount = 0;
int opt;
while (-1 != (opt = getopt(argc, (char **const)argv, optchars)))
{
switch (opt)
{
case 'b':
opt_buffered++;
break;
case 'c':
opt_console++;
break;
case 'd':
optCount++;
break;
case 'f':
opt_force++;
break;
case 'h':
opt_help++;
usage(1);
return -1;
break;
case 'F':
opt_exit++;
opt_force++;
break;
case 'l':
optCount++;
break;
case 'm':
opt_mark++;
break;
case 'M':
opt_Mark++;
break;
case 'r':
opt_raw++;
break;
case 'P':
optCount++;
break;
case 's':
opt_stats++;
break;
case 'S':
optCount++;
i = sscanf(optarg, "%d+%d,%s", &opt_Source, &opt_SrcPlus, opt_SourcesPath);
if (i == 1)
sscanf(optarg, "%*d,%s", opt_SourcesPath);
l2l_dbg(3, "Sources option parse result: %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath);
if (opt_Source)
{
opt_undo++;
opt_redo++;
}
break;
case 't':
opt_twice++;
break;
case 'T':
opt_twice++;
opt_Twice++;
break;
case 'u':
opt_undo++;
break;
case 'U':
opt_undo++;
opt_redo++;
break;
case 'v':
opt_verbose++;
break;
case 'z':
optCount++;
strcpy(opt_7z, optarg);
break;
default:
usage(0);
return -2;
break;
}
optCount++;
}
if(opt_console)
{
l2l_dbg(2, "Note: use 's' command in console mode. Statistics option disabled\n");
opt_stats = 0;
}
if (opt_SourcesPath[0])
{
strcat(opt_SourcesPath, PATH_STR);
}
if (!opt_dir[0])
{
strcpy(opt_dir, opt_SourcesPath);
strcat(opt_dir, DEF_OPT_DIR);
}
return optCount;
}