summaryrefslogtreecommitdiffstats
path: root/ui/twin/pbt-main.c
blob: cf546625090f8305e43fd777c42cbec2cfe45fe8 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 *  Copyright Geoff Levand <geoff@infradead.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif

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

#include "pbt-main.h"

void pbt_print_version(void)
{
	printf("petitboot-twin (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
}

void pbt_print_usage(void)
{
	pbt_print_version();
	printf(
"Usage: petitboot-twin [-h, --help] [-l, --log log-file]\n"
"                      [-r, --reset-defaults] [-s, --start-daemon]\n"
"                      [-t, --timeout] [-V, --version]\n"
"                      [[-f --fbdev] | [-x --x11]]\n");
}

/**
 * pbt_opts_parse - Parse the command line options.
 */

int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
{
	static const struct option long_options[] = {
		{"fbdev",          no_argument,       NULL, 'f'},
		{"help",           no_argument,       NULL, 'h'},
		{"log",            required_argument, NULL, 'l'},
		{"reset-defaults", no_argument,       NULL, 'r'},
		{"start-daemon",   no_argument,       NULL, 's'},
		{"timeout",        no_argument,       NULL, 't'},
		{"version",        no_argument,       NULL, 'V'},
		{"x11",            no_argument,       NULL, 'x'},
		{ NULL, 0, NULL, 0},
	};
	static const char short_options[] = "dfhl:strVx";
	static const struct pbt_opts default_values = {
		.backend = pbt_twin_x11,
		.log_file = "/var/log/petitboot/petitboot-twin.log",
	};

	*opts = default_values;

	while (1) {
		int c = getopt_long(argc, argv, short_options, long_options,
			NULL);

		if (c == EOF)
			break;

		switch (c) {
		case 'f':
			opts->backend = pbt_twin_fbdev;
			break;
		case 'h':
			opts->show_help = pbt_opt_yes;
			break;
		case 'l':
			opts->log_file = optarg;
			break;
		case 's':
			opts->start_daemon = pbt_opt_yes;
			break;
		case 't':
			opts->use_timeout = pbt_opt_yes;
			break;
		case 'r':
			opts->reset_defaults = pbt_opt_yes;
			break;
		case 'V':
			opts->show_version = pbt_opt_yes;
			break;
		case 'x':
			opts->backend = pbt_twin_x11;
			break;
		default:
			opts->show_help = pbt_opt_yes;
			return -1;
		}
	}

	return optind != argc;
}
OpenPOWER on IntegriCloud