Code

vcs-svn: teach line_buffer to handle multiple input files
[git.git] / test-line-buffer.c
1 /*
2  * test-line-buffer.c: code to exercise the svn importer's input helper
3  *
4  * Input format:
5  *      number NL
6  *      (number bytes) NL
7  *      number NL
8  *      ...
9  */
11 #include "git-compat-util.h"
12 #include "vcs-svn/line_buffer.h"
14 static uint32_t strtouint32(const char *s)
15 {
16         char *end;
17         uintmax_t n = strtoumax(s, &end, 10);
18         if (*s == '\0' || *end != '\0')
19                 die("invalid count: %s", s);
20         return (uint32_t) n;
21 }
23 int main(int argc, char *argv[])
24 {
25         struct line_buffer buf = LINE_BUFFER_INIT;
26         char *s;
28         if (argc != 1)
29                 usage("test-line-buffer < input.txt");
30         if (buffer_init(&buf, NULL))
31                 die_errno("open error");
32         while ((s = buffer_read_line(&buf))) {
33                 s = buffer_read_string(&buf, strtouint32(s));
34                 fputs(s, stdout);
35                 fputc('\n', stdout);
36                 buffer_skip_bytes(&buf, 1);
37                 if (!(s = buffer_read_line(&buf)))
38                         break;
39                 buffer_copy_bytes(&buf, strtouint32(s) + 1);
40         }
41         if (buffer_deinit(&buf))
42                 die("input error");
43         if (ferror(stdout))
44                 die("output error");
45         buffer_reset(&buf);
46         return 0;
47 }