]> git.ozlabs.org Git - petitboot/blob - ui/twin/pbt-main.c
ui: Fix typo: 'deamon' -> 'daemon'
[petitboot] / ui / twin / pbt-main.c
1 /*
2  *  Copyright Geoff Levand <geoff@infradead.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <stdio.h>
23 #include <getopt.h>
24
25 #include "pbt-main.h"
26
27 void pbt_print_version(void)
28 {
29         printf("petitboot-twin (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
30 }
31
32 void pbt_print_usage(void)
33 {
34         pbt_print_version();
35         printf(
36 "Usage: petitboot-twin [-h, --help] [-l, --log log-file]\n"
37 "                      [-r, --reset-defaults] [-s, --start-daemon]\n"
38 "                      [-t, --timeout] [-V, --version]\n"
39 "                      [[-f --fbdev] | [-x --x11]]\n");
40 }
41
42 /**
43  * pbt_opts_parse - Parse the command line options.
44  */
45
46 int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
47 {
48         static const struct option long_options[] = {
49                 {"fbdev",          no_argument,       NULL, 'f'},
50                 {"help",           no_argument,       NULL, 'h'},
51                 {"log",            required_argument, NULL, 'l'},
52                 {"reset-defaults", no_argument,       NULL, 'r'},
53                 {"start-daemon",   no_argument,       NULL, 's'},
54                 {"timeout",        no_argument,       NULL, 't'},
55                 {"version",        no_argument,       NULL, 'V'},
56                 {"x11",            no_argument,       NULL, 'x'},
57                 { NULL, 0, NULL, 0},
58         };
59         static const char short_options[] = "dfhl:strVx";
60         static const struct pbt_opts default_values = {
61                 .backend = pbt_twin_x11,
62                 .log_file = "/var/log/petitboot/petitboot-twin.log",
63         };
64
65         *opts = default_values;
66
67         while (1) {
68                 int c = getopt_long(argc, argv, short_options, long_options,
69                         NULL);
70
71                 if (c == EOF)
72                         break;
73
74                 switch (c) {
75                 case 'f':
76                         opts->backend = pbt_twin_fbdev;
77                         break;
78                 case 'h':
79                         opts->show_help = pbt_opt_yes;
80                         break;
81                 case 'l':
82                         opts->log_file = optarg;
83                         break;
84                 case 's':
85                         opts->start_daemon = pbt_opt_yes;
86                         break;
87                 case 't':
88                         opts->use_timeout = pbt_opt_yes;
89                         break;
90                 case 'r':
91                         opts->reset_defaults = pbt_opt_yes;
92                         break;
93                 case 'V':
94                         opts->show_version = pbt_opt_yes;
95                         break;
96                 case 'x':
97                         opts->backend = pbt_twin_x11;
98                         break;
99                 default:
100                         opts->show_help = pbt_opt_yes;
101                         return -1;
102                 }
103         }
104
105         return optind != argc;
106 }