aboutsummaryrefslogtreecommitdiff
path: root/src/opt.c
blob: 7b6d083fa06531d773393ce94d463656ccde97ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include "config.h"
#include "opt.h"

#define CONFIG_OPT(default_val) { {0},0,{default_val} }

struct opt config_opts[] =  { CONFIG_OPT(DEFAULT_FIFO), CONFIG_OPT(NULL) };
const int opt_siz = ( sizeof(config_opts)/sizeof(config_opts[0]) );


void
usage(char *arg0)
{
  fprintf(stderr, "\n%s (%s)\n  %s\n", PKGNAME, VERSION, PKGDESC);
  fprintf(stderr, "  Written by %s (%s).\n", AUTHOR, AUTHOR_EMAIL);
  fprintf(stderr, "  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\n");
  fprintf(stderr, "  Command:\n\t%s [args]\n", arg0);
  fprintf(stderr, "  Arguments:\n\t-h this\n\t-f [passfifo] default: %s\n\t-c [cryptcreate]\n", DEFAULT_FIFO);
}

int
parse_cmd(int argc, char **argv)
{
  int opt;

  while ((opt = getopt(argc, argv, "hf:c:")) != -1) {
    switch (opt) {
      case 'h':
        usage(argv[0]);
        return 1;
      case 'f':
        s_OPT(FIFO_PATH, strdup(optarg));
        break;
      case 'c':
        s_OPT(CRYPT_CMD, strdup(optarg));
        break;
    }
  }
  return 0;
}