4 static void pack_line(const char *line)
6 if (!strcmp(line, "0000") || !strcmp(line, "0000\n"))
8 else if (!strcmp(line, "0001") || !strcmp(line, "0001\n"))
11 packet_write_fmt(1, "%s", line);
14 static void pack(int argc, const char **argv)
16 if (argc) { /* read from argv */
18 for (i = 0; i < argc; i++)
20 } else { /* read from stdin */
21 char line[LARGE_PACKET_MAX];
22 while (fgets(line, sizeof(line), stdin)) {
28 static void unpack(void)
30 struct packet_reader reader;
31 packet_reader_init(&reader, 0, NULL, 0,
32 PACKET_READ_GENTLE_ON_EOF |
33 PACKET_READ_CHOMP_NEWLINE);
35 while (packet_reader_read(&reader) != PACKET_READ_EOF) {
36 switch (reader.status) {
39 case PACKET_READ_NORMAL:
40 printf("%s\n", reader.line);
42 case PACKET_READ_FLUSH:
45 case PACKET_READ_DELIM:
52 static void unpack_sideband(void)
54 struct packet_reader reader;
55 packet_reader_init(&reader, 0, NULL, 0,
56 PACKET_READ_GENTLE_ON_EOF |
57 PACKET_READ_CHOMP_NEWLINE);
59 while (packet_reader_read(&reader) != PACKET_READ_EOF) {
63 switch (reader.status) {
66 case PACKET_READ_NORMAL:
67 band = reader.line[0] & 0xff;
68 if (band < 1 || band > 2)
69 die("unexpected side band %d", band);
72 write_or_die(fd, reader.line + 1, reader.pktlen - 1);
74 case PACKET_READ_FLUSH:
76 case PACKET_READ_DELIM:
82 int cmd_main(int argc, const char **argv)
85 die("too few arguments");
87 if (!strcmp(argv[1], "pack"))
88 pack(argc - 2, argv + 2);
89 else if (!strcmp(argv[1], "unpack"))
91 else if (!strcmp(argv[1], "unpack-sideband"))
94 die("invalid argument '%s'", argv[1]);