Merge branch 'nd/index-doc'
[gitweb.git] / test-line-buffer.c
index ec19b13ee23d0de5a2423941655452627d3d00cc..7ec9b13c9b2ceb84fb6dd0dd229e9f6cb8c1a635 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include "git-compat-util.h"
+#include "strbuf.h"
 #include "vcs-svn/line_buffer.h"
 
 static uint32_t strtouint32(const char *s)
@@ -17,17 +18,20 @@ static uint32_t strtouint32(const char *s)
 static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
 {
        switch (*command) {
+       case 'b':
+               if (!prefixcmp(command, "binary ")) {
+                       struct strbuf sb = STRBUF_INIT;
+                       strbuf_addch(&sb, '>');
+                       buffer_read_binary(buf, &sb, strtouint32(arg));
+                       fwrite(sb.buf, 1, sb.len, stdout);
+                       strbuf_release(&sb);
+                       return;
+               }
        case 'c':
                if (!prefixcmp(command, "copy ")) {
                        buffer_copy_bytes(buf, strtouint32(arg));
                        return;
                }
-       case 'r':
-               if (!prefixcmp(command, "read ")) {
-                       const char *s = buffer_read_string(buf, strtouint32(arg));
-                       fputs(s, stdout);
-                       return;
-               }
        case 's':
                if (!prefixcmp(command, "skip ")) {
                        buffer_skip_bytes(buf, strtouint32(arg));
@@ -59,13 +63,18 @@ int main(int argc, char *argv[])
        else if (argc == 2)
                filename = argv[1];
        else
-               usage("test-line-buffer [file] < script");
+               usage("test-line-buffer [file | &fd] < script");
 
        if (buffer_init(&stdin_buf, NULL))
                die_errno("open error");
        if (filename) {
-               if (buffer_init(&file_buf, filename))
-                       die_errno("error opening %s", filename);
+               if (*filename == '&') {
+                       if (buffer_fdinit(&file_buf, strtouint32(filename + 1)))
+                               die_errno("error opening fd %s", filename + 1);
+               } else {
+                       if (buffer_init(&file_buf, filename))
+                               die_errno("error opening %s", filename);
+               }
                input = &file_buf;
        }