| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: err.c,v 1.114 2021/04/18 10:02:16 rillig Exp $ */ | | 1 | /* $NetBSD: err.c,v 1.115 2021/04/18 10:09:49 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994, 1995 Jochen Pohl | | 4 | * Copyright (c) 1994, 1995 Jochen Pohl |
5 | * All Rights Reserved. | | 5 | * All Rights Reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 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 | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 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 | | 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. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #if HAVE_NBTOOL_CONFIG_H | | 34 | #if HAVE_NBTOOL_CONFIG_H |
35 | #include "nbtool_config.h" | | 35 | #include "nbtool_config.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | #if defined(__RCSID) && !defined(lint) | | 39 | #if defined(__RCSID) && !defined(lint) |
40 | __RCSID("$NetBSD: err.c,v 1.114 2021/04/18 10:02:16 rillig Exp $"); | | 40 | __RCSID("$NetBSD: err.c,v 1.115 2021/04/18 10:09:49 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <sys/types.h> | | 43 | #include <sys/types.h> |
44 | #include <stdarg.h> | | 44 | #include <stdarg.h> |
45 | #include <stdlib.h> | | 45 | #include <stdlib.h> |
46 | | | 46 | |
47 | #include "lint1.h" | | 47 | #include "lint1.h" |
48 | | | 48 | |
49 | /* number of errors found */ | | 49 | /* number of errors found */ |
50 | int nerr; | | 50 | int nerr; |
51 | | | 51 | |
52 | /* number of syntax errors */ | | 52 | /* number of syntax errors */ |
53 | int sytxerr; | | 53 | int sytxerr; |
| @@ -474,97 +474,97 @@ lbasename(const char *path) | | | @@ -474,97 +474,97 @@ lbasename(const char *path) |
474 | return path; | | 474 | return path; |
475 | | | 475 | |
476 | p = base = dir = path; | | 476 | p = base = dir = path; |
477 | while (*p != '\0') { | | 477 | while (*p != '\0') { |
478 | if (*p++ == '/') { | | 478 | if (*p++ == '/') { |
479 | dir = base; | | 479 | dir = base; |
480 | base = p; | | 480 | base = p; |
481 | } | | 481 | } |
482 | } | | 482 | } |
483 | return *base != '\0' ? base : dir; | | 483 | return *base != '\0' ? base : dir; |
484 | } | | 484 | } |
485 | | | 485 | |
486 | static void | | 486 | static void |
487 | verror_at(int n, pos_t pos, va_list ap) | | 487 | verror_at(int msgid, pos_t pos, va_list ap) |
488 | { | | 488 | { |
489 | const char *fn; | | 489 | const char *fn; |
490 | | | 490 | |
491 | if (ERR_ISSET(n, &msgset)) | | 491 | if (ERR_ISSET(msgid, &msgset)) |
492 | return; | | 492 | return; |
493 | | | 493 | |
494 | fn = lbasename(pos.p_file); | | 494 | fn = lbasename(pos.p_file); |
495 | (void)printf("%s(%d): error: ", fn, pos.p_line); | | 495 | (void)printf("%s(%d): error: ", fn, pos.p_line); |
496 | (void)vprintf(msgs[n], ap); | | 496 | (void)vprintf(msgs[msgid], ap); |
497 | (void)printf(" [%d]\n", n); | | 497 | (void)printf(" [%d]\n", msgid); |
498 | nerr++; | | 498 | nerr++; |
499 | print_stack_trace(); | | 499 | print_stack_trace(); |
500 | } | | 500 | } |
501 | | | 501 | |
502 | static void | | 502 | static void |
503 | vwarning_at(int n, pos_t pos, va_list ap) | | 503 | vwarning_at(int msgid, pos_t pos, va_list ap) |
504 | { | | 504 | { |
505 | const char *fn; | | 505 | const char *fn; |
506 | | | 506 | |
507 | if (ERR_ISSET(n, &msgset)) | | 507 | if (ERR_ISSET(msgid, &msgset)) |
508 | return; | | 508 | return; |
509 | | | 509 | |
510 | #ifdef DEBUG | | 510 | #ifdef DEBUG |
511 | printf("%s: lwarn=%d n=%d\n", __func__, lwarn, n); | | 511 | printf("%s: lwarn=%d msgid=%d\n", __func__, lwarn, msgid); |
512 | #endif | | 512 | #endif |
513 | if (lwarn == LWARN_NONE || lwarn == n) | | 513 | if (lwarn == LWARN_NONE || lwarn == msgid) |
514 | /* this warning is suppressed by a LINTED comment */ | | 514 | /* this warning is suppressed by a LINTED comment */ |
515 | return; | | 515 | return; |
516 | | | 516 | |
517 | fn = lbasename(pos.p_file); | | 517 | fn = lbasename(pos.p_file); |
518 | (void)printf("%s(%d): warning: ", fn, pos.p_line); | | 518 | (void)printf("%s(%d): warning: ", fn, pos.p_line); |
519 | (void)vprintf(msgs[n], ap); | | 519 | (void)vprintf(msgs[msgid], ap); |
520 | (void)printf(" [%d]\n", n); | | 520 | (void)printf(" [%d]\n", msgid); |
521 | if (wflag) | | 521 | if (wflag) |
522 | nerr++; | | 522 | nerr++; |
523 | print_stack_trace(); | | 523 | print_stack_trace(); |
524 | } | | 524 | } |
525 | | | 525 | |
526 | static void | | 526 | static void |
527 | vmessage_at(int n, pos_t pos, va_list ap) | | 527 | vmessage_at(int msgid, pos_t pos, va_list ap) |
528 | { | | 528 | { |
529 | const char *fn; | | 529 | const char *fn; |
530 | | | 530 | |
531 | if (ERR_ISSET(n, &msgset)) | | 531 | if (ERR_ISSET(msgid, &msgset)) |
532 | return; | | 532 | return; |
533 | | | 533 | |
534 | fn = lbasename(pos.p_file); | | 534 | fn = lbasename(pos.p_file); |
535 | (void)printf("%s(%d): ", fn, pos.p_line); | | 535 | (void)printf("%s(%d): ", fn, pos.p_line); |
536 | (void)vprintf(msgs[n], ap); | | 536 | (void)vprintf(msgs[msgid], ap); |
537 | (void)printf(" [%d]\n", n); | | 537 | (void)printf(" [%d]\n", msgid); |
538 | print_stack_trace(); | | 538 | print_stack_trace(); |
539 | } | | 539 | } |
540 | | | 540 | |
541 | void | | 541 | void |
542 | (error_at)(int n, pos_t pos, ...) | | 542 | (error_at)(int msgid, pos_t pos, ...) |
543 | { | | 543 | { |
544 | va_list ap; | | 544 | va_list ap; |
545 | | | 545 | |
546 | va_start(ap, pos); | | 546 | va_start(ap, pos); |
547 | verror_at(n, pos, ap); | | 547 | verror_at(msgid, pos, ap); |
548 | va_end(ap); | | 548 | va_end(ap); |
549 | } | | 549 | } |
550 | | | 550 | |
551 | void | | 551 | void |
552 | (error)(int n, ...) | | 552 | (error)(int msgid, ...) |
553 | { | | 553 | { |
554 | va_list ap; | | 554 | va_list ap; |
555 | | | 555 | |
556 | va_start(ap, n); | | 556 | va_start(ap, msgid); |
557 | verror_at(n, curr_pos, ap); | | 557 | verror_at(msgid, curr_pos, ap); |
558 | va_end(ap); | | 558 | va_end(ap); |
559 | } | | 559 | } |
560 | | | 560 | |
561 | void | | 561 | void |
562 | internal_error(const char *file, int line, const char *msg, ...) | | 562 | internal_error(const char *file, int line, const char *msg, ...) |
563 | { | | 563 | { |
564 | va_list ap; | | 564 | va_list ap; |
565 | const char *fn; | | 565 | const char *fn; |
566 | | | 566 | |
567 | fn = lbasename(curr_pos.p_file); | | 567 | fn = lbasename(curr_pos.p_file); |
568 | (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ", | | 568 | (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ", |
569 | file, line, fn, curr_pos.p_line); | | 569 | file, line, fn, curr_pos.p_line); |
570 | va_start(ap, msg); | | 570 | va_start(ap, msg); |
| @@ -579,98 +579,98 @@ void | | | @@ -579,98 +579,98 @@ void |
579 | assert_failed(const char *file, int line, const char *func, const char *cond) | | 579 | assert_failed(const char *file, int line, const char *func, const char *cond) |
580 | { | | 580 | { |
581 | const char *fn; | | 581 | const char *fn; |
582 | | | 582 | |
583 | fn = lbasename(curr_pos.p_file); | | 583 | fn = lbasename(curr_pos.p_file); |
584 | (void)fprintf(stderr, | | 584 | (void)fprintf(stderr, |
585 | "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n", | | 585 | "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n", |
586 | cond, func, file, line, fn, curr_pos.p_line); | | 586 | cond, func, file, line, fn, curr_pos.p_line); |
587 | print_stack_trace(); | | 587 | print_stack_trace(); |
588 | abort(); | | 588 | abort(); |
589 | } | | 589 | } |
590 | | | 590 | |
591 | void | | 591 | void |
592 | (warning_at)(int n, pos_t pos, ...) | | 592 | (warning_at)(int msgid, pos_t pos, ...) |
593 | { | | 593 | { |
594 | va_list ap; | | 594 | va_list ap; |
595 | | | 595 | |
596 | va_start(ap, pos); | | 596 | va_start(ap, pos); |
597 | vwarning_at(n, pos, ap); | | 597 | vwarning_at(msgid, pos, ap); |
598 | va_end(ap); | | 598 | va_end(ap); |
599 | } | | 599 | } |
600 | | | 600 | |
601 | void | | 601 | void |
602 | (warning)(int n, ...) | | 602 | (warning)(int msgid, ...) |
603 | { | | 603 | { |
604 | va_list ap; | | 604 | va_list ap; |
605 | | | 605 | |
606 | va_start(ap, n); | | 606 | va_start(ap, msgid); |
607 | vwarning_at(n, curr_pos, ap); | | 607 | vwarning_at(msgid, curr_pos, ap); |
608 | va_end(ap); | | 608 | va_end(ap); |
609 | } | | 609 | } |
610 | | | 610 | |
611 | void | | 611 | void |
612 | (message_at)(int n, pos_t pos, ...) | | 612 | (message_at)(int msgid, pos_t pos, ...) |
613 | { | | 613 | { |
614 | va_list ap; | | 614 | va_list ap; |
615 | | | 615 | |
616 | va_start(ap, pos); | | 616 | va_start(ap, pos); |
617 | vmessage_at(n, pos, ap); | | 617 | vmessage_at(msgid, pos, ap); |
618 | va_end(ap); | | 618 | va_end(ap); |
619 | } | | 619 | } |
620 | | | 620 | |
621 | void | | 621 | void |
622 | (message)(int n, ...) | | 622 | (message)(int msgid, ...) |
623 | { | | 623 | { |
624 | va_list ap; | | 624 | va_list ap; |
625 | | | 625 | |
626 | va_start(ap, n); | | 626 | va_start(ap, msgid); |
627 | vmessage_at(n, curr_pos, ap); | | 627 | vmessage_at(msgid, curr_pos, ap); |
628 | va_end(ap); | | 628 | va_end(ap); |
629 | } | | 629 | } |
630 | | | 630 | |
631 | /* | | 631 | /* |
632 | * XXX I think the logic is possibly somewhat screwed up here. The | | 632 | * XXX I think the logic is possibly somewhat screwed up here. The |
633 | * question is, how do we want to interpret the -s and -S flags going | | 633 | * question is, how do we want to interpret the -s and -S flags going |
634 | * forward? We need to answer that and then we can fix this to be | | 634 | * forward? We need to answer that and then we can fix this to be |
635 | * "right"... [perry, 2 Nov 2002] | | 635 | * "right"... [perry, 2 Nov 2002] |
636 | */ | | 636 | */ |
637 | void | | 637 | void |
638 | (c99ism)(int n, ...) | | 638 | (c99ism)(int msgid, ...) |
639 | { | | 639 | { |
640 | va_list ap; | | 640 | va_list ap; |
641 | bool extensions_ok = Sflag || gflag; | | 641 | bool extensions_ok = Sflag || gflag; |
642 | | | 642 | |
643 | va_start(ap, n); | | 643 | va_start(ap, msgid); |
644 | if (sflag && !extensions_ok) { | | 644 | if (sflag && !extensions_ok) { |
645 | verror_at(n, curr_pos, ap); | | 645 | verror_at(msgid, curr_pos, ap); |
646 | } else if (sflag || !extensions_ok) { | | 646 | } else if (sflag || !extensions_ok) { |
647 | vwarning_at(n, curr_pos, ap); | | 647 | vwarning_at(msgid, curr_pos, ap); |
648 | } | | 648 | } |
649 | va_end(ap); | | 649 | va_end(ap); |
650 | } | | 650 | } |
651 | | | 651 | |
652 | void | | 652 | void |
653 | (c11ism)(int n, ...) | | 653 | (c11ism)(int msgid, ...) |
654 | { | | 654 | { |
655 | va_list ap; | | 655 | va_list ap; |
656 | | | 656 | |
657 | if (c11flag || gflag) | | 657 | if (c11flag || gflag) |
658 | return; | | 658 | return; |
659 | va_start(ap, n); | | 659 | va_start(ap, msgid); |
660 | verror_at(n, curr_pos, ap); | | 660 | verror_at(msgid, curr_pos, ap); |
661 | va_end(ap); | | 661 | va_end(ap); |
662 | } | | 662 | } |
663 | | | 663 | |
664 | void | | 664 | void |
665 | (gnuism)(int n, ...) | | 665 | (gnuism)(int msgid, ...) |
666 | { | | 666 | { |
667 | va_list ap; | | 667 | va_list ap; |
668 | | | 668 | |
669 | va_start(ap, n); | | 669 | va_start(ap, msgid); |
670 | if (sflag && !gflag) { | | 670 | if (sflag && !gflag) { |
671 | verror_at(n, curr_pos, ap); | | 671 | verror_at(msgid, curr_pos, ap); |
672 | } else if (sflag || !gflag) { | | 672 | } else if (sflag || !gflag) { |
673 | vwarning_at(n, curr_pos, ap); | | 673 | vwarning_at(msgid, curr_pos, ap); |
674 | } | | 674 | } |
675 | va_end(ap); | | 675 | va_end(ap); |
676 | } | | 676 | } |