Module Name: src Committed By: rillig Date: Sun Feb 19 19:27:02 UTC 2023
Modified Files: src/usr.bin/xlint/lint1: err.c src/usr.bin/xlint/lint2: msg.c src/usr.bin/xlint/xlint: xlint.c Log Message: lint: make basename simpler There is no need to handle trailing slashes since lint only handles regular files in diagnostics, not directories. Furthermore, only the last '/' was ignored, but multiple trailing slashes would not. To generate a diff of this commit: cvs rdiff -u -r1.187 -r1.188 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint2/msg.c cvs rdiff -u -r1.108 -r1.109 src/usr.bin/xlint/xlint/xlint.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.187 src/usr.bin/xlint/lint1/err.c:1.188 --- src/usr.bin/xlint/lint1/err.c:1.187 Sat Feb 18 15:21:34 2023 +++ src/usr.bin/xlint/lint1/err.c Sun Feb 19 19:27:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.187 2023/02/18 15:21:34 rillig Exp $ */ +/* $NetBSD: err.c,v 1.188 2023/02/19 19:27:01 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.187 2023/02/18 15:21:34 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.188 2023/02/19 19:27:01 rillig Exp $"); #endif #include <limits.h> @@ -498,19 +498,15 @@ msglist(void) static const char * lbasename(const char *path) { - const char *p, *base, *dir; if (Fflag) return path; - p = base = dir = path; - while (*p != '\0') { - if (*p++ == '/') { - dir = base; - base = p; - } - } - return *base != '\0' ? base : dir; + const char *base = path; + for (const char *p = path; *p != '\0'; p++) + if (*p == '/') + base = p + 1; + return base; } static void Index: src/usr.bin/xlint/lint2/msg.c diff -u src/usr.bin/xlint/lint2/msg.c:1.18 src/usr.bin/xlint/lint2/msg.c:1.19 --- src/usr.bin/xlint/lint2/msg.c:1.18 Thu Feb 2 22:23:30 2023 +++ src/usr.bin/xlint/lint2/msg.c Sun Feb 19 19:27:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: msg.c,v 1.18 2023/02/02 22:23:30 rillig Exp $ */ +/* $NetBSD: msg.c,v 1.19 2023/02/19 19:27:01 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: msg.c,v 1.18 2023/02/02 22:23:30 rillig Exp $"); +__RCSID("$NetBSD: msg.c,v 1.19 2023/02/19 19:27:01 rillig Exp $"); #endif #include <stdarg.h> @@ -87,19 +87,15 @@ msg(int n, ...) static const char * lbasename(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 *base = path; + for (const char *p = path; *p != '\0'; p++) + if (*p == '/') + base = p + 1; + return base; } /* Index: src/usr.bin/xlint/xlint/xlint.c diff -u src/usr.bin/xlint/xlint/xlint.c:1.108 src/usr.bin/xlint/xlint/xlint.c:1.109 --- src/usr.bin/xlint/xlint/xlint.c:1.108 Sun Jan 22 15:20:01 2023 +++ src/usr.bin/xlint/xlint/xlint.c Sun Feb 19 19:27:02 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: xlint.c,v 1.108 2023/01/22 15:20:01 rillig Exp $ */ +/* $NetBSD: xlint.c,v 1.109 2023/02/19 19:27:02 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: xlint.c,v 1.108 2023/01/22 15:20:01 rillig Exp $"); +__RCSID("$NetBSD: xlint.c,v 1.109 2023/02/19 19:27:02 rillig Exp $"); #endif #include <sys/param.h> @@ -227,18 +227,17 @@ terminate(int signo) } /* - * Returns a pointer to the last component of strg after delim. - * Returns strg if the string does not contain delim. + * Returns a pointer to the last component of path after delim. + * Returns path if the string does not contain delim. */ static const char * -lbasename(const char *strg, int delim) +lbasename(const char *path, int delim) { - const char *base = strg; - for (const char *p = strg; *p != '\0'; p++) { - if (p[0] == delim && p[1] != '\0') + const char *base = path; + for (const char *p = path; *p != '\0'; p++) + if (*p == delim) base = p + 1; - } return base; }