From: Guyzmo Date: Thu, 12 Jan 2017 01:14:21 +0000 (+0100) Subject: Support of multiple config files as CLI arguments X-Git-Tag: neomutt-20170128~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83f7558efab3dcd7b7e227a727ef95f711363f50;p=neomutt Support of multiple config files as CLI arguments - changed the Muttrc global to a LIST* - set it up to parse in order of parsing - updated AliasFile to be a LIST* as well Closes #234 --- diff --git a/alias.c b/alias.c index 0091ac792..7d9a2b8aa 100644 --- a/alias.c +++ b/alias.c @@ -344,49 +344,53 @@ retry_name: else Aliases = new; - strfcpy (buf, NONULL (AliasFile), sizeof (buf)); - if (mutt_get_field (_("Save to file: "), buf, sizeof (buf), MUTT_FILE) != 0) - return; - mutt_expand_path (buf, sizeof (buf)); - if ((rc = fopen (buf, "a+"))) + for (LIST *AliasFile = AliasFiles; AliasFile != NULL; + AliasFile = AliasFile->next) { - /* terminate existing file with \n if necessary */ - if (fseek (rc, 0, SEEK_END)) - goto fseek_err; - if (ftell(rc) > 0) + strfcpy(buf, NONULL(AliasFile->data), sizeof(buf)); + if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), MUTT_FILE) != 0) + return; + mutt_expand_path(buf, sizeof(buf)); + if ((rc = fopen(buf, "a+"))) { - if (fseek (rc, -1, SEEK_CUR) < 0) - goto fseek_err; - if (fread(buf, 1, 1, rc) != 1) + /* terminate existing file with \n if necessary */ + if (fseek(rc, 0, SEEK_END)) + goto fseek_err; + if (ftell(rc) > 0) { - mutt_perror (_("Error reading alias file")); - safe_fclose (&rc); - return; + if (fseek(rc, -1, SEEK_CUR) < 0) + goto fseek_err; + if (fread(buf, 1, 1, rc) != 1) + { + mutt_perror(_("Error reading alias file")); + safe_fclose(&rc); + return; + } + if (fseek(rc, 0, SEEK_END) < 0) + goto fseek_err; + if (buf[0] != '\n') + fputc('\n', rc); } - if (fseek (rc, 0, SEEK_END) < 0) - goto fseek_err; - if (buf[0] != '\n') - fputc ('\n', rc); - } - if (mutt_check_alias_name (new->name, NULL, 0)) - mutt_quote_filename (buf, sizeof (buf), new->name); - else - strfcpy (buf, new->name, sizeof (buf)); - recode_buf (buf, sizeof (buf)); - fprintf (rc, "alias %s ", buf); - buf[0] = 0; - rfc822_write_address (buf, sizeof (buf), new->addr, 0); - recode_buf (buf, sizeof (buf)); - write_safe_address (rc, buf); - fputc ('\n', rc); - if (safe_fsync_close(&rc) != 0) - mutt_message ("Trouble adding alias: %s.", strerror(errno)); + if (mutt_check_alias_name(new->name, NULL, 0)) + mutt_quote_filename(buf, sizeof(buf), new->name); + else + strfcpy(buf, new->name, sizeof(buf)); + recode_buf(buf, sizeof(buf)); + fprintf(rc, "alias %s ", buf); + buf[0] = 0; + rfc822_write_address(buf, sizeof(buf), new->addr, 0); + recode_buf(buf, sizeof(buf)); + write_safe_address(rc, buf); + fputc('\n', rc); + if (safe_fsync_close(&rc) != 0) + mutt_message("Trouble adding alias: %s.", strerror(errno)); + else + mutt_message(_("Alias added.")); + } else - mutt_message (_("Alias added.")); + mutt_perror(buf); } - else - mutt_perror (buf); return; diff --git a/globals.h b/globals.h index 9be77dbbd..cf9b6d501 100644 --- a/globals.h +++ b/globals.h @@ -31,7 +31,7 @@ WHERE char *MuttDotlock; WHERE ADDRESS *EnvFrom; WHERE ADDRESS *From; -WHERE char *AliasFile; +WHERE LIST *AliasFiles; WHERE char *AliasFmt; WHERE char *AssumedCharset; WHERE char *AttachSep; @@ -98,7 +98,7 @@ WHERE char *Mixmaster; WHERE char *MixEntryFormat; #endif -WHERE char *Muttrc INITVAL (NULL); +WHERE LIST *Muttrc INITVAL (0); #ifdef USE_NNTP WHERE char *GroupFormat; WHERE char *Inews; diff --git a/init.c b/init.c index c500e182b..a920ef82b 100644 --- a/init.c +++ b/init.c @@ -3712,26 +3712,31 @@ void mutt_init (int skip_sys_rc, LIST *commands) xdg_cfg_home = buffer; } - Muttrc = mutt_find_cfg (Homedir, xdg_cfg_home); + char *config = mutt_find_cfg (Homedir, xdg_cfg_home); + if (config) + Muttrc = mutt_add_list (Muttrc, config); } else { - strfcpy (buffer, Muttrc, sizeof (buffer)); - FREE (&Muttrc); - mutt_expand_path (buffer, sizeof (buffer)); - Muttrc = safe_strdup (buffer); - if (access (Muttrc, F_OK)) + for (LIST *config = Muttrc; config != NULL; config = config->next) { - snprintf (buffer, sizeof (buffer), "%s: %s", Muttrc, strerror (errno)); - mutt_endwin (buffer); - exit (1); + strfcpy(buffer, config->data, sizeof(buffer)); + FREE(&config->data); + mutt_expand_path(buffer, sizeof(buffer)); + config->data = safe_strdup(buffer); + if (access(config->data, F_OK)) + { + snprintf(buffer, sizeof(buffer), "%s: %s", config->data, strerror(errno)); + mutt_endwin(buffer); + exit(1); + } } } if (Muttrc) { - FREE (&AliasFile); - AliasFile = safe_strdup (Muttrc); + FREE (&AliasFiles); + AliasFiles = mutt_copy_list(Muttrc); } /* Process the global rc file if it exists and the user hasn't explicity @@ -3785,15 +3790,18 @@ void mutt_init (int skip_sys_rc, LIST *commands) } /* Read the user's initialization file. */ - if (Muttrc) + for (LIST *config = Muttrc; config != NULL; config = config->next) { - if (!option (OPTNOCURSES)) - endwin (); - if (source_rc (Muttrc, &err) != 0) + if (config->data) { - fputs (err.data, stderr); - fputc ('\n', stderr); - need_pause = 1; + if (!option(OPTNOCURSES)) + endwin(); + if (source_rc(config->data, &err) != 0) + { + fputs(err.data, stderr); + fputc('\n', stderr); + need_pause = 1; + } } } diff --git a/init.h b/init.h index 2eb3d1ed7..495da23ed 100644 --- a/init.h +++ b/init.h @@ -123,7 +123,7 @@ struct option_t MuttVars[] = { ** check only happens after the \fIfirst\fP edit of the file). When set ** to \fIno\fP, composition will never be aborted. */ - { "alias_file", DT_PATH, R_NONE, UL &AliasFile, UL "~/.muttrc" }, + { "alias_file", DT_PATH, R_NONE, UL &AliasFiles, UL "~/.muttrc" }, /* ** .pp ** The default file in which to save aliases created by the diff --git a/main.c b/main.c index 472c318b6..7c239246e 100644 --- a/main.c +++ b/main.c @@ -278,7 +278,8 @@ int main (int argc, char **argv, char **environ) break; case 'F': - mutt_str_replace (&Muttrc, optarg); + // mutt_str_replace (&Muttrc, optarg); + Muttrc = mutt_add_list (Muttrc, optarg); break; case 'f':