comparison mpffs/cat.c @ 37:8256eec598dd

mpffs-cat: more sensible handling of -v
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Jun 2013 17:56:27 +0000
parents ee4c761187cf
children 7ceab8bfacb3
comparison
equal deleted inserted replaced
36:390be89892c4 37:8256eec598dd
13 #include "struct.h" 13 #include "struct.h"
14 14
15 extern char *imgfile; 15 extern char *imgfile;
16 extern int verbose; 16 extern int verbose;
17 17
18 int cat_v;
19
18 cat_chunk(chi) 20 cat_chunk(chi)
19 struct chunkinfo *chi; 21 struct chunkinfo *chi;
20 { 22 {
21 u8 *dp; 23 u8 *dp;
22 size_t len; 24 size_t len;
24 26
25 dp = chi->start; 27 dp = chi->start;
26 len = chi->len; 28 len = chi->len;
27 while (len) { 29 while (len) {
28 c = *dp++; 30 c = *dp++;
29 if (!verbose || c >= ' ' && c <= '~' || c == '\n') 31 if (!cat_v || c >= ' ' && c <= '~' || c == '\n')
30 putchar(c); 32 putchar(c);
31 else { 33 else {
32 if (c & 0x80) { 34 if (c & 0x80) {
33 putchar('M'); 35 putchar('M');
34 putchar('-'); 36 putchar('-');
57 "mpffs-cat: the requested FFS object is not a regular file\n"); 59 "mpffs-cat: the requested FFS object is not a regular file\n");
58 exit(1); 60 exit(1);
59 } 61 }
60 validate_chunk(&obj); 62 validate_chunk(&obj);
61 size_head_chunk(&obj, &chi); 63 size_head_chunk(&obj, &chi);
62 if (verbose)
63 printf("\n--- file content:\n");
64 cat_chunk(&chi); 64 cat_chunk(&chi);
65 for (ent = obj.descend; ent != 0xFFFF; ent = obj.descend) { 65 for (ent = obj.descend; ent != 0xFFFF; ent = obj.descend) {
66 obj.entryno = ent; 66 obj.entryno = ent;
67 get_index_entry(&obj); 67 get_index_entry(&obj);
68 if (obj.type != 0xF4) { 68 if (obj.type != 0xF4) {
73 } 73 }
74 validate_chunk(&obj); 74 validate_chunk(&obj);
75 size_extra_chunk(&obj, &chi); 75 size_extra_chunk(&obj, &chi);
76 cat_chunk(&chi); 76 cat_chunk(&chi);
77 } 77 }
78 if (verbose) 78 if (cat_v)
79 printf("\n-- end quote --\n"); 79 putchar('\n');
80 } 80 }
81 81
82 usage() 82 usage()
83 { 83 {
84 fprintf(stderr, "usage: mpffs-cat [options] ffs-image pathname\n"); 84 fprintf(stderr, "usage: mpffs-cat [options] ffs-image pathname\n");
92 int idx; 92 int idx;
93 93
94 parse_cmdline_options(argc, argv); 94 parse_cmdline_options(argc, argv);
95 if (argc - optind != 2) 95 if (argc - optind != 2)
96 usage(); 96 usage();
97 if (verbose) {
98 cat_v = 1;
99 verbose--;
100 }
97 imgfile = argv[optind]; 101 imgfile = argv[optind];
98 preliminaries(); 102 preliminaries();
99 idx = find_pathname(argv[optind+1]); 103 idx = find_pathname(argv[optind+1]);
100 cat_file(idx); 104 cat_file(idx);
101 exit(0); 105 exit(0);