Allow setting configuration file via commandline

This commit is contained in:
Dale Weiler 2012-12-18 05:22:23 +00:00
parent ed4213d403
commit 2587aed697
3 changed files with 20 additions and 14 deletions

View file

@ -882,6 +882,7 @@ bool opts_setoptim(const char *, bool);
void opts_init (const char *, int, size_t);
void opts_set (uint32_t *, size_t, bool);
void opts_setoptimlevel(unsigned int);
void opts_ini_init (const char *);
enum {
# define GMQCC_TYPE_FLAGS

6
main.c
View file

@ -138,6 +138,7 @@ static bool options_parse(int argc, char **argv) {
char buffer[1024];
char *redirout = (char*)stdout;
char *redirerr = (char*)stderr;
char *config = NULL;
while (!argend && argc > 1) {
char *argarg;
@ -195,6 +196,10 @@ static bool options_parse(int argc, char **argv) {
con_change(redirout, redirerr);
continue;
}
if (options_long_gcc("config", &argc, &argv, &argarg)) {
config = argarg;
continue;
}
/* show defaults (like pathscale) */
if (!strcmp(argv[0]+1, "show-defaults")) {
@ -437,6 +442,7 @@ static bool options_parse(int argc, char **argv) {
vec_push(items, item);
}
}
opts_ini_init(config);
return true;
}

27
opts.c
View file

@ -25,7 +25,6 @@
unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
opts_cmd_t opts; /* command lien options */
static void opts_ini_init();
static void opts_setdefault() {
memset(&opts, 0, sizeof(opts_cmd_t));
@ -63,8 +62,6 @@ void opts_init(const char *output, int standard, size_t arraysize) {
opts.output = output;
opts.standard = standard;
opts.max_array_size = arraysize;
opts_ini_init();
}
static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) {
@ -299,23 +296,25 @@ static char *opts_ini_load(const char *section, const char *name, const char *va
* Actual loading subsystem, this finds the ini or cfg file, and properly
* loads it and executes it to set compiler options.
*/
static void opts_ini_init() {
void opts_ini_init(const char *file) {
/*
* Possible matches are:
* gmqcc.ini
* gmqcc.cfg
*/
char *error;
size_t line;
FILE *ini;
char *file;
char *error;
size_t line;
FILE *ini;
/* try ini */
if (!(ini = fopen((file = "gmqcc.ini"), "r")))
/* try cfg */
if (!(ini = fopen((file = "gmqcc.cfg"), "r")))
return;
if (!file) {
/* try ini */
if (!(ini = fopen((file = "gmqcc.ini"), "r")))
/* try cfg */
if (!(ini = fopen((file = "gmqcc.cfg"), "r")))
return;
} else if (!(ini = fopen(file, "r")))
return;
con_out("found ini file `%s`\n", file);