From 17bfb0ef0a48330b1d54e61fe3c30d83528d2d90 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 25 Jan 2023 20:16:22 +0100 Subject: style: typedef structs, shorter namespaces I've wanted to do this for a while, and since I've just had a relatively large refactor commit (pcpy), this is as good of a time as any. Typedefing structs was mostly inspired by Plan 9's coding style. It makes some lines of code much shorter at basically no expense. Everything related to userland kept old-style struct definitions, so as not to force that style onto other people. I also considered changing SCREAMING_ENUM_FIELDS to NicerLookingCamelcase, but I didn't, just in case that'd be confusing. --- src/user/app/init/driver/termcook.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/user/app/init/driver/termcook.c') diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c index 8845839..a76f3a8 100644 --- a/src/user/app/init/driver/termcook.c +++ b/src/user/app/init/driver/termcook.c @@ -10,21 +10,21 @@ enum tstate { CSI, }; -static void w_output(handle_t output, const char *buf, size_t len) { +static void w_output(hid_t output, const char *buf, size_t len) { size_t pos = 0; while (pos < len) { - int ret = _syscall_write(output, buf + pos, len - pos, pos, 0); + int ret = _sys_write(output, buf + pos, len - pos, pos, 0); if (ret < 0) break; pos += ret; } } -static void line_editor(handle_t input, handle_t output) { +static void line_editor(hid_t input, hid_t output) { char readbuf[16], linebuf[256]; size_t linepos = 0; enum tstate state = Normal; for (;;) { - int readlen = _syscall_read(input, readbuf, sizeof readbuf, -1); + int readlen = _sys_read(input, readbuf, sizeof readbuf, -1); if (readlen < 0) return; for (int i = 0; i < readlen; i++) { char c = readbuf[i]; @@ -39,13 +39,13 @@ static void line_editor(handle_t input, handle_t output) { } break; case 3: /* C-c */ - _syscall_exit(1); + _sys_exit(1); case 4: /* EOT, C-d */ if (linepos > 0) { w_output(output, linebuf, linepos); linepos = 0; } else { - _syscall_write(output, NULL, 0, 0, 0); /* EOF */ + _sys_write(output, NULL, 0, 0, 0); /* EOF */ } break; case '\n': @@ -82,14 +82,14 @@ static void line_editor(handle_t input, handle_t output) { } void termcook(void) { - handle_t stdin_pipe[2] = {-1, -1}; - if (_syscall_pipe(stdin_pipe, 0) < 0) + hid_t stdin_pipe[2] = {-1, -1}; + if (_sys_pipe(stdin_pipe, 0) < 0) return; if (!fork()) { /* the caller continues in a child process, * so it can be killed when the line editor quits */ - _syscall_dup(stdin_pipe[0], 0, 0); + _sys_dup(stdin_pipe[0], 0, 0); close(stdin_pipe[0]); close(stdin_pipe[1]); return; @@ -99,5 +99,5 @@ void termcook(void) { line_editor(0, stdin_pipe[1]); exit(0); } - exit(_syscall_await()); + exit(_sys_await()); } -- cgit v1.2.3