2 * test-line-buffer.c: code to exercise the svn importer's input helper
5 #include "git-compat-util.h"
6 #include "vcs-svn/line_buffer.h"
8 static uint32_t strtouint32(const char *s)
11 uintmax_t n = strtoumax(s, &end, 10);
12 if (*s == '\0' || *end != '\0')
13 die("invalid count: %s", s);
17 static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
21 if (!prefixcmp(command, "copy ")) {
22 buffer_copy_bytes(buf, strtouint32(arg));
26 if (!prefixcmp(command, "read ")) {
27 const char *s = buffer_read_string(buf, strtouint32(arg));
32 if (!prefixcmp(command, "skip ")) {
33 buffer_skip_bytes(buf, strtouint32(arg));
37 die("unrecognized command: %s", command);
41 static void handle_line(const char *line, struct line_buffer *stdin_buf)
43 const char *arg = strchr(line, ' ');
45 die("no argument in line: %s", line);
46 handle_command(line, arg + 1, stdin_buf);
49 int main(int argc, char *argv[])
51 struct line_buffer stdin_buf = LINE_BUFFER_INIT;
55 usage("test-line-buffer < script");
57 if (buffer_init(&stdin_buf, NULL))
58 die_errno("open error");
59 while ((s = buffer_read_line(&stdin_buf)))
60 handle_line(s, &stdin_buf);
61 if (buffer_deinit(&stdin_buf))
65 buffer_reset(&stdin_buf);