Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 68 lines (60 sloc) 1.502 kb
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
1 /*
2 * test-line-buffer.c: code to exercise the svn importer's input helper
3 */
4
5 #include "git-compat-util.h"
6 #include "vcs-svn/line_buffer.h"
7
8 static uint32_t strtouint32(const char *s)
9 {
10 char *end;
11 uintmax_t n = strtoumax(s, &end, 10);
12 if (*s == '\0' || *end != '\0')
13 die("invalid count: %s", s);
14 return (uint32_t) n;
15 }
16
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
17 static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
18 {
19 switch (*command) {
20 case 'c':
21 if (!prefixcmp(command, "copy ")) {
7b990c9 @jrn vcs-svn: tweak test-line-buffer to not assume line-oriented input
jrn authored
22 buffer_copy_bytes(buf, strtouint32(arg));
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
23 return;
24 }
25 case 'r':
26 if (!prefixcmp(command, "read ")) {
27 const char *s = buffer_read_string(buf, strtouint32(arg));
7b990c9 @jrn vcs-svn: tweak test-line-buffer to not assume line-oriented input
jrn authored
28 fputs(s, stdout);
29 return;
30 }
31 case 's':
32 if (!prefixcmp(command, "skip ")) {
33 buffer_skip_bytes(buf, strtouint32(arg));
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
34 return;
35 }
36 default:
37 die("unrecognized command: %s", command);
38 }
39 }
40
41 static void handle_line(const char *line, struct line_buffer *stdin_buf)
42 {
43 const char *arg = strchr(line, ' ');
44 if (!arg)
45 die("no argument in line: %s", line);
46 handle_command(line, arg + 1, stdin_buf);
47 }
48
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
49 int main(int argc, char *argv[])
50 {
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
51 struct line_buffer stdin_buf = LINE_BUFFER_INIT;
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
52 char *s;
53
54 if (argc != 1)
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
55 usage("test-line-buffer < script");
56
57 if (buffer_init(&stdin_buf, NULL))
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
58 die_errno("open error");
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
59 while ((s = buffer_read_line(&stdin_buf)))
60 handle_line(s, &stdin_buf);
61 if (buffer_deinit(&stdin_buf))
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
62 die("input error");
63 if (ferror(stdout))
64 die("output error");
850c5ea @jrn vcs-svn: make test-line-buffer input format more flexible
jrn authored
65 buffer_reset(&stdin_buf);
3bbaec0 @barrbrain Add stream helper library
barrbrain authored
66 return 0;
67 }
Something went wrong with that request. Please try again.