191586Smarkm/*	$NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $	*/
212099Sjoerg
312099Sjoerg/*
412099Sjoerg * Copyright (c) 1994, 1995 Jochen Pohl
512099Sjoerg * All Rights Reserved.
612099Sjoerg *
712099Sjoerg * Redistribution and use in source and binary forms, with or without
812099Sjoerg * modification, are permitted provided that the following conditions
912099Sjoerg * are met:
1012099Sjoerg * 1. Redistributions of source code must retain the above copyright
1112099Sjoerg *    notice, this list of conditions and the following disclaimer.
1212099Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1312099Sjoerg *    notice, this list of conditions and the following disclaimer in the
1412099Sjoerg *    documentation and/or other materials provided with the distribution.
1512099Sjoerg * 3. All advertising materials mentioning features or use of this software
1612099Sjoerg *    must display the following acknowledgement:
1712099Sjoerg *      This product includes software developed by Jochen Pohl for
1812099Sjoerg *	The NetBSD Project.
1912099Sjoerg * 4. The name of the author may not be used to endorse or promote products
2012099Sjoerg *    derived from this software without specific prior written permission.
2112099Sjoerg *
2212099Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2312099Sjoerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2412099Sjoerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2512099Sjoerg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2612099Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2712099Sjoerg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2812099Sjoerg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2912099Sjoerg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3012099Sjoerg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3112099Sjoerg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3212099Sjoerg */
3312099Sjoerg
3491586Smarkm#include <sys/cdefs.h>
35223262Sbenl__FBSDID("$FreeBSD$");
3691586Smarkm#if defined(__RCSID) && !defined(lint)
3791586Smarkm__RCSID("$NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
3812099Sjoerg#endif
3912099Sjoerg
4012099Sjoerg#include <stdio.h>
4112099Sjoerg#include <stdarg.h>
4291586Smarkm#include <string.h>
4312099Sjoerg
4412099Sjoerg#include "lint2.h"
4512099Sjoerg
4612099Sjoergstatic	const	char *msgs[] = {
4712099Sjoerg	"%s used( %s ), but not defined",			      /* 0 */
4812099Sjoerg	"%s defined( %s ), but never used",			      /* 1 */
4912099Sjoerg	"%s declared( %s ), but never used or defined",		      /* 2 */
5012099Sjoerg	"%s multiply defined  \t%s  ::  %s",			      /* 3 */
5112099Sjoerg	"%s value used inconsistently  \t%s  ::  %s",		      /* 4 */
5212099Sjoerg	"%s value declared inconsistently  \t%s  ::  %s",	      /* 5 */
5312099Sjoerg	"%s, arg %d used inconsistently  \t%s  ::  %s",		      /* 6 */
5412099Sjoerg	"%s: variable # of args  \t%s  ::  %s",			      /* 7 */
5512099Sjoerg	"%s returns value which is always ignored",		      /* 8 */
5612099Sjoerg	"%s returns value which is sometimes ignored",		      /* 9 */
5712099Sjoerg	"%s value is used( %s ), but none returned",		      /* 10 */
5812099Sjoerg	"%s, arg %d declared inconsistently  \t%s :: %s",	      /* 11 */
5912099Sjoerg	"%s: variable # of args declared  \t%s  ::  %s",	      /* 12 */
6012099Sjoerg	"%s: malformed format string  \t%s",			      /* 13 */
6112099Sjoerg	"%s, arg %d inconsistent with format  \t%s",		      /* 14 */
6212099Sjoerg	"%s: too few args for format  \t%s",			      /* 15 */
6312099Sjoerg	"%s: too many args for format  \t%s",			      /* 16 */
6412099Sjoerg	"%s function value must be declared before use  \t%s  ::  %s",/* 17 */
6591586Smarkm	"%s renamed multiple times  \t%s  ::  %s",		      /* 18 */
6612099Sjoerg};
6712099Sjoerg
6891586Smarkmstatic	const	char *lbasename(const char *);
6912099Sjoerg
7012099Sjoergvoid
7112099Sjoergmsg(int n, ...)
7212099Sjoerg{
7312099Sjoerg	va_list	ap;
7412099Sjoerg
7512099Sjoerg	va_start(ap, n);
7612099Sjoerg
7712099Sjoerg	(void)vprintf(msgs[n], ap);
7812099Sjoerg	(void)printf("\n");
7912099Sjoerg
8012099Sjoerg	va_end(ap);
8112099Sjoerg}
8212099Sjoerg
8312099Sjoerg/*
8412099Sjoerg * Return a pointer to the last component of a path.
8512099Sjoerg */
8612099Sjoergstatic const char *
8791586Smarkmlbasename(const char *path)
8812099Sjoerg{
8912099Sjoerg	const	char *cp, *cp1, *cp2;
9012099Sjoerg
9112099Sjoerg	if (Fflag)
9212099Sjoerg		return (path);
9312099Sjoerg
9412099Sjoerg	cp = cp1 = cp2 = path;
9512099Sjoerg	while (*cp != '\0') {
9612099Sjoerg		if (*cp++ == '/') {
9712099Sjoerg			cp2 = cp1;
9812099Sjoerg			cp1 = cp;
9912099Sjoerg		}
10012099Sjoerg	}
10112099Sjoerg	return (*cp1 == '\0' ? cp2 : cp1);
10212099Sjoerg}
10312099Sjoerg
10412099Sjoerg/*
10512099Sjoerg * Create a string which describes a position in a source file.
10612099Sjoerg */
10712099Sjoergconst char *
10891586Smarkmmkpos(pos_t *posp)
10912099Sjoerg{
11012099Sjoerg	size_t	len;
11112099Sjoerg	const	char *fn;
11212099Sjoerg	static	char	*buf;
11312099Sjoerg	static	size_t	blen = 0;
11412099Sjoerg	int	qm, src, line;
11512099Sjoerg
11612099Sjoerg	if (Hflag && posp->p_src != posp->p_isrc) {
11712099Sjoerg		src = posp->p_isrc;
11812099Sjoerg		line = posp->p_iline;
11912099Sjoerg	} else {
12012099Sjoerg		src = posp->p_src;
12112099Sjoerg		line = posp->p_line;
12212099Sjoerg	}
12312099Sjoerg	qm = !Hflag && posp->p_src != posp->p_isrc;
12412099Sjoerg
12591586Smarkm	len = strlen(fn = lbasename(fnames[src]));
12612099Sjoerg	len += 3 * sizeof (u_short) + 4;
12712099Sjoerg
12812099Sjoerg	if (len > blen)
12912099Sjoerg		buf = xrealloc(buf, blen = len);
13012099Sjoerg	if (line != 0) {
131223262Sbenl		(void)sprintf(buf, "%s%s(%d)",
13212099Sjoerg			      fn, qm ? "?" : "", line);
13312099Sjoerg	} else {
13412099Sjoerg		(void)sprintf(buf, "%s", fn);
13512099Sjoerg	}
13612099Sjoerg
13712099Sjoerg	return (buf);
13812099Sjoerg}
139