#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: msg.c,v 1.4 1998/02/22 15:40:41 christos Exp $");
#endif
#include <string.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "lint2.h"
static const char *msgs[] = {
"%s used( %s ), but not defined",
"%s defined( %s ), but never used",
"%s declared( %s ), but never used or defined",
"%s multiply defined \t%s :: %s",
"%s value used inconsistently \t%s :: %s",
"%s value declared inconsistently \t%s :: %s",
"%s, arg %d used inconsistently \t%s :: %s",
"%s: variable # of args \t%s :: %s",
"%s returns value which is always ignored",
"%s returns value which is sometimes ignored",
"%s value is used( %s ), but none returned",
"%s, arg %d declared inconsistently \t%s :: %s",
"%s: variable # of args declared \t%s :: %s",
"%s: malformed format string \t%s",
"%s, arg %d inconsistent with format \t%s",
"%s: too few args for format \t%s",
"%s: too many args for format \t%s",
"%s function value must be declared before use \t%s :: %s",
"%s renamed multiple times \t%s :: %s",
};
static const char *basename __P((const char *));
#ifdef __STDC__
void
msg(int n, ...)
{
#else
void
msg(va_alist)
va_dcl
int n;
{
#endif
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
n = va_arg(ap, int);
#endif
(void)vprintf(msgs[n], ap);
(void)printf("\n");
va_end(ap);
}
static const char *
basename(path)
const char *path;
{
const char *cp, *cp1, *cp2;
if (Fflag)
return (path);
cp = cp1 = cp2 = path;
while (*cp != '\0') {
if (*cp++ == '/') {
cp2 = cp1;
cp1 = cp;
}
}
return (*cp1 == '\0' ? cp2 : cp1);
}
const char *
mkpos(posp)
pos_t *posp;
{
size_t len;
const char *fn;
static char *buf;
static size_t blen = 0;
int qm, src, line;
if (Hflag && posp->p_src != posp->p_isrc) {
src = posp->p_isrc;
line = posp->p_iline;
} else {
src = posp->p_src;
line = posp->p_line;
}
qm = !Hflag && posp->p_src != posp->p_isrc;
len = strlen(fn = basename(fnames[src]));
len += 3 * sizeof (u_short) + 4;
if (len > blen)
buf = xrealloc(buf, blen = len);
if (line != 0) {
(void)sprintf(buf, "%s%s(%hu)",
fn, qm ? "?" : "", line);
} else {
(void)sprintf(buf, "%s", fn);
}
return (buf);
}