>From 62fd69a3d3a547cc3579484571b2abcb2fcd668a Mon Sep 17 00:00:00 2001 From: Bruce Korb Date: Sun, 15 Apr 2012 12:08:53 -0700 Subject: [PATCH] fmt: use generated char classifications * lib/fmt-class.map: file describing the character classes used by fmt. * lib/fmt.c: use fmt-class.h in preference to roll-your-own * src/Makefile.am: add rule to derive fmt-class.h from fmt-class.map --- .gitignore | 1 + src/.gitignore | 1 + src/Makefile.am | 45 +++++++++++++++++++++++---------------------- src/fmt-class.map | 31 +++++++++++++++++++++++++++++++ src/fmt.c | 17 +++++------------ 5 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 src/fmt-class.map diff --git a/.gitignore b/.gitignore index 383361b..f5e35dc 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ /lib/ref-del.sed /lib/selinux /lib/signal.h +/lib/spawn.h /lib/stamp-h1 /lib/stdalign.h /lib/stdio.h diff --git a/src/.gitignore b/src/.gitignore index 9c4c9b7..0e5e47f 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -114,3 +114,4 @@ wheel.h who whoami yes +fmt-class.h diff --git a/src/Makefile.am b/src/Makefile.am index 06ab615..8e59801 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -468,30 +468,27 @@ ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources) # This is for the '[' program. Automake transliterates '[' to '_'. __SOURCES = lbracket.c -cp_SOURCES = cp.c $(copy_sources) -dir_SOURCES = ls.c ls-dir.c -vdir_SOURCES = ls.c ls-vdir.c -id_SOURCES = id.c group-list.c -groups_SOURCES = groups.c group-list.c -ls_SOURCES = ls.c ls-ls.c -ln_SOURCES = ln.c relpath.c relpath.h -chown_SOURCES = chown.c chown-core.c -chgrp_SOURCES = chgrp.c chown-core.c -kill_SOURCES = kill.c operand2sig.c +arch_SOURCES = uname.c uname-arch.c +chgrp_SOURCES = chgrp.c chown-core.c +chown_SOURCES = chown.c chown-core.c +cp_SOURCES = cp.c $(copy_sources) +df_SOURCES = df.c find-mount-point.c +dir_SOURCES = ls.c ls-dir.c +fmt_SOURCES = fmt.c fmt-class.h +groups_SOURCES = groups.c group-list.c +id_SOURCES = id.c group-list.c +kill_SOURCES = kill.c operand2sig.c +ln_SOURCES = ln.c relpath.c relpath.h +ls_SOURCES = ls.c ls-ls.c +mkdir_SOURCES = mkdir.c prog-fprintf.c +mv_SOURCES = mv.c remove.c $(copy_sources) realpath_SOURCES = realpath.c relpath.c relpath.h +rm_SOURCES = rm.c remove.c +rmdir_SOURCES = rmdir.c prog-fprintf.c +stat_SOURCES = stat.c find-mount-point.c timeout_SOURCES = timeout.c operand2sig.c - -mv_SOURCES = mv.c remove.c $(copy_sources) -rm_SOURCES = rm.c remove.c - -mkdir_SOURCES = mkdir.c prog-fprintf.c -rmdir_SOURCES = rmdir.c prog-fprintf.c - -df_SOURCES = df.c find-mount-point.c -stat_SOURCES = stat.c find-mount-point.c - -uname_SOURCES = uname.c uname-uname.c -arch_SOURCES = uname.c uname-arch.c +uname_SOURCES = uname.c uname-uname.c +vdir_SOURCES = ls.c ls-vdir.c md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS) sha1sum_SOURCES = md5sum.c @@ -526,6 +523,10 @@ dircolors.h: dcgen dircolors.hin $(AM_V_at)chmod a-w $@-t $(AM_V_at)mv $@-t $@ +BUILT_SOURCES += fmt-class.h +fmt-class.h : fmt-class.map + char-mapper fmt-class.map + wheel_size = 5 BUILT_SOURCES += wheel-size.h diff --git a/src/fmt-class.map b/src/fmt-class.map new file mode 100644 index 0000000..2aee676 --- /dev/null +++ b/src/fmt-class.map @@ -0,0 +1,31 @@ + +%guard +%file fmt-class.h +%backup + +%comment + This file contains the character classifications used by fmt + for identifying quoted strings and sentence terminators. + The table is static scope, so %guard is empty. + + This is part of GNU fmt -- a simple text formatter. + Copyright (C) 1994-2012 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 . +% + +open "(['\"" +close ")]'\"" +period ".?!" +punct "\x21-\x7E" -"a-zA-Z0-9" diff --git a/src/fmt.c b/src/fmt.c index 308b645..e0bbc22 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -113,12 +113,7 @@ typedef long int COST; #define MAXWORDS 1000 #define MAXCHARS 5000 - -/* Extra ctype(3)-style macros. */ - -#define isopen(c) (strchr ("(['`\"", c) != NULL) -#define isclose(c) (strchr (")]'\"", c) != NULL) -#define isperiod(c) (strchr (".?!", c) != NULL) +#include "fmt-class.h" /* Size of a tab stop, for expansion on input and re-introduction on output. */ @@ -773,13 +768,11 @@ check_punctuation (WORD *w) { char const *start = w->text; char const *finish = start + (w->length - 1); - unsigned char fin = *finish; - w->paren = isopen (*start); - w->punct = !! ispunct (fin); - while (start < finish && isclose (*finish)) - finish--; - w->period = isperiod (*finish); + w->paren = IS_OPEN_CHAR (*start); + w->punct = IS_PUNCT_CHAR (*finish); + finish = SPN_CLOSE_BACK (start, start + w->length); + w->period = (finish > start) && IS_PERIOD_CHAR (finish[-1]); } /* Flush part of the paragraph to make room. This function is called on -- 1.7.7