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.
|
* 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_DISABLED " (DISABLED AT COMPILE TIME)"
|
||||||
#define WARNING
|
#define WARNING
|
||||||
static const char *usage_text =
|
static const char *usage_text =
|
||||||
@ -363,14 +363,8 @@ static attr_noret void usage(int ret) {
|
|||||||
fputs(usage_text, f);
|
fputs(usage_text, f);
|
||||||
#undef WARNING
|
#undef WARNING
|
||||||
#undef WARNING_DISABLED
|
#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 char *shortopts = "D:I:O:d:r:o:m:l:t:i:e:hscnfFCaSzGb";
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"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},
|
{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;
|
int o = 0, longopt_idx = -1;
|
||||||
|
|
||||||
if (first_pass) {
|
|
||||||
// Pre-parse the commandline arguments to check for --config and invalid
|
// Pre-parse the commandline arguments to check for --config and invalid
|
||||||
// switches
|
// switches
|
||||||
// Must reset optind to 0 here in case we reread the commandline
|
// Must reset optind to 0 here in case we reread the commandline
|
||||||
// arguments
|
// arguments
|
||||||
optind = 1;
|
optind = 1;
|
||||||
while (-1 !=
|
while (-1 != (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
||||||
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
if (o == 256)
|
||||||
if (256 == o)
|
*config_file = strdup(optarg);
|
||||||
ps->o.config_file = strdup(optarg);
|
else if (o == 'd') {
|
||||||
else if ('d' == o) {
|
|
||||||
log_warn("-d will be ignored, please use the DISPLAY "
|
log_warn("-d will be ignored, please use the DISPLAY "
|
||||||
"environment variable");
|
"environment variable");
|
||||||
} else if (314 == o)
|
} else if (o == 314) {
|
||||||
ps->o.show_all_xerrors = true;
|
*all_xerrors = true;
|
||||||
else if (318 == o) {
|
} else if (o == 318) {
|
||||||
printf("%s\n", COMPTON_VERSION);
|
printf("%s\n", COMPTON_VERSION);
|
||||||
exit(0);
|
*exit_code = 0;
|
||||||
} else if (320 == o) {
|
return true;
|
||||||
|
} else if (o == 'S') {
|
||||||
|
log_warn("-S will be ignored");
|
||||||
|
} else if (o == 320) {
|
||||||
log_warn("--no-name-pixmap will be ignored");
|
log_warn("--no-name-pixmap will be ignored");
|
||||||
} else if ('?' == o || ':' == o)
|
} else if (o == '?' || o == ':') {
|
||||||
usage(1);
|
usage(1);
|
||||||
|
*exit_code = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for abundant positional arguments
|
// Check for abundant positional arguments
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
log_fatal("compton doesn't accept positional arguments.");
|
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;
|
bool shadow_enable = false, fading_enable = false;
|
||||||
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
|
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
|
||||||
|
|
||||||
|
@ -8,7 +8,12 @@
|
|||||||
|
|
||||||
typedef struct session session_t;
|
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.
|
* 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;
|
ps->ignore_tail = &ps->ignore_head;
|
||||||
gettimeofday(&ps->time_start, NULL);
|
gettimeofday(&ps->time_start, NULL);
|
||||||
|
|
||||||
// First pass
|
int exit_code;
|
||||||
get_cfg(ps, argc, argv, true);
|
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
|
// Inherit old Display if possible, primarily for resource leak checking
|
||||||
if (ps_old && ps_old->dpy)
|
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);
|
xcb_xfixes_query_version(ps->c, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION).sequence);
|
||||||
|
|
||||||
// Second pass
|
// Second pass
|
||||||
get_cfg(ps, argc, argv, false);
|
get_cfg(ps, argc, argv);
|
||||||
|
|
||||||
rebuild_shadow_exclude_reg(ps);
|
rebuild_shadow_exclude_reg(ps);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user