Home | History | Annotate | Line # | Download | only in hexdump
parse.c revision 1.8.2.1
      1  1.8.2.1        he /*	$NetBSD: parse.c,v 1.8.2.1 2000/10/12 21:40:29 he Exp $	*/
      2      1.4       tls 
      3      1.1       cgd /*
      4      1.6       mrg  * Copyright (c) 1989, 1993
      5      1.6       mrg  *	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.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16      1.1       cgd  *    must display the following acknowledgement:
     17      1.1       cgd  *	This product includes software developed by the University of
     18      1.1       cgd  *	California, Berkeley and its contributors.
     19      1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20      1.1       cgd  *    may be used to endorse or promote products derived from this software
     21      1.1       cgd  *    without specific prior written permission.
     22      1.1       cgd  *
     23      1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24      1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25      1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26      1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27      1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28      1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29      1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30      1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31      1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32      1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33      1.1       cgd  * SUCH DAMAGE.
     34      1.1       cgd  */
     35      1.1       cgd 
     36      1.7     lukem #include <sys/cdefs.h>
     37      1.1       cgd #ifndef lint
     38      1.5     mikel #if 0
     39      1.6       mrg static char sccsid[] = "@(#)parse.c	8.1 (Berkeley) 6/6/93";
     40      1.5     mikel #else
     41  1.8.2.1        he __RCSID("$NetBSD: parse.c,v 1.8.2.1 2000/10/12 21:40:29 he Exp $");
     42      1.5     mikel #endif
     43      1.1       cgd #endif /* not lint */
     44      1.1       cgd 
     45      1.1       cgd #include <sys/types.h>
     46      1.1       cgd #include <sys/file.h>
     47      1.6       mrg 
     48      1.5     mikel #include <ctype.h>
     49      1.7     lukem #include <err.h>
     50      1.6       mrg #include <errno.h>
     51      1.6       mrg #include <fcntl.h>
     52      1.1       cgd #include <stdio.h>
     53      1.1       cgd #include <stdlib.h>
     54      1.1       cgd #include <string.h>
     55      1.6       mrg 
     56      1.1       cgd #include "hexdump.h"
     57      1.1       cgd 
     58      1.1       cgd FU *endfu;					/* format at end-of-data */
     59      1.1       cgd 
     60      1.5     mikel void
     61      1.1       cgd addfile(name)
     62      1.1       cgd 	char *name;
     63      1.1       cgd {
     64      1.7     lukem 	char *p;
     65      1.1       cgd 	FILE *fp;
     66      1.1       cgd 	int ch;
     67      1.1       cgd 	char buf[2048 + 1];
     68      1.1       cgd 
     69      1.6       mrg 	if ((fp = fopen(name, "r")) == NULL)
     70      1.7     lukem 		err(1, "fopen %s", name);
     71      1.1       cgd 	while (fgets(buf, sizeof(buf), fp)) {
     72      1.5     mikel 		if (!(p = strchr(buf, '\n'))) {
     73      1.7     lukem 			warnx("line too long.");
     74      1.1       cgd 			while ((ch = getchar()) != '\n' && ch != EOF);
     75      1.1       cgd 			continue;
     76      1.1       cgd 		}
     77      1.1       cgd 		*p = '\0';
     78      1.8  christos 		for (p = buf; *p && isspace((unsigned char)*p); ++p);
     79      1.1       cgd 		if (!*p || *p == '#')
     80      1.1       cgd 			continue;
     81      1.1       cgd 		add(p);
     82      1.1       cgd 	}
     83      1.1       cgd 	(void)fclose(fp);
     84      1.1       cgd }
     85      1.1       cgd 
     86      1.5     mikel void
     87      1.1       cgd add(fmt)
     88      1.1       cgd 	char *fmt;
     89      1.1       cgd {
     90      1.7     lukem 	char *p;
     91      1.1       cgd 	static FS **nextfs;
     92      1.1       cgd 	FS *tfs;
     93      1.1       cgd 	FU *tfu, **nextfu;
     94      1.5     mikel 	char *savep;
     95      1.1       cgd 
     96      1.1       cgd 	/* start new linked list of format units */
     97      1.6       mrg 	tfs = emalloc(sizeof(FS));
     98      1.1       cgd 	if (!fshead)
     99      1.1       cgd 		fshead = tfs;
    100      1.1       cgd 	else
    101      1.1       cgd 		*nextfs = tfs;
    102      1.1       cgd 	nextfs = &tfs->nextfs;
    103      1.1       cgd 	nextfu = &tfs->nextfu;
    104      1.1       cgd 
    105      1.1       cgd 	/* take the format string and break it up into format units */
    106      1.1       cgd 	for (p = fmt;;) {
    107      1.1       cgd 		/* skip leading white space */
    108      1.8  christos 		for (; isspace((unsigned char)*p); ++p);
    109      1.1       cgd 		if (!*p)
    110      1.1       cgd 			break;
    111      1.1       cgd 
    112      1.1       cgd 		/* allocate a new format unit and link it in */
    113      1.6       mrg 		tfu = emalloc(sizeof(FU));
    114      1.1       cgd 		*nextfu = tfu;
    115      1.1       cgd 		nextfu = &tfu->nextfu;
    116      1.1       cgd 		tfu->reps = 1;
    117      1.1       cgd 
    118      1.1       cgd 		/* if leading digit, repetition count */
    119      1.8  christos 		if (isdigit((unsigned char)*p)) {
    120      1.8  christos 			for (savep = p; isdigit((unsigned char)*p); ++p);
    121      1.8  christos 			if (!isspace((unsigned char)*p) && *p != '/')
    122      1.1       cgd 				badfmt(fmt);
    123      1.1       cgd 			/* may overwrite either white space or slash */
    124      1.1       cgd 			tfu->reps = atoi(savep);
    125      1.1       cgd 			tfu->flags = F_SETREP;
    126      1.1       cgd 			/* skip trailing white space */
    127      1.8  christos 			for (++p; isspace((unsigned char)*p); ++p);
    128      1.1       cgd 		}
    129      1.1       cgd 
    130      1.1       cgd 		/* skip slash and trailing white space */
    131      1.1       cgd 		if (*p == '/')
    132      1.8  christos 			while (isspace((unsigned char)*++p));
    133      1.1       cgd 
    134      1.1       cgd 		/* byte count */
    135      1.8  christos 		if (isdigit((unsigned char)*p)) {
    136      1.8  christos 			for (savep = p; isdigit((unsigned char)*p); ++p);
    137      1.8  christos 			if (!isspace((unsigned char)*p))
    138      1.1       cgd 				badfmt(fmt);
    139      1.1       cgd 			tfu->bcnt = atoi(savep);
    140      1.1       cgd 			/* skip trailing white space */
    141      1.8  christos 			for (++p; isspace((unsigned char)*p); ++p);
    142      1.1       cgd 		}
    143      1.1       cgd 
    144      1.1       cgd 		/* format */
    145      1.1       cgd 		if (*p != '"')
    146      1.1       cgd 			badfmt(fmt);
    147      1.1       cgd 		for (savep = ++p; *p != '"';)
    148      1.1       cgd 			if (*p++ == 0)
    149      1.1       cgd 				badfmt(fmt);
    150      1.1       cgd 		if (!(tfu->fmt = malloc(p - savep + 1)))
    151      1.1       cgd 			nomem();
    152      1.1       cgd 		(void) strncpy(tfu->fmt, savep, p - savep);
    153      1.1       cgd 		tfu->fmt[p - savep] = '\0';
    154      1.1       cgd 		escape(tfu->fmt);
    155      1.1       cgd 		p++;
    156      1.1       cgd 	}
    157      1.1       cgd }
    158      1.1       cgd 
    159      1.5     mikel static const char *spec = ".#-+ 0123456789";
    160      1.5     mikel 
    161      1.5     mikel int
    162      1.1       cgd size(fs)
    163      1.1       cgd 	FS *fs;
    164      1.1       cgd {
    165      1.7     lukem 	FU *fu;
    166      1.7     lukem 	int bcnt, cursize;
    167      1.7     lukem 	char *fmt;
    168      1.1       cgd 	int prec;
    169      1.1       cgd 
    170      1.1       cgd 	/* figure out the data block size needed for each format unit */
    171      1.1       cgd 	for (cursize = 0, fu = fs->nextfu; fu; fu = fu->nextfu) {
    172      1.1       cgd 		if (fu->bcnt) {
    173      1.1       cgd 			cursize += fu->bcnt * fu->reps;
    174      1.1       cgd 			continue;
    175      1.1       cgd 		}
    176      1.1       cgd 		for (bcnt = prec = 0, fmt = fu->fmt; *fmt; ++fmt) {
    177      1.1       cgd 			if (*fmt != '%')
    178      1.1       cgd 				continue;
    179      1.1       cgd 			/*
    180      1.1       cgd 			 * skip any special chars -- save precision in
    181      1.1       cgd 			 * case it's a %s format.
    182      1.1       cgd 			 */
    183      1.5     mikel 			while (strchr(spec + 1, *++fmt));
    184      1.8  christos 			if (*fmt == '.' && isdigit((unsigned char)*++fmt)) {
    185      1.1       cgd 				prec = atoi(fmt);
    186      1.8  christos 				while (isdigit((unsigned char)*++fmt));
    187      1.1       cgd 			}
    188      1.1       cgd 			switch(*fmt) {
    189      1.1       cgd 			case 'c':
    190      1.1       cgd 				bcnt += 1;
    191      1.1       cgd 				break;
    192      1.1       cgd 			case 'd': case 'i': case 'o': case 'u':
    193      1.1       cgd 			case 'x': case 'X':
    194      1.1       cgd 				bcnt += 4;
    195      1.1       cgd 				break;
    196      1.1       cgd 			case 'e': case 'E': case 'f': case 'g': case 'G':
    197      1.1       cgd 				bcnt += 8;
    198      1.1       cgd 				break;
    199      1.1       cgd 			case 's':
    200      1.1       cgd 				bcnt += prec;
    201      1.1       cgd 				break;
    202      1.1       cgd 			case '_':
    203      1.1       cgd 				switch(*++fmt) {
    204      1.1       cgd 				case 'c': case 'p': case 'u':
    205      1.1       cgd 					bcnt += 1;
    206      1.1       cgd 					break;
    207      1.1       cgd 				}
    208      1.1       cgd 			}
    209      1.1       cgd 		}
    210      1.1       cgd 		cursize += bcnt * fu->reps;
    211      1.1       cgd 	}
    212      1.6       mrg 	return (cursize);
    213      1.1       cgd }
    214      1.1       cgd 
    215      1.5     mikel void
    216      1.1       cgd rewrite(fs)
    217      1.1       cgd 	FS *fs;
    218      1.1       cgd {
    219      1.1       cgd 	enum { NOTOKAY, USEBCNT, USEPREC } sokay;
    220      1.7     lukem 	PR *pr, **nextpr;
    221      1.7     lukem 	FU *fu;
    222      1.7     lukem 	char *p1, *p2;
    223      1.6       mrg 	char savech, *fmtp, cs[3];
    224      1.1       cgd 	int nconv, prec;
    225      1.1       cgd 
    226      1.7     lukem 	nextpr = NULL;
    227      1.7     lukem 	prec = 0;
    228      1.1       cgd 	for (fu = fs->nextfu; fu; fu = fu->nextfu) {
    229      1.1       cgd 		/*
    230      1.6       mrg 		 * Break each format unit into print units; each conversion
    231      1.6       mrg 		 * character gets its own.
    232      1.1       cgd 		 */
    233      1.1       cgd 		for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
    234      1.6       mrg 			pr = emalloc(sizeof(PR));
    235      1.1       cgd 			if (!fu->nextpr)
    236      1.1       cgd 				fu->nextpr = pr;
    237      1.1       cgd 			else
    238      1.1       cgd 				*nextpr = pr;
    239      1.1       cgd 
    240      1.6       mrg 			/* Skip preceding text and up to the next % sign. */
    241      1.1       cgd 			for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
    242      1.1       cgd 
    243      1.6       mrg 			/* Only text in the string. */
    244      1.1       cgd 			if (!*p1) {
    245      1.1       cgd 				pr->fmt = fmtp;
    246      1.1       cgd 				pr->flags = F_TEXT;
    247      1.1       cgd 				break;
    248      1.1       cgd 			}
    249      1.1       cgd 
    250      1.1       cgd 			/*
    251      1.6       mrg 			 * Get precision for %s -- if have a byte count, don't
    252      1.1       cgd 			 * need it.
    253      1.1       cgd 			 */
    254      1.1       cgd 			if (fu->bcnt) {
    255      1.1       cgd 				sokay = USEBCNT;
    256      1.6       mrg 				/* Skip to conversion character. */
    257      1.5     mikel 				for (++p1; strchr(spec, *p1); ++p1);
    258      1.1       cgd 			} else {
    259      1.6       mrg 				/* Skip any special chars, field width. */
    260      1.5     mikel 				while (strchr(spec + 1, *++p1));
    261      1.8  christos 				if (*p1 == '.' &&
    262      1.8  christos 				    isdigit((unsigned char)*++p1)) {
    263      1.1       cgd 					sokay = USEPREC;
    264      1.1       cgd 					prec = atoi(p1);
    265      1.8  christos 					while (isdigit((unsigned char)*++p1))
    266      1.8  christos 						continue;
    267      1.6       mrg 				} else
    268      1.1       cgd 					sokay = NOTOKAY;
    269      1.1       cgd 			}
    270      1.1       cgd 
    271      1.6       mrg 			p2 = p1 + 1;		/* Set end pointer. */
    272      1.6       mrg 			cs[0] = *p1;		/* Set conversion string. */
    273      1.6       mrg 			cs[1] = '\0';
    274      1.1       cgd 
    275      1.1       cgd 			/*
    276      1.6       mrg 			 * Figure out the byte count for each conversion;
    277      1.1       cgd 			 * rewrite the format as necessary, set up blank-
    278      1.1       cgd 			 * padding for end of data.
    279      1.1       cgd 			 */
    280      1.6       mrg 			switch(cs[0]) {
    281      1.1       cgd 			case 'c':
    282      1.1       cgd 				pr->flags = F_CHAR;
    283      1.1       cgd 				switch(fu->bcnt) {
    284      1.1       cgd 				case 0: case 1:
    285      1.1       cgd 					pr->bcnt = 1;
    286      1.1       cgd 					break;
    287      1.1       cgd 				default:
    288      1.1       cgd 					p1[1] = '\0';
    289      1.1       cgd 					badcnt(p1);
    290      1.1       cgd 				}
    291      1.1       cgd 				break;
    292      1.1       cgd 			case 'd': case 'i':
    293      1.1       cgd 				pr->flags = F_INT;
    294      1.6       mrg 				goto isint;
    295      1.1       cgd 			case 'o': case 'u': case 'x': case 'X':
    296      1.1       cgd 				pr->flags = F_UINT;
    297      1.6       mrg isint:				cs[2] = '\0';
    298      1.6       mrg 				cs[1] = cs[0];
    299      1.6       mrg 				cs[0] = 'q';
    300      1.6       mrg 				switch(fu->bcnt) {
    301      1.1       cgd 				case 0: case 4:
    302      1.1       cgd 					pr->bcnt = 4;
    303      1.1       cgd 					break;
    304      1.1       cgd 				case 1:
    305      1.1       cgd 					pr->bcnt = 1;
    306      1.1       cgd 					break;
    307      1.1       cgd 				case 2:
    308      1.1       cgd 					pr->bcnt = 2;
    309      1.1       cgd 					break;
    310      1.1       cgd 				default:
    311      1.1       cgd 					p1[1] = '\0';
    312      1.1       cgd 					badcnt(p1);
    313      1.1       cgd 				}
    314      1.1       cgd 				break;
    315      1.1       cgd 			case 'e': case 'E': case 'f': case 'g': case 'G':
    316      1.1       cgd 				pr->flags = F_DBL;
    317      1.1       cgd 				switch(fu->bcnt) {
    318      1.1       cgd 				case 0: case 8:
    319      1.1       cgd 					pr->bcnt = 8;
    320      1.1       cgd 					break;
    321      1.1       cgd 				case 4:
    322      1.1       cgd 					pr->bcnt = 4;
    323      1.1       cgd 					break;
    324      1.1       cgd 				default:
    325      1.1       cgd 					p1[1] = '\0';
    326      1.1       cgd 					badcnt(p1);
    327      1.1       cgd 				}
    328      1.1       cgd 				break;
    329      1.1       cgd 			case 's':
    330      1.1       cgd 				pr->flags = F_STR;
    331      1.1       cgd 				switch(sokay) {
    332      1.1       cgd 				case NOTOKAY:
    333      1.1       cgd 					badsfmt();
    334      1.1       cgd 				case USEBCNT:
    335      1.1       cgd 					pr->bcnt = fu->bcnt;
    336      1.1       cgd 					break;
    337      1.1       cgd 				case USEPREC:
    338      1.1       cgd 					pr->bcnt = prec;
    339      1.1       cgd 					break;
    340      1.1       cgd 				}
    341      1.1       cgd 				break;
    342      1.1       cgd 			case '_':
    343      1.1       cgd 				++p2;
    344      1.1       cgd 				switch(p1[1]) {
    345      1.1       cgd 				case 'A':
    346      1.1       cgd 					endfu = fu;
    347      1.1       cgd 					fu->flags |= F_IGNORE;
    348      1.1       cgd 					/* FALLTHROUGH */
    349      1.1       cgd 				case 'a':
    350      1.1       cgd 					pr->flags = F_ADDRESS;
    351      1.1       cgd 					++p2;
    352      1.1       cgd 					switch(p1[2]) {
    353      1.1       cgd 					case 'd': case 'o': case'x':
    354      1.6       mrg 						cs[0] = 'q';
    355      1.6       mrg 						cs[1] = p1[2];
    356      1.6       mrg 						cs[2] = '\0';
    357      1.1       cgd 						break;
    358      1.1       cgd 					default:
    359      1.1       cgd 						p1[3] = '\0';
    360      1.1       cgd 						badconv(p1);
    361      1.1       cgd 					}
    362      1.1       cgd 					break;
    363      1.1       cgd 				case 'c':
    364      1.1       cgd 					pr->flags = F_C;
    365      1.6       mrg 					/* cs[0] = 'c';	set in conv_c */
    366      1.6       mrg 					goto isint2;
    367      1.1       cgd 				case 'p':
    368      1.1       cgd 					pr->flags = F_P;
    369      1.6       mrg 					cs[0] = 'c';
    370      1.6       mrg 					goto isint2;
    371      1.1       cgd 				case 'u':
    372      1.1       cgd 					pr->flags = F_U;
    373      1.6       mrg 					/* cs[0] = 'c';	set in conv_u */
    374      1.6       mrg isint2:					switch(fu->bcnt) {
    375      1.1       cgd 					case 0: case 1:
    376      1.1       cgd 						pr->bcnt = 1;
    377      1.1       cgd 						break;
    378      1.1       cgd 					default:
    379      1.1       cgd 						p1[2] = '\0';
    380      1.1       cgd 						badcnt(p1);
    381      1.1       cgd 					}
    382      1.1       cgd 					break;
    383      1.1       cgd 				default:
    384      1.1       cgd 					p1[2] = '\0';
    385      1.1       cgd 					badconv(p1);
    386      1.1       cgd 				}
    387      1.1       cgd 				break;
    388      1.1       cgd 			default:
    389      1.1       cgd 				p1[1] = '\0';
    390      1.1       cgd 				badconv(p1);
    391      1.1       cgd 			}
    392      1.1       cgd 
    393      1.1       cgd 			/*
    394      1.6       mrg 			 * Copy to PR format string, set conversion character
    395      1.1       cgd 			 * pointer, update original.
    396      1.1       cgd 			 */
    397      1.1       cgd 			savech = *p2;
    398      1.6       mrg 			p1[0] = '\0';
    399  1.8.2.1        he 			pr->fmt = emalloc(strlen(fmtp) + strlen(cs) + 1);
    400      1.6       mrg 			(void)strcpy(pr->fmt, fmtp);
    401      1.6       mrg 			(void)strcat(pr->fmt, cs);
    402      1.1       cgd 			*p2 = savech;
    403      1.1       cgd 			pr->cchar = pr->fmt + (p1 - fmtp);
    404      1.1       cgd 			fmtp = p2;
    405      1.1       cgd 
    406      1.6       mrg 			/* Only one conversion character if byte count. */
    407      1.6       mrg 			if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)
    408      1.7     lukem 				errx(1,
    409      1.7     lukem 			    "byte count with multiple conversion characters");
    410      1.1       cgd 		}
    411      1.1       cgd 		/*
    412      1.6       mrg 		 * If format unit byte count not specified, figure it out
    413      1.1       cgd 		 * so can adjust rep count later.
    414      1.1       cgd 		 */
    415      1.1       cgd 		if (!fu->bcnt)
    416      1.1       cgd 			for (pr = fu->nextpr; pr; pr = pr->nextpr)
    417      1.1       cgd 				fu->bcnt += pr->bcnt;
    418      1.1       cgd 	}
    419      1.1       cgd 	/*
    420      1.6       mrg 	 * If the format string interprets any data at all, and it's
    421      1.1       cgd 	 * not the same as the blocksize, and its last format unit
    422      1.1       cgd 	 * interprets any data at all, and has no iteration count,
    423      1.1       cgd 	 * repeat it as necessary.
    424      1.1       cgd 	 *
    425      1.6       mrg 	 * If, rep count is greater than 1, no trailing whitespace
    426      1.1       cgd 	 * gets output from the last iteration of the format unit.
    427      1.1       cgd 	 */
    428      1.1       cgd 	for (fu = fs->nextfu;; fu = fu->nextfu) {
    429      1.1       cgd 		if (!fu->nextfu && fs->bcnt < blocksize &&
    430      1.1       cgd 		    !(fu->flags&F_SETREP) && fu->bcnt)
    431      1.1       cgd 			fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
    432      1.1       cgd 		if (fu->reps > 1) {
    433      1.1       cgd 			for (pr = fu->nextpr;; pr = pr->nextpr)
    434      1.1       cgd 				if (!pr->nextpr)
    435      1.1       cgd 					break;
    436      1.1       cgd 			for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
    437      1.8  christos 				p2 = isspace((unsigned char)*p1) ? p1 : NULL;
    438      1.1       cgd 			if (p2)
    439      1.1       cgd 				pr->nospace = p2;
    440      1.1       cgd 		}
    441      1.1       cgd 		if (!fu->nextfu)
    442      1.1       cgd 			break;
    443      1.1       cgd 	}
    444      1.6       mrg #ifdef DEBUG
    445      1.6       mrg 	for (fu = fs->nextfu; fu; fu = fu->nextfu) {
    446      1.6       mrg 		(void)printf("fmt:");
    447      1.6       mrg 		for (pr = fu->nextpr; pr; pr = pr->nextpr)
    448      1.6       mrg 			(void)printf(" {%s}", pr->fmt);
    449      1.6       mrg 		(void)printf("\n");
    450      1.6       mrg 	}
    451      1.6       mrg #endif
    452      1.1       cgd }
    453      1.1       cgd 
    454      1.5     mikel void
    455      1.1       cgd escape(p1)
    456      1.7     lukem 	char *p1;
    457      1.1       cgd {
    458      1.7     lukem 	char *p2;
    459      1.1       cgd 
    460      1.1       cgd 	/* alphabetic escape sequences have to be done in place */
    461      1.1       cgd 	for (p2 = p1;; ++p1, ++p2) {
    462      1.1       cgd 		if (!*p1) {
    463      1.1       cgd 			*p2 = *p1;
    464      1.1       cgd 			break;
    465      1.1       cgd 		}
    466      1.1       cgd 		if (*p1 == '\\')
    467      1.1       cgd 			switch(*++p1) {
    468      1.1       cgd 			case 'a':
    469      1.1       cgd 			     /* *p2 = '\a'; */
    470      1.1       cgd 				*p2 = '\007';
    471      1.1       cgd 				break;
    472      1.1       cgd 			case 'b':
    473      1.1       cgd 				*p2 = '\b';
    474      1.1       cgd 				break;
    475      1.1       cgd 			case 'f':
    476      1.1       cgd 				*p2 = '\f';
    477      1.1       cgd 				break;
    478      1.1       cgd 			case 'n':
    479      1.1       cgd 				*p2 = '\n';
    480      1.1       cgd 				break;
    481      1.1       cgd 			case 'r':
    482      1.1       cgd 				*p2 = '\r';
    483      1.1       cgd 				break;
    484      1.1       cgd 			case 't':
    485      1.1       cgd 				*p2 = '\t';
    486      1.1       cgd 				break;
    487      1.1       cgd 			case 'v':
    488      1.1       cgd 				*p2 = '\v';
    489      1.1       cgd 				break;
    490      1.1       cgd 			default:
    491      1.1       cgd 				*p2 = *p1;
    492      1.1       cgd 				break;
    493      1.1       cgd 			}
    494      1.1       cgd 	}
    495      1.1       cgd }
    496      1.1       cgd 
    497      1.5     mikel void
    498      1.1       cgd badcnt(s)
    499      1.1       cgd 	char *s;
    500      1.1       cgd {
    501      1.7     lukem 	errx(1, "%s: bad byte count", s);
    502      1.1       cgd }
    503      1.1       cgd 
    504      1.5     mikel void
    505      1.1       cgd badsfmt()
    506      1.1       cgd {
    507      1.7     lukem 	errx(1, "%%s: requires a precision or a byte count\n");
    508      1.1       cgd }
    509      1.1       cgd 
    510      1.5     mikel void
    511      1.1       cgd badfmt(fmt)
    512      1.1       cgd 	char *fmt;
    513      1.1       cgd {
    514      1.7     lukem 	errx(1, "\"%s\": bad format\n", fmt);
    515      1.1       cgd }
    516      1.1       cgd 
    517      1.5     mikel void
    518      1.1       cgd badconv(ch)
    519      1.1       cgd 	char *ch;
    520      1.1       cgd {
    521      1.7     lukem 	errx(1, "%%%s: bad conversion character\n", ch);
    522      1.1       cgd }
    523