Home | History | Annotate | Line # | Download | only in lint2
msg.c revision 1.2.4.1
      1  1.2.4.1  thorpej /*	$NetBSD: msg.c,v 1.2.4.1 1997/11/04 21:42:49 thorpej Exp $	*/
      2      1.2      cgd 
      3      1.1      cgd /*
      4      1.1      cgd  * Copyright (c) 1994, 1995 Jochen Pohl
      5      1.1      cgd  * 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 Jochen Pohl for
     18      1.1      cgd  *	The NetBSD Project.
     19      1.1      cgd  * 4. The name of the author may not be used to endorse or promote products
     20      1.1      cgd  *    derived from this software without specific prior written permission.
     21      1.1      cgd  *
     22      1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.1      cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.1      cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.1      cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.1      cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.1      cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.1      cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.1      cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.1      cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.1      cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.1      cgd  */
     33      1.1      cgd 
     34      1.1      cgd #ifndef lint
     35  1.2.4.1  thorpej static char rcsid[] = "$NetBSD: msg.c,v 1.2.4.1 1997/11/04 21:42:49 thorpej Exp $";
     36      1.1      cgd #endif
     37      1.1      cgd 
     38      1.1      cgd #include <string.h>
     39      1.1      cgd 
     40      1.1      cgd #include <stdio.h>
     41      1.1      cgd #ifdef __STDC__
     42      1.1      cgd #include <stdarg.h>
     43      1.1      cgd #else
     44      1.1      cgd #include <varargs.h>
     45      1.1      cgd #endif
     46      1.1      cgd 
     47      1.1      cgd #include "lint2.h"
     48      1.1      cgd 
     49      1.1      cgd 
     50      1.1      cgd static	const	char *msgs[] = {
     51      1.1      cgd 	"%s used( %s ), but not defined",			      /* 0 */
     52      1.1      cgd 	"%s defined( %s ), but never used",			      /* 1 */
     53      1.1      cgd 	"%s declared( %s ), but never used or defined",		      /* 2 */
     54      1.1      cgd 	"%s multiply defined  \t%s  ::  %s",			      /* 3 */
     55      1.1      cgd 	"%s value used inconsistently  \t%s  ::  %s",		      /* 4 */
     56      1.1      cgd 	"%s value declared inconsistently  \t%s  ::  %s",	      /* 5 */
     57      1.1      cgd 	"%s, arg %d used inconsistently  \t%s  ::  %s",		      /* 6 */
     58      1.1      cgd 	"%s: variable # of args  \t%s  ::  %s",			      /* 7 */
     59      1.1      cgd 	"%s returns value which is always ignored",		      /* 8 */
     60      1.1      cgd 	"%s returns value which is sometimes ignored",		      /* 9 */
     61      1.1      cgd 	"%s value is used( %s ), but none returned",		      /* 10 */
     62      1.1      cgd 	"%s, arg %d declared inconsistently  \t%s :: %s",	      /* 11 */
     63      1.1      cgd 	"%s: variable # of args declared  \t%s  ::  %s",	      /* 12 */
     64      1.1      cgd 	"%s: malformed format string  \t%s",			      /* 13 */
     65      1.1      cgd 	"%s, arg %d inconsistent with format  \t%s",		      /* 14 */
     66      1.1      cgd 	"%s: too few args for format  \t%s",			      /* 15 */
     67      1.1      cgd 	"%s: too many args for format  \t%s",			      /* 16 */
     68      1.1      cgd 	"%s function value must be declared before use  \t%s  ::  %s",/* 17 */
     69  1.2.4.1  thorpej 	"%s renamed multiple times  \t%s  ::  %s",		      /* 18 */
     70      1.1      cgd };
     71      1.1      cgd 
     72      1.1      cgd static	const	char *basename __P((const char *));
     73      1.1      cgd 
     74      1.1      cgd #ifdef __STDC__
     75      1.1      cgd void
     76      1.1      cgd msg(int n, ...)
     77      1.1      cgd {
     78      1.1      cgd #else
     79      1.1      cgd void
     80      1.1      cgd msg(va_alist)
     81      1.1      cgd 	va_dcl
     82      1.1      cgd 	int	n;
     83      1.1      cgd {
     84      1.1      cgd #endif
     85      1.1      cgd 	va_list	ap;
     86      1.1      cgd 
     87      1.1      cgd #ifdef __STDC__
     88      1.1      cgd 	va_start(ap, n);
     89      1.1      cgd #else
     90      1.1      cgd 	va_start(ap);
     91      1.1      cgd 	n = va_arg(ap, int);
     92      1.1      cgd #endif
     93      1.1      cgd 
     94      1.1      cgd 	(void)vprintf(msgs[n], ap);
     95      1.1      cgd 	(void)printf("\n");
     96      1.1      cgd 
     97      1.1      cgd 	va_end(ap);
     98      1.1      cgd }
     99      1.1      cgd 
    100      1.1      cgd /*
    101      1.1      cgd  * Return a pointer to the last component of a path.
    102      1.1      cgd  */
    103      1.1      cgd static const char *
    104      1.1      cgd basename(path)
    105      1.1      cgd 	const	char *path;
    106      1.1      cgd {
    107      1.1      cgd 	const	char *cp, *cp1, *cp2;
    108      1.1      cgd 
    109      1.1      cgd 	if (Fflag)
    110      1.1      cgd 		return (path);
    111      1.1      cgd 
    112      1.1      cgd 	cp = cp1 = cp2 = path;
    113      1.1      cgd 	while (*cp != '\0') {
    114      1.1      cgd 		if (*cp++ == '/') {
    115      1.1      cgd 			cp2 = cp1;
    116      1.1      cgd 			cp1 = cp;
    117      1.1      cgd 		}
    118      1.1      cgd 	}
    119      1.1      cgd 	return (*cp1 == '\0' ? cp2 : cp1);
    120      1.1      cgd }
    121      1.1      cgd 
    122      1.1      cgd /*
    123      1.1      cgd  * Create a string which describes a position in a source file.
    124      1.1      cgd  */
    125      1.1      cgd const char *
    126      1.1      cgd mkpos(posp)
    127      1.1      cgd 	pos_t	*posp;
    128      1.1      cgd {
    129      1.1      cgd 	size_t	len;
    130      1.1      cgd 	const	char *fn;
    131      1.1      cgd 	static	char	*buf;
    132      1.1      cgd 	static	size_t	blen = 0;
    133      1.1      cgd 	int	qm, src, line;
    134      1.1      cgd 
    135      1.1      cgd 	if (Hflag && posp->p_src != posp->p_isrc) {
    136      1.1      cgd 		src = posp->p_isrc;
    137      1.1      cgd 		line = posp->p_iline;
    138      1.1      cgd 	} else {
    139      1.1      cgd 		src = posp->p_src;
    140      1.1      cgd 		line = posp->p_line;
    141      1.1      cgd 	}
    142      1.1      cgd 	qm = !Hflag && posp->p_src != posp->p_isrc;
    143      1.1      cgd 
    144      1.1      cgd 	len = strlen(fn = basename(fnames[src]));
    145      1.1      cgd 	len += 3 * sizeof (u_short) + 4;
    146      1.1      cgd 
    147      1.1      cgd 	if (len > blen)
    148      1.1      cgd 		buf = xrealloc(buf, blen = len);
    149      1.1      cgd 	if (line != 0) {
    150      1.1      cgd 		(void)sprintf(buf, "%s%s(%hu)",
    151      1.1      cgd 			      fn, qm ? "?" : "", line);
    152      1.1      cgd 	} else {
    153      1.1      cgd 		(void)sprintf(buf, "%s", fn);
    154      1.1      cgd 	}
    155      1.1      cgd 
    156      1.1      cgd 	return (buf);
    157      1.1      cgd }
    158      1.1      cgd 
    159