]> git.ipfire.org Git - thirdparty/git.git/blame - test-line-buffer.c
vcs-svn: teach line_buffer to handle multiple input files
[thirdparty/git.git] / test-line-buffer.c
CommitLineData
3bbaec00
DB
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 */
10
11#include "git-compat-util.h"
12#include "vcs-svn/line_buffer.h"
13
14static 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}
22
23int main(int argc, char *argv[])
24{
e5e45ca1 25 struct line_buffer buf = LINE_BUFFER_INIT;
3bbaec00
DB
26 char *s;
27
28 if (argc != 1)
29 usage("test-line-buffer < input.txt");
e5e45ca1 30 if (buffer_init(&buf, NULL))
3bbaec00 31 die_errno("open error");
e5e45ca1
JN
32 while ((s = buffer_read_line(&buf))) {
33 s = buffer_read_string(&buf, strtouint32(s));
3bbaec00
DB
34 fputs(s, stdout);
35 fputc('\n', stdout);
e5e45ca1
JN
36 buffer_skip_bytes(&buf, 1);
37 if (!(s = buffer_read_line(&buf)))
3bbaec00 38 break;
e5e45ca1 39 buffer_copy_bytes(&buf, strtouint32(s) + 1);
3bbaec00 40 }
e5e45ca1 41 if (buffer_deinit(&buf))
3bbaec00
DB
42 die("input error");
43 if (ferror(stdout))
44 die("output error");
e5e45ca1 45 buffer_reset(&buf);
3bbaec00
DB
46 return 0;
47}