1#define EX_USAGE 1
2
3OPTIONS_BEGIN("direvent",
4              [<GNU direvent monitors changes in directories>],
5              [<[CONFIG]>],
6              [<gnu>],
7              [<copyright_year=2012-2014>],
8              [<copyright_holder=Sergey Poznyakoff>])
9
10OPTION(debug,d,,
11       [<increase debug level>])
12BEGIN
13	opt_debug_level++;
14END
15
16OPTION(,l,PRIO,
17       [<log everything with priority PRIO and higher to the stderr, as well as to the syslog>])
18BEGIN
19	if (strcmp(optarg, "none") == 0)
20		log_to_stderr = -1;
21	else
22		log_to_stderr = get_priority(optarg);
23END
24
25OPTION(facility,F,NAME,
26       [<set syslog facility>])
27BEGIN
28	opt_facility = get_facility(optarg);
29END
30
31OPTION(foreground,f,,
32       [<remain in foreground>])
33BEGIN
34	opt_foreground++;
35END
36
37OPTION(include-directory,I,DIR,
38       [<add include directory>])
39BEGIN
40        grecs_preproc_add_include_dir(optarg);
41END
42
43OPTION(self-test,T,PROG,
44       [<self-test mode>])
45BEGIN
46	self_test_prog = optarg;
47END
48
49OPTION(pidfile,P,FILE,
50       [<set PID file>])
51BEGIN
52	opt_pidfile = optarg;
53END
54
55OPTION(lint,t,,
56       [<check configuration file and exit>])
57BEGIN
58	lint_only = 1;
59END
60
61OPTION(user,u,USER,
62       [<run as this user>])
63BEGIN
64	opt_user = optarg;
65	if (!getpwnam(opt_user)) {
66		diag(LOG_CRIT, "no such user: %s", opt_user);
67		exit(1);
68	}
69END
70
71OPTION(config-help,H,,
72       [<show configuration file summary>])
73BEGIN
74	config_help();
75	exit(0);
76END
77
78
79OPTIONS_END
80
81static int
82print_dir(int flag, const char *dir, void *data)
83{
84	FILE *fp = data;
85	fprintf(fp, "%s\n", dir);
86	return 0;
87}
88
89static void
90help_hook(FILE *fp)
91{
92	fprintf(fp,
93		_("The optional CONFIG argument supplies the name of the "
94		  "configuration file\n"
95	          "to use instead of %s.\n\n"), DEFAULT_CONFFILE);
96	/* TRANSLATORS: %s is one of: inotify, kqueue */
97	fprintf(fp, _("This direvent uses %s interface.\n\n"), INTERFACE);
98
99	if (grecs_include_path_count(GRECS_STD_INCLUDE)) {
100		fprintf(fp, _("Include search path:\n"));
101		grecs_foreach_include_dir(GRECS_STD_INCLUDE, print_dir, fp);
102	} else
103		fprintf(fp, _("No include search path.\n"));
104	fprintf(fp, "\n");
105}
106
107void
108parse_options(int argc, char *argv[], int *index)
109{
110	proginfo.print_help_hook = help_hook;
111	GETOPT(argc, argv, *index)
112}
113