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:
Yuxuan Shui 2018-12-20 23:58:47 +00:00
parent 9b121447b9
commit 2a2958b68d
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 147 additions and 130 deletions

View File

@ -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,16 +363,10 @@ 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[] = {
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'},
{"config", required_argument, NULL, 256},
{"shadow-radius", required_argument, NULL, 'r'},
@ -462,40 +456,55 @@ void get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{"diagnostics", no_argument, NULL, 801},
// Must terminate with a NULL entry
{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));

View File

@ -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);

View File

@ -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);