version 1.1.2.1, 2012/07/04 13:49:02
|
version 1.1.2.2, 2012/07/04 15:59:10
|
Line 1
|
Line 1
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
io_enableDEBUG; |
|
|
|
cfg_root_t cfg; |
|
FILE *output; |
|
char szConfig[MAXPATHLEN] = VOUCHER_CFG; |
|
extern char compiled[], compiledby[], compilehost[]; |
|
|
|
|
|
static void |
|
Usage() |
|
{ |
|
printf( " -= VOUCHER =- management tool\n" |
|
"=== %s === %s@%s ===\n\n" |
|
"Syntax: voucher [options] -r <RollID> [count]\n" |
|
"\tvoucher [options] -t <voucher> [voucher [voucher ...]]\n\n" |
|
"\t-v\t\tVerbose (more -v more verbosity)\n" |
|
"\t-r\t\tRequest new voucher(s) mode\n" |
|
"\t-t\t\tTest voucher(s) mode\n" |
|
"\t-c <config>\tConfig file\n" |
|
"\t-o <output>\tOutput file [default=-]\n" |
|
"\n", compiled, compiledby, compilehost); |
|
} |
|
|
|
static void |
|
AtExit() |
|
{ |
|
if (output != stdout) |
|
fclose(output); |
|
} |
|
|
|
static inline int |
|
RedirOutput(const char *name) |
|
{ |
|
AtExit(); |
|
|
|
if (strcmp(name, "-")) { |
|
output = fopen(name, "w+"); |
|
if (!output) { |
|
printf("Error:: can't redirect output #%d - %s\n", |
|
errno, strerror(errno)); |
|
return -1; |
|
} |
|
} else |
|
output = stdout; |
|
return 0; |
|
} |
|
|
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
|
char ch, mode = 0; |
|
int rid, cnt = 1; |
|
|
|
output = stdout; |
|
atexit(AtExit); |
|
|
|
while ((ch = getopt(argc, argv, "hvrtc:o:")) != -1) |
|
switch (ch) { |
|
case 'r': |
|
mode = 1; |
|
break; |
|
case 't': |
|
mode = 2; |
|
break; |
|
case 'c': |
|
strlcpy(szConfig, optarg, sizeof szConfig); |
|
break; |
|
case 'o': |
|
RedirOutput(optarg); |
|
break; |
|
case 'v': |
|
io_incDebug; |
|
break; |
|
case 'h': |
|
default: |
|
Usage(); |
|
return 1; |
|
} |
|
argc -= optind; |
|
argv += optind; |
|
if (!argc || !mode) { |
|
printf("Error:: not enough parameter or unspecified mode ...\n\n"); |
|
Usage(); |
|
return 1; |
|
} |
|
if (cfgLoadConfig(szConfig, &cfg)) { |
|
printf("Error:: load config #%d - %s\n", cfg_GetErrno(), cfg_GetError()); |
|
return 2; |
|
} |
|
|
|
cfgUnloadConfig(&cfg); |
return 0; |
return 0; |
} |
} |