aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-11-14 13:56:25 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-11-22 18:28:55 +0000
commit8619ebd778b43288f74cb260d84fcf7831a1982d (patch)
treebe0adc1f639c43a28723897b501360f602405881
parentinstall: small rewording and restructuring of PGO instructions (diff)
pgo: support for specifying multiple stimuli files
-rw-r--r--pgo/pgo.c70
1 files 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 <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -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;
+
+ 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;
+ }
+
+ 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;
+ }
- vt_from_slave(&term, data, st.st_size);
+ int fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "error: %s: failed to open: %s",
+ argv[i], strerror(errno));
+ goto out;
+ }
- free(data);
+ 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;
}