Commit: 576d06c1a98602b05396d74fb55f475ac36ba597
Parent: 9e4ce3d75c61473f0378817ff74cb878ba6602f5
Author: Randy Palamar
Date: Tue, 10 Sep 2024 21:34:55 -0600
replace fputs/fputc with os_write_err_msg in main code
stderr is already not buffered so we are again losing nothing by
doing this. fprintf will be later.
Diffstat:
3 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/main.c b/main.c
@@ -65,7 +65,7 @@ do_debug(GLCtx *gl)
init_callbacks(gl);
gl->flags |= NEEDS_BLIT;
}
- fputs("Reloaded Main Program\n", stderr);
+ os_write_err_msg(s8("Reloaded Main Program\n"));
}
}
@@ -75,16 +75,16 @@ static void
gl_debug_logger(u32 src, u32 type, u32 id, u32 lvl, i32 len, const char *msg, const void *data)
{
(void)src; (void)type; (void)id; (void)data;
- fputs("[GL Error ", stderr);
+ os_write_err_msg(s8("[GL Error "));
switch (lvl) {
- case GL_DEBUG_SEVERITY_HIGH: fputs("HIGH]: ", stderr); break;
- case GL_DEBUG_SEVERITY_MEDIUM: fputs("MEDIUM]: ", stderr); break;
- case GL_DEBUG_SEVERITY_LOW: fputs("LOW]: ", stderr); break;
- case GL_DEBUG_SEVERITY_NOTIFICATION: fputs("NOTIFICATION]: ", stderr); break;
- default: fputs("INVALID]: ", stderr); break;
+ case GL_DEBUG_SEVERITY_HIGH: os_write_err_msg(s8("HIGH]: ")); break;
+ case GL_DEBUG_SEVERITY_MEDIUM: os_write_err_msg(s8("MEDIUM]: ")); break;
+ case GL_DEBUG_SEVERITY_LOW: os_write_err_msg(s8("LOW]: ")); break;
+ case GL_DEBUG_SEVERITY_NOTIFICATION: os_write_err_msg(s8("NOTIFICATION]: ")); break;
+ default: os_write_err_msg(s8("INVALID]: ")); break;
}
- fwrite(msg, 1, len, stderr);
- fputc('\n', stderr);
+ os_write_err_msg((s8){.len = len, .data = (u8 *)msg});
+ os_write_err_msg(s8("\n"));
}
@@ -207,8 +207,8 @@ compile_shader(Arena a, u32 type, s8 shader)
glGetShaderiv(sid, GL_INFO_LOG_LENGTH, &len);
s8 err = s8alloc(&a, len);
glGetShaderInfoLog(sid, len, (int *)&err.len, (char *)err.data);
- fputs("compile_shader: ", stderr);
- fwrite(err.data, 1, err.len, stderr);
+ os_write_err_msg(s8("compile_shader: "));
+ os_write_err_msg(err);
glDeleteShader(sid);
return 0;
}
diff --git a/os_unix.c b/os_unix.c
@@ -27,6 +27,12 @@ typedef struct {
#define OS_MAP_READ PROT_READ
#define OS_MAP_PRIVATE MAP_PRIVATE
+static void
+os_write_err_msg(s8 msg)
+{
+ write(STDERR_FILENO, msg.data, msg.len);
+}
+
__attribute__((noreturn))
static void
os_die(char *fmt, ...)
@@ -308,5 +314,5 @@ os_set_term_size(os_child c, u32 rows, u32 cols, i32 x, i32 y)
ws.ws_xpixel = x;
ws.ws_ypixel = y;
if (ioctl(c.fd, TIOCSWINSZ, &ws) < 0)
- fputs("os_set_term_size\n", stderr);
+ os_write_err_msg(s8("os_set_term_size\n"));
}
diff --git a/terminal.c b/terminal.c
@@ -309,27 +309,29 @@ term_reset(Term *t)
static void
dump_csi(CSI *csi)
{
- fputs("raw: ESC[", stderr);
+ os_write_err_msg(s8("raw: ESC["));
for (size i = 0; i < csi->raw.len; i++) {
u8 c = csi->raw.data[i];
if (ISPRINT(c))
- fputc(c, stderr);
+ os_write_err_msg((s8){.len = 1, .data = csi->raw.data + i});
else if (c == '\n')
- fputs("(\\n)", stderr);
+ os_write_err_msg(s8("\\n"));
else if (c == '\r')
- fputs("(\\r)", stderr);
+ os_write_err_msg(s8("\\r"));
else
- fprintf(stderr, "(0x%02X)", c);
+ fprintf(stderr, "\\x%02X", c);
}
fprintf(stderr, "\n\tparsed = { .priv = %d, .mode = ", csi->priv);
- if (ISPRINT(csi->mode))
- fputc(csi->mode, stderr);
- else
- fprintf(stderr, "(0x%02X)", csi->mode);
+ if (ISPRINT(csi->mode)) {
+ u8 buf[1] = {csi->mode};
+ os_write_err_msg((s8){.len = 1, .data = buf});
+ } else {
+ fprintf(stderr, "\\x%02X", csi->mode);
+ }
fprintf(stderr, ", .argc = %d, .argv = {", csi->argc);
for (i32 i = 0; i < csi->argc; i++)
fprintf(stderr, " %d", csi->argv[i]);
- fputs(" } }\n", stderr);
+ os_write_err_msg(s8(" } }\n"));
}
/* ED/DECSED: Erase in Display */
@@ -467,7 +469,7 @@ set_mode(Term *t, CSI *csi, b32 set)
else t->gl.mode &= ~WIN_MODE_BRACKPASTE;
break;
default:
- fputs("set_mode: unhandled mode: ", stderr);
+ os_write_err_msg(s8("set_mode: unhandled mode: "));
dump_csi(csi);
}
}
@@ -571,7 +573,7 @@ set_colours(Term *t, CSI *csi)
if (dcr.status == CR_SUCCESS) {
cs->fg = dcr.colour;
} else {
- fputs("set_colours: ", stderr);
+ os_write_err_msg(s8("set_colours: "));
dump_csi(csi);
}
break;
@@ -583,7 +585,7 @@ set_colours(Term *t, CSI *csi)
if (dcr.status == CR_SUCCESS) {
cs->bg = dcr.colour;
} else {
- fputs("set_colours: ", stderr);
+ os_write_err_msg(s8("set_colours: "));
dump_csi(csi);
}
break;
@@ -743,7 +745,7 @@ handle_csi(Term *t, CSI *csi)
/* FALLTHROUGH */
default:
unknown:
- fputs("unknown csi: ", stderr);
+ os_write_err_msg(s8("unknown csi: "));
dump_csi(csi);
}
}
@@ -801,17 +803,17 @@ reset_csi(CSI *csi, s8 *raw)
static void
dump_osc(OSC *osc)
{
- fputs("ESC]", stderr);
+ os_write_err_msg(s8("ESC]"));
for (size i = 0; i < osc->raw.len; i++) {
u8 cp = osc->raw.data[i];
if (ISPRINT(cp))
- fputc(cp, stderr);
+ os_write_err_msg((s8){.len = 1, .data = osc->raw.data + i});
else if (cp == '\n')
- fputs("\\n", stderr);
+ os_write_err_msg(s8("\\n"));
else if (cp == '\r')
- fputs("\\r", stderr);
+ os_write_err_msg(s8("\\r"));
else if (cp == '\a')
- fputs("\\a", stderr);
+ os_write_err_msg(s8("\\a"));
else
fprintf(stderr, "\\x%02X", cp);
}
@@ -830,7 +832,7 @@ handle_osc(Term *t, s8 *raw, Arena a)
case 1: /* IGNORED: set icon name */ break;
case 2: set_window_title(t->gl.window, a, osc.arg); break;
default:
- fputs("unhandled osc cmd: ", stderr);
+ os_write_err_msg(s8("unhandled osc cmd: "));
dump_osc(&osc);
break;
}