summaryrefslogtreecommitdiff
path: root/usr.bin/osh
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/osh')
-rw-r--r--usr.bin/osh/osh.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index af7f4ab..545f95a 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -43,6 +43,9 @@
#define is_printable(C) ((C) >= 32 && (C) <= 126)
#define is_ascii(C) ((C) >= 0 && (C) <= 128)
+#define INPUT_SIZE 64
+
+#define REPEAT "!!"
#define COMMENT '@'
#define WELCOME \
":::::::::::::::::::::::::::::::::::::::\n" \
@@ -66,7 +69,8 @@
#define PROMPT "[%s::osmora]~ "
-static char buf[64];
+static char last_command[INPUT_SIZE];
+static char buf[INPUT_SIZE];
static int running;
static int bell_fd;
static bool bs_bell = true; /* Beep on backspace */
@@ -365,6 +369,18 @@ parse_line(char *input)
struct parse_state state = {0};
pid_t child;
+ /*
+ * If we are using the REPEAT shorthand,
+ * repeat the last command. We return -EAGAIN
+ * to indicate we did not parse a normal command
+ * so the repeat command isn't pushed into the last
+ * command buffer and we enter a recursive hell.
+ */
+ if (strcmp(input, REPEAT) == 0) {
+ parse_line(last_command);
+ return -EAGAIN;
+ }
+
/* Ensure the aux vector is zeored */
memset(argv, 0, sizeof(argv));
@@ -426,6 +442,25 @@ open_script(const char *pathname)
return 0;
}
+static void
+dump_file(const char *pathname)
+{
+ FILE *file;
+ char buf[64];
+ int fd;
+
+ file = fopen(pathname, "r");
+ if (file == NULL) {
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), file) != NULL) {
+ printf("%s", buf);
+ }
+
+ fclose(file);
+}
+
int
main(int argc, char **argv)
{
@@ -442,7 +477,7 @@ main(int argc, char **argv)
running = 1;
bell_fd = open("/dev/beep", O_WRONLY);
- puts(WELCOME);
+ dump_file("/etc/motd");
while (running) {
printf(PROMPT, getlogin());
@@ -457,6 +492,7 @@ main(int argc, char **argv)
continue;
}
+ memcpy(last_command, buf, buf_i + 1);
buf[0] = '\0';
}
return 0;