-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a 'paste' command to write a local file to the terminal #27
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leave uninitialized and see below. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move check after initializing |
||
i = read(fd, buf, BUFSIZE); | ||
if (i < 0) { | ||
ret = errno; | ||
fprintf(stderr, "%s\n", strerror(ret)); | ||
return -ret; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leaks |
||
} | ||
|
||
ios->write(ios, buf, i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You call write with |
||
} | ||
|
||
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 <file>", | ||
}, { | ||
.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 <scriptfile>", | ||
}, { | ||
.name = "log", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to initialize.