Home | History | Annotate | Line # | Download | only in config
util.c revision 1.8.8.1
      1  1.8.8.1      yamt /*	$NetBSD: util.c,v 1.8.8.1 2012/04/17 00:09:30 yamt Exp $	*/
      2      1.1   thorpej 
      3      1.1   thorpej /*
      4      1.1   thorpej  * Copyright (c) 1992, 1993
      5      1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
      6      1.1   thorpej  *
      7      1.1   thorpej  * This software was developed by the Computer Systems Engineering group
      8      1.1   thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9      1.1   thorpej  * contributed to Berkeley.
     10      1.1   thorpej  *
     11      1.1   thorpej  * All advertising materials mentioning features or use of this software
     12      1.1   thorpej  * must display the following acknowledgement:
     13      1.1   thorpej  *	This product includes software developed by the University of
     14      1.1   thorpej  *	California, Lawrence Berkeley Laboratories.
     15      1.1   thorpej  *
     16      1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     17      1.1   thorpej  * modification, are permitted provided that the following conditions
     18      1.1   thorpej  * are met:
     19      1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     20      1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     21      1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     22      1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     23      1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     24      1.1   thorpej  * 3. Neither the name of the University nor the names of its contributors
     25      1.1   thorpej  *    may be used to endorse or promote products derived from this software
     26      1.1   thorpej  *    without specific prior written permission.
     27      1.1   thorpej  *
     28      1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29      1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30      1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31      1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32      1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33      1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34      1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35      1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36      1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37      1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38      1.1   thorpej  * SUCH DAMAGE.
     39      1.1   thorpej  *
     40      1.1   thorpej  *	from: @(#)util.c	8.1 (Berkeley) 6/6/93
     41      1.1   thorpej  */
     42      1.1   thorpej 
     43      1.1   thorpej #if HAVE_NBTOOL_CONFIG_H
     44      1.1   thorpej #include "nbtool_config.h"
     45      1.1   thorpej #endif
     46      1.1   thorpej 
     47      1.3  christos #include <sys/types.h>
     48  1.8.8.1      yamt #include <assert.h>
     49      1.1   thorpej #include <ctype.h>
     50      1.1   thorpej #include <stdio.h>
     51      1.1   thorpej #include <stdlib.h>
     52      1.1   thorpej #include <string.h>
     53      1.1   thorpej #include <stdarg.h>
     54      1.3  christos #include <util.h>
     55      1.6  christos #include <err.h>
     56      1.1   thorpej #include "defs.h"
     57      1.1   thorpej 
     58      1.6  christos static void cfgvxerror(const char *, int, const char *, va_list)
     59  1.8.8.1      yamt 	     __printflike(3, 0);
     60      1.6  christos static void cfgvxwarn(const char *, int, const char *, va_list)
     61  1.8.8.1      yamt 	     __printflike(3, 0);
     62      1.6  christos static void cfgvxmsg(const char *, int, const char *, const char *, va_list)
     63  1.8.8.1      yamt      __printflike(4, 0);
     64  1.8.8.1      yamt 
     65  1.8.8.1      yamt /************************************************************/
     66  1.8.8.1      yamt 
     67  1.8.8.1      yamt /*
     68  1.8.8.1      yamt  * Prefix stack
     69  1.8.8.1      yamt  */
     70      1.1   thorpej 
     71      1.1   thorpej /*
     72      1.1   thorpej  * Push a prefix onto the prefix stack.
     73      1.1   thorpej  */
     74      1.1   thorpej void
     75      1.1   thorpej prefix_push(const char *path)
     76      1.1   thorpej {
     77      1.1   thorpej 	struct prefix *pf;
     78      1.1   thorpej 	char *cp;
     79      1.1   thorpej 
     80      1.1   thorpej 	pf = ecalloc(1, sizeof(struct prefix));
     81      1.1   thorpej 
     82      1.1   thorpej 	if (! SLIST_EMPTY(&prefixes) && *path != '/') {
     83      1.1   thorpej 		cp = emalloc(strlen(SLIST_FIRST(&prefixes)->pf_prefix) + 1 +
     84      1.1   thorpej 		    strlen(path) + 1);
     85      1.1   thorpej 		(void) sprintf(cp, "%s/%s",
     86      1.1   thorpej 		    SLIST_FIRST(&prefixes)->pf_prefix, path);
     87      1.1   thorpej 		pf->pf_prefix = intern(cp);
     88      1.1   thorpej 		free(cp);
     89      1.1   thorpej 	} else
     90      1.1   thorpej 		pf->pf_prefix = intern(path);
     91      1.1   thorpej 
     92      1.1   thorpej 	SLIST_INSERT_HEAD(&prefixes, pf, pf_next);
     93      1.1   thorpej }
     94      1.1   thorpej 
     95      1.1   thorpej /*
     96      1.1   thorpej  * Pop a prefix off the prefix stack.
     97      1.1   thorpej  */
     98      1.1   thorpej void
     99      1.1   thorpej prefix_pop(void)
    100      1.1   thorpej {
    101      1.1   thorpej 	struct prefix *pf;
    102      1.1   thorpej 
    103      1.1   thorpej 	if ((pf = SLIST_FIRST(&prefixes)) == NULL) {
    104      1.6  christos 		cfgerror("no prefixes on the stack to pop");
    105      1.1   thorpej 		return;
    106      1.1   thorpej 	}
    107      1.1   thorpej 
    108      1.1   thorpej 	SLIST_REMOVE_HEAD(&prefixes, pf_next);
    109      1.1   thorpej 	/* Remember this prefix for emitting -I... directives later. */
    110      1.1   thorpej 	SLIST_INSERT_HEAD(&allprefixes, pf, pf_next);
    111      1.1   thorpej }
    112      1.1   thorpej 
    113      1.1   thorpej /*
    114      1.1   thorpej  * Prepend the source path to a file name.
    115      1.1   thorpej  */
    116      1.1   thorpej char *
    117      1.1   thorpej sourcepath(const char *file)
    118      1.1   thorpej {
    119      1.1   thorpej 	size_t len;
    120      1.1   thorpej 	char *cp;
    121      1.1   thorpej 	struct prefix *pf;
    122      1.1   thorpej 
    123      1.1   thorpej 	pf = SLIST_EMPTY(&prefixes) ? NULL : SLIST_FIRST(&prefixes);
    124      1.1   thorpej 	if (pf != NULL && *pf->pf_prefix == '/')
    125      1.1   thorpej 		len = strlen(pf->pf_prefix) + 1 + strlen(file) + 1;
    126      1.1   thorpej 	else {
    127      1.1   thorpej 		len = strlen(srcdir) + 1 + strlen(file) + 1;
    128      1.1   thorpej 		if (pf != NULL)
    129      1.1   thorpej 			len += strlen(pf->pf_prefix) + 1;
    130      1.1   thorpej 	}
    131      1.1   thorpej 
    132      1.1   thorpej 	cp = emalloc(len);
    133      1.1   thorpej 
    134      1.1   thorpej 	if (pf != NULL) {
    135      1.1   thorpej 		if (*pf->pf_prefix == '/')
    136      1.1   thorpej 			(void) sprintf(cp, "%s/%s", pf->pf_prefix, file);
    137      1.1   thorpej 		else
    138      1.1   thorpej 			(void) sprintf(cp, "%s/%s/%s", srcdir,
    139      1.1   thorpej 			    pf->pf_prefix, file);
    140      1.1   thorpej 	} else
    141      1.1   thorpej 		(void) sprintf(cp, "%s/%s", srcdir, file);
    142      1.1   thorpej 	return (cp);
    143      1.1   thorpej }
    144      1.1   thorpej 
    145  1.8.8.1      yamt /************************************************************/
    146  1.8.8.1      yamt 
    147  1.8.8.1      yamt /*
    148  1.8.8.1      yamt  * Data structures
    149  1.8.8.1      yamt  */
    150  1.8.8.1      yamt 
    151  1.8.8.1      yamt /*
    152  1.8.8.1      yamt  * nvlist
    153  1.8.8.1      yamt  */
    154  1.8.8.1      yamt 
    155      1.1   thorpej struct nvlist *
    156      1.8  christos newnv(const char *name, const char *str, void *ptr, long long i, struct nvlist *next)
    157      1.1   thorpej {
    158      1.1   thorpej 	struct nvlist *nv;
    159      1.1   thorpej 
    160      1.4       dsl 	nv = ecalloc(1, sizeof(*nv));
    161      1.1   thorpej 	nv->nv_next = next;
    162      1.1   thorpej 	nv->nv_name = name;
    163      1.4       dsl 	nv->nv_str = str;
    164      1.4       dsl 	nv->nv_ptr = ptr;
    165      1.8  christos 	nv->nv_num = i;
    166      1.4       dsl 	return nv;
    167      1.1   thorpej }
    168      1.1   thorpej 
    169      1.1   thorpej /*
    170      1.1   thorpej  * Free an nvlist structure (just one).
    171      1.1   thorpej  */
    172      1.1   thorpej void
    173      1.1   thorpej nvfree(struct nvlist *nv)
    174      1.1   thorpej {
    175      1.1   thorpej 
    176      1.4       dsl 	free(nv);
    177      1.1   thorpej }
    178      1.1   thorpej 
    179      1.1   thorpej /*
    180      1.1   thorpej  * Free an nvlist (the whole list).
    181      1.1   thorpej  */
    182      1.1   thorpej void
    183      1.1   thorpej nvfreel(struct nvlist *nv)
    184      1.1   thorpej {
    185      1.1   thorpej 	struct nvlist *next;
    186      1.1   thorpej 
    187      1.1   thorpej 	for (; nv != NULL; nv = next) {
    188      1.1   thorpej 		next = nv->nv_next;
    189      1.4       dsl 		free(nv);
    190      1.1   thorpej 	}
    191      1.1   thorpej }
    192      1.1   thorpej 
    193      1.5      cube struct nvlist *
    194      1.5      cube nvcat(struct nvlist *nv1, struct nvlist *nv2)
    195      1.5      cube {
    196      1.5      cube 	struct nvlist *nv;
    197      1.5      cube 
    198      1.5      cube 	if (nv1 == NULL)
    199      1.5      cube 		return nv2;
    200      1.5      cube 
    201      1.5      cube 	for (nv = nv1; nv->nv_next != NULL; nv = nv->nv_next);
    202      1.5      cube 
    203      1.5      cube 	nv->nv_next = nv2;
    204      1.5      cube 	return nv1;
    205      1.5      cube }
    206      1.5      cube 
    207  1.8.8.1      yamt /*
    208  1.8.8.1      yamt  * Option definition lists
    209  1.8.8.1      yamt  */
    210  1.8.8.1      yamt 
    211  1.8.8.1      yamt struct defoptlist *
    212  1.8.8.1      yamt defoptlist_create(const char *name, const char *val, const char *lintval)
    213  1.8.8.1      yamt {
    214  1.8.8.1      yamt 	struct defoptlist *dl;
    215  1.8.8.1      yamt 
    216  1.8.8.1      yamt 	dl = emalloc(sizeof(*dl));
    217  1.8.8.1      yamt 	dl->dl_next = NULL;
    218  1.8.8.1      yamt 	dl->dl_name = name;
    219  1.8.8.1      yamt 	dl->dl_value = val;
    220  1.8.8.1      yamt 	dl->dl_lintvalue = lintval;
    221  1.8.8.1      yamt 	dl->dl_obsolete = 0;
    222  1.8.8.1      yamt 	dl->dl_depends = NULL;
    223  1.8.8.1      yamt 	return dl;
    224  1.8.8.1      yamt }
    225  1.8.8.1      yamt 
    226  1.8.8.1      yamt void
    227  1.8.8.1      yamt defoptlist_destroy(struct defoptlist *dl)
    228  1.8.8.1      yamt {
    229  1.8.8.1      yamt 	struct defoptlist *next;
    230  1.8.8.1      yamt 
    231  1.8.8.1      yamt 	while (dl != NULL) {
    232  1.8.8.1      yamt 		next = dl->dl_next;
    233  1.8.8.1      yamt 		dl->dl_next = NULL;
    234  1.8.8.1      yamt 
    235  1.8.8.1      yamt 		// XXX should we assert that dl->dl_deps is null to
    236  1.8.8.1      yamt 		// be sure the deps have already been destroyed?
    237  1.8.8.1      yamt 		free(dl);
    238  1.8.8.1      yamt 
    239  1.8.8.1      yamt 		dl = next;
    240  1.8.8.1      yamt 	}
    241  1.8.8.1      yamt }
    242  1.8.8.1      yamt 
    243  1.8.8.1      yamt struct defoptlist *
    244  1.8.8.1      yamt defoptlist_append(struct defoptlist *dla, struct defoptlist *dlb)
    245  1.8.8.1      yamt {
    246  1.8.8.1      yamt 	struct defoptlist *dl;
    247  1.8.8.1      yamt 
    248  1.8.8.1      yamt 	if (dla == NULL)
    249  1.8.8.1      yamt 		return dlb;
    250  1.8.8.1      yamt 
    251  1.8.8.1      yamt 	for (dl = dla; dl->dl_next != NULL; dl = dl->dl_next)
    252  1.8.8.1      yamt 		;
    253  1.8.8.1      yamt 
    254  1.8.8.1      yamt 	dl->dl_next = dlb;
    255  1.8.8.1      yamt 	return dla;
    256  1.8.8.1      yamt }
    257  1.8.8.1      yamt 
    258  1.8.8.1      yamt /*
    259  1.8.8.1      yamt  * Locator lists
    260  1.8.8.1      yamt  */
    261  1.8.8.1      yamt 
    262  1.8.8.1      yamt struct loclist *
    263  1.8.8.1      yamt loclist_create(const char *name, const char *string, long long num)
    264  1.8.8.1      yamt {
    265  1.8.8.1      yamt 	struct loclist *ll;
    266  1.8.8.1      yamt 
    267  1.8.8.1      yamt 	ll = emalloc(sizeof(*ll));
    268  1.8.8.1      yamt 	ll->ll_name = name;
    269  1.8.8.1      yamt 	ll->ll_string = string;
    270  1.8.8.1      yamt 	ll->ll_num = num;
    271  1.8.8.1      yamt 	ll->ll_next = NULL;
    272  1.8.8.1      yamt 	return ll;
    273  1.8.8.1      yamt }
    274  1.8.8.1      yamt 
    275  1.8.8.1      yamt void
    276  1.8.8.1      yamt loclist_destroy(struct loclist *ll)
    277  1.8.8.1      yamt {
    278  1.8.8.1      yamt 	struct loclist *next;
    279  1.8.8.1      yamt 
    280  1.8.8.1      yamt 	while (ll != NULL) {
    281  1.8.8.1      yamt 		next = ll->ll_next;
    282  1.8.8.1      yamt 		ll->ll_next = NULL;
    283  1.8.8.1      yamt 		free(ll);
    284  1.8.8.1      yamt 		ll = next;
    285  1.8.8.1      yamt 	}
    286  1.8.8.1      yamt }
    287  1.8.8.1      yamt 
    288  1.8.8.1      yamt /*
    289  1.8.8.1      yamt  * Attribute lists
    290  1.8.8.1      yamt  */
    291  1.8.8.1      yamt 
    292  1.8.8.1      yamt struct attrlist *
    293  1.8.8.1      yamt attrlist_create(void)
    294  1.8.8.1      yamt {
    295  1.8.8.1      yamt 	struct attrlist *al;
    296  1.8.8.1      yamt 
    297  1.8.8.1      yamt 	al = emalloc(sizeof(*al));
    298  1.8.8.1      yamt 	al->al_next = NULL;
    299  1.8.8.1      yamt 	al->al_this = NULL;
    300  1.8.8.1      yamt 	return al;
    301  1.8.8.1      yamt }
    302  1.8.8.1      yamt 
    303  1.8.8.1      yamt struct attrlist *
    304  1.8.8.1      yamt attrlist_cons(struct attrlist *next, struct attr *a)
    305  1.8.8.1      yamt {
    306  1.8.8.1      yamt 	struct attrlist *al;
    307  1.8.8.1      yamt 
    308  1.8.8.1      yamt 	al = attrlist_create();
    309  1.8.8.1      yamt 	al->al_next = next;
    310  1.8.8.1      yamt 	al->al_this = a;
    311  1.8.8.1      yamt 	return al;
    312  1.8.8.1      yamt }
    313  1.8.8.1      yamt 
    314  1.8.8.1      yamt void
    315  1.8.8.1      yamt attrlist_destroy(struct attrlist *al)
    316  1.8.8.1      yamt {
    317  1.8.8.1      yamt 	assert(al->al_next == NULL);
    318  1.8.8.1      yamt 	assert(al->al_this == NULL);
    319  1.8.8.1      yamt 	free(al);
    320  1.8.8.1      yamt }
    321  1.8.8.1      yamt 
    322  1.8.8.1      yamt void
    323  1.8.8.1      yamt attrlist_destroyall(struct attrlist *al)
    324  1.8.8.1      yamt {
    325  1.8.8.1      yamt 	struct attrlist *next;
    326  1.8.8.1      yamt 
    327  1.8.8.1      yamt 	while (al != NULL) {
    328  1.8.8.1      yamt 		next = al->al_next;
    329  1.8.8.1      yamt 		al->al_next = NULL;
    330  1.8.8.1      yamt 		/* XXX should we make the caller guarantee this? */
    331  1.8.8.1      yamt 		al->al_this = NULL;
    332  1.8.8.1      yamt 		attrlist_destroy(al);
    333  1.8.8.1      yamt 		al = next;
    334  1.8.8.1      yamt 	}
    335  1.8.8.1      yamt }
    336  1.8.8.1      yamt 
    337  1.8.8.1      yamt /*
    338  1.8.8.1      yamt  * Condition expressions
    339  1.8.8.1      yamt  */
    340  1.8.8.1      yamt 
    341  1.8.8.1      yamt /*
    342  1.8.8.1      yamt  * Create an expression node.
    343  1.8.8.1      yamt  */
    344  1.8.8.1      yamt struct condexpr *
    345  1.8.8.1      yamt condexpr_create(enum condexpr_types type)
    346  1.8.8.1      yamt {
    347  1.8.8.1      yamt 	struct condexpr *cx;
    348  1.8.8.1      yamt 
    349  1.8.8.1      yamt 	cx = emalloc(sizeof(*cx));
    350  1.8.8.1      yamt 	cx->cx_type = type;
    351  1.8.8.1      yamt 	switch (type) {
    352  1.8.8.1      yamt 
    353  1.8.8.1      yamt 	    case CX_ATOM:
    354  1.8.8.1      yamt 		cx->cx_atom = NULL;
    355  1.8.8.1      yamt 		break;
    356  1.8.8.1      yamt 
    357  1.8.8.1      yamt 	    case CX_NOT:
    358  1.8.8.1      yamt 		cx->cx_not = NULL;
    359  1.8.8.1      yamt 		break;
    360  1.8.8.1      yamt 
    361  1.8.8.1      yamt 	    case CX_AND:
    362  1.8.8.1      yamt 		cx->cx_and.left = NULL;
    363  1.8.8.1      yamt 		cx->cx_and.right = NULL;
    364  1.8.8.1      yamt 		break;
    365  1.8.8.1      yamt 
    366  1.8.8.1      yamt 	    case CX_OR:
    367  1.8.8.1      yamt 		cx->cx_or.left = NULL;
    368  1.8.8.1      yamt 		cx->cx_or.right = NULL;
    369  1.8.8.1      yamt 		break;
    370  1.8.8.1      yamt 
    371  1.8.8.1      yamt 	    default:
    372  1.8.8.1      yamt 		panic("condexpr_create: invalid expr type %d", (int)type);
    373  1.8.8.1      yamt 	}
    374  1.8.8.1      yamt 	return cx;
    375  1.8.8.1      yamt }
    376  1.8.8.1      yamt 
    377  1.8.8.1      yamt /*
    378  1.8.8.1      yamt  * Free an expression tree.
    379  1.8.8.1      yamt  */
    380  1.8.8.1      yamt void
    381  1.8.8.1      yamt condexpr_destroy(struct condexpr *expr)
    382  1.8.8.1      yamt {
    383  1.8.8.1      yamt 	switch (expr->cx_type) {
    384  1.8.8.1      yamt 
    385  1.8.8.1      yamt 	    case CX_ATOM:
    386  1.8.8.1      yamt 		/* nothing */
    387  1.8.8.1      yamt 		break;
    388  1.8.8.1      yamt 
    389  1.8.8.1      yamt 	    case CX_NOT:
    390  1.8.8.1      yamt 		condexpr_destroy(expr->cx_not);
    391  1.8.8.1      yamt 		break;
    392  1.8.8.1      yamt 
    393  1.8.8.1      yamt 	    case CX_AND:
    394  1.8.8.1      yamt 		condexpr_destroy(expr->cx_and.left);
    395  1.8.8.1      yamt 		condexpr_destroy(expr->cx_and.right);
    396  1.8.8.1      yamt 		break;
    397  1.8.8.1      yamt 
    398  1.8.8.1      yamt 	    case CX_OR:
    399  1.8.8.1      yamt 		condexpr_destroy(expr->cx_or.left);
    400  1.8.8.1      yamt 		condexpr_destroy(expr->cx_or.right);
    401  1.8.8.1      yamt 		break;
    402  1.8.8.1      yamt 
    403  1.8.8.1      yamt 	    default:
    404  1.8.8.1      yamt 		panic("condexpr_destroy: invalid expr type %d",
    405  1.8.8.1      yamt 		      (int)expr->cx_type);
    406  1.8.8.1      yamt 	}
    407  1.8.8.1      yamt 	free(expr);
    408  1.8.8.1      yamt }
    409  1.8.8.1      yamt 
    410  1.8.8.1      yamt /************************************************************/
    411  1.8.8.1      yamt 
    412  1.8.8.1      yamt /*
    413  1.8.8.1      yamt  * Diagnostic messages
    414  1.8.8.1      yamt  */
    415  1.8.8.1      yamt 
    416      1.1   thorpej void
    417      1.6  christos cfgwarn(const char *fmt, ...)
    418      1.1   thorpej {
    419      1.1   thorpej 	va_list ap;
    420      1.1   thorpej 	extern const char *yyfile;
    421      1.1   thorpej 
    422      1.1   thorpej 	va_start(ap, fmt);
    423      1.6  christos 	cfgvxwarn(yyfile, currentline(), fmt, ap);
    424      1.1   thorpej 	va_end(ap);
    425      1.1   thorpej }
    426      1.1   thorpej 
    427      1.2      cube void
    428      1.6  christos cfgxwarn(const char *file, int line, const char *fmt, ...)
    429      1.2      cube {
    430      1.2      cube 	va_list ap;
    431      1.2      cube 
    432      1.2      cube 	va_start(ap, fmt);
    433      1.6  christos 	cfgvxwarn(file, line, fmt, ap);
    434      1.2      cube 	va_end(ap);
    435      1.2      cube }
    436      1.1   thorpej 
    437      1.1   thorpej static void
    438      1.6  christos cfgvxwarn(const char *file, int line, const char *fmt, va_list ap)
    439      1.1   thorpej {
    440      1.6  christos 	cfgvxmsg(file, line, "warning: ", fmt, ap);
    441      1.1   thorpej }
    442      1.1   thorpej 
    443      1.1   thorpej /*
    444      1.1   thorpej  * External (config file) error.  Complain, using current file
    445      1.1   thorpej  * and line number.
    446      1.1   thorpej  */
    447      1.1   thorpej void
    448      1.6  christos cfgerror(const char *fmt, ...)
    449      1.1   thorpej {
    450      1.1   thorpej 	va_list ap;
    451      1.1   thorpej 	extern const char *yyfile;
    452      1.1   thorpej 
    453      1.1   thorpej 	va_start(ap, fmt);
    454      1.6  christos 	cfgvxerror(yyfile, currentline(), fmt, ap);
    455      1.1   thorpej 	va_end(ap);
    456      1.1   thorpej }
    457      1.1   thorpej 
    458      1.1   thorpej /*
    459      1.1   thorpej  * Delayed config file error (i.e., something was wrong but we could not
    460      1.1   thorpej  * find out about it until later).
    461      1.1   thorpej  */
    462      1.1   thorpej void
    463      1.6  christos cfgxerror(const char *file, int line, const char *fmt, ...)
    464      1.1   thorpej {
    465      1.1   thorpej 	va_list ap;
    466      1.1   thorpej 
    467      1.1   thorpej 	va_start(ap, fmt);
    468      1.6  christos 	cfgvxerror(file, line, fmt, ap);
    469      1.1   thorpej 	va_end(ap);
    470      1.1   thorpej }
    471      1.1   thorpej 
    472      1.1   thorpej /*
    473      1.1   thorpej  * Internal form of error() and xerror().
    474      1.1   thorpej  */
    475      1.1   thorpej static void
    476      1.6  christos cfgvxerror(const char *file, int line, const char *fmt, va_list ap)
    477      1.1   thorpej {
    478      1.6  christos 	cfgvxmsg(file, line, "", fmt, ap);
    479      1.1   thorpej 	errors++;
    480      1.1   thorpej }
    481      1.1   thorpej 
    482      1.1   thorpej 
    483      1.1   thorpej /*
    484      1.1   thorpej  * Internal error, abort.
    485      1.1   thorpej  */
    486      1.1   thorpej __dead void
    487      1.1   thorpej panic(const char *fmt, ...)
    488      1.1   thorpej {
    489      1.1   thorpej 	va_list ap;
    490      1.1   thorpej 
    491      1.1   thorpej 	va_start(ap, fmt);
    492      1.6  christos 	(void)fprintf(stderr, "%s: panic: ", getprogname());
    493      1.1   thorpej 	(void)vfprintf(stderr, fmt, ap);
    494      1.1   thorpej 	(void)putc('\n', stderr);
    495      1.1   thorpej 	va_end(ap);
    496      1.1   thorpej 	exit(2);
    497      1.1   thorpej }
    498      1.1   thorpej 
    499      1.1   thorpej /*
    500      1.1   thorpej  * Internal form of error() and xerror().
    501      1.1   thorpej  */
    502      1.1   thorpej static void
    503      1.6  christos cfgvxmsg(const char *file, int line, const char *msgclass, const char *fmt,
    504      1.1   thorpej       va_list ap)
    505      1.1   thorpej {
    506      1.1   thorpej 
    507      1.1   thorpej 	(void)fprintf(stderr, "%s:%d: %s", file, line, msgclass);
    508      1.1   thorpej 	(void)vfprintf(stderr, fmt, ap);
    509      1.1   thorpej 	(void)putc('\n', stderr);
    510      1.1   thorpej }
    511      1.7     lukem 
    512      1.7     lukem void
    513      1.7     lukem autogen_comment(FILE *fp, const char *targetfile)
    514      1.7     lukem {
    515      1.7     lukem 
    516      1.7     lukem 	(void)fprintf(fp,
    517      1.7     lukem 	    "/*\n"
    518      1.7     lukem 	    " * MACHINE GENERATED: DO NOT EDIT\n"
    519      1.7     lukem 	    " *\n"
    520      1.7     lukem 	    " * %s, from \"%s\"\n"
    521      1.7     lukem 	    " */\n\n",
    522      1.7     lukem 	    targetfile, conffile);
    523      1.7     lukem }
    524