From 684e810ae2de35dd2761bc28149280a249810d5b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 27 Oct 2023 17:15:08 -0700 Subject: [PATCH 03/11] maint: move field_sep into separate module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is so that we don’t need to have every source file include ctype.h. * bootstrap.conf (gnulib_modules): Add cu-ctype. * gl/lib/cu-ctype.c, gl/lib/cu-ctype.h, gl/modules/cu-ctype: New files. * src/join.c, src/numfmt.c, src/sort.c, src/uniq.c: Include cu-ctype.h, for field_sep. * src/system.h (field_sep): Remove; now supplied by cu-ctype. --- bootstrap.conf | 1 + gl/lib/cu-ctype.c | 3 +++ gl/lib/cu-ctype.h | 35 +++++++++++++++++++++++++++++++++++ gl/modules/cu-ctype | 24 ++++++++++++++++++++++++ src/join.c | 1 + src/numfmt.c | 1 + src/sort.c | 1 + src/system.h | 7 ------- src/uniq.c | 1 + 9 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 gl/lib/cu-ctype.c create mode 100644 gl/lib/cu-ctype.h create mode 100644 gl/modules/cu-ctype diff --git a/bootstrap.conf b/bootstrap.conf index db0c90c67..4724544d7 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -70,6 +70,7 @@ gnulib_modules=" crypto/sha256 crypto/sha512 crypto/sm3 + cu-ctype cycle-check d-ino d-type diff --git a/gl/lib/cu-ctype.c b/gl/lib/cu-ctype.c new file mode 100644 index 000000000..9f753de2e --- /dev/null +++ b/gl/lib/cu-ctype.c @@ -0,0 +1,3 @@ +#include +#define CU_CTYPE_INLINE _GL_EXTERN_INLINE +#include diff --git a/gl/lib/cu-ctype.h b/gl/lib/cu-ctype.h new file mode 100644 index 000000000..82f1d73f2 --- /dev/null +++ b/gl/lib/cu-ctype.h @@ -0,0 +1,35 @@ +/* Character type definitions for coreutils + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#ifndef _GL_INLINE_HEADER_BEGIN +# error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef CU_CTYPE_INLINE +# define CU_CTYPE_INLINE _GL_INLINE +#endif + +/* '\n' is considered a field separator with --zero-terminated. */ +CU_CTYPE_INLINE bool +field_sep (unsigned char ch) +{ + return isblank (ch) || ch == '\n'; +} + +_GL_INLINE_HEADER_END diff --git a/gl/modules/cu-ctype b/gl/modules/cu-ctype new file mode 100644 index 000000000..bd328b32e --- /dev/null +++ b/gl/modules/cu-ctype @@ -0,0 +1,24 @@ +Description: +ctype.h-like definitions for coreutils + +Files: +lib/cu-ctype.c +lib/cu-ctype.h + +Depends-on: +ctype +extern-inline + +configure.ac: + +Makefile.am: +lib_SOURCES += cu-ctype.c + +Include: +"cu-ctype.h" + +License: +GPL + +Maintainer: +all diff --git a/src/join.c b/src/join.c index 7eef58c0b..b95cf2b9b 100644 --- a/src/join.c +++ b/src/join.c @@ -23,6 +23,7 @@ #include "system.h" #include "assure.h" +#include "cu-ctype.h" #include "fadvise.h" #include "hard-locale.h" #include "linebuffer.h" diff --git a/src/numfmt.c b/src/numfmt.c index 8fd6e77ad..2ce70226c 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -24,6 +24,7 @@ #include "argmatch.h" #include "c-ctype.h" +#include "cu-ctype.h" #include "mbswidth.h" #include "quote.h" #include "system.h" diff --git a/src/sort.c b/src/sort.c index 5c86b8332..6856e6151 100644 --- a/src/sort.c +++ b/src/sort.c @@ -31,6 +31,7 @@ #include "system.h" #include "argmatch.h" #include "assure.h" +#include "cu-ctype.h" #include "fadvise.h" #include "filevercmp.h" #include "flexmember.h" diff --git a/src/system.h b/src/system.h index 21b15839b..b4e0a7275 100644 --- a/src/system.h +++ b/src/system.h @@ -158,13 +158,6 @@ enum errors that the cast doesn't. */ static inline unsigned char to_uchar (char ch) { return ch; } -/* '\n' is considered a field separator with --zero-terminated. */ -static inline bool -field_sep (unsigned char ch) -{ - return isblank (ch) || ch == '\n'; -} - #include /* Take care of NLS matters. */ diff --git a/src/uniq.c b/src/uniq.c index d294ed665..7e177ac5a 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -23,6 +23,7 @@ #include "system.h" #include "argmatch.h" +#include "cu-ctype.h" #include "linebuffer.h" #include "fadvise.h" #include "posixver.h" -- 2.39.2