diff options
author | dzwdz | 2023-01-25 20:16:22 +0100 |
---|---|---|
committer | dzwdz | 2023-01-25 20:16:22 +0100 |
commit | 17bfb0ef0a48330b1d54e61fe3c30d83528d2d90 (patch) | |
tree | b3d4aed1f408edcb17fe5c86fccaeacaa2a5a48a /src/user/app/init/driver | |
parent | 2ad6ee8ed15d1bf898645a16dbc06991a3c1425e (diff) |
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.
Diffstat (limited to 'src/user/app/init/driver')
-rw-r--r-- | src/user/app/init/driver/driver.h | 2 | ||||
-rw-r--r-- | src/user/app/init/driver/initctl.c | 6 | ||||
-rw-r--r-- | src/user/app/init/driver/ps2.c | 6 | ||||
-rw-r--r-- | src/user/app/init/driver/termcook.c | 20 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/user/app/init/driver/driver.h b/src/user/app/init/driver/driver.h index fc9f51b..98c18f1 100644 --- a/src/user/app/init/driver/driver.h +++ b/src/user/app/init/driver/driver.h @@ -1,7 +1,7 @@ #pragma once #include <camellia/types.h> -void initctl_drv(handle_t killswitch); +void initctl_drv(hid_t killswitch); void ps2_drv(void); void tmpfs_drv(void); diff --git a/src/user/app/init/driver/initctl.c b/src/user/app/init/driver/initctl.c index 67c8ade..fed71b7 100644 --- a/src/user/app/init/driver/initctl.c +++ b/src/user/app/init/driver/initctl.c @@ -6,7 +6,7 @@ #include <string.h> #include <camellia/compat.h> -void initctl_drv(handle_t killswitch) { +void initctl_drv(hid_t killswitch) { struct ufs_request res; char buf[64]; const size_t buflen = sizeof buf; @@ -28,10 +28,10 @@ void initctl_drv(handle_t killswitch) { } } if (!strcmp(buf, "halt")) { - _syscall_write(killswitch, "halt", 4, 0, 0); + _sys_write(killswitch, "halt", 4, 0, 0); } if (!strcmp(buf, "intr")) { - _syscall_write(killswitch, "intr", 4, 0, 0); + _sys_write(killswitch, "intr", 4, 0, 0); } c0_fs_respond(NULL, res.len, 0); break; diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c index 1accbfc..a5cdb07 100644 --- a/src/user/app/init/driver/ps2.c +++ b/src/user/app/init/driver/ps2.c @@ -32,7 +32,7 @@ static const char keymap_upper[] = { static volatile uint8_t backlog_buf[16]; static volatile ring_t backlog = {(void*)backlog_buf, sizeof backlog_buf, 0, 0}; -static handle_t fd; +static hid_t fd; static bool keys[0x80] = {0}; @@ -63,7 +63,7 @@ static void main_loop(void) { case VFSOP_READ: while (ring_used((void*)&backlog) == 0) { /* read raw input until we have something to output */ - int len = _syscall_read(fd, buf, sizeof buf, 0); + int len = _sys_read(fd, buf, sizeof buf, 0); if (len == 0) break; for (int i = 0; i < len; i++) parse_scancode(buf[i]); @@ -80,7 +80,7 @@ static void main_loop(void) { } void ps2_drv(void) { - fd = _syscall_open("/kdev/ps2/kb", 12, 0); + fd = _sys_open("/kdev/ps2/kb", 12, 0); if (fd < 0) exit(1); main_loop(); 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()); } |