Deleted Added
full compact
err.c (75831) err.c (91592)
1/* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */
1/* $NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $ */
2
3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 16 unchanged lines hidden (view full) ---

26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
2
3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 16 unchanged lines hidden (view full) ---

26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef lint
35static const char rcsid[] =
36 "$FreeBSD: head/usr.bin/xlint/lint1/err.c 75831 2001-04-22 17:06:12Z asmodai $";
34#include <sys/cdefs.h>
35#if defined(__RCSID) && !defined(lint)
36__RCSID("$NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $");
37#endif
37#endif
38__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/err.c 91592 2002-03-03 15:12:50Z markm $");
38
39
40#include <sys/types.h>
41#include <stdlib.h>
42#include <stdarg.h>
43
44#include "lint1.h"
45
39/* number of errors found */
40int nerr;
41
42/* number of syntax errors */
43int sytxerr;
44
46/* number of errors found */
47int nerr;
48
49/* number of syntax errors */
50int sytxerr;
51
45#include <stdlib.h>
46#ifdef __STDC__
47#include <stdarg.h>
48#else
49#include <varargs.h>
50#endif
51
52
52#include "lint1.h"
53static const char *basename(const char *);
54static void verror(int, va_list);
55static void vwarning(int, va_list);
53
56
54static const char *basename __P((const char *));
55static void verror __P((int, va_list));
56static void vwarning __P((int, va_list));
57
57
58
59const char *msgs[] = {
60 "syntax error: empty declaration", /* 0 */
61 "old style declaration; add int", /* 1 */
62 "empty declaration", /* 2 */
63 "%s declared in argument declaration list", /* 3 */
64 "illegal type combination", /* 4 */
65 "modifying typedef with '%s'; only qualifiers allowed", /* 5 */
66 "use 'double' instead of 'long float'", /* 6 */

--- 295 unchanged lines hidden (view full) ---

362 "%s returns pointer to automatic object", /* 302 */
363 "ANSI C forbids conversion of %s to %s", /* 303 */
364 "ANSI C forbids conversion of %s to %s, arg #%d", /* 304 */
365 "ANSI C forbids conversion of %s to %s, op %s", /* 305 */
366 "constant truncated by conversion, op %s", /* 306 */
367 "static variable %s set but not used", /* 307 */
368 "", /* 308 */
369 "extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */
58const char *msgs[] = {
59 "syntax error: empty declaration", /* 0 */
60 "old style declaration; add int", /* 1 */
61 "empty declaration", /* 2 */
62 "%s declared in argument declaration list", /* 3 */
63 "illegal type combination", /* 4 */
64 "modifying typedef with '%s'; only qualifiers allowed", /* 5 */
65 "use 'double' instead of 'long float'", /* 6 */

--- 295 unchanged lines hidden (view full) ---

361 "%s returns pointer to automatic object", /* 302 */
362 "ANSI C forbids conversion of %s to %s", /* 303 */
363 "ANSI C forbids conversion of %s to %s, arg #%d", /* 304 */
364 "ANSI C forbids conversion of %s to %s, op %s", /* 305 */
365 "constant truncated by conversion, op %s", /* 306 */
366 "static variable %s set but not used", /* 307 */
367 "", /* 308 */
368 "extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */
369 "symbol renaming can't be used on function arguments", /* 310 */
370 "symbol renaming can't be used on automatic variables", /* 311 */
371 "%s C does not support // comments", /* 312 */
370};
371
372/*
372};
373
374/*
375 * print a list of the messages with their ids
376 */
377void
378msglist(void)
379{
380 int i;
381
382 for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
383 printf("%d\t%s\n", i, msgs[i]);
384}
385
386/*
373 * If Fflag is not set basename() returns a pointer to the last
374 * component of the path, otherwise it returns the argument.
375 */
376static const char *
387 * If Fflag is not set basename() returns a pointer to the last
388 * component of the path, otherwise it returns the argument.
389 */
390static const char *
377basename(path)
378 const char *path;
391basename(const char *path)
379{
380 const char *cp, *cp1, *cp2;
381
382 if (Fflag)
383 return (path);
384
385 cp = cp1 = cp2 = path;
386 while (*cp != '\0') {
387 if (*cp++ == '/') {
388 cp2 = cp1;
389 cp1 = cp;
390 }
391 }
392 return (*cp1 == '\0' ? cp2 : cp1);
393}
394
395static void
392{
393 const char *cp, *cp1, *cp2;
394
395 if (Fflag)
396 return (path);
397
398 cp = cp1 = cp2 = path;
399 while (*cp != '\0') {
400 if (*cp++ == '/') {
401 cp2 = cp1;
402 cp1 = cp;
403 }
404 }
405 return (*cp1 == '\0' ? cp2 : cp1);
406}
407
408static void
396verror(n, ap)
397 int n;
398 va_list ap;
409verror( int n, va_list ap)
399{
400 const char *fn;
401
410{
411 const char *fn;
412
413 if (ERR_ISSET(n, &msgset))
414 return;
415
402 fn = basename(curr_pos.p_file);
403 (void)printf("%s:%d: ", fn, curr_pos.p_line);
404 (void)vprintf(msgs[n], ap);
416 fn = basename(curr_pos.p_file);
417 (void)printf("%s:%d: ", fn, curr_pos.p_line);
418 (void)vprintf(msgs[n], ap);
405 (void)printf("\n");
419 (void)printf(" [%d]\n", n);
406 nerr++;
407}
408
409static void
420 nerr++;
421}
422
423static void
410vwarning(n, ap)
411 int n;
412 va_list ap;
424vwarning( int n, va_list ap)
413{
414 const char *fn;
415
425{
426 const char *fn;
427
428 if (ERR_ISSET(n, &msgset))
429 return;
430
416 if (nowarn)
417 /* this warning is suppressed by a LINTED comment */
418 return;
419
420 fn = basename(curr_pos.p_file);
421 (void)printf("%s:%d: warning: ", fn, curr_pos.p_line);
422 (void)vprintf(msgs[n], ap);
431 if (nowarn)
432 /* this warning is suppressed by a LINTED comment */
433 return;
434
435 fn = basename(curr_pos.p_file);
436 (void)printf("%s:%d: warning: ", fn, curr_pos.p_line);
437 (void)vprintf(msgs[n], ap);
423 (void)printf("\n");
438 (void)printf(" [%d]\n", n);
439 if (wflag)
440 nerr++;
424}
425
426void
441}
442
443void
427#ifdef __STDC__
428error(int n, ...)
444error(int n, ...)
429#else
430error(n, va_alist)
431 int n;
432 va_dcl
433#endif
434{
435 va_list ap;
436
445{
446 va_list ap;
447
437#ifdef __STDC__
438 va_start(ap, n);
448 va_start(ap, n);
439#else
440 va_start(ap);
441#endif
442 verror(n, ap);
443 va_end(ap);
444}
445
446void
449 verror(n, ap);
450 va_end(ap);
451}
452
453void
447#ifdef __STDC__
448lerror(const char *msg, ...)
454lerror(const char *msg, ...)
449#else
450lerror(msg, va_alist)
451 const char *msg;
452 va_dcl
453#endif
454{
455 va_list ap;
456 const char *fn;
457
455{
456 va_list ap;
457 const char *fn;
458
458#ifdef __STDC__
459 va_start(ap, msg);
459 va_start(ap, msg);
460#else
461 va_start(ap);
462#endif
463 fn = basename(curr_pos.p_file);
464 (void)fprintf(stderr, "%s:%d: lint error: ", fn, curr_pos.p_line);
465 (void)vfprintf(stderr, msg, ap);
466 (void)fprintf(stderr, "\n");
467 va_end(ap);
468 exit(1);
469}
470
471void
460 fn = basename(curr_pos.p_file);
461 (void)fprintf(stderr, "%s:%d: lint error: ", fn, curr_pos.p_line);
462 (void)vfprintf(stderr, msg, ap);
463 (void)fprintf(stderr, "\n");
464 va_end(ap);
465 exit(1);
466}
467
468void
472#ifdef __STDC__
473warning(int n, ...)
469warning(int n, ...)
474#else
475warning(n, va_alist)
476 int n;
477 va_dcl
478#endif
479{
480 va_list ap;
481
470{
471 va_list ap;
472
482#ifdef __STDC__
483 va_start(ap, n);
473 va_start(ap, n);
484#else
485 va_start(ap);
486#endif
487 vwarning(n, ap);
488 va_end(ap);
489}
490
491void
474 vwarning(n, ap);
475 va_end(ap);
476}
477
478void
492#ifdef __STDC__
493message(int n, ...)
479message(int n, ...)
494#else
495message(n, va_alist)
496 int n;
497 va_dcl
498#endif
499{
500 va_list ap;
501 const char *fn;
502
480{
481 va_list ap;
482 const char *fn;
483
503#ifdef __STDC__
484 if (ERR_ISSET(n, &msgset))
485 return;
486
504 va_start(ap, n);
487 va_start(ap, n);
505#else
506 va_start(ap);
507#endif
508 fn = basename(curr_pos.p_file);
509 (void)printf("%s:%d: ", fn, curr_pos.p_line);
510 (void)vprintf(msgs[n], ap);
488 fn = basename(curr_pos.p_file);
489 (void)printf("%s:%d: ", fn, curr_pos.p_line);
490 (void)vprintf(msgs[n], ap);
511 (void)printf("\n");
491 (void)printf(" [%d]\n", n);
512 va_end(ap);
513}
514
515int
492 va_end(ap);
493}
494
495int
516#ifdef __STDC__
517gnuism(int n, ...)
496gnuism(int n, ...)
518#else
519gnuism(n, va_alist)
520 int n;
521 va_dcl
522#endif
523{
524 va_list ap;
525 int msg;
526
497{
498 va_list ap;
499 int msg;
500
527#ifdef __STDC__
528 va_start(ap, n);
501 va_start(ap, n);
529#else
530 va_start(ap);
531#endif
532 if (sflag && !gflag) {
533 verror(n, ap);
534 msg = 1;
535 } else if (!sflag && gflag) {
536 msg = 0;
537 } else {
538 vwarning(n, ap);
539 msg = 1;
540 }
541 va_end(ap);
542
543 return (msg);
544}
502 if (sflag && !gflag) {
503 verror(n, ap);
504 msg = 1;
505 } else if (!sflag && gflag) {
506 msg = 0;
507 } else {
508 vwarning(n, ap);
509 msg = 1;
510 }
511 va_end(ap);
512
513 return (msg);
514}