FreeCalypso > hg > freecalypso-reveng
annotate mpffs/cat.c @ 394:07000c2d21cd
se_k200i: add compiled-in RF parameter table extracts
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 06 Nov 2022 02:35:54 +0000 |
parents | 7ceab8bfacb3 |
children |
rev | line source |
---|---|
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the main function and other code specific to mpffs-cat |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <ctype.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <unistd.h> |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "types.h" |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "struct.h" |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern char *imgfile; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 extern int verbose; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
37
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
18 int cat_v; |
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
19 |
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 cat_chunk(chi) |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 struct chunkinfo *chi; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 u8 *dp; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 size_t len; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int c; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 dp = chi->start; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 len = chi->len; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 while (len) { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 c = *dp++; |
37
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
31 if (!cat_v || c >= ' ' && c <= '~' || c == '\n') |
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 putchar(c); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 else { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (c & 0x80) { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 putchar('M'); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 putchar('-'); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 c &= 0x7F; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 putchar('^'); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 if (c == 0x7F) |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 putchar('?'); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 else |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 putchar(c + '@'); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 len--; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 |
40
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
49 void |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
50 extra_chunk_callback(obj, opaque) |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
51 struct objinfo *obj; |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
52 u_long opaque; |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
53 { |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
54 struct chunkinfo chi; |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
55 |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
56 size_extra_chunk(obj, &chi); |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
57 cat_chunk(&chi); |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
58 } |
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
59 |
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 cat_file(headidx) |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 struct objinfo obj; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 struct chunkinfo chi; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 obj.entryno = headidx; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 get_index_entry(&obj); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (obj.type != 0xF1) { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 fprintf(stderr, |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 "mpffs-cat: the requested FFS object is not a regular file\n"); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 exit(1); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 validate_chunk(&obj); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 size_head_chunk(&obj, &chi); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 cat_chunk(&chi); |
40
7ceab8bfacb3
mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
37
diff
changeset
|
75 iterate_extra_chunks(obj.descend, extra_chunk_callback, (u_long) 0); |
37
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
76 if (cat_v) |
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
77 putchar('\n'); |
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 usage() |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 fprintf(stderr, "usage: mpffs-cat [options] ffs-image pathname\n"); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 exit(1); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 main(argc, argv) |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 char **argv; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 { |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 extern int optind; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 int idx; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 parse_cmdline_options(argc, argv); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 if (argc - optind != 2) |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 usage(); |
37
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
95 if (verbose) { |
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
96 cat_v = 1; |
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
97 verbose--; |
8256eec598dd
mpffs-cat: more sensible handling of -v
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
98 } |
35
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 imgfile = argv[optind]; |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 preliminaries(); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 idx = find_pathname(argv[optind+1]); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 cat_file(idx); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 exit(0); |
ee4c761187cf
mpffs-cat implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 } |