Split the first and second pass of get_cfg
They are not separate functions Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
9b121447b9
commit
2a2958b68d
|
@ -13,7 +13,7 @@
|
|||
/**
|
||||
* Print usage text and exit.
|
||||
*/
|
||||
static attr_noret void usage(int ret) {
|
||||
static void usage(int ret) {
|
||||
#define WARNING_DISABLED " (DISABLED AT COMPILE TIME)"
|
||||
#define WARNING
|
||||
static const char *usage_text =
|
||||
|
@ -363,14 +363,8 @@ static attr_noret void usage(int ret) {
|
|||
fputs(usage_text, f);
|
||||
#undef WARNING
|
||||
#undef WARNING_DISABLED
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process arguments and configuration files.
|
||||
*/
|
||||
void get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||
static const char *shortopts = "D:I:O:d:r:o:m:l:t:i:e:hscnfFCaSzGb";
|
||||
static const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
|
@ -464,39 +458,54 @@ void get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
|||
{NULL, 0, NULL, 0},
|
||||
};
|
||||
|
||||
/// Get config options that are needed to parse the rest of the options
|
||||
/// Return true if we should quit
|
||||
bool get_early_config(int argc, char *const *argv, char **config_file, bool *all_xerrors,
|
||||
int *exit_code) {
|
||||
int o = 0, longopt_idx = -1;
|
||||
|
||||
if (first_pass) {
|
||||
// Pre-parse the commandline arguments to check for --config and invalid
|
||||
// switches
|
||||
// Must reset optind to 0 here in case we reread the commandline
|
||||
// arguments
|
||||
optind = 1;
|
||||
while (-1 !=
|
||||
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
||||
if (256 == o)
|
||||
ps->o.config_file = strdup(optarg);
|
||||
else if ('d' == o) {
|
||||
while (-1 != (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
||||
if (o == 256)
|
||||
*config_file = strdup(optarg);
|
||||
else if (o == 'd') {
|
||||
log_warn("-d will be ignored, please use the DISPLAY "
|
||||
"environment variable");
|
||||
} else if (314 == o)
|
||||
ps->o.show_all_xerrors = true;
|
||||
else if (318 == o) {
|
||||
} else if (o == 314) {
|
||||
*all_xerrors = true;
|
||||
} else if (o == 318) {
|
||||
printf("%s\n", COMPTON_VERSION);
|
||||
exit(0);
|
||||
} else if (320 == o) {
|
||||
*exit_code = 0;
|
||||
return true;
|
||||
} else if (o == 'S') {
|
||||
log_warn("-S will be ignored");
|
||||
} else if (o == 320) {
|
||||
log_warn("--no-name-pixmap will be ignored");
|
||||
} else if ('?' == o || ':' == o)
|
||||
} else if (o == '?' || o == ':') {
|
||||
usage(1);
|
||||
*exit_code = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for abundant positional arguments
|
||||
if (optind < argc)
|
||||
log_fatal("compton doesn't accept positional arguments.");
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process arguments and configuration files.
|
||||
*/
|
||||
void get_cfg(session_t *ps, int argc, char *const *argv) {
|
||||
|
||||
int o = 0, longopt_idx = -1;
|
||||
|
||||
bool shadow_enable = false, fading_enable = false;
|
||||
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
|
||||
|
||||
|
|
|
@ -8,7 +8,12 @@
|
|||
|
||||
typedef struct session session_t;
|
||||
|
||||
/// Get config options that are needed to parse the rest of the options
|
||||
/// Return true if we should quit
|
||||
bool get_early_config(int argc, char *const *argv, char **config_file, bool *all_xerrors,
|
||||
int *exit_code);
|
||||
|
||||
/**
|
||||
* Process arguments and configuration files.
|
||||
*/
|
||||
void get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass);
|
||||
void get_cfg(session_t *ps, int argc, char *const *argv);
|
||||
|
|
|
@ -2730,8 +2730,11 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
|||
ps->ignore_tail = &ps->ignore_head;
|
||||
gettimeofday(&ps->time_start, NULL);
|
||||
|
||||
// First pass
|
||||
get_cfg(ps, argc, argv, true);
|
||||
int exit_code;
|
||||
if (get_early_config(argc, argv, &ps->o.config_file, &ps->o.show_all_xerrors,
|
||||
&exit_code)) {
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
// Inherit old Display if possible, primarily for resource leak checking
|
||||
if (ps_old && ps_old->dpy)
|
||||
|
@ -2828,7 +2831,7 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
|||
xcb_xfixes_query_version(ps->c, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION).sequence);
|
||||
|
||||
// Second pass
|
||||
get_cfg(ps, argc, argv, false);
|
||||
get_cfg(ps, argc, argv);
|
||||
|
||||
rebuild_shadow_exclude_reg(ps);
|
||||
|
||||
|
|
Loading…
Reference in New Issue