From 8619ebd778b43288f74cb260d84fcf7831a1982d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 14 Nov 2020 14:56:25 +0100 Subject: [PATCH] pgo: support for specifying multiple stimuli files --- pgo/pgo.c | 70 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/pgo/pgo.c b/pgo/pgo.c index c9c1a896..bef61b4b 100644 --- a/pgo/pgo.c +++ b/pgo/pgo.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include @@ -10,6 +12,14 @@ #include "user-notification.h" #include "vt.h" +static void +usage(const char *prog_name) +{ + printf( + "Usage: %s stimuli-file1 stimuli-file2 ... stimuli-fileN\n", + prog_name); +} + void wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...) {} enum async_write_status @@ -172,6 +182,11 @@ extract_finish(struct extraction_context *context, char **text, size_t *len) int main(int argc, const char *const *argv) { + if (argc < 2) { + usage(argv[0]); + return EXIT_FAILURE; + } + const int row_count = 67; const int col_count = 135; const int grid_row_count = 16384; @@ -209,25 +224,52 @@ main(int argc, const char *const *argv) }, }; - struct stat st; - if (stat(argv[1], &st) < 0) - return 1; - uint8_t *data = malloc(st.st_size); - int fd = open(argv[1], O_RDONLY); - if (fd < 0) - return 1; - ssize_t amount = read(fd, data, st.st_size); - if (amount != st.st_size) - return 1; - close(fd); + int ret = EXIT_FAILURE; - vt_from_slave(&term, data, st.st_size); + for (int i = 1; i < argc; i++) { + struct stat st; + if (stat(argv[i], &st) < 0) { + fprintf(stderr, "error: %s: failed to stat: %s", + argv[i], strerror(errno)); + goto out; + } - free(data); + uint8_t *data = malloc(st.st_size); + if (data == NULL) { + fprintf(stderr, "error: %s: failed to allocate buffer: %s", + argv[i], strerror(errno)); + goto out; + } + + int fd = open(argv[1], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "error: %s: failed to open: %s", + argv[i], strerror(errno)); + goto out; + } + + ssize_t amount = read(fd, data, st.st_size); + if (amount != st.st_size) { + fprintf(stderr, "error: %s: failed to read: %s", + argv[i], strerror(errno)); + goto out; + } + + close(fd); + + printf("Feeding VT parser with %s\n", argv[i]); + vt_from_slave(&term, data, st.st_size); + free(data); + } + + ret = EXIT_SUCCESS; + +out: for (int i = 0; i < grid_row_count; i++) { free(rows[i]->cells); free(rows[i]); } + free(rows); - return 0; + return ret; }