summaryrefslogtreecommitdiffstats
path: root/CRT.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-05 17:24:59 +0200
committercgzones <cgzones@googlemail.com>2020-10-14 14:28:02 +0200
commit1df7fa387a1b5c9541a5b3b49c1ac0fb77bba05f (patch)
tree3224a0684052e306b119fd5940dff858fd29e8c1 /CRT.c
parent59edb2e80ce0430d13be8374d45a7eeafdf65604 (diff)
Misc CRT cleanup
Diffstat (limited to 'CRT.c')
-rw-r--r--CRT.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/CRT.c b/CRT.c
index a6e606ef..1469ff3d 100644
--- a/CRT.c
+++ b/CRT.c
@@ -28,20 +28,20 @@ in the source distribution for its full text.
#include <sys/types.h>
#endif
-#define ColorIndex(i,j) ((7-i)*8+j)
+#define ColorIndex(i,j) ((7-(i))*8+(j))
#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j))
-#define Black COLOR_BLACK
-#define Red COLOR_RED
-#define Green COLOR_GREEN
-#define Yellow COLOR_YELLOW
-#define Blue COLOR_BLUE
+#define Black COLOR_BLACK
+#define Red COLOR_RED
+#define Green COLOR_GREEN
+#define Yellow COLOR_YELLOW
+#define Blue COLOR_BLUE
#define Magenta COLOR_MAGENTA
-#define Cyan COLOR_CYAN
-#define White COLOR_WHITE
+#define Cyan COLOR_CYAN
+#define White COLOR_WHITE
-#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
+#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = {
@@ -74,11 +74,9 @@ bool CRT_utf8 = false;
const char *const *CRT_treeStr = CRT_treeStrAscii;
-static bool CRT_hasColors;
+int CRT_delay;
-int CRT_delay = 0;
-
-int* CRT_colors;
+const int* CRT_colors;
int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[COLORSCHEME_DEFAULT] = {
@@ -544,9 +542,7 @@ int CRT_scrollHAmount = 5;
int CRT_scrollWheelVAmount = 10;
-char* CRT_termType;
-
-// TODO move color scheme to Settings, perhaps?
+const char* CRT_termType;
int CRT_colorScheme = 0;
@@ -563,35 +559,29 @@ static int CRT_euid = -1;
static int CRT_egid = -1;
-#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
-
void CRT_dropPrivileges() {
CRT_egid = getegid();
CRT_euid = geteuid();
if (setegid(getgid()) == -1) {
- DIE("Fatal error: failed dropping group privileges.\n");
+ CRT_fatalError("Fatal error: failed dropping group privileges");
}
if (seteuid(getuid()) == -1) {
- DIE("Fatal error: failed dropping user privileges.\n");
+ CRT_fatalError("Fatal error: failed dropping user privileges");
}
}
void CRT_restorePrivileges() {
if (CRT_egid == -1 || CRT_euid == -1) {
- DIE("Fatal error: internal inconsistency.\n");
+ CRT_fatalError("Fatal error: internal inconsistency");
}
if (setegid(CRT_egid) == -1) {
- DIE("Fatal error: failed restoring group privileges.\n");
+ CRT_fatalError("Fatal error: failed restoring group privileges");
}
if (seteuid(CRT_euid) == -1) {
- DIE("Fatal error: failed restoring user privileges.\n");
+ CRT_fatalError("Fatal error: failed restoring user privileges");
}
}
-#else /* HAVE_SETUID_ENABLED */
-
-// In this case, the setuid operations are defined as macros in CRT.h
-
#endif /* HAVE_SETUID_ENABLED */
static struct sigaction old_sig_handler[32];
@@ -601,10 +591,7 @@ static struct sigaction old_sig_handler[32];
void CRT_init(int delay, int colorScheme, bool allowUnicode) {
initscr();
noecho();
- CRT_delay = delay;
- if (CRT_delay == 0) {
- CRT_delay = 1;
- }
+ CRT_delay = CLAMP(delay, 1, 255);
CRT_colors = CRT_colorSchemes[colorScheme];
CRT_colorScheme = colorScheme;
@@ -619,12 +606,8 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) {
keypad(stdscr, true);
mouseinterval(0);
curs_set(0);
- if (has_colors()) {
+ if (has_colors())
start_color();
- CRT_hasColors = true;
- } else {
- CRT_hasColors = false;
- }
CRT_termType = getenv("TERM");
if (String_eq(CRT_termType, "linux"))
CRT_scrollHAmount = 20;

© 2014-2024 Faster IT GmbH | imprint | privacy policy