Skip to content

Commit

Permalink
config: misc files
Browse files Browse the repository at this point in the history
Eliminate Config global variables from the remaining source files.
  • Loading branch information
flatcap committed Mar 24, 2021
1 parent 240e059 commit 2d26a9d
Show file tree
Hide file tree
Showing 36 changed files with 303 additions and 274 deletions.
3 changes: 2 additions & 1 deletion command_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
}

mutt_buffer_strcpy(&m->pathbuf, buf->data);
/* int rc = */ mx_path_canon2(m, C_Folder);
const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
/* int rc = */ mx_path_canon2(m, c_folder);

if (m->type <= MUTT_UNKNOWN)
{
Expand Down
5 changes: 2 additions & 3 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,6 @@ void mutt_print_message(struct Mailbox *m, struct EmailList *el)
int mutt_select_sort(bool reverse)
{
const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
enum SortType method = c_sort; /* save the current method in case of abort */
enum SortType new_sort = c_sort;

switch (mutt_multi_choice(reverse ?
Expand Down Expand Up @@ -857,7 +856,7 @@ int mutt_select_sort(bool reverse)
new_sort |= SORT_REVERSE;

cs_subset_str_native_set(NeoMutt->sub, "sort", new_sort, NULL);
return (c_sort != method) ? 0 : -1; /* no need to resort if it's the same */
return (new_sort != c_sort) ? 0 : -1; /* no need to resort if it's the same */
}

/**
Expand All @@ -875,7 +874,7 @@ bool mutt_shell_escape(void)
return false;
}

const char *c_shell = cs_subset_string(NeoMutt->sub, "shell");
const char *const c_shell = cs_subset_string(NeoMutt->sub, "shell");
if ((buf[0] == '\0') && c_shell)
mutt_str_copy(buf, c_shell, sizeof(buf));
if (buf[0] == '\0')
Expand Down
13 changes: 8 additions & 5 deletions complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <string.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "mutt_globals.h"
#include "muttlib.h"
Expand All @@ -56,7 +57,7 @@
*/
int mutt_complete(char *buf, size_t buflen)
{
char *p = NULL;
const char *p = NULL;
DIR *dirp = NULL;
struct dirent *de = NULL;
int init = 0;
Expand All @@ -77,15 +78,17 @@ int mutt_complete(char *buf, size_t buflen)
return nntp_complete(buf, buflen);
#endif

const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
#ifdef USE_IMAP
imap_path = mutt_buffer_pool_get();
/* we can use '/' as a delimiter, imap_complete rewrites it */
if ((*buf == '=') || (*buf == '+') || (*buf == '!'))
{
if (*buf == '!')
p = NONULL(C_SpoolFile);
p = NONULL(c_spool_file);
else
p = NONULL(C_Folder);
p = NONULL(c_folder);

mutt_buffer_concat_path(imap_path, p, buf + 1);
}
Expand All @@ -111,9 +114,9 @@ int mutt_complete(char *buf, size_t buflen)
{
mutt_buffer_addch(dirpart, *buf);
if (*buf == '!')
mutt_buffer_strcpy(exp_dirpart, NONULL(C_SpoolFile));
mutt_buffer_strcpy(exp_dirpart, NONULL(c_spool_file));
else
mutt_buffer_strcpy(exp_dirpart, NONULL(C_Folder));
mutt_buffer_strcpy(exp_dirpart, NONULL(c_folder));
p = strrchr(buf, '/');
if (p)
{
Expand Down
5 changes: 3 additions & 2 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void ctx_update(struct Context *ctx)
}
e->msgno = msgno;

const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
if (e->env->supersedes)
{
struct Email *e2 = NULL;
Expand All @@ -165,7 +166,7 @@ void ctx_update(struct Context *ctx)
if (e2)
{
e2->superseded = true;
if (C_Score)
if (c_score)
mutt_score_message(ctx->mailbox, e2, true);
}
}
Expand All @@ -177,7 +178,7 @@ void ctx_update(struct Context *ctx)
mutt_hash_insert(m->subj_hash, e->env->real_subj, e);
mutt_label_hash_add(m, e);

if (C_Score)
if (c_score)
mutt_score_message(ctx->mailbox, e, false);

if (e->changed)
Expand Down
10 changes: 7 additions & 3 deletions copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end,
if (chflags & (CH_DECODE | CH_PREFIX))
{
const char *pre = (chflags & CH_PREFIX) ? prefix : NULL;
wraplen = mutt_window_wrap_cols(wraplen, C_Wrap);
const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
wraplen = mutt_window_wrap_cols(wraplen, c_wrap);

if (mutt_write_one_header(fp_out, 0, *hp, pre, wraplen, chflags, NeoMutt->sub) == -1)
{
Expand Down Expand Up @@ -629,11 +630,14 @@ int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e,

if (cmflags & MUTT_CM_PREFIX)
{
if (C_TextFlowed)
const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
if (c_text_flowed)
mutt_str_copy(prefix, ">", sizeof(prefix));
else
{
mutt_make_string(prefix, sizeof(prefix), wraplen, NONULL(C_IndentString),
const char *const c_indent_string =
cs_subset_string(NeoMutt->sub, "indent_string");
mutt_make_string(prefix, sizeof(prefix), wraplen, NONULL(c_indent_string),
Context->mailbox, -1, e, MUTT_FORMAT_NO_FLAGS, NULL);
}
}
Expand Down
6 changes: 4 additions & 2 deletions editmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
goto bail;
}

mutt_edit_file(NONULL(C_Editor), mutt_buffer_string(fname));
const char *const c_editor = cs_subset_string(NeoMutt->sub, "editor");
mutt_edit_file(NONULL(c_editor), mutt_buffer_string(fname));

rc = stat(mutt_buffer_string(fname), &sb);
if (rc == -1)
Expand Down Expand Up @@ -257,7 +258,8 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
mutt_set_flag(m, e, MUTT_PURGE, true);
mutt_set_flag(m, e, MUTT_READ, true);

if (C_DeleteUntag)
const bool c_delete_untag = cs_subset_bool(NeoMutt->sub, "delete_untag");
if (c_delete_untag)
mutt_set_flag(m, e, MUTT_TAG, false);
}
else if (rc == -1)
Expand Down
4 changes: 3 additions & 1 deletion enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags fl
if (state->curpos == 0)
{
// Pressing backspace when no text is in the command prompt should exit the prompt
if (C_AbortBackspace && (state->lastchar == 0))
const bool c_abort_backspace =
cs_subset_bool(NeoMutt->sub, "abort_backspace");
if (c_abort_backspace && (state->lastchar == 0))
goto bye;
// Pressing backspace with text in the command prompt should just beep
mutt_beep(false);
Expand Down
6 changes: 4 additions & 2 deletions flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void mutt_set_flag_update(struct Mailbox *m, struct Email *e,

if (bf)
{
if (!e->deleted && !m->readonly && (!e->flagged || !C_FlagSafe))
const bool c_flag_safe = cs_subset_bool(NeoMutt->sub, "flag_safe");
if (!e->deleted && !m->readonly && (!e->flagged || !c_flag_safe))
{
e->deleted = true;
update = true;
Expand Down Expand Up @@ -378,7 +379,8 @@ int mutt_thread_set_flag(struct Mailbox *m, struct Email *e,
struct MuttThread *start = NULL;
struct MuttThread *cur = e->thread;

if ((C_Sort & SORT_MASK) != SORT_THREADS)
const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
if ((c_sort & SORT_MASK) != SORT_THREADS)
{
mutt_error(_("Threading is not enabled"));
return -1;
Expand Down
9 changes: 6 additions & 3 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <string.h>
#include <wchar.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "pager/lib.h"
#include "functions.h"
Expand Down Expand Up @@ -247,9 +248,10 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2,
col = pad(fp, mutt_strwidth(t1), col_a);
}

const char *const c_pager = cs_subset_string(NeoMutt->sub, "pager");
if (ismacro > 0)
{
if (!C_Pager || mutt_str_equal(C_Pager, "builtin"))
if (!c_pager || mutt_str_equal(c_pager, "builtin"))
fputs("_\010", fp); // Ctrl-H (backspace)
fputs("M ", fp);
col += 2;
Expand Down Expand Up @@ -289,10 +291,11 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2,

if (*t3)
{
if (mutt_str_equal(C_Pager, "builtin"))
if (mutt_str_equal(c_pager, "builtin"))
{
n += col - wraplen;
if (C_Markers)
const bool c_markers = cs_subset_bool(NeoMutt->sub, "markers");
if (c_markers)
n++;
}
else
Expand Down
31 changes: 17 additions & 14 deletions hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
#include "compmbox/lib.h"
#endif

/* These Config Variables are only used in hook.c */
char *C_DefaultHook; ///< Config: Pattern to use for hooks that only have a simple regex
bool C_ForceName; ///< Config: Save outgoing mail in a folder of their name
bool C_SaveName; ///< Config: Save outgoing message to mailbox of recipient's name if it exists

/**
* struct Hook - A list of user hooks
*/
Expand Down Expand Up @@ -133,6 +128,8 @@ enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s,
goto cleanup;
}

const char *const c_default_hook =
cs_subset_string(NeoMutt->sub, "default_hook");
if (data & (MUTT_FOLDER_HOOK | MUTT_MBOX_HOOK))
{
/* Accidentally using the ^ mailbox shortcut in the .neomuttrc is a
Expand Down Expand Up @@ -169,14 +166,14 @@ enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s,
}
}
#endif
else if (C_DefaultHook && (~data & MUTT_GLOBAL_HOOK) &&
else if (c_default_hook && (~data & MUTT_GLOBAL_HOOK) &&
!(data & (MUTT_CHARSET_HOOK | MUTT_ICONV_HOOK | MUTT_ACCOUNT_HOOK)) &&
(!WithCrypto || !(data & MUTT_CRYPT_HOOK)))
{
/* At this stage remain only message-hooks, reply-hooks, send-hooks,
* send2-hooks, save-hooks, and fcc-hooks: All those allowing full
* patterns. If given a simple regex, we expand $default_hook. */
mutt_check_simple(pattern, C_DefaultHook);
mutt_check_simple(pattern, c_default_hook);
}

if (data & (MUTT_MBOX_HOOK | MUTT_SAVE_HOOK | MUTT_FCC_HOOK))
Expand Down Expand Up @@ -393,8 +390,10 @@ enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s,
goto out;
}

if (C_DefaultHook)
mutt_check_simple(pattern, C_DefaultHook);
const char *const c_default_hook =
cs_subset_string(NeoMutt->sub, "default_hook");
if (c_default_hook)
mutt_check_simple(pattern, c_default_hook);

/* check to make sure that a matching hook doesn't already exist */
struct Hook *hook = NULL;
Expand Down Expand Up @@ -699,18 +698,22 @@ void mutt_select_fcc(struct Buffer *path, struct Email *e)
const struct Address *to = TAILQ_FIRST(&e->env->to);
const struct Address *cc = TAILQ_FIRST(&e->env->cc);
const struct Address *bcc = TAILQ_FIRST(&e->env->bcc);
if ((C_SaveName || C_ForceName) && (to || cc || bcc))
const bool c_save_name = cs_subset_bool(NeoMutt->sub, "save_name");
const bool c_force_name = cs_subset_bool(NeoMutt->sub, "force_name");
const char *const c_record = cs_subset_string(NeoMutt->sub, "record");
if ((c_save_name || c_force_name) && (to || cc || bcc))
{
const struct Address *addr = to ? to : (cc ? cc : bcc);
struct Buffer *buf = mutt_buffer_pool_get();
mutt_safe_path(buf, addr);
mutt_buffer_concat_path(path, NONULL(C_Folder), mutt_buffer_string(buf));
const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
mutt_buffer_concat_path(path, NONULL(c_folder), mutt_buffer_string(buf));
mutt_buffer_pool_release(&buf);
if (!C_ForceName && (mx_access(mutt_buffer_string(path), W_OK) != 0))
mutt_buffer_strcpy(path, C_Record);
if (!c_force_name && (mx_access(mutt_buffer_string(path), W_OK) != 0))
mutt_buffer_strcpy(path, c_record);
}
else
mutt_buffer_strcpy(path, C_Record);
mutt_buffer_strcpy(path, c_record);
}
else
mutt_buffer_fix_dptr(path);
Expand Down
5 changes: 0 additions & 5 deletions hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ struct Email;
struct ListHead;
struct Mailbox;

/* These Config Variables are only used in hook.c */
extern char *C_DefaultHook;
extern bool C_ForceName;
extern bool C_SaveName;

typedef uint32_t HookFlags; ///< Flags for mutt_parse_hook(), e.g. #MUTT_FOLDER_HOOK
#define MUTT_HOOK_NO_FLAGS 0 ///< No flags are set
#define MUTT_FOLDER_HOOK (1 << 0) ///< folder-hook: when entering a mailbox
Expand Down
6 changes: 3 additions & 3 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static bool get_hostname(struct ConfigSet *cs)
const char *short_host = NULL;
struct utsname utsname;

const char *c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
if (c_hostname)
{
short_host = c_hostname;
Expand Down Expand Up @@ -810,7 +810,7 @@ int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
env_ed = "vi";
cs_str_initial_set(cs, "editor", env_ed, NULL);

const char *c_editor = cs_subset_string(NeoMutt->sub, "editor");
const char *const c_editor = cs_subset_string(NeoMutt->sub, "editor");
if (!c_editor)
cs_str_reset(cs, "editor", NULL);

Expand Down Expand Up @@ -956,7 +956,7 @@ int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
goto done; // TEST14: neomutt -e broken (press 'q')
}

const char *c_tmpdir = cs_subset_path(NeoMutt->sub, "tmpdir");
const char *const c_tmpdir = cs_subset_path(NeoMutt->sub, "tmpdir");
mutt_file_mkdir(c_tmpdir, S_IRWXU);

mutt_hist_init();
Expand Down
8 changes: 5 additions & 3 deletions keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ int km_dokey(enum MenuType menu)

while (true)
{
int i = (C_Timeout > 0) ? C_Timeout : 60;
const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
int i = (c_timeout > 0) ? c_timeout : 60;
#ifdef USE_IMAP
/* keepalive may need to run more frequently than `$timeout` allows */
if (c_imap_keepalive)
Expand Down Expand Up @@ -873,7 +874,8 @@ static const char *km_keyname(int c)
void mutt_init_abort_key(void)
{
keycode_t buf[2];
size_t len = parsekeys(C_AbortKey, buf, mutt_array_size(buf));
const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
if (len == 0)
{
mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
Expand All @@ -883,7 +885,7 @@ void mutt_init_abort_key(void)
if (len > 1)
{
mutt_warning(
_("Specified abort key sequence (%s) will be truncated to first key"), C_AbortKey);
_("Specified abort key sequence (%s) will be truncated to first key"), c_abort_key);
}
AbortKey = buf[0];
}
Expand Down
Loading

0 comments on commit 2d26a9d

Please sign in to comment.