提交 d89fdec5 编写于 作者: R Rich Felker

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.
上级 0bc03091
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int isalnum(int c) int isalnum(int c)
{ {
return isalpha(c) || isdigit(c); return isalpha(c) || isdigit(c);
} }
int __isalnum_l(int c, locale_t l)
{
return isalnum(c);
}
weak_alias(__isalnum_l, isalnum_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
#undef isalpha #undef isalpha
int isalpha(int c) int isalpha(int c)
{ {
return ((unsigned)c|32)-'a' < 26; return ((unsigned)c|32)-'a' < 26;
} }
int __isalpha_l(int c, locale_t l)
{
return isalpha(c);
}
weak_alias(__isalpha_l, isalpha_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int isblank(int c) int isblank(int c)
{ {
return (c == ' ' || c == '\t'); return (c == ' ' || c == '\t');
} }
int __isblank_l(int c, locale_t l)
{
return isblank(c);
}
weak_alias(__isblank_l, isblank_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int iscntrl(int c) int iscntrl(int c)
{ {
return (unsigned)c < 0x20 || c == 0x7f; return (unsigned)c < 0x20 || c == 0x7f;
} }
int __iscntrl_l(int c, locale_t l)
{
return iscntrl(c);
}
weak_alias(__iscntrl_l, iscntrl_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
#undef isdigit #undef isdigit
int isdigit(int c) int isdigit(int c)
{ {
return (unsigned)c-'0' < 10; return (unsigned)c-'0' < 10;
} }
int __isdigit_l(int c, locale_t l)
{
return isdigit(c);
}
weak_alias(__isdigit_l, isdigit_l);
#include <ctype.h>
#include "libc.h"
#undef isgraph
int isgraph(int c) int isgraph(int c)
{ {
return (unsigned)c-0x21 < 0x5e; return (unsigned)c-0x21 < 0x5e;
} }
int __isgraph_l(int c, locale_t l)
{
return isgraph(c);
}
weak_alias(__isgraph_l, isgraph_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
#undef islower #undef islower
int islower(int c) int islower(int c)
{ {
return (unsigned)c-'a' < 26; return (unsigned)c-'a' < 26;
} }
int __islower_l(int c, locale_t l)
{
return islower(c);
}
weak_alias(__islower_l, islower_l);
#include <ctype.h>
#include "libc.h"
#undef isprint
int isprint(int c) int isprint(int c)
{ {
return (unsigned)c-0x20 < 0x5f; return (unsigned)c-0x20 < 0x5f;
} }
int __isprint_l(int c, locale_t l)
{
return isprint(c);
}
weak_alias(__isprint_l, isprint_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int ispunct(int c) int ispunct(int c)
{ {
return isgraph(c) && !isalnum(c); return isgraph(c) && !isalnum(c);
} }
int __ispunct_l(int c, locale_t l)
{
return ispunct(c);
}
weak_alias(__ispunct_l, ispunct_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int isspace(int c) int isspace(int c)
{ {
return c == ' ' || (unsigned)c-'\t' < 5; return c == ' ' || (unsigned)c-'\t' < 5;
} }
int __isspace_l(int c, locale_t l)
{
return isspace(c);
}
weak_alias(__isspace_l, isspace_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
#undef isupper #undef isupper
int isupper(int c) int isupper(int c)
{ {
return (unsigned)c-'A' < 26; return (unsigned)c-'A' < 26;
} }
int __isupper_l(int c, locale_t l)
{
return isupper(c);
}
weak_alias(__isupper_l, isupper_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswalnum(wint_t wc) int iswalnum(wint_t wc)
{ {
return iswdigit(wc) || iswalpha(wc); return iswdigit(wc) || iswalpha(wc);
} }
int __iswalnum_l(wint_t c, locale_t l)
{
return iswalnum(c);
}
weak_alias(__iswalnum_l, iswalnum_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
static const unsigned char table[] = { static const unsigned char table[] = {
#include "alpha.h" #include "alpha.h"
...@@ -12,3 +13,10 @@ int iswalpha(wint_t wc) ...@@ -12,3 +13,10 @@ int iswalpha(wint_t wc)
return 1; return 1;
return 0; return 0;
} }
int __iswalpha_l(wint_t c, locale_t l)
{
return iswalpha(c);
}
weak_alias(__iswalpha_l, iswalpha_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int iswblank(wint_t wc) int iswblank(wint_t wc)
{ {
return isblank(wc); return isblank(wc);
} }
int __iswblank_l(wint_t c, locale_t l)
{
return iswblank(c);
}
weak_alias(__iswblank_l, iswblank_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswcntrl(wint_t wc) int iswcntrl(wint_t wc)
{ {
...@@ -8,3 +8,10 @@ int iswcntrl(wint_t wc) ...@@ -8,3 +8,10 @@ int iswcntrl(wint_t wc)
|| (unsigned)(wc-0x2028) < 2 || (unsigned)(wc-0x2028) < 2
|| (unsigned)(wc-0xfff9) < 3; || (unsigned)(wc-0xfff9) < 3;
} }
int __iswcntrl_l(wint_t c, locale_t l)
{
return iswcntrl(c);
}
weak_alias(__iswcntrl_l, iswcntrl_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <string.h> #include <string.h>
#include "libc.h"
#define WCTYPE_ALNUM 1 #define WCTYPE_ALNUM 1
#define WCTYPE_ALPHA 2 #define WCTYPE_ALPHA 2
...@@ -61,3 +61,16 @@ wctype_t wctype(const char *s) ...@@ -61,3 +61,16 @@ wctype_t wctype(const char *s)
return i; return i;
return 0; 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);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include "libc.h"
#undef iswdigit #undef iswdigit
...@@ -7,3 +7,10 @@ int iswdigit(wint_t wc) ...@@ -7,3 +7,10 @@ int iswdigit(wint_t wc)
{ {
return (unsigned)wc-'0' < 10; return (unsigned)wc-'0' < 10;
} }
int __iswdigit_l(wint_t c, locale_t l)
{
return iswdigit(c);
}
weak_alias(__iswdigit_l, iswdigit_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswgraph(wint_t wc) int iswgraph(wint_t wc)
{ {
/* ISO C defines this function as: */ /* ISO C defines this function as: */
return !iswspace(wc) && iswprint(wc); return !iswspace(wc) && iswprint(wc);
} }
int __iswgraph_l(wint_t c, locale_t l)
{
return iswgraph(c);
}
weak_alias(__iswgraph_l, iswgraph_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswlower(wint_t wc) int iswlower(wint_t wc)
{ {
return towupper(wc) != wc || wc == 0xdf; return towupper(wc) != wc || wc == 0xdf;
} }
int __iswlower_l(wint_t c, locale_t l)
{
return iswlower(c);
}
weak_alias(__iswlower_l, iswlower_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
/* Consider all legal codepoints as printable except for: /* Consider all legal codepoints as printable except for:
* - C0 and C1 control characters * - C0 and C1 control characters
...@@ -17,3 +18,10 @@ int iswprint(wint_t wc) ...@@ -17,3 +18,10 @@ int iswprint(wint_t wc)
return 0; return 0;
return 1; return 1;
} }
int __iswprint_l(wint_t c, locale_t l)
{
return iswprint(c);
}
weak_alias(__iswprint_l, iswprint_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
static const unsigned char table[] = { static const unsigned char table[] = {
#include "punct.h" #include "punct.h"
...@@ -10,3 +11,10 @@ int iswpunct(wint_t wc) ...@@ -10,3 +11,10 @@ int iswpunct(wint_t wc)
return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1;
return 0; return 0;
} }
int __iswpunct_l(wint_t c, locale_t l)
{
return iswpunct(c);
}
weak_alias(__iswpunct_l, iswpunct_l);
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <ctype.h> #include "libc.h"
/* Our definition of whitespace is the Unicode White_Space property, /* Our definition of whitespace is the Unicode White_Space property,
* minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script- * minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script-
...@@ -16,3 +16,10 @@ int iswspace(wint_t wc) ...@@ -16,3 +16,10 @@ int iswspace(wint_t wc)
}; };
return wc && wcschr(spaces, wc); return wc && wcschr(spaces, wc);
} }
int __iswspace_l(wint_t c, locale_t l)
{
return iswspace(c);
}
weak_alias(__iswspace_l, iswspace_l);
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswupper(wint_t wc) int iswupper(wint_t wc)
{ {
return towlower(wc) != wc; return towlower(wc) != wc;
} }
int __iswupper_l(wint_t c, locale_t l)
{
return iswupper(c);
}
weak_alias(__iswupper_l, iswupper_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include "libc.h"
int iswxdigit(wint_t wc) int iswxdigit(wint_t wc)
{ {
return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6; 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);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int isxdigit(int c) int isxdigit(int c)
{ {
return isdigit(c) || ((unsigned)c|32)-'a' < 6; 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);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int tolower(int c) int tolower(int c)
{ {
if (isupper(c)) return c | 32; if (isupper(c)) return c | 32;
return c; return c;
} }
int __tolower_l(int c, locale_t l)
{
return tolower(c);
}
weak_alias(__tolower_l, tolower_l);
#include <ctype.h> #include <ctype.h>
#include "libc.h"
int toupper(int c) int toupper(int c)
{ {
if (islower(c)) return c & 0x5f; if (islower(c)) return c & 0x5f;
return c; return c;
} }
int __toupper_l(int c, locale_t l)
{
return toupper(c);
}
weak_alias(__toupper_l, toupper_l);
#include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <stdio.h> #include "libc.h"
#define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 } #define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 }
#define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1) #define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1)
...@@ -266,3 +265,16 @@ wint_t towlower(wint_t wc) ...@@ -266,3 +265,16 @@ wint_t towlower(wint_t wc)
{ {
return __towcase(wc, 1); 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);
#include <wctype.h> #include <wctype.h>
#include <string.h> #include <string.h>
#include "libc.h"
wctrans_t wctrans(const char *class) wctrans_t wctrans(const char *class)
{ {
...@@ -14,3 +15,16 @@ wint_t towctrans(wint_t wc, wctrans_t trans) ...@@ -14,3 +15,16 @@ wint_t towctrans(wint_t wc, wctrans_t trans)
if (trans == (wctrans_t)2) return towlower(wc); if (trans == (wctrans_t)2) return towlower(wc);
return 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);
#include <ctype.h>
int isalnum_l(int c, locale_t l)
{
return isalnum(c);
}
#include <ctype.h>
int isalpha_l(int c, locale_t l)
{
return isalpha(c);
}
#include <ctype.h>
int isblank_l(int c, locale_t l)
{
return isblank(c);
}
#include <ctype.h>
int iscntrl_l(int c, locale_t l)
{
return iscntrl(c);
}
#include <ctype.h>
int isdigit_l(int c, locale_t l)
{
return isdigit(c);
}
#include <ctype.h>
int isgraph_l(int c, locale_t l)
{
return isgraph(c);
}
#include <ctype.h>
int islower_l(int c, locale_t l)
{
return islower(c);
}
#include <ctype.h>
int isprint_l(int c, locale_t l)
{
return isprint(c);
}
#include <ctype.h>
int ispunct_l(int c, locale_t l)
{
return ispunct(c);
}
#include <ctype.h>
int isspace_l(int c, locale_t l)
{
return isspace(c);
}
#include <ctype.h>
int isupper_l(int c, locale_t l)
{
return isupper(c);
}
#include <wctype.h>
int iswalnum_l(wint_t c, locale_t l)
{
return iswalnum(c);
}
#include <wctype.h>
int iswalpha_l(wint_t c, locale_t l)
{
return iswalpha(c);
}
#include <wctype.h>
int iswblank_l(wint_t c, locale_t l)
{
return iswblank(c);
}
#include <wctype.h>
int iswcntrl_l(wint_t c, locale_t l)
{
return iswcntrl(c);
}
#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);
#include <wctype.h>
int iswdigit_l(wint_t c, locale_t l)
{
return iswdigit(c);
}
#include <wctype.h>
int iswgraph_l(wint_t c, locale_t l)
{
return iswgraph(c);
}
#include <wctype.h>
int iswlower_l(wint_t c, locale_t l)
{
return iswlower(c);
}
#include <wctype.h>
int iswprint_l(wint_t c, locale_t l)
{
return iswprint(c);
}
#include <wctype.h>
int iswpunct_l(wint_t c, locale_t l)
{
return iswpunct(c);
}
#include <wctype.h>
int iswspace_l(wint_t c, locale_t l)
{
return iswspace(c);
}
#include <wctype.h>
int iswupper_l(wint_t c, locale_t l)
{
return iswupper(c);
}
#include <wctype.h>
int iswxdigit_l(wint_t c, locale_t l)
{
return iswxdigit(c);
}
#include <ctype.h>
int isxdigit_l(int c, locale_t l)
{
return isxdigit(c);
}
#include <ctype.h>
int tolower_l(int c, locale_t l)
{
return tolower(c);
}
#include <ctype.h>
int toupper_l(int c, locale_t l)
{
return toupper(c);
}
#include <wctype.h>
wint_t towctrans_l(wint_t c, wctrans_t t, locale_t l)
{
return towctrans(c, t);
}
#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);
#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);
#include <wctype.h>
wctrans_t wctrans_l(const char *s, locale_t l)
{
return wctrans(s);
}
#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);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册