xref: /minix3/usr.bin/m4/misc.c (revision 71c7dcb9ce66b73f93cf114720b764542608dc95)
12e8d1edaSArun Thomas /*	$OpenBSD: misc.c,v 1.41 2009/10/14 17:19:47 sthen Exp $	*/
2*71c7dcb9SLionel Sambuc /*	$NetBSD: misc.c,v 1.23 2012/03/20 20:34:58 matt Exp $	*/
32e8d1edaSArun Thomas 
42e8d1edaSArun Thomas /*
52e8d1edaSArun Thomas  * Copyright (c) 1989, 1993
62e8d1edaSArun Thomas  *	The Regents of the University of California.  All rights reserved.
72e8d1edaSArun Thomas  *
82e8d1edaSArun Thomas  * This code is derived from software contributed to Berkeley by
92e8d1edaSArun Thomas  * Ozan Yigit at York University.
102e8d1edaSArun Thomas  *
112e8d1edaSArun Thomas  * Redistribution and use in source and binary forms, with or without
122e8d1edaSArun Thomas  * modification, are permitted provided that the following conditions
132e8d1edaSArun Thomas  * are met:
142e8d1edaSArun Thomas  * 1. Redistributions of source code must retain the above copyright
152e8d1edaSArun Thomas  *    notice, this list of conditions and the following disclaimer.
162e8d1edaSArun Thomas  * 2. Redistributions in binary form must reproduce the above copyright
172e8d1edaSArun Thomas  *    notice, this list of conditions and the following disclaimer in the
182e8d1edaSArun Thomas  *    documentation and/or other materials provided with the distribution.
192e8d1edaSArun Thomas  * 3. Neither the name of the University nor the names of its contributors
202e8d1edaSArun Thomas  *    may be used to endorse or promote products derived from this software
212e8d1edaSArun Thomas  *    without specific prior written permission.
222e8d1edaSArun Thomas  *
232e8d1edaSArun Thomas  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
242e8d1edaSArun Thomas  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
252e8d1edaSArun Thomas  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
262e8d1edaSArun Thomas  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
272e8d1edaSArun Thomas  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
282e8d1edaSArun Thomas  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
292e8d1edaSArun Thomas  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
302e8d1edaSArun Thomas  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
312e8d1edaSArun Thomas  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
322e8d1edaSArun Thomas  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
332e8d1edaSArun Thomas  * SUCH DAMAGE.
342e8d1edaSArun Thomas  */
352e8d1edaSArun Thomas #if HAVE_NBTOOL_CONFIG_H
362e8d1edaSArun Thomas #include "nbtool_config.h"
372e8d1edaSArun Thomas #endif
382e8d1edaSArun Thomas #include <sys/cdefs.h>
39*71c7dcb9SLionel Sambuc __RCSID("$NetBSD: misc.c,v 1.23 2012/03/20 20:34:58 matt Exp $");
402e8d1edaSArun Thomas #include <sys/types.h>
412e8d1edaSArun Thomas #include <errno.h>
422e8d1edaSArun Thomas #include <unistd.h>
432e8d1edaSArun Thomas #include <stdarg.h>
442e8d1edaSArun Thomas #include <stdio.h>
452e8d1edaSArun Thomas #include <stdlib.h>
462e8d1edaSArun Thomas #include <stddef.h>
472e8d1edaSArun Thomas #include <string.h>
482e8d1edaSArun Thomas #include <err.h>
492e8d1edaSArun Thomas #include "mdef.h"
502e8d1edaSArun Thomas #include "stdd.h"
512e8d1edaSArun Thomas #include "extern.h"
522e8d1edaSArun Thomas #include "pathnames.h"
532e8d1edaSArun Thomas 
542e8d1edaSArun Thomas 
552e8d1edaSArun Thomas char *ep;		/* first free char in strspace */
562e8d1edaSArun Thomas static char *strspace;	/* string space for evaluation */
572e8d1edaSArun Thomas char *endest;		/* end of string space	       */
582e8d1edaSArun Thomas static size_t strsize = STRSPMAX;
592e8d1edaSArun Thomas static size_t bufsize = BUFSIZE;
602e8d1edaSArun Thomas 
612e8d1edaSArun Thomas unsigned char *buf;			/* push-back buffer	       */
622e8d1edaSArun Thomas unsigned char *bufbase;			/* the base for current ilevel */
632e8d1edaSArun Thomas unsigned char *bbase[MAXINP];		/* the base for each ilevel    */
642e8d1edaSArun Thomas unsigned char *bp; 			/* first available character   */
652e8d1edaSArun Thomas unsigned char *endpbb;			/* end of push-back buffer     */
662e8d1edaSArun Thomas 
672e8d1edaSArun Thomas 
682e8d1edaSArun Thomas /*
692e8d1edaSArun Thomas  * find the index of second str in the first str.
702e8d1edaSArun Thomas  */
712e8d1edaSArun Thomas ptrdiff_t
indx(const char * s1,const char * s2)722e8d1edaSArun Thomas indx(const char *s1, const char *s2)
732e8d1edaSArun Thomas {
742e8d1edaSArun Thomas 	char *t;
752e8d1edaSArun Thomas 
762e8d1edaSArun Thomas 	t = strstr(s1, s2);
772e8d1edaSArun Thomas 	if (t == NULL)
782e8d1edaSArun Thomas 		return (-1);
792e8d1edaSArun Thomas 	else
802e8d1edaSArun Thomas 		return (t - s1);
812e8d1edaSArun Thomas }
822e8d1edaSArun Thomas /*
832e8d1edaSArun Thomas  *  pushback - push character back onto input
842e8d1edaSArun Thomas  */
852e8d1edaSArun Thomas void
pushback(int c)862e8d1edaSArun Thomas pushback(int c)
872e8d1edaSArun Thomas {
882e8d1edaSArun Thomas 	if (c == EOF)
892e8d1edaSArun Thomas 		return;
902e8d1edaSArun Thomas 	if (bp >= endpbb)
912e8d1edaSArun Thomas 		enlarge_bufspace();
922e8d1edaSArun Thomas 	*bp++ = c;
932e8d1edaSArun Thomas }
942e8d1edaSArun Thomas 
952e8d1edaSArun Thomas /*
962e8d1edaSArun Thomas  *  pbstr - push string back onto input
972e8d1edaSArun Thomas  *          pushback is replicated to improve
982e8d1edaSArun Thomas  *          performance.
992e8d1edaSArun Thomas  */
1002e8d1edaSArun Thomas void
pbstr(const char * s)1012e8d1edaSArun Thomas pbstr(const char *s)
1022e8d1edaSArun Thomas {
1032e8d1edaSArun Thomas 	size_t n;
1042e8d1edaSArun Thomas 
1052e8d1edaSArun Thomas 	n = strlen(s);
1062e8d1edaSArun Thomas 	while ((size_t)(endpbb - bp) <= n)
1072e8d1edaSArun Thomas 		enlarge_bufspace();
1082e8d1edaSArun Thomas 	while (n > 0)
1092e8d1edaSArun Thomas 		*bp++ = s[--n];
1102e8d1edaSArun Thomas }
1112e8d1edaSArun Thomas 
1122e8d1edaSArun Thomas /*
1132e8d1edaSArun Thomas  *  pbnum - convert number to string, push back on input.
1142e8d1edaSArun Thomas  */
1152e8d1edaSArun Thomas void
pbnum(int n)1162e8d1edaSArun Thomas pbnum(int n)
1172e8d1edaSArun Thomas {
1182e8d1edaSArun Thomas 	pbnumbase(n, 10, 0);
1192e8d1edaSArun Thomas }
1202e8d1edaSArun Thomas 
1212e8d1edaSArun Thomas void
pbnumbase(int n,int base,int d)1222e8d1edaSArun Thomas pbnumbase(int n, int base, int d)
1232e8d1edaSArun Thomas {
1242e8d1edaSArun Thomas 	static char digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
1252e8d1edaSArun Thomas 	int num;
1262e8d1edaSArun Thomas 	int printed = 0;
1272e8d1edaSArun Thomas 
1282e8d1edaSArun Thomas 	if (base > 36)
1292e8d1edaSArun Thomas 		m4errx(1, "base %d > 36: not supported.", base);
1302e8d1edaSArun Thomas 
1312e8d1edaSArun Thomas 	if (base < 2)
1322e8d1edaSArun Thomas 		m4errx(1, "bad base %d for conversion.", base);
1332e8d1edaSArun Thomas 
1342e8d1edaSArun Thomas 	num = (n < 0) ? -n : n;
1352e8d1edaSArun Thomas 	do {
1362e8d1edaSArun Thomas 		pushback(digits[num % base]);
1372e8d1edaSArun Thomas 		printed++;
1382e8d1edaSArun Thomas 	}
1392e8d1edaSArun Thomas 	while ((num /= base) > 0);
1402e8d1edaSArun Thomas 
1412e8d1edaSArun Thomas 	if (n < 0)
1422e8d1edaSArun Thomas 		printed++;
1432e8d1edaSArun Thomas 	while (printed++ < d)
1442e8d1edaSArun Thomas 		pushback('0');
1452e8d1edaSArun Thomas 
1462e8d1edaSArun Thomas 	if (n < 0)
1472e8d1edaSArun Thomas 		pushback('-');
1482e8d1edaSArun Thomas }
1492e8d1edaSArun Thomas 
1502e8d1edaSArun Thomas /*
1512e8d1edaSArun Thomas  *  pbunsigned - convert unsigned long to string, push back on input.
1522e8d1edaSArun Thomas  */
1532e8d1edaSArun Thomas void
pbunsigned(unsigned long n)1542e8d1edaSArun Thomas pbunsigned(unsigned long n)
1552e8d1edaSArun Thomas {
1562e8d1edaSArun Thomas 	do {
1572e8d1edaSArun Thomas 		pushback(n % 10 + '0');
1582e8d1edaSArun Thomas 	}
1592e8d1edaSArun Thomas 	while ((n /= 10) > 0);
1602e8d1edaSArun Thomas }
1612e8d1edaSArun Thomas 
1622e8d1edaSArun Thomas void
initspaces(void)163*71c7dcb9SLionel Sambuc initspaces(void)
1642e8d1edaSArun Thomas {
1652e8d1edaSArun Thomas 	int i;
1662e8d1edaSArun Thomas 
1672e8d1edaSArun Thomas 	strspace = xalloc(strsize+1, NULL);
1682e8d1edaSArun Thomas 	ep = strspace;
1692e8d1edaSArun Thomas 	endest = strspace+strsize;
1702e8d1edaSArun Thomas 	buf = (unsigned char *)xalloc(bufsize, NULL);
1712e8d1edaSArun Thomas 	bufbase = buf;
1722e8d1edaSArun Thomas 	bp = buf;
1732e8d1edaSArun Thomas 	endpbb = buf + bufsize;
1742e8d1edaSArun Thomas 	for (i = 0; i < MAXINP; i++)
1752e8d1edaSArun Thomas 		bbase[i] = buf;
1762e8d1edaSArun Thomas }
1772e8d1edaSArun Thomas 
1782e8d1edaSArun Thomas void
enlarge_strspace(void)179*71c7dcb9SLionel Sambuc enlarge_strspace(void)
1802e8d1edaSArun Thomas {
1812e8d1edaSArun Thomas 	char *newstrspace;
1822e8d1edaSArun Thomas 	int i;
1832e8d1edaSArun Thomas 
1842e8d1edaSArun Thomas 	strsize *= 2;
1852e8d1edaSArun Thomas 	newstrspace = malloc(strsize + 1);
1862e8d1edaSArun Thomas 	if (!newstrspace)
1872e8d1edaSArun Thomas 		errx(1, "string space overflow");
1882e8d1edaSArun Thomas 	memcpy(newstrspace, strspace, strsize/2);
1892e8d1edaSArun Thomas 	for (i = 0; i <= sp; i++)
1902e8d1edaSArun Thomas 		if (sstack[i])
1912e8d1edaSArun Thomas 			mstack[i].sstr = (mstack[i].sstr - strspace)
1922e8d1edaSArun Thomas 			    + newstrspace;
1932e8d1edaSArun Thomas 	ep = (ep-strspace) + newstrspace;
1942e8d1edaSArun Thomas 	free(strspace);
1952e8d1edaSArun Thomas 	strspace = newstrspace;
1962e8d1edaSArun Thomas 	endest = strspace + strsize;
1972e8d1edaSArun Thomas }
1982e8d1edaSArun Thomas 
1992e8d1edaSArun Thomas void
enlarge_bufspace(void)200*71c7dcb9SLionel Sambuc enlarge_bufspace(void)
2012e8d1edaSArun Thomas {
2022e8d1edaSArun Thomas 	unsigned char *newbuf;
2032e8d1edaSArun Thomas 	int i;
2042e8d1edaSArun Thomas 
2052e8d1edaSArun Thomas 	bufsize += bufsize/2;
2062e8d1edaSArun Thomas 	newbuf = xrealloc(buf, bufsize, "too many characters pushed back");
2072e8d1edaSArun Thomas 	for (i = 0; i < MAXINP; i++)
2082e8d1edaSArun Thomas 		bbase[i] = (bbase[i]-buf)+newbuf;
2092e8d1edaSArun Thomas 	bp = (bp-buf)+newbuf;
2102e8d1edaSArun Thomas 	bufbase = (bufbase-buf)+newbuf;
2112e8d1edaSArun Thomas 	buf = newbuf;
2122e8d1edaSArun Thomas 	endpbb = buf+bufsize;
2132e8d1edaSArun Thomas }
2142e8d1edaSArun Thomas 
2152e8d1edaSArun Thomas /*
2162e8d1edaSArun Thomas  *  chrsave - put single char on string space
2172e8d1edaSArun Thomas  */
2182e8d1edaSArun Thomas void
chrsave(int c)2192e8d1edaSArun Thomas chrsave(int c)
2202e8d1edaSArun Thomas {
2212e8d1edaSArun Thomas 	if (ep >= endest)
2222e8d1edaSArun Thomas 		enlarge_strspace();
2232e8d1edaSArun Thomas 	*ep++ = c;
2242e8d1edaSArun Thomas }
2252e8d1edaSArun Thomas 
2262e8d1edaSArun Thomas /*
2272e8d1edaSArun Thomas  * read in a diversion file, and dispose it.
2282e8d1edaSArun Thomas  */
2292e8d1edaSArun Thomas void
getdiv(int n)2302e8d1edaSArun Thomas getdiv(int n)
2312e8d1edaSArun Thomas {
2322e8d1edaSArun Thomas 	int c;
2332e8d1edaSArun Thomas 
2342e8d1edaSArun Thomas 	if (active == outfile[n])
2352e8d1edaSArun Thomas 		m4errx(1, "undivert: diversion still active.");
2362e8d1edaSArun Thomas 	rewind(outfile[n]);
2372e8d1edaSArun Thomas 	while ((c = getc(outfile[n])) != EOF)
2382e8d1edaSArun Thomas 		putc(c, active);
2392e8d1edaSArun Thomas 	(void) fclose(outfile[n]);
2402e8d1edaSArun Thomas 	outfile[n] = NULL;
2412e8d1edaSArun Thomas }
2422e8d1edaSArun Thomas 
2432e8d1edaSArun Thomas /*
2442e8d1edaSArun Thomas  * killdiv - get rid of the diversion files
2452e8d1edaSArun Thomas  */
2462e8d1edaSArun Thomas void
killdiv(void)247*71c7dcb9SLionel Sambuc killdiv(void)
2482e8d1edaSArun Thomas {
2492e8d1edaSArun Thomas 	int n;
2502e8d1edaSArun Thomas 
2512e8d1edaSArun Thomas 	for (n = 0; n < maxout; n++)
2522e8d1edaSArun Thomas 		if (outfile[n] != NULL) {
2532e8d1edaSArun Thomas 			(void) fclose(outfile[n]);
2542e8d1edaSArun Thomas 		}
2552e8d1edaSArun Thomas }
2562e8d1edaSArun Thomas 
2572e8d1edaSArun Thomas void
m4errx(int exval,const char * fmt,...)2582e8d1edaSArun Thomas m4errx(int exval, const char *fmt, ...)
2592e8d1edaSArun Thomas {
2602e8d1edaSArun Thomas 	fprintf(stderr, "%s: ", getprogname());
2612e8d1edaSArun Thomas 	fprintf(stderr, "%s at line %lu: ", CURRENT_NAME, CURRENT_LINE);
2622e8d1edaSArun Thomas 	if (fmt != NULL) {
2632e8d1edaSArun Thomas 		va_list ap;
2642e8d1edaSArun Thomas 
2652e8d1edaSArun Thomas 		va_start(ap, fmt);
2662e8d1edaSArun Thomas 		vfprintf(stderr, fmt, ap);
2672e8d1edaSArun Thomas 		va_end(ap);
2682e8d1edaSArun Thomas 	}
2692e8d1edaSArun Thomas 	fprintf(stderr, "\n");
2702e8d1edaSArun Thomas 	exit(exval);
2712e8d1edaSArun Thomas }
2722e8d1edaSArun Thomas 
2732e8d1edaSArun Thomas /*
2742e8d1edaSArun Thomas  * resizedivs: allocate more diversion files */
2752e8d1edaSArun Thomas void
resizedivs(int n)2762e8d1edaSArun Thomas resizedivs(int n)
2772e8d1edaSArun Thomas {
2782e8d1edaSArun Thomas 	int i;
2792e8d1edaSArun Thomas 
2802e8d1edaSArun Thomas 	outfile = (FILE **)xrealloc(outfile, sizeof(FILE *) * n,
2812e8d1edaSArun Thomas 	    "too many diverts %d", n);
2822e8d1edaSArun Thomas 	for (i = maxout; i < n; i++)
2832e8d1edaSArun Thomas 		outfile[i] = NULL;
2842e8d1edaSArun Thomas 	maxout = n;
2852e8d1edaSArun Thomas }
2862e8d1edaSArun Thomas 
2872e8d1edaSArun Thomas void *
xalloc(size_t n,const char * fmt,...)2882e8d1edaSArun Thomas xalloc(size_t n, const char *fmt, ...)
2892e8d1edaSArun Thomas {
2902e8d1edaSArun Thomas 	void *p = malloc(n);
2912e8d1edaSArun Thomas 
2922e8d1edaSArun Thomas 	if (p == NULL) {
2932e8d1edaSArun Thomas 		if (fmt == NULL)
2942e8d1edaSArun Thomas 			err(1, "malloc");
2952e8d1edaSArun Thomas 		else {
2962e8d1edaSArun Thomas 			va_list va;
2972e8d1edaSArun Thomas 
2982e8d1edaSArun Thomas 			va_start(va, fmt);
2992e8d1edaSArun Thomas 			verr(1, fmt, va);
3002e8d1edaSArun Thomas 			va_end(va);
3012e8d1edaSArun Thomas 		}
3022e8d1edaSArun Thomas 	}
3032e8d1edaSArun Thomas 	return p;
3042e8d1edaSArun Thomas }
3052e8d1edaSArun Thomas 
3062e8d1edaSArun Thomas void *
xrealloc(void * old,size_t n,const char * fmt,...)3072e8d1edaSArun Thomas xrealloc(void *old, size_t n, const char *fmt, ...)
3082e8d1edaSArun Thomas {
3092e8d1edaSArun Thomas 	char *p = realloc(old, n);
3102e8d1edaSArun Thomas 
3112e8d1edaSArun Thomas 	if (p == NULL) {
3122e8d1edaSArun Thomas 		free(old);
3132e8d1edaSArun Thomas 		if (fmt == NULL)
3142e8d1edaSArun Thomas 			err(1, "realloc");
3152e8d1edaSArun Thomas 		else {
3162e8d1edaSArun Thomas 			va_list va;
3172e8d1edaSArun Thomas 
3182e8d1edaSArun Thomas 			va_start(va, fmt);
3192e8d1edaSArun Thomas 			verr(1, fmt, va);
3202e8d1edaSArun Thomas 			va_end(va);
3212e8d1edaSArun Thomas 	    	}
3222e8d1edaSArun Thomas 	}
3232e8d1edaSArun Thomas 	return p;
3242e8d1edaSArun Thomas }
3252e8d1edaSArun Thomas 
3262e8d1edaSArun Thomas char *
xstrdup(const char * s)3272e8d1edaSArun Thomas xstrdup(const char *s)
3282e8d1edaSArun Thomas {
3292e8d1edaSArun Thomas 	char *p = strdup(s);
3302e8d1edaSArun Thomas 	if (p == NULL)
3312e8d1edaSArun Thomas 		err(1, "strdup");
3322e8d1edaSArun Thomas 	return p;
3332e8d1edaSArun Thomas }
3342e8d1edaSArun Thomas 
3352e8d1edaSArun Thomas int
obtain_char(struct input_file * f)3362e8d1edaSArun Thomas obtain_char(struct input_file *f)
3372e8d1edaSArun Thomas {
3382e8d1edaSArun Thomas 	if (f->c == EOF)
3392e8d1edaSArun Thomas 		return EOF;
3402e8d1edaSArun Thomas 
3412e8d1edaSArun Thomas 	f->c = fgetc(f->file);
3422e8d1edaSArun Thomas 	if (f->c == '\n')
3432e8d1edaSArun Thomas 		f->lineno++;
3442e8d1edaSArun Thomas 
3452e8d1edaSArun Thomas 	return f->c;
3462e8d1edaSArun Thomas }
3472e8d1edaSArun Thomas 
3482e8d1edaSArun Thomas void
set_input(struct input_file * f,FILE * real,const char * name)3492e8d1edaSArun Thomas set_input(struct input_file *f, FILE *real, const char *name)
3502e8d1edaSArun Thomas {
3512e8d1edaSArun Thomas 	f->file = real;
3522e8d1edaSArun Thomas 	f->lineno = 1;
3532e8d1edaSArun Thomas 	f->c = 0;
3542e8d1edaSArun Thomas 	f->name = xstrdup(name);
3552e8d1edaSArun Thomas 	emit_synchline();
3562e8d1edaSArun Thomas }
3572e8d1edaSArun Thomas 
3582e8d1edaSArun Thomas void
do_emit_synchline(void)359*71c7dcb9SLionel Sambuc do_emit_synchline(void)
3602e8d1edaSArun Thomas {
3612e8d1edaSArun Thomas 	fprintf(active, "#line %lu \"%s\"\n",
3622e8d1edaSArun Thomas 	    infile[ilevel].lineno, infile[ilevel].name);
3632e8d1edaSArun Thomas 	infile[ilevel].synch_lineno = infile[ilevel].lineno;
3642e8d1edaSArun Thomas }
3652e8d1edaSArun Thomas 
3662e8d1edaSArun Thomas void
release_input(struct input_file * f)3672e8d1edaSArun Thomas release_input(struct input_file *f)
3682e8d1edaSArun Thomas {
3692e8d1edaSArun Thomas 	if (f->file != stdin)
3702e8d1edaSArun Thomas 	    fclose(f->file);
3712e8d1edaSArun Thomas 	f->c = EOF;
3722e8d1edaSArun Thomas 	/*
3732e8d1edaSArun Thomas 	 * XXX can't free filename, as there might still be
3742e8d1edaSArun Thomas 	 * error information pointing to it.
3752e8d1edaSArun Thomas 	 */
3762e8d1edaSArun Thomas }
3772e8d1edaSArun Thomas 
3782e8d1edaSArun Thomas void
doprintlineno(struct input_file * f)3792e8d1edaSArun Thomas doprintlineno(struct input_file *f)
3802e8d1edaSArun Thomas {
381*71c7dcb9SLionel Sambuc 	pbunsigned(TOKEN_LINE(f));
3822e8d1edaSArun Thomas }
3832e8d1edaSArun Thomas 
3842e8d1edaSArun Thomas void
doprintfilename(struct input_file * f)3852e8d1edaSArun Thomas doprintfilename(struct input_file *f)
3862e8d1edaSArun Thomas {
3872e8d1edaSArun Thomas 	pbstr(rquote);
3882e8d1edaSArun Thomas 	pbstr(f->name);
3892e8d1edaSArun Thomas 	pbstr(lquote);
3902e8d1edaSArun Thomas }
3912e8d1edaSArun Thomas 
3922e8d1edaSArun Thomas /*
3932e8d1edaSArun Thomas  * buffer_mark/dump_buffer: allows one to save a mark in a buffer,
3942e8d1edaSArun Thomas  * and later dump everything that was added since then to a file.
3952e8d1edaSArun Thomas  */
3962e8d1edaSArun Thomas size_t
buffer_mark(void)397*71c7dcb9SLionel Sambuc buffer_mark(void)
3982e8d1edaSArun Thomas {
3992e8d1edaSArun Thomas 	return bp - buf;
4002e8d1edaSArun Thomas }
4012e8d1edaSArun Thomas 
4022e8d1edaSArun Thomas 
4032e8d1edaSArun Thomas void
dump_buffer(FILE * f,size_t m)4042e8d1edaSArun Thomas dump_buffer(FILE *f, size_t m)
4052e8d1edaSArun Thomas {
4062e8d1edaSArun Thomas 	unsigned char *s;
4072e8d1edaSArun Thomas 
4082e8d1edaSArun Thomas 	for (s = bp; (size_t)(s - buf) > m;)
4092e8d1edaSArun Thomas 		fputc(*--s, f);
4102e8d1edaSArun Thomas }
411