diff --git a/commands.c b/commands.c index 6d6c0e9..f4d2aa9 100644 --- a/commands.c +++ b/commands.c @@ -145,6 +145,38 @@ static int cmd_break(int argc, char *argv[]) return MICROCOM_CMD_START; } +static int cmd_paste(int argc, char *argv[]) +{ + int fd = -1; + int i = 1; + int ret; + unsigned char buf[BUFSIZE]; + + if (argc < 2) + return MICROCOM_CMD_USAGE; + + fd = open(argv[1], O_RDONLY); + if (fd == -1) { + ret = errno; + fprintf(stderr, "unable to open '%s': %s\n", argv[1], strerror(ret)); + return -ret; + } + + while (i > 0) { + i = read(fd, buf, BUFSIZE); + if (i < 0) { + ret = errno; + fprintf(stderr, "%s\n", strerror(ret)); + return -ret; + } + + ios->write(ios, buf, i); + } + + close(fd); + return MICROCOM_CMD_START; +} + static int cmd_quit(int argc, char *argv[]) { microcom_exit(0); @@ -223,6 +255,11 @@ static struct cmd cmds[] = { .name = "break", .fn = cmd_break, .info = "send break", + }, { + .name = "paste", + .fn = cmd_paste, + .info = "write contents of file to the terminal", + .help = "paste ", }, { .name = "quit", .fn = cmd_quit, @@ -234,7 +271,7 @@ static struct cmd cmds[] = { }, { .name = "x", .fn = cmd_execute, - .info = "execute a script", + .info = "execute a script containing microcom commands", .help = "x ", }, { .name = "log", diff --git a/microcom.h b/microcom.h index 0956e7d..3cbae2b 100644 --- a/microcom.h +++ b/microcom.h @@ -55,6 +55,8 @@ struct ios_ops { int fd; }; +#define BUFSIZE 1024 + int mux_loop(struct ios_ops *); /* mux.c */ void init_terminal(void); void restore_terminal(void); diff --git a/mux.c b/mux.c index 33c92f7..227a2b7 100644 --- a/mux.c +++ b/mux.c @@ -23,8 +23,6 @@ #include #include -#define BUFSIZE 1024 - /* This is called with buf[-2:0] being IAC SB COM_PORT_OPTION */ static int do_com_port_option(struct ios_ops *ios, unsigned char *buf, int len) {