Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint lint: make basename simpler
details: https://anonhg.NetBSD.org/src/rev/872c01402b5e
branches: trunk
changeset: 373590:872c01402b5e
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Feb 19 19:27:01 2023 +0000
description:
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.
diffstat:
usr.bin/xlint/lint1/err.c | 18 +++++++-----------
usr.bin/xlint/lint2/msg.c | 18 +++++++-----------
usr.bin/xlint/xlint/xlint.c | 17 ++++++++---------
3 files changed, 22 insertions(+), 31 deletions(-)
diffs (129 lines):
diff -r 47c8de9403e8 -r 872c01402b5e usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Feb 19 18:09:45 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Feb 19 19:27:01 2023 +0000
@@ -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 @@
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
diff -r 47c8de9403e8 -r 872c01402b5e usr.bin/xlint/lint2/msg.c
--- a/usr.bin/xlint/lint2/msg.c Sun Feb 19 18:09:45 2023 +0000
+++ b/usr.bin/xlint/lint2/msg.c Sun Feb 19 19:27:01 2023 +0000
@@ -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 @@
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;
}
/*
diff -r 47c8de9403e8 -r 872c01402b5e usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c Sun Feb 19 18:09:45 2023 +0000
+++ b/usr.bin/xlint/xlint/xlint.c Sun Feb 19 19:27:01 2023 +0000
@@ -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 @@
}
/*
- * 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;
}
Home |
Main Index |
Thread Index |
Old Index