msg.c revision 12099
112099Sjoerg/* $NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd 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 3412099Sjoerg#ifndef lint 3512099Sjoergstatic char rcsid[] = "$NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd Exp $"; 3612099Sjoerg#endif 3712099Sjoerg 3812099Sjoerg#include <string.h> 3912099Sjoerg 4012099Sjoerg#include <stdio.h> 4112099Sjoerg#ifdef __STDC__ 4212099Sjoerg#include <stdarg.h> 4312099Sjoerg#else 4412099Sjoerg#include <varargs.h> 4512099Sjoerg#endif 4612099Sjoerg 4712099Sjoerg#include "lint2.h" 4812099Sjoerg 4912099Sjoerg 5012099Sjoergstatic const char *msgs[] = { 5112099Sjoerg "%s used( %s ), but not defined", /* 0 */ 5212099Sjoerg "%s defined( %s ), but never used", /* 1 */ 5312099Sjoerg "%s declared( %s ), but never used or defined", /* 2 */ 5412099Sjoerg "%s multiply defined \t%s :: %s", /* 3 */ 5512099Sjoerg "%s value used inconsistently \t%s :: %s", /* 4 */ 5612099Sjoerg "%s value declared inconsistently \t%s :: %s", /* 5 */ 5712099Sjoerg "%s, arg %d used inconsistently \t%s :: %s", /* 6 */ 5812099Sjoerg "%s: variable # of args \t%s :: %s", /* 7 */ 5912099Sjoerg "%s returns value which is always ignored", /* 8 */ 6012099Sjoerg "%s returns value which is sometimes ignored", /* 9 */ 6112099Sjoerg "%s value is used( %s ), but none returned", /* 10 */ 6212099Sjoerg "%s, arg %d declared inconsistently \t%s :: %s", /* 11 */ 6312099Sjoerg "%s: variable # of args declared \t%s :: %s", /* 12 */ 6412099Sjoerg "%s: malformed format string \t%s", /* 13 */ 6512099Sjoerg "%s, arg %d inconsistent with format \t%s", /* 14 */ 6612099Sjoerg "%s: too few args for format \t%s", /* 15 */ 6712099Sjoerg "%s: too many args for format \t%s", /* 16 */ 6812099Sjoerg "%s function value must be declared before use \t%s :: %s",/* 17 */ 6912099Sjoerg}; 7012099Sjoerg 7112099Sjoergstatic const char *basename __P((const char *)); 7212099Sjoerg 7312099Sjoerg#ifdef __STDC__ 7412099Sjoergvoid 7512099Sjoergmsg(int n, ...) 7612099Sjoerg{ 7712099Sjoerg#else 7812099Sjoergvoid 7912099Sjoergmsg(va_alist) 8012099Sjoerg va_dcl 8112099Sjoerg int n; 8212099Sjoerg{ 8312099Sjoerg#endif 8412099Sjoerg va_list ap; 8512099Sjoerg 8612099Sjoerg#ifdef __STDC__ 8712099Sjoerg va_start(ap, n); 8812099Sjoerg#else 8912099Sjoerg va_start(ap); 9012099Sjoerg n = va_arg(ap, int); 9112099Sjoerg#endif 9212099Sjoerg 9312099Sjoerg (void)vprintf(msgs[n], ap); 9412099Sjoerg (void)printf("\n"); 9512099Sjoerg 9612099Sjoerg va_end(ap); 9712099Sjoerg} 9812099Sjoerg 9912099Sjoerg/* 10012099Sjoerg * Return a pointer to the last component of a path. 10112099Sjoerg */ 10212099Sjoergstatic const char * 10312099Sjoergbasename(path) 10412099Sjoerg const char *path; 10512099Sjoerg{ 10612099Sjoerg const char *cp, *cp1, *cp2; 10712099Sjoerg 10812099Sjoerg if (Fflag) 10912099Sjoerg return (path); 11012099Sjoerg 11112099Sjoerg cp = cp1 = cp2 = path; 11212099Sjoerg while (*cp != '\0') { 11312099Sjoerg if (*cp++ == '/') { 11412099Sjoerg cp2 = cp1; 11512099Sjoerg cp1 = cp; 11612099Sjoerg } 11712099Sjoerg } 11812099Sjoerg return (*cp1 == '\0' ? cp2 : cp1); 11912099Sjoerg} 12012099Sjoerg 12112099Sjoerg/* 12212099Sjoerg * Create a string which describes a position in a source file. 12312099Sjoerg */ 12412099Sjoergconst char * 12512099Sjoergmkpos(posp) 12612099Sjoerg pos_t *posp; 12712099Sjoerg{ 12812099Sjoerg size_t len; 12912099Sjoerg const char *fn; 13012099Sjoerg static char *buf; 13112099Sjoerg static size_t blen = 0; 13212099Sjoerg int qm, src, line; 13312099Sjoerg 13412099Sjoerg if (Hflag && posp->p_src != posp->p_isrc) { 13512099Sjoerg src = posp->p_isrc; 13612099Sjoerg line = posp->p_iline; 13712099Sjoerg } else { 13812099Sjoerg src = posp->p_src; 13912099Sjoerg line = posp->p_line; 14012099Sjoerg } 14112099Sjoerg qm = !Hflag && posp->p_src != posp->p_isrc; 14212099Sjoerg 14312099Sjoerg len = strlen(fn = basename(fnames[src])); 14412099Sjoerg len += 3 * sizeof (u_short) + 4; 14512099Sjoerg 14612099Sjoerg if (len > blen) 14712099Sjoerg buf = xrealloc(buf, blen = len); 14812099Sjoerg if (line != 0) { 14912099Sjoerg (void)sprintf(buf, "%s%s(%hu)", 15012099Sjoerg fn, qm ? "?" : "", line); 15112099Sjoerg } else { 15212099Sjoerg (void)sprintf(buf, "%s", fn); 15312099Sjoerg } 15412099Sjoerg 15512099Sjoerg return (buf); 15612099Sjoerg} 15712099Sjoerg 158