diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/Makefile | 3 | ||||
-rw-r--r-- | usr.bin/fetch/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/fetch/fetch.c | 58 | ||||
-rw-r--r-- | usr.bin/kfgwm/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/kfgwm/include/kfg/types.h | 39 | ||||
-rw-r--r-- | usr.bin/kfgwm/include/kfg/window.h | 60 | ||||
-rw-r--r-- | usr.bin/kfgwm/kfgwm.c | 85 | ||||
-rw-r--r-- | usr.bin/kfgwm/window.c | 132 | ||||
-rw-r--r-- | usr.bin/kmsg/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/kmsg/kmsg.c | 62 | ||||
-rw-r--r-- | usr.bin/osh/osh.c | 94 |
11 files changed, 521 insertions, 30 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 1c973ff..3fb6a73 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -6,3 +6,6 @@ ARGS = -I$(ROOT)/builddeps LDSCRIPT=$(LDSCRIPT) USRDIR=$(USRDIR) ROOT=$(ROOT) .PHONY: all all: make -C osh/ $(ARGS) + make -C kmsg/ $(ARGS) + make -C fetch/ $(ARGS) + make -C kfgwm/ $(ARGS) diff --git a/usr.bin/fetch/Makefile b/usr.bin/fetch/Makefile new file mode 100644 index 0000000..4b08e84 --- /dev/null +++ b/usr.bin/fetch/Makefile @@ -0,0 +1,6 @@ +include user.mk + +CFILES = $(shell find . -name "*.c") + +$(ROOT)/base/usr/bin/fetch: + gcc $(CFILES) -o $@ $(INTERNAL_CFLAGS) diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c new file mode 100644 index 0000000..98b2d3c --- /dev/null +++ b/usr.bin/fetch/fetch.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +#define prcons(FD, STR) write((FD), (STR), strlen((STR))) + +#define ASCII_ART \ + " ____ \n" \ + " | \\__\\ \n" \ + " | /\\ \\ user: root\n" \ + " |/ \\ \\ OS: Hyra/amd64 v"_OSVER"\n" \ + " \\ R. \\ \\ arch: "_OSARCH"\n" \ + " \\ I. \\ \\\n" + + +int +main(void) +{ + int fd; + + fd = open("/dev/console", O_WRONLY); + if (fd < 0) { + return fd; + } + + prcons(fd, ASCII_ART); + close(fd); + return 0; +} diff --git a/usr.bin/kfgwm/Makefile b/usr.bin/kfgwm/Makefile new file mode 100644 index 0000000..a0fb49a --- /dev/null +++ b/usr.bin/kfgwm/Makefile @@ -0,0 +1,6 @@ +include user.mk + +CFILES = $(shell find . -name "*.c") + +$(ROOT)/base/usr/bin/kfgwm: + gcc $(CFILES) -Iinclude/ -o $@ $(INTERNAL_CFLAGS) diff --git a/usr.bin/kfgwm/include/kfg/types.h b/usr.bin/kfgwm/include/kfg/types.h new file mode 100644 index 0000000..43d8074 --- /dev/null +++ b/usr.bin/kfgwm/include/kfg/types.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef KFG_TYPES_H_ +#define KFG_TYPES_H_ + +#include <sys/types.h> + +typedef uint32_t kfgpos_t; +typedef uint32_t kfgdim_t; +typedef uint32_t kfgpixel_t; + +#endif /* !KFG_TYPES_H_ */ diff --git a/usr.bin/kfgwm/include/kfg/window.h b/usr.bin/kfgwm/include/kfg/window.h new file mode 100644 index 0000000..058e4b7 --- /dev/null +++ b/usr.bin/kfgwm/include/kfg/window.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef KFG_WINDOW_H_ +#define KFG_WINDOW_H_ + +#include <kfg/types.h> + +#define KFG_RED 0x6E0C24 +#define KFG_YELLOW 0xF0A401 +#define KFG_WHITE 0xF2E5BC +#define KFG_DARK 0x1D2021 +#define KFG_BLUE 0x076678 +#define KFG_AQUA 0x427B58 + +/* Default dimensions */ +#define KFG_BORDER_WIDTH 1 +#define KFG_BORDER_HEIGHT 1 +#define KFG_TITLE_HEIGHT 10 + +struct kfg_window { + kfgpos_t x; + kfgpos_t y; + kfgdim_t width; + kfgdim_t height; + kfgdim_t fb_pitch; + kfgpixel_t bg; + kfgpixel_t border_bg; + kfgpixel_t *framebuf; +}; + +int kfg_win_draw(struct kfg_window *parent, struct kfg_window *wp); + +#endif /* !KFG_WINDOW_H_ */ diff --git a/usr.bin/kfgwm/kfgwm.c b/usr.bin/kfgwm/kfgwm.c new file mode 100644 index 0000000..eb28a8e --- /dev/null +++ b/usr.bin/kfgwm/kfgwm.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/fbdev.h> +#include <kfg/window.h> +#include <fcntl.h> +#include <stddef.h> +#include <unistd.h> + +int +main(void) +{ + int fb_fd, fbattr_fd, prot; + size_t fb_size; + uint32_t *framep; + struct fbattr fbattr; + struct kfg_window root_win, test_win; + + fb_fd = open("/dev/fb0", O_RDWR); + if (fb_fd < 0) { + return fb_fd; + } + + fbattr_fd = open("/ctl/fb0/attr", O_RDONLY); + if (fbattr_fd < 0) { + close(fb_fd); + return fbattr_fd; + } + + read(fbattr_fd, &fbattr, sizeof(fbattr)); + close(fbattr_fd); + + fb_size = fbattr.height * fbattr.pitch; + prot = PROT_READ | PROT_WRITE; + framep = mmap(NULL, fb_size, prot, MAP_SHARED, fb_fd, 0); + + root_win.x = 0; + root_win.y = 0; + root_win.width = fbattr.width; + root_win.height = fbattr.height; + root_win.fb_pitch = fbattr.pitch; + root_win.framebuf = framep; + root_win.bg = KFG_RED; + root_win.border_bg = KFG_RED; + + test_win.x = 150; + test_win.y = 85; + test_win.width = 425; + test_win.height = 350; + test_win.fb_pitch = fbattr.pitch; + test_win.framebuf = framep; + test_win.bg = KFG_DARK; + test_win.border_bg = KFG_RED; + + kfg_win_draw(&root_win, &test_win); + for (;;); +} diff --git a/usr.bin/kfgwm/window.c b/usr.bin/kfgwm/window.c new file mode 100644 index 0000000..259e841 --- /dev/null +++ b/usr.bin/kfgwm/window.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/errno.h> +#include <sys/cdefs.h> +#include <kfg/window.h> +#include <stddef.h> + +__always_inline static inline size_t +pixel_index(struct kfg_window *wp, kfgpos_t x, kfgpos_t y) +{ + return x + y * (wp->fb_pitch / 4); +} + +static void +draw_win(struct kfg_window *parent, struct kfg_window *wp) +{ + kfgpixel_t *framep; + kfgpos_t x_i, y_i; /* Start */ + kfgpos_t x_end, y_end; /* End */ + kfgpixel_t brush = wp->bg; + kfgpos_t rx, ry; /* Starts at 0 */ + kfgpos_t rx_end, ry_end; /* Starts at 0 */ + size_t i; + + framep = parent->framebuf; + x_i = wp->x; + y_i = wp->y; + x_end = x_i + wp->width; + y_end = y_i + wp->height; + + for (kfgpos_t x = x_i; x < x_end; ++x) { + for (kfgpos_t y = y_i; y < y_i+KFG_TITLE_HEIGHT; ++y) { + rx = (x - x_i); + ry = (y - y_i); + + if (rx <= KFG_BORDER_WIDTH && (rx % 2) == 0) + brush = KFG_WHITE; + else + brush = KFG_AQUA; + + i = pixel_index(parent, x, y); + framep[i] = brush; + } + } + + y_i = wp->y + KFG_TITLE_HEIGHT; + for (kfgpos_t x = x_i; x < x_end; ++x) { + for (kfgpos_t y = y_i; y < y_end; ++y) { + rx = (x - x_i); + ry = (y - y_i); + + if (rx <= KFG_BORDER_WIDTH) + brush = wp->border_bg; + else if (ry <= KFG_BORDER_HEIGHT) + brush = wp->border_bg; + else if (rx >= (wp->width - KFG_BORDER_WIDTH)) + brush = wp->border_bg; + else if (ry >= (wp->height - KFG_BORDER_HEIGHT)) + brush = wp->border_bg; + else + brush = wp->bg; + + i = pixel_index(parent, x, y); + framep[i] = brush; + } + } +} + +/* + * Draw a window on the screen + * + * @parent: Parent window + * @wp: New window to draw + * + * TODO: Double buffering and multiple windows. + */ +int +kfg_win_draw(struct kfg_window *parent, struct kfg_window *wp) +{ + kfgpos_t start_x, start_y; + kfgpos_t end_x, end_y; + kfgpos_t max_x, max_y; + kfgdim_t width, height; + + if (parent == NULL) { + return -EINVAL; + } + if (parent->framebuf == NULL) { + return -EINVAL; + } + + max_x = wp->x + parent->width; + max_y = wp->y + parent->height; + + /* Don't overflow the framebuffer! */ + if ((wp->x + wp->width) > max_x) { + wp->x = max_x; + } + if ((wp->y + wp->height) > max_y) { + wp->y = max_y; + } + + draw_win(parent, wp); + return 0; +} diff --git a/usr.bin/kmsg/Makefile b/usr.bin/kmsg/Makefile new file mode 100644 index 0000000..9b76cc2 --- /dev/null +++ b/usr.bin/kmsg/Makefile @@ -0,0 +1,6 @@ +include user.mk + +CFILES = $(shell find . -name "*.c") + +$(ROOT)/base/usr/bin/kmsg: + gcc $(CFILES) -o $@ $(INTERNAL_CFLAGS) diff --git a/usr.bin/kmsg/kmsg.c b/usr.bin/kmsg/kmsg.c new file mode 100644 index 0000000..678ad8c --- /dev/null +++ b/usr.bin/kmsg/kmsg.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +int +main(void) +{ + int mfd, cons_fd; + ssize_t retval; + char linebuf[256]; + + if ((mfd = open("/dev/kmsg", O_RDONLY)) < 0) { + return mfd; + } + if ((cons_fd = open("/dev/console", O_WRONLY)) < 0) { + close(mfd); + return cons_fd; + } + + for (;;) { + retval = read(mfd, linebuf, sizeof(linebuf) - 1); + if (retval <= 0) { + break; + } + linebuf[retval] = '\0'; + write(cons_fd, linebuf, strlen(linebuf)); + } + + close(cons_fd); + close(mfd); + return 0; +} diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c index 9b4e9ab..ca9a241 100644 --- a/usr.bin/osh/osh.c +++ b/usr.bin/osh/osh.c @@ -30,8 +30,10 @@ #include <sys/types.h> #include <sys/cdefs.h> #include <sys/reboot.h> +#include <sys/spawn.h> #include <fcntl.h> #include <stddef.h> +#include <stdbool.h> #include <unistd.h> #include <string.h> @@ -50,6 +52,9 @@ "reboot - Reboot the machine\n" \ "shutdown - Power off the machine\n" \ "kmsg - Print kernel message buffer\n" \ + "fetch - System information\n" \ + "kfg - Start up kfgwm\n" \ + "bell - Toggle backspace bell\n" \ "exit - Exit the shell\n" #define PROMPT "[root::osmora]~ " @@ -57,9 +62,12 @@ static char buf[64]; static uint8_t i; static int running; +static int bell_fd; +static bool bs_bell = true; /* Beep on backspace */ struct command { const char *name; + const char *path; void (*func)(int fd, int argc, char *argv[]); }; @@ -88,29 +96,6 @@ cmd_shutdown(int fd, int argc, char *argv[]) } void -cmd_kmsg(int fd, int argc, char *argv[]) -{ - int mfd; - ssize_t retval; - char linebuf[256]; - - if ((mfd = open("/dev/kmsg", O_RDONLY)) < 0) { - return; - } - - for (;;) { - retval = read(mfd, linebuf, sizeof(linebuf) - 1); - if (retval <= 0) { - break; - } - linebuf[retval] = '\0'; - prcons(fd, linebuf); - } - - close(mfd); -} - -void cmd_echo(int fd, int argc, char *argv[]) { for (i = 1; i < argc; i++) { @@ -120,6 +105,27 @@ cmd_echo(int fd, int argc, char *argv[]) prcons(fd, "\n"); } +void +cmd_bell(int fd, int argc, char *argv[]) +{ + const char *usage_str = "usage: bell [on/off]\n"; + const char *arg; + + if (argc < 2) { + prcons(fd, usage_str); + return; + } + + arg = argv[1]; + if (strcmp(arg, "on") == 0) { + bs_bell = true; + } else if (strcmp(arg, "off") == 0) { + bs_bell = false; + } else { + prcons(fd, usage_str); + } +} + int parse_args(char *input, char *argv[], int max_args) { @@ -159,8 +165,17 @@ getstr(int fd) { char c; uint8_t input; + uint32_t beep_payload; + i = 0; + /* + * Prepare the beep payload @ 500 Hz + * for 20ms + */ + beep_payload = 500; + beep_payload |= (30 << 16); + for (;;) { if (read(fd, &input, 2) <= 0) { continue; @@ -180,6 +195,8 @@ getstr(int fd) if (i > 0) { i--; write(fd, "\b \b", 3); + } else if (bell_fd > 0 && bs_bell) { + write(bell_fd, &beep_payload, sizeof(beep_payload)); } } else if (is_ascii(c) && i < sizeof(buf) - 1) { /* write to fd and add to buffer */ @@ -189,13 +206,29 @@ getstr(int fd) } } +static void +command_run(struct command *cmd, int fd, int argc, char *argv[]) +{ + if (cmd->func != NULL) { + cmd->func(fd, argc, argv); + return; + } + + if (cmd->path != NULL) { + spawn(cmd->path, SPAWN_WAIT); + } +} + struct command cmds[] = { - {"help", cmd_help}, - {"echo", cmd_echo}, - {"exit", cmd_exit}, - {"reboot", cmd_reboot}, - {"shutdown", cmd_shutdown}, - {"kmsg", cmd_kmsg}, + {"help", NULL, cmd_help}, + {"echo", NULL, cmd_echo}, + {"exit", NULL, cmd_exit}, + {"reboot", NULL, cmd_reboot}, + {"shutdown", NULL, cmd_shutdown}, + {"bell", NULL, cmd_bell}, + {"kmsg", "/usr/bin/kmsg", NULL}, + {"fetch", "/usr/bin/fetch", NULL}, + {"kfg", "/usr/bin/kfgwm", NULL}, {NULL, NULL} }; @@ -213,6 +246,7 @@ main(void) i = 0; running = 1; found = 0; + bell_fd = open("/dev/beep", O_WRONLY); prcons(fd, WELCOME); while (running) { @@ -230,7 +264,7 @@ main(void) for (i = 0; cmds[i].name != NULL; i++) { if (strcmp(input, cmds[i].name) == 0) { - cmds[i].func(fd, argc, argv); + command_run(&cmds[i], fd, argc, argv); found = 1; break; } |