Skip to content

Commit

Permalink
Consolidate CRT_delay and CRT_crashSettings into one
Browse files Browse the repository at this point in the history
No reason to have two pointers when one will do the trick,
and the code becomes a little less obfuscated as a result.
  • Loading branch information
natoscott committed Aug 5, 2024
1 parent bda4ac3 commit 4c4a5fb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ bool CRT_utf8 = false;

const char* const* CRT_treeStr = CRT_treeStrAscii;

static const Settings* CRT_crashSettings;
static const int* CRT_delay;
static const Settings* CRT_settings;

const char* CRT_degreeSign;

Expand Down Expand Up @@ -836,7 +835,7 @@ ATTR_NORETURN
static void CRT_handleSIGTERM(int sgn) {
CRT_done();

if (!CRT_crashSettings->changed)
if (!CRT_settings->changed)
_exit(0);

const char* signal_str = strsignal(sgn);
Expand Down Expand Up @@ -1055,8 +1054,7 @@ void CRT_init(const Settings* settings, bool allowUnicode, bool retainScreenOnEx

redirectStderr();
noecho();
CRT_crashSettings = settings;
CRT_delay = &(settings->delay);
CRT_settings = settings;
CRT_colors = CRT_colorSchemes[settings->colorScheme];
CRT_colorScheme = settings->colorScheme;

Expand All @@ -1065,7 +1063,7 @@ void CRT_init(const Settings* settings, bool allowUnicode, bool retainScreenOnEx
CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White, Black) : color;
}

halfdelay(*CRT_delay);
halfdelay(settings->delay);
nonl();
intrflush(stdscr, false);
keypad(stdscr, true);
Expand Down Expand Up @@ -1180,7 +1178,7 @@ int CRT_readKey(void) {
cbreak();
nodelay(stdscr, FALSE);
int ret = getch();
halfdelay(*CRT_delay);
halfdelay(CRT_settings->delay);
return ret;
}

Expand All @@ -1191,7 +1189,7 @@ void CRT_disableDelay(void) {
}

void CRT_enableDelay(void) {
halfdelay(*CRT_delay);
halfdelay(CRT_settings->delay);
}

void CRT_setColors(int colorScheme) {
Expand Down Expand Up @@ -1312,7 +1310,7 @@ void CRT_handleSIGSEGV(int signal) {
full_write_str(STDERR_FILENO,
"Setting information:\n"
"--------------------\n");
Settings_write(CRT_crashSettings, true);
Settings_write(CRT_settings, true);
full_write_str(STDERR_FILENO, "\n\n");

#ifdef PRINT_BACKTRACE
Expand Down

0 comments on commit 4c4a5fb

Please sign in to comment.