1: /* Copyright (c) 1979 Regents of the University of California */
2: #include <sys/types.h>
3: #include <stdio.h>
4: #include <a.out.h>
5: #include <ctype.h>
6:
7: long ftell();
8:
9: /*
10: * Strings - extract strings from an object file for whatever
11: *
12: * Bill Joy UCB
13: * April 22, 1978
14: *
15: * The algorithm is to look for sequences of "non-junk" characters
16: * The variable "minlen" is the minimum length string printed.
17: * This helps get rid of garbage.
18: * Default minimum string length is 4 characters.
19: */
20:
21: struct exec ;
22: struct ovlhdr ovlbuf;
23:
24: char *infile = "Standard input";
25: int oflg;
26: int asdata;
27: long offset;
28: int minlength = 4;
29:
30: main(argc, argv)
31: int argc;
32: char *argv[];
33: {
34: register i;
35: off_t off;
36:
37: argc--, argv++;
38: while (argc > 0 && argv[0][0] == '-') {
39: register int i;
40: if (argv[0][1] == 0)
41: asdata++;
42: else for (i = 1; argv[0][i] != 0; i++) switch (argv[0][i]) {
43:
44: case 'o':
45: oflg++;
46: break;
47:
48: case 'a':
49: asdata++;
50: break;
51:
52: default:
53: if (!isdigit(argv[0][i])) {
54: fprintf(stderr, "Usage: strings [ - ] [ -o ] [ -# ] [ file ... ]\n");
55: exit(1);
56: }
57: minlength = argv[0][i] - '0';
58: for (i++; isdigit(argv[0][i]); i++)
59: minlength = minlength * 10 + argv[0][i] - '0';
60: i--;
61: break;
62: }
63: argc--, argv++;
64: }
65: do {
66: if (argc > 0) {
67: if (freopen(argv[0], "r", stdin) == NULL) {
68: perror(argv[0]);
69: exit(1);
70: }
71: infile = argv[0];
72: argc--, argv++;
73: }
74: fseek(stdin, (long) 0, 0);
75: if (asdata ||
76: fread((char *)&header, sizeof header, 1, stdin) != 1 ||
77: N_BADMAG(header)) {
78: fseek(stdin, (long) 0, 0);
79: find((long) 100000000L);
80: continue;
81: }
82: off = (long) N_TXTOFF(header) + (long) header.a_text;
83: if (header.a_magic == A_MAGIC5 || header.a_magic == A_MAGIC6) {
84: fread ((char *) &ovlbuf, sizeof ovlbuf, 1, stdin);
85: for (i = 0; i < NOVL; i++)
86: off += ovlbuf.ov_siz[i];
87: }
88: fseek(stdin, off, 0);
89: find((long) header.a_data);
90: } while (argc > 0);
91: }
92:
93: find(cnt)
94: long cnt;
95: {
96: static char buf[BUFSIZ];
97: register char *cp;
98: register int c, cc;
99:
100: cp = buf, cc = 0;
101: for (; cnt != 0; cnt--) {
102: c = getc(stdin);
103: if (c == '\n' || dirt(c) || cnt == 0) {
104: if (cp > buf && cp[-1] == '\n')
105: --cp;
106: *cp++ = 0;
107: if (cp > &buf[minlength]) {
108: if (oflg)
109: printf("%7D ", ftell(stdin) - cc - 1);
110: printf("%s\n", buf);
111: }
112: cp = buf, cc = 0;
113: } else {
114: if (cp < &buf[sizeof buf - 2])
115: *cp++ = c;
116: cc++;
117: }
118: if (ferror(stdin) || feof(stdin))
119: break;
120: }
121: }
122:
123: dirt(c)
124: int c;
125: {
126:
127: switch (c) {
128:
129: case '\n':
130: case '\f':
131: return (0);
132:
133: case 0177:
134: return (1);
135:
136: default:
137: return (c > 0200 || c < ' ');
138: }
139: }
Defined functions
dirt
defined in line
123; used 1 times
find
defined in line
93; used 2 times
main
defined in line
30;
never used
Defined variables
defined in line
21; used 8 times
oflg
defined in line
25; used 2 times