File: cmdline.c

package info (click to toggle)
lsm 1.0.4-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 588 kB
  • ctags: 390
  • sloc: ansic: 6,932; sh: 283; makefile: 146
file content (59 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
/*

  (C) 2014 Mika Ilmaranta <ilmis@nullnet.fi>

  License: GPLv2

*/

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

#include "globals.h"
#include "usage.h"
#include "cmdline.h"

void cmdline_parse(int argc, char *argv[])
{
	static struct option long_options[] = {
		{ "help",               0, 0, 'h' },
		{ "version",            0, 0, 'v' },
		{ "config",             1, 0, 'c' },
		{ "pidfile",            1, 0, 'p' },
		{ "no-fork",            0, 0, 'f' },
		{ 0, 0, 0, 0 },
	};

	set_prog(argv[0]);

	for(;;) {
		int i = getopt_long(argc, argv, "hvc:p:f", long_options, NULL);
		if(i == -1) break;
		switch(i) {
		case 'h':
		case 'v':
			usage_and_exit();

		case 'c':
			set_configfile(optarg);
			break;

		case 'p':
			set_pidfile(optarg);
			break;

		case 'f':
			set_nodaemon(1);
			break;

		default:
			usage_and_exit();
		}
	}

	if(optind < argc)
		usage_and_exit();
}

/* EOF */