2010-08-10 00:39:43 +02:00
|
|
|
/*
|
|
|
|
* test-line-buffer.c: code to exercise the svn importer's input helper
|
|
|
|
*
|
|
|
|
* Input format:
|
|
|
|
* number NL
|
|
|
|
* (number bytes) NL
|
|
|
|
* number NL
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "vcs-svn/line_buffer.h"
|
|
|
|
|
|
|
|
static uint32_t strtouint32(const char *s)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
uintmax_t n = strtoumax(s, &end, 10);
|
|
|
|
if (*s == '\0' || *end != '\0')
|
|
|
|
die("invalid count: %s", s);
|
|
|
|
return (uint32_t) n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2010-10-11 04:41:06 +02:00
|
|
|
struct line_buffer buf = LINE_BUFFER_INIT;
|
2010-08-10 00:39:43 +02:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage("test-line-buffer < input.txt");
|
2010-10-11 04:41:06 +02:00
|
|
|
if (buffer_init(&buf, NULL))
|
2010-08-10 00:39:43 +02:00
|
|
|
die_errno("open error");
|
2010-10-11 04:41:06 +02:00
|
|
|
while ((s = buffer_read_line(&buf))) {
|
|
|
|
s = buffer_read_string(&buf, strtouint32(s));
|
2010-08-10 00:39:43 +02:00
|
|
|
fputs(s, stdout);
|
|
|
|
fputc('\n', stdout);
|
2010-10-11 04:41:06 +02:00
|
|
|
buffer_skip_bytes(&buf, 1);
|
|
|
|
if (!(s = buffer_read_line(&buf)))
|
2010-08-10 00:39:43 +02:00
|
|
|
break;
|
2010-10-11 04:41:06 +02:00
|
|
|
buffer_copy_bytes(&buf, strtouint32(s) + 1);
|
2010-08-10 00:39:43 +02:00
|
|
|
}
|
2010-10-11 04:41:06 +02:00
|
|
|
if (buffer_deinit(&buf))
|
2010-08-10 00:39:43 +02:00
|
|
|
die("input error");
|
|
|
|
if (ferror(stdout))
|
|
|
|
die("output error");
|
2010-10-11 04:41:06 +02:00
|
|
|
buffer_reset(&buf);
|
2010-08-10 00:39:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|