[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils int cleanup for sort, tr, system.h
From: |
Paul Eggert |
Subject: |
coreutils int cleanup for sort, tr, system.h |
Date: |
Fri, 30 Jul 2004 14:10:36 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed this minor cleanup patch. It doesn't fix any bugs.
2004-07-30 Paul Eggert <address@hidden>
* src/sort.c (UCHAR): Remove; all uses changed to to_uchar.
(IS_THOUSANDS_SEP): Use bool when appropriate.
(numcompare, main): Use char, not int, when the value is always a char.
(numcompare): Remove "register"; compilers are smart enough these days.
* src/system.h (errno, CHAR_BIT): Remove decls;
no longer needed now we assume C89 or better.
Include <inttypes.h> before <stdint.h>, as it's the
Autoconf-recommended pattern.
(to_uchar): New inline function, moved here from tr.c.
Use full names for int types, e.g. "long int" rather than "long".
* src/tr.c (to_uchar): Remove; now in system.h.
(is_char_class_member): Use bool when appropriate.
Index: src/sort.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/sort.c,v
retrieving revision 1.288
diff -p -u -r1.288 sort.c
--- src/sort.c 21 Jun 2004 15:03:35 -0000 1.288
+++ src/sort.c 19 Jul 2004 04:39:10 -0000
@@ -66,7 +66,6 @@ double strtod ();
#endif
#define UCHAR_LIM (UCHAR_MAX + 1)
-#define UCHAR(c) ((unsigned char) (c))
#ifndef DEFAULT_TMPDIR
# define DEFAULT_TMPDIR "/tmp"
@@ -104,7 +103,7 @@ static bool hard_LC_TIME;
#else
# define decimal_point C_DECIMAL_POINT
-# define IS_THOUSANDS_SEP(x) 0
+# define IS_THOUSANDS_SEP(x) false
#endif
@@ -566,7 +565,7 @@ inittables (void)
monthtab[i].val = i + 1;
for (j = 0; j < s_len; j++)
- name[j] = fold_toupper[UCHAR (s[j])];
+ name[j] = fold_toupper[to_uchar (s[j])];
name[j] = '\0';
}
qsort ((void *) monthtab, MONTHS_PER_YEAR,
@@ -806,14 +805,14 @@ begfield (const struct line *line, const
else
while (ptr < lim && sword--)
{
- while (ptr < lim && blanks[UCHAR (*ptr)])
+ while (ptr < lim && blanks[to_uchar (*ptr)])
++ptr;
- while (ptr < lim && !blanks[UCHAR (*ptr)])
+ while (ptr < lim && !blanks[to_uchar (*ptr)])
++ptr;
}
if (key->skipsblanks)
- while (ptr < lim && blanks[UCHAR (*ptr)])
+ while (ptr < lim && blanks[to_uchar (*ptr)])
++ptr;
/* Advance PTR by SCHAR (if possible), but no further than LIM. */
@@ -854,9 +853,9 @@ limfield (const struct line *line, const
else
while (ptr < lim && eword--)
{
- while (ptr < lim && blanks[UCHAR (*ptr)])
+ while (ptr < lim && blanks[to_uchar (*ptr)])
++ptr;
- while (ptr < lim && !blanks[UCHAR (*ptr)])
+ while (ptr < lim && !blanks[to_uchar (*ptr)])
++ptr;
}
@@ -903,9 +902,9 @@ limfield (const struct line *line, const
{
char *newlim;
newlim = ptr;
- while (newlim < lim && blanks[UCHAR (*newlim)])
+ while (newlim < lim && blanks[to_uchar (*newlim)])
++newlim;
- while (newlim < lim && !blanks[UCHAR (*newlim)])
+ while (newlim < lim && !blanks[to_uchar (*newlim)])
++newlim;
lim = newlim;
}
@@ -915,7 +914,7 @@ limfield (const struct line *line, const
of the field, don't start counting bytes until after skipping
past any leading blanks. */
if (key->skipeblanks)
- while (ptr < lim && blanks[UCHAR (*ptr)])
+ while (ptr < lim && blanks[to_uchar (*ptr)])
++ptr;
/* Advance PTR by ECHAR (if possible), but no further than LIM. */
@@ -1010,7 +1009,7 @@ fillbuf (struct buffer *buf, register FI
else
{
if (key->skipsblanks)
- while (blanks[UCHAR (*line_start)])
+ while (blanks[to_uchar (*line_start)])
line_start++;
line->keybeg = line_start;
}
@@ -1111,15 +1110,18 @@ fraccompare (register const char *a, reg
static int
numcompare (register const char *a, register const char *b)
{
- register int tmpa, tmpb, tmp;
- register size_t log_a, log_b;
+ char tmpa;
+ char tmpb;
+ int tmp;
+ size_t log_a;
+ size_t log_b;
tmpa = *a;
tmpb = *b;
- while (blanks[UCHAR (tmpa)])
+ while (blanks[to_uchar (tmpa)])
tmpa = *++a;
- while (blanks[UCHAR (tmpb)])
+ while (blanks[to_uchar (tmpb)])
tmpb = *++b;
if (tmpa == NEGATION_SIGN)
@@ -1286,7 +1288,7 @@ getmonth (const char *s, size_t len)
register size_t i;
register int lo = 0, hi = MONTHS_PER_YEAR, result;
- while (len > 0 && blanks[UCHAR (*s)])
+ while (len > 0 && blanks[to_uchar (*s)])
{
++s;
--len;
@@ -1297,7 +1299,7 @@ getmonth (const char *s, size_t len)
month = alloca (len + 1);
for (i = 0; i < len; ++i)
- month[i] = fold_toupper[UCHAR (s[i])];
+ month[i] = fold_toupper[to_uchar (s[i])];
month[len] = '\0';
do
@@ -1371,17 +1373,17 @@ keycompare (const struct line *a, const
if (i < lena)
{
copy_a[new_len_a] = (translate
- ? translate[UCHAR (texta[i])]
+ ? translate[to_uchar (texta[i])]
: texta[i]);
- if (!ignore || !ignore[UCHAR (texta[i])])
+ if (!ignore || !ignore[to_uchar (texta[i])])
++new_len_a;
}
if (i < lenb)
{
copy_b[new_len_b] = (translate
- ? translate[UCHAR (textb[i])]
+ ? translate[to_uchar (textb[i])]
: textb [i]);
- if (!ignore || !ignore[UCHAR (textb[i])])
+ if (!ignore || !ignore[to_uchar (textb[i])])
++new_len_b;
}
}
@@ -1402,13 +1404,13 @@ keycompare (const struct line *a, const
{ \
for (;;) \
{ \
- while (texta < lima && ignore[UCHAR (*texta)]) \
+ while (texta < lima && ignore[to_uchar (*texta)]) \
++texta; \
- while (textb < limb && ignore[UCHAR (*textb)]) \
+ while (textb < limb && ignore[to_uchar (*textb)]) \
++textb; \
if (! (texta < lima && textb < limb)) \
break; \
- diff = UCHAR (A) - UCHAR (B); \
+ diff = to_uchar (A) - to_uchar (B); \
if (diff) \
goto not_equal; \
++texta; \
@@ -1420,8 +1422,8 @@ keycompare (const struct line *a, const
while (0)
if (translate)
- CMP_WITH_IGNORE (translate[UCHAR (*texta)],
- translate[UCHAR (*textb)]);
+ CMP_WITH_IGNORE (translate[to_uchar (*texta)],
+ translate[to_uchar (*textb)]);
else
CMP_WITH_IGNORE (*texta, *textb);
}
@@ -1435,8 +1437,8 @@ keycompare (const struct line *a, const
{
while (texta < lima && textb < limb)
{
- diff = (UCHAR (translate[UCHAR (*texta++)])
- - UCHAR (translate[UCHAR (*textb++)]));
+ diff = (to_uchar (translate[to_uchar (*texta++)])
+ - to_uchar (translate[to_uchar (*textb++)]));
if (diff)
goto not_equal;
}
@@ -1470,9 +1472,9 @@ keycompare (const struct line *a, const
texta = a->text, textb = b->text;
if (key->skipsblanks)
{
- while (texta < lima && blanks[UCHAR (*texta)])
+ while (texta < lima && blanks[to_uchar (*texta)])
++texta;
- while (textb < limb && blanks[UCHAR (*textb)])
+ while (textb < limb && blanks[to_uchar (*textb)])
++textb;
}
}
@@ -2424,7 +2426,7 @@ main (int argc, char **argv)
case 't':
{
- int newtab = optarg[0];
+ char newtab = optarg[0];
if (! newtab)
error (SORT_FAILURE, 0, _("empty tab"));
if (optarg[1])
Index: src/system.h
===================================================================
RCS file: /home/eggert/coreutils/cu/src/system.h,v
retrieving revision 1.90
diff -p -u -r1.90 system.h
--- src/system.h 30 Jun 2004 22:33:40 -0000 1.90
+++ src/system.h 20 Jul 2004 05:15:26 -0000
@@ -119,9 +119,6 @@ void *memrchr (const void *, int, size_t
#endif
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
/* Some systems don't define the following symbols. */
#ifndef ENOSYS
@@ -365,29 +362,28 @@ initialize_exit_failure (int status)
# include <sys/exceptn.h>
#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
#if HAVE_STDINT_H
# include <stdint.h>
#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h> /* for the definition of UINTMAX_MAX */
-#endif
-
#if !defined PRIdMAX || PRI_MACROS_BROKEN
# undef PRIdMAX
-# define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
+# define PRIdMAX (sizeof (uintmax_t) == sizeof (long int) ? "ld" : "lld")
#endif
#if !defined PRIoMAX || PRI_MACROS_BROKEN
# undef PRIoMAX
-# define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
+# define PRIoMAX (sizeof (uintmax_t) == sizeof (long int) ? "lo" : "llo")
#endif
#if !defined PRIuMAX || PRI_MACROS_BROKEN
# undef PRIuMAX
-# define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
+# define PRIuMAX (sizeof (uintmax_t) == sizeof (long int) ? "lu" : "llu")
#endif
#if !defined PRIxMAX || PRI_MACROS_BROKEN
# undef PRIxMAX
-# define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
+# define PRIxMAX (sizeof (uintmax_t) == sizeof (long int) ? "lx" : "llx")
#endif
#include <ctype.h>
@@ -457,7 +453,12 @@ initialize_exit_failure (int status)
POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
ISDIGIT_LOCALE unless it's important to use the locale's definition
of `digit' even when the host does not conform to POSIX. */
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
+
+/* Convert a possibly-signed character to an unsigned character. This is
+ a bit safer than casting to unsigned char, since it catches some type
+ errors that the cast doesn't. */
+static inline unsigned char to_uchar (char ch) { return ch; }
/* Take care of NLS matters. */
@@ -633,10 +634,6 @@ enum
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
-#ifndef CHAR_BIT
-# define CHAR_BIT 8
-#endif
-
/* The extra casts work around common compiler bugs. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
@@ -691,11 +688,11 @@ enum
#endif
#ifndef LONG_MAX
-# define LONG_MAX TYPE_MAXIMUM (long)
+# define LONG_MAX TYPE_MAXIMUM (long int)
#endif
#ifndef ULONG_MAX
-# define ULONG_MAX TYPE_MAXIMUM (unsigned long)
+# define ULONG_MAX TYPE_MAXIMUM (unsigned long int)
#endif
#ifndef SIZE_MAX
@@ -771,7 +768,7 @@ enum
#endif
#if ! HAVE_FSEEKO && ! defined fseeko
-# define fseeko(s, o, w) ((o) == (long) (o) \
+# define fseeko(s, o, w) ((o) == (long int) (o) \
? fseek (s, o, w) \
: (errno = EOVERFLOW, -1))
#endif
Index: src/tr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/tr.c,v
retrieving revision 1.136
diff -p -u -r1.136 tr.c
--- src/tr.c 21 Jun 2004 15:03:35 -0000 1.136
+++ src/tr.c 19 Jul 2004 22:32:26 -0000
@@ -37,11 +37,6 @@
enum { N_CHARS = UCHAR_MAX + 1 };
-/* Convert a possibly-signed character to an unsigned character. This is
- a bit safer than casting to unsigned char, since it catches some type
- errors that the cast doesn't. */
-static inline unsigned char to_uchar (char ch) { return ch; }
-
/* An unsigned integer type big enough to hold a repeat count or an
unsigned character. POSIX requires support for repeat counts as
high as 2**31 - 1. Since repeat counts might need to expand to
@@ -375,13 +370,13 @@ is_equiv_class_member (unsigned char equ
return (equiv_class == c);
}
-/* Return nonzero if the character C is a member of the
+/* Return true if the character C is a member of the
character class CHAR_CLASS. */
-static int
+static bool
is_char_class_member (enum Char_class char_class, unsigned char c)
{
- int result;
+ bool result;
switch (char_class)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils int cleanup for sort, tr, system.h,
Paul Eggert <=