baddc

bad dc(1)
git clone git://bvnf.space/baddc.git
Log | Files | Refs

commit 59c261a78b8a7a493fd8e4670de935e3ac32bf2f
parent fdd44d34944a2af483accefd481ad7e544aad345
Author: phoebos <ben@bvnf.space>
Date:   Mon, 31 Jan 2022 00:11:25 +0000

read commands from file if an argument is provided

Diffstat:
Mbaddc.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/baddc.c b/baddc.c @@ -105,7 +105,18 @@ struct map { #define NUM_OPS ((sizeof(ops)) / (sizeof(*ops))) -int main(void) { +int main(int argc, char **argv) { + FILE *fp = NULL; + if (argc == 1) { + fp = stdin; + } else { + fp = fopen(argv[1], "r"); + if (fp == NULL) { + perror(argv[1]); + return 1; + } + } + char *buf = NULL; size_t buflen = 0; ssize_t n = 0; @@ -113,7 +124,7 @@ int main(void) { int curnum = 0; int numready = 0; int neg = 1; - while ((n = getline(&buf, &buflen, stdin)) != -1) { + while ((n = getline(&buf, &buflen, fp)) != -1) { for (ssize_t i = 0; i < n - 1; i++) { if (buf[i] == 'q') goto end;