source: libabac/options.c @ a9494ad

mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change on this file since a9494ad was 202a7f9, checked in by Mei <mei@…>, 12 years ago

commited modified files for rt1

  • Property mode set to 100644
File size: 1.3 KB
Line 
1
2#include <stdio.h>
3#include <getopt.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include "options.h"
8
9static void _usage(char *name) {
10    printf(
11        "Usage: %s \\\n"
12        "        --keystore <keystore> \\\n"
13        "        --role <keyid.role> --principal <keyid>\n"
14        "    loads the keystore and runs the query role <-?- principal\n",
15        name
16    );
17    exit(1);
18}
19
20void get_options(int argc, char **argv, options_t *opts) {
21#define OPT_KEYSTORE    1
22#define OPT_ROLE        2
23#define OPT_PRINCIPAL   3
24    struct option options[] = {
25        { "keystore",   1, 0, OPT_KEYSTORE  },
26        { "role",       1, 0, OPT_ROLE      },
27        { "principal",  1, 0, OPT_PRINCIPAL },
28        { 0 },
29    };
30
31    for ( ; ; ) {
32        int c = getopt_long(argc, argv, "", options, NULL);
33        if (c < 0)
34            break;
35
36        switch (c) {
37            case OPT_KEYSTORE:
38                opts->keystore = strdup(optarg);
39                break;
40            case OPT_ROLE:
41                opts->role = strdup(optarg);
42                break;
43            case OPT_PRINCIPAL:
44                opts->principal = strdup(optarg);
45                break;
46
47            default:
48                _usage(argv[0]);
49        }
50    }
51
52    if (!(opts->keystore && opts->role && opts->principal))
53        _usage(argv[0]);
54}
Note: See TracBrowser for help on using the repository browser.