1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32: #include <sys/cdefs.h>
33: #ifndef lint
34: __COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\
35: The Regents of the University of California. All rights reserved.\n");
36: #endif
37:
38: #ifndef lint
39: #if 0
40: static char sccsid[] = "@(#)ppt.c 8.1 (Berkeley) 5/31/93";
41: #else
42: __RCSID("$NetBSD: ppt.c,v 1.16 2004/01/27 20:30:30 jsm Exp $");
43: #endif
44: #endif
45:
46: #include <err.h>
47: #include <stdio.h>
48: #include <stdlib.h>
49: #include <string.h>
50: #include <unistd.h>
51:
52: #define EDGE "___________"
53:
54: void usage(void);
55: int main(int, char *[]);
56: static void putppt(int);
57: int getppt(const char *);
58:
59: void
60: usage(void)
61: {
62: extern char *__progname;
63: fprintf(stderr, "usage: %s [-d] [string ...]\n", __progname);
64: exit(1);
65: }
66:
67: int
68: main(argc, argv)
69: int argc;
70: char **argv;
71: {
72: char *p, buf[132];
73: int c, start, neednl, dflag;
74:
75:
76: setregid(getgid(), getgid());
77:
78: dflag = 0;
79: while ((c = getopt(argc, argv, "dh")) != -1)
80: switch(c) {
81: case 'd':
82: dflag = 1;
83: break;
84: case 'h':
85: case '?':
86: default:
87: usage();
88: }
89: argc -= optind;
90: argv += optind;
91:
92: if (dflag) {
93: if (argc > 0)
94: usage();
95:
96: start = 0;
97: neednl = 0;
98: while (fgets(buf, sizeof(buf), stdin) != NULL) {
99: c = getppt(buf);
100: if (c < 0) {
101: if (start) {
102:
103: if (neednl)
104: putchar('\n');
105: exit(0);
106: } else
107: continue;
108: }
109: start = 1;
110: putchar(c);
111: neednl = (c != '\n');
112: }
113: if (!feof(stdin))
114: err(1, "fgets");
115: if (neednl)
116: putchar('\n');
117: } else {
118: (void) puts(EDGE);
119: if (argc > 0)
120: while ((p = *argv++)) {
121: for (; *p; ++p)
122: putppt((int)*p);
123: if ((*(argv)))
124: putppt((int)' ');
125: }
126: else while ((c = getchar()) != EOF)
127: putppt(c);
128: (void) puts(EDGE);
129: }
130: exit(0);
131: }
132:
133: static void
134: putppt(c)
135: int c;
136: {
137: int i;
138:
139: (void) putchar('|');
140: for (i = 7; i >= 0; i--) {
141: if (i == 2)
142: (void) putchar('.');
143: if ((c&(1<<i)) != 0)
144: (void) putchar('o');
145: else
146: (void) putchar(' ');
147: }
148: (void) putchar('|');
149: (void) putchar('\n');
150: }
151:
152: int
153: getppt(const char *buf)
154: {
155: const char *p = strchr(buf, '.');
156: int c;
157:
158: if (p == NULL)
159: return (-1);
160:
161: c = 0;
162: if (p[ 3] != ' ')
163: c |= 0001;
164: if (p[ 2] != ' ')
165: c |= 0002;
166: if (p[ 1] != ' ')
167: c |= 0004;
168: if (p[-1] != ' ')
169: c |= 0010;
170: if (p[-2] != ' ')
171: c |= 0020;
172: if (p[-3] != ' ')
173: c |= 0040;
174: if (p[-4] != ' ')
175: c |= 0100;
176: if (p[-5] != ' ')
177: c |= 0200;
178:
179: return (c);
180: }