1 |
/* opts-std-startup.c - Standard startup-time command line parser. |
/* opts-std-startup.c - Standard startup-time command line parser. |
2 |
Copyright (C) 1995,96,97,98,99,2001,02,2003 Free Software Foundation, Inc. |
Copyright (C) 1995,96,97,98,99,2001,02,2003,2004,2005 Free Software Foundation, Inc. |
3 |
Written by Miles Bader <miles@gnu.org> and Marcus Brinkmann. |
Written by Miles Bader <miles@gnu.org> and Marcus Brinkmann. |
4 |
|
|
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
25 |
#include "priv.h" |
#include "priv.h" |
26 |
|
|
27 |
|
|
28 |
/* Option keys for long-only options in diskfs_common_options. */ |
/* Option keys for long-only options in argp_option. */ |
29 |
#define OPT_SLACK 600 /* --slack */ |
#define OPT_SLACK 600 /* --slack */ |
30 |
#define OPT_JUMP_DOWN_ON_INPUT 601 /* --jump-down-on-input */ |
#define OPT_JUMP_DOWN_ON_INPUT 601 /* --jump-down-on-input */ |
31 |
#define OPT_NO_JUMP_DOWN_ON_INPUT 602 /* --no-jump-down-on-input */ |
#define OPT_NO_JUMP_DOWN_ON_INPUT 602 /* --no-jump-down-on-input */ |
33 |
#define OPT_NO_JUMP_DOWN_ON_OUTPUT 604 /* --no-jump-down-on-output */ |
#define OPT_NO_JUMP_DOWN_ON_OUTPUT 604 /* --no-jump-down-on-output */ |
34 |
#define OPT_VISUAL_BELL 605 /* --visual-bell */ |
#define OPT_VISUAL_BELL 605 /* --visual-bell */ |
35 |
#define OPT_AUDIBLE_BELL 606 /* --audible-bell */ |
#define OPT_AUDIBLE_BELL 606 /* --audible-bell */ |
36 |
|
#define OPT_MOUSE_SHOW 607 /* --mouse-show-on */ |
37 |
|
#define OPT_MOUSE_HIDE 608 /* --mouse-hide-on */ |
38 |
|
#define OPT_MOUSE_SENS 609 /* --mouse-sensitivity */ |
39 |
|
|
40 |
/* Common value for diskfs_common_options and diskfs_default_sync_interval. */ |
/* The number of records the client is allowed to lag behind the server. */ |
41 |
#define DEFAULT_SLACK 100 |
#define DEFAULT_SLACK 100 |
42 |
#define DEFAULT_SLACK_STRING STRINGIFY(DEFAULT_SLACK) |
#define DEFAULT_SLACK_STRING STRINGIFY(DEFAULT_SLACK) |
43 |
#define STRINGIFY(x) STRINGIFY_1(x) |
#define STRINGIFY(x) STRINGIFY_1(x) |
44 |
#define STRINGIFY_1(x) #x |
#define STRINGIFY_1(x) #x |
45 |
|
|
46 |
|
/* The mouse sensitivity. */ |
47 |
|
#define DEFAULT_MOUSE_SENS 3.0 |
48 |
|
#define DEFAULT_MOUSE_SENS_STRING STRINGIFY(DEFAULT_MOUSE_SENS) |
49 |
|
|
50 |
/* Number of records the client is allowed to lag behind the |
/* Number of records the client is allowed to lag behind the |
51 |
server. */ |
server. */ |
52 |
int _cons_slack = DEFAULT_SLACK; |
int _cons_slack = DEFAULT_SLACK; |
66 |
/* The type of bell used for the audible bell. */ |
/* The type of bell used for the audible bell. */ |
67 |
bell_type_t _cons_audible_bell = BELL_AUDIBLE; |
bell_type_t _cons_audible_bell = BELL_AUDIBLE; |
68 |
|
|
69 |
|
/* The type of events that will make the mouse cursor visible. */ |
70 |
|
int _cons_show_mouse = CONS_EVT_MOUSE_MOVE; |
71 |
|
|
72 |
|
/* The type of events that will hide the mouse cursor. */ |
73 |
|
int _cons_hide_mouse = CONS_EVT_KEYPRESS; |
74 |
|
|
75 |
|
/* The mouse sensitivity. */ |
76 |
|
float _cons_mouse_sens = DEFAULT_MOUSE_SENS; |
77 |
|
|
78 |
static const struct argp_option |
static const struct argp_option |
79 |
startup_options[] = |
startup_options[] = |
80 |
{ |
{ |
92 |
"off, visual, audible" }, |
"off, visual, audible" }, |
93 |
{ "audible-bell", OPT_AUDIBLE_BELL, "BELL", 0, "Audible bell: on (default), " |
{ "audible-bell", OPT_AUDIBLE_BELL, "BELL", 0, "Audible bell: on (default), " |
94 |
"off, visual, audible" }, |
"off, visual, audible" }, |
95 |
|
{ "mouse-show-on", OPT_MOUSE_SHOW, "EVENTS", 0, "One or more of the events" |
96 |
|
" mousemove, mousebutton, keypress, output (default is mousemove), if one" |
97 |
|
" of these events occur the mouse cursor will be made visible" }, |
98 |
|
{ "mouse-hide-on", OPT_MOUSE_HIDE, "EVENTS", 0, "One or more of the events" |
99 |
|
" mousemove, mousebutton, keypress, output (default is keypress), if one" |
100 |
|
" of these events occur the mouse cursor will be hidden " }, |
101 |
|
{ "mouse-sensitivity", OPT_MOUSE_SENS, "SENSITIVITY", 0, "The mouse" |
102 |
|
" sensitivity (default " DEFAULT_MOUSE_SENS_STRING "). A lower value" |
103 |
|
" means more sensitive" }, |
104 |
{ 0, 0 } |
{ 0, 0 } |
105 |
}; |
}; |
106 |
|
|
111 |
static error_t |
static error_t |
112 |
parse_startup_opt (int opt, char *arg, struct argp_state *state) |
parse_startup_opt (int opt, char *arg, struct argp_state *state) |
113 |
{ |
{ |
114 |
|
int parse_events (char *events) |
115 |
|
{ |
116 |
|
char *evtstr = strdupa (events); |
117 |
|
char *tok = strtok (evtstr, ","); |
118 |
|
int evmask = 0; |
119 |
|
|
120 |
|
while (tok) |
121 |
|
{ |
122 |
|
if (!strcasecmp ("mousemove", tok)) |
123 |
|
evmask |= CONS_EVT_MOUSE_MOVE; |
124 |
|
else if (!strcasecmp ("mousebutton", tok)) |
125 |
|
evmask |= CONS_EVT_MOUSE_BUTTON; |
126 |
|
else if (!strcasecmp ("keypress", tok)) |
127 |
|
evmask |= CONS_EVT_KEYPRESS; |
128 |
|
else if (!strcasecmp ("output", tok)) |
129 |
|
evmask |= CONS_EVT_OUTPUT; |
130 |
|
else |
131 |
|
argp_error (state, "The event can be one of: MOUSEMOVE," |
132 |
|
" MOUSEBUTTON, KEYPRESS or OUTPUT"); |
133 |
|
tok = strtok (NULL, ","); |
134 |
|
} |
135 |
|
return evmask; |
136 |
|
} |
137 |
|
|
138 |
switch (opt) |
switch (opt) |
139 |
{ |
{ |
140 |
case OPT_SLACK: |
case OPT_SLACK: |
180 |
argp_error (state, "The visual bell can be one of: on, off, visual, " |
argp_error (state, "The visual bell can be one of: on, off, visual, " |
181 |
"audible"); |
"audible"); |
182 |
break; |
break; |
183 |
|
|
184 |
|
case OPT_MOUSE_SHOW: |
185 |
|
_cons_show_mouse = parse_events (arg); |
186 |
|
break; |
187 |
|
|
188 |
|
case OPT_MOUSE_HIDE: |
189 |
|
_cons_hide_mouse = parse_events (arg); |
190 |
|
break; |
191 |
|
|
192 |
|
case OPT_MOUSE_SENS: |
193 |
|
{ |
194 |
|
char *tail; |
195 |
|
|
196 |
|
errno = 0; |
197 |
|
_cons_mouse_sens = strtod (arg, &tail); |
198 |
|
if (tail == NULL || tail == arg || *tail != '\0') |
199 |
|
argp_error (state, "SENSITIVITY is not a number: %s", arg); |
200 |
|
if (errno) |
201 |
|
argp_error (state, "Overflow in argument SENSITIVITY %s", arg); |
202 |
|
break; |
203 |
|
} |
204 |
|
|
205 |
case ARGP_KEY_ARG: |
case ARGP_KEY_ARG: |
206 |
if (state->arg_num > 0) |
if (state->arg_num > 0) |
207 |
/* Too many arguments. */ |
/* Too many arguments. */ |