3 static void pack_line(const char *line)
5 if (!strcmp(line, "0000") || !strcmp(line, "0000\n"))
7 else if (!strcmp(line, "0001") || !strcmp(line, "0001\n"))
10 packet_write_fmt(1, "%s", line);
13 static void pack(int argc, const char **argv)
15 if (argc) { /* read from argv */
17 for (i = 0; i < argc; i++)
19 } else { /* read from stdin */
20 char line[LARGE_PACKET_MAX];
21 while (fgets(line, sizeof(line), stdin)) {
27 static void unpack(void)
29 struct packet_reader reader;
30 packet_reader_init(&reader, 0, NULL, 0,
31 PACKET_READ_GENTLE_ON_EOF |
32 PACKET_READ_CHOMP_NEWLINE);
34 while (packet_reader_read(&reader) != PACKET_READ_EOF) {
35 switch (reader.status) {
38 case PACKET_READ_NORMAL:
39 printf("%s\n", reader.line);
41 case PACKET_READ_FLUSH:
44 case PACKET_READ_DELIM:
51 int cmd_main(int argc, const char **argv)
54 die("too few arguments");
56 if (!strcmp(argv[1], "pack"))
57 pack(argc - 2, argv + 2);
58 else if (!strcmp(argv[1], "unpack"))
61 die("invalid argument '%s'", argv[1]);