test-line-buffer.con commit t7407: fix line endings for mingw build (c91897b)
   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{
  25        char *s;
  26
  27        if (argc != 1)
  28                usage("test-line-buffer < input.txt");
  29        if (buffer_init(NULL))
  30                die_errno("open error");
  31        while ((s = buffer_read_line())) {
  32                s = buffer_read_string(strtouint32(s));
  33                fputs(s, stdout);
  34                fputc('\n', stdout);
  35                buffer_skip_bytes(1);
  36                if (!(s = buffer_read_line()))
  37                        break;
  38                buffer_copy_bytes(strtouint32(s) + 1);
  39        }
  40        if (buffer_deinit())
  41                die("input error");
  42        if (ferror(stdout))
  43                die("output error");
  44        buffer_reset();
  45        return 0;
  46}