fmt.c revision 1.27 1 1.27 christos /* $NetBSD: fmt.c,v 1.27 2007/06/03 22:39:21 christos Exp $ */
2 1.4 jtc
3 1.1 cgd /*
4 1.4 jtc * Copyright (c) 1980, 1993
5 1.4 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.17 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.6 lukem #include <sys/cdefs.h>
33 1.1 cgd #ifndef lint
34 1.6 lukem __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
35 1.6 lukem The Regents of the University of California. All rights reserved.\n");
36 1.1 cgd #endif /* not lint */
37 1.1 cgd
38 1.1 cgd #ifndef lint
39 1.4 jtc #if 0
40 1.4 jtc static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
41 1.4 jtc #endif
42 1.27 christos __RCSID("$NetBSD: fmt.c,v 1.27 2007/06/03 22:39:21 christos Exp $");
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.16 wiz #include <ctype.h>
46 1.16 wiz #include <locale.h>
47 1.1 cgd #include <stdio.h>
48 1.3 cgd #include <stdlib.h>
49 1.26 christos #include <unistd.h>
50 1.26 christos #include <errno.h>
51 1.26 christos #include <err.h>
52 1.26 christos #include <limits.h>
53 1.3 cgd #include <string.h>
54 1.19 christos #include "buffer.h"
55 1.1 cgd
56 1.1 cgd /*
57 1.1 cgd * fmt -- format the concatenation of input files or standard input
58 1.1 cgd * onto standard output. Designed for use with Mail ~|
59 1.1 cgd *
60 1.1 cgd * Syntax : fmt [ goal [ max ] ] [ name ... ]
61 1.1 cgd * Authors: Kurt Shoens (UCB) 12/7/78;
62 1.1 cgd * Liz Allen (UMCP) 2/24/83 [Addition of goal length concept].
63 1.1 cgd */
64 1.1 cgd
65 1.1 cgd /* LIZ@UOM 6/18/85 --New variables goal_length and max_length */
66 1.1 cgd #define GOAL_LENGTH 65
67 1.1 cgd #define MAX_LENGTH 75
68 1.19 christos static size_t goal_length; /* Target or goal line length in output */
69 1.19 christos static size_t max_length; /* Max line length in output */
70 1.19 christos static size_t pfx; /* Current leading blank count */
71 1.26 christos static int raw; /* Don't treat mail specially */
72 1.24 christos static int lineno; /* Current input line */
73 1.24 christos static int mark; /* Last place we saw a head line */
74 1.19 christos static int center;
75 1.19 christos static struct buffer outbuf;
76 1.1 cgd
77 1.19 christos static const char *headnames[] = {"To", "Subject", "Cc", 0};
78 1.1 cgd
79 1.26 christos static void usage(void) __attribute__((__noreturn__));
80 1.26 christos static int getnum(const char *, const char *, size_t *, int);
81 1.16 wiz static void fmt(FILE *);
82 1.16 wiz static int ispref(const char *, const char *);
83 1.16 wiz static void leadin(void);
84 1.16 wiz static void oflush(void);
85 1.19 christos static void pack(const char *, size_t);
86 1.19 christos static void prefix(const struct buffer *, int);
87 1.16 wiz static void split(const char *, int);
88 1.19 christos static void tabulate(struct buffer *);
89 1.10 jdolecek
90 1.19 christos
91 1.19 christos int ishead(const char *);
92 1.6 lukem
93 1.1 cgd /*
94 1.1 cgd * Drive the whole formatter by managing input files. Also,
95 1.1 cgd * cause initialization of the output stuff and flush it out
96 1.1 cgd * at the end.
97 1.1 cgd */
98 1.1 cgd
99 1.6 lukem int
100 1.16 wiz main(int argc, char **argv)
101 1.1 cgd {
102 1.6 lukem FILE *fi;
103 1.6 lukem int errs = 0;
104 1.26 christos int compat = 1;
105 1.26 christos int c;
106 1.1 cgd
107 1.1 cgd goal_length = GOAL_LENGTH;
108 1.1 cgd max_length = MAX_LENGTH;
109 1.19 christos buf_init(&outbuf);
110 1.1 cgd lineno = 1;
111 1.24 christos mark = -10;
112 1.5 kleink
113 1.19 christos setprogname(*argv);
114 1.23 christos (void)setlocale(LC_ALL, "");
115 1.5 kleink
116 1.26 christos while ((c = getopt(argc, argv, "Cg:m:r")) != -1)
117 1.26 christos switch (c) {
118 1.26 christos case 'C':
119 1.26 christos center++;
120 1.26 christos break;
121 1.26 christos case 'g':
122 1.26 christos (void)getnum(optarg, "goal", &goal_length, 1);
123 1.26 christos compat = 0;
124 1.26 christos break;
125 1.26 christos case 'm':
126 1.26 christos (void)getnum(optarg, "max", &max_length, 1);
127 1.26 christos compat = 0;
128 1.26 christos break;
129 1.26 christos case 'r':
130 1.26 christos raw++;
131 1.26 christos break;
132 1.26 christos default:
133 1.26 christos usage();
134 1.26 christos }
135 1.26 christos
136 1.26 christos argc -= optind;
137 1.26 christos argv += optind;
138 1.26 christos
139 1.1 cgd /*
140 1.26 christos * compatibility with old usage.
141 1.1 cgd */
142 1.27 christos if (compat && argc > 0 && getnum(*argv, "goal", &goal_length, 0)) {
143 1.1 cgd argv++;
144 1.1 cgd argc--;
145 1.27 christos if (argc > 0 && getnum(*argv, "max", &max_length, 0)) {
146 1.1 cgd argv++;
147 1.1 cgd argc--;
148 1.1 cgd }
149 1.1 cgd }
150 1.26 christos
151 1.1 cgd if (max_length <= goal_length) {
152 1.19 christos errx(1, "Max length (%zu) must be greater than goal "
153 1.19 christos "length (%zu)", max_length, goal_length);
154 1.1 cgd }
155 1.26 christos if (argc == 0) {
156 1.1 cgd fmt(stdin);
157 1.1 cgd oflush();
158 1.19 christos return 0;
159 1.1 cgd }
160 1.26 christos while (argc--) {
161 1.26 christos if ((fi = fopen(*argv++, "r")) == NULL) {
162 1.19 christos warn("Cannot open `%s'", *argv);
163 1.1 cgd errs++;
164 1.1 cgd continue;
165 1.1 cgd }
166 1.1 cgd fmt(fi);
167 1.23 christos (void)fclose(fi);
168 1.1 cgd }
169 1.1 cgd oflush();
170 1.19 christos buf_end(&outbuf);
171 1.19 christos return errs;
172 1.1 cgd }
173 1.1 cgd
174 1.26 christos static void
175 1.26 christos usage(void)
176 1.26 christos {
177 1.26 christos (void)fprintf(stderr,
178 1.26 christos "Usage: %s [-Cr] [-g <goal>] [-m <max>] [<files>..]\n"
179 1.26 christos "\t %s [-Cr] [<goal>] [<max>] [<files>]\n",
180 1.26 christos getprogname(), getprogname());
181 1.26 christos exit(1);
182 1.26 christos }
183 1.26 christos
184 1.26 christos static int
185 1.26 christos getnum(const char *str, const char *what, size_t *res, int badnum)
186 1.26 christos {
187 1.26 christos unsigned long ul;
188 1.26 christos char *ep;
189 1.26 christos
190 1.26 christos errno = 0;
191 1.26 christos ul = strtoul(str, &ep, 0);
192 1.26 christos if (*str != '\0' && *ep == '\0') {
193 1.26 christos if ((errno == ERANGE && ul == ULONG_MAX) || ul > SIZE_T_MAX)
194 1.26 christos errx(1, "%s number `%s' too big", what, str);
195 1.26 christos *res = (size_t)ul;
196 1.26 christos return 1;
197 1.26 christos } else if (badnum)
198 1.26 christos errx(1, "Bad %s number `%s'", what, str);
199 1.26 christos
200 1.26 christos return 0;
201 1.26 christos }
202 1.26 christos
203 1.1 cgd /*
204 1.1 cgd * Read up characters from the passed input file, forming lines,
205 1.1 cgd * doing ^H processing, expanding tabs, stripping trailing blanks,
206 1.1 cgd * and sending each line down for analysis.
207 1.1 cgd */
208 1.10 jdolecek static void
209 1.16 wiz fmt(FILE *fi)
210 1.1 cgd {
211 1.19 christos struct buffer lbuf, cbuf;
212 1.6 lukem char *cp, *cp2;
213 1.19 christos int c, add_space;
214 1.19 christos size_t len, col;
215 1.1 cgd
216 1.12 abs if (center) {
217 1.19 christos for (;;) {
218 1.19 christos cp = fgetln(fi, &len);
219 1.12 abs if (!cp)
220 1.12 abs return;
221 1.19 christos cp2 = cp + len - 1;
222 1.19 christos while (len-- && isspace((unsigned char)*cp))
223 1.12 abs cp++;
224 1.18 dsl while (cp2 > cp && isspace((unsigned char)*cp2))
225 1.12 abs cp2--;
226 1.12 abs if (cp == cp2)
227 1.23 christos (void)putchar('\n');
228 1.12 abs col = cp2 - cp;
229 1.19 christos if (goal_length > col)
230 1.19 christos for (c = 0; c < (goal_length - col) / 2; c++)
231 1.23 christos (void)putchar(' ');
232 1.12 abs while (cp <= cp2)
233 1.23 christos (void)putchar(*cp++);
234 1.23 christos (void)putchar('\n');
235 1.12 abs }
236 1.12 abs }
237 1.19 christos
238 1.19 christos buf_init(&lbuf);
239 1.19 christos buf_init(&cbuf);
240 1.1 cgd c = getc(fi);
241 1.19 christos
242 1.1 cgd while (c != EOF) {
243 1.1 cgd /*
244 1.1 cgd * Collect a line, doing ^H processing.
245 1.1 cgd * Leave tabs for now.
246 1.1 cgd */
247 1.19 christos buf_reset(&lbuf);
248 1.19 christos while (c != '\n' && c != EOF) {
249 1.1 cgd if (c == '\b') {
250 1.23 christos (void)buf_unputc(&lbuf);
251 1.1 cgd c = getc(fi);
252 1.1 cgd continue;
253 1.1 cgd }
254 1.15 abs if(!(isprint(c) || c == '\t' || c >= 160)) {
255 1.1 cgd c = getc(fi);
256 1.1 cgd continue;
257 1.1 cgd }
258 1.19 christos buf_putc(&lbuf, c);
259 1.1 cgd c = getc(fi);
260 1.1 cgd }
261 1.19 christos buf_putc(&lbuf, '\0');
262 1.23 christos (void)buf_unputc(&lbuf);
263 1.19 christos add_space = c != EOF;
264 1.10 jdolecek
265 1.10 jdolecek /*
266 1.19 christos * Expand tabs on the way.
267 1.1 cgd */
268 1.1 cgd col = 0;
269 1.19 christos cp = lbuf.bptr;
270 1.19 christos buf_reset(&cbuf);
271 1.19 christos while ((c = *cp++) != '\0') {
272 1.1 cgd if (c != '\t') {
273 1.1 cgd col++;
274 1.19 christos buf_putc(&cbuf, c);
275 1.1 cgd continue;
276 1.1 cgd }
277 1.1 cgd do {
278 1.19 christos buf_putc(&cbuf, ' ');
279 1.1 cgd col++;
280 1.1 cgd } while ((col & 07) != 0);
281 1.1 cgd }
282 1.1 cgd
283 1.1 cgd /*
284 1.1 cgd * Swipe trailing blanks from the line.
285 1.1 cgd */
286 1.19 christos for (cp2 = cbuf.ptr - 1; cp2 >= cbuf.bptr && *cp2 == ' '; cp2--)
287 1.19 christos continue;
288 1.19 christos cbuf.ptr = cp2 + 1;
289 1.19 christos buf_putc(&cbuf, '\0');
290 1.23 christos (void)buf_unputc(&cbuf);
291 1.19 christos prefix(&cbuf, add_space);
292 1.1 cgd if (c != EOF)
293 1.1 cgd c = getc(fi);
294 1.1 cgd }
295 1.19 christos buf_end(&cbuf);
296 1.19 christos buf_end(&lbuf);
297 1.1 cgd }
298 1.1 cgd
299 1.1 cgd /*
300 1.1 cgd * Take a line devoid of tabs and other garbage and determine its
301 1.1 cgd * blank prefix. If the indent changes, call for a linebreak.
302 1.1 cgd * If the input line is blank, echo the blank line on the output.
303 1.1 cgd * Finally, if the line minus the prefix is a mail header, try to keep
304 1.1 cgd * it on a line by itself.
305 1.1 cgd */
306 1.10 jdolecek static void
307 1.19 christos prefix(const struct buffer *buf, int add_space)
308 1.1 cgd {
309 1.10 jdolecek const char *cp;
310 1.19 christos const char **hp;
311 1.19 christos size_t np;
312 1.19 christos int h;
313 1.1 cgd
314 1.19 christos if (buf->ptr == buf->bptr) {
315 1.1 cgd oflush();
316 1.23 christos (void)putchar('\n');
317 1.1 cgd return;
318 1.1 cgd }
319 1.19 christos for (cp = buf->bptr; *cp == ' '; cp++)
320 1.19 christos continue;
321 1.19 christos np = cp - buf->bptr;
322 1.1 cgd
323 1.1 cgd /*
324 1.1 cgd * The following horrible expression attempts to avoid linebreaks
325 1.1 cgd * when the indent changes due to a paragraph.
326 1.1 cgd */
327 1.19 christos if (np != pfx && (np > pfx || abs((int)(pfx - np)) > 8))
328 1.19 christos oflush();
329 1.26 christos if (!raw) {
330 1.26 christos if ((h = ishead(cp)) != 0) {
331 1.26 christos oflush();
332 1.26 christos mark = lineno;
333 1.26 christos }
334 1.26 christos if (lineno - mark < 3 && lineno - mark > 0)
335 1.26 christos for (hp = &headnames[0]; *hp != NULL; hp++)
336 1.26 christos if (ispref(*hp, cp)) {
337 1.26 christos h = 1;
338 1.26 christos oflush();
339 1.26 christos break;
340 1.26 christos }
341 1.26 christos if (!h && (h = (*cp == '.')))
342 1.26 christos oflush();
343 1.26 christos } else
344 1.26 christos h = 0;
345 1.1 cgd pfx = np;
346 1.10 jdolecek if (h) {
347 1.19 christos pack(cp, (size_t)(buf->ptr - cp));
348 1.1 cgd oflush();
349 1.10 jdolecek } else
350 1.10 jdolecek split(cp, add_space);
351 1.1 cgd lineno++;
352 1.1 cgd }
353 1.1 cgd
354 1.1 cgd /*
355 1.1 cgd * Split up the passed line into output "words" which are
356 1.1 cgd * maximal strings of non-blanks with the blank separation
357 1.1 cgd * attached at the end. Pass these words along to the output
358 1.1 cgd * line packer.
359 1.1 cgd */
360 1.10 jdolecek static void
361 1.16 wiz split(const char line[], int add_space)
362 1.1 cgd {
363 1.10 jdolecek const char *cp;
364 1.19 christos struct buffer word;
365 1.19 christos size_t wlen;
366 1.1 cgd
367 1.19 christos buf_init(&word);
368 1.1 cgd cp = line;
369 1.1 cgd while (*cp) {
370 1.19 christos buf_reset(&word);
371 1.19 christos wlen = 0;
372 1.1 cgd
373 1.1 cgd /*
374 1.1 cgd * Collect a 'word,' allowing it to contain escaped white
375 1.1 cgd * space.
376 1.1 cgd */
377 1.1 cgd while (*cp && *cp != ' ') {
378 1.9 christos if (*cp == '\\' && isspace((unsigned char)cp[1]))
379 1.19 christos buf_putc(&word, *cp++);
380 1.19 christos buf_putc(&word, *cp++);
381 1.19 christos wlen++;
382 1.1 cgd }
383 1.1 cgd
384 1.1 cgd /*
385 1.1 cgd * Guarantee a space at end of line. Two spaces after end of
386 1.1 cgd * sentence punctuation.
387 1.1 cgd */
388 1.10 jdolecek if (*cp == '\0' && add_space) {
389 1.19 christos buf_putc(&word, ' ');
390 1.7 lukem if (strchr(".:!", cp[-1]))
391 1.19 christos buf_putc(&word, ' ');
392 1.1 cgd }
393 1.1 cgd while (*cp == ' ')
394 1.19 christos buf_putc(&word, *cp++);
395 1.19 christos
396 1.19 christos buf_putc(&word, '\0');
397 1.23 christos (void)buf_unputc(&word);
398 1.19 christos
399 1.19 christos pack(word.bptr, wlen);
400 1.1 cgd }
401 1.19 christos buf_end(&word);
402 1.1 cgd }
403 1.1 cgd
404 1.1 cgd /*
405 1.1 cgd * Output section.
406 1.1 cgd * Build up line images from the words passed in. Prefix
407 1.20 christos * each line with correct number of blanks.
408 1.20 christos *
409 1.20 christos * At the bottom of this whole mess, leading tabs are reinserted.
410 1.1 cgd */
411 1.1 cgd
412 1.1 cgd /*
413 1.1 cgd * Pack a word onto the output line. If this is the beginning of
414 1.1 cgd * the line, push on the appropriately-sized string of blanks first.
415 1.1 cgd * If the word won't fit on the current line, flush and begin a new
416 1.1 cgd * line. If the word is too long to fit all by itself on a line,
417 1.1 cgd * just give it its own and hope for the best.
418 1.1 cgd *
419 1.1 cgd * LIZ@UOM 6/18/85 -- If the new word will fit in at less than the
420 1.1 cgd * goal length, take it. If not, then check to see if the line
421 1.1 cgd * will be over the max length; if so put the word on the next
422 1.1 cgd * line. If not, check to see if the line will be closer to the
423 1.1 cgd * goal length with or without the word and take it or put it on
424 1.1 cgd * the next line accordingly.
425 1.1 cgd */
426 1.1 cgd
427 1.10 jdolecek static void
428 1.19 christos pack(const char *word, size_t wlen)
429 1.1 cgd {
430 1.10 jdolecek const char *cp;
431 1.19 christos size_t s, t;
432 1.1 cgd
433 1.19 christos if (outbuf.bptr == outbuf.ptr)
434 1.1 cgd leadin();
435 1.1 cgd /*
436 1.1 cgd * LIZ@UOM 6/18/85 -- change condition to check goal_length; s is the
437 1.1 cgd * length of the line before the word is added; t is now the length
438 1.1 cgd * of the line after the word is added
439 1.1 cgd */
440 1.19 christos s = outbuf.ptr - outbuf.bptr;
441 1.19 christos t = wlen + s;
442 1.22 christos if ((t <= goal_length) || ((t <= max_length) &&
443 1.22 christos (s <= goal_length) && (t - goal_length <= goal_length - s))) {
444 1.1 cgd /*
445 1.1 cgd * In like flint!
446 1.1 cgd */
447 1.19 christos for (cp = word; *cp;)
448 1.19 christos buf_putc(&outbuf, *cp++);
449 1.1 cgd return;
450 1.1 cgd }
451 1.1 cgd if (s > pfx) {
452 1.1 cgd oflush();
453 1.1 cgd leadin();
454 1.1 cgd }
455 1.19 christos for (cp = word; *cp;)
456 1.19 christos buf_putc(&outbuf, *cp++);
457 1.1 cgd }
458 1.1 cgd
459 1.1 cgd /*
460 1.1 cgd * If there is anything on the current output line, send it on
461 1.20 christos * its way. Reset outbuf.
462 1.1 cgd */
463 1.10 jdolecek static void
464 1.16 wiz oflush(void)
465 1.1 cgd {
466 1.19 christos if (outbuf.bptr == outbuf.ptr)
467 1.1 cgd return;
468 1.19 christos buf_putc(&outbuf, '\0');
469 1.23 christos (void)buf_unputc(&outbuf);
470 1.19 christos tabulate(&outbuf);
471 1.19 christos buf_reset(&outbuf);
472 1.1 cgd }
473 1.1 cgd
474 1.1 cgd /*
475 1.1 cgd * Take the passed line buffer, insert leading tabs where possible, and
476 1.1 cgd * output on standard output (finally).
477 1.1 cgd */
478 1.10 jdolecek static void
479 1.19 christos tabulate(struct buffer *buf)
480 1.1 cgd {
481 1.6 lukem char *cp;
482 1.19 christos size_t b, t;
483 1.1 cgd
484 1.1 cgd /*
485 1.1 cgd * Toss trailing blanks in the output line.
486 1.1 cgd */
487 1.25 christos for (cp = buf->ptr - 1; cp >= buf->bptr && *cp == ' '; cp--)
488 1.19 christos continue;
489 1.25 christos *++cp = '\0';
490 1.1 cgd
491 1.1 cgd /*
492 1.1 cgd * Count the leading blank space and tabulate.
493 1.1 cgd */
494 1.19 christos for (cp = buf->bptr; *cp == ' '; cp++)
495 1.19 christos continue;
496 1.19 christos b = cp - buf->bptr;
497 1.20 christos t = b / 8;
498 1.20 christos b = b % 8;
499 1.1 cgd if (t > 0)
500 1.1 cgd do
501 1.23 christos (void)putchar('\t');
502 1.1 cgd while (--t);
503 1.1 cgd if (b > 0)
504 1.1 cgd do
505 1.23 christos (void)putchar(' ');
506 1.1 cgd while (--b);
507 1.1 cgd while (*cp)
508 1.23 christos (void)putchar(*cp++);
509 1.23 christos (void)putchar('\n');
510 1.1 cgd }
511 1.1 cgd
512 1.1 cgd /*
513 1.1 cgd * Initialize the output line with the appropriate number of
514 1.1 cgd * leading blanks.
515 1.1 cgd */
516 1.10 jdolecek static void
517 1.16 wiz leadin(void)
518 1.1 cgd {
519 1.19 christos size_t b;
520 1.19 christos
521 1.19 christos buf_reset(&outbuf);
522 1.1 cgd
523 1.19 christos for (b = 0; b < pfx; b++)
524 1.19 christos buf_putc(&outbuf, ' ');
525 1.1 cgd }
526 1.1 cgd
527 1.1 cgd /*
528 1.1 cgd * Is s1 a prefix of s2??
529 1.1 cgd */
530 1.10 jdolecek static int
531 1.16 wiz ispref(const char *s1, const char *s2)
532 1.1 cgd {
533 1.1 cgd
534 1.1 cgd while (*s1++ == *s2)
535 1.19 christos continue;
536 1.19 christos return *s1 == '\0';
537 1.1 cgd }
538