5 static void pack_line(const char *line)
7 if (!strcmp(line, "0000") || !strcmp(line, "0000\n"))
9 else if (!strcmp(line, "0001") || !strcmp(line, "0001\n"))
12 packet_write_fmt(1, "%s", line);
15 static void pack(int argc, const char **argv)
17 if (argc) { /* read from argv */
19 for (i = 0; i < argc; i++)
21 } else { /* read from stdin */
22 char line[LARGE_PACKET_MAX];
23 while (fgets(line, sizeof(line), stdin)) {
29 static void unpack(void)
31 struct packet_reader reader;
32 packet_reader_init(&reader, 0, NULL, 0,
33 PACKET_READ_GENTLE_ON_EOF |
34 PACKET_READ_CHOMP_NEWLINE);
36 while (packet_reader_read(&reader) != PACKET_READ_EOF) {
37 switch (reader.status) {
40 case PACKET_READ_NORMAL:
41 printf("%s\n", reader.line);
43 case PACKET_READ_FLUSH:
46 case PACKET_READ_DELIM:
49 case PACKET_READ_RESPONSE_END:
56 static void unpack_sideband(void)
58 struct packet_reader reader;
59 packet_reader_init(&reader, 0, NULL, 0,
60 PACKET_READ_GENTLE_ON_EOF |
61 PACKET_READ_CHOMP_NEWLINE);
63 while (packet_reader_read(&reader) != PACKET_READ_EOF) {
67 switch (reader.status) {
70 case PACKET_READ_NORMAL:
71 band = reader.line[0] & 0xff;
72 if (band < 1 || band > 2)
73 continue; /* skip non-sideband packets */
76 write_or_die(fd, reader.line + 1, reader.pktlen - 1);
78 case PACKET_READ_FLUSH:
80 case PACKET_READ_DELIM:
81 case PACKET_READ_RESPONSE_END:
87 int cmd__pkt_line(int argc, const char **argv)
90 die("too few arguments");
92 if (!strcmp(argv[1], "pack"))
93 pack(argc - 2, argv + 2);
94 else if (!strcmp(argv[1], "unpack"))
96 else if (!strcmp(argv[1], "unpack-sideband"))
99 die("invalid argument '%s'", argv[1]);