consolidate *_l ctype/wctype functions into their non-_l source files

the main practical purposes of this commit are to remove a huge amount
of clutter from the src/locale directory, to cut down on the length of
the $(AR) and $(LD) command lines, and to reduce the amount of space
wasted by object file headers in the static libc.a. build time may
also be reduced, though this has not been measured.

as an additional justification, if there ever were a need for the
behavior of these functions to vary by locale, it would be necessary
for the non-_l versions to call the _l versions, so that linking the
former without the latter would not be possible anyway.
This commit is contained in:
Rich Felker 2014-07-02 21:16:05 -04:00
parent 0bc03091bb
commit d89fdec51b
61 changed files with 256 additions and 213 deletions

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}
int __isalnum_l(int c, locale_t l)
{
return isalnum(c);
}
weak_alias(__isalnum_l, isalnum_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef isalpha
int isalpha(int c)
{
return ((unsigned)c|32)-'a' < 26;
}
int __isalpha_l(int c, locale_t l)
{
return isalpha(c);
}
weak_alias(__isalpha_l, isalpha_l);

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int isblank(int c)
{
return (c == ' ' || c == '\t');
}
int __isblank_l(int c, locale_t l)
{
return isblank(c);
}
weak_alias(__isblank_l, isblank_l);

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int iscntrl(int c)
{
return (unsigned)c < 0x20 || c == 0x7f;
}
int __iscntrl_l(int c, locale_t l)
{
return iscntrl(c);
}
weak_alias(__iscntrl_l, iscntrl_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef isdigit
int isdigit(int c)
{
return (unsigned)c-'0' < 10;
}
int __isdigit_l(int c, locale_t l)
{
return isdigit(c);
}
weak_alias(__isdigit_l, isdigit_l);

View File

@ -1,4 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef isgraph
int isgraph(int c)
{
return (unsigned)c-0x21 < 0x5e;
}
int __isgraph_l(int c, locale_t l)
{
return isgraph(c);
}
weak_alias(__isgraph_l, isgraph_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef islower
int islower(int c)
{
return (unsigned)c-'a' < 26;
}
int __islower_l(int c, locale_t l)
{
return islower(c);
}
weak_alias(__islower_l, islower_l);

View File

@ -1,4 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef isprint
int isprint(int c)
{
return (unsigned)c-0x20 < 0x5f;
}
int __isprint_l(int c, locale_t l)
{
return isprint(c);
}
weak_alias(__isprint_l, isprint_l);

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}
int __ispunct_l(int c, locale_t l)
{
return ispunct(c);
}
weak_alias(__ispunct_l, ispunct_l);

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int isspace(int c)
{
return c == ' ' || (unsigned)c-'\t' < 5;
}
int __isspace_l(int c, locale_t l)
{
return isspace(c);
}
weak_alias(__isspace_l, isspace_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
#undef isupper
int isupper(int c)
{
return (unsigned)c-'A' < 26;
}
int __isupper_l(int c, locale_t l)
{
return isupper(c);
}
weak_alias(__isupper_l, isupper_l);

View File

@ -1,7 +1,14 @@
#include <wchar.h>
#include <wctype.h>
#include "libc.h"
int iswalnum(wint_t wc)
{
return iswdigit(wc) || iswalpha(wc);
}
int __iswalnum_l(wint_t c, locale_t l)
{
return iswalnum(c);
}
weak_alias(__iswalnum_l, iswalnum_l);

View File

@ -1,4 +1,5 @@
#include <wctype.h>
#include "libc.h"
static const unsigned char table[] = {
#include "alpha.h"
@ -12,3 +13,10 @@ int iswalpha(wint_t wc)
return 1;
return 0;
}
int __iswalpha_l(wint_t c, locale_t l)
{
return iswalpha(c);
}
weak_alias(__iswalpha_l, iswalpha_l);

View File

@ -1,8 +1,15 @@
#include <wchar.h>
#include <wctype.h>
#include <ctype.h>
#include "libc.h"
int iswblank(wint_t wc)
{
return isblank(wc);
}
int __iswblank_l(wint_t c, locale_t l)
{
return iswblank(c);
}
weak_alias(__iswblank_l, iswblank_l);

View File

@ -1,5 +1,5 @@
#include <wchar.h>
#include <wctype.h>
#include "libc.h"
int iswcntrl(wint_t wc)
{
@ -8,3 +8,10 @@ int iswcntrl(wint_t wc)
|| (unsigned)(wc-0x2028) < 2
|| (unsigned)(wc-0xfff9) < 3;
}
int __iswcntrl_l(wint_t c, locale_t l)
{
return iswcntrl(c);
}
weak_alias(__iswcntrl_l, iswcntrl_l);

View File

@ -1,6 +1,6 @@
#include <wchar.h>
#include <wctype.h>
#include <string.h>
#include "libc.h"
#define WCTYPE_ALNUM 1
#define WCTYPE_ALPHA 2
@ -61,3 +61,16 @@ wctype_t wctype(const char *s)
return i;
return 0;
}
int __iswctype_l(wint_t c, wctype_t t, locale_t l)
{
return iswctype(c, t);
}
wctype_t __wctype_l(const char *s, locale_t l)
{
return wctype(s);
}
weak_alias(__iswctype_l, iswctype_l);
weak_alias(__wctype_l, wctype_l);

View File

@ -1,5 +1,5 @@
#include <wchar.h>
#include <wctype.h>
#include "libc.h"
#undef iswdigit
@ -7,3 +7,10 @@ int iswdigit(wint_t wc)
{
return (unsigned)wc-'0' < 10;
}
int __iswdigit_l(wint_t c, locale_t l)
{
return iswdigit(c);
}
weak_alias(__iswdigit_l, iswdigit_l);

View File

@ -1,7 +1,15 @@
#include <wctype.h>
#include "libc.h"
int iswgraph(wint_t wc)
{
/* ISO C defines this function as: */
return !iswspace(wc) && iswprint(wc);
}
int __iswgraph_l(wint_t c, locale_t l)
{
return iswgraph(c);
}
weak_alias(__iswgraph_l, iswgraph_l);

View File

@ -1,6 +1,14 @@
#include <wctype.h>
#include "libc.h"
int iswlower(wint_t wc)
{
return towupper(wc) != wc || wc == 0xdf;
}
int __iswlower_l(wint_t c, locale_t l)
{
return iswlower(c);
}
weak_alias(__iswlower_l, iswlower_l);

View File

@ -1,4 +1,5 @@
#include <wctype.h>
#include "libc.h"
/* Consider all legal codepoints as printable except for:
* - C0 and C1 control characters
@ -17,3 +18,10 @@ int iswprint(wint_t wc)
return 0;
return 1;
}
int __iswprint_l(wint_t c, locale_t l)
{
return iswprint(c);
}
weak_alias(__iswprint_l, iswprint_l);

View File

@ -1,4 +1,5 @@
#include <wctype.h>
#include "libc.h"
static const unsigned char table[] = {
#include "punct.h"
@ -10,3 +11,10 @@ int iswpunct(wint_t wc)
return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1;
return 0;
}
int __iswpunct_l(wint_t c, locale_t l)
{
return iswpunct(c);
}
weak_alias(__iswpunct_l, iswpunct_l);

View File

@ -1,6 +1,6 @@
#include <wchar.h>
#include <wctype.h>
#include <ctype.h>
#include "libc.h"
/* Our definition of whitespace is the Unicode White_Space property,
* minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script-
@ -16,3 +16,10 @@ int iswspace(wint_t wc)
};
return wc && wcschr(spaces, wc);
}
int __iswspace_l(wint_t c, locale_t l)
{
return iswspace(c);
}
weak_alias(__iswspace_l, iswspace_l);

View File

@ -1,6 +1,14 @@
#include <wctype.h>
#include "libc.h"
int iswupper(wint_t wc)
{
return towlower(wc) != wc;
}
int __iswupper_l(wint_t c, locale_t l)
{
return iswupper(c);
}
weak_alias(__iswupper_l, iswupper_l);

View File

@ -1,7 +1,14 @@
#include <wchar.h>
#include <wctype.h>
#include "libc.h"
int iswxdigit(wint_t wc)
{
return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6;
}
int __iswxdigit_l(wint_t c, locale_t l)
{
return iswxdigit(c);
}
weak_alias(__iswxdigit_l, iswxdigit_l);

View File

@ -1,6 +1,14 @@
#include <ctype.h>
#include "libc.h"
int isxdigit(int c)
{
return isdigit(c) || ((unsigned)c|32)-'a' < 6;
}
int __isxdigit_l(int c, locale_t l)
{
return isxdigit(c);
}
weak_alias(__isxdigit_l, isxdigit_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
int tolower(int c)
{
if (isupper(c)) return c | 32;
return c;
}
int __tolower_l(int c, locale_t l)
{
return tolower(c);
}
weak_alias(__tolower_l, tolower_l);

View File

@ -1,7 +1,15 @@
#include <ctype.h>
#include "libc.h"
int toupper(int c)
{
if (islower(c)) return c & 0x5f;
return c;
}
int __toupper_l(int c, locale_t l)
{
return toupper(c);
}
weak_alias(__toupper_l, toupper_l);

View File

@ -1,6 +1,5 @@
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
#include "libc.h"
#define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 }
#define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1)
@ -266,3 +265,16 @@ wint_t towlower(wint_t wc)
{
return __towcase(wc, 1);
}
wint_t __towupper_l(wint_t c, locale_t l)
{
return towupper(c);
}
wint_t __towlower_l(wint_t c, locale_t l)
{
return towlower(c);
}
weak_alias(__towupper_l, towupper_l);
weak_alias(__towlower_l, towlower_l);

View File

@ -1,5 +1,6 @@
#include <wctype.h>
#include <string.h>
#include "libc.h"
wctrans_t wctrans(const char *class)
{
@ -14,3 +15,16 @@ wint_t towctrans(wint_t wc, wctrans_t trans)
if (trans == (wctrans_t)2) return towlower(wc);
return wc;
}
wctrans_t __wctrans_l(const char *s, locale_t l)
{
return wctrans(s);
}
wint_t __towctrans_l(wint_t c, wctrans_t t, locale_t l)
{
return towctrans(c, t);
}
weak_alias(__wctrans_l, wctrans_l);
weak_alias(__towctrans_l, towctrans_l);

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isalnum_l(int c, locale_t l)
{
return isalnum(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isalpha_l(int c, locale_t l)
{
return isalpha(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isblank_l(int c, locale_t l)
{
return isblank(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int iscntrl_l(int c, locale_t l)
{
return iscntrl(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isdigit_l(int c, locale_t l)
{
return isdigit(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isgraph_l(int c, locale_t l)
{
return isgraph(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int islower_l(int c, locale_t l)
{
return islower(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isprint_l(int c, locale_t l)
{
return isprint(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int ispunct_l(int c, locale_t l)
{
return ispunct(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isspace_l(int c, locale_t l)
{
return isspace(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isupper_l(int c, locale_t l)
{
return isupper(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswalnum_l(wint_t c, locale_t l)
{
return iswalnum(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswalpha_l(wint_t c, locale_t l)
{
return iswalpha(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswblank_l(wint_t c, locale_t l)
{
return iswblank(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswcntrl_l(wint_t c, locale_t l)
{
return iswcntrl(c);
}

View File

@ -1,9 +0,0 @@
#include <wctype.h>
#include "libc.h"
int iswctype_l(wint_t c, wctype_t t, locale_t l)
{
return iswctype(c, t);
}
weak_alias(iswctype_l, __iswctype_l);

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswdigit_l(wint_t c, locale_t l)
{
return iswdigit(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswgraph_l(wint_t c, locale_t l)
{
return iswgraph(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswlower_l(wint_t c, locale_t l)
{
return iswlower(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswprint_l(wint_t c, locale_t l)
{
return iswprint(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswpunct_l(wint_t c, locale_t l)
{
return iswpunct(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswspace_l(wint_t c, locale_t l)
{
return iswspace(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswupper_l(wint_t c, locale_t l)
{
return iswupper(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
int iswxdigit_l(wint_t c, locale_t l)
{
return iswxdigit(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int isxdigit_l(int c, locale_t l)
{
return isxdigit(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int tolower_l(int c, locale_t l)
{
return tolower(c);
}

View File

@ -1,6 +0,0 @@
#include <ctype.h>
int toupper_l(int c, locale_t l)
{
return toupper(c);
}

View File

@ -1,6 +0,0 @@
#include <wctype.h>
wint_t towctrans_l(wint_t c, wctrans_t t, locale_t l)
{
return towctrans(c, t);
}

View File

@ -1,9 +0,0 @@
#include <wctype.h>
#include "libc.h"
wint_t towlower_l(wint_t c, locale_t l)
{
return towlower(c);
}
weak_alias(towlower_l, __towlower_l);

View File

@ -1,9 +0,0 @@
#include <wctype.h>
#include "libc.h"
wint_t towupper_l(wint_t c, locale_t l)
{
return towupper(c);
}
weak_alias(towupper_l, __towupper_l);

View File

@ -1,6 +0,0 @@
#include <wctype.h>
wctrans_t wctrans_l(const char *s, locale_t l)
{
return wctrans(s);
}

View File

@ -1,9 +0,0 @@
#include <wctype.h>
#include "libc.h"
wctype_t wctype_l(const char *s, locale_t l)
{
return wctype(s);
}
weak_alias(wctype_l, __wctype_l);