1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(DOSCCS) && !defined(lint)
8: char copyright[] =
9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10: All rights reserved.\n";
11:
12: static char sccsid[] = "@(#)strings.c 5.1.2 (2.11BSD GTE) 2/25/94";
13: #endif
14:
15: #include <sys/types.h>
16: #include <stdio.h>
17: #include <a.out.h>
18: #include <ctype.h>
19: #include <sys/file.h>
20:
21: /*
22: * strings
23: */
24:
25: struct xexec ;
26:
27: char *infile = "Standard input";
28: int oflg;
29: int asdata;
30: long offset;
31: int minlength = 4;
32:
33: main(argc, argv)
34: int argc;
35: char *argv[];
36: {
37:
38: argc--, argv++;
39: while (argc > 0 && argv[0][0] == '-') {
40: register int i;
41: if (argv[0][1] == 0)
42: asdata++;
43: else for (i = 1; argv[0][i] != 0; i++) switch (argv[0][i]) {
44:
45: case 'o':
46: oflg++;
47: break;
48:
49: case 'a':
50: asdata++;
51: break;
52:
53: default:
54: if (!isdigit(argv[0][i])) {
55: fprintf(stderr, "Usage: strings [ -a ] [ -o ] [ -# ] [ file ... ]\n");
56: exit(1);
57: }
58: minlength = argv[0][i] - '0';
59: for (i++; isdigit(argv[0][i]); i++)
60: minlength = minlength * 10 + argv[0][i] - '0';
61: i--;
62: break;
63: }
64: argc--, argv++;
65: }
66: do {
67: if (argc > 0) {
68: if (freopen(argv[0], "r", stdin) == NULL) {
69: perror(argv[0]);
70: exit(1);
71: }
72: infile = argv[0];
73: argc--, argv++;
74: }
75: fseek(stdin, (long) 0, L_SET);
76: if (asdata ||
77: fread((char *)&header, sizeof header, 1, stdin) != 1 ||
78: N_BADMAG(header.e)) {
79: fseek(stdin, (long) 0, L_SET);
80: find((long) 100000000L);
81: continue;
82: }
83: fseek(stdin, (long) N_DATOFF(header), L_SET);
84: find((long) header.e.a_data);
85: } while (argc > 0);
86: }
87:
88: find(cnt)
89: long cnt;
90: {
91: static char buf[BUFSIZ];
92: register char *cp;
93: register int c, cc;
94:
95: cp = buf, cc = 0;
96: for (; cnt != 0; cnt--) {
97: c = getc(stdin);
98: if (c == '\n' || dirt(c) || cnt == 0) {
99: if (cp > buf && cp[-1] == '\n')
100: --cp;
101: *cp++ = 0;
102: if (cp > &buf[minlength]) {
103: if (oflg)
104: printf("%ld ", ftell(stdin) - cc - 1);
105: printf("%s\n", buf);
106: }
107: cp = buf, cc = 0;
108: } else {
109: if (cp < &buf[sizeof buf - 2])
110: *cp++ = c;
111: cc++;
112: }
113: if (ferror(stdin) || feof(stdin))
114: break;
115: }
116: }
117:
118: dirt(c)
119: int c;
120: {
121:
122: switch (c) {
123:
124: case '\n':
125: case '\f':
126: return (0);
127:
128: case 0177:
129: return (1);
130:
131: default:
132: return (c > 0200 || c < ' ');
133: }
134: }
Defined functions
dirt
defined in line
118; used 1 times
find
defined in line
88; used 2 times
main
defined in line
33;
never used
Defined variables
defined in line
25; used 5 times
oflg
defined in line
28; used 2 times