Home | History | Annotate | Line # | Download | only in config
util.c revision 1.20
      1  1.20  uebayasi /*	$NetBSD: util.c,v 1.20 2015/09/01 13:42:48 uebayasi 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.19  christos #include <sys/cdefs.h>
     48  1.19  christos __RCSID("$NetBSD: util.c,v 1.20 2015/09/01 13:42:48 uebayasi Exp $");
     49  1.19  christos 
     50   1.3  christos #include <sys/types.h>
     51  1.10  dholland #include <assert.h>
     52   1.1   thorpej #include <ctype.h>
     53   1.1   thorpej #include <stdio.h>
     54   1.1   thorpej #include <stdlib.h>
     55   1.1   thorpej #include <string.h>
     56   1.1   thorpej #include <stdarg.h>
     57   1.3  christos #include <util.h>
     58   1.6  christos #include <err.h>
     59   1.1   thorpej #include "defs.h"
     60   1.1   thorpej 
     61   1.6  christos static void cfgvxerror(const char *, int, const char *, va_list)
     62   1.9  dholland 	     __printflike(3, 0);
     63  1.17  uebayasi static void cfgvxdbg(const char *, int, const char *, va_list)
     64  1.17  uebayasi 	     __printflike(3, 0);
     65   1.6  christos static void cfgvxwarn(const char *, int, const char *, va_list)
     66   1.9  dholland 	     __printflike(3, 0);
     67   1.6  christos static void cfgvxmsg(const char *, int, const char *, const char *, va_list)
     68   1.9  dholland      __printflike(4, 0);
     69   1.1   thorpej 
     70  1.12  dholland /************************************************************/
     71  1.12  dholland 
     72  1.12  dholland /*
     73  1.12  dholland  * Prefix stack
     74  1.12  dholland  */
     75  1.12  dholland 
     76  1.20  uebayasi static void
     77  1.20  uebayasi prefixlist_push(struct prefixlist *pl, const char *path)
     78   1.1   thorpej {
     79  1.20  uebayasi 	struct prefix *prevpf = SLIST_FIRST(pl);
     80   1.1   thorpej 	struct prefix *pf;
     81   1.1   thorpej 	char *cp;
     82   1.1   thorpej 
     83   1.1   thorpej 	pf = ecalloc(1, sizeof(struct prefix));
     84   1.1   thorpej 
     85  1.20  uebayasi 	if (prevpf != NULL) {
     86  1.20  uebayasi 		cp = emalloc(strlen(prevpf->pf_prefix) + 1 +
     87   1.1   thorpej 		    strlen(path) + 1);
     88  1.20  uebayasi 		(void) sprintf(cp, "%s/%s", prevpf->pf_prefix, path);
     89   1.1   thorpej 		pf->pf_prefix = intern(cp);
     90   1.1   thorpej 		free(cp);
     91   1.1   thorpej 	} else
     92   1.1   thorpej 		pf->pf_prefix = intern(path);
     93   1.1   thorpej 
     94  1.20  uebayasi 	SLIST_INSERT_HEAD(pl, pf, pf_next);
     95  1.20  uebayasi }
     96  1.20  uebayasi 
     97  1.20  uebayasi static void
     98  1.20  uebayasi prefixlist_pop(struct prefixlist *allpl, struct prefixlist *pl)
     99  1.20  uebayasi {
    100  1.20  uebayasi 	struct prefix *pf;
    101  1.20  uebayasi 
    102  1.20  uebayasi 	if ((pf = SLIST_FIRST(pl)) == NULL) {
    103  1.20  uebayasi 		cfgerror("no prefixes on the stack to pop");
    104  1.20  uebayasi 		return;
    105  1.20  uebayasi 	}
    106  1.20  uebayasi 
    107  1.20  uebayasi 	SLIST_REMOVE_HEAD(pl, pf_next);
    108  1.20  uebayasi 	/* Remember this prefix for emitting -I... directives later. */
    109  1.20  uebayasi 	SLIST_INSERT_HEAD(allpl, pf, pf_next);
    110  1.20  uebayasi }
    111  1.20  uebayasi 
    112  1.20  uebayasi /*
    113  1.20  uebayasi  * Push a prefix onto the prefix stack.
    114  1.20  uebayasi  */
    115  1.20  uebayasi void
    116  1.20  uebayasi prefix_push(const char *path)
    117  1.20  uebayasi {
    118  1.20  uebayasi 	prefixlist_push(&prefixes, path);
    119   1.1   thorpej }
    120   1.1   thorpej 
    121   1.1   thorpej /*
    122   1.1   thorpej  * Pop a prefix off the prefix stack.
    123   1.1   thorpej  */
    124   1.1   thorpej void
    125   1.1   thorpej prefix_pop(void)
    126   1.1   thorpej {
    127  1.20  uebayasi 	prefixlist_pop(&allprefixes, &prefixes);
    128  1.20  uebayasi }
    129   1.1   thorpej 
    130  1.20  uebayasi /*
    131  1.20  uebayasi  * Push a buildprefix onto the buildprefix stack.
    132  1.20  uebayasi  */
    133  1.20  uebayasi void
    134  1.20  uebayasi buildprefix_push(const char *path)
    135  1.20  uebayasi {
    136  1.20  uebayasi 	prefixlist_push(&buildprefixes, path);
    137  1.20  uebayasi }
    138   1.1   thorpej 
    139  1.20  uebayasi /*
    140  1.20  uebayasi  * Pop a buildprefix off the buildprefix stack.
    141  1.20  uebayasi  */
    142  1.20  uebayasi void
    143  1.20  uebayasi buildprefix_pop(void)
    144  1.20  uebayasi {
    145  1.20  uebayasi 	prefixlist_pop(&allbuildprefixes, &buildprefixes);
    146   1.1   thorpej }
    147   1.1   thorpej 
    148   1.1   thorpej /*
    149   1.1   thorpej  * Prepend the source path to a file name.
    150   1.1   thorpej  */
    151   1.1   thorpej char *
    152   1.1   thorpej sourcepath(const char *file)
    153   1.1   thorpej {
    154   1.1   thorpej 	size_t len;
    155   1.1   thorpej 	char *cp;
    156   1.1   thorpej 	struct prefix *pf;
    157   1.1   thorpej 
    158   1.1   thorpej 	pf = SLIST_EMPTY(&prefixes) ? NULL : SLIST_FIRST(&prefixes);
    159   1.1   thorpej 	if (pf != NULL && *pf->pf_prefix == '/')
    160   1.1   thorpej 		len = strlen(pf->pf_prefix) + 1 + strlen(file) + 1;
    161   1.1   thorpej 	else {
    162   1.1   thorpej 		len = strlen(srcdir) + 1 + strlen(file) + 1;
    163   1.1   thorpej 		if (pf != NULL)
    164   1.1   thorpej 			len += strlen(pf->pf_prefix) + 1;
    165   1.1   thorpej 	}
    166   1.1   thorpej 
    167   1.1   thorpej 	cp = emalloc(len);
    168   1.1   thorpej 
    169   1.1   thorpej 	if (pf != NULL) {
    170   1.1   thorpej 		if (*pf->pf_prefix == '/')
    171   1.1   thorpej 			(void) sprintf(cp, "%s/%s", pf->pf_prefix, file);
    172   1.1   thorpej 		else
    173   1.1   thorpej 			(void) sprintf(cp, "%s/%s/%s", srcdir,
    174   1.1   thorpej 			    pf->pf_prefix, file);
    175   1.1   thorpej 	} else
    176   1.1   thorpej 		(void) sprintf(cp, "%s/%s", srcdir, file);
    177   1.1   thorpej 	return (cp);
    178   1.1   thorpej }
    179   1.1   thorpej 
    180  1.12  dholland /************************************************************/
    181  1.12  dholland 
    182  1.12  dholland /*
    183  1.12  dholland  * Data structures
    184  1.12  dholland  */
    185  1.12  dholland 
    186  1.12  dholland /*
    187  1.12  dholland  * nvlist
    188  1.12  dholland  */
    189  1.12  dholland 
    190   1.1   thorpej struct nvlist *
    191   1.8  christos newnv(const char *name, const char *str, void *ptr, long long i, struct nvlist *next)
    192   1.1   thorpej {
    193   1.1   thorpej 	struct nvlist *nv;
    194   1.1   thorpej 
    195   1.4       dsl 	nv = ecalloc(1, sizeof(*nv));
    196   1.1   thorpej 	nv->nv_next = next;
    197   1.1   thorpej 	nv->nv_name = name;
    198   1.4       dsl 	nv->nv_str = str;
    199   1.4       dsl 	nv->nv_ptr = ptr;
    200   1.8  christos 	nv->nv_num = i;
    201   1.4       dsl 	return nv;
    202   1.1   thorpej }
    203   1.1   thorpej 
    204   1.1   thorpej /*
    205   1.1   thorpej  * Free an nvlist structure (just one).
    206   1.1   thorpej  */
    207   1.1   thorpej void
    208   1.1   thorpej nvfree(struct nvlist *nv)
    209   1.1   thorpej {
    210   1.1   thorpej 
    211   1.4       dsl 	free(nv);
    212   1.1   thorpej }
    213   1.1   thorpej 
    214   1.1   thorpej /*
    215   1.1   thorpej  * Free an nvlist (the whole list).
    216   1.1   thorpej  */
    217   1.1   thorpej void
    218   1.1   thorpej nvfreel(struct nvlist *nv)
    219   1.1   thorpej {
    220   1.1   thorpej 	struct nvlist *next;
    221   1.1   thorpej 
    222   1.1   thorpej 	for (; nv != NULL; nv = next) {
    223   1.1   thorpej 		next = nv->nv_next;
    224   1.4       dsl 		free(nv);
    225   1.1   thorpej 	}
    226   1.1   thorpej }
    227   1.1   thorpej 
    228   1.5      cube struct nvlist *
    229   1.5      cube nvcat(struct nvlist *nv1, struct nvlist *nv2)
    230   1.5      cube {
    231   1.5      cube 	struct nvlist *nv;
    232   1.5      cube 
    233   1.5      cube 	if (nv1 == NULL)
    234   1.5      cube 		return nv2;
    235   1.5      cube 
    236   1.5      cube 	for (nv = nv1; nv->nv_next != NULL; nv = nv->nv_next);
    237   1.5      cube 
    238   1.5      cube 	nv->nv_next = nv2;
    239   1.5      cube 	return nv1;
    240   1.5      cube }
    241   1.5      cube 
    242  1.12  dholland /*
    243  1.14  dholland  * Option definition lists
    244  1.14  dholland  */
    245  1.14  dholland 
    246  1.14  dholland struct defoptlist *
    247  1.14  dholland defoptlist_create(const char *name, const char *val, const char *lintval)
    248  1.14  dholland {
    249  1.14  dholland 	struct defoptlist *dl;
    250  1.14  dholland 
    251  1.14  dholland 	dl = emalloc(sizeof(*dl));
    252  1.14  dholland 	dl->dl_next = NULL;
    253  1.14  dholland 	dl->dl_name = name;
    254  1.14  dholland 	dl->dl_value = val;
    255  1.14  dholland 	dl->dl_lintvalue = lintval;
    256  1.14  dholland 	dl->dl_obsolete = 0;
    257  1.14  dholland 	dl->dl_depends = NULL;
    258  1.14  dholland 	return dl;
    259  1.14  dholland }
    260  1.14  dholland 
    261  1.14  dholland void
    262  1.14  dholland defoptlist_destroy(struct defoptlist *dl)
    263  1.14  dholland {
    264  1.14  dholland 	struct defoptlist *next;
    265  1.14  dholland 
    266  1.14  dholland 	while (dl != NULL) {
    267  1.14  dholland 		next = dl->dl_next;
    268  1.14  dholland 		dl->dl_next = NULL;
    269  1.14  dholland 
    270  1.14  dholland 		// XXX should we assert that dl->dl_deps is null to
    271  1.14  dholland 		// be sure the deps have already been destroyed?
    272  1.14  dholland 		free(dl);
    273  1.14  dholland 
    274  1.14  dholland 		dl = next;
    275  1.14  dholland 	}
    276  1.14  dholland }
    277  1.14  dholland 
    278  1.14  dholland struct defoptlist *
    279  1.14  dholland defoptlist_append(struct defoptlist *dla, struct defoptlist *dlb)
    280  1.14  dholland {
    281  1.14  dholland 	struct defoptlist *dl;
    282  1.14  dholland 
    283  1.14  dholland 	if (dla == NULL)
    284  1.14  dholland 		return dlb;
    285  1.14  dholland 
    286  1.14  dholland 	for (dl = dla; dl->dl_next != NULL; dl = dl->dl_next)
    287  1.14  dholland 		;
    288  1.14  dholland 
    289  1.14  dholland 	dl->dl_next = dlb;
    290  1.14  dholland 	return dla;
    291  1.14  dholland }
    292  1.14  dholland 
    293  1.14  dholland /*
    294  1.13  dholland  * Locator lists
    295  1.13  dholland  */
    296  1.13  dholland 
    297  1.13  dholland struct loclist *
    298  1.13  dholland loclist_create(const char *name, const char *string, long long num)
    299  1.13  dholland {
    300  1.13  dholland 	struct loclist *ll;
    301  1.13  dholland 
    302  1.13  dholland 	ll = emalloc(sizeof(*ll));
    303  1.13  dholland 	ll->ll_name = name;
    304  1.13  dholland 	ll->ll_string = string;
    305  1.13  dholland 	ll->ll_num = num;
    306  1.13  dholland 	ll->ll_next = NULL;
    307  1.13  dholland 	return ll;
    308  1.13  dholland }
    309  1.13  dholland 
    310  1.13  dholland void
    311  1.13  dholland loclist_destroy(struct loclist *ll)
    312  1.13  dholland {
    313  1.13  dholland 	struct loclist *next;
    314  1.13  dholland 
    315  1.13  dholland 	while (ll != NULL) {
    316  1.13  dholland 		next = ll->ll_next;
    317  1.13  dholland 		ll->ll_next = NULL;
    318  1.13  dholland 		free(ll);
    319  1.13  dholland 		ll = next;
    320  1.13  dholland 	}
    321  1.13  dholland }
    322  1.13  dholland 
    323  1.13  dholland /*
    324  1.12  dholland  * Attribute lists
    325  1.12  dholland  */
    326  1.12  dholland 
    327  1.10  dholland struct attrlist *
    328  1.10  dholland attrlist_create(void)
    329  1.10  dholland {
    330  1.10  dholland 	struct attrlist *al;
    331  1.10  dholland 
    332  1.10  dholland 	al = emalloc(sizeof(*al));
    333  1.10  dholland 	al->al_next = NULL;
    334  1.10  dholland 	al->al_this = NULL;
    335  1.10  dholland 	return al;
    336  1.10  dholland }
    337  1.10  dholland 
    338  1.10  dholland struct attrlist *
    339  1.10  dholland attrlist_cons(struct attrlist *next, struct attr *a)
    340  1.10  dholland {
    341  1.10  dholland 	struct attrlist *al;
    342  1.10  dholland 
    343  1.10  dholland 	al = attrlist_create();
    344  1.10  dholland 	al->al_next = next;
    345  1.10  dholland 	al->al_this = a;
    346  1.10  dholland 	return al;
    347  1.10  dholland }
    348  1.10  dholland 
    349  1.10  dholland void
    350  1.10  dholland attrlist_destroy(struct attrlist *al)
    351  1.10  dholland {
    352  1.10  dholland 	assert(al->al_next == NULL);
    353  1.10  dholland 	assert(al->al_this == NULL);
    354  1.10  dholland 	free(al);
    355  1.10  dholland }
    356  1.10  dholland 
    357  1.10  dholland void
    358  1.10  dholland attrlist_destroyall(struct attrlist *al)
    359  1.10  dholland {
    360  1.10  dholland 	struct attrlist *next;
    361  1.10  dholland 
    362  1.10  dholland 	while (al != NULL) {
    363  1.10  dholland 		next = al->al_next;
    364  1.10  dholland 		al->al_next = NULL;
    365  1.10  dholland 		/* XXX should we make the caller guarantee this? */
    366  1.10  dholland 		al->al_this = NULL;
    367  1.10  dholland 		attrlist_destroy(al);
    368  1.10  dholland 		al = next;
    369  1.10  dholland 	}
    370  1.10  dholland }
    371  1.10  dholland 
    372  1.11  dholland /*
    373  1.12  dholland  * Condition expressions
    374  1.12  dholland  */
    375  1.12  dholland 
    376  1.12  dholland /*
    377  1.11  dholland  * Create an expression node.
    378  1.11  dholland  */
    379  1.11  dholland struct condexpr *
    380  1.11  dholland condexpr_create(enum condexpr_types type)
    381  1.11  dholland {
    382  1.11  dholland 	struct condexpr *cx;
    383  1.11  dholland 
    384  1.11  dholland 	cx = emalloc(sizeof(*cx));
    385  1.11  dholland 	cx->cx_type = type;
    386  1.11  dholland 	switch (type) {
    387  1.11  dholland 
    388  1.11  dholland 	    case CX_ATOM:
    389  1.11  dholland 		cx->cx_atom = NULL;
    390  1.11  dholland 		break;
    391  1.11  dholland 
    392  1.11  dholland 	    case CX_NOT:
    393  1.11  dholland 		cx->cx_not = NULL;
    394  1.11  dholland 		break;
    395  1.11  dholland 
    396  1.11  dholland 	    case CX_AND:
    397  1.11  dholland 		cx->cx_and.left = NULL;
    398  1.11  dholland 		cx->cx_and.right = NULL;
    399  1.11  dholland 		break;
    400  1.11  dholland 
    401  1.11  dholland 	    case CX_OR:
    402  1.11  dholland 		cx->cx_or.left = NULL;
    403  1.11  dholland 		cx->cx_or.right = NULL;
    404  1.11  dholland 		break;
    405  1.11  dholland 
    406  1.11  dholland 	    default:
    407  1.11  dholland 		panic("condexpr_create: invalid expr type %d", (int)type);
    408  1.11  dholland 	}
    409  1.11  dholland 	return cx;
    410  1.11  dholland }
    411  1.11  dholland 
    412  1.11  dholland /*
    413  1.11  dholland  * Free an expression tree.
    414  1.11  dholland  */
    415  1.11  dholland void
    416  1.11  dholland condexpr_destroy(struct condexpr *expr)
    417  1.11  dholland {
    418  1.11  dholland 	switch (expr->cx_type) {
    419  1.11  dholland 
    420  1.11  dholland 	    case CX_ATOM:
    421  1.11  dholland 		/* nothing */
    422  1.11  dholland 		break;
    423  1.11  dholland 
    424  1.11  dholland 	    case CX_NOT:
    425  1.11  dholland 		condexpr_destroy(expr->cx_not);
    426  1.11  dholland 		break;
    427  1.11  dholland 
    428  1.11  dholland 	    case CX_AND:
    429  1.11  dholland 		condexpr_destroy(expr->cx_and.left);
    430  1.11  dholland 		condexpr_destroy(expr->cx_and.right);
    431  1.11  dholland 		break;
    432  1.11  dholland 
    433  1.11  dholland 	    case CX_OR:
    434  1.11  dholland 		condexpr_destroy(expr->cx_or.left);
    435  1.11  dholland 		condexpr_destroy(expr->cx_or.right);
    436  1.11  dholland 		break;
    437  1.11  dholland 
    438  1.11  dholland 	    default:
    439  1.11  dholland 		panic("condexpr_destroy: invalid expr type %d",
    440  1.11  dholland 		      (int)expr->cx_type);
    441  1.11  dholland 	}
    442  1.11  dholland 	free(expr);
    443  1.11  dholland }
    444  1.11  dholland 
    445  1.12  dholland /************************************************************/
    446  1.12  dholland 
    447  1.12  dholland /*
    448  1.12  dholland  * Diagnostic messages
    449  1.12  dholland  */
    450  1.12  dholland 
    451  1.17  uebayasi void
    452  1.17  uebayasi cfgdbg(const char *fmt, ...)
    453  1.17  uebayasi {
    454  1.17  uebayasi 	va_list ap;
    455  1.17  uebayasi 	extern const char *yyfile;
    456  1.17  uebayasi 
    457  1.17  uebayasi 	va_start(ap, fmt);
    458  1.17  uebayasi 	cfgvxdbg(yyfile, currentline(), fmt, ap);
    459  1.17  uebayasi 	va_end(ap);
    460  1.17  uebayasi }
    461  1.17  uebayasi 
    462   1.1   thorpej void
    463   1.6  christos cfgwarn(const char *fmt, ...)
    464   1.1   thorpej {
    465   1.1   thorpej 	va_list ap;
    466   1.1   thorpej 	extern const char *yyfile;
    467   1.1   thorpej 
    468   1.1   thorpej 	va_start(ap, fmt);
    469   1.6  christos 	cfgvxwarn(yyfile, currentline(), fmt, ap);
    470   1.1   thorpej 	va_end(ap);
    471   1.1   thorpej }
    472   1.1   thorpej 
    473   1.2      cube void
    474   1.6  christos cfgxwarn(const char *file, int line, const char *fmt, ...)
    475   1.2      cube {
    476   1.2      cube 	va_list ap;
    477   1.2      cube 
    478   1.2      cube 	va_start(ap, fmt);
    479   1.6  christos 	cfgvxwarn(file, line, fmt, ap);
    480   1.2      cube 	va_end(ap);
    481   1.2      cube }
    482   1.1   thorpej 
    483  1.17  uebayasi static void
    484  1.17  uebayasi cfgvxdbg(const char *file, int line, const char *fmt, va_list ap)
    485  1.17  uebayasi {
    486  1.17  uebayasi 	cfgvxmsg(file, line, "debug: ", fmt, ap);
    487  1.17  uebayasi }
    488  1.17  uebayasi 
    489   1.1   thorpej static void
    490   1.6  christos cfgvxwarn(const char *file, int line, const char *fmt, va_list ap)
    491   1.1   thorpej {
    492   1.6  christos 	cfgvxmsg(file, line, "warning: ", fmt, ap);
    493   1.1   thorpej }
    494   1.1   thorpej 
    495   1.1   thorpej /*
    496   1.1   thorpej  * External (config file) error.  Complain, using current file
    497   1.1   thorpej  * and line number.
    498   1.1   thorpej  */
    499   1.1   thorpej void
    500   1.6  christos cfgerror(const char *fmt, ...)
    501   1.1   thorpej {
    502   1.1   thorpej 	va_list ap;
    503   1.1   thorpej 	extern const char *yyfile;
    504   1.1   thorpej 
    505   1.1   thorpej 	va_start(ap, fmt);
    506   1.6  christos 	cfgvxerror(yyfile, currentline(), fmt, ap);
    507   1.1   thorpej 	va_end(ap);
    508   1.1   thorpej }
    509   1.1   thorpej 
    510   1.1   thorpej /*
    511   1.1   thorpej  * Delayed config file error (i.e., something was wrong but we could not
    512   1.1   thorpej  * find out about it until later).
    513   1.1   thorpej  */
    514   1.1   thorpej void
    515   1.6  christos cfgxerror(const char *file, int line, const char *fmt, ...)
    516   1.1   thorpej {
    517   1.1   thorpej 	va_list ap;
    518   1.1   thorpej 
    519   1.1   thorpej 	va_start(ap, fmt);
    520   1.6  christos 	cfgvxerror(file, line, fmt, ap);
    521   1.1   thorpej 	va_end(ap);
    522   1.1   thorpej }
    523   1.1   thorpej 
    524   1.1   thorpej /*
    525   1.1   thorpej  * Internal form of error() and xerror().
    526   1.1   thorpej  */
    527   1.1   thorpej static void
    528   1.6  christos cfgvxerror(const char *file, int line, const char *fmt, va_list ap)
    529   1.1   thorpej {
    530   1.6  christos 	cfgvxmsg(file, line, "", fmt, ap);
    531   1.1   thorpej 	errors++;
    532   1.1   thorpej }
    533   1.1   thorpej 
    534   1.1   thorpej 
    535   1.1   thorpej /*
    536   1.1   thorpej  * Internal error, abort.
    537   1.1   thorpej  */
    538   1.1   thorpej __dead void
    539   1.1   thorpej panic(const char *fmt, ...)
    540   1.1   thorpej {
    541   1.1   thorpej 	va_list ap;
    542   1.1   thorpej 
    543   1.1   thorpej 	va_start(ap, fmt);
    544   1.6  christos 	(void)fprintf(stderr, "%s: panic: ", getprogname());
    545   1.1   thorpej 	(void)vfprintf(stderr, fmt, ap);
    546   1.1   thorpej 	(void)putc('\n', stderr);
    547   1.1   thorpej 	va_end(ap);
    548   1.1   thorpej 	exit(2);
    549   1.1   thorpej }
    550   1.1   thorpej 
    551   1.1   thorpej /*
    552   1.1   thorpej  * Internal form of error() and xerror().
    553   1.1   thorpej  */
    554   1.1   thorpej static void
    555   1.6  christos cfgvxmsg(const char *file, int line, const char *msgclass, const char *fmt,
    556   1.1   thorpej       va_list ap)
    557   1.1   thorpej {
    558   1.1   thorpej 
    559  1.16  christos 	(void)fprintf(stderr, "%s:%d: %s", file, line, msgclass);
    560   1.1   thorpej 	(void)vfprintf(stderr, fmt, ap);
    561   1.1   thorpej 	(void)putc('\n', stderr);
    562   1.1   thorpej }
    563   1.7     lukem 
    564   1.7     lukem void
    565   1.7     lukem autogen_comment(FILE *fp, const char *targetfile)
    566   1.7     lukem {
    567   1.7     lukem 
    568   1.7     lukem 	(void)fprintf(fp,
    569   1.7     lukem 	    "/*\n"
    570   1.7     lukem 	    " * MACHINE GENERATED: DO NOT EDIT\n"
    571   1.7     lukem 	    " *\n"
    572   1.7     lukem 	    " * %s, from \"%s\"\n"
    573   1.7     lukem 	    " */\n\n",
    574   1.7     lukem 	    targetfile, conffile);
    575   1.7     lukem }
    576