factor out a `setcfg` function for setting the cfg global

This commit is contained in:
blissful 2023-11-18 16:30:40 -05:00
parent 703d349389
commit c0b3cc8689
No known key found for this signature in database
GPG Key ID: 3FC5AA97AA6A4D78
1 changed files with 16 additions and 9 deletions

View File

@ -4276,6 +4276,18 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
addch(ind); addch(ind);
} }
/**
* Sets the global cfg variable and restores related state to match the new
* cfg.
*/
static void setcfg(settings newcfg)
{
cfg = newcfg;
/* Synchronize the global function pointers to match the new cfg. */
entrycmpfn = cfg.reverse ? &reventrycmp : &entrycmp;
namecmpfn = cfg.version ? &xstrverscasecmp : &xstricmp;
}
static void savecurctx(char *path, char *curname, int nextctx) static void savecurctx(char *path, char *curname, int nextctx)
{ {
settings tmpcfg = cfg; settings tmpcfg = cfg;
@ -4307,10 +4319,7 @@ static void savecurctx(char *path, char *curname, int nextctx)
} }
tmpcfg.curctx = nextctx; tmpcfg.curctx = nextctx;
cfg = tmpcfg; setcfg(tmpcfg);
/* Restore the global function pointers alongside the cfg. */
entrycmpfn = cfg.reverse ? &reventrycmp : &entrycmp;
namecmpfn = cfg.version ? &xstrverscasecmp : &xstricmp;
} }
#ifndef NOSSN #ifndef NOSSN
@ -6251,6 +6260,7 @@ static int set_sort_flags(int r)
r = 'd'; r = 'd';
} }
/* Ensure function pointers are in sync with cfg. */
entrycmpfn = cfg.reverse ? &reventrycmp : &entrycmp; entrycmpfn = cfg.reverse ? &reventrycmp : &entrycmp;
namecmpfn = cfg.version ? &xstrverscasecmp : &xstricmp; namecmpfn = cfg.version ? &xstrverscasecmp : &xstricmp;
} else if (r == CONTROL('T')) { } else if (r == CONTROL('T')) {
@ -8017,12 +8027,9 @@ nochange:
lastdir = g_ctx[r].c_last; lastdir = g_ctx[r].c_last;
lastname = g_ctx[r].c_name; lastname = g_ctx[r].c_name;
cfg = g_ctx[r].c_cfg; g_ctx[r].c_cfg.curctx = r;
/* Restore the global function pointers alongside the cfg. */ setcfg(g_ctx[r].c_cfg);
entrycmpfn = cfg.reverse ? &reventrycmp : &entrycmp;
namecmpfn = cfg.version ? &xstrverscasecmp : &xstricmp;
cfg.curctx = r;
setdirwatch(); setdirwatch();
goto begin; goto begin;
} }