Replace bools for binary states with an uchar

This commit is contained in:
Arun Prakash Jana 2019-12-20 16:01:35 +05:30
parent 37988cf854
commit 88b8d2641d
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 22 additions and 18 deletions

View File

@ -331,8 +331,6 @@ static kv bookmark[BM_MAX];
static kv plug[PLUGIN_MAX]; static kv plug[PLUGIN_MAX];
static uchar g_tmpfplen; static uchar g_tmpfplen;
static uchar blk_shift = BLK_SHIFT_512; static uchar blk_shift = BLK_SHIFT_512;
static bool interrupted = FALSE;
static bool rangesel = FALSE;
/* Retain old signal handlers */ /* Retain old signal handlers */
#ifdef __linux__ #ifdef __linux__
@ -353,8 +351,14 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
/* Buffer to store plugins control pipe location */ /* Buffer to store plugins control pipe location */
static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned)); static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
/* MISC NON-PERSISTENT INTERNAL BINARY STATES */
/* Plugin control initialization status */ /* Plugin control initialization status */
static bool g_plinit = FALSE; #define STATE_PLUGIN_INIT 0x1
#define STATE_INTERRUPTED 0x2
#define STATE_RANGESEL 0x4
static uchar g_states;
/* Options to identify file mime */ /* Options to identify file mime */
#if defined(__APPLE__) #if defined(__APPLE__)
@ -604,7 +608,7 @@ static void sigint_handler(int sig)
{ {
(void) sig; (void) sig;
interrupted = TRUE; g_states |= STATE_INTERRUPTED;
} }
static uint xatoi(const char *str) static uint xatoi(const char *str)
@ -3607,9 +3611,9 @@ static bool run_selected_plugin(char **path, const char *file, char *newpath, ch
if (*file == '_') if (*file == '_')
return run_cmd_as_plugin(*path, file, newpath, runfile); return run_cmd_as_plugin(*path, file, newpath, runfile);
if (!g_plinit) { if (!(g_states & STATE_PLUGIN_INIT)) {
plctrl_init(); plctrl_init();
g_plinit = TRUE; g_states |= STATE_PLUGIN_INIT;
} }
fd = open(g_pipepath, O_RDONLY | O_NONBLOCK); fd = open(g_pipepath, O_RDONLY | O_NONBLOCK);
@ -3796,7 +3800,7 @@ static int dentfill(char *path, struct entry **dents)
dir_blocks += dirwalk(buf, &sb); dir_blocks += dirwalk(buf, &sb);
if (interrupted) { if (g_states & STATE_INTERRUPTED) {
closedir(dirp); closedir(dirp);
return n; return n;
} }
@ -3893,7 +3897,7 @@ static int dentfill(char *path, struct entry **dents)
else else
num_files = num_saved; num_files = num_saved;
if (interrupted) { if (g_states & STATE_INTERRUPTED) {
closedir(dirp); closedir(dirp);
return n; return n;
} }
@ -4189,7 +4193,7 @@ static void redraw(char *path)
mvprintw(lastln, 0, "%d/%d [%d:%s] %cu:%s free:%s files:%lu %lldB %s", mvprintw(lastln, 0, "%d/%d [%d:%s] %cu:%s free:%s files:%lu %lldB %s",
cur + 1, ndents, cfg.selmode, cur + 1, ndents, cfg.selmode,
(rangesel ? "*" : (nselected ? xitoa(nselected) : "")), ((g_states & STATE_RANGESEL) ? "*" : (nselected ? xitoa(nselected) : "")),
c, buf, coolsize(get_fs_info(path, FREE)), num_files, c, buf, coolsize(get_fs_info(path, FREE)), num_files,
(ll)pent->blocks << blk_shift, ptr); (ll)pent->blocks << blk_shift, ptr);
} else { /* light or detail mode */ } else { /* light or detail mode */
@ -4203,7 +4207,7 @@ static void redraw(char *path)
mvprintw(lastln, 0, "%d/%d [%d:%s] %s%s %s %s %s [%s]", mvprintw(lastln, 0, "%d/%d [%d:%s] %s%s %s %s %s [%s]",
cur + 1, ndents, cfg.selmode, cur + 1, ndents, cfg.selmode,
(rangesel ? "*" : (nselected ? xitoa(nselected) : "")), ((g_states & STATE_RANGESEL) ? "*" : (nselected ? xitoa(nselected) : "")),
sort, buf, get_lsperms(pent->mode), coolsize(pent->size), ptr, base); sort, buf, get_lsperms(pent->mode), coolsize(pent->size), ptr, base);
} }
} else } else
@ -4280,8 +4284,8 @@ begin:
printwarn(&presel); printwarn(&presel);
populate(path, lastname); populate(path, lastname);
if (interrupted) { if (g_states & STATE_INTERRUPTED) {
interrupted = FALSE; g_states &= ~STATE_INTERRUPTED;
cfg.apparentsz = 0; cfg.apparentsz = 0;
cfg.blkorder = 0; cfg.blkorder = 0;
blk_shift = BLK_SHIFT_512; blk_shift = BLK_SHIFT_512;
@ -4870,8 +4874,8 @@ nochange:
goto nochange; goto nochange;
startselection(); startselection();
if (rangesel) if (g_states & STATE_RANGESEL)
rangesel = FALSE; g_states &= ~STATE_RANGESEL;
/* Toggle selection status */ /* Toggle selection status */
dents[cur].flags ^= FILE_SELECTED; dents[cur].flags ^= FILE_SELECTED;
@ -4904,14 +4908,14 @@ nochange:
goto nochange; goto nochange;
startselection(); startselection();
rangesel ^= TRUE; g_states ^= STATE_RANGESEL;
if (stat(path, &sb) == -1) { if (stat(path, &sb) == -1) {
printwarn(&presel); printwarn(&presel);
goto nochange; goto nochange;
} }
if (rangesel) { /* Range selection started */ if (g_states & STATE_RANGESEL) { /* Range selection started */
inode = sb.st_ino; inode = sb.st_ino;
selstartid = cur; selstartid = cur;
continue; continue;
@ -4941,8 +4945,8 @@ nochange:
goto nochange; goto nochange;
startselection(); startselection();
if (rangesel) if (g_states & STATE_RANGESEL)
rangesel = FALSE; g_states &= ~STATE_RANGESEL;
selstartid = 0; selstartid = 0;
selendid = ndents - 1; selendid = ndents - 1;