Annotation of embedtools/src/voucher.c, revision 1.1.2.2

1.1.2.1   misho       1: #include "global.h"
                      2: 
                      3: 
1.1.2.2 ! misho       4: io_enableDEBUG;
        !             5: 
        !             6: cfg_root_t cfg;
        !             7: FILE *output;
        !             8: char szConfig[MAXPATHLEN] = VOUCHER_CFG;
        !             9: extern char compiled[], compiledby[], compilehost[];
        !            10: 
        !            11: 
        !            12: static void
        !            13: Usage()
        !            14: {
        !            15:        printf( " -= VOUCHER =- management tool\n"
        !            16:                "=== %s === %s@%s ===\n\n"
        !            17:                "Syntax: voucher [options] -r <RollID> [count]\n"
        !            18:                "\tvoucher [options] -t <voucher> [voucher [voucher ...]]\n\n"
        !            19:                "\t-v\t\tVerbose (more -v more verbosity)\n"
        !            20:                "\t-r\t\tRequest new voucher(s) mode\n"
        !            21:                "\t-t\t\tTest voucher(s) mode\n"
        !            22:                "\t-c <config>\tConfig file\n"
        !            23:                "\t-o <output>\tOutput file [default=-]\n"
        !            24:                "\n", compiled, compiledby, compilehost);
        !            25: }
        !            26: 
        !            27: static void
        !            28: AtExit()
        !            29: {
        !            30:        if (output != stdout)
        !            31:                fclose(output);
        !            32: }
        !            33: 
        !            34: static inline int
        !            35: RedirOutput(const char *name)
        !            36: {
        !            37:        AtExit();
        !            38: 
        !            39:        if (strcmp(name, "-")) {
        !            40:                output = fopen(name, "w+");
        !            41:                if (!output) {
        !            42:                        printf("Error:: can't redirect output #%d - %s\n", 
        !            43:                                        errno, strerror(errno));
        !            44:                        return -1;
        !            45:                }
        !            46:        } else
        !            47:                output = stdout;
        !            48:        return 0;
        !            49: }
        !            50: 
        !            51: 
1.1.2.1   misho      52: int
                     53: main(int argc, char **argv)
                     54: {
1.1.2.2 ! misho      55:        char ch, mode = 0;
        !            56:        int rid, cnt = 1;
        !            57: 
        !            58:        output = stdout;
        !            59:        atexit(AtExit);
        !            60: 
        !            61:        while ((ch = getopt(argc, argv, "hvrtc:o:")) != -1)
        !            62:                switch (ch) {
        !            63:                        case 'r':
        !            64:                                mode = 1;
        !            65:                                break;
        !            66:                        case 't':
        !            67:                                mode = 2;
        !            68:                                break;
        !            69:                        case 'c':
        !            70:                                strlcpy(szConfig, optarg, sizeof szConfig);
        !            71:                                break;
        !            72:                        case 'o':
        !            73:                                RedirOutput(optarg);
        !            74:                                break;
        !            75:                        case 'v':
        !            76:                                io_incDebug;
        !            77:                                break;
        !            78:                        case 'h':
        !            79:                        default:
        !            80:                                Usage();
        !            81:                                return 1;
        !            82:                }
        !            83:        argc -= optind;
        !            84:        argv += optind;
        !            85:        if (!argc || !mode) {
        !            86:                printf("Error:: not enough parameter or unspecified mode ...\n\n");
        !            87:                Usage();
        !            88:                return 1;
        !            89:        }
        !            90:        if (cfgLoadConfig(szConfig, &cfg)) {
        !            91:                printf("Error:: load config #%d - %s\n", cfg_GetErrno(), cfg_GetError());
        !            92:                return 2;
        !            93:        }
        !            94: 
        !            95:        cfgUnloadConfig(&cfg);
1.1.2.1   misho      96:        return 0;
                     97: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>