diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index a342c020cc..b4d1b26e63 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -87,7 +87,7 @@ SYSTEM_LIBS = libmail.so libmedia.so libmidi.so libmidi2.so libnetwork.so libpng.so - libroot.so + libroot.so libroot-addon-icu.so libscreensaver.so libtextencoding.so libtiff.so libtracker.so libtranslation.so libz.so diff --git a/headers/posix/langinfo.h b/headers/posix/langinfo.h new file mode 100644 index 0000000000..0dbfbfce69 --- /dev/null +++ b/headers/posix/langinfo.h @@ -0,0 +1,93 @@ +/* + * Copyright 2010, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _LANGINFO_H_ +#define _LANGINFO_H_ + + +#include +#include +#include + + +enum { + CODESET, /* codeset name */ + D_T_FMT, /* string for formatting date and time */ + D_FMT, /* date format string */ + T_FMT, /* time format string */ + T_FMT_AMPM, /* a.m. or p.m. time formatting string */ + AM_STR, /* Ante Meridian affix */ + PM_STR, /* Post Meridian affix */ + + /* week day names */ + DAY_1, + DAY_2, + DAY_3, + DAY_4, + DAY_5, + DAY_6, + DAY_7, + + /* abbreviated week day names */ + ABDAY_1, + ABDAY_2, + ABDAY_3, + ABDAY_4, + ABDAY_5, + ABDAY_6, + ABDAY_7, + + /* month names */ + MON_1, + MON_2, + MON_3, + MON_4, + MON_5, + MON_6, + MON_7, + MON_8, + MON_9, + MON_10, + MON_11, + MON_12, + + /* abbreviated month names */ + ABMON_1, + ABMON_2, + ABMON_3, + ABMON_4, + ABMON_5, + ABMON_6, + ABMON_7, + ABMON_8, + ABMON_9, + ABMON_10, + ABMON_11, + ABMON_12, + + ERA, /* era description segments */ + ERA_D_FMT, /* era date format string */ + ERA_D_T_FMT, /* era date and time format string */ + ERA_T_FMT, /* era time format string */ + ALT_DIGITS, /* alternative symbols for digits */ + + RADIXCHAR, /* radix char */ + THOUSEP, /* separator for thousands */ + + YESEXPR, /* affirmative response expression */ + NOEXPR, /* negative response expression */ + + CRNCYSTR, /* currency symbol */ + + _NL_LANGINFO_LAST +}; + +__BEGIN_DECLS + +extern char* nl_langinfo(nl_item item); + +__END_DECLS + + +#endif /* _LANGINFO_H_ */ diff --git a/headers/posix/locale.h b/headers/posix/locale.h index 619cd4894a..f18784e8df 100644 --- a/headers/posix/locale.h +++ b/headers/posix/locale.h @@ -1,6 +1,6 @@ #ifndef _LOCALE_H_ #define _LOCALE_H_ -/* +/* ** Distributed under the terms of the OpenBeOS License. */ @@ -25,6 +25,12 @@ struct lconv { char n_sep_by_space; char p_sign_posn; char n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; }; #define LC_ALL 0 @@ -34,6 +40,11 @@ struct lconv { #define LC_NUMERIC 4 #define LC_TIME 5 #define LC_MESSAGES 6 +/* + * the values above must be kept in loopable order (i.e. strictly increasing + * with no holes) and in sync with the value below + */ +#define LC_LAST LC_MESSAGES #ifdef __cplusplus extern "C" { diff --git a/headers/posix/monetary.h b/headers/posix/monetary.h new file mode 100644 index 0000000000..0576481642 --- /dev/null +++ b/headers/posix/monetary.h @@ -0,0 +1,22 @@ +/* + * Copyright 2010, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _MONETARY_H_ +#define _MONETARY_H_ + + +#include +#include +#include +#include + + +__BEGIN_DECLS + +extern ssize_t strfmon(char* s, size_t maxsize, const char* format, ...); + +__END_DECLS + + +#endif /* _MONETARY_H_ */ diff --git a/headers/posix/nl_types.h b/headers/posix/nl_types.h new file mode 100644 index 0000000000..f62b93a082 --- /dev/null +++ b/headers/posix/nl_types.h @@ -0,0 +1,28 @@ +/* + * Copyright 2010, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _NL_TYPES_H_ +#define _NL_TYPES_H_ + + +#include + + +#define NL_SETD 0 +#define NL_CAT_LOCALE 1 + +typedef int nl_item; +typedef void* nl_catd; + +__BEGIN_DECLS + +extern nl_catd catopen(const char *name, int oflag); +extern char* catgets(nl_catd cat, int setID, int msgID, + const char *defaultMessage); +extern int catclose(nl_catd cat); + +__END_DECLS + + +#endif /* _NL_TYPES_H_ */ diff --git a/headers/posix/wchar.h b/headers/posix/wchar.h index 9dce19dd31..f9ab3513e6 100644 --- a/headers/posix/wchar.h +++ b/headers/posix/wchar.h @@ -36,6 +36,12 @@ typedef struct { #define WCHAR_MIN 0x00000000UL #define WCHAR_MAX 0x7FFFFFFFUL +/* + * Haiku is always using UTF32 in wchars, other encodings can be handled + * by converting to/from wchar by means of mbsrtowcs() or wcsrtombs(). + * TODO: define __STDC_ISO_10646__ accordingly in our compilers. + */ + #ifdef __cplusplus extern "C" { diff --git a/headers/posix/wctype.h b/headers/posix/wctype.h index 1abdd40486..9ae5828753 100644 --- a/headers/posix/wctype.h +++ b/headers/posix/wctype.h @@ -8,7 +8,7 @@ #include -typedef const int *wctrans_t; +typedef int wctrans_t; #ifdef __cplusplus extern "C" { @@ -28,7 +28,7 @@ extern int iswupper(wint_t wc); extern int iswxdigit(wint_t wc); extern int iswctype(wint_t wc, wctype_t charClass); -extern wint_t towctrans(wint_t wc, wctrans_t charClass); +extern wint_t towctrans(wint_t wc, wctrans_t transition); extern wint_t towlower(wint_t wc); extern wint_t towupper(wint_t wc); diff --git a/headers/private/libroot/locale/ICUCategoryData.h b/headers/private/libroot/locale/ICUCategoryData.h new file mode 100644 index 0000000000..1c325a8d06 --- /dev/null +++ b/headers/private/libroot/locale/ICUCategoryData.h @@ -0,0 +1,53 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_CATEGORY_DATA_H +#define _ICU_CATEGORY_DATA_H + + +#include +#include +#include + +#include + + +namespace BPrivate { + + +class ICUCategoryData { +public: + ICUCategoryData(); + virtual ~ICUCategoryData(); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + const char * PosixLocaleName() + { return fPosixLocaleName; } + +protected: + status_t _ConvertUnicodeStringToLocaleconvEntry( + const UnicodeString& string, + char* destination, int destinationSize, + const char* defaultValue = ""); + + static const uint16 skMaxPosixLocaleNameLen = 128; + static const size_t skLCBufSize = 16; + + Locale fLocale; + UConverter* fConverter; + char fPosixLocaleName[skMaxPosixLocaleNameLen]; + char fGivenCharset[UCNV_MAX_CONVERTER_NAME_LENGTH]; + +private: + status_t _SetupConverter(); +}; + + +} // namespace BPrivate + + +#endif // _ICU_CATEGORY_DATA_H diff --git a/headers/private/libroot/locale/ICUCollateData.h b/headers/private/libroot/locale/ICUCollateData.h new file mode 100644 index 0000000000..284b840874 --- /dev/null +++ b/headers/private/libroot/locale/ICUCollateData.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_COLLATE_DATA_H +#define _ICU_COLLATE_DATA_H + + +#include "ICUCategoryData.h" + +#include + + +namespace BPrivate { + + +class ICUCollateData : public ICUCategoryData { + typedef ICUCategoryData inherited; + +public: + ICUCollateData(); + virtual ~ICUCollateData(); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + status_t Strcoll(const char* a, const char* b, int& out); + status_t Strxfrm(char* out, const char* in, size_t size, + size_t& outSize); + +private: + status_t _ToUnicodeString(const char* in, + UnicodeString& out); + + Collator* fCollator; +}; + + +} // namespace BPrivate + + +#endif // _ICU_COLLATE_DATA_H diff --git a/headers/private/libroot/locale/ICUCtypeData.h b/headers/private/libroot/locale/ICUCtypeData.h new file mode 100644 index 0000000000..38d91f2973 --- /dev/null +++ b/headers/private/libroot/locale/ICUCtypeData.h @@ -0,0 +1,46 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_CTYPE_DATA_H +#define _ICU_CTYPE_DATA_H + + +#include "ICUCategoryData.h" +#include "LocaleBackend.h" + + +namespace BPrivate { + + +class ICUCtypeData : public ICUCategoryData { + typedef ICUCategoryData inherited; +public: + ICUCtypeData(); + virtual ~ICUCtypeData(); + + void Initialize(LocaleCtypeDataBridge* dataBridge); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + int IsWCType(wint_t wc, wctype_t charClass); + status_t ToWCTrans(wint_t wc, wctrans_t transition, + wint_t& result); + + const char* GetLanginfo(int index); + +private: + unsigned short fClassInfo[256]; + int fToLowerMap[256]; + int fToUpperMap[256]; + + LocaleCtypeDataBridge* fDataBridge; +}; + + +} // namespace BPrivate + + +#endif // _ICU_CTYPE_DATA_H diff --git a/headers/private/libroot/locale/ICULocaleBackend.h b/headers/private/libroot/locale/ICULocaleBackend.h new file mode 100644 index 0000000000..bd19899281 --- /dev/null +++ b/headers/private/libroot/locale/ICULocaleBackend.h @@ -0,0 +1,74 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_LOCALE_BACKEND_H +#define _ICU_LOCALE_BACKEND_H + + +#include "LocaleBackend.h" + +#include +#include + +#include "ICUCollateData.h" +#include "ICUCtypeData.h" +#include "ICUMessagesData.h" +#include "ICUMonetaryData.h" +#include "ICUNumericData.h" +#include "ICUTimeData.h" + + +namespace BPrivate { + + +class ICULocaleBackend : public LocaleBackend { +public: + ICULocaleBackend(); + virtual ~ICULocaleBackend(); + + virtual void Initialize(LocaleDataBridge* dataBridge); + + virtual const char* SetLocale(int category, + const char* posixLocaleName); + virtual const struct lconv* LocaleConv(); + virtual const struct lc_time_t* LCTimeInfo(); + + virtual int IsWCType(wint_t wc, wctype_t charClass); + virtual status_t ToWCTrans(wint_t wc, wctrans_t transition, + wint_t& result); + + virtual const char* GetLanginfo(int index); + + virtual status_t Strcoll(const char* a, const char* b, int& out); + virtual status_t Strxfrm(char* out, const char* in, size_t size, + size_t& outSize); + +private: + const char* _QueryLocale(int category); + const char* _SetPosixLocale(int category); + + // buffer for locale names (up to one per category) + char fLocaleDescription[512]; + + // data containers + struct lconv fLocaleConv; + struct lc_time_t fLCTimeInfo; + + // these work on the data containers above + ICUCollateData fCollateData; + ICUCtypeData fCtypeData; + ICUMessagesData fMessagesData; + ICUMonetaryData fMonetaryData; + ICUNumericData fNumericData; + ICUTimeData fTimeData; + + // static posix langinfo data + const char** fPosixLanginfo; +}; + + +} // namespace BPrivate + + +#endif // _ICU_LOCALE_BACKEND_H diff --git a/headers/private/libroot/locale/ICULocaleconvData.h b/headers/private/libroot/locale/ICULocaleconvData.h new file mode 100644 index 0000000000..35606d3bd8 --- /dev/null +++ b/headers/private/libroot/locale/ICULocaleconvData.h @@ -0,0 +1,33 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_LOCALECONV_DATA_H +#define _ICU_LOCALECONV_DATA_H + + +#include "ICUCategoryData.h" + +#include + + +namespace BPrivate { + + +typedef DecimalFormatSymbols::ENumberFormatSymbol FormatSymbol; + +class ICULocaleconvData : public ICUCategoryData { + typedef ICUCategoryData inherited; + +protected: + status_t _SetLocaleconvEntry( + const DecimalFormatSymbols* formatSymbols, + char* destination, FormatSymbol symbol, + const char* defaultValue = ""); +}; + + +} // namespace BPrivate + + +#endif // _ICU_LOCALECONV_DATA_H diff --git a/headers/private/libroot/locale/ICUMessagesData.h b/headers/private/libroot/locale/ICUMessagesData.h new file mode 100644 index 0000000000..fe8c5e52a7 --- /dev/null +++ b/headers/private/libroot/locale/ICUMessagesData.h @@ -0,0 +1,39 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_MESSAGES_DATA_H +#define _ICU_MESSAGES_DATA_H + + +#include "ICUCategoryData.h" +#include "LocaleBackend.h" + + +namespace BPrivate { + + +class ICUMessagesData : public ICUCategoryData { + typedef ICUCategoryData inherited; +public: + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + void Initialize( + LocaleMessagesDataBridge* dataBridge); + + const char* GetLanginfo(int index); + +private: + char fYesExpression[80]; + char fNoExpression[80]; + + const char** fPosixLanginfo; +}; + + +} // namespace BPrivate + + +#endif // _ICU_MESSAGES_DATA_H diff --git a/headers/private/libroot/locale/ICUMonetaryData.h b/headers/private/libroot/locale/ICUMonetaryData.h new file mode 100644 index 0000000000..ded34d54e5 --- /dev/null +++ b/headers/private/libroot/locale/ICUMonetaryData.h @@ -0,0 +1,69 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_MONETARY_DATA_H +#define _ICU_MONETARY_DATA_H + + +#include "ICULocaleconvData.h" +#include "LocaleBackend.h" + +#include + + +namespace BPrivate { + + +class ICUMonetaryData : public ICULocaleconvData { + typedef ICULocaleconvData inherited; +public: + static const int32 kParenthesesAroundCurrencyAndValue = 0; + static const int32 kSignPrecedesCurrencyAndValue = 1; + static const int32 kSignSucceedsCurrencyAndValue = 2; + static const int32 kSignImmediatelyPrecedesCurrency = 3; + static const int32 kSignImmediatelySucceedsCurrency = 4; + + ICUMonetaryData(struct lconv& localeConv); + + void Initialize( + LocaleMonetaryDataBridge* dataBridge); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + const char* GetLanginfo(int index); + +private: + static const int32 kCsPrecedesFlag = 1 << 0; + static const int32 kSepBySpaceFlag = 1 << 1; + + int32 _DetermineCurrencyPosAndSeparator( + const UnicodeString& prefix, + const UnicodeString& suffix, + const UnicodeString& signSymbol, + const UnicodeString& currencySymbol, + UChar& currencySeparatorChar); + int32 _DetermineSignPos(const UnicodeString& prefix, + const UnicodeString& suffix, + const UnicodeString& signSymbol, + const UnicodeString& currencySymbol); + + char fDecimalPoint[skLCBufSize]; + char fThousandsSep[skLCBufSize]; + char fGrouping[skLCBufSize]; + char fIntCurrSymbol[skLCBufSize]; + char fCurrencySymbol[skLCBufSize]; + char fPositiveSign[skLCBufSize]; + char fNegativeSign[skLCBufSize]; + + struct lconv& fLocaleConv; + const struct lconv* fPosixLocaleConv; +}; + + +} // namespace BPrivate + + +#endif // _ICU_MONETARY_DATA_H diff --git a/headers/private/libroot/locale/ICUNumericData.h b/headers/private/libroot/locale/ICUNumericData.h new file mode 100644 index 0000000000..723f393f80 --- /dev/null +++ b/headers/private/libroot/locale/ICUNumericData.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_NUMERIC_DATA_H +#define _ICU_NUMERIC_DATA_H + + +#include "ICULocaleconvData.h" +#include "LocaleBackend.h" + + +namespace BPrivate { + + +class ICUNumericData : public ICULocaleconvData { + typedef ICULocaleconvData inherited; + +public: + ICUNumericData(struct lconv& localeConv); + + void Initialize(LocaleNumericDataBridge* dataBridge); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + virtual const char* GetLanginfo(int index); + +private: + char fDecimalPoint[skLCBufSize]; + char fThousandsSep[skLCBufSize]; + char fGrouping[skLCBufSize]; + + struct lconv& fLocaleConv; + LocaleNumericDataBridge* fDataBridge; +}; + + +} // namespace BPrivate + + +#endif // _ICU_NUMERIC_DATA_H diff --git a/headers/private/libroot/locale/ICUTimeData.h b/headers/private/libroot/locale/ICUTimeData.h new file mode 100644 index 0000000000..b8647956fe --- /dev/null +++ b/headers/private/libroot/locale/ICUTimeData.h @@ -0,0 +1,62 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ICU_TIME_DATA_H +#define _ICU_TIME_DATA_H + + +#include "ICUCategoryData.h" +#include "LocaleBackend.h" + +#include + +#include + + +namespace BPrivate { + + +class ICUTimeData : public ICUCategoryData { + typedef ICUCategoryData inherited; +public: + ICUTimeData(struct lc_time_t& lcTimeInfo); + + void Initialize(LocaleTimeDataBridge* dataBridge); + + virtual status_t SetTo(const Locale& locale, + const char* posixLocaleName); + virtual status_t SetToPosix(); + + const char* GetLanginfo(int index); + +private: + status_t _SetLCTimeEntries(const UnicodeString* strings, + char* destination, int entrySize, + int count, int maxCount); + status_t _SetLCTimePattern(DateFormat* format, + char* destination, int destinationSize); + + char fMon[12][24]; + char fMonth[12][64]; + char fWday[7][24]; + char fWeekday[7][64]; + char fTimeFormat[24]; + char fDateFormat[24]; + char fDateTimeFormat[32]; + char fAm[24]; + char fPm[24]; + char fDateTimeZoneFormat[32]; + char fAltMonth[12][64]; + char fMonthDayOrder[4]; + char fAmPmFormat[32]; + + struct lc_time_t& fLCTimeInfo; + const struct lc_time_t* fPosixLCTimeInfo; +}; + + +} // namespace BPrivate + + +#endif // _ICU_TIME_DATA_H diff --git a/headers/private/libroot/locale/LocaleBackend.h b/headers/private/libroot/locale/LocaleBackend.h new file mode 100644 index 0000000000..b12de25e9d --- /dev/null +++ b/headers/private/libroot/locale/LocaleBackend.h @@ -0,0 +1,111 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _LOCALE_BACKEND_H +#define _LOCALE_BACKEND_H + + +#include + +#include + + +struct lconv; +struct lc_time_t; + + +namespace BPrivate { + + +struct LocaleCtypeDataBridge { + const unsigned short** addrOfClassInfoTable; + const int** addrOfToLowerTable; + const int** addrOfToUpperTable; + + const unsigned short* posixClassInfo; + const int* posixToLowerMap; + const int* posixToUpperMap; + + LocaleCtypeDataBridge(); +}; + + +struct LocaleMessagesDataBridge { + const char** posixLanginfo; + + LocaleMessagesDataBridge(); +}; + + +struct LocaleMonetaryDataBridge { + const struct lconv* posixLocaleConv; + + LocaleMonetaryDataBridge(); +}; + + +struct LocaleNumericDataBridge { + const char** addrOfGlibcDecimalPoint; + const char** addrOfGlibcThousandsSep; + const char** addrOfGlibcGrouping; + uint32_t* addrOfGlibcWCDecimalPoint; + uint32_t* addrOfGlibcWCThousandsSep; + const struct lconv* posixLocaleConv; + + LocaleNumericDataBridge(); +}; + + +struct LocaleTimeDataBridge { + const struct lc_time_t* posixLCTimeInfo; + + LocaleTimeDataBridge(); +}; + + +struct LocaleDataBridge { + LocaleCtypeDataBridge ctypeDataBridge; + LocaleMessagesDataBridge messagesDataBridge; + LocaleMonetaryDataBridge monetaryDataBridge; + LocaleNumericDataBridge numericDataBridge; + LocaleTimeDataBridge timeDataBridge; + const char** posixLanginfo; + + LocaleDataBridge(); +}; + + +class LocaleBackend { +public: + LocaleBackend(); + virtual ~LocaleBackend(); + + virtual const char* SetLocale(int category, const char* locale) = 0; + virtual const struct lconv* LocaleConv() = 0; + virtual const struct lc_time_t* LCTimeInfo() = 0; + + virtual int IsWCType(wint_t wc, wctype_t charClass) = 0; + virtual status_t ToWCTrans(wint_t wc, wctrans_t transition, + wint_t& result) = 0; + + virtual const char* GetLanginfo(int index) = 0; + + virtual status_t Strcoll(const char* a, const char* b, + int& out) = 0; + virtual status_t Strxfrm(char* out, const char* in, size_t size, + size_t& outSize) = 0; + + virtual void Initialize(LocaleDataBridge* dataBridge) = 0; + + static status_t LoadBackend(); +}; + + +extern LocaleBackend* gLocaleBackend; + + +} // namespace BPrivate + + +#endif // _LOCALE_BACKEND_H diff --git a/headers/private/libroot/locale/PosixCtype.h b/headers/private/libroot/locale/PosixCtype.h new file mode 100644 index 0000000000..9dfa51e83c --- /dev/null +++ b/headers/private/libroot/locale/PosixCtype.h @@ -0,0 +1,20 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _POSIX_CTYPE_H +#define _POSIX_CTYPE_H + + +namespace BPrivate { + + +extern const unsigned short gPosixClassInfo[256]; +extern const int gPosixToLowerMap[256]; +extern const int gPosixToUpperMap[256]; + + +} // namespace BPrivate + + +#endif // _POSIX_CTYPE_H diff --git a/headers/private/libroot/locale/PosixLanginfo.h b/headers/private/libroot/locale/PosixLanginfo.h new file mode 100644 index 0000000000..42bf2d8181 --- /dev/null +++ b/headers/private/libroot/locale/PosixLanginfo.h @@ -0,0 +1,18 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _POSIX_LANGINFO_H +#define _POSIX_LANGINFO_H + + +namespace BPrivate { + + +extern const char* gPosixLanginfo[]; + + +} // namespace BPrivate + + +#endif // _POSIX_LANGINFO_H diff --git a/headers/private/libroot/locale/PosixLocaleConv.h b/headers/private/libroot/locale/PosixLocaleConv.h new file mode 100644 index 0000000000..5c27ce5662 --- /dev/null +++ b/headers/private/libroot/locale/PosixLocaleConv.h @@ -0,0 +1,21 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _POSIX_LOCALE_CONV_H +#define _POSIX_LOCALE_CONV_H + + +#include + + +namespace BPrivate { + + +extern struct lconv gPosixLocaleConv; + + +} // namespace BPrivate + + +#endif // _POSIX_LOCALE_CONV_H diff --git a/headers/private/libroot/time/PosixLCTimeInfo.h b/headers/private/libroot/time/PosixLCTimeInfo.h new file mode 100644 index 0000000000..8819bb3356 --- /dev/null +++ b/headers/private/libroot/time/PosixLCTimeInfo.h @@ -0,0 +1,21 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _POSIX_LC_TIME_INFO_H +#define _POSIX_LC_TIME_INFO_H + + +#include + + +namespace BPrivate { + + +extern const struct lc_time_t gPosixLCTimeInfo; + + +} // namespace BPrivate + + +#endif // _POSIX_LC_TIME_INFO_H diff --git a/src/system/libroot/posix/time/timelocal.h b/headers/private/libroot/time/timelocal.h similarity index 79% rename from src/system/libroot/posix/time/timelocal.h rename to headers/private/libroot/time/timelocal.h index ebd9cd0f5f..5e5983443f 100644 --- a/src/system/libroot/posix/time/timelocal.h +++ b/headers/private/libroot/time/timelocal.h @@ -25,31 +25,36 @@ * * $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdtime/timelocal.h,v 1.11 2002/01/24 15:07:44 phantom Exp $ */ - #ifndef _TIMELOCAL_H_ #define _TIMELOCAL_H_ + +#include + + /* * Private header file for the strftime and strptime localization * stuff. */ -struct lc_time_T { - const char *mon[12]; - const char *month[12]; - const char *wday[7]; - const char *weekday[7]; - const char *X_fmt; - const char *x_fmt; - const char *c_fmt; - const char *am; - const char *pm; - const char *date_fmt; - const char *alt_month[12]; - const char *md_order; - const char *ampm_fmt; +struct lc_time_t { + const char* mon[12]; + const char* month[12]; + const char* wday[7]; + const char* weekday[7]; + const char* X_fmt; + const char* x_fmt; + const char* c_fmt; + const char* am; + const char* pm; + const char* date_fmt; + const char* alt_month[12]; + const char* md_order; + const char* ampm_fmt; }; -struct lc_time_T *__get_current_time_locale(void); -int __time_load_locale(const char *); +__BEGIN_DECLS +const struct lc_time_t* __get_current_time_locale(void); +__END_DECLS + #endif /* !_TIMELOCAL_H_ */ diff --git a/headers/private/locale/langinfo.h b/headers/private/locale/langinfo.h deleted file mode 100644 index 0bea057cec..0000000000 --- a/headers/private/locale/langinfo.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _LANGINFO_H_ -#define _LANGINFO_H_ - -#include -#include - -#define CODESET B_CODESET /* codeset name */ -#define D_T_FMT B_DATE_TIME_FORMAT /* string for formatting date and time */ -#define D_FMT B_DATE_FORMAT /* date format string */ -#define T_FMT B_TIME_FORMAT /* time format string */ -#define T_FMT_AMPM B_AM_PM_TIME_FORMAT /* a.m. or p.m. time formatting string */ -#define AM_STR B_AM_STRING /* Ante Meridian affix */ -#define PM_STR B_PM_STRING /* Post Meridian affix */ - -/* week day names */ -#define DAY_1 B_DAY_1 -#define DAY_2 B_DAY_2 -#define DAY_3 B_DAY_3 -#define DAY_4 B_DAY_4 -#define DAY_5 B_DAY_5 -#define DAY_6 B_DAY_6 -#define DAY_7 B_DAY_7 - -/* abbreviated week day names */ -#define ABDAY_1 B_AB_DAY_1 -#define ABDAY_2 B_AB_DAY_2 -#define ABDAY_3 B_AB_DAY_3 -#define ABDAY_4 B_AB_DAY_4 -#define ABDAY_5 B_AB_DAY_5 -#define ABDAY_6 B_AB_DAY_6 -#define ABDAY_7 B_AB_DAY_7 - -/* month names */ -#define MON_1 B_MON_1 -#define MON_2 B_MON_2 -#define MON_3 B_MON_3 -#define MON_4 B_MON_4 -#define MON_5 B_MON_5 -#define MON_6 B_MON_6 -#define MON_7 B_MON_7 -#define MON_8 B_MON_8 -#define MON_9 B_MON_9 -#define MON_10 B_MON_10 -#define MON_11 B_MON_11 -#define MON_12 B_MON_12 - -/* abbreviated month names */ -#define ABMON_1 B_AB_MON_1 -#define ABMON_2 B_AB_MON_2 -#define ABMON_3 B_AB_MON_3 -#define ABMON_4 B_AB_MON_4 -#define ABMON_5 B_AB_MON_5 -#define ABMON_6 B_AB_MON_6 -#define ABMON_7 B_AB_MON_7 -#define ABMON_8 B_AB_MON_8 -#define ABMON_9 B_AB_MON_9 -#define ABMON_10 B_AB_MON_10 -#define ABMON_11 B_AB_MON_11 -#define ABMON_12 B_AB_MON_12 - -#define ERA B_ERA /* era description segments */ -#define ERA_D_FMT B_ERA_DATE_FORMAT /* era date format string */ -#define ERA_D_T_FMT B_ERA_DATE_TIME_FORMAT /* era date and time format string */ -#define ERA_T_FMT B_TIME_FORMAT /* era time format string */ -#define ALT_DIGITS B_ALT_DIGITS /* alternative symbols for digits */ - -#define RADIXCHAR B_DECIMAL_POINT /* radix char */ -#define THOUSEP B_THOUSANDS_SEPARATOR /* separator for thousands */ - -#define YESEXPR B_YES_EXPRESSION /* affirmative response expression */ -#define NOEXPR B_NO_EXPRESSION /* negative response expression */ -#define YESSTR B_YES_STRING /* affirmative response for yes/no queries */ -#define NOSTR B_NO_STRING /* negative response for yes/no queries */ - -#define CRNCYSTR B_CURRENCY_SYMBOL /* currency symbol */ - -//#define D_MD_ORDER 57 /* month/day order (local extension) */ - -#ifdef __cplusplus -extern "C" -#endif -char *nl_langinfo(nl_item); - -#endif /* _LANGINFO_H_ */ diff --git a/headers/private/locale/monetary.h b/headers/private/locale/monetary.h deleted file mode 100644 index 92f32528a9..0000000000 --- a/headers/private/locale/monetary.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _MONETARY_H_ -#define _MONETARY_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ssize_t strfmon(char *string, size_t maxSize, const char *format, ...); -ssize_t vstrfmon(char *string, size_t maxSize, const char *format, va_list args); - -#ifdef __cplusplus -} -#endif - -#endif /* _MONETARY_H_ */ diff --git a/headers/private/locale/nl_types.h b/headers/private/locale/nl_types.h deleted file mode 100644 index 78dc9c2f3c..0000000000 --- a/headers/private/locale/nl_types.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Distributed under the terms of the MIT License. - */ -#ifndef _NL_TYPES_H_ -#define _NL_TYPES_H_ - - -#define NL_SETD 0 -#define NL_CAT_LOCALE 1 - -typedef int nl_item; -typedef void *nl_catd; - -#ifdef __cplusplus -extern "C" { -#endif - -extern nl_catd catopen(const char *name, int oflag); -extern char *catgets(nl_catd cat, int setID, int msgID, const char *defaultMessage); -extern int catclose(nl_catd cat); - -#ifdef __cplusplus -} -#endif - -#endif /* _NL_TYPES_H_ */ diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 4d719e7bbd..69b2005f23 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src system boot ; local librootFunctions = abs.o ctype.o + LocaleData.o qsort.o kernel_vsprintf.o memcmp.o diff --git a/src/system/kernel/lib/Jamfile b/src/system/kernel/lib/Jamfile index d82abe70e5..7ac30bcb68 100644 --- a/src/system/kernel/lib/Jamfile +++ b/src/system/kernel/lib/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src system kernel lib ; UsePrivateHeaders shared ; +UsePrivateHeaders [ FDirName libroot locale ] ; # kernel libroot os files @@ -41,8 +42,9 @@ KernelMergeObject kernel_lib_posix.o : poll.c utime.c # locale - ctype.c - localeconv.c + ctype.cpp + localeconv.cpp + LocaleData.cpp # stdio (this subdir) kernel_vsprintf.cpp # stdlib diff --git a/src/system/libroot/Jamfile b/src/system/libroot/Jamfile index 3e56ff2c3b..cd2d069505 100644 --- a/src/system/libroot/Jamfile +++ b/src/system/libroot/Jamfile @@ -30,7 +30,6 @@ local librootObjects = posix_gnu_stdlib.o posix_gnu_string.o posix_gnu_wcsmbs.o - posix_gnu_wctype.o posix_stdlib.o posix_string.o posix_string_arch_$(TARGET_ARCH).o @@ -92,5 +91,6 @@ if $(TARGET_PLATFORM) = haiku { } +SubInclude HAIKU_TOP src system libroot add-ons ; SubInclude HAIKU_TOP src system libroot os ; SubInclude HAIKU_TOP src system libroot posix ; diff --git a/src/system/libroot/add-ons/Jamfile b/src/system/libroot/add-ons/Jamfile new file mode 100644 index 0000000000..2e29e7a902 --- /dev/null +++ b/src/system/libroot/add-ons/Jamfile @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src system libroot add-ons ; + +SubInclude HAIKU_TOP src system libroot add-ons icu ; diff --git a/src/system/libroot/add-ons/icu/Jamfile b/src/system/libroot/add-ons/icu/Jamfile new file mode 100644 index 0000000000..b43ff2d977 --- /dev/null +++ b/src/system/libroot/add-ons/icu/Jamfile @@ -0,0 +1,14 @@ +SubDir HAIKU_TOP src system libroot add-ons icu ; + +local addonIcuObjects = + addon_icu_locale.o +; + +SharedLibrary libroot-addon-icu.so + : + : + $(addonIcuObjects:G=nogrist) + $(TARGET_LIBSTDC++) $(HAIKU_ICU_LIBS) +; + +SubInclude HAIKU_TOP src system libroot add-ons icu locale ; diff --git a/src/system/libroot/add-ons/icu/locale/ICUCategoryData.cpp b/src/system/libroot/add-ons/icu/locale/ICUCategoryData.cpp new file mode 100644 index 0000000000..11c626750e --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUCategoryData.cpp @@ -0,0 +1,133 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUCategoryData.h" + +#include + +#include + + +namespace BPrivate { + + +ICUCategoryData::ICUCategoryData() + : + fConverter(NULL) +{ + *fPosixLocaleName = '\0'; + *fGivenCharset = '\0'; +} + + +ICUCategoryData::~ICUCategoryData() +{ + if (fConverter) + ucnv_close(fConverter); +} + + +status_t +ICUCategoryData::_SetupConverter() +{ + if (fConverter != NULL) { + ucnv_close(fConverter); + fConverter = NULL; + } + + UErrorCode icuStatus = U_ZERO_ERROR; + fConverter = ucnv_open(fGivenCharset, &icuStatus); + if (fConverter == NULL) + return B_NAME_NOT_FOUND; + + icuStatus = U_ZERO_ERROR; + ucnv_setToUCallBack(fConverter, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, + NULL, &icuStatus); + icuStatus = U_ZERO_ERROR; + ucnv_setFromUCallBack(fConverter, UCNV_FROM_U_CALLBACK_STOP, NULL, NULL, + NULL, &icuStatus); + if (!U_SUCCESS(icuStatus)) + return B_ERROR; + + return B_OK; +} + + +status_t +ICUCategoryData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + if (!posixLocaleName) + return B_BAD_VALUE; + + fLocale = locale; + strlcpy(fPosixLocaleName, posixLocaleName, skMaxPosixLocaleNameLen); + *fGivenCharset = '\0'; + + // POSIX locales often contain an embedded charset, but ICU does not + // handle these within locales (that part of the name is simply + // ignored). + // We need to fetch the charset specification and lookup an appropriate + // ICU charset converter. This converter will later be used to get info + // about ctype properties. + const char* charsetStart = strchr(fPosixLocaleName, '.'); + if (charsetStart) { + ++charsetStart; + int l = 0; + while (charsetStart[l] != '\0' && charsetStart[l] != '@') + ++l; + snprintf(fGivenCharset, UCNV_MAX_CONVERTER_NAME_LENGTH, "%.*s", l, + charsetStart); + } + if (!strlen(fGivenCharset)) + strcpy(fGivenCharset, "utf-8"); + + return _SetupConverter(); +} + + +status_t +ICUCategoryData::SetToPosix() +{ + fLocale = Locale::createFromName("en_US_POSIX"); + strcpy(fPosixLocaleName, "POSIX"); + strcpy(fGivenCharset, "US-ASCII"); + + return _SetupConverter(); +} + + +status_t +ICUCategoryData::_ConvertUnicodeStringToLocaleconvEntry( + const UnicodeString& string, char* destination, int destinationSize, + const char* defaultValue) +{ + status_t result = B_OK; + UErrorCode icuStatus = U_ZERO_ERROR; + + ucnv_fromUChars(fConverter, destination, destinationSize, + string.getBuffer(), string.length(), &icuStatus); + if (!U_SUCCESS(icuStatus)) { + switch (icuStatus) { + case U_BUFFER_OVERFLOW_ERROR: + result = B_NAME_TOO_LONG; + break; + case U_INVALID_CHAR_FOUND: + case U_TRUNCATED_CHAR_FOUND: + case U_ILLEGAL_CHAR_FOUND: + result = B_BAD_DATA; + break; + default: + result = B_ERROR; + break; + } + strcpy(destination, defaultValue); + } + + return result; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUCollateData.cpp b/src/system/libroot/add-ons/icu/locale/ICUCollateData.cpp new file mode 100644 index 0000000000..7789e9b64e --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUCollateData.cpp @@ -0,0 +1,176 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUCollateData.h" + +#include + +#include + + +namespace BPrivate { + + +ICUCollateData::ICUCollateData() + : + fCollator(NULL) +{ +} + + +ICUCollateData::~ICUCollateData() +{ + delete fCollator; +} + + +status_t +ICUCollateData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + + if (result == B_OK) { + UErrorCode icuStatus = U_ZERO_ERROR; + delete fCollator; + fCollator = Collator::createInstance(fLocale, icuStatus); + if (!U_SUCCESS(icuStatus)) + return B_NO_MEMORY; + } + + return result; +} + + +status_t +ICUCollateData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + if (result == B_OK) { + delete fCollator; + fCollator = NULL; + } + + return result; +} + + +status_t +ICUCollateData::Strcoll(const char* a, const char* b, int& result) +{ + if (strcmp(fPosixLocaleName, "POSIX") == 0) { + // handle POSIX here as the collator ICU uses for that (english) is + // incompatible in too many ways + result = strcmp(a, b); + for (const char* aIter = a; *aIter != 0; ++aIter) { + if (*aIter < 0) + return B_BAD_VALUE; + } + for (const char* bIter = b; *bIter != 0; ++bIter) { + if (*bIter < 0) + return B_BAD_VALUE; + } + return B_OK; + } + + status_t status = B_OK; + UErrorCode icuStatus = U_ZERO_ERROR; + + if (strcasecmp(fGivenCharset, "utf-8") == 0) { + UCharIterator aIter, bIter; + uiter_setUTF8(&aIter, a, -1); + uiter_setUTF8(&bIter, b, -1); + + result = fCollator->compare(aIter, bIter, icuStatus); + } else { + UnicodeString unicodeA; + UnicodeString unicodeB; + + if (_ToUnicodeString(a, unicodeA) != B_OK + || _ToUnicodeString(b, unicodeB) != B_OK) { + status = B_BAD_VALUE; + } + + result = fCollator->compare(unicodeA, unicodeB, icuStatus); + } + + if (!U_SUCCESS(icuStatus)) + status = B_BAD_VALUE; + + return status; +} + + +status_t +ICUCollateData::Strxfrm(char* out, const char* in, size_t size, size_t& outSize) +{ + if (strcmp(fPosixLocaleName, "POSIX") == 0) { + // handle POSIX here as the collator ICU uses for that (english) is + // incompatible in too many ways + outSize = strlcpy(out, in, size); + for (const char* inIter = in; *inIter != 0; ++inIter) { + if (*inIter < 0) + return B_BAD_VALUE; + } + return B_OK; + } + + if (in == NULL) { + outSize = 0; + return B_OK; + } + + UErrorCode icuStatus = U_ZERO_ERROR; + + UnicodeString unicodeIn; + if (_ToUnicodeString(in, unicodeIn) != B_OK) + return B_BAD_VALUE; + + outSize = fCollator->getSortKey(unicodeIn, (uint8_t*)out, size); + if (!U_SUCCESS(icuStatus)) + return B_BAD_VALUE; + + return B_OK; +} + + +status_t +ICUCollateData::_ToUnicodeString(const char* in, UnicodeString& out) +{ + out.remove(); + + if (in == NULL) + return B_OK; + + size_t inLen = strlen(in); + if (inLen == 0) + return B_OK; + + UErrorCode icuStatus = U_ZERO_ERROR; + int32_t outLen = ucnv_toUChars(fConverter, NULL, 0, in, inLen, &icuStatus); + if (icuStatus != U_BUFFER_OVERFLOW_ERROR) + return B_BAD_VALUE; + if (outLen < 0) + return B_ERROR; + if (outLen == 0) + return B_OK; + + UChar* outBuf = out.getBuffer(outLen + 1); + icuStatus = U_ZERO_ERROR; + outLen + = ucnv_toUChars(fConverter, outBuf, outLen + 1, in, inLen, &icuStatus); + if (!U_SUCCESS(icuStatus)) { + out.releaseBuffer(0); + return B_BAD_VALUE; + } + + out.releaseBuffer(outLen); + + return B_OK; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUCtypeData.cpp b/src/system/libroot/add-ons/icu/locale/ICUCtypeData.cpp new file mode 100644 index 0000000000..432ef1e15a --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUCtypeData.cpp @@ -0,0 +1,186 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUCtypeData.h" + +#include +#include + +#include + + +namespace BPrivate { + + +ICUCtypeData::ICUCtypeData() + : + fDataBridge(NULL) +{ +} + + +ICUCtypeData::~ICUCtypeData() +{ +} + + +void +ICUCtypeData::Initialize(LocaleCtypeDataBridge* dataBridge) +{ + *dataBridge->addrOfClassInfoTable = fClassInfo; + *dataBridge->addrOfToLowerTable = fToLowerMap; + *dataBridge->addrOfToUpperTable = fToUpperMap; + fDataBridge = dataBridge; +} + + +status_t +ICUCtypeData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + if (result != B_OK) + return result; + + UErrorCode icuStatus = U_ZERO_ERROR; + + ucnv_reset(fConverter); + char buffer[] = { 0, 0 }; + for (int i = 0; i < 256; ++i) { + const char* source = buffer; + buffer[0] = (char)i; + buffer[1] = '\0'; + icuStatus = U_ZERO_ERROR; + UChar32 unicodeChar + = ucnv_getNextUChar(fConverter, &source, source + 1, &icuStatus); + + unsigned short classInfo = 0; + unsigned int toLower = i; + unsigned int toUpper = i; + if (U_SUCCESS(icuStatus)) { + if (u_isblank(unicodeChar)) + classInfo |= _ISblank; + if (u_charType(unicodeChar) == U_CONTROL_CHAR) + classInfo |= _IScntrl; + if (u_ispunct(unicodeChar)) + classInfo |= _ISpunct; + if (u_hasBinaryProperty(unicodeChar, UCHAR_POSIX_ALNUM)) + classInfo |= _ISalnum; + if (u_isUUppercase(unicodeChar)) + classInfo |= _ISupper; + if (u_isULowercase(unicodeChar)) + classInfo |= _ISlower; + if (u_isUAlphabetic(unicodeChar)) + classInfo |= _ISalpha; + if (u_isdigit(unicodeChar)) + classInfo |= _ISdigit; + if (u_isxdigit(unicodeChar)) + classInfo |= _ISxdigit; + if (u_isUWhiteSpace(unicodeChar)) + classInfo |= _ISspace; + if (u_hasBinaryProperty(unicodeChar, UCHAR_POSIX_PRINT)) + classInfo |= _ISprint; + if (u_hasBinaryProperty(unicodeChar, UCHAR_POSIX_GRAPH)) + classInfo |= _ISgraph; + + UChar lowerChar = u_tolower(unicodeChar); + icuStatus = U_ZERO_ERROR; + ucnv_fromUChars(fConverter, buffer, 1, &lowerChar, 1, &icuStatus); + if (U_SUCCESS(icuStatus)) + toLower = (unsigned char)buffer[0]; + + UChar upperChar = u_toupper(unicodeChar); + icuStatus = U_ZERO_ERROR; + ucnv_fromUChars(fConverter, buffer, 1, &upperChar, 1, &icuStatus); + if (U_SUCCESS(icuStatus)) + toUpper = (unsigned char)buffer[0]; + } + fClassInfo[i] = classInfo; + fToLowerMap[i] = toLower; + fToUpperMap[i] = toUpper; + } + + return B_OK; +} + + +status_t +ICUCtypeData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + if (result == B_OK) { + memcpy(fClassInfo, fDataBridge->posixClassInfo, sizeof(fClassInfo)); + memcpy(fToLowerMap, fDataBridge->posixToLowerMap, sizeof(fToLowerMap)); + memcpy(fToUpperMap, fDataBridge->posixToUpperMap, sizeof(fToUpperMap)); + } + + return result; +} + + +int +ICUCtypeData::IsWCType(wint_t wc, wctype_t charClass) +{ + switch (charClass) { + case _ISalnum: + return u_hasBinaryProperty(wc, UCHAR_POSIX_ALNUM); + case _ISalpha: + return u_isUAlphabetic(wc); + case _ISblank: + return u_isblank(wc); + case _IScntrl: + return u_charType(wc) == U_CONTROL_CHAR; + case _ISdigit: + return u_isdigit(wc); + case _ISgraph: + return u_hasBinaryProperty(wc, UCHAR_POSIX_GRAPH); + case _ISlower: + return u_isULowercase(wc); + case _ISprint: + return u_hasBinaryProperty(wc, UCHAR_POSIX_PRINT); + case _ISpunct: + return u_ispunct(wc); + case _ISspace: + return u_isUWhiteSpace(wc); + case _ISupper: + return u_isUUppercase(wc); + case _ISxdigit: + return u_isxdigit(wc); + default: + return 0; + } +} + + +status_t +ICUCtypeData::ToWCTrans(wint_t wc, wctrans_t transition, wint_t& result) +{ + switch (transition) { + case _ISlower: + result = u_tolower(wc); + return B_OK; + case _ISupper: + result = u_toupper(wc); + return B_OK; + default: + return B_BAD_VALUE; + } +} + + +const char* +ICUCtypeData::GetLanginfo(int index) +{ + switch(index) { + case CODESET: + return fGivenCharset; + default: + return ""; + } +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICULocaleBackend.cpp b/src/system/libroot/add-ons/icu/locale/ICULocaleBackend.cpp new file mode 100644 index 0000000000..173a12216e --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICULocaleBackend.cpp @@ -0,0 +1,319 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICULocaleBackend.h" + +#include + +#include +#include +#include + + +namespace BPrivate { + + +extern "C" LocaleBackend* +CreateInstance() +{ + return new(std::nothrow) ICULocaleBackend(); +} + + +ICULocaleBackend::ICULocaleBackend() + : + fMonetaryData(fLocaleConv), + fNumericData(fLocaleConv), + fTimeData(fLCTimeInfo) +{ +} + + +ICULocaleBackend::~ICULocaleBackend() +{ +} + + +void +ICULocaleBackend::Initialize(LocaleDataBridge* dataBridge) +{ + fCtypeData.Initialize(&dataBridge->ctypeDataBridge); + fMessagesData.Initialize(&dataBridge->messagesDataBridge); + fMonetaryData.Initialize(&dataBridge->monetaryDataBridge); + fNumericData.Initialize(&dataBridge->numericDataBridge); + fTimeData.Initialize(&dataBridge->timeDataBridge); + + fPosixLanginfo = dataBridge->posixLanginfo; + + _SetPosixLocale(LC_ALL); +} + + +const char* +ICULocaleBackend::SetLocale(int category, const char* posixLocaleName) +{ + if (posixLocaleName == NULL) + return _QueryLocale(category); + + if (strcasecmp(posixLocaleName, "POSIX") == 0 + || strcasecmp(posixLocaleName, "C") == 0) + return _SetPosixLocale(category); + + Locale locale = Locale::createCanonical(posixLocaleName); + switch (category) { + case LC_ALL: + if (fCollateData.SetTo(locale, posixLocaleName) != B_OK + || fCtypeData.SetTo(locale, posixLocaleName) != B_OK + || fMessagesData.SetTo(locale, posixLocaleName) != B_OK + || fMonetaryData.SetTo(locale, posixLocaleName) != B_OK + || fNumericData.SetTo(locale, posixLocaleName) != B_OK + || fTimeData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_COLLATE: + if (fCollateData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_CTYPE: + if (fCtypeData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_MESSAGES: + if (fMessagesData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_MONETARY: + if (fMonetaryData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_NUMERIC: + if (fNumericData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + case LC_TIME: + if (fTimeData.SetTo(locale, posixLocaleName) != B_OK) + return NULL; + break; + default: + // unsupported category + return NULL; + } + + return posixLocaleName; +} + + +const struct lconv* +ICULocaleBackend::LocaleConv() +{ + return &fLocaleConv; +} + + +const struct lc_time_t* +ICULocaleBackend::LCTimeInfo() +{ + return &fLCTimeInfo; +} + + +int +ICULocaleBackend::IsWCType(wint_t wc, wctype_t charClass) +{ + return fCtypeData.IsWCType(wc, charClass); +} + + +status_t +ICULocaleBackend::ToWCTrans(wint_t wc, wctrans_t transition, wint_t& result) +{ + return fCtypeData.ToWCTrans(wc, transition, result); +} + + +const char* +ICULocaleBackend::GetLanginfo(int index) +{ + switch(index) { + case CODESET: + return fCtypeData.GetLanginfo(index); + + case D_T_FMT: + case D_FMT: + case T_FMT: + case T_FMT_AMPM: + case AM_STR: + case PM_STR: + case DAY_1: + case DAY_2: + case DAY_3: + case DAY_4: + case DAY_5: + case DAY_6: + case DAY_7: + case ABDAY_1: + case ABDAY_2: + case ABDAY_3: + case ABDAY_4: + case ABDAY_5: + case ABDAY_6: + case ABDAY_7: + case MON_1: + case MON_2: + case MON_3: + case MON_4: + case MON_5: + case MON_6: + case MON_7: + case MON_8: + case MON_9: + case MON_10: + case MON_11: + case MON_12: + case ABMON_1: + case ABMON_2: + case ABMON_3: + case ABMON_4: + case ABMON_5: + case ABMON_6: + case ABMON_7: + case ABMON_8: + case ABMON_9: + case ABMON_10: + case ABMON_11: + case ABMON_12: + return fTimeData.GetLanginfo(index); + + case ERA: + case ERA_D_FMT: + case ERA_D_T_FMT: + case ERA_T_FMT: + case ALT_DIGITS: + return fPosixLanginfo[index]; + + case RADIXCHAR: + case THOUSEP: + return fNumericData.GetLanginfo(index); + + case YESEXPR: + case NOEXPR: + return fMessagesData.GetLanginfo(index); + + case CRNCYSTR: + return fMonetaryData.GetLanginfo(index); + + default: + return ""; + } +} + + +status_t +ICULocaleBackend::Strcoll(const char* a, const char* b, int& result) +{ + return fCollateData.Strcoll(a, b, result); +} + + +status_t +ICULocaleBackend::Strxfrm(char* out, const char* in, size_t size, + size_t& outSize) +{ + return fCollateData.Strxfrm(out, in, size, outSize); +} + + +const char* +ICULocaleBackend::_QueryLocale(int category) +{ + switch (category) { + case LC_ALL: + { + // if all categories have the same locale, return that + const char* locale = fCollateData.PosixLocaleName(); + if (strcmp(locale, fCtypeData.PosixLocaleName()) == 0 + && strcmp(locale, fMessagesData.PosixLocaleName()) == 0 + && strcmp(locale, fMonetaryData.PosixLocaleName()) == 0 + && strcmp(locale, fNumericData.PosixLocaleName()) == 0 + && strcmp(locale, fTimeData.PosixLocaleName()) == 0) + return locale; + + // build a string with all info (at least glibc does it, too) + snprintf(fLocaleDescription, sizeof(fLocaleDescription), + "LC_COLLATE=%s;LC_CTYPE=%s;LC_MESSAGES=%s;LC_MONETARY=%s;" + "LC_NUMERIC=%s;LC_TIME=%s", + fCollateData.PosixLocaleName(), fCtypeData.PosixLocaleName(), + fMessagesData.PosixLocaleName(), + fMonetaryData.PosixLocaleName(), fNumericData.PosixLocaleName(), + fTimeData.PosixLocaleName()); + return fLocaleDescription; + } + case LC_COLLATE: + return fCollateData.PosixLocaleName(); + case LC_CTYPE: + return fCtypeData.PosixLocaleName(); + case LC_MESSAGES: + return fMessagesData.PosixLocaleName(); + case LC_MONETARY: + return fMonetaryData.PosixLocaleName(); + case LC_NUMERIC: + return fNumericData.PosixLocaleName(); + case LC_TIME: + return fTimeData.PosixLocaleName(); + default: + // unsupported category + return NULL; + } +} + + +const char* +ICULocaleBackend::_SetPosixLocale(int category) +{ + switch (category) { + case LC_ALL: + if (fCollateData.SetToPosix() != B_OK + || fCtypeData.SetToPosix() != B_OK + || fMessagesData.SetToPosix() != B_OK + || fMonetaryData.SetToPosix() != B_OK + || fNumericData.SetToPosix() != B_OK + || fTimeData.SetToPosix() != B_OK) + return NULL; + break; + case LC_COLLATE: + if (fCollateData.SetToPosix() != B_OK) + return NULL; + break; + case LC_CTYPE: + if (fCtypeData.SetToPosix() != B_OK) + return NULL; + break; + case LC_MESSAGES: + if (fMessagesData.SetToPosix() != B_OK) + return NULL; + break; + case LC_MONETARY: + if (fMonetaryData.SetToPosix() != B_OK) + return NULL; + break; + case LC_NUMERIC: + if (fNumericData.SetToPosix() != B_OK) + return NULL; + break; + case LC_TIME: + if (fTimeData.SetToPosix() != B_OK) + return NULL; + break; + default: + // unsupported category + return NULL; + } + + return "POSIX"; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICULocaleconvData.cpp b/src/system/libroot/add-ons/icu/locale/ICULocaleconvData.cpp new file mode 100644 index 0000000000..5bfb2c153e --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICULocaleconvData.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICULocaleconvData.h" + +#include + + +namespace BPrivate { + + +status_t +ICULocaleconvData::_SetLocaleconvEntry(const DecimalFormatSymbols* formatSymbols, + char* destination, FormatSymbol symbol, const char* defaultValue) +{ + status_t result = B_OK; + + UnicodeString symbolString = formatSymbols->getSymbol(symbol); + if (!symbolString.isEmpty()) { + result = _ConvertUnicodeStringToLocaleconvEntry(symbolString, + destination, skLCBufSize, defaultValue); + } else + destination[0] = '\0'; + + return result; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUMessagesData.cpp b/src/system/libroot/add-ons/icu/locale/ICUMessagesData.cpp new file mode 100644 index 0000000000..b1aacd1b60 --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUMessagesData.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUMessagesData.h" + +#include +#include + + +namespace BPrivate { + + +void +ICUMessagesData::Initialize(LocaleMessagesDataBridge* dataBridge) +{ + fPosixLanginfo = dataBridge->posixLanginfo; +} + + +status_t +ICUMessagesData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + + // TODO: open the "POSIX" catalog and fetch the translations from there! + + return result; +} + + +status_t +ICUMessagesData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + strcpy(fYesExpression, fPosixLanginfo[YESEXPR]); + strcpy(fNoExpression, fPosixLanginfo[NOEXPR]); + + return result; +} + + +const char* +ICUMessagesData::GetLanginfo(int index) +{ + switch(index) { + case YESEXPR: + return fYesExpression; + case NOEXPR: + return fNoExpression; + default: + return ""; + } +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUMonetaryData.cpp b/src/system/libroot/add-ons/icu/locale/ICUMonetaryData.cpp new file mode 100644 index 0000000000..e6d061a864 --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUMonetaryData.cpp @@ -0,0 +1,322 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUMonetaryData.h" + +#include +#include +#include + + +namespace BPrivate { + + +ICUMonetaryData::ICUMonetaryData(struct lconv& localeConv) + : + fLocaleConv(localeConv), + fPosixLocaleConv(NULL) +{ + fLocaleConv.int_curr_symbol = fIntCurrSymbol; + fLocaleConv.currency_symbol = fCurrencySymbol; + fLocaleConv.mon_decimal_point = fDecimalPoint; + fLocaleConv.mon_thousands_sep = fThousandsSep; + fLocaleConv.mon_grouping = fGrouping; + fLocaleConv.positive_sign = fPositiveSign; + fLocaleConv.negative_sign = fNegativeSign; +} + + +void +ICUMonetaryData::Initialize(LocaleMonetaryDataBridge* dataBridge) +{ + fPosixLocaleConv = dataBridge->posixLocaleConv; +} + + +status_t +ICUMonetaryData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + + if (result == B_OK) { + UErrorCode icuStatus = U_ZERO_ERROR; + UChar intlCurrencySeparatorChar = CHAR_MAX; + DecimalFormat* currencyFormat = dynamic_cast( + NumberFormat::createCurrencyInstance(locale, icuStatus)); + if (!U_SUCCESS(icuStatus)) + return B_UNSUPPORTED; + if (!currencyFormat) + return B_BAD_TYPE; + + const DecimalFormatSymbols* formatSymbols + = currencyFormat->getDecimalFormatSymbols(); + if (!formatSymbols) + result = B_BAD_DATA; + + if (result == B_OK) { + result = _SetLocaleconvEntry(formatSymbols, fDecimalPoint, + DecimalFormatSymbols::kMonetarySeparatorSymbol); + } + if (result == B_OK) { + result = _SetLocaleconvEntry(formatSymbols, fThousandsSep, + DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol); + } + if (result == B_OK) { + int32 groupingSize = currencyFormat->getGroupingSize(); + if (groupingSize < 1) + fGrouping[0] = '\0'; + else { + fGrouping[0] = groupingSize; + int32 secondaryGroupingSize + = currencyFormat->getSecondaryGroupingSize(); + if (secondaryGroupingSize < 1) + fGrouping[1] = '\0'; + else { + fGrouping[1] = secondaryGroupingSize; + fGrouping[2] = '\0'; + } + } + } + if (result == B_OK) { + fLocaleConv.int_frac_digits + = currencyFormat->getMinimumFractionDigits(); + fLocaleConv.frac_digits + = currencyFormat->getMinimumFractionDigits(); + } + if (result == B_OK) { + UnicodeString positivePrefix, positiveSuffix, negativePrefix, + negativeSuffix; + currencyFormat->getPositivePrefix(positivePrefix); + currencyFormat->getPositiveSuffix(positiveSuffix); + currencyFormat->getNegativePrefix(negativePrefix); + currencyFormat->getNegativeSuffix(negativeSuffix); + UnicodeString currencySymbol = formatSymbols->getSymbol( + DecimalFormatSymbols::kCurrencySymbol); + UnicodeString plusSymbol = formatSymbols->getSymbol( + DecimalFormatSymbols::kPlusSignSymbol); + UnicodeString minusSymbol = formatSymbols->getSymbol( + DecimalFormatSymbols::kMinusSignSymbol); + + // fill national values + int32 positiveCurrencyFlags = _DetermineCurrencyPosAndSeparator( + positivePrefix, positiveSuffix, plusSymbol, currencySymbol, + intlCurrencySeparatorChar); + fLocaleConv.p_cs_precedes + = (positiveCurrencyFlags & kCsPrecedesFlag) ? 1 : 0; + fLocaleConv.p_sep_by_space + = (positiveCurrencyFlags & kSepBySpaceFlag) ? 1 : 0; + + int32 negativeCurrencyFlags = _DetermineCurrencyPosAndSeparator( + negativePrefix, negativeSuffix, minusSymbol, currencySymbol, + intlCurrencySeparatorChar); + fLocaleConv.n_cs_precedes + = (negativeCurrencyFlags & kCsPrecedesFlag) ? 1 : 0; + fLocaleConv.n_sep_by_space + = (negativeCurrencyFlags & kSepBySpaceFlag) ? 1 : 0; + + fLocaleConv.p_sign_posn = _DetermineSignPos(positivePrefix, + positiveSuffix, plusSymbol, currencySymbol); + fLocaleConv.n_sign_posn = _DetermineSignPos(negativePrefix, + negativeSuffix, minusSymbol, currencySymbol); + if (fLocaleConv.p_sign_posn == CHAR_MAX) { + // usually there is no positive sign indicator, so we + // adopt the sign pos of the negative sign symbol + fLocaleConv.p_sign_posn = fLocaleConv.n_sign_posn; + } + + // copy national to international values, as ICU does not seem + // to have separate info for those + fLocaleConv.int_p_cs_precedes = fLocaleConv.p_cs_precedes; + fLocaleConv.int_p_sep_by_space = fLocaleConv.p_sep_by_space; + fLocaleConv.int_n_cs_precedes = fLocaleConv.n_cs_precedes; + fLocaleConv.int_n_sep_by_space = fLocaleConv.n_sep_by_space; + fLocaleConv.int_p_sign_posn = fLocaleConv.p_sign_posn; + fLocaleConv.int_n_sign_posn = fLocaleConv.n_sign_posn; + + // only set sign symbols if they are actually used in any pattern + if (positivePrefix.indexOf(plusSymbol) > -1 + || positiveSuffix.indexOf(plusSymbol) > -1) { + result = _SetLocaleconvEntry(formatSymbols, fPositiveSign, + DecimalFormatSymbols::kPlusSignSymbol); + } else + fPositiveSign[0] = '\0'; + if (negativePrefix.indexOf(minusSymbol) > -1 + || negativeSuffix.indexOf(minusSymbol) > -1) { + result = _SetLocaleconvEntry(formatSymbols, fNegativeSign, + DecimalFormatSymbols::kMinusSignSymbol); + } else + fNegativeSign[0] = '\0'; + } + if (result == B_OK) { + UnicodeString intlCurrencySymbol = formatSymbols->getSymbol( + DecimalFormatSymbols::kIntlCurrencySymbol); + if (intlCurrencySeparatorChar != CHAR_MAX) + intlCurrencySymbol += intlCurrencySeparatorChar; + else + intlCurrencySymbol += ' '; + result = _ConvertUnicodeStringToLocaleconvEntry(intlCurrencySymbol, + fIntCurrSymbol, skLCBufSize); + } + if (result == B_OK) { + result = _SetLocaleconvEntry(formatSymbols, fCurrencySymbol, + DecimalFormatSymbols::kCurrencySymbol); + if (fCurrencySymbol[0] == '\0') { + // fall back to the international currency symbol + result = _SetLocaleconvEntry(formatSymbols, fCurrencySymbol, + DecimalFormatSymbols::kIntlCurrencySymbol); + fCurrencySymbol[3] = '\0'; + // drop separator char that's contained in int-curr-symbol + } + } + + delete currencyFormat; + } + + return result; +} + + +status_t +ICUMonetaryData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + if (result == B_OK) { + strcpy(fDecimalPoint, fPosixLocaleConv->mon_decimal_point); + strcpy(fThousandsSep, fPosixLocaleConv->mon_thousands_sep); + strcpy(fGrouping, fPosixLocaleConv->mon_grouping); + strcpy(fCurrencySymbol, fPosixLocaleConv->currency_symbol); + strcpy(fIntCurrSymbol, fPosixLocaleConv->int_curr_symbol); + strcpy(fPositiveSign, fPosixLocaleConv->positive_sign); + strcpy(fNegativeSign, fPosixLocaleConv->negative_sign); + fLocaleConv.int_frac_digits = fPosixLocaleConv->int_frac_digits; + fLocaleConv.frac_digits = fPosixLocaleConv->frac_digits; + fLocaleConv.p_cs_precedes = fPosixLocaleConv->p_cs_precedes; + fLocaleConv.p_sep_by_space = fPosixLocaleConv->p_sep_by_space; + fLocaleConv.n_cs_precedes = fPosixLocaleConv->n_cs_precedes; + fLocaleConv.n_sep_by_space = fPosixLocaleConv->n_sep_by_space; + fLocaleConv.p_sign_posn = fPosixLocaleConv->p_sign_posn; + fLocaleConv.n_sign_posn = fPosixLocaleConv->n_sign_posn; + fLocaleConv.int_p_cs_precedes = fPosixLocaleConv->int_p_cs_precedes; + fLocaleConv.int_p_sep_by_space = fPosixLocaleConv->int_p_sep_by_space; + fLocaleConv.int_n_cs_precedes = fPosixLocaleConv->int_n_cs_precedes; + fLocaleConv.int_n_sep_by_space = fPosixLocaleConv->int_n_sep_by_space; + fLocaleConv.int_p_sign_posn = fPosixLocaleConv->int_p_sign_posn; + fLocaleConv.int_n_sign_posn = fPosixLocaleConv->int_n_sign_posn; + } + + return result; +} + + +const char* +ICUMonetaryData::GetLanginfo(int index) +{ + switch(index) { + case CRNCYSTR: + return fCurrencySymbol; + default: + return ""; + } +} + + +int32 +ICUMonetaryData::_DetermineCurrencyPosAndSeparator(const UnicodeString& prefix, + const UnicodeString& suffix, const UnicodeString& signSymbol, + const UnicodeString& currencySymbol, UChar& currencySeparatorChar) +{ + int32 result = 0; + + int32 currencySymbolPos = prefix.indexOf(currencySymbol); + if (currencySymbolPos > -1) { + result |= kCsPrecedesFlag; + int32 signSymbolPos = prefix.indexOf(signSymbol); + // if a char is following the currency symbol, we assume it's + // the separator (usually space), but we need to take care to + // skip over the sign symbol, if found + int32 potentialSeparatorPos + = currencySymbolPos + currencySymbol.length(); + if (potentialSeparatorPos == signSymbolPos) + potentialSeparatorPos++; + if (prefix.charAt(potentialSeparatorPos) != 0xFFFF) { + // We can't use the actual separator char since this is usually + // 'c2a0' (non-breakable space), which is not available in the + // ASCII charset used/assumed by POSIX lconv. So we use space + // instead. + currencySeparatorChar = ' '; + result |= kSepBySpaceFlag; + } + } else { + currencySymbolPos = suffix.indexOf(currencySymbol); + if (currencySymbolPos > -1) { + int32 signSymbolPos = suffix.indexOf(signSymbol); + // if a char is preceding the currency symbol, we assume + // it's the separator (usually space), but we need to take + // care to skip the sign symbol, if found + int32 potentialSeparatorPos = currencySymbolPos - 1; + if (potentialSeparatorPos == signSymbolPos) + potentialSeparatorPos--; + if (suffix.charAt(potentialSeparatorPos) != 0xFFFF) { + // We can't use the actual separator char since this is usually + // 'c2a0' (non-breakable space), which is not available in the + // ASCII charset used/assumed by POSIX lconv. So we use space + // instead. + currencySeparatorChar = ' '; + result |= kSepBySpaceFlag; + } + } + } + + return result; +} + + +/* + * This method determines the positive/negative sign position value according to + * the following map (where '$' indicated the currency symbol, '#' the number + * value, and '-' or parantheses the sign symbol): + * ($#) -> 0 + * (#$) -> 0 + * -$# -> 1 + * -#$ -> 1 + * $-# -> 4 + * $#- -> 2 + * #$- -> 2 + * #-$ -> 3 + */ +int32 +ICUMonetaryData::_DetermineSignPos(const UnicodeString& prefix, + const UnicodeString& suffix, const UnicodeString& signSymbol, + const UnicodeString& currencySymbol) +{ + if (prefix.indexOf(UnicodeString("(", "")) >= 0 + && suffix.indexOf(UnicodeString(")", "")) >= 0) + return kParenthesesAroundCurrencyAndValue; + + UnicodeString value("#", ""); + UnicodeString prefixNumberSuffixString = prefix + value + suffix; + int32 signSymbolPos = prefixNumberSuffixString.indexOf(signSymbol); + if (signSymbolPos >= 0) { + int32 valuePos = prefixNumberSuffixString.indexOf(value); + int32 currencySymbolPos + = prefixNumberSuffixString.indexOf(currencySymbol); + + if (signSymbolPos < valuePos && signSymbolPos < currencySymbolPos) + return kSignPrecedesCurrencyAndValue; + if (signSymbolPos > valuePos && signSymbolPos > currencySymbolPos) + return kSignSucceedsCurrencyAndValue; + if (signSymbolPos == currencySymbolPos - 1) + return kSignImmediatelyPrecedesCurrency; + if (signSymbolPos == currencySymbolPos + currencySymbol.length()) + return kSignImmediatelySucceedsCurrency; + } + + return CHAR_MAX; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUNumericData.cpp b/src/system/libroot/add-ons/icu/locale/ICUNumericData.cpp new file mode 100644 index 0000000000..6a410ee46e --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUNumericData.cpp @@ -0,0 +1,126 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUNumericData.h" + +#include +#include +#include + + +namespace BPrivate { + + +ICUNumericData::ICUNumericData(struct lconv& localeConv) + : + fLocaleConv(localeConv), + fDataBridge(NULL) +{ + fLocaleConv.decimal_point = fDecimalPoint; + fLocaleConv.thousands_sep = fThousandsSep; + fLocaleConv.grouping = fGrouping; +} + + +void +ICUNumericData::Initialize(LocaleNumericDataBridge* dataBridge) +{ + *dataBridge->addrOfGlibcDecimalPoint = fDecimalPoint; + *dataBridge->addrOfGlibcThousandsSep = fThousandsSep; + *dataBridge->addrOfGlibcGrouping = fGrouping; + fDataBridge = dataBridge; +} + + +status_t +ICUNumericData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + + if (result == B_OK) { + UErrorCode icuStatus = U_ZERO_ERROR; + DecimalFormat* numberFormat = dynamic_cast( + NumberFormat::createInstance(locale, DecimalFormat::kNumberStyle, + icuStatus)); + if (!U_SUCCESS(icuStatus)) + return B_UNSUPPORTED; + if (!numberFormat) + return B_BAD_TYPE; + const DecimalFormatSymbols* formatSymbols + = numberFormat->getDecimalFormatSymbols(); + if (!formatSymbols) + result = B_BAD_DATA; + + if (result == B_OK) { + result = _SetLocaleconvEntry(formatSymbols, fDecimalPoint, + DecimalFormatSymbols::kDecimalSeparatorSymbol); + *fDataBridge->addrOfGlibcWCDecimalPoint + = (unsigned int)fDecimalPoint[0]; + } + if (result == B_OK) { + result = _SetLocaleconvEntry(formatSymbols, fThousandsSep, + DecimalFormatSymbols::kGroupingSeparatorSymbol); + *fDataBridge->addrOfGlibcWCThousandsSep + = (unsigned int)fThousandsSep[0]; + } + if (result == B_OK) { + int32 groupingSize = numberFormat->getGroupingSize(); + if (groupingSize < 1) + fGrouping[0] = '\0'; + else { + fGrouping[0] = groupingSize; + int32 secondaryGroupingSize + = numberFormat->getSecondaryGroupingSize(); + if (secondaryGroupingSize < 1) + fGrouping[1] = '\0'; + else { + fGrouping[1] = secondaryGroupingSize; + fGrouping[2] = '\0'; + } + } + } + + delete numberFormat; + } + + return result; +} + + +status_t +ICUNumericData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + if (result == B_OK) { + strcpy(fDecimalPoint, fDataBridge->posixLocaleConv->decimal_point); + strcpy(fThousandsSep, fDataBridge->posixLocaleConv->thousands_sep); + strcpy(fGrouping, fDataBridge->posixLocaleConv->grouping); + *fDataBridge->addrOfGlibcWCDecimalPoint + = (unsigned int)fDecimalPoint[0]; + *fDataBridge->addrOfGlibcWCThousandsSep + = (unsigned int)fThousandsSep[0]; + } + + return result; +} + + +const char* +ICUNumericData::GetLanginfo(int index) +{ + switch(index) { + case RADIXCHAR: + return fDecimalPoint; + case THOUSEP: + return fThousandsSep; + default: + return ""; + } +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/ICUTimeData.cpp b/src/system/libroot/add-ons/icu/locale/ICUTimeData.cpp new file mode 100644 index 0000000000..77185996b8 --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/ICUTimeData.cpp @@ -0,0 +1,400 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "ICUTimeData.h" + +#include +#include + +#include +#include + + +namespace BPrivate { + + +ICUTimeData::ICUTimeData(struct lc_time_t& lcTimeInfo) + : + fLCTimeInfo(lcTimeInfo), + fPosixLCTimeInfo(NULL) +{ + for (int i = 0; i < 12; ++i) { + fLCTimeInfo.mon[i] = fMon[i]; + fLCTimeInfo.month[i] = fMonth[i]; + fLCTimeInfo.alt_month[i] = fAltMonth[i]; + } + for (int i = 0; i < 7; ++i) { + fLCTimeInfo.wday[i] = fWday[i]; + fLCTimeInfo.weekday[i] = fWeekday[i]; + } + fLCTimeInfo.X_fmt = fTimeFormat; + fLCTimeInfo.x_fmt = fDateFormat; + fLCTimeInfo.c_fmt = fDateTimeFormat; + fLCTimeInfo.am = fAm; + fLCTimeInfo.pm = fPm; + fLCTimeInfo.date_fmt = fDateTimeZoneFormat; + fLCTimeInfo.md_order = fMonthDayOrder; + fLCTimeInfo.ampm_fmt = fAmPmFormat; +} + + +void +ICUTimeData::Initialize(LocaleTimeDataBridge* dataBridge) +{ + fPosixLCTimeInfo = dataBridge->posixLCTimeInfo; +} + + +status_t +ICUTimeData::SetTo(const Locale& locale, const char* posixLocaleName) +{ + status_t result = inherited::SetTo(locale, posixLocaleName); + if (result != B_OK) + return result; + + UErrorCode icuStatus = U_ZERO_ERROR; + DateFormatSymbols formatSymbols(fLocale, icuStatus); + if (!U_SUCCESS(icuStatus)) + return B_UNSUPPORTED; + + int count = 0; + const UnicodeString* strings = formatSymbols.getShortMonths(count); + result = _SetLCTimeEntries(strings, fMon[0], sizeof(fMon[0]), count, 12); + + if (result == B_OK) { + strings = formatSymbols.getMonths(count); + result = _SetLCTimeEntries(strings, fMonth[0], sizeof(fMonth[0]), count, + 12); + } + + if (result == B_OK) { + strings = formatSymbols.getShortWeekdays(count); + if (count == 8 && strings[0].length() == 0) { + // ICUs weekday arrays are 1-based + strings++; + count = 7; + } + result + = _SetLCTimeEntries(strings, fWday[0], sizeof(fWday[0]), count, 7); + } + + if (result == B_OK) { + strings = formatSymbols.getWeekdays(count); + if (count == 8 && strings[0].length() == 0) { + // ICUs weekday arrays are 1-based + strings++; + count = 7; + } + result = _SetLCTimeEntries(strings, fWeekday[0], sizeof(fWeekday[0]), + count, 7); + } + + if (result == B_OK) { + try { + DateFormat* format = DateFormat::createTimeInstance( + DateFormat::kDefault, fLocale); + result = _SetLCTimePattern(format, fTimeFormat, sizeof(fTimeFormat)); + delete format; + } catch(...) { + result = B_NO_MEMORY; + } + } + + if (result == B_OK) { + try { + DateFormat* format = DateFormat::createDateInstance( + DateFormat::kDefault, fLocale); + result = _SetLCTimePattern(format, fDateFormat, sizeof(fDateFormat)); + delete format; + } catch(...) { + result = B_NO_MEMORY; + } + } + + if (result == B_OK) { + try { + DateFormat* format = DateFormat::createDateTimeInstance( + DateFormat::kFull, DateFormat::kFull, fLocale); + result = _SetLCTimePattern(format, fDateTimeFormat, + sizeof(fDateTimeFormat)); + delete format; + } catch(...) { + result = B_NO_MEMORY; + } + } + + if (result == B_OK) { + strings = formatSymbols.getAmPmStrings(count); + result = _SetLCTimeEntries(strings, fAm, sizeof(fAm), 1, 1); + if (result == B_OK) + result = _SetLCTimeEntries(&strings[1], fPm, sizeof(fPm), 1, 1); + } + + if (result == B_OK) { + strings = formatSymbols.getMonths(count, DateFormatSymbols::STANDALONE, + DateFormatSymbols::WIDE); + result = _SetLCTimeEntries(strings, fAltMonth[0], sizeof(fAltMonth[0]), + count, 12); + } + + strcpy(fAmPmFormat, fPosixLCTimeInfo->ampm_fmt); + // ICU does not provide anything for this (and that makes sense, too) + + return result; +} + + +status_t +ICUTimeData::SetToPosix() +{ + status_t result = inherited::SetToPosix(); + + if (result == B_OK) { + for (int i = 0; i < 12; ++i) { + strcpy(fMon[i], fPosixLCTimeInfo->mon[i]); + strcpy(fMonth[i], fPosixLCTimeInfo->month[i]); + strcpy(fAltMonth[i], fPosixLCTimeInfo->alt_month[i]); + } + for (int i = 0; i < 7; ++i) { + strcpy(fWday[i], fPosixLCTimeInfo->wday[i]); + strcpy(fWeekday[i], fPosixLCTimeInfo->weekday[i]); + } + strcpy(fTimeFormat, fPosixLCTimeInfo->X_fmt); + strcpy(fDateFormat, fPosixLCTimeInfo->x_fmt); + strcpy(fDateTimeFormat, fPosixLCTimeInfo->c_fmt); + strcpy(fAm, fPosixLCTimeInfo->am); + strcpy(fPm, fPosixLCTimeInfo->pm); + strcpy(fDateTimeZoneFormat, fPosixLCTimeInfo->date_fmt); + strcpy(fMonthDayOrder, fPosixLCTimeInfo->md_order); + strcpy(fAmPmFormat, fPosixLCTimeInfo->ampm_fmt); + } + + return result; +} + + +const char* +ICUTimeData::GetLanginfo(int index) +{ + switch(index) { + case D_T_FMT: + return fDateTimeFormat; + case D_FMT: + return fDateFormat; + case T_FMT: + return fTimeFormat; + case T_FMT_AMPM: + return fAmPmFormat; + case AM_STR: + return fAm; + case PM_STR: + return fPm; + + case DAY_1: + case DAY_2: + case DAY_3: + case DAY_4: + case DAY_5: + case DAY_6: + case DAY_7: + return fWeekday[index - DAY_1]; + + case ABDAY_1: + case ABDAY_2: + case ABDAY_3: + case ABDAY_4: + case ABDAY_5: + case ABDAY_6: + case ABDAY_7: + return fWday[index - ABDAY_1]; + + case MON_1: + case MON_2: + case MON_3: + case MON_4: + case MON_5: + case MON_6: + case MON_7: + case MON_8: + case MON_9: + case MON_10: + case MON_11: + case MON_12: + return fMonth[index - MON_1]; + + case ABMON_1: + case ABMON_2: + case ABMON_3: + case ABMON_4: + case ABMON_5: + case ABMON_6: + case ABMON_7: + case ABMON_8: + case ABMON_9: + case ABMON_10: + case ABMON_11: + case ABMON_12: + return fMon[index - ABMON_1]; + + default: + return ""; + } +} + + +status_t +ICUTimeData::_SetLCTimeEntries(const UnicodeString* strings, char* destination, + int entrySize, int count, int maxCount) +{ + if (strings == NULL) + return B_ERROR; + + status_t result = B_OK; + if (count > maxCount) + count = maxCount; + for (int32 i = 0; result == B_OK && i < count; ++i) { + result = _ConvertUnicodeStringToLocaleconvEntry(strings[i], destination, + entrySize); + destination += entrySize; + } + + return result; +} + + +status_t +ICUTimeData::_SetLCTimePattern(DateFormat* format, char* destination, + int destinationSize) +{ + SimpleDateFormat* simpleFormat = dynamic_cast(format); + if (!simpleFormat) + return B_BAD_TYPE; + + // convert ICU-type pattern to posix (i.e. strftime()) format string + UnicodeString icuPattern; + simpleFormat->toPattern(icuPattern); + UnicodeString posixPattern; + if (icuPattern.length() > 0) { + UChar lastCharSeen = 0; + int lastCharCount = 1; + bool inSingleQuotes = false; + bool inDoubleQuotes = false; + // we loop one character past the end on purpose, which will result in a + // final -1 char to be processed, which in turn will let us handle the + // last character (via lastCharSeen) + for (int i = 0; i <= icuPattern.length(); ++i) { + UChar currChar = icuPattern.charAt(i); + if (lastCharSeen != 0 && currChar == lastCharSeen) { + lastCharCount++; + continue; + } + + if (!inSingleQuotes && !inDoubleQuotes) { + switch (lastCharSeen) { + case L'a': + posixPattern.append(UnicodeString("%p", "")); + break; + case L'd': + if (lastCharCount == 2) + posixPattern.append(UnicodeString("%d", "")); + else + posixPattern.append(UnicodeString("%e", "")); + break; + case L'D': + posixPattern.append(UnicodeString("%j", "")); + break; + case L'c': + // fall through, to handle 'c' the same as 'e' + case L'e': + if (lastCharCount == 4) + posixPattern.append(UnicodeString("%A", "")); + else if (lastCharCount <= 2) + posixPattern.append(UnicodeString("%u", "")); + else + posixPattern.append(UnicodeString("%a", "")); + break; + case L'E': + if (lastCharCount == 4) + posixPattern.append(UnicodeString("%A", "")); + else + posixPattern.append(UnicodeString("%a", "")); + break; + case L'k': + // fall through, to handle 'k' the same as 'h' + case L'h': + if (lastCharCount == 2) + posixPattern.append(UnicodeString("%I", "")); + else + posixPattern.append(UnicodeString("%l", "")); + break; + case L'H': + if (lastCharCount == 2) + posixPattern.append(UnicodeString("%H", "")); + else + posixPattern.append(UnicodeString("%k", "")); + break; + case L'm': + posixPattern.append(UnicodeString("%M", "")); + break; + case L'L': + // fall through, to handle 'L' the same as 'M' + case L'M': + if (lastCharCount == 4) + posixPattern.append(UnicodeString("%B", "")); + else if (lastCharCount == 3) + posixPattern.append(UnicodeString("%b", "")); + else + posixPattern.append(UnicodeString("%m", "")); + break; + case L's': + posixPattern.append(UnicodeString("%S", "")); + break; + case L'w': + posixPattern.append(UnicodeString("%V", "")); + break; + case L'y': + if (lastCharCount == 2) + posixPattern.append(UnicodeString("%y", "")); + else + posixPattern.append(UnicodeString("%Y", "")); + break; + case L'Y': + posixPattern.append(UnicodeString("%G", "")); + break; + case L'z': + posixPattern.append(UnicodeString("%Z", "")); + break; + case L'Z': + posixPattern.append(UnicodeString("%z", "")); + break; + default: + if (lastCharSeen != 0) + posixPattern.append(lastCharSeen); + } + } else { + if (lastCharSeen != 0) + posixPattern.append(lastCharSeen); + } + + if (currChar == L'"') { + inDoubleQuotes = !inDoubleQuotes; + lastCharSeen = 0; + } else if (currChar == L'\'') { + inSingleQuotes = !inSingleQuotes; + lastCharSeen = 0; + } else + lastCharSeen = currChar; + + lastCharCount = 1; + } + } + + return _ConvertUnicodeStringToLocaleconvEntry(posixPattern, destination, + destinationSize); +} + + +} // namespace BPrivate diff --git a/src/system/libroot/add-ons/icu/locale/Jamfile b/src/system/libroot/add-ons/icu/locale/Jamfile new file mode 100644 index 0000000000..21e68dbd53 --- /dev/null +++ b/src/system/libroot/add-ons/icu/locale/Jamfile @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src system libroot add-ons icu locale ; + +UsePrivateHeaders [ FDirName libroot locale ] ; +UsePrivateHeaders [ FDirName libroot time ] ; + +local sources = + ICUCategoryData.cpp + ICUCollateData.cpp + ICUCtypeData.cpp + ICULocaleBackend.cpp + ICULocaleconvData.cpp + ICUMessagesData.cpp + ICUMonetaryData.cpp + ICUNumericData.cpp + ICUTimeData.cpp +; + +SubDirSysHdrs $(HAIKU_ICU_HEADERS) ; +Includes [ FGristFiles $(sources) ] : $(HAIKU_ICU_HEADERS_DEPENDENCY) ; + # Dependency needed to trigger downloading/unzipping the package before + # compiling the files. + +MergeObject addon_icu_locale.o : $(sources) ; diff --git a/src/system/libroot/posix/glibc/Jamfile b/src/system/libroot/posix/glibc/Jamfile index 03929bb6e4..a3c6035226 100644 --- a/src/system/libroot/posix/glibc/Jamfile +++ b/src/system/libroot/posix/glibc/Jamfile @@ -12,4 +12,3 @@ SubInclude HAIKU_TOP src system libroot posix glibc stdio-common ; SubInclude HAIKU_TOP src system libroot posix glibc stdlib ; SubInclude HAIKU_TOP src system libroot posix glibc string ; SubInclude HAIKU_TOP src system libroot posix glibc wcsmbs ; -SubInclude HAIKU_TOP src system libroot posix glibc wctype ; diff --git a/src/system/libroot/posix/glibc/catgets/nl_types.h b/src/system/libroot/posix/glibc/catgets/nl_types.h index 9322aa2461..cb6d7d7547 100644 --- a/src/system/libroot/posix/glibc/catgets/nl_types.h +++ b/src/system/libroot/posix/glibc/catgets/nl_types.h @@ -21,32 +21,11 @@ #include -/* The default message set used by the gencat program. */ -#define NL_SETD 1 - -/* Value for FLAG parameter of `catgets' to say we want XPG4 compliance. */ -#define NL_CAT_LOCALE 1 - - __BEGIN_DECLS -/* Message catalog descriptor type. */ -typedef void *nl_catd; - /* Type used by `nl_langinfo'. */ typedef int nl_item; -/* Open message catalog for later use, returning descriptor. */ -extern nl_catd catopen (__const char *__cat_name, int __flag) __THROW; - -/* Return translation with NUMBER in SET of CATALOG; if not found - return STRING. */ -extern char *catgets (nl_catd __catalog, int __set, int __number, - __const char *__string) __THROW; - -/* Close message CATALOG. */ -extern int catclose (nl_catd __catalog) __THROW; - __END_DECLS #endif /* nl_types.h */ diff --git a/src/system/libroot/posix/glibc/ctype/Jamfile b/src/system/libroot/posix/glibc/ctype/Jamfile index 75b0f7e105..ff8c702a3e 100644 --- a/src/system/libroot/posix/glibc/ctype/Jamfile +++ b/src/system/libroot/posix/glibc/ctype/Jamfile @@ -9,8 +9,5 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ; SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ; MergeObject posix_gnu_ctype.o : - ctype_l.c - ctype.c - ctype-extn.c ctype-info.c ; diff --git a/src/system/libroot/posix/glibc/ctype/Makefile b/src/system/libroot/posix/glibc/ctype/Makefile deleted file mode 100644 index eaf4d32314..0000000000 --- a/src/system/libroot/posix/glibc/ctype/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 1991, 1992, 1993, 1997, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Sub-makefile for ctype portion of the library. -# -subdir := ctype -headers := ctype.h - -routines := ctype ctype-extn ctype_l isctype -aux := ctype-info - -tests := test_ctype - -include ../Rules diff --git a/src/system/libroot/posix/glibc/ctype/Versions b/src/system/libroot/posix/glibc/ctype/Versions deleted file mode 100644 index 8cf0338b39..0000000000 --- a/src/system/libroot/posix/glibc/ctype/Versions +++ /dev/null @@ -1,24 +0,0 @@ -libc { - GLIBC_2.0 { - # global variables - __ctype_b; __ctype32_b; __ctype_tolower; __ctype_toupper; - _tolower; _toupper; - - # i* - isalnum; isalpha; isascii; isblank; iscntrl; isdigit; isgraph; islower; - isprint; ispunct; isspace; isupper; isxdigit; - - # t* - toascii; tolower; toupper; - } - GLIBC_2.2 { - # global variables - __ctype32_tolower; __ctype32_toupper; - } - GLIBC_2.3 { - isctype; __isctype; - - # functions used by optimized macros in ctype.h - __ctype_b_loc; __ctype_tolower_loc; __ctype_toupper_loc; - } -} diff --git a/src/system/libroot/posix/glibc/ctype/ctype-extn.c b/src/system/libroot/posix/glibc/ctype/ctype-extn.c deleted file mode 100644 index 0732fb1b1a..0000000000 --- a/src/system/libroot/posix/glibc/ctype/ctype-extn.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 1991, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define __NO_CTYPE -#include -/* -#define __ctype_tolower \ - ((uint32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128) -#define __ctype_toupper \ - ((uint32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128) -*/ -/* Real function versions of the non-ANSI ctype functions. isblank is - now in ISO C99 but we leave it here. */ - -int -isblank (int c) -{ - return __isctype (c, _ISblank); -} - -int -_tolower (int c) -{ - return __ctype_tolower[c]; -} -int -_toupper (int c) -{ - return __ctype_toupper[c]; -} - -int -toascii (int c) -{ - return __toascii (c); -} -weak_alias (toascii, __toascii_l) - -int -isascii (int c) -{ - return __isascii (c); -} -weak_alias (isascii, __isascii_l) - -/* -int -__isblank_l (int c, __locale_t l) -{ - return __isctype_l (c, _ISblank, l); -} -weak_alias (__isblank_l, isblank_l) -*/ diff --git a/src/system/libroot/posix/glibc/ctype/ctype-info.c b/src/system/libroot/posix/glibc/ctype/ctype-info.c index f683ce3346..1c9c2e9f2d 100644 --- a/src/system/libroot/posix/glibc/ctype/ctype-info.c +++ b/src/system/libroot/posix/glibc/ctype/ctype-info.c @@ -42,12 +42,6 @@ extern const char _nl_C_LC_CTYPE_width[]; #define b(t,x,o) (((const t *) _nl_C_LC_CTYPE_##x) + o) -const unsigned short int *__ctype_b = b (unsigned short int, class, 128); -const __uint32_t *__ctype32_b = b (__uint32_t, class32, 0); -const __int32_t *__ctype_tolower = b (__int32_t, tolower, 128); -const __int32_t *__ctype_toupper = b (__int32_t, toupper, 128); -const __uint32_t *__ctype32_tolower = b (__uint32_t, tolower, 128); -const __uint32_t *__ctype32_toupper = b (__uint32_t, toupper, 128); const char *__ctype32_wctype[12] = { b(char, class_upper, 32), @@ -68,4 +62,3 @@ const char *__ctype32_wctrans[2] = b(char, map_toupper, 0), b(char, map_tolower, 0) }; -const char *__ctype32_width = b (char, width, 0); diff --git a/src/system/libroot/posix/glibc/ctype/ctype.c b/src/system/libroot/posix/glibc/ctype/ctype.c deleted file mode 100644 index 4bcbd30ef7..0000000000 --- a/src/system/libroot/posix/glibc/ctype/ctype.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define __NO_CTYPE -#include - -/* Provide real-function versions of all the ctype macros. */ - -#define func(name, type) \ - int name (int c) { return __isctype (c, type); } - -func (isalnum, _ISalnum) -func (isalpha, _ISalpha) -func (iscntrl, _IScntrl) -func (isdigit, _ISdigit) -func (islower, _ISlower) -func (isgraph, _ISgraph) -func (isprint, _ISprint) -func (ispunct, _ISpunct) -func (isspace, _ISspace) -func (isupper, _ISupper) -func (isxdigit, _ISxdigit) - -int -tolower (int c) -{ - return c >= -128 && c < 256 ? __ctype_tolower[c] : c; -} - -int -toupper (int c) -{ - return c >= -128 && c < 256 ? __ctype_toupper[c] : c; -} diff --git a/src/system/libroot/posix/glibc/ctype/ctype_l.c b/src/system/libroot/posix/glibc/ctype/ctype_l.c deleted file mode 100644 index e47992c592..0000000000 --- a/src/system/libroot/posix/glibc/ctype/ctype_l.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (C) 1991,92,97,2001,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define __NO_CTYPE -#include -#include - -/* Provide real-function versions of all the ctype macros. */ - -int __isctype_l(int c, unsigned short int t, __locale_t l); - -#define func(name, type) \ - int __##name (int c, __locale_t l) { return __isctype_l (c, type, l); } \ - weak_alias (__##name, name) - -func (isalnum_l, _ISalnum) -func (isalpha_l, _ISalpha) -func (iscntrl_l, _IScntrl) -func (isdigit_l, _ISdigit) -func (islower_l, _ISlower) -func (isgraph_l, _ISgraph) -func (isprint_l, _ISprint) -func (ispunct_l, _ISpunct) -func (isspace_l, _ISspace) -func (isupper_l, _ISupper) -func (isxdigit_l, _ISxdigit) - -int -(__tolower_l) (int c, __locale_t l) -{ - return l->__ctype_tolower[c]; -} -weak_alias (__tolower_l, tolower_l) - -int -(__toupper_l) (int c, __locale_t l) -{ - return l->__ctype_toupper[c]; -} -weak_alias (__toupper_l, toupper_l) - -int -(__isctype_l) (int c, unsigned short int t, __locale_t l) -{ - return (l->__ctype_b[c] & t); -} -weak_alias (__isctype_l, isctype_l) - diff --git a/src/system/libroot/posix/glibc/ctype/isctype.c b/src/system/libroot/posix/glibc/ctype/isctype.c deleted file mode 100644 index a04da3eb56..0000000000 --- a/src/system/libroot/posix/glibc/ctype/isctype.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef __isctype - -int -__isctype (ch, mask) - int ch; - int mask; -{ - return (((uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128) - [(int) (ch)] & mask); -} -weak_alias (__isctype, isctype) diff --git a/src/system/libroot/posix/glibc/ctype/test_ctype.c b/src/system/libroot/posix/glibc/ctype/test_ctype.c deleted file mode 100644 index d577e88dd6..0000000000 --- a/src/system/libroot/posix/glibc/ctype/test_ctype.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright (C) 1991, 1994, 1996, 1997, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -#define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#define XOR(e,f) (((e) && !(f)) || (!(e) && (f))) - -#ifdef __GNUC__ -__inline -#endif -static void -print_char (unsigned char c) -{ - printf("%d/", (int) c); - if (isgraph(c)) - printf("'%c'", c); - else - printf("'\\%.3o'", c); -} - -int -main (int argc, char **argv) -{ - unsigned short int c; - int lose = 0; - -#define TRYEM do { \ - TRY (isascii); \ - TRY (isalnum); \ - TRY (isalpha); \ - TRY (iscntrl); \ - TRY (isdigit); \ - TRY (isgraph); \ - TRY (islower); \ - TRY (isprint); \ - TRY (ispunct); \ - TRY (isspace); \ - TRY (isupper); \ - TRY (isxdigit); \ - TRY (isblank); \ - } while (0) - - for (c = 0; c <= UCHAR_MAX; ++c) - { - print_char (c); - - if (XOR (islower (c), ISLOWER (c)) || toupper (c) != TOUPPER (c)) - { - fputs (" BOGUS", stdout); - ++lose; - } - -#define TRY(isfoo) if (isfoo (c)) fputs (" " #isfoo, stdout) - TRYEM; -#undef TRY - - fputs("; lower = ", stdout); - print_char(tolower(c)); - fputs("; upper = ", stdout); - print_char(toupper(c)); - putchar('\n'); - } - - fputs ("EOF", stdout); - if (tolower (EOF) != EOF) - { - ++lose; - printf (" tolower BOGUS %d;", tolower (EOF)); - } - if (toupper (EOF) != EOF) - { - ++lose; - printf (" toupper BOGUS %d;", toupper (EOF)); - } - -#define TRY(isfoo) if (isfoo (EOF)) fputs (" " #isfoo, stdout), ++lose - TRYEM; -#undef TRY - - return lose ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/src/system/libroot/posix/glibc/iconv/Jamfile b/src/system/libroot/posix/glibc/iconv/Jamfile index 95463a14ec..8689bcaccf 100644 --- a/src/system/libroot/posix/glibc/iconv/Jamfile +++ b/src/system/libroot/posix/glibc/iconv/Jamfile @@ -8,7 +8,6 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc libio ; SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ctype ; SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc iconv ; SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ; -#SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc string ; SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ; SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ; @@ -18,7 +17,6 @@ MergeObject posix_gnu_iconv.o : gconv_cache.c gconv_conf.c gconv_db.c -# gconv_dl.c gconv_simple.c gconv_trans.c ; diff --git a/src/system/libroot/posix/glibc/iconv/Makefile b/src/system/libroot/posix/glibc/iconv/Makefile deleted file mode 100644 index 15846c2c07..0000000000 --- a/src/system/libroot/posix/glibc/iconv/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Makefile for iconv. -# -subdir := iconv - -include ../Makeconfig - -headers = iconv.h gconv.h -routines = iconv_open iconv iconv_close \ - gconv_open gconv gconv_close gconv_db gconv_conf \ - gconv_builtin gconv_simple gconv_trans gconv_cache -ifeq ($(elf),yes) -routines += gconv_dl -else -CFLAGS-gconv_db.c = -DSTATIC_GCONV -CFLAGS-gconv_cache.c = -DSTATIC_GCONV -CFLAGS-gconv_simple.c = -DSTATIC_GCONV -endif - -vpath %.c ../locale/programs - -iconv_prog-modules = iconv_charmap charmap charmap-dir linereader \ - dummy-repertoire simple-hash xstrdup xmalloc -iconvconfig-modules = strtab xmalloc -extra-objs = $(iconv_prog-modules:=.o) $(iconvconfig-modules:=.o) -CFLAGS-iconv_prog.c = -I../locale/programs -CFLAGS-iconv_charmap.c = -I../locale/programs -CFLAGS-dummy-repertoire.c = -I../locale/programs -CFLAGS-charmap.c = -DCHARMAP_PATH='"$(i18ndir)/charmaps"' \ - -DDEFAULT_CHARMAP=null_pointer -DNEED_NULL_POINTER -CFLAGS-linereader.c = -DNO_TRANSLITERATION -CFLAGS-simple-hash.c = -I../locale - -tests = tst-iconv1 tst-iconv2 tst-iconv3 - -distribute = gconv_builtin.h gconv_int.h loop.c skeleton.c iconv_prog.h \ - iconv_charmap.c dummy-repertoire.c gconv_charset.h strtab.c \ - iconvconfig.h - -others = iconv_prog iconvconfig -install-others = $(inst_bindir)/iconv -install-sbin = iconvconfig - -CFLAGS-gconv_cache.c += -DGCONV_DIR='"$(gconvdir)"' -CFLAGS-gconv_conf.c = -DGCONV_PATH='"$(gconvdir)"' -CFLAGS-iconvconfig.c = -DGCONV_PATH='"$(gconvdir)"' -DGCONV_DIR='"$(gconvdir)"' - -CPPFLAGS-iconv_prog = -DNOT_IN_libc -CPPFLAGS-iconv_charmap = -DNOT_IN_libc -CPPFLAGS-iconvconfig = -DNOT_IN_libc -CPPFLAGS-linereader = -DNOT_IN_libc -CPPFLAGS-strtab = -DNOT_IN_libc -CPPFLAGS-charmap = -DNOT_IN_libc -CPPFLAGS-charmap-dir = -DNOT_IN_libc - -include ../Rules - -$(inst_bindir)/iconv: $(objpfx)iconv_prog $(+force) - $(do-install-program) - -$(objpfx)iconv_prog: $(iconv_prog-modules:%=$(objpfx)%.o) -$(objpfx)iconvconfig: $(iconvconfig-modules:%=$(objpfx)%.o) diff --git a/src/system/libroot/posix/glibc/iconv/Versions b/src/system/libroot/posix/glibc/iconv/Versions deleted file mode 100644 index 7f09ed49c4..0000000000 --- a/src/system/libroot/posix/glibc/iconv/Versions +++ /dev/null @@ -1,10 +0,0 @@ -libc { - GLIBC_2.1 { - # i* - iconv_open; iconv; iconv_close; - } - GLIBC_PRIVATE { - # functions shared with iconv program - __gconv_get_alias_db; __gconv_get_modules_db; __gconv_get_cache; - } -} diff --git a/src/system/libroot/posix/glibc/iconv/dummy-repertoire.c b/src/system/libroot/posix/glibc/iconv/dummy-repertoire.c deleted file mode 100644 index a195460f9a..0000000000 --- a/src/system/libroot/posix/glibc/iconv/dummy-repertoire.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* For iconv we don't have to handle repertoire maps. Provide dummy - definitions to allow the use of linereader.c unchanged. */ -#include - - -uint32_t -repertoire_find_value (const struct repertoire_t *repertoire, const char *name, - size_t len) -{ - return ILLEGAL_CHAR_VALUE; -} - - -const char * -repertoire_find_symbol (const struct repertoire_t *repertoire, uint32_t ucs) -{ - return NULL; -} diff --git a/src/system/libroot/posix/glibc/iconv/gconv.c b/src/system/libroot/posix/glibc/iconv/gconv.c deleted file mode 100644 index f3f49b7db3..0000000000 --- a/src/system/libroot/posix/glibc/iconv/gconv.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Convert characters in input buffer using conversion descriptor to - output buffer. - Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include - -int -internal_function -__gconv (__gconv_t cd, const unsigned char **inbuf, - const unsigned char *inbufend, unsigned char **outbuf, - unsigned char *outbufend, size_t *irreversible) -{ - size_t last_step; - int result; - - if (cd == (__gconv_t) -1L) - return __GCONV_ILLEGAL_DESCRIPTOR; - - last_step = cd->__nsteps - 1; - - assert (irreversible != NULL); - *irreversible = 0; - - cd->__data[last_step].__outbuf = outbuf != NULL ? *outbuf : NULL; - cd->__data[last_step].__outbufend = outbufend; - - if (inbuf == NULL || *inbuf == NULL) - /* We just flush. */ - result = DL_CALL_FCT (cd->__steps->__fct, - (cd->__steps, cd->__data, NULL, NULL, NULL, - irreversible, - cd->__data[last_step].__outbuf == NULL ? 2 : 1, 0)); - else - { - const unsigned char *last_start; - - assert (outbuf != NULL && *outbuf != NULL); - - do - { - last_start = *inbuf; - result = DL_CALL_FCT (cd->__steps->__fct, - (cd->__steps, cd->__data, inbuf, inbufend, - NULL, irreversible, 0, 0)); - } - while (result == __GCONV_EMPTY_INPUT && last_start != *inbuf - && *inbuf + cd->__steps->__min_needed_from <= inbufend); - } - - if (outbuf != NULL && *outbuf != NULL) - *outbuf = cd->__data[last_step].__outbuf; - - return result; -} diff --git a/src/system/libroot/posix/glibc/iconv/gconv_close.c b/src/system/libroot/posix/glibc/iconv/gconv_close.c deleted file mode 100644 index cc0ecd650b..0000000000 --- a/src/system/libroot/posix/glibc/iconv/gconv_close.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Release any resource associated with given conversion descriptor. - Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include - - -int -internal_function -__gconv_close (__gconv_t cd) -{ - struct __gconv_step *srunp; - struct __gconv_step_data *drunp; - size_t nsteps; - - /* Free all resources by calling destructor functions and release - the implementations. */ - srunp = cd->__steps; - nsteps = cd->__nsteps; - drunp = cd->__data; - do - { - struct __gconv_trans_data *transp; - - transp = drunp->__trans; - while (transp != NULL) - { - struct __gconv_trans_data *curp = transp; - transp = transp->__next; - - if (__builtin_expect (curp->__trans_end_fct != NULL, 0)) - curp->__trans_end_fct (curp->__data); - - free (curp); - } - - if (!(drunp->__flags & __GCONV_IS_LAST) && drunp->__outbuf != NULL) - free (drunp->__outbuf); - } - while (!((drunp++)->__flags & __GCONV_IS_LAST)); - - /* Free the data allocated for the descriptor. */ - free (cd); - - /* Close the participating modules. */ - return __gconv_close_transform (srunp, nsteps); -} diff --git a/src/system/libroot/posix/glibc/iconv/gconv_open.c b/src/system/libroot/posix/glibc/iconv/gconv_open.c deleted file mode 100644 index 94a54f8008..0000000000 --- a/src/system/libroot/posix/glibc/iconv/gconv_open.c +++ /dev/null @@ -1,337 +0,0 @@ -/* Find matching transformation algorithms and initialize steps. - Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include "../locale/localeinfo.h" -#include -#include - -#include - - -int -internal_function -__gconv_open (const char *toset, const char *fromset, __gconv_t *handle, - int flags) -{ - struct __gconv_step *steps; - size_t nsteps; - __gconv_t result = NULL; - size_t cnt = 0; - int res; - int conv_flags = 0; - const char *errhand; - const char *ignore; - struct trans_struct *trans = NULL; - - /* Find out whether any error handling method is specified. */ - errhand = strchr (toset, '/'); - if (errhand != NULL) - errhand = strchr (errhand + 1, '/'); - if (__builtin_expect (errhand != NULL, 1)) - { - if (*++errhand == '\0') - errhand = NULL; - else - { - /* Make copy without the error handling description. */ - char *newtoset = (char *) alloca (errhand - toset + 1); - char *tok; - char *ptr; - - newtoset[errhand - toset] = '\0'; - toset = memcpy (newtoset, toset, errhand - toset); - - /* Find the appropriate transliteration handlers. */ - tok = strdupa (errhand); - - tok = __strtok_r (tok, ",", &ptr); - while (tok != NULL) - { - if (__strcasecmp_l (tok, "TRANSLIT", &_nl_C_locobj) == 0) - { - /* It's the builtin transliteration handling. We only - support it for working on the internal encoding. */ - static const char *internal_trans_names[1] = { "INTERNAL" }; - struct trans_struct *lastp = NULL; - struct trans_struct *runp; - - for (runp = trans; runp != NULL; runp = runp->next) - if (runp->trans_fct == __gconv_transliterate) - break; - else - lastp = runp; - - if (runp == NULL) - { - struct trans_struct *newp; - - newp = (struct trans_struct *) alloca (sizeof (*newp)); - memset (newp, '\0', sizeof (*newp)); - - /* We leave the `name' field zero to signal that - this is an internal transliteration step. */ - newp->csnames = internal_trans_names; - newp->ncsnames = 1; - newp->trans_fct = __gconv_transliterate; - - if (lastp == NULL) - trans = newp; - else - lastp->next = newp; - } - } - else if (__strcasecmp_l (tok, "IGNORE", &_nl_C_locobj) == 0) - /* Set the flag to ignore all errors. */ - conv_flags |= __GCONV_IGNORE_ERRORS; - else - { - /* `tok' is possibly a module name. We'll see later - whether we can find it. But first see that we do - not already a module of this name. */ - struct trans_struct *lastp = NULL; - struct trans_struct *runp; - - for (runp = trans; runp != NULL; runp = runp->next) - if (runp->name != NULL - && __strcasecmp_l (tok, runp->name, - &_nl_C_locobj) == 0) - break; - else - lastp = runp; - - if (runp == NULL) - { - struct trans_struct *newp; - - newp = (struct trans_struct *) alloca (sizeof (*newp)); - memset (newp, '\0', sizeof (*newp)); - newp->name = tok; - - if (lastp == NULL) - trans = newp; - else - lastp->next = newp; - } - } - - tok = __strtok_r (NULL, ",", &ptr); - } - } - } - - /* For the source character set we ignore the error handler specification. - XXX Is this really always the best? */ - ignore = strchr (fromset, '/'); - if (ignore != NULL && (ignore = strchr (ignore + 1, '/')) != NULL - && *++ignore != '\0') - { - char *newfromset = (char *) alloca (ignore - fromset + 1); - - newfromset[ignore - fromset] = '\0'; - fromset = memcpy (newfromset, fromset, ignore - fromset); - } - - /* If the string is empty define this to mean the charset of the - currently selected locale. */ - if (strcmp (toset, "//") == 0) - { - const char *codeset = _NL_CURRENT (LC_CTYPE, CODESET); - size_t len = strlen (codeset); - char *dest; - toset = dest = (char *) alloca (len + 3); - memcpy (__mempcpy (dest, codeset, len), "//", 3); - } - if (strcmp (fromset, "//") == 0) - { - const char *codeset = _NL_CURRENT (LC_CTYPE, CODESET); - size_t len = strlen (codeset); - char *dest; - fromset = dest = (char *) alloca (len + 3); - memcpy (__mempcpy (dest, codeset, len), "//", 3); - } - - res = __gconv_find_transform (toset, fromset, &steps, &nsteps, flags); - if (res == __GCONV_OK) - { - /* Find the modules. */ - struct trans_struct *lastp = NULL; - struct trans_struct *runp; - - for (runp = trans; runp != NULL; runp = runp->next) - { - if (runp->name == NULL - || __builtin_expect (__gconv_translit_find (runp), 0) == 0) - lastp = runp; - else - /* This means we haven't found the module. Remove it. */ - (lastp == NULL ? trans : lastp->next) = runp->next; - } - - /* Allocate room for handle. */ - result = (__gconv_t) malloc (sizeof (struct __gconv_info) - + (nsteps - * sizeof (struct __gconv_step_data))); - if (result == NULL) - res = __GCONV_NOMEM; - else - { - size_t n; - - /* Remember the list of steps. */ - result->__steps = steps; - result->__nsteps = nsteps; - - /* Clear the array for the step data. */ - memset (result->__data, '\0', - nsteps * sizeof (struct __gconv_step_data)); - - /* Call all initialization functions for the transformation - step implementations. */ - for (cnt = 0; cnt < nsteps; ++cnt) - { - size_t size; - - /* Would have to be done if we would not clear the whole - array above. */ -#if 0 - /* Reset the counter. */ - result->__data[cnt].__invocation_counter = 0; - - /* It's a regular use. */ - result->__data[cnt].__internal_use = 0; -#endif - - /* We use the `mbstate_t' member in DATA. */ - result->__data[cnt].__statep = &result->__data[cnt].__state; - - /* Now see whether we can use any of the transliteration - modules for this step. */ - for (runp = trans; runp != NULL; runp = runp->next) - for (n = 0; n < runp->ncsnames; ++n) - if (__strcasecmp_l (steps[cnt].__from_name, - runp->csnames[n], &_nl_C_locobj) == 0) - { - void *data = NULL; - - /* Match! Now try the initializer. */ - if (runp->trans_init_fct == NULL - || (runp->trans_init_fct (&data, - steps[cnt].__to_name) - == __GCONV_OK)) - { - /* Append at the end of the list. */ - struct __gconv_trans_data *newp; - struct __gconv_trans_data **lastp; - - newp = (struct __gconv_trans_data *) - malloc (sizeof (struct __gconv_trans_data)); - if (newp == NULL) - { - res = __GCONV_NOMEM; - goto bail; - } - - newp->__trans_fct = runp->trans_fct; - newp->__trans_context_fct = runp->trans_context_fct; - newp->__trans_end_fct = runp->trans_end_fct; - newp->__data = data; - newp->__next = NULL; - - lastp = &result->__data[cnt].__trans; - while (*lastp != NULL) - lastp = &(*lastp)->__next; - - *lastp = newp; - } - break; - } - - /* If this is the last step we must not allocate an - output buffer. */ - if (cnt < nsteps - 1) - { - result->__data[cnt].__flags = conv_flags; - - /* Allocate the buffer. */ - size = (GCONV_NCHAR_GOAL * steps[cnt].__max_needed_to); - - result->__data[cnt].__outbuf = (char *) malloc (size); - if (result->__data[cnt].__outbuf == NULL) - { - res = __GCONV_NOMEM; - goto bail; - } - - result->__data[cnt].__outbufend = - result->__data[cnt].__outbuf + size; - } - else - { - /* Handle the last entry. */ - result->__data[cnt].__flags = conv_flags | __GCONV_IS_LAST; - - break; - } - } - } - - if (res != __GCONV_OK) - { - /* Something went wrong. Free all the resources. */ - int serrno; - bail: - serrno = errno; - - if (result != NULL) - { - while (cnt-- > 0) - { - struct __gconv_trans_data *transp; - - transp = result->__data[cnt].__trans; - while (transp != NULL) - { - struct __gconv_trans_data *curp = transp; - transp = transp->__next; - - if (__builtin_expect (curp->__trans_end_fct != NULL, 0)) - curp->__trans_end_fct (curp->__data); - - free (curp); - } - - free (result->__data[cnt].__outbuf); - } - - free (result); - result = NULL; - } - - __gconv_close_transform (steps, nsteps); - - __set_errno (serrno); - } - } - - *handle = result; - return res; -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv.c b/src/system/libroot/posix/glibc/iconv/iconv.c deleted file mode 100644 index d0f5528f55..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Convert characters in input buffer using conversion descriptor to - output buffer. - Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include /* for NULL */ -#include -#include - -#include - -#include - - -size_t -iconv (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, - size_t *outbytesleft) -{ - __gconv_t gcd = (__gconv_t) cd; - char *outstart = outbuf ? *outbuf : NULL; - size_t irreversible; - int result; - - if (__builtin_expect (inbuf == NULL || *inbuf == NULL, 0)) - { - if (outbuf == NULL || *outbuf == NULL) - result = __gconv (gcd, NULL, NULL, NULL, NULL, &irreversible); - else - result = __gconv (gcd, NULL, NULL, (unsigned char **) outbuf, - (unsigned char *) (outstart + *outbytesleft), - &irreversible); - } - else - { - const char *instart = *inbuf; - - result = __gconv (gcd, (const unsigned char **) inbuf, - (const unsigned char *) (*inbuf + *inbytesleft), - (unsigned char **) outbuf, - (unsigned char *) (*outbuf + *outbytesleft), - &irreversible); - - *inbytesleft -= *inbuf - instart; - } - if (outstart != NULL) - *outbytesleft -= *outbuf - outstart; - - switch (__builtin_expect (result, __GCONV_OK)) - { - case __GCONV_ILLEGAL_DESCRIPTOR: - __set_errno (EBADF); - irreversible = (size_t) -1L; - break; - - case __GCONV_ILLEGAL_INPUT: - __set_errno (EILSEQ); - irreversible = (size_t) -1L; - break; - - case __GCONV_FULL_OUTPUT: - __set_errno (E2BIG); - irreversible = (size_t) -1L; - break; - - case __GCONV_INCOMPLETE_INPUT: - __set_errno (EINVAL); - irreversible = (size_t) -1L; - break; - - case __GCONV_EMPTY_INPUT: - case __GCONV_OK: - /* Nothing. */ - break; - - default: - assert (!"Nothing like this should happen"); - } - - return irreversible; -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv.h b/src/system/libroot/posix/glibc/iconv/iconv.h deleted file mode 100644 index 5a795dc5df..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _ICONV_H -#define _ICONV_H 1 - -#include -#define __need_size_t -#include - - -__BEGIN_DECLS - -/* Identifier for conversion method from one codeset to another. */ -typedef void *iconv_t; - - -/* Allocate descriptor for code conversion from codeset FROMCODE to - codeset TOCODE. */ -extern iconv_t iconv_open (__const char *__tocode, __const char *__fromcode) - __THROW; - -/* Convert at most *INBYTESLEFT bytes from *INBUF according to the - code conversion algorithm specified by CD and place up to - *OUTBYTESLEFT bytes in buffer at *OUTBUF. */ -extern size_t iconv (iconv_t __cd, char **__restrict __inbuf, - size_t *__restrict __inbytesleft, - char **__restrict __outbuf, - size_t *__restrict __outbytesleft); - -/* Free resources allocated for descriptor CD for code conversion. */ -extern int iconv_close (iconv_t __cd) __THROW; - -__END_DECLS - -#endif /* iconv.h */ diff --git a/src/system/libroot/posix/glibc/iconv/iconv_charmap.c b/src/system/libroot/posix/glibc/iconv/iconv_charmap.c deleted file mode 100644 index 03a8f5fa23..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv_charmap.c +++ /dev/null @@ -1,568 +0,0 @@ -/* Convert using charmaps and possibly iconv(). - Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "iconv_prog.h" - - -/* Prototypes for a few program-wide used functions. */ -extern void *xmalloc (size_t __n); -extern void *xcalloc (size_t __n, size_t __s); - - -struct convtable -{ - int term[256 / 8]; - union - { - struct convtable *sub; - struct charseq *out; - } val[256]; -}; - - -static inline struct convtable * -allocate_table (void) -{ - return (struct convtable *) xcalloc (1, sizeof (struct convtable)); -} - - -static inline int -is_term (struct convtable *tbl, unsigned int idx) -{ - return tbl->term[idx / 8] & (1 << (idx % 8)); -} - - -static inline void -clear_term (struct convtable *tbl, unsigned int idx) -{ - tbl->term[idx / 8] &= ~(1 << (idx % 8)); -} - - -static inline void -set_term (struct convtable *tbl, unsigned int idx) -{ - tbl->term[idx / 8] |= 1 << (idx % 8); -} - - -/* Generate the conversion table. */ -static struct convtable *use_from_charmap (struct charmap_t *from_charmap, - const char *to_code); -static struct convtable *use_to_charmap (const char *from_code, - struct charmap_t *to_charmap); -static struct convtable *use_both_charmaps (struct charmap_t *from_charmap, - struct charmap_t *to_charmap); - -/* Prototypes for the functions doing the actual work. */ -static int process_block (struct convtable *tbl, char *addr, size_t len, - FILE *output); -static int process_fd (struct convtable *tbl, int fd, FILE *output); -static int process_file (struct convtable *tbl, FILE *input, FILE *output); - - -int -charmap_conversion (const char *from_code, struct charmap_t *from_charmap, - const char *to_code, struct charmap_t *to_charmap, - int argc, int remaining, char *argv[], FILE *output) -{ - struct convtable *cvtbl; - int status = EXIT_SUCCESS; - - /* We have three different cases to handle: - - - both, from_charmap and to_charmap, are available. This means we - can assume that the symbolic names match and use them to create - the mapping. - - - only from_charmap is available. In this case we can only hope that - the symbolic names used are of the form in which case we - can use a UCS4->"to_code" iconv() conversion for the second step. - - - only to_charmap is available. This is similar, only that we would - use iconv() for the "to_code"->UCS4 conversion. - - We first create a table which maps input bytes into output bytes. - Once this is done we can handle all three of the cases above - equally. */ - if (from_charmap != NULL) - { - if (to_charmap == NULL) - cvtbl = use_from_charmap (from_charmap, to_code); - else - cvtbl = use_both_charmaps (from_charmap, to_charmap); - } - else - { - assert (to_charmap != NULL); - cvtbl = use_to_charmap (from_code, to_charmap); - } - - /* If we couldn't generate a table stop now. */ - if (cvtbl == NULL) - return EXIT_FAILURE; - - /* We can now start the conversion. */ - if (remaining == argc) - { - if (process_file (cvtbl, stdin, output) != 0) - status = EXIT_FAILURE; - } - else - do - { - struct stat st; - char *addr; - int fd; - - if (verbose) - printf ("%s:\n", argv[remaining]); - if (strcmp (argv[remaining], "-") == 0) - fd = 0; - else - { - fd = open (argv[remaining], O_RDONLY); - - if (fd == -1) - { - error (0, errno, _("cannot open input file `%s'"), - argv[remaining]); - status = EXIT_FAILURE; - continue; - } - } - -#ifdef _POSIX_MAPPED_FILES - /* We have possibilities for reading the input file. First try - to mmap() it since this will provide the fastest solution. */ - if (fstat (fd, &st) == 0 - && ((addr = mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, - fd, 0)) != MAP_FAILED)) - { - /* Yes, we can use mmap(). The descriptor is not needed - anymore. */ - if (close (fd) != 0) - error (EXIT_FAILURE, errno, - _("error while closing input `%s'"), argv[remaining]); - - if (process_block (cvtbl, addr, st.st_size, output) < 0) - { - /* Something went wrong. */ - status = EXIT_FAILURE; - - /* We don't need the input data anymore. */ - munmap ((void *) addr, st.st_size); - - /* We cannot go on with producing output since it might - lead to problem because the last output might leave - the output stream in an undefined state. */ - break; - } - - /* We don't need the input data anymore. */ - munmap ((void *) addr, st.st_size); - } - else -#endif /* _POSIX_MAPPED_FILES */ - { - /* Read the file in pieces. */ - if (process_fd (cvtbl, fd, output) != 0) - { - /* Something went wrong. */ - status = EXIT_FAILURE; - - /* We don't need the input file anymore. */ - close (fd); - - /* We cannot go on with producing output since it might - lead to problem because the last output might leave - the output stream in an undefined state. */ - break; - } - - /* Now close the file. */ - close (fd); - } - } - while (++remaining < argc); - - /* All done. */ - return status; -} - - -static void -add_bytes (struct convtable *tbl, struct charseq *in, struct charseq *out) -{ - int n = 0; - unsigned int byte; - - assert (in->nbytes > 0); - - byte = ((unsigned char *) in->bytes)[n]; - while (n + 1 < in->nbytes) - { - if (is_term (tbl, byte) || tbl->val[byte].sub == NULL) - { - /* Note that we simply ignore a definition for a byte sequence - which is also the prefix for a longer one. */ - clear_term (tbl, byte); - tbl->val[byte].sub = - (struct convtable *) xcalloc (1, sizeof (struct convtable)); - } - - tbl = tbl->val[byte].sub; - - byte = ((unsigned char *) in->bytes)[++n]; - } - - /* Only add the new sequence if there is none yet and the byte sequence - is not part of an even longer one. */ - if (! is_term (tbl, byte) && tbl->val[byte].sub == NULL) - { - set_term (tbl, byte); - tbl->val[byte].out = out; - } -} - - -static struct convtable * -use_from_charmap (struct charmap_t *from_charmap, const char *to_code) -{ - /* We iterate over all entries in the from_charmap and for those which - have a known UCS4 representation we use an iconv() call to determine - the mapping to the to_code charset. */ - struct convtable *rettbl; - iconv_t cd; - void *ptr = NULL; - const void *key; - size_t keylen; - void *data; - - cd = iconv_open (to_code, "WCHAR_T"); - if (cd == (iconv_t) -1) - /* We cannot do anything. */ - return NULL; - - rettbl = allocate_table (); - - while (iterate_table (&from_charmap->char_table, &ptr, &key, &keylen, &data) - >= 0) - { - struct charseq *in = (struct charseq *) data; - - if (in->ucs4 != UNINITIALIZED_CHAR_VALUE) - { - /* There is a chance. Try the iconv module. */ - wchar_t inbuf[1] = { in->ucs4 }; - unsigned char outbuf[64]; - char *inptr = (char *) inbuf; - size_t inlen = sizeof (inbuf); - char *outptr = (char *) outbuf; - size_t outlen = sizeof (outbuf); - - (void) iconv (cd, &inptr, &inlen, &outptr, &outlen); - - if (outptr != (char *) outbuf) - { - /* We got some output. Good, use it. */ - struct charseq *newp; - - outlen = sizeof (outbuf) - outlen; - assert ((char *) outbuf + outlen == outptr); - - newp = (struct charseq *) xmalloc (sizeof (struct charseq) - + outlen); - newp->name = in->name; - newp->ucs4 = in->ucs4; - newp->nbytes = outlen; - memcpy (newp->bytes, outbuf, outlen); - - add_bytes (rettbl, in, newp); - } - - /* Clear any possible state left behind. */ - (void) iconv (cd, NULL, NULL, NULL, NULL); - } - } - - iconv_close (cd); - - return rettbl; -} - - -static struct convtable * -use_to_charmap (const char *from_code, struct charmap_t *to_charmap) -{ - /* We iterate over all entries in the to_charmap and for those which - have a known UCS4 representation we use an iconv() call to determine - the mapping to the from_code charset. */ - struct convtable *rettbl; - iconv_t cd; - void *ptr = NULL; - const void *key; - size_t keylen; - void *data; - - /* Note that the conversion we use here is the reverse direction. Without - exhaustive search we cannot figure out which input yields the UCS4 - character we are looking for. Therefore we determine it the other - way round. */ - cd = iconv_open (from_code, "WCHAR_T"); - if (cd == (iconv_t) -1) - /* We cannot do anything. */ - return NULL; - - rettbl = allocate_table (); - - while (iterate_table (&to_charmap->char_table, &ptr, &key, &keylen, &data) - >= 0) - { - struct charseq *out = (struct charseq *) data; - - if (out->ucs4 != UNINITIALIZED_CHAR_VALUE) - { - /* There is a chance. Try the iconv module. */ - wchar_t inbuf[1] = { out->ucs4 }; - unsigned char outbuf[64]; - char *inptr = (char *) inbuf; - size_t inlen = sizeof (inbuf); - char *outptr = (char *) outbuf; - size_t outlen = sizeof (outbuf); - - (void) iconv (cd, &inptr, &inlen, &outptr, &outlen); - - if (outptr != (char *) outbuf) - { - /* We got some output. Good, use it. */ - struct charseq *newp; - - outlen = sizeof (outbuf) - outlen; - assert ((char *) outbuf + outlen == outptr); - - newp = (struct charseq *) xmalloc (sizeof (struct charseq) - + outlen); - newp->name = out->name; - newp->ucs4 = out->ucs4; - newp->nbytes = outlen; - memcpy (newp->bytes, outbuf, outlen); - - add_bytes (rettbl, newp, out); - } - - /* Clear any possible state left behind. */ - (void) iconv (cd, NULL, NULL, NULL, NULL); - } - } - - iconv_close (cd); - - return rettbl; -} - - -static struct convtable * -use_both_charmaps (struct charmap_t *from_charmap, - struct charmap_t *to_charmap) -{ - /* In this case we iterate over all the entries in the from_charmap, - determine the internal name, and find an appropriate entry in the - to_charmap (if it exists). */ - struct convtable *rettbl = allocate_table (); - void *ptr = NULL; - const void *key; - size_t keylen; - void *data; - - while (iterate_table (&from_charmap->char_table, &ptr, &key, &keylen, &data) - >= 0) - { - struct charseq *in = (struct charseq *) data; - struct charseq *out = charmap_find_value (to_charmap, key, keylen); - - if (out != NULL) - add_bytes (rettbl, in, out); - } - - return rettbl; -} - - -static int -process_block (struct convtable *tbl, char *addr, size_t len, FILE *output) -{ - size_t n = 0; - - while (n < len) - { - struct convtable *cur = tbl; - unsigned char *curp = (unsigned char *) addr; - unsigned int byte = *curp; - int cnt; - struct charseq *out; - - while (! is_term (cur, byte)) - if (cur->val[byte].sub == NULL) - { - /* This is a invalid sequence. Skip the first byte if we are - ignoring errors. Otherwise punt. */ - if (! omit_invalid) - { - error (0, 0, _("illegal input sequence at position %Zd"), n); - return -1; - } - - n -= curp - (unsigned char *) addr; - - byte = *(curp = (unsigned char *) ++addr); - if (++n >= len) - /* All converted. */ - return 0; - - cur = tbl; - } - else - { - cur = cur->val[byte].sub; - - if (++n >= len) - { - error (0, 0, _("\ -incomplete character or shift sequence at end of buffer")); - return -1; - } - - byte = *++curp; - } - - /* We found a final byte. Write the output bytes. */ - out = cur->val[byte].out; - for (cnt = 0; cnt < out->nbytes; ++cnt) - fputc_unlocked (out->bytes[cnt], output); - - addr = (char *) curp + 1; - ++n; - } - - return 0; -} - - -static int -process_fd (struct convtable *tbl, int fd, FILE *output) -{ - /* We have a problem with reading from a descriptor since we must not - provide the iconv() function an incomplete character or shift - sequence at the end of the buffer. Since we have to deal with - arbitrary encodings we must read the whole text in a buffer and - process it in one step. */ - static char *inbuf = NULL; - static size_t maxlen = 0; - char *inptr = NULL; - size_t actlen = 0; - - while (actlen < maxlen) - { - ssize_t n = read (fd, inptr, maxlen - actlen); - - if (n == 0) - /* No more text to read. */ - break; - - if (n == -1) - { - /* Error while reading. */ - error (0, errno, _("error while reading the input")); - return -1; - } - - inptr += n; - actlen += n; - } - - if (actlen == maxlen) - while (1) - { - ssize_t n; - char *new_inbuf; - - /* Increase the buffer. */ - new_inbuf = (char *) realloc (inbuf, maxlen + 32768); - if (new_inbuf == NULL) - { - error (0, errno, _("unable to allocate buffer for input")); - return -1; - } - inbuf = new_inbuf; - maxlen += 32768; - inptr = inbuf + actlen; - - do - { - n = read (fd, inptr, maxlen - actlen); - - if (n == 0) - /* No more text to read. */ - break; - - if (n == -1) - { - /* Error while reading. */ - error (0, errno, _("error while reading the input")); - return -1; - } - - inptr += n; - actlen += n; - } - while (actlen < maxlen); - - if (n == 0) - /* Break again so we leave both loops. */ - break; - } - - /* Now we have all the input in the buffer. Process it in one run. */ - return process_block (tbl, inbuf, actlen, output); -} - - -static int -process_file (struct convtable *tbl, FILE *input, FILE *output) -{ - /* This should be safe since we use this function only for `stdin' and - we haven't read anything so far. */ - return process_fd (tbl, fileno (input), output); -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv_close.c b/src/system/libroot/posix/glibc/iconv/iconv_close.c deleted file mode 100644 index 038acc69e2..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv_close.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Release any resource associated with given conversion descriptor. - Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -#include - - -int -iconv_close (iconv_t cd) -{ - if (__builtin_expect (cd == (iconv_t *) -1L, 0)) - { - __set_errno (EBADF); - return -1; - } - - return __gconv_close ((__gconv_t) cd) ? -1 : 0; -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv_open.c b/src/system/libroot/posix/glibc/iconv/iconv_open.c deleted file mode 100644 index e0f6135575..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv_open.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Get descriptor for character set conversion. - Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -#include -#include "gconv_charset.h" - - -iconv_t -iconv_open (const char *tocode, const char *fromcode) -{ - char *tocode_conv; - char *fromcode_conv; - size_t tocode_len; - size_t fromcode_len; - __gconv_t cd; - int res; - - /* Normalize the name. We remove all characters beside alpha-numeric, - '_', '-', '/', and '.'. */ - tocode_len = strlen (tocode); - tocode_conv = (char *) alloca (tocode_len + 3); - strip (tocode_conv, tocode); - tocode = (tocode_conv[2] == '\0' && tocode[0] != '\0' - ? upstr (tocode_conv, tocode) : tocode_conv); - - fromcode_len = strlen (fromcode); - fromcode_conv = (char *) alloca (fromcode_len + 3); - strip (fromcode_conv, fromcode); - fromcode = (fromcode_conv[2] == '\0' && fromcode[0] != '\0' - ? upstr (fromcode_conv, fromcode) : fromcode_conv); - - res = __gconv_open (tocode, fromcode, &cd, 0); - - if (__builtin_expect (res, __GCONV_OK) != __GCONV_OK) - { - /* We must set the error number according to the specs. */ - if (res == __GCONV_NOCONV || res == __GCONV_NODB) - __set_errno (EINVAL); - - return (iconv_t) -1; - } - - return (iconv_t) cd; -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv_prog.c b/src/system/libroot/posix/glibc/iconv/iconv_prog.c deleted file mode 100644 index 78b430d7d7..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv_prog.c +++ /dev/null @@ -1,770 +0,0 @@ -/* Convert text in given files from the specified from-set to the to-set. - Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _POSIX_MAPPED_FILES -# include -#endif -#include -#include -#include "iconv_prog.h" -#include "iconvconfig.h" - -/* Get libc version number. */ -#include "../version.h" - -#define PACKAGE _libc_intl_domainname - - -/* Name and version of program. */ -static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; - -#define OPT_VERBOSE 1000 -#define OPT_LIST 'l' - -/* Definitions of arguments for argp functions. */ -static const struct argp_option options[] = -{ - { NULL, 0, NULL, 0, N_("Input/Output format specification:") }, - { "from-code", 'f', "NAME", 0, N_("encoding of original text") }, - { "to-code", 't', "NAME", 0, N_("encoding for output") }, - { NULL, 0, NULL, 0, N_("Information:") }, - { "list", 'l', NULL, 0, N_("list all known coded character sets") }, - { NULL, 0, NULL, 0, N_("Output control:") }, - { NULL, 'c', NULL, 0, N_("omit invalid characters from output") }, - { "output", 'o', "FILE", 0, N_("output file") }, - { "silent", 's', NULL, 0, N_("suppress warnings") }, - { "verbose", OPT_VERBOSE, NULL, 0, N_("print progress information") }, - { NULL, 0, NULL, 0, NULL } -}; - -/* Short description of program. */ -static const char doc[] = N_("\ -Convert encoding of given files from one encoding to another."); - -/* Strings for arguments in help texts. */ -static const char args_doc[] = N_("[FILE...]"); - -/* Prototype for option handler. */ -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -/* Function to print some extra text in the help message. */ -static char *more_help (int key, const char *text, void *input); - -/* Data structure to communicate with argp functions. */ -static struct argp argp = -{ - options, parse_opt, args_doc, doc, NULL, more_help -}; - -/* Code sets to convert from and to respectively. An empty string as the - default causes the 'iconv_open' function to look up the charset of the - currently selected locale and use it. */ -static const char *from_code = ""; -static const char *to_code = ""; - -/* File to write output to. If NULL write to stdout. */ -static const char *output_file; - -/* Nonzero if verbose ouput is wanted. */ -int verbose; - -/* Nonzero if list of all coded character sets is wanted. */ -static int list; - -/* If nonzero omit invalid character from output. */ -int omit_invalid; - -/* Prototypes for the functions doing the actual work. */ -static int process_block (iconv_t cd, char *addr, size_t len, FILE *output); -static int process_fd (iconv_t cd, int fd, FILE *output); -static int process_file (iconv_t cd, FILE *input, FILE *output); -static void print_known_names (void) internal_function; - - -int -main (int argc, char *argv[]) -{ - int status = EXIT_SUCCESS; - int remaining; - FILE *output; - iconv_t cd; - const char *orig_to_code; - struct charmap_t *from_charmap = NULL; - struct charmap_t *to_charmap = NULL; - - /* Set locale via LC_ALL. */ - setlocale (LC_ALL, ""); - - /* Set the text message domain. */ - textdomain (_libc_intl_domainname); - - /* Parse and process arguments. */ - argp_parse (&argp, argc, argv, 0, &remaining, NULL); - - /* List all coded character sets if wanted. */ - if (list) - { - print_known_names (); - exit (EXIT_SUCCESS); - } - - /* If we have to ignore errors make sure we use the appropriate name for - the to-character-set. */ - orig_to_code = to_code; - if (omit_invalid) - { - const char *errhand = strchrnul (to_code, '/'); - int nslash = 2; - char *newp; - char *cp; - - if (*errhand == '/') - { - --nslash; - errhand = strchrnul (errhand, '/'); - - if (*errhand == '/') - { - --nslash; - ++errhand; - } - } - - newp = (char *) alloca (errhand - to_code + nslash + 6 + 1); - cp = mempcpy (newp, to_code, errhand - to_code); - while (nslash-- > 0) - *cp++ = '/'; - memcpy (cp, "IGNORE", sizeof ("IGNORE")); - - to_code = newp; - } - - /* POSIX 1003.2b introduces a silly thing: the arguments to -t anf -f - can be file names of charmaps. In this case iconv will have to read - those charmaps and use them to do the conversion. But there are - holes in the specification. There is nothing said that if -f is a - charmap filename that -t must be, too. And vice versa. There is - also no word about the symbolic names used. What if they don't - match? */ - if (strchr (from_code, '/') != NULL) - /* The from-name might be a charmap file name. Try reading the - file. */ - from_charmap = charmap_read (from_code, /*0, 1*/1, 0, 0); - - if (strchr (orig_to_code, '/') != NULL) - /* The to-name might be a charmap file name. Try reading the - file. */ - to_charmap = charmap_read (orig_to_code, /*0, 1,*/1,0, 0); - - - /* Determine output file. */ - if (output_file != NULL && strcmp (output_file, "-") != 0) - { - output = fopen (output_file, "w"); - if (output == NULL) - error (EXIT_FAILURE, errno, _("cannot open output file")); - } - else - output = stdout; - - /* At this point we have to handle two cases. The first one is - where a charmap is used for the from- or to-charset, or both. We - handle this special since it is very different from the sane way of - doing things. The other case allows converting using the iconv() - function. */ - if (from_charmap != NULL || to_charmap != NULL) - /* Construct the conversion table and do the conversion. */ - status = charmap_conversion (from_code, from_charmap, to_code, to_charmap, - argc, remaining, argv, output); - else - { - /* Let's see whether we have these coded character sets. */ - cd = iconv_open (to_code, from_code); - if (cd == (iconv_t) -1) - { - if (errno == EINVAL) - { - /* Try to be nice with the user and tell her which of the - two encoding names is wrong. This is possible because - all supported encodings can be converted from/to Unicode, - in other words, because the graph of encodings is - connected. */ - bool from_wrong = - (iconv_open ("UTF-8", from_code) == (iconv_t) -1 - && errno == EINVAL); - bool to_wrong = - (iconv_open (to_code, "UTF-8") == (iconv_t) -1 - && errno == EINVAL); - const char *from_pretty = - (from_code[0] ? from_code : nl_langinfo (CODESET)); - const char *to_pretty = - (orig_to_code[0] ? orig_to_code : nl_langinfo (CODESET)); - - if (from_wrong) - { - if (to_wrong) - error (EXIT_FAILURE, 0, - _("\ -conversion from `%s' and to `%s' are not supported"), - from_pretty, to_pretty); - else - error (EXIT_FAILURE, 0, - _("conversion from `%s' is not supported"), - from_pretty); - } - else - { - if (to_wrong) - error (EXIT_FAILURE, 0, - _("conversion to `%s' is not supported"), - to_pretty); - else - error (EXIT_FAILURE, 0, - _("conversion from `%s' to `%s' is not supported"), - from_pretty, to_pretty); - } - } - else - error (EXIT_FAILURE, errno, - _("failed to start conversion processing")); - } - - /* Now process the remaining files. Write them to stdout or the file - specified with the `-o' parameter. If we have no file given as - the parameter process all from stdin. */ - if (remaining == argc) - { - if (process_file (cd, stdin, output) != 0) - status = EXIT_FAILURE; - } - else - do - { -#ifdef _POSIX_MAPPED_FILES - struct stat st; - char *addr; -#endif - int fd; - - if (verbose) - printf ("%s:\n", argv[remaining]); - if (strcmp (argv[remaining], "-") == 0) - fd = 0; - else - { - fd = open (argv[remaining], O_RDONLY); - - if (fd == -1) - { - error (0, errno, _("cannot open input file `%s'"), - argv[remaining]); - status = EXIT_FAILURE; - continue; - } - } - -#ifdef _POSIX_MAPPED_FILES - /* We have possibilities for reading the input file. First try - to mmap() it since this will provide the fastest solution. */ - if (fstat (fd, &st) == 0 - && ((addr = mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, - fd, 0)) != MAP_FAILED)) - { - /* Yes, we can use mmap(). The descriptor is not needed - anymore. */ - if (close (fd) != 0) - error (EXIT_FAILURE, errno, - _("error while closing input `%s'"), - argv[remaining]); - - if (process_block (cd, addr, st.st_size, output) < 0) - { - /* Something went wrong. */ - status = EXIT_FAILURE; - - /* We don't need the input data anymore. */ - munmap ((void *) addr, st.st_size); - - /* We cannot go on with producing output since it might - lead to problem because the last output might leave - the output stream in an undefined state. */ - break; - } - - /* We don't need the input data anymore. */ - munmap ((void *) addr, st.st_size); - } - else -#endif /* _POSIX_MAPPED_FILES */ - { - /* Read the file in pieces. */ - if (process_fd (cd, fd, output) != 0) - { - /* Something went wrong. */ - status = EXIT_FAILURE; - - /* We don't need the input file anymore. */ - close (fd); - - /* We cannot go on with producing output since it might - lead to problem because the last output might leave - the output stream in an undefined state. */ - break; - } - - /* Now close the file. */ - close (fd); - } - } - while (++remaining < argc); - } - - /* Close the output file now. */ - if (fclose (output)) - error (EXIT_FAILURE, errno, _("error while closing output file")); - - return status; -} - - -/* Handle program arguments. */ -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case 'f': - from_code = arg; - break; - case 't': - to_code = arg; - break; - case 'o': - output_file = arg; - break; - case 's': - /* Nothing, for now at least. We are not giving out any information - about missing character or so. */ - break; - case 'c': - /* Omit invalid characters from output. */ - omit_invalid = 1; - break; - case OPT_VERBOSE: - verbose = 1; - break; - case OPT_LIST: - list = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - - -static char * -more_help (int key, const char *text, void *input) -{ - switch (key) - { - case ARGP_KEY_HELP_EXTRA: - /* We print some extra information. */ - return strdup (gettext ("\ -Report bugs using the `glibcbug' script to .\n")); - default: - break; - } - return (char *) text; -} - - -/* Print the version information. */ -static void -print_version (FILE *stream, struct argp_state *state) -{ - fprintf (stream, "iconv (GNU %s) %s\n", PACKAGE, VERSION); - fprintf (stream, gettext ("\ -Copyright (C) %s Free Software Foundation, Inc.\n\ -This is free software; see the source for copying conditions. There is NO\n\ -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2003"); - fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); -} - - -static int -process_block (iconv_t cd, char *addr, size_t len, FILE *output) -{ -#define OUTBUF_SIZE 32768 - const char *start = addr; - char outbuf[OUTBUF_SIZE]; - char *outptr; - size_t outlen; - size_t n; - - while (len > 0) - { - outptr = outbuf; - outlen = OUTBUF_SIZE; - n = iconv (cd, &addr, &len, &outptr, &outlen); - - if (outptr != outbuf) - { - /* We have something to write out. */ - int errno_save = errno; - - if (fwrite (outbuf, 1, outptr - outbuf, output) - < (size_t) (outptr - outbuf) - || ferror (output)) - { - /* Error occurred while printing the result. */ - error (0, 0, _("\ -conversion stopped due to problem in writing the output")); - return -1; - } - - errno = errno_save; - } - - if (n != (size_t) -1) - { - /* All the input test is processed. For state-dependent - character sets we have to flush the state now. */ - outptr = outbuf; - outlen = OUTBUF_SIZE; - (void) iconv (cd, NULL, NULL, &outptr, &outlen); - - if (outptr != outbuf) - { - /* We have something to write out. */ - int errno_save = errno; - - if (fwrite (outbuf, 1, outptr - outbuf, output) - < (size_t) (outptr - outbuf) - || ferror (output)) - { - /* Error occurred while printing the result. */ - error (0, 0, _("\ -conversion stopped due to problem in writing the output")); - return -1; - } - - errno = errno_save; - } - - break; - } - - if (errno != E2BIG) - { - /* iconv() ran into a problem. */ - switch (errno) - { - case EILSEQ: - error (0, 0, _("illegal input sequence at position %ld"), - (long) (addr - start)); - break; - case EINVAL: - error (0, 0, _("\ -incomplete character or shift sequence at end of buffer")); - break; - case EBADF: - error (0, 0, _("internal error (illegal descriptor)")); - break; - default: - error (0, 0, _("unknown iconv() error %d"), errno); - break; - } - - return -1; - } - } - - return 0; -} - - -static int -process_fd (iconv_t cd, int fd, FILE *output) -{ - /* we have a problem with reading from a desriptor since we must not - provide the iconv() function an incomplete character or shift - sequence at the end of the buffer. Since we have to deal with - arbitrary encodings we must read the whole text in a buffer and - process it in one step. */ - static char *inbuf = NULL; - static size_t maxlen = 0; - char *inptr = NULL; - size_t actlen = 0; - - while (actlen < maxlen) - { - ssize_t n = read (fd, inptr, maxlen - actlen); - - if (n == 0) - /* No more text to read. */ - break; - - if (n == -1) - { - /* Error while reading. */ - error (0, errno, _("error while reading the input")); - return -1; - } - - inptr += n; - actlen += n; - } - - if (actlen == maxlen) - while (1) - { - ssize_t n; - char *new_inbuf; - - /* Increase the buffer. */ - new_inbuf = (char *) realloc (inbuf, maxlen + 32768); - if (new_inbuf == NULL) - { - error (0, errno, _("unable to allocate buffer for input")); - return -1; - } - inbuf = new_inbuf; - maxlen += 32768; - inptr = inbuf + actlen; - - do - { - n = read (fd, inptr, maxlen - actlen); - - if (n == 0) - /* No more text to read. */ - break; - - if (n == -1) - { - /* Error while reading. */ - error (0, errno, _("error while reading the input")); - return -1; - } - - inptr += n; - actlen += n; - } - while (actlen < maxlen); - - if (n == 0) - /* Break again so we leave both loops. */ - break; - } - - /* Now we have all the input in the buffer. Process it in one run. */ - return process_block (cd, inbuf, actlen, output); -} - - -static int -process_file (iconv_t cd, FILE *input, FILE *output) -{ - /* This should be safe since we use this function only for `stdin' and - we haven't read anything so far. */ - return process_fd (cd, fileno (input), output); -} - - -/* Print all known character sets/encodings. */ -static void *printlist; -static size_t column; -static int not_first; - -static void -insert_print_list (const void *nodep, VISIT value, int level) -{ - if (value == leaf || value == postorder) - { - const struct gconv_alias *s = *(const struct gconv_alias **) nodep; - tsearch (s->fromname, &printlist, (__compar_fn_t) strverscmp); - } -} - -static void -do_print_human (const void *nodep, VISIT value, int level) -{ - if (value == leaf || value == postorder) - { - const char *s = *(const char **) nodep; - size_t len = strlen (s); - size_t cnt; - - while (len > 0 && s[len - 1] == '/') - --len; - - for (cnt = 0; cnt < len; ++cnt) - if (isalnum (s[cnt])) - break; - if (cnt == len) - return; - - if (not_first) - { - putchar (','); - ++column; - - if (column > 2 && column + len > 77) - { - fputs ("\n ", stdout); - column = 2; - } - else - { - putchar (' '); - ++column; - } - } - else - not_first = 1; - - fwrite (s, len, 1, stdout); - column += len; - } -} - -static void -do_print (const void *nodep, VISIT value, int level) -{ - if (value == leaf || value == postorder) - { - const char *s = *(const char **) nodep; - - puts (s); - } -} - -static void -internal_function -add_known_names (struct gconv_module *node) -{ - if (node->left != NULL) - add_known_names (node->left); - if (node->right != NULL) - add_known_names (node->right); - do - { - if (strcmp (node->from_string, "INTERNAL")) - tsearch (node->from_string, &printlist, - (__compar_fn_t) strverscmp); - if (strcmp (node->to_string, "INTERNAL") != 0) - tsearch (node->to_string, &printlist, (__compar_fn_t) strverscmp); - - node = node->same; - } - while (node != NULL); -} - - -static void -insert_cache (void) -{ - const struct gconvcache_header *header; - const char *strtab; - const struct hash_entry *hashtab; - size_t cnt; - - header = (const struct gconvcache_header *) __gconv_get_cache (); - strtab = (char *) header + header->string_offset; - hashtab = (struct hash_entry *) ((char *) header + header->hash_offset); - - for (cnt = 0; cnt < header->hash_size; ++cnt) - if (hashtab[cnt].string_offset != 0) - { - const char *str = strtab + hashtab[cnt].string_offset; - - if (strcmp (str, "INTERNAL") != 0) - tsearch (str, &printlist, (__compar_fn_t) strverscmp); - } -} - - -static void -internal_function -print_known_names (void) -{ - iconv_t h; - void *cache; - - /* We must initialize the internal databases first. */ - h = iconv_open ("L1", "L1"); - iconv_close (h); - - /* See whether we have a cache. */ - cache = __gconv_get_cache (); - if (cache != NULL) - /* Yep, use only this information. */ - insert_cache (); - else - { - struct gconv_module *modules; - - /* No, then use the information read from the gconv-modules file. - First add the aliases. */ - twalk (__gconv_get_alias_db (), insert_print_list); - - /* Add the from- and to-names from the known modules. */ - modules = __gconv_get_modules_db (); - if (modules != NULL) - add_known_names (modules); - } - - fputs (_("\ -The following list contain all the coded character sets known. This does\n\ -not necessarily mean that all combinations of these names can be used for\n\ -the FROM and TO command line parameters. One coded character set can be\n\ -listed with several different names (aliases).\n\n "), stdout); - - /* Now print the collected names. */ - column = 2; - if (isatty (fileno (stdout))) - { - twalk (printlist, do_print_human); - - if (column != 0) - puts (""); - } - else - twalk (printlist, do_print); -} diff --git a/src/system/libroot/posix/glibc/iconv/iconv_prog.h b/src/system/libroot/posix/glibc/iconv/iconv_prog.h deleted file mode 100644 index 17d67dddc5..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconv_prog.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _ICONV_PROG_H -#define _ICONV_PROG_H 1 - -#include -#include - - -/* Nonzero if verbose ouput is wanted. */ -extern int verbose; - -/* If nonzero omit invalid character from output. */ -extern int omit_invalid; - -/* Perform the conversion using a charmap or two. */ -extern int charmap_conversion (const char *from_code, - struct charmap_t *from_charmap, - const char *to_code, - struct charmap_t *to_charmap, - int argc, int remaining, char *argv[], - FILE *output); - - -#endif /* iconv_prog.h */ diff --git a/src/system/libroot/posix/glibc/iconv/iconvconfig.c b/src/system/libroot/posix/glibc/iconv/iconvconfig.c deleted file mode 100644 index 33ffeb34fc..0000000000 --- a/src/system/libroot/posix/glibc/iconv/iconvconfig.c +++ /dev/null @@ -1,1210 +0,0 @@ -/* Generate fastloading iconv module configuration files. - Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "iconvconfig.h" - -/* Get libc version number. */ -#include "../version.h" - -#define PACKAGE _libc_intl_domainname - - -/* The hashing function we use. */ -#include "../intl/hash-string.h" - - -/* Types used. */ -struct module -{ - char *fromname; - struct Strent *fromname_strent; - char *filename; - struct Strent *filename_strent; - const char *directory; - struct Strent *directory_strent; - struct module *next; - int cost; - struct Strent *toname_strent; - char toname[0]; -}; - -struct alias -{ - char *fromname; - struct Strent *froment; - struct module *module; - struct Strent *toent; - char toname[0]; -}; - -struct name -{ - const char *name; - struct Strent *strent; - int module_idx; - uint32_t hashval; -}; - -struct name_info -{ - const char *canonical_name; - struct Strent *canonical_strent; - - struct module *from_internal; - struct module *to_internal; - - struct other_conv_list - { - int dest_idx; - struct other_conv - { - gidx_t module_idx; - struct module *module; - struct other_conv *next; - } other_conv; - struct other_conv_list *next; - } *other_conv_list; -}; - - -/* Name and version of program. */ -static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; - -/* Short description of program. */ -static const char doc[] = N_("\ -Create fastloading iconv module configuration file."); - -/* Strings for arguments in help texts. */ -static const char args_doc[] = N_("[DIR...]"); - -/* Prototype for option handler. */ -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -/* Function to print some extra text in the help message. */ -static char *more_help (int key, const char *text, void *input); - -/* Definitions of arguments for argp functions. */ -#define OPT_PREFIX 300 -static const struct argp_option options[] = -{ - { "prefix", OPT_PREFIX, "PATH", 0, N_("Prefix used for all file accesses") }, - { NULL, 0, NULL, 0, NULL } -}; - -/* Data structure to communicate with argp functions. */ -static struct argp argp = -{ - - options, parse_opt, args_doc, doc, NULL, more_help -}; - - -/* The function doing the actual work. */ -static int handle_dir (const char *dir); - -/* Add all known builtin conversions and aliases. */ -static void add_builtins (void); - -/* Create list of all aliases without circular aliases. */ -static void get_aliases (void); - -/* Create list of all modules. */ -static void get_modules (void); - -/* Get list of all the names and thereby indexing them. */ -static void generate_name_list (void); - -/* Collect information about all the names. */ -static void generate_name_info (void); - -/* Write the output file. */ -static int write_output (void); - - -/* Prefix to be used for all file accesses. */ -static const char *prefix = ""; -/* Its length. */ -static size_t prefix_len; - -/* Search tree of the modules we know. */ -static void *modules; - -/* Search tree of the aliases we know. */ -static void *aliases; - -/* Search tree for name to index mapping. */ -static void *names; - -/* Number of names we know about. */ -static int nnames; - -/* List of all aliases. */ -static struct alias **alias_list; -static size_t nalias_list; -static size_t nalias_list_max; - -/* List of all modules. */ -static struct module **module_list; -static size_t nmodule_list; -static size_t nmodule_list_max; - -/* Names and information about them. */ -static struct name_info *name_info; -static size_t nname_info; - -/* Number of translations not from or to INTERNAL. */ -static size_t nextra_modules; - - -/* Names and aliases for the builtin transformations. */ -static struct -{ - const char *from; - const char *to; -} builtin_alias[] = - { -#define BUILTIN_ALIAS(alias, real) \ - { .from = alias, .to = real }, -#define BUILTIN_TRANSFORMATION(From, To, Cost, Name, Fct, BtowcFct, \ - MinF, MaxF, MinT, MaxT) -#include - }; -#undef BUILTIN_ALIAS -#undef BUILTIN_TRANSFORMATION -#define nbuiltin_alias (sizeof (builtin_alias) / sizeof (builtin_alias[0])) - -static struct -{ - const char *from; - const char *to; - const char *module; - int cost; -} builtin_trans[] = - { -#define BUILTIN_ALIAS(alias, real) -#define BUILTIN_TRANSFORMATION(From, To, Cost, Name, Fct, BtowcFct, \ - MinF, MaxF, MinT, MaxT) \ - { .from = From, .to = To, .module = Name, .cost = Cost }, -#include - }; -#undef BUILTIN_ALIAS -#undef BUILTIN_TRANSFORMATION -#define nbuiltin_trans (sizeof (builtin_trans) / sizeof (builtin_trans[0])) - - -/* Filename extension for the modules. */ -#ifndef MODULE_EXT -# define MODULE_EXT ".so" -#endif -static const char gconv_module_ext[] = MODULE_EXT; - - -extern void *xmalloc (size_t n) __attribute_malloc__; -extern void *xcalloc (size_t n, size_t m) __attribute_malloc__; -extern void *xrealloc (void *p, size_t n); - - -/* C string table handling. */ -struct Strtab; -struct Strent; - -/* Create new C string table object in memory. */ -extern struct Strtab *strtabinit (void); - -/* Free resources allocated for C string table ST. */ -extern void strtabfree (struct Strtab *st); - -/* Add string STR (length LEN is != 0) to C string table ST. */ -extern struct Strent *strtabadd (struct Strtab *st, const char *str, - size_t len); - -/* Finalize string table ST and store size in *SIZE and return a pointer. */ -extern void *strtabfinalize (struct Strtab *st, size_t *size); - -/* Get offset in string table for string associated with SE. */ -extern size_t strtaboffset (struct Strent *se); - -/* String table we construct. */ -static struct Strtab *strtab; - - - -int -main (int argc, char *argv[]) -{ - int remaining; - int status = 0; - char *path; - char *tp; - - /* Enable memory use testing. */ - /* mcheck_pedantic (NULL); */ - mtrace (); - - /* Set locale via LC_ALL. */ - setlocale (LC_ALL, ""); - - /* Set the text message domain. */ - textdomain (_libc_intl_domainname); - - /* Parse and process arguments. */ - argp_parse (&argp, argc, argv, 0, &remaining, NULL); - - /* Initialize the string table. */ - strtab = strtabinit (); - - /* Handle all directories mentioned. */ - while (remaining < argc) - status |= handle_dir (argv[remaining++]); - - /* In any case also handle the standard directory. */ - path = strdupa (GCONV_PATH); - tp = strtok (path, ":"); - while (tp != NULL) - { - status |= handle_dir (tp); - - tp = strtok (NULL, ":"); - } - - /* Add the builtin transformations and aliases without overwriting - anything. */ - add_builtins (); - - /* Store aliases in an array. */ - get_aliases (); - - /* Get list of all modules. */ - get_modules (); - - /* Generate list of all the names we know to handle in some way. */ - generate_name_list (); - - /* Now we know all the names we will handle, collect information - about them. */ - generate_name_info (); - - /* Write the output file, but only if we haven't seen any error. */ - if (status == 0) - status = write_output (); - else - error (1, 0, _("no output file produced because warning were issued")); - - return status; -} - - -/* Handle program arguments. */ -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case OPT_PREFIX: - prefix = arg; - prefix_len = strlen (prefix); - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - - -static char * -more_help (int key, const char *text, void *input) -{ - switch (key) - { - case ARGP_KEY_HELP_EXTRA: - /* We print some extra information. */ - return strdup (gettext ("\ -Report bugs using the `glibcbug' script to .\n")); - default: - break; - } - return (char *) text; -} - - -/* Print the version information. */ -static void -print_version (FILE *stream, struct argp_state *state) -{ - fprintf (stream, "iconvconfig (GNU %s) %s\n", PACKAGE, VERSION); - fprintf (stream, gettext ("\ -Copyright (C) %s Free Software Foundation, Inc.\n\ -This is free software; see the source for copying conditions. There is NO\n\ -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2003"); - fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); -} - - -static int -alias_compare (const void *p1, const void *p2) -{ - const struct alias *a1 = (const struct alias *) p1; - const struct alias *a2 = (const struct alias *) p2; - - return strcmp (a1->fromname, a2->fromname); -} - - -static void -new_alias (const char *fromname, size_t fromlen, const char *toname, - size_t tolen) -{ - struct alias *newp; - void **inserted; - - newp = (struct alias *) xmalloc (sizeof (struct alias) + fromlen + tolen); - - newp->fromname = mempcpy (newp->toname, toname, tolen); - memcpy (newp->fromname, fromname, fromlen); - newp->module = NULL; - - inserted = (void **) tsearch (newp, &aliases, alias_compare); - if (inserted == NULL) - error (EXIT_FAILURE, errno, gettext ("while inserting in search tree")); - if (*inserted != newp) - /* Something went wrong, free this entry. */ - free (newp); - else - { - newp->froment = strtabadd (strtab, newp->fromname, fromlen); - newp->toent = strtabadd (strtab, newp->toname, tolen); - } -} - - -/* Add new alias. */ -static void -add_alias (char *rp) -{ - /* We now expect two more string. The strings are normalized - (converted to UPPER case) and strored in the alias database. */ - char *from; - char *to; - char *wp; - - while (isspace (*rp)) - ++rp; - from = wp = rp; - while (*rp != '\0' && !isspace (*rp)) - *wp++ = toupper (*rp++); - if (*rp == '\0') - /* There is no `to' string on the line. Ignore it. */ - return; - *wp++ = '\0'; - to = ++rp; - while (isspace (*rp)) - ++rp; - while (*rp != '\0' && !isspace (*rp)) - *wp++ = toupper (*rp++); - if (to == wp) - /* No `to' string, ignore the line. */ - return; - *wp++ = '\0'; - - assert (strlen (from) + 1 == (size_t) (to - from)); - assert (strlen (to) + 1 == (size_t) (wp - to)); - - new_alias (from, to - from, to, wp - to); -} - - -static void -append_alias (const void *nodep, VISIT value, int level) -{ - if (value != leaf && value != postorder) - return; - - if (nalias_list_max == nalias_list) - { - nalias_list_max += 50; - alias_list = (struct alias **) xrealloc (alias_list, - (nalias_list_max - * sizeof (struct alias *))); - } - - alias_list[nalias_list++] = *(struct alias **) nodep; -} - - -static void -get_aliases (void) -{ - twalk (aliases, append_alias); -} - - -static int -module_compare (const void *p1, const void *p2) -{ - const struct module *m1 = (const struct module *) p1; - const struct module *m2 = (const struct module *) p2; - int result; - - result = strcmp (m1->fromname, m2->fromname); - if (result == 0) - result = strcmp (m1->toname, m2->toname); - - return result; -} - - -/* Create new module record. */ -static void -new_module (const char *fromname, size_t fromlen, const char *toname, - size_t tolen, const char *directory, - const char *filename, size_t filelen, int cost, size_t need_ext) -{ - struct module *new_module; - size_t dirlen = strlen (directory) + 1; - char *tmp; - void **inserted; - - new_module = (struct module *) xmalloc (sizeof (struct module) - + fromlen + tolen + filelen - + need_ext); - - new_module->fromname = mempcpy (new_module->toname, toname, tolen); - - new_module->filename = mempcpy (new_module->fromname, fromname, fromlen); - - new_module->cost = cost; - new_module->next = NULL; - - tmp = mempcpy (new_module->filename, filename, filelen); - if (need_ext) - { - memcpy (tmp - 1, gconv_module_ext, need_ext + 1); - filelen += need_ext; - } - new_module->directory = directory; - - /* Now insert the new module data structure in our search tree. */ - inserted = (void **) tsearch (new_module, &modules, module_compare); - if (inserted == NULL) - error (EXIT_FAILURE, errno, "while inserting in search tree"); - if (*inserted != new_module) - free (new_module); - else - { - new_module->fromname_strent = strtabadd (strtab, new_module->fromname, - fromlen); - new_module->toname_strent = strtabadd (strtab, new_module->toname, - tolen); - new_module->filename_strent = strtabadd (strtab, new_module->filename, - filelen); - new_module->directory_strent = strtabadd (strtab, directory, dirlen); - } -} - - -/* Add new module. */ -static void -internal_function -add_module (char *rp, const char *directory) -{ - /* We expect now - 1. `from' name - 2. `to' name - 3. filename of the module - 4. an optional cost value - */ - char *from; - char *to; - char *module; - char *wp; - int need_ext; - int cost; - - while (isspace (*rp)) - ++rp; - from = rp; - while (*rp != '\0' && !isspace (*rp)) - { - *rp = toupper (*rp); - ++rp; - } - if (*rp == '\0') - return; - *rp++ = '\0'; - to = wp = rp; - while (isspace (*rp)) - ++rp; - while (*rp != '\0' && !isspace (*rp)) - *wp++ = toupper (*rp++); - if (*rp == '\0') - return; - *wp++ = '\0'; - do - ++rp; - while (isspace (*rp)); - module = wp; - while (*rp != '\0' && !isspace (*rp)) - *wp++ = *rp++; - if (*rp == '\0') - { - /* There is no cost, use one by default. */ - *wp++ = '\0'; - cost = 1; - } - else - { - /* There might be a cost value. */ - char *endp; - - *wp++ = '\0'; - cost = strtol (rp, &endp, 10); - if (rp == endp || cost < 1) - /* No useful information. */ - cost = 1; - } - - if (module[0] == '\0') - /* No module name given. */ - return; - - /* See whether we must add the ending. */ - need_ext = 0; - if ((size_t) (wp - module) < sizeof (gconv_module_ext) - || memcmp (wp - sizeof (gconv_module_ext), gconv_module_ext, - sizeof (gconv_module_ext)) != 0) - /* We must add the module extension. */ - need_ext = sizeof (gconv_module_ext) - 1; - - assert (strlen (from) + 1 == (size_t) (to - from)); - assert (strlen (to) + 1 == (size_t) (module - to)); - assert (strlen (module) + 1 == (size_t) (wp - module)); - - new_module (from, to - from, to, module - to, directory, module, wp - module, - cost, need_ext); -} - - -/* Read the config file and add the data for this directory to that. */ -static int -handle_dir (const char *dir) -{ - char *infile; - char *cp; - FILE *fp; - char *line = NULL; - size_t linelen = 0; - size_t dirlen = strlen (dir); - - if (dir[dirlen - 1] != '/') - { - char *newp = (char *) xmalloc (dirlen + 2); - dir = memcpy (newp, dir, dirlen); - newp[dirlen++] = '/'; - newp[dirlen] = '\0'; - } - - cp = infile = (char *) alloca (prefix_len + dirlen + sizeof "gconv-modules"); - if (dir[0] == '/') - cp = mempcpy (cp, prefix, prefix_len); - strcpy (mempcpy (cp, dir, dirlen), "gconv-modules"); - - fp = fopen (infile, "r"); - if (fp == NULL) - { - error (0, errno, "cannot open `%s'", infile); - return 1; - } - - /* No threads present. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - while (!feof_unlocked (fp)) - { - char *rp, *endp, *word; - ssize_t n = __getdelim (&line, &linelen, '\n', fp); - - if (n < 0) - /* An error occurred. */ - break; - - rp = line; - /* Terminate the line (excluding comments or newline) with a NUL - byte to simplify the following code. */ - endp = strchr (rp, '#'); - if (endp != NULL) - *endp = '\0'; - else - if (rp[n - 1] == '\n') - rp[n - 1] = '\0'; - - while (isspace (*rp)) - ++rp; - - /* If this is an empty line go on with the next one. */ - if (rp == endp) - continue; - - word = rp; - while (*rp != '\0' && !isspace (*rp)) - ++rp; - - if (rp - word == sizeof ("alias") - 1 - && memcmp (word, "alias", sizeof ("alias") - 1) == 0) - add_alias (rp); - else if (rp - word == sizeof ("module") - 1 - && memcmp (word, "module", sizeof ("module") - 1) == 0) - add_module (rp, dir); - /* else */ - /* Otherwise ignore the line. */ - } - - free (line); - - fclose (fp); - - return 0; -} - - -static void -append_module (const void *nodep, VISIT value, int level) -{ - struct module *mo; - - if (value != leaf && value != postorder) - return; - - mo = *(struct module **) nodep; - - if (nmodule_list > 0 - && strcmp (module_list[nmodule_list - 1]->fromname, mo->fromname) == 0) - { - /* Same name. */ - mo->next = module_list[nmodule_list - 1]; - module_list[nmodule_list - 1] = mo; - - return; - } - - if (nmodule_list_max == nmodule_list) - { - nmodule_list_max += 50; - module_list = (struct module **) xrealloc (module_list, - (nmodule_list_max - * sizeof (struct module *))); - } - - module_list[nmodule_list++] = mo; -} - - -static void -get_modules (void) -{ - twalk (modules, append_module); -} - - -static void -add_builtins (void) -{ - size_t cnt; - - /* Add all aliases. */ - for (cnt = 0; cnt < nbuiltin_alias; ++cnt) - new_alias (builtin_alias[cnt].from, - strlen (builtin_alias[cnt].from) + 1, - builtin_alias[cnt].to, - strlen (builtin_alias[cnt].to) + 1); - - /* add the builtin transformations. */ - for (cnt = 0; cnt < nbuiltin_trans; ++cnt) - new_module (builtin_trans[cnt].from, - strlen (builtin_trans[cnt].from) + 1, - builtin_trans[cnt].to, - strlen (builtin_trans[cnt].to) + 1, - "", builtin_trans[cnt].module, - strlen (builtin_trans[cnt].module) + 1, - builtin_trans[cnt].cost, 0); -} - - -static int -name_compare (const void *p1, const void *p2) -{ - const struct name *n1 = (const struct name *) p1; - const struct name *n2 = (const struct name *) p2; - - return strcmp (n1->name, n2->name); -} - - -static struct name * -new_name (const char *str, struct Strent *strent) -{ - struct name *newp = (struct name *) xmalloc (sizeof (struct name)); - - newp->name = str; - newp->strent = strent; - newp->module_idx = -1; - newp->hashval = hash_string (str); - - ++nnames; - - return newp; -} - - -static void -generate_name_list (void) -{ - size_t i; - - /* A name we always need. */ - tsearch (new_name ("INTERNAL", strtabadd (strtab, "INTERNAL", - sizeof ("INTERNAL"))), - &names, name_compare); - - for (i = 0; i < nmodule_list; ++i) - { - struct module *runp; - - if (strcmp (module_list[i]->fromname, "INTERNAL") != 0) - tsearch (new_name (module_list[i]->fromname, - module_list[i]->fromname_strent), - &names, name_compare); - - for (runp = module_list[i]; runp != NULL; runp = runp->next) - if (strcmp (runp->toname, "INTERNAL") != 0) - tsearch (new_name (runp->toname, runp->toname_strent), - &names, name_compare); - } -} - - -static int -name_to_module_idx (const char *name, int add) -{ - struct name **res; - struct name fake_name = { .name = name }; - int idx; - - res = (struct name **) tfind (&fake_name, &names, name_compare); - if (res == NULL) - abort (); - - idx = (*res)->module_idx; - if (idx == -1 && add) - /* No module index assigned yet. */ - idx = (*res)->module_idx = nname_info++; - - return idx; -} - - -static void -generate_name_info (void) -{ - size_t i; - int idx; - - name_info = (struct name_info *) xcalloc (nmodule_list + 1, - sizeof (struct name_info)); - - /* First add a special entry for the INTERNAL name. This must have - index zero. */ - idx = name_to_module_idx ("INTERNAL", 1); - name_info[0].canonical_name = "INTERNAL"; - name_info[0].canonical_strent = strtabadd (strtab, "INTERNAL", - sizeof ("INTERNAL")); - assert (nname_info == 1); - - for (i = 0; i < nmodule_list; ++i) - { - struct module *runp; - - for (runp = module_list[i]; runp != NULL; runp = runp->next) - if (strcmp (runp->fromname, "INTERNAL") == 0) - { - idx = name_to_module_idx (runp->toname, 1); - name_info[idx].from_internal = runp; - assert (name_info[idx].canonical_name == NULL - || strcmp (name_info[idx].canonical_name, - runp->toname) == 0); - name_info[idx].canonical_name = runp->toname; - name_info[idx].canonical_strent = runp->toname_strent; - } - else if (strcmp (runp->toname, "INTERNAL") == 0) - { - idx = name_to_module_idx (runp->fromname, 1); - name_info[idx].to_internal = runp; - assert (name_info[idx].canonical_name == NULL - || strcmp (name_info[idx].canonical_name, - runp->fromname) == 0); - name_info[idx].canonical_name = runp->fromname; - name_info[idx].canonical_strent = runp->fromname_strent; - } - else - { - /* This is a transformation not to or from the INTERNAL - encoding. */ - int from_idx = name_to_module_idx (runp->fromname, 1); - int to_idx = name_to_module_idx (runp->toname, 1); - struct other_conv_list *newp; - - newp = (struct other_conv_list *) - xmalloc (sizeof (struct other_conv_list)); - newp->other_conv.module_idx = to_idx; - newp->other_conv.module = runp; - newp->other_conv.next = NULL; /* XXX Allow multiple module sequence */ - newp->dest_idx = to_idx; - newp->next = name_info[from_idx].other_conv_list; - name_info[from_idx].other_conv_list = newp; - assert (name_info[from_idx].canonical_name == NULL - || strcmp (name_info[from_idx].canonical_name, - runp->fromname) == 0); - name_info[from_idx].canonical_name = runp->fromname; - name_info[from_idx].canonical_strent = runp->fromname_strent; - - ++nextra_modules; - } - } - - /* Now add the module index information for all the aliases. */ - for (i = 0; i < nalias_list; ++i) - { - struct name fake_name = { .name = alias_list[i]->toname }; - struct name **tonamep; - - tonamep = (struct name **) tfind (&fake_name, &names, name_compare); - if (tonamep != NULL) - { - struct name *newp = new_name (alias_list[i]->fromname, - alias_list[i]->froment); - newp->module_idx = (*tonamep)->module_idx; - tsearch (newp, &names, name_compare); - } - } -} - - -static int -is_prime (unsigned long int candidate) -{ - /* No even number and none less than 10 will be passed here. */ - unsigned long int divn = 3; - unsigned long int sq = divn * divn; - - while (sq < candidate && candidate % divn != 0) - { - ++divn; - sq += 4 * divn; - ++divn; - } - - return candidate % divn != 0; -} - - -static uint32_t -next_prime (uint32_t seed) -{ - /* Make it definitely odd. */ - seed |= 1; - - while (!is_prime (seed)) - seed += 2; - - return seed; -} - - -/* Format of the output file. - - Offset Length Description - 0000 4 Magic header bytes - 0004 4 Offset of string table (stoff) - 0008 4 Offset of name hashing table (hoff) - 000C 4 Hashing table size (hsize) - 0010 4 Offset of module table (moff) - 0014 4 Offset of other conversion module table (ooff) - - stoff ??? String table - - hoff 8*hsize Array of tuples - string table offset - module index - - moff ??? Array of tuples - canonical name offset - from-internal module dir name offset - from-internal module name off - to-internal module dir name offset - to-internal module name offset - offset into other conversion table - - ooff ??? One or more of - number of steps/modules - one or more of tuple - canonical name offset for output - module dir name offset - module name offset - (following last entry with step count 0) -*/ -static int -write_output (void) -{ - int fd; - char *string_table; - size_t string_table_size; - struct gconvcache_header header; - struct hash_entry *hash_table; - size_t hash_size; - struct module_entry *module_table; - char *extra_table; - char *cur_extra_table; - size_t n; - int idx; - struct iovec iov[6]; - static const gidx_t null_word; - size_t total; - char tmpfname[prefix_len + sizeof (GCONV_MODULES_CACHE) - + strlen (".XXXXXX")]; - char finalname[prefix_len + sizeof (GCONV_MODULES_CACHE)]; - - /* Function to insert the names. */ - static void name_insert (const void *nodep, VISIT value, int level) - { - struct name *name; - unsigned int idx; - unsigned int hval2; - - if (value != leaf && value != postorder) - return; - - name = *(struct name **) nodep; - idx = name->hashval % hash_size; - hval2 = 1 + name->hashval % (hash_size - 2); - - while (hash_table[idx].string_offset != 0) - if ((idx += hval2) >= hash_size) - idx -= hash_size; - - hash_table[idx].string_offset = strtaboffset (name->strent); - - assert (name->module_idx != -1); - hash_table[idx].module_idx = name->module_idx; - } - - /* Open the output file. */ - assert (GCONV_MODULES_CACHE[0] == '/'); - strcpy (stpcpy (mempcpy (tmpfname, prefix, prefix_len), GCONV_MODULES_CACHE), - ".XXXXXX"); - fd = mkstemp (tmpfname); - if (fd == -1) - return 1; - - strcpy (mempcpy (finalname, prefix, prefix_len), GCONV_MODULES_CACHE); - - /* Create the string table. */ - string_table = strtabfinalize (strtab, &string_table_size); - - /* Create the hashing table. We know how many strings we have. - Creating a perfect hash table is not reasonable here. Therefore - we use open hashing and a table size which is the next prime 40% - larger than the number of strings. */ - hash_size = next_prime (nnames * 1.4); - hash_table = (struct hash_entry *) xcalloc (hash_size, - sizeof (struct hash_entry)); - /* Fill the hash table. */ - twalk (names, name_insert); - - /* Create the section for the module list. */ - module_table = (struct module_entry *) xcalloc (sizeof (struct module_entry), - nname_info); - - /* Allocate memory for the non-INTERNAL conversions. The allocated - memory can be more than is actually needed. */ - extra_table = (char *) xcalloc (sizeof (struct extra_entry) - + sizeof (gidx_t) - + sizeof (struct extra_entry_module), - nextra_modules); - cur_extra_table = extra_table; - - /* Fill in the module information. */ - for (n = 0; n < nname_info; ++n) - { - module_table[n].canonname_offset = - strtaboffset (name_info[n].canonical_strent); - - if (name_info[n].from_internal == NULL) - { - module_table[n].fromdir_offset = 0; - module_table[n].fromname_offset = 0; - } - else - { - module_table[n].fromdir_offset = - strtaboffset (name_info[n].from_internal->directory_strent); - module_table[n].fromname_offset = - strtaboffset (name_info[n].from_internal->filename_strent); - } - - if (name_info[n].to_internal == NULL) - { - module_table[n].todir_offset = 0; - module_table[n].toname_offset = 0; - } - else - { - module_table[n].todir_offset = - strtaboffset (name_info[n].to_internal->directory_strent); - module_table[n].toname_offset = - strtaboffset (name_info[n].to_internal->filename_strent); - } - - if (name_info[n].other_conv_list != NULL) - { - struct other_conv_list *other = name_info[n].other_conv_list; - - /* Store the reference. We add 1 to distinguish the entry - at offset zero from the case where no extra modules are - available. The file reader has to account for the - offset. */ - module_table[n].extra_offset = 1 + cur_extra_table - extra_table; - - do - { - struct other_conv *runp; - struct extra_entry *extra; - - /* Allocate new entry. */ - extra = (struct extra_entry *) cur_extra_table; - cur_extra_table += sizeof (struct extra_entry); - extra->module_cnt = 0; - - runp = &other->other_conv; - do - { - cur_extra_table += sizeof (struct extra_entry_module); - extra->module[extra->module_cnt].outname_offset = - runp->next == NULL - ? other->dest_idx : runp->next->module_idx; - extra->module[extra->module_cnt].dir_offset = - strtaboffset (runp->module->directory_strent); - extra->module[extra->module_cnt].name_offset = - strtaboffset (runp->module->filename_strent); - ++extra->module_cnt; - - runp = runp->next; - } - while (runp != NULL); - - other = other->next; - } - while (other != NULL); - - /* Final module_cnt is zero. */ - *((gidx_t *) cur_extra_table) = 0; - cur_extra_table += sizeof (gidx_t); - } - } - - header.magic = GCONVCACHE_MAGIC; - - iov[0].iov_base = &header; - iov[0].iov_len = sizeof (struct gconvcache_header); - total = iov[0].iov_len; - - header.string_offset = total; - iov[1].iov_base = string_table; - iov[1].iov_len = string_table_size; - total += iov[1].iov_len; - - idx = 2; - if ((string_table_size & (sizeof (gidx_t) - 1)) != 0) - { - iov[2].iov_base = (void *) &null_word; - iov[2].iov_len = (sizeof (gidx_t) - - (string_table_size & (sizeof (gidx_t) - 1))); - total += iov[2].iov_len; - ++idx; - } - - header.hash_offset = total; - header.hash_size = hash_size; - iov[idx].iov_base = hash_table; - iov[idx].iov_len = hash_size * sizeof (struct hash_entry); - total += iov[idx].iov_len; - ++idx; - - header.module_offset = total; - iov[idx].iov_base = module_table; - iov[idx].iov_len = nname_info * sizeof (struct module_entry); - total += iov[idx].iov_len; - ++idx; - - assert ((size_t) (cur_extra_table - extra_table) - <= ((sizeof (struct extra_entry) + sizeof (gidx_t) - + sizeof (struct extra_entry_module)) - * nextra_modules)); - header.otherconv_offset = total; - iov[idx].iov_base = extra_table; - iov[idx].iov_len = cur_extra_table - extra_table; - total += iov[idx].iov_len; - ++idx; - - if ((size_t) TEMP_FAILURE_RETRY (writev (fd, iov, idx)) != total - /* The file was created with mode 0600. Make it world-readable. */ - || fchmod (fd, 0644) != 0 - /* Rename the file, possibly replacing an old one. */ - || rename (tmpfname, finalname) != 0) - { - int save_errno = errno; - close (fd); - unlink (tmpfname); - error (EXIT_FAILURE, save_errno, - gettext ("cannot generate output file")); - } - - close (fd); - - return 0; -} diff --git a/src/system/libroot/posix/glibc/iconv/strtab.c b/src/system/libroot/posix/glibc/iconv/strtab.c deleted file mode 100644 index e6feb2cf24..0000000000 --- a/src/system/libroot/posix/glibc/iconv/strtab.c +++ /dev/null @@ -1,340 +0,0 @@ -/* C string table handling. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - Written by Ulrich Drepper , 2000. - - 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 2, 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, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - - -struct Strent -{ - const char *string; - size_t len; - struct Strent *next; - struct Strent *left; - struct Strent *right; - size_t offset; - char reverse[0]; -}; - - -struct memoryblock -{ - struct memoryblock *next; - char memory[0]; -}; - - -struct Strtab -{ - struct Strent *root; - struct memoryblock *memory; - char *backp; - size_t left; - size_t total; - - struct Strent null; -}; - - -/* Cache for the pagesize. We correct this value a bit so that `malloc' - is not allocating more than a page. */ -static size_t ps; - - -extern void *xmalloc (size_t n) __attribute_malloc__; - -/* Prototypes for our functions that are used from iconvconfig.c. If - you change these, change also iconvconfig.c. */ -/* Create new C string table object in memory. */ -extern struct Strtab *strtabinit (void); - -/* Free resources allocated for C string table ST. */ -extern void strtabfree (struct Strtab *st); - -/* Add string STR (length LEN is != 0) to C string table ST. */ -extern struct Strent *strtabadd (struct Strtab *st, const char *str, - size_t len); - -/* Finalize string table ST and store size in *SIZE and return a pointer. */ -extern void *strtabfinalize (struct Strtab *st, size_t *size); - -/* Get offset in string table for string associated with SE. */ -extern size_t strtaboffset (struct Strent *se); - - -struct Strtab * -strtabinit (void) -{ - struct Strtab *ret; - - if (ps == 0) - { - ps = sysconf (_SC_PAGESIZE) - 2 * sizeof (void *); - assert (sizeof (struct memoryblock) < ps); - } - - ret = (struct Strtab *) calloc (1, sizeof (struct Strtab)); - if (ret != NULL) - { - ret->null.len = 1; - ret->null.string = ""; - } - return ret; -} - - -static void -morememory (struct Strtab *st, size_t len) -{ - struct memoryblock *newmem; - - if (len < ps) - len = ps; - newmem = (struct memoryblock *) malloc (len); - if (newmem == NULL) - abort (); - - newmem->next = st->memory; - st->memory = newmem; - st->backp = newmem->memory; - st->left = len - offsetof (struct memoryblock, memory); -} - - -void -strtabfree (struct Strtab *st) -{ - struct memoryblock *mb = st->memory; - - while (mb != NULL) - { - void *old = mb; - mb = mb->next; - free (old); - } - - free (st); -} - - -static struct Strent * -newstring (struct Strtab *st, const char *str, size_t len) -{ - struct Strent *newstr; - size_t align; - int i; - - /* Compute the amount of padding needed to make the structure aligned. */ - align = ((__alignof__ (struct Strent) - - (((uintptr_t) st->backp) - & (__alignof__ (struct Strent) - 1))) - & (__alignof__ (struct Strent) - 1)); - - /* Make sure there is enough room in the memory block. */ - if (st->left < align + sizeof (struct Strent) + len) - { - morememory (st, sizeof (struct Strent) + len); - align = 0; - } - - /* Create the reserved string. */ - newstr = (struct Strent *) (st->backp + align); - newstr->string = str; - newstr->len = len; - newstr->next = NULL; - newstr->left = NULL; - newstr->right = NULL; - newstr->offset = 0; - for (i = len - 2; i >= 0; --i) - newstr->reverse[i] = str[len - 2 - i]; - newstr->reverse[len - 1] = '\0'; - st->backp += align + sizeof (struct Strent) + len; - st->left -= align + sizeof (struct Strent) + len; - - return newstr; -} - - -/* XXX This function should definitely be rewritten to use a balancing - tree algorith (AVL, red-black trees). For now a simple, correct - implementation is enough. */ -static struct Strent ** -searchstring (struct Strent **sep, struct Strent *newstr) -{ - int cmpres; - - /* More strings? */ - if (*sep == NULL) - { - *sep = newstr; - return sep; - } - - /* Compare the strings. */ - cmpres = memcmp ((*sep)->reverse, newstr->reverse, - MIN ((*sep)->len, newstr->len) - 1); - if (cmpres == 0) - /* We found a matching string. */ - return sep; - else if (cmpres > 0) - return searchstring (&(*sep)->left, newstr); - else - return searchstring (&(*sep)->right, newstr); -} - - -/* Add new string. The actual string is assumed to be permanent. */ -struct Strent * -strtabadd (struct Strtab *st, const char *str, size_t len) -{ - struct Strent *newstr; - struct Strent **sep; - - /* Compute the string length if the caller doesn't know it. */ - if (len == 0) - len = strlen (str) + 1; - - /* Make sure all "" strings get offset 0. */ - if (len == 1) - return &st->null; - - /* Allocate memory for the new string and its associated information. */ - newstr = newstring (st, str, len); - - /* Search in the array for the place to insert the string. If there - is no string with matching prefix and no string with matching - leading substring, create a new entry. */ - sep = searchstring (&st->root, newstr); - if (*sep != newstr) - { - /* This is not the same entry. This means we have a prefix match. */ - if ((*sep)->len > newstr->len) - { - struct Strent *subs; - - for (subs = (*sep)->next; subs; subs = subs->next) - if (subs->len == newstr->len) - { - /* We have an exact match with a substring. Free the memory - we allocated. */ - st->left += st->backp - (char *) newstr; - st->backp = (char *) newstr; - - return subs; - } - - /* We have a new substring. This means we don't need the reverse - string of this entry anymore. */ - st->backp -= newstr->len; - st->left += newstr->len; - - newstr->next = (*sep)->next; - (*sep)->next = newstr; - } - else if ((*sep)->len != newstr->len) - { - /* When we get here it means that the string we are about to - add has a common prefix with a string we already have but - it is longer. In this case we have to put it first. */ - st->total += newstr->len - (*sep)->len; - newstr->next = *sep; - newstr->left = (*sep)->left; - newstr->right = (*sep)->right; - *sep = newstr; - } - else - { - /* We have an exact match. Free the memory we allocated. */ - st->left += st->backp - (char *) newstr; - st->backp = (char *) newstr; - - newstr = *sep; - } - } - else - st->total += newstr->len; - - return newstr; -} - - -static void -copystrings (struct Strent *nodep, char **freep, size_t *offsetp) -{ - struct Strent *subs; - - if (nodep->left != NULL) - copystrings (nodep->left, freep, offsetp); - - /* Process the current node. */ - nodep->offset = *offsetp; - *freep = (char *) mempcpy (*freep, nodep->string, nodep->len); - *offsetp += nodep->len; - - for (subs = nodep->next; subs != NULL; subs = subs->next) - { - assert (subs->len < nodep->len); - subs->offset = nodep->offset + nodep->len - subs->len; - } - - if (nodep->right != NULL) - copystrings (nodep->right, freep, offsetp); -} - - -void * -strtabfinalize (struct Strtab *st, size_t *size) -{ - size_t copylen; - char *endp; - char *retval; - - /* Fill in the information. */ - endp = retval = (char *) xmalloc (st->total + 1); - - /* Always put an empty string at the beginning so that a zero offset - can mean error. */ - *endp++ = '\0'; - - /* Now run through the tree and add all the string while also updating - the offset members of the elfstrent records. */ - copylen = 1; - copystrings (st->root, &endp, ©len); - assert (copylen == st->total + 1); - assert (endp = retval + st->total + 1); - *size = copylen; - - return retval; -} - - -size_t -strtaboffset (struct Strent *se) -{ - return se->offset; -} diff --git a/src/system/libroot/posix/glibc/iconv/tst-iconv1.c b/src/system/libroot/posix/glibc/iconv/tst-iconv1.c deleted file mode 100644 index d806ce6ae8..0000000000 --- a/src/system/libroot/posix/glibc/iconv/tst-iconv1.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Test case by yaoz@nih.gov. */ - -#include -#include -#include -#include - -int -main (void) -{ - char utf8[5]; - wchar_t ucs4[5]; - iconv_t cd; - char *inbuf; - char *outbuf; - size_t inbytes; - size_t outbytes; - size_t n; - - strcpy (utf8, "abcd"); - - /* From UTF8 to UCS4. */ - cd = iconv_open ("UCS4", "UTF8"); - if (cd == (iconv_t) -1) - { - perror ("iconv_open"); - return 1; - } - - inbuf = utf8; - inbytes = 4; - outbuf = (char *) ucs4; - outbytes = 4 * sizeof (wchar_t); /* "Argument list too long" error. */ - n = iconv (cd, &inbuf, &inbytes, &outbuf, &outbytes); - if (n == (size_t) -1) - { - printf ("iconv: %m\n"); - iconv_close (cd); - return 1; - } - iconv_close (cd); - - return 0; -} diff --git a/src/system/libroot/posix/glibc/iconv/tst-iconv2.c b/src/system/libroot/posix/glibc/iconv/tst-iconv2.c deleted file mode 100644 index 8807e09c8c..0000000000 --- a/src/system/libroot/posix/glibc/iconv/tst-iconv2.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include - - -int -main (void) -{ - char buf[3]; - const wchar_t wc[1] = L"a"; - iconv_t cd; - char *inptr; - size_t inlen; - char *outptr; - size_t outlen; - size_t n; - int e; - int result = 0; - - mtrace (); - - cd = iconv_open ("UCS4", "WCHAR_T"); - if (cd == (iconv_t) -1) - { - printf ("cannot convert from wchar_t to UCS4: %m\n"); - exit (1); - } - - inptr = (char *) wc; - inlen = sizeof (wchar_t); - outptr = buf; - outlen = 3; - - n = iconv (cd, &inptr, &inlen, &outptr, &outlen); - e = errno; - - if (n != (size_t) -1) - { - printf ("incorrect iconv() return value: %zd, expected -1\n", n); - result = 1; - } - - if (e != E2BIG) - { - printf ("incorrect error value: %s, expected %s\n", - strerror (e), strerror (E2BIG)); - result = 1; - } - - if (inptr != (char *) wc) - { - puts ("inptr changed"); - result = 1; - } - - if (inlen != sizeof (wchar_t)) - { - puts ("inlen changed"); - result = 1; - } - - if (outptr != buf) - { - puts ("outptr changed"); - result = 1; - } - - if (outlen != 3) - { - puts ("outlen changed"); - result = 1; - } - - iconv_close (cd); - - return result; -} diff --git a/src/system/libroot/posix/glibc/iconv/tst-iconv3.c b/src/system/libroot/posix/glibc/iconv/tst-iconv3.c deleted file mode 100644 index 7d92d3bb1c..0000000000 --- a/src/system/libroot/posix/glibc/iconv/tst-iconv3.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Contributed by Owen Taylor . */ - -#include -#include -#include -#include - -#define BUFSIZE 10000 - -int -main (int argc, char *argv[]) -{ - char inbuf[BUFSIZE]; - wchar_t outbuf[BUFSIZE]; - - iconv_t cd; - int i; - char *inptr; - char *outptr; - size_t inbytes_left, outbytes_left; - int count; - int result = 0; - - for (i=0; i < BUFSIZE; i++) - inbuf[i] = 'a'; - - cd = iconv_open ("UCS-4LE", "UTF-8"); - - inbytes_left = BUFSIZE; - outbytes_left = BUFSIZE * 4; - inptr = inbuf; - outptr = (char *) outbuf; - - count = iconv (cd, &inptr, &inbytes_left, &outptr, &outbytes_left); - - if (count < 0) - { - if (errno == E2BIG) - printf ("Received E2BIG\n"); - else - printf ("Received something else\n"); - - printf ("inptr change: %td\n", inptr - inbuf); - printf ("inlen change: %zd\n", BUFSIZE - inbytes_left); - printf ("outptr change: %zd\n", outptr - (char *) outbuf); - printf ("outlen change: %zd\n", BUFSIZE * 4 - outbytes_left); - result = 1; - } - else - printf ("Succeeded\n"); - - return result; -} diff --git a/src/system/libroot/posix/glibc/intl/Depend b/src/system/libroot/posix/glibc/intl/Depend deleted file mode 100644 index 981111e299..0000000000 --- a/src/system/libroot/posix/glibc/intl/Depend +++ /dev/null @@ -1,2 +0,0 @@ -iconvdata -localedata diff --git a/src/system/libroot/posix/glibc/intl/Makefile b/src/system/libroot/posix/glibc/intl/Makefile deleted file mode 100644 index 60700e2152..0000000000 --- a/src/system/libroot/posix/glibc/intl/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# Makefile for intl subdirectory: message handling code from GNU gettext. - -subdir = intl -headers = libintl.h -routines = bindtextdom dcgettext dgettext gettext \ - dcigettext dcngettext dngettext ngettext \ - finddomain loadmsgcat localealias textdomain \ - l10nflist explodename plural plural-exp -distribute = gmo.h gettextP.h hash-string.h loadinfo.h locale.alias \ - plural.y plural-exp.h po2test.sed tst-gettext.sh tst-translit.sh \ - translit.po tst-gettext2.sh tstlang1.po tstlang2.po tstcodeset.po\ - tst-codeset.sh plural-eval.c - -test-srcs := tst-gettext tst-translit tst-gettext2 tst-codeset -tests = tst-ngettext - -before-compile = $(objpfx)msgs.h - -install-others = $(inst_msgcatdir)/locale.alias - -generated = msgs.h mtrace-tst-gettext tst-gettext.mtrace -generated-dirs := domaindir localedir - -include ../Makeconfig - -ifneq (no,$(BISON)) -plural.c: plural.y - $(BISON) $(BISONFLAGS) $@ $^ -ifeq ($(with-cvs),yes) - test ! -d CVS || cvs $(CVSOPTS) commit -m'$(BISON) $(BISONFLAGS) $@ $^' $@ -endif -endif -$(objpfx)plural.o: plural.c - -include ../Rules - -ifeq (no,$(cross-compiling)) -ifeq (yes,$(build-shared)) -ifneq ($(strip $(MSGFMT)),:) -tests: $(objpfx)tst-translit.out $(objpfx)tst-gettext2.out \ - $(objpfx)tst-codeset.out -ifneq (no,$(PERL)) -tests: $(objpfx)mtrace-tst-gettext -endif -endif -$(objpfx)mtrace-tst-gettext: $(objpfx)tst-gettext.out - $(common-objpfx)malloc/mtrace $(objpfx)tst-gettext.mtrace > $@ -$(objpfx)tst-gettext.out: tst-gettext.sh $(objpfx)tst-gettext - $(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/ \ - $(objpfx)tst-gettext.mtrace -$(objpfx)tst-translit.out: tst-translit.sh $(objpfx)tst-translit - $(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/ -$(objpfx)tst-gettext2.out: tst-gettext2.sh $(objpfx)tst-gettext2 - $(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/ -$(objpfx)tst-codeset.out: tst-codeset.sh $(objpfx)tst-codeset - $(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/ -endif -endif - -$(objpfx)msgs.h: po2test.sed ../po/de.po - $(make-target-directory) - sed -f $^ > $@ - -CFLAGS-tst-gettext.c = -DTESTSTRS_H=\"$(objpfx)msgs.h\" -CFLAGS-tst-gettext2.c = -DOBJPFX=\"$(objpfx)\" -CFLAGS-tst-translit.c = -DOBJPFX=\"$(objpfx)\" -CFLAGS-tst-codeset.c = -DOBJPFX=\"$(objpfx)\" - -$(objpfx)tst-translit.out: $(objpfx)tst-gettext.out -$(objpfx)tst-gettext2.out: $(objpfx)tst-gettext.out -$(objpfx)tst-codeset.out: $(objpfx)tst-gettext.out - -CPPFLAGS += -D'LOCALEDIR="$(msgcatdir)"' \ - -D'LOCALE_ALIAS_PATH="$(msgcatdir)"' -BISONFLAGS = --yacc --name-prefix=__gettext --output - -$(inst_msgcatdir)/locale.alias: locale.alias $(+force) - $(do-install) diff --git a/src/system/libroot/posix/glibc/intl/Versions b/src/system/libroot/posix/glibc/intl/Versions deleted file mode 100644 index d76982dbe3..0000000000 --- a/src/system/libroot/posix/glibc/intl/Versions +++ /dev/null @@ -1,31 +0,0 @@ -libc { - GLIBC_2.0 { - # global variables - _nl_msg_cat_cntr; _nl_default_dirname; _nl_domain_bindings; - - # functions used in inline functions or macros - __dcgettext; - - # functions used in other libraries - __dgettext; - - # b* - bindtextdomain; - - # d* - dcgettext; dgettext; gettext; - - # t* - textdomain; - } - GLIBC_2.2 { - # b* - bind_textdomain_codeset; - - # d* - dcngettext; dngettext; - - # n* - ngettext; - } -} diff --git a/src/system/libroot/posix/glibc/intl/bindtextdom.c b/src/system/libroot/posix/glibc/intl/bindtextdom.c deleted file mode 100644 index 39256ed566..0000000000 --- a/src/system/libroot/posix/glibc/intl/bindtextdom.c +++ /dev/null @@ -1,375 +0,0 @@ -/* Implementation of the bindtextdomain(3) function - Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif -#include "gettextP.h" - -#ifdef _LIBC -/* We have to handle multi-threaded applications. */ -# include -#else -/* Provide dummy implementation if this is outside glibc. */ -# define __libc_rwlock_define(CLASS, NAME) -# define __libc_rwlock_wrlock(NAME) -# define __libc_rwlock_unlock(NAME) -#endif - -/* The internal variables in the standalone libintl.a must have different - names than the internal variables in GNU libc, otherwise programs - using libintl.a cannot be linked statically. */ -#if !defined _LIBC -# define _nl_default_dirname libintl_nl_default_dirname -# define _nl_domain_bindings libintl_nl_domain_bindings -#endif - -/* Some compilers, like SunOS4 cc, don't have offsetof in . */ -#ifndef offsetof -# define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) -#endif - -/* @@ end of prolog @@ */ - -/* Contains the default location of the message catalogs. */ -extern const char _nl_default_dirname[]; -#ifdef _LIBC -extern const char _nl_default_dirname_internal[] attribute_hidden; -#else -# define INTUSE(name) name -#endif - -/* List with bindings of specific domains. */ -extern struct binding *_nl_domain_bindings; - -/* Lock variable to protect the global data in the gettext implementation. */ -__libc_rwlock_define (extern, _nl_state_lock attribute_hidden) - - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define BINDTEXTDOMAIN __bindtextdomain -# define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset -# ifndef strdup -# define strdup(str) __strdup (str) -# endif -#else -# define BINDTEXTDOMAIN libintl_bindtextdomain -# define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset -#endif - -/* Prototypes for local functions. */ -static void set_binding_values PARAMS ((const char *domainname, - const char **dirnamep, - const char **codesetp)); - -/* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP - to be used for the DOMAINNAME message catalog. - If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not - modified, only the current value is returned. - If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither - modified nor returned. */ -static void -set_binding_values (domainname, dirnamep, codesetp) - const char *domainname; - const char **dirnamep; - const char **codesetp; -{ - struct binding *binding; - int modified; - - /* Some sanity checks. */ - if (domainname == NULL || domainname[0] == '\0') - { - if (dirnamep) - *dirnamep = NULL; - if (codesetp) - *codesetp = NULL; - return; - } - - __libc_rwlock_wrlock (_nl_state_lock); - - modified = 0; - - for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) - { - int compare = strcmp (domainname, binding->domainname); - if (compare == 0) - /* We found it! */ - break; - if (compare < 0) - { - /* It is not in the list. */ - binding = NULL; - break; - } - } - - if (binding != NULL) - { - if (dirnamep) - { - const char *dirname = *dirnamep; - - if (dirname == NULL) - /* The current binding has be to returned. */ - *dirnamep = binding->dirname; - else - { - /* The domain is already bound. If the new value and the old - one are equal we simply do nothing. Otherwise replace the - old binding. */ - char *result = binding->dirname; - if (strcmp (dirname, result) != 0) - { - if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) - result = (char *) INTUSE(_nl_default_dirname); - else - { -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (dirname); -#else - size_t len = strlen (dirname) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result != NULL, 1)) - memcpy (result, dirname, len); -#endif - } - - if (__builtin_expect (result != NULL, 1)) - { - if (binding->dirname != INTUSE(_nl_default_dirname)) - free (binding->dirname); - - binding->dirname = result; - modified = 1; - } - } - *dirnamep = result; - } - } - - if (codesetp) - { - const char *codeset = *codesetp; - - if (codeset == NULL) - /* The current binding has be to returned. */ - *codesetp = binding->codeset; - else - { - /* The domain is already bound. If the new value and the old - one are equal we simply do nothing. Otherwise replace the - old binding. */ - char *result = binding->codeset; - if (result == NULL || strcmp (codeset, result) != 0) - { -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (codeset); -#else - size_t len = strlen (codeset) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result != NULL, 1)) - memcpy (result, codeset, len); -#endif - - if (__builtin_expect (result != NULL, 1)) - { - if (binding->codeset != NULL) - free (binding->codeset); - - binding->codeset = result; - ++binding->codeset_cntr; - modified = 1; - } - } - *codesetp = result; - } - } - } - else if ((dirnamep == NULL || *dirnamep == NULL) - && (codesetp == NULL || *codesetp == NULL)) - { - /* Simply return the default values. */ - if (dirnamep) - *dirnamep = INTUSE(_nl_default_dirname); - if (codesetp) - *codesetp = NULL; - } - else - { - /* We have to create a new binding. */ - size_t len = strlen (domainname) + 1; - struct binding *new_binding = - (struct binding *) malloc (offsetof (struct binding, domainname) + len); - - if (__builtin_expect (new_binding == NULL, 0)) - goto failed; - - memcpy (new_binding->domainname, domainname, len); - - if (dirnamep) - { - const char *dirname = *dirnamep; - - if (dirname == NULL) - /* The default value. */ - dirname = INTUSE(_nl_default_dirname); - else - { - if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) - dirname = INTUSE(_nl_default_dirname); - else - { - char *result; -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (dirname); - if (__builtin_expect (result == NULL, 0)) - goto failed_dirname; -#else - size_t len = strlen (dirname) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result == NULL, 0)) - goto failed_dirname; - memcpy (result, dirname, len); -#endif - dirname = result; - } - } - *dirnamep = dirname; - new_binding->dirname = (char *) dirname; - } - else - /* The default value. */ - new_binding->dirname = (char *) INTUSE(_nl_default_dirname); - - new_binding->codeset_cntr = 0; - - if (codesetp) - { - const char *codeset = *codesetp; - - if (codeset != NULL) - { - char *result; - -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (codeset); - if (__builtin_expect (result == NULL, 0)) - goto failed_codeset; -#else - size_t len = strlen (codeset) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result == NULL, 0)) - goto failed_codeset; - memcpy (result, codeset, len); -#endif - codeset = result; - ++new_binding->codeset_cntr; - } - *codesetp = codeset; - new_binding->codeset = (char *) codeset; - } - else - new_binding->codeset = NULL; - - /* Now enqueue it. */ - if (_nl_domain_bindings == NULL - || strcmp (domainname, _nl_domain_bindings->domainname) < 0) - { - new_binding->next = _nl_domain_bindings; - _nl_domain_bindings = new_binding; - } - else - { - binding = _nl_domain_bindings; - while (binding->next != NULL - && strcmp (domainname, binding->next->domainname) > 0) - binding = binding->next; - - new_binding->next = binding->next; - binding->next = new_binding; - } - - modified = 1; - - /* Here we deal with memory allocation failures. */ - if (0) - { - failed_codeset: - if (new_binding->dirname != INTUSE(_nl_default_dirname)) - free (new_binding->dirname); - failed_dirname: - free (new_binding); - failed: - if (dirnamep) - *dirnamep = NULL; - if (codesetp) - *codesetp = NULL; - } - } - - /* If we modified any binding, we flush the caches. */ - if (modified) - ++_nl_msg_cat_cntr; - - __libc_rwlock_unlock (_nl_state_lock); -} - -/* Specify that the DOMAINNAME message catalog will be found - in DIRNAME rather than in the system locale data base. */ -char * -BINDTEXTDOMAIN (domainname, dirname) - const char *domainname; - const char *dirname; -{ - set_binding_values (domainname, &dirname, NULL); - return (char *) dirname; -} - -/* Specify the character encoding in which the messages from the - DOMAINNAME message catalog will be returned. */ -char * -BIND_TEXTDOMAIN_CODESET (domainname, codeset) - const char *domainname; - const char *codeset; -{ - set_binding_values (domainname, NULL, &codeset); - return (char *) codeset; -} - -#ifdef _LIBC -/* Aliases for function names in GNU C Library. */ -weak_alias (__bindtextdomain, bindtextdomain); -weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset); -#endif diff --git a/src/system/libroot/posix/glibc/intl/dcgettext.c b/src/system/libroot/posix/glibc/intl/dcgettext.c deleted file mode 100644 index 55f81eb887..0000000000 --- a/src/system/libroot/posix/glibc/intl/dcgettext.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Implementation of the dcgettext(3) function. - Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define DCGETTEXT __dcgettext -# define DCIGETTEXT __dcigettext -#else -# define DCGETTEXT libintl_dcgettext -# define DCIGETTEXT libintl_dcigettext -#endif - -/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY - locale. */ -char * -DCGETTEXT (domainname, msgid, category) - const char *domainname; - const char *msgid; - int category; -{ - return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -INTDEF(__dcgettext) -weak_alias (__dcgettext, dcgettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/dcigettext.c b/src/system/libroot/posix/glibc/intl/dcigettext.c deleted file mode 100644 index 9118dbdda9..0000000000 --- a/src/system/libroot/posix/glibc/intl/dcigettext.c +++ /dev/null @@ -1,1173 +0,0 @@ -/* Implementation of the internal dcigettext function. - Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Tell glibc's to provide a prototype for mempcpy(). - This must come before because may include - , and once has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#ifdef __GNUC__ -# define alloca __builtin_alloca -# define HAVE_ALLOCA 1 -#else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca -char *alloca (); -# endif -# endif -# endif -#endif - -#include -#ifndef errno -extern int errno; -#endif -#ifndef __set_errno -# define __set_errno(val) errno = (val) -#endif - -#include -#include -#include - -#if defined HAVE_UNISTD_H || defined _LIBC -# include -#endif - -#include - -#if defined HAVE_SYS_PARAM_H || defined _LIBC -# include -#endif - -#include "gettextP.h" -#include "plural-exp.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif -#include "hash-string.h" - -/* Thread safetyness. */ -#ifdef _LIBC -# include -#else -/* Provide dummy implementation if this is outside glibc. */ -# define __libc_lock_define_initialized(CLASS, NAME) -# define __libc_lock_lock(NAME) -# define __libc_lock_unlock(NAME) -# define __libc_rwlock_define_initialized(CLASS, NAME) -# define __libc_rwlock_rdlock(NAME) -# define __libc_rwlock_unlock(NAME) -#endif - -/* Alignment of types. */ -#if defined __GNUC__ && __GNUC__ >= 2 -# define alignof(TYPE) __alignof__ (TYPE) -#else -# define alignof(TYPE) \ - ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2) -#endif - -/* The internal variables in the standalone libintl.a must have different - names than the internal variables in GNU libc, otherwise programs - using libintl.a cannot be linked statically. */ -#if !defined _LIBC -# define _nl_default_default_domain libintl_nl_default_default_domain -# define _nl_current_default_domain libintl_nl_current_default_domain -# define _nl_default_dirname libintl_nl_default_dirname -# define _nl_domain_bindings libintl_nl_domain_bindings -#endif - -/* Some compilers, like SunOS4 cc, don't have offsetof in . */ -#ifndef offsetof -# define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) -#endif - -/* @@ end of prolog @@ */ - -#ifdef _LIBC -/* Rename the non ANSI C functions. This is required by the standard - because some ANSI C functions will require linking with this object - file and the name space must not be polluted. */ -# define getcwd __getcwd -# ifndef stpcpy -# define stpcpy __stpcpy -# endif -# define tfind __tfind -#else -# if !defined HAVE_GETCWD -char *getwd (); -# define getcwd(buf, max) getwd (buf) -# else -char *getcwd (); -# endif -# ifndef HAVE_STPCPY -static char *stpcpy PARAMS ((char *dest, const char *src)); -# endif -# ifndef HAVE_MEMPCPY -static void *mempcpy PARAMS ((void *dest, const void *src, size_t n)); -# endif -#endif - -/* Amount to increase buffer size by in each try. */ -#define PATH_INCR 32 - -/* The following is from pathmax.h. */ -/* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define - PATH_MAX but might cause redefinition warnings when sys/param.h is - later included (as on MORE/BSD 4.3). */ -#if defined _POSIX_VERSION || (defined HAVE_LIMITS_H && !defined __GNUC__) -# include -#endif - -#ifndef _POSIX_PATH_MAX -# define _POSIX_PATH_MAX 255 -#endif - -#if !defined PATH_MAX && defined _PC_PATH_MAX -# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX)) -#endif - -/* Don't include sys/param.h if it already has been. */ -#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN -# include -#endif - -#if !defined PATH_MAX && defined MAXPATHLEN -# define PATH_MAX MAXPATHLEN -#endif - -#ifndef PATH_MAX -# define PATH_MAX _POSIX_PATH_MAX -#endif - -/* This is the type used for the search tree where known translations - are stored. */ -struct known_translation_t -{ - /* Domain in which to search. */ - char *domainname; - - /* The category. */ - int category; - - /* State of the catalog counter at the point the string was found. */ - int counter; - - /* Catalog where the string was found. */ - struct loaded_l10nfile *domain; - - /* And finally the translation. */ - const char *translation; - size_t translation_length; - - /* Pointer to the string in question. */ - char msgid[ZERO]; -}; - -/* Root of the search tree with known translations. We can use this - only if the system provides the `tsearch' function family. */ -#if defined HAVE_TSEARCH || defined _LIBC -# include - -static void *root; - -# ifdef _LIBC -# define tsearch __tsearch -# endif - -/* Function to compare two entries in the table of known translations. */ -static int transcmp PARAMS ((const void *p1, const void *p2)); -static int -transcmp (p1, p2) - const void *p1; - const void *p2; -{ - const struct known_translation_t *s1; - const struct known_translation_t *s2; - int result; - - s1 = (const struct known_translation_t *) p1; - s2 = (const struct known_translation_t *) p2; - - result = strcmp (s1->msgid, s2->msgid); - if (result == 0) - { - result = strcmp (s1->domainname, s2->domainname); - if (result == 0) - /* We compare the category last (though this is the cheapest - operation) since it is hopefully always the same (namely - LC_MESSAGES). */ - result = s1->category - s2->category; - } - - return result; -} -#endif - -#ifndef INTVARDEF -# define INTVARDEF -#endif -#ifndef INTUSE -# define INTUSE(name) name -#endif - -/* Name of the default domain used for gettext(3) prior any call to - textdomain(3). The default value for this is "messages". */ -const char _nl_default_default_domain[] attribute_hidden = "messages"; - -/* Value used as the default domain for gettext(3). */ -const char *_nl_current_default_domain attribute_hidden - = _nl_default_default_domain; - -/* Contains the default location of the message catalogs. */ -const char _nl_default_dirname[] = LOCALEDIR; -INTVARDEF (_nl_default_dirname) - -/* List with bindings of specific domains created by bindtextdomain() - calls. */ -struct binding *_nl_domain_bindings; - -/* Prototypes for local functions. */ -static char *plural_lookup PARAMS ((struct loaded_l10nfile *domain, - unsigned long int n, - const char *translation, - size_t translation_len)) - internal_function; -static const char *guess_category_value PARAMS ((int category, - const char *categoryname)) - internal_function; -#ifdef _LIBC -# include "../locale/localeinfo.h" -# define category_to_name(category) _nl_category_names[category] -#else -static const char *category_to_name PARAMS ((int category)) internal_function; -#endif - - -/* For those loosing systems which don't have `alloca' we have to add - some additional code emulating it. */ -#ifdef HAVE_ALLOCA -/* Nothing has to be done. */ -# define freea(p) /* nothing */ -# define ADD_BLOCK(list, address) /* nothing */ -# define FREE_BLOCKS(list) /* nothing */ -#else -struct block_list -{ - void *address; - struct block_list *next; -}; -# define ADD_BLOCK(list, addr) \ - do { \ - struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ - /* If we cannot get a free block we cannot add the new element to \ - the list. */ \ - if (newp != NULL) { \ - newp->address = (addr); \ - newp->next = (list); \ - (list) = newp; \ - } \ - } while (0) -# define FREE_BLOCKS(list) \ - do { \ - while (list != NULL) { \ - struct block_list *old = list; \ - list = list->next; \ - free (old->address); \ - free (old); \ - } \ - } while (0) -# undef alloca -# define alloca(size) (malloc (size)) -# define freea(p) free (p) -#endif /* have alloca */ - - -#ifdef _LIBC -/* List of blocks allocated for translations. */ -typedef struct transmem_list -{ - struct transmem_list *next; - char data[ZERO]; -} transmem_block_t; -static struct transmem_list *transmem_list; -#else -typedef unsigned char transmem_block_t; -#endif - - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define DCIGETTEXT __dcigettext -#else -# define DCIGETTEXT libintl_dcigettext -#endif - -/* Lock variable to protect the global data in the gettext implementation. */ -#ifdef _LIBC -__libc_rwlock_define_initialized (, _nl_state_lock attribute_hidden) -#endif - -/* Checking whether the binaries runs SUID must be done and glibc provides - easier methods therefore we make a difference here. */ -#ifdef _LIBC -# define ENABLE_SECURE __libc_enable_secure -# define DETERMINE_SECURE -#else -# ifndef HAVE_GETUID -# define getuid() 0 -# endif -# ifndef HAVE_GETGID -# define getgid() 0 -# endif -# ifndef HAVE_GETEUID -# define geteuid() getuid() -# endif -# ifndef HAVE_GETEGID -# define getegid() getgid() -# endif -static int enable_secure; -# define ENABLE_SECURE (enable_secure == 1) -# define DETERMINE_SECURE \ - if (enable_secure == 0) \ - { \ - if (getuid () != geteuid () || getgid () != getegid ()) \ - enable_secure = 1; \ - else \ - enable_secure = -1; \ - } -#endif - -/* Get the function to evaluate the plural expression. */ -#include "plural-eval.c" - -/* Look up MSGID in the DOMAINNAME message catalog for the current - CATEGORY locale and, if PLURAL is nonzero, search over string - depending on the plural form determined by N. */ -char * -DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) - const char *domainname; - const char *msgid1; - const char *msgid2; - int plural; - unsigned long int n; - int category; -{ -#ifndef HAVE_ALLOCA - struct block_list *block_list = NULL; -#endif - struct loaded_l10nfile *domain; - struct binding *binding; - const char *categoryname; - const char *categoryvalue; - char *dirname, *xdomainname; - char *single_locale; - char *retval; - size_t retlen; - int saved_errno; -#if defined HAVE_TSEARCH || defined _LIBC - struct known_translation_t *search; - struct known_translation_t **foundp = NULL; - size_t msgid_len; -#endif - size_t domainname_len; - - /* If no real MSGID is given return NULL. */ - if (msgid1 == NULL) - return NULL; - -#ifdef _LIBC - if (category < 0 || category >= __LC_LAST || category == LC_ALL) - /* Bogus. */ - return (plural == 0 - ? (char *) msgid1 - /* Use the Germanic plural rule. */ - : n == 1 ? (char *) msgid1 : (char *) msgid2); -#endif - - __libc_rwlock_rdlock (_nl_state_lock); - - /* If DOMAINNAME is NULL, we are interested in the default domain. If - CATEGORY is not LC_MESSAGES this might not make much sense but the - definition left this undefined. */ - if (domainname == NULL) - domainname = _nl_current_default_domain; - -#if defined HAVE_TSEARCH || defined _LIBC - msgid_len = strlen (msgid1) + 1; - - /* Try to find the translation among those which we found at - some time. */ - search = (struct known_translation_t *) - alloca (offsetof (struct known_translation_t, msgid) + msgid_len); - memcpy (search->msgid, msgid1, msgid_len); - search->domainname = (char *) domainname; - search->category = category; - - foundp = (struct known_translation_t **) tfind (search, &root, transcmp); - freea (search); - if (foundp != NULL && (*foundp)->counter == _nl_msg_cat_cntr) - { - /* Now deal with plural. */ - if (plural) - retval = plural_lookup ((*foundp)->domain, n, (*foundp)->translation, - (*foundp)->translation_length); - else - retval = (char *) (*foundp)->translation; - - __libc_rwlock_unlock (_nl_state_lock); - return retval; - } -#endif - - /* Preserve the `errno' value. */ - saved_errno = errno; - - /* See whether this is a SUID binary or not. */ - DETERMINE_SECURE; - - /* First find matching binding. */ - for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) - { - int compare = strcmp (domainname, binding->domainname); - if (compare == 0) - /* We found it! */ - break; - if (compare < 0) - { - /* It is not in the list. */ - binding = NULL; - break; - } - } - - if (binding == NULL) - dirname = (char *) INTUSE(_nl_default_dirname); - else if (binding->dirname[0] == '/') - dirname = binding->dirname; - else - { - /* We have a relative path. Make it absolute now. */ - size_t dirname_len = strlen (binding->dirname) + 1; - size_t path_max; - char *ret; - - path_max = (unsigned int) PATH_MAX; - path_max += 2; /* The getcwd docs say to do this. */ - - for (;;) - { - dirname = (char *) alloca (path_max + dirname_len); - ADD_BLOCK (block_list, dirname); - - __set_errno (0); - ret = getcwd (dirname, path_max); - if (ret != NULL || errno != ERANGE) - break; - - path_max += path_max / 2; - path_max += PATH_INCR; - } - - if (ret == NULL) - { - /* We cannot get the current working directory. Don't signal an - error but simply return the default string. */ - FREE_BLOCKS (block_list); - __libc_rwlock_unlock (_nl_state_lock); - __set_errno (saved_errno); - return (plural == 0 - ? (char *) msgid1 - /* Use the Germanic plural rule. */ - : n == 1 ? (char *) msgid1 : (char *) msgid2); - } - - stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname); - } - - /* Now determine the symbolic name of CATEGORY and its value. */ - categoryname = category_to_name (category); - categoryvalue = guess_category_value (category, categoryname); - - domainname_len = strlen (domainname); - xdomainname = (char *) alloca (strlen (categoryname) - + domainname_len + 5); - ADD_BLOCK (block_list, xdomainname); - - stpcpy (mempcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"), - domainname, domainname_len), - ".mo"); - - /* Creating working area. */ - single_locale = (char *) alloca (strlen (categoryvalue) + 1); - ADD_BLOCK (block_list, single_locale); - - - /* Search for the given string. This is a loop because we perhaps - got an ordered list of languages to consider for the translation. */ - while (1) - { - /* Make CATEGORYVALUE point to the next element of the list. */ - while (categoryvalue[0] != '\0' && categoryvalue[0] == ':') - ++categoryvalue; - if (categoryvalue[0] == '\0') - { - /* The whole contents of CATEGORYVALUE has been searched but - no valid entry has been found. We solve this situation - by implicitly appending a "C" entry, i.e. no translation - will take place. */ - single_locale[0] = 'C'; - single_locale[1] = '\0'; - } - else - { - char *cp = single_locale; - while (categoryvalue[0] != '\0' && categoryvalue[0] != ':') - *cp++ = *categoryvalue++; - *cp = '\0'; - - /* When this is a SUID binary we must not allow accessing files - outside the dedicated directories. */ - if (ENABLE_SECURE && strchr (single_locale, '/') != NULL) - /* Ingore this entry. */ - continue; - } - - /* If the current locale value is C (or POSIX) we don't load a - domain. Return the MSGID. */ - if (strcmp (single_locale, "C") == 0 - || strcmp (single_locale, "POSIX") == 0) - { - FREE_BLOCKS (block_list); - __libc_rwlock_unlock (_nl_state_lock); - __set_errno (saved_errno); - return (plural == 0 - ? (char *) msgid1 - /* Use the Germanic plural rule. */ - : n == 1 ? (char *) msgid1 : (char *) msgid2); - } - - - /* Find structure describing the message catalog matching the - DOMAINNAME and CATEGORY. */ - domain = _nl_find_domain (dirname, single_locale, xdomainname, binding); - - if (domain != NULL) - { - retval = _nl_find_msg (domain, binding, msgid1, &retlen); - - if (retval == NULL) - { - int cnt; - - for (cnt = 0; domain->successor[cnt] != NULL; ++cnt) - { - retval = _nl_find_msg (domain->successor[cnt], binding, - msgid1, &retlen); - - if (retval != NULL) - { - domain = domain->successor[cnt]; - break; - } - } - } - - if (retval != NULL) - { - /* Found the translation of MSGID1 in domain DOMAIN: - starting at RETVAL, RETLEN bytes. */ - FREE_BLOCKS (block_list); -#if defined HAVE_TSEARCH || defined _LIBC - if (foundp == NULL) - { - /* Create a new entry and add it to the search tree. */ - struct known_translation_t *newp; - - newp = (struct known_translation_t *) - malloc (offsetof (struct known_translation_t, msgid) - + msgid_len + domainname_len + 1); - if (newp != NULL) - { - newp->domainname = - mempcpy (newp->msgid, msgid1, msgid_len); - memcpy (newp->domainname, domainname, domainname_len + 1); - newp->category = category; - newp->counter = _nl_msg_cat_cntr; - newp->domain = domain; - newp->translation = retval; - newp->translation_length = retlen; - - /* Insert the entry in the search tree. */ - foundp = (struct known_translation_t **) - tsearch (newp, &root, transcmp); - if (foundp == NULL - || __builtin_expect (*foundp != newp, 0)) - /* The insert failed. */ - free (newp); - } - } - else - { - /* We can update the existing entry. */ - (*foundp)->counter = _nl_msg_cat_cntr; - (*foundp)->domain = domain; - (*foundp)->translation = retval; - (*foundp)->translation_length = retlen; - } -#endif - __set_errno (saved_errno); - - /* Now deal with plural. */ - if (plural) - retval = plural_lookup (domain, n, retval, retlen); - - __libc_rwlock_unlock (_nl_state_lock); - return retval; - } - } - } - /* NOTREACHED */ -} - - -char * -internal_function -_nl_find_msg (domain_file, domainbinding, msgid, lengthp) - struct loaded_l10nfile *domain_file; - struct binding *domainbinding; - const char *msgid; - size_t *lengthp; -{ - struct loaded_domain *domain; - nls_uint32 nstrings; - size_t act; - char *result; - size_t resultlen; - - if (domain_file->decided == 0) - _nl_load_domain (domain_file, domainbinding); - - if (domain_file->data == NULL) - return NULL; - - domain = (struct loaded_domain *) domain_file->data; - - nstrings = domain->nstrings; - - /* Locate the MSGID and its translation. */ - if (domain->hash_tab != NULL) - { - /* Use the hashing table. */ - nls_uint32 len = strlen (msgid); - nls_uint32 hash_val = hash_string (msgid); - nls_uint32 idx = hash_val % domain->hash_size; - nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); - - while (1) - { - nls_uint32 nstr = - W (domain->must_swap_hash_tab, domain->hash_tab[idx]); - - if (nstr == 0) - /* Hash table entry is empty. */ - return NULL; - - nstr--; - - /* Compare msgid with the original string at index nstr. - We compare the lengths with >=, not ==, because plural entries - are represented by strings with an embedded NUL. */ - if (nstr < nstrings - ? W (domain->must_swap, domain->orig_tab[nstr].length) >= len - && (strcmp (msgid, - domain->data + W (domain->must_swap, - domain->orig_tab[nstr].offset)) - == 0) - : domain->orig_sysdep_tab[nstr - nstrings].length > len - && (strcmp (msgid, - domain->orig_sysdep_tab[nstr - nstrings].pointer) - == 0)) - { - act = nstr; - goto found; - } - - if (idx >= domain->hash_size - incr) - idx -= domain->hash_size - incr; - else - idx += incr; - } - /* NOTREACHED */ - } - else - { - /* Try the default method: binary search in the sorted array of - messages. */ - size_t top, bottom; - - bottom = 0; - top = nstrings; - while (bottom < top) - { - int cmp_val; - - act = (bottom + top) / 2; - cmp_val = strcmp (msgid, (domain->data - + W (domain->must_swap, - domain->orig_tab[act].offset))); - if (cmp_val < 0) - top = act; - else if (cmp_val > 0) - bottom = act + 1; - else - goto found; - } - /* No translation was found. */ - return NULL; - } - - found: - /* The translation was found at index ACT. If we have to convert the - string to use a different character set, this is the time. */ - if (act < nstrings) - { - result = (char *) - (domain->data + W (domain->must_swap, domain->trans_tab[act].offset)); - resultlen = W (domain->must_swap, domain->trans_tab[act].length) + 1; - } - else - { - result = (char *) domain->trans_sysdep_tab[act - nstrings].pointer; - resultlen = domain->trans_sysdep_tab[act - nstrings].length; - } - -#if defined _LIBC || HAVE_ICONV - if (domain->codeset_cntr - != (domainbinding != NULL ? domainbinding->codeset_cntr : 0)) - { - /* The domain's codeset has changed through bind_textdomain_codeset() - since the message catalog was initialized or last accessed. We - have to reinitialize the converter. */ - _nl_free_domain_conv (domain); - _nl_init_domain_conv (domain_file, domain, domainbinding); - } - - if ( -# ifdef _LIBC - domain->conv != (__gconv_t) -1 -# else -# if HAVE_ICONV - domain->conv != (iconv_t) -1 -# endif -# endif - ) - { - /* We are supposed to do a conversion. First allocate an - appropriate table with the same structure as the table - of translations in the file, where we can put the pointers - to the converted strings in. - There is a slight complication with plural entries. They - are represented by consecutive NUL terminated strings. We - handle this case by converting RESULTLEN bytes, including - NULs. */ - - if (domain->conv_tab == NULL - && ((domain->conv_tab = - (char **) calloc (nstrings + domain->n_sysdep_strings, - sizeof (char *))) - == NULL)) - /* Mark that we didn't succeed allocating a table. */ - domain->conv_tab = (char **) -1; - - if (__builtin_expect (domain->conv_tab == (char **) -1, 0)) - /* Nothing we can do, no more memory. */ - goto converted; - - if (domain->conv_tab[act] == NULL) - { - /* We haven't used this string so far, so it is not - translated yet. Do this now. */ - /* We use a bit more efficient memory handling. - We allocate always larger blocks which get used over - time. This is faster than many small allocations. */ - __libc_lock_define_initialized (static, lock) -# define INITIAL_BLOCK_SIZE 4080 - static unsigned char *freemem; - static size_t freemem_size; - - const unsigned char *inbuf; - unsigned char *outbuf; - int malloc_count; -# ifndef _LIBC - transmem_block_t *transmem_list = NULL; -# endif - - __libc_lock_lock (lock); - - inbuf = (const unsigned char *) result; - outbuf = freemem + sizeof (size_t); - - malloc_count = 0; - while (1) - { - transmem_block_t *newmem; -# ifdef _LIBC - size_t non_reversible; - int res; - - if (freemem_size < sizeof (size_t)) - goto resize_freemem; - - res = __gconv (domain->conv, - &inbuf, inbuf + resultlen, - &outbuf, - outbuf + freemem_size - sizeof (size_t), - &non_reversible); - - if (res == __GCONV_OK || res == __GCONV_EMPTY_INPUT) - break; - - if (res != __GCONV_FULL_OUTPUT) - { - __libc_lock_unlock (lock); - goto converted; - } - - inbuf = result; -# else -# if HAVE_ICONV - const char *inptr = (const char *) inbuf; - size_t inleft = resultlen; - char *outptr = (char *) outbuf; - size_t outleft; - - if (freemem_size < sizeof (size_t)) - goto resize_freemem; - - outleft = freemem_size - sizeof (size_t); - if (iconv (domain->conv, - (ICONV_CONST char **) &inptr, &inleft, - &outptr, &outleft) - != (size_t) (-1)) - { - outbuf = (unsigned char *) outptr; - break; - } - if (errno != E2BIG) - { - __libc_lock_unlock (lock); - goto converted; - } -# endif -# endif - - resize_freemem: - /* We must allocate a new buffer or resize the old one. */ - if (malloc_count > 0) - { - ++malloc_count; - freemem_size = malloc_count * INITIAL_BLOCK_SIZE; - newmem = (transmem_block_t *) realloc (transmem_list, - freemem_size); -# ifdef _LIBC - if (newmem != NULL) - transmem_list = transmem_list->next; - else - { - struct transmem_list *old = transmem_list; - - transmem_list = transmem_list->next; - free (old); - } -# endif - } - else - { - malloc_count = 1; - freemem_size = INITIAL_BLOCK_SIZE; - newmem = (transmem_block_t *) malloc (freemem_size); - } - if (__builtin_expect (newmem == NULL, 0)) - { - freemem = NULL; - freemem_size = 0; - __libc_lock_unlock (lock); - goto converted; - } - -# ifdef _LIBC - /* Add the block to the list of blocks we have to free - at some point. */ - newmem->next = transmem_list; - transmem_list = newmem; - - freemem = newmem->data; - freemem_size -= offsetof (struct transmem_list, data); -# else - transmem_list = newmem; - freemem = newmem; -# endif - - outbuf = freemem + sizeof (size_t); - } - - /* We have now in our buffer a converted string. Put this - into the table of conversions. */ - *(size_t *) freemem = outbuf - freemem - sizeof (size_t); - domain->conv_tab[act] = (char *) freemem; - /* Shrink freemem, but keep it aligned. */ - freemem_size -= outbuf - freemem; - freemem = outbuf; - freemem += freemem_size & (alignof (size_t) - 1); - freemem_size = freemem_size & ~ (alignof (size_t) - 1); - - __libc_lock_unlock (lock); - } - - /* Now domain->conv_tab[act] contains the translation of all - the plural variants. */ - result = domain->conv_tab[act] + sizeof (size_t); - resultlen = *(size_t *) domain->conv_tab[act]; - } - - converted: - /* The result string is converted. */ - -#endif /* _LIBC || HAVE_ICONV */ - - *lengthp = resultlen; - return result; -} - - -/* Look up a plural variant. */ -static char * -internal_function -plural_lookup (domain, n, translation, translation_len) - struct loaded_l10nfile *domain; - unsigned long int n; - const char *translation; - size_t translation_len; -{ - struct loaded_domain *domaindata = (struct loaded_domain *) domain->data; - unsigned long int index; - const char *p; - - index = plural_eval (domaindata->plural, n); - if (index >= domaindata->nplurals) - /* This should never happen. It means the plural expression and the - given maximum value do not match. */ - index = 0; - - /* Skip INDEX strings at TRANSLATION. */ - p = translation; - while (index-- > 0) - { -#ifdef _LIBC - p = __rawmemchr (p, '\0'); -#else - p = strchr (p, '\0'); -#endif - /* And skip over the NUL byte. */ - p++; - - if (p >= translation + translation_len) - /* This should never happen. It means the plural expression - evaluated to a value larger than the number of variants - available for MSGID1. */ - return (char *) translation; - } - return (char *) p; -} - -#ifndef _LIBC -/* Return string representation of locale CATEGORY. */ -static const char * -internal_function -category_to_name (category) - int category; -{ - const char *retval; - - switch (category) - { -#ifdef LC_COLLATE - case LC_COLLATE: - retval = "LC_COLLATE"; - break; -#endif -#ifdef LC_CTYPE - case LC_CTYPE: - retval = "LC_CTYPE"; - break; -#endif -#ifdef LC_MONETARY - case LC_MONETARY: - retval = "LC_MONETARY"; - break; -#endif -#ifdef LC_NUMERIC - case LC_NUMERIC: - retval = "LC_NUMERIC"; - break; -#endif -#ifdef LC_TIME - case LC_TIME: - retval = "LC_TIME"; - break; -#endif -#ifdef LC_MESSAGES - case LC_MESSAGES: - retval = "LC_MESSAGES"; - break; -#endif -#ifdef LC_RESPONSE - case LC_RESPONSE: - retval = "LC_RESPONSE"; - break; -#endif -#ifdef LC_ALL - case LC_ALL: - /* This might not make sense but is perhaps better than any other - value. */ - retval = "LC_ALL"; - break; -#endif - default: - /* If you have a better idea for a default value let me know. */ - retval = "LC_XXX"; - } - - return retval; -} -#endif - -/* Guess value of current locale from value of the environment variables. */ -static const char * -internal_function -guess_category_value (category, categoryname) - int category; - const char *categoryname; -{ - const char *language; - const char *retval; - - /* The highest priority value is the `LANGUAGE' environment - variable. But we don't use the value if the currently selected - locale is the C locale. This is a GNU extension. */ - language = getenv ("LANGUAGE"); - if (language != NULL && language[0] == '\0') - language = NULL; - - /* We have to proceed with the POSIX methods of looking to `LC_ALL', - `LC_xxx', and `LANG'. On some systems this can be done by the - `setlocale' function itself. */ -#ifdef _LIBC - retval = __current_locale_name (category); -#else - retval = _nl_locale_name (category, categoryname); -#endif - - return language != NULL && strcmp (retval, "C") != 0 ? language : retval; -} - -/* @@ begin of epilog @@ */ - -/* We don't want libintl.a to depend on any other library. So we - avoid the non-standard function stpcpy. In GNU C Library this - function is available, though. Also allow the symbol HAVE_STPCPY - to be defined. */ -#if !_LIBC && !HAVE_STPCPY -static char * -stpcpy (dest, src) - char *dest; - const char *src; -{ - while ((*dest++ = *src++) != '\0') - /* Do nothing. */ ; - return dest - 1; -} -#endif - -#if !_LIBC && !HAVE_MEMPCPY -static void * -mempcpy (dest, src, n) - void *dest; - const void *src; - size_t n; -{ - return (void *) ((char *) memcpy (dest, src, n) + n); -} -#endif - - -#ifdef _LIBC -/* If we want to free all resources we have to do some work at - program's end. */ -libc_freeres_fn (free_mem) -{ - void *old; - - while (_nl_domain_bindings != NULL) - { - struct binding *oldp = _nl_domain_bindings; - _nl_domain_bindings = _nl_domain_bindings->next; - if (oldp->dirname != INTUSE(_nl_default_dirname)) - /* Yes, this is a pointer comparison. */ - free (oldp->dirname); - free (oldp->codeset); - free (oldp); - } - - if (_nl_current_default_domain != _nl_default_default_domain) - /* Yes, again a pointer comparison. */ - free ((char *) _nl_current_default_domain); - - /* Remove the search tree with the known translations. */ - __tdestroy (root, free); - root = NULL; - - while (transmem_list != NULL) - { - old = transmem_list; - transmem_list = transmem_list->next; - free (old); - } -} -#endif diff --git a/src/system/libroot/posix/glibc/intl/dcngettext.c b/src/system/libroot/posix/glibc/intl/dcngettext.c deleted file mode 100644 index 6d95d1bc74..0000000000 --- a/src/system/libroot/posix/glibc/intl/dcngettext.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Implementation of the dcngettext(3) function. - Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define DCNGETTEXT __dcngettext -# define DCIGETTEXT __dcigettext -#else -# define DCNGETTEXT libintl_dcngettext -# define DCIGETTEXT libintl_dcigettext -#endif - -/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY - locale. */ -char * -DCNGETTEXT (domainname, msgid1, msgid2, n, category) - const char *domainname; - const char *msgid1; - const char *msgid2; - unsigned long int n; - int category; -{ - return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__dcngettext, dcngettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/dgettext.c b/src/system/libroot/posix/glibc/intl/dgettext.c deleted file mode 100644 index c766d9508d..0000000000 --- a/src/system/libroot/posix/glibc/intl/dgettext.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Implementation of the dgettext(3) function. - Copyright (C) 1995-1997, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define DGETTEXT __dgettext -# define DCGETTEXT INTUSE(__dcgettext) -#else -# define DGETTEXT libintl_dgettext -# define DCGETTEXT libintl_dcgettext -#endif - -/* Look up MSGID in the DOMAINNAME message catalog of the current - LC_MESSAGES locale. */ -char * -DGETTEXT (domainname, msgid) - const char *domainname; - const char *msgid; -{ - return DCGETTEXT (domainname, msgid, LC_MESSAGES); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__dgettext, dgettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/dngettext.c b/src/system/libroot/posix/glibc/intl/dngettext.c deleted file mode 100644 index 89c7b0afcf..0000000000 --- a/src/system/libroot/posix/glibc/intl/dngettext.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Implementation of the dngettext(3) function. - Copyright (C) 1995-1997, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define DNGETTEXT __dngettext -# define DCNGETTEXT __dcngettext -#else -# define DNGETTEXT libintl_dngettext -# define DCNGETTEXT libintl_dcngettext -#endif - -/* Look up MSGID in the DOMAINNAME message catalog of the current - LC_MESSAGES locale and skip message according to the plural form. */ -char * -DNGETTEXT (domainname, msgid1, msgid2, n) - const char *domainname; - const char *msgid1; - const char *msgid2; - unsigned long int n; -{ - return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__dngettext, dngettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/explodename.c b/src/system/libroot/posix/glibc/intl/explodename.c deleted file mode 100644 index f7bcfa5ff6..0000000000 --- a/src/system/libroot/posix/glibc/intl/explodename.c +++ /dev/null @@ -1,136 +0,0 @@ -/* Copyright (C) 1995-2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include "loadinfo.h" - -/* On some strange systems still no definition of NULL is found. Sigh! */ -#ifndef NULL -# if defined __STDC__ && __STDC__ -# define NULL ((void *) 0) -# else -# define NULL 0 -# endif -#endif - -/* @@ end of prolog @@ */ - -static char *_nl_find_language PARAMS ((const char *name)); - -static char * -_nl_find_language (name) - const char *name; -{ - while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '.') - ++name; - - return (char *) name; -} - - -int -_nl_explode_name (name, language, modifier, territory, codeset, - normalized_codeset) - char *name; - const char **language; - const char **modifier; - const char **territory; - const char **codeset; - const char **normalized_codeset; -{ - char *cp; - int mask; - - *modifier = NULL; - *territory = NULL; - *codeset = NULL; - *normalized_codeset = NULL; - - /* Now we determine the single parts of the locale name. First - look for the language. Termination symbols are `_', '.', and `@'. */ - mask = 0; - *language = cp = name; - cp = _nl_find_language (*language); - - if (*language == cp) - /* This does not make sense: language has to be specified. Use - this entry as it is without exploding. Perhaps it is an alias. */ - cp = strchr (*language, '\0'); - else if (cp[0] != '@') - { - if (cp[0] == '_') - { - /* Next is the territory. */ - cp[0] = '\0'; - *territory = ++cp; - - while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@') - ++cp; - - mask |= XPG_TERRITORY; - } - - if (cp[0] == '.') - { - /* Next is the codeset. */ - cp[0] = '\0'; - *codeset = ++cp; - - while (cp[0] != '\0' && cp[0] != '@') - ++cp; - - mask |= XPG_CODESET; - - if (*codeset != cp && (*codeset)[0] != '\0') - { - *normalized_codeset = _nl_normalize_codeset (*codeset, - cp - *codeset); - if (strcmp (*codeset, *normalized_codeset) == 0) - free ((char *) *normalized_codeset); - else - mask |= XPG_NORM_CODESET; - } - } - } - - if (cp[0] == '@') - { - /* Next is the modifier. */ - cp[0] = '\0'; - *modifier = ++cp; - - if (cp[0] != '\0') - mask |= XPG_MODIFIER; - } - - if (*territory != NULL && (*territory)[0] == '\0') - mask &= ~XPG_TERRITORY; - - if (*codeset != NULL && (*codeset)[0] == '\0') - mask &= ~XPG_CODESET; - - return mask; -} diff --git a/src/system/libroot/posix/glibc/intl/finddomain.c b/src/system/libroot/posix/glibc/intl/finddomain.c deleted file mode 100644 index 1031e4d5b1..0000000000 --- a/src/system/libroot/posix/glibc/intl/finddomain.c +++ /dev/null @@ -1,185 +0,0 @@ -/* Handle list of needed message catalogs - Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#if defined HAVE_UNISTD_H || defined _LIBC -# include -#endif - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ -/* List of already loaded domains. */ -static struct loaded_l10nfile *_nl_loaded_domains; - - -/* Return a data structure describing the message catalog described by - the DOMAINNAME and CATEGORY parameters with respect to the currently - established bindings. */ -struct loaded_l10nfile * -internal_function -_nl_find_domain (dirname, locale, domainname, domainbinding) - const char *dirname; - char *locale; - const char *domainname; - struct binding *domainbinding; -{ - struct loaded_l10nfile *retval; - const char *language; - const char *modifier; - const char *territory; - const char *codeset; - const char *normalized_codeset; - const char *alias_value; - int mask; - - /* LOCALE can consist of up to four recognized parts for the XPG syntax: - - language[_territory[.codeset]][@modifier] - - Beside the first part all of them are allowed to be missing. If - the full specified locale is not found, the less specific one are - looked for. The various parts will be stripped off according to - the following order: - (1) codeset - (2) normalized codeset - (3) territory - (4) modifier - */ - - /* If we have already tested for this locale entry there has to - be one data set in the list of loaded domains. */ - retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, - strlen (dirname) + 1, 0, locale, NULL, NULL, - NULL, NULL, domainname, 0); - if (retval != NULL) - { - /* We know something about this locale. */ - int cnt; - - if (retval->decided == 0) - _nl_load_domain (retval, domainbinding); - - if (retval->data != NULL) - return retval; - - for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) - { - if (retval->successor[cnt]->decided == 0) - _nl_load_domain (retval->successor[cnt], domainbinding); - - if (retval->successor[cnt]->data != NULL) - break; - } - return cnt >= 0 ? retval : NULL; - /* NOTREACHED */ - } - - /* See whether the locale value is an alias. If yes its value - *overwrites* the alias name. No test for the original value is - done. */ - alias_value = _nl_expand_alias (locale); - if (alias_value != NULL) - { -#if defined _LIBC || defined HAVE_STRDUP - locale = strdup (alias_value); - if (locale == NULL) - return NULL; -#else - size_t len = strlen (alias_value) + 1; - locale = (char *) malloc (len); - if (locale == NULL) - return NULL; - - memcpy (locale, alias_value, len); -#endif - } - - /* Now we determine the single parts of the locale name. First - look for the language. Termination symbols are `_' and `@' if - we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */ - mask = _nl_explode_name (locale, &language, &modifier, &territory, - &codeset, &normalized_codeset); - - /* Create all possible locale entries which might be interested in - generalization. */ - retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, - strlen (dirname) + 1, mask, language, territory, - codeset, normalized_codeset, modifier, - domainname, 1); - if (retval == NULL) - /* This means we are out of core. */ - return NULL; - - if (retval->decided == 0) - _nl_load_domain (retval, domainbinding); - if (retval->data == NULL) - { - int cnt; - for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) - { - if (retval->successor[cnt]->decided == 0) - _nl_load_domain (retval->successor[cnt], domainbinding); - if (retval->successor[cnt]->data != NULL) - break; - } - } - - /* The room for an alias was dynamically allocated. Free it now. */ - if (alias_value != NULL) - free (locale); - - /* The space for normalized_codeset is dynamically allocated. Free it. */ - if (mask & XPG_NORM_CODESET) - free ((void *) normalized_codeset); - - return retval; -} - - -#ifdef _LIBC -libc_freeres_fn (free_mem) -{ - struct loaded_l10nfile *runp = _nl_loaded_domains; - - while (runp != NULL) - { - struct loaded_l10nfile *here = runp; - if (runp->data != NULL) - _nl_unload_domain ((struct loaded_domain *) runp->data); - runp = runp->next; - free ((char *) here->filename); - free (here); - } -} -#endif diff --git a/src/system/libroot/posix/glibc/intl/gettext.c b/src/system/libroot/posix/glibc/intl/gettext.c deleted file mode 100644 index 63abe582b5..0000000000 --- a/src/system/libroot/posix/glibc/intl/gettext.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Implementation of gettext(3) function. - Copyright (C) 1995, 1997, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef _LIBC -# define __need_NULL -# include -#else -# include /* Just for NULL. */ -#endif - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define GETTEXT __gettext -# define DCGETTEXT INTUSE(__dcgettext) -#else -# define GETTEXT libintl_gettext -# define DCGETTEXT libintl_dcgettext -#endif - -/* Look up MSGID in the current default message catalog for the current - LC_MESSAGES locale. If not found, returns MSGID itself (the default - text). */ -char * -GETTEXT (msgid) - const char *msgid; -{ - return DCGETTEXT (NULL, msgid, LC_MESSAGES); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__gettext, gettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/gettextP.h b/src/system/libroot/posix/glibc/intl/gettextP.h deleted file mode 100644 index 69a95cabc7..0000000000 --- a/src/system/libroot/posix/glibc/intl/gettextP.h +++ /dev/null @@ -1,245 +0,0 @@ -/* Header describing internals of libintl library. - Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _GETTEXTP_H -#define _GETTEXTP_H - -#include /* Get size_t. */ - -#ifdef _LIBC -# include "../iconv/gconv_int.h" -#else -# if HAVE_ICONV -# include -# endif -#endif - -#include "loadinfo.h" - -#include "gmo.h" /* Get nls_uint32. */ - -/* @@ end of prolog @@ */ - -#ifndef PARAMS -# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES -# define PARAMS(args) args -# else -# define PARAMS(args) () -# endif -#endif - -#ifndef internal_function -# define internal_function -#endif - -#ifndef attribute_hidden -# define attribute_hidden -#endif - -/* Tell the compiler when a conditional or integer expression is - almost always true or almost always false. */ -#ifndef HAVE_BUILTIN_EXPECT -# define __builtin_expect(expr, val) (expr) -#endif - -#ifndef W -# define W(flag, data) ((flag) ? SWAP (data) : (data)) -#endif - - -#ifdef _LIBC -# include -# define SWAP(i) bswap_32 (i) -#else -static nls_uint32 SWAP PARAMS ((nls_uint32 i)); - -static inline nls_uint32 -SWAP (i) - nls_uint32 i; -{ - return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); -} -#endif - - -/* In-memory representation of system dependent string. */ -struct sysdep_string_desc -{ - /* Length of addressed string, including the trailing NUL. */ - size_t length; - /* Pointer to addressed string. */ - const char *pointer; -}; - -/* The representation of an opened message catalog. */ -struct loaded_domain -{ - /* Pointer to memory containing the .mo file. */ - const char *data; - /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */ - int use_mmap; - /* Size of mmap()ed memory. */ - size_t mmap_size; - /* 1 if the .mo file uses a different endianness than this machine. */ - int must_swap; - /* Pointer to additional malloc()ed memory. */ - void *malloced; - - /* Number of static strings pairs. */ - nls_uint32 nstrings; - /* Pointer to descriptors of original strings in the file. */ - const struct string_desc *orig_tab; - /* Pointer to descriptors of translated strings in the file. */ - const struct string_desc *trans_tab; - - /* Number of system dependent strings pairs. */ - nls_uint32 n_sysdep_strings; - /* Pointer to descriptors of original sysdep strings. */ - const struct sysdep_string_desc *orig_sysdep_tab; - /* Pointer to descriptors of translated sysdep strings. */ - const struct sysdep_string_desc *trans_sysdep_tab; - - /* Size of hash table. */ - nls_uint32 hash_size; - /* Pointer to hash table. */ - const nls_uint32 *hash_tab; - /* 1 if the hash table uses a different endianness than this machine. */ - int must_swap_hash_tab; - - int codeset_cntr; -#ifdef _LIBC - __gconv_t conv; -#else -# if HAVE_ICONV - iconv_t conv; -# endif -#endif - char **conv_tab; - - struct expression *plural; - unsigned long int nplurals; -}; - -/* We want to allocate a string at the end of the struct. But ISO C - doesn't allow zero sized arrays. */ -#ifdef __GNUC__ -# define ZERO 0 -#else -# define ZERO 1 -#endif - -/* A set of settings bound to a message domain. Used to store settings - from bindtextdomain() and bind_textdomain_codeset(). */ -struct binding -{ - struct binding *next; - char *dirname; - int codeset_cntr; /* Incremented each time codeset changes. */ - char *codeset; - char domainname[ZERO]; -}; - -/* A counter which is incremented each time some previous translations - become invalid. - This variable is part of the external ABI of the GNU libintl. */ -extern int _nl_msg_cat_cntr; - -#ifndef _LIBC -const char *_nl_locale_name PARAMS ((int category, const char *categoryname)); -#endif - -struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname, - char *__locale, - const char *__domainname, - struct binding *__domainbinding)) - internal_function; -void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain, - struct binding *__domainbinding)) - internal_function; -void _nl_unload_domain PARAMS ((struct loaded_domain *__domain)) - internal_function; -const char *_nl_init_domain_conv PARAMS ((struct loaded_l10nfile *__domain_file, - struct loaded_domain *__domain, - struct binding *__domainbinding)) - internal_function; -void _nl_free_domain_conv PARAMS ((struct loaded_domain *__domain)) - internal_function; - -char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file, - struct binding *domainbinding, - const char *msgid, size_t *lengthp)) - internal_function; - -#ifdef _LIBC -extern char *__gettext PARAMS ((const char *__msgid)); -extern char *__dgettext PARAMS ((const char *__domainname, - const char *__msgid)); -extern char *__dcgettext PARAMS ((const char *__domainname, - const char *__msgid, int __category)); -extern char *__ngettext PARAMS ((const char *__msgid1, const char *__msgid2, - unsigned long int __n)); -extern char *__dngettext PARAMS ((const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int n)); -extern char *__dcngettext PARAMS ((const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int __n, int __category)); -extern char *__dcigettext PARAMS ((const char *__domainname, - const char *__msgid1, const char *__msgid2, - int __plural, unsigned long int __n, - int __category)); -extern char *__textdomain PARAMS ((const char *__domainname)); -extern char *__bindtextdomain PARAMS ((const char *__domainname, - const char *__dirname)); -extern char *__bind_textdomain_codeset PARAMS ((const char *__domainname, - const char *__codeset)); -#else -extern char *libintl_gettext PARAMS ((const char *__msgid)); -extern char *libintl_dgettext PARAMS ((const char *__domainname, - const char *__msgid)); -extern char *libintl_dcgettext PARAMS ((const char *__domainname, - const char *__msgid, int __category)); -extern char *libintl_ngettext PARAMS ((const char *__msgid1, - const char *__msgid2, - unsigned long int __n)); -extern char *libintl_dngettext PARAMS ((const char *__domainname, - const char *__msgid1, - const char *__msgid2, - unsigned long int __n)); -extern char *libintl_dcngettext PARAMS ((const char *__domainname, - const char *__msgid1, - const char *__msgid2, - unsigned long int __n, - int __category)); -extern char *libintl_dcigettext PARAMS ((const char *__domainname, - const char *__msgid1, - const char *__msgid2, - int __plural, unsigned long int __n, - int __category)); -extern char *libintl_textdomain PARAMS ((const char *__domainname)); -extern char *libintl_bindtextdomain PARAMS ((const char *__domainname, - const char *__dirname)); -extern char *libintl_bind_textdomain_codeset PARAMS ((const char *__domainname, - const char *__codeset)); -#endif - -/* @@ begin of epilog @@ */ - -#endif /* gettextP.h */ diff --git a/src/system/libroot/posix/glibc/intl/gmo.h b/src/system/libroot/posix/glibc/intl/gmo.h deleted file mode 100644 index 65e0b27440..0000000000 --- a/src/system/libroot/posix/glibc/intl/gmo.h +++ /dev/null @@ -1,149 +0,0 @@ -/* Internal header for GNU gettext internationalization functions. - Copyright (C) 1995, 1997, 2000-2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _GETTEXT_H -#define _GETTEXT_H 1 - -#include - -/* @@ end of prolog @@ */ - -/* The magic number of the GNU message catalog format. */ -#define _MAGIC 0x950412de -#define _MAGIC_SWAPPED 0xde120495 - -/* Revision number of the currently used .mo (binary) file format. */ -#define MO_REVISION_NUMBER 0 - -/* The following contortions are an attempt to use the C preprocessor - to determine an unsigned integral type that is 32 bits wide. An - alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but - as of version autoconf-2.13, the AC_CHECK_SIZEOF macro doesn't work - when cross-compiling. */ - -#if __STDC__ -# define UINT_MAX_32_BITS 4294967295U -#else -# define UINT_MAX_32_BITS 0xFFFFFFFF -#endif - -/* If UINT_MAX isn't defined, assume it's a 32-bit type. - This should be valid for all systems GNU cares about because - that doesn't include 16-bit systems, and only modern systems - (that certainly have ) have 64+-bit integral types. */ - -#ifndef UINT_MAX -# define UINT_MAX UINT_MAX_32_BITS -#endif - -#if UINT_MAX == UINT_MAX_32_BITS -typedef unsigned nls_uint32; -#else -# if USHRT_MAX == UINT_MAX_32_BITS -typedef unsigned short nls_uint32; -# else -# if ULONG_MAX == UINT_MAX_32_BITS -typedef unsigned long nls_uint32; -# else - /* The following line is intended to throw an error. Using #error is - not portable enough. */ - "Cannot determine unsigned 32-bit data type." -# endif -# endif -#endif - - -/* Header for binary .mo file format. */ -struct mo_file_header -{ - /* The magic number. */ - nls_uint32 magic; - /* The revision number of the file format. */ - nls_uint32 revision; - - /* The following are only used in .mo files with major revision 0. */ - - /* The number of strings pairs. */ - nls_uint32 nstrings; - /* Offset of table with start offsets of original strings. */ - nls_uint32 orig_tab_offset; - /* Offset of table with start offsets of translated strings. */ - nls_uint32 trans_tab_offset; - /* Size of hash table. */ - nls_uint32 hash_tab_size; - /* Offset of first hash table entry. */ - nls_uint32 hash_tab_offset; - - /* The following are only used in .mo files with minor revision >= 1. */ - - /* The number of system dependent segments. */ - nls_uint32 n_sysdep_segments; - /* Offset of table describing system dependent segments. */ - nls_uint32 sysdep_segments_offset; - /* The number of system dependent strings pairs. */ - nls_uint32 n_sysdep_strings; - /* Offset of table with start offsets of original sysdep strings. */ - nls_uint32 orig_sysdep_tab_offset; - /* Offset of table with start offsets of translated sysdep strings. */ - nls_uint32 trans_sysdep_tab_offset; -}; - -/* Descriptor for static string contained in the binary .mo file. */ -struct string_desc -{ - /* Length of addressed string, not including the trailing NUL. */ - nls_uint32 length; - /* Offset of string in file. */ - nls_uint32 offset; -}; - -/* The following are only used in .mo files with minor revision >= 1. */ - -/* Descriptor for system dependent string segment. */ -struct sysdep_segment -{ - /* Length of addressed string, including the trailing NUL. */ - nls_uint32 length; - /* Offset of string in file. */ - nls_uint32 offset; -}; - -/* Descriptor for system dependent string. */ -struct sysdep_string -{ - /* Offset of static string segments in file. */ - nls_uint32 offset; - /* Alternating sequence of static and system dependent segments. - The last segment is a static segment, including the trailing NUL. */ - struct segment_pair - { - /* Size of static segment. */ - nls_uint32 segsize; - /* Reference to system dependent string segment, or ~0 at the end. */ - nls_uint32 sysdepref; - } segments[1]; -}; - -/* Marker for the end of the segments[] array. This has the value 0xFFFFFFFF, - regardless whether 'int' is 16 bit, 32 bit, or 64 bit. */ -#define SEGMENTS_END ((nls_uint32) ~0) - -/* @@ begin of epilog @@ */ - -#endif /* gettext.h */ diff --git a/src/system/libroot/posix/glibc/intl/l10nflist.c b/src/system/libroot/posix/glibc/intl/l10nflist.c deleted file mode 100644 index 31760bdaaa..0000000000 --- a/src/system/libroot/posix/glibc/intl/l10nflist.c +++ /dev/null @@ -1,377 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Tell glibc's to provide a prototype for stpcpy(). - This must come before because may include - , and once has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#if defined _LIBC || defined HAVE_ARGZ_H -# include -#endif -#include -#include -#include - -#include "loadinfo.h" - -/* On some strange systems still no definition of NULL is found. Sigh! */ -#ifndef NULL -# if defined __STDC__ && __STDC__ -# define NULL ((void *) 0) -# else -# define NULL 0 -# endif -#endif - -/* @@ end of prolog @@ */ - -#ifdef _LIBC -/* Rename the non ANSI C functions. This is required by the standard - because some ANSI C functions will require linking with this object - file and the name space must not be polluted. */ -# ifndef stpcpy -# define stpcpy(dest, src) __stpcpy(dest, src) -# endif -#else -# ifndef HAVE_STPCPY -static char *stpcpy PARAMS ((char *dest, const char *src)); -# endif -#endif - -/* Define function which are usually not available. */ - -#if !defined _LIBC && !defined HAVE___ARGZ_COUNT -/* Returns the number of strings in ARGZ. */ -static size_t argz_count__ PARAMS ((const char *argz, size_t len)); - -static size_t -argz_count__ (argz, len) - const char *argz; - size_t len; -{ - size_t count = 0; - while (len > 0) - { - size_t part_len = strlen (argz); - argz += part_len + 1; - len -= part_len + 1; - count++; - } - return count; -} -# undef __argz_count -# define __argz_count(argz, len) argz_count__ (argz, len) -#else -# ifdef _LIBC -# define __argz_count(argz, len) INTUSE(__argz_count) (argz, len) -# endif -#endif /* !_LIBC && !HAVE___ARGZ_COUNT */ - -#if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY -/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's - except the last into the character SEP. */ -static void argz_stringify__ PARAMS ((char *argz, size_t len, int sep)); - -static void -argz_stringify__ (argz, len, sep) - char *argz; - size_t len; - int sep; -{ - while (len > 0) - { - size_t part_len = strlen (argz); - argz += part_len; - len -= part_len + 1; - if (len > 0) - *argz++ = sep; - } -} -# undef __argz_stringify -# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep) -#else -# ifdef _LIBC -# define __argz_stringify(argz, len, sep) \ - INTUSE(__argz_stringify) (argz, len, sep) -# endif -#endif /* !_LIBC && !HAVE___ARGZ_STRINGIFY */ - -#if !defined _LIBC && !defined HAVE___ARGZ_NEXT -static char *argz_next__ PARAMS ((char *argz, size_t argz_len, - const char *entry)); - -static char * -argz_next__ (argz, argz_len, entry) - char *argz; - size_t argz_len; - const char *entry; -{ - if (entry) - { - if (entry < argz + argz_len) - entry = strchr (entry, '\0') + 1; - - return entry >= argz + argz_len ? NULL : (char *) entry; - } - else - if (argz_len > 0) - return argz; - else - return 0; -} -# undef __argz_next -# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry) -#endif /* !_LIBC && !HAVE___ARGZ_NEXT */ - - -/* Return number of bits set in X. */ -static int pop PARAMS ((int x)); - -static inline int -pop (x) - int x; -{ - /* We assume that no more than 16 bits are used. */ - x = ((x & ~0x5555) >> 1) + (x & 0x5555); - x = ((x & ~0x3333) >> 2) + (x & 0x3333); - x = ((x >> 4) + x) & 0x0f0f; - x = ((x >> 8) + x) & 0xff; - - return x; -} - - -struct loaded_l10nfile * -_nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, mask, language, - territory, codeset, normalized_codeset, modifier, - filename, do_allocate) - struct loaded_l10nfile **l10nfile_list; - const char *dirlist; - size_t dirlist_len; - int mask; - const char *language; - const char *territory; - const char *codeset; - const char *normalized_codeset; - const char *modifier; - const char *filename; - int do_allocate; -{ - char *abs_filename; - struct loaded_l10nfile *last = NULL; - struct loaded_l10nfile *retval; - char *cp; - size_t entries; - int cnt; - - /* Allocate room for the full file name. */ - abs_filename = (char *) malloc (dirlist_len - + strlen (language) - + ((mask & XPG_TERRITORY) != 0 - ? strlen (territory) + 1 : 0) - + ((mask & XPG_CODESET) != 0 - ? strlen (codeset) + 1 : 0) - + ((mask & XPG_NORM_CODESET) != 0 - ? strlen (normalized_codeset) + 1 : 0) - + ((mask & XPG_MODIFIER) != 0 - ? strlen (modifier) + 1 : 0) - + 1 + strlen (filename) + 1); - - if (abs_filename == NULL) - return NULL; - - retval = NULL; - last = NULL; - - /* Construct file name. */ - memcpy (abs_filename, dirlist, dirlist_len); - __argz_stringify (abs_filename, dirlist_len, ':'); - cp = abs_filename + (dirlist_len - 1); - *cp++ = '/'; - cp = stpcpy (cp, language); - - if ((mask & XPG_TERRITORY) != 0) - { - *cp++ = '_'; - cp = stpcpy (cp, territory); - } - if ((mask & XPG_CODESET) != 0) - { - *cp++ = '.'; - cp = stpcpy (cp, codeset); - } - if ((mask & XPG_NORM_CODESET) != 0) - { - *cp++ = '.'; - cp = stpcpy (cp, normalized_codeset); - } - if ((mask & XPG_MODIFIER) != 0) - { - *cp++ = '@'; - cp = stpcpy (cp, modifier); - } - - *cp++ = '/'; - stpcpy (cp, filename); - - /* Look in list of already loaded domains whether it is already - available. */ - last = NULL; - for (retval = *l10nfile_list; retval != NULL; retval = retval->next) - if (retval->filename != NULL) - { - int compare = strcmp (retval->filename, abs_filename); - if (compare == 0) - /* We found it! */ - break; - if (compare < 0) - { - /* It's not in the list. */ - retval = NULL; - break; - } - - last = retval; - } - - if (retval != NULL || do_allocate == 0) - { - free (abs_filename); - return retval; - } - - retval = (struct loaded_l10nfile *) - malloc (sizeof (*retval) + (__argz_count (dirlist, dirlist_len) - * (1 << pop (mask)) - * sizeof (struct loaded_l10nfile *))); - if (retval == NULL) - return NULL; - - retval->filename = abs_filename; - retval->decided = (__argz_count (dirlist, dirlist_len) != 1 - || ((mask & XPG_CODESET) != 0 - && (mask & XPG_NORM_CODESET) != 0)); - retval->data = NULL; - - if (last == NULL) - { - retval->next = *l10nfile_list; - *l10nfile_list = retval; - } - else - { - retval->next = last->next; - last->next = retval; - } - - entries = 0; - /* If the DIRLIST is a real list the RETVAL entry corresponds not to - a real file. So we have to use the DIRLIST separation mechanism - of the inner loop. */ - cnt = __argz_count (dirlist, dirlist_len) == 1 ? mask - 1 : mask; - for (; cnt >= 0; --cnt) - if ((cnt & ~mask) == 0) - { - /* Iterate over all elements of the DIRLIST. */ - char *dir = NULL; - - while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir)) - != NULL) - retval->successor[entries++] - = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt, - language, territory, codeset, - normalized_codeset, modifier, filename, 1); - } - retval->successor[entries] = NULL; - - return retval; -} - -/* Normalize codeset name. There is no standard for the codeset - names. Normalization allows the user to use any of the common - names. The return value is dynamically allocated and has to be - freed by the caller. */ -const char * -_nl_normalize_codeset (codeset, name_len) - const char *codeset; - size_t name_len; -{ - int len = 0; - int only_digit = 1; - char *retval; - char *wp; - size_t cnt; - - for (cnt = 0; cnt < name_len; ++cnt) - if (isalnum ((unsigned char) codeset[cnt])) - { - ++len; - - if (isalpha ((unsigned char) codeset[cnt])) - only_digit = 0; - } - - retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1); - - if (retval != NULL) - { - if (only_digit) - wp = stpcpy (retval, "iso"); - else - wp = retval; - - for (cnt = 0; cnt < name_len; ++cnt) - if (isalpha ((unsigned char) codeset[cnt])) - *wp++ = tolower ((unsigned char) codeset[cnt]); - else if (isdigit ((unsigned char) codeset[cnt])) - *wp++ = codeset[cnt]; - - *wp = '\0'; - } - - return (const char *) retval; -} - - -/* @@ begin of epilog @@ */ - -/* We don't want libintl.a to depend on any other library. So we - avoid the non-standard function stpcpy. In GNU C Library this - function is available, though. Also allow the symbol HAVE_STPCPY - to be defined. */ -#if !_LIBC && !HAVE_STPCPY -static char * -stpcpy (dest, src) - char *dest; - const char *src; -{ - while ((*dest++ = *src++) != '\0') - /* Do nothing. */ ; - return dest - 1; -} -#endif diff --git a/src/system/libroot/posix/glibc/intl/libintl.h b/src/system/libroot/posix/glibc/intl/libintl.h deleted file mode 100644 index 89db38f3b1..0000000000 --- a/src/system/libroot/posix/glibc/intl/libintl.h +++ /dev/null @@ -1,122 +0,0 @@ -/* Message catalogs for internationalization. - Copyright (C) 1995-1999, 2000-2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - This file is derived from the file libgettext.h in the GNU gettext package. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LIBINTL_H -#define _LIBINTL_H 1 - -#include - -/* We define an additional symbol to signal that we use the GNU - implementation of gettext. */ -#define __USE_GNU_GETTEXT 1 - -/* Provide information about the supported file formats. Returns the - maximum minor revision number supported for a given major revision. */ -#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \ - ((major) == 0 ? 1 : -1) - -__BEGIN_DECLS - -/* Look up MSGID in the current default message catalog for the current - LC_MESSAGES locale. If not found, returns MSGID itself (the default - text). */ -extern char *gettext (__const char *__msgid) __THROW; - -/* Look up MSGID in the DOMAINNAME message catalog for the current - LC_MESSAGES locale. */ -extern char *dgettext (__const char *__domainname, __const char *__msgid) - __THROW; -extern char *__dgettext (__const char *__domainname, __const char *__msgid) - __THROW __attribute_format_arg__ (2); - -/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY - locale. */ -extern char *dcgettext (__const char *__domainname, - __const char *__msgid, int __category) __THROW; -extern char *__dcgettext (__const char *__domainname, - __const char *__msgid, int __category) - __THROW __attribute_format_arg__ (2); - - -/* Similar to `gettext' but select the plural form corresponding to the - number N. */ -extern char *ngettext (__const char *__msgid1, __const char *__msgid2, - unsigned long int __n) - __THROW __attribute_format_arg__ (1) __attribute_format_arg__ (2); - -/* Similar to `dgettext' but select the plural form corresponding to the - number N. */ -extern char *dngettext (__const char *__domainname, __const char *__msgid1, - __const char *__msgid2, unsigned long int __n) - __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3); - -/* Similar to `dcgettext' but select the plural form corresponding to the - number N. */ -extern char *dcngettext (__const char *__domainname, __const char *__msgid1, - __const char *__msgid2, unsigned long int __n, - int __category) - __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3); - - -/* Set the current default message catalog to DOMAINNAME. - If DOMAINNAME is null, return the current default. - If DOMAINNAME is "", reset to the default of "messages". */ -extern char *textdomain (__const char *__domainname) __THROW; - -/* Specify that the DOMAINNAME message catalog will be found - in DIRNAME rather than in the system locale data base. */ -extern char *bindtextdomain (__const char *__domainname, - __const char *__dirname) __THROW; - -/* Specify the character encoding in which the messages from the - DOMAINNAME message catalog will be returned. */ -extern char *bind_textdomain_codeset (__const char *__domainname, - __const char *__codeset) __THROW; - - -/* Optimized version of the function above. */ -#if defined __OPTIMIZE__ - -/* We need NULL for `gettext'. */ -# define __need_NULL -# include - -/* We need LC_MESSAGES for `dgettext'. */ -# include - -/* These must be macros. Inlined functions are useless because the - `__builtin_constant_p' predicate in dcgettext would always return - false. */ - -# define gettext(msgid) dgettext (NULL, msgid) - -# define dgettext(domainname, msgid) \ - dcgettext (domainname, msgid, LC_MESSAGES) - -# define ngettext(msgid1, msgid2, n) dngettext (NULL, msgid1, msgid2, n) - -# define dngettext(domainname, msgid1, msgid2, n) \ - dcngettext (domainname, msgid1, msgid2, n, LC_MESSAGES) - -#endif /* Optimizing. */ - -__END_DECLS - -#endif /* libintl.h */ diff --git a/src/system/libroot/posix/glibc/intl/loadmsgcat.c b/src/system/libroot/posix/glibc/intl/loadmsgcat.c deleted file mode 100644 index afcbd3c9fb..0000000000 --- a/src/system/libroot/posix/glibc/intl/loadmsgcat.c +++ /dev/null @@ -1,1301 +0,0 @@ -/* Load needed message catalogs. - Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Tell glibc's to provide a prototype for mempcpy(). - This must come before because may include - , and once has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -# undef alloca -# define alloca __builtin_alloca -# define HAVE_ALLOCA 1 -#else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca -char *alloca (); -# endif -# endif -# endif -#endif - -#include -#include - -#if defined HAVE_UNISTD_H || defined _LIBC -# include -#endif - -#ifdef _LIBC -# include -# include -#endif - -#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \ - || (defined _LIBC && defined _POSIX_MAPPED_FILES) -# include -# undef HAVE_MMAP -# define HAVE_MMAP 1 -#else -# undef HAVE_MMAP -#endif - -#if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC -# include -#endif -#if defined HAVE_INTTYPES_H || defined _LIBC -# include -#endif - -#include "gmo.h" -#include "gettextP.h" -#include "hash-string.h" -#include "plural-exp.h" - -#ifdef _LIBC -# include "../locale/localeinfo.h" -#endif - -/* Provide fallback values for macros that ought to be defined in . - Note that our fallback values need not be literal strings, because we don't - use them with preprocessor string concatenation. */ -#if !defined PRId8 || PRI_MACROS_BROKEN -# undef PRId8 -# define PRId8 "d" -#endif -#if !defined PRIi8 || PRI_MACROS_BROKEN -# undef PRIi8 -# define PRIi8 "i" -#endif -#if !defined PRIo8 || PRI_MACROS_BROKEN -# undef PRIo8 -# define PRIo8 "o" -#endif -#if !defined PRIu8 || PRI_MACROS_BROKEN -# undef PRIu8 -# define PRIu8 "u" -#endif -#if !defined PRIx8 || PRI_MACROS_BROKEN -# undef PRIx8 -# define PRIx8 "x" -#endif -#if !defined PRIX8 || PRI_MACROS_BROKEN -# undef PRIX8 -# define PRIX8 "X" -#endif -#if !defined PRId16 || PRI_MACROS_BROKEN -# undef PRId16 -# define PRId16 "d" -#endif -#if !defined PRIi16 || PRI_MACROS_BROKEN -# undef PRIi16 -# define PRIi16 "i" -#endif -#if !defined PRIo16 || PRI_MACROS_BROKEN -# undef PRIo16 -# define PRIo16 "o" -#endif -#if !defined PRIu16 || PRI_MACROS_BROKEN -# undef PRIu16 -# define PRIu16 "u" -#endif -#if !defined PRIx16 || PRI_MACROS_BROKEN -# undef PRIx16 -# define PRIx16 "x" -#endif -#if !defined PRIX16 || PRI_MACROS_BROKEN -# undef PRIX16 -# define PRIX16 "X" -#endif -#if !defined PRId32 || PRI_MACROS_BROKEN -# undef PRId32 -# define PRId32 "d" -#endif -#if !defined PRIi32 || PRI_MACROS_BROKEN -# undef PRIi32 -# define PRIi32 "i" -#endif -#if !defined PRIo32 || PRI_MACROS_BROKEN -# undef PRIo32 -# define PRIo32 "o" -#endif -#if !defined PRIu32 || PRI_MACROS_BROKEN -# undef PRIu32 -# define PRIu32 "u" -#endif -#if !defined PRIx32 || PRI_MACROS_BROKEN -# undef PRIx32 -# define PRIx32 "x" -#endif -#if !defined PRIX32 || PRI_MACROS_BROKEN -# undef PRIX32 -# define PRIX32 "X" -#endif -#if !defined PRId64 || PRI_MACROS_BROKEN -# undef PRId64 -# define PRId64 (sizeof (long) == 8 ? "ld" : "lld") -#endif -#if !defined PRIi64 || PRI_MACROS_BROKEN -# undef PRIi64 -# define PRIi64 (sizeof (long) == 8 ? "li" : "lli") -#endif -#if !defined PRIo64 || PRI_MACROS_BROKEN -# undef PRIo64 -# define PRIo64 (sizeof (long) == 8 ? "lo" : "llo") -#endif -#if !defined PRIu64 || PRI_MACROS_BROKEN -# undef PRIu64 -# define PRIu64 (sizeof (long) == 8 ? "lu" : "llu") -#endif -#if !defined PRIx64 || PRI_MACROS_BROKEN -# undef PRIx64 -# define PRIx64 (sizeof (long) == 8 ? "lx" : "llx") -#endif -#if !defined PRIX64 || PRI_MACROS_BROKEN -# undef PRIX64 -# define PRIX64 (sizeof (long) == 8 ? "lX" : "llX") -#endif -#if !defined PRIdLEAST8 || PRI_MACROS_BROKEN -# undef PRIdLEAST8 -# define PRIdLEAST8 "d" -#endif -#if !defined PRIiLEAST8 || PRI_MACROS_BROKEN -# undef PRIiLEAST8 -# define PRIiLEAST8 "i" -#endif -#if !defined PRIoLEAST8 || PRI_MACROS_BROKEN -# undef PRIoLEAST8 -# define PRIoLEAST8 "o" -#endif -#if !defined PRIuLEAST8 || PRI_MACROS_BROKEN -# undef PRIuLEAST8 -# define PRIuLEAST8 "u" -#endif -#if !defined PRIxLEAST8 || PRI_MACROS_BROKEN -# undef PRIxLEAST8 -# define PRIxLEAST8 "x" -#endif -#if !defined PRIXLEAST8 || PRI_MACROS_BROKEN -# undef PRIXLEAST8 -# define PRIXLEAST8 "X" -#endif -#if !defined PRIdLEAST16 || PRI_MACROS_BROKEN -# undef PRIdLEAST16 -# define PRIdLEAST16 "d" -#endif -#if !defined PRIiLEAST16 || PRI_MACROS_BROKEN -# undef PRIiLEAST16 -# define PRIiLEAST16 "i" -#endif -#if !defined PRIoLEAST16 || PRI_MACROS_BROKEN -# undef PRIoLEAST16 -# define PRIoLEAST16 "o" -#endif -#if !defined PRIuLEAST16 || PRI_MACROS_BROKEN -# undef PRIuLEAST16 -# define PRIuLEAST16 "u" -#endif -#if !defined PRIxLEAST16 || PRI_MACROS_BROKEN -# undef PRIxLEAST16 -# define PRIxLEAST16 "x" -#endif -#if !defined PRIXLEAST16 || PRI_MACROS_BROKEN -# undef PRIXLEAST16 -# define PRIXLEAST16 "X" -#endif -#if !defined PRIdLEAST32 || PRI_MACROS_BROKEN -# undef PRIdLEAST32 -# define PRIdLEAST32 "d" -#endif -#if !defined PRIiLEAST32 || PRI_MACROS_BROKEN -# undef PRIiLEAST32 -# define PRIiLEAST32 "i" -#endif -#if !defined PRIoLEAST32 || PRI_MACROS_BROKEN -# undef PRIoLEAST32 -# define PRIoLEAST32 "o" -#endif -#if !defined PRIuLEAST32 || PRI_MACROS_BROKEN -# undef PRIuLEAST32 -# define PRIuLEAST32 "u" -#endif -#if !defined PRIxLEAST32 || PRI_MACROS_BROKEN -# undef PRIxLEAST32 -# define PRIxLEAST32 "x" -#endif -#if !defined PRIXLEAST32 || PRI_MACROS_BROKEN -# undef PRIXLEAST32 -# define PRIXLEAST32 "X" -#endif -#if !defined PRIdLEAST64 || PRI_MACROS_BROKEN -# undef PRIdLEAST64 -# define PRIdLEAST64 PRId64 -#endif -#if !defined PRIiLEAST64 || PRI_MACROS_BROKEN -# undef PRIiLEAST64 -# define PRIiLEAST64 PRIi64 -#endif -#if !defined PRIoLEAST64 || PRI_MACROS_BROKEN -# undef PRIoLEAST64 -# define PRIoLEAST64 PRIo64 -#endif -#if !defined PRIuLEAST64 || PRI_MACROS_BROKEN -# undef PRIuLEAST64 -# define PRIuLEAST64 PRIu64 -#endif -#if !defined PRIxLEAST64 || PRI_MACROS_BROKEN -# undef PRIxLEAST64 -# define PRIxLEAST64 PRIx64 -#endif -#if !defined PRIXLEAST64 || PRI_MACROS_BROKEN -# undef PRIXLEAST64 -# define PRIXLEAST64 PRIX64 -#endif -#if !defined PRIdFAST8 || PRI_MACROS_BROKEN -# undef PRIdFAST8 -# define PRIdFAST8 "d" -#endif -#if !defined PRIiFAST8 || PRI_MACROS_BROKEN -# undef PRIiFAST8 -# define PRIiFAST8 "i" -#endif -#if !defined PRIoFAST8 || PRI_MACROS_BROKEN -# undef PRIoFAST8 -# define PRIoFAST8 "o" -#endif -#if !defined PRIuFAST8 || PRI_MACROS_BROKEN -# undef PRIuFAST8 -# define PRIuFAST8 "u" -#endif -#if !defined PRIxFAST8 || PRI_MACROS_BROKEN -# undef PRIxFAST8 -# define PRIxFAST8 "x" -#endif -#if !defined PRIXFAST8 || PRI_MACROS_BROKEN -# undef PRIXFAST8 -# define PRIXFAST8 "X" -#endif -#if !defined PRIdFAST16 || PRI_MACROS_BROKEN -# undef PRIdFAST16 -# define PRIdFAST16 "d" -#endif -#if !defined PRIiFAST16 || PRI_MACROS_BROKEN -# undef PRIiFAST16 -# define PRIiFAST16 "i" -#endif -#if !defined PRIoFAST16 || PRI_MACROS_BROKEN -# undef PRIoFAST16 -# define PRIoFAST16 "o" -#endif -#if !defined PRIuFAST16 || PRI_MACROS_BROKEN -# undef PRIuFAST16 -# define PRIuFAST16 "u" -#endif -#if !defined PRIxFAST16 || PRI_MACROS_BROKEN -# undef PRIxFAST16 -# define PRIxFAST16 "x" -#endif -#if !defined PRIXFAST16 || PRI_MACROS_BROKEN -# undef PRIXFAST16 -# define PRIXFAST16 "X" -#endif -#if !defined PRIdFAST32 || PRI_MACROS_BROKEN -# undef PRIdFAST32 -# define PRIdFAST32 "d" -#endif -#if !defined PRIiFAST32 || PRI_MACROS_BROKEN -# undef PRIiFAST32 -# define PRIiFAST32 "i" -#endif -#if !defined PRIoFAST32 || PRI_MACROS_BROKEN -# undef PRIoFAST32 -# define PRIoFAST32 "o" -#endif -#if !defined PRIuFAST32 || PRI_MACROS_BROKEN -# undef PRIuFAST32 -# define PRIuFAST32 "u" -#endif -#if !defined PRIxFAST32 || PRI_MACROS_BROKEN -# undef PRIxFAST32 -# define PRIxFAST32 "x" -#endif -#if !defined PRIXFAST32 || PRI_MACROS_BROKEN -# undef PRIXFAST32 -# define PRIXFAST32 "X" -#endif -#if !defined PRIdFAST64 || PRI_MACROS_BROKEN -# undef PRIdFAST64 -# define PRIdFAST64 PRId64 -#endif -#if !defined PRIiFAST64 || PRI_MACROS_BROKEN -# undef PRIiFAST64 -# define PRIiFAST64 PRIi64 -#endif -#if !defined PRIoFAST64 || PRI_MACROS_BROKEN -# undef PRIoFAST64 -# define PRIoFAST64 PRIo64 -#endif -#if !defined PRIuFAST64 || PRI_MACROS_BROKEN -# undef PRIuFAST64 -# define PRIuFAST64 PRIu64 -#endif -#if !defined PRIxFAST64 || PRI_MACROS_BROKEN -# undef PRIxFAST64 -# define PRIxFAST64 PRIx64 -#endif -#if !defined PRIXFAST64 || PRI_MACROS_BROKEN -# undef PRIXFAST64 -# define PRIXFAST64 PRIX64 -#endif -#if !defined PRIdMAX || PRI_MACROS_BROKEN -# undef PRIdMAX -# define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld") -#endif -#if !defined PRIiMAX || PRI_MACROS_BROKEN -# undef PRIiMAX -# define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli") -#endif -#if !defined PRIoMAX || PRI_MACROS_BROKEN -# undef PRIoMAX -# define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo") -#endif -#if !defined PRIuMAX || PRI_MACROS_BROKEN -# undef PRIuMAX -# define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu") -#endif -#if !defined PRIxMAX || PRI_MACROS_BROKEN -# undef PRIxMAX -# define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx") -#endif -#if !defined PRIXMAX || PRI_MACROS_BROKEN -# undef PRIXMAX -# define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX") -#endif -#if !defined PRIdPTR || PRI_MACROS_BROKEN -# undef PRIdPTR -# define PRIdPTR \ - (sizeof (void *) == sizeof (long) ? "ld" : \ - sizeof (void *) == sizeof (int) ? "d" : \ - "lld") -#endif -#if !defined PRIiPTR || PRI_MACROS_BROKEN -# undef PRIiPTR -# define PRIiPTR \ - (sizeof (void *) == sizeof (long) ? "li" : \ - sizeof (void *) == sizeof (int) ? "i" : \ - "lli") -#endif -#if !defined PRIoPTR || PRI_MACROS_BROKEN -# undef PRIoPTR -# define PRIoPTR \ - (sizeof (void *) == sizeof (long) ? "lo" : \ - sizeof (void *) == sizeof (int) ? "o" : \ - "llo") -#endif -#if !defined PRIuPTR || PRI_MACROS_BROKEN -# undef PRIuPTR -# define PRIuPTR \ - (sizeof (void *) == sizeof (long) ? "lu" : \ - sizeof (void *) == sizeof (int) ? "u" : \ - "llu") -#endif -#if !defined PRIxPTR || PRI_MACROS_BROKEN -# undef PRIxPTR -# define PRIxPTR \ - (sizeof (void *) == sizeof (long) ? "lx" : \ - sizeof (void *) == sizeof (int) ? "x" : \ - "llx") -#endif -#if !defined PRIXPTR || PRI_MACROS_BROKEN -# undef PRIXPTR -# define PRIXPTR \ - (sizeof (void *) == sizeof (long) ? "lX" : \ - sizeof (void *) == sizeof (int) ? "X" : \ - "llX") -#endif - -/* @@ end of prolog @@ */ - -#ifdef _LIBC -/* Rename the non ISO C functions. This is required by the standard - because some ISO C functions will require linking with this object - file and the name space must not be polluted. */ -# define open __open -# define close __close -# define read __read -# define mmap __mmap -# define munmap __munmap -#endif - -/* For those losing systems which don't have `alloca' we have to add - some additional code emulating it. */ -#ifdef HAVE_ALLOCA -# define freea(p) /* nothing */ -#else -# define alloca(n) malloc (n) -# define freea(p) free (p) -#endif - - -/* Prototypes for local functions. Needed to ensure compiler checking of - function argument counts despite of K&R C function definition syntax. */ -static const char *get_sysdep_segment_value PARAMS ((const char *name)); - - -/* We need a sign, whether a new catalog was loaded, which can be associated - with all translations. This is important if the translations are - cached by one of GCC's features. */ -int _nl_msg_cat_cntr; - - -/* Expand a system dependent string segment. Return NULL if unsupported. */ -static const char * -get_sysdep_segment_value (name) - const char *name; -{ - /* Test for an ISO C 99 section 7.8.1 format string directive. - Syntax: - P R I { d | i | o | u | x | X } - { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */ - /* We don't use a table of 14 times 6 'const char *' strings here, because - data relocations cost startup time. */ - if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I') - { - if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u' - || name[3] == 'x' || name[3] == 'X') - { - if (name[4] == '8' && name[5] == '\0') - { - if (name[3] == 'd') - return PRId8; - if (name[3] == 'i') - return PRIi8; - if (name[3] == 'o') - return PRIo8; - if (name[3] == 'u') - return PRIu8; - if (name[3] == 'x') - return PRIx8; - if (name[3] == 'X') - return PRIX8; - abort (); - } - if (name[4] == '1' && name[5] == '6' && name[6] == '\0') - { - if (name[3] == 'd') - return PRId16; - if (name[3] == 'i') - return PRIi16; - if (name[3] == 'o') - return PRIo16; - if (name[3] == 'u') - return PRIu16; - if (name[3] == 'x') - return PRIx16; - if (name[3] == 'X') - return PRIX16; - abort (); - } - if (name[4] == '3' && name[5] == '2' && name[6] == '\0') - { - if (name[3] == 'd') - return PRId32; - if (name[3] == 'i') - return PRIi32; - if (name[3] == 'o') - return PRIo32; - if (name[3] == 'u') - return PRIu32; - if (name[3] == 'x') - return PRIx32; - if (name[3] == 'X') - return PRIX32; - abort (); - } - if (name[4] == '6' && name[5] == '4' && name[6] == '\0') - { - if (name[3] == 'd') - return PRId64; - if (name[3] == 'i') - return PRIi64; - if (name[3] == 'o') - return PRIo64; - if (name[3] == 'u') - return PRIu64; - if (name[3] == 'x') - return PRIx64; - if (name[3] == 'X') - return PRIX64; - abort (); - } - if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A' - && name[7] == 'S' && name[8] == 'T') - { - if (name[9] == '8' && name[10] == '\0') - { - if (name[3] == 'd') - return PRIdLEAST8; - if (name[3] == 'i') - return PRIiLEAST8; - if (name[3] == 'o') - return PRIoLEAST8; - if (name[3] == 'u') - return PRIuLEAST8; - if (name[3] == 'x') - return PRIxLEAST8; - if (name[3] == 'X') - return PRIXLEAST8; - abort (); - } - if (name[9] == '1' && name[10] == '6' && name[11] == '\0') - { - if (name[3] == 'd') - return PRIdLEAST16; - if (name[3] == 'i') - return PRIiLEAST16; - if (name[3] == 'o') - return PRIoLEAST16; - if (name[3] == 'u') - return PRIuLEAST16; - if (name[3] == 'x') - return PRIxLEAST16; - if (name[3] == 'X') - return PRIXLEAST16; - abort (); - } - if (name[9] == '3' && name[10] == '2' && name[11] == '\0') - { - if (name[3] == 'd') - return PRIdLEAST32; - if (name[3] == 'i') - return PRIiLEAST32; - if (name[3] == 'o') - return PRIoLEAST32; - if (name[3] == 'u') - return PRIuLEAST32; - if (name[3] == 'x') - return PRIxLEAST32; - if (name[3] == 'X') - return PRIXLEAST32; - abort (); - } - if (name[9] == '6' && name[10] == '4' && name[11] == '\0') - { - if (name[3] == 'd') - return PRIdLEAST64; - if (name[3] == 'i') - return PRIiLEAST64; - if (name[3] == 'o') - return PRIoLEAST64; - if (name[3] == 'u') - return PRIuLEAST64; - if (name[3] == 'x') - return PRIxLEAST64; - if (name[3] == 'X') - return PRIXLEAST64; - abort (); - } - } - if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S' - && name[7] == 'T') - { - if (name[8] == '8' && name[9] == '\0') - { - if (name[3] == 'd') - return PRIdFAST8; - if (name[3] == 'i') - return PRIiFAST8; - if (name[3] == 'o') - return PRIoFAST8; - if (name[3] == 'u') - return PRIuFAST8; - if (name[3] == 'x') - return PRIxFAST8; - if (name[3] == 'X') - return PRIXFAST8; - abort (); - } - if (name[8] == '1' && name[9] == '6' && name[10] == '\0') - { - if (name[3] == 'd') - return PRIdFAST16; - if (name[3] == 'i') - return PRIiFAST16; - if (name[3] == 'o') - return PRIoFAST16; - if (name[3] == 'u') - return PRIuFAST16; - if (name[3] == 'x') - return PRIxFAST16; - if (name[3] == 'X') - return PRIXFAST16; - abort (); - } - if (name[8] == '3' && name[9] == '2' && name[10] == '\0') - { - if (name[3] == 'd') - return PRIdFAST32; - if (name[3] == 'i') - return PRIiFAST32; - if (name[3] == 'o') - return PRIoFAST32; - if (name[3] == 'u') - return PRIuFAST32; - if (name[3] == 'x') - return PRIxFAST32; - if (name[3] == 'X') - return PRIXFAST32; - abort (); - } - if (name[8] == '6' && name[9] == '4' && name[10] == '\0') - { - if (name[3] == 'd') - return PRIdFAST64; - if (name[3] == 'i') - return PRIiFAST64; - if (name[3] == 'o') - return PRIoFAST64; - if (name[3] == 'u') - return PRIuFAST64; - if (name[3] == 'x') - return PRIxFAST64; - if (name[3] == 'X') - return PRIXFAST64; - abort (); - } - } - if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X' - && name[7] == '\0') - { - if (name[3] == 'd') - return PRIdMAX; - if (name[3] == 'i') - return PRIiMAX; - if (name[3] == 'o') - return PRIoMAX; - if (name[3] == 'u') - return PRIuMAX; - if (name[3] == 'x') - return PRIxMAX; - if (name[3] == 'X') - return PRIXMAX; - abort (); - } - if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R' - && name[7] == '\0') - { - if (name[3] == 'd') - return PRIdPTR; - if (name[3] == 'i') - return PRIiPTR; - if (name[3] == 'o') - return PRIoPTR; - if (name[3] == 'u') - return PRIuPTR; - if (name[3] == 'x') - return PRIxPTR; - if (name[3] == 'X') - return PRIXPTR; - abort (); - } - } - } - /* Other system dependent strings are not valid. */ - return NULL; -} - -/* Initialize the codeset dependent parts of an opened message catalog. - Return the header entry. */ -const char * -internal_function -_nl_init_domain_conv (domain_file, domain, domainbinding) - struct loaded_l10nfile *domain_file; - struct loaded_domain *domain; - struct binding *domainbinding; -{ - /* Find out about the character set the file is encoded with. - This can be found (in textual form) in the entry "". If this - entry does not exist or if this does not contain the `charset=' - information, we will assume the charset matches the one the - current locale and we don't have to perform any conversion. */ - char *nullentry; - size_t nullentrylen; - - /* Preinitialize fields, to avoid recursion during _nl_find_msg. */ - domain->codeset_cntr = - (domainbinding != NULL ? domainbinding->codeset_cntr : 0); -#ifdef _LIBC - domain->conv = (__gconv_t) -1; -#else -# if HAVE_ICONV - domain->conv = (iconv_t) -1; -# endif -#endif - domain->conv_tab = NULL; - - /* Get the header entry. */ - nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen); - - if (nullentry != NULL) - { -#if defined _LIBC || HAVE_ICONV - const char *charsetstr; - - charsetstr = strstr (nullentry, "charset="); - if (charsetstr != NULL) - { - size_t len; - char *charset; - const char *outcharset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - - charset = (char *) alloca (len + 1); -# if defined _LIBC || HAVE_MEMPCPY - *((char *) mempcpy (charset, charsetstr, len)) = '\0'; -# else - memcpy (charset, charsetstr, len); - charset[len] = '\0'; -# endif - - /* The output charset should normally be determined by the - locale. But sometimes the locale is not used or not correctly - set up, so we provide a possibility for the user to override - this. Moreover, the value specified through - bind_textdomain_codeset overrides both. */ - if (domainbinding != NULL && domainbinding->codeset != NULL) - outcharset = domainbinding->codeset; - else - { - outcharset = getenv ("OUTPUT_CHARSET"); - if (outcharset == NULL || outcharset[0] == '\0') - { -# ifdef _LIBC - outcharset = _NL_CURRENT (LC_CTYPE, CODESET); -# else -# if HAVE_ICONV - extern const char *locale_charset PARAMS ((void)); - outcharset = locale_charset (); -# endif -# endif - } - } - -# ifdef _LIBC - /* We always want to use transliteration. */ - outcharset = norm_add_slashes (outcharset, "TRANSLIT"); - charset = norm_add_slashes (charset, NULL); - if (__gconv_open (outcharset, charset, &domain->conv, - GCONV_AVOID_NOCONV) - != __GCONV_OK) - domain->conv = (__gconv_t) -1; -# else -# if HAVE_ICONV - /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5, - we want to use transliteration. */ -# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ - || _LIBICONV_VERSION >= 0x0105 - if (strchr (outcharset, '/') == NULL) - { - char *tmp; - - len = strlen (outcharset); - tmp = (char *) alloca (len + 10 + 1); - memcpy (tmp, outcharset, len); - memcpy (tmp + len, "//TRANSLIT", 10 + 1); - outcharset = tmp; - - domain->conv = iconv_open (outcharset, charset); - - freea (outcharset); - } - else -# endif - domain->conv = iconv_open (outcharset, charset); -# endif -# endif - - freea (charset); - } -#endif /* _LIBC || HAVE_ICONV */ - } - - return nullentry; -} - -/* Frees the codeset dependent parts of an opened message catalog. */ -void -internal_function -_nl_free_domain_conv (domain) - struct loaded_domain *domain; -{ - if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1) - free (domain->conv_tab); - -#ifdef _LIBC - if (domain->conv != (__gconv_t) -1) - __gconv_close (domain->conv); -#else -# if HAVE_ICONV - if (domain->conv != (iconv_t) -1) - iconv_close (domain->conv); -# endif -#endif -} - -/* Load the message catalogs specified by FILENAME. If it is no valid - message catalog do nothing. */ -void -internal_function -_nl_load_domain (domain_file, domainbinding) - struct loaded_l10nfile *domain_file; - struct binding *domainbinding; -{ - int fd; - size_t size; -#ifdef _LIBC - struct stat64 st; -#else - struct stat st; -#endif - struct mo_file_header *data = (struct mo_file_header *) -1; - int use_mmap = 0; - struct loaded_domain *domain; - int revision; - const char *nullentry; - - domain_file->decided = 1; - domain_file->data = NULL; - - /* Note that it would be useless to store domainbinding in domain_file - because domainbinding might be == NULL now but != NULL later (after - a call to bind_textdomain_codeset). */ - - /* If the record does not represent a valid locale the FILENAME - might be NULL. This can happen when according to the given - specification the locale file name is different for XPG and CEN - syntax. */ - if (domain_file->filename == NULL) - return; - - /* Try to open the addressed file. */ - fd = open (domain_file->filename, O_RDONLY); - if (fd == -1) - return; - - /* We must know about the size of the file. */ - if ( -#ifdef _LIBC - __builtin_expect (fstat64 (fd, &st) != 0, 0) -#else - __builtin_expect (fstat (fd, &st) != 0, 0) -#endif - || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0) - || __builtin_expect (size < sizeof (struct mo_file_header), 0)) - { - /* Something went wrong. */ - close (fd); - return; - } - -#ifdef HAVE_MMAP - /* Now we are ready to load the file. If mmap() is available we try - this first. If not available or it failed we try to load it. */ - data = (struct mo_file_header *) mmap (NULL, size, PROT_READ, - MAP_PRIVATE, fd, 0); - - if (__builtin_expect (data != (struct mo_file_header *) -1, 1)) - { - /* mmap() call was successful. */ - close (fd); - use_mmap = 1; - } -#endif - - /* If the data is not yet available (i.e. mmap'ed) we try to load - it manually. */ - if (data == (struct mo_file_header *) -1) - { - size_t to_read; - char *read_ptr; - - data = (struct mo_file_header *) malloc (size); - if (data == NULL) - return; - - to_read = size; - read_ptr = (char *) data; - do - { - long int nb = (long int) read (fd, read_ptr, to_read); - if (nb <= 0) - { -#ifdef EINTR - if (nb == -1 && errno == EINTR) - continue; -#endif - close (fd); - return; - } - read_ptr += nb; - to_read -= nb; - } - while (to_read > 0); - - close (fd); - } - - /* Using the magic number we can test whether it really is a message - catalog file. */ - if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED, - 0)) - { - /* The magic number is wrong: not a message catalog file. */ -#ifdef HAVE_MMAP - if (use_mmap) - munmap ((caddr_t) data, size); - else -#endif - free (data); - return; - } - - domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain)); - if (domain == NULL) - return; - domain_file->data = domain; - - domain->data = (char *) data; - domain->use_mmap = use_mmap; - domain->mmap_size = size; - domain->must_swap = data->magic != _MAGIC; - domain->malloced = NULL; - - /* Fill in the information about the available tables. */ - revision = W (domain->must_swap, data->revision); - /* We support only the major revision 0. */ - switch (revision >> 16) - { - case 0: - domain->nstrings = W (domain->must_swap, data->nstrings); - domain->orig_tab = (const struct string_desc *) - ((char *) data + W (domain->must_swap, data->orig_tab_offset)); - domain->trans_tab = (const struct string_desc *) - ((char *) data + W (domain->must_swap, data->trans_tab_offset)); - domain->hash_size = W (domain->must_swap, data->hash_tab_size); - domain->hash_tab = - (domain->hash_size > 2 - ? (const nls_uint32 *) - ((char *) data + W (domain->must_swap, data->hash_tab_offset)) - : NULL); - domain->must_swap_hash_tab = domain->must_swap; - - /* Now dispatch on the minor revision. */ - switch (revision & 0xffff) - { - case 0: - domain->n_sysdep_strings = 0; - domain->orig_sysdep_tab = NULL; - domain->trans_sysdep_tab = NULL; - break; - case 1: - default: - { - nls_uint32 n_sysdep_strings; - - if (domain->hash_tab == NULL) - /* This is invalid. These minor revisions need a hash table. */ - goto invalid; - - n_sysdep_strings = - W (domain->must_swap, data->n_sysdep_strings); - if (n_sysdep_strings > 0) - { - nls_uint32 n_sysdep_segments; - const struct sysdep_segment *sysdep_segments; - const char **sysdep_segment_values; - const nls_uint32 *orig_sysdep_tab; - const nls_uint32 *trans_sysdep_tab; - size_t memneed; - char *mem; - struct sysdep_string_desc *inmem_orig_sysdep_tab; - struct sysdep_string_desc *inmem_trans_sysdep_tab; - nls_uint32 *inmem_hash_tab; - unsigned int i; - - /* Get the values of the system dependent segments. */ - n_sysdep_segments = - W (domain->must_swap, data->n_sysdep_segments); - sysdep_segments = (const struct sysdep_segment *) - ((char *) data - + W (domain->must_swap, data->sysdep_segments_offset)); - sysdep_segment_values = - alloca (n_sysdep_segments * sizeof (const char *)); - for (i = 0; i < n_sysdep_segments; i++) - { - const char *name = - (char *) data - + W (domain->must_swap, sysdep_segments[i].offset); - nls_uint32 namelen = - W (domain->must_swap, sysdep_segments[i].length); - - if (!(namelen > 0 && name[namelen - 1] == '\0')) - { - freea (sysdep_segment_values); - goto invalid; - } - - sysdep_segment_values[i] = get_sysdep_segment_value (name); - } - - orig_sysdep_tab = (const nls_uint32 *) - ((char *) data - + W (domain->must_swap, data->orig_sysdep_tab_offset)); - trans_sysdep_tab = (const nls_uint32 *) - ((char *) data - + W (domain->must_swap, data->trans_sysdep_tab_offset)); - - /* Compute the amount of additional memory needed for the - system dependent strings and the augmented hash table. */ - memneed = 2 * n_sysdep_strings - * sizeof (struct sysdep_string_desc) - + domain->hash_size * sizeof (nls_uint32); - for (i = 0; i < 2 * n_sysdep_strings; i++) - { - const struct sysdep_string *sysdep_string = - (const struct sysdep_string *) - ((char *) data - + W (domain->must_swap, - i < n_sysdep_strings - ? orig_sysdep_tab[i] - : trans_sysdep_tab[i - n_sysdep_strings])); - size_t need = 0; - const struct segment_pair *p = sysdep_string->segments; - - if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END) - for (p = sysdep_string->segments;; p++) - { - nls_uint32 sysdepref; - - need += W (domain->must_swap, p->segsize); - - sysdepref = W (domain->must_swap, p->sysdepref); - if (sysdepref == SEGMENTS_END) - break; - - if (sysdepref >= n_sysdep_segments) - { - /* Invalid. */ - freea (sysdep_segment_values); - goto invalid; - } - - need += strlen (sysdep_segment_values[sysdepref]); - } - - memneed += need; - } - - /* Allocate additional memory. */ - mem = (char *) malloc (memneed); - if (mem == NULL) - goto invalid; - - domain->malloced = mem; - inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem; - mem += n_sysdep_strings * sizeof (struct sysdep_string_desc); - inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem; - mem += n_sysdep_strings * sizeof (struct sysdep_string_desc); - inmem_hash_tab = (nls_uint32 *) mem; - mem += domain->hash_size * sizeof (nls_uint32); - - /* Compute the system dependent strings. */ - for (i = 0; i < 2 * n_sysdep_strings; i++) - { - const struct sysdep_string *sysdep_string = - (const struct sysdep_string *) - ((char *) data - + W (domain->must_swap, - i < n_sysdep_strings - ? orig_sysdep_tab[i] - : trans_sysdep_tab[i - n_sysdep_strings])); - const char *static_segments = - (char *) data - + W (domain->must_swap, sysdep_string->offset); - const struct segment_pair *p = sysdep_string->segments; - - /* Concatenate the segments, and fill - inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and - inmem_trans_sysdep_tab[i-n_sysdep_strings] (for - i >= n_sysdep_strings). */ - - if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END) - { - /* Only one static segment. */ - inmem_orig_sysdep_tab[i].length = - W (domain->must_swap, p->segsize); - inmem_orig_sysdep_tab[i].pointer = static_segments; - } - else - { - inmem_orig_sysdep_tab[i].pointer = mem; - - for (p = sysdep_string->segments;; p++) - { - nls_uint32 segsize = - W (domain->must_swap, p->segsize); - nls_uint32 sysdepref = - W (domain->must_swap, p->sysdepref); - size_t n; - - if (segsize > 0) - { - memcpy (mem, static_segments, segsize); - mem += segsize; - static_segments += segsize; - } - - if (sysdepref == SEGMENTS_END) - break; - - n = strlen (sysdep_segment_values[sysdepref]); - memcpy (mem, sysdep_segment_values[sysdepref], n); - mem += n; - } - - inmem_orig_sysdep_tab[i].length = - mem - inmem_orig_sysdep_tab[i].pointer; - } - } - - /* Compute the augmented hash table. */ - for (i = 0; i < domain->hash_size; i++) - inmem_hash_tab[i] = - W (domain->must_swap_hash_tab, domain->hash_tab[i]); - for (i = 0; i < n_sysdep_strings; i++) - { - const char *msgid = inmem_orig_sysdep_tab[i].pointer; - nls_uint32 hash_val = hash_string (msgid); - nls_uint32 idx = hash_val % domain->hash_size; - nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); - - for (;;) - { - if (inmem_hash_tab[idx] == 0) - { - /* Hash table entry is empty. Use it. */ - inmem_hash_tab[idx] = 1 + domain->nstrings + i; - break; - } - - if (idx >= domain->hash_size - incr) - idx -= domain->hash_size - incr; - else - idx += incr; - } - } - - freea (sysdep_segment_values); - - domain->n_sysdep_strings = n_sysdep_strings; - domain->orig_sysdep_tab = inmem_orig_sysdep_tab; - domain->trans_sysdep_tab = inmem_trans_sysdep_tab; - - domain->hash_tab = inmem_hash_tab; - domain->must_swap_hash_tab = 0; - } - else - { - domain->n_sysdep_strings = 0; - domain->orig_sysdep_tab = NULL; - domain->trans_sysdep_tab = NULL; - } - } - break; - } - break; - default: - /* This is an invalid revision. */ - invalid: - /* This is an invalid .mo file. */ - if (domain->malloced) - free (domain->malloced); -#ifdef HAVE_MMAP - if (use_mmap) - munmap ((caddr_t) data, size); - else -#endif - free (data); - free (domain); - domain_file->data = NULL; - return; - } - - /* Now initialize the character set converter from the character set - the file is encoded with (found in the header entry) to the domain's - specified character set or the locale's character set. */ - nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding); - - /* Also look for a plural specification. */ - EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals); -} - - -#ifdef _LIBC -void -internal_function -_nl_unload_domain (domain) - struct loaded_domain *domain; -{ - if (domain->plural != &__gettext_germanic_plural) - __gettext_free_exp (domain->plural); - - _nl_free_domain_conv (domain); - - if (domain->malloced) - free (domain->malloced); - -# ifdef _POSIX_MAPPED_FILES - if (domain->use_mmap) - munmap ((caddr_t) domain->data, domain->mmap_size); - else -# endif /* _POSIX_MAPPED_FILES */ - free ((void *) domain->data); - - free (domain); -} -#endif diff --git a/src/system/libroot/posix/glibc/intl/locale.alias b/src/system/libroot/posix/glibc/intl/locale.alias deleted file mode 100644 index 08c250d35d..0000000000 --- a/src/system/libroot/posix/glibc/intl/locale.alias +++ /dev/null @@ -1,75 +0,0 @@ -# Locale name alias data base. -# Copyright (C) 1996,1997,1998,1999,2000,2001 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 2, 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, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# The format of this file is the same as for the corresponding file of -# the X Window System, which normally can be found in -# /usr/lib/X11/locale/locale.alias -# A single line contains two fields: an alias and a substitution value. -# All entries are case independent. - -# Note: This file is far from being complete. If you have a value for -# your own site which you think might be useful for others too, share -# it with the rest of us. Send it using the `glibcbug' script to -# bugs@gnu.org. - -bokmal no_NO.ISO-8859-1 -bokml no_NO.ISO-8859-1 -catalan ca_ES.ISO-8859-1 -croatian hr_HR.ISO-8859-2 -czech cs_CZ.ISO-8859-2 -danish da_DK.ISO-8859-1 -dansk da_DK.ISO-8859-1 -deutsch de_DE.ISO-8859-1 -dutch nl_NL.ISO-8859-1 -eesti et_EE.ISO-8859-1 -estonian et_EE.ISO-8859-1 -finnish fi_FI.ISO-8859-1 -franais fr_FR.ISO-8859-1 -french fr_FR.ISO-8859-1 -galego gl_ES.ISO-8859-1 -galician gl_ES.ISO-8859-1 -german de_DE.ISO-8859-1 -greek el_GR.ISO-8859-7 -hebrew he_IL.ISO-8859-8 -hrvatski hr_HR.ISO-8859-2 -hungarian hu_HU.ISO-8859-2 -icelandic is_IS.ISO-8859-1 -italian it_IT.ISO-8859-1 -japanese ja_JP.eucJP -japanese.euc ja_JP.eucJP -ja_JP ja_JP.eucJP -ja_JP.ujis ja_JP.eucJP -japanese.sjis ja_JP.SJIS -korean ko_KR.eucKR -korean.euc ko_KR.eucKR -ko_KR ko_KR.eucKR -lithuanian lt_LT.ISO-8859-13 -nb_NO no_NO.ISO-8859-1 -nb_NO.ISO-8859-1 no_NO.ISO-8859-1 -norwegian no_NO.ISO-8859-1 -nynorsk nn_NO.ISO-8859-1 -polish pl_PL.ISO-8859-2 -portuguese pt_PT.ISO-8859-1 -romanian ro_RO.ISO-8859-2 -russian ru_RU.ISO-8859-5 -slovak sk_SK.ISO-8859-2 -slovene sl_SI.ISO-8859-2 -slovenian sl_SI.ISO-8859-2 -spanish es_ES.ISO-8859-1 -swedish sv_SE.ISO-8859-1 -thai th_TH.TIS-620 -turkish tr_TR.ISO-8859-9 diff --git a/src/system/libroot/posix/glibc/intl/localealias.c b/src/system/libroot/posix/glibc/intl/localealias.c deleted file mode 100644 index 697ef8c43a..0000000000 --- a/src/system/libroot/posix/glibc/intl/localealias.c +++ /dev/null @@ -1,405 +0,0 @@ -/* Handle aliases for locale names. - Copyright (C) 1995-1999, 2000,01,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Tell glibc's to provide a prototype for mempcpy(). - This must come before because may include - , and once has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#if defined _LIBC || defined HAVE___FSETLOCKING -# include -#endif -#include - -#ifdef __GNUC__ -# undef alloca -# define alloca __builtin_alloca -# define HAVE_ALLOCA 1 -#else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca -char *alloca (); -# endif -# endif -# endif -#endif - -#include -#include - -#include "gettextP.h" - -/* @@ end of prolog @@ */ - -#ifdef _LIBC -/* Rename the non ANSI C functions. This is required by the standard - because some ANSI C functions will require linking with this object - file and the name space must not be polluted. */ -# define strcasecmp __strcasecmp - -# ifndef mempcpy -# define mempcpy __mempcpy -# endif -# define HAVE_MEMPCPY 1 -# define HAVE___FSETLOCKING 1 - -/* We need locking here since we can be called from different places. */ -# include - -__libc_lock_define_initialized (static, lock); -#endif - -#ifndef internal_function -# define internal_function -#endif - -/* Some optimizations for glibc. */ -#ifdef _LIBC -# define FEOF(fp) feof_unlocked (fp) -# define FGETS(buf, n, fp) fgets_unlocked (buf, n, fp) -#else -# define FEOF(fp) feof (fp) -# define FGETS(buf, n, fp) fgets (buf, n, fp) -#endif - -/* For those losing systems which don't have `alloca' we have to add - some additional code emulating it. */ -#ifdef HAVE_ALLOCA -# define freea(p) /* nothing */ -#else -# define alloca(n) malloc (n) -# define freea(p) free (p) -#endif - -#if defined _LIBC_REENTRANT || defined HAVE_FGETS_UNLOCKED -# undef fgets -# define fgets(buf, len, s) fgets_unlocked (buf, len, s) -#endif -#if defined _LIBC_REENTRANT || defined HAVE_FEOF_UNLOCKED -# undef feof -# define feof(s) feof_unlocked (s) -#endif - - -struct alias_map -{ - const char *alias; - const char *value; -}; - - -#ifndef _LIBC -# define libc_freeres_ptr(decl) decl -#endif - -libc_freeres_ptr (static char *string_space); -static size_t string_space_act; -static size_t string_space_max; -libc_freeres_ptr (static struct alias_map *map); -static size_t nmap; -static size_t maxmap; - - -/* Prototypes for local functions. */ -static size_t read_alias_file PARAMS ((const char *fname, int fname_len)) - internal_function; -static int extend_alias_table PARAMS ((void)); -static int alias_compare PARAMS ((const struct alias_map *map1, - const struct alias_map *map2)); - - -const char * -_nl_expand_alias (name) - const char *name; -{ - static const char *locale_alias_path = LOCALE_ALIAS_PATH; - struct alias_map *retval; - const char *result = NULL; - size_t added; - -#ifdef _LIBC - __libc_lock_lock (lock); -#endif - - do - { - struct alias_map item; - - item.alias = name; - - if (nmap > 0) - retval = (struct alias_map *) bsearch (&item, map, nmap, - sizeof (struct alias_map), - (int (*) PARAMS ((const void *, - const void *)) - ) alias_compare); - else - retval = NULL; - - /* We really found an alias. Return the value. */ - if (retval != NULL) - { - result = retval->value; - break; - } - - /* Perhaps we can find another alias file. */ - added = 0; - while (added == 0 && locale_alias_path[0] != '\0') - { - const char *start; - - while (locale_alias_path[0] == ':') - ++locale_alias_path; - start = locale_alias_path; - - while (locale_alias_path[0] != '\0' && locale_alias_path[0] != ':') - ++locale_alias_path; - - if (start < locale_alias_path) - added = read_alias_file (start, locale_alias_path - start); - } - } - while (added != 0); - -#ifdef _LIBC - __libc_lock_unlock (lock); -#endif - - return result; -} - - -static size_t -internal_function -read_alias_file (fname, fname_len) - const char *fname; - int fname_len; -{ - FILE *fp; - char *full_fname; - size_t added; - static const char aliasfile[] = "/locale.alias"; - - full_fname = (char *) alloca (fname_len + sizeof aliasfile); -#ifdef HAVE_MEMPCPY - mempcpy (mempcpy (full_fname, fname, fname_len), - aliasfile, sizeof aliasfile); -#else - memcpy (full_fname, fname, fname_len); - memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); -#endif - - fp = fopen (full_fname, "r"); - freea (full_fname); - if (fp == NULL) - return 0; - -#ifdef HAVE___FSETLOCKING - /* No threads present. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); -#endif - - added = 0; - while (!FEOF (fp)) - { - /* It is a reasonable approach to use a fix buffer here because - a) we are only interested in the first two fields - b) these fields must be usable as file names and so must not - be that long - We avoid a multi-kilobyte buffer here since this would use up - stack space which we might not have if the program ran out of - memory. */ - char buf[400]; - char *alias; - char *value; - char *cp; - - if (FGETS (buf, sizeof buf, fp) == NULL) - /* EOF reached. */ - break; - - cp = buf; - /* Ignore leading white space. */ - while (isspace ((unsigned char) cp[0])) - ++cp; - - /* A leading '#' signals a comment line. */ - if (cp[0] != '\0' && cp[0] != '#') - { - alias = cp++; - while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) - ++cp; - /* Terminate alias name. */ - if (cp[0] != '\0') - *cp++ = '\0'; - - /* Now look for the beginning of the value. */ - while (isspace ((unsigned char) cp[0])) - ++cp; - - if (cp[0] != '\0') - { - size_t alias_len; - size_t value_len; - - value = cp++; - while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) - ++cp; - /* Terminate value. */ - if (cp[0] == '\n') - { - /* This has to be done to make the following test - for the end of line possible. We are looking for - the terminating '\n' which do not overwrite here. */ - *cp++ = '\0'; - *cp = '\n'; - } - else if (cp[0] != '\0') - *cp++ = '\0'; - - if (nmap >= maxmap) - if (__builtin_expect (extend_alias_table (), 0)) - return added; - - alias_len = strlen (alias) + 1; - value_len = strlen (value) + 1; - - if (string_space_act + alias_len + value_len > string_space_max) - { - /* Increase size of memory pool. */ - size_t new_size = (string_space_max - + (alias_len + value_len > 1024 - ? alias_len + value_len : 1024)); - char *new_pool = (char *) realloc (string_space, new_size); - if (new_pool == NULL) - return added; - - if (__builtin_expect (string_space != new_pool, 0)) - { - size_t i; - - for (i = 0; i < nmap; i++) - { - map[i].alias += new_pool - string_space; - map[i].value += new_pool - string_space; - } - } - - string_space = new_pool; - string_space_max = new_size; - } - - map[nmap].alias = memcpy (&string_space[string_space_act], - alias, alias_len); - string_space_act += alias_len; - - map[nmap].value = memcpy (&string_space[string_space_act], - value, value_len); - string_space_act += value_len; - - ++nmap; - ++added; - } - } - - /* Possibly not the whole line fits into the buffer. Ignore - the rest of the line. */ - while (strchr (buf, '\n') == NULL) - if (FGETS (buf, sizeof buf, fp) == NULL) - /* Make sure the inner loop will be left. The outer loop - will exit at the `feof' test. */ - break; - } - - /* Should we test for ferror()? I think we have to silently ignore - errors. --drepper */ - fclose (fp); - - if (added > 0) - qsort (map, nmap, sizeof (struct alias_map), - (int (*) PARAMS ((const void *, const void *))) alias_compare); - - return added; -} - - -static int -extend_alias_table () -{ - size_t new_size; - struct alias_map *new_map; - - new_size = maxmap == 0 ? 100 : 2 * maxmap; - new_map = (struct alias_map *) realloc (map, (new_size - * sizeof (struct alias_map))); - if (new_map == NULL) - /* Simply don't extend: we don't have any more core. */ - return -1; - - map = new_map; - maxmap = new_size; - return 0; -} - - -static int -alias_compare (map1, map2) - const struct alias_map *map1; - const struct alias_map *map2; -{ -#if defined _LIBC || defined HAVE_STRCASECMP - return strcasecmp (map1->alias, map2->alias); -#else - const unsigned char *p1 = (const unsigned char *) map1->alias; - const unsigned char *p2 = (const unsigned char *) map2->alias; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - /* I know this seems to be odd but the tolower() function in - some systems libc cannot handle nonalpha characters. */ - c1 = isupper (*p1) ? tolower (*p1) : *p1; - c2 = isupper (*p2) ? tolower (*p2) : *p2; - if (c1 == '\0') - break; - ++p1; - ++p2; - } - while (c1 == c2); - - return c1 - c2; -#endif -} diff --git a/src/system/libroot/posix/glibc/intl/ngettext.c b/src/system/libroot/posix/glibc/intl/ngettext.c deleted file mode 100644 index 7118eae324..0000000000 --- a/src/system/libroot/posix/glibc/intl/ngettext.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Implementation of ngettext(3) function. - Copyright (C) 1995, 1997, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef _LIBC -# define __need_NULL -# include -#else -# include /* Just for NULL. */ -#endif - -#include "gettextP.h" -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif - -#include - -/* @@ end of prolog @@ */ - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define NGETTEXT __ngettext -# define DCNGETTEXT __dcngettext -#else -# define NGETTEXT libintl_ngettext -# define DCNGETTEXT libintl_dcngettext -#endif - -/* Look up MSGID in the current default message catalog for the current - LC_MESSAGES locale. If not found, returns MSGID itself (the default - text). */ -char * -NGETTEXT (msgid1, msgid2, n) - const char *msgid1; - const char *msgid2; - unsigned long int n; -{ - return DCNGETTEXT (NULL, msgid1, msgid2, n, LC_MESSAGES); -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__ngettext, ngettext); -#endif diff --git a/src/system/libroot/posix/glibc/intl/plural-eval.c b/src/system/libroot/posix/glibc/intl/plural-eval.c deleted file mode 100644 index ed29e201b2..0000000000 --- a/src/system/libroot/posix/glibc/intl/plural-eval.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Plural expression evaluation. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -static unsigned long int plural_eval (struct expression *pexp, - unsigned long int n) - internal_function; - -static unsigned long int -internal_function -plural_eval (pexp, n) - struct expression *pexp; - unsigned long int n; -{ - switch (pexp->nargs) - { - case 0: - switch (pexp->operation) - { - case var: - return n; - case num: - return pexp->val.num; - default: - break; - } - /* NOTREACHED */ - break; - case 1: - { - /* pexp->operation must be lnot. */ - unsigned long int arg = plural_eval (pexp->val.args[0], n); - return ! arg; - } - case 2: - { - unsigned long int leftarg = plural_eval (pexp->val.args[0], n); - if (pexp->operation == lor) - return leftarg || plural_eval (pexp->val.args[1], n); - else if (pexp->operation == land) - return leftarg && plural_eval (pexp->val.args[1], n); - else - { - unsigned long int rightarg = plural_eval (pexp->val.args[1], n); - - switch (pexp->operation) - { - case mult: - return leftarg * rightarg; - case divide: - return leftarg / rightarg; - case module: - return leftarg % rightarg; - case plus: - return leftarg + rightarg; - case minus: - return leftarg - rightarg; - case less_than: - return leftarg < rightarg; - case greater_than: - return leftarg > rightarg; - case less_or_equal: - return leftarg <= rightarg; - case greater_or_equal: - return leftarg >= rightarg; - case equal: - return leftarg == rightarg; - case not_equal: - return leftarg != rightarg; - default: - break; - } - } - /* NOTREACHED */ - break; - } - case 3: - { - /* pexp->operation must be qmop. */ - unsigned long int boolarg = plural_eval (pexp->val.args[0], n); - return plural_eval (pexp->val.args[boolarg ? 1 : 2], n); - } - } - /* NOTREACHED */ - return 0; -} diff --git a/src/system/libroot/posix/glibc/intl/plural-exp.c b/src/system/libroot/posix/glibc/intl/plural-exp.c deleted file mode 100644 index ba5d455cd5..0000000000 --- a/src/system/libroot/posix/glibc/intl/plural-exp.c +++ /dev/null @@ -1,157 +0,0 @@ -/* Expression parsing for plural form selection. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - Written by Ulrich Drepper , 2000. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include "plural-exp.h" - -#if (defined __GNUC__ && !defined __APPLE_CC__) \ - || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) - -/* These structs are the constant expression for the germanic plural - form determination. It represents the expression "n != 1". */ -static const struct expression plvar = -{ - .nargs = 0, - .operation = var, -}; -static const struct expression plone = -{ - .nargs = 0, - .operation = num, - .val = - { - .num = 1 - } -}; -struct expression GERMANIC_PLURAL = -{ - .nargs = 2, - .operation = not_equal, - .val = - { - .args = - { - [0] = (struct expression *) &plvar, - [1] = (struct expression *) &plone - } - } -}; - -# define INIT_GERMANIC_PLURAL() - -#else - -/* For compilers without support for ISO C 99 struct/union initializers: - Initialization at run-time. */ - -static struct expression plvar; -static struct expression plone; -struct expression GERMANIC_PLURAL; - -static void -init_germanic_plural () -{ - if (plone.val.num == 0) - { - plvar.nargs = 0; - plvar.operation = var; - - plone.nargs = 0; - plone.operation = num; - plone.val.num = 1; - - GERMANIC_PLURAL.nargs = 2; - GERMANIC_PLURAL.operation = not_equal; - GERMANIC_PLURAL.val.args[0] = &plvar; - GERMANIC_PLURAL.val.args[1] = &plone; - } -} - -# define INIT_GERMANIC_PLURAL() init_germanic_plural () - -#endif - -void -internal_function -EXTRACT_PLURAL_EXPRESSION (nullentry, pluralp, npluralsp) - const char *nullentry; - struct expression **pluralp; - unsigned long int *npluralsp; -{ - if (nullentry != NULL) - { - const char *plural; - const char *nplurals; - - plural = strstr (nullentry, "plural="); - nplurals = strstr (nullentry, "nplurals="); - if (plural == NULL || nplurals == NULL) - goto no_plural; - else - { - char *endp; - unsigned long int n; - struct parse_args args; - - /* First get the number. */ - nplurals += 9; - while (*nplurals != '\0' && isspace ((unsigned char) *nplurals)) - ++nplurals; - if (!(*nplurals >= '0' && *nplurals <= '9')) - goto no_plural; -#if defined HAVE_STRTOUL || defined _LIBC - n = strtoul (nplurals, &endp, 10); -#else - for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++) - n = n * 10 + (*endp - '0'); -#endif - if (nplurals == endp) - goto no_plural; - *npluralsp = n; - - /* Due to the restrictions bison imposes onto the interface of the - scanner function we have to put the input string and the result - passed up from the parser into the same structure which address - is passed down to the parser. */ - plural += 7; - args.cp = plural; - if (PLURAL_PARSE (&args) != 0) - goto no_plural; - *pluralp = args.res; - } - } - else - { - /* By default we are using the Germanic form: singular form only - for `one', the plural form otherwise. Yes, this is also what - English is using since English is a Germanic language. */ - no_plural: - INIT_GERMANIC_PLURAL (); - *pluralp = &GERMANIC_PLURAL; - *npluralsp = 2; - } -} diff --git a/src/system/libroot/posix/glibc/intl/plural-exp.h b/src/system/libroot/posix/glibc/intl/plural-exp.h deleted file mode 100644 index 75c702f79c..0000000000 --- a/src/system/libroot/posix/glibc/intl/plural-exp.h +++ /dev/null @@ -1,127 +0,0 @@ -/* Expression parsing and evaluation for plural form selection. - Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. - Written by Ulrich Drepper , 2000. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _PLURAL_EXP_H -#define _PLURAL_EXP_H - -#ifndef PARAMS -# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES -# define PARAMS(args) args -# else -# define PARAMS(args) () -# endif -#endif - -#ifndef internal_function -# define internal_function -#endif - -#ifndef attribute_hidden -# define attribute_hidden -#endif - - -/* This is the representation of the expressions to determine the - plural form. */ -struct expression -{ - int nargs; /* Number of arguments. */ - enum operator - { - /* Without arguments: */ - var, /* The variable "n". */ - num, /* Decimal number. */ - /* Unary operators: */ - lnot, /* Logical NOT. */ - /* Binary operators: */ - mult, /* Multiplication. */ - divide, /* Division. */ - module, /* Modulo operation. */ - plus, /* Addition. */ - minus, /* Subtraction. */ - less_than, /* Comparison. */ - greater_than, /* Comparison. */ - less_or_equal, /* Comparison. */ - greater_or_equal, /* Comparison. */ - equal, /* Comparison for equality. */ - not_equal, /* Comparison for inequality. */ - land, /* Logical AND. */ - lor, /* Logical OR. */ - /* Ternary operators: */ - qmop /* Question mark operator. */ - } operation; - union - { - unsigned long int num; /* Number value for `num'. */ - struct expression *args[3]; /* Up to three arguments. */ - } val; -}; - -/* This is the data structure to pass information to the parser and get - the result in a thread-safe way. */ -struct parse_args -{ - const char *cp; - struct expression *res; -}; - - -/* Names for the libintl functions are a problem. This source code is used - 1. in the GNU C Library library, - 2. in the GNU libintl library, - 3. in the GNU gettext tools. - The function names in each situation must be different, to allow for - binary incompatible changes in 'struct expression'. Furthermore, - 1. in the GNU C Library library, the names have a __ prefix, - 2.+3. in the GNU libintl library and in the GNU gettext tools, the names - must follow ANSI C and not start with __. - So we have to distinguish the three cases. */ -#ifdef _LIBC -# define FREE_EXPRESSION __gettext_free_exp -# define PLURAL_PARSE __gettextparse -# define GERMANIC_PLURAL __gettext_germanic_plural -# define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural -#elif defined (IN_LIBINTL) -# define FREE_EXPRESSION libintl_gettext_free_exp -# define PLURAL_PARSE libintl_gettextparse -# define GERMANIC_PLURAL libintl_gettext_germanic_plural -# define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural -#else -# define FREE_EXPRESSION free_plural_expression -# define PLURAL_PARSE parse_plural_expression -# define GERMANIC_PLURAL germanic_plural -# define EXTRACT_PLURAL_EXPRESSION extract_plural_expression -#endif - -extern void FREE_EXPRESSION PARAMS ((struct expression *exp)) - internal_function; -extern int PLURAL_PARSE PARAMS ((void *arg)); -extern struct expression GERMANIC_PLURAL attribute_hidden; -extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry, - struct expression **pluralp, - unsigned long int *npluralsp)) - internal_function; - -#if !defined (_LIBC) && !defined (IN_LIBINTL) -extern unsigned long int plural_eval PARAMS ((struct expression *pexp, - unsigned long int n)); -#endif - -#endif /* _PLURAL_EXP_H */ diff --git a/src/system/libroot/posix/glibc/intl/plural.c b/src/system/libroot/posix/glibc/intl/plural.c deleted file mode 100644 index 8425fc3e01..0000000000 --- a/src/system/libroot/posix/glibc/intl/plural.c +++ /dev/null @@ -1,1518 +0,0 @@ -/* A Bison parser, made from plural.y - by GNU bison 1.35. */ - -#define YYBISON 1 /* Identify Bison output. */ - -#define yyparse __gettextparse -#define yylex __gettextlex -#define yyerror __gettexterror -#define yylval __gettextlval -#define yychar __gettextchar -#define yydebug __gettextdebug -#define yynerrs __gettextnerrs -# define EQUOP2 257 -# define CMPOP2 258 -# define ADDOP2 259 -# define MULOP2 260 -# define NUMBER 261 - -#line 1 "plural.y" - -/* Expression parsing for plural form selection. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* The bison generated parser uses alloca. AIX 3 forces us to put this - declaration at the beginning of the file. The declaration in bison's - skeleton file comes too late. This must come before - because may include arbitrary system headers. */ -#if defined _AIX && !defined __GNUC__ - #pragma alloca -#endif -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "plural-exp.h" - -/* The main function generated by the parser is called __gettextparse, - but we want it to be called PLURAL_PARSE. */ -#ifndef _LIBC -# define __gettextparse PLURAL_PARSE -#endif - -#define YYLEX_PARAM &((struct parse_args *) arg)->cp -#define YYPARSE_PARAM arg - -#line 49 "plural.y" -#ifndef YYSTYPE -typedef union { - unsigned long int num; - enum operator op; - struct expression *exp; -} yystype; -# define YYSTYPE yystype -# define YYSTYPE_IS_TRIVIAL 1 -#endif -#line 55 "plural.y" - -/* Prototypes for local functions. */ -static struct expression *new_exp PARAMS ((int nargs, enum operator op, - struct expression * const *args)); -static inline struct expression *new_exp_0 PARAMS ((enum operator op)); -static inline struct expression *new_exp_1 PARAMS ((enum operator op, - struct expression *right)); -static struct expression *new_exp_2 PARAMS ((enum operator op, - struct expression *left, - struct expression *right)); -static inline struct expression *new_exp_3 PARAMS ((enum operator op, - struct expression *bexp, - struct expression *tbranch, - struct expression *fbranch)); -static int yylex PARAMS ((YYSTYPE *lval, const char **pexp)); -static void yyerror PARAMS ((const char *str)); - -/* Allocation of expressions. */ - -static struct expression * -new_exp (nargs, op, args) - int nargs; - enum operator op; - struct expression * const *args; -{ - int i; - struct expression *newp; - - /* If any of the argument could not be malloc'ed, just return NULL. */ - for (i = nargs - 1; i >= 0; i--) - if (args[i] == NULL) - goto fail; - - /* Allocate a new expression. */ - newp = (struct expression *) malloc (sizeof (*newp)); - if (newp != NULL) - { - newp->nargs = nargs; - newp->operation = op; - for (i = nargs - 1; i >= 0; i--) - newp->val.args[i] = args[i]; - return newp; - } - - fail: - for (i = nargs - 1; i >= 0; i--) - FREE_EXPRESSION (args[i]); - - return NULL; -} - -static inline struct expression * -new_exp_0 (op) - enum operator op; -{ - return new_exp (0, op, NULL); -} - -static inline struct expression * -new_exp_1 (op, right) - enum operator op; - struct expression *right; -{ - struct expression *args[1]; - - args[0] = right; - return new_exp (1, op, args); -} - -static struct expression * -new_exp_2 (op, left, right) - enum operator op; - struct expression *left; - struct expression *right; -{ - struct expression *args[2]; - - args[0] = left; - args[1] = right; - return new_exp (2, op, args); -} - -static inline struct expression * -new_exp_3 (op, bexp, tbranch, fbranch) - enum operator op; - struct expression *bexp; - struct expression *tbranch; - struct expression *fbranch; -{ - struct expression *args[3]; - - args[0] = bexp; - args[1] = tbranch; - args[2] = fbranch; - return new_exp (3, op, args); -} - -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - - - -#define YYFINAL 27 -#define YYFLAG -32768 -#define YYNTBASE 16 - -/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ -#define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 18) - -/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ -static const char yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 10, 2, 2, 2, 2, 5, 2, - 14, 15, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 12, 2, - 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 6, 7, 8, - 9, 11 -}; - -#if YYDEBUG -static const short yyprhs[] = -{ - 0, 0, 2, 8, 12, 16, 20, 24, 28, 32, - 35, 37, 39 -}; -static const short yyrhs[] = -{ - 17, 0, 17, 3, 17, 12, 17, 0, 17, 4, - 17, 0, 17, 5, 17, 0, 17, 6, 17, 0, - 17, 7, 17, 0, 17, 8, 17, 0, 17, 9, - 17, 0, 10, 17, 0, 13, 0, 11, 0, 14, - 17, 15, 0 -}; - -#endif - -#if YYDEBUG -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const short yyrline[] = -{ - 0, 174, 182, 186, 190, 194, 198, 202, 206, 210, - 214, 218, 223 -}; -#endif - - -#if (YYDEBUG) || defined YYERROR_VERBOSE - -/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */ -static const char *const yytname[] = -{ - "$", "error", "$undefined.", "'?'", "'|'", "'&'", "EQUOP2", "CMPOP2", - "ADDOP2", "MULOP2", "'!'", "NUMBER", "':'", "'n'", "'('", "')'", - "start", "exp", 0 -}; -#endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const short yyr1[] = -{ - 0, 16, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const short yyr2[] = -{ - 0, 1, 5, 3, 3, 3, 3, 3, 3, 2, - 1, 1, 3 -}; - -/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE - doesn't specify something else to do. Zero means the default is an - error. */ -static const short yydefact[] = -{ - 0, 0, 11, 10, 0, 1, 9, 0, 0, 0, - 0, 0, 0, 0, 0, 12, 0, 3, 4, 5, - 6, 7, 8, 0, 2, 0, 0, 0 -}; - -static const short yydefgoto[] = -{ - 25, 5 -}; - -static const short yypact[] = -{ - -9, -9,-32768,-32768, -9, 34,-32768, 11, -9, -9, - -9, -9, -9, -9, -9,-32768, 24, 39, 43, 16, - 26, -3,-32768, -9, 34, 21, 53,-32768 -}; - -static const short yypgoto[] = -{ - -32768, -1 -}; - - -#define YYLAST 53 - - -static const short yytable[] = -{ - 6, 1, 2, 7, 3, 4, 14, 16, 17, 18, - 19, 20, 21, 22, 8, 9, 10, 11, 12, 13, - 14, 26, 24, 12, 13, 14, 15, 8, 9, 10, - 11, 12, 13, 14, 13, 14, 23, 8, 9, 10, - 11, 12, 13, 14, 10, 11, 12, 13, 14, 11, - 12, 13, 14, 27 -}; - -static const short yycheck[] = -{ - 1, 10, 11, 4, 13, 14, 9, 8, 9, 10, - 11, 12, 13, 14, 3, 4, 5, 6, 7, 8, - 9, 0, 23, 7, 8, 9, 15, 3, 4, 5, - 6, 7, 8, 9, 8, 9, 12, 3, 4, 5, - 6, 7, 8, 9, 5, 6, 7, 8, 9, 6, - 7, 8, 9, 0 -}; -#define YYPURE 1 - -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line 3 "/castro/street/H-alpha-linux/share/bison/bison.simple" - -/* Skeleton output parser for bison, - - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 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 2, 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, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* This is the parser code that is written into each bison parser when - the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -#if ! defined (yyoverflow) || defined (YYERROR_VERBOSE) - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca -# else -# ifndef YYSTACK_USE_ALLOCA -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca -# else -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# else -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -# define YYSTACK_ALLOC malloc -# define YYSTACK_FREE free -# endif -#endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */ - - -#if (! defined (yyoverflow) \ - && (! defined (__cplusplus) \ - || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - short yyss; - YYSTYPE yyvs; -# if YYLSP_NEEDED - YYLTYPE yyls; -# endif -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# if YYLSP_NEEDED -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ - + 2 * YYSTACK_GAP_MAX) -# else -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAX) -# endif - -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - register YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (0) -# endif -# endif - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) - -#endif - - -#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) -# define YYSIZE_T __SIZE_TYPE__ -#endif -#if ! defined (YYSIZE_T) && defined (size_t) -# define YYSIZE_T size_t -#endif -#if ! defined (YYSIZE_T) -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -#endif -#if ! defined (YYSIZE_T) -# define YYSIZE_T unsigned int -#endif - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 -#define YYEOF 0 -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ -#define YYFAIL goto yyerrlab -#define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yychar1 = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror ("syntax error: cannot back up"); \ - YYERROR; \ - } \ -while (0) - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). - - When YYLLOC_DEFAULT is run, CURRENT is set the location of the - first token. By default, to implement support for ranges, extend - its range to the last symbol. */ - -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; -#endif - - -/* YYLEX -- calling `yylex' with the right arguments. */ - -#if YYPURE -# if YYLSP_NEEDED -# ifdef YYLEX_PARAM -# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) -# else -# define YYLEX yylex (&yylval, &yylloc) -# endif -# else /* !YYLSP_NEEDED */ -# ifdef YYLEX_PARAM -# define YYLEX yylex (&yylval, YYLEX_PARAM) -# else -# define YYLEX yylex (&yylval) -# endif -# endif /* !YYLSP_NEEDED */ -#else /* !YYPURE */ -# define YYLEX yylex () -#endif /* !YYPURE */ - - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -#endif /* !YYDEBUG */ - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#if YYMAXDEPTH == 0 -# undef YYMAXDEPTH -#endif - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - -#ifdef YYERROR_VERBOSE - -# ifndef yystrlen -# if defined (__GLIBC__) && defined (_STRING_H) -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -# if defined (__STDC__) || defined (__cplusplus) -yystrlen (const char *yystr) -# else -yystrlen (yystr) - const char *yystr; -# endif -{ - register const char *yys = yystr; - - while (*yys++ != '\0') - continue; - - return yys - yystr - 1; -} -# endif -# endif - -# ifndef yystpcpy -# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -# if defined (__STDC__) || defined (__cplusplus) -yystpcpy (char *yydest, const char *yysrc) -# else -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -# endif -{ - register char *yyd = yydest; - register const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif -#endif - -#line 315 "/castro/street/H-alpha-linux/share/bison/bison.simple" - - -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ - -#ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM -# define YYPARSE_PARAM_DECL -# else -# define YYPARSE_PARAM_ARG YYPARSE_PARAM -# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; -# endif -#else /* !YYPARSE_PARAM */ -# define YYPARSE_PARAM_ARG -# define YYPARSE_PARAM_DECL -#endif /* !YYPARSE_PARAM */ - -/* Prevent warning if -Wstrict-prototypes. */ -#ifdef __GNUC__ -# ifdef YYPARSE_PARAM -int yyparse (void *); -# else -int yyparse (void); -# endif -#endif - -/* YY_DECL_VARIABLES -- depending whether we use a pure parser, - variables are global, or local to YYPARSE. */ - -#define YY_DECL_NON_LSP_VARIABLES \ -/* The lookahead symbol. */ \ -int yychar; \ - \ -/* The semantic value of the lookahead symbol. */ \ -YYSTYPE yylval; \ - \ -/* Number of parse errors so far. */ \ -int yynerrs; - -#if YYLSP_NEEDED -# define YY_DECL_VARIABLES \ -YY_DECL_NON_LSP_VARIABLES \ - \ -/* Location data for the lookahead symbol. */ \ -YYLTYPE yylloc; -#else -# define YY_DECL_VARIABLES \ -YY_DECL_NON_LSP_VARIABLES -#endif - - -/* If nonreentrant, generate the variables here. */ - -#if !YYPURE -YY_DECL_VARIABLES -#endif /* !YYPURE */ - -int -yyparse (YYPARSE_PARAM_ARG) - YYPARSE_PARAM_DECL -{ - /* If reentrant, generate the variables here. */ -#if YYPURE - YY_DECL_VARIABLES -#endif /* !YYPURE */ - - register int yystate; - register int yyn; - int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ - int yychar1 = 0; - - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - short yyssa[YYINITDEPTH]; - short *yyss = yyssa; - register short *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - register YYSTYPE *yyvsp; - -#if YYLSP_NEEDED - /* The location stack. */ - YYLTYPE yylsa[YYINITDEPTH]; - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; -#endif - -#if YYLSP_NEEDED -# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) -#else -# define YYPOPSTACK (yyvsp--, yyssp--) -#endif - - YYSIZE_T yystacksize = YYINITDEPTH; - - - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; -#if YYLSP_NEEDED - YYLTYPE yyloc; -#endif - - /* When reducing, the number of symbols on the RHS of the reduced - rule. */ - int yylen; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; -#if YYLSP_NEEDED - yylsp = yyls; -#endif - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. - */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyssp >= yyss + yystacksize - 1) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. */ -# if YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow ("parser stack overflow", - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yyls1, yysize * sizeof (*yylsp), - &yystacksize); - yyls = yyls1; -# else - yyoverflow ("parser stack overflow", - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); -# endif - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyoverflowlab; -# else - /* Extend the stack our own way. */ - if (yystacksize >= YYMAXDEPTH) - goto yyoverflowlab; - yystacksize *= 2; - if (yystacksize > YYMAXDEPTH) - yystacksize = YYMAXDEPTH; - - { - short *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyoverflowlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); -# if YYLSP_NEEDED - YYSTACK_RELOCATE (yyls); -# endif -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; -#if YYLSP_NEEDED - yylsp = yyls + yysize - 1; -#endif - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyssp >= yyss + yystacksize - 1) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - goto yybackup; - - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - -/* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ -/* yyresume: */ - - /* First try to decide what to do without reference to lookahead token. */ - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* yychar is either YYEMPTY or YYEOF - or a valid token in external form. */ - - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; - } - - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ - { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yychar1 = YYTRANSLATE (yychar); - -#if YYDEBUG - /* We have to keep this `#if YYDEBUG', since we use variables - which are defined only if `YYDEBUG' is set. */ - if (yydebug) - { - YYFPRINTF (stderr, "Next token is %d (%s", - yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise - meaning of a token, for further debugging info. */ -# ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -# endif - YYFPRINTF (stderr, ")\n"); - } -#endif - } - - yyn += yychar1; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) - goto yydefault; - - yyn = yytable[yyn]; - - /* yyn is what to do for this token type in this state. - Negative => reduce, -yyn is rule number. - Positive => shift, yyn is new state. - New state is final state => don't bother to shift, - just return success. - 0, or most negative number => error. */ - - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrlab; - - if (yyn == YYFINAL) - YYACCEPT; - - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %d (%s), ", - yychar, yytname[yychar1])); - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; -#if YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - yystate = yyn; - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to the semantic value of - the lookahead token. This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - -#if YYLSP_NEEDED - /* Similarly for the default location. Let the user run additional - commands if for instance locations are ranges. */ - yyloc = yylsp[1-yylen]; - YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); -#endif - -#if YYDEBUG - /* We have to keep this `#if YYDEBUG', since we use variables which - are defined only if `YYDEBUG' is set. */ - if (yydebug) - { - int yyi; - - YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); - - /* Print the symbols being reduced, and their result. */ - for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++) - YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); - YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); - } -#endif - - switch (yyn) { - -case 1: -#line 175 "plural.y" -{ - if (yyvsp[0].exp == NULL) - YYABORT; - ((struct parse_args *) arg)->res = yyvsp[0].exp; - } - break; -case 2: -#line 183 "plural.y" -{ - yyval.exp = new_exp_3 (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 3: -#line 187 "plural.y" -{ - yyval.exp = new_exp_2 (lor, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 4: -#line 191 "plural.y" -{ - yyval.exp = new_exp_2 (land, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 5: -#line 195 "plural.y" -{ - yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 6: -#line 199 "plural.y" -{ - yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 7: -#line 203 "plural.y" -{ - yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 8: -#line 207 "plural.y" -{ - yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); - } - break; -case 9: -#line 211 "plural.y" -{ - yyval.exp = new_exp_1 (lnot, yyvsp[0].exp); - } - break; -case 10: -#line 215 "plural.y" -{ - yyval.exp = new_exp_0 (var); - } - break; -case 11: -#line 219 "plural.y" -{ - if ((yyval.exp = new_exp_0 (num)) != NULL) - yyval.exp->val.num = yyvsp[0].num; - } - break; -case 12: -#line 224 "plural.y" -{ - yyval.exp = yyvsp[-1].exp; - } - break; -} - -#line 705 "/castro/street/H-alpha-linux/share/bison/bison.simple" - - - yyvsp -= yylen; - yyssp -= yylen; -#if YYLSP_NEEDED - yylsp -= yylen; -#endif - -#if YYDEBUG - if (yydebug) - { - short *yyssp1 = yyss - 1; - YYFPRINTF (stderr, "state stack now"); - while (yyssp1 != yyssp) - YYFPRINTF (stderr, " %d", *++yyssp1); - YYFPRINTF (stderr, "\n"); - } -#endif - - *++yyvsp = yyval; -#if YYLSP_NEEDED - *++yylsp = yyloc; -#endif - - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTBASE] + *yyssp; - if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTBASE]; - - goto yynewstate; - - -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ -yyerrlab: - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; - -#ifdef YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (yyn > YYFLAG && yyn < YYLAST) - { - YYSIZE_T yysize = 0; - char *yymsg; - int yyx, yycount; - - yycount = 0; - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) - if (yycheck[yyx + yyn] == yyx) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("parse error, unexpected ") + 1; - yysize += yystrlen (yytname[YYTRANSLATE (yychar)]); - yymsg = (char *) YYSTACK_ALLOC (yysize); - if (yymsg != 0) - { - char *yyp = yystpcpy (yymsg, "parse error, unexpected "); - yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]); - - if (yycount < 5) - { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) - if (yycheck[yyx + yyn] == yyx) - { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); - yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; - } - } - yyerror (yymsg); - YYSTACK_FREE (yymsg); - } - else - yyerror ("parse error; also virtual memory exhausted"); - } - else -#endif /* defined (YYERROR_VERBOSE) */ - yyerror ("parse error"); - } - goto yyerrlab1; - - -/*--------------------------------------------------. -| yyerrlab1 -- error raised explicitly by an action | -`--------------------------------------------------*/ -yyerrlab1: - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - /* return failure if at end of input */ - if (yychar == YYEOF) - YYABORT; - YYDPRINTF ((stderr, "Discarding token %d (%s).\n", - yychar, yytname[yychar1])); - yychar = YYEMPTY; - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - - yyerrstatus = 3; /* Each real token shifted decrements this */ - - goto yyerrhandle; - - -/*-------------------------------------------------------------------. -| yyerrdefault -- current state does not do anything special for the | -| error token. | -`-------------------------------------------------------------------*/ -yyerrdefault: -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ - - /* If its default is to accept any token, ok. Otherwise pop it. */ - yyn = yydefact[yystate]; - if (yyn) - goto yydefault; -#endif - - -/*---------------------------------------------------------------. -| yyerrpop -- pop the current state because it cannot handle the | -| error token | -`---------------------------------------------------------------*/ -yyerrpop: - if (yyssp == yyss) - YYABORT; - yyvsp--; - yystate = *--yyssp; -#if YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG - if (yydebug) - { - short *yyssp1 = yyss - 1; - YYFPRINTF (stderr, "Error: state stack now"); - while (yyssp1 != yyssp) - YYFPRINTF (stderr, " %d", *++yyssp1); - YYFPRINTF (stderr, "\n"); - } -#endif - -/*--------------. -| yyerrhandle. | -`--------------*/ -yyerrhandle: - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrpop; - - if (yyn == YYFINAL) - YYACCEPT; - - YYDPRINTF ((stderr, "Shifting error token, ")); - - *++yyvsp = yylval; -#if YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -/*---------------------------------------------. -| yyoverflowab -- parser overflow comes here. | -`---------------------------------------------*/ -yyoverflowlab: - yyerror ("parser stack overflow"); - yyresult = 2; - /* Fall through. */ - -yyreturn: -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif - return yyresult; -} -#line 229 "plural.y" - - -void -internal_function -FREE_EXPRESSION (exp) - struct expression *exp; -{ - if (exp == NULL) - return; - - /* Handle the recursive case. */ - switch (exp->nargs) - { - case 3: - FREE_EXPRESSION (exp->val.args[2]); - /* FALLTHROUGH */ - case 2: - FREE_EXPRESSION (exp->val.args[1]); - /* FALLTHROUGH */ - case 1: - FREE_EXPRESSION (exp->val.args[0]); - /* FALLTHROUGH */ - default: - break; - } - - free (exp); -} - - -static int -yylex (lval, pexp) - YYSTYPE *lval; - const char **pexp; -{ - const char *exp = *pexp; - int result; - - while (1) - { - if (exp[0] == '\0') - { - *pexp = exp; - return YYEOF; - } - - if (exp[0] != ' ' && exp[0] != '\t') - break; - - ++exp; - } - - result = *exp++; - switch (result) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - unsigned long int n = result - '0'; - while (exp[0] >= '0' && exp[0] <= '9') - { - n *= 10; - n += exp[0] - '0'; - ++exp; - } - lval->num = n; - result = NUMBER; - } - break; - - case '=': - if (exp[0] == '=') - { - ++exp; - lval->op = equal; - result = EQUOP2; - } - else - result = YYERRCODE; - break; - - case '!': - if (exp[0] == '=') - { - ++exp; - lval->op = not_equal; - result = EQUOP2; - } - break; - - case '&': - case '|': - if (exp[0] == result) - ++exp; - else - result = YYERRCODE; - break; - - case '<': - if (exp[0] == '=') - { - ++exp; - lval->op = less_or_equal; - } - else - lval->op = less_than; - result = CMPOP2; - break; - - case '>': - if (exp[0] == '=') - { - ++exp; - lval->op = greater_or_equal; - } - else - lval->op = greater_than; - result = CMPOP2; - break; - - case '*': - lval->op = mult; - result = MULOP2; - break; - - case '/': - lval->op = divide; - result = MULOP2; - break; - - case '%': - lval->op = module; - result = MULOP2; - break; - - case '+': - lval->op = plus; - result = ADDOP2; - break; - - case '-': - lval->op = minus; - result = ADDOP2; - break; - - case 'n': - case '?': - case ':': - case '(': - case ')': - /* Nothing, just return the character. */ - break; - - case ';': - case '\n': - case '\0': - /* Be safe and let the user call this function again. */ - --exp; - result = YYEOF; - break; - - default: - result = YYERRCODE; -#if YYDEBUG != 0 - --exp; -#endif - break; - } - - *pexp = exp; - - return result; -} - - -static void -yyerror (str) - const char *str; -{ - /* Do nothing. We don't print error messages here. */ -} diff --git a/src/system/libroot/posix/glibc/intl/plural.y b/src/system/libroot/posix/glibc/intl/plural.y deleted file mode 100644 index 045427b828..0000000000 --- a/src/system/libroot/posix/glibc/intl/plural.y +++ /dev/null @@ -1,409 +0,0 @@ -%{ -/* Expression parsing for plural form selection. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* The bison generated parser uses alloca. AIX 3 forces us to put this - declaration at the beginning of the file. The declaration in bison's - skeleton file comes too late. This must come before - because may include arbitrary system headers. */ -#if defined _AIX && !defined __GNUC__ - #pragma alloca -#endif -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "plural-exp.h" - -/* The main function generated by the parser is called __gettextparse, - but we want it to be called PLURAL_PARSE. */ -#ifndef _LIBC -# define __gettextparse PLURAL_PARSE -#endif - -#define YYLEX_PARAM &((struct parse_args *) arg)->cp -#define YYPARSE_PARAM arg -%} -%pure_parser -%expect 7 - -%union { - unsigned long int num; - enum operator op; - struct expression *exp; -} - -%{ -/* Prototypes for local functions. */ -static struct expression *new_exp PARAMS ((int nargs, enum operator op, - struct expression * const *args)); -static inline struct expression *new_exp_0 PARAMS ((enum operator op)); -static inline struct expression *new_exp_1 PARAMS ((enum operator op, - struct expression *right)); -static struct expression *new_exp_2 PARAMS ((enum operator op, - struct expression *left, - struct expression *right)); -static inline struct expression *new_exp_3 PARAMS ((enum operator op, - struct expression *bexp, - struct expression *tbranch, - struct expression *fbranch)); -static int yylex PARAMS ((YYSTYPE *lval, const char **pexp)); -static void yyerror PARAMS ((const char *str)); - -/* Allocation of expressions. */ - -static struct expression * -new_exp (nargs, op, args) - int nargs; - enum operator op; - struct expression * const *args; -{ - int i; - struct expression *newp; - - /* If any of the argument could not be malloc'ed, just return NULL. */ - for (i = nargs - 1; i >= 0; i--) - if (args[i] == NULL) - goto fail; - - /* Allocate a new expression. */ - newp = (struct expression *) malloc (sizeof (*newp)); - if (newp != NULL) - { - newp->nargs = nargs; - newp->operation = op; - for (i = nargs - 1; i >= 0; i--) - newp->val.args[i] = args[i]; - return newp; - } - - fail: - for (i = nargs - 1; i >= 0; i--) - FREE_EXPRESSION (args[i]); - - return NULL; -} - -static inline struct expression * -new_exp_0 (op) - enum operator op; -{ - return new_exp (0, op, NULL); -} - -static inline struct expression * -new_exp_1 (op, right) - enum operator op; - struct expression *right; -{ - struct expression *args[1]; - - args[0] = right; - return new_exp (1, op, args); -} - -static struct expression * -new_exp_2 (op, left, right) - enum operator op; - struct expression *left; - struct expression *right; -{ - struct expression *args[2]; - - args[0] = left; - args[1] = right; - return new_exp (2, op, args); -} - -static inline struct expression * -new_exp_3 (op, bexp, tbranch, fbranch) - enum operator op; - struct expression *bexp; - struct expression *tbranch; - struct expression *fbranch; -{ - struct expression *args[3]; - - args[0] = bexp; - args[1] = tbranch; - args[2] = fbranch; - return new_exp (3, op, args); -} - -%} - -/* This declares that all operators have the same associativity and the - precedence order as in C. See [Harbison, Steele: C, A Reference Manual]. - There is no unary minus and no bitwise operators. - Operators with the same syntactic behaviour have been merged into a single - token, to save space in the array generated by bison. */ -%right '?' /* ? */ -%left '|' /* || */ -%left '&' /* && */ -%left EQUOP2 /* == != */ -%left CMPOP2 /* < > <= >= */ -%left ADDOP2 /* + - */ -%left MULOP2 /* * / % */ -%right '!' /* ! */ - -%token EQUOP2 CMPOP2 ADDOP2 MULOP2 -%token NUMBER -%type exp - -%% - -start: exp - { - if ($1 == NULL) - YYABORT; - ((struct parse_args *) arg)->res = $1; - } - ; - -exp: exp '?' exp ':' exp - { - $$ = new_exp_3 (qmop, $1, $3, $5); - } - | exp '|' exp - { - $$ = new_exp_2 (lor, $1, $3); - } - | exp '&' exp - { - $$ = new_exp_2 (land, $1, $3); - } - | exp EQUOP2 exp - { - $$ = new_exp_2 ($2, $1, $3); - } - | exp CMPOP2 exp - { - $$ = new_exp_2 ($2, $1, $3); - } - | exp ADDOP2 exp - { - $$ = new_exp_2 ($2, $1, $3); - } - | exp MULOP2 exp - { - $$ = new_exp_2 ($2, $1, $3); - } - | '!' exp - { - $$ = new_exp_1 (lnot, $2); - } - | 'n' - { - $$ = new_exp_0 (var); - } - | NUMBER - { - if (($$ = new_exp_0 (num)) != NULL) - $$->val.num = $1; - } - | '(' exp ')' - { - $$ = $2; - } - ; - -%% - -void -internal_function -FREE_EXPRESSION (exp) - struct expression *exp; -{ - if (exp == NULL) - return; - - /* Handle the recursive case. */ - switch (exp->nargs) - { - case 3: - FREE_EXPRESSION (exp->val.args[2]); - /* FALLTHROUGH */ - case 2: - FREE_EXPRESSION (exp->val.args[1]); - /* FALLTHROUGH */ - case 1: - FREE_EXPRESSION (exp->val.args[0]); - /* FALLTHROUGH */ - default: - break; - } - - free (exp); -} - - -static int -yylex (lval, pexp) - YYSTYPE *lval; - const char **pexp; -{ - const char *exp = *pexp; - int result; - - while (1) - { - if (exp[0] == '\0') - { - *pexp = exp; - return YYEOF; - } - - if (exp[0] != ' ' && exp[0] != '\t') - break; - - ++exp; - } - - result = *exp++; - switch (result) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - unsigned long int n = result - '0'; - while (exp[0] >= '0' && exp[0] <= '9') - { - n *= 10; - n += exp[0] - '0'; - ++exp; - } - lval->num = n; - result = NUMBER; - } - break; - - case '=': - if (exp[0] == '=') - { - ++exp; - lval->op = equal; - result = EQUOP2; - } - else - result = YYERRCODE; - break; - - case '!': - if (exp[0] == '=') - { - ++exp; - lval->op = not_equal; - result = EQUOP2; - } - break; - - case '&': - case '|': - if (exp[0] == result) - ++exp; - else - result = YYERRCODE; - break; - - case '<': - if (exp[0] == '=') - { - ++exp; - lval->op = less_or_equal; - } - else - lval->op = less_than; - result = CMPOP2; - break; - - case '>': - if (exp[0] == '=') - { - ++exp; - lval->op = greater_or_equal; - } - else - lval->op = greater_than; - result = CMPOP2; - break; - - case '*': - lval->op = mult; - result = MULOP2; - break; - - case '/': - lval->op = divide; - result = MULOP2; - break; - - case '%': - lval->op = module; - result = MULOP2; - break; - - case '+': - lval->op = plus; - result = ADDOP2; - break; - - case '-': - lval->op = minus; - result = ADDOP2; - break; - - case 'n': - case '?': - case ':': - case '(': - case ')': - /* Nothing, just return the character. */ - break; - - case ';': - case '\n': - case '\0': - /* Be safe and let the user call this function again. */ - --exp; - result = YYEOF; - break; - - default: - result = YYERRCODE; -#if YYDEBUG != 0 - --exp; -#endif - break; - } - - *pexp = exp; - - return result; -} - - -static void -yyerror (str) - const char *str; -{ - /* Do nothing. We don't print error messages here. */ -} diff --git a/src/system/libroot/posix/glibc/intl/po2test.sed b/src/system/libroot/posix/glibc/intl/po2test.sed deleted file mode 100644 index d1c2f3d086..0000000000 --- a/src/system/libroot/posix/glibc/intl/po2test.sed +++ /dev/null @@ -1,70 +0,0 @@ -# po2test.sed - Convert Uniforum style .po file to C code for testing. -# Copyright (C) 2000 Free Software Foundation, Inc. -# Ulrich Drepper , 2000. -# -# 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 2, 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, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# -# We copy the original message as a comment into the .msg file. But enclose -# them with INPUT ( ). -# -/^msgid/ { - s/msgid[ ]*"\(.*\)"/INPUT ("\1")/ -# Clear flag from last substitution. - tb -# Append the next line. - :b - N -# Look whether second part is a continuation line. - s/\(.*\)")\(\n\)"\(.*\)"/\1\\\2\3")/ -# Yes, then branch. - ta - P - D -# Note that `D' includes a jump to the start!! -# We found a continuation line. But before printing insert '\'. - :a - s/\(.*\)")\(\n.*\)/\1\\\2/ - P -# We cannot use the sed command `D' here - s/.*\n\(.*\)/\1/ - tb -} -# -# Copy the translations as well and enclose them with OUTPUT ( ). -# -/^msgstr/ { - s/msgstr[ ]*"\(.*\)"/OUTPUT ("\1")/ -# Clear flag from last substitution. - tb -# Append the next line. - :b - N -# Look whether second part is a continuation line. - s/\(.*\)")\(\n\)"\(.*\)"/\1\\\2\3")/ -# Yes, then branch. - ta - P - D -# Note that `D' includes a jump to the start!! -# We found a continuation line. But before printing insert '\'. - :a - s/\(.*\)")\(\n.*\)/\1\\\2/ - P -# We cannot use the sed command `D' here - s/.*\n\(.*\)/\1/ - tb -} -d diff --git a/src/system/libroot/posix/glibc/intl/textdomain.c b/src/system/libroot/posix/glibc/intl/textdomain.c deleted file mode 100644 index 1c23e94d76..0000000000 --- a/src/system/libroot/posix/glibc/intl/textdomain.c +++ /dev/null @@ -1,143 +0,0 @@ -/* Implementation of the textdomain(3) function. - Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#ifdef _LIBC -# include -#else -# include "libgnuintl.h" -#endif -#include "gettextP.h" - -#ifdef _LIBC -/* We have to handle multi-threaded applications. */ -# include -#else -/* Provide dummy implementation if this is outside glibc. */ -# define __libc_rwlock_define(CLASS, NAME) -# define __libc_rwlock_wrlock(NAME) -# define __libc_rwlock_unlock(NAME) -#endif - -/* The internal variables in the standalone libintl.a must have different - names than the internal variables in GNU libc, otherwise programs - using libintl.a cannot be linked statically. */ -#if !defined _LIBC -# define _nl_default_default_domain libintl_nl_default_default_domain -# define _nl_current_default_domain libintl_nl_current_default_domain -#endif - -/* @@ end of prolog @@ */ - -/* Name of the default text domain. */ -extern const char _nl_default_default_domain[] attribute_hidden; - -/* Default text domain in which entries for gettext(3) are to be found. */ -extern const char *_nl_current_default_domain attribute_hidden; - - -/* Names for the libintl functions are a problem. They must not clash - with existing names and they should follow ANSI C. But this source - code is also used in GNU C Library where the names have a __ - prefix. So we have to make a difference here. */ -#ifdef _LIBC -# define TEXTDOMAIN __textdomain -# ifndef strdup -# define strdup(str) __strdup (str) -# endif -#else -# define TEXTDOMAIN libintl_textdomain -#endif - -/* Lock variable to protect the global data in the gettext implementation. */ -__libc_rwlock_define (extern, _nl_state_lock attribute_hidden) - -/* Set the current default message catalog to DOMAINNAME. - If DOMAINNAME is null, return the current default. - If DOMAINNAME is "", reset to the default of "messages". */ -char * -TEXTDOMAIN (domainname) - const char *domainname; -{ - char *new_domain; - char *old_domain; - - /* A NULL pointer requests the current setting. */ - if (domainname == NULL) - return (char *) _nl_current_default_domain; - - __libc_rwlock_wrlock (_nl_state_lock); - - old_domain = (char *) _nl_current_default_domain; - - /* If domain name is the null string set to default domain "messages". */ - if (domainname[0] == '\0' - || strcmp (domainname, _nl_default_default_domain) == 0) - { - _nl_current_default_domain = _nl_default_default_domain; - new_domain = (char *) _nl_current_default_domain; - } - else if (strcmp (domainname, old_domain) == 0) - /* This can happen and people will use it to signal that some - environment variable changed. */ - new_domain = old_domain; - else - { - /* If the following malloc fails `_nl_current_default_domain' - will be NULL. This value will be returned and so signals we - are out of core. */ -#if defined _LIBC || defined HAVE_STRDUP - new_domain = strdup (domainname); -#else - size_t len = strlen (domainname) + 1; - new_domain = (char *) malloc (len); - if (new_domain != NULL) - memcpy (new_domain, domainname, len); -#endif - - if (new_domain != NULL) - _nl_current_default_domain = new_domain; - } - - /* We use this possibility to signal a change of the loaded catalogs - since this is most likely the case and there is no other easy we - to do it. Do it only when the call was successful. */ - if (new_domain != NULL) - { - ++_nl_msg_cat_cntr; - - if (old_domain != new_domain && old_domain != _nl_default_default_domain) - free (old_domain); - } - - __libc_rwlock_unlock (_nl_state_lock); - - return new_domain; -} - -#ifdef _LIBC -/* Alias for function name in GNU C Library. */ -weak_alias (__textdomain, textdomain); -#endif diff --git a/src/system/libroot/posix/glibc/intl/translit.po b/src/system/libroot/posix/glibc/intl/translit.po deleted file mode 100644 index 5df5d0d064..0000000000 --- a/src/system/libroot/posix/glibc/intl/translit.po +++ /dev/null @@ -1,9 +0,0 @@ -msgid "" -msgstr "" -"Content-Type: text/plain; charset=ISO-8859-1\n" - -msgid "test" -msgstr "߻" - -msgid "onemore" -msgstr "*=" diff --git a/src/system/libroot/posix/glibc/intl/tst-codeset.c b/src/system/libroot/posix/glibc/intl/tst-codeset.c deleted file mode 100644 index df10161274..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-codeset.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Test of bind_textdomain_codeset. - Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Bruno Haible , 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include - -int -main (void) -{ - char *s; - int result = 0; - - unsetenv ("LANGUAGE"); - unsetenv ("OUTPUT_CHARSET"); - setlocale (LC_ALL, "de_DE.ISO-8859-1"); - textdomain ("codeset"); - bindtextdomain ("codeset", OBJPFX "domaindir"); - - /* Here we expect output in ISO-8859-1. */ - s = gettext ("cheese"); - if (strcmp (s, "K\344se")) - { - printf ("call 1 returned: %s\n", s); - result = 1; - } - - bind_textdomain_codeset ("codeset", "UTF-8"); - - /* Here we expect output in UTF-8. */ - s = gettext ("cheese"); - if (strcmp (s, "K\303\244se")) - { - printf ("call 2 returned: %s\n", s); - result = 1; - } - - return result; -} diff --git a/src/system/libroot/posix/glibc/intl/tst-codeset.sh b/src/system/libroot/posix/glibc/intl/tst-codeset.sh deleted file mode 100644 index 3d9b9559b7..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-codeset.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/sh -# Test of bind_textdomain_codeset. -# Copyright (C) 2001, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -common_objpfx=$1 -objpfx=$2 - -LC_ALL=C -export LC_ALL - -# Generate the test data. -test -d ${objpfx}domaindir || mkdir ${objpfx}domaindir -# Create the domain directories. -test -d ${objpfx}domaindir/de_DE || mkdir ${objpfx}domaindir/de_DE -test -d ${objpfx}domaindir/de_DE/LC_MESSAGES || mkdir ${objpfx}domaindir/de_DE/LC_MESSAGES -# Populate them. -msgfmt -o ${objpfx}domaindir/de_DE/LC_MESSAGES/codeset.mo tstcodeset.po - -GCONV_PATH=${common_objpfx}iconvdata -export GCONV_PATH -LOCPATH=${common_objpfx}localedata -export LOCPATH - -${common_objpfx}elf/ld.so --library-path $common_objpfx \ -${objpfx}tst-codeset > ${objpfx}tst-codeset.out - -exit $? diff --git a/src/system/libroot/posix/glibc/intl/tst-gettext.c b/src/system/libroot/posix/glibc/intl/tst-gettext.c deleted file mode 100644 index 8a768e03c5..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-gettext.c +++ /dev/null @@ -1,369 +0,0 @@ -/* Test of the gettext functions. - Copyright (C) 2000, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -const struct -{ - const char *msgid; - const char *msgstr; -} msgs[] = -{ -#define INPUT(Str) { Str, -#define OUTPUT(Str) Str }, -#include TESTSTRS_H -}; - -const char *catname[] = -{ - [LC_MESSAGES] = "LC_MESSAGES", - [LC_TIME] = "LC_TIME", - [LC_NUMERIC] = "LC_NUMERIC" -}; - - -static int positive_gettext_test (void); -static int negative_gettext_test (void); -static int positive_dgettext_test (const char *domain); -static int positive_dcgettext_test (const char *domain, int category); -static int negative_dcgettext_test (const char *domain, int category); - - -#define check_setlocale(cat, name) do { \ - if (setlocale (cat, name) == NULL) \ - { \ - printf ("%s:%u: setlocale (%s, \"%s\"): %m\n", \ - __FILE__, __LINE__, #cat, name); \ - result = 1; \ - } \ - } while (0) - -int -main (int argc, char *argv[]) -{ - int result = 0; - - /* For debugging. */ - mtrace (); - - /* This is the place where the .mo files are placed. */ - if (argc > 1) - { - bindtextdomain ("existing-domain", argv[1]); - bindtextdomain ("existing-time-domain", argv[1]); - bindtextdomain ("non-existing-domain", argv[1]); - } - - /* The locale the catalog is created for is "existing-category". Now - set the various variables in question to this value and run the - test. */ - setenv ("LANGUAGE", "existing-locale", 1); - setenv ("LC_ALL", "non-existing-locale", 1); - setenv ("LC_MESSAGES", "non-existing-locale", 1); - setenv ("LC_CTYPE", "non-existing-locale", 1); - setenv ("LANG", "non-existing-locale", 1); - check_setlocale (LC_CTYPE, "de_DE.ISO-8859-1"); - check_setlocale (LC_MESSAGES, "de_DE.ISO-8859-1"); - unsetenv ("OUTPUT_CHARSET"); - /* This is the name of the existing domain with a catalog for the - LC_MESSAGES category. */ - textdomain ("existing-domain"); - puts ("test `gettext' with LANGUAGE set"); - if (positive_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - /* This is the name of a non-existing domain with a catalog for the - LC_MESSAGES category. We leave this value set for the `dgettext' - and `dcgettext' tests. */ - textdomain ("non-existing-domain"); - puts ("test `gettext' with LANGUAGE set"); - if (negative_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - puts ("test `dgettext' with LANGUAGE set"); - if (positive_dgettext_test ("existing-domain") != 0) - { - puts ("FAILED"); - result = 1; - } - - /* Now the same tests with LC_ALL deciding. */ - unsetenv ("LANGUAGE"); - setenv ("LC_ALL", "existing-locale", 1); - check_setlocale (LC_ALL, ""); - puts ("test `gettext' with LC_ALL set"); - /* This is the name of the existing domain with a catalog for the - LC_MESSAGES category. */ - textdomain ("existing-domain"); - if (positive_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - /* This is the name of a non-existing domain with a catalog for the - LC_MESSAGES category. We leave this value set for the `dgettext' - and `dcgettext' tests. */ - textdomain ("non-existing-domain"); - puts ("test `gettext' with LC_ALL deciding"); - if (negative_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - puts ("test `dgettext' with LC_ALL deciding"); - if (positive_dgettext_test ("existing-domain") != 0) - { - puts ("FAILED"); - result = 1; - } - - /* Now the same tests with LC_MESSAGES deciding. */ - unsetenv ("LC_ALL"); - setenv ("LC_MESSAGES", "existing-locale", 1); - check_setlocale (LC_MESSAGES, ""); - setenv ("LC_TIME", "existing-locale", 1); - check_setlocale (LC_TIME, ""); - setenv ("LC_NUMERIC", "non-existing-locale", 1); - char *what = setlocale (LC_NUMERIC, ""); - if (what != NULL) - { - printf ("setlocale succeeded (%s), expected failure\n", what); - result = 1; - } - - puts ("test `gettext' with LC_ALL set"); - /* This is the name of the existing domain with a catalog for the - LC_MESSAGES category. */ - textdomain ("existing-domain"); - if (positive_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - /* This is the name of a non-existing domain with a catalog for the - LC_MESSAGES category. We leave this value set for the `dgettext' - and `dcgettext' tests. */ - textdomain ("non-existing-domain"); - puts ("test `gettext' with LC_xxx deciding"); - if (negative_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - puts ("test `dgettext' with LC_xxx deciding"); - if (positive_dgettext_test ("existing-domain") != 0) - { - puts ("FAILED"); - result = 1; - } - puts ("test `dcgettext' with category == LC_MESSAGES"); - if (positive_dcgettext_test ("existing-domain", LC_MESSAGES) != 0) - { - puts ("FAILED"); - result = 1; - } - /* Try a different category. For this we also switch the domain. */ - puts ("test `dcgettext' with LANGUAGE == LC_TIME"); - if (positive_dcgettext_test ("existing-time-domain", LC_TIME) != 0) - { - puts ("FAILED"); - result = 1; - } - /* This time use a category for which there is no catalog. */ - puts ("test `dcgettext' with LANGUAGE == LC_NUMERIC"); - if (negative_dcgettext_test ("existing-domain", LC_NUMERIC) != 0) - { - puts ("FAILED"); - result = 1; - } - - /* Now the same tests with LANG deciding. */ - unsetenv ("LC_MESSAGES"); - unsetenv ("LC_CTYPE"); - unsetenv ("LC_TIME"); - unsetenv ("LC_NUMERIC"); - setenv ("LANG", "existing-locale", 1); - check_setlocale (LC_ALL, ""); - /* This is the name of the existing domain with a catalog for the - LC_MESSAGES category. */ - textdomain ("existing-domain"); - puts ("test `gettext' with LANG set"); - if (positive_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - /* This is the name of a non-existing domain with a catalog for the - LC_MESSAGES category. We leave this value set for the `dgettext' - and `dcgettext' tests. */ - textdomain ("non-existing-domain"); - puts ("test `gettext' with LANG set"); - if (negative_gettext_test () != 0) - { - puts ("FAILED"); - result = 1; - } - puts ("test `dgettext' with LANG set"); - if (positive_dgettext_test ("existing-domain") != 0) - { - puts ("FAILED"); - result = 1; - } - - check_setlocale (LC_ALL, "C"); - - return result; -} - - -static int -positive_gettext_test (void) -{ - size_t cnt; - int result = 0; - - for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt) - { - const char *found = gettext (msgs[cnt].msgid); - - if (found == NULL - || (msgs[cnt].msgstr[0] != '\0' - && strcmp (found, msgs[cnt].msgstr) != 0)) - { - /* Oops, shouldn't happen. */ - printf ("\ - gettext (\"%s\") failed, returned \"%s\", expected \"%s\"\n", - msgs[cnt].msgid, found, msgs[cnt].msgstr); - result = 1; - } - } - - return result; -} - - -static int -negative_gettext_test (void) -{ - size_t cnt; - int result = 0; - - for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt) - { - const char *found = gettext (msgs[cnt].msgid); - - if (found != msgs[cnt].msgid) - { - /* Oops, shouldn't happen. */ - printf (" gettext (\"%s\") failed\n", msgs[cnt].msgid); - result = 1; - } - } - - return result; -} - - -static int -positive_dgettext_test (const char *domain) -{ - size_t cnt; - int result = 0; - - for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt) - { - const char *found = dgettext (domain, msgs[cnt].msgid); - - if (found == NULL - || (msgs[cnt].msgstr[0] != '\0' - && strcmp (found, msgs[cnt].msgstr) != 0)) - { - /* Oops, shouldn't happen. */ - printf ("\ - dgettext (\"%s\", \"%s\") failed, returned \"%s\", expected \"%s\"\n", - domain, msgs[cnt].msgid, found, msgs[cnt].msgstr); - result = 1; - } - } - - return result; -} - - -static int -positive_dcgettext_test (const char *domain, int category) -{ - size_t cnt; - int result = 0; - - for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt) - { - const char *found = dcgettext (domain, msgs[cnt].msgid, category); - - if (found == NULL - || (msgs[cnt].msgstr[0] != '\0' - && strcmp (found, msgs[cnt].msgstr) != 0)) - { - /* Oops, shouldn't happen. */ - printf ("\ - dcgettext (\"%s\", \"%s\", %s) failed, returned \"%s\", expected \"%s\"\n", - domain, msgs[cnt].msgid, catname[category], found, - msgs[cnt].msgstr); - result = 1; - } - } - - return result; -} - - -static int -negative_dcgettext_test (const char *domain, int category) -{ - size_t cnt; - int result = 0; - - for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt) - { - const char *found = dcgettext (domain, msgs[cnt].msgid, category); - - if (found != msgs[cnt].msgid) - { - /* Oops, shouldn't happen. */ - printf (" dcgettext (\"%s\", \"%s\", %s) failed\n", - domain, msgs[cnt].msgid, catname[category]); - result = 1; - } - } - - return result; -} diff --git a/src/system/libroot/posix/glibc/intl/tst-gettext.sh b/src/system/libroot/posix/glibc/intl/tst-gettext.sh deleted file mode 100755 index cf6f6f3292..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-gettext.sh +++ /dev/null @@ -1,59 +0,0 @@ -#! /bin/sh -# Test of gettext functions. -# Copyright (C) 2000, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -common_objpfx=$1 -objpfx=$2 -malloc_trace=$3 - -LC_ALL=C -export LC_ALL - -# Generate the test data. - -# Create the locale directories. -mkdir -p ${objpfx}localedir/existing-locale/LC_MESSAGES -for f in ADDRESS COLLATE CTYPE IDENTIFICATION MEASUREMENT MONETARY NAME NUMERIC PAPER TELEPHONE TIME; do - cp -f ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_$f \ - ${objpfx}localedir/existing-locale -done -cp -f ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_MESSAGES/SYS_LC_MESSAGES \ - ${objpfx}localedir/existing-locale/LC_MESSAGES - -# Create the domain directories. -mkdir -p ${objpfx}domaindir/existing-locale/LC_MESSAGES -mkdir -p ${objpfx}domaindir/existing-locale/LC_TIME -# Populate them. -msgfmt -o ${objpfx}domaindir/existing-locale/LC_MESSAGES/existing-domain.mo \ - -f ../po/de.po -msgfmt -o ${objpfx}domaindir/existing-locale/LC_TIME/existing-time-domain.mo \ - -f ../po/de.po - -GCONV_PATH=${common_objpfx}iconvdata -export GCONV_PATH -LOCPATH=${common_objpfx}localedata -export LOCPATH - -# Now run the test. -MALLOC_TRACE=$malloc_trace LOCPATH=${objpfx}localedir:$LOCPATH \ -${common_objpfx}elf/ld.so --library-path $common_objpfx \ -${objpfx}tst-gettext > ${objpfx}tst-gettext.out ${objpfx}domaindir - -exit $? diff --git a/src/system/libroot/posix/glibc/intl/tst-gettext2.c b/src/system/libroot/posix/glibc/intl/tst-gettext2.c deleted file mode 100644 index 8188aa5251..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-gettext2.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Test of the gettext functions. - Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Thorsten Kukuk and - Andreas Jaeger , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - - -#include -#include -#include -#include - -struct data_t -{ - const char *selection; - const char *description; -}; - -int data_cnt = 2; -struct data_t strings[] = -{ - { "String1", N_("First string for testing.") }, - { "String2", N_("Another string for testing.") } -}; - -const int lang_cnt = 3; -const char *lang[] = {"lang1", "lang2", "lang3"}; - -int -main (void) -{ - int i; - - /* Clean up environment. */ - unsetenv ("LANGUAGE"); - unsetenv ("LC_ALL"); - unsetenv ("LC_MESSAGES"); - unsetenv ("LC_CTYPE"); - unsetenv ("LANG"); - unsetenv ("OUTPUT_CHARSET"); - - textdomain ("tstlang"); - - for (i = 0; i < lang_cnt; ++i) - { - int j; - - if (setlocale (LC_ALL, lang[i]) == NULL) - setlocale (LC_ALL, "C"); - bindtextdomain ("tstlang", OBJPFX "domaindir"); - - for (j = 0; j < data_cnt; ++j) - printf ("%s - %s\n", strings[j].selection, - gettext (strings[j].description)); - } - - return 0; -} diff --git a/src/system/libroot/posix/glibc/intl/tst-gettext2.sh b/src/system/libroot/posix/glibc/intl/tst-gettext2.sh deleted file mode 100644 index 4b9c35213b..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-gettext2.sh +++ /dev/null @@ -1,80 +0,0 @@ -#! /bin/sh -# Test of gettext functions. -# Copyright (C) 2000 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -common_objpfx=$1 -objpfx=$2 - -GCONV_PATH=${common_objpfx}iconvdata -export GCONV_PATH -LOCPATH=${objpfx}domaindir -export LOCPATH -LC_ALL=C -export LC_ALL - -# Generate the test data. -test -d ${objpfx}domaindir || mkdir ${objpfx}domaindir -# Create the locale directories. -test -d ${objpfx}domaindir/lang1 || { - mkdir ${objpfx}domaindir/lang1 - for f in ADDRESS COLLATE CTYPE IDENTIFICATION MEASUREMENT MONETARY NAME NUMERIC PAPER TELEPHONE TIME; do - cp ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_$f \ - ${objpfx}domaindir/lang1 - done -} -test -d ${objpfx}domaindir/lang2 || { - mkdir ${objpfx}domaindir/lang2 - for f in ADDRESS COLLATE CTYPE IDENTIFICATION MEASUREMENT MONETARY NAME NUMERIC PAPER TELEPHONE TIME; do - cp ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_$f \ - ${objpfx}domaindir/lang2 - done -} -test -d ${objpfx}domaindir/lang1/LC_MESSAGES || { - mkdir ${objpfx}domaindir/lang1/LC_MESSAGES - cp ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_MESSAGES/SYS_LC_MESSAGES \ - ${objpfx}domaindir/lang1/LC_MESSAGES -} -test -d ${objpfx}domaindir/lang2/LC_MESSAGES || { - mkdir ${objpfx}domaindir/lang2/LC_MESSAGES - cp ${common_objpfx}localedata/de_DE.ISO-8859-1/LC_MESSAGES/SYS_LC_MESSAGES \ - ${objpfx}domaindir/lang2/LC_MESSAGES -} - -# Populate them. -msgfmt -o ${objpfx}domaindir/lang1/LC_MESSAGES/tstlang.mo \ - tstlang1.po - -msgfmt -o ${objpfx}domaindir/lang2/LC_MESSAGES/tstlang.mo \ - tstlang2.po - - -# Now run the test. -${common_objpfx}elf/ld.so --library-path $common_objpfx \ -${objpfx}tst-gettext2 > ${objpfx}tst-gettext2.out ${objpfx}domaindir && -cmp ${objpfx}tst-gettext2.out - <, 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include - - -int -main (void) -{ - const char *strs[2] = { "singular", "plural" }; - unsigned long int i; - int res = 0; - - /* We don't want any translation here. */ - setenv ("LANGUAGE", "C", 1); - unsetenv ("OUTPUT_CHARSET"); - - for (i = 0; i < 30; ++i) - { - char *tr; - - tr = ngettext (strs[0], strs[1], i); -#define TEST \ - do \ - if (tr != strs[i != 1]) \ - { \ - if (strcmp (tr, strs[i != 1]) == 0) \ - printf ("%lu: correct string, wrong pointer (%s)\n", i, tr); \ - else \ - printf ("%lu: wrong result (%s)\n", i, tr); \ - res = 1; \ - } \ - while (0) - TEST; - - tr = dngettext ("messages", strs[0], strs[1], i); - TEST; - - tr = dcngettext ("messages", strs[0], strs[1], i, LC_MESSAGES); - TEST; - } - - return res; -} diff --git a/src/system/libroot/posix/glibc/intl/tst-translit.c b/src/system/libroot/posix/glibc/intl/tst-translit.c deleted file mode 100644 index 4f8b0cdc83..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-translit.c +++ /dev/null @@ -1,52 +0,0 @@ -/* Test of translitation in the gettext functions. - Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include - -int -main (void) -{ - int result = 0; - const char *s; - - setenv ("LANGUAGE", "existing-locale", 1); - unsetenv ("OUTPUT_CHARSET"); - setlocale (LC_ALL, "en_US.ANSI_X3.4-1968"); - textdomain ("translit"); - bindtextdomain ("translit", OBJPFX "domaindir"); - -#define TEST(in, exp) \ - s = gettext (in); \ - puts (s); \ - result |= strcmp (s, exp) != 0; - - TEST ("test", "<<(C) AEss>>"); - TEST ("test", "<<(C) AEss>>"); - TEST ("onemore", " 1/2 * 1/2 = 1/4 "); - TEST ("onemore", " 1/2 * 1/2 = 1/4 "); - TEST ("test", "<<(C) AEss>>"); - - return result; -} diff --git a/src/system/libroot/posix/glibc/intl/tst-translit.sh b/src/system/libroot/posix/glibc/intl/tst-translit.sh deleted file mode 100755 index e2508df4df..0000000000 --- a/src/system/libroot/posix/glibc/intl/tst-translit.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /bin/sh -# Test of transliteration in gettext functions. -# Copyright (C) 2000, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -common_objpfx=$1 -objpfx=$2 - -LC_ALL=C -export LC_ALL - -msgfmt -o ${objpfx}domaindir/existing-locale/LC_MESSAGES/translit.mo \ - translit.po - -GCONV_PATH=${common_objpfx}iconvdata -export GCONV_PATH -LOCPATH=${common_objpfx}localedata -export LOCPATH - -${common_objpfx}elf/ld.so --library-path $common_objpfx \ -${objpfx}tst-translit > ${objpfx}tst-translit.out ${objpfx}domaindir - -exit $? diff --git a/src/system/libroot/posix/glibc/intl/tstcodeset.po b/src/system/libroot/posix/glibc/intl/tstcodeset.po deleted file mode 100644 index 9a6231d600..0000000000 --- a/src/system/libroot/posix/glibc/intl/tstcodeset.po +++ /dev/null @@ -1,8 +0,0 @@ -msgid "" -msgstr "" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=ISO-8859-1\n" -"Content-Transfer-Encoding: 8-bit\n" - -msgid "cheese" -msgstr "Kse" diff --git a/src/system/libroot/posix/glibc/intl/tstlang1.po b/src/system/libroot/posix/glibc/intl/tstlang1.po deleted file mode 100644 index c411ce116f..0000000000 --- a/src/system/libroot/posix/glibc/intl/tstlang1.po +++ /dev/null @@ -1,13 +0,0 @@ -msgid "" -msgstr "" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=US-ASCII\n" -"Content-Transfer-Encoding: 7-bit\n" - -#: tst-gettext2.c:33 -msgid "First string for testing." -msgstr "Lang1: 1st string" - -#: tst-gettext2.c:34 -msgid "Another string for testing." -msgstr "Lang1: 2nd string" diff --git a/src/system/libroot/posix/glibc/intl/tstlang2.po b/src/system/libroot/posix/glibc/intl/tstlang2.po deleted file mode 100644 index d1606c8ede..0000000000 --- a/src/system/libroot/posix/glibc/intl/tstlang2.po +++ /dev/null @@ -1,13 +0,0 @@ -msgid "" -msgstr "" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=US-ASCII\n" -"Content-Transfer-Encoding: 7-bit\n" - -#: tst-gettext2.c:33 -msgid "First string for testing." -msgstr "Lang2: 1st string" - -#: tst-gettext2.c:34 -msgid "Another string for testing." -msgstr "Lang2: 2nd string" diff --git a/src/system/libroot/posix/glibc/locale/C-address.c b/src/system/libroot/posix/glibc/locale/C-address.c deleted file mode 100644 index eabb6fd4a4..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-address.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.10 "LC_ADDRESS". */ - -const struct locale_data _nl_C_LC_ADDRESS = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 13, - { - { string: "%a%N%f%N%d%N%b%N%s %h %e %r%N%C-%z %T%N%c%N" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/C-identification.c b/src/system/libroot/posix/glibc/locale/C-identification.c deleted file mode 100644 index 8af6858309..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-identification.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.12 "LC_IDENTIFICATION". */ - -const struct locale_data _nl_C_LC_IDENTIFICATION = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 16, - { - { string: "ISO/IEC 14652 i18n FDCC-set" }, - { string: "ISO/IEC JTC1/SC22/WG20 - internationalization" }, - { string: "C/o Keld Simonsen, Skt. Jorgens Alle 8, DK-1615 Kobenhavn V" }, - { string: "Keld Simonsen" }, - { string: "keld@dkuug.dk" }, - { string: "+45 3122-6543" }, - { string: "+45 3325-6543" }, - { string: "" }, - { string: "ISO" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "1.0" }, - { string: "1997-12-20" }, - { string: "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" - "i18n:1999\0" "i18n:1999\0" "\0" "i18n:1999\0" - "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" - "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" "i18n:1999\0" - "i18n:1999" }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/C-measurement.c b/src/system/libroot/posix/glibc/locale/C-measurement.c deleted file mode 100644 index e6473672c1..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-measurement.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.12 "LC_MEASUREMENT". */ - -const struct locale_data _nl_C_LC_MEASUREMENT = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 2, - { - { string: "\1" }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/C-name.c b/src/system/libroot/posix/glibc/locale/C-name.c deleted file mode 100644 index 4286b82443..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-name.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.9 "LC_NAME". */ - -const struct locale_data _nl_C_LC_NAME = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 7, - { - { string: "%p%t%g%t%m%t%f" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/C-paper.c b/src/system/libroot/posix/glibc/locale/C-paper.c deleted file mode 100644 index a168084c26..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-paper.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.8 "LC_PAPER". */ - -const struct locale_data _nl_C_LC_PAPER = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 3, - { - { word: 297 }, - { word: 210 }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/C-telephone.c b/src/system/libroot/posix/glibc/locale/C-telephone.c deleted file mode 100644 index d7c830ce13..0000000000 --- a/src/system/libroot/posix/glibc/locale/C-telephone.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "localeinfo.h" - -/* This table's entries are taken from ISO 14652, the table in section - 4.11 "LC_TELEPHONE". */ - -const struct locale_data _nl_C_LC_TELEPHONE = -{ - _nl_C_name, - NULL, 0, 0, /* no file mapped */ - UNDELETABLE, - 0, - NULL, - 5, - { - { string: "+%c %a %l" }, - { string: "" }, - { string: "" }, - { string: "" }, - { string: _nl_C_codeset } - } -}; diff --git a/src/system/libroot/posix/glibc/locale/Jamfile b/src/system/libroot/posix/glibc/locale/Jamfile index 00e0f2b492..7797505cb8 100644 --- a/src/system/libroot/posix/glibc/locale/Jamfile +++ b/src/system/libroot/posix/glibc/locale/Jamfile @@ -10,34 +10,19 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ; SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO -DLOCALEDIR=\'\"/share/locale\"\' ; MergeObject posix_gnu_locale.o : - C-address.c C-collate.c C-ctype.c - C-identification.c - C-measurement.c C-messages.c C-monetary.c - C-name.c C-numeric.c - C-paper.c - C-telephone.c C-time.c C_name.c coll-lookup.c -# findlocale.c - lc-address.c lc-collate.c lc-ctype.c - lc-identification.c - lc-measurement.c lc-messages.c lc-monetary.c - lc-name.c lc-numeric.c - lc-paper.c - lc-telephone.c -# lc-time.c mb_cur_max.c -# setlocale.c xlocale.c ; diff --git a/src/system/libroot/posix/glibc/locale/Makefile b/src/system/libroot/posix/glibc/locale/Makefile deleted file mode 100644 index 03ed1b66fa..0000000000 --- a/src/system/libroot/posix/glibc/locale/Makefile +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright (C) 1991, 92, 1995-1999, 2000, 2001 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Makefile for locales. -# -subdir := locale - -headers = locale.h bits/locale.h langinfo.h xlocale.h -distribute = localeinfo.h categories.def iso-639.def iso-3166.def \ - iso-4217.def weight.h weightwc.h strlen-hash.h elem-hash.h \ - indigits.h indigitswc.h outdigits.h outdigitswc.h \ - coll-lookup.h C-translit.h.in C-translit.h gen-translit.pl \ - $(addprefix programs/, \ - locale.c localedef.c \ - $(localedef-modules:=.c) $(locale-modules:=.c) \ - $(lib-modules:=.c) config.h simple-hash.h \ - charmap-kw.gperf charmap-kw.h locfile-token.h \ - locfile-kw.gperf locfile-kw.h linereader.h \ - locfile.h charmap.h repertoire.h localedef.h \ - 3level.h charmap-dir.h) -routines = setlocale findlocale loadlocale localeconv nl_langinfo \ - nl_langinfo_l mb_cur_max \ - newlocale duplocale freelocale -tests = tst-C-locale -categories = ctype messages monetary numeric time paper name \ - address telephone measurement identification collate -aux = $(categories:%=lc-%) $(categories:%=C-%) SYS_libc C_name \ - xlocale -others = localedef locale -#others-static = localedef locale -install-bin = localedef locale -extra-objs = $(localedef-modules:=.o) $(locale-modules:=.o) \ - $(lib-modules:=.o) - -extra-libs = libBrokenLocale -extra-libs-others = $(extra-libs) - -libBrokenLocale-routines = broken_cur_max - -subdir-dirs = programs -vpath %.c programs -vpath %.h programs -vpath %.gperf programs - -localedef-modules := $(categories:%=ld-%) charmap linereader locfile \ - repertoire -locale-modules := locale-spec -lib-modules := charmap-dir simple-hash xmalloc xstrdup - - -GPERF = gperf -GPERFFLAGS = -acCgopt -k1,2,5,9,$$ -L ANSI-C - -include ../Rules - -programs/%-kw.h: programs/%-kw.gperf - $(GPERF) $(GPERFFLAGS) -N $(@F:-kw.h=_hash) $< > $@.new - mv -f $@.new $@ - -$(objpfx)localedef: $(localedef-modules:%=$(objpfx)%.o) -$(objpfx)locale: $(locale-modules:%=$(objpfx)%.o) -$(objpfx)localedef $(objpfx)locale: $(lib-modules:%=$(objpfx)%.o) - -C-translit.h: C-translit.h.in gen-translit.pl - $(PERL) gen-translit.pl < $< > $@.tmp - mv -f $@.tmp $@ -ifeq ($(with-cvs),yes) - test ! -d CVS || cvs $(CVSOPTS) commit -mRegenerated $@ -endif - -localepath = "$(localedir):$(i18ndir)" - -locale-CPPFLAGS := -DLOCALE_PATH='$(localepath)' \ - -DLOCALEDIR='"$(localedir)"' \ - -DLOCALE_ALIAS_PATH='"$(msgcatdir)"' \ - -DCHARMAP_PATH='"$(i18ndir)/charmaps"' \ - -DREPERTOIREMAP_PATH='"$(i18ndir)/repertoiremaps"' \ - -DLOCSRCDIR='"$(i18ndir)/locales"' -DHAVE_CONFIG_H \ - -Iprograms - -CFLAGS-charmap.c = -Wno-write-strings -Wno-char-subscripts -CFLAGS-locfile.c = -Wno-write-strings -Wno-char-subscripts -CFLAGS-charmap-dir.c = -Wno-write-strings - -# Depend on libc.so so a DT_NEEDED is generated in the shared objects. -# This ensures they will load libc.so for needed symbols if loaded by -# a statically-linked program that hasn't already loaded it. -$(objpfx)libBrokenLocale.so: $(common-objpfx)libc.so \ - $(common-objpfx)libc_nonshared.a diff --git a/src/system/libroot/posix/glibc/locale/SYS_libc.c b/src/system/libroot/posix/glibc/locale/SYS_libc.c deleted file mode 100644 index 53c9a6034e..0000000000 --- a/src/system/libroot/posix/glibc/locale/SYS_libc.c +++ /dev/null @@ -1,4 +0,0 @@ -/* Define a constant for the dgettext domainname for libc internal messages, - so the string constant is not repeated in dozens of object files. */ - -const char _libc_intl_domainname[] = "libc"; diff --git a/src/system/libroot/posix/glibc/locale/Versions b/src/system/libroot/posix/glibc/locale/Versions deleted file mode 100644 index 9c3bda4ffd..0000000000 --- a/src/system/libroot/posix/glibc/locale/Versions +++ /dev/null @@ -1,51 +0,0 @@ -libBrokenLocale { - GLIBC_2.0 { - __ctype_get_mb_cur_max; - } -} - -libc { - GLIBC_2.0 { - # global variables - __collate_element_hash; __collate_element_strings; - __collate_symbol_classes; __collate_symbol_hash; __collate_symbol_strings; - _libc_intl_domainname; _nl_current_LC_COLLATE; _nl_current_LC_CTYPE; - - # functions used in inline functions or macros - __ctype_get_mb_cur_max; - - # l* - localeconv; - - # n* - nl_langinfo; - - # s* - setlocale; - } - GLIBC_2.1 { - # functions from the experimental locale implementation - __newlocale; __duplocale; __freelocale; - __isalnum_l; __isalpha_l; __isascii_l; __isblank_l; __iscntrl_l; - __isdigit_l; __isgraph_l; __islower_l; __isprint_l; __ispunct_l; - __isspace_l; __isupper_l; __iswalnum_l; __iswalpha_l; __iswblank_l; - __iswcntrl_l; __iswctype_l; __iswdigit_l; __iswgraph_l; __iswlower_l; - __iswprint_l; __iswpunct_l; __iswspace_l; __iswupper_l; __iswxdigit_l; - __isxdigit_l; __strcasecmp_l; __strcoll_l; __strfmon_l; __strncasecmp_l; - __strtod_l; __strtof_l; __strtol_l; __strtold_l; __strtoll_l; __strtoul_l; - __strtoull_l; __strxfrm_l; __toascii_l; __tolower_l; __toupper_l; - __towctrans_l; __towlower_l; __towupper_l; __wcscasecmp_l; __wcscoll_l; - __wcsncasecmp_l; __wcstod_l; __wcstof_l; __wcstol_l; __wcstold_l; - __wcstoll_l; __wcstoul_l; __wcstoull_l; __wcsxfrm_l; __wctype_l; - } - GLIBC_2.2 { - # The data structure changed. - localeconv; - - # more functions from the experimental locale implementation - __wctrans_l; - - # missing function from the experimental locale implementation - __nl_langinfo_l; - } -} diff --git a/src/system/libroot/posix/glibc/locale/bits/locale.h b/src/system/libroot/posix/glibc/locale/bits/locale.h index 50064b53e7..c2745d5b6e 100644 --- a/src/system/libroot/posix/glibc/locale/bits/locale.h +++ b/src/system/libroot/posix/glibc/locale/bits/locale.h @@ -33,12 +33,6 @@ enum __LC_MONETARY = 4, __LC_MESSAGES = 5, __LC_ALL = 6, - __LC_PAPER = 7, - __LC_NAME = 8, - __LC_ADDRESS = 9, - __LC_TELEPHONE = 10, - __LC_MEASUREMENT = 11, - __LC_IDENTIFICATION = 12 }; #endif /* bits/locale.h */ diff --git a/src/system/libroot/posix/glibc/locale/broken_cur_max.c b/src/system/libroot/posix/glibc/locale/broken_cur_max.c deleted file mode 100644 index c997bec163..0000000000 --- a/src/system/libroot/posix/glibc/locale/broken_cur_max.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Return number of characters in multibyte representation for current - character set. - Copyright (C) 1996, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include "localeinfo.h" - - -/* This is a gross hack to get broken programs running. - - ISO C provides no mean to find out how many bytes the wide - character representation really uses. But it defines MB_CUR_LEN to - return the information for the multi-byte character representation. - Many programmers don't know the difference between the two and - think this means the same. But assuming all characters have a size - of MB_CUR_LEN after they have been processed by `mbrtowc' is wrong. - Instead the maximum number of characters used for the conversion is - MB_CUR_LEN. - - It is known that some Motif applications have this problem. To - cure this one has to make sure the glibc uses the function in this - file instead of the one in locale/mb_cur_max.c. This can either be - done by linking with this file or by using the LD_PRELOAD feature - of the dynamic linker. */ -size_t -__ctype_get_mb_cur_max (void) -{ - size_t correct_value = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX); - - return ((size_t []) { 1, 1, 1, 2, 2, 3, 4 })[correct_value]; -} diff --git a/src/system/libroot/posix/glibc/locale/categories.def b/src/system/libroot/posix/glibc/locale/categories.def index 257fac73ae..782b3975ad 100644 --- a/src/system/libroot/posix/glibc/locale/categories.def +++ b/src/system/libroot/posix/glibc/locale/categories.def @@ -260,85 +260,3 @@ DEFINE_CATEGORY DEFINE_ELEMENT (NOSTR, "nostr", opt, string) DEFINE_ELEMENT (_NL_MESSAGES_CODESET, "messages-codeset", std, string) ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_PAPER, "LC_PAPER", - ( - DEFINE_ELEMENT (_NL_PAPER_HEIGHT, "height", std, word) - DEFINE_ELEMENT (_NL_PAPER_WIDTH, "width", std, word) - DEFINE_ELEMENT (_NL_PAPER_CODESET, "paper-codeset", std, string) - ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_NAME, "LC_NAME", - ( - DEFINE_ELEMENT (_NL_NAME_NAME_FMT, "name_fmt", std, string) - DEFINE_ELEMENT (_NL_NAME_NAME_GEN, "name_gen", std, string) - DEFINE_ELEMENT (_NL_NAME_NAME_MR, "name_mr", std, string) - DEFINE_ELEMENT (_NL_NAME_NAME_MRS, "name_mrs", std, string) - DEFINE_ELEMENT (_NL_NAME_NAME_MISS, "name_miss", std, string) - DEFINE_ELEMENT (_NL_NAME_NAME_MS, "name_ms", std, string) - DEFINE_ELEMENT (_NL_NAME_CODESET, "name-codeset", std, string) - ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_ADDRESS, "LC_ADDRESS", - ( - DEFINE_ELEMENT (_NL_ADDRESS_POSTAL_FMT, "postal_fmt", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_NAME, "country_name", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_POST, "country_post", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_AB2, "country_ab2", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_AB3, "country_ab3", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_CAR, "country_car", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_NUM, "country_num", std, word) - DEFINE_ELEMENT (_NL_ADDRESS_COUNTRY_ISBN, "country_isbn", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_LANG_NAME, "lang_name", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_LANG_AB, "lang_ab", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_LANG_TERM, "lang_term", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_LANG_LIB, "lang_lib", std, string) - DEFINE_ELEMENT (_NL_ADDRESS_CODESET, "address-codeset", std, string) - ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_TELEPHONE, "LC_TELEPHONE", - ( - DEFINE_ELEMENT (_NL_TELEPHONE_TEL_INT_FMT, "tel_int_fmt", std, string) - DEFINE_ELEMENT (_NL_TELEPHONE_TEL_DOM_FMT, "tel_dom_fmt", std, string) - DEFINE_ELEMENT (_NL_TELEPHONE_INT_SELECT, "int_select", std, string) - DEFINE_ELEMENT (_NL_TELEPHONE_INT_PREFIX, "int_prefix", std, string) - DEFINE_ELEMENT (_NL_TELEPHONE_CODESET, "telephone-codeset", std, string) - ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_MEASUREMENT, "LC_MEASUREMENT", - ( - DEFINE_ELEMENT (_NL_MEASUREMENT_MEASUREMENT, "measurement", std, byte) - DEFINE_ELEMENT (_NL_MEASUREMENT_CODESET, "measurement-codeset", std, string) - ), NO_POSTLOAD) - -DEFINE_CATEGORY -( - LC_IDENTIFICATION, "LC_IDENTIFICATION", - ( - DEFINE_ELEMENT (_NL_IDENTIFICATION_TITLE, "title", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_SOURCE, "source", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_ADDRESS, "address", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_CONTACT, "contact", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_EMAIL, "email", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_TEL, "tel", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_FAX, "fax", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_LANGUAGE, "language", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_TERRITORY, "territory", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_AUDIENCE, "audience", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_APPLICATION, "applcation", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_ABBREVIATION, "abbreviation", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_REVISION, "revision", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_DATE, "date", std, string) - DEFINE_ELEMENT (_NL_IDENTIFICATION_CATEGORY, "category", std, stringarray, 13, 13) - DEFINE_ELEMENT (_NL_IDENTIFICATION_CODESET, "identification-codeset", std, string) - ), NO_POSTLOAD) diff --git a/src/system/libroot/posix/glibc/locale/duplocale.c b/src/system/libroot/posix/glibc/locale/duplocale.c deleted file mode 100644 index 2fe23fc6ad..0000000000 --- a/src/system/libroot/posix/glibc/locale/duplocale.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Duplicate handle for selection of locales. - Copyright (C) 1997, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -#include - - -/* Lock for protecting global data. */ -__libc_lock_define (extern , __libc_setlocale_lock) - - -__locale_t -__duplocale (__locale_t dataset) -{ - __locale_t result; - - /* We modify global data. */ - __libc_lock_lock (__libc_setlocale_lock); - - /* Get memory. */ - result = (__locale_t) malloc (sizeof (struct __locale_struct)); - if (result != NULL) - { - int cnt; - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - result->__locales[cnt] = dataset->__locales[cnt]; - if (result->__locales[cnt]->usage_count < MAX_USAGE_COUNT) - ++result->__locales[cnt]->usage_count; - } - } - - /* Update the special members. */ - result->__ctype_b = dataset->__ctype_b; - result->__ctype_tolower = dataset->__ctype_tolower; - result->__ctype_toupper = dataset->__ctype_toupper; - - /* It's done. */ - __libc_lock_unlock (__libc_setlocale_lock); - - return result; -} diff --git a/src/system/libroot/posix/glibc/locale/findlocale.c b/src/system/libroot/posix/glibc/locale/findlocale.c deleted file mode 100644 index 59b99925bf..0000000000 --- a/src/system/libroot/posix/glibc/locale/findlocale.c +++ /dev/null @@ -1,289 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#ifdef _POSIX_MAPPED_FILES -# include -#endif - -#include "localeinfo.h" -#include "../iconv/gconv_charset.h" - - -/* Constant data defined in setlocale.c. */ -extern struct locale_data *const _nl_C[]; - - -/* For each category we keep a list of records for the locale files - which are somehow addressed. */ -struct loaded_l10nfile *_nl_locale_file_list[__LC_LAST]; - - -struct locale_data * -_nl_find_locale (const char *locale_path, size_t locale_path_len, - int category, const char **name) -{ - int mask; - /* Name of the locale for this category. */ - char *loc_name; - const char *language; - const char *modifier; - const char *territory; - const char *codeset; - const char *normalized_codeset; - const char *special; - const char *sponsor; - const char *revision; - struct loaded_l10nfile *locale_file; - - if ((*name)[0] == '\0') - { - /* The user decides which locale to use by setting environment - variables. */ - *name = getenv ("LC_ALL"); - if (*name == NULL || (*name)[0] == '\0') - *name = getenv (_nl_category_names[category]); - if (*name == NULL || (*name)[0] == '\0') - *name = getenv ("LANG"); - } - - if (*name == NULL || (*name)[0] == '\0' - || (__builtin_expect (__libc_enable_secure, 0) - && strchr (*name, '/') != NULL)) - *name = (char *) _nl_C_name; - - if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0 - || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0) - { - /* We need not load anything. The needed data is contained in - the library itself. */ - *name = (char *) _nl_C_name; - return _nl_C[category]; - } - - /* We really have to load some data. First see whether the name is - an alias. Please note that this makes it impossible to have "C" - or "POSIX" as aliases. */ - loc_name = (char *) _nl_expand_alias (*name); - if (loc_name == NULL) - /* It is no alias. */ - loc_name = (char *) *name; - - /* Make a writable copy of the locale name. */ - loc_name = strdupa (loc_name); - - /* LOCALE can consist of up to four recognized parts for the XPG syntax: - - language[_territory[.codeset]][@modifier] - - and six parts for the CEN syntax: - - language[_territory][+audience][+special][,[sponsor][_revision]] - - Beside the first all of them are allowed to be missing. If the - full specified locale is not found, the less specific one are - looked for. The various part will be stripped of according to - the following order: - (1) revision - (2) sponsor - (3) special - (4) codeset - (5) normalized codeset - (6) territory - (7) audience/modifier - */ - mask = _nl_explode_name (loc_name, &language, &modifier, &territory, - &codeset, &normalized_codeset, &special, - &sponsor, &revision); - - /* If exactly this locale was already asked for we have an entry with - the complete name. */ - locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category], - locale_path, locale_path_len, mask, - language, territory, codeset, - normalized_codeset, modifier, special, - sponsor, revision, - _nl_category_names[category], 0); - - if (locale_file == NULL) - { - /* Find status record for addressed locale file. We have to search - through all directories in the locale path. */ - locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category], - locale_path, locale_path_len, mask, - language, territory, codeset, - normalized_codeset, modifier, special, - sponsor, revision, - _nl_category_names[category], 1); - if (locale_file == NULL) - /* This means we are out of core. */ - return NULL; - } - - /* The space for normalized_codeset is dynamically allocated. Free it. */ - if (mask & XPG_NORM_CODESET) - free ((void *) normalized_codeset); - - if (locale_file->decided == 0) - _nl_load_locale (locale_file, category); - - if (locale_file->data == NULL) - { - int cnt; - for (cnt = 0; locale_file->successor[cnt] != NULL; ++cnt) - { - if (locale_file->successor[cnt]->decided == 0) - _nl_load_locale (locale_file->successor[cnt], category); - if (locale_file->successor[cnt]->data != NULL) - break; - } - /* Move the entry we found (or NULL) to the first place of - successors. */ - locale_file->successor[0] = locale_file->successor[cnt]; - locale_file = locale_file->successor[cnt]; - - if (locale_file == NULL) - return NULL; - } - - /* The LC_CTYPE category allows to check whether a locale is really - usable. If the locale name contains a charset name and the - charset name used in the locale (present in the LC_CTYPE data) is - not the same (after resolving aliases etc) we reject the locale - since using it would irritate users expecting the charset named - in the locale name. */ - if (codeset != NULL) - { - /* Get the codeset information from the locale file. */ - static const int codeset_idx[] = - { - [__LC_CTYPE] = _NL_ITEM_INDEX (CODESET), - [__LC_NUMERIC] = _NL_ITEM_INDEX (_NL_NUMERIC_CODESET), - [__LC_TIME] = _NL_ITEM_INDEX (_NL_TIME_CODESET), - [__LC_COLLATE] = _NL_ITEM_INDEX (_NL_COLLATE_CODESET), - [__LC_MONETARY] = _NL_ITEM_INDEX (_NL_MONETARY_CODESET), - [__LC_MESSAGES] = _NL_ITEM_INDEX (_NL_MESSAGES_CODESET), - [__LC_PAPER] = _NL_ITEM_INDEX (_NL_PAPER_CODESET), - [__LC_NAME] = _NL_ITEM_INDEX (_NL_NAME_CODESET), - [__LC_ADDRESS] = _NL_ITEM_INDEX (_NL_ADDRESS_CODESET), - [__LC_TELEPHONE] = _NL_ITEM_INDEX (_NL_TELEPHONE_CODESET), - [__LC_MEASUREMENT] = _NL_ITEM_INDEX (_NL_MEASUREMENT_CODESET), - [__LC_IDENTIFICATION] = _NL_ITEM_INDEX (_NL_IDENTIFICATION_CODESET) - }; - const struct locale_data *data; - const char *locale_codeset; - char *clocale_codeset; - char *ccodeset; - - data = (const struct locale_data *) locale_file->data; - locale_codeset = - (const char *) data->values[codeset_idx[category]].string; - assert (locale_codeset != NULL); - /* Note the length of the allocated memory: +3 for up to two slashes - and the NUL byte. */ - clocale_codeset = (char *) alloca (strlen (locale_codeset) + 3); - strip (clocale_codeset, locale_codeset); - - ccodeset = (char *) alloca (strlen (codeset) + 3); - strip (ccodeset, codeset); - - if (__gconv_compare_alias (upstr (ccodeset, ccodeset), - upstr (clocale_codeset, - clocale_codeset)) != 0) - /* The codesets are not identical, don't use the locale. */ - return NULL; - } - - /* Determine the locale name for which loading succeeded. This - information comes from the file name. The form is - //LC_foo. We must extract the part. */ - if (((const struct locale_data *) locale_file->data)->name == NULL) - { - char *cp, *endp; - - endp = strrchr (locale_file->filename, '/'); - cp = endp - 1; - while (cp[-1] != '/') - --cp; - ((struct locale_data *) locale_file->data)->name = __strndup (cp, - endp - cp); - } - - /* Determine whether the user wants transliteration or not. */ - if ((modifier != NULL && __strcasecmp (modifier, "TRANSLIT") == 0) - || (special != NULL && __strcasecmp (special, "TRANSLIT") == 0)) - ((struct locale_data *) locale_file->data)->use_translit = 1; - - /* Increment the usage count. */ - if (((const struct locale_data *) locale_file->data)->usage_count - < MAX_USAGE_COUNT) - ++((struct locale_data *) locale_file->data)->usage_count; - - return (struct locale_data *) locale_file->data; -} - - -/* Calling this function assumes the lock for handling global locale data - is acquired. */ -void -_nl_remove_locale (int locale, struct locale_data *data) -{ - if (--data->usage_count == 0) - { - /* First search the entry in the list of loaded files. */ - struct loaded_l10nfile *ptr = _nl_locale_file_list[locale]; - - /* Search for the entry. It must be in the list. Otherwise it - is a bug and we crash badly. */ - while ((struct locale_data *) ptr->data != data) - ptr = ptr->next; - - /* Mark the data as not available anymore. So when the data has - to be used again it is reloaded. */ - ptr->decided = 0; - ptr->data = NULL; - - /* Free the name. */ - free ((char *) data->name); - -#ifdef _POSIX_MAPPED_FILES - /* Really delete the data. First delete the real data. */ - if (__builtin_expect (data->mmaped, 1)) - { - /* Try to unmap the area. If this fails we mark the area as - permanent. */ - if (__munmap ((caddr_t) data->filedata, data->filesize) != 0) - { - data->usage_count = UNDELETABLE; - return; - } - } - else -#endif /* _POSIX_MAPPED_FILES */ - /* The memory was malloced. */ - free ((void *) data->filedata); - - /* Now free the structure itself. */ - free (data); - } -} diff --git a/src/system/libroot/posix/glibc/locale/freelocale.c b/src/system/libroot/posix/glibc/locale/freelocale.c deleted file mode 100644 index 83d07b962c..0000000000 --- a/src/system/libroot/posix/glibc/locale/freelocale.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Free data allocated by a call to setlocale_r - Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -#include "localeinfo.h" - - -/* Lock for protecting global data. */ -__libc_lock_define (extern , __libc_setlocale_lock) - - -void -__freelocale (__locale_t dataset) -{ - int cnt; - - /* We modify global data. */ - __libc_lock_lock (__libc_setlocale_lock); - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL && dataset->__locales[cnt]->usage_count != UNDELETABLE) - /* We can remove the data. */ - _nl_remove_locale (cnt, dataset->__locales[cnt]); - - /* Free the locale_t handle itself. */ - free (dataset); - - /* It's done. */ - __libc_lock_unlock (__libc_setlocale_lock); -} diff --git a/src/system/libroot/posix/glibc/locale/global-locale.c b/src/system/libroot/posix/glibc/locale/global-locale.c deleted file mode 100644 index a5cae3c5d1..0000000000 --- a/src/system/libroot/posix/glibc/locale/global-locale.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Locale object representing the global locale controlled by setlocale. - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include "localeinfo.h" - -#define DEFINE_CATEGORY(category, category_name, items, a) \ -extern struct locale_data _nl_C_##category; weak_extern (_nl_C_##category) -#include "categories.def" -#undef DEFINE_CATEGORY - -/* Defined in locale/C-ctype.c. */ -extern const char _nl_C_LC_CTYPE_class[] attribute_hidden; -extern const char _nl_C_LC_CTYPE_toupper[] attribute_hidden; -extern const char _nl_C_LC_CTYPE_tolower[] attribute_hidden; -weak_extern (_nl_C_LC_CTYPE_class) -weak_extern (_nl_C_LC_CTYPE_toupper) -weak_extern (_nl_C_LC_CTYPE_tolower) - -/* Here we define the locale object maintained by setlocale. - The references in the initializer are weak, so the parts of - the structure that are never referred to will be zero. */ - -struct __locale_struct _nl_global_locale attribute_hidden = - { - .__locales = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = &_nl_C_##category, -#include "categories.def" -#undef DEFINE_CATEGORY - }, - .__names = - { - [LC_ALL] = _nl_C_name, -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = _nl_C_name, -#include "categories.def" -#undef DEFINE_CATEGORY - }, - .__ctype_b = (const unsigned short int *) _nl_C_LC_CTYPE_class + 128, - .__ctype_tolower = (const int *) _nl_C_LC_CTYPE_tolower + 128, - .__ctype_toupper = (const int *) _nl_C_LC_CTYPE_toupper + 128 - }; - -#include -#if USE_TLS && HAVE___THREAD -/* The tsd macros don't permit an initializer. */ -__thread void *__libc_tsd_LOCALE = &_nl_global_locale; -#else -__libc_tsd_define (, LOCALE) -/* This is a bad kludge presuming the variable name used by the macros. - Using typeof makes sure to barf if we do not match the macro definition. - This ifndef is a further bad kludge for Hurd, where there is an explicit - initialization. */ -# ifndef _HURD_THREADVAR_H -__typeof (__libc_tsd_LOCALE_data) __libc_tsd_LOCALE_data = &_nl_global_locale; -# endif -#endif diff --git a/src/system/libroot/posix/glibc/locale/hashval.h b/src/system/libroot/posix/glibc/locale/hashval.h deleted file mode 100644 index 52ef8b5da9..0000000000 --- a/src/system/libroot/posix/glibc/locale/hashval.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Implement simple hashing table with string based keys. - Copyright (C) 1994-1997, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , October 1994. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef hashval_t -# define hashval_t unsigned long int -#endif -#include /* For CHAR_BIT. */ - -hashval_t -compute_hashval (const void *key, size_t keylen) -{ - size_t cnt; - hashval_t hval; - - /* Compute the hash value for the given string. The algorithm - is taken from [Aho,Sethi,Ullman], modified to reduce the number of - collisions for short strings with very varied bit patterns. - See http://www.clisp.org/haible/hashfunc.html. */ - cnt = 0; - hval = keylen; - while (cnt < keylen) - { - hval = (hval << 9) | (hval >> (sizeof hval * CHAR_BIT - 9)); - hval += (hashval_t) *(((char *) key) + cnt++); - } - return hval != 0 ? hval : ~((hashval_t) 0); -} diff --git a/src/system/libroot/posix/glibc/locale/indigits.h b/src/system/libroot/posix/glibc/locale/indigits.h deleted file mode 100644 index b0bf40d53a..0000000000 --- a/src/system/libroot/posix/glibc/locale/indigits.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Look up the value of the next multibyte character and return its numerical - value if it is one of the digits known in the locale. If *DECIDED is - -1 this means it is not yet decided which form it is and we have to - search through all available digits. Otherwise we know which script - the digits are from. */ -static inline int -indigit_value (const char **s, size_t *len, int *decided) -{ - int from_level; - int to_level; - const char *mbdigits[10]; - int i; - int n; - - if (*decided != -1) - from_level = to_level = *decided; - else - { - from_level = 0; - to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_MB_LEN) - 1; - assert (from_level <= to_level); - } - - /* In this round we get the pointer to the digit strings and also perform - the first round of comparisons. */ - for (n = 0; n < 10; ++n) - { - size_t dlen; - - /* Get the string for the digits with value N. */ - mbdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_MB + n); - dlen = strlen (mbdigits[n]); - - if (from_level == 0 && dlen <= *len - && memcmp (*s, mbdigits[n], dlen) == 0) - { - /* Found it. */ - *s += dlen; - *len -= dlen; - if (*decided == -1) - *decided = 0; - return n; - } - - /* Advance the pointer to the next string. */ - mbdigits[n] += dlen + 1; - } - - /* Now perform the remaining tests. */ - for (i = 1; i <= to_level; ++i) - { - /* Search all ten digits of this level. */ - for (n = 0; n < 10; ++n) - { - size_t dlen = strlen (mbdigits[n]); - - if (i >= from_level && dlen <= *len - && memcmp (*s, mbdigits[n], dlen) == 0) - { - /* Found it. */ - *s += dlen; - *len -= dlen; - if (*decided == -1) - *decided = from_level; - return n; - } - - /* Advance the pointer to the next string. */ - mbdigits[n] += dlen + 1; - } - } - - /* If we reach this point no matching digit was found. */ - return -1; -} diff --git a/src/system/libroot/posix/glibc/locale/indigitswc.h b/src/system/libroot/posix/glibc/locale/indigitswc.h deleted file mode 100644 index d09de8989f..0000000000 --- a/src/system/libroot/posix/glibc/locale/indigitswc.h +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -/* Look up the value of the next multibyte character and return its numerical - value if it is one of the digits known in the locale. If *DECIDED is - -1 this means it is not yet decided which form it is and we have to - search through all available digits. Otherwise we know which script - the digits are from. */ -static inline int -indigitwc_value (wchar_t wc, int *decided) -{ - int from_level; - int to_level; - const wchar_t *wcdigits[10]; - int n; - - if (*decided != -1) - from_level = to_level = *decided; - else - { - from_level = 0; - to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_WC_LEN) - 1; - assert (from_level <= to_level); - } - - /* In this round we get the pointer to the digit strings and also perform - the first round of comparisons. */ - for (n = 0; n < 10; ++n) - { - /* Get the string for the digits with value N. */ - wcdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n); - wcdigits[n] += from_level; - - if (wc == *wcdigits[n]) - { - /* Found it. */ - if (*decided == -1) - *decided = 0; - return n; - } - - /* Advance the pointer to the next string. */ - ++wcdigits[n]; - } - - /* Now perform the remaining tests. */ - while (++from_level <= to_level) - { - /* Search all ten digits of this level. */ - for (n = 0; n < 10; ++n) - { - if (wc == *wcdigits[n]) - { - /* Found it. */ - if (*decided == -1) - *decided = from_level; - return n; - } - - /* Advance the pointer to the next string. */ - ++wcdigits[n]; - } - } - - /* If we reach this point no matching digit was found. */ - return -1; -} diff --git a/src/system/libroot/posix/glibc/locale/iso-3166.def b/src/system/libroot/posix/glibc/locale/iso-3166.def deleted file mode 100644 index 43a6ae1085..0000000000 --- a/src/system/libroot/posix/glibc/locale/iso-3166.def +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Defines the country codes and abbreviations according to ISO 3166. - * This is used in ld-address.c (address_finish). - * - * If you find something missing or wrong contact - */ -DEFINE_COUNTRY_CODE ("AFGHANISTAN", AF, AFG, 4) -DEFINE_COUNTRY_CODE ("ALBANIA", AL, ALB, 8) -DEFINE_COUNTRY_CODE ("ALGERIA", DZ, DZA, 12) -DEFINE_COUNTRY_CODE ("AMERICAN SAMOA", AS, ASM, 16) -DEFINE_COUNTRY_CODE ("ANDORRA", AD, AND, 20) -DEFINE_COUNTRY_CODE ("ANGOLA", AO, AGO, 24) -DEFINE_COUNTRY_CODE ("ANGUILLA", AI, AIA, 660) -DEFINE_COUNTRY_CODE ("ANTARCTICA", AQ, ATA, 10) -DEFINE_COUNTRY_CODE ("ANTIGUA AND BARBUDA", AG, ATG, 28) -DEFINE_COUNTRY_CODE ("ARGENTINA", AR, ARG, 32) -DEFINE_COUNTRY_CODE ("ARMENIA", AM, ARM, 51) -DEFINE_COUNTRY_CODE ("ARUBA", AW, ABW, 533) -DEFINE_COUNTRY_CODE ("AUSTRALIA", AU, AUS, 36) -DEFINE_COUNTRY_CODE ("AUSTRIA", AT, AUT, 40) -DEFINE_COUNTRY_CODE ("AZERBAIJAN", AZ, AZE, 31) -DEFINE_COUNTRY_CODE ("BAHAMAS", BS, BHS, 44) -DEFINE_COUNTRY_CODE ("BAHRAIN", BH, BHR, 48) -DEFINE_COUNTRY_CODE ("BANGLADESH", BD, BGD, 50) -DEFINE_COUNTRY_CODE ("BARBADOS", BB, BRB, 52) -DEFINE_COUNTRY_CODE ("BELARUS", BY, BLR, 112) -DEFINE_COUNTRY_CODE ("BELGIUM", BE, BEL, 56) -DEFINE_COUNTRY_CODE ("BELIZE", BZ, BLZ, 84) -DEFINE_COUNTRY_CODE ("BENIN", BJ, BEN, 204) -DEFINE_COUNTRY_CODE ("BERMUDA", BM, BMU, 60) -DEFINE_COUNTRY_CODE ("BHUTAN", BT, BTN, 64) -DEFINE_COUNTRY_CODE ("BOLIVIA", BO, BOL, 68) -DEFINE_COUNTRY_CODE ("BOSNIA AND HERZEGOVINA", BA, BIH, 70) -DEFINE_COUNTRY_CODE ("BOTSWANA", BW, BWA, 72) -DEFINE_COUNTRY_CODE ("BOUVET ISLAND", BV, BVT, 74) -DEFINE_COUNTRY_CODE ("BRAZIL", BR, BRA, 76) -DEFINE_COUNTRY_CODE ("BRITISH INDIAN OCEAN TERRITORY", IO, IOT, 86) -DEFINE_COUNTRY_CODE ("BRUNEI DARUSSALAM", BN, BRN, 96) -DEFINE_COUNTRY_CODE ("BULGARIA", BG, BGR, 100) -DEFINE_COUNTRY_CODE ("BURKINA FASO", BF, BFA, 854) -DEFINE_COUNTRY_CODE ("BURUNDI", BI, BDI, 108) -DEFINE_COUNTRY_CODE ("CAMBODIA", KH, KHM, 116) -DEFINE_COUNTRY_CODE ("CAMEROON", CM, CMR, 120) -DEFINE_COUNTRY_CODE ("CANADA", CA, CAN, 124) -DEFINE_COUNTRY_CODE ("CAPE VERDE", CV, CPV, 132) -DEFINE_COUNTRY_CODE ("CAYMAN ISLANDS", KY, CYM, 136) -DEFINE_COUNTRY_CODE ("CENTRAL AFRICAN REPUBLIC", CF, CAF, 140) -DEFINE_COUNTRY_CODE ("CHAD", TD, TCD, 148) -DEFINE_COUNTRY_CODE ("CHILE", CL, CHL, 152) -DEFINE_COUNTRY_CODE ("CHINA", CN, CHN, 156) -DEFINE_COUNTRY_CODE ("CHRISTMAS ISLAND", CX, CXR, 162) -DEFINE_COUNTRY_CODE ("COCOS (KEELING) ISLANDS", CC, CCK, 166) -DEFINE_COUNTRY_CODE ("COLOMBIA", CO, COL, 170) -DEFINE_COUNTRY_CODE ("COMOROS", KM, COM, 174) -DEFINE_COUNTRY_CODE ("CONGO", CG, COG, 178) -DEFINE_COUNTRY_CODE ("CONGO, THE DEMOCRATIC REPUBLIC OF THE", CD, COD, 180) -DEFINE_COUNTRY_CODE ("COOK ISLANDS", CK, COK, 184) -DEFINE_COUNTRY_CODE ("COSTA RICA", CR, CRI, 188) -DEFINE_COUNTRY_CODE ("COTE D'IVOIRE", CI, CIV, 384) -DEFINE_COUNTRY_CODE ("CROATIA", HR, HRV, 191) -DEFINE_COUNTRY_CODE ("CUBA", CU, CUB, 192) -DEFINE_COUNTRY_CODE ("CYPRUS", CY, CYP, 196) -DEFINE_COUNTRY_CODE ("CZECH REPUBLIC", CZ, CZE, 203) -DEFINE_COUNTRY_CODE ("DENMARK", DK, DNK, 208) -DEFINE_COUNTRY_CODE ("DJIBOUTI", DJ, DJI, 262) -DEFINE_COUNTRY_CODE ("DOMINICA", DM, DMA, 212) -DEFINE_COUNTRY_CODE ("DOMINICAN REPUBLIC", DO, DOM, 214) -DEFINE_COUNTRY_CODE ("EAST TIMOR", TP, TMP, 626) -DEFINE_COUNTRY_CODE ("ECUADOR", EC, ECU, 218) -DEFINE_COUNTRY_CODE ("EGYPT", EG, EGY, 818) -DEFINE_COUNTRY_CODE ("EL SALVADOR", SV, SLV, 222) -DEFINE_COUNTRY_CODE ("EQUATORIAL GUINEA", GQ, GNQ, 226) -DEFINE_COUNTRY_CODE ("ERITREA", ER, ERI, 232) -DEFINE_COUNTRY_CODE ("ESTONIA", EE, EST, 233) -DEFINE_COUNTRY_CODE ("ETHIOPIA", ET, ETH, 231) -DEFINE_COUNTRY_CODE ("FALKLAND ISLANDS (MALVINAS)", FK, FLK, 238) -DEFINE_COUNTRY_CODE ("FAROE ISLANDS", FO, FRO, 234) -DEFINE_COUNTRY_CODE ("FIJI", FJ, FJI, 242) -DEFINE_COUNTRY_CODE ("FINLAND", FI, FIN, 246) -DEFINE_COUNTRY_CODE ("FRANCE", FR, FRA, 250) -DEFINE_COUNTRY_CODE ("FRENCH GUIANA", GF, GUF, 254) -DEFINE_COUNTRY_CODE ("FRENCH POLYNESIA", PF, PYF, 258) -DEFINE_COUNTRY_CODE ("FRENCH SOUTHERN TERRITORIES", TF, ATF, 260) -DEFINE_COUNTRY_CODE ("GABON", GA, GAB, 266) -DEFINE_COUNTRY_CODE ("GAMBIA", GM, GMB, 270) -DEFINE_COUNTRY_CODE ("GEORGIA", GE, GEO, 268) -DEFINE_COUNTRY_CODE ("GERMANY", DE, DEU, 276) -DEFINE_COUNTRY_CODE ("GHANA", GH, GHA, 288) -DEFINE_COUNTRY_CODE ("GIBRALTAR", GI, GIB, 292) -DEFINE_COUNTRY_CODE ("GREECE", GR, GRC, 300) -DEFINE_COUNTRY_CODE ("GREENLAND", GL, GRL, 304) -DEFINE_COUNTRY_CODE ("GRENADA", GD, GRD, 308) -DEFINE_COUNTRY_CODE ("GUADELOUPE", GP, GLP, 312) -DEFINE_COUNTRY_CODE ("GUAM", GU, GUM, 316) -DEFINE_COUNTRY_CODE ("GUATEMALA", GT, GTM, 320) -DEFINE_COUNTRY_CODE ("GUINEA", GN, GIN, 324) -DEFINE_COUNTRY_CODE ("GUINEA-BISSAU", GW, GNB, 624) -DEFINE_COUNTRY_CODE ("GUYANA", GY, GUY, 328) -DEFINE_COUNTRY_CODE ("HAITI", HT, HTI, 332) -DEFINE_COUNTRY_CODE ("HEARD ISLAND AND MCDONALD ISLANDS", HM, HMD, 334) -DEFINE_COUNTRY_CODE ("HOLY SEE (VATICAN CITY STATE)", VA, VAT, 336) -DEFINE_COUNTRY_CODE ("HONDURAS", HN, HND, 340) -DEFINE_COUNTRY_CODE ("HONG KONG", HK, HKG, 344) -DEFINE_COUNTRY_CODE ("HUNGARY", HU, HUN, 348) -DEFINE_COUNTRY_CODE ("ICELAND", IS, ISL, 352) -DEFINE_COUNTRY_CODE ("INDIA", IN, IND, 356) -DEFINE_COUNTRY_CODE ("INDONESIA", ID, IDN, 360) -DEFINE_COUNTRY_CODE ("IRAN, ISLAMIC REPUBLIC OF", IR, IRN, 364) -DEFINE_COUNTRY_CODE ("IRAQ", IQ, IRQ, 368) -DEFINE_COUNTRY_CODE ("IRELAND", IE, IRL, 372) -DEFINE_COUNTRY_CODE ("ISRAEL", IL, ISR, 376) -DEFINE_COUNTRY_CODE ("ITALY", IT, ITA, 380) -DEFINE_COUNTRY_CODE ("JAMAICA", JM, JAM, 388) -DEFINE_COUNTRY_CODE ("JAPAN", JP, JPN, 392) -DEFINE_COUNTRY_CODE ("JORDAN", JO, JOR, 400) -DEFINE_COUNTRY_CODE ("KAZAKSTAN", KZ, KAZ, 398) -DEFINE_COUNTRY_CODE ("KENYA", KE, KEN, 404) -DEFINE_COUNTRY_CODE ("KIRIBATI", KI, KIR, 296) -DEFINE_COUNTRY_CODE ("KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF", KP, PRK, 408) -DEFINE_COUNTRY_CODE ("KOREA, REPUBLIC OF", KR, KOR, 410) -DEFINE_COUNTRY_CODE ("KUWAIT", KW, KWT, 414) -DEFINE_COUNTRY_CODE ("KYRGYZSTAN", KG, KGZ, 417) -DEFINE_COUNTRY_CODE ("LAO PEOPLE'S DEMOCRATIC REPUBLIC", LA, LAO, 418) -DEFINE_COUNTRY_CODE ("LATVIA", LV, LVA, 428) -DEFINE_COUNTRY_CODE ("LEBANON", LB, LBN, 422) -DEFINE_COUNTRY_CODE ("LESOTHO", LS, LSO, 426) -DEFINE_COUNTRY_CODE ("LIBERIA", LR, LBR, 430) -DEFINE_COUNTRY_CODE ("LIBYAN ARAB JAMAHIRIYA", LY, LBY, 434) -DEFINE_COUNTRY_CODE ("LIECHTENSTEIN", LI, LIE, 438) -DEFINE_COUNTRY_CODE ("LITHUANIA", LT, LTU, 440) -DEFINE_COUNTRY_CODE ("LUXEMBOURG", LU, LUX, 442) -DEFINE_COUNTRY_CODE ("MACAU", MO, MAC, 446) -DEFINE_COUNTRY_CODE ("MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF", MK, MKD, 807) -DEFINE_COUNTRY_CODE ("MADAGASCAR", MG, MDG, 450) -DEFINE_COUNTRY_CODE ("MALAWI", MW, MWI, 454) -DEFINE_COUNTRY_CODE ("MALAYSIA", MY, MYS, 458) -DEFINE_COUNTRY_CODE ("MALDIVES", MV, MDV, 462) -DEFINE_COUNTRY_CODE ("MALI", ML, MLI, 466) -DEFINE_COUNTRY_CODE ("MALTA", MT, MLT, 470) -DEFINE_COUNTRY_CODE ("MARSHALL ISLANDS", MH, MHL, 584) -DEFINE_COUNTRY_CODE ("MARTINIQUE", MQ, MTQ, 474) -DEFINE_COUNTRY_CODE ("MAURITANIA", MR, MRT, 478) -DEFINE_COUNTRY_CODE ("MAURITIUS", MU, MUS, 480) -DEFINE_COUNTRY_CODE ("MAYOTTE", YT, MYT, 175) -DEFINE_COUNTRY_CODE ("MEXICO", MX, MEX, 484) -DEFINE_COUNTRY_CODE ("MICRONESIA, FEDERATED STATES OF", FM, FSM, 583) -DEFINE_COUNTRY_CODE ("MOLDOVA, REPUBLIC OF", MD, MDA, 498) -DEFINE_COUNTRY_CODE ("MONACO", MC, MCO, 492) -DEFINE_COUNTRY_CODE ("MONGOLIA", MN, MNG, 496) -DEFINE_COUNTRY_CODE ("MONTSERRAT", MS, MSR, 500) -DEFINE_COUNTRY_CODE ("MOROCCO", MA, MAR, 504) -DEFINE_COUNTRY_CODE ("MOZAMBIQUE", MZ, MOZ, 508) -DEFINE_COUNTRY_CODE ("MYANMAR", MM, MMR, 104) -DEFINE_COUNTRY_CODE ("NAMIBIA", NA, NAM, 516) -DEFINE_COUNTRY_CODE ("NAURU", NR, NRU, 520) -DEFINE_COUNTRY_CODE ("NEPAL", NP, NPL, 524) -DEFINE_COUNTRY_CODE ("NETHERLANDS", NL, NLD, 528) -DEFINE_COUNTRY_CODE ("NETHERLANDS ANTILLES", AN, ANT, 530) -DEFINE_COUNTRY_CODE ("NEW CALEDONIA", NC, NCL, 540) -DEFINE_COUNTRY_CODE ("NEW ZEALAND", NZ, NZL, 554) -DEFINE_COUNTRY_CODE ("NICARAGUA", NI, NIC, 558) -DEFINE_COUNTRY_CODE ("NIGER", NE, NER, 562) -DEFINE_COUNTRY_CODE ("NIGERIA", NG, NGA, 566) -DEFINE_COUNTRY_CODE ("NIUE", NU, NIU, 570) -DEFINE_COUNTRY_CODE ("NORFOLK ISLAND", NF, NFK, 574) -DEFINE_COUNTRY_CODE ("NORTHERN MARIANA ISLANDS", MP, MNP, 580) -DEFINE_COUNTRY_CODE ("NORWAY", NO, NOR, 578) -DEFINE_COUNTRY_CODE ("OMAN", OM, OMN, 512) -DEFINE_COUNTRY_CODE ("PAKISTAN", PK, PAK, 586) -DEFINE_COUNTRY_CODE ("PALAU", PW, PLW, 585) -DEFINE_COUNTRY_CODE ("PALESTINIAN TERRITORY, OCCUPIED", PS, PSE, 275) -DEFINE_COUNTRY_CODE ("PANAMA", PA, PAN, 591) -DEFINE_COUNTRY_CODE ("PAPUA NEW GUINEA", PG, PNG, 598) -DEFINE_COUNTRY_CODE ("PARAGUAY", PY, PRY, 600) -DEFINE_COUNTRY_CODE ("PERU", PE, PER, 604) -DEFINE_COUNTRY_CODE ("PHILIPPINES", PH, PHL, 608) -DEFINE_COUNTRY_CODE ("PITCAIRN", PN, PCN, 612) -DEFINE_COUNTRY_CODE ("POLAND", PL, POL, 616) -DEFINE_COUNTRY_CODE ("PORTUGAL", PT, PRT, 620) -DEFINE_COUNTRY_CODE ("PUERTO RICO", PR, PRI, 630) -DEFINE_COUNTRY_CODE ("QATAR", QA, QAT, 634) -DEFINE_COUNTRY_CODE ("REUNION", RE, REU, 638) -DEFINE_COUNTRY_CODE ("ROMANIA", RO, ROM, 642) -DEFINE_COUNTRY_CODE ("RUSSIAN FEDERATION", RU, RUS, 643) -DEFINE_COUNTRY_CODE ("RWANDA", RW, RWA, 646) -DEFINE_COUNTRY_CODE ("SAINT HELENA", SH, SHN, 654) -DEFINE_COUNTRY_CODE ("SAINT KITTS AND NEVIS", KN, KNA, 659) -DEFINE_COUNTRY_CODE ("SAINT LUCIA", LC, LCA, 662) -DEFINE_COUNTRY_CODE ("SAINT PIERRE AND MIQUELON", PM, SPM, 666) -DEFINE_COUNTRY_CODE ("SAINT VINCENT AND THE GRENADINES", VC, VCT, 670) -DEFINE_COUNTRY_CODE ("SAMOA", WS, WSM, 882) -DEFINE_COUNTRY_CODE ("SAN MARINO", SM, SMR, 674) -DEFINE_COUNTRY_CODE ("SAO TOME AND PRINCIPE", ST, STP, 678) -DEFINE_COUNTRY_CODE ("SAUDI ARABIA", SA, SAU, 682) -DEFINE_COUNTRY_CODE ("SENEGAL", SN, SEN, 686) -DEFINE_COUNTRY_CODE ("SEYCHELLES", SC, SYC, 690) -DEFINE_COUNTRY_CODE ("SIERRA LEONE", SL, SLE, 694) -DEFINE_COUNTRY_CODE ("SINGAPORE", SG, SGP, 702) -DEFINE_COUNTRY_CODE ("SLOVAKIA", SK, SVK, 703) -DEFINE_COUNTRY_CODE ("SLOVENIA", SI, SVN, 705) -DEFINE_COUNTRY_CODE ("SOLOMON ISLANDS", SB, SLB, 90) -DEFINE_COUNTRY_CODE ("SOMALIA", SO, SOM, 706) -DEFINE_COUNTRY_CODE ("SOUTH AFRICA", ZA, ZAF, 710) -DEFINE_COUNTRY_CODE ("SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS", GS, SGS, 239) -DEFINE_COUNTRY_CODE ("SPAIN", ES, ESP, 724) -DEFINE_COUNTRY_CODE ("SRI LANKA", LK, LKA, 144) -DEFINE_COUNTRY_CODE ("SUDAN", SD, SDN, 736) -DEFINE_COUNTRY_CODE ("SURINAME", SR, SUR, 740) -DEFINE_COUNTRY_CODE ("SVALBARD AND JAN MAYEN", SJ, SJM, 744) -DEFINE_COUNTRY_CODE ("SWAZILAND", SZ, SWZ, 748) -DEFINE_COUNTRY_CODE ("SWEDEN", SE, SWE, 752) -DEFINE_COUNTRY_CODE ("SWITZERLAND", CH, CHE, 756) -DEFINE_COUNTRY_CODE ("SYRIAN ARAB REPUBLIC", SY, SYR, 760) -DEFINE_COUNTRY_CODE ("TAIWAN, PROVINCE OF CHINA", TW, TWN, 158) -DEFINE_COUNTRY_CODE ("TAJIKISTAN", TJ, TJK, 762) -DEFINE_COUNTRY_CODE ("TANZANIA, UNITED REPUBLIC OF", TZ, TZA, 834) -DEFINE_COUNTRY_CODE ("THAILAND", TH, THA, 764) -DEFINE_COUNTRY_CODE ("TOGO", TG, TGO, 768) -DEFINE_COUNTRY_CODE ("TOKELAU", TK, TKL, 772) -DEFINE_COUNTRY_CODE ("TONGA", TO, TON, 776) -DEFINE_COUNTRY_CODE ("TRINIDAD AND TOBAGO", TT, TTO, 780) -DEFINE_COUNTRY_CODE ("TUNISIA", TN, TUN, 788) -DEFINE_COUNTRY_CODE ("TURKEY", TR, TUR, 792) -DEFINE_COUNTRY_CODE ("TURKMENISTAN", TM, TKM, 795) -DEFINE_COUNTRY_CODE ("TURKS AND CAICOS ISLANDS", TC, TCA, 796) -DEFINE_COUNTRY_CODE ("TUVALU", TV, TUV, 798) -DEFINE_COUNTRY_CODE ("UGANDA", UG, UGA, 800) -DEFINE_COUNTRY_CODE ("UKRAINE", UA, UKR, 804) -DEFINE_COUNTRY_CODE ("UNITED ARAB EMIRATES", AE, ARE, 784) -DEFINE_COUNTRY_CODE ("UNITED KINGDOM", GB, GBR, 826) -DEFINE_COUNTRY_CODE ("UNITED STATES", US, USA, 840) -DEFINE_COUNTRY_CODE ("UNITED STATES MINOR OUTLYING ISLANDS", UM, UMI, 581) -DEFINE_COUNTRY_CODE ("URUGUAY", UY, URY, 858) -DEFINE_COUNTRY_CODE ("UZBEKISTAN", UZ, UZB, 860) -DEFINE_COUNTRY_CODE ("VANUATU", VU, VUT, 548) -DEFINE_COUNTRY_CODE ("VENEZUELA", VE, VEN, 862) -DEFINE_COUNTRY_CODE ("VIET NAM", VN, VNM, 704) -DEFINE_COUNTRY_CODE ("VIRGIN ISLANDS, BRITISH", VG, VGB, 92) -DEFINE_COUNTRY_CODE ("VIRGIN ISLANDS, U.S.", VI, VIR, 850) -DEFINE_COUNTRY_CODE ("WALLIS AND FUTUNA", WF, WLF, 876) -DEFINE_COUNTRY_CODE ("WESTERN SAHARA", EH, ESH, 732) -DEFINE_COUNTRY_CODE ("YEMEN", YE, YEM, 887) -DEFINE_COUNTRY_CODE ("YUGOSLAVIA", YU, YUG, 891) -DEFINE_COUNTRY_CODE ("ZAMBIA", ZM, ZMB, 894) -DEFINE_COUNTRY_CODE ("ZIMBABWE", ZW, ZWE, 716) diff --git a/src/system/libroot/posix/glibc/locale/iso-4217.def b/src/system/libroot/posix/glibc/locale/iso-4217.def deleted file mode 100644 index 2524054196..0000000000 --- a/src/system/libroot/posix/glibc/locale/iso-4217.def +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Defines the valid international currency symbols according to ISO 4217. - * This is used in monetary.c(monetary_check). - * - * If you find something missing or wrong contact - * - * !!! The list has to be sorted !!! - */ -DEFINE_INT_CURR("ADP ") /* Andorran Peseta */ -DEFINE_INT_CURR("AED ") /* United Arab Emirates Dirham */ -DEFINE_INT_CURR("AFA ") /* Afghanistan Afgani */ -DEFINE_INT_CURR("ALL ") /* Albanian Lek */ -DEFINE_INT_CURR("AMD ") /* Armenia Dram */ -DEFINE_INT_CURR("ANG ") /* Netherlands Antilles */ -DEFINE_INT_CURR("AON ") /* Angolan New Kwanza */ -DEFINE_INT_CURR("ARS ") /* Argentine Peso */ -DEFINE_INT_CURR("ATS ") /* Austrian Schilling */ -DEFINE_INT_CURR("AUD ") /* Australian Dollar */ -DEFINE_INT_CURR("AWG ") /* Aruba Guilder */ -DEFINE_INT_CURR("AZM ") /* Azerbaijan Manat */ -DEFINE_INT_CURR("BAK ") /* Bosnian and Herzegovina Convertible Mark */ -DEFINE_INT_CURR("BBD ") /* Barbados Dollar */ -DEFINE_INT_CURR("BDT ") /* Bangladesh Taka */ -DEFINE_INT_CURR("BEF ") /* Belgian Franc */ -DEFINE_INT_CURR("BGL ") /* Bulgarian Lev */ -DEFINE_INT_CURR("BHD ") /* Bahraini Dinar */ -DEFINE_INT_CURR("BIF ") /* Burundi Franc */ -DEFINE_INT_CURR("BMD ") /* Burmudian Dollar */ -DEFINE_INT_CURR("BND ") /* Brunei Dollar */ -DEFINE_INT_CURR("BOB ") /* Bolivian Boliviano */ -DEFINE_INT_CURR("BPS ") /* Canton and Enderbury Islands */ /* ?? */ -DEFINE_INT_CURR("BRE ") /* Brazil Real */ /* obsolete */ -DEFINE_INT_CURR("BRL ") /* Brazil Cruzeiro */ -DEFINE_INT_CURR("BSD ") /* Bahamas Dollar */ -DEFINE_INT_CURR("BTN ") /* Bhutan Ngultrum */ -DEFINE_INT_CURR("BUK ") /* Burma */ /* obsolete */ -DEFINE_INT_CURR("BWP ") /* Botswana Pula */ -DEFINE_INT_CURR("BYB ") /* Belarus Ruble */ -DEFINE_INT_CURR("BZD ") /* Belize Dollar */ -DEFINE_INT_CURR("CAD ") /* Canadian Dollar */ -DEFINE_INT_CURR("CDF ") /* Congo Dem.Rep. Franc */ -DEFINE_INT_CURR("CFP ") /* French Pacific Island Franc */ /* ??*/ -DEFINE_INT_CURR("CHF ") /* Swiss Franc (Liechtenstein) */ -DEFINE_INT_CURR("CLP ") /* Chilean Peso */ -DEFINE_INT_CURR("CNY ") /* China Yuan Renminbi */ -DEFINE_INT_CURR("COP ") /* Colombian Peso */ -DEFINE_INT_CURR("CRC ") /* Costa Rican Colon */ -DEFINE_INT_CURR("CUP ") /* Cuban Peso */ -DEFINE_INT_CURR("CVE ") /* Cape Verde Escudo */ -DEFINE_INT_CURR("CYP ") /* Cypriot Pound */ -DEFINE_INT_CURR("CZK ") /* Czech Koruna */ -DEFINE_INT_CURR("DEM ") /* German Mark */ -DEFINE_INT_CURR("DJF ") /* Djibouti Franc */ -DEFINE_INT_CURR("DKK ") /* Danish Krone (Faroe Islands, Greenland) */ -DEFINE_INT_CURR("DOP ") /* Dominican Republic */ -DEFINE_INT_CURR("DZD ") /* Algerian Dinar */ -DEFINE_INT_CURR("ECS ") /* Ecuadoran Sucre */ -DEFINE_INT_CURR("EEK ") /* Estonian Kroon */ -DEFINE_INT_CURR("EGP ") /* Egyptian Pound */ -DEFINE_INT_CURR("ERN ") /* Eritrean Nakfa */ -DEFINE_INT_CURR("ESP ") /* Spanish Peseta */ -DEFINE_INT_CURR("ETB ") /* Ethiopian Birr */ -DEFINE_INT_CURR("EUR ") /* European Union Euro */ -DEFINE_INT_CURR("FIM ") /* Finnish Markka */ -DEFINE_INT_CURR("FJD ") /* Fiji Dollar */ -DEFINE_INT_CURR("FKP ") /* Falkland Islands Pound (Malvinas) */ -DEFINE_INT_CURR("FRF ") /* French Franc */ -DEFINE_INT_CURR("GBP ") /* British Pound */ -DEFINE_INT_CURR("GEL ") /* Georgia Lari */ -DEFINE_INT_CURR("GHC ") /* Ghana Cedi */ -DEFINE_INT_CURR("GIP ") /* Gibraltar Pound */ -DEFINE_INT_CURR("GMD ") /* Gambian Dalasi */ -DEFINE_INT_CURR("GNF ") /* Guinea Franc */ -DEFINE_INT_CURR("GNS ") /* Guinea Syli */ -DEFINE_INT_CURR("GQE ") /* Equatorial Guinea Ekwele */ -DEFINE_INT_CURR("GRD ") /* Greek Drachma */ -DEFINE_INT_CURR("GTQ ") /* Guatemala Quetzal */ -DEFINE_INT_CURR("GWP ") /* Guinea-Bissau Peso */ -DEFINE_INT_CURR("GYD ") /* Guyana Dollar */ -DEFINE_INT_CURR("HKD ") /* Hong Kong Dollar */ -DEFINE_INT_CURR("HNL ") /* Honduras Lempira */ -DEFINE_INT_CURR("HRK ") /* Croatia Kuna */ -DEFINE_INT_CURR("HTG ") /* Haiti Gourde */ -DEFINE_INT_CURR("HUF ") /* Hungarian Forint */ -DEFINE_INT_CURR("IDR ") /* Indonesia Rupiah */ -DEFINE_INT_CURR("IEP ") /* Irish Pound */ -DEFINE_INT_CURR("ILS ") /* Israeli Shekel */ -DEFINE_INT_CURR("INR ") /* Indian Rupee (Bhutan) */ -DEFINE_INT_CURR("IQD ") /* Iraqi Dinar */ -DEFINE_INT_CURR("IRR ") /* Iranian Rial */ -DEFINE_INT_CURR("ISK ") /* Iceland Krona */ -DEFINE_INT_CURR("ITL ") /* Italian Lira (San Marino, Vatican City) */ -DEFINE_INT_CURR("JMD ") /* Jamaican Dollar */ -DEFINE_INT_CURR("JOD ") /* Jordanian Dinar */ -DEFINE_INT_CURR("JPY ") /* Japanese Yen */ -DEFINE_INT_CURR("KES ") /* Kenyan Shilling */ -DEFINE_INT_CURR("KGS ") /* Kyrgyzstan Som */ -DEFINE_INT_CURR("KHR ") /* Democratic Kampuchea Riel */ -DEFINE_INT_CURR("KMF ") /* Comoros Franc */ -DEFINE_INT_CURR("KPW ") /* Democratic People's of Korea Won */ -DEFINE_INT_CURR("KRW ") /* Republic of Korea Won */ -DEFINE_INT_CURR("KWD ") /* Kuwaiti Dinar */ -DEFINE_INT_CURR("KYD ") /* Cayman Islands */ -DEFINE_INT_CURR("KZT ") /* Kazakhstan Tenge */ -DEFINE_INT_CURR("LAK ") /* Lao People's Democratic Republic New Kip */ -DEFINE_INT_CURR("LBP ") /* Lebanese Pound */ -DEFINE_INT_CURR("LKR ") /* Sri Lankan Rupee */ -DEFINE_INT_CURR("LRD ") /* Liberian Dollar */ -DEFINE_INT_CURR("LSL ") /* Lesotho Maloti */ -DEFINE_INT_CURR("LTL ") /* Lithuanian Litas */ -DEFINE_INT_CURR("LUF ") /* Luxembourg Franc */ -DEFINE_INT_CURR("LVL ") /* Latvia Lat */ -DEFINE_INT_CURR("LYD ") /* Libyan Arab Jamahiriya Dinar */ -DEFINE_INT_CURR("MAD ") /* Moroccan Dirham */ -DEFINE_INT_CURR("MDL ") /* Moldova Lei */ -DEFINE_INT_CURR("MGF ") /* Madagasy Franc */ -DEFINE_INT_CURR("MKD ") /* Macedonia Denar */ -DEFINE_INT_CURR("MLF ") /* Mali Franc */ -DEFINE_INT_CURR("MMK ") /* Myanmar Kyat */ -DEFINE_INT_CURR("MNT ") /* Mongolia Tugrik */ -DEFINE_INT_CURR("MOP ") /* Macau Pataca */ -DEFINE_INT_CURR("MRO ") /* Mauritania Ouguiya */ -DEFINE_INT_CURR("MTL ") /* Maltese Lira */ -DEFINE_INT_CURR("MUR ") /* Mauritius Rupee */ -DEFINE_INT_CURR("MVR ") /* Maldives Rupee */ -DEFINE_INT_CURR("MWK ") /* Malawi Kwacha */ -DEFINE_INT_CURR("MXP ") /* Mexican Peso */ -DEFINE_INT_CURR("MYR ") /* Malaysian Ringgit */ -DEFINE_INT_CURR("MZM ") /* Mozambique Metical */ -DEFINE_INT_CURR("NAD ") /* Namibia Dollar */ -DEFINE_INT_CURR("NGN ") /* Nigeria Naira */ -DEFINE_INT_CURR("NIO ") /* Nicaragua Cordoba Oro */ -DEFINE_INT_CURR("NLG ") /* Netherlands Guilder */ -DEFINE_INT_CURR("NOK ") /* Norwegian Krone */ -DEFINE_INT_CURR("NPR ") /* Nepalese Rupee */ -DEFINE_INT_CURR("NZD ") /* New Zealand Dollar */ -DEFINE_INT_CURR("OMR ") /* Omani Rial */ -DEFINE_INT_CURR("PAB ") /* Panamaniam Balboa */ -DEFINE_INT_CURR("PEN ") /* Peruvian New Sol */ -DEFINE_INT_CURR("PGK ") /* Papau New Guinea Kina */ -DEFINE_INT_CURR("PHP ") /* Philippines Peso */ -DEFINE_INT_CURR("PKR ") /* Pakistan Rupee */ -DEFINE_INT_CURR("PLZ ") /* Polish Zloty */ -DEFINE_INT_CURR("PTE ") /* Portugese Escudo */ -DEFINE_INT_CURR("PYG ") /* Paraguay Guarani */ -DEFINE_INT_CURR("QAR ") /* Qatar Rial */ -DEFINE_INT_CURR("ROL ") /* Romanian Leu */ -DEFINE_INT_CURR("RUR ") /* Russian Ruble */ -DEFINE_INT_CURR("RWF ") /* Rwanda Franc */ -DEFINE_INT_CURR("SAR ") /* Saudi Arabia Riyal */ -DEFINE_INT_CURR("SBD ") /* Solomon Islands Dollar */ -DEFINE_INT_CURR("SCR ") /* Seychelles Rupee */ -DEFINE_INT_CURR("SDP ") /* Sudanese Pound */ -DEFINE_INT_CURR("SEK ") /* Swedish Krona */ -DEFINE_INT_CURR("SGD ") /* Singapore Dollar */ -DEFINE_INT_CURR("SHP ") /* St. Helena Pound */ -DEFINE_INT_CURR("SIT ") /* Slovenian Tolar */ -DEFINE_INT_CURR("SKK ") /* Slovakian Koruna */ -DEFINE_INT_CURR("SLL ") /* Sierra Leone Leone */ -DEFINE_INT_CURR("SOS ") /* Somalia Schilling */ -DEFINE_INT_CURR("SRG ") /* Suriname Guilder */ -DEFINE_INT_CURR("STD ") /* Sao Tome and Principe Dobra */ -DEFINE_INT_CURR("SUR ") /* Soviet Union Rubel (Ukrainian, Byelorussion) */ /* ??*/ -DEFINE_INT_CURR("SVC ") /* El Salvador Colon */ -DEFINE_INT_CURR("SYP ") /* Syrian Arab Republic Pound */ -DEFINE_INT_CURR("SZL ") /* Swaziland Lilangeni */ -DEFINE_INT_CURR("THB ") /* Thai Baht */ -DEFINE_INT_CURR("TJR ") /* Tajikistani Ruble */ -DEFINE_INT_CURR("TMM ") /* Turkmenistan Manet */ -DEFINE_INT_CURR("TND ") /* Tunisian Dinar */ -DEFINE_INT_CURR("TOP ") /* Tonga Pa'Anga */ -DEFINE_INT_CURR("TPE ") /* East Timor Escudo */ /* ??? */ -DEFINE_INT_CURR("TRL ") /* Turkish Lira */ -DEFINE_INT_CURR("TTD ") /* Trinidad and Tobago */ -DEFINE_INT_CURR("TWD ") /* Taiwan, Province of China Dollar */ -DEFINE_INT_CURR("TZS ") /* United Republic of Tanzania Shilling */ -DEFINE_INT_CURR("UAH ") /* Ukraine Hryvna */ -DEFINE_INT_CURR("UGS ") /* Ugandan Shilling */ /* obsolete */ -DEFINE_INT_CURR("UGX ") /* Ugandan Shilling */ -DEFINE_INT_CURR("USD ") /* United States Dollar */ -DEFINE_INT_CURR("UYN ") /* Uruguay New Peso */ /* obsolete */ -DEFINE_INT_CURR("UYP ") /* Uruguay Peso */ /* obsolete */ -DEFINE_INT_CURR("UYU ") /* Uruguay Peso Uruguayo */ -DEFINE_INT_CURR("UZS ") /* Uzbekistan Sum */ -DEFINE_INT_CURR("VEB ") /* Venezuelan Bolivar */ -DEFINE_INT_CURR("VND ") /* Viet Nam Dong */ -DEFINE_INT_CURR("VUV ") /* Vanuatu Vatu */ -DEFINE_INT_CURR("WST ") /* Samoa Tala */ -DEFINE_INT_CURR("XAF ") /* Central African Franc (United Republic of Cameroon, Central African Republic, Chad, Congo, Gabon) */ -DEFINE_INT_CURR("XCD ") /* East Caribbean Dollar (Antiqua, Dominica, Grenada, Montserrat, St. Kitts-Nevis-Anguilla, Saint Lucia, Saint Vincent and the Grenadines) */ -DEFINE_INT_CURR("XDR ") /* International Monetary Fund */ -DEFINE_INT_CURR("XDS ") /* St. Christopher Dollar */ /* ?? */ -DEFINE_INT_CURR("XOF ") /* West African Franc (Benin, Ivory Coast, Niger, Senegal, Togo, Upper Volta) */ -DEFINE_INT_CURR("XPF ") /* French polynesia, New Caledonia, Wallis and Futuna Islands */ -DEFINE_INT_CURR("YDD ") /* Yemini Dinar (Democratic Yemen) */ /* obsolete */ -DEFINE_INT_CURR("YER ") /* Yemeni Rial */ -DEFINE_INT_CURR("YUN ") /* Yugoslavian New Dinar */ -DEFINE_INT_CURR("ZAR ") /* South Africa Rand (Lesotho, Namibia) */ -DEFINE_INT_CURR("ZMK ") /* Zambian Kwacha */ -DEFINE_INT_CURR("ZRN ") /* Zaire New Zaire */ /* obsolete */ -DEFINE_INT_CURR("ZWD ") /* Zimbabwe Dollar */ diff --git a/src/system/libroot/posix/glibc/locale/iso-639.def b/src/system/libroot/posix/glibc/locale/iso-639.def deleted file mode 100644 index 7ae5d51898..0000000000 --- a/src/system/libroot/posix/glibc/locale/iso-639.def +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Defines the languages codes and abbreviations according to ISO 639-[12]. - * This is used in ld-address.c (address_finish). - * - * Format is: ("English name", 639-1-code, 639-2/T-code, 639-2/B-code) - * If you find something missing or wrong contact - */ - -DEFINE_LANGUAGE_CODE ("Afar", aa, aar, aar) -DEFINE_LANGUAGE_CODE ("Abkhazian", ab, abk, abk) -DEFINE_LANGUAGE_CODE ("Afrikaans", af, afr, afr) -DEFINE_LANGUAGE_CODE ("Albanian", sq, sqi, alb) -DEFINE_LANGUAGE_CODE ("Amharic", am, amh, amh) -DEFINE_LANGUAGE_CODE ("Arabic", ar, ara, ara) -DEFINE_LANGUAGE_CODE ("Armenian", hy, hye, arm) -DEFINE_LANGUAGE_CODE ("Assamese", as, asm, asm) -DEFINE_LANGUAGE_CODE ("Avestan", ae, ave, ave) -DEFINE_LANGUAGE_CODE ("Aymara", ay, aym, aym) -DEFINE_LANGUAGE_CODE ("Azerbaijani", az, aze, aze) -DEFINE_LANGUAGE_CODE ("Bashkir", ba, bak, bak) -DEFINE_LANGUAGE_CODE ("Basque", eu, eus, baq) -DEFINE_LANGUAGE_CODE ("Belarusian", be, bel, bel) -DEFINE_LANGUAGE_CODE ("Bengali", bn, ben, ben) -DEFINE_LANGUAGE_CODE ("Bihari", bh, bih, bih) -DEFINE_LANGUAGE_CODE ("Bislama", bi, bis, bis) -DEFINE_LANGUAGE_CODE ("Bosnian", bs, bos, bos) -DEFINE_LANGUAGE_CODE ("Breton", br, bre, bre) -DEFINE_LANGUAGE_CODE ("Bulgarian", bg, bul, bul) -DEFINE_LANGUAGE_CODE ("Burmese", my, mya, bur) -DEFINE_LANGUAGE_CODE ("Catalan", ca, cat, cat) -DEFINE_LANGUAGE_CODE ("Chamorro", ch, cha, cha) -DEFINE_LANGUAGE_CODE ("Chechen", ce, che, che) -DEFINE_LANGUAGE_CODE ("Chinese", zh, zho, chi) -DEFINE_LANGUAGE_CODE ("Church Slavic", cu, chu, chu) -DEFINE_LANGUAGE_CODE ("Chuvash", cv, chv, chv) -DEFINE_LANGUAGE_CODE ("Cornish", kw, cor, cor) -DEFINE_LANGUAGE_CODE ("Corsican", co, cos, cos) -DEFINE_LANGUAGE_CODE ("Czech", cs, ces, cze) -DEFINE_LANGUAGE_CODE ("Danish", da, dan, dan) -DEFINE_LANGUAGE_CODE ("Dutch", nl, nld, dut) -DEFINE_LANGUAGE_CODE ("Dzongkha", dz, dzo, dzo) -DEFINE_LANGUAGE_CODE ("English", en, eng, eng) -DEFINE_LANGUAGE_CODE ("Esperanto", eo, epo, epo) -DEFINE_LANGUAGE_CODE ("Estonian", et, est, est) -DEFINE_LANGUAGE_CODE ("Faroese", fo, fao, fao) -DEFINE_LANGUAGE_CODE ("Fijian", fj, fij, fij) -DEFINE_LANGUAGE_CODE ("Finnish", fi, fin, fin) -DEFINE_LANGUAGE_CODE ("French", fr, fra, fre) -DEFINE_LANGUAGE_CODE ("Frisian", fy, fry, fry) -DEFINE_LANGUAGE_CODE ("Georgian", ka, kat, geo) -DEFINE_LANGUAGE_CODE ("German", de, deu, ger) -DEFINE_LANGUAGE_CODE ("Gaelic (Scots)", gd, gla, gla) -DEFINE_LANGUAGE_CODE ("Irish", ga, gle, gle) -DEFINE_LANGUAGE_CODE ("Gallegan", gl, glg, glg) -DEFINE_LANGUAGE_CODE ("Manx", gv, glv, glv) -DEFINE_LANGUAGE_CODE ("Greek, Modern ()", el, gre, ell) -DEFINE_LANGUAGE_CODE ("Guarani", gn, grn, grn) -DEFINE_LANGUAGE_CODE ("Gujarati", gu, guj, guj) -DEFINE_LANGUAGE_CODE ("Hebrew", he, heb, heb) -DEFINE_LANGUAGE_CODE ("Herero", hz, her, her) -DEFINE_LANGUAGE_CODE ("Hindi", hi, hin, hin) -DEFINE_LANGUAGE_CODE ("Hiri Motu", ho, hmo, hmo) -DEFINE_LANGUAGE_CODE ("Hungarian", hu, hun, hun) -DEFINE_LANGUAGE_CODE ("Icelandic", is, isl, ice) -DEFINE_LANGUAGE_CODE ("Inuktitut", iu, iku, iku) -DEFINE_LANGUAGE_CODE ("Interlingue", ie, ile, ile) -DEFINE_LANGUAGE_CODE ("Interlingua", ia, ina, ina) -DEFINE_LANGUAGE_CODE ("Indonesian", id, ind, ind) -DEFINE_LANGUAGE_CODE ("Inupiaq", ik, ipk, ipk) -DEFINE_LANGUAGE_CODE ("Italian", it, ita, ita) -DEFINE_LANGUAGE_CODE ("Javanese", jv, jaw, jav) -DEFINE_LANGUAGE_CODE ("Japanese", ja, jpn, jpn) -DEFINE_LANGUAGE_CODE ("Kalaallisut (Greenlandic)", kl, kal, kal) -DEFINE_LANGUAGE_CODE ("Kannada", kn, kan, kan) -DEFINE_LANGUAGE_CODE ("Kashmiri", ks, kas, kas) -DEFINE_LANGUAGE_CODE ("Kazakh", kk, kaz, kaz) -DEFINE_LANGUAGE_CODE ("Khmer", km, khm, khm) -DEFINE_LANGUAGE_CODE ("Kikuyu", ki, kik, kik) -DEFINE_LANGUAGE_CODE ("Kinyarwanda", rw, kin, kin) -DEFINE_LANGUAGE_CODE ("Kirghiz", ky, kir, kir) -DEFINE_LANGUAGE_CODE ("Komi", kv, kom, kom) -DEFINE_LANGUAGE_CODE ("Korean", ko, kor, kor) -DEFINE_LANGUAGE_CODE ("Kuanyama", kj, kua, kua) -DEFINE_LANGUAGE_CODE ("Kurdish", ku, kur, kur) -DEFINE_LANGUAGE_CODE ("Lao", lo, lao, lao) -DEFINE_LANGUAGE_CODE ("Latin", la, lat, lat) -DEFINE_LANGUAGE_CODE ("Latvian", lv, lav, lav) -DEFINE_LANGUAGE_CODE ("Lingala", ln, lin, lin) -DEFINE_LANGUAGE_CODE ("Lithuanian", lt, lit, lit) -DEFINE_LANGUAGE_CODE ("Letzeburgesch", lb, ltz, ltz) -DEFINE_LANGUAGE_CODE ("Macedonian", mk, mkd, mac) -DEFINE_LANGUAGE_CODE ("Marshall", mh, mah, mah) -DEFINE_LANGUAGE_CODE ("Malayalam", ml, mal, mal) -DEFINE_LANGUAGE_CODE ("Maori", mi, mri, mao) -DEFINE_LANGUAGE_CODE ("Marathi", mr, mar, mar) -DEFINE_LANGUAGE_CODE ("Malay", ms, msa, may) -DEFINE_LANGUAGE_CODE ("Malagasy", mg, mlg, mlg) -DEFINE_LANGUAGE_CODE ("Maltese", mt, mlt, mlt) -DEFINE_LANGUAGE_CODE ("Moldavian", mo, mol, mol) -DEFINE_LANGUAGE_CODE ("Mongolian", mn, mon, mon) -DEFINE_LANGUAGE_CODE ("Nauru", na, nau, nau) -DEFINE_LANGUAGE_CODE ("Navajo", nv, nav, nav) -DEFINE_LANGUAGE_CODE ("Ndebele, South", nr, nbl, nbl) -DEFINE_LANGUAGE_CODE ("Ndebele, North", nd, nde, nde) -DEFINE_LANGUAGE_CODE ("Ndonga", ng, ndo, ndo) -DEFINE_LANGUAGE_CODE ("Nepali", ne, nep, nep) -DEFINE_LANGUAGE_CODE ("Norwegian", no, nor, nor) -DEFINE_LANGUAGE_CODE ("Norwegian Nynorsk", nn, nno, nno) -DEFINE_LANGUAGE_CODE ("Norwegian Bokml", nb, nob, nob) -DEFINE_LANGUAGE_CODE ("Chichewa; Nyanja", ny, nya, nya) -DEFINE_LANGUAGE_CODE ("Occitan (post 1500); Provenal", oc, oci, oci) -DEFINE_LANGUAGE_CODE ("Oriya", or, ori, ori) -DEFINE_LANGUAGE_CODE ("Oromo", om, orm, orm) -DEFINE_LANGUAGE_CODE ("Ossetian; Ossetic", os, oss, oss) -DEFINE_LANGUAGE_CODE ("Panjabi", pa, pan, pan) -DEFINE_LANGUAGE_CODE ("Persian", fa, fas, per) -DEFINE_LANGUAGE_CODE ("Pali", pi, pli, pli) -DEFINE_LANGUAGE_CODE ("Polish", pl, pol, pol) -DEFINE_LANGUAGE_CODE ("Portuguese", pt, por, por) -DEFINE_LANGUAGE_CODE ("Pushto", ps, pus, pus) -DEFINE_LANGUAGE_CODE ("Quechua", qu, que, que) -DEFINE_LANGUAGE_CODE ("Raeto-Romance", rm, roh, roh) -DEFINE_LANGUAGE_CODE ("Romanian", ro, ron, rum) -DEFINE_LANGUAGE_CODE ("Rundi", rn, run, run) -DEFINE_LANGUAGE_CODE ("Russian", ru, rus, rus) -DEFINE_LANGUAGE_CODE ("Sango", sg, sag, sag) -DEFINE_LANGUAGE_CODE ("Sanskrit", sa, san, san) -DEFINE_LANGUAGE_CODE ("Serbian", sr, srp, scc) -DEFINE_LANGUAGE_CODE ("Croatian", hr, hrv, scr) -DEFINE_LANGUAGE_CODE ("Sinhalese", si, sin, sin) -DEFINE_LANGUAGE_CODE ("Slovak", sk, slk, slo) -DEFINE_LANGUAGE_CODE ("Slovenian", sl, slv, slv) -DEFINE_LANGUAGE_CODE ("Northern Sami", se, sme, sme) -DEFINE_LANGUAGE_CODE ("Samoan", sm, smo, smo) -DEFINE_LANGUAGE_CODE ("Shona", sn, sna, sna) -DEFINE_LANGUAGE_CODE ("Sindhi", sd, snd, snd) -DEFINE_LANGUAGE_CODE ("Somali", so, som, som) -DEFINE_LANGUAGE_CODE ("Sotho, Southern", st, sot, sot) -DEFINE_LANGUAGE_CODE ("Spanish", es, spa, spa) -DEFINE_LANGUAGE_CODE ("Sardinian", sc, srd, srd) -DEFINE_LANGUAGE_CODE ("Swati", ss, ssw, ssw) -DEFINE_LANGUAGE_CODE ("Sundanese", su, sun, sun) -DEFINE_LANGUAGE_CODE ("Swahili", sw, swa, swa) -DEFINE_LANGUAGE_CODE ("Swedish", sv, swe, swe) -DEFINE_LANGUAGE_CODE ("Tahitian", ty, tah, tah) -DEFINE_LANGUAGE_CODE ("Tamil", ta, tam, tam) -DEFINE_LANGUAGE_CODE ("Tatar", tt, tat, tat) -DEFINE_LANGUAGE_CODE ("Telugu", te, tel, tel) -DEFINE_LANGUAGE_CODE ("Tajik", tg, tgk, tgk) -DEFINE_LANGUAGE_CODE ("Tagalog", tl, tgl, tgl) -DEFINE_LANGUAGE_CODE ("Thai", th, tha, tha) -DEFINE_LANGUAGE_CODE ("Tibetan", bo, bod, tib) -DEFINE_LANGUAGE_CODE ("Tigrinya", ti, tir, tir) -DEFINE_LANGUAGE_CODE ("Tonga (Tonga Islands)", to, ton, ton) -DEFINE_LANGUAGE_CODE ("Tswana", tn, tsn, tsn) -DEFINE_LANGUAGE_CODE ("Tsonga", ts, tso, tso) -DEFINE_LANGUAGE_CODE ("Turkish", tr, tur, tur) -DEFINE_LANGUAGE_CODE ("Turkmen", tk, tuk, tuk) -DEFINE_LANGUAGE_CODE ("Twi", tw, twi, twi) -DEFINE_LANGUAGE_CODE ("Uighur", ug, uig, uig) -DEFINE_LANGUAGE_CODE ("Ukrainian", uk, ukr, ukr) -DEFINE_LANGUAGE_CODE ("Urdu", ur, urd, urd) -DEFINE_LANGUAGE_CODE ("Uzbek", uz, uzb, uzb) -DEFINE_LANGUAGE_CODE ("Vietnamese", vi, vie, vie) -DEFINE_LANGUAGE_CODE ("Volapk", vo, vol, vol) -DEFINE_LANGUAGE_CODE ("Welsh", cy, cym, wel) -DEFINE_LANGUAGE_CODE ("Wolof", wo, wol, wol) -DEFINE_LANGUAGE_CODE ("Xhosa", xh, xho, xho) -DEFINE_LANGUAGE_CODE ("Yiddish", yi, yid, yid) -DEFINE_LANGUAGE_CODE ("Yoruba", yo, yor, yor) -DEFINE_LANGUAGE_CODE ("Zhuang", za, zha, zha) -DEFINE_LANGUAGE_CODE ("Zulu", zu, zul, zul) diff --git a/src/system/libroot/posix/glibc/locale/langinfo.h b/src/system/libroot/posix/glibc/locale/langinfo.h index 859b007c12..14f289aa91 100644 --- a/src/system/libroot/posix/glibc/locale/langinfo.h +++ b/src/system/libroot/posix/glibc/locale/langinfo.h @@ -503,87 +503,18 @@ enum _NL_MESSAGES_CODESET, _NL_NUM_LC_MESSAGES, - _NL_PAPER_HEIGHT = _NL_ITEM (__LC_PAPER, 0), - _NL_PAPER_WIDTH, - _NL_PAPER_CODESET, - _NL_NUM_LC_PAPER, - - _NL_NAME_NAME_FMT = _NL_ITEM (__LC_NAME, 0), - _NL_NAME_NAME_GEN, - _NL_NAME_NAME_MR, - _NL_NAME_NAME_MRS, - _NL_NAME_NAME_MISS, - _NL_NAME_NAME_MS, - _NL_NAME_CODESET, - _NL_NUM_LC_NAME, - - _NL_ADDRESS_POSTAL_FMT = _NL_ITEM (__LC_ADDRESS, 0), - _NL_ADDRESS_COUNTRY_NAME, - _NL_ADDRESS_COUNTRY_POST, - _NL_ADDRESS_COUNTRY_AB2, - _NL_ADDRESS_COUNTRY_AB3, - _NL_ADDRESS_COUNTRY_CAR, - _NL_ADDRESS_COUNTRY_NUM, - _NL_ADDRESS_COUNTRY_ISBN, - _NL_ADDRESS_LANG_NAME, - _NL_ADDRESS_LANG_AB, - _NL_ADDRESS_LANG_TERM, - _NL_ADDRESS_LANG_LIB, - _NL_ADDRESS_CODESET, - _NL_NUM_LC_ADDRESS, - - _NL_TELEPHONE_TEL_INT_FMT = _NL_ITEM (__LC_TELEPHONE, 0), - _NL_TELEPHONE_TEL_DOM_FMT, - _NL_TELEPHONE_INT_SELECT, - _NL_TELEPHONE_INT_PREFIX, - _NL_TELEPHONE_CODESET, - _NL_NUM_LC_TELEPHONE, - - _NL_MEASUREMENT_MEASUREMENT = _NL_ITEM (__LC_MEASUREMENT, 0), - _NL_MEASUREMENT_CODESET, - _NL_NUM_LC_MEASUREMENT, - - _NL_IDENTIFICATION_TITLE = _NL_ITEM (__LC_IDENTIFICATION, 0), - _NL_IDENTIFICATION_SOURCE, - _NL_IDENTIFICATION_ADDRESS, - _NL_IDENTIFICATION_CONTACT, - _NL_IDENTIFICATION_EMAIL, - _NL_IDENTIFICATION_TEL, - _NL_IDENTIFICATION_FAX, - _NL_IDENTIFICATION_LANGUAGE, - _NL_IDENTIFICATION_TERRITORY, - _NL_IDENTIFICATION_AUDIENCE, - _NL_IDENTIFICATION_APPLICATION, - _NL_IDENTIFICATION_ABBREVIATION, - _NL_IDENTIFICATION_REVISION, - _NL_IDENTIFICATION_DATE, - _NL_IDENTIFICATION_CATEGORY, - _NL_IDENTIFICATION_CODESET, - _NL_NUM_LC_IDENTIFICATION, /* This marks the highest value used. */ _NL_NUM }; -/* Return the current locale's value for ITEM. - If ITEM is invalid, an empty string is returned. - - The string returned will not change until `setlocale' is called; - it is usually in read-only memory and cannot be modified. */ - -extern char *nl_langinfo (nl_item __item) __THROW; - - #ifdef __USE_GNU /* This interface is for the extended locale model. See for more information. */ /* Get locale datatype definition. */ # include - -/* Just like nl_langinfo but get the information from the locale object L. */ -extern char *__nl_langinfo_l (nl_item __item, __locale_t l); #endif __END_DECLS diff --git a/src/system/libroot/posix/glibc/locale/lc-address.c b/src/system/libroot/posix/glibc/locale/lc-address.c deleted file mode 100644 index 0144403462..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-address.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_ADDRESS category. - Copyright (C) 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_ADDRESS); diff --git a/src/system/libroot/posix/glibc/locale/lc-ctype.c b/src/system/libroot/posix/glibc/locale/lc-ctype.c index 3f9e108b61..742dae41ee 100644 --- a/src/system/libroot/posix/glibc/locale/lc-ctype.c +++ b/src/system/libroot/posix/glibc/locale/lc-ctype.c @@ -40,22 +40,11 @@ _nl_postload_ctype (void) #define current(type,x,offset) \ ((const type *) _NL_CURRENT (LC_CTYPE, paste(_NL_CTYPE_,x)) + offset) - extern const uint32_t *__ctype32_b; - extern const uint32_t *__ctype32_toupper; - extern const uint32_t *__ctype32_tolower; extern const char *__ctype32_wctype[12]; extern const char *__ctype32_wctrans[2]; - extern const char *__ctype32_width; size_t offset, cnt; - __ctype_b = current (uint16_t, CLASS, 128); - __ctype_toupper = current (uint32_t, TOUPPER, 128); - __ctype_tolower = current (uint32_t, TOLOWER, 128); - __ctype32_b = current (uint32_t, CLASS32, 0); - __ctype32_toupper = current (uint32_t, TOUPPER32, 0); - __ctype32_tolower = current (uint32_t, TOLOWER32, 0); - offset = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_CLASS_OFFSET); for (cnt = 0; cnt < 12; cnt++) __ctype32_wctype[cnt] = _nl_current_LC_CTYPE->values[offset + cnt].string; @@ -63,6 +52,4 @@ _nl_postload_ctype (void) offset = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_OFFSET); for (cnt = 0; cnt < 2; cnt++) __ctype32_wctrans[cnt] = _nl_current_LC_CTYPE->values[offset + cnt].string; - - __ctype32_width = current (char, WIDTH, 0); } diff --git a/src/system/libroot/posix/glibc/locale/lc-identification.c b/src/system/libroot/posix/glibc/locale/lc-identification.c deleted file mode 100644 index df868eeadd..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-identification.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_IDENTIFICATION category. - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_IDENTIFICATION); diff --git a/src/system/libroot/posix/glibc/locale/lc-measurement.c b/src/system/libroot/posix/glibc/locale/lc-measurement.c deleted file mode 100644 index 63729bb5f5..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-measurement.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_MEASUREMENT category. - Copyright (C) 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_MEASUREMENT); diff --git a/src/system/libroot/posix/glibc/locale/lc-name.c b/src/system/libroot/posix/glibc/locale/lc-name.c deleted file mode 100644 index 689c0662ee..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-name.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_NAME category. - Copyright (C) 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_NAME); diff --git a/src/system/libroot/posix/glibc/locale/lc-paper.c b/src/system/libroot/posix/glibc/locale/lc-paper.c deleted file mode 100644 index 3c47a90f7e..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-paper.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_PAPER category. - Copyright (C) 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_PAPER); diff --git a/src/system/libroot/posix/glibc/locale/lc-telephone.c b/src/system/libroot/posix/glibc/locale/lc-telephone.c deleted file mode 100644 index 054ce657c9..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-telephone.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Define current locale data for LC_TELEPHONE category. - Copyright (C) 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_TELEPHONE); diff --git a/src/system/libroot/posix/glibc/locale/lc-time.c b/src/system/libroot/posix/glibc/locale/lc-time.c deleted file mode 100644 index efa56b8f82..0000000000 --- a/src/system/libroot/posix/glibc/locale/lc-time.c +++ /dev/null @@ -1,316 +0,0 @@ -/* Define current locale data for LC_TIME category. - Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include "localeinfo.h" - -_NL_CURRENT_DEFINE (LC_TIME); - -/* Some of the functions here must not be used while setlocale is called. */ -__libc_lock_define (extern, __libc_setlocale_lock) - - -static int era_initialized; - -static struct era_entry *eras; -static size_t num_eras; -static int alt_digits_initialized; -static const char **alt_digits; - - -static int walt_digits_initialized; -static const wchar_t **walt_digits; - - -void -_nl_postload_time (void) -{ - /* Prepare lazy initialization of `era' and `alt_digits' array. */ - era_initialized = 0; - alt_digits_initialized = 0; - walt_digits_initialized = 0; -} - -#define ERA_DATE_CMP(a, b) \ - (a[0] < b[0] || (a[0] == b[0] && (a[1] < b[1] \ - || (a[1] == b[1] && a[2] <= b[2])))) - -static void -_nl_init_era_entries (void) -{ - size_t cnt; - - __libc_lock_lock (__libc_setlocale_lock); - - if (era_initialized == 0) - { - size_t new_num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - if (new_num_eras == 0) - { - free (eras); - eras = NULL; - } - else - { - if (num_eras != new_num_eras) - eras = (struct era_entry *) realloc (eras, - new_num_eras - * sizeof (struct era_entry)); - if (eras == NULL) - { - num_eras = 0; - eras = NULL; - } - else - { - const char *ptr = _NL_CURRENT (LC_TIME, _NL_TIME_ERA_ENTRIES); - num_eras = new_num_eras; - - for (cnt = 0; cnt < num_eras; ++cnt) - { - const char *base_ptr = ptr; - memcpy ((void *) (eras + cnt), (const void *) ptr, - sizeof (uint32_t) * 8); - - if (ERA_DATE_CMP(eras[cnt].start_date, - eras[cnt].stop_date)) - if (eras[cnt].direction == (uint32_t) '+') - eras[cnt].absolute_direction = 1; - else - eras[cnt].absolute_direction = -1; - else - if (eras[cnt].direction == (uint32_t) '+') - eras[cnt].absolute_direction = -1; - else - eras[cnt].absolute_direction = 1; - - /* Skip numeric values. */ - ptr += sizeof (uint32_t) * 8; - - /* Set and skip era name. */ - eras[cnt].era_name = ptr; - ptr = strchr (ptr, '\0') + 1; - - /* Set and skip era format. */ - eras[cnt].era_format = ptr; - ptr = strchr (ptr, '\0') + 1; - - ptr += 3 - (((ptr - (const char *) base_ptr) + 3) & 3); - - /* Set and skip wide era name. */ - eras[cnt].era_wname = (wchar_t *) ptr; - ptr = (char *) (wcschr ((wchar_t *) ptr, L'\0') + 1); - - /* Set and skip wide era format. */ - eras[cnt].era_wformat = (wchar_t *) ptr; - ptr = (char *) (wcschr ((wchar_t *) ptr, L'\0') + 1); - } - } - } - - era_initialized = 1; - } - - __libc_lock_unlock (__libc_setlocale_lock); -} - - -struct era_entry * -_nl_get_era_entry (const struct tm *tp) -{ - struct era_entry *result; - int32_t tdate[3]; - size_t cnt; - - tdate[0] = tp->tm_year; - tdate[1] = tp->tm_mon; - tdate[2] = tp->tm_mday; - - if (era_initialized == 0) - _nl_init_era_entries (); - - /* Now compare date with the available eras. */ - for (cnt = 0; cnt < num_eras; ++cnt) - if ((ERA_DATE_CMP(eras[cnt].start_date, tdate) - && ERA_DATE_CMP(tdate, eras[cnt].stop_date)) - || (ERA_DATE_CMP(eras[cnt].stop_date, tdate) - && ERA_DATE_CMP(tdate, eras[cnt].start_date))) - break; - - result = cnt < num_eras ? &eras[cnt] : NULL; - - return result; -} - - -struct era_entry * -_nl_select_era_entry (int cnt) -{ - if (era_initialized == 0) - _nl_init_era_entries (); - - return &eras[cnt]; -} - - -const char * -_nl_get_alt_digit (unsigned int number) -{ - const char *result; - - __libc_lock_lock (__libc_setlocale_lock); - - if (alt_digits_initialized == 0) - { - alt_digits_initialized = 1; - - if (alt_digits == NULL) - alt_digits = malloc (100 * sizeof (const char *)); - - if (alt_digits != NULL) - { - const char *ptr = _NL_CURRENT (LC_TIME, ALT_DIGITS); - size_t cnt; - - if (alt_digits != NULL) - for (cnt = 0; cnt < 100; ++cnt) - { - alt_digits[cnt] = ptr; - - /* Skip digit format. */ - ptr = strchr (ptr, '\0') + 1; - } - } - } - - result = alt_digits != NULL && number < 100 ? alt_digits[number] : NULL; - - __libc_lock_unlock (__libc_setlocale_lock); - - return result; -} - - -const wchar_t * -_nl_get_walt_digit (unsigned int number) -{ - const wchar_t *result; - - __libc_lock_lock (__libc_setlocale_lock); - - if (walt_digits_initialized == 0) - { - walt_digits_initialized = 1; - - if (walt_digits == NULL) - walt_digits = malloc (100 * sizeof (const uint32_t *)); - - if (walt_digits != NULL) - { - const wchar_t *ptr = _NL_CURRENT_WSTR (LC_TIME, _NL_WALT_DIGITS); - size_t cnt; - - for (cnt = 0; cnt < 100; ++cnt) - { - walt_digits[cnt] = ptr; - - /* Skip digit format. */ - ptr = wcschr (ptr, L'\0') + 1; - } - } - } - - result = walt_digits != NULL && number < 100 ? walt_digits[number] : NULL; - - __libc_lock_unlock (__libc_setlocale_lock); - - return (wchar_t *) result; -} - - -int -_nl_parse_alt_digit (const char **strp) -{ - const char *str = *strp; - int result = -1; - size_t cnt; - size_t maxlen = 0; - - __libc_lock_lock (__libc_setlocale_lock); - - if (alt_digits_initialized == 0) - { - alt_digits_initialized = 1; - - if (alt_digits == NULL) - alt_digits = malloc (100 * sizeof (const char *)); - - if (alt_digits != NULL) - { - const char *ptr = _NL_CURRENT (LC_TIME, ALT_DIGITS); - - if (alt_digits != NULL) - for (cnt = 0; cnt < 100; ++cnt) - { - alt_digits[cnt] = ptr; - - /* Skip digit format. */ - ptr = strchr (ptr, '\0') + 1; - } - } - } - - /* Matching is not unambiguos. The alternative digits could be like - I, II, III, ... and the first one is a substring of the second - and third. Therefore we must keep on searching until we found - the longest possible match. Note that this is not specified in - the standard. */ - for (cnt = 0; cnt < 100; ++cnt) - { - size_t len = strlen (alt_digits[cnt]); - - if (len > maxlen && strncmp (alt_digits[cnt], str, len) == 0) - { - maxlen = len; - result = (int) cnt; - } - } - - __libc_lock_unlock (__libc_setlocale_lock); - - if (result != -1) - *strp += maxlen; - - return result; -} - - -static void -free_mem (void) -{ - free (alt_digits); - free (walt_digits); -} -text_set_element (__libc_subfreeres, free_mem); diff --git a/src/system/libroot/posix/glibc/locale/loadarchive.c b/src/system/libroot/posix/glibc/locale/loadarchive.c deleted file mode 100644 index 3fddc7d05b..0000000000 --- a/src/system/libroot/posix/glibc/locale/loadarchive.c +++ /dev/null @@ -1,541 +0,0 @@ -/* Code to load locale data from the locale archive file. - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "localeinfo.h" -#include "locarchive.h" - -/* Define the hash function. We define the function as static inline. */ -#define compute_hashval static inline compute_hashval -#define hashval_t uint32_t -#include "hashval.h" -#undef compute_hashval - - -/* Name of the locale archive file. */ -static const char archfname[] = LOCALEDIR "/locale-archive"; - -/* Size of initial mapping window, optimal if large enough to - cover the header plus the initial locale. */ -#define ARCHIVE_MAPPING_WINDOW (2 * 1024 * 1024) - -#ifndef MAP_COPY -/* This is not quite as good as MAP_COPY since unexamined pages - can change out from under us and give us inconsistent data. - But we rely on the user not to diddle the system's live archive. - Even though we only ever use PROT_READ, using MAP_SHARED would - not give the system sufficient freedom to e.g. let the on disk - file go away because it doesn't know we won't call mprotect later. */ -# define MAP_COPY MAP_PRIVATE -#endif -#ifndef MAP_FILE - /* Some systems do not have this flag; it is superfluous. */ -# define MAP_FILE 0 -#endif - -/* Record of contiguous pages already mapped from the locale archive. */ -struct archmapped -{ - void *ptr; - uint32_t from; - uint32_t len; - struct archmapped *next; -}; -static struct archmapped *archmapped; - -/* This describes the mapping at the beginning of the file that contains - the header data. There could be data in the following partial page, - so this is searched like any other. Once the archive has been used, - ARCHMAPPED points to this; if mapping the archive header failed, - then headmap.ptr is null. */ -static struct archmapped headmap; -static struct stat64 archive_stat; /* stat of archive when header mapped. */ - -/* Record of locales that we have already loaded from the archive. */ -struct locale_in_archive -{ - struct locale_in_archive *next; - char *name; - struct locale_data *data[__LC_LAST]; -}; -static struct locale_in_archive *archloaded; - - -/* Local structure and subroutine of _nl_load_archive, see below. */ -struct range -{ - uint32_t from; - uint32_t len; - int category; - void *result; -}; - -static int -rangecmp (const void *p1, const void *p2) -{ - return ((struct range *) p1)->from - ((struct range *) p2)->from; -} - - -/* Calculate the amount of space needed for all the tables described - by the given header. Note we do not include the empty table space - that has been preallocated in the file, so our mapping may not be - large enough if localedef adds data to the file in place. However, - doing that would permute the header fields while we are accessing - them and thus not be safe anyway, so we don't allow for that. */ -static inline off_t -calculate_head_size (const struct locarhead *h) -{ - off_t namehash_end = (h->namehash_offset - + h->namehash_size * sizeof (struct namehashent)); - off_t string_end = h->string_offset + h->string_used; - off_t locrectab_end = (h->locrectab_offset - + h->locrectab_used * sizeof (struct locrecent)); - return MAX (namehash_end, MAX (string_end, locrectab_end)); -} - - -/* Find the locale *NAMEP in the locale archive, and return the - internalized data structure for its CATEGORY data. If this locale has - already been loaded from the archive, just returns the existing data - structure. If successful, sets *NAMEP to point directly into the mapped - archive string table; that way, the next call can short-circuit strcmp. */ -struct locale_data * -internal_function -_nl_load_locale_from_archive (int category, const char **namep) -{ - const char *name = *namep; - struct - { - void *addr; - size_t len; - } results[__LC_LAST]; - struct locale_in_archive *lia; - struct locarhead *head; - struct namehashent *namehashtab; - struct locrecent *locrec; - struct archmapped *mapped; - struct archmapped *last; - unsigned long int hval; - size_t idx; - size_t incr; - struct range ranges[__LC_LAST - 1]; - int nranges; - int cnt; - size_t ps = __sysconf (_SC_PAGE_SIZE); - int fd = -1; - - /* Check if we have already loaded this locale from the archive. - If we previously loaded the locale but found bogons in the data, - then we will have stored a null pointer to return here. */ - for (lia = archloaded; lia != NULL; lia = lia->next) - if (name == lia->name || !strcmp (name, lia->name)) - { - *namep = lia->name; - return lia->data[category]; - } - - { - /* If the name contains a codeset, then we normalize the name before - doing the lookup. */ - const char *p = strchr (name, '.'); - if (p != NULL && p[1] != '@' && p[1] != '\0') - { - const char *rest = __strchrnul (++p, '@'); - const char *normalized_codeset = _nl_normalize_codeset (p, rest - p); - if (normalized_codeset == NULL) /* malloc failure */ - return NULL; - if (strncmp (normalized_codeset, p, rest - p) != 0 - || normalized_codeset[rest - p] != '\0') - { - /* There is a normalized codeset name that is different from - what was specified; reconstruct a new locale name using it. */ - size_t normlen = strlen (normalized_codeset); - size_t restlen = strlen (rest) + 1; - char *newname = alloca (p - name + normlen + restlen); - memcpy (__mempcpy (__mempcpy (newname, name, p - name), - normalized_codeset, normlen), - rest, restlen); - free ((char *) normalized_codeset); - name = newname; - } - } - } - - /* Make sure the archive is loaded. */ - if (archmapped == NULL) - { - void *result; - size_t headsize, mapsize; - - /* We do this early as a sign that we have tried to open the archive. - If headmap.ptr remains null, that's an indication that we tried - and failed, so we won't try again. */ - archmapped = &headmap; - - /* The archive has never been opened. */ - fd = __open64 (archfname, O_RDONLY); - if (fd < 0) - /* Cannot open the archive, for whatever reason. */ - return NULL; - - if (__fxstat64 (_STAT_VER, fd, &archive_stat) == -1) - { - /* stat failed, very strange. */ - close_and_out: - if (fd >= 0) - __close (fd); - return NULL; - } - - - /* Map an initial window probably large enough to cover the header - and the first locale's data. With a large address space, we can - just map the whole file and be sure everything is covered. */ - - mapsize = (sizeof (void *) > 4 ? archive_stat.st_size - : MIN (archive_stat.st_size, ARCHIVE_MAPPING_WINDOW)); - - result = __mmap64 (NULL, mapsize, PROT_READ, MAP_FILE|MAP_COPY, fd, 0); - if (result == MAP_FAILED) - goto close_and_out; - - /* Check whether the file is large enough for the sizes given in - the header. Theoretically an archive could be so large that - just the header fails to fit in our initial mapping window. */ - headsize = calculate_head_size ((const struct locarhead *) result); - if (headsize > mapsize) - { - (void) __munmap (result, mapsize); - if (sizeof (void *) > 4 || headsize > archive_stat.st_size) - /* The file is not big enough for the header. Bogus. */ - goto close_and_out; - - /* Freakishly long header. */ - /* XXX could use mremap when available */ - mapsize = (headsize + ps - 1) & ~(ps - 1); - result = __mmap64 (NULL, mapsize, PROT_READ, MAP_FILE|MAP_COPY, - fd, 0); - if (result == MAP_FAILED) - goto close_and_out; - } - - if (sizeof (void *) > 4 || mapsize >= archive_stat.st_size) - { - /* We've mapped the whole file already, so we can be - sure we won't need this file descriptor later. */ - __close (fd); - fd = -1; - } - - headmap.ptr = result; - /* headmap.from already initialized to zero. */ - headmap.len = mapsize; - } - - /* If there is no archive or it cannot be loaded for some reason fail. */ - if (__builtin_expect (headmap.ptr == NULL, 0)) - goto close_and_out; - - /* We have the archive available. To find the name we first have to - determine its hash value. */ - hval = compute_hashval (name, strlen (name)); - - head = headmap.ptr; - namehashtab = (struct namehashent *) ((char *) head - + head->namehash_offset); - - idx = hval % head->namehash_size; - incr = 1 + hval % (head->namehash_size - 2); - - /* If the name_offset field is zero this means this is a - deleted entry and therefore no entry can be found. */ - while (1) - { - if (namehashtab[idx].name_offset == 0) - /* Not found. */ - goto close_and_out; - - if (namehashtab[idx].hashval == hval - && strcmp (name, headmap.ptr + namehashtab[idx].name_offset) == 0) - /* Found the entry. */ - break; - - idx += incr; - if (idx >= head->namehash_size) - idx -= head->namehash_size; - } - - /* We found an entry. It might be a placeholder for a removed one. */ - if (namehashtab[idx].locrec_offset == 0) - goto close_and_out; - - locrec = (struct locrecent *) (headmap.ptr + namehashtab[idx].locrec_offset); - - if (sizeof (void *) > 4 /* || headmap.len == archive_stat.st_size */) - { - /* We already have the whole locale archive mapped in. */ - assert (headmap.len == archive_stat.st_size); - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - if (locrec->record[cnt].offset + locrec->record[cnt].len - > headmap.len) - /* The archive locrectab contains bogus offsets. */ - goto close_and_out; - results[cnt].addr = headmap.ptr + locrec->record[cnt].offset; - results[cnt].len = locrec->record[cnt].len; - } - } - else - { - /* Get the offsets of the data files and sort them. */ - for (cnt = nranges = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - ranges[nranges].from = locrec->record[cnt].offset; - ranges[nranges].len = locrec->record[cnt].len; - ranges[nranges].category = cnt; - ranges[nranges].result = NULL; - - ++nranges; - } - - qsort (ranges, nranges, sizeof (ranges[0]), rangecmp); - - /* The information about mmap'd blocks is kept in a list. - Skip over the blocks which are before the data we need. */ - last = mapped = archmapped; - for (cnt = 0; cnt < nranges; ++cnt) - { - int upper; - size_t from; - size_t to; - void *addr; - struct archmapped *newp; - - /* Determine whether the appropriate page is already mapped. */ - while (mapped != NULL - && (mapped->from + mapped->len - <= ranges[cnt].from + ranges[cnt].len)) - { - last = mapped; - mapped = mapped->next; - } - - /* Do we have a match? */ - if (mapped != NULL - && mapped->from <= ranges[cnt].from - && (ranges[cnt].from + ranges[cnt].len - <= mapped->from + mapped->len)) - { - /* Yep, already loaded. */ - results[ranges[cnt].category].addr = ((char *) mapped->ptr - + ranges[cnt].from - - mapped->from); - results[ranges[cnt].category].len = ranges[cnt].len; - continue; - } - - /* Map the range with the locale data from the file. We will - try to cover as much of the locale as possible. I.e., if the - next category (next as in "next offset") is on the current or - immediately following page we use it as well. */ - assert (powerof2 (ps)); - from = ranges[cnt].from & ~(ps - 1); - upper = cnt; - do - { - to = ranges[upper].from + ranges[upper].len; - if (to > (size_t) archive_stat.st_size) - /* The archive locrectab contains bogus offsets. */ - goto close_and_out; - to = (to + ps - 1) & ~(ps - 1); - - /* If a range is already mmaped in, stop. */ - if (mapped != NULL && ranges[upper].from >= mapped->from) - break; - - ++upper; - } - /* Loop while still in contiguous pages. */ - while (upper < nranges && ranges[upper].from < to + ps); - - /* Open the file if it hasn't happened yet. */ - if (fd == -1) - { - struct stat64 st; - fd = __open64 (archfname, O_RDONLY); - if (fd == -1) - /* Cannot open the archive, for whatever reason. */ - return NULL; - /* Now verify we think this is really the same archive file - we opened before. If it has been changed we cannot trust - the header we read previously. */ - if (__fxstat64 (_STAT_VER, fd, &st) < 0 - || st.st_size != archive_stat.st_size - || st.st_mtime != archive_stat.st_mtime - || st.st_dev != archive_stat.st_dev - || st.st_ino != archive_stat.st_ino) - goto close_and_out; - } - - /* Map the range from the archive. */ - addr = __mmap64 (NULL, to - from, PROT_READ, MAP_FILE|MAP_COPY, - fd, from); - if (addr == MAP_FAILED) - goto close_and_out; - - /* Allocate a record for this mapping. */ - newp = (struct archmapped *) malloc (sizeof (struct archmapped)); - if (newp == NULL) - { - (void) __munmap (addr, to - from); - goto close_and_out; - } - - /* And queue it. */ - newp->ptr = addr; - newp->from = from; - newp->len = to - from; - assert (last->next == mapped); - newp->next = mapped; - last->next = newp; - last = newp; - - /* Determine the load addresses for the category data. */ - do - { - assert (ranges[cnt].from >= from); - results[ranges[cnt].category].addr = ((char *) addr - + ranges[cnt].from - from); - results[ranges[cnt].category].len = ranges[cnt].len; - } - while (++cnt < upper); - --cnt; /* The 'for' will increase 'cnt' again. */ - } - } - - /* We don't need the file descriptor any longer. */ - if (fd >= 0) - __close (fd); - fd = -1; - - /* We succeeded in mapping all the necessary regions of the archive. - Now we need the expected data structures to point into the data. */ - - lia = malloc (sizeof *lia); - if (__builtin_expect (lia == NULL, 0)) - return NULL; - - lia->name = strdup (*namep); - if (__builtin_expect (lia->name == NULL, 0)) - { - free (lia); - return NULL; - } - - lia->next = archloaded; - archloaded = lia; - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - lia->data[cnt] = _nl_intern_locale_data (cnt, - results[cnt].addr, - results[cnt].len); - if (__builtin_expect (lia->data[cnt] != NULL, 1)) - { - /* _nl_intern_locale_data leaves us these fields to initialize. */ - lia->data[cnt]->alloc = ld_archive; - lia->data[cnt]->name = lia->name; - - /* We do this instead of bumping the count each time we return - this data because the mappings stay around forever anyway - and we might as well hold on to a little more memory and not - have to rebuild it on the next lookup of the same thing. - If we were to maintain the usage_count normally and let the - structures be freed, we would have to remove the elements - from archloaded too. */ - lia->data[cnt]->usage_count = UNDELETABLE; - } - } - - *namep = lia->name; - return lia->data[category]; -} - -void __libc_freeres_fn_section -_nl_archive_subfreeres (void) -{ - struct locale_in_archive *lia; - struct archmapped *am; - - /* Toss out our cached locales. */ - lia = archloaded; - while (lia != NULL) - { - int category; - struct locale_in_archive *dead = lia; - lia = lia->next; - - free (dead->name); - for (category = 0; category < __LC_LAST; ++category) - if (category != LC_ALL) - { - /* _nl_unload_locale just does this free for the archive case. */ - if (dead->data[category]->private.cleanup) - (*dead->data[category]->private.cleanup) (dead->data[category]); - - free (dead->data[category]); - } - free (dead); - } - archloaded = NULL; - - if (archmapped != NULL) - { - /* Now toss all the mapping windows, which we know nothing is using any - more because we just tossed all the locales that point into them. */ - - assert (archmapped == &headmap); - archmapped = NULL; - (void) __munmap (headmap.ptr, headmap.len); - am = headmap.next; - while (am != NULL) - { - struct archmapped *dead = am; - am = am->next; - (void) __munmap (dead->ptr, dead->len); - free (dead); - } - } -} diff --git a/src/system/libroot/posix/glibc/locale/loadlocale.c b/src/system/libroot/posix/glibc/locale/loadlocale.c deleted file mode 100644 index 53962babac..0000000000 --- a/src/system/libroot/posix/glibc/locale/loadlocale.c +++ /dev/null @@ -1,246 +0,0 @@ -/* Functions to read locale data files. - Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#ifdef _POSIX_MAPPED_FILES -# include -#endif -#include - -#include "localeinfo.h" - - -static const size_t _nl_category_num_items[] = -{ -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = _NL_ITEM_INDEX (_NL_NUM_##category), -#include "categories.def" -#undef DEFINE_CATEGORY -}; - - -#define NO_PAREN(arg, rest...) arg, ##rest - -#define DEFINE_CATEGORY(category, category_name, items, a) \ -static const enum value_type _nl_value_type_##category[] = { NO_PAREN items }; -#define DEFINE_ELEMENT(element, element_name, optstd, type, rest...) \ - [_NL_ITEM_INDEX (element)] = type, -#include "categories.def" -#undef DEFINE_CATEGORY - -static const enum value_type *_nl_value_types[] = -{ -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = _nl_value_type_##category, -#include "categories.def" -#undef DEFINE_CATEGORY -}; - - -void -_nl_load_locale (struct loaded_l10nfile *file, int category) -{ - int fd; - struct - { - unsigned int magic; - unsigned int nstrings; - unsigned int strindex[0]; - } *filedata; - struct stat64 st; - struct locale_data *newdata; - int save_err; - int mmaped = 1; - size_t cnt; - - file->decided = 1; - file->data = NULL; - - fd = __open (file->filename, O_RDONLY); - if (__builtin_expect (fd, 0) < 0) - /* Cannot open the file. */ - return; - - if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) < 0) - goto puntfd; - if (__builtin_expect (S_ISDIR (st.st_mode), 0)) - { - /* LOCALE/LC_foo is a directory; open LOCALE/LC_foo/SYS_LC_foo - instead. */ - char *newp; - size_t filenamelen; - - __close (fd); - - filenamelen = strlen (file->filename); - newp = (char *) alloca (filenamelen - + 5 + _nl_category_name_sizes[category] + 1); - __mempcpy (__mempcpy (__mempcpy (newp, file->filename, filenamelen), - "/SYS_", 5), - _nl_category_names[category], - _nl_category_name_sizes[category] + 1); - - fd = __open (newp, O_RDONLY); - if (__builtin_expect (fd, 0) < 0) - return; - - if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) < 0) - goto puntfd; - } - - /* Map in the file's data. */ - save_err = errno; -#ifdef _POSIX_MAPPED_FILES -# ifndef MAP_COPY - /* Linux seems to lack read-only copy-on-write. */ -# define MAP_COPY MAP_PRIVATE -# endif -# ifndef MAP_FILE - /* Some systems do not have this flag; it is superfluous. */ -# define MAP_FILE 0 -# endif -# ifndef MAP_INHERIT - /* Some systems might lack this; they lose. */ -# define MAP_INHERIT 0 -# endif - filedata = (void *) __mmap ((caddr_t) 0, st.st_size, PROT_READ, - MAP_FILE|MAP_COPY|MAP_INHERIT, fd, 0); - if (__builtin_expect ((void *) filedata != MAP_FAILED, 1)) - { - if (__builtin_expect (st.st_size < sizeof (*filedata), 0)) - /* This cannot be a locale data file since it's too small. */ - goto puntfd; - } - else - { - if (__builtin_expect (errno, ENOSYS) == ENOSYS) - { -#endif /* _POSIX_MAPPED_FILES */ - /* No mmap; allocate a buffer and read from the file. */ - mmaped = 0; - filedata = malloc (st.st_size); - if (filedata != NULL) - { - off_t to_read = st.st_size; - ssize_t nread; - char *p = (char *) filedata; - while (to_read > 0) - { - nread = __read (fd, p, to_read); - if (__builtin_expect (nread, 1) <= 0) - { - free (filedata); - if (nread == 0) - __set_errno (EINVAL); /* Bizarreness going on. */ - goto puntfd; - } - p += nread; - to_read -= nread; - } - } - else - goto puntfd; - __set_errno (save_err); -#ifdef _POSIX_MAPPED_FILES - } - else - goto puntfd; - } -#endif /* _POSIX_MAPPED_FILES */ - - if (__builtin_expect (filedata->magic != LIMAGIC (category), 0)) - /* Bad data file in either byte order. */ - { - puntmap: -#ifdef _POSIX_MAPPED_FILES - __munmap ((caddr_t) filedata, st.st_size); -#endif - puntfd: - __close (fd); - return; - } - - if (__builtin_expect (filedata->nstrings < _nl_category_num_items[category], - 0) - || (__builtin_expect (sizeof *filedata - + filedata->nstrings * sizeof (unsigned int) - >= (size_t) st.st_size, 0))) - { - /* Insufficient data. */ - __set_errno (EINVAL); - goto puntmap; - } - - newdata = malloc (sizeof *newdata - + filedata->nstrings * sizeof (union locale_data_value)); - if (newdata == NULL) - goto puntmap; - - newdata->name = NULL; /* This will be filled if necessary in findlocale.c. */ - newdata->filedata = (void *) filedata; - newdata->filesize = st.st_size; - newdata->mmaped = mmaped; - newdata->usage_count = 0; - newdata->use_translit = 0; - newdata->options = NULL; - newdata->nstrings = filedata->nstrings; - for (cnt = 0; cnt < newdata->nstrings; ++cnt) - { - off_t idx = filedata->strindex[cnt]; - if (__builtin_expect (idx > newdata->filesize, 0)) - { - free (newdata); - __set_errno (EINVAL); - goto puntmap; - } - if (__builtin_expect (_nl_value_types[category][cnt] == word, 0)) - { - assert (idx % __alignof__ (u_int32_t) == 0); - newdata->values[cnt].word = - *((u_int32_t *) (newdata->filedata + idx)); - } - else - newdata->values[cnt].string = newdata->filedata + idx; - } - - __close (fd); - file->data = newdata; -} - -void -_nl_unload_locale (struct locale_data *locale) -{ -#ifdef _POSIX_MAPPED_FILES - if (__builtin_expect (locale->mmaped, 1)) - __munmap ((caddr_t) locale->filedata, locale->filesize); - else -#endif - free ((void *) locale->filedata); - - free ((char *) locale->options); - free ((char *) locale->name); - free (locale); -} diff --git a/src/system/libroot/posix/glibc/locale/locale.h b/src/system/libroot/posix/glibc/locale/locale.h index 9133038178..2770798b6f 100644 --- a/src/system/libroot/posix/glibc/locale/locale.h +++ b/src/system/libroot/posix/glibc/locale/locale.h @@ -40,12 +40,6 @@ __BEGIN_DECLS #define LC_MONETARY __LC_MONETARY #define LC_MESSAGES __LC_MESSAGES #define LC_ALL __LC_ALL -#define LC_PAPER __LC_PAPER -#define LC_NAME __LC_NAME -#define LC_ADDRESS __LC_ADDRESS -#define LC_TELEPHONE __LC_TELEPHONE -#define LC_MEASUREMENT __LC_MEASUREMENT -#define LC_IDENTIFICATION __LC_IDENTIFICATION /* Structure giving information about numeric and monetary notation. */ diff --git a/src/system/libroot/posix/glibc/locale/localeconv.c b/src/system/libroot/posix/glibc/locale/localeconv.c deleted file mode 100644 index e1582f5942..0000000000 --- a/src/system/libroot/posix/glibc/locale/localeconv.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (C) 1991, 92, 95, 97, 99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include "localeinfo.h" -#include - -/* Return monetary and numeric information about the current locale. */ -struct lconv * -__localeconv (void) -{ - static struct lconv result; - - result.decimal_point = (char *) _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT); - result.thousands_sep = (char *) _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP); - result.grouping = (char *) _NL_CURRENT (LC_NUMERIC, GROUPING); - if (*result.grouping == CHAR_MAX || *result.grouping == -1) - result.grouping = (char *) ""; - - result.int_curr_symbol = (char *) _NL_CURRENT (LC_MONETARY, INT_CURR_SYMBOL); - result.currency_symbol = (char *) _NL_CURRENT (LC_MONETARY, CURRENCY_SYMBOL); - result.mon_decimal_point = (char *) _NL_CURRENT (LC_MONETARY, - MON_DECIMAL_POINT); - result.mon_thousands_sep = (char *) _NL_CURRENT (LC_MONETARY, - MON_THOUSANDS_SEP); - result.mon_grouping = (char *) _NL_CURRENT (LC_MONETARY, MON_GROUPING); - if (*result.mon_grouping == CHAR_MAX || *result.mon_grouping == -1) - result.mon_grouping = (char *) ""; - result.positive_sign = (char *) _NL_CURRENT (LC_MONETARY, POSITIVE_SIGN); - result.negative_sign = (char *) _NL_CURRENT (LC_MONETARY, NEGATIVE_SIGN); - result.int_frac_digits = *(char *) _NL_CURRENT (LC_MONETARY, - INT_FRAC_DIGITS); - result.frac_digits = *(char *) _NL_CURRENT (LC_MONETARY, FRAC_DIGITS); - result.p_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, P_CS_PRECEDES); - result.p_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, P_SEP_BY_SPACE); - result.n_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, N_CS_PRECEDES); - result.n_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, N_SEP_BY_SPACE); - result.p_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, P_SIGN_POSN); - result.n_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, N_SIGN_POSN); - result.int_p_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, - INT_P_CS_PRECEDES); - result.int_p_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, - INT_P_SEP_BY_SPACE); - result.int_n_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, - INT_N_CS_PRECEDES); - result.int_n_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, - INT_N_SEP_BY_SPACE); - result.int_p_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, - INT_P_SIGN_POSN); - result.int_n_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, - INT_N_SIGN_POSN); - - return &result; -} - -versioned_symbol (libc, __localeconv, localeconv, GLIBC_2_2); -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) -strong_alias (__localeconv, __localeconv20) -compat_symbol (libc, __localeconv20, localeconv, GLIBC_2_0); -#endif diff --git a/src/system/libroot/posix/glibc/locale/localeinfo.h b/src/system/libroot/posix/glibc/locale/localeinfo.h index e7528e9edb..814a273210 100644 --- a/src/system/libroot/posix/glibc/locale/localeinfo.h +++ b/src/system/libroot/posix/glibc/locale/localeinfo.h @@ -28,7 +28,7 @@ #include /* This has to be changed whenever a new locale is defined. */ -#define __LC_LAST 13 +#define __LC_LAST 7 #include /* For loaded_l10nfile definition. */ diff --git a/src/system/libroot/posix/glibc/locale/localename.c b/src/system/libroot/posix/glibc/locale/localename.c deleted file mode 100644 index 845cfb0e71..0000000000 --- a/src/system/libroot/posix/glibc/locale/localename.c +++ /dev/null @@ -1,27 +0,0 @@ -/* current locale setting names - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "localeinfo.h" - -const char * -attribute_hidden -__current_locale_name (int category) -{ - return _NL_CURRENT_LOCALE->__names[category]; -} diff --git a/src/system/libroot/posix/glibc/locale/locarchive.h b/src/system/libroot/posix/glibc/locale/locarchive.h deleted file mode 100644 index e94bc2b480..0000000000 --- a/src/system/libroot/posix/glibc/locale/locarchive.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Definitions for locale archive handling. - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LOCARCHIVE_H -#define _LOCARCHIVE_H 1 - -#include - - -#define AR_MAGIC 0xde020109 - -struct locarhead -{ - uint32_t magic; - /* Serial number. */ - uint32_t serial; - /* Name hash table. */ - uint32_t namehash_offset; - uint32_t namehash_used; - uint32_t namehash_size; - /* String table. */ - uint32_t string_offset; - uint32_t string_used; - uint32_t string_size; - /* Table with locale records. */ - uint32_t locrectab_offset; - uint32_t locrectab_used; - uint32_t locrectab_size; - /* MD5 sum hash table. */ - uint32_t sumhash_offset; - uint32_t sumhash_used; - uint32_t sumhash_size; -}; - - -struct namehashent -{ - /* Hash value of the name. */ - uint32_t hashval; - /* Offset of the name in the string table. */ - uint32_t name_offset; - /* Offset of the locale record. */ - uint32_t locrec_offset; -}; - - -struct sumhashent -{ - /* MD5 sum. */ - char sum[16]; - /* Offset of the file in the archive. */ - uint32_t file_offset; -}; - -struct locrecent -{ - uint32_t refs; /* # of namehashent records that point here */ - struct - { - uint32_t offset; - uint32_t len; - } record[__LC_LAST]; -}; - - -struct locarhandle -{ - int fd; - void *addr; - size_t len; -}; - - -/* In memory data for the locales with their checksums. */ -typedef struct locale_category_data -{ - off64_t size; - void *addr; - char sum[16]; -} locale_data_t[__LC_LAST]; - -#endif /* locarchive.h */ diff --git a/src/system/libroot/posix/glibc/locale/newlocale.c b/src/system/libroot/posix/glibc/locale/newlocale.c deleted file mode 100644 index 4a785d0c0f..0000000000 --- a/src/system/libroot/posix/glibc/locale/newlocale.c +++ /dev/null @@ -1,186 +0,0 @@ -/* Return a reference to locale information record. - Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -#include "localeinfo.h" - - -/* Constant data defined in setlocale.c. */ -extern struct locale_data *const _nl_C[]; - -/* Use this when we come along an error. */ -#define ERROR_RETURN \ - do { \ - __set_errno (EINVAL); \ - return NULL; \ - } while (0) - - -__locale_t -__newlocale (int category_mask, const char *locale, __locale_t base) -{ - /* Intermediate memory for result. */ - const char *newnames[__LC_LAST]; - struct __locale_struct result; - __locale_t result_ptr; - char *locale_path; - size_t locale_path_len; - const char *locpath_var; - int cnt; - - /* We treat LC_ALL in the same way as if all bits were set. */ - if (category_mask == 1 << LC_ALL) - category_mask = (1 << __LC_LAST) - 1 - (1 << LC_ALL); - - /* Sanity check for CATEGORY argument. */ - if ((category_mask & ~((1 << __LC_LAST) - 1 - (1 << LC_ALL))) != 0) - ERROR_RETURN; - - /* `newlocale' does not support asking for the locale name. */ - if (locale == NULL) - ERROR_RETURN; - - /* Allocate memory for the result. */ - if (base != NULL) - result = *base; - else - { - /* Fill with pointers to C locale data. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - result.__locales[cnt] = _nl_C[cnt]; - } - - /* If no category is to be set we return BASE if available or a - dataset using the C locale data. */ - if (category_mask == 0) - { - result_ptr = (__locale_t) malloc (sizeof (struct __locale_struct)); - if (result_ptr == NULL) - return NULL; - *result_ptr = result; - - goto update; - } - - /* We perhaps really have to load some data. So we determine the - path in which to look for the data now. The environment variable - `LOCPATH' must only be used when the binary has no SUID or SGID - bit set. */ - locale_path = NULL; - locale_path_len = 0; - - locpath_var = getenv ("LOCPATH"); - if (locpath_var != NULL && locpath_var[0] != '\0') - if (__argz_create_sep (locpath_var, ':', - &locale_path, &locale_path_len) != 0) - return NULL; - - if (__argz_append (&locale_path, &locale_path_len, - LOCALEDIR, sizeof (LOCALEDIR)) != 0) - return NULL; - - /* Get the names for the locales we are interested in. We either - allow a composite name or a single name. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - newnames[cnt] = locale; - if (strchr (locale, ';') != NULL) - { - /* This is a composite name. Make a copy and split it up. */ - char *np = strdupa (locale); - char *cp; - - while ((cp = strchr (np, '=')) != NULL) - { - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL - && (size_t) (cp - np) == _nl_category_name_sizes[cnt] - && memcmp (np, _nl_category_names[cnt], cp - np) == 0) - break; - - if (cnt == __LC_LAST) - /* Bogus category name. */ - ERROR_RETURN; - - /* Found the category this clause sets. */ - newnames[cnt] = ++cp; - cp = strchr (cp, ';'); - if (cp != NULL) - { - /* Examine the next clause. */ - *cp = '\0'; - np = cp + 1; - } - else - /* This was the last clause. We are done. */ - break; - } - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL - && (category_mask & 1 << cnt) != 0 && newnames[cnt] == locale) - /* The composite name did not specify the category we need. */ - ERROR_RETURN; - } - - /* Now process all categories we are interested in. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL && (category_mask & 1 << cnt) != 0) - { - result.__locales[cnt] = _nl_find_locale (locale_path, locale_path_len, - cnt, &newnames[cnt]); - if (result.__locales[cnt] == NULL) - return NULL; - } - - /* We successfully loaded all required data. */ - if (base == NULL) - { - /* Allocate new structure. */ - result_ptr = (__locale_t) malloc (sizeof (struct __locale_struct)); - if (result_ptr == NULL) - return NULL; - - } - else - /* We modify the base structure. */ - result_ptr = base; - - *result_ptr = result; - - /* Update the special members. */ - update: - { - union locale_data_value *ctypes = result_ptr->__locales[LC_CTYPE]->values; - result_ptr->__ctype_b = (const unsigned short int *) - ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)].string + 128; - result_ptr->__ctype_tolower = (const int *) - ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string + 128; - result_ptr->__ctype_toupper = (const int *) - ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string + 128; - } - - return result_ptr; -} diff --git a/src/system/libroot/posix/glibc/locale/nl_langinfo.c b/src/system/libroot/posix/glibc/locale/nl_langinfo.c deleted file mode 100644 index 7b62c73c63..0000000000 --- a/src/system/libroot/posix/glibc/locale/nl_langinfo.c +++ /dev/null @@ -1,60 +0,0 @@ -/* User interface for extracting locale-dependent parameters. - Copyright (C) 1995,1996,1997,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include "localeinfo.h" - - -/* Return a string with the data for locale-dependent parameter ITEM. */ - -#ifdef USE_IN_EXTENDED_LOCALE_MODEL -char * -__nl_langinfo_l (item, l) - nl_item item; - __locale_t l; -#else -char * -nl_langinfo (item) - nl_item item; -#endif -{ - int category = _NL_ITEM_CATEGORY (item); - unsigned int index = _NL_ITEM_INDEX (item); - const struct locale_data *data; - - if (category < 0 || category == LC_ALL || category >= __LC_LAST) - /* Bogus category: bogus item. */ - return (char *) ""; - -#ifdef USE_IN_EXTENDED_LOCALE_MODEL - data = l->__locales[category]; -#else - data = *_nl_current[category]; -#endif - - if (index >= data->nstrings) - /* Bogus index for this category: bogus item. */ - return (char *) ""; - - /* Return the string for the specified item. */ - return (char *) data->values[index].string; -} diff --git a/src/system/libroot/posix/glibc/locale/nl_langinfo_l.c b/src/system/libroot/posix/glibc/locale/nl_langinfo_l.c deleted file mode 100644 index ef7b7a1a6a..0000000000 --- a/src/system/libroot/posix/glibc/locale/nl_langinfo_l.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 -#include diff --git a/src/system/libroot/posix/glibc/locale/programs/3level.h b/src/system/libroot/posix/glibc/locale/programs/3level.h deleted file mode 100644 index f4d641d67c..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/3level.h +++ /dev/null @@ -1,323 +0,0 @@ -/* Copyright (C) 2000-2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Bruno Haible , 2000. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Construction of sparse 3-level tables. - See wchar-lookup.h or coll-lookup.h for their structure and the - meaning of p and q. - - Before including this file, set - TABLE to the name of the structure to be defined - ELEMENT to the type of every entry - DEFAULT to the default value for empty entries - ITERATE if you want the TABLE_iterate function to be defined - NO_FINALIZE if you don't want the TABLE_finalize function to be defined - - This will define - - struct TABLE; - void TABLE_init (struct TABLE *t); - ELEMENT TABLE_get (struct TABLE *t, uint32_t wc); - void TABLE_add (struct TABLE *t, uint32_t wc, ELEMENT value); - void TABLE_iterate (struct TABLE *t, - void (*fn) (uint32_t wc, ELEMENT value)); - void TABLE_finalize (struct TABLE *t); -*/ - -#define CONCAT(a,b) CONCAT1(a,b) -#define CONCAT1(a,b) a##b - -struct TABLE -{ - /* Parameters. */ - unsigned int p; - unsigned int q; - /* Working representation. */ - size_t level1_alloc; - size_t level1_size; - uint32_t *level1; - size_t level2_alloc; - size_t level2_size; - uint32_t *level2; - size_t level3_alloc; - size_t level3_size; - ELEMENT *level3; - /* Compressed representation. */ - size_t result_size; - char *result; -}; - -/* Initialize. Assumes t->p and t->q have already been set. */ -static inline void -CONCAT(TABLE,_init) (struct TABLE *t) -{ - t->level1 = NULL; - t->level1_alloc = t->level1_size = 0; - t->level2 = NULL; - t->level2_alloc = t->level2_size = 0; - t->level3 = NULL; - t->level3_alloc = t->level3_size = 0; -} - -/* Marker for an empty slot. This has the value 0xFFFFFFFF, regardless - whether 'int' is 16 bit, 32 bit, or 64 bit. */ -#define EMPTY ((uint32_t) ~0) - -/* Retrieve an entry. */ -static inline ELEMENT -CONCAT(TABLE,_get) (struct TABLE *t, uint32_t wc) -{ - uint32_t index1 = wc >> (t->q + t->p); - if (index1 < t->level1_size) - { - uint32_t lookup1 = t->level1[index1]; - if (lookup1 != EMPTY) - { - uint32_t index2 = ((wc >> t->p) & ((1 << t->q) - 1)) - + (lookup1 << t->q); - uint32_t lookup2 = t->level2[index2]; - if (lookup2 != EMPTY) - { - uint32_t index3 = (wc & ((1 << t->p) - 1)) - + (lookup2 << t->p); - ELEMENT lookup3 = t->level3[index3]; - - return lookup3; - } - } - } - return DEFAULT; -} - -/* Add one entry. */ -static void -CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value) -{ - uint32_t index1 = wc >> (t->q + t->p); - uint32_t index2 = (wc >> t->p) & ((1 << t->q) - 1); - uint32_t index3 = wc & ((1 << t->p) - 1); - size_t i, i1, i2; - - if (value == CONCAT(TABLE,_get) (t, wc)) - return; - - if (index1 >= t->level1_size) - { - if (index1 >= t->level1_alloc) - { - size_t alloc = 2 * t->level1_alloc; - if (alloc <= index1) - alloc = index1 + 1; - t->level1 = (uint32_t *) xrealloc ((char *) t->level1, - alloc * sizeof (uint32_t)); - t->level1_alloc = alloc; - } - while (index1 >= t->level1_size) - t->level1[t->level1_size++] = EMPTY; - } - - if (t->level1[index1] == EMPTY) - { - if (t->level2_size == t->level2_alloc) - { - size_t alloc = 2 * t->level2_alloc + 1; - t->level2 = (uint32_t *) xrealloc ((char *) t->level2, - (alloc << t->q) * sizeof (uint32_t)); - t->level2_alloc = alloc; - } - i1 = t->level2_size << t->q; - i2 = (t->level2_size + 1) << t->q; - for (i = i1; i < i2; i++) - t->level2[i] = EMPTY; - t->level1[index1] = t->level2_size++; - } - - index2 += t->level1[index1] << t->q; - - if (t->level2[index2] == EMPTY) - { - if (t->level3_size == t->level3_alloc) - { - size_t alloc = 2 * t->level3_alloc + 1; - t->level3 = (ELEMENT *) xrealloc ((char *) t->level3, - (alloc << t->p) * sizeof (ELEMENT)); - t->level3_alloc = alloc; - } - i1 = t->level3_size << t->p; - i2 = (t->level3_size + 1) << t->p; - for (i = i1; i < i2; i++) - t->level3[i] = DEFAULT; - t->level2[index2] = t->level3_size++; - } - - index3 += t->level2[index2] << t->p; - - t->level3[index3] = value; -} - -#ifdef ITERATE -/* Apply a function to all entries in the table. */ -static void -CONCAT(TABLE,_iterate) (struct TABLE *t, - void (*fn) (uint32_t wc, ELEMENT value)) -{ - uint32_t index1; - for (index1 = 0; index1 < t->level1_size; index1++) - { - uint32_t lookup1 = t->level1[index1]; - if (lookup1 != EMPTY) - { - uint32_t lookup1_shifted = lookup1 << t->q; - uint32_t index2; - for (index2 = 0; index2 < (1 << t->q); index2++) - { - uint32_t lookup2 = t->level2[index2 + lookup1_shifted]; - if (lookup2 != EMPTY) - { - uint32_t lookup2_shifted = lookup2 << t->p; - uint32_t index3; - for (index3 = 0; index3 < (1 << t->p); index3++) - { - ELEMENT lookup3 = t->level3[index3 + lookup2_shifted]; - if (lookup3 != DEFAULT) - fn ((((index1 << t->q) + index2) << t->p) + index3, - lookup3); - } - } - } - } - } -} -#endif - -#ifndef NO_FINALIZE -/* Finalize and shrink. */ -static void -CONCAT(TABLE,_finalize) (struct TABLE *t) -{ - size_t i, j, k; - uint32_t reorder3[t->level3_size]; - uint32_t reorder2[t->level2_size]; - uint32_t level1_offset, level2_offset, level3_offset, last_offset; - - /* Uniquify level3 blocks. */ - k = 0; - for (j = 0; j < t->level3_size; j++) - { - for (i = 0; i < k; i++) - if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (ELEMENT)) == 0) - break; - /* Relocate block j to block i. */ - reorder3[j] = i; - if (i == k) - { - if (i != j) - memcpy (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (ELEMENT)); - k++; - } - } - t->level3_size = k; - - for (i = 0; i < (t->level2_size << t->q); i++) - if (t->level2[i] != EMPTY) - t->level2[i] = reorder3[t->level2[i]]; - - /* Uniquify level2 blocks. */ - k = 0; - for (j = 0; j < t->level2_size; j++) - { - for (i = 0; i < k; i++) - if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)) == 0) - break; - /* Relocate block j to block i. */ - reorder2[j] = i; - if (i == k) - { - if (i != j) - memcpy (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)); - k++; - } - } - t->level2_size = k; - - for (i = 0; i < t->level1_size; i++) - if (t->level1[i] != EMPTY) - t->level1[i] = reorder2[t->level1[i]]; - - /* Create and fill the resulting compressed representation. */ - last_offset = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t) - + (t->level2_size << t->q) * sizeof (uint32_t) - + (t->level3_size << t->p) * sizeof (ELEMENT); - t->result_size = (last_offset + 3) & ~3ul; - t->result = (char *) xmalloc (t->result_size); - - level1_offset = - 5 * sizeof (uint32_t); - level2_offset = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t); - level3_offset = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t) - + (t->level2_size << t->q) * sizeof (uint32_t); - - ((uint32_t *) t->result)[0] = t->q + t->p; - ((uint32_t *) t->result)[1] = t->level1_size; - ((uint32_t *) t->result)[2] = t->p; - ((uint32_t *) t->result)[3] = (1 << t->q) - 1; - ((uint32_t *) t->result)[4] = (1 << t->p) - 1; - - for (i = 0; i < t->level1_size; i++) - ((uint32_t *) (t->result + level1_offset))[i] = - (t->level1[i] == EMPTY - ? 0 - : (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset); - - for (i = 0; i < (t->level2_size << t->q); i++) - ((uint32_t *) (t->result + level2_offset))[i] = - (t->level2[i] == EMPTY - ? 0 - : (t->level2[i] << t->p) * sizeof (ELEMENT) + level3_offset); - - for (i = 0; i < (t->level3_size << t->p); i++) - ((ELEMENT *) (t->result + level3_offset))[i] = t->level3[i]; - - if (last_offset < t->result_size) - memset (t->result + last_offset, 0, t->result_size - last_offset); - - if (t->level1_alloc > 0) - free (t->level1); - if (t->level2_alloc > 0) - free (t->level2); - if (t->level3_alloc > 0) - free (t->level3); -} -#endif - -#undef EMPTY -#undef TABLE -#undef ELEMENT -#undef DEFAULT -#undef ITERATE -#undef NO_FINALIZE diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap-dir.c b/src/system/libroot/posix/glibc/locale/programs/charmap-dir.c deleted file mode 100644 index 14cf765632..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap-dir.c +++ /dev/null @@ -1,313 +0,0 @@ -/* Copyright (C) 2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "charmap-dir.h" - -extern void *xmalloc (size_t n); -extern void *xrealloc (void *p, size_t n); - -/* The data type of a charmap directory being traversed. */ -struct charmap_dir -{ - DIR *dir; - /* The directory pathname, ending in a slash. */ - char *directory; - size_t directory_len; - /* Scratch area used for returning pathnames. */ - char *pathname; - size_t pathname_size; -}; - -/* Starts a charmap directory traversal. - Returns a CHARMAP_DIR, or NULL if the directory doesn't exist. */ -CHARMAP_DIR * -charmap_opendir (const char *directory) -{ - struct charmap_dir *cdir; - DIR *dir; - size_t len; - int add_slash; - - dir = opendir (directory); - if (dir == NULL) - { - error (1, errno, gettext ("cannot read character map directory `%s'"), - directory); - return NULL; - } - - cdir = (struct charmap_dir *) xmalloc (sizeof (struct charmap_dir)); - cdir->dir = dir; - - len = strlen (directory); - add_slash = (len == 0 || directory[len - 1] != '/'); - cdir->directory = (char *) xmalloc (len + add_slash + 1); - memcpy (cdir->directory, directory, len); - if (add_slash) - cdir->directory[len] = '/'; - cdir->directory[len + add_slash] = '\0'; - cdir->directory_len = len + add_slash; - - cdir->pathname = NULL; - cdir->pathname_size = 0; - - return cdir; -} - -/* Reads the next directory entry. - Returns its charmap name, or NULL if past the last entry or upon error. - The storage returned may be overwritten by a later charmap_readdir - call on the same CHARMAP_DIR. */ -const char * -charmap_readdir (CHARMAP_DIR *cdir) -{ - for (;;) - { - struct dirent *dirent; - size_t len; - size_t size; - char *filename; - mode_t mode; - - dirent = readdir (cdir->dir); - if (dirent == NULL) - return NULL; - if (strcmp (dirent->d_name, ".") == 0) - continue; - if (strcmp (dirent->d_name, "..") == 0) - continue; - - len = strlen (dirent->d_name); - - size = cdir->directory_len + len + 1; - if (size > cdir->pathname_size) - { - free (cdir->pathname); - if (size < 2 * cdir->pathname_size) - size = 2 * cdir->pathname_size; - cdir->pathname = (char *) xmalloc (size); - cdir->pathname_size = size; - } - - stpcpy (stpcpy (cdir->pathname, cdir->directory), dirent->d_name); - filename = cdir->pathname + cdir->directory_len; - -#ifdef _DIRENT_HAVE_D_TYPE - if (dirent->d_type != DT_UNKNOWN && dirent->d_type != DT_LNK) - mode = DTTOIF (dirent->d_type); - else -#endif - { - struct stat statbuf; - - if (stat (cdir->pathname, &statbuf) < 0) - continue; - - mode = statbuf.st_mode; - } - - if (!S_ISREG (mode)) - continue; - - /* For compressed charmaps, the canonical charmap name does not - include the extension. */ - if (len > 3 && memcmp (&filename[len - 3], ".gz", 3) == 0) - filename[len - 3] = '\0'; - else if (len > 4 && memcmp (&filename[len - 4], ".bz2", 4) == 0) - filename[len - 4] = '\0'; - - return filename; - } -} - -/* Finishes a charmap directory traversal, and frees the resources - attached to the CHARMAP_DIR. */ -int -charmap_closedir (CHARMAP_DIR *cdir) -{ - DIR *dir = cdir->dir; - - free (cdir->directory); - free (cdir->pathname); - free (cdir); - return closedir (dir); -} - -/* Creates a subprocess decompressing the given pathname, and returns - a stream reading its output (the decompressed data). */ -static -FILE * -fopen_uncompressed (const char *pathname, const char *compressor) -{ - int pfd; - - pfd = open (pathname, O_RDONLY); - if (pfd >= 0) - { - struct stat statbuf; - int fd[2]; - - if (fstat (pfd, &statbuf) >= 0 - && S_ISREG (statbuf.st_mode) - && pipe (fd) >= 0) - { - char *argv[4] - = { (char *) compressor, (char *) "-d", (char *) "-c", NULL }; - posix_spawn_file_actions_t actions; - - if (posix_spawn_file_actions_init (&actions) == 0) - { - if (posix_spawn_file_actions_adddup2 (&actions, - fd[1], STDOUT_FILENO) == 0 - && posix_spawn_file_actions_addclose (&actions, fd[1]) == 0 - && posix_spawn_file_actions_addclose (&actions, fd[0]) == 0 - && posix_spawn_file_actions_adddup2 (&actions, - pfd, STDIN_FILENO) == 0 - && posix_spawn_file_actions_addclose (&actions, pfd) == 0 - && posix_spawnp (NULL, compressor, &actions, NULL, - argv, environ) == 0) - { - posix_spawn_file_actions_destroy (&actions); - close (fd[1]); - close (pfd); - return fdopen (fd[0], "r"); - } - posix_spawn_file_actions_destroy (&actions); - } - close (fd[1]); - close (fd[0]); - } - close (pfd); - } - return NULL; -} - -/* Opens a charmap for reading, given its name (not an alias name). */ -FILE * -charmap_open (const char *directory, const char *name) -{ - size_t dlen = strlen (directory); - int add_slash = (dlen == 0 || directory[dlen - 1] != '/'); - size_t nlen = strlen (name); - char *pathname; - char *p; - FILE *stream; - - pathname = alloca (dlen + add_slash + nlen + 5); - p = stpcpy (pathname, directory); - if (add_slash) - *p++ = '/'; - p = stpcpy (p, name); - - stream = fopen (pathname, "r"); - if (stream != NULL) - return stream; - - memcpy (p, ".gz", 4); - stream = fopen_uncompressed (pathname, "gzip"); - if (stream != NULL) - return stream; - - memcpy (p, ".bz2", 5); - stream = fopen_uncompressed (pathname, "bzip2"); - if (stream != NULL) - return stream; - - return NULL; -} - -/* An empty alias list. Avoids the need to return NULL from - charmap_aliases. */ -static char *empty[1]; - -/* Returns a NULL terminated list of alias names of a charmap. */ -char ** -charmap_aliases (const char *directory, const char *name) -{ - FILE *stream; - char **aliases; - size_t naliases; - - stream = charmap_open (directory, name); - if (stream == NULL) - return empty; - - aliases = NULL; - naliases = 0; - - while (!feof (stream)) - { - char *alias = NULL; - char junk[BUFSIZ]; - - if (fscanf (stream, " %as", &alias) == 1 - || fscanf (stream, "%% alias %as", &alias) == 1) - { - aliases = (char **) xrealloc (aliases, - (naliases + 2) * sizeof (char *)); - aliases[naliases++] = alias; - } - - /* Read the rest of the line. */ - if (fgets (junk, sizeof junk, stream) != NULL) - { - if (strstr (junk, "CHARMAP") != NULL) - /* We cannot expect more aliases from now on. */ - break; - - while (strchr (junk, '\n') == NULL - && fgets (junk, sizeof junk, stream) != NULL) - continue; - } - } - - fclose (stream); - - if (naliases == 0) - return empty; - - aliases[naliases] = NULL; - return aliases; -} - -/* Frees an alias list returned by charmap_aliases. */ -void -charmap_free_aliases (char **aliases) -{ - if (aliases != empty) - { - char **p; - - for (p = aliases; *p; p++) - free (*p); - - free (aliases); - } -} diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap-dir.h b/src/system/libroot/posix/glibc/locale/programs/charmap-dir.h deleted file mode 100644 index 1d07c64ec1..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap-dir.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _CHARMAP_DIR_H -#define _CHARMAP_DIR_H 1 - -/* The data type of a charmap directory being traversed. */ -typedef struct charmap_dir CHARMAP_DIR; - -/* Starts a charmap directory traversal. - Returns a CHARMAP_DIR, or NULL if the directory doesn't exist. */ -extern CHARMAP_DIR *charmap_opendir (const char *directory); - -/* Reads the next directory entry. - Returns its charmap name, or NULL if past the last entry or upon error. - The storage returned may be overwritten by a later charmap_readdir - call on the same CHARMAP_DIR. */ -extern const char *charmap_readdir (CHARMAP_DIR *dir); - -/* Finishes a charmap directory traversal, and frees the resources - attached to the CHARMAP_DIR. */ -extern int charmap_closedir (CHARMAP_DIR *dir); - -/* Returns a NULL terminated list of alias names of a charmap. */ -extern char **charmap_aliases (const char *directory, const char *name); - -/* Frees an alias list returned by charmap_aliases. */ -extern void charmap_free_aliases (char **aliases); - -/* Opens a charmap for reading, given its name (not an alias name). */ -extern FILE *charmap_open (const char *directory, const char *name); - -#endif /* _CHARMAP_DIR_H */ diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap-kw.gperf b/src/system/libroot/posix/glibc/locale/programs/charmap-kw.gperf deleted file mode 100644 index 83da36aa74..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap-kw.gperf +++ /dev/null @@ -1,43 +0,0 @@ -%{ -/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper, . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "locfile-token.h" -%} -struct keyword_t ; -%% -code_set_name, tok_code_set_name, 1 -mb_cur_max, tok_mb_cur_max, 1 -mb_cur_min, tok_mb_cur_min, 1 -escape_char, tok_escape_char, 1 -comment_char, tok_comment_char, 1 -g0esc, tok_g0esc, 1 -g1esc, tok_g1esc, 1 -g2esc, tok_g2esc, 1 -g3esc, tok_g3esc, 1 -escseq, tok_escseq, 1 -addset, tok_addset, 1 -include, tok_include, 1 -CHARMAP, tok_charmap, 0 -END, tok_end, 0 -WIDTH, tok_width, 0 -WIDTH_VARIABLE, tok_width_variable, 0 -WIDTH_DEFAULT, tok_width_default, 0 diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap-kw.h b/src/system/libroot/posix/glibc/locale/programs/charmap-kw.h deleted file mode 100644 index 089f45d7d8..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap-kw.h +++ /dev/null @@ -1,143 +0,0 @@ -/* ANSI-C code produced by gperf version 2.7.2 */ -/* Command-line: gperf -acCgopt -k'1,2,5,9,$' -L ANSI-C -N charmap_hash programs/charmap-kw.gperf */ -/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper, . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "locfile-token.h" -struct keyword_t ; - -#define TOTAL_KEYWORDS 17 -#define MIN_WORD_LENGTH 3 -#define MAX_WORD_LENGTH 14 -#define MIN_HASH_VALUE 3 -#define MAX_HASH_VALUE 35 -/* maximum key range = 33, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static unsigned int -hash (register const char *str, register unsigned int len) -{ - static const unsigned char asso_values[] = - { - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 25, 10, - 15, 20, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 10, 0, 0, - 5, 36, 0, 0, 36, 36, 36, 0, 0, 36, - 0, 36, 0, 36, 0, 36, 36, 0, 36, 36, - 36, 36, 36, 36, 36, 0, 36, 0, 0, 0, - 10, 0, 36, 0, 0, 0, 36, 36, 36, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, - 25, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36 - }; - register int hval = len; - - switch (hval) - { - default: - case 9: - hval += asso_values[(unsigned char)str[8]]; - case 8: - case 7: - case 6: - case 5: - hval += asso_values[(unsigned char)str[4]]; - case 4: - case 3: - case 2: - hval += asso_values[(unsigned char)str[1]]; - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval + asso_values[(unsigned char)str[len - 1]]; -} - -#ifdef __GNUC__ -__inline -#endif -const struct keyword_t * -charmap_hash (register const char *str, register unsigned int len) -{ - static const struct keyword_t wordlist[] = - { - {""}, {""}, {""}, - {"END", tok_end, 0}, - {""}, - {"WIDTH", tok_width, 0}, - {"escseq", tok_escseq, 1}, - {"include", tok_include, 1}, - {""}, {""}, - {"mb_cur_min", tok_mb_cur_min, 1}, - {"escape_char", tok_escape_char, 1}, - {"comment_char", tok_comment_char, 1}, - {"code_set_name", tok_code_set_name, 1}, - {"WIDTH_VARIABLE", tok_width_variable, 0}, - {"g1esc", tok_g1esc, 1}, - {"addset", tok_addset, 1}, - {"CHARMAP", tok_charmap, 0}, - {"WIDTH_DEFAULT", tok_width_default, 0}, - {""}, - {"g2esc", tok_g2esc, 1}, - {""}, {""}, {""}, {""}, - {"g3esc", tok_g3esc, 1}, - {""}, {""}, {""}, {""}, - {"g0esc", tok_g0esc, 1}, - {""}, {""}, {""}, {""}, - {"mb_cur_max", tok_mb_cur_max, 1} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') - return &wordlist[key]; - } - } - return 0; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap.c b/src/system/libroot/posix/glibc/locale/programs/charmap.c deleted file mode 100644 index 5d2441d17a..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap.c +++ /dev/null @@ -1,1085 +0,0 @@ -/* Copyright (C) 1996,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "error.h" -#include "linereader.h" -#include "charmap.h" -#include "charmap-dir.h" -#include "repertoire.h" - -#include - - -/* Define the lookup function. */ -#include "charmap-kw.h" - - -extern void *xmalloc (size_t __n); - -/* Prototypes for local functions. */ -static struct charmap_t *parse_charmap (struct linereader *cmfile, - int verbose, int be_quiet); -static void new_width (struct linereader *cmfile, struct charmap_t *result, - const char *from, const char *to, - unsigned long int width); -static void charmap_new_char (struct linereader *lr, struct charmap_t *cm, - int nbytes, char *bytes, const char *from, - const char *to, int decimal_ellipsis, int step); - - -#ifdef NEED_NULL_POINTER -static const char *null_pointer; -#endif - -static struct linereader * -cmlr_open (const char *directory, const char *name, kw_hash_fct_t hf) -{ - FILE *fp; - - fp = charmap_open (directory, name); - if (fp == NULL) - return NULL; - else - { - size_t dlen = strlen (directory); - int add_slash = (dlen == 0 || directory[dlen - 1] != '/'); - size_t nlen = strlen (name); - char *pathname; - char *p; - - pathname = alloca (dlen + add_slash + nlen + 1); - p = stpcpy (pathname, directory); - if (add_slash) - *p++ = '/'; - stpcpy (p, name); - - return lr_create (fp, pathname, hf); - } -} - -struct charmap_t * -charmap_read (const char *filename, int verbose, int be_quiet, int use_default) -{ - struct charmap_t *result = NULL; - - if (filename != NULL) - { - struct linereader *cmfile; - - /* First try the name as found in the parameter. */ - cmfile = lr_open (filename, charmap_hash); - if (cmfile == NULL) - { - /* No successful. So start looking through the directories - in the I18NPATH if this is a simple name. */ - if (strchr (filename, '/') == NULL) - { - char *i18npath = getenv ("I18NPATH"); - if (i18npath != NULL && *i18npath != '\0') - { - char path[strlen (i18npath) + sizeof ("/charmaps")]; - char *next; - i18npath = strdupa (i18npath); - - while (cmfile == NULL - && (next = strsep (&i18npath, ":")) != NULL) - { - stpcpy (stpcpy (path, next), "/charmaps"); - cmfile = cmlr_open (path, filename, charmap_hash); - - if (cmfile == NULL) - { - /* Try without the "/charmaps" part. */ - cmfile = cmlr_open (next, filename, charmap_hash); - } - } - } - - if (cmfile == NULL) - { - /* Try the default directory. */ - cmfile = cmlr_open (CHARMAP_PATH, filename, charmap_hash); - } - } - } - - if (cmfile != NULL) - { - result = parse_charmap (cmfile, verbose, be_quiet); - - if (result == NULL && !be_quiet) - error (0, errno, _("character map file `%s' not found"), filename); - } - } - - if (result == NULL && filename != NULL && strchr (filename, '/') == NULL) - { - /* OK, one more try. We also accept the names given to the - character sets in the files. Sometimes they differ from the - file name. */ - CHARMAP_DIR *dir; - - dir = charmap_opendir (CHARMAP_PATH); - if (dir != NULL) - { - const char *dirent; - - while ((dirent = charmap_readdir (dir)) != NULL) - { - char **aliases; - char **p; - int found; - - aliases = charmap_aliases (CHARMAP_PATH, dirent); - found = 0; - for (p = aliases; *p; p++) - if (strcasecmp (*p, filename) == 0) - { - found = 1; - break; - } - charmap_free_aliases (aliases); - - if (found) - { - struct linereader *cmfile; - - cmfile = cmlr_open (CHARMAP_PATH, dirent, charmap_hash); - if (cmfile != NULL) - result = parse_charmap (cmfile, verbose, be_quiet); - - break; - } - } - - charmap_closedir (dir); - } - } - - if (result == NULL && DEFAULT_CHARMAP != NULL) - { - struct linereader *cmfile; - - cmfile = cmlr_open (CHARMAP_PATH, DEFAULT_CHARMAP, charmap_hash); - if (cmfile != NULL) - result = parse_charmap (cmfile, verbose, be_quiet); - - if (result == NULL) - error (4, errno, _("default character map file `%s' not found"), - DEFAULT_CHARMAP); - } - - /* Test of ASCII compatibility of locale encoding. - - Verify that the encoding to be used in a locale is ASCII compatible, - at least for the graphic characters, excluding the control characters, - '$' and '@'. This constraint comes from an ISO C 99 restriction. - - ISO C 99 section 7.17.(2) (about wchar_t): - the null character shall have the code value zero and each member of - the basic character set shall have a code value equal to its value - when used as the lone character in an integer character constant. - ISO C 99 section 5.2.1.(3): - Both the basic source and basic execution character sets shall have - the following members: the 26 uppercase letters of the Latin alphabet - A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - the 26 lowercase letters of the Latin alphabet - a b c d e f g h i j k l m n o p q r s t u v w x y z - the 10 decimal digits - 0 1 2 3 4 5 6 7 8 9 - the following 29 graphic characters - ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~ - the space character, and control characters representing horizontal - tab, vertical tab, and form feed. - - Therefore, for all members of the "basic character set", the 'char' code - must have the same value as the 'wchar_t' code, which in glibc is the - same as the Unicode code, which for all of the enumerated characters - is identical to the ASCII code. */ - if (result != NULL && use_default) - { - static const char basic_charset[] = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '!', '"', '#', '%', '&', '\'', '(', ')', '*', '+', ',', '-', - '.', '/', ':', ';', '<', '=', '>', '?', '[', '\\', ']', '^', - '_', '{', '|', '}', '~', ' ', '\t', '\v', '\f', '\0' - }; - int failed = 0; - const char *p = basic_charset; - - do - { - struct charseq * seq = charmap_find_symbol (result, p, 1); - - if (seq == NULL || seq->ucs4 != *p) - failed = 1; - } - while (*p++ != '\0'); - - if (failed) - fprintf (stderr, _("\ -character map `%s' is not ASCII compatible, locale not ISO C compliant\n"), - result->code_set_name); - } - - return result; -} - - -static struct charmap_t * -parse_charmap (struct linereader *cmfile, int verbose, int be_quiet) -{ - struct charmap_t *result; - int state; - enum token_t expected_tok = tok_error; - const char *expected_str = NULL; - char *from_name = NULL; - char *to_name = NULL; - enum token_t ellipsis = 0; - int step = 1; - - /* We don't want symbolic names in string to be translated. */ - cmfile->translate_strings = 0; - - /* Allocate room for result. */ - result = (struct charmap_t *) xmalloc (sizeof (struct charmap_t)); - memset (result, '\0', sizeof (struct charmap_t)); - /* The default DEFAULT_WIDTH is 1. */ - result->width_default = 1; - -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free - obstack_init (&result->mem_pool); - - if (init_hash (&result->char_table, 256) - || init_hash (&result->byte_table, 256)) - { - free (result); - return NULL; - } - - /* We use a state machine to describe the charmap description file - format. */ - state = 1; - while (1) - { - /* What's on? */ - struct token *now = lr_token (cmfile, NULL, NULL, verbose); - enum token_t nowtok = now->tok; - struct token *arg; - - if (nowtok == tok_eof) - break; - - switch (state) - { - case 1: - /* The beginning. We expect the special declarations, EOL or - `CHARMAP'. */ - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (nowtok == tok_charmap) - { - from_name = NULL; - to_name = NULL; - - /* We have to set up the real work. Fill in some - default values. */ - if (result->mb_cur_max == 0) - result->mb_cur_max = 1; - if (result->mb_cur_min == 0) - result->mb_cur_min = result->mb_cur_max; - if (result->mb_cur_min > result->mb_cur_max) - { - if (!be_quiet) - error (0, 0, _("\ -%s: must be greater than \n"), - cmfile->fname); - - result->mb_cur_min = result->mb_cur_max; - } - - lr_ignore_rest (cmfile, 1); - - state = 2; - continue; - } - - if (nowtok != tok_code_set_name && nowtok != tok_mb_cur_max - && nowtok != tok_mb_cur_min && nowtok != tok_escape_char - && nowtok != tok_comment_char && nowtok != tok_g0esc - && nowtok != tok_g1esc && nowtok != tok_g2esc - && nowtok != tok_g3esc && nowtok != tok_repertoiremap - && nowtok != tok_include) - { - lr_error (cmfile, _("syntax error in prolog: %s"), - _("invalid definition")); - - lr_ignore_rest (cmfile, 0); - continue; - } - - /* We know that we need an argument. */ - arg = lr_token (cmfile, NULL, NULL, verbose); - - switch (nowtok) - { - case tok_code_set_name: - case tok_repertoiremap: - if (arg->tok != tok_ident && arg->tok != tok_string) - { - badarg: - lr_error (cmfile, _("syntax error in prolog: %s"), - _("bad argument")); - - lr_ignore_rest (cmfile, 0); - continue; - } - - if (nowtok == tok_code_set_name) - result->code_set_name = obstack_copy0 (&result->mem_pool, - arg->val.str.startmb, - arg->val.str.lenmb); - else - result->repertoiremap = obstack_copy0 (&result->mem_pool, - arg->val.str.startmb, - arg->val.str.lenmb); - - lr_ignore_rest (cmfile, 1); - continue; - - case tok_mb_cur_max: - case tok_mb_cur_min: - if (arg->tok != tok_number) - goto badarg; - - if (verbose - && ((nowtok == tok_mb_cur_max - && result->mb_cur_max != 0) - || (nowtok == tok_mb_cur_max - && result->mb_cur_max != 0))) - lr_error (cmfile, _("duplicate definition of <%s>"), - nowtok == tok_mb_cur_min - ? "mb_cur_min" : "mb_cur_max"); - - if (arg->val.num < 1) - { - lr_error (cmfile, - _("value for <%s> must be 1 or greater"), - nowtok == tok_mb_cur_min - ? "mb_cur_min" : "mb_cur_max"); - - lr_ignore_rest (cmfile, 0); - continue; - } - if ((nowtok == tok_mb_cur_max && result->mb_cur_min != 0 - && (int) arg->val.num < result->mb_cur_min) - || (nowtok == tok_mb_cur_min && result->mb_cur_max != 0 - && (int) arg->val.num > result->mb_cur_max)) - { - lr_error (cmfile, _("\ -value of <%s> must be greater or equal than the value of <%s>"), - "mb_cur_max", "mb_cur_min"); - - lr_ignore_rest (cmfile, 0); - continue; - } - - if (nowtok == tok_mb_cur_max) - result->mb_cur_max = arg->val.num; - else - result->mb_cur_min = arg->val.num; - - lr_ignore_rest (cmfile, 1); - continue; - - case tok_escape_char: - case tok_comment_char: - if (arg->tok != tok_ident) - goto badarg; - - if (arg->val.str.lenmb != 1) - { - lr_error (cmfile, _("\ -argument to <%s> must be a single character"), - nowtok == tok_escape_char ? "escape_char" - : "comment_char"); - - lr_ignore_rest (cmfile, 0); - continue; - } - - if (nowtok == tok_escape_char) - cmfile->escape_char = *arg->val.str.startmb; - else - cmfile->comment_char = *arg->val.str.startmb; - - lr_ignore_rest (cmfile, 1); - continue; - - case tok_g0esc: - case tok_g1esc: - case tok_g2esc: - case tok_g3esc: - case tok_escseq: - lr_ignore_rest (cmfile, 0); /* XXX */ - continue; - - case tok_include: - lr_error (cmfile, _("\ -character sets with locking states are not supported")); - exit (4); - - default: - /* Cannot happen. */ - assert (! "Should not happen"); - } - break; - - case 2: - /* We have seen `CHARMAP' and now are in the body. Each line - must have the format "%s %s %s\n" or "%s...%s %s %s\n". */ - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (nowtok == tok_end) - { - expected_tok = tok_charmap; - expected_str = "CHARMAP"; - state = 90; - continue; - } - - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "CHARMAP", _("no symbolic name given")); - - lr_ignore_rest (cmfile, 0); - continue; - } - - /* If the previous line was not completely correct free the - used memory. */ - if (from_name != NULL) - obstack_free (&result->mem_pool, from_name); - - if (nowtok == tok_bsymbol) - from_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - from_name = (char *) obstack_finish (&result->mem_pool); - } - to_name = NULL; - - state = 3; - continue; - - case 3: - /* We have two possibilities: We can see an ellipsis or an - encoding value. */ - if (nowtok == tok_ellipsis3 || nowtok == tok_ellipsis4 - || nowtok == tok_ellipsis2 || nowtok == tok_ellipsis4_2 - || nowtok == tok_ellipsis2_2) - { - ellipsis = nowtok; - if (nowtok == tok_ellipsis4_2) - { - step = 2; - nowtok = tok_ellipsis4; - } - else if (nowtok == tok_ellipsis2_2) - { - step = 2; - nowtok = tok_ellipsis2; - } - state = 4; - continue; - } - /* FALLTHROUGH */ - - case 5: - if (nowtok != tok_charcode) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "CHARMAP", _("invalid encoding given")); - - lr_ignore_rest (cmfile, 0); - - state = 2; - continue; - } - - if (now->val.charcode.nbytes < result->mb_cur_min) - lr_error (cmfile, _("too few bytes in character encoding")); - else if (now->val.charcode.nbytes > result->mb_cur_max) - lr_error (cmfile, _("too many bytes in character encoding")); - else - charmap_new_char (cmfile, result, now->val.charcode.nbytes, - now->val.charcode.bytes, from_name, to_name, - ellipsis != tok_ellipsis2, step); - - /* Ignore trailing comment silently. */ - lr_ignore_rest (cmfile, 0); - - from_name = NULL; - to_name = NULL; - ellipsis = tok_none; - step = 1; - - state = 2; - continue; - - case 4: - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "CHARMAP", - _("no symbolic name given for end of range")); - - lr_ignore_rest (cmfile, 0); - continue; - } - - /* Copy the to-name in a safe place. */ - if (nowtok == tok_bsymbol) - to_name = (char *) obstack_copy0 (&result->mem_pool, - cmfile->token.val.str.startmb, - cmfile->token.val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - to_name = (char *) obstack_finish (&result->mem_pool); - } - - state = 5; - continue; - - case 90: - if (nowtok != expected_tok) - lr_error (cmfile, _("\ -`%1$s' definition does not end with `END %1$s'"), expected_str); - - lr_ignore_rest (cmfile, nowtok == expected_tok); - state = 91; - continue; - - case 91: - /* Waiting for WIDTH... */ - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (nowtok == tok_width_default) - { - state = 92; - continue; - } - - if (nowtok == tok_width) - { - lr_ignore_rest (cmfile, 1); - state = 93; - continue; - } - - if (nowtok == tok_width_variable) - { - lr_ignore_rest (cmfile, 1); - state = 98; - continue; - } - - lr_error (cmfile, _("\ -only WIDTH definitions are allowed to follow the CHARMAP definition")); - - lr_ignore_rest (cmfile, 0); - continue; - - case 92: - if (nowtok != tok_number) - lr_error (cmfile, _("value for %s must be an integer"), - "WIDTH_DEFAULT"); - else - result->width_default = now->val.num; - - lr_ignore_rest (cmfile, nowtok == tok_number); - - state = 91; - continue; - - case 93: - /* We now expect `END WIDTH' or lines of the format "%s %d\n" or - "%s...%s %d\n". */ - if (nowtok == tok_eol) - /* ignore empty lines. */ - continue; - - if (nowtok == tok_end) - { - expected_tok = tok_width; - expected_str = "WIDTH"; - state = 90; - continue; - } - - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "WIDTH", _("no symbolic name given")); - - lr_ignore_rest (cmfile, 0); - continue; - } - - if (from_name != NULL) - obstack_free (&result->mem_pool, from_name); - - if (nowtok == tok_bsymbol) - from_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - from_name = (char *) obstack_finish (&result->mem_pool); - } - - to_name = NULL; - - state = 94; - continue; - - case 94: - if (nowtok == tok_ellipsis3) - { - state = 95; - continue; - } - - case 96: - if (nowtok != tok_number) - lr_error (cmfile, _("value for %s must be an integer"), - "WIDTH"); - else - { - /* Store width for chars. */ - new_width (cmfile, result, from_name, to_name, now->val.num); - - from_name = NULL; - to_name = NULL; - } - - lr_ignore_rest (cmfile, nowtok == tok_number); - - state = 93; - continue; - - case 95: - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "WIDTH", _("no symbolic name given for end of range")); - - lr_ignore_rest (cmfile, 0); - - state = 93; - continue; - } - - if (nowtok == tok_bsymbol) - to_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - to_name = (char *) obstack_finish (&result->mem_pool); - } - - state = 96; - continue; - - case 98: - /* We now expect `END WIDTH_VARIABLE' or lines of the format - "%s\n" or "%s...%s\n". */ - if (nowtok == tok_eol) - /* ignore empty lines. */ - continue; - - if (nowtok == tok_end) - { - expected_tok = tok_width_variable; - expected_str = "WIDTH_VARIABLE"; - state = 90; - continue; - } - - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "WIDTH_VARIABLE", _("no symbolic name given")); - - lr_ignore_rest (cmfile, 0); - - continue; - } - - if (from_name != NULL) - obstack_free (&result->mem_pool, from_name); - - if (nowtok == tok_bsymbol) - from_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - from_name = (char *) obstack_finish (&result->mem_pool); - } - to_name = NULL; - - state = 99; - continue; - - case 99: - if (nowtok == tok_ellipsis3) - state = 100; - - /* Store info. */ - from_name = NULL; - - /* Warn */ - state = 98; - continue; - - case 100: - if (nowtok != tok_bsymbol && nowtok != tok_ucs4) - { - lr_error (cmfile, _("syntax error in %s definition: %s"), - "WIDTH_VARIABLE", - _("no symbolic name given for end of range")); - lr_ignore_rest (cmfile, 0); - continue; - } - - if (nowtok == tok_bsymbol) - to_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - else - { - obstack_printf (&result->mem_pool, "U%08X", - cmfile->token.val.ucs4); - obstack_1grow (&result->mem_pool, '\0'); - to_name = (char *) obstack_finish (&result->mem_pool); - } - - /* XXX Enter value into table. */ - - lr_ignore_rest (cmfile, 1); - - state = 98; - continue; - - default: - error (5, 0, _("%s: error in state machine"), __FILE__); - /* NOTREACHED */ - } - break; - } - - if (state != 91 && !be_quiet) - error (0, 0, _("%s: premature end of file"), cmfile->fname); - - lr_close (cmfile); - - return result; -} - - -static void -new_width (struct linereader *cmfile, struct charmap_t *result, - const char *from, const char *to, unsigned long int width) -{ - struct charseq *from_val; - struct charseq *to_val; - - from_val = charmap_find_value (result, from, strlen (from)); - if (from_val == NULL) - { - lr_error (cmfile, _("unknown character `%s'"), from); - return; - } - - if (to == NULL) - to_val = from_val; - else - { - to_val = charmap_find_value (result, to, strlen (to)); - if (to_val == NULL) - { - lr_error (cmfile, _("unknown character `%s'"), to); - return; - } - } - - if (result->nwidth_rules >= result->nwidth_rules_max) - { - size_t new_size = result->nwidth_rules + 32; - struct width_rule *new_rules = - (struct width_rule *) obstack_alloc (&result->mem_pool, - (new_size - * sizeof (struct width_rule))); - - memcpy (new_rules, result->width_rules, - result->nwidth_rules_max * sizeof (struct width_rule)); - - result->width_rules = new_rules; - result->nwidth_rules_max = new_size; - } - - result->width_rules[result->nwidth_rules].from = from_val; - result->width_rules[result->nwidth_rules].to = to_val; - result->width_rules[result->nwidth_rules].width = (unsigned int) width; - ++result->nwidth_rules; -} - - -struct charseq * -charmap_find_value (const struct charmap_t *cm, const char *name, size_t len) -{ - void *result; - - return (find_entry ((hash_table *) &cm->char_table, name, len, &result) - < 0 ? NULL : (struct charseq *) result); -} - - -static void -charmap_new_char (struct linereader *lr, struct charmap_t *cm, - int nbytes, char *bytes, const char *from, const char *to, - int decimal_ellipsis, int step) -{ - hash_table *ht = &cm->char_table; - hash_table *bt = &cm->byte_table; - struct obstack *ob = &cm->mem_pool; - char *from_end; - char *to_end; - const char *cp; - int prefix_len, len1, len2; - unsigned int from_nr, to_nr, cnt; - struct charseq *newp; - - len1 = strlen (from); - - if (to == NULL) - { - newp = (struct charseq *) obstack_alloc (ob, sizeof (*newp) + nbytes); - newp->nbytes = nbytes; - memcpy (newp->bytes, bytes, nbytes); - newp->name = from; - - newp->ucs4 = UNINITIALIZED_CHAR_VALUE; - if ((from[0] == 'U' || from[0] == 'P') && (len1 == 5 || len1 == 9)) - { - /* Maybe the name is of the form `Uxxxx' or `Uxxxxxxxx' where - xxxx and xxxxxxxx are hexadecimal numbers. In this case - we use the value of xxxx or xxxxxxxx as the UCS4 value of - this character and we don't have to consult the repertoire - map. - - If the name is of the form `Pxxxx' or `Pxxxxxxxx' the xxxx - and xxxxxxxx also give the code point in UCS4 but this must - be in the private, i.e., unassigned, area. This should be - used for characters which do not (yet) have an equivalent - in ISO 10646 and Unicode. */ - char *endp; - - errno = 0; - newp->ucs4 = strtoul (from + 1, &endp, 16); - if (endp - from != len1 - || (newp->ucs4 == ULONG_MAX && errno == ERANGE) - || newp->ucs4 >= 0x80000000) - /* This wasn't successful. Signal this name cannot be a - correct UCS value. */ - newp->ucs4 = UNINITIALIZED_CHAR_VALUE; - } - - insert_entry (ht, from, len1, newp); - insert_entry (bt, newp->bytes, nbytes, newp); - /* Please note that it isn't a bug if a symbol is defined more - than once. All later definitions are simply discarded. */ - return; - } - - /* We have a range: the names must have names with equal prefixes - and an equal number of digits, where the second number is greater - or equal than the first. */ - len2 = strlen (to); - - if (len1 != len2) - { - illegal_range: - lr_error (lr, _("invalid names for character range")); - return; - } - - cp = &from[len1 - 1]; - if (decimal_ellipsis) - while (isdigit (*cp) && cp >= from) - --cp; - else - while (isxdigit (*cp) && cp >= from) - { - if (!isdigit (*cp) && !isupper (*cp)) - lr_error (lr, _("\ -hexadecimal range format should use only capital characters")); - --cp; - } - - prefix_len = (cp - from) + 1; - - if (cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0) - goto illegal_range; - - errno = 0; - from_nr = strtoul (&from[prefix_len], &from_end, decimal_ellipsis ? 10 : 16); - if (*from_end != '\0' || (from_nr == ULONG_MAX && errno == ERANGE) - || ((to_nr = strtoul (&to[prefix_len], &to_end, - decimal_ellipsis ? 10 : 16)) == ULONG_MAX - && errno == ERANGE) - || *to_end != '\0') - { - lr_error (lr, _("<%s> and <%s> are illegal names for range"), from, to); - return; - } - - if (from_nr > to_nr) - { - lr_error (lr, _("upper limit in range is not higher then lower limit")); - return; - } - - for (cnt = from_nr; cnt <= to_nr; cnt += step) - { - char *name_end; - obstack_printf (ob, decimal_ellipsis ? "%.*s%0*d" : "%.*s%0*X", - prefix_len, from, len1 - prefix_len, cnt); - obstack_1grow (ob, '\0'); - name_end = obstack_finish (ob); - - newp = (struct charseq *) obstack_alloc (ob, sizeof (*newp) + nbytes); - newp->nbytes = nbytes; - memcpy (newp->bytes, bytes, nbytes); - newp->name = name_end; - - newp->ucs4 = UNINITIALIZED_CHAR_VALUE; - if ((name_end[0] == 'U' || name_end[0] == 'P') - && (len1 == 5 || len1 == 9)) - { - /* Maybe the name is of the form `Uxxxx' or `Uxxxxxxxx' where - xxxx and xxxxxxxx are hexadecimal numbers. In this case - we use the value of xxxx or xxxxxxxx as the UCS4 value of - this character and we don't have to consult the repertoire - map. - - If the name is of the form `Pxxxx' or `Pxxxxxxxx' the xxxx - and xxxxxxxx also give the code point in UCS4 but this must - be in the private, i.e., unassigned, area. This should be - used for characters which do not (yet) have an equivalent - in ISO 10646 and Unicode. */ - char *endp; - - errno = 0; - newp->ucs4 = strtoul (name_end + 1, &endp, 16); - if (endp - name_end != len1 - || (newp->ucs4 == ULONG_MAX && errno == ERANGE) - || newp->ucs4 >= 0x80000000) - /* This wasn't successful. Signal this name cannot be a - correct UCS value. */ - newp->ucs4 = UNINITIALIZED_CHAR_VALUE; - } - - insert_entry (ht, name_end, len1, newp); - insert_entry (bt, newp->bytes, nbytes, newp); - /* Please note we don't examine the return value since it is no error - if we have two definitions for a symbol. */ - - /* Increment the value in the byte sequence. */ - if (++bytes[nbytes - 1] == '\0') - { - int b = nbytes - 2; - - do - if (b < 0) - { - lr_error (lr, - _("resulting bytes for range not representable.")); - return; - } - while (++bytes[b--] == 0); - } - } -} - - -struct charseq * -charmap_find_symbol (const struct charmap_t *cm, const char *bytes, - size_t nbytes) -{ - void *result; - - return (find_entry ((hash_table *) &cm->byte_table, bytes, nbytes, &result) - < 0 ? NULL : (struct charseq *) result); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/charmap.h b/src/system/libroot/posix/glibc/locale/programs/charmap.h deleted file mode 100644 index f4ca3abe6c..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/charmap.h +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _CHARMAP_H -#define _CHARMAP_H - -#include - -#include "repertoire.h" -#include "simple-hash.h" - - -struct width_rule -{ - struct charseq *from; - struct charseq *to; - unsigned int width; -}; - - -struct charmap_t -{ - const char *code_set_name; - const char *repertoiremap; - int mb_cur_min; - int mb_cur_max; - - struct width_rule *width_rules; - size_t nwidth_rules; - size_t nwidth_rules_max; - unsigned int width_default; - - struct obstack mem_pool; - hash_table char_table; - hash_table byte_table; - hash_table ucs4_table; -}; - - -/* This is the structure used for entries in the hash table. It represents - the sequence of bytes used for the coded character. */ -struct charseq -{ - const char *name; - uint32_t ucs4; - int nbytes; - unsigned char bytes[0]; -}; - - -/* Prototypes for charmap handling functions. */ -extern struct charmap_t *charmap_read (const char *filename, int verbose, - int be_quiet, int use_default); - -/* Return the value stored under the given key in the hashing table. */ -extern struct charseq *charmap_find_value (const struct charmap_t *charmap, - const char *name, size_t len); - -/* Return symbol for given multibyte sequence. */ -extern struct charseq *charmap_find_symbol (const struct charmap_t *charmap, - const char *name, size_t len); - -#endif /* charmap.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/config.h b/src/system/libroot/posix/glibc/locale/programs/config.h deleted file mode 100644 index 12a921c1cf..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/config.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Configuration for localedef program. - Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LD_CONFIG_H -#define _LD_CONFIG_H 1 - -/* Use the internal textdomain used for libc messages. */ -#define PACKAGE _libc_intl_domainname -#ifndef VERSION -/* Get libc version number. */ -#include "../../version.h" -#endif - -#define DEFAULT_CHARMAP "ANSI_X3.4-1968" /* ASCII */ - -#ifndef PARAMS -# if __STDC__ -# define PARAMS(args) args -# else -# define PARAMS(args) () -# endif -#endif - -/* This must be one higer than the last used LC_xxx category value. */ -#define __LC_LAST 13 - -#include_next -#endif diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-address.c b/src/system/libroot/posix/glibc/locale/programs/ld-address.c deleted file mode 100644 index 96866a2ef6..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-address.c +++ /dev/null @@ -1,598 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -static struct -{ - const char ab2[3]; - const char ab3[4]; - uint32_t num; -} iso3166[] = -{ -#define DEFINE_COUNTRY_CODE(Name, Ab2, Ab3, Num) \ - { #Ab2, #Ab3, Num }, -#include "iso-3166.def" -}; - - -static struct -{ - const char ab[3]; - const char term[4]; - const char lib[4]; -} iso639[] = -{ -#define DEFINE_LANGUAGE_CODE(Name, Ab, Term, Lib) \ - { #Ab, #Term, #Lib }, -#include "iso-639.def" -}; - - -/* The real definition of the struct for the LC_ADDRESS locale. */ -struct locale_address_t -{ - const char *postal_fmt; - const char *country_name; - const char *country_post; - const char *country_ab2; - const char *country_ab3; - uint32_t country_num; - const char *country_car; - const char *country_isbn; - const char *lang_name; - const char *lang_ab; - const char *lang_term; - const char *lang_lib; -}; - - -static void -address_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_ADDRESS].address = - (struct locale_address_t *) xcalloc (1, - sizeof (struct locale_address_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -address_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_address_t *address = locale->categories[LC_ADDRESS].address; - size_t cnt; - int helper; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (address == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_ADDRESS] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_ADDRESS, from->copy_name[LC_ADDRESS], - from->repertoire_name, charmap); - while (from->categories[LC_ADDRESS].address == NULL - && from->copy_name[LC_ADDRESS] != NULL); - - address = locale->categories[LC_ADDRESS].address - = from->categories[LC_ADDRESS].address; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (address == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_ADDRESS"); - address_startup (NULL, locale, 0); - address = locale->categories[LC_ADDRESS].address; - nothing = 1; - } - } - - if (address->postal_fmt == NULL) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_ADDRESS", "postal_fmt"); - /* Use as the default value the value of the i18n locale. */ - address->postal_fmt = "%a%N%f%N%d%N%b%N%s %h %e %r%N%C-%z %T%N%c%N"; - } - else - { - /* We must check whether the format string contains only the - allowed escape sequences. */ - const char *cp = address->postal_fmt; - - if (*cp == '\0') - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_ADDRESS", "postal_fmt"); - else - while (*cp != '\0') - { - if (*cp == '%') - { - if (*++cp == 'R') - /* Romanize-flag. */ - ++cp; - if (strchr ("afdbshNtreCzTSc%", *cp) == NULL) - { - error (0, 0, _("\ -%s: invalid escape `%%%c' sequence in field `%s'"), - "LC_ADDRESS", *cp, "postal_fmt"); - break; - } - } - ++cp; - } - } - -#define TEST_ELEM(cat) \ - if (address->cat == NULL) \ - { \ - if (verbose && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_ADDRESS", #cat); \ - address->cat = ""; \ - } - - TEST_ELEM (country_name); - /* XXX Test against list of defined codes. */ - TEST_ELEM (country_post); - /* XXX Test against list of defined codes. */ - TEST_ELEM (country_car); - /* XXX Test against list of defined codes. */ - TEST_ELEM (country_isbn); - TEST_ELEM (lang_name); - - helper = 1; - if (address->lang_term == NULL) - { - if (verbose && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_ADDRESS", - "lang_term"); - address->lang_term = ""; - cnt = sizeof (iso639) / sizeof (iso639[0]); - } - else if (address->lang_term[0] == '\0') - { - if (verbose) - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_ADDRESS", "lang_term"); - cnt = sizeof (iso639) / sizeof (iso639[0]); - } - else - { - /* Look for this language in the table. */ - for (cnt = 0; cnt < sizeof (iso639) / sizeof (iso639[0]); ++cnt) - if (strcmp (address->lang_term, iso639[cnt].term) == 0) - break; - if (cnt == sizeof (iso639) / sizeof (iso639[0])) - error (0, 0, _("\ -%s: terminology language code `%s' not defined"), - "LC_ADDRESS", address->lang_term); - } - - if (address->lang_ab == NULL) - { - if (verbose && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_ADDRESS", "lang_ab"); - address->lang_ab = ""; - } - else if (address->lang_ab[0] == '\0') - { - if (verbose) - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_ADDRESS", "lang_ab"); - } - else - { - if (cnt == sizeof (iso639) / sizeof (iso639[0])) - { - helper = 2; - for (cnt = 0; cnt < sizeof (iso639) / sizeof (iso639[0]); ++cnt) - if (strcmp (address->lang_ab, iso639[cnt].ab) == 0) - break; - if (cnt == sizeof (iso639) / sizeof (iso639[0])) - error (0, 0, _("\ -%s: language abbreviation `%s' not defined"), - "LC_ADDRESS", address->lang_ab); - } - else - if (strcmp (iso639[cnt].ab, address->lang_ab) != 0) - error (0, 0, _("\ -%s: `%s' value does not match `%s' value"), - "LC_ADDRESS", "lang_ab", "lang_term"); - } - - if (address->lang_lib == NULL) - /* This is no error. */ - address->lang_lib = address->lang_term; - else if (address->lang_lib[0] == '\0') - { - if (verbose) - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_ADDRESS", "lang_lib"); - } - else - { - if (cnt == sizeof (iso639) / sizeof (iso639[0])) - { - for (cnt = 0; cnt < sizeof (iso639) / sizeof (iso639[0]); ++cnt) - if (strcmp (address->lang_lib, iso639[cnt].lib) == 0) - break; - if (cnt == sizeof (iso639) / sizeof (iso639[0])) - error (0, 0, _("\ -%s: language abbreviation `%s' not defined"), - "LC_ADDRESS", address->lang_lib); - } - else - if (strcmp (iso639[cnt].ab, address->lang_ab) != 0) - error (0, 0, _("\ -%s: `%s' value does not match `%s' value"), "LC_ADDRESS", "lang_lib", - helper == 1 ? "lang_term" : "lang_ab"); - } - - if (address->country_num == 0) - { - if (verbose && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_ADDRESS", "country_num"); - cnt = sizeof (iso3166) / sizeof (iso3166[0]); - } - else - { - for (cnt = 0; cnt < sizeof (iso3166) / sizeof (iso3166[0]); ++cnt) - if (address->country_num == iso3166[cnt].num) - break; - - if (cnt == sizeof (iso3166) / sizeof (iso3166[0])) - error (0, 0, _("\ -%s: numeric country code `%d' not valid"), - "LC_ADDRESS", address->country_num); - } - - if (address->country_ab2 == NULL) - { - if (verbose && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_ADDRESS", "country_ab2"); - address->country_ab2 = " "; - } - else if (cnt != sizeof (iso3166) / sizeof (iso3166[0]) - && strcmp (address->country_ab2, iso3166[cnt].ab2) != 0) - error (0, 0, _("%s: `%s' value does not match `%s' value"), - "LC_ADDRESS", "country_ab2", "country_num"); - - if (address->country_ab3 == NULL) - { - if (verbose && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_ADDRESS", "country_ab3"); - address->country_ab3 = " "; - } - else if (cnt != sizeof (iso3166) / sizeof (iso3166[0]) - && strcmp (address->country_ab3, iso3166[cnt].ab3) != 0) - error (0, 0, _("%s: `%s' value does not match `%s' value"), - "LC_ADDRESS", "country_ab3", "country_num"); -} - - -void -address_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_address_t *address = locale->categories[LC_ADDRESS].address; - struct iovec iov[3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_ADDRESS); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) address->postal_fmt; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_post; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_ab2; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_ab3; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_car; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - - /* Align following data */ - iov[cnt].iov_base = (void *) "\0\0"; - iov[cnt].iov_len = ((idx[cnt - 2] + 3) & ~3) - idx[cnt - 2]; - idx[cnt - 2] = (idx[cnt - 2] + 3) & ~3; - ++cnt; - - iov[cnt].iov_base = (void *) &address->country_num; - iov[cnt].iov_len = sizeof (uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->country_isbn; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->lang_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->lang_ab; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->lang_term; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) address->lang_lib; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS)); - - write_locale_data (output_path, "LC_ADDRESS", - 3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS), iov); -} - - -/* The parser for the LC_ADDRESS section of the locale definition. */ -void -address_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_address_t *address; - struct token *now; - struct token *arg; - enum token_t nowtok; - - /* The rest of the line containing `LC_ADDRESS' must be free. */ - lr_ignore_rest (ldfile, 1); - - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_address, - LC_ADDRESS, "LC_ADDRESS", ignore_content); - return; - } - - /* Prepare the data structures. */ - address_startup (ldfile, result, ignore_content); - address = result->categories[LC_ADDRESS].address; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ignore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_string) \ - goto err_label; \ - if (address->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_ADDRESS", #cat); \ - else if (!ignore_content && arg->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_ADDRESS", #cat); \ - address->cat = ""; \ - } \ - else if (!ignore_content) \ - address->cat = arg->val.str.startmb; \ - break - - STR_ELEM (postal_fmt); - STR_ELEM (country_name); - STR_ELEM (country_post); - STR_ELEM (country_ab2); - STR_ELEM (country_ab3); - STR_ELEM (country_car); - STR_ELEM (lang_name); - STR_ELEM (lang_ab); - STR_ELEM (lang_term); - STR_ELEM (lang_lib); - -#define INT_STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_string && arg->tok != tok_number) \ - goto err_label; \ - if (address->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_ADDRESS", #cat); \ - else if (!ignore_content && arg->tok == tok_string \ - && arg->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_ADDRESS", #cat); \ - address->cat = ""; \ - } \ - else if (!ignore_content) \ - { \ - if (arg->tok == tok_string) \ - address->cat = arg->val.str.startmb; \ - else \ - { \ - char *numbuf = (char *) xmalloc (11); \ - snprintf (numbuf, 11, "%ld", arg->val.num); \ - address->cat = numbuf; \ - } \ - } \ - break - - INT_STR_ELEM (country_isbn); - -#define INT_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_number) \ - goto err_label; \ - else if (address->cat != 0) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_ADDRESS", #cat); \ - else if (!ignore_content) \ - address->cat = arg->val.num; \ - break - - INT_ELEM (country_num); - - case tok_end: - /* Next we assume `LC_ADDRESS'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), - "LC_ADDRESS"); - else if (arg->tok != tok_lc_address) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_ADDRESS"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_address); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_ADDRESS"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_ADDRESS"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-collate.c b/src/system/libroot/posix/glibc/locale/programs/ld-collate.c deleted file mode 100644 index 6d238a658e..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-collate.c +++ /dev/null @@ -1,3757 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include "charmap.h" -#include "localeinfo.h" -#include "linereader.h" -#include "locfile.h" -#include "localedef.h" -#include "elem-hash.h" - -/* Uncomment the following line in the production version. */ -/* #define NDEBUG 1 */ -#include - -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free - -static inline void -obstack_int32_grow (struct obstack *obstack, int32_t data) -{ - if (sizeof (int32_t) == sizeof (int)) - obstack_int_grow (obstack, data); - else - obstack_grow (obstack, &data, sizeof (int32_t)); -} - -static inline void -obstack_int32_grow_fast (struct obstack *obstack, int32_t data) -{ - if (sizeof (int32_t) == sizeof (int)) - obstack_int_grow_fast (obstack, data); - else - obstack_grow (obstack, &data, sizeof (int32_t)); -} - -/* Forward declaration. */ -struct element_t; - -/* Data type for list of strings. */ -struct section_list -{ - /* Successor in the known_sections list. */ - struct section_list *def_next; - /* Successor in the sections list. */ - struct section_list *next; - /* Name of the section. */ - const char *name; - /* First element of this section. */ - struct element_t *first; - /* Last element of this section. */ - struct element_t *last; - /* These are the rules for this section. */ - enum coll_sort_rule *rules; - /* Index of the rule set in the appropriate section of the output file. */ - int ruleidx; -}; - -struct element_t; - -struct element_list_t -{ - /* Number of elements. */ - int cnt; - - struct element_t **w; -}; - -/* Data type for collating element. */ -struct element_t -{ - const char *name; - - const char *mbs; - size_t nmbs; - const uint32_t *wcs; - size_t nwcs; - int *mborder; - int wcorder; - - /* The following is a bit mask which bits are set if this element is - used in the appropriate level. Interesting for the singlebyte - weight computation. - - XXX The type here restricts the number of levels to 32. It could - be changed if necessary but I doubt this is necessary. */ - unsigned int used_in_level; - - struct element_list_t *weights; - - /* Nonzero if this is a real character definition. */ - int is_character; - - /* Order of the character in the sequence. This information will - be used in range expressions. */ - int mbseqorder; - int wcseqorder; - - /* Where does the definition come from. */ - const char *file; - size_t line; - - /* Which section does this belong to. */ - struct section_list *section; - - /* Predecessor and successor in the order list. */ - struct element_t *last; - struct element_t *next; - - /* Next element in multibyte output list. */ - struct element_t *mbnext; - struct element_t *mblast; - - /* Next element in wide character output list. */ - struct element_t *wcnext; - struct element_t *wclast; -}; - -/* Special element value. */ -#define ELEMENT_ELLIPSIS2 ((struct element_t *) 1) -#define ELEMENT_ELLIPSIS3 ((struct element_t *) 2) -#define ELEMENT_ELLIPSIS4 ((struct element_t *) 3) - -/* Data type for collating symbol. */ -struct symbol_t -{ - const char *name; - - /* Point to place in the order list. */ - struct element_t *order; - - /* Where does the definition come from. */ - const char *file; - size_t line; -}; - -/* Sparse table of struct element_t *. */ -#define TABLE wchead_table -#define ELEMENT struct element_t * -#define DEFAULT NULL -#define ITERATE -#define NO_FINALIZE -#include "3level.h" - -/* Sparse table of int32_t. */ -#define TABLE collidx_table -#define ELEMENT int32_t -#define DEFAULT 0 -#include "3level.h" - -/* Sparse table of uint32_t. */ -#define TABLE collseq_table -#define ELEMENT uint32_t -#define DEFAULT ~((uint32_t) 0) -#include "3level.h" - - -/* The real definition of the struct for the LC_COLLATE locale. */ -struct locale_collate_t -{ - int col_weight_max; - int cur_weight_max; - - /* List of known scripts. */ - struct section_list *known_sections; - /* List of used sections. */ - struct section_list *sections; - /* Current section using definition. */ - struct section_list *current_section; - /* There always can be an unnamed section. */ - struct section_list unnamed_section; - /* To make handling of errors easier we have another section. */ - struct section_list error_section; - /* Sometimes we are defining the values for collating symbols before - the first actual section. */ - struct section_list symbol_section; - - /* Start of the order list. */ - struct element_t *start; - - /* The undefined element. */ - struct element_t undefined; - - /* This is the cursor for `reorder_after' insertions. */ - struct element_t *cursor; - - /* This value is used when handling ellipsis. */ - struct element_t ellipsis_weight; - - /* Known collating elements. */ - hash_table elem_table; - - /* Known collating symbols. */ - hash_table sym_table; - - /* Known collation sequences. */ - hash_table seq_table; - - struct obstack mempool; - - /* The LC_COLLATE category is a bit special as it is sometimes possible - that the definitions from more than one input file contains information. - Therefore we keep all relevant input in a list. */ - struct locale_collate_t *next; - - /* Arrays with heads of the list for each of the leading bytes in - the multibyte sequences. */ - struct element_t *mbheads[256]; - - /* Arrays with heads of the list for each of the leading bytes in - the multibyte sequences. */ - struct wchead_table wcheads; - - /* The arrays with the collation sequence order. */ - unsigned char mbseqorder[256]; - struct collseq_table wcseqorder; -}; - - -/* We have a few global variables which are used for reading all - LC_COLLATE category descriptions in all files. */ -static uint32_t nrules; - - -/* We need UTF-8 encoding of numbers. */ -static inline int -utf8_encode (char *buf, int val) -{ - int retval; - - if (val < 0x80) - { - *buf++ = (char) val; - retval = 1; - } - else - { - int step; - - for (step = 2; step < 6; ++step) - if ((val & (~(uint32_t)0 << (5 * step + 1))) == 0) - break; - retval = step; - - *buf = (unsigned char) (~0xff >> step); - --step; - do - { - buf[step] = 0x80 | (val & 0x3f); - val >>= 6; - } - while (--step > 0); - *buf |= val; - } - - return retval; -} - - -static struct section_list * -make_seclist_elem (struct locale_collate_t *collate, const char *string, - struct section_list *next) -{ - struct section_list *newp; - - newp = (struct section_list *) obstack_alloc (&collate->mempool, - sizeof (*newp)); - newp->next = next; - newp->name = string; - newp->first = NULL; - newp->last = NULL; - - return newp; -} - - -static struct element_t * -new_element (struct locale_collate_t *collate, const char *mbs, size_t mbslen, - const uint32_t *wcs, const char *name, size_t namelen, - int is_character) -{ - struct element_t *newp; - - newp = (struct element_t *) obstack_alloc (&collate->mempool, - sizeof (*newp)); - newp->name = name == NULL ? NULL : obstack_copy0 (&collate->mempool, - name, namelen); - if (mbs != NULL) - { - newp->mbs = obstack_copy0 (&collate->mempool, mbs, mbslen); - newp->nmbs = mbslen; - } - else - { - newp->mbs = NULL; - newp->nmbs = 0; - } - if (wcs != NULL) - { - size_t nwcs = wcslen ((wchar_t *) wcs); - uint32_t zero = 0; - obstack_grow (&collate->mempool, wcs, nwcs * sizeof (uint32_t)); - obstack_grow (&collate->mempool, &zero, sizeof (uint32_t)); - newp->wcs = (uint32_t *) obstack_finish (&collate->mempool); - newp->nwcs = nwcs; - } - else - { - newp->wcs = NULL; - newp->nwcs = 0; - } - newp->mborder = NULL; - newp->wcorder = 0; - newp->used_in_level = 0; - newp->is_character = is_character; - - /* Will be assigned later. XXX */ - newp->mbseqorder = 0; - newp->wcseqorder = 0; - - /* Will be allocated later. */ - newp->weights = NULL; - - newp->file = NULL; - newp->line = 0; - - newp->section = collate->current_section; - - newp->last = NULL; - newp->next = NULL; - - newp->mbnext = NULL; - newp->mblast = NULL; - - newp->wcnext = NULL; - newp->wclast = NULL; - - return newp; -} - - -static struct symbol_t * -new_symbol (struct locale_collate_t *collate, const char *name, size_t len) -{ - struct symbol_t *newp; - - newp = (struct symbol_t *) obstack_alloc (&collate->mempool, sizeof (*newp)); - - newp->name = obstack_copy0 (&collate->mempool, name, len); - newp->order = NULL; - - newp->file = NULL; - newp->line = 0; - - return newp; -} - - -/* Test whether this name is already defined somewhere. */ -static int -check_duplicate (struct linereader *ldfile, struct locale_collate_t *collate, - struct charmap_t *charmap, struct repertoire_t *repertoire, - const char *symbol, size_t symbol_len) -{ - void *ignore = NULL; - - if (find_entry (&charmap->char_table, symbol, symbol_len, &ignore) == 0) - { - lr_error (ldfile, _("`%.*s' already defined in charmap"), - (int) symbol_len, symbol); - return 1; - } - - if (repertoire != NULL - && (find_entry (&repertoire->char_table, symbol, symbol_len, &ignore) - == 0)) - { - lr_error (ldfile, _("`%.*s' already defined in repertoire"), - (int) symbol_len, symbol); - return 1; - } - - if (find_entry (&collate->sym_table, symbol, symbol_len, &ignore) == 0) - { - lr_error (ldfile, _("`%.*s' already defined as collating symbol"), - (int) symbol_len, symbol); - return 1; - } - - if (find_entry (&collate->elem_table, symbol, symbol_len, &ignore) == 0) - { - lr_error (ldfile, _("`%.*s' already defined as collating element"), - (int) symbol_len, symbol); - return 1; - } - - return 0; -} - - -/* Read the direction specification. */ -static void -read_directions (struct linereader *ldfile, struct token *arg, - struct charmap_t *charmap, struct repertoire_t *repertoire, - struct locale_collate_t *collate) -{ - int cnt = 0; - int max = nrules ?: 10; - enum coll_sort_rule *rules = calloc (max, sizeof (*rules)); - int warned = 0; - - while (1) - { - int valid = 0; - - if (arg->tok == tok_forward) - { - if (rules[cnt] & sort_backward) - { - if (! warned) - { - lr_error (ldfile, _("\ -%s: `forward' and `backward' are mutually excluding each other"), - "LC_COLLATE"); - warned = 1; - } - } - else if (rules[cnt] & sort_forward) - { - if (! warned) - { - lr_error (ldfile, _("\ -%s: `%s' mentioned more than once in definition of weight %d"), - "LC_COLLATE", "forward", cnt + 1); - } - } - else - rules[cnt] |= sort_forward; - - valid = 1; - } - else if (arg->tok == tok_backward) - { - if (rules[cnt] & sort_forward) - { - if (! warned) - { - lr_error (ldfile, _("\ -%s: `forward' and `backward' are mutually excluding each other"), - "LC_COLLATE"); - warned = 1; - } - } - else if (rules[cnt] & sort_backward) - { - if (! warned) - { - lr_error (ldfile, _("\ -%s: `%s' mentioned more than once in definition of weight %d"), - "LC_COLLATE", "backward", cnt + 1); - } - } - else - rules[cnt] |= sort_backward; - - valid = 1; - } - else if (arg->tok == tok_position) - { - if (rules[cnt] & sort_position) - { - if (! warned) - { - lr_error (ldfile, _("\ -%s: `%s' mentioned more than once in definition of weight %d"), - "LC_COLLATE", "position", cnt + 1); - } - } - else - rules[cnt] |= sort_position; - - valid = 1; - } - - if (valid) - arg = lr_token (ldfile, charmap, repertoire, verbose); - - if (arg->tok == tok_eof || arg->tok == tok_eol || arg->tok == tok_comma - || arg->tok == tok_semicolon) - { - if (! valid && ! warned) - { - lr_error (ldfile, _("%s: syntax error"), "LC_COLLATE"); - warned = 1; - } - - /* See whether we have to increment the counter. */ - if (arg->tok != tok_comma && rules[cnt] != 0) - { - /* Add the default `forward' if we have seen only `position'. */ - if (rules[cnt] == sort_position) - rules[cnt] = sort_position | sort_forward; - - ++cnt; - } - - if (arg->tok == tok_eof || arg->tok == tok_eol) - /* End of line or file, so we exit the loop. */ - break; - - if (nrules == 0) - { - /* See whether we have enough room in the array. */ - if (cnt == max) - { - max += 10; - rules = (enum coll_sort_rule *) xrealloc (rules, - max - * sizeof (*rules)); - memset (&rules[cnt], '\0', (max - cnt) * sizeof (*rules)); - } - } - else - { - if (cnt == nrules) - { - /* There must not be any more rule. */ - if (! warned) - { - lr_error (ldfile, _("\ -%s: too many rules; first entry only had %d"), - "LC_COLLATE", nrules); - warned = 1; - } - - lr_ignore_rest (ldfile, 0); - break; - } - } - } - else - { - if (! warned) - { - lr_error (ldfile, _("%s: syntax error"), "LC_COLLATE"); - warned = 1; - } - } - - arg = lr_token (ldfile, charmap, repertoire, verbose); - } - - if (nrules == 0) - { - /* Now we know how many rules we have. */ - nrules = cnt; - rules = (enum coll_sort_rule *) xrealloc (rules, - nrules * sizeof (*rules)); - } - else - { - if (cnt < nrules) - { - /* Not enough rules in this specification. */ - if (! warned) - lr_error (ldfile, _("%s: not enough sorting rules"), "LC_COLLATE"); - - do - rules[cnt] = sort_forward; - while (++cnt < nrules); - } - } - - collate->current_section->rules = rules; -} - - -static struct element_t * -find_element (struct linereader *ldfile, struct locale_collate_t *collate, - const char *str, size_t len) -{ - struct element_t *result = NULL; - - /* Search for the entries among the collation sequences already define. */ - if (find_entry (&collate->seq_table, str, len, (void **) &result) != 0) - { - /* Nope, not define yet. So we see whether it is a - collation symbol. */ - void *ptr; - - if (find_entry (&collate->sym_table, str, len, &ptr) == 0) - { - /* It's a collation symbol. */ - struct symbol_t *sym = (struct symbol_t *) ptr; - result = sym->order; - - if (result == NULL) - result = sym->order = new_element (collate, NULL, 0, NULL, - NULL, 0, 0); - } - else if (find_entry (&collate->elem_table, str, len, - (void **) &result) != 0) - { - /* It's also no collation element. So it is a character - element defined later. */ - result = new_element (collate, NULL, 0, NULL, str, len, 1); - /* Insert it into the sequence table. */ - insert_entry (&collate->seq_table, str, len, result); - } - } - - return result; -} - - -static void -unlink_element (struct locale_collate_t *collate) -{ - if (collate->cursor == collate->start) - { - assert (collate->cursor->next == NULL); - assert (collate->cursor->last == NULL); - collate->cursor = NULL; - } - else - { - if (collate->cursor->next != NULL) - collate->cursor->next->last = collate->cursor->last; - if (collate->cursor->last != NULL) - collate->cursor->last->next = collate->cursor->next; - collate->cursor = collate->cursor->last; - } -} - - -static void -insert_weights (struct linereader *ldfile, struct element_t *elem, - struct charmap_t *charmap, struct repertoire_t *repertoire, - struct locale_collate_t *collate, enum token_t ellipsis) -{ - int weight_cnt; - struct token *arg; - - /* Initialize all the fields. */ - elem->file = ldfile->fname; - elem->line = ldfile->lineno; - - elem->last = collate->cursor; - elem->next = collate->cursor ? collate->cursor->next : NULL; - if (collate->cursor != NULL && collate->cursor->next != NULL) - collate->cursor->next->last = elem; - if (collate->cursor != NULL) - collate->cursor->next = elem; - if (collate->start == NULL) - { - assert (collate->cursor == NULL); - collate->start = elem; - } - - elem->section = collate->current_section; - - if (collate->current_section->first == NULL) - collate->current_section->first = elem; - if (collate->current_section->last == collate->cursor) - collate->current_section->last = elem; - - collate->cursor = elem; - - elem->weights = (struct element_list_t *) - obstack_alloc (&collate->mempool, nrules * sizeof (struct element_list_t)); - memset (elem->weights, '\0', nrules * sizeof (struct element_list_t)); - - weight_cnt = 0; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - do - { - if (arg->tok == tok_eof || arg->tok == tok_eol) - break; - - if (arg->tok == tok_ignore) - { - /* The weight for this level has to be ignored. We use the - null pointer to indicate this. */ - elem->weights[weight_cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, sizeof (struct element_t *)); - elem->weights[weight_cnt].w[0] = NULL; - elem->weights[weight_cnt].cnt = 1; - } - else if (arg->tok == tok_bsymbol || arg->tok == tok_ucs4) - { - char ucs4str[10]; - struct element_t *val; - char *symstr; - size_t symlen; - - if (arg->tok == tok_bsymbol) - { - symstr = arg->val.str.startmb; - symlen = arg->val.str.lenmb; - } - else - { - snprintf (ucs4str, sizeof (ucs4str), "U%08X", arg->val.ucs4); - symstr = ucs4str; - symlen = 9; - } - - val = find_element (ldfile, collate, symstr, symlen); - if (val == NULL) - break; - - elem->weights[weight_cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, sizeof (struct element_t *)); - elem->weights[weight_cnt].w[0] = val; - elem->weights[weight_cnt].cnt = 1; - } - else if (arg->tok == tok_string) - { - /* Split the string up in the individual characters and put - the element definitions in the list. */ - const char *cp = arg->val.str.startmb; - int cnt = 0; - struct element_t *charelem; - struct element_t **weights = NULL; - int max = 0; - - if (*cp == '\0') - { - lr_error (ldfile, _("%s: empty weight string not allowed"), - "LC_COLLATE"); - lr_ignore_rest (ldfile, 0); - break; - } - - do - { - if (*cp == '<') - { - /* Ahh, it's a bsymbol or an UCS4 value. If it's - the latter we have to unify the name. */ - const char *startp = ++cp; - size_t len; - - while (*cp != '>') - { - if (*cp == ldfile->escape_char) - ++cp; - if (*cp == '\0') - /* It's a syntax error. */ - goto syntax; - - ++cp; - } - - if (cp - startp == 5 && startp[0] == 'U' - && isxdigit (startp[1]) && isxdigit (startp[2]) - && isxdigit (startp[3]) && isxdigit (startp[4])) - { - unsigned int ucs4 = strtoul (startp + 1, NULL, 16); - char *newstr; - - newstr = (char *) xmalloc (10); - snprintf (newstr, 10, "U%08X", ucs4); - startp = newstr; - - len = 9; - } - else - len = cp - startp; - - charelem = find_element (ldfile, collate, startp, len); - ++cp; - } - else - { - /* People really shouldn't use characters directly in - the string. Especially since it's not really clear - what this means. We interpret all characters in the - string as if that would be bsymbols. Otherwise we - would have to match back to bsymbols somehow and this - is normally not what people normally expect. */ - charelem = find_element (ldfile, collate, cp++, 1); - } - - if (charelem == NULL) - { - /* We ignore the rest of the line. */ - lr_ignore_rest (ldfile, 0); - break; - } - - /* Add the pointer. */ - if (cnt >= max) - { - struct element_t **newp; - max += 10; - newp = (struct element_t **) - alloca (max * sizeof (struct element_t *)); - memcpy (newp, weights, cnt * sizeof (struct element_t *)); - weights = newp; - } - weights[cnt++] = charelem; - } - while (*cp != '\0'); - - /* Now store the information. */ - elem->weights[weight_cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, - cnt * sizeof (struct element_t *)); - memcpy (elem->weights[weight_cnt].w, weights, - cnt * sizeof (struct element_t *)); - elem->weights[weight_cnt].cnt = cnt; - - /* We don't need the string anymore. */ - free (arg->val.str.startmb); - } - else if (ellipsis != tok_none - && (arg->tok == tok_ellipsis2 - || arg->tok == tok_ellipsis3 - || arg->tok == tok_ellipsis4)) - { - /* It must be the same ellipsis as used in the initial column. */ - if (arg->tok != ellipsis) - lr_error (ldfile, _("\ -%s: weights must use the same ellipsis symbol as the name"), - "LC_COLLATE"); - - /* The weight for this level will depend on the element - iterating over the range. Put a placeholder. */ - elem->weights[weight_cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, sizeof (struct element_t *)); - elem->weights[weight_cnt].w[0] = ELEMENT_ELLIPSIS2; - elem->weights[weight_cnt].cnt = 1; - } - else - { - syntax: - /* It's a syntax error. */ - lr_error (ldfile, _("%s: syntax error"), "LC_COLLATE"); - lr_ignore_rest (ldfile, 0); - break; - } - - arg = lr_token (ldfile, charmap, repertoire, verbose); - /* This better should be the end of the line or a semicolon. */ - if (arg->tok == tok_semicolon) - /* OK, ignore this and read the next token. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - else if (arg->tok != tok_eof && arg->tok != tok_eol) - { - /* It's a syntax error. */ - lr_error (ldfile, _("%s: syntax error"), "LC_COLLATE"); - lr_ignore_rest (ldfile, 0); - break; - } - } - while (++weight_cnt < nrules); - - if (weight_cnt < nrules) - { - /* This means the rest of the line uses the current element as - the weight. */ - do - { - elem->weights[weight_cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, sizeof (struct element_t *)); - if (ellipsis == tok_none) - elem->weights[weight_cnt].w[0] = elem; - else - elem->weights[weight_cnt].w[0] = ELEMENT_ELLIPSIS2; - elem->weights[weight_cnt].cnt = 1; - } - while (++weight_cnt < nrules); - } - else - { - if (arg->tok == tok_ignore || arg->tok == tok_bsymbol) - { - /* Too many rule values. */ - lr_error (ldfile, _("%s: too many values"), "LC_COLLATE"); - lr_ignore_rest (ldfile, 0); - } - else - lr_ignore_rest (ldfile, arg->tok != tok_eol && arg->tok != tok_eof); - } -} - - -static int -insert_value (struct linereader *ldfile, const char *symstr, size_t symlen, - struct charmap_t *charmap, struct repertoire_t *repertoire, - struct locale_collate_t *collate) -{ - /* First find out what kind of symbol this is. */ - struct charseq *seq; - uint32_t wc; - struct element_t *elem = NULL; - - /* Try to find the character in the charmap. */ - seq = charmap_find_value (charmap, symstr, symlen); - - /* Determine the wide character. */ - if (seq == NULL || seq->ucs4 == UNINITIALIZED_CHAR_VALUE) - { - wc = repertoire_find_value (repertoire, symstr, symlen); - if (seq != NULL) - seq->ucs4 = wc; - } - else - wc = seq->ucs4; - - if (wc == ILLEGAL_CHAR_VALUE && seq == NULL) - { - /* It's no character, so look through the collation elements and - symbol list. */ - if (find_entry (&collate->elem_table, symstr, symlen, - (void **) &elem) != 0) - { - void *result; - struct symbol_t *sym = NULL; - - /* It's also collation element. Therefore it's either a - collating symbol or it's a character which is not - supported by the character set. In the later case we - simply create a dummy entry. */ - if (find_entry (&collate->sym_table, symstr, symlen, &result) == 0) - { - /* It's a collation symbol. */ - sym = (struct symbol_t *) result; - - elem = sym->order; - } - - if (elem == NULL) - { - elem = new_element (collate, NULL, 0, NULL, symstr, symlen, 0); - - if (sym != NULL) - sym->order = elem; - else - /* Enter a fake element in the sequence table. This - won't cause anything in the output since there is - no multibyte or wide character associated with - it. */ - insert_entry (&collate->seq_table, symstr, symlen, elem); - } - } - } - else - { - /* Otherwise the symbols stands for a character. */ - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &elem) != 0) - { - uint32_t wcs[2] = { wc, 0 }; - - /* We have to allocate an entry. */ - elem = new_element (collate, seq != NULL ? seq->bytes : NULL, - seq != NULL ? seq->nbytes : 0, - wc == ILLEGAL_CHAR_VALUE ? NULL : wcs, - symstr, symlen, 1); - - /* And add it to the table. */ - if (insert_entry (&collate->seq_table, symstr, symlen, elem) != 0) - /* This cannot happen. */ - assert (! "Internal error"); - } - else - { - /* Maybe the character was used before the definition. In this case - we have to insert the byte sequences now. */ - if (elem->mbs == NULL && seq != NULL) - { - elem->mbs = obstack_copy0 (&collate->mempool, - seq->bytes, seq->nbytes); - elem->nmbs = seq->nbytes; - } - - if (elem->wcs == NULL && wc != ILLEGAL_CHAR_VALUE) - { - uint32_t wcs[2] = { wc, 0 }; - - elem->wcs = obstack_copy (&collate->mempool, wcs, sizeof (wcs)); - elem->nwcs = 1; - } - } - } - - /* Test whether this element is not already in the list. */ - if (elem->next != NULL || elem == collate->cursor) - { - lr_error (ldfile, _("order for `%.*s' already defined at %s:%Zu"), - (int) symlen, symstr, elem->file, elem->line); - lr_ignore_rest (ldfile, 0); - return 1; - } - - insert_weights (ldfile, elem, charmap, repertoire, collate, tok_none); - - return 0; -} - - -static void -handle_ellipsis (struct linereader *ldfile, const char *symstr, size_t symlen, - enum token_t ellipsis, struct charmap_t *charmap, - struct repertoire_t *repertoire, - struct locale_collate_t *collate) -{ - struct element_t *startp; - struct element_t *endp; - - /* Unlink the entry added for the ellipsis. */ - unlink_element (collate); - startp = collate->cursor; - - /* Process and add the end-entry. */ - if (symstr != NULL - && insert_value (ldfile, symstr, symlen, charmap, repertoire, collate)) - /* Something went wrong with inserting the to-value. This means - we cannot process the ellipsis. */ - return; - - /* Reset the cursor. */ - collate->cursor = startp; - - /* Now we have to handle many different situations: - - we have to distinguish between the three different ellipsis forms - - the is the ellipsis at the beginning, in the middle, or at the end. - */ - endp = collate->cursor->next; - assert (symstr == NULL || endp != NULL); - - /* XXX The following is probably very wrong since also collating symbols - can appear in ranges. But do we want/can refine the test for that? */ -#if 0 - /* Both, the start and the end symbol, must stand for characters. */ - if ((startp != NULL && (startp->name == NULL || ! startp->is_character)) - || (endp != NULL && (endp->name == NULL|| ! endp->is_character))) - { - lr_error (ldfile, _("\ -%s: the start and the end symbol of a range must stand for characters"), - "LC_COLLATE"); - return; - } -#endif - - if (ellipsis == tok_ellipsis3) - { - /* One requirement we make here: the length of the byte - sequences for the first and end character must be the same. - This is mainly to prevent unwanted effects and this is often - not what is wanted. */ - size_t len = (startp->mbs != NULL ? startp->nmbs - : (endp->mbs != NULL ? endp->nmbs : 0)); - char mbcnt[len + 1]; - char mbend[len + 1]; - - /* Well, this should be caught somewhere else already. Just to - make sure. */ - assert (startp == NULL || startp->wcs == NULL || startp->wcs[1] == 0); - assert (endp == NULL || endp->wcs == NULL || endp->wcs[1] == 0); - - if (startp != NULL && endp != NULL - && startp->mbs != NULL && endp->mbs != NULL - && startp->nmbs != endp->nmbs) - { - lr_error (ldfile, _("\ -%s: byte sequences of first and last character must have the same length"), - "LC_COLLATE"); - return; - } - - /* Determine whether we have to generate multibyte sequences. */ - if ((startp == NULL || startp->mbs != NULL) - && (endp == NULL || endp->mbs != NULL)) - { - int cnt; - int ret; - - /* Prepare the beginning byte sequence. This is either from the - beginning byte sequence or it is all nulls if it was an - initial ellipsis. */ - if (startp == NULL || startp->mbs == NULL) - memset (mbcnt, '\0', len); - else - { - memcpy (mbcnt, startp->mbs, len); - - /* And increment it so that the value is the first one we will - try to insert. */ - for (cnt = len - 1; cnt >= 0; --cnt) - if (++mbcnt[cnt] != '\0') - break; - } - mbcnt[len] = '\0'; - - /* And the end sequence. */ - if (endp == NULL || endp->mbs == NULL) - memset (mbend, '\0', len); - else - memcpy (mbend, endp->mbs, len); - mbend[len] = '\0'; - - /* Test whether we have a correct range. */ - ret = memcmp (mbcnt, mbend, len); - if (ret >= 0) - { - if (ret > 0) - lr_error (ldfile, _("%s: byte sequence of first character of \ -sequence is not lower than that of the last character"), "LC_COLLATE"); - return; - } - - /* Generate the byte sequences data. */ - while (1) - { - struct charseq *seq; - - /* Quite a bit of work ahead. We have to find the character - definition for the byte sequence and then determine the - wide character belonging to it. */ - seq = charmap_find_symbol (charmap, mbcnt, len); - if (seq != NULL) - { - struct element_t *elem; - size_t namelen; - - /* I don't this this can ever happen. */ - assert (seq->name != NULL); - namelen = strlen (seq->name); - - if (seq->ucs4 == UNINITIALIZED_CHAR_VALUE) - seq->ucs4 = repertoire_find_value (repertoire, seq->name, - namelen); - - /* Now we are ready to insert the new value in the - sequence. Find out whether the element is - already known. */ - if (find_entry (&collate->seq_table, seq->name, namelen, - (void **) &elem) != 0) - { - uint32_t wcs[2] = { seq->ucs4, 0 }; - - /* We have to allocate an entry. */ - elem = new_element (collate, mbcnt, len, - seq->ucs4 == ILLEGAL_CHAR_VALUE - ? NULL : wcs, seq->name, - namelen, 1); - - /* And add it to the table. */ - if (insert_entry (&collate->seq_table, seq->name, - namelen, elem) != 0) - /* This cannot happen. */ - assert (! "Internal error"); - } - - /* Test whether this element is not already in the list. */ - if (elem->next != NULL || (collate->cursor != NULL - && elem->next == collate->cursor)) - { - lr_error (ldfile, _("\ -order for `%.*s' already defined at %s:%Zu"), - (int) namelen, seq->name, - elem->file, elem->line); - goto increment; - } - - /* Enqueue the new element. */ - elem->last = collate->cursor; - if (collate->cursor == NULL) - elem->next = NULL; - else - { - elem->next = collate->cursor->next; - elem->last->next = elem; - if (elem->next != NULL) - elem->next->last = elem; - } - if (collate->start == NULL) - { - assert (collate->cursor == NULL); - collate->start = elem; - } - collate->cursor = elem; - - /* Add the weight value. We take them from the - `ellipsis_weights' member of `collate'. */ - elem->weights = (struct element_list_t *) - obstack_alloc (&collate->mempool, - nrules * sizeof (struct element_list_t)); - for (cnt = 0; cnt < nrules; ++cnt) - if (collate->ellipsis_weight.weights[cnt].cnt == 1 - && (collate->ellipsis_weight.weights[cnt].w[0] - == ELEMENT_ELLIPSIS2)) - { - elem->weights[cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, - sizeof (struct element_t *)); - elem->weights[cnt].w[0] = elem; - elem->weights[cnt].cnt = 1; - } - else - { - /* Simply use the weight from `ellipsis_weight'. */ - elem->weights[cnt].w = - collate->ellipsis_weight.weights[cnt].w; - elem->weights[cnt].cnt = - collate->ellipsis_weight.weights[cnt].cnt; - } - } - - /* Increment for the next round. */ - increment: - for (cnt = len - 1; cnt >= 0; --cnt) - if (++mbcnt[cnt] != '\0') - break; - - /* Find out whether this was all. */ - if (cnt < 0 || memcmp (mbcnt, mbend, len) >= 0) - /* Yep, that's all. */ - break; - } - } - } - else - { - /* For symbolic range we naturally must have a beginning and an - end specified by the user. */ - if (startp == NULL) - lr_error (ldfile, _("\ -%s: symbolic range ellipsis must not directly follow `order_start'"), - "LC_COLLATE"); - else if (endp == NULL) - lr_error (ldfile, _("\ -%s: symbolic range ellipsis must not be directly followed by `order_end'"), - "LC_COLLATE"); - else - { - /* Determine the range. To do so we have to determine the - common prefix of the both names and then the numeric - values of both ends. */ - size_t lenfrom = strlen (startp->name); - size_t lento = strlen (endp->name); - char buf[lento + 1]; - int preflen = 0; - long int from; - long int to; - char *cp; - int base = ellipsis == tok_ellipsis2 ? 16 : 10; - - if (lenfrom != lento) - { - invalid_range: - lr_error (ldfile, _("\ -`%s' and `%.*s' are no valid names for symbolic range"), - startp->name, (int) lento, endp->name); - return; - } - - while (startp->name[preflen] == endp->name[preflen]) - if (startp->name[preflen] == '\0') - /* Nothing to be done. The start and end point are identical - and while inserting the end point we have already given - the user an error message. */ - return; - else - ++preflen; - - errno = 0; - from = strtol (startp->name + preflen, &cp, base); - if ((from == UINT_MAX && errno == ERANGE) || *cp != '\0') - goto invalid_range; - - errno = 0; - to = strtol (endp->name + preflen, &cp, base); - if ((to == UINT_MAX && errno == ERANGE) || *cp != '\0') - goto invalid_range; - - /* Copy the prefix. */ - memcpy (buf, startp->name, preflen); - - /* Loop over all values. */ - for (++from; from < to; ++from) - { - struct element_t *elem = NULL; - struct charseq *seq; - uint32_t wc; - int cnt; - - /* Generate the the name. */ - sprintf (buf + preflen, base == 10 ? "%ld" : "%lX", from); - - /* Look whether this name is already defined. */ - if (find_entry (&collate->seq_table, buf, symlen, - (void **) &elem) == 0) - { - if (elem->next != NULL || (collate->cursor != NULL - && elem->next == collate->cursor)) - { - lr_error (ldfile, _("\ -%s: order for `%.*s' already defined at %s:%Zu"), - "LC_COLLATE", (int) lenfrom, buf, - elem->file, elem->line); - continue; - } - - if (elem->name == NULL) - { - lr_error (ldfile, _("%s: `%s' must be a character"), - "LC_COLLATE", buf); - continue; - } - } - - if (elem == NULL || (elem->mbs == NULL && elem->wcs == NULL)) - { - /* Search for a character of this name. */ - seq = charmap_find_value (charmap, buf, lenfrom); - if (seq == NULL || seq->ucs4 == UNINITIALIZED_CHAR_VALUE) - { - wc = repertoire_find_value (repertoire, buf, lenfrom); - - if (seq != NULL) - seq->ucs4 = wc; - } - else - wc = seq->ucs4; - - if (wc == ILLEGAL_CHAR_VALUE && seq == NULL) - /* We don't know anything about a character with this - name. XXX Should we warn? */ - continue; - - if (elem == NULL) - { - uint32_t wcs[2] = { wc, 0 }; - - /* We have to allocate an entry. */ - elem = new_element (collate, - seq != NULL ? seq->bytes : NULL, - seq != NULL ? seq->nbytes : 0, - wc == ILLEGAL_CHAR_VALUE - ? NULL : wcs, buf, lenfrom, 1); - } - else - { - /* Update the element. */ - if (seq != NULL) - { - elem->mbs = obstack_copy0 (&collate->mempool, - seq->bytes, seq->nbytes); - elem->nmbs = seq->nbytes; - } - - if (wc != ILLEGAL_CHAR_VALUE) - { - uint32_t zero = 0; - - obstack_grow (&collate->mempool, - &wc, sizeof (uint32_t)); - obstack_grow (&collate->mempool, - &zero, sizeof (uint32_t)); - elem->wcs = obstack_finish (&collate->mempool); - elem->nwcs = 1; - } - } - - elem->file = ldfile->fname; - elem->line = ldfile->lineno; - elem->section = collate->current_section; - } - - /* Enqueue the new element. */ - elem->last = collate->cursor; - elem->next = collate->cursor->next; - elem->last->next = elem; - if (elem->next != NULL) - elem->next->last = elem; - collate->cursor = elem; - - /* Now add the weights. They come from the `ellipsis_weights' - member of `collate'. */ - elem->weights = (struct element_list_t *) - obstack_alloc (&collate->mempool, - nrules * sizeof (struct element_list_t)); - for (cnt = 0; cnt < nrules; ++cnt) - if (collate->ellipsis_weight.weights[cnt].cnt == 1 - && (collate->ellipsis_weight.weights[cnt].w[0] - == ELEMENT_ELLIPSIS2)) - { - elem->weights[cnt].w = (struct element_t **) - obstack_alloc (&collate->mempool, - sizeof (struct element_t *)); - elem->weights[cnt].w[0] = elem; - elem->weights[cnt].cnt = 1; - } - else - { - /* Simly use the weight from `ellipsis_weight'. */ - elem->weights[cnt].w = - collate->ellipsis_weight.weights[cnt].w; - elem->weights[cnt].cnt = - collate->ellipsis_weight.weights[cnt].cnt; - } - } - } - } -} - - -static void -collate_startup (struct linereader *ldfile, struct localedef_t *locale, - struct localedef_t *copy_locale, int ignore_content) -{ - if (!ignore_content && locale->categories[LC_COLLATE].collate == NULL) - { - struct locale_collate_t *collate; - - if (copy_locale == NULL) - { - collate = locale->categories[LC_COLLATE].collate = - (struct locale_collate_t *) - xcalloc (1, sizeof (struct locale_collate_t)); - - /* Init the various data structures. */ - init_hash (&collate->elem_table, 100); - init_hash (&collate->sym_table, 100); - init_hash (&collate->seq_table, 500); - obstack_init (&collate->mempool); - - collate->col_weight_max = -1; - } - else - /* Reuse the copy_locale's data structures. */ - collate = locale->categories[LC_COLLATE].collate = - copy_locale->categories[LC_COLLATE].collate; - } - - ldfile->translate_strings = 0; - ldfile->return_widestr = 0; -} - - -void -collate_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - /* Now is the time when we can assign the individual collation - values for all the symbols. We have possibly different values - for the wide- and the multibyte-character symbols. This is done - since it might make a difference in the encoding if there is in - some cases no multibyte-character but there are wide-characters. - (The other way around it is not important since theencoded - collation value in the wide-character case is 32 bits wide and - therefore requires no encoding). - - The lowest collation value assigned is 2. Zero is reserved for - the NUL byte terminating the strings in the `strxfrm'/`wcsxfrm' - functions and 1 is used to separate the individual passes for the - different rules. - - We also have to construct is list with all the bytes/words which - can come first in a sequence, followed by all the elements which - also start with this byte/word. The order is reverse which has - among others the important effect that longer strings are located - first in the list. This is required for the output data since - the algorithm used in `strcoll' etc depends on this. - - The multibyte case is easy. We simply sort into an array with - 256 elements. */ - struct locale_collate_t *collate = locale->categories[LC_COLLATE].collate; - int mbact[nrules]; - int wcact; - int mbseqact; - int wcseqact; - struct element_t *runp; - int i; - int need_undefined = 0; - struct section_list *sect; - int ruleidx; - int nr_wide_elems = 0; - - if (collate == NULL) - { - /* No data, no check. */ - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), "LC_COLLATE"); - return; - } - - /* If this assertion is hit change the type in `element_t'. */ - assert (nrules <= sizeof (runp->used_in_level) * 8); - - /* Make sure that the `position' rule is used either in all sections - or in none. */ - for (i = 0; i < nrules; ++i) - for (sect = collate->sections; sect != NULL; sect = sect->next) - if (sect->rules != NULL - && ((sect->rules[i] & sort_position) - != (collate->sections->rules[i] & sort_position))) - { - error (0, 0, _("\ -%s: `position' must be used for a specific level in all sections or none"), - "LC_COLLATE"); - break; - } - - /* Find out which elements are used at which level. At the same - time we find out whether we have any undefined symbols. */ - runp = collate->start; - while (runp != NULL) - { - if (runp->mbs != NULL) - { - for (i = 0; i < nrules; ++i) - { - int j; - - for (j = 0; j < runp->weights[i].cnt; ++j) - /* A NULL pointer as the weight means IGNORE. */ - if (runp->weights[i].w[j] != NULL) - { - if (runp->weights[i].w[j]->weights == NULL) - { - error_at_line (0, 0, runp->file, runp->line, - _("symbol `%s' not defined"), - runp->weights[i].w[j]->name); - - need_undefined = 1; - runp->weights[i].w[j] = &collate->undefined; - } - else - /* Set the bit for the level. */ - runp->weights[i].w[j]->used_in_level |= 1 << i; - } - } - } - - /* Up to the next entry. */ - runp = runp->next; - } - - /* Walk through the list of defined sequences and assign weights. Also - create the data structure which will allow generating the single byte - character based tables. - - Since at each time only the weights for each of the rules are - only compared to other weights for this rule it is possible to - assign more compact weight values than simply counting all - weights in sequence. We can assign weights from 3, one for each - rule individually and only for those elements, which are actually - used for this rule. - - Why is this important? It is not for the wide char table. But - it is for the singlebyte output since here larger numbers have to - be encoded to make it possible to emit the value as a byte - string. */ - for (i = 0; i < nrules; ++i) - mbact[i] = 2; - wcact = 2; - mbseqact = 0; - wcseqact = 0; - runp = collate->start; - while (runp != NULL) - { - /* Determine the order. */ - if (runp->used_in_level != 0) - { - runp->mborder = (int *) obstack_alloc (&collate->mempool, - nrules * sizeof (int)); - - for (i = 0; i < nrules; ++i) - if ((runp->used_in_level & (1 << i)) != 0) - runp->mborder[i] = mbact[i]++; - else - runp->mborder[i] = 0; - } - - if (runp->mbs != NULL) - { - struct element_t **eptr; - struct element_t *lastp = NULL; - - /* Find the point where to insert in the list. */ - eptr = &collate->mbheads[((unsigned char *) runp->mbs)[0]]; - while (*eptr != NULL) - { - if ((*eptr)->nmbs < runp->nmbs) - break; - - if ((*eptr)->nmbs == runp->nmbs) - { - int c = memcmp ((*eptr)->mbs, runp->mbs, runp->nmbs); - - if (c == 0) - { - /* This should not happen. It means that we have - to symbols with the same byte sequence. It is - of course an error. */ - error_at_line (0, 0, (*eptr)->file, (*eptr)->line, - _("symbol `%s' has the same encoding as"), - (*eptr)->name); - error_at_line (0, 0, runp->file, runp->line, - _("symbol `%s'"), runp->name); - goto dont_insert; - } - else if (c < 0) - /* Insert it here. */ - break; - } - - /* To the next entry. */ - lastp = *eptr; - eptr = &(*eptr)->mbnext; - } - - /* Set the pointers. */ - runp->mbnext = *eptr; - runp->mblast = lastp; - if (*eptr != NULL) - (*eptr)->mblast = runp; - *eptr = runp; - dont_insert: - ; - } - - if (runp->used_in_level) - { - runp->wcorder = wcact++; - - /* We take the opportunity to count the elements which have - wide characters. */ - ++nr_wide_elems; - } - - if (runp->is_character) - { - if (runp->nmbs == 1) - collate->mbseqorder[((unsigned char *) runp->mbs)[0]] = mbseqact++; - - runp->wcseqorder = wcseqact++; - } - - /* Up to the next entry. */ - runp = runp->next; - } - - /* Find out whether any of the `mbheads' entries is unset. In this - case we use the UNDEFINED entry. */ - for (i = 1; i < 256; ++i) - if (collate->mbheads[i] == NULL) - { - need_undefined = 1; - collate->mbheads[i] = &collate->undefined; - } - - /* Now to the wide character case. */ - collate->wcheads.p = 6; - collate->wcheads.q = 10; - wchead_table_init (&collate->wcheads); - - collate->wcseqorder.p = 6; - collate->wcseqorder.q = 10; - collseq_table_init (&collate->wcseqorder); - - /* Start adding. */ - runp = collate->start; - while (runp != NULL) - { - if (runp->wcs != NULL) - { - struct element_t *e; - struct element_t **eptr; - struct element_t *lastp; - - /* Insert the collation sequence value. */ - collseq_table_add (&collate->wcseqorder, runp->wcs[0], - runp->wcseqorder); - - /* Find the point where to insert in the list. */ - e = wchead_table_get (&collate->wcheads, runp->wcs[0]); - eptr = &e; - lastp = NULL; - while (*eptr != NULL) - { - if ((*eptr)->nwcs < runp->nwcs) - break; - - if ((*eptr)->nwcs == runp->nwcs) - { - int c = wmemcmp ((wchar_t *) (*eptr)->wcs, - (wchar_t *) runp->wcs, runp->nwcs); - - if (c == 0) - { - /* This should not happen. It means that we have - two symbols with the same byte sequence. It is - of course an error. */ - error_at_line (0, 0, (*eptr)->file, (*eptr)->line, - _("symbol `%s' has the same encoding as"), - (*eptr)->name); - error_at_line (0, 0, runp->file, runp->line, - _("symbol `%s'"), runp->name); - goto dont_insertwc; - } - else if (c < 0) - /* Insert it here. */ - break; - } - - /* To the next entry. */ - lastp = *eptr; - eptr = &(*eptr)->wcnext; - } - - /* Set the pointers. */ - runp->wcnext = *eptr; - runp->wclast = lastp; - if (*eptr != NULL) - (*eptr)->wclast = runp; - *eptr = runp; - if (eptr == &e) - wchead_table_add (&collate->wcheads, runp->wcs[0], e); - dont_insertwc: - ; - } - - /* Up to the next entry. */ - runp = runp->next; - } - - collseq_table_finalize (&collate->wcseqorder); - - /* Now determine whether the UNDEFINED entry is needed and if yes, - whether it was defined. */ - collate->undefined.used_in_level = need_undefined ? ~0ul : 0; - if (collate->undefined.file == NULL) - { - if (need_undefined) - { - /* This seems not to be enforced by recent standards. Don't - emit an error, simply append UNDEFINED at the end. */ - if (0) - error (0, 0, _("no definition of `UNDEFINED'")); - - /* Add UNDEFINED at the end. */ - collate->undefined.mborder = - (int *) obstack_alloc (&collate->mempool, nrules * sizeof (int)); - - for (i = 0; i < nrules; ++i) - collate->undefined.mborder[i] = mbact[i]++; - } - - /* In any case we will need the definition for the wide character - case. But we will not complain that it is missing since the - specification strangely enough does not seem to account for - this. */ - collate->undefined.wcorder = wcact++; - } - - /* Finally, try to unify the rules for the sections. Whenever the rules - for a section are the same as those for another section give the - ruleset the same index. Since there are never many section we can - use an O(n^2) algorithm here. */ - sect = collate->sections; - while (sect != NULL && sect->rules == NULL) - sect = sect->next; - assert (sect != NULL); - ruleidx = 0; - do - { - struct section_list *osect = collate->sections; - - while (osect != sect) - if (osect->rules != NULL - && memcmp (osect->rules, sect->rules, nrules) == 0) - break; - else - osect = osect->next; - - if (osect == sect) - sect->ruleidx = ruleidx++; - else - sect->ruleidx = osect->ruleidx; - - /* Next section. */ - do - sect = sect->next; - while (sect != NULL && sect->rules == NULL); - } - while (sect != NULL); - /* We are currently not prepared for more than 128 rulesets. But this - should never really be a problem. */ - assert (ruleidx <= 128); -} - - -static int32_t -output_weight (struct obstack *pool, struct locale_collate_t *collate, - struct element_t *elem) -{ - size_t cnt; - int32_t retval; - - /* Optimize the use of UNDEFINED. */ - if (elem == &collate->undefined) - /* The weights are already inserted. */ - return 0; - - /* This byte can start exactly one collation element and this is - a single byte. We can directly give the index to the weights. */ - retval = obstack_object_size (pool); - - /* Construct the weight. */ - for (cnt = 0; cnt < nrules; ++cnt) - { - char buf[elem->weights[cnt].cnt * 7]; - int len = 0; - int i; - - for (i = 0; i < elem->weights[cnt].cnt; ++i) - /* Encode the weight value. We do nothing for IGNORE entries. */ - if (elem->weights[cnt].w[i] != NULL) - len += utf8_encode (&buf[len], - elem->weights[cnt].w[i]->mborder[cnt]); - - /* And add the buffer content. */ - obstack_1grow (pool, len); - obstack_grow (pool, buf, len); - } - - return retval | ((elem->section->ruleidx & 0x7f) << 24); -} - - -static int32_t -output_weightwc (struct obstack *pool, struct locale_collate_t *collate, - struct element_t *elem) -{ - size_t cnt; - int32_t retval; - - /* Optimize the use of UNDEFINED. */ - if (elem == &collate->undefined) - /* The weights are already inserted. */ - return 0; - - /* This byte can start exactly one collation element and this is - a single byte. We can directly give the index to the weights. */ - retval = obstack_object_size (pool) / sizeof (int32_t); - - /* Construct the weight. */ - for (cnt = 0; cnt < nrules; ++cnt) - { - int32_t buf[elem->weights[cnt].cnt]; - int i; - int32_t j; - - for (i = 0, j = 0; i < elem->weights[cnt].cnt; ++i) - if (elem->weights[cnt].w[i] != NULL) - buf[j++] = elem->weights[cnt].w[i]->wcorder; - - /* And add the buffer content. */ - obstack_int32_grow (pool, j); - - obstack_grow (pool, buf, j * sizeof (int32_t)); - } - - return retval | ((elem->section->ruleidx & 0x7f) << 24); -} - - -void -collate_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_collate_t *collate = locale->categories[LC_COLLATE].collate; - const size_t nelems = _NL_ITEM_INDEX (_NL_NUM_LC_COLLATE); - struct iovec iov[2 + nelems]; - struct locale_file data; - uint32_t idx[nelems]; - size_t cnt; - size_t ch; - int32_t tablemb[256]; - struct obstack weightpool; - struct obstack extrapool; - struct obstack indirectpool; - struct section_list *sect; - struct collidx_table tablewc; - uint32_t elem_size; - uint32_t *elem_table; - int i; - struct element_t *runp; - - data.magic = LIMAGIC (LC_COLLATE); - data.n = nelems; - iov[0].iov_base = (void *) &data; - iov[0].iov_len = sizeof (data); - - iov[1].iov_base = (void *) idx; - iov[1].iov_len = sizeof (idx); - - idx[0] = iov[0].iov_len + iov[1].iov_len; - cnt = 0; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_NRULES)); - iov[2 + cnt].iov_base = &nrules; - iov[2 + cnt].iov_len = sizeof (uint32_t); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - /* If we have no LC_COLLATE data emit only the number of rules as zero. */ - if (collate == NULL) - { - int32_t dummy = 0; - - while (cnt < _NL_ITEM_INDEX (_NL_NUM_LC_COLLATE)) - { - /* The words have to be handled specially. */ - if (cnt == _NL_ITEM_INDEX (_NL_COLLATE_SYMB_HASH_SIZEMB)) - { - iov[2 + cnt].iov_base = &dummy; - iov[2 + cnt].iov_len = sizeof (int32_t); - } - else - { - iov[2 + cnt].iov_base = NULL; - iov[2 + cnt].iov_len = 0; - } - - if (cnt + 1 < _NL_ITEM_INDEX (_NL_NUM_LC_COLLATE)) - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - } - - assert (cnt == _NL_ITEM_INDEX (_NL_NUM_LC_COLLATE)); - - write_locale_data (output_path, "LC_COLLATE", 2 + cnt, iov); - - return; - } - - obstack_init (&weightpool); - obstack_init (&extrapool); - obstack_init (&indirectpool); - - /* Since we are using the sign of an integer to mark indirection the - offsets in the arrays we are indirectly referring to must not be - zero since -0 == 0. Therefore we add a bit of dummy content. */ - obstack_int32_grow (&extrapool, 0); - obstack_int32_grow (&indirectpool, 0); - - /* Prepare the ruleset table. */ - for (sect = collate->sections, i = 0; sect != NULL; sect = sect->next) - if (sect->rules != NULL && sect->ruleidx == i) - { - int j; - - obstack_make_room (&weightpool, nrules); - - for (j = 0; j < nrules; ++j) - obstack_1grow_fast (&weightpool, sect->rules[j]); - ++i; - } - /* And align the output. */ - i = (nrules * i) % __alignof__ (int32_t); - if (i > 0) - do - obstack_1grow (&weightpool, '\0'); - while (++i < __alignof__ (int32_t)); - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_RULESETS)); - iov[2 + cnt].iov_len = obstack_object_size (&weightpool); - iov[2 + cnt].iov_base = obstack_finish (&weightpool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - /* Generate the 8-bit table. Walk through the lists of sequences - starting with the same byte and add them one after the other to - the table. In case we have more than one sequence starting with - the same byte we have to use extra indirection. - - First add a record for the NUL byte. This entry will never be used - so it does not matter. */ - tablemb[0] = 0; - - /* Now insert the `UNDEFINED' value if it is used. Since this value - will probably be used more than once it is good to store the - weights only once. */ - if (collate->undefined.used_in_level != 0) - output_weight (&weightpool, collate, &collate->undefined); - - for (ch = 1; ch < 256; ++ch) - if (collate->mbheads[ch]->mbnext == NULL - && collate->mbheads[ch]->nmbs <= 1) - { - tablemb[ch] = output_weight (&weightpool, collate, - collate->mbheads[ch]); - } - else - { - /* The entries in the list are sorted by length and then - alphabetically. This is the order in which we will add the - elements to the collation table. This allows simply walking - the table in sequence and stopping at the first matching - entry. Since the longer sequences are coming first in the - list they have the possibility to match first, just as it - has to be. In the worst case we are walking to the end of - the list where we put, if no singlebyte sequence is defined - in the locale definition, the weights for UNDEFINED. - - To reduce the length of the search list we compress them a bit. - This happens by collecting sequences of consecutive byte - sequences in one entry (having and begin and end byte sequence) - and add only one index into the weight table. We can find the - consecutive entries since they are also consecutive in the list. */ - struct element_t *runp = collate->mbheads[ch]; - struct element_t *lastp; - - assert ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) == 0); - - tablemb[ch] = -obstack_object_size (&extrapool); - - do - { - /* Store the current index in the weight table. We know that - the current position in the `extrapool' is aligned on a - 32-bit address. */ - int32_t weightidx; - int added; - - /* Find out wether this is a single entry or we have more than - one consecutive entry. */ - if (runp->mbnext != NULL - && runp->nmbs == runp->mbnext->nmbs - && memcmp (runp->mbs, runp->mbnext->mbs, runp->nmbs - 1) == 0 - && (runp->mbs[runp->nmbs - 1] - == runp->mbnext->mbs[runp->nmbs - 1] + 1)) - { - int i; - struct element_t *series_startp = runp; - struct element_t *curp; - - /* Compute how much space we will need. */ - added = ((sizeof (int32_t) + 1 + 2 * (runp->nmbs - 1) - + __alignof__ (int32_t) - 1) - & ~(__alignof__ (int32_t) - 1)); - assert ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) == 0); - obstack_make_room (&extrapool, added); - - /* More than one consecutive entry. We mark this by having - a negative index into the indirect table. */ - obstack_int32_grow_fast (&extrapool, - -(obstack_object_size (&indirectpool) - / sizeof (int32_t))); - - /* Now search first the end of the series. */ - do - runp = runp->mbnext; - while (runp->mbnext != NULL - && runp->nmbs == runp->mbnext->nmbs - && memcmp (runp->mbs, runp->mbnext->mbs, - runp->nmbs - 1) == 0 - && (runp->mbs[runp->nmbs - 1] - == runp->mbnext->mbs[runp->nmbs - 1] + 1)); - - /* Now walk backward from here to the beginning. */ - curp = runp; - - assert (runp->nmbs <= 256); - obstack_1grow_fast (&extrapool, curp->nmbs - 1); - for (i = 1; i < curp->nmbs; ++i) - obstack_1grow_fast (&extrapool, curp->mbs[i]); - - /* Now find the end of the consecutive sequence and - add all the indeces in the indirect pool. */ - do - { - weightidx = output_weight (&weightpool, collate, curp); - obstack_int32_grow (&indirectpool, weightidx); - - curp = curp->mblast; - } - while (curp != series_startp); - - /* Add the final weight. */ - weightidx = output_weight (&weightpool, collate, curp); - obstack_int32_grow (&indirectpool, weightidx); - - /* And add the end byte sequence. Without length this - time. */ - for (i = 1; i < curp->nmbs; ++i) - obstack_1grow_fast (&extrapool, curp->mbs[i]); - } - else - { - /* A single entry. Simply add the index and the length and - string (except for the first character which is already - tested for). */ - int i; - - /* Output the weight info. */ - weightidx = output_weight (&weightpool, collate, runp); - - added = ((sizeof (int32_t) + 1 + runp->nmbs - 1 - + __alignof__ (int32_t) - 1) - & ~(__alignof__ (int32_t) - 1)); - assert ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) == 0); - obstack_make_room (&extrapool, added); - - obstack_int32_grow_fast (&extrapool, weightidx); - assert (runp->nmbs <= 256); - obstack_1grow_fast (&extrapool, runp->nmbs - 1); - - for (i = 1; i < runp->nmbs; ++i) - obstack_1grow_fast (&extrapool, runp->mbs[i]); - } - - /* Add alignment bytes if necessary. */ - while ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) != 0) - obstack_1grow_fast (&extrapool, '\0'); - - /* Next entry. */ - lastp = runp; - runp = runp->mbnext; - } - while (runp != NULL); - - assert ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) == 0); - - /* If the final entry in the list is not a single character we - add an UNDEFINED entry here. */ - if (lastp->nmbs != 1) - { - int added = ((sizeof (int32_t) + 1 + 1 + __alignof__ (int32_t) - 1) - & ~(__alignof__ (int32_t) - 1)); - obstack_make_room (&extrapool, added); - - obstack_int32_grow_fast (&extrapool, 0); - /* XXX What rule? We just pick the first. */ - obstack_1grow_fast (&extrapool, 0); - /* Length is zero. */ - obstack_1grow_fast (&extrapool, 0); - - /* Add alignment bytes if necessary. */ - while ((obstack_object_size (&extrapool) - & (__alignof__ (int32_t) - 1)) != 0) - obstack_1grow_fast (&extrapool, '\0'); - } - } - - /* Add padding to the tables if necessary. */ - while ((obstack_object_size (&weightpool) & (__alignof__ (int32_t) - 1)) - != 0) - obstack_1grow (&weightpool, 0); - - /* Now add the four tables. */ - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_TABLEMB)); - iov[2 + cnt].iov_base = tablemb; - iov[2 + cnt].iov_len = sizeof (tablemb); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert ((iov[2 + cnt].iov_len & (__alignof__ (int32_t) - 1)) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_WEIGHTMB)); - iov[2 + cnt].iov_len = obstack_object_size (&weightpool); - iov[2 + cnt].iov_base = obstack_finish (&weightpool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_EXTRAMB)); - iov[2 + cnt].iov_len = obstack_object_size (&extrapool); - iov[2 + cnt].iov_base = obstack_finish (&extrapool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_INDIRECTMB)); - iov[2 + cnt].iov_len = obstack_object_size (&indirectpool); - iov[2 + cnt].iov_base = obstack_finish (&indirectpool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert ((iov[2 + cnt].iov_len & (__alignof__ (int32_t) - 1)) == 0); - ++cnt; - - - /* Now the same for the wide character table. We need to store some - more information here. */ - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_GAP1)); - iov[2 + cnt].iov_base = NULL; - iov[2 + cnt].iov_len = 0; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_GAP2)); - iov[2 + cnt].iov_base = NULL; - iov[2 + cnt].iov_len = 0; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_GAP3)); - iov[2 + cnt].iov_base = NULL; - iov[2 + cnt].iov_len = 0; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - /* Since we are using the sign of an integer to mark indirection the - offsets in the arrays we are indirectly referring to must not be - zero since -0 == 0. Therefore we add a bit of dummy content. */ - obstack_int32_grow (&extrapool, 0); - obstack_int32_grow (&indirectpool, 0); - - /* Now insert the `UNDEFINED' value if it is used. Since this value - will probably be used more than once it is good to store the - weights only once. */ - if (output_weightwc (&weightpool, collate, &collate->undefined) != 0) - abort (); - - /* Generate the table. Walk through the lists of sequences starting - with the same wide character and add them one after the other to - the table. In case we have more than one sequence starting with - the same byte we have to use extra indirection. */ - { - auto void add_to_tablewc (uint32_t ch, struct element_t *runp); - - void add_to_tablewc (uint32_t ch, struct element_t *runp) - { - if (runp->wcnext == NULL && runp->nwcs == 1) - { - int32_t weigthidx = output_weightwc (&weightpool, collate, runp); - collidx_table_add (&tablewc, ch, weigthidx); - } - else - { - /* As for the singlebyte table, we recognize sequences and - compress them. */ - struct element_t *lastp; - - collidx_table_add (&tablewc, ch, - -(obstack_object_size (&extrapool) / sizeof (uint32_t))); - - do - { - /* Store the current index in the weight table. We know that - the current position in the `extrapool' is aligned on a - 32-bit address. */ - int32_t weightidx; - int added; - - /* Find out wether this is a single entry or we have more than - one consecutive entry. */ - if (runp->wcnext != NULL - && runp->nwcs == runp->wcnext->nwcs - && wmemcmp ((wchar_t *) runp->wcs, - (wchar_t *)runp->wcnext->wcs, - runp->nwcs - 1) == 0 - && (runp->wcs[runp->nwcs - 1] - == runp->wcnext->wcs[runp->nwcs - 1] + 1)) - { - int i; - struct element_t *series_startp = runp; - struct element_t *curp; - - /* Now add first the initial byte sequence. */ - added = (1 + 1 + 2 * (runp->nwcs - 1)) * sizeof (int32_t); - if (sizeof (int32_t) == sizeof (int)) - obstack_make_room (&extrapool, added); - - /* More than one consecutive entry. We mark this by having - a negative index into the indirect table. */ - obstack_int32_grow_fast (&extrapool, - -(obstack_object_size (&indirectpool) - / sizeof (int32_t))); - obstack_int32_grow_fast (&extrapool, runp->nwcs - 1); - - do - runp = runp->wcnext; - while (runp->wcnext != NULL - && runp->nwcs == runp->wcnext->nwcs - && wmemcmp ((wchar_t *) runp->wcs, - (wchar_t *)runp->wcnext->wcs, - runp->nwcs - 1) == 0 - && (runp->wcs[runp->nwcs - 1] - == runp->wcnext->wcs[runp->nwcs - 1] + 1)); - - /* Now walk backward from here to the beginning. */ - curp = runp; - - for (i = 1; i < runp->nwcs; ++i) - obstack_int32_grow_fast (&extrapool, curp->wcs[i]); - - /* Now find the end of the consecutive sequence and - add all the indeces in the indirect pool. */ - do - { - weightidx = output_weightwc (&weightpool, collate, - curp); - obstack_int32_grow (&indirectpool, weightidx); - - curp = curp->wclast; - } - while (curp != series_startp); - - /* Add the final weight. */ - weightidx = output_weightwc (&weightpool, collate, curp); - obstack_int32_grow (&indirectpool, weightidx); - - /* And add the end byte sequence. Without length this - time. */ - for (i = 1; i < curp->nwcs; ++i) - obstack_int32_grow (&extrapool, curp->wcs[i]); - } - else - { - /* A single entry. Simply add the index and the length and - string (except for the first character which is already - tested for). */ - int i; - - /* Output the weight info. */ - weightidx = output_weightwc (&weightpool, collate, runp); - - added = (1 + 1 + runp->nwcs - 1) * sizeof (int32_t); - if (sizeof (int) == sizeof (int32_t)) - obstack_make_room (&extrapool, added); - - obstack_int32_grow_fast (&extrapool, weightidx); - obstack_int32_grow_fast (&extrapool, runp->nwcs - 1); - for (i = 1; i < runp->nwcs; ++i) - obstack_int32_grow_fast (&extrapool, runp->wcs[i]); - } - - /* Next entry. */ - lastp = runp; - runp = runp->wcnext; - } - while (runp != NULL); - } - } - - tablewc.p = 6; - tablewc.q = 10; - collidx_table_init (&tablewc); - - wchead_table_iterate (&collate->wcheads, add_to_tablewc); - - collidx_table_finalize (&tablewc); - } - - /* Now add the four tables. */ - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_TABLEWC)); - iov[2 + cnt].iov_base = tablewc.result; - iov[2 + cnt].iov_len = tablewc.result_size; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (iov[2 + cnt].iov_len % sizeof (int32_t) == 0); - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_WEIGHTWC)); - iov[2 + cnt].iov_len = obstack_object_size (&weightpool); - iov[2 + cnt].iov_base = obstack_finish (&weightpool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (iov[2 + cnt].iov_len % sizeof (int32_t) == 0); - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_EXTRAWC)); - iov[2 + cnt].iov_len = obstack_object_size (&extrapool); - iov[2 + cnt].iov_base = obstack_finish (&extrapool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (iov[2 + cnt].iov_len % sizeof (int32_t) == 0); - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_INDIRECTWC)); - iov[2 + cnt].iov_len = obstack_object_size (&indirectpool); - iov[2 + cnt].iov_base = obstack_finish (&indirectpool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (iov[2 + cnt].iov_len % sizeof (int32_t) == 0); - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - - /* Finally write the table with collation element names out. It is - a hash table with a simple function which gets the name of the - character as the input. One character might have many names. The - value associated with the name is an index into the weight table - where we are then interested in the first-level weight value. - - To determine how large the table should be we are counting the - elements have to put in. Since we are using internal chaining - using a secondary hash function we have to make the table a bit - larger to avoid extremely long search times. We can achieve - good results with a 40% larger table than there are entries. */ - elem_size = 0; - runp = collate->start; - while (runp != NULL) - { - if (runp->mbs != NULL && runp->weights != NULL) - /* Yep, the element really counts. */ - ++elem_size; - - runp = runp->next; - } - /* Add 40% and find the next prime number. */ - elem_size = MIN (next_prime (elem_size * 1.4), 257); - - /* Allocate the table. Each entry consists of two words: the hash - value and an index in a secondary table which provides the index - into the weight table and the string itself (so that a match can - be determined). */ - elem_table = (uint32_t *) obstack_alloc (&extrapool, - elem_size * 2 * sizeof (uint32_t)); - memset (elem_table, '\0', elem_size * 2 * sizeof (uint32_t)); - - /* Now add the elements. */ - runp = collate->start; - while (runp != NULL) - { - if (runp->mbs != NULL && runp->weights != NULL && !runp->is_character) - { - /* Compute the hash value of the name. */ - uint32_t namelen = strlen (runp->name); - uint32_t hash = elem_hash (runp->name, namelen); - size_t idx = hash % elem_size; - - if (elem_table[idx * 2] != 0) - { - /* The spot is already take. Try iterating using the value - from the secondary hashing function. */ - size_t iter = hash % (elem_size - 2); - - do - { - idx += iter; - if (idx >= elem_size) - idx -= elem_size; - } - while (elem_table[idx * 2] != 0); - } - /* This is the spot where we will insert the value. */ - elem_table[idx * 2] = hash; - elem_table[idx * 2 + 1] = obstack_object_size (&extrapool); - - /* The the string itself including length. */ - obstack_1grow (&extrapool, namelen); - obstack_grow (&extrapool, runp->name, namelen); - - /* And the multibyte representation. */ - obstack_1grow (&extrapool, runp->nmbs); - obstack_grow (&extrapool, runp->mbs, runp->nmbs); - - /* And align again to 32 bits. */ - if ((1 + namelen + 1 + runp->nmbs) % sizeof (int32_t) != 0) - obstack_grow (&extrapool, "\0\0", - (sizeof (int32_t) - - ((1 + namelen + 1 + runp->nmbs) - % sizeof (int32_t)))); - - /* Now some 32-bit values: multibyte collation sequence, - wide char string (including length), and wide char - collation sequence. */ - obstack_int32_grow (&extrapool, runp->mbseqorder); - - obstack_int32_grow (&extrapool, runp->nwcs); - obstack_grow (&extrapool, runp->wcs, - runp->nwcs * sizeof (uint32_t)); - - obstack_int32_grow (&extrapool, runp->wcseqorder); - } - - runp = runp->next; - } - - /* Prepare to write out this data. */ - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_SYMB_HASH_SIZEMB)); - iov[2 + cnt].iov_base = &elem_size; - iov[2 + cnt].iov_len = sizeof (int32_t); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_SYMB_TABLEMB)); - iov[2 + cnt].iov_base = elem_table; - iov[2 + cnt].iov_len = elem_size * 2 * sizeof (int32_t); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_SYMB_EXTRAMB)); - iov[2 + cnt].iov_len = obstack_object_size (&extrapool); - iov[2 + cnt].iov_base = obstack_finish (&extrapool); - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_COLLSEQMB)); - iov[2 + cnt].iov_base = collate->mbseqorder; - iov[2 + cnt].iov_len = 256; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_COLLSEQWC)); - iov[2 + cnt].iov_base = collate->wcseqorder.result; - iov[2 + cnt].iov_len = collate->wcseqorder.result_size; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - assert (idx[cnt] % __alignof__ (int32_t) == 0); - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_COLLATE_CODESET)); - iov[2 + cnt].iov_base = (void *) charmap->code_set_name; - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - ++cnt; - - assert (cnt == _NL_ITEM_INDEX (_NL_NUM_LC_COLLATE)); - - write_locale_data (output_path, "LC_COLLATE", 2 + cnt, iov); - - obstack_free (&weightpool, NULL); - obstack_free (&extrapool, NULL); - obstack_free (&indirectpool, NULL); -} - - -void -collate_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_collate_t *collate; - struct token *now; - struct token *arg = NULL; - enum token_t nowtok; - enum token_t was_ellipsis = tok_none; - struct localedef_t *copy_locale = NULL; - /* Parsing state: - 0 - start - 1 - between `order-start' and `order-end' - 2 - after `order-end' - 3 - after `reorder-after', waiting for `reorder-end' - 4 - after `reorder-end' - 5 - after `reorder-sections-after', waiting for `reorder-sections-end' - 6 - after `reorder-sections-end' - */ - int state = 0; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_COLLATE' must be free. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - if (nowtok == tok_copy) - { - state = 2; - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_string) - { - SYNTAX_ERROR (_("%s: syntax error"), "LC_COLLATE"); - - skip_category: - do - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok != tok_eof && now->tok != tok_end); - - if (now->tok != tok_eof - || (now = lr_token (ldfile, charmap, NULL, verbose), - now->tok == tok_eof)) - lr_error (ldfile, _("%s: premature end of file"), "LC_COLLATE"); - else if (now->tok != tok_lc_collate) - { - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_COLLATE"); - lr_ignore_rest (ldfile, 0); - } - else - lr_ignore_rest (ldfile, 1); - - return; - } - - if (! ignore_content) - { - /* Get the locale definition. */ - copy_locale = load_locale (LC_COLLATE, now->val.str.startmb, - repertoire_name, charmap, NULL); - if ((copy_locale->avail & COLLATE_LOCALE) == 0) - { - /* Not yet loaded. So do it now. */ - if (locfile_read (copy_locale, charmap) != 0) - goto skip_category; - } - } - - lr_ignore_rest (ldfile, 1); - - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* Prepare the data structures. */ - collate_startup (ldfile, result, copy_locale, ignore_content); - collate = result->categories[LC_COLLATE].collate; - - while (1) - { - char ucs4buf[10]; - char *symstr; - size_t symlen; - - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { - case tok_copy: - /* Allow copying other locales. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_string) - goto err_label; - - if (! ignore_content) - load_locale (LC_COLLATE, now->val.str.startmb, repertoire_name, - charmap, result); - - lr_ignore_rest (ldfile, 1); - break; - - case tok_coll_weight_max: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0) - goto err_label; - - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok != tok_number) - goto err_label; - if (collate->col_weight_max != -1) - lr_error (ldfile, _("%s: duplicate definition of `%s'"), - "LC_COLLATE", "col_weight_max"); - else - collate->col_weight_max = arg->val.num; - lr_ignore_rest (ldfile, 1); - break; - - case tok_section_symbol: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0) - goto err_label; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - goto err_label; - else if (!ignore_content) - { - /* Check whether this section is already known. */ - struct section_list *known = collate->sections; - while (known != NULL) - { - if (strcmp (known->name, arg->val.str.startmb) == 0) - break; - known = known->next; - } - - if (known != NULL) - { - lr_error (ldfile, - _("%s: duplicate declaration of section `%s'"), - "LC_COLLATE", arg->val.str.startmb); - free (arg->val.str.startmb); - } - else - collate->sections = make_seclist_elem (collate, - arg->val.str.startmb, - collate->sections); - - lr_ignore_rest (ldfile, known == NULL); - } - else - { - free (arg->val.str.startmb); - lr_ignore_rest (ldfile, 0); - } - break; - - case tok_collating_element: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0 && state != 2) - goto err_label; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - goto err_label; - else - { - const char *symbol = arg->val.str.startmb; - size_t symbol_len = arg->val.str.lenmb; - - /* Next the `from' keyword. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_from) - { - free ((char *) symbol); - goto err_label; - } - - ldfile->return_widestr = 1; - ldfile->translate_strings = 1; - - /* Finally the string with the replacement. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - - ldfile->return_widestr = 0; - ldfile->translate_strings = 0; - - if (arg->tok != tok_string) - goto err_label; - - if (!ignore_content && symbol != NULL) - { - /* The name is already defined. */ - if (check_duplicate (ldfile, collate, charmap, - repertoire, symbol, symbol_len)) - goto col_elem_free; - - if (arg->val.str.startmb != NULL) - insert_entry (&collate->elem_table, symbol, symbol_len, - new_element (collate, - arg->val.str.startmb, - arg->val.str.lenmb - 1, - arg->val.str.startwc, - symbol, symbol_len, 0)); - } - else - { - col_elem_free: - if (symbol != NULL) - free ((char *) symbol); - if (arg->val.str.startmb != NULL) - free (arg->val.str.startmb); - if (arg->val.str.startwc != NULL) - free (arg->val.str.startwc); - } - lr_ignore_rest (ldfile, 1); - } - break; - - case tok_collating_symbol: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0 && state != 2) - goto err_label; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - goto err_label; - else - { - char *symbol = arg->val.str.startmb; - size_t symbol_len = arg->val.str.lenmb; - char *endsymbol = NULL; - size_t endsymbol_len = 0; - enum token_t ellipsis = tok_none; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok == tok_ellipsis2 || arg->tok == tok_ellipsis4) - { - ellipsis = arg->tok; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - { - free (symbol); - goto err_label; - } - - endsymbol = arg->val.str.startmb; - endsymbol_len = arg->val.str.lenmb; - - lr_ignore_rest (ldfile, 1); - } - else if (arg->tok != tok_eol) - { - free (symbol); - goto err_label; - } - - if (!ignore_content) - { - if (symbol == NULL - || (ellipsis != tok_none && endsymbol == NULL)) - { - lr_error (ldfile, _("\ -%s: unknown character in collating symbol name"), - "LC_COLLATE"); - goto col_sym_free; - } - else if (ellipsis == tok_none) - { - /* A single symbol, no ellipsis. */ - if (check_duplicate (ldfile, collate, charmap, - repertoire, symbol, symbol_len)) - /* The name is already defined. */ - goto col_sym_free; - - insert_entry (&collate->sym_table, symbol, symbol_len, - new_symbol (collate, symbol, symbol_len)); - } - else if (symbol_len != endsymbol_len) - { - col_sym_inv_range: - lr_error (ldfile, - _("invalid names for character range")); - goto col_sym_free; - } - else - { - /* Oh my, we have to handle an ellipsis. First, as - usual, determine the common prefix and then - convert the rest into a range. */ - size_t prefixlen; - unsigned long int from; - unsigned long int to; - char *endp; - - for (prefixlen = 0; prefixlen < symbol_len; ++prefixlen) - if (symbol[prefixlen] != endsymbol[prefixlen]) - break; - - /* Convert the rest into numbers. */ - symbol[symbol_len] = '\0'; - from = strtoul (&symbol[prefixlen], &endp, - ellipsis == tok_ellipsis2 ? 16 : 10); - if (*endp != '\0') - goto col_sym_inv_range; - - endsymbol[symbol_len] = '\0'; - to = strtoul (&endsymbol[prefixlen], &endp, - ellipsis == tok_ellipsis2 ? 16 : 10); - if (*endp != '\0') - goto col_sym_inv_range; - - if (from > to) - goto col_sym_inv_range; - - /* Now loop over all entries. */ - while (from <= to) - { - char *symbuf; - - symbuf = (char *) obstack_alloc (&collate->mempool, - symbol_len + 1); - - /* Create the name. */ - sprintf (symbuf, - ellipsis == tok_ellipsis2 - ? "%.*s%.*lX" : "%.*s%.*lu", - (int) prefixlen, symbol, - (int) (symbol_len - prefixlen), from); - - if (check_duplicate (ldfile, collate, charmap, - repertoire, symbuf, symbol_len)) - /* The name is already defined. */ - goto col_sym_free; - - insert_entry (&collate->sym_table, symbuf, - symbol_len, - new_symbol (collate, symbuf, - symbol_len)); - - /* Increment the counter. */ - ++from; - } - - goto col_sym_free; - } - } - else - { - col_sym_free: - if (symbol != NULL) - free (symbol); - if (endsymbol != NULL) - free (endsymbol); - } - } - break; - - case tok_symbol_equivalence: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0) - goto err_label; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - goto err_label; - else - { - const char *newname = arg->val.str.startmb; - size_t newname_len = arg->val.str.lenmb; - const char *symname; - size_t symname_len; - struct symbol_t *symval; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - { - if (newname != NULL) - free ((char *) newname); - goto err_label; - } - - symname = arg->val.str.startmb; - symname_len = arg->val.str.lenmb; - - if (newname == NULL) - { - lr_error (ldfile, _("\ -%s: unknown character in equivalent definition name"), - "LC_COLLATE"); - - sym_equiv_free: - if (newname != NULL) - free ((char *) newname); - if (symname != NULL) - free ((char *) symname); - break; - } - if (symname == NULL) - { - lr_error (ldfile, _("\ -%s: unknown character in equivalent definition value"), - "LC_COLLATE"); - goto sym_equiv_free; - } - - /* See whether the symbol name is already defined. */ - if (find_entry (&collate->sym_table, symname, symname_len, - (void **) &symval) != 0) - { - lr_error (ldfile, _("\ -%s: unknown symbol `%s' in equivalent definition"), - "LC_COLLATE", symname); - goto col_sym_free; - } - - if (insert_entry (&collate->sym_table, - newname, newname_len, symval) < 0) - { - lr_error (ldfile, _("\ -error while adding equivalent collating symbol")); - goto sym_equiv_free; - } - - free ((char *) symname); - } - lr_ignore_rest (ldfile, 1); - break; - - case tok_script: - /* We get told about the scripts we know. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_bsymbol) - goto err_label; - else - { - struct section_list *runp = collate->known_sections; - char *name; - - while (runp != NULL) - if (strncmp (runp->name, arg->val.str.startmb, - arg->val.str.lenmb) == 0 - && runp->name[arg->val.str.lenmb] == '\0') - break; - else - runp = runp->def_next; - - if (runp != NULL) - { - lr_error (ldfile, _("duplicate definition of script `%s'"), - runp->name); - lr_ignore_rest (ldfile, 0); - break; - } - - runp = (struct section_list *) xcalloc (1, sizeof (*runp)); - name = (char *) xmalloc (arg->val.str.lenmb + 1); - memcpy (name, arg->val.str.startmb, arg->val.str.lenmb); - name[arg->val.str.lenmb] = '\0'; - runp->name = name; - - runp->def_next = collate->known_sections; - collate->known_sections = runp; - } - lr_ignore_rest (ldfile, 1); - break; - - case tok_order_start: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0 && state != 1) - goto err_label; - state = 1; - - /* The 14652 draft does not specify whether all `order_start' lines - must contain the same number of sort-rules, but 14651 does. So - we require this here as well. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok == tok_bsymbol) - { - /* This better should be a section name. */ - struct section_list *sp = collate->known_sections; - while (sp != NULL - && (sp->name == NULL - || strncmp (sp->name, arg->val.str.startmb, - arg->val.str.lenmb) != 0 - || sp->name[arg->val.str.lenmb] != '\0')) - sp = sp->def_next; - - if (sp == NULL) - { - lr_error (ldfile, _("\ -%s: unknown section name `%s'"), - "LC_COLLATE", arg->val.str.startmb); - /* We use the error section. */ - collate->current_section = &collate->error_section; - - if (collate->error_section.first == NULL) - { - /* Insert &collate->error_section at the end of - the collate->sections list. */ - if (collate->sections == NULL) - collate->sections = &collate->error_section; - else - { - sp = collate->sections; - while (sp->next != NULL) - sp = sp->next; - - sp->next = &collate->error_section; - } - collate->error_section.next = NULL; - } - } - else - { - /* One should not be allowed to open the same - section twice. */ - if (sp->first != NULL) - lr_error (ldfile, _("\ -%s: multiple order definitions for section `%s'"), - "LC_COLLATE", sp->name); - else - { - /* Insert sp in the collate->sections list, - right after collate->current_section. */ - if (collate->current_section == NULL) - collate->current_section = sp; - else - { - sp->next = collate->current_section->next; - collate->current_section->next = sp; - } - } - - /* Next should come the end of the line or a semicolon. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok == tok_eol) - { - uint32_t cnt; - - /* This means we have exactly one rule: `forward'. */ - if (nrules > 1) - lr_error (ldfile, _("\ -%s: invalid number of sorting rules"), - "LC_COLLATE"); - else - nrules = 1; - sp->rules = obstack_alloc (&collate->mempool, - (sizeof (enum coll_sort_rule) - * nrules)); - for (cnt = 0; cnt < nrules; ++cnt) - sp->rules[cnt] = sort_forward; - - /* Next line. */ - break; - } - - /* Get the next token. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - } - } - else - { - /* There is no section symbol. Therefore we use the unnamed - section. */ - collate->current_section = &collate->unnamed_section; - - if (collate->unnamed_section.first != NULL) - lr_error (ldfile, _("\ -%s: multiple order definitions for unnamed section"), - "LC_COLLATE"); - else - { - /* Insert &collate->unnamed_section at the beginning of - the collate->sections list. */ - collate->unnamed_section.next = collate->sections; - collate->sections = &collate->unnamed_section; - } - } - - /* Now read the direction names. */ - read_directions (ldfile, arg, charmap, repertoire, collate); - - /* From now we need the strings untranslated. */ - ldfile->translate_strings = 0; - break; - - case tok_order_end: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 1) - goto err_label; - - /* Handle ellipsis at end of list. */ - if (was_ellipsis != tok_none) - { - handle_ellipsis (ldfile, NULL, 0, was_ellipsis, charmap, - repertoire, collate); - was_ellipsis = tok_none; - } - - state = 2; - lr_ignore_rest (ldfile, 1); - break; - - case tok_reorder_after: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state == 1) - { - lr_error (ldfile, _("%s: missing `order_end' keyword"), - "LC_COLLATE"); - state = 2; - - /* Handle ellipsis at end of list. */ - if (was_ellipsis != tok_none) - { - handle_ellipsis (ldfile, arg->val.str.startmb, - arg->val.str.lenmb, was_ellipsis, charmap, - repertoire, collate); - was_ellipsis = tok_none; - } - } - else if (state != 2 && state != 3) - goto err_label; - state = 3; - - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok == tok_bsymbol || arg->tok == tok_ucs4) - { - /* Find this symbol in the sequence table. */ - char ucsbuf[10]; - char *startmb; - size_t lenmb; - struct element_t *insp; - int no_error = 1; - - if (arg->tok == tok_bsymbol) - { - startmb = arg->val.str.startmb; - lenmb = arg->val.str.lenmb; - } - else - { - sprintf (ucsbuf, "U%08X", arg->val.ucs4); - startmb = ucsbuf; - lenmb = 9; - } - - if (find_entry (&collate->seq_table, startmb, lenmb, - (void **) &insp) == 0) - /* Yes, the symbol exists. Simply point the cursor - to it. */ - collate->cursor = insp; - else - { - struct symbol_t *symbp; - - if (find_entry (&collate->sym_table, startmb, lenmb, - (void **) &symbp) == 0) - { - if (symbp->order->last != NULL - || symbp->order->next != NULL) - collate->cursor = symbp->order; - else - { - /* This is a collating symbol but its position - is not yet defined. */ - lr_error (ldfile, _("\ -%s: order for collating symbol %.*s not yet defined"), - "LC_COLLATE", (int) lenmb, startmb); - collate->cursor = NULL; - no_error = 0; - } - } - else if (find_entry (&collate->elem_table, startmb, lenmb, - (void **) &insp) == 0) - { - if (insp->last != NULL || insp->next != NULL) - collate->cursor = insp; - else - { - /* This is a collating element but its position - is not yet defined. */ - lr_error (ldfile, _("\ -%s: order for collating element %.*s not yet defined"), - "LC_COLLATE", (int) lenmb, startmb); - collate->cursor = NULL; - no_error = 0; - } - } - else - { - /* This is bad. The symbol after which we have to - insert does not exist. */ - lr_error (ldfile, _("\ -%s: cannot reorder after %.*s: symbol not known"), - "LC_COLLATE", (int) lenmb, startmb); - collate->cursor = NULL; - no_error = 0; - } - } - - lr_ignore_rest (ldfile, no_error); - } - else - /* This must not happen. */ - goto err_label; - break; - - case tok_reorder_end: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - break; - - if (state != 3) - goto err_label; - state = 4; - lr_ignore_rest (ldfile, 1); - break; - - case tok_reorder_sections_after: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state == 1) - { - lr_error (ldfile, _("%s: missing `order_end' keyword"), - "LC_COLLATE"); - state = 2; - - /* Handle ellipsis at end of list. */ - if (was_ellipsis != tok_none) - { - handle_ellipsis (ldfile, NULL, 0, was_ellipsis, charmap, - repertoire, collate); - was_ellipsis = tok_none; - } - } - else if (state == 3) - { - error (0, 0, _("%s: missing `reorder-end' keyword"), - "LC_COLLATE"); - state = 4; - } - else if (state != 2 && state != 4) - goto err_label; - state = 5; - - /* Get the name of the sections we are adding after. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok == tok_bsymbol) - { - /* Now find a section with this name. */ - struct section_list *runp = collate->sections; - - while (runp != NULL) - { - if (runp->name != NULL - && strlen (runp->name) == arg->val.str.lenmb - && memcmp (runp->name, arg->val.str.startmb, - arg->val.str.lenmb) == 0) - break; - - runp = runp->next; - } - - if (runp != NULL) - collate->current_section = runp; - else - { - /* This is bad. The section after which we have to - reorder does not exist. Therefore we cannot - process the whole rest of this reorder - specification. */ - lr_error (ldfile, _("%s: section `%.*s' not known"), - "LC_COLLATE", (int) arg->val.str.lenmb, - arg->val.str.startmb); - - do - { - lr_ignore_rest (ldfile, 0); - - now = lr_token (ldfile, charmap, NULL, verbose); - } - while (now->tok == tok_reorder_sections_after - || now->tok == tok_reorder_sections_end - || now->tok == tok_end); - - /* Process the token we just saw. */ - nowtok = now->tok; - continue; - } - } - else - /* This must not happen. */ - goto err_label; - break; - - case tok_reorder_sections_end: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - break; - - if (state != 5) - goto err_label; - state = 6; - lr_ignore_rest (ldfile, 1); - break; - - case tok_bsymbol: - case tok_ucs4: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 0 && state != 1 && state != 3 && state != 5) - goto err_label; - - if ((state == 0 || state == 5) && nowtok == tok_ucs4) - goto err_label; - - if (nowtok == tok_ucs4) - { - snprintf (ucs4buf, sizeof (ucs4buf), "U%08X", now->val.ucs4); - symstr = ucs4buf; - symlen = 9; - } - else - { - symstr = arg->val.str.startmb; - symlen = arg->val.str.lenmb; - } - - if (state == 0) - { - /* We are outside an `order_start' region. This means - we must only accept definitions of values for - collation symbols since these are purely abstract - values and don't need directions associated. */ - struct element_t *seqp; - - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &seqp) == 0) - { - /* It's already defined. First check whether this - is really a collating symbol. */ - if (seqp->is_character) - goto err_label; - - goto move_entry; - } - else - { - void *result; - - if (find_entry (&collate->sym_table, symstr, symlen, - &result) != 0) - /* No collating symbol, it's an error. */ - goto err_label; - - /* Maybe this is the first time we define a symbol - value and it is before the first actual section. */ - if (collate->sections == NULL) - collate->sections = collate->current_section = - &collate->symbol_section; - } - - if (was_ellipsis != tok_none) - { - - handle_ellipsis (ldfile, symstr, symlen, was_ellipsis, - charmap, repertoire, collate); - - /* Remember that we processed the ellipsis. */ - was_ellipsis = tok_none; - - /* And don't add the value a second time. */ - break; - } - } - else if (state == 3) - { - /* It is possible that we already have this collation sequence. - In this case we move the entry. */ - struct element_t *seqp; - void *sym; - - /* If the symbol after which we have to insert was not found - ignore all entries. */ - if (collate->cursor == NULL) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &seqp) == 0) - goto move_entry; - - if (find_entry (&collate->sym_table, symstr, symlen, &sym) == 0 - && (seqp = ((struct symbol_t *) sym)->order) != NULL) - goto move_entry; - - if (find_entry (&collate->elem_table, symstr, symlen, - (void **) &seqp) == 0 - && (seqp->last != NULL || seqp->next != NULL - || (collate->start != NULL && seqp == collate->start))) - { - move_entry: - /* Remove the entry from the old position. */ - if (seqp->last == NULL) - collate->start = seqp->next; - else - seqp->last->next = seqp->next; - if (seqp->next != NULL) - seqp->next->last = seqp->last; - - /* We also have to check whether this entry is the - first or last of a section. */ - if (seqp->section->first == seqp) - { - if (seqp->section->first == seqp->section->last) - /* This section has no content anymore. */ - seqp->section->first = seqp->section->last = NULL; - else - seqp->section->first = seqp->next; - } - else if (seqp->section->last == seqp) - seqp->section->last = seqp->last; - - /* Now insert it in the new place. */ - insert_weights (ldfile, seqp, charmap, repertoire, collate, - tok_none); - break; - } - - /* Otherwise we just add a new entry. */ - } - else if (state == 5) - { - /* We are reordering sections. Find the named section. */ - struct section_list *runp = collate->sections; - struct section_list *prevp = NULL; - - while (runp != NULL) - { - if (runp->name != NULL - && strlen (runp->name) == symlen - && memcmp (runp->name, symstr, symlen) == 0) - break; - - prevp = runp; - runp = runp->next; - } - - if (runp == NULL) - { - lr_error (ldfile, _("%s: section `%.*s' not known"), - "LC_COLLATE", (int) symlen, symstr); - lr_ignore_rest (ldfile, 0); - } - else - { - if (runp != collate->current_section) - { - /* Remove the named section from the old place and - insert it in the new one. */ - prevp->next = runp->next; - - runp->next = collate->current_section->next; - collate->current_section->next = runp; - collate->current_section = runp; - } - - /* Process the rest of the line which might change - the collation rules. */ - arg = lr_token (ldfile, charmap, repertoire, verbose); - if (arg->tok != tok_eof && arg->tok != tok_eol) - read_directions (ldfile, arg, charmap, repertoire, - collate); - } - break; - } - else if (was_ellipsis != tok_none) - { - /* Using the information in the `ellipsis_weight' - element and this and the last value we have to handle - the ellipsis now. */ - assert (state == 1); - - handle_ellipsis (ldfile, symstr, symlen, was_ellipsis, charmap, - repertoire, collate); - - /* Remember that we processed the ellipsis. */ - was_ellipsis = tok_none; - - /* And don't add the value a second time. */ - break; - } - - /* Now insert in the new place. */ - insert_value (ldfile, symstr, symlen, charmap, repertoire, collate); - break; - - case tok_undefined: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (state != 1) - goto err_label; - - if (was_ellipsis != tok_none) - { - lr_error (ldfile, - _("%s: cannot have `%s' as end of ellipsis range"), - "LC_COLLATE", "UNDEFINED"); - - unlink_element (collate); - was_ellipsis = tok_none; - } - - /* See whether UNDEFINED already appeared somewhere. */ - if (collate->undefined.next != NULL - || &collate->undefined == collate->cursor) - { - lr_error (ldfile, - _("%s: order for `%.*s' already defined at %s:%Zu"), - "LC_COLLATE", 9, "UNDEFINED", - collate->undefined.file, - collate->undefined.line); - lr_ignore_rest (ldfile, 0); - } - else - /* Parse the weights. */ - insert_weights (ldfile, &collate->undefined, charmap, - repertoire, collate, tok_none); - break; - - case tok_ellipsis2: /* symbolic hexadecimal ellipsis */ - case tok_ellipsis3: /* absolute ellipsis */ - case tok_ellipsis4: /* symbolic decimal ellipsis */ - /* This is the symbolic (decimal or hexadecimal) or absolute - ellipsis. */ - if (was_ellipsis != tok_none) - goto err_label; - - if (state != 0 && state != 1 && state != 3) - goto err_label; - - was_ellipsis = nowtok; - - insert_weights (ldfile, &collate->ellipsis_weight, charmap, - repertoire, collate, nowtok); - break; - - case tok_end: - /* Next we assume `LC_COLLATE'. */ - if (!ignore_content) - { - if (state == 0) - /* We must either see a copy statement or have - ordering values. */ - lr_error (ldfile, - _("%s: empty category description not allowed"), - "LC_COLLATE"); - else if (state == 1) - { - lr_error (ldfile, _("%s: missing `order_end' keyword"), - "LC_COLLATE"); - - /* Handle ellipsis at end of list. */ - if (was_ellipsis != tok_none) - { - handle_ellipsis (ldfile, NULL, 0, was_ellipsis, charmap, - repertoire, collate); - was_ellipsis = tok_none; - } - } - else if (state == 3) - error (0, 0, _("%s: missing `reorder-end' keyword"), - "LC_COLLATE"); - else if (state == 5) - error (0, 0, _("%s: missing `reorder-sections-end' keyword"), - "LC_COLLATE"); - } - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_COLLATE"); - else if (arg->tok != tok_lc_collate) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_COLLATE"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_collate); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_COLLATE"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_COLLATE"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-ctype.c b/src/system/libroot/posix/glibc/locale/programs/ld-ctype.c deleted file mode 100644 index fbcf388cb7..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-ctype.c +++ /dev/null @@ -1,4089 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "charmap.h" -#include "localeinfo.h" -#include "langinfo.h" -#include "linereader.h" -#include "locfile-token.h" -#include "locfile.h" -#include "localedef.h" - -#include - - -#ifdef PREDEFINED_CLASSES -/* These are the extra bits not in wctype.h since these are not preallocated - classes. */ -# define _ISwspecial1 (1 << 29) -# define _ISwspecial2 (1 << 30) -# define _ISwspecial3 (1 << 31) -#endif - - -/* The bit used for representing a special class. */ -#define BITPOS(class) ((class) - tok_upper) -#define BIT(class) (_ISbit (BITPOS (class))) -#define BITw(class) (_ISwbit (BITPOS (class))) - -#define ELEM(ctype, collection, idx, value) \ - *find_idx (ctype, &ctype->collection idx, &ctype->collection##_max idx, \ - &ctype->collection##_act idx, value) - - -/* To be compatible with former implementations we for now restrict - the number of bits for character classes to 16. When compatibility - is not necessary anymore increase the number to 32. */ -#define char_class_t uint16_t -#define char_class32_t uint32_t - - -/* Type to describe a transliteration action. We have a possibly - multiple character from-string and a set of multiple character - to-strings. All are 32bit values since this is what is used in - the gconv functions. */ -struct translit_to_t -{ - uint32_t *str; - - struct translit_to_t *next; -}; - -struct translit_t -{ - uint32_t *from; - - const char *fname; - size_t lineno; - - struct translit_to_t *to; - - struct translit_t *next; -}; - -struct translit_ignore_t -{ - uint32_t from; - uint32_t to; - uint32_t step; - - const char *fname; - size_t lineno; - - struct translit_ignore_t *next; -}; - - -/* Type to describe a transliteration include statement. */ -struct translit_include_t -{ - const char *copy_locale; - const char *copy_repertoire; - - struct translit_include_t *next; -}; - - -/* Sparse table of uint32_t. */ -#define TABLE idx_table -#define ELEMENT uint32_t -#define DEFAULT ((uint32_t) ~0) -#define NO_FINALIZE -#include "3level.h" - - -/* The real definition of the struct for the LC_CTYPE locale. */ -struct locale_ctype_t -{ - uint32_t *charnames; - size_t charnames_max; - size_t charnames_act; - /* An index lookup table, to speedup find_idx. */ - struct idx_table charnames_idx; - - struct repertoire_t *repertoire; - - /* We will allow up to 8 * sizeof (uint32_t) character classes. */ -#define MAX_NR_CHARCLASS (8 * sizeof (uint32_t)) - size_t nr_charclass; - const char *classnames[MAX_NR_CHARCLASS]; - uint32_t last_class_char; - uint32_t class256_collection[256]; - uint32_t *class_collection; - size_t class_collection_max; - size_t class_collection_act; - uint32_t class_done; - uint32_t class_offset; - - struct charseq **mbdigits; - size_t mbdigits_act; - size_t mbdigits_max; - uint32_t *wcdigits; - size_t wcdigits_act; - size_t wcdigits_max; - - struct charseq *mboutdigits[10]; - uint32_t wcoutdigits[10]; - size_t outdigits_act; - - /* If the following number ever turns out to be too small simply - increase it. But I doubt it will. --drepper@gnu */ -#define MAX_NR_CHARMAP 16 - const char *mapnames[MAX_NR_CHARMAP]; - uint32_t *map_collection[MAX_NR_CHARMAP]; - uint32_t map256_collection[2][256]; - size_t map_collection_max[MAX_NR_CHARMAP]; - size_t map_collection_act[MAX_NR_CHARMAP]; - size_t map_collection_nr; - size_t last_map_idx; - int tomap_done[MAX_NR_CHARMAP]; - uint32_t map_offset; - - /* Transliteration information. */ - struct translit_include_t *translit_include; - struct translit_t *translit; - struct translit_ignore_t *translit_ignore; - uint32_t ntranslit_ignore; - - uint32_t *default_missing; - const char *default_missing_file; - size_t default_missing_lineno; - - /* The arrays for the binary representation. */ - char_class_t *ctype_b; - char_class32_t *ctype32_b; - uint32_t **map_b; - uint32_t **map32_b; - uint32_t **class_b; - struct iovec *class_3level; - struct iovec *map_3level; - uint32_t *class_name_ptr; - uint32_t *map_name_ptr; - struct iovec width; - uint32_t mb_cur_max; - const char *codeset_name; - uint32_t *translit_from_idx; - uint32_t *translit_from_tbl; - uint32_t *translit_to_idx; - uint32_t *translit_to_tbl; - uint32_t translit_idx_size; - size_t translit_from_tbl_size; - size_t translit_to_tbl_size; - - struct obstack mempool; -}; - -/* Marker for an empty slot. This has the value 0xFFFFFFFF, regardless - whether 'int' is 16 bit, 32 bit, or 64 bit. */ -#define EMPTY ((uint32_t) ~0) - - -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free - - -/* Prototypes for local functions. */ -static void ctype_startup (struct linereader *lr, struct localedef_t *locale, - struct charmap_t *charmap, - struct localedef_t *copy_locale, - int ignore_content); -static void ctype_class_new (struct linereader *lr, - struct locale_ctype_t *ctype, const char *name); -static void ctype_map_new (struct linereader *lr, - struct locale_ctype_t *ctype, - const char *name, struct charmap_t *charmap); -static uint32_t *find_idx (struct locale_ctype_t *ctype, uint32_t **table, - size_t *max, size_t *act, unsigned int idx); -static void set_class_defaults (struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire); -static void allocate_arrays (struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire); - - -static const char *longnames[] = -{ - "zero", "one", "two", "three", "four", - "five", "six", "seven", "eight", "nine" -}; -static const char *uninames[] = -{ - "U00000030", "U00000031", "U00000032", "U00000033", "U00000034", - "U00000035", "U00000036", "U00000037", "U00000038", "U00000039" -}; -static const unsigned char digits[] = "0123456789"; - - -static void -ctype_startup (struct linereader *lr, struct localedef_t *locale, - struct charmap_t *charmap, struct localedef_t *copy_locale, - int ignore_content) -{ - unsigned int cnt; - struct locale_ctype_t *ctype; - - if (!ignore_content && locale->categories[LC_CTYPE].ctype == NULL) - { - if (copy_locale == NULL) - { - /* Allocate the needed room. */ - locale->categories[LC_CTYPE].ctype = ctype = - (struct locale_ctype_t *) xcalloc (1, - sizeof (struct locale_ctype_t)); - - /* We have seen no names yet. */ - ctype->charnames_max = charmap->mb_cur_max == 1 ? 256 : 512; - ctype->charnames = - (unsigned int *) xmalloc (ctype->charnames_max - * sizeof (unsigned int)); - for (cnt = 0; cnt < 256; ++cnt) - ctype->charnames[cnt] = cnt; - ctype->charnames_act = 256; - idx_table_init (&ctype->charnames_idx); - - /* Fill character class information. */ - ctype->last_class_char = ILLEGAL_CHAR_VALUE; - /* The order of the following instructions determines the bit - positions! */ - ctype_class_new (lr, ctype, "upper"); - ctype_class_new (lr, ctype, "lower"); - ctype_class_new (lr, ctype, "alpha"); - ctype_class_new (lr, ctype, "digit"); - ctype_class_new (lr, ctype, "xdigit"); - ctype_class_new (lr, ctype, "space"); - ctype_class_new (lr, ctype, "print"); - ctype_class_new (lr, ctype, "graph"); - ctype_class_new (lr, ctype, "blank"); - ctype_class_new (lr, ctype, "cntrl"); - ctype_class_new (lr, ctype, "punct"); - ctype_class_new (lr, ctype, "alnum"); -#ifdef PREDEFINED_CLASSES - /* The following are extensions from ISO 14652. */ - ctype_class_new (lr, ctype, "left_to_right"); - ctype_class_new (lr, ctype, "right_to_left"); - ctype_class_new (lr, ctype, "num_terminator"); - ctype_class_new (lr, ctype, "num_separator"); - ctype_class_new (lr, ctype, "segment_separator"); - ctype_class_new (lr, ctype, "block_separator"); - ctype_class_new (lr, ctype, "direction_control"); - ctype_class_new (lr, ctype, "sym_swap_layout"); - ctype_class_new (lr, ctype, "char_shape_selector"); - ctype_class_new (lr, ctype, "num_shape_selector"); - ctype_class_new (lr, ctype, "non_spacing"); - ctype_class_new (lr, ctype, "non_spacing_level3"); - ctype_class_new (lr, ctype, "normal_connect"); - ctype_class_new (lr, ctype, "r_connect"); - ctype_class_new (lr, ctype, "no_connect"); - ctype_class_new (lr, ctype, "no_connect-space"); - ctype_class_new (lr, ctype, "vowel_connect"); -#endif - - ctype->class_collection_max = charmap->mb_cur_max == 1 ? 256 : 512; - ctype->class_collection - = (uint32_t *) xcalloc (sizeof (unsigned long int), - ctype->class_collection_max); - ctype->class_collection_act = 256; - - /* Fill character map information. */ - ctype->last_map_idx = MAX_NR_CHARMAP; - ctype_map_new (lr, ctype, "toupper", charmap); - ctype_map_new (lr, ctype, "tolower", charmap); -#ifdef PREDEFINED_CLASSES - ctype_map_new (lr, ctype, "tosymmetric", charmap); -#endif - - /* Fill first 256 entries in `toXXX' arrays. */ - for (cnt = 0; cnt < 256; ++cnt) - { - ctype->map_collection[0][cnt] = cnt; - ctype->map_collection[1][cnt] = cnt; -#ifdef PREDEFINED_CLASSES - ctype->map_collection[2][cnt] = cnt; -#endif - ctype->map256_collection[0][cnt] = cnt; - ctype->map256_collection[1][cnt] = cnt; - } - - obstack_init (&ctype->mempool); - } - else - ctype = locale->categories[LC_CTYPE].ctype = - copy_locale->categories[LC_CTYPE].ctype; - } -} - - -void -ctype_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - /* See POSIX.2, table 2-6 for the meaning of the following table. */ -#define NCLASS 12 - static const struct - { - const char *name; - const char allow[NCLASS]; - } - valid_table[NCLASS] = - { - /* The order is important. See token.h for more information. - M = Always, D = Default, - = Permitted, X = Mutually exclusive */ - { "upper", "--MX-XDDXXX-" }, - { "lower", "--MX-XDDXXX-" }, - { "alpha", "---X-XDDXXX-" }, - { "digit", "XXX--XDDXXX-" }, - { "xdigit", "-----XDDXXX-" }, - { "space", "XXXXX------X" }, - { "print", "---------X--" }, - { "graph", "---------X--" }, - { "blank", "XXXXXM-----X" }, - { "cntrl", "XXXXX-XX--XX" }, - { "punct", "XXXXX-DD-X-X" }, - { "alnum", "-----XDDXXX-" } - }; - size_t cnt; - int cls1, cls2; - uint32_t space_value; - struct charseq *space_seq; - struct locale_ctype_t *ctype = locale->categories[LC_CTYPE].ctype; - int warned; - const void *key; - size_t len; - void *vdata; - void *curs; - - /* Now resolve copying and also handle completely missing definitions. */ - if (ctype == NULL) - { - const char *repertoire_name; - - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_CTYPE] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_CTYPE, from->copy_name[LC_CTYPE], - from->repertoire_name, charmap); - while (from->categories[LC_CTYPE].ctype == NULL - && from->copy_name[LC_CTYPE] != NULL); - - ctype = locale->categories[LC_CTYPE].ctype - = from->categories[LC_CTYPE].ctype; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (ctype == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), "LC_CTYPE"); - ctype_startup (NULL, locale, charmap, NULL, 0); - ctype = locale->categories[LC_CTYPE].ctype; - } - - /* Get the repertoire we have to use. */ - repertoire_name = locale->repertoire_name ?: repertoire_global; - if (repertoire_name != NULL) - ctype->repertoire = repertoire_read (repertoire_name); - } - - /* We need the name of the currently used 8-bit character set to - make correct conversion between this 8-bit representation and the - ISO 10646 character set used internally for wide characters. */ - ctype->codeset_name = charmap->code_set_name; - if (ctype->codeset_name == NULL) - { - if (! be_quiet) - error (0, 0, _("No character set name specified in charmap")); - ctype->codeset_name = "//UNKNOWN//"; - } - - /* Set default value for classes not specified. */ - set_class_defaults (ctype, charmap, ctype->repertoire); - - /* Check according to table. */ - for (cnt = 0; cnt < ctype->class_collection_act; ++cnt) - { - uint32_t tmp = ctype->class_collection[cnt]; - - if (tmp != 0) - { - for (cls1 = 0; cls1 < NCLASS; ++cls1) - if ((tmp & _ISwbit (cls1)) != 0) - for (cls2 = 0; cls2 < NCLASS; ++cls2) - if (valid_table[cls1].allow[cls2] != '-') - { - int eq = (tmp & _ISwbit (cls2)) != 0; - switch (valid_table[cls1].allow[cls2]) - { - case 'M': - if (!eq) - { - uint32_t value = ctype->charnames[cnt]; - - if (!be_quiet) - error (0, 0, _("\ -character L'\\u%0*x' in class `%s' must be in class `%s'"), - value > 0xffff ? 8 : 4, value, - valid_table[cls1].name, - valid_table[cls2].name); - } - break; - - case 'X': - if (eq) - { - uint32_t value = ctype->charnames[cnt]; - - if (!be_quiet) - error (0, 0, _("\ -character L'\\u%0*x' in class `%s' must not be in class `%s'"), - value > 0xffff ? 8 : 4, value, - valid_table[cls1].name, - valid_table[cls2].name); - } - break; - - case 'D': - ctype->class_collection[cnt] |= _ISwbit (cls2); - break; - - default: - error (5, 0, _("internal error in %s, line %u"), - __FUNCTION__, __LINE__); - } - } - } - } - - for (cnt = 0; cnt < 256; ++cnt) - { - uint32_t tmp = ctype->class256_collection[cnt]; - - if (tmp != 0) - { - for (cls1 = 0; cls1 < NCLASS; ++cls1) - if ((tmp & _ISbit (cls1)) != 0) - for (cls2 = 0; cls2 < NCLASS; ++cls2) - if (valid_table[cls1].allow[cls2] != '-') - { - int eq = (tmp & _ISbit (cls2)) != 0; - switch (valid_table[cls1].allow[cls2]) - { - case 'M': - if (!eq) - { - char buf[17]; - - snprintf (buf, sizeof buf, "\\%Zo", cnt); - - if (!be_quiet) - error (0, 0, _("\ -character '%s' in class `%s' must be in class `%s'"), - buf, valid_table[cls1].name, - valid_table[cls2].name); - } - break; - - case 'X': - if (eq) - { - char buf[17]; - - snprintf (buf, sizeof buf, "\\%Zo", cnt); - - if (!be_quiet) - error (0, 0, _("\ -character '%s' in class `%s' must not be in class `%s'"), - buf, valid_table[cls1].name, - valid_table[cls2].name); - } - break; - - case 'D': - ctype->class256_collection[cnt] |= _ISbit (cls2); - break; - - default: - error (5, 0, _("internal error in %s, line %u"), - __FUNCTION__, __LINE__); - } - } - } - } - - /* ... and now test as a special case. */ - space_value = 32; - if (((cnt = BITPOS (tok_space), - (ELEM (ctype, class_collection, , space_value) - & BITw (tok_space)) == 0) - || (cnt = BITPOS (tok_blank), - (ELEM (ctype, class_collection, , space_value) - & BITw (tok_blank)) == 0))) - { - if (!be_quiet) - error (0, 0, _(" character not in class `%s'"), - valid_table[cnt].name); - } - else if (((cnt = BITPOS (tok_punct), - (ELEM (ctype, class_collection, , space_value) - & BITw (tok_punct)) != 0) - || (cnt = BITPOS (tok_graph), - (ELEM (ctype, class_collection, , space_value) - & BITw (tok_graph)) - != 0))) - { - if (!be_quiet) - error (0, 0, _(" character must not be in class `%s'"), - valid_table[cnt].name); - } - else - ELEM (ctype, class_collection, , space_value) |= BITw (tok_print); - - space_seq = charmap_find_value (charmap, "SP", 2); - if (space_seq == NULL) - space_seq = charmap_find_value (charmap, "space", 5); - if (space_seq == NULL) - space_seq = charmap_find_value (charmap, "U00000020", 9); - if (space_seq == NULL || space_seq->nbytes != 1) - { - if (!be_quiet) - error (0, 0, _("character not defined in character map")); - } - else if (((cnt = BITPOS (tok_space), - (ctype->class256_collection[space_seq->bytes[0]] - & BIT (tok_space)) == 0) - || (cnt = BITPOS (tok_blank), - (ctype->class256_collection[space_seq->bytes[0]] - & BIT (tok_blank)) == 0))) - { - if (!be_quiet) - error (0, 0, _(" character not in class `%s'"), - valid_table[cnt].name); - } - else if (((cnt = BITPOS (tok_punct), - (ctype->class256_collection[space_seq->bytes[0]] - & BIT (tok_punct)) != 0) - || (cnt = BITPOS (tok_graph), - (ctype->class256_collection[space_seq->bytes[0]] - & BIT (tok_graph)) != 0))) - { - if (!be_quiet) - error (0, 0, _(" character must not be in class `%s'"), - valid_table[cnt].name); - } - else - ctype->class256_collection[space_seq->bytes[0]] |= BIT (tok_print); - - /* Now that the tests are done make sure the name array contains all - characters which are handled in the WIDTH section of the - character set definition file. */ - if (charmap->width_rules != NULL) - for (cnt = 0; cnt < charmap->nwidth_rules; ++cnt) - { - unsigned char bytes[charmap->mb_cur_max]; - int nbytes = charmap->width_rules[cnt].from->nbytes; - - /* We have the range of character for which the width is - specified described using byte sequences of the multibyte - charset. We have to convert this to UCS4 now. And we - cannot simply convert the beginning and the end of the - sequence, we have to iterate over the byte sequence and - convert it for every single character. */ - memcpy (bytes, charmap->width_rules[cnt].from->bytes, nbytes); - - while (nbytes < charmap->width_rules[cnt].to->nbytes - || memcmp (bytes, charmap->width_rules[cnt].to->bytes, - nbytes) <= 0) - { - /* Find the UCS value for `bytes'. */ - int inner; - uint32_t wch; - struct charseq *seq = charmap_find_symbol (charmap, bytes, nbytes); - - if (seq == NULL) - wch = ILLEGAL_CHAR_VALUE; - else if (seq->ucs4 != UNINITIALIZED_CHAR_VALUE) - wch = seq->ucs4; - else - wch = repertoire_find_value (ctype->repertoire, seq->name, - strlen (seq->name)); - - if (wch != ILLEGAL_CHAR_VALUE) - /* We are only interested in the side-effects of the - `find_idx' call. It will add appropriate entries in - the name array if this is necessary. */ - (void) find_idx (ctype, NULL, NULL, NULL, wch); - - /* "Increment" the bytes sequence. */ - inner = nbytes - 1; - while (inner >= 0 && bytes[inner] == 0xff) - --inner; - - if (inner < 0) - { - /* We have to extend the byte sequence. */ - if (nbytes >= charmap->width_rules[cnt].to->nbytes) - break; - - bytes[0] = 1; - memset (&bytes[1], 0, nbytes); - ++nbytes; - } - else - { - ++bytes[inner]; - while (++inner < nbytes) - bytes[inner] = 0; - } - } - } - - /* Now set all the other characters of the character set to the - default width. */ - curs = NULL; - while (iterate_table (&charmap->char_table, &curs, &key, &len, &vdata) == 0) - { - struct charseq *data = (struct charseq *) vdata; - - if (data->ucs4 == UNINITIALIZED_CHAR_VALUE) - data->ucs4 = repertoire_find_value (ctype->repertoire, - data->name, len); - - if (data->ucs4 != ILLEGAL_CHAR_VALUE) - (void) find_idx (ctype, NULL, NULL, NULL, data->ucs4); - } - - /* There must be a multiple of 10 digits. */ - if (ctype->mbdigits_act % 10 != 0) - { - assert (ctype->mbdigits_act == ctype->wcdigits_act); - ctype->wcdigits_act -= ctype->mbdigits_act % 10; - ctype->mbdigits_act -= ctype->mbdigits_act % 10; - error (0, 0, _("`digit' category has not entries in groups of ten")); - } - - /* Check the input digits. There must be a multiple of ten available. - In each group it could be that one or the other character is missing. - In this case the whole group must be removed. */ - cnt = 0; - while (cnt < ctype->mbdigits_act) - { - size_t inner; - for (inner = 0; inner < 10; ++inner) - if (ctype->mbdigits[cnt + inner] == NULL) - break; - - if (inner == 10) - cnt += 10; - else - { - /* Remove the group. */ - memmove (&ctype->mbdigits[cnt], &ctype->mbdigits[cnt + 10], - ((ctype->wcdigits_act - cnt - 10) - * sizeof (ctype->mbdigits[0]))); - ctype->mbdigits_act -= 10; - } - } - - /* If no input digits are given use the default. */ - if (ctype->mbdigits_act == 0) - { - if (ctype->mbdigits_max == 0) - { - ctype->mbdigits = obstack_alloc (&charmap->mem_pool, - 10 * sizeof (struct charseq *)); - ctype->mbdigits_max = 10; - } - - for (cnt = 0; cnt < 10; ++cnt) - { - ctype->mbdigits[cnt] = charmap_find_symbol (charmap, - digits + cnt, 1); - if (ctype->mbdigits[cnt] == NULL) - { - ctype->mbdigits[cnt] = charmap_find_symbol (charmap, - longnames[cnt], - strlen (longnames[cnt])); - if (ctype->mbdigits[cnt] == NULL) - { - /* Hum, this ain't good. */ - error (0, 0, _("\ -no input digits defined and none of the standard names in the charmap")); - - ctype->mbdigits[cnt] = obstack_alloc (&charmap->mem_pool, - sizeof (struct charseq) + 1); - - /* This is better than nothing. */ - ctype->mbdigits[cnt]->bytes[0] = digits[cnt]; - ctype->mbdigits[cnt]->nbytes = 1; - } - } - } - - ctype->mbdigits_act = 10; - } - - /* Check the wide character input digits. There must be a multiple - of ten available. In each group it could be that one or the other - character is missing. In this case the whole group must be - removed. */ - cnt = 0; - while (cnt < ctype->wcdigits_act) - { - size_t inner; - for (inner = 0; inner < 10; ++inner) - if (ctype->wcdigits[cnt + inner] == ILLEGAL_CHAR_VALUE) - break; - - if (inner == 10) - cnt += 10; - else - { - /* Remove the group. */ - memmove (&ctype->wcdigits[cnt], &ctype->wcdigits[cnt + 10], - ((ctype->wcdigits_act - cnt - 10) - * sizeof (ctype->wcdigits[0]))); - ctype->wcdigits_act -= 10; - } - } - - /* If no input digits are given use the default. */ - if (ctype->wcdigits_act == 0) - { - if (ctype->wcdigits_max == 0) - { - ctype->wcdigits = obstack_alloc (&charmap->mem_pool, - 10 * sizeof (uint32_t)); - ctype->wcdigits_max = 10; - } - - for (cnt = 0; cnt < 10; ++cnt) - ctype->wcdigits[cnt] = L'0' + cnt; - - ctype->mbdigits_act = 10; - } - - /* Check the outdigits. */ - warned = 0; - for (cnt = 0; cnt < 10; ++cnt) - if (ctype->mboutdigits[cnt] == NULL) - { - static struct charseq replace[2]; - - if (!warned) - { - error (0, 0, _("\ -not all characters used in `outdigit' are available in the charmap")); - warned = 1; - } - - replace[0].nbytes = 1; - replace[0].bytes[0] = '?'; - replace[0].bytes[1] = '\0'; - ctype->mboutdigits[cnt] = &replace[0]; - } - - warned = 0; - for (cnt = 0; cnt < 10; ++cnt) - if (ctype->wcoutdigits[cnt] == 0) - { - if (!warned) - { - error (0, 0, _("\ -not all characters used in `outdigit' are available in the repertoire")); - warned = 1; - } - - ctype->wcoutdigits[cnt] = L'?'; - } - - /* Sort the entries in the translit_ignore list. */ - if (ctype->translit_ignore != NULL) - { - struct translit_ignore_t *firstp = ctype->translit_ignore; - struct translit_ignore_t *runp; - - ctype->ntranslit_ignore = 1; - - for (runp = firstp->next; runp != NULL; runp = runp->next) - { - struct translit_ignore_t *lastp = NULL; - struct translit_ignore_t *cmpp; - - ++ctype->ntranslit_ignore; - - for (cmpp = firstp; cmpp != NULL; lastp = cmpp, cmpp = cmpp->next) - if (runp->from < cmpp->from) - break; - - runp->next = lastp; - if (lastp == NULL) - firstp = runp; - } - - ctype->translit_ignore = firstp; - } -} - - -void -ctype_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - static const char nulbytes[4] = { 0, 0, 0, 0 }; - struct locale_ctype_t *ctype = locale->categories[LC_CTYPE].ctype; - const size_t nelems = (_NL_ITEM_INDEX (_NL_CTYPE_EXTRA_MAP_1) - + ctype->nr_charclass + ctype->map_collection_nr); - struct iovec iov[2 + nelems + 2 * ctype->nr_charclass - + ctype->map_collection_nr + 4]; - struct locale_file data; - uint32_t idx[nelems + 1]; - uint32_t default_missing_len; - size_t elem, cnt, offset, total; - char *cp; - - /* Now prepare the output: Find the sizes of the table we can use. */ - allocate_arrays (ctype, charmap, ctype->repertoire); - - data.magic = LIMAGIC (LC_CTYPE); - data.n = nelems; - iov[0].iov_base = (void *) &data; - iov[0].iov_len = sizeof (data); - - iov[1].iov_base = (void *) idx; - iov[1].iov_len = nelems * sizeof (uint32_t); - - idx[0] = iov[0].iov_len + iov[1].iov_len; - offset = 0; - - for (elem = 0; elem < nelems; ++elem) - { - if (elem < _NL_ITEM_INDEX (_NL_CTYPE_EXTRA_MAP_1)) - switch (elem) - { -#define CTYPE_EMPTY(name) \ - case name: \ - iov[2 + elem + offset].iov_base = NULL; \ - iov[2 + elem + offset].iov_len = 0; \ - idx[elem + 1] = idx[elem]; \ - break - - CTYPE_EMPTY(_NL_CTYPE_GAP1); - CTYPE_EMPTY(_NL_CTYPE_GAP2); - CTYPE_EMPTY(_NL_CTYPE_GAP3); - CTYPE_EMPTY(_NL_CTYPE_GAP4); - CTYPE_EMPTY(_NL_CTYPE_GAP5); - CTYPE_EMPTY(_NL_CTYPE_GAP6); - -#define CTYPE_DATA(name, base, len) \ - case _NL_ITEM_INDEX (name): \ - iov[2 + elem + offset].iov_base = (base); \ - iov[2 + elem + offset].iov_len = (len); \ - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; \ - break - - CTYPE_DATA (_NL_CTYPE_CLASS, - ctype->ctype_b, - (256 + 128) * sizeof (char_class_t)); - - CTYPE_DATA (_NL_CTYPE_TOUPPER, - ctype->map_b[0], - (256 + 128) * sizeof (uint32_t)); - CTYPE_DATA (_NL_CTYPE_TOLOWER, - ctype->map_b[1], - (256 + 128) * sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_TOUPPER32, - ctype->map32_b[0], - 256 * sizeof (uint32_t)); - CTYPE_DATA (_NL_CTYPE_TOLOWER32, - ctype->map32_b[1], - 256 * sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_CLASS32, - ctype->ctype32_b, - 256 * sizeof (char_class32_t)); - - CTYPE_DATA (_NL_CTYPE_CLASS_OFFSET, - &ctype->class_offset, sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_MAP_OFFSET, - &ctype->map_offset, sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_TRANSLIT_TAB_SIZE, - &ctype->translit_idx_size, sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_TRANSLIT_FROM_IDX, - ctype->translit_from_idx, - ctype->translit_idx_size * sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_TRANSLIT_FROM_TBL, - ctype->translit_from_tbl, - ctype->translit_from_tbl_size); - - CTYPE_DATA (_NL_CTYPE_TRANSLIT_TO_IDX, - ctype->translit_to_idx, - ctype->translit_idx_size * sizeof (uint32_t)); - - CTYPE_DATA (_NL_CTYPE_TRANSLIT_TO_TBL, - ctype->translit_to_tbl, ctype->translit_to_tbl_size); - - case _NL_ITEM_INDEX (_NL_CTYPE_CLASS_NAMES): - /* The class name array. */ - total = 0; - for (cnt = 0; cnt < ctype->nr_charclass; ++cnt, ++offset) - { - iov[2 + elem + offset].iov_base - = (void *) ctype->classnames[cnt]; - iov[2 + elem + offset].iov_len - = strlen (ctype->classnames[cnt]) + 1; - total += iov[2 + elem + offset].iov_len; - } - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = 1 + (4 - ((total + 1) % 4)); - total += 1 + (4 - ((total + 1) % 4)); - - idx[elem + 1] = idx[elem] + total; - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_MAP_NAMES): - /* The class name array. */ - total = 0; - for (cnt = 0; cnt < ctype->map_collection_nr; ++cnt, ++offset) - { - iov[2 + elem + offset].iov_base - = (void *) ctype->mapnames[cnt]; - iov[2 + elem + offset].iov_len - = strlen (ctype->mapnames[cnt]) + 1; - total += iov[2 + elem + offset].iov_len; - } - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = 1 + (4 - ((total + 1) % 4)); - total += 1 + (4 - ((total + 1) % 4)); - - idx[elem + 1] = idx[elem] + total; - break; - - CTYPE_DATA (_NL_CTYPE_WIDTH, - ctype->width.iov_base, - ctype->width.iov_len); - - CTYPE_DATA (_NL_CTYPE_MB_CUR_MAX, - &ctype->mb_cur_max, sizeof (uint32_t)); - - case _NL_ITEM_INDEX (_NL_CTYPE_CODESET_NAME): - total = strlen (ctype->codeset_name) + 1; - if (total % 4 == 0) - iov[2 + elem + offset].iov_base = (char *) ctype->codeset_name; - else - { - iov[2 + elem + offset].iov_base = alloca ((total + 3) & ~3); - memset (mempcpy (iov[2 + elem + offset].iov_base, - ctype->codeset_name, total), - '\0', 4 - (total & 3)); - total = (total + 3) & ~3; - } - iov[2 + elem + offset].iov_len = total; - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS_MB_LEN): - iov[2 + elem + offset].iov_base = alloca (sizeof (uint32_t)); - iov[2 + elem + offset].iov_len = sizeof (uint32_t); - *(uint32_t *) iov[2 + elem + offset].iov_base = - ctype->mbdigits_act / 10; - idx[elem + 1] = idx[elem] + sizeof (uint32_t); - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS_WC_LEN): - /* Align entries. */ - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = (4 - idx[elem] % 4) % 4; - idx[elem] += iov[2 + elem + offset].iov_len; - ++offset; - - iov[2 + elem + offset].iov_base = alloca (sizeof (uint32_t)); - iov[2 + elem + offset].iov_len = sizeof (uint32_t); - *(uint32_t *) iov[2 + elem + offset].iov_base = - ctype->wcdigits_act / 10; - idx[elem + 1] = idx[elem] + sizeof (uint32_t); - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS0_MB) ... _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS9_MB): - /* Compute the length of all possible characters. For INDIGITS - there might be more than one. We simply concatenate all of - them with a NUL byte following. The NUL byte wouldn't be - necessary but it makes it easier for the user. */ - total = 0; - - for (cnt = elem - _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS0_MB); - cnt < ctype->mbdigits_act; cnt += 10) - total += ctype->mbdigits[cnt]->nbytes + 1; - iov[2 + elem + offset].iov_base = (char *) alloca (total); - iov[2 + elem + offset].iov_len = total; - - cp = iov[2 + elem + offset].iov_base; - for (cnt = elem - _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS0_MB); - cnt < ctype->mbdigits_act; cnt += 10) - { - cp = mempcpy (cp, ctype->mbdigits[cnt]->bytes, - ctype->mbdigits[cnt]->nbytes); - *cp++ = '\0'; - } - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT0_MB) ... _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT9_MB): - /* Compute the length of all possible characters. For INDIGITS - there might be more than one. We simply concatenate all of - them with a NUL byte following. The NUL byte wouldn't be - necessary but it makes it easier for the user. */ - cnt = elem - _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT0_MB); - total = ctype->mboutdigits[cnt]->nbytes + 1; - iov[2 + elem + offset].iov_base = (char *) alloca (total); - iov[2 + elem + offset].iov_len = total; - - *(char *) mempcpy (iov[2 + elem + offset].iov_base, - ctype->mboutdigits[cnt]->bytes, - ctype->mboutdigits[cnt]->nbytes) = '\0'; - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS0_WC) ... _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS9_WC): - total = ctype->wcdigits_act / 10; - - iov[2 + elem + offset].iov_base = - (uint32_t *) alloca (total * sizeof (uint32_t)); - iov[2 + elem + offset].iov_len = total * sizeof (uint32_t); - - for (cnt = elem - _NL_ITEM_INDEX (_NL_CTYPE_INDIGITS0_WC); - cnt < ctype->wcdigits_act; cnt += 10) - ((uint32_t *) iov[2 + elem + offset].iov_base)[cnt / 10] - = ctype->wcdigits[cnt]; - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT0_WC): - /* Align entries. */ - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = (4 - idx[elem] % 4) % 4; - idx[elem] += iov[2 + elem + offset].iov_len; - ++offset; - /* FALLTRHOUGH */ - - case _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT1_WC) ... _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT9_WC): - cnt = elem - _NL_ITEM_INDEX (_NL_CTYPE_OUTDIGIT0_WC); - iov[2 + elem + offset].iov_base = &ctype->wcoutdigits[cnt]; - iov[2 + elem + offset].iov_len = sizeof (uint32_t); - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX(_NL_CTYPE_TRANSLIT_DEFAULT_MISSING_LEN): - /* Align entries. */ - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = (4 - idx[elem] % 4) % 4; - idx[elem] += iov[2 + elem + offset].iov_len; - ++offset; - - default_missing_len = (ctype->default_missing - ? wcslen ((wchar_t *)ctype->default_missing) - : 0); - iov[2 + elem + offset].iov_base = &default_missing_len; - iov[2 + elem + offset].iov_len = sizeof (uint32_t); - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX(_NL_CTYPE_TRANSLIT_DEFAULT_MISSING): - iov[2 + elem + offset].iov_base = - ctype->default_missing ?: (uint32_t *) L""; - iov[2 + elem + offset].iov_len = - wcslen (iov[2 + elem + offset].iov_base); - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX(_NL_CTYPE_TRANSLIT_IGNORE_LEN): - /* Align entries. */ - iov[2 + elem + offset].iov_base = (void *) nulbytes; - iov[2 + elem + offset].iov_len = (4 - idx[elem] % 4) % 4; - idx[elem] += iov[2 + elem + offset].iov_len; - ++offset; - - iov[2 + elem + offset].iov_base = &ctype->ntranslit_ignore; - iov[2 + elem + offset].iov_len = sizeof (uint32_t); - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - case _NL_ITEM_INDEX(_NL_CTYPE_TRANSLIT_IGNORE): - { - uint32_t *ranges = (uint32_t *) alloca (ctype->ntranslit_ignore - * 3 * sizeof (uint32_t)); - struct translit_ignore_t *runp; - - iov[2 + elem + offset].iov_base = ranges; - iov[2 + elem + offset].iov_len = (ctype->ntranslit_ignore - * 3 * sizeof (uint32_t)); - - for (runp = ctype->translit_ignore; runp != NULL; - runp = runp->next) - { - *ranges++ = runp->from; - *ranges++ = runp->to; - *ranges++ = runp->step; - } - } - /* Remove the following line in case a new entry is added - after _NL_CTYPE_TRANSLIT_DEFAULT_MISSING_LEN. */ - if (elem < nelems) - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - break; - - default: - assert (! "unknown CTYPE element"); - } - else - { - /* Handle extra maps. */ - size_t nr = elem - _NL_ITEM_INDEX (_NL_CTYPE_EXTRA_MAP_1); - if (nr < ctype->nr_charclass) - { - iov[2 + elem + offset].iov_base = ctype->class_b[nr]; - iov[2 + elem + offset].iov_len = 256 / 32 * sizeof (uint32_t); - idx[elem] += iov[2 + elem + offset].iov_len; - ++offset; - - iov[2 + elem + offset] = ctype->class_3level[nr]; - } - else - { - nr -= ctype->nr_charclass; - assert (nr < ctype->map_collection_nr); - iov[2 + elem + offset] = ctype->map_3level[nr]; - } - idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len; - } - } - - assert (2 + elem + offset == (nelems + 2 * ctype->nr_charclass - + ctype->map_collection_nr + 4 + 2)); - - write_locale_data (output_path, "LC_CTYPE", 2 + elem + offset, iov); -} - - -/* Local functions. */ -static void -ctype_class_new (struct linereader *lr, struct locale_ctype_t *ctype, - const char *name) -{ - size_t cnt; - - for (cnt = 0; cnt < ctype->nr_charclass; ++cnt) - if (strcmp (ctype->classnames[cnt], name) == 0) - break; - - if (cnt < ctype->nr_charclass) - { - lr_error (lr, _("character class `%s' already defined"), name); - return; - } - - if (ctype->nr_charclass == MAX_NR_CHARCLASS) - /* Exit code 2 is prescribed in P1003.2b. */ - error (2, 0, _("\ -implementation limit: no more than %Zd character classes allowed"), - MAX_NR_CHARCLASS); - - ctype->classnames[ctype->nr_charclass++] = name; -} - - -static void -ctype_map_new (struct linereader *lr, struct locale_ctype_t *ctype, - const char *name, struct charmap_t *charmap) -{ - size_t max_chars = 0; - size_t cnt; - - for (cnt = 0; cnt < ctype->map_collection_nr; ++cnt) - { - if (strcmp (ctype->mapnames[cnt], name) == 0) - break; - - if (max_chars < ctype->map_collection_max[cnt]) - max_chars = ctype->map_collection_max[cnt]; - } - - if (cnt < ctype->map_collection_nr) - { - lr_error (lr, _("character map `%s' already defined"), name); - return; - } - - if (ctype->map_collection_nr == MAX_NR_CHARMAP) - /* Exit code 2 is prescribed in P1003.2b. */ - error (2, 0, _("\ -implementation limit: no more than %d character maps allowed"), - MAX_NR_CHARMAP); - - ctype->mapnames[cnt] = name; - - if (max_chars == 0) - ctype->map_collection_max[cnt] = charmap->mb_cur_max == 1 ? 256 : 512; - else - ctype->map_collection_max[cnt] = max_chars; - - ctype->map_collection[cnt] = (uint32_t *) - xcalloc (sizeof (uint32_t), ctype->map_collection_max[cnt]); - ctype->map_collection_act[cnt] = 256; - - ++ctype->map_collection_nr; -} - - -/* We have to be prepared that TABLE, MAX, and ACT can be NULL. This - is possible if we only want to extend the name array. */ -static uint32_t * -find_idx (struct locale_ctype_t *ctype, uint32_t **table, size_t *max, - size_t *act, uint32_t idx) -{ - size_t cnt; - - if (idx < 256) - return table == NULL ? NULL : &(*table)[idx]; - - /* Use the charnames_idx lookup table instead of the slow search loop. */ -#if 1 - cnt = idx_table_get (&ctype->charnames_idx, idx); - if (cnt == EMPTY) - /* Not found. */ - cnt = ctype->charnames_act; -#else - for (cnt = 256; cnt < ctype->charnames_act; ++cnt) - if (ctype->charnames[cnt] == idx) - break; -#endif - - /* We have to distinguish two cases: the name is found or not. */ - if (cnt == ctype->charnames_act) - { - /* Extend the name array. */ - if (ctype->charnames_act == ctype->charnames_max) - { - ctype->charnames_max *= 2; - ctype->charnames = (uint32_t *) - xrealloc (ctype->charnames, - sizeof (uint32_t) * ctype->charnames_max); - } - ctype->charnames[ctype->charnames_act++] = idx; - idx_table_add (&ctype->charnames_idx, idx, cnt); - } - - if (table == NULL) - /* We have done everything we are asked to do. */ - return NULL; - - if (max == NULL) - /* The caller does not want to extend the table. */ - return (cnt >= *act ? NULL : &(*table)[cnt]); - - if (cnt >= *act) - { - if (cnt >= *max) - { - size_t old_max = *max; - do - *max *= 2; - while (*max <= cnt); - - *table = - (uint32_t *) xrealloc (*table, *max * sizeof (uint32_t)); - memset (&(*table)[old_max], '\0', - (*max - old_max) * sizeof (uint32_t)); - } - - *act = cnt + 1; - } - - return &(*table)[cnt]; -} - - -static int -get_character (struct token *now, struct charmap_t *charmap, - struct repertoire_t *repertoire, - struct charseq **seqp, uint32_t *wchp) -{ - if (now->tok == tok_bsymbol) - { - /* This will hopefully be the normal case. */ - *wchp = repertoire_find_value (repertoire, now->val.str.startmb, - now->val.str.lenmb); - *seqp = charmap_find_value (charmap, now->val.str.startmb, - now->val.str.lenmb); - } - else if (now->tok == tok_ucs4) - { - char utmp[10]; - - snprintf (utmp, sizeof (utmp), "U%08X", now->val.ucs4); - *seqp = charmap_find_value (charmap, utmp, 9); - - if (*seqp == NULL) - *seqp = repertoire_find_seq (repertoire, now->val.ucs4); - - if (*seqp == NULL) - { - /* Compute the value in the charmap from the UCS value. */ - const char *symbol = repertoire_find_symbol (repertoire, - now->val.ucs4); - - if (symbol == NULL) - *seqp = NULL; - else - *seqp = charmap_find_value (charmap, symbol, strlen (symbol)); - - if (*seqp == NULL) - { - if (repertoire != NULL) - { - /* Insert a negative entry. */ - static const struct charseq negative - = { .ucs4 = ILLEGAL_CHAR_VALUE }; - uint32_t *newp = obstack_alloc (&repertoire->mem_pool, - sizeof (uint32_t)); - *newp = now->val.ucs4; - - insert_entry (&repertoire->seq_table, newp, - sizeof (uint32_t), (void *) &negative); - } - } - else - (*seqp)->ucs4 = now->val.ucs4; - } - else if ((*seqp)->ucs4 != now->val.ucs4) - *seqp = NULL; - - *wchp = now->val.ucs4; - } - else if (now->tok == tok_charcode) - { - /* We must map from the byte code to UCS4. */ - *seqp = charmap_find_symbol (charmap, now->val.str.startmb, - now->val.str.lenmb); - - if (*seqp == NULL) - *wchp = ILLEGAL_CHAR_VALUE; - else - { - if ((*seqp)->ucs4 == UNINITIALIZED_CHAR_VALUE) - (*seqp)->ucs4 = repertoire_find_value (repertoire, (*seqp)->name, - strlen ((*seqp)->name)); - *wchp = (*seqp)->ucs4; - } - } - else - return 1; - - return 0; -} - - -/* Ellipsis like in `..' or `....' and - the .(2). counterparts. */ -static void -charclass_symbolic_ellipsis (struct linereader *ldfile, - struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire, - struct token *now, - const char *last_str, - unsigned long int class256_bit, - unsigned long int class_bit, int base, - int ignore_content, int handle_digits, int step) -{ - const char *nowstr = now->val.str.startmb; - char tmp[now->val.str.lenmb + 1]; - const char *cp; - char *endp; - unsigned long int from; - unsigned long int to; - - /* We have to compute the ellipsis values using the symbolic names. */ - assert (last_str != NULL); - - if (strlen (last_str) != now->val.str.lenmb) - { - invalid_range: - lr_error (ldfile, - _("`%s' and `%.*s' are no valid names for symbolic range"), - last_str, (int) now->val.str.lenmb, nowstr); - return; - } - - if (memcmp (last_str, nowstr, now->val.str.lenmb) == 0) - /* Nothing to do, the names are the same. */ - return; - - for (cp = last_str; *cp == *(nowstr + (cp - last_str)); ++cp) - ; - - errno = 0; - from = strtoul (cp, &endp, base); - if ((from == UINT_MAX && errno == ERANGE) || *endp != '\0') - goto invalid_range; - - to = strtoul (nowstr + (cp - last_str), &endp, base); - if ((to == UINT_MAX && errno == ERANGE) - || (endp - nowstr) != now->val.str.lenmb || from >= to) - goto invalid_range; - - /* OK, we have a range FROM - TO. Now we can create the symbolic names. */ - if (!ignore_content) - { - now->val.str.startmb = tmp; - while ((from += step) <= to) - { - struct charseq *seq; - uint32_t wch; - - sprintf (tmp, (base == 10 ? "%.*s%0*ld" : "%.*s%0*lX"), - (int) (cp - last_str), last_str, - (int) (now->val.str.lenmb - (cp - last_str)), - from); - - get_character (now, charmap, repertoire, &seq, &wch); - - if (seq != NULL && seq->nbytes == 1) - /* Yep, we can store information about this byte sequence. */ - ctype->class256_collection[seq->bytes[0]] |= class256_bit; - - if (wch != ILLEGAL_CHAR_VALUE && class_bit != 0) - /* We have the UCS4 position. */ - *find_idx (ctype, &ctype->class_collection, - &ctype->class_collection_max, - &ctype->class_collection_act, wch) |= class_bit; - - if (handle_digits == 1) - { - /* We must store the digit values. */ - if (ctype->mbdigits_act == ctype->mbdigits_max) - { - ctype->mbdigits_max *= 2; - ctype->mbdigits = xrealloc (ctype->mbdigits, - (ctype->mbdigits_max - * sizeof (char *))); - ctype->wcdigits_max *= 2; - ctype->wcdigits = xrealloc (ctype->wcdigits, - (ctype->wcdigits_max - * sizeof (uint32_t))); - } - - ctype->mbdigits[ctype->mbdigits_act++] = seq; - ctype->wcdigits[ctype->wcdigits_act++] = wch; - } - else if (handle_digits == 2) - { - /* We must store the digit values. */ - if (ctype->outdigits_act >= 10) - { - lr_error (ldfile, _("\ -%s: field `%s' does not contain exactly ten entries"), - "LC_CTYPE", "outdigit"); - return; - } - - ctype->mboutdigits[ctype->outdigits_act] = seq; - ctype->wcoutdigits[ctype->outdigits_act] = wch; - ++ctype->outdigits_act; - } - } - } -} - - -/* Ellipsis like in `..' or `..(2)..'. */ -static void -charclass_ucs4_ellipsis (struct linereader *ldfile, - struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire, - struct token *now, uint32_t last_wch, - unsigned long int class256_bit, - unsigned long int class_bit, int ignore_content, - int handle_digits, int step) -{ - if (last_wch > now->val.ucs4) - { - lr_error (ldfile, _("\ -to-value of range is smaller than from-value "), - (now->val.ucs4 | last_wch) < 65536 ? 4 : 8, now->val.ucs4, - (now->val.ucs4 | last_wch) < 65536 ? 4 : 8, last_wch); - return; - } - - if (!ignore_content) - while ((last_wch += step) <= now->val.ucs4) - { - /* We have to find out whether there is a byte sequence corresponding - to this UCS4 value. */ - struct charseq *seq; - char utmp[10]; - - snprintf (utmp, sizeof (utmp), "U%08X", last_wch); - seq = charmap_find_value (charmap, utmp, 9); - if (seq == NULL) - { - snprintf (utmp, sizeof (utmp), "U%04X", last_wch); - seq = charmap_find_value (charmap, utmp, 5); - } - - if (seq == NULL) - /* Try looking in the repertoire map. */ - seq = repertoire_find_seq (repertoire, last_wch); - - /* If this is the first time we look for this sequence create a new - entry. */ - if (seq == NULL) - { - static const struct charseq negative - = { .ucs4 = ILLEGAL_CHAR_VALUE }; - - /* Find the symbolic name for this UCS4 value. */ - if (repertoire != NULL) - { - const char *symbol = repertoire_find_symbol (repertoire, - last_wch); - uint32_t *newp = obstack_alloc (&repertoire->mem_pool, - sizeof (uint32_t)); - *newp = last_wch; - - if (symbol != NULL) - /* We have a name, now search the multibyte value. */ - seq = charmap_find_value (charmap, symbol, strlen (symbol)); - - if (seq == NULL) - /* We have to create a fake entry. */ - seq = (struct charseq *) &negative; - else - seq->ucs4 = last_wch; - - insert_entry (&repertoire->seq_table, newp, sizeof (uint32_t), - seq); - } - else - /* We have to create a fake entry. */ - seq = (struct charseq *) &negative; - } - - /* We have a name, now search the multibyte value. */ - if (seq->ucs4 == last_wch && seq->nbytes == 1) - /* Yep, we can store information about this byte sequence. */ - ctype->class256_collection[(size_t) seq->bytes[0]] - |= class256_bit; - - /* And of course we have the UCS4 position. */ - if (class_bit != 0) - *find_idx (ctype, &ctype->class_collection, - &ctype->class_collection_max, - &ctype->class_collection_act, last_wch) |= class_bit; - - if (handle_digits == 1) - { - /* We must store the digit values. */ - if (ctype->mbdigits_act == ctype->mbdigits_max) - { - ctype->mbdigits_max *= 2; - ctype->mbdigits = xrealloc (ctype->mbdigits, - (ctype->mbdigits_max - * sizeof (char *))); - ctype->wcdigits_max *= 2; - ctype->wcdigits = xrealloc (ctype->wcdigits, - (ctype->wcdigits_max - * sizeof (uint32_t))); - } - - ctype->mbdigits[ctype->mbdigits_act++] = (seq->ucs4 == last_wch - ? seq : NULL); - ctype->wcdigits[ctype->wcdigits_act++] = last_wch; - } - else if (handle_digits == 2) - { - /* We must store the digit values. */ - if (ctype->outdigits_act >= 10) - { - lr_error (ldfile, _("\ -%s: field `%s' does not contain exactly ten entries"), - "LC_CTYPE", "outdigit"); - return; - } - - ctype->mboutdigits[ctype->outdigits_act] = (seq->ucs4 == last_wch - ? seq : NULL); - ctype->wcoutdigits[ctype->outdigits_act] = last_wch; - ++ctype->outdigits_act; - } - } -} - - -/* Ellipsis as in `/xea/x12.../xea/x34'. */ -static void -charclass_charcode_ellipsis (struct linereader *ldfile, - struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire, - struct token *now, char *last_charcode, - uint32_t last_charcode_len, - unsigned long int class256_bit, - unsigned long int class_bit, int ignore_content, - int handle_digits) -{ - /* First check whether the to-value is larger. */ - if (now->val.charcode.nbytes != last_charcode_len) - { - lr_error (ldfile, _("\ -start and end character sequence of range must have the same length")); - return; - } - - if (memcmp (last_charcode, now->val.charcode.bytes, last_charcode_len) > 0) - { - lr_error (ldfile, _("\ -to-value character sequence is smaller than from-value sequence")); - return; - } - - if (!ignore_content) - { - do - { - /* Increment the byte sequence value. */ - struct charseq *seq; - uint32_t wch; - int i; - - for (i = last_charcode_len - 1; i >= 0; --i) - if (++last_charcode[i] != 0) - break; - - if (last_charcode_len == 1) - /* Of course we have the charcode value. */ - ctype->class256_collection[(size_t) last_charcode[0]] - |= class256_bit; - - /* Find the symbolic name. */ - seq = charmap_find_symbol (charmap, last_charcode, - last_charcode_len); - if (seq != NULL) - { - if (seq->ucs4 == UNINITIALIZED_CHAR_VALUE) - seq->ucs4 = repertoire_find_value (repertoire, seq->name, - strlen (seq->name)); - wch = seq == NULL ? ILLEGAL_CHAR_VALUE : seq->ucs4; - - if (wch != ILLEGAL_CHAR_VALUE && class_bit != 0) - *find_idx (ctype, &ctype->class_collection, - &ctype->class_collection_max, - &ctype->class_collection_act, wch) |= class_bit; - } - else - wch = ILLEGAL_CHAR_VALUE; - - if (handle_digits == 1) - { - /* We must store the digit values. */ - if (ctype->mbdigits_act == ctype->mbdigits_max) - { - ctype->mbdigits_max *= 2; - ctype->mbdigits = xrealloc (ctype->mbdigits, - (ctype->mbdigits_max - * sizeof (char *))); - ctype->wcdigits_max *= 2; - ctype->wcdigits = xrealloc (ctype->wcdigits, - (ctype->wcdigits_max - * sizeof (uint32_t))); - } - - seq = xmalloc (sizeof (struct charseq) + last_charcode_len); - memcpy ((char *) (seq + 1), last_charcode, last_charcode_len); - seq->nbytes = last_charcode_len; - - ctype->mbdigits[ctype->mbdigits_act++] = seq; - ctype->wcdigits[ctype->wcdigits_act++] = wch; - } - else if (handle_digits == 2) - { - struct charseq *seq; - /* We must store the digit values. */ - if (ctype->outdigits_act >= 10) - { - lr_error (ldfile, _("\ -%s: field `%s' does not contain exactly ten entries"), - "LC_CTYPE", "outdigit"); - return; - } - - seq = xmalloc (sizeof (struct charseq) + last_charcode_len); - memcpy ((char *) (seq + 1), last_charcode, last_charcode_len); - seq->nbytes = last_charcode_len; - - ctype->mboutdigits[ctype->outdigits_act] = seq; - ctype->wcoutdigits[ctype->outdigits_act] = wch; - ++ctype->outdigits_act; - } - } - while (memcmp (last_charcode, now->val.charcode.bytes, - last_charcode_len) != 0); - } -} - - -/* Read one transliteration entry. */ -static uint32_t * -read_widestring (struct linereader *ldfile, struct token *now, - struct charmap_t *charmap, struct repertoire_t *repertoire) -{ - uint32_t *wstr; - - if (now->tok == tok_default_missing) - /* The special name "" will denote this case. */ - wstr = ((uint32_t *) { 0 }); - else if (now->tok == tok_bsymbol) - { - /* Get the value from the repertoire. */ - wstr = (uint32_t *) xmalloc (2 * sizeof (uint32_t)); - wstr[0] = repertoire_find_value (repertoire, now->val.str.startmb, - now->val.str.lenmb); - if (wstr[0] == ILLEGAL_CHAR_VALUE) - { - /* We cannot proceed, we don't know the UCS4 value. */ - free (wstr); - return NULL; - } - - wstr[1] = 0; - } - else if (now->tok == tok_ucs4) - { - wstr = (uint32_t *) xmalloc (2 * sizeof (uint32_t)); - wstr[0] = now->val.ucs4; - wstr[1] = 0; - } - else if (now->tok == tok_charcode) - { - /* Argh, we have to convert to the symbol name first and then to the - UCS4 value. */ - struct charseq *seq = charmap_find_symbol (charmap, - now->val.str.startmb, - now->val.str.lenmb); - if (seq == NULL) - /* Cannot find the UCS4 value. */ - return NULL; - - if (seq->ucs4 == UNINITIALIZED_CHAR_VALUE) - seq->ucs4 = repertoire_find_value (repertoire, seq->name, - strlen (seq->name)); - if (seq->ucs4 == ILLEGAL_CHAR_VALUE) - /* We cannot proceed, we don't know the UCS4 value. */ - return NULL; - - wstr = (uint32_t *) xmalloc (2 * sizeof (uint32_t)); - wstr[0] = seq->ucs4; - wstr[1] = 0; - } - else if (now->tok == tok_string) - { - wstr = now->val.str.startwc; - if (wstr == NULL || wstr[0] == 0) - return NULL; - } - else - { - if (now->tok != tok_eol && now->tok != tok_eof) - lr_ignore_rest (ldfile, 0); - SYNTAX_ERROR (_("%s: syntax error"), "LC_CTYPE"); - return (uint32_t *) -1l; - } - - return wstr; -} - - -static void -read_translit_entry (struct linereader *ldfile, struct locale_ctype_t *ctype, - struct token *now, struct charmap_t *charmap, - struct repertoire_t *repertoire) -{ - uint32_t *from_wstr = read_widestring (ldfile, now, charmap, repertoire); - struct translit_t *result; - struct translit_to_t **top; - struct obstack *ob = &ctype->mempool; - int first; - int ignore; - - if (from_wstr == NULL) - /* There is no valid from string. */ - return; - - result = (struct translit_t *) obstack_alloc (ob, - sizeof (struct translit_t)); - result->from = from_wstr; - result->fname = ldfile->fname; - result->lineno = ldfile->lineno; - result->next = NULL; - result->to = NULL; - top = &result->to; - first = 1; - ignore = 0; - - while (1) - { - uint32_t *to_wstr; - - /* Next we have one or more transliterations. They are - separated by semicolons. */ - now = lr_token (ldfile, charmap, repertoire, verbose); - - if (!first && (now->tok == tok_semicolon || now->tok == tok_eol)) - { - /* One string read. */ - const uint32_t zero = 0; - - if (!ignore) - { - obstack_grow (ob, &zero, 4); - to_wstr = obstack_finish (ob); - - *top = obstack_alloc (ob, sizeof (struct translit_to_t)); - (*top)->str = to_wstr; - (*top)->next = NULL; - } - - if (now->tok == tok_eol) - { - result->next = ctype->translit; - ctype->translit = result; - return; - } - - if (!ignore) - top = &(*top)->next; - ignore = 0; - } - else - { - to_wstr = read_widestring (ldfile, now, charmap, repertoire); - if (to_wstr == (uint32_t *) -1l) - { - /* An error occurred. */ - obstack_free (ob, result); - return; - } - - if (to_wstr == NULL) - ignore = 1; - else - /* This value is usable. */ - obstack_grow (ob, to_wstr, wcslen ((wchar_t *) to_wstr) * 4); - - first = 0; - } - } -} - - -static void -read_translit_ignore_entry (struct linereader *ldfile, - struct locale_ctype_t *ctype, - struct charmap_t *charmap, - struct repertoire_t *repertoire) -{ - /* We expect a semicolon-separated list of characters we ignore. We are - only interested in the wide character definitions. These must be - single characters, possibly defining a range when an ellipsis is used. */ - while (1) - { - struct token *now = lr_token (ldfile, charmap, repertoire, verbose); - struct translit_ignore_t *newp; - uint32_t from; - - if (now->tok == tok_eol || now->tok == tok_eof) - { - lr_error (ldfile, - _("premature end of `translit_ignore' definition")); - return; - } - - if (now->tok != tok_bsymbol && now->tok != tok_ucs4) - { - lr_error (ldfile, _("syntax error")); - lr_ignore_rest (ldfile, 0); - return; - } - - if (now->tok == tok_ucs4) - from = now->val.ucs4; - else - /* Try to get the value. */ - from = repertoire_find_value (repertoire, now->val.str.startmb, - now->val.str.lenmb); - - if (from == ILLEGAL_CHAR_VALUE) - { - lr_error (ldfile, "invalid character name"); - newp = NULL; - } - else - { - newp = (struct translit_ignore_t *) - obstack_alloc (&ctype->mempool, sizeof (struct translit_ignore_t)); - newp->from = from; - newp->to = from; - newp->step = 1; - - newp->next = ctype->translit_ignore; - ctype->translit_ignore = newp; - } - - /* Now we expect either a semicolon, an ellipsis, or the end of the - line. */ - now = lr_token (ldfile, charmap, repertoire, verbose); - - if (now->tok == tok_ellipsis2 || now->tok == tok_ellipsis2_2) - { - /* XXX Should we bother implementing `....'? `...' certainly - will not be implemented. */ - uint32_t to; - int step = now->tok == tok_ellipsis2_2 ? 2 : 1; - - now = lr_token (ldfile, charmap, repertoire, verbose); - - if (now->tok == tok_eol || now->tok == tok_eof) - { - lr_error (ldfile, - _("premature end of `translit_ignore' definition")); - return; - } - - if (now->tok != tok_bsymbol && now->tok != tok_ucs4) - { - lr_error (ldfile, _("syntax error")); - lr_ignore_rest (ldfile, 0); - return; - } - - if (now->tok == tok_ucs4) - to = now->val.ucs4; - else - /* Try to get the value. */ - to = repertoire_find_value (repertoire, now->val.str.startmb, - now->val.str.lenmb); - - if (to == ILLEGAL_CHAR_VALUE) - lr_error (ldfile, "invalid character name"); - else - { - /* Make sure the `to'-value is larger. */ - if (to >= from) - { - newp->to = to; - newp->step = step; - } - else - lr_error (ldfile, _("\ -to-value of range is smaller than from-value "), - (to | from) < 65536 ? 4 : 8, to, - (to | from) < 65536 ? 4 : 8, from); - } - - /* And the next token. */ - now = lr_token (ldfile, charmap, repertoire, verbose); - } - - if (now->tok == tok_eol || now->tok == tok_eof) - /* We are done. */ - return; - - if (now->tok == tok_semicolon) - /* Next round. */ - continue; - - /* If we come here something is wrong. */ - lr_error (ldfile, _("syntax error")); - lr_ignore_rest (ldfile, 0); - return; - } -} - - -/* The parser for the LC_CTYPE section of the locale definition. */ -void -ctype_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_ctype_t *ctype; - struct token *now; - enum token_t nowtok; - size_t cnt; - struct charseq *last_seq; - uint32_t last_wch = 0; - enum token_t last_token; - enum token_t ellipsis_token; - int step; - char last_charcode[16]; - size_t last_charcode_len = 0; - const char *last_str = NULL; - int mapidx; - struct localedef_t *copy_locale = NULL; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_CTYPE' must be free. */ - lr_ignore_rest (ldfile, 1); - - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_string) - { - SYNTAX_ERROR (_("%s: syntax error"), "LC_CTYPE"); - - skip_category: - do - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok != tok_eof && now->tok != tok_end); - - if (now->tok != tok_eof - || (now = lr_token (ldfile, charmap, NULL, verbose), - now->tok == tok_eof)) - lr_error (ldfile, _("%s: premature end of file"), "LC_CTYPE"); - else if (now->tok != tok_lc_ctype) - { - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_CTYPE"); - lr_ignore_rest (ldfile, 0); - } - else - lr_ignore_rest (ldfile, 1); - - return; - } - - if (! ignore_content) - { - /* Get the locale definition. */ - copy_locale = load_locale (LC_CTYPE, now->val.str.startmb, - repertoire_name, charmap, NULL); - if ((copy_locale->avail & CTYPE_LOCALE) == 0) - { - /* Not yet loaded. So do it now. */ - if (locfile_read (copy_locale, charmap) != 0) - goto skip_category; - } - } - - lr_ignore_rest (ldfile, 1); - - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* Prepare the data structures. */ - ctype_startup (ldfile, result, charmap, copy_locale, ignore_content); - ctype = result->categories[LC_CTYPE].ctype; - - /* Remember the repertoire we use. */ - if (!ignore_content) - ctype->repertoire = repertoire; - - while (1) - { - unsigned long int class_bit = 0; - unsigned long int class256_bit = 0; - int handle_digits = 0; - - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { - case tok_charclass: - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok == tok_ident || now->tok == tok_string) - { - ctype_class_new (ldfile, ctype, now->val.str.startmb); - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - break; - now = lr_token (ldfile, charmap, NULL, verbose); - } - if (now->tok != tok_eol) - SYNTAX_ERROR (_("\ -%s: syntax error in definition of new character class"), "LC_CTYPE"); - break; - - case tok_charconv: - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok == tok_ident || now->tok == tok_string) - { - ctype_map_new (ldfile, ctype, now->val.str.startmb, charmap); - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - break; - now = lr_token (ldfile, charmap, NULL, verbose); - } - if (now->tok != tok_eol) - SYNTAX_ERROR (_("\ -%s: syntax error in definition of new character map"), "LC_CTYPE"); - break; - - case tok_class: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - /* We simply forget the `class' keyword and use the following - operand to determine the bit. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_ident || now->tok == tok_string) - { - /* Must can be one of the predefined class names. */ - for (cnt = 0; cnt < ctype->nr_charclass; ++cnt) - if (strcmp (ctype->classnames[cnt], now->val.str.startmb) == 0) - break; - if (cnt >= ctype->nr_charclass) - { -#ifdef PREDEFINED_CLASSES - if (now->val.str.lenmb == 8 - && memcmp ("special1", now->val.str.startmb, 8) == 0) - class_bit = _ISwspecial1; - else if (now->val.str.lenmb == 8 - && memcmp ("special2", now->val.str.startmb, 8) == 0) - class_bit = _ISwspecial2; - else if (now->val.str.lenmb == 8 - && memcmp ("special3", now->val.str.startmb, 8) == 0) - class_bit = _ISwspecial3; - else -#endif - { - /* OK, it's a new class. */ - ctype_class_new (ldfile, ctype, now->val.str.startmb); - - class_bit = _ISwbit (ctype->nr_charclass - 1); - } - } - else - { - class_bit = _ISwbit (cnt); - - free (now->val.str.startmb); - } - } - else if (now->tok == tok_digit) - goto handle_tok_digit; - else if (now->tok < tok_upper || now->tok > tok_blank) - goto err_label; - else - { - class_bit = BITw (now->tok); - class256_bit = BIT (now->tok); - } - - /* The next character must be a semicolon. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - goto err_label; - goto read_charclass; - - case tok_upper: - case tok_lower: - case tok_alpha: - case tok_alnum: - case tok_space: - case tok_cntrl: - case tok_punct: - case tok_graph: - case tok_print: - case tok_xdigit: - case tok_blank: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - class_bit = BITw (now->tok); - class256_bit = BIT (now->tok); - handle_digits = 0; - read_charclass: - ctype->class_done |= class_bit; - last_token = tok_none; - ellipsis_token = tok_none; - step = 1; - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok != tok_eol && now->tok != tok_eof) - { - uint32_t wch; - struct charseq *seq; - - if (ellipsis_token == tok_none) - { - if (get_character (now, charmap, repertoire, &seq, &wch)) - goto err_label; - - if (!ignore_content && seq != NULL && seq->nbytes == 1) - /* Yep, we can store information about this byte - sequence. */ - ctype->class256_collection[seq->bytes[0]] |= class256_bit; - - if (!ignore_content && wch != ILLEGAL_CHAR_VALUE - && class_bit != 0) - /* We have the UCS4 position. */ - *find_idx (ctype, &ctype->class_collection, - &ctype->class_collection_max, - &ctype->class_collection_act, wch) |= class_bit; - - last_token = now->tok; - /* Terminate the string. */ - if (last_token == tok_bsymbol) - { - now->val.str.startmb[now->val.str.lenmb] = '\0'; - last_str = now->val.str.startmb; - } - else - last_str = NULL; - last_seq = seq; - last_wch = wch; - memcpy (last_charcode, now->val.charcode.bytes, 16); - last_charcode_len = now->val.charcode.nbytes; - - if (!ignore_content && handle_digits == 1) - { - /* We must store the digit values. */ - if (ctype->mbdigits_act == ctype->mbdigits_max) - { - ctype->mbdigits_max += 10; - ctype->mbdigits = xrealloc (ctype->mbdigits, - (ctype->mbdigits_max - * sizeof (char *))); - ctype->wcdigits_max += 10; - ctype->wcdigits = xrealloc (ctype->wcdigits, - (ctype->wcdigits_max - * sizeof (uint32_t))); - } - - ctype->mbdigits[ctype->mbdigits_act++] = seq; - ctype->wcdigits[ctype->wcdigits_act++] = wch; - } - else if (!ignore_content && handle_digits == 2) - { - /* We must store the digit values. */ - if (ctype->outdigits_act >= 10) - { - lr_error (ldfile, _("\ -%s: field `%s' does not contain exactly ten entries"), - "LC_CTYPE", "outdigit"); - lr_ignore_rest (ldfile, 0); - break; - } - - ctype->mboutdigits[ctype->outdigits_act] = seq; - ctype->wcoutdigits[ctype->outdigits_act] = wch; - ++ctype->outdigits_act; - } - } - else - { - /* Now it gets complicated. We have to resolve the - ellipsis problem. First we must distinguish between - the different kind of ellipsis and this must match the - tokens we have seen. */ - assert (last_token != tok_none); - - if (last_token != now->tok) - { - lr_error (ldfile, _("\ -ellipsis range must be marked by two operands of same type")); - lr_ignore_rest (ldfile, 0); - break; - } - - if (last_token == tok_bsymbol) - { - if (ellipsis_token == tok_ellipsis3) - lr_error (ldfile, _("with symbolic name range values \ -the absolute ellipsis `...' must not be used")); - - charclass_symbolic_ellipsis (ldfile, ctype, charmap, - repertoire, now, last_str, - class256_bit, class_bit, - (ellipsis_token - == tok_ellipsis4 - ? 10 : 16), - ignore_content, - handle_digits, step); - } - else if (last_token == tok_ucs4) - { - if (ellipsis_token != tok_ellipsis2) - lr_error (ldfile, _("\ -with UCS range values one must use the hexadecimal symbolic ellipsis `..'")); - - charclass_ucs4_ellipsis (ldfile, ctype, charmap, - repertoire, now, last_wch, - class256_bit, class_bit, - ignore_content, handle_digits, - step); - } - else - { - assert (last_token == tok_charcode); - - if (ellipsis_token != tok_ellipsis3) - lr_error (ldfile, _("\ -with character code range values one must use the absolute ellipsis `...'")); - - charclass_charcode_ellipsis (ldfile, ctype, charmap, - repertoire, now, - last_charcode, - last_charcode_len, - class256_bit, class_bit, - ignore_content, - handle_digits); - } - - /* Now we have used the last value. */ - last_token = tok_none; - } - - /* Next we expect a semicolon or the end of the line. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_eol || now->tok == tok_eof) - break; - - if (last_token != tok_none - && now->tok >= tok_ellipsis2 && now->tok <= tok_ellipsis4_2) - { - if (now->tok == tok_ellipsis2_2) - { - now->tok = tok_ellipsis2; - step = 2; - } - else if (now->tok == tok_ellipsis4_2) - { - now->tok = tok_ellipsis4; - step = 2; - } - - ellipsis_token = now->tok; - - now = lr_token (ldfile, charmap, NULL, verbose); - continue; - } - - if (now->tok != tok_semicolon) - goto err_label; - - /* And get the next character. */ - now = lr_token (ldfile, charmap, NULL, verbose); - - ellipsis_token = tok_none; - step = 1; - } - break; - - case tok_digit: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - handle_tok_digit: - class_bit = _ISwdigit; - class256_bit = _ISdigit; - handle_digits = 1; - goto read_charclass; - - case tok_outdigit: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - if (ctype->outdigits_act != 0) - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), - "LC_CTYPE", "outdigit"); - class_bit = 0; - class256_bit = 0; - handle_digits = 2; - goto read_charclass; - - case tok_toupper: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - mapidx = 0; - goto read_mapping; - - case tok_tolower: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - mapidx = 1; - goto read_mapping; - - case tok_map: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - /* We simply forget the `map' keyword and use the following - operand to determine the mapping. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_ident || now->tok == tok_string) - { - size_t cnt; - - for (cnt = 2; cnt < ctype->map_collection_nr; ++cnt) - if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0) - break; - - if (cnt < ctype->map_collection_nr) - free (now->val.str.startmb); - else - /* OK, it's a new map. */ - ctype_map_new (ldfile, ctype, now->val.str.startmb, charmap); - - mapidx = cnt; - } - else if (now->tok < tok_toupper || now->tok > tok_tolower) - goto err_label; - else - mapidx = now->tok - tok_toupper; - - now = lr_token (ldfile, charmap, NULL, verbose); - /* This better should be a semicolon. */ - if (now->tok != tok_semicolon) - goto err_label; - - read_mapping: - /* Test whether this mapping was already defined. */ - if (ctype->tomap_done[mapidx]) - { - lr_error (ldfile, _("duplicated definition for mapping `%s'"), - ctype->mapnames[mapidx]); - lr_ignore_rest (ldfile, 0); - break; - } - ctype->tomap_done[mapidx] = 1; - - now = lr_token (ldfile, charmap, NULL, verbose); - while (now->tok != tok_eol && now->tok != tok_eof) - { - struct charseq *from_seq; - uint32_t from_wch; - struct charseq *to_seq; - uint32_t to_wch; - - /* Every pair starts with an opening brace. */ - if (now->tok != tok_open_brace) - goto err_label; - - /* Next comes the from-value. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (get_character (now, charmap, repertoire, &from_seq, - &from_wch) != 0) - goto err_label; - - /* The next is a comma. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_comma) - goto err_label; - - /* And the other value. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (get_character (now, charmap, repertoire, &to_seq, - &to_wch) != 0) - goto err_label; - - /* And the last thing is the closing brace. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_close_brace) - goto err_label; - - if (!ignore_content) - { - if (mapidx < 2 && from_seq != NULL && to_seq != NULL - && from_seq->nbytes == 1 && to_seq->nbytes == 1) - /* We can use this value. */ - ctype->map256_collection[mapidx][from_seq->bytes[0]] - = to_seq->bytes[0]; - - if (from_wch != ILLEGAL_CHAR_VALUE - && to_wch != ILLEGAL_CHAR_VALUE) - /* Both correct values. */ - *find_idx (ctype, &ctype->map_collection[mapidx], - &ctype->map_collection_max[mapidx], - &ctype->map_collection_act[mapidx], - from_wch) = to_wch; - } - - /* Now comes a semicolon or the end of the line/file. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_semicolon) - now = lr_token (ldfile, charmap, NULL, verbose); - } - break; - - case tok_translit_start: - /* Ignore the entire translit section with its peculiar syntax - if we don't need the input. */ - if (ignore_content) - { - do - { - lr_ignore_rest (ldfile, 0); - now = lr_token (ldfile, charmap, NULL, verbose); - } - while (now->tok != tok_translit_end && now->tok != tok_eof); - - if (now->tok == tok_eof) - lr_error (ldfile, _(\ -"%s: `translit_start' section does not end with `translit_end'"), - "LC_CTYPE"); - - break; - } - - /* The rest of the line better should be empty. */ - lr_ignore_rest (ldfile, 1); - - /* We count here the number of allocated entries in the `translit' - array. */ - cnt = 0; - - ldfile->translate_strings = 1; - ldfile->return_widestr = 1; - - /* We proceed until we see the `translit_end' token. */ - while (now = lr_token (ldfile, charmap, repertoire, verbose), - now->tok != tok_translit_end && now->tok != tok_eof) - { - if (now->tok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (now->tok == tok_include) - { - /* We have to include locale. */ - const char *locale_name; - const char *repertoire_name; - struct translit_include_t *include_stmt, **include_ptr; - - now = lr_token (ldfile, charmap, NULL, verbose); - /* This should be a string or an identifier. In any - case something to name a locale. */ - if (now->tok != tok_string && now->tok != tok_ident) - { - translit_syntax: - lr_error (ldfile, _("%s: syntax error"), "LC_CTYPE"); - lr_ignore_rest (ldfile, 0); - continue; - } - locale_name = now->val.str.startmb; - - /* Next should be a semicolon. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - goto translit_syntax; - - /* Now the repertoire name. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if ((now->tok != tok_string && now->tok != tok_ident) - || now->val.str.startmb == NULL) - goto translit_syntax; - repertoire_name = now->val.str.startmb; - - /* Save the include statement for later processing. */ - include_stmt = (struct translit_include_t *) - xmalloc (sizeof (struct translit_include_t)); - include_stmt->copy_locale = locale_name; - include_stmt->copy_repertoire = repertoire_name; - include_stmt->next = NULL; - - include_ptr = &ctype->translit_include; - while (*include_ptr != NULL) - include_ptr = &(*include_ptr)->next; - *include_ptr = include_stmt; - - /* The rest of the line must be empty. */ - lr_ignore_rest (ldfile, 1); - - /* Make sure the locale is read. */ - add_to_readlist (LC_CTYPE, locale_name, repertoire_name, - 1, NULL); - continue; - } - else if (now->tok == tok_default_missing) - { - uint32_t *wstr; - - while (1) - { - /* We expect a single character or string as the - argument. */ - now = lr_token (ldfile, charmap, NULL, verbose); - wstr = read_widestring (ldfile, now, charmap, - repertoire); - - if (wstr != NULL) - { - if (ctype->default_missing != NULL) - { - lr_error (ldfile, _("\ -%s: duplicate `default_missing' definition"), "LC_CTYPE"); - error_at_line (0, 0, ctype->default_missing_file, - ctype->default_missing_lineno, - _("\ -previous definition was here")); - } - else - { - ctype->default_missing = wstr; - ctype->default_missing_file = ldfile->fname; - ctype->default_missing_lineno = ldfile->lineno; - } - /* We can have more entries, ignore them. */ - lr_ignore_rest (ldfile, 0); - break; - } - else if (wstr == (uint32_t *) -1l) - /* This was an syntax error. */ - break; - - /* Maybe there is another replacement we can use. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_eol || now->tok == tok_eof) - { - /* Nothing found. We tell the user. */ - lr_error (ldfile, _("\ -%s: no representable `default_missing' definition found"), "LC_CTYPE"); - break; - } - if (now->tok != tok_semicolon) - goto translit_syntax; - } - - continue; - } - else if (now->tok == tok_translit_ignore) - { - read_translit_ignore_entry (ldfile, ctype, charmap, - repertoire); - continue; - } - - read_translit_entry (ldfile, ctype, now, charmap, repertoire); - } - ldfile->return_widestr = 0; - - if (now->tok == tok_eof) - lr_error (ldfile, _(\ -"%s: `translit_start' section does not end with `translit_end'"), - "LC_CTYPE"); - - break; - - case tok_ident: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - /* This could mean one of several things. First test whether - it's a character class name. */ - for (cnt = 0; cnt < ctype->nr_charclass; ++cnt) - if (strcmp (now->val.str.startmb, ctype->classnames[cnt]) == 0) - break; - if (cnt < ctype->nr_charclass) - { - class_bit = _ISwbit (cnt); - class256_bit = cnt <= 11 ? _ISbit (cnt) : 0; - free (now->val.str.startmb); - goto read_charclass; - } - for (cnt = 0; cnt < ctype->map_collection_nr; ++cnt) - if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0) - break; - if (cnt < ctype->map_collection_nr) - { - mapidx = cnt; - free (now->val.str.startmb); - goto read_mapping; - } -#ifdef PREDEFINED_CLASSES - if (strcmp (now->val.str.startmb, "special1") == 0) - { - class_bit = _ISwspecial1; - free (now->val.str.startmb); - goto read_charclass; - } - if (strcmp (now->val.str.startmb, "special2") == 0) - { - class_bit = _ISwspecial2; - free (now->val.str.startmb); - goto read_charclass; - } - if (strcmp (now->val.str.startmb, "special3") == 0) - { - class_bit = _ISwspecial3; - free (now->val.str.startmb); - goto read_charclass; - } - if (strcmp (now->val.str.startmb, "tosymmetric") == 0) - { - mapidx = 2; - goto read_mapping; - } -#endif - break; - - case tok_end: - /* Next we assume `LC_CTYPE'. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_eof) - break; - if (now->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), - "LC_CTYPE"); - else if (now->tok != tok_lc_ctype) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_CTYPE"); - lr_ignore_rest (ldfile, now->tok == tok_lc_ctype); - return; - - default: - err_label: - if (now->tok != tok_eof) - SYNTAX_ERROR (_("%s: syntax error"), "LC_CTYPE"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_CTYPE"); -} - - -static void -set_class_defaults (struct locale_ctype_t *ctype, struct charmap_t *charmap, - struct repertoire_t *repertoire) -{ - size_t cnt; - - /* These function defines the default values for the classes and conversions - according to POSIX.2 2.5.2.1. - It may seem that the order of these if-blocks is arbitrary but it is NOT. - Don't move them unless you know what you do! */ - - auto void set_default (int bitpos, int from, int to); - - void set_default (int bitpos, int from, int to) - { - char tmp[2]; - int ch; - int bit = _ISbit (bitpos); - int bitw = _ISwbit (bitpos); - /* Define string. */ - strcpy (tmp, "?"); - - for (ch = from; ch <= to; ++ch) - { - struct charseq *seq; - tmp[0] = ch; - - seq = charmap_find_value (charmap, tmp, 1); - if (seq == NULL) - { - char buf[10]; - sprintf (buf, "U%08X", ch); - seq = charmap_find_value (charmap, buf, 9); - } - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined in charmap while needed as default value"), - "LC_CTYPE", tmp); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", tmp); - else - ctype->class256_collection[seq->bytes[0]] |= bit; - - /* No need to search here, the ASCII value is also the Unicode - value. */ - ELEM (ctype, class_collection, , ch) |= bitw; - } - } - - /* Set default values if keyword was not present. */ - if ((ctype->class_done & BITw (tok_upper)) == 0) - /* "If this keyword [lower] is not specified, the lowercase letters - `A' through `Z', ..., shall automatically belong to this class, - with implementation defined character values." [P1003.2, 2.5.2.1] */ - set_default (BITPOS (tok_upper), 'A', 'Z'); - - if ((ctype->class_done & BITw (tok_lower)) == 0) - /* "If this keyword [lower] is not specified, the lowercase letters - `a' through `z', ..., shall automatically belong to this class, - with implementation defined character values." [P1003.2, 2.5.2.1] */ - set_default (BITPOS (tok_lower), 'a', 'z'); - - if ((ctype->class_done & BITw (tok_alpha)) == 0) - { - /* Table 2-6 in P1003.2 says that characters in class `upper' or - class `lower' *must* be in class `alpha'. */ - unsigned long int mask = BIT (tok_upper) | BIT (tok_lower); - unsigned long int maskw = BITw (tok_upper) | BITw (tok_lower); - - for (cnt = 0; cnt < 256; ++cnt) - if ((ctype->class256_collection[cnt] & mask) != 0) - ctype->class256_collection[cnt] |= BIT (tok_alpha); - - for (cnt = 0; cnt < ctype->class_collection_act; ++cnt) - if ((ctype->class_collection[cnt] & maskw) != 0) - ctype->class_collection[cnt] |= BITw (tok_alpha); - } - - if ((ctype->class_done & BITw (tok_digit)) == 0) - /* "If this keyword [digit] is not specified, the digits `0' through - `9', ..., shall automatically belong to this class, with - implementation-defined character values." [P1003.2, 2.5.2.1] */ - set_default (BITPOS (tok_digit), '0', '9'); - - /* "Only characters specified for the `alpha' and `digit' keyword - shall be specified. Characters specified for the keyword `alpha' - and `digit' are automatically included in this class. */ - { - unsigned long int mask = BIT (tok_alpha) | BIT (tok_digit); - unsigned long int maskw = BITw (tok_alpha) | BITw (tok_digit); - - for (cnt = 0; cnt < 256; ++cnt) - if ((ctype->class256_collection[cnt] & mask) != 0) - ctype->class256_collection[cnt] |= BIT (tok_alnum); - - for (cnt = 0; cnt < ctype->class_collection_act; ++cnt) - if ((ctype->class_collection[cnt] & maskw) != 0) - ctype->class_collection[cnt] |= BITw (tok_alnum); - } - - if ((ctype->class_done & BITw (tok_space)) == 0) - /* "If this keyword [space] is not specified, the characters , - , , , , and - , ..., shall automatically belong to this class, - with implementation-defined character values." [P1003.2, 2.5.2.1] */ - { - struct charseq *seq; - - seq = charmap_find_value (charmap, "space", 5); - if (seq == NULL) - seq = charmap_find_value (charmap, "SP", 2); - if (seq == NULL) - seq = charmap_find_value (charmap, "U00000020", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L' ') |= BITw (tok_space); - - seq = charmap_find_value (charmap, "form-feed", 9); - if (seq == NULL) - seq = charmap_find_value (charmap, "U0000000C", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\f') |= BITw (tok_space); - - - seq = charmap_find_value (charmap, "newline", 7); - if (seq == NULL) - seq = charmap_find_value (charmap, "U0000000A", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -character `%s' not defined while needed as default value"), - ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\n') |= BITw (tok_space); - - - seq = charmap_find_value (charmap, "carriage-return", 15); - if (seq == NULL) - seq = charmap_find_value (charmap, "U0000000D", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\r') |= BITw (tok_space); - - - seq = charmap_find_value (charmap, "tab", 3); - if (seq == NULL) - seq = charmap_find_value (charmap, "U00000009", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\t') |= BITw (tok_space); - - - seq = charmap_find_value (charmap, "vertical-tab", 12); - if (seq == NULL) - seq = charmap_find_value (charmap, "U0000000B", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_space); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\v') |= BITw (tok_space); - } - - if ((ctype->class_done & BITw (tok_xdigit)) == 0) - /* "If this keyword is not specified, the digits `0' to `9', the - uppercase letters `A' through `F', and the lowercase letters `a' - through `f', ..., shell automatically belong to this class, with - implementation defined character values." [P1003.2, 2.5.2.1] */ - { - set_default (BITPOS (tok_xdigit), '0', '9'); - set_default (BITPOS (tok_xdigit), 'A', 'F'); - set_default (BITPOS (tok_xdigit), 'a', 'f'); - } - - if ((ctype->class_done & BITw (tok_blank)) == 0) - /* "If this keyword [blank] is unspecified, the characters and - shall belong to this character class." [P1003.2, 2.5.2.1] */ - { - struct charseq *seq; - - seq = charmap_find_value (charmap, "space", 5); - if (seq == NULL) - seq = charmap_find_value (charmap, "SP", 2); - if (seq == NULL) - seq = charmap_find_value (charmap, "U00000020", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_blank); - - /* No need to search. */ - ELEM (ctype, class_collection, , L' ') |= BITw (tok_blank); - - - seq = charmap_find_value (charmap, "tab", 3); - if (seq == NULL) - seq = charmap_find_value (charmap, "U00000009", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_blank); - - /* No need to search. */ - ELEM (ctype, class_collection, , L'\t') |= BITw (tok_blank); - } - - if ((ctype->class_done & BITw (tok_graph)) == 0) - /* "If this keyword [graph] is not specified, characters specified for - the keywords `upper', `lower', `alpha', `digit', `xdigit' and `punct', - shall belong to this character class." [P1003.2, 2.5.2.1] */ - { - unsigned long int mask = BIT (tok_upper) | BIT (tok_lower) | - BIT (tok_alpha) | BIT (tok_digit) | BIT (tok_xdigit) | BIT (tok_punct); - unsigned long int maskw = BITw (tok_upper) | BITw (tok_lower) | - BITw (tok_alpha) | BITw (tok_digit) | BITw (tok_xdigit) | - BITw (tok_punct); - size_t cnt; - - for (cnt = 0; cnt < ctype->class_collection_act; ++cnt) - if ((ctype->class_collection[cnt] & maskw) != 0) - ctype->class_collection[cnt] |= BITw (tok_graph); - - for (cnt = 0; cnt < 256; ++cnt) - if ((ctype->class256_collection[cnt] & mask) != 0) - ctype->class256_collection[cnt] |= BIT (tok_graph); - } - - if ((ctype->class_done & BITw (tok_print)) == 0) - /* "If this keyword [print] is not provided, characters specified for - the keywords `upper', `lower', `alpha', `digit', `xdigit', `punct', - and the character shall belong to this character class." - [P1003.2, 2.5.2.1] */ - { - unsigned long int mask = BIT (tok_upper) | BIT (tok_lower) | - BIT (tok_alpha) | BIT (tok_digit) | BIT (tok_xdigit) | BIT (tok_punct); - unsigned long int maskw = BITw (tok_upper) | BITw (tok_lower) | - BITw (tok_alpha) | BITw (tok_digit) | BITw (tok_xdigit) | - BITw (tok_punct); - size_t cnt; - struct charseq *seq; - - for (cnt = 0; cnt < ctype->class_collection_act; ++cnt) - if ((ctype->class_collection[cnt] & maskw) != 0) - ctype->class_collection[cnt] |= BITw (tok_print); - - for (cnt = 0; cnt < 256; ++cnt) - if ((ctype->class256_collection[cnt] & mask) != 0) - ctype->class256_collection[cnt] |= BIT (tok_print); - - - seq = charmap_find_value (charmap, "space", 5); - if (seq == NULL) - seq = charmap_find_value (charmap, "SP", 2); - if (seq == NULL) - seq = charmap_find_value (charmap, "U00000020", 9); - if (seq == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", ""); - } - else if (seq->nbytes != 1) - error (0, 0, _("\ -%s: character `%s' in charmap not representable with one byte"), - "LC_CTYPE", ""); - else - ctype->class256_collection[seq->bytes[0]] |= BIT (tok_print); - - /* No need to search. */ - ELEM (ctype, class_collection, , L' ') |= BITw (tok_print); - } - - if (ctype->tomap_done[0] == 0) - /* "If this keyword [toupper] is not specified, the lowercase letters - `a' through `z', and their corresponding uppercase letters `A' to - `Z', ..., shall automatically be included, with implementation- - defined character values." [P1003.2, 2.5.2.1] */ - { - char tmp[4]; - int ch; - - strcpy (tmp, ""); - - for (ch = 'a'; ch <= 'z'; ++ch) - { - struct charseq *seq_from, *seq_to; - - tmp[1] = (char) ch; - - seq_from = charmap_find_value (charmap, &tmp[1], 1); - if (seq_from == NULL) - { - char buf[10]; - sprintf (buf, "U%08X", ch); - seq_from = charmap_find_value (charmap, buf, 9); - } - if (seq_from == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", tmp); - } - else if (seq_from->nbytes != 1) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' needed as default value not representable with one byte"), - "LC_CTYPE", tmp); - } - else - { - /* This conversion is implementation defined. */ - tmp[1] = (char) (ch + ('A' - 'a')); - seq_to = charmap_find_value (charmap, &tmp[1], 1); - if (seq_to == NULL) - { - char buf[10]; - sprintf (buf, "U%08X", ch + ('A' - 'a')); - seq_to = charmap_find_value (charmap, buf, 9); - } - if (seq_to == NULL) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' not defined while needed as default value"), - "LC_CTYPE", tmp); - } - else if (seq_to->nbytes != 1) - { - if (!be_quiet) - error (0, 0, _("\ -%s: character `%s' needed as default value not representable with one byte"), - "LC_CTYPE", tmp); - } - else - /* The index [0] is determined by the order of the - `ctype_map_newP' calls in `ctype_startup'. */ - ctype->map256_collection[0][seq_from->bytes[0]] - = seq_to->bytes[0]; - } - - /* No need to search. */ - ELEM (ctype, map_collection, [0], ch) = ch + ('A' - 'a'); - } - } - - if (ctype->tomap_done[1] == 0) - /* "If this keyword [tolower] is not specified, the mapping shall be - the reverse mapping of the one specified to `toupper'." [P1003.2] */ - { - for (cnt = 0; cnt < ctype->map_collection_act[0]; ++cnt) - if (ctype->map_collection[0][cnt] != 0) - ELEM (ctype, map_collection, [1], - ctype->map_collection[0][cnt]) - = ctype->charnames[cnt]; - - for (cnt = 0; cnt < 256; ++cnt) - if (ctype->map256_collection[0][cnt] != 0) - ctype->map256_collection[1][ctype->map256_collection[0][cnt]] = cnt; - } - - if (ctype->outdigits_act != 10) - { - if (ctype->outdigits_act != 0) - error (0,0, _("%s: field `%s' does not contain exactly ten entries"), - "LC_CTYPE", "outdigit"); - - for (cnt = ctype->outdigits_act; cnt < 10; ++cnt) - { - ctype->mboutdigits[cnt] = charmap_find_symbol (charmap, - digits + cnt, 1); - - if (ctype->mboutdigits[cnt] == NULL) - ctype->mboutdigits[cnt] = charmap_find_symbol (charmap, - longnames[cnt], - strlen (longnames[cnt])); - - if (ctype->mboutdigits[cnt] == NULL) - ctype->mboutdigits[cnt] = charmap_find_symbol (charmap, - uninames[cnt], 9); - - if (ctype->mboutdigits[cnt] == NULL) - { - /* Provide a replacement. */ - error (0, 0, _("\ -no output digits defined and none of the standard names in the charmap")); - - ctype->mboutdigits[cnt] = obstack_alloc (&charmap->mem_pool, - sizeof (struct charseq) - + 1); - - /* This is better than nothing. */ - ctype->mboutdigits[cnt]->bytes[0] = digits[cnt]; - ctype->mboutdigits[cnt]->nbytes = 1; - } - - ctype->wcoutdigits[cnt] = L'0' + cnt; - } - - ctype->outdigits_act = 10; - } -} - - -/* Construction of sparse 3-level tables. - See wchar-lookup.h for their structure and the meaning of p and q. */ - -struct wctype_table -{ - /* Parameters. */ - unsigned int p; - unsigned int q; - /* Working representation. */ - size_t level1_alloc; - size_t level1_size; - uint32_t *level1; - size_t level2_alloc; - size_t level2_size; - uint32_t *level2; - size_t level3_alloc; - size_t level3_size; - uint32_t *level3; - /* Compressed representation. */ - size_t result_size; - char *result; -}; - -/* Initialize. Assumes t->p and t->q have already been set. */ -static inline void -wctype_table_init (struct wctype_table *t) -{ - t->level1 = NULL; - t->level1_alloc = t->level1_size = 0; - t->level2 = NULL; - t->level2_alloc = t->level2_size = 0; - t->level3 = NULL; - t->level3_alloc = t->level3_size = 0; -} - -/* Retrieve an entry. */ -static inline int -wctype_table_get (struct wctype_table *t, uint32_t wc) -{ - uint32_t index1 = wc >> (t->q + t->p + 5); - if (index1 < t->level1_size) - { - uint32_t lookup1 = t->level1[index1]; - if (lookup1 != EMPTY) - { - uint32_t index2 = ((wc >> (t->p + 5)) & ((1 << t->q) - 1)) - + (lookup1 << t->q); - uint32_t lookup2 = t->level2[index2]; - if (lookup2 != EMPTY) - { - uint32_t index3 = ((wc >> 5) & ((1 << t->p) - 1)) - + (lookup2 << t->p); - uint32_t lookup3 = t->level3[index3]; - uint32_t index4 = wc & 0x1f; - - return (lookup3 >> index4) & 1; - } - } - } - return 0; -} - -/* Add one entry. */ -static void -wctype_table_add (struct wctype_table *t, uint32_t wc) -{ - uint32_t index1 = wc >> (t->q + t->p + 5); - uint32_t index2 = (wc >> (t->p + 5)) & ((1 << t->q) - 1); - uint32_t index3 = (wc >> 5) & ((1 << t->p) - 1); - uint32_t index4 = wc & 0x1f; - size_t i, i1, i2; - - if (index1 >= t->level1_size) - { - if (index1 >= t->level1_alloc) - { - size_t alloc = 2 * t->level1_alloc; - if (alloc <= index1) - alloc = index1 + 1; - t->level1 = (uint32_t *) xrealloc ((char *) t->level1, - alloc * sizeof (uint32_t)); - t->level1_alloc = alloc; - } - while (index1 >= t->level1_size) - t->level1[t->level1_size++] = EMPTY; - } - - if (t->level1[index1] == EMPTY) - { - if (t->level2_size == t->level2_alloc) - { - size_t alloc = 2 * t->level2_alloc + 1; - t->level2 = (uint32_t *) xrealloc ((char *) t->level2, - (alloc << t->q) * sizeof (uint32_t)); - t->level2_alloc = alloc; - } - i1 = t->level2_size << t->q; - i2 = (t->level2_size + 1) << t->q; - for (i = i1; i < i2; i++) - t->level2[i] = EMPTY; - t->level1[index1] = t->level2_size++; - } - - index2 += t->level1[index1] << t->q; - - if (t->level2[index2] == EMPTY) - { - if (t->level3_size == t->level3_alloc) - { - size_t alloc = 2 * t->level3_alloc + 1; - t->level3 = (uint32_t *) xrealloc ((char *) t->level3, - (alloc << t->p) * sizeof (uint32_t)); - t->level3_alloc = alloc; - } - i1 = t->level3_size << t->p; - i2 = (t->level3_size + 1) << t->p; - for (i = i1; i < i2; i++) - t->level3[i] = 0; - t->level2[index2] = t->level3_size++; - } - - index3 += t->level2[index2] << t->p; - - t->level3[index3] |= (uint32_t)1 << index4; -} - -/* Finalize and shrink. */ -static void -wctype_table_finalize (struct wctype_table *t) -{ - size_t i, j, k; - uint32_t reorder3[t->level3_size]; - uint32_t reorder2[t->level2_size]; - uint32_t level1_offset, level2_offset, level3_offset; - - /* Uniquify level3 blocks. */ - k = 0; - for (j = 0; j < t->level3_size; j++) - { - for (i = 0; i < k; i++) - if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (uint32_t)) == 0) - break; - /* Relocate block j to block i. */ - reorder3[j] = i; - if (i == k) - { - if (i != j) - memcpy (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (uint32_t)); - k++; - } - } - t->level3_size = k; - - for (i = 0; i < (t->level2_size << t->q); i++) - if (t->level2[i] != EMPTY) - t->level2[i] = reorder3[t->level2[i]]; - - /* Uniquify level2 blocks. */ - k = 0; - for (j = 0; j < t->level2_size; j++) - { - for (i = 0; i < k; i++) - if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)) == 0) - break; - /* Relocate block j to block i. */ - reorder2[j] = i; - if (i == k) - { - if (i != j) - memcpy (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)); - k++; - } - } - t->level2_size = k; - - for (i = 0; i < t->level1_size; i++) - if (t->level1[i] != EMPTY) - t->level1[i] = reorder2[t->level1[i]]; - - /* Create and fill the resulting compressed representation. */ - t->result_size = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t) - + (t->level2_size << t->q) * sizeof (uint32_t) - + (t->level3_size << t->p) * sizeof (uint32_t); - t->result = (char *) xmalloc (t->result_size); - - level1_offset = - 5 * sizeof (uint32_t); - level2_offset = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t); - level3_offset = - 5 * sizeof (uint32_t) - + t->level1_size * sizeof (uint32_t) - + (t->level2_size << t->q) * sizeof (uint32_t); - - ((uint32_t *) t->result)[0] = t->q + t->p + 5; - ((uint32_t *) t->result)[1] = t->level1_size; - ((uint32_t *) t->result)[2] = t->p + 5; - ((uint32_t *) t->result)[3] = (1 << t->q) - 1; - ((uint32_t *) t->result)[4] = (1 << t->p) - 1; - - for (i = 0; i < t->level1_size; i++) - ((uint32_t *) (t->result + level1_offset))[i] = - (t->level1[i] == EMPTY - ? 0 - : (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset); - - for (i = 0; i < (t->level2_size << t->q); i++) - ((uint32_t *) (t->result + level2_offset))[i] = - (t->level2[i] == EMPTY - ? 0 - : (t->level2[i] << t->p) * sizeof (uint32_t) + level3_offset); - - for (i = 0; i < (t->level3_size << t->p); i++) - ((uint32_t *) (t->result + level3_offset))[i] = t->level3[i]; - - if (t->level1_alloc > 0) - free (t->level1); - if (t->level2_alloc > 0) - free (t->level2); - if (t->level3_alloc > 0) - free (t->level3); -} - -#define TABLE wcwidth_table -#define ELEMENT uint8_t -#define DEFAULT 0xff -#include "3level.h" - -#define TABLE wctrans_table -#define ELEMENT int32_t -#define DEFAULT 0 -#define wctrans_table_add wctrans_table_add_internal -#include "3level.h" -#undef wctrans_table_add -/* The wctrans_table must actually store the difference between the - desired result and the argument. */ -static inline void -wctrans_table_add (struct wctrans_table *t, uint32_t wc, uint32_t mapped_wc) -{ - wctrans_table_add_internal (t, wc, mapped_wc - wc); -} - - -/* Flattens the included transliterations into a translit list. - Inserts them in the list at `cursor', and returns the new cursor. */ -static struct translit_t ** -translit_flatten (struct locale_ctype_t *ctype, struct charmap_t *charmap, - struct translit_t **cursor) -{ - while (ctype->translit_include != NULL) - { - const char *copy_locale = ctype->translit_include->copy_locale; - const char *copy_repertoire = ctype->translit_include->copy_repertoire; - struct localedef_t *other; - - /* Unchain the include statement. During the depth-first traversal - we don't want to visit any locale more than once. */ - ctype->translit_include = ctype->translit_include->next; - - other = find_locale (LC_CTYPE, copy_locale, copy_repertoire, charmap); - - if (other == NULL) - { - error (0, 0, _("\ -%s: transliteration data from locale `%s' not available"), - "LC_CTYPE", copy_locale); - } - else - { - struct locale_ctype_t *other_ctype = - other->categories[LC_CTYPE].ctype; - - cursor = translit_flatten (other_ctype, charmap, cursor); - assert (other_ctype->translit_include == NULL); - - if (other_ctype->translit != NULL) - { - /* Insert the other_ctype->translit list at *cursor. */ - struct translit_t *endp = other_ctype->translit; - while (endp->next != NULL) - endp = endp->next; - - endp->next = *cursor; - *cursor = other_ctype->translit; - - /* Avoid any risk of circular lists. */ - other_ctype->translit = NULL; - - cursor = &endp->next; - } - - if (ctype->default_missing == NULL) - ctype->default_missing = other_ctype->default_missing; - } - } - - return cursor; -} - -static void -allocate_arrays (struct locale_ctype_t *ctype, struct charmap_t *charmap, - struct repertoire_t *repertoire) -{ - size_t idx, nr; - const void *key; - size_t len; - void *vdata; - void *curs; - - /* You wonder about this amount of memory? This is only because some - users do not manage to address the array with unsigned values or - data types with range >= 256. '\200' would result in the array - index -128. To help these poor people we duplicate the entries for - 128 up to 255 below the entry for \0. */ - ctype->ctype_b = (char_class_t *) xcalloc (256 + 128, sizeof (char_class_t)); - ctype->ctype32_b = (char_class32_t *) xcalloc (256, sizeof (char_class32_t)); - ctype->class_b = (uint32_t **) - xmalloc (ctype->nr_charclass * sizeof (uint32_t *)); - ctype->class_3level = (struct iovec *) - xmalloc (ctype->nr_charclass * sizeof (struct iovec)); - - /* This is the array accessed using the multibyte string elements. */ - for (idx = 0; idx < 256; ++idx) - ctype->ctype_b[128 + idx] = ctype->class256_collection[idx]; - - /* Mirror first 127 entries. We must take care that entry -1 is not - mirrored because EOF == -1. */ - for (idx = 0; idx < 127; ++idx) - ctype->ctype_b[idx] = ctype->ctype_b[256 + idx]; - - /* The 32 bit array contains all characters < 0x100. */ - for (idx = 0; idx < ctype->class_collection_act; ++idx) - if (ctype->charnames[idx] < 0x100) - ctype->ctype32_b[ctype->charnames[idx]] = ctype->class_collection[idx]; - - for (nr = 0; nr < ctype->nr_charclass; nr++) - { - ctype->class_b[nr] = (uint32_t *) xcalloc (256 / 32, sizeof (uint32_t)); - - for (idx = 0; idx < 256; ++idx) - if (ctype->class256_collection[idx] & _ISbit (nr)) - ctype->class_b[nr][idx >> 5] |= (uint32_t)1 << (idx & 0x1f); - } - - for (nr = 0; nr < ctype->nr_charclass; nr++) - { - struct wctype_table t; - - t.p = 4; /* or: 5 */ - t.q = 7; /* or: 6 */ - wctype_table_init (&t); - - for (idx = 0; idx < ctype->class_collection_act; ++idx) - if (ctype->class_collection[idx] & _ISwbit (nr)) - wctype_table_add (&t, ctype->charnames[idx]); - - wctype_table_finalize (&t); - - if (verbose) - fprintf (stderr, _("%s: table for class \"%s\": %lu bytes\n"), - "LC_CTYPE", ctype->classnames[nr], - (unsigned long int) t.result_size); - - ctype->class_3level[nr].iov_base = t.result; - ctype->class_3level[nr].iov_len = t.result_size; - } - - /* Room for table of mappings. */ - ctype->map_b = (uint32_t **) xmalloc (2 * sizeof (uint32_t *)); - ctype->map32_b = (uint32_t **) xmalloc (ctype->map_collection_nr - * sizeof (uint32_t *)); - ctype->map_3level = (struct iovec *) - xmalloc (ctype->map_collection_nr * sizeof (struct iovec)); - - /* Fill in all mappings. */ - for (idx = 0; idx < 2; ++idx) - { - unsigned int idx2; - - /* Allocate table. */ - ctype->map_b[idx] = (uint32_t *) - xmalloc ((256 + 128) * sizeof (uint32_t)); - - /* Copy values from collection. */ - for (idx2 = 0; idx2 < 256; ++idx2) - ctype->map_b[idx][128 + idx2] = ctype->map256_collection[idx][idx2]; - - /* Mirror first 127 entries. We must take care not to map entry - -1 because EOF == -1. */ - for (idx2 = 0; idx2 < 127; ++idx2) - ctype->map_b[idx][idx2] = ctype->map_b[idx][256 + idx2]; - - /* EOF must map to EOF. */ - ctype->map_b[idx][127] = EOF; - } - - for (idx = 0; idx < ctype->map_collection_nr; ++idx) - { - unsigned int idx2; - - /* Allocate table. */ - ctype->map32_b[idx] = (uint32_t *) xmalloc (256 * sizeof (uint32_t)); - - /* Copy values from collection. Default is identity mapping. */ - for (idx2 = 0; idx2 < 256; ++idx2) - ctype->map32_b[idx][idx2] = - (ctype->map_collection[idx][idx2] != 0 - ? ctype->map_collection[idx][idx2] - : idx2); - } - - for (nr = 0; nr < ctype->map_collection_nr; nr++) - { - struct wctrans_table t; - - t.p = 7; - t.q = 9; - wctrans_table_init (&t); - - for (idx = 0; idx < ctype->map_collection_act[nr]; ++idx) - if (ctype->map_collection[nr][idx] != 0) - wctrans_table_add (&t, ctype->charnames[idx], - ctype->map_collection[nr][idx]); - - wctrans_table_finalize (&t); - - if (verbose) - fprintf (stderr, _("%s: table for map \"%s\": %lu bytes\n"), - "LC_CTYPE", ctype->mapnames[nr], - (unsigned long int) t.result_size); - - ctype->map_3level[nr].iov_base = t.result; - ctype->map_3level[nr].iov_len = t.result_size; - } - - /* Extra array for class and map names. */ - ctype->class_name_ptr = (uint32_t *) xmalloc (ctype->nr_charclass - * sizeof (uint32_t)); - ctype->map_name_ptr = (uint32_t *) xmalloc (ctype->map_collection_nr - * sizeof (uint32_t)); - - ctype->class_offset = _NL_ITEM_INDEX (_NL_CTYPE_EXTRA_MAP_1); - ctype->map_offset = ctype->class_offset + ctype->nr_charclass; - - /* Array for width information. Because the expected widths are very - small (never larger than 2) we use only one single byte. This - saves space. - We put only printable characters in the table. wcwidth is specified - to return -1 for non-printable characters. Doing the check here - saves a run-time check. - But we put L'\0' in the table. This again saves a run-time check. */ - { - struct wcwidth_table t; - - t.p = 7; - t.q = 9; - wcwidth_table_init (&t); - - /* First set all the printable characters of the character set to - the default width. */ - curs = NULL; - while (iterate_table (&charmap->char_table, &curs, &key, &len, &vdata) == 0) - { - struct charseq *data = (struct charseq *) vdata; - - if (data->ucs4 == UNINITIALIZED_CHAR_VALUE) - data->ucs4 = repertoire_find_value (ctype->repertoire, - data->name, len); - - if (data->ucs4 != ILLEGAL_CHAR_VALUE) - { - uint32_t *class_bits = - find_idx (ctype, &ctype->class_collection, NULL, - &ctype->class_collection_act, data->ucs4); - - if (class_bits != NULL && (*class_bits & BITw (tok_print))) - wcwidth_table_add (&t, data->ucs4, charmap->width_default); - } - } - - /* Now add the explicitly specified widths. */ - if (charmap->width_rules != NULL) - { - size_t cnt; - - for (cnt = 0; cnt < charmap->nwidth_rules; ++cnt) - { - unsigned char bytes[charmap->mb_cur_max]; - int nbytes = charmap->width_rules[cnt].from->nbytes; - - /* We have the range of character for which the width is - specified described using byte sequences of the multibyte - charset. We have to convert this to UCS4 now. And we - cannot simply convert the beginning and the end of the - sequence, we have to iterate over the byte sequence and - convert it for every single character. */ - memcpy (bytes, charmap->width_rules[cnt].from->bytes, nbytes); - - while (nbytes < charmap->width_rules[cnt].to->nbytes - || memcmp (bytes, charmap->width_rules[cnt].to->bytes, - nbytes) <= 0) - { - /* Find the UCS value for `bytes'. */ - int inner; - uint32_t wch; - struct charseq *seq = - charmap_find_symbol (charmap, bytes, nbytes); - - if (seq == NULL) - wch = ILLEGAL_CHAR_VALUE; - else if (seq->ucs4 != UNINITIALIZED_CHAR_VALUE) - wch = seq->ucs4; - else - wch = repertoire_find_value (ctype->repertoire, seq->name, - strlen (seq->name)); - - if (wch != ILLEGAL_CHAR_VALUE) - { - /* Store the value. */ - uint32_t *class_bits = - find_idx (ctype, &ctype->class_collection, NULL, - &ctype->class_collection_act, wch); - - if (class_bits != NULL && (*class_bits & BITw (tok_print))) - wcwidth_table_add (&t, wch, - charmap->width_rules[cnt].width); - } - - /* "Increment" the bytes sequence. */ - inner = nbytes - 1; - while (inner >= 0 && bytes[inner] == 0xff) - --inner; - - if (inner < 0) - { - /* We have to extend the byte sequence. */ - if (nbytes >= charmap->width_rules[cnt].to->nbytes) - break; - - bytes[0] = 1; - memset (&bytes[1], 0, nbytes); - ++nbytes; - } - else - { - ++bytes[inner]; - while (++inner < nbytes) - bytes[inner] = 0; - } - } - } - } - - /* Set the width of L'\0' to 0. */ - wcwidth_table_add (&t, 0, 0); - - wcwidth_table_finalize (&t); - - if (verbose) - fprintf (stderr, _("%s: table for width: %lu bytes\n"), - "LC_CTYPE", (unsigned long int) t.result_size); - - ctype->width.iov_base = t.result; - ctype->width.iov_len = t.result_size; - } - - /* Set MB_CUR_MAX. */ - ctype->mb_cur_max = charmap->mb_cur_max; - - /* Now determine the table for the transliteration information. - - XXX It is not yet clear to me whether it is worth implementing a - complicated algorithm which uses a hash table to locate the entries. - For now I'll use a simple array which can be searching using binary - search. */ - if (ctype->translit_include != NULL) - /* Traverse the locales mentioned in the `include' statements in a - depth-first way and fold in their transliteration information. */ - translit_flatten (ctype, charmap, &ctype->translit); - - if (ctype->translit != NULL) - { - /* First count how many entries we have. This is the upper limit - since some entries from the included files might be overwritten. */ - size_t number = 0; - size_t cnt; - struct translit_t *runp = ctype->translit; - struct translit_t **sorted; - size_t from_len, to_len; - - while (runp != NULL) - { - ++number; - runp = runp->next; - } - - /* Next we allocate an array large enough and fill in the values. */ - sorted = (struct translit_t **) alloca (number - * sizeof (struct translit_t **)); - runp = ctype->translit; - number = 0; - do - { - /* Search for the place where to insert this string. - XXX Better use a real sorting algorithm later. */ - size_t idx = 0; - int replace = 0; - - while (idx < number) - { - int res = wcscmp ((const wchar_t *) sorted[idx]->from, - (const wchar_t *) runp->from); - if (res == 0) - { - replace = 1; - break; - } - if (res > 0) - break; - ++idx; - } - - if (replace) - sorted[idx] = runp; - else - { - memmove (&sorted[idx + 1], &sorted[idx], - (number - idx) * sizeof (struct translit_t *)); - sorted[idx] = runp; - ++number; - } - - runp = runp->next; - } - while (runp != NULL); - - /* The next step is putting all the possible transliteration - strings in one memory block so that we can write it out. - We need several different blocks: - - index to the from-string array - - from-string array - - index to the to-string array - - to-string array. - */ - from_len = to_len = 0; - for (cnt = 0; cnt < number; ++cnt) - { - struct translit_to_t *srunp; - from_len += wcslen ((const wchar_t *) sorted[cnt]->from) + 1; - srunp = sorted[cnt]->to; - while (srunp != NULL) - { - to_len += wcslen ((const wchar_t *) srunp->str) + 1; - srunp = srunp->next; - } - /* Plus one for the extra NUL character marking the end of - the list for the current entry. */ - ++to_len; - } - - /* We can allocate the arrays for the results. */ - ctype->translit_from_idx = xmalloc (number * sizeof (uint32_t)); - ctype->translit_from_tbl = xmalloc (from_len * sizeof (uint32_t)); - ctype->translit_to_idx = xmalloc (number * sizeof (uint32_t)); - ctype->translit_to_tbl = xmalloc (to_len * sizeof (uint32_t)); - - from_len = 0; - to_len = 0; - for (cnt = 0; cnt < number; ++cnt) - { - size_t len; - struct translit_to_t *srunp; - - ctype->translit_from_idx[cnt] = from_len; - ctype->translit_to_idx[cnt] = to_len; - - len = wcslen ((const wchar_t *) sorted[cnt]->from) + 1; - wmemcpy ((wchar_t *) &ctype->translit_from_tbl[from_len], - (const wchar_t *) sorted[cnt]->from, len); - from_len += len; - - ctype->translit_to_idx[cnt] = to_len; - srunp = sorted[cnt]->to; - while (srunp != NULL) - { - len = wcslen ((const wchar_t *) srunp->str) + 1; - wmemcpy ((wchar_t *) &ctype->translit_to_tbl[to_len], - (const wchar_t *) srunp->str, len); - to_len += len; - srunp = srunp->next; - } - ctype->translit_to_tbl[to_len++] = L'\0'; - } - - /* Store the information about the length. */ - ctype->translit_idx_size = number; - ctype->translit_from_tbl_size = from_len * sizeof (uint32_t); - ctype->translit_to_tbl_size = to_len * sizeof (uint32_t); - } - else - { - /* Provide some dummy pointers since we have nothing to write out. */ - static uint32_t no_str = { 0 }; - - ctype->translit_from_idx = &no_str; - ctype->translit_from_tbl = &no_str; - ctype->translit_to_tbl = &no_str; - ctype->translit_idx_size = 0; - ctype->translit_from_tbl_size = 0; - ctype->translit_to_tbl_size = 0; - } -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-identification.c b/src/system/libroot/posix/glibc/locale/programs/ld-identification.c deleted file mode 100644 index a64fe63d1b..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-identification.c +++ /dev/null @@ -1,465 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_IDENTIFICATION locale. */ -struct locale_identification_t -{ - const char *title; - const char *source; - const char *address; - const char *contact; - const char *email; - const char *tel; - const char *fax; - const char *language; - const char *territory; - const char *audience; - const char *application; - const char *abbreviation; - const char *revision; - const char *date; - const char *category[__LC_LAST]; -}; - - -static const char *category_name[__LC_LAST] = -{ - [LC_CTYPE] = "LC_CTYPE", - [LC_NUMERIC] = "LC_NUMERIC", - [LC_TIME] = "LC_TIME", - [LC_COLLATE] = "LC_COLLATE", - [LC_MONETARY] = "LC_MONETARY", - [LC_MESSAGES] = "LC_MESSAGES", - [LC_ALL] = "LC_ALL", - [LC_PAPER] = "LC_PAPER", - [LC_NAME] = "LC_NAME", - [LC_ADDRESS] = "LC_ADDRESS", - [LC_TELEPHONE] = "LC_TELEPHONE", - [LC_MEASUREMENT] = "LC_MEASUREMENT", - [LC_IDENTIFICATION] = "LC_IDENTIFICATION" -}; - - -static void -identification_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - { - locale->categories[LC_IDENTIFICATION].identification = - (struct locale_identification_t *) - xcalloc (1, sizeof (struct locale_identification_t)); - - locale->categories[LC_IDENTIFICATION].identification->category[LC_ALL] = - ""; - } - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -identification_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_identification_t *identification - = locale->categories[LC_IDENTIFICATION].identification; - int nothing = 0; - size_t num; - - /* Now resolve copying and also handle completely missing definitions. */ - if (identification == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_IDENTIFICATION] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_IDENTIFICATION, - from->copy_name[LC_IDENTIFICATION], - from->repertoire_name, charmap); - while (from->categories[LC_IDENTIFICATION].identification == NULL - && from->copy_name[LC_IDENTIFICATION] != NULL); - - identification = locale->categories[LC_IDENTIFICATION].identification - = from->categories[LC_IDENTIFICATION].identification; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (identification == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_IDENTIFICATION"); - identification_startup (NULL, locale, 0); - identification - = locale->categories[LC_IDENTIFICATION].identification; - nothing = 1; - } - } - -#define TEST_ELEM(cat) \ - if (identification->cat == NULL) \ - { \ - if (verbose && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), \ - "LC_IDENTIFICATION", #cat); \ - identification->cat = ""; \ - } - - TEST_ELEM (title); - TEST_ELEM (source); - TEST_ELEM (address); - TEST_ELEM (contact); - TEST_ELEM (email); - TEST_ELEM (tel); - TEST_ELEM (fax); - TEST_ELEM (language); - TEST_ELEM (territory); - TEST_ELEM (audience); - TEST_ELEM (application); - TEST_ELEM (abbreviation); - TEST_ELEM (revision); - TEST_ELEM (date); - - for (num = 0; num < __LC_LAST; ++num) - if (num != LC_ALL && identification->category[num] == NULL) - { - if (verbose && ! nothing) - error (0, 0, _("%s: no identification for category `%s'"), - "LC_IDENTIFICATION", category_name[num]); - identification->category[num] = ""; - } -} - - -void -identification_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_identification_t *identification - = locale->categories[LC_IDENTIFICATION].identification; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION) - + (__LC_LAST - 2)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION)]; - size_t cnt = 0; - size_t num; - size_t last_idx; - - data.magic = LIMAGIC (LC_IDENTIFICATION); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) identification->title; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->source; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->address; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->contact; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->email; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->tel; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->fax; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->language; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->territory; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->audience; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->application; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->abbreviation; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->revision; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) identification->date; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - last_idx = cnt - 1; - idx[last_idx] = idx[cnt - 2]; - for (num = 0; num < __LC_LAST; ++num) - if (num != LC_ALL) - { - iov[cnt].iov_base = (void *) identification->category[num]; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - idx[last_idx] += iov[cnt].iov_len; - ++cnt; - } - - assert (last_idx == _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION) - 1); - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION) - + (__LC_LAST - 2))); - - write_locale_data (output_path, "LC_IDENTIFICATION", cnt, iov); -} - - -/* The parser for the LC_IDENTIFICATION section of the locale definition. */ -void -identification_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_identification_t *identification; - struct token *now; - struct token *arg; - struct token *cattok; - int category; - enum token_t nowtok; - - /* The rest of the line containing `LC_IDENTIFICATION' must be free. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, - tok_lc_identification, LC_IDENTIFICATION, - "LC_IDENTIFICATION", ignore_content); - return; - } - - /* Prepare the data structures. */ - identification_startup (ldfile, result, ignore_content); - identification = result->categories[LC_IDENTIFICATION].identification; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ignore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_string) \ - goto err_label; \ - if (identification->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \ - else if (!ignore_content && arg->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \ - identification->cat = ""; \ - } \ - else if (!ignore_content) \ - identification->cat = arg->val.str.startmb; \ - break - - STR_ELEM (title); - STR_ELEM (source); - STR_ELEM (address); - STR_ELEM (contact); - STR_ELEM (email); - STR_ELEM (tel); - STR_ELEM (fax); - STR_ELEM (language); - STR_ELEM (territory); - STR_ELEM (audience); - STR_ELEM (application); - STR_ELEM (abbreviation); - STR_ELEM (revision); - STR_ELEM (date); - - case tok_category: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - /* We expect two operands. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok != tok_string && arg->tok != tok_ident) - goto err_label; - /* Next is a semicolon. */ - cattok = lr_token (ldfile, charmap, NULL, verbose); - if (cattok->tok != tok_semicolon) - goto err_label; - /* Now a LC_xxx identifier. */ - cattok = lr_token (ldfile, charmap, NULL, verbose); - switch (cattok->tok) - { -#define CATEGORY(lname, uname) \ - case tok_lc_##lname: \ - category = LC_##uname; \ - break - - CATEGORY (identification, IDENTIFICATION); - CATEGORY (ctype, CTYPE); - CATEGORY (collate, COLLATE); - CATEGORY (time, TIME); - CATEGORY (numeric, NUMERIC); - CATEGORY (monetary, MONETARY); - CATEGORY (messages, MESSAGES); - CATEGORY (paper, PAPER); - CATEGORY (name, NAME); - CATEGORY (address, ADDRESS); - CATEGORY (telephone, TELEPHONE); - CATEGORY (measurement, MEASUREMENT); - - default: - goto err_label; - } - if (identification->category[category] != NULL) - { - lr_error (ldfile, _("\ -%s: duplicate category version definition"), "LC_IDENTIFICATION"); - free (arg->val.str.startmb); - } - else - identification->category[category] = arg->val.str.startmb; - break; - - case tok_end: - /* Next we assume `LC_IDENTIFICATION'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), - "LC_IDENTIFICATION"); - else if (arg->tok != tok_lc_identification) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_identification); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_IDENTIFICATION"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-measurement.c b/src/system/libroot/posix/glibc/locale/programs/ld-measurement.c deleted file mode 100644 index 90187420b4..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-measurement.c +++ /dev/null @@ -1,255 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_MEASUREMENT locale. */ -struct locale_measurement_t -{ - unsigned char measurement; -}; - - -static void -measurement_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_MEASUREMENT].measurement = - (struct locale_measurement_t *) - xcalloc (1, sizeof (struct locale_measurement_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -measurement_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_measurement_t *measurement = - locale->categories[LC_MEASUREMENT].measurement; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (measurement == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_MEASUREMENT] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_MEASUREMENT, - from->copy_name[LC_MEASUREMENT], - from->repertoire_name, charmap); - while (from->categories[LC_MEASUREMENT].measurement == NULL - && from->copy_name[LC_MEASUREMENT] != NULL); - - measurement = locale->categories[LC_MEASUREMENT].measurement - = from->categories[LC_MEASUREMENT].measurement; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (measurement == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_MEASUREMENT"); - measurement_startup (NULL, locale, 0); - measurement = locale->categories[LC_MEASUREMENT].measurement; - nothing = 1; - } - } - - if (measurement->measurement == 0) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_MEASUREMENT", "measurement"); - /* Use as the default value the value of the i18n locale. */ - measurement->measurement = 1; - } - else - { - if (measurement->measurement > 3) - error (0, 0, _("%s: invalid value for field `%s'"), - "LC_MEASUREMENT", "measurement"); - } -} - - -void -measurement_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_measurement_t *measurement = - locale->categories[LC_MEASUREMENT].measurement; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_MEASUREMENT); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = &measurement->measurement; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT)); - - write_locale_data (output_path, "LC_MEASUREMENT", - 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT), iov); -} - - -/* The parser for the LC_MEASUREMENT section of the locale definition. */ -void -measurement_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_measurement_t *measurement; - struct token *now; - struct token *arg; - enum token_t nowtok; - - /* The rest of the line containing `LC_MEASUREMENT' must be free. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, - tok_lc_measurement, LC_MEASUREMENT, "LC_MEASUREMENT", - ignore_content); - return; - } - - /* Prepare the data structures. */ - measurement_startup (ldfile, result, ignore_content); - measurement = result->categories[LC_MEASUREMENT].measurement; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define INT_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_number) \ - goto err_label; \ - else if (measurement->cat != 0) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_MEASUREMENT", #cat); \ - else if (!ignore_content) \ - measurement->cat = arg->val.num; \ - break - - INT_ELEM (measurement); - - case tok_end: - /* Next we assume `LC_MEASUREMENT'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), - "LC_MEASUREMENT"); - else if (arg->tok != tok_lc_measurement) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_measurement); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), - "LC_MEASUREMENT"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-messages.c b/src/system/libroot/posix/glibc/locale/programs/ld-messages.c deleted file mode 100644 index 48c63e2a61..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-messages.c +++ /dev/null @@ -1,348 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include - -#include "linereader.h" -#include "localedef.h" -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_MESSAGES locale. */ -struct locale_messages_t -{ - const char *yesexpr; - const char *noexpr; - const char *yesstr; - const char *nostr; -}; - - -static void -messages_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_MESSAGES].messages = - (struct locale_messages_t *) xcalloc (1, - sizeof (struct locale_messages_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -messages_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_messages_t *messages - = locale->categories[LC_MESSAGES].messages; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (messages == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_MESSAGES] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_MESSAGES, from->copy_name[LC_MESSAGES], - from->repertoire_name, charmap); - while (from->categories[LC_MESSAGES].messages == NULL - && from->copy_name[LC_MESSAGES] != NULL); - - messages = locale->categories[LC_MESSAGES].messages - = from->categories[LC_MESSAGES].messages; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (messages == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_MESSAGES"); - messages_startup (NULL, locale, 0); - messages = locale->categories[LC_MESSAGES].messages; - nothing = 1; - } - } - - /* The fields YESSTR and NOSTR are optional. */ - if (messages->yesstr == NULL) - messages->yesstr = ""; - if (messages->nostr == NULL) - messages->nostr = ""; - - if (messages->yesexpr == NULL) - { - if (! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' undefined"), "LC_MESSAGES", "yesexpr"); - messages->yesexpr = "^[yY]"; - } - else if (messages->yesexpr[0] == '\0') - { - if (!be_quiet) - error (0, 0, _("\ -%s: value for field `%s' must not be an empty string"), - "LC_MESSAGES", "yesexpr"); - } - else - { - int result; - regex_t re; - - /* Test whether it are correct regular expressions. */ - result = regcomp (&re, messages->yesexpr, REG_EXTENDED); - if (result != 0 && !be_quiet) - { - char errbuf[BUFSIZ]; - - (void) regerror (result, &re, errbuf, BUFSIZ); - error (0, 0, _("\ -%s: no correct regular expression for field `%s': %s"), - "LC_MESSAGES", "yesexpr", errbuf); - } - else if (result != 0) - regfree (&re); - } - - if (messages->noexpr == NULL) - { - if (! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' undefined"), "LC_MESSAGES", "noexpr"); - messages->noexpr = "^[nN]"; - } - else if (messages->noexpr[0] == '\0') - { - if (!be_quiet) - error (0, 0, _("\ -%s: value for field `%s' must not be an empty string"), - "LC_MESSAGES", "noexpr"); - } - else - { - int result; - regex_t re; - - /* Test whether it are correct regular expressions. */ - result = regcomp (&re, messages->noexpr, REG_EXTENDED); - if (result != 0 && !be_quiet) - { - char errbuf[BUFSIZ]; - - (void) regerror (result, &re, errbuf, BUFSIZ); - error (0, 0, _("\ -%s: no correct regular expression for field `%s': %s"), - "LC_MESSAGES", "noexpr", errbuf); - } - else if (result != 0) - regfree (&re); - } -} - - -void -messages_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_messages_t *messages - = locale->categories[LC_MESSAGES].messages; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_MESSAGES); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (char *) messages->yesexpr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (char *) messages->noexpr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (char *) messages->yesstr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (char *) messages->nostr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (char *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - - assert (cnt + 1 == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES)); - - write_locale_data (output_path, "LC_MESSAGES", - 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES), iov); -} - - -/* The parser for the LC_MESSAGES section of the locale definition. */ -void -messages_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_messages_t *messages; - struct token *now; - enum token_t nowtok; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_MESSAGES' must be free. */ - lr_ignore_rest (ldfile, 1); - - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_messages, - LC_MESSAGES, "LC_MESSAGES", ignore_content); - return; - } - - /* Prepare the data structures. */ - messages_startup (ldfile, result, ignore_content); - messages = result->categories[LC_MESSAGES].messages; - - while (1) - { - struct token *arg; - - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ignore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - if (messages->cat != NULL) \ - { \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_MESSAGES", #cat); \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_string) \ - goto syntax_error; \ - else if (!ignore_content && now->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_MESSAGES", #cat); \ - messages->cat = ""; \ - } \ - else if (!ignore_content) \ - messages->cat = now->val.str.startmb; \ - break - - STR_ELEM (yesexpr); - STR_ELEM (noexpr); - STR_ELEM (yesstr); - STR_ELEM (nostr); - - case tok_end: - /* Next we assume `LC_MESSAGES'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_MESSAGES"); - else if (arg->tok != tok_lc_messages) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_MESSAGES"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_messages); - return; - - default: - syntax_error: - SYNTAX_ERROR (_("%s: syntax error"), "LC_MESSAGES"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_MESSAGES"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-monetary.c b/src/system/libroot/posix/glibc/locale/programs/ld-monetary.c deleted file mode 100644 index 08a10fdcc1..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-monetary.c +++ /dev/null @@ -1,953 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -#include - -#include "linereader.h" -#include "localedef.h" -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_MONETARY locale. */ -struct locale_monetary_t -{ - const char *int_curr_symbol; - const char *currency_symbol; - const char *mon_decimal_point; - const char *mon_thousands_sep; - uint32_t mon_decimal_point_wc; - uint32_t mon_thousands_sep_wc; - char *mon_grouping; - size_t mon_grouping_len; - const char *positive_sign; - const char *negative_sign; - signed char int_frac_digits; - signed char frac_digits; - signed char p_cs_precedes; - signed char p_sep_by_space; - signed char n_cs_precedes; - signed char n_sep_by_space; - signed char p_sign_posn; - signed char n_sign_posn; - signed char int_p_cs_precedes; - signed char int_p_sep_by_space; - signed char int_n_cs_precedes; - signed char int_n_sep_by_space; - signed char int_p_sign_posn; - signed char int_n_sign_posn; - const char *duo_int_curr_symbol; - const char *duo_currency_symbol; - signed char duo_int_frac_digits; - signed char duo_frac_digits; - signed char duo_p_cs_precedes; - signed char duo_p_sep_by_space; - signed char duo_n_cs_precedes; - signed char duo_n_sep_by_space; - signed char duo_p_sign_posn; - signed char duo_n_sign_posn; - signed char duo_int_p_cs_precedes; - signed char duo_int_p_sep_by_space; - signed char duo_int_n_cs_precedes; - signed char duo_int_n_sep_by_space; - signed char duo_int_p_sign_posn; - signed char duo_int_n_sign_posn; - uint32_t uno_valid_from; - uint32_t uno_valid_to; - uint32_t duo_valid_from; - uint32_t duo_valid_to; - uint32_t conversion_rate[2]; - char *crncystr; -}; - - -/* The content iof the field int_curr_symbol has to be taken from - ISO-4217. We test for correct values. */ -#define DEFINE_INT_CURR(str) str, -static const char *const valid_int_curr[] = - { -# include "../iso-4217.def" - }; -#define NR_VALID_INT_CURR ((sizeof (valid_int_curr) \ - / sizeof (valid_int_curr[0]))) -#undef DEFINE_INT_CURR - - -/* Prototypes for local functions. */ -static int curr_strcmp (const char *s1, const char **s2); - - -static void -monetary_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - { - struct locale_monetary_t *monetary; - - locale->categories[LC_MONETARY].monetary = monetary = - (struct locale_monetary_t *) xmalloc (sizeof (*monetary)); - - memset (monetary, '\0', sizeof (struct locale_monetary_t)); - - monetary->mon_grouping = NULL; - monetary->mon_grouping_len = 0; - - monetary->int_frac_digits = -2; - monetary->frac_digits = -2; - monetary->p_cs_precedes = -2; - monetary->p_sep_by_space = -2; - monetary->n_cs_precedes = -2; - monetary->n_sep_by_space = -2; - monetary->p_sign_posn = -2; - monetary->n_sign_posn = -2; - monetary->int_p_cs_precedes = -2; - monetary->int_p_sep_by_space = -2; - monetary->int_n_cs_precedes = -2; - monetary->int_n_sep_by_space = -2; - monetary->int_p_sign_posn = -2; - monetary->int_n_sign_posn = -2; - monetary->duo_int_frac_digits = -2; - monetary->duo_frac_digits = -2; - monetary->duo_p_cs_precedes = -2; - monetary->duo_p_sep_by_space = -2; - monetary->duo_n_cs_precedes = -2; - monetary->duo_n_sep_by_space = -2; - monetary->duo_p_sign_posn = -2; - monetary->duo_n_sign_posn = -2; - monetary->duo_int_p_cs_precedes = -2; - monetary->duo_int_p_sep_by_space = -2; - monetary->duo_int_n_cs_precedes = -2; - monetary->duo_int_n_sep_by_space = -2; - monetary->duo_int_p_sign_posn = -2; - monetary->duo_int_n_sign_posn = -2; - } - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -monetary_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_monetary_t *monetary - = locale->categories[LC_MONETARY].monetary; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (monetary == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_MONETARY] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_MONETARY, from->copy_name[LC_MONETARY], - from->repertoire_name, charmap); - while (from->categories[LC_MONETARY].monetary == NULL - && from->copy_name[LC_MONETARY] != NULL); - - monetary = locale->categories[LC_MONETARY].monetary - = from->categories[LC_MONETARY].monetary; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (monetary == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_MONETARY"); - monetary_startup (NULL, locale, 0); - monetary = locale->categories[LC_MONETARY].monetary; - nothing = 1; - } - } - -#define TEST_ELEM(cat, initval) \ - if (monetary->cat == NULL) \ - { \ - if (! be_quiet && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat); \ - monetary->cat = initval; \ - } - - TEST_ELEM (int_curr_symbol, ""); - TEST_ELEM (currency_symbol, ""); - TEST_ELEM (mon_decimal_point, "."); - TEST_ELEM (mon_thousands_sep, ""); - TEST_ELEM (positive_sign, ""); - TEST_ELEM (negative_sign, ""); - - /* The international currency symbol must come from ISO 4217. */ - if (monetary->int_curr_symbol != NULL) - { - if (strlen (monetary->int_curr_symbol) != 4) - { - if (! be_quiet && ! nothing) - error (0, 0, _("\ -%s: value of field `int_curr_symbol' has wrong length"), - "LC_MONETARY"); - } - else if (bsearch (monetary->int_curr_symbol, valid_int_curr, - NR_VALID_INT_CURR, sizeof (const char *), - (comparison_fn_t) curr_strcmp) == NULL - && !be_quiet) - error (0, 0, _("\ -%s: value of field `int_curr_symbol' does \ -not correspond to a valid name in ISO 4217"), - "LC_MONETARY"); - } - - /* The decimal point must not be empty. This is not said explicitly - in POSIX but ANSI C (ISO/IEC 9899) says in 4.4.2.1 it has to be - != "". */ - if (monetary->mon_decimal_point == NULL) - { - if (! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_decimal_point"); - monetary->mon_decimal_point = "."; - } - else if (monetary->mon_decimal_point[0] == '\0' && ! be_quiet && ! nothing) - { - error (0, 0, _("\ -%s: value for field `%s' must not be the empty string"), - "LC_MONETARY", "mon_decimal_point"); - } - if (monetary->mon_decimal_point_wc == L'\0') - monetary->mon_decimal_point_wc = L'.'; - - if (monetary->mon_grouping_len == 0) - { - if (! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_grouping"); - - monetary->mon_grouping = (char *) "\177"; - monetary->mon_grouping_len = 1; - } - -#undef TEST_ELEM -#define TEST_ELEM(cat, min, max, initval) \ - if (monetary->cat == -2) \ - { \ - if (! be_quiet && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat); \ - monetary->cat = initval; \ - } \ - else if ((monetary->cat < min || monetary->cat > max) \ - && !be_quiet && !nothing) \ - error (0, 0, _(" \ -%s: value for field `%s' must be in range %d...%d"), \ - "LC_MONETARY", #cat, min, max) - - TEST_ELEM (int_frac_digits, -128, 127, -1); - TEST_ELEM (frac_digits, -128, 127, -1); - TEST_ELEM (p_cs_precedes, -1, 1, -1); - TEST_ELEM (p_sep_by_space, -1, 2, -1); - TEST_ELEM (n_cs_precedes, -1, 1, -1); - TEST_ELEM (n_sep_by_space, -1, 2, -1); - TEST_ELEM (p_sign_posn, -1, 4, -1); - TEST_ELEM (n_sign_posn, -1, 4, -1); - - /* The non-POSIX.2 extensions are optional. */ - if (monetary->duo_int_curr_symbol == NULL) - monetary->duo_int_curr_symbol = monetary->int_curr_symbol; - if (monetary->duo_currency_symbol == NULL) - monetary->duo_currency_symbol = monetary->currency_symbol; - - if (monetary->duo_int_frac_digits == -2) - monetary->duo_int_frac_digits = monetary->int_frac_digits; - if (monetary->duo_frac_digits == -2) - monetary->duo_frac_digits = monetary->frac_digits; - -#undef TEST_ELEM -#define TEST_ELEM(cat, alt, min, max) \ - if (monetary->cat == -2) \ - monetary->cat = monetary->alt; \ - else if ((monetary->cat < min || monetary->cat > max) && !be_quiet \ - && ! nothing) \ - error (0, 0, _("\ -%s: value for field `%s' must be in range %d...%d"), \ - "LC_MONETARY", #cat, min, max) - - TEST_ELEM (int_p_cs_precedes, p_cs_precedes, -1, 1); - TEST_ELEM (int_p_sep_by_space, p_sep_by_space, -1, 2); - TEST_ELEM (int_n_cs_precedes, n_cs_precedes, -1, 1); - TEST_ELEM (int_n_sep_by_space, n_sep_by_space, -1, 2); - TEST_ELEM (int_p_sign_posn, p_sign_posn, -1, 4); - TEST_ELEM (int_n_sign_posn, n_sign_posn, -1, 4); - - TEST_ELEM (duo_p_cs_precedes, p_cs_precedes, -1, 1); - TEST_ELEM (duo_p_sep_by_space, p_sep_by_space, -1, 2); - TEST_ELEM (duo_n_cs_precedes, n_cs_precedes, -1, 1); - TEST_ELEM (duo_n_sep_by_space, n_sep_by_space, -1, 2); - TEST_ELEM (duo_int_p_cs_precedes, int_p_cs_precedes, -1, 1); - TEST_ELEM (duo_int_p_sep_by_space, int_p_sep_by_space, -1, 2); - TEST_ELEM (duo_int_n_cs_precedes, int_n_cs_precedes, -1, 1); - TEST_ELEM (duo_int_n_sep_by_space, int_n_sep_by_space, -1, 2); - TEST_ELEM (duo_p_sign_posn, p_sign_posn, -1, 4); - TEST_ELEM (duo_n_sign_posn, n_sign_posn, -1, 4); - TEST_ELEM (duo_int_p_sign_posn, int_p_sign_posn, -1, 4); - TEST_ELEM (duo_int_n_sign_posn, int_n_sign_posn, -1, 4); - - if (monetary->uno_valid_from == 0) - monetary->uno_valid_from = 10101; - if (monetary->uno_valid_to == 0) - monetary->uno_valid_to = 99991231; - if (monetary->duo_valid_from == 0) - monetary->duo_valid_from = 10101; - if (monetary->duo_valid_to == 0) - monetary->duo_valid_to = 99991231; - - if (monetary->conversion_rate[0] == 0) - { - monetary->conversion_rate[0] = 1; - monetary->conversion_rate[1] = 1; - } - - /* Create the crncystr entry. */ - monetary->crncystr = (char *) xmalloc (strlen (monetary->currency_symbol) - + 2); - monetary->crncystr[0] = monetary->p_cs_precedes ? '-' : '+'; - strcpy (&monetary->crncystr[1], monetary->currency_symbol); -} - - -void -monetary_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_monetary_t *monetary - = locale->categories[LC_MONETARY].monetary; - struct iovec iov[3 + _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_MONETARY)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_MONETARY); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) monetary->int_curr_symbol; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->currency_symbol; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->mon_decimal_point; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->mon_thousands_sep; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = monetary->mon_grouping; - iov[cnt].iov_len = monetary->mon_grouping_len; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->positive_sign; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->negative_sign; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_frac_digits; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->frac_digits; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->p_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->p_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->n_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->n_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->p_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->n_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->crncystr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_p_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_p_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_n_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_n_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_p_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->int_n_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->duo_int_curr_symbol; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->duo_currency_symbol; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_frac_digits; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_frac_digits; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_p_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_p_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_n_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_n_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_p_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_p_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_n_cs_precedes; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_n_sep_by_space; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_p_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_n_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_p_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_int_n_sign_posn; - iov[cnt].iov_len = 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - - /* Align following data */ - iov[cnt].iov_base = (void *) "\0\0"; - iov[cnt].iov_len = ((idx[cnt - 2] + 3) & ~3) - idx[cnt - 2]; - idx[cnt - 2] = (idx[cnt - 2] + 3) & ~3; - ++cnt; - - iov[cnt].iov_base = (void *) &monetary->uno_valid_from; - iov[cnt].iov_len = sizeof(uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->uno_valid_to; - iov[cnt].iov_len = sizeof(uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_valid_from; - iov[cnt].iov_len = sizeof(uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->duo_valid_to; - iov[cnt].iov_len = sizeof(uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) monetary->conversion_rate; - iov[cnt].iov_len = 2 * sizeof(uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->mon_decimal_point_wc; - iov[cnt].iov_len = sizeof (uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &monetary->mon_thousands_sep_wc; - iov[cnt].iov_len = sizeof (uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 3 + _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY)); - - write_locale_data (output_path, "LC_MONETARY", - 3 + _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY), iov); -} - - -static int -curr_strcmp (const char *s1, const char **s2) -{ - return strcmp (s1, *s2); -} - - -/* The parser for the LC_MONETARY section of the locale definition. */ -void -monetary_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_monetary_t *monetary; - struct token *now; - enum token_t nowtok; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_MONETARY' must be free. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_monetary, - LC_MONETARY, "LC_MONETARY", ignore_content); - return; - } - - /* Prepare the data structures. */ - monetary_startup (ldfile, result, ignore_content); - monetary = result->categories[LC_MONETARY].monetary; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ignore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - now = lr_token (ldfile, charmap, NULL, verbose); \ - if (now->tok != tok_string) \ - goto err_label; \ - else if (monetary->cat != NULL) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_MONETARY", #cat); \ - else if (!ignore_content && now->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_MONETARY", #cat); \ - monetary->cat = ""; \ - } \ - else if (!ignore_content) \ - monetary->cat = now->val.str.startmb; \ - lr_ignore_rest (ldfile, 1); \ - break - - STR_ELEM (int_curr_symbol); - STR_ELEM (currency_symbol); - STR_ELEM (positive_sign); - STR_ELEM (negative_sign); - STR_ELEM (duo_int_curr_symbol); - STR_ELEM (duo_currency_symbol); - -#define STR_ELEM_WC(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - ldfile->return_widestr = 1; \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_string) \ - goto err_label; \ - if (monetary->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_MONETARY", #cat); \ - else if (!ignore_content && now->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_MONETARY", #cat); \ - monetary->cat = ""; \ - monetary->cat##_wc = L'\0'; \ - } \ - else if (now->val.str.startwc != NULL && now->val.str.lenwc > 2) \ - { \ - lr_error (ldfile, _("\ -%s: value for field `%s' must be a single character"), "LC_MONETARY", #cat); \ - } \ - else if (!ignore_content) \ - { \ - monetary->cat = now->val.str.startmb; \ - \ - if (now->val.str.startwc != NULL) \ - monetary->cat##_wc = *now->val.str.startwc; \ - } \ - ldfile->return_widestr = 0; \ - break - - STR_ELEM_WC (mon_decimal_point); - STR_ELEM_WC (mon_thousands_sep); - -#define INT_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - now = lr_token (ldfile, charmap, NULL, verbose); \ - if (now->tok != tok_minus1 && now->tok != tok_number) \ - goto err_label; \ - else if (monetary->cat != -2) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_MONETARY", #cat); \ - else if (!ignore_content) \ - monetary->cat = now->tok == tok_minus1 ? -1 : now->val.num; \ - break - - INT_ELEM (int_frac_digits); - INT_ELEM (frac_digits); - INT_ELEM (p_cs_precedes); - INT_ELEM (p_sep_by_space); - INT_ELEM (n_cs_precedes); - INT_ELEM (n_sep_by_space); - INT_ELEM (p_sign_posn); - INT_ELEM (n_sign_posn); - INT_ELEM (int_p_cs_precedes); - INT_ELEM (int_p_sep_by_space); - INT_ELEM (int_n_cs_precedes); - INT_ELEM (int_n_sep_by_space); - INT_ELEM (int_p_sign_posn); - INT_ELEM (int_n_sign_posn); - INT_ELEM (duo_int_frac_digits); - INT_ELEM (duo_frac_digits); - INT_ELEM (duo_p_cs_precedes); - INT_ELEM (duo_p_sep_by_space); - INT_ELEM (duo_n_cs_precedes); - INT_ELEM (duo_n_sep_by_space); - INT_ELEM (duo_p_sign_posn); - INT_ELEM (duo_n_sign_posn); - INT_ELEM (duo_int_p_cs_precedes); - INT_ELEM (duo_int_p_sep_by_space); - INT_ELEM (duo_int_n_cs_precedes); - INT_ELEM (duo_int_n_sep_by_space); - INT_ELEM (duo_int_p_sign_posn); - INT_ELEM (duo_int_n_sign_posn); - INT_ELEM (uno_valid_from); - INT_ELEM (uno_valid_to); - INT_ELEM (duo_valid_from); - INT_ELEM (duo_valid_to); - - case tok_mon_grouping: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_minus1 && now->tok != tok_number) - goto err_label; - else - { - size_t act = 0; - size_t max = 10; - char *grouping = ignore_content ? NULL : xmalloc (max); - - do - { - if (act + 1 >= max) - { - max *= 2; - grouping = xrealloc (grouping, max); - } - - if (act > 0 && grouping[act - 1] == '\177') - { - lr_error (ldfile, _("\ -%s: `-1' must be last entry in `%s' field"), - "LC_MONETARY", "mon_grouping"); - lr_ignore_rest (ldfile, 0); - break; - } - - if (now->tok == tok_minus1) - { - if (!ignore_content) - grouping[act++] = '\177'; - } - else if (now->val.num == 0) - { - /* A value of 0 disables grouping from here on but - we must not store a NUL character since this - terminates the string. Use something different - which must not be used otherwise. */ - if (!ignore_content) - grouping[act++] = '\377'; - } - else if (now->val.num > 126) - lr_error (ldfile, _("\ -%s: values for field `%s' must be smaller than 127"), - "LC_MONETARY", "mon_grouping"); - else if (!ignore_content) - grouping[act++] = now->val.num; - - /* Next must be semicolon. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - break; - - now = lr_token (ldfile, charmap, NULL, verbose); - } - while (now->tok == tok_minus1 || now->tok == tok_number); - - if (now->tok != tok_eol) - goto err_label; - - if (!ignore_content) - { - grouping[act++] = '\0'; - - monetary->mon_grouping = xrealloc (grouping, act); - monetary->mon_grouping_len = act; - } - } - break; - - case tok_conversion_rate: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_number) - goto err_label; - if (now->val.num == 0) - { - invalid_conversion_rate: - lr_error (ldfile, _("conversion rate value cannot be zero")); - if (!ignore_content) - { - monetary->conversion_rate[0] = 1; - monetary->conversion_rate[1] = 1; - } - break; - } - if (!ignore_content) - monetary->conversion_rate[0] = now->val.num; - /* Next must be a semicolon. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - goto err_label; - /* And another number. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_number) - goto err_label; - if (now->val.num == 0) - goto invalid_conversion_rate; - if (!ignore_content) - monetary->conversion_rate[1] = now->val.num; - /* The rest of the line must be empty. */ - lr_ignore_rest (ldfile, 1); - break; - - case tok_end: - /* Next we assume `LC_MONETARY'. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_eof) - break; - if (now->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_MONETARY"); - else if (now->tok != tok_lc_monetary) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_MONETARY"); - lr_ignore_rest (ldfile, now->tok == tok_lc_monetary); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_MONETARY"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_MONETARY"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-name.c b/src/system/libroot/posix/glibc/locale/programs/ld-name.c deleted file mode 100644 index 423f1707c2..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-name.c +++ /dev/null @@ -1,322 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_NAME locale. */ -struct locale_name_t -{ - const char *name_fmt; - const char *name_gen; - const char *name_mr; - const char *name_mrs; - const char *name_miss; - const char *name_ms; -}; - - -static void -name_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_NAME].name = - (struct locale_name_t *) xcalloc (1, sizeof (struct locale_name_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -name_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_name_t *name = locale->categories[LC_NAME].name; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (name == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_NAME] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_NAME, from->copy_name[LC_NAME], - from->repertoire_name, charmap); - while (from->categories[LC_NAME].name == NULL - && from->copy_name[LC_NAME] != NULL); - - name = locale->categories[LC_NAME].name - = from->categories[LC_NAME].name; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (name == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), "LC_NAME"); - name_startup (NULL, locale, 0); - name = locale->categories[LC_NAME].name; - nothing = 1; - } - } - - if (name->name_fmt == NULL) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_NAME", "name_fmt"); - /* Use as the default value the value of the i18n locale. */ - name->name_fmt = "%p%t%g%t%m%t%f"; - } - else - { - /* We must check whether the format string contains only the - allowed escape sequences. */ - const char *cp = name->name_fmt; - - if (*cp == '\0') - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_NAME", "name_fmt"); - else - while (*cp != '\0') - { - if (*cp == '%') - { - if (*++cp == 'R') - /* Romanize-flag. */ - ++cp; - if (strchr ("dfFgGlomMpsSt", *cp) == NULL) - { - error (0, 0, _("\ -%s: invalid escape sequence in field `%s'"), - "LC_NAME", "name_fmt"); - break; - } - } - ++cp; - } - } - -#define TEST_ELEM(cat) \ - if (name->cat == NULL) \ - { \ - if (verbose && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_NAME", #cat); \ - name->cat = ""; \ - } - - TEST_ELEM (name_gen); - TEST_ELEM (name_mr); - TEST_ELEM (name_mrs); - TEST_ELEM (name_miss); - TEST_ELEM (name_ms); -} - - -void -name_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_name_t *name = locale->categories[LC_NAME].name; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_NAME)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_NAME); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_NAME); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) name->name_fmt; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) name->name_gen; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) name->name_mr; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) name->name_mrs; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) name->name_miss; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) name->name_ms; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME)); - - write_locale_data (output_path, "LC_NAME", - 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME), iov); -} - - -/* The parser for the LC_NAME section of the locale definition. */ -void -name_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_name_t *name; - struct token *now; - struct token *arg; - enum token_t nowtok; - - /* The rest of the line containing `LC_NAME' must be empty. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_name, - LC_NAME, "LC_NAME", ignore_content); - return; - } - - /* Prepare the data structures. */ - name_startup (ldfile, result, ignore_content); - name = result->categories[LC_NAME].name; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ignore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_string) \ - goto err_label; \ - if (name->cat != NULL) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_NAME", #cat); \ - else if (!ignore_content && arg->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("%s: unknown character in field `%s'"), \ - "LC_NAME", #cat); \ - name->cat = ""; \ - } \ - else if (!ignore_content) \ - name->cat = arg->val.str.startmb; \ - break - - STR_ELEM (name_fmt); - STR_ELEM (name_gen); - STR_ELEM (name_mr); - STR_ELEM (name_mrs); - STR_ELEM (name_miss); - STR_ELEM (name_ms); - - case tok_end: - /* Next we assume `LC_NAME'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_NAME"); - else if (arg->tok != tok_lc_name) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_NAME"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_name); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_NAME"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_NAME"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-numeric.c b/src/system/libroot/posix/glibc/locale/programs/ld-numeric.c deleted file mode 100644 index 886dd9d27f..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-numeric.c +++ /dev/null @@ -1,392 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include - -#include "linereader.h" -#include "localedef.h" -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_NUMERIC locale. */ -struct locale_numeric_t -{ - const char *decimal_point; - const char *thousands_sep; - char *grouping; - size_t grouping_len; - uint32_t decimal_point_wc; - uint32_t thousands_sep_wc; -}; - - -static void -numeric_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - { - locale->categories[LC_NUMERIC].numeric = - (struct locale_numeric_t *) xcalloc (1, - sizeof (struct locale_numeric_t)); - } - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -numeric_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_numeric_t *numeric = locale->categories[LC_NUMERIC].numeric; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (numeric == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_NUMERIC] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_NUMERIC, from->copy_name[LC_NUMERIC], - from->repertoire_name, charmap); - while (from->categories[LC_NUMERIC].numeric == NULL - && from->copy_name[LC_NUMERIC] != NULL); - - numeric = locale->categories[LC_NUMERIC].numeric - = from->categories[LC_NUMERIC].numeric; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (numeric == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_NUMERIC"); - numeric_startup (NULL, locale, 0); - numeric = locale->categories[LC_NUMERIC].numeric; - nothing = 1; - } - } - - /* The decimal point must not be empty. This is not said explicitly - in POSIX but ANSI C (ISO/IEC 9899) says in 4.4.2.1 it has to be - != "". */ - if (numeric->decimal_point == NULL) - { - if (! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_NUMERIC", "decimal_point"); - numeric->decimal_point = "."; - } - else if (numeric->decimal_point[0] == '\0' && ! be_quiet && ! nothing) - { - error (0, 0, _("\ -%s: value for field `%s' must not be the empty string"), - "LC_NUMERIC", "decimal_point"); - } - if (numeric->decimal_point_wc == L'\0') - numeric->decimal_point_wc = L'.'; - - if (numeric->grouping_len == 0 && ! be_quiet && ! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_NUMERIC", "grouping"); -} - - -void -numeric_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_numeric_t *numeric = locale->categories[LC_NUMERIC].numeric; - struct iovec iov[3 + _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_NUMERIC); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) (numeric->decimal_point ?: ""); - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) (numeric->thousands_sep ?: ""); - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = numeric->grouping; - iov[cnt].iov_len = numeric->grouping_len; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - - /* Align following data */ - iov[cnt].iov_base = (void *) "\0\0"; - iov[cnt].iov_len = ((idx[cnt - 2] + 3) & ~3) - idx[cnt - 2]; - idx[cnt - 2] = (idx[cnt - 2] + 3) & ~3; - ++cnt; - - iov[cnt].iov_base = (void *) &numeric->decimal_point_wc; - iov[cnt].iov_len = sizeof (uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) &numeric->thousands_sep_wc; - iov[cnt].iov_len = sizeof (uint32_t); - ++cnt; - - idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - - assert (cnt + 1 == 3 + _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC)); - - write_locale_data (output_path, "LC_NUMERIC", - 3 + _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC), iov); -} - - -/* The parser for the LC_NUMERIC section of the locale definition. */ -void -numeric_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_numeric_t *numeric; - struct token *now; - enum token_t nowtok; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_NUMERIC' must be free. */ - lr_ignore_rest (ldfile, 1); - - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_numeric, - LC_NUMERIC, "LC_NUMERIC", ignore_content); - return; - } - - /* Prepare the data structures. */ - numeric_startup (ldfile, result, ignore_content); - numeric = result->categories[LC_NUMERIC].numeric; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - ldfile->return_widestr = 1; \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_string) \ - goto err_label; \ - if (numeric->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_NUMERIC", #cat); \ - else if (!ignore_content && now->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("\ -%s: unknown character in field `%s'"), "LC_NUMERIC", #cat); \ - numeric->cat = ""; \ - numeric->cat##_wc = L'\0'; \ - } \ - else if (now->val.str.startwc != NULL && now->val.str.lenwc > 2) \ - { \ - lr_error (ldfile, _("\ -%s: value for field `%s' must be a single character"), "LC_NUMERIC", #cat); \ - } \ - else if (!ignore_content) \ - { \ - numeric->cat = now->val.str.startmb; \ - \ - if (now->val.str.startwc != NULL) \ - numeric->cat##_wc = *now->val.str.startwc; \ - } \ - ldfile->return_widestr = 0; \ - break - - STR_ELEM (decimal_point); - STR_ELEM (thousands_sep); - - case tok_grouping: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_minus1 && now->tok != tok_number) - goto err_label; - else - { - size_t act = 0; - size_t max = 10; - char *grouping = ignore_content ? NULL : xmalloc (max); - - do - { - if (act + 1 >= max) - { - max *= 2; - grouping = xrealloc (grouping, max); - } - - if (act > 0 && grouping[act - 1] == '\177') - { - lr_error (ldfile, _("\ -%s: `-1' must be last entry in `%s' field"), "LC_NUMERIC", "grouping"); - lr_ignore_rest (ldfile, 0); - break; - } - - if (now->tok == tok_minus1) - { - if (!ignore_content) - grouping[act++] = '\177'; - } - else if (now->val.num == 0) - { - /* A value of 0 disables grouping from here on but - we must not store a NUL character since this - terminates the string. Use something different - which must not be used otherwise. */ - if (!ignore_content) - grouping[act++] = '\377'; - } - else if (now->val.num > 126) - lr_error (ldfile, _("\ -%s: values for field `%s' must be smaller than 127"), - "LC_NUMERIC", "grouping"); - else if (!ignore_content) - grouping[act++] = now->val.num; - - /* Next must be semicolon. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_semicolon) - break; - - now = lr_token (ldfile, charmap, NULL, verbose); - } - while (now->tok == tok_minus1 || now->tok == tok_number); - - if (now->tok != tok_eol) - goto err_label; - - if (!ignore_content) - { - grouping[act++] = '\0'; - - numeric->grouping = xrealloc (grouping, act); - numeric->grouping_len = act; - } - } - break; - - case tok_end: - /* Next we assume `LC_NUMERIC'. */ - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok == tok_eof) - break; - if (now->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_NUMERIC"); - else if (now->tok != tok_lc_numeric) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_NUMERIC"); - lr_ignore_rest (ldfile, now->tok == tok_lc_numeric); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_NUMERIC"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_NUMERIC"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-paper.c b/src/system/libroot/posix/glibc/locale/programs/ld-paper.c deleted file mode 100644 index 2fc78202a2..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-paper.c +++ /dev/null @@ -1,255 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_PAPER locale. */ -struct locale_paper_t -{ - uint32_t height; - uint32_t width; -}; - - -static void -paper_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_PAPER].paper = - (struct locale_paper_t *) xcalloc (1, sizeof (struct locale_paper_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -paper_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_paper_t *paper = locale->categories[LC_PAPER].paper; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (paper == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_PAPER] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_PAPER, from->copy_name[LC_PAPER], - from->repertoire_name, charmap); - while (from->categories[LC_PAPER].paper == NULL - && from->copy_name[LC_PAPER] != NULL); - - paper = locale->categories[LC_PAPER].paper - = from->categories[LC_PAPER].paper; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (paper == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), "LC_PAPER"); - paper_startup (NULL, locale, 0); - paper = locale->categories[LC_PAPER].paper; - nothing = 1; - } - } - - if (paper->height == 0) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_PAPER", "height"); - /* Use as default values the values from the i18n locale. */ - paper->height = 297; - } - - if (paper->width == 0) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), "LC_PAPER", "width"); - /* Use as default values the values from the i18n locale. */ - paper->width = 210; - } -} - - -void -paper_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_paper_t *paper = locale->categories[LC_PAPER].paper; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_PAPER)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_PAPER); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_PAPER); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[cnt - 2].iov_len + iov[cnt - 1].iov_len; - iov[cnt].iov_base = &paper->height; - iov[cnt].iov_len = 4; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = &paper->width; - iov[cnt].iov_len = 4; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER)); - - write_locale_data (output_path, "LC_PAPER", - 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER), iov); -} - - -/* The parser for the LC_PAPER section of the locale definition. */ -void -paper_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_paper_t *paper; - struct token *now; - struct token *arg; - enum token_t nowtok; - - /* The rest of the line containing `LC_PAPER' must be empty. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_paper, - LC_PAPER, "LC_PAPER", ignore_content); - return; - } - - /* Prepare the data structures. */ - paper_startup (ldfile, result, ignore_content); - paper = result->categories[LC_PAPER].paper; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define INT_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_number) \ - goto err_label; \ - else if (paper->cat != 0) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_PAPER", #cat); \ - else if (!ignore_content) \ - paper->cat = arg->val.num; \ - break - - INT_ELEM (height); - INT_ELEM (width); - - case tok_end: - /* Next we assume `LC_PAPER'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_PAPER"); - else if (arg->tok != tok_lc_paper) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_PAPER"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_paper); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_PAPER"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-telephone.c b/src/system/libroot/posix/glibc/locale/programs/ld-telephone.c deleted file mode 100644 index 31cfd25041..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-telephone.c +++ /dev/null @@ -1,330 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#include - -#include "localeinfo.h" -#include "locfile.h" - - -/* The real definition of the struct for the LC_TELEPHONE locale. */ -struct locale_telephone_t -{ - const char *tel_int_fmt; - const char *tel_dom_fmt; - const char *int_select; - const char *int_prefix; -}; - - -static void -telephone_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_TELEPHONE].telephone = (struct locale_telephone_t *) - xcalloc (1, sizeof (struct locale_telephone_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 0; - } -} - - -void -telephone_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_telephone_t *telephone = - locale->categories[LC_TELEPHONE].telephone; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (telephone == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_TELEPHONE] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_TELEPHONE, from->copy_name[LC_TELEPHONE], - from->repertoire_name, charmap); - while (from->categories[LC_TELEPHONE].telephone == NULL - && from->copy_name[LC_TELEPHONE] != NULL); - - telephone = locale->categories[LC_TELEPHONE].telephone - = from->categories[LC_TELEPHONE].telephone; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (telephone == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), - "LC_TELEPHONE"); - telephone_startup (NULL, locale, 0); - telephone = locale->categories[LC_TELEPHONE].telephone; - nothing = 1; - } - } - - if (telephone->tel_int_fmt == NULL) - { - if (! nothing) - error (0, 0, _("%s: field `%s' not defined"), - "LC_TELEPHONE", "tel_int_fmt"); - /* Use as the default value the value of the i18n locale. */ - telephone->tel_int_fmt = "+%c %a %l"; - } - else - { - /* We must check whether the format string contains only the - allowed escape sequences. */ - const char *cp = telephone->tel_int_fmt; - - if (*cp == '\0') - error (0, 0, _("%s: field `%s' must not be empty"), - "LC_TELEPHONE", "tel_int_fmt"); - else - while (*cp != '\0') - { - if (*cp == '%') - { - if (strchr ("aAlc", *++cp) == NULL) - { - error (0, 0, _("\ -%s: invalid escape sequence in field `%s'"), - "LC_TELEPHONE", "tel_int_fmt"); - break; - } - } - ++cp; - } - } - - if (telephone->tel_dom_fmt == NULL) - telephone->tel_dom_fmt = ""; - else if (telephone->tel_dom_fmt[0] != '\0') - { - /* We must check whether the format string contains only the - allowed escape sequences. */ - const char *cp = telephone->tel_dom_fmt; - - while (*cp != '\0') - { - if (*cp == '%') - { - if (strchr ("aAlc", *++cp) == NULL) - { - error (0, 0, _("%s: invalid escape sequence in field `%s'"), - "LC_TELEPHONE", "tel_dom_fmt"); - break; - } - } - ++cp; - } - } - -#define TEST_ELEM(cat) \ - if (telephone->cat == NULL) \ - { \ - if (verbose && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_TELEPHONE", #cat); \ - telephone->cat = ""; \ - } - - TEST_ELEM (int_select); - TEST_ELEM (int_prefix); -} - - -void -telephone_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_telephone_t *telephone = - locale->categories[LC_TELEPHONE].telephone; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE)]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE)]; - size_t cnt = 0; - - data.magic = LIMAGIC (LC_TELEPHONE); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE); - iov[cnt].iov_base = (void *) &data; - iov[cnt].iov_len = sizeof (data); - ++cnt; - - iov[cnt].iov_base = (void *) idx; - iov[cnt].iov_len = sizeof (idx); - ++cnt; - - idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; - iov[cnt].iov_base = (void *) telephone->tel_int_fmt; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) telephone->tel_dom_fmt; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) telephone->int_select; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) telephone->int_prefix; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; - iov[cnt].iov_base = (void *) charmap->code_set_name;; - iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1; - ++cnt; - - assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE)); - - write_locale_data (output_path, "LC_TELEPHONE", - 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE), iov); -} - - -/* The parser for the LC_TELEPHONE section of the locale definition. */ -void -telephone_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct locale_telephone_t *telephone; - struct token *now; - struct token *arg; - enum token_t nowtok; - - /* The rest of the line containing `LC_TELEPHONE' must be free. */ - lr_ignore_rest (ldfile, 1); - - do - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_telephone, - LC_TELEPHONE, "LC_TELEPHONE", ignore_content); - return; - } - - /* Prepare the data structures. */ - telephone_startup (ldfile, result, ignore_content); - telephone = result->categories[LC_TELEPHONE].telephone; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - arg = lr_token (ldfile, charmap, NULL, verbose); \ - if (arg->tok != tok_string) \ - goto err_label; \ - if (telephone->cat != NULL) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_TELEPHONE", #cat); \ - else if (!ignore_content && arg->val.str.startmb == NULL) \ - { \ - lr_error (ldfile, _("%s: unknown character in field `%s'"), \ - "LC_TELEPHONE", #cat); \ - telephone->cat = ""; \ - } \ - else if (!ignore_content) \ - telephone->cat = arg->val.str.startmb; \ - break - - STR_ELEM (tel_int_fmt); - STR_ELEM (tel_dom_fmt); - STR_ELEM (int_select); - STR_ELEM (int_prefix); - - case tok_end: - /* Next we assume `LC_TELEPHONE'. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - if (arg->tok == tok_eof) - break; - if (arg->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_TELEPHONE"); - else if (arg->tok != tok_lc_telephone) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_TELEPHONE"); - lr_ignore_rest (ldfile, arg->tok == tok_lc_telephone); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_TELEPHONE"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, NULL, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_TELEPHONE"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/ld-time.c b/src/system/libroot/posix/glibc/locale/programs/ld-time.c deleted file mode 100644 index 6245b0f05e..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/ld-time.c +++ /dev/null @@ -1,1216 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -#include - -#include "linereader.h" -#include "localedef.h" -#include "localeinfo.h" -#include "locfile.h" - - -/* Entry describing an entry of the era specification. */ -struct era_data -{ - int32_t direction; - int32_t offset; - int32_t start_date[3]; - int32_t stop_date[3]; - const char *name; - const char *format; - uint32_t *wname; - uint32_t *wformat; -}; - - -/* The real definition of the struct for the LC_TIME locale. */ -struct locale_time_t -{ - const char *abday[7]; - const uint32_t *wabday[7]; - int abday_defined; - const char *day[7]; - const uint32_t *wday[7]; - int day_defined; - const char *abmon[12]; - const uint32_t *wabmon[12]; - int abmon_defined; - const char *mon[12]; - const uint32_t *wmon[12]; - int mon_defined; - const char *am_pm[2]; - const uint32_t *wam_pm[2]; - int am_pm_defined; - const char *d_t_fmt; - const uint32_t *wd_t_fmt; - const char *d_fmt; - const uint32_t *wd_fmt; - const char *t_fmt; - const uint32_t *wt_fmt; - const char *t_fmt_ampm; - const uint32_t *wt_fmt_ampm; - const char **era; - const uint32_t **wera; - uint32_t num_era; - const char *era_year; - const uint32_t *wera_year; - const char *era_d_t_fmt; - const uint32_t *wera_d_t_fmt; - const char *era_t_fmt; - const uint32_t *wera_t_fmt; - const char *era_d_fmt; - const uint32_t *wera_d_fmt; - const char *alt_digits[100]; - const uint32_t *walt_digits[100]; - const char *date_fmt; - const uint32_t *wdate_fmt; - int alt_digits_defined; - unsigned char week_ndays; - uint32_t week_1stday; - unsigned char week_1stweek; - unsigned char first_weekday; - unsigned char first_workday; - unsigned char cal_direction; - const char *timezone; - const uint32_t *wtimezone; - - struct era_data *era_entries; -}; - - -/* This constant is used to represent an empty wide character string. */ -static const uint32_t empty_wstr[1] = { 0 }; - - -static void -time_startup (struct linereader *lr, struct localedef_t *locale, - int ignore_content) -{ - if (!ignore_content) - locale->categories[LC_TIME].time = - (struct locale_time_t *) xcalloc (1, sizeof (struct locale_time_t)); - - if (lr != NULL) - { - lr->translate_strings = 1; - lr->return_widestr = 1; - } -} - - -void -time_finish (struct localedef_t *locale, struct charmap_t *charmap) -{ - struct locale_time_t *time = locale->categories[LC_TIME].time; - int nothing = 0; - - /* Now resolve copying and also handle completely missing definitions. */ - if (time == NULL) - { - /* First see whether we were supposed to copy. If yes, find the - actual definition. */ - if (locale->copy_name[LC_TIME] != NULL) - { - /* Find the copying locale. This has to happen transitively since - the locale we are copying from might also copying another one. */ - struct localedef_t *from = locale; - - do - from = find_locale (LC_TIME, from->copy_name[LC_TIME], - from->repertoire_name, charmap); - while (from->categories[LC_TIME].time == NULL - && from->copy_name[LC_TIME] != NULL); - - time = locale->categories[LC_TIME].time - = from->categories[LC_TIME].time; - } - - /* If there is still no definition issue an warning and create an - empty one. */ - if (time == NULL) - { - if (! be_quiet) - error (0, 0, _("No definition for %s category found"), "LC_TIME"); - time_startup (NULL, locale, 0); - time = locale->categories[LC_TIME].time; - nothing = 1; - } - } - -#define noparen(arg1, argn...) arg1, ##argn -#define TESTARR_ELEM(cat, val) \ - if (!time->cat##_defined) \ - { \ - const char *initval[] = { noparen val }; \ - int i; \ - \ - if (! be_quiet && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_TIME", #cat); \ - \ - for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \ - time->cat[i] = initval[i]; \ - } - - TESTARR_ELEM (abday, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" )); - TESTARR_ELEM (day, ( "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" )); - TESTARR_ELEM (abmon, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" )); - TESTARR_ELEM (mon, ( "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December" )); - TESTARR_ELEM (am_pm, ( "AM", "PM" )); - -#define TEST_ELEM(cat, initval) \ - if (time->cat == NULL) \ - { \ - if (! be_quiet && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_TIME", #cat); \ - \ - time->cat = initval; \ - } - - TEST_ELEM (d_t_fmt, "%a %b %e %H:%M:%S %Y"); - TEST_ELEM (d_fmt, "%m/%d/%y"); - TEST_ELEM (t_fmt, "%H:%M:%S"); - - /* According to C.Y.Alexis Cheng the T_FMT_AMPM - field is optional. */ - if (time->t_fmt_ampm == NULL) - { - if (time->am_pm[0][0] == '\0' && time->am_pm[1][0] == '\0') - { - /* No AM/PM strings defined, use the 24h format as default. */ - time->t_fmt_ampm = time->t_fmt; - time->wt_fmt_ampm = time->wt_fmt; - } - else - { - time->t_fmt_ampm = "%I:%M:%S %p"; - time->wt_fmt_ampm = (const uint32_t *) L"%I:%M:%S %p"; - } - } - - /* Now process the era entries. */ - if (time->num_era != 0) - { - const int days_per_month[12] = { 31, 29, 31, 30, 31, 30, - 31, 31, 30, 31 ,30, 31 }; - size_t idx; - wchar_t *wstr; - - time->era_entries = - (struct era_data *) xmalloc (time->num_era - * sizeof (struct era_data)); - - for (idx = 0; idx < time->num_era; ++idx) - { - size_t era_len = strlen (time->era[idx]); - char *str = xmalloc ((era_len + 1 + 3) & ~3); - char *endp; - - memcpy (str, time->era[idx], era_len + 1); - - /* First character must be + or - for the direction. */ - if (*str != '+' && *str != '-') - { - if (!be_quiet) - error (0, 0, - _("%s: direction flag in string %Zd in `era' field" - " is not '+' nor '-'"), - "LC_TIME", idx + 1); - /* Default arbitrarily to '+'. */ - time->era_entries[idx].direction = '+'; - } - else - time->era_entries[idx].direction = *str; - if (*++str != ':') - { - if (!be_quiet) - error (0, 0, - _("%s: direction flag in string %Zd in `era' field" - " is not a single character"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else - ++str; - - /* Now the offset year. */ - time->era_entries[idx].offset = strtol (str, &endp, 10); - if (endp == str) - { - if (!be_quiet) - error (0, 0, _("%s: invalid number for offset in string %Zd in" - " `era' field"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else if (*endp != ':') - { - if (!be_quiet) - error (0, 0, _("%s: garbage at end of offset value in" - " string %Zd in `era' field"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else - str = endp + 1; - - /* Next is the starting date in ISO format. */ - if (strncmp (str, "-*", 2) == 0) - { - time->era_entries[idx].start_date[0] = - time->era_entries[idx].start_date[1] = - time->era_entries[idx].start_date[2] = 0x80000000; - if (str[2] != ':') - goto garbage_start_date; - str += 3; - } - else if (strncmp (str, "+*", 2) == 0) - { - time->era_entries[idx].start_date[0] = - time->era_entries[idx].start_date[1] = - time->era_entries[idx].start_date[2] = 0x7fffffff; - if (str[2] != ':') - goto garbage_start_date; - str += 3; - } - else - { - time->era_entries[idx].start_date[0] = strtol (str, &endp, 10); - if (endp == str || *endp != '/') - goto invalid_start_date; - else - str = endp + 1; - time->era_entries[idx].start_date[0] -= 1900; - /* year -1 represent 1 B.C. (not -1 A.D.) */ - if (time->era_entries[idx].start_date[0] < -1900) - ++time->era_entries[idx].start_date[0]; - - time->era_entries[idx].start_date[1] = strtol (str, &endp, 10); - if (endp == str || *endp != '/') - goto invalid_start_date; - else - str = endp + 1; - time->era_entries[idx].start_date[1] -= 1; - - time->era_entries[idx].start_date[2] = strtol (str, &endp, 10); - if (endp == str) - { - invalid_start_date: - if (!be_quiet) - error (0, 0, _("%s: invalid starting date in string %Zd in" - " `era' field"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else if (*endp != ':') - { - garbage_start_date: - if (!be_quiet) - error (0, 0, _("%s: garbage at end of starting date " - "in string %Zd in `era' field "), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else - { - str = endp + 1; - - /* Check for valid value. */ - if ((time->era_entries[idx].start_date[1] < 0 - || time->era_entries[idx].start_date[1] >= 12 - || time->era_entries[idx].start_date[2] < 0 - || (time->era_entries[idx].start_date[2] - > days_per_month[time->era_entries[idx].start_date[1]]) - || (time->era_entries[idx].start_date[1] == 2 - && time->era_entries[idx].start_date[2] == 29 - && !__isleap (time->era_entries[idx].start_date[0]))) - && !be_quiet) - error (0, 0, _("%s: starting date is invalid in" - " string %Zd in `era' field"), - "LC_TIME", idx + 1); - } - } - - /* Next is the stopping date in ISO format. */ - if (strncmp (str, "-*", 2) == 0) - { - time->era_entries[idx].stop_date[0] = - time->era_entries[idx].stop_date[1] = - time->era_entries[idx].stop_date[2] = 0x80000000; - if (str[2] != ':') - goto garbage_stop_date; - str += 3; - } - else if (strncmp (str, "+*", 2) == 0) - { - time->era_entries[idx].stop_date[0] = - time->era_entries[idx].stop_date[1] = - time->era_entries[idx].stop_date[2] = 0x7fffffff; - if (str[2] != ':') - goto garbage_stop_date; - str += 3; - } - else - { - time->era_entries[idx].stop_date[0] = strtol (str, &endp, 10); - if (endp == str || *endp != '/') - goto invalid_stop_date; - else - str = endp + 1; - time->era_entries[idx].stop_date[0] -= 1900; - /* year -1 represent 1 B.C. (not -1 A.D.) */ - if (time->era_entries[idx].stop_date[0] < -1900) - ++time->era_entries[idx].stop_date[0]; - - time->era_entries[idx].stop_date[1] = strtol (str, &endp, 10); - if (endp == str || *endp != '/') - goto invalid_stop_date; - else - str = endp + 1; - time->era_entries[idx].stop_date[1] -= 1; - - time->era_entries[idx].stop_date[2] = strtol (str, &endp, 10); - if (endp == str) - { - invalid_stop_date: - if (!be_quiet) - error (0, 0, _("%s: invalid stopping date in string %Zd in" - " `era' field"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else if (*endp != ':') - { - garbage_stop_date: - if (!be_quiet) - error (0, 0, _("%s: garbage at end of stopping date " - "in string %Zd in `era' field"), - "LC_TIME", idx + 1); - (void) strsep (&str, ":"); - } - else - { - str = endp + 1; - - /* Check for valid value. */ - if ((time->era_entries[idx].stop_date[1] < 0 - || time->era_entries[idx].stop_date[1] >= 12 - || time->era_entries[idx].stop_date[2] < 0 - || (time->era_entries[idx].stop_date[2] - > days_per_month[time->era_entries[idx].stop_date[1]]) - || (time->era_entries[idx].stop_date[1] == 2 - && time->era_entries[idx].stop_date[2] == 29 - && !__isleap (time->era_entries[idx].stop_date[0]))) - && !be_quiet) - error (0, 0, _("%s: stopping date is invalid in" - " string %Zd in `era' field"), - "LC_TIME", idx + 1); - } - } - - if (str == NULL || *str == '\0') - { - if (!be_quiet) - error (0, 0, _("%s: missing era name in string %Zd in `era'" - " field"), "LC_TIME", idx + 1); - time->era_entries[idx].name = - time->era_entries[idx].format = ""; - } - else - { - time->era_entries[idx].name = strsep (&str, ":"); - - if (str == NULL || *str == '\0') - { - if (!be_quiet) - error (0, 0, _("%s: missing era format in string %Zd" - " in `era' field"), - "LC_TIME", idx + 1); - time->era_entries[idx].name = - time->era_entries[idx].format = ""; - } - else - time->era_entries[idx].format = str; - } - - /* Now generate the wide character name and format. */ - wstr = wcschr ((wchar_t *) time->wera[idx], L':');/* end direction */ - wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end offset */ - wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end start */ - wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end end */ - time->era_entries[idx].wname = (uint32_t *) wstr + 1; - wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end name */ - *wstr = L'\0'; - time->era_entries[idx].wformat = (uint32_t *) wstr + 1; - } - } - - if (time->week_ndays == 0) - time->week_ndays = 7; - - if (time->week_1stday == 0) - time->week_1stday = 19971130; - - if (time->week_1stweek > time->week_ndays) - error (0, 0, _("\ -%s: third operand for value of field `%s' must not be larger than %d"), - "LC_TIME", "week", 7); - - if (time->first_weekday == '\0') - /* The definition does not specify this so the default is used. */ - time->first_weekday = 1; - else if (time->first_weekday > time->week_ndays) - error (0, 0, _("\ -%s: values of field `%s' must not be larger than %d"), - "LC_TIME", "first_weekday", 7); - - if (time->first_workday == '\0') - /* The definition does not specify this so the default is used. */ - time->first_workday = 1; - else if (time->first_workday > time->week_ndays) - error (0, 0, _("\ -%s: values of field `%s' must not be larger than %d"), - "LC_TIME", "first_workday", 7); - - if (time->cal_direction == '\0') - /* The definition does not specify this so the default is used. */ - time->cal_direction = 1; - else if (time->cal_direction > 3) - error (0, 0, _("\ -%s: values for field `%s' must not be larger than %d"), - "LC_TIME", "cal_direction", 3); - - /* XXX We don't perform any tests on the timezone value since this is - simply useless, stupid $&$!@... */ - if (time->timezone == NULL) - time->timezone = ""; - - if (time->date_fmt == NULL) - time->date_fmt = "%a %b %e %H:%M:%S %Z %Y"; - if (time->wdate_fmt == NULL) - time->wdate_fmt = (const uint32_t *) L"%a %b %e %H:%M:%S %Z %Y"; -} - - -void -time_output (struct localedef_t *locale, struct charmap_t *charmap, - const char *output_path) -{ - struct locale_time_t *time = locale->categories[LC_TIME].time; - struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME) - + time->num_era - 1 - + 2 * 99 - + 2 + time->num_era * 10 - 1]; - struct locale_file data; - uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_TIME)]; - size_t cnt, last_idx, num, n; - - data.magic = LIMAGIC (LC_TIME); - data.n = _NL_ITEM_INDEX (_NL_NUM_LC_TIME); - iov[0].iov_base = (void *) &data; - iov[0].iov_len = sizeof (data); - - iov[1].iov_base = (void *) idx; - iov[1].iov_len = sizeof (idx); - - idx[0] = iov[0].iov_len + iov[1].iov_len; - - /* The ab'days. */ - for (cnt = 0; cnt <= _NL_ITEM_INDEX (ABDAY_7); ++cnt) - { - iov[2 + cnt].iov_base = - (void *) (time->abday[cnt - _NL_ITEM_INDEX (ABDAY_1)] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - } - - /* The days. */ - for (; cnt <= _NL_ITEM_INDEX (DAY_7); ++cnt) - { - iov[2 + cnt].iov_base = - (void *) (time->day[cnt - _NL_ITEM_INDEX (DAY_1)] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - } - - /* The ab'mons. */ - for (; cnt <= _NL_ITEM_INDEX (ABMON_12); ++cnt) - { - iov[2 + cnt].iov_base = - (void *) (time->abmon[cnt - _NL_ITEM_INDEX (ABMON_1)] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - } - - /* The mons. */ - for (; cnt <= _NL_ITEM_INDEX (MON_12); ++cnt) - { - iov[2 + cnt].iov_base = - (void *) (time->mon[cnt - _NL_ITEM_INDEX (MON_1)] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - } - - /* AM/PM. */ - for (; cnt <= _NL_ITEM_INDEX (PM_STR); ++cnt) - { - iov[2 + cnt].iov_base = - (void *) (time->am_pm[cnt - _NL_ITEM_INDEX (AM_STR)] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - } - - iov[2 + cnt].iov_base = (void *) (time->d_t_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - iov[2 + cnt].iov_base = (void *) (time->d_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - iov[2 + cnt].iov_base = (void *) (time->t_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - ++cnt; - - iov[2 + cnt].iov_base = (void *) (time->t_fmt_ampm ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len; - last_idx = ++cnt; - - idx[1 + last_idx] = idx[last_idx]; - for (num = 0; num < time->num_era; ++num, ++cnt) - { - iov[2 + cnt].iov_base = (void *) time->era[num]; - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] += iov[2 + cnt].iov_len; - } - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->era_year ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->era_d_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - idx[1 + last_idx] = idx[last_idx]; - for (num = 0; num < 100; ++num, ++cnt) - { - iov[2 + cnt].iov_base = (void *) (time->alt_digits[num] ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] += iov[2 + cnt].iov_len; - } - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->era_d_t_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->era_t_fmt ?: ""); - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - - /* We must align the following data. */ - iov[2 + cnt].iov_base = (void *) "\0\0"; - iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx]; - idx[last_idx] = (idx[last_idx] + 3) & ~3; - ++cnt; - - /* The `era' data in usable form. */ - iov[2 + cnt].iov_base = (void *) &time->num_era; - iov[2 + cnt].iov_len = sizeof (uint32_t); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - idx[1 + last_idx] = idx[last_idx]; - for (num = 0; num < time->num_era; ++num) - { - size_t l; - - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].direction; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].offset; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[0]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[1]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[2]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[0]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[1]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[2]; - iov[2 + cnt].iov_len = sizeof (int32_t); - ++cnt; - - l = (strchr (time->era_entries[num].format, '\0') - - time->era_entries[num].name) + 1; - l = (l + 3) & ~3; - iov[2 + cnt].iov_base = (void *) time->era_entries[num].name; - iov[2 + cnt].iov_len = l; - ++cnt; - - idx[1 + last_idx] += 8 * sizeof (int32_t) + l; - - assert (idx[1 + last_idx] % 4 == 0); - - iov[2 + cnt].iov_base = (void *) time->era_entries[num].wname; - iov[2 + cnt].iov_len = ((wcschr ((wchar_t *) time->era_entries[num].wformat, L'\0') - - (wchar_t *) time->era_entries[num].wname + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] += iov[2 + cnt].iov_len; - ++cnt; - } - ++last_idx; - - /* The wide character ab'days. */ - for (n = 0; n < 7; ++n, ++cnt, ++last_idx) - { - iov[2 + cnt].iov_base = - (void *) (time->wabday[n] ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - } - - /* The wide character days. */ - for (n = 0; n < 7; ++n, ++cnt, ++last_idx) - { - iov[2 + cnt].iov_base = - (void *) (time->wday[n] ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - } - - /* The wide character ab'mons. */ - for (n = 0; n < 12; ++n, ++cnt, ++last_idx) - { - iov[2 + cnt].iov_base = - (void *) (time->wabmon[n] ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - } - - /* The wide character mons. */ - for (n = 0; n < 12; ++n, ++cnt, ++last_idx) - { - iov[2 + cnt].iov_base = - (void *) (time->wmon[n] ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - } - - /* Wide character AM/PM. */ - for (n = 0; n < 2; ++n, ++cnt, ++last_idx) - { - iov[2 + cnt].iov_base = - (void *) (time->wam_pm[n] ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - } - - iov[2 + cnt].iov_base = (void *) (time->wd_t_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wd_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wt_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wt_fmt_ampm ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wera_year ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wera_d_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - idx[1 + last_idx] = idx[last_idx]; - for (num = 0; num < 100; ++num, ++cnt) - { - iov[2 + cnt].iov_base = (void *) (time->walt_digits[num] - ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] += iov[2 + cnt].iov_len; - } - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wera_d_t_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) (time->wera_t_fmt ?: empty_wstr); - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) &time->week_ndays; - iov[2 + cnt].iov_len = 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - /* We must align the following data. */ - iov[2 + cnt].iov_base = (void *) "\0\0"; - iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx]; - idx[last_idx] = (idx[last_idx] + 3) & ~3; - ++cnt; - - iov[2 + cnt].iov_base = (void *) &time->week_1stday; - iov[2 + cnt].iov_len = sizeof(uint32_t); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) &time->week_1stweek; - iov[2 + cnt].iov_len = 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) &time->first_weekday; - iov[2 + cnt].iov_len = 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) &time->first_workday; - iov[2 + cnt].iov_len = 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) &time->cal_direction; - iov[2 + cnt].iov_len = 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) time->timezone; - iov[2 + cnt].iov_len = strlen (time->timezone) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) time->date_fmt; - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) time->wdate_fmt; - iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1) - * sizeof (uint32_t)); - idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len; - ++cnt; - ++last_idx; - - iov[2 + cnt].iov_base = (void *) charmap->code_set_name; - iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; - ++cnt; - ++last_idx; - - assert (cnt == (_NL_ITEM_INDEX (_NL_NUM_LC_TIME) - + time->num_era - 1 - + 2 * 99 - + 2 + time->num_era * 10 - 1)); - assert (last_idx == _NL_ITEM_INDEX (_NL_NUM_LC_TIME)); - - write_locale_data (output_path, "LC_TIME", 2 + cnt, iov); -} - - -/* The parser for the LC_TIME section of the locale definition. */ -void -time_read (struct linereader *ldfile, struct localedef_t *result, - struct charmap_t *charmap, const char *repertoire_name, - int ignore_content) -{ - struct repertoire_t *repertoire = NULL; - struct locale_time_t *time; - struct token *now; - enum token_t nowtok; - size_t cnt; - - /* Get the repertoire we have to use. */ - if (repertoire_name != NULL) - repertoire = repertoire_read (repertoire_name); - - /* The rest of the line containing `LC_TIME' must be free. */ - lr_ignore_rest (ldfile, 1); - - - do - { - now = lr_token (ldfile, charmap, repertoire, verbose); - nowtok = now->tok; - } - while (nowtok == tok_eol); - - /* If we see `copy' now we are almost done. */ - if (nowtok == tok_copy) - { - handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_time, - LC_TIME, "LC_TIME", ignore_content); - return; - } - - /* Prepare the data structures. */ - time_startup (ldfile, result, ignore_content); - time = result->categories[LC_TIME].time; - - while (1) - { - /* Of course we don't proceed beyond the end of file. */ - if (nowtok == tok_eof) - break; - - /* Ingore empty lines. */ - if (nowtok == tok_eol) - { - now = lr_token (ldfile, charmap, repertoire, verbose); - nowtok = now->tok; - continue; - } - - switch (nowtok) - { -#define STRARR_ELEM(cat, min, max) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - for (cnt = 0; cnt < max; ++cnt) \ - { \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok == tok_eol) \ - { \ - if (cnt < min) \ - lr_error (ldfile, _("%s: too few values for field `%s'"), \ - "LC_TIME", #cat); \ - if (!ignore_content) \ - do \ - { \ - time->cat[cnt] = ""; \ - time->w##cat[cnt] = empty_wstr; \ - } \ - while (++cnt < max); \ - break; \ - } \ - else if (now->tok != tok_string) \ - goto err_label; \ - else if (!ignore_content && (now->val.str.startmb == NULL \ - || now->val.str.startwc == NULL)) \ - { \ - lr_error (ldfile, _("%s: unknown character in field `%s'"), \ - "LC_TIME", #cat); \ - time->cat[cnt] = ""; \ - time->w##cat[cnt] = empty_wstr; \ - } \ - else if (!ignore_content) \ - { \ - time->cat[cnt] = now->val.str.startmb; \ - time->w##cat[cnt] = now->val.str.startwc; \ - } \ - \ - /* Match the semicolon. */ \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_semicolon && now->tok != tok_eol) \ - break; \ - } \ - if (now->tok != tok_eol) \ - { \ - while (!ignore_content && cnt < min) \ - { \ - time->cat[cnt] = ""; \ - time->w##cat[cnt++] = empty_wstr; \ - } \ - \ - if (now->tok == tok_semicolon) \ - { \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok == tok_eol) \ - lr_error (ldfile, _("extra trailing semicolon")); \ - else if (now->tok == tok_string) \ - { \ - lr_error (ldfile, _("\ -%s: too many values for field `%s'"), \ - "LC_TIME", #cat); \ - lr_ignore_rest (ldfile, 0); \ - } \ - else \ - goto err_label; \ - } \ - else \ - goto err_label; \ - } \ - time->cat##_defined = 1; \ - break - - STRARR_ELEM (abday, 7, 7); - STRARR_ELEM (day, 7, 7); - STRARR_ELEM (abmon, 12, 12); - STRARR_ELEM (mon, 12, 12); - STRARR_ELEM (am_pm, 2, 2); - STRARR_ELEM (alt_digits, 0, 100); - - case tok_era: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - do - { - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_string) - goto err_label; - if (!ignore_content && (now->val.str.startmb == NULL - || now->val.str.startwc == NULL)) - { - lr_error (ldfile, _("%s: unknown character in field `%s'"), - "LC_TIME", "era"); - lr_ignore_rest (ldfile, 0); - break; - } - if (!ignore_content) - { - time->era = xrealloc (time->era, - (time->num_era + 1) * sizeof (char *)); - time->era[time->num_era] = now->val.str.startmb; - - time->wera = xrealloc (time->wera, - (time->num_era + 1) - * sizeof (char *)); - time->wera[time->num_era++] = now->val.str.startwc; - } - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_eol && now->tok != tok_semicolon) - goto err_label; - } - while (now->tok == tok_semicolon); - break; - -#define STR_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_string) \ - goto err_label; \ - else if (time->cat != NULL) \ - lr_error (ldfile, _("\ -%s: field `%s' declared more than once"), "LC_TIME", #cat); \ - else if (!ignore_content && (now->val.str.startmb == NULL \ - || now->val.str.startwc == NULL)) \ - { \ - lr_error (ldfile, _("%s: unknown character in field `%s'"), \ - "LC_TIME", #cat); \ - time->cat = ""; \ - time->w##cat = empty_wstr; \ - } \ - else if (!ignore_content) \ - { \ - time->cat = now->val.str.startmb; \ - time->w##cat = now->val.str.startwc; \ - } \ - break - - STR_ELEM (d_t_fmt); - STR_ELEM (d_fmt); - STR_ELEM (t_fmt); - STR_ELEM (t_fmt_ampm); - STR_ELEM (era_year); - STR_ELEM (era_d_t_fmt); - STR_ELEM (era_d_fmt); - STR_ELEM (era_t_fmt); - STR_ELEM (timezone); - STR_ELEM (date_fmt); - -#define INT_ELEM(cat) \ - case tok_##cat: \ - /* Ignore the rest of the line if we don't need the input of \ - this line. */ \ - if (ignore_content) \ - { \ - lr_ignore_rest (ldfile, 0); \ - break; \ - } \ - \ - now = lr_token (ldfile, charmap, repertoire, verbose); \ - if (now->tok != tok_number) \ - goto err_label; \ - else if (time->cat != 0) \ - lr_error (ldfile, _("%s: field `%s' declared more than once"), \ - "LC_TIME", #cat); \ - else if (!ignore_content) \ - time->cat = now->val.num; \ - break - - INT_ELEM (first_weekday); - INT_ELEM (first_workday); - INT_ELEM (cal_direction); - - case tok_week: - /* Ignore the rest of the line if we don't need the input of - this line. */ - if (ignore_content) - { - lr_ignore_rest (ldfile, 0); - break; - } - - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_number) - goto err_label; - time->week_ndays = now->val.num; - - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_semicolon) - goto err_label; - - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_number) - goto err_label; - time->week_1stday = now->val.num; - - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_semicolon) - goto err_label; - - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok != tok_number) - goto err_label; - time->week_1stweek = now->val.num; - - lr_ignore_rest (ldfile, 1); - break; - - case tok_end: - /* Next we assume `LC_TIME'. */ - now = lr_token (ldfile, charmap, repertoire, verbose); - if (now->tok == tok_eof) - break; - if (now->tok == tok_eol) - lr_error (ldfile, _("%s: incomplete `END' line"), "LC_TIME"); - else if (now->tok != tok_lc_time) - lr_error (ldfile, _("\ -%1$s: definition does not end with `END %1$s'"), "LC_TIME"); - lr_ignore_rest (ldfile, now->tok == tok_lc_time); - return; - - default: - err_label: - SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME"); - } - - /* Prepare for the next round. */ - now = lr_token (ldfile, charmap, repertoire, verbose); - nowtok = now->tok; - } - - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), "LC_TIME"); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/linereader.c b/src/system/libroot/posix/glibc/locale/programs/linereader.c deleted file mode 100644 index ac843bcd2f..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/linereader.c +++ /dev/null @@ -1,821 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -#include "charmap.h" -#include "error.h" -#include "linereader.h" - -/* Prototypes for a few program-wide used functions. */ -extern void *xmalloc (size_t __n); -extern void *xrealloc (void *__p, size_t __n); -extern char *xstrdup (const char *__str); - - -/* Prototypes for local functions. */ -static struct token *get_toplvl_escape (struct linereader *lr); -static struct token *get_symname (struct linereader *lr); -static struct token *get_ident (struct linereader *lr); -static struct token *get_string (struct linereader *lr, - const struct charmap_t *charmap, - const struct repertoire_t *repertoire, - int verbose); - - -struct linereader * -lr_open (const char *fname, kw_hash_fct_t hf) -{ - FILE *fp; - - if (fname == NULL || strcmp (fname, "-") == 0 - || strcmp (fname, "/dev/stdin") == 0) - return lr_create (stdin, "", hf); - else - { - fp = fopen (fname, "r"); - if (fp == NULL) - return NULL; - return lr_create (fp, fname, hf); - } -} - -struct linereader * -lr_create (FILE *fp, const char *fname, kw_hash_fct_t hf) -{ - struct linereader *result; - int n; - - result = (struct linereader *) xmalloc (sizeof (*result)); - - result->fp = fp; - result->fname = xstrdup (fname); - result->buf = NULL; - result->bufsize = 0; - result->lineno = 1; - result->idx = 0; - result->comment_char = '#'; - result->escape_char = '\\'; - result->translate_strings = 1; - - n = getdelim (&result->buf, &result->bufsize, '\n', result->fp); - if (n < 0) - { - int save = errno; - fclose (result->fp); - free ((char *) result->fname); - free (result); - errno = save; - return NULL; - } - - if (n > 1 && result->buf[n - 2] == '\\' && result->buf[n - 1] == '\n') - n -= 2; - - result->buf[n] = '\0'; - result->bufact = n; - result->hash_fct = hf; - - return result; -} - - -int -lr_eof (struct linereader *lr) -{ - return lr->bufact = 0; -} - - -void -lr_close (struct linereader *lr) -{ - fclose (lr->fp); - free (lr->buf); - free (lr); -} - - -int -lr_next (struct linereader *lr) -{ - int n; - - n = getdelim (&lr->buf, &lr->bufsize, '\n', lr->fp); - if (n < 0) - return -1; - - ++lr->lineno; - - if (n > 1 && lr->buf[n - 2] == lr->escape_char && lr->buf[n - 1] == '\n') - { -#if 0 - /* XXX Is this correct? */ - /* An escaped newline character is substituted with a single . */ - --n; - lr->buf[n - 1] = ' '; -#else - n -= 2; -#endif - } - - lr->buf[n] = '\0'; - lr->bufact = n; - lr->idx = 0; - - return 0; -} - - -/* Defined in error.c. */ -/* This variable is incremented each time `error' is called. */ -extern unsigned int error_message_count; - -/* The calling program should define program_name and set it to the - name of the executing program. */ -extern char *program_name; - - -struct token * -lr_token (struct linereader *lr, const struct charmap_t *charmap, - const struct repertoire_t *repertoire, int verbose) -{ - int ch; - - while (1) - { - do - { - ch = lr_getc (lr); - - if (ch == EOF) - { - lr->token.tok = tok_eof; - return &lr->token; - }; - - if (ch == '\n') - { - lr->token.tok = tok_eol; - return &lr->token; - } - } - while (isspace (ch)); - - if (ch == EOF) - { - lr->token.tok = tok_eof; - return &lr->token; - }; - - if (ch != lr->comment_char) - break; - - /* Is there an newline at the end of the buffer? */ - if (lr->buf[lr->bufact - 1] != '\n') - { - /* No. Some people want this to mean that only the line in - the file not the logical, concatenated line is ignored. - Let's try this. */ - lr->idx = lr->bufact; - continue; - } - - /* Ignore rest of line. */ - lr_ignore_rest (lr, 0); - lr->token.tok = tok_eol; - return &lr->token; - } - - /* Match escape sequences. */ - if (ch == lr->escape_char) - return get_toplvl_escape (lr); - - /* Match ellipsis. */ - if (ch == '.') - { - if (strncmp (&lr->buf[lr->idx], "...(2)....", 10) == 0) - { - int cnt; - for (cnt = 0; cnt < 10; ++cnt) - lr_getc (lr); - lr->token.tok = tok_ellipsis4_2; - return &lr->token; - } - if (strncmp (&lr->buf[lr->idx], "...", 3) == 0) - { - lr_getc (lr); - lr_getc (lr); - lr_getc (lr); - lr->token.tok = tok_ellipsis4; - return &lr->token; - } - if (strncmp (&lr->buf[lr->idx], "..", 2) == 0) - { - lr_getc (lr); - lr_getc (lr); - lr->token.tok = tok_ellipsis3; - return &lr->token; - } - if (strncmp (&lr->buf[lr->idx], ".(2)..", 6) == 0) - { - int cnt; - for (cnt = 0; cnt < 6; ++cnt) - lr_getc (lr); - lr->token.tok = tok_ellipsis2_2; - return &lr->token; - } - if (lr->buf[lr->idx] == '.') - { - lr_getc (lr); - lr->token.tok = tok_ellipsis2; - return &lr->token; - } - } - - switch (ch) - { - case '<': - return get_symname (lr); - - case '0' ... '9': - lr->token.tok = tok_number; - lr->token.val.num = ch - '0'; - - while (isdigit (ch = lr_getc (lr))) - { - lr->token.val.num *= 10; - lr->token.val.num += ch - '0'; - } - if (isalpha (ch)) - lr_error (lr, _("garbage at end of number")); - lr_ungetn (lr, 1); - - return &lr->token; - - case ';': - lr->token.tok = tok_semicolon; - return &lr->token; - - case ',': - lr->token.tok = tok_comma; - return &lr->token; - - case '(': - lr->token.tok = tok_open_brace; - return &lr->token; - - case ')': - lr->token.tok = tok_close_brace; - return &lr->token; - - case '"': - return get_string (lr, charmap, repertoire, verbose); - - case '-': - ch = lr_getc (lr); - if (ch == '1') - { - lr->token.tok = tok_minus1; - return &lr->token; - } - lr_ungetn (lr, 2); - break; - } - - return get_ident (lr); -} - - -static struct token * -get_toplvl_escape (struct linereader *lr) -{ - /* This is supposed to be a numeric value. We return the - numerical value and the number of bytes. */ - size_t start_idx = lr->idx - 1; - char *bytes = lr->token.val.charcode.bytes; - int nbytes = 0; - int ch; - - do - { - unsigned int byte = 0; - unsigned int base = 8; - - ch = lr_getc (lr); - - if (ch == 'd') - { - base = 10; - ch = lr_getc (lr); - } - else if (ch == 'x') - { - base = 16; - ch = lr_getc (lr); - } - - if ((base == 16 && !isxdigit (ch)) - || (base != 16 && (ch < '0' || ch >= (int) ('0' + base)))) - { - esc_error: - lr->token.val.str.startmb = &lr->buf[start_idx]; - - while (ch != EOF && !isspace (ch)) - ch = lr_getc (lr); - lr->token.val.str.lenmb = lr->idx - start_idx; - - lr->token.tok = tok_error; - return &lr->token; - } - - if (isdigit (ch)) - byte = ch - '0'; - else - byte = tolower (ch) - 'a' + 10; - - ch = lr_getc (lr); - if ((base == 16 && !isxdigit (ch)) - || (base != 16 && (ch < '0' || ch >= (int) ('0' + base)))) - goto esc_error; - - byte *= base; - if (isdigit (ch)) - byte += ch - '0'; - else - byte += tolower (ch) - 'a' + 10; - - ch = lr_getc (lr); - if (base != 16 && isdigit (ch)) - { - byte *= base; - byte += ch - '0'; - - ch = lr_getc (lr); - } - - bytes[nbytes++] = byte; - } - while (ch == lr->escape_char - && nbytes < sizeof (lr->token.val.charcode.bytes)); - - if (!isspace (ch)) - lr_error (lr, _("garbage at end of character code specification")); - - lr_ungetn (lr, 1); - - lr->token.tok = tok_charcode; - lr->token.val.charcode.nbytes = nbytes; - - return &lr->token; -} - - -#define ADDC(ch) \ - do \ - { \ - if (bufact == bufmax) \ - { \ - bufmax *= 2; \ - buf = xrealloc (buf, bufmax); \ - } \ - buf[bufact++] = (ch); \ - } \ - while (0) - - -#define ADDS(s, l) \ - do \ - { \ - size_t _l = (l); \ - if (bufact + _l > bufmax) \ - { \ - if (bufact < _l) \ - bufact = _l; \ - bufmax *= 2; \ - buf = xrealloc (buf, bufmax); \ - } \ - memcpy (&buf[bufact], s, _l); \ - bufact += _l; \ - } \ - while (0) - - -#define ADDWC(ch) \ - do \ - { \ - if (buf2act == buf2max) \ - { \ - buf2max *= 2; \ - buf2 = xrealloc (buf2, buf2max * 4); \ - } \ - buf2[buf2act++] = (ch); \ - } \ - while (0) - - -static struct token * -get_symname (struct linereader *lr) -{ - /* Symbol in brackets. We must distinguish three kinds: - 1. reserved words - 2. ISO 10646 position values - 3. all other. */ - char *buf; - size_t bufact = 0; - size_t bufmax = 56; - const struct keyword_t *kw; - int ch; - - buf = (char *) xmalloc (bufmax); - - do - { - ch = lr_getc (lr); - if (ch == lr->escape_char) - { - int c2 = lr_getc (lr); - ADDC (c2); - - if (c2 == '\n') - ch = '\n'; - } - else - ADDC (ch); - } - while (ch != '>' && ch != '\n'); - - if (ch == '\n') - lr_error (lr, _("unterminated symbolic name")); - - /* Test for ISO 10646 position value. */ - if (buf[0] == 'U' && (bufact == 6 || bufact == 10)) - { - char *cp = buf + 1; - while (cp < &buf[bufact - 1] && isxdigit (*cp)) - ++cp; - - if (cp == &buf[bufact - 1]) - { - /* Yes, it is. */ - lr->token.tok = tok_ucs4; - lr->token.val.ucs4 = strtoul (buf + 1, NULL, 16); - - return &lr->token; - } - } - - /* It is a symbolic name. Test for reserved words. */ - kw = lr->hash_fct (buf, bufact - 1); - - if (kw != NULL && kw->symname_or_ident == 1) - { - lr->token.tok = kw->token; - free (buf); - } - else - { - lr->token.tok = tok_bsymbol; - - buf[bufact] = '\0'; - buf = xrealloc (buf, bufact + 1); - - lr->token.val.str.startmb = buf; - lr->token.val.str.lenmb = bufact - 1; - } - - return &lr->token; -} - - -static struct token * -get_ident (struct linereader *lr) -{ - char *buf; - size_t bufact; - size_t bufmax = 56; - const struct keyword_t *kw; - int ch; - - buf = xmalloc (bufmax); - bufact = 0; - - ADDC (lr->buf[lr->idx - 1]); - - while (!isspace ((ch = lr_getc (lr))) && ch != '"' && ch != ';' - && ch != '<' && ch != ',' && ch != EOF) - { - if (ch == lr->escape_char) - { - ch = lr_getc (lr); - if (ch == '\n' || ch == EOF) - { - lr_error (lr, _("invalid escape sequence")); - break; - } - } - ADDC (ch); - } - - lr_ungetc (lr, ch); - - kw = lr->hash_fct (buf, bufact); - - if (kw != NULL && kw->symname_or_ident == 0) - { - lr->token.tok = kw->token; - free (buf); - } - else - { - lr->token.tok = tok_ident; - - buf[bufact] = '\0'; - buf = xrealloc (buf, bufact + 1); - - lr->token.val.str.startmb = buf; - lr->token.val.str.lenmb = bufact; - } - - return &lr->token; -} - - -static struct token * -get_string (struct linereader *lr, const struct charmap_t *charmap, - const struct repertoire_t *repertoire, int verbose) -{ - int return_widestr = lr->return_widestr; - char *buf; - wchar_t *buf2 = NULL; - size_t bufact; - size_t bufmax = 56; - - /* We must return two different strings. */ - buf = xmalloc (bufmax); - bufact = 0; - - /* We know it'll be a string. */ - lr->token.tok = tok_string; - - /* If we need not translate the strings (i.e., expand <...> parts) - we can run a simple loop. */ - if (!lr->translate_strings) - { - int ch; - - buf2 = NULL; - while ((ch = lr_getc (lr)) != '"' && ch != '\n' && ch != EOF) - ADDC (ch); - - /* Catch errors with trailing escape character. */ - if (bufact > 0 && buf[bufact - 1] == lr->escape_char - && (bufact == 1 || buf[bufact - 2] != lr->escape_char)) - { - lr_error (lr, _("illegal escape sequence at end of string")); - --bufact; - } - else if (ch == '\n' || ch == EOF) - lr_error (lr, _("unterminated string")); - - ADDC ('\0'); - } - else - { - int illegal_string = 0; - size_t buf2act = 0; - size_t buf2max = 56 * sizeof (uint32_t); - int ch; - int warned = 0; - - /* We have to provide the wide character result as well. */ - if (return_widestr) - buf2 = xmalloc (buf2max); - - /* Read until the end of the string (or end of the line or file). */ - while ((ch = lr_getc (lr)) != '"' && ch != '\n' && ch != EOF) - { - size_t startidx; - uint32_t wch; - struct charseq *seq; - - if (ch != '<') - { - /* The standards leave it up to the implementation to decide - what to do with character which stand for themself. We - could jump through hoops to find out the value relative to - the charmap and the repertoire map, but instead we leave - it up to the locale definition author to write a better - definition. We assume here that every character which - stands for itself is encoded using ISO 8859-1. Using the - escape character is allowed. */ - if (ch == lr->escape_char) - { - ch = lr_getc (lr); - if (ch == '\n' || ch == EOF) - break; - } - - if (verbose && !warned) - { - lr_error (lr, _("\ -non-symbolic character value should not be used")); - warned = 1; - } - - ADDC (ch); - if (return_widestr) - ADDWC ((uint32_t) ch); - - continue; - } - - /* Now we have to search for the end of the symbolic name, i.e., - the closing '>'. */ - startidx = bufact; - while ((ch = lr_getc (lr)) != '>' && ch != '\n' && ch != EOF) - { - if (ch == lr->escape_char) - { - ch = lr_getc (lr); - if (ch == '\n' || ch == EOF) - break; - } - ADDC (ch); - } - if (ch == '\n' || ch == EOF) - /* Not a correct string. */ - break; - if (bufact == startidx) - { - /* <> is no correct name. Ignore it and also signal an - error. */ - illegal_string = 1; - continue; - } - - /* It might be a Uxxxx symbol. */ - if (buf[startidx] == 'U' - && (bufact - startidx == 5 || bufact - startidx == 9)) - { - char *cp = buf + startidx + 1; - while (cp < &buf[bufact] && isxdigit (*cp)) - ++cp; - - if (cp == &buf[bufact]) - { - char utmp[10]; - const char *symbol = NULL; - - /* Yes, it is. */ - ADDC ('\0'); - wch = strtoul (buf + startidx + 1, NULL, 16); - - /* Now forget about the name we just added. */ - bufact = startidx; - - if (return_widestr) - ADDWC (wch); - - /* See whether the charmap contains the Uxxxxxxxx names. */ - snprintf (utmp, sizeof (utmp), "U%08X", wch); - seq = charmap_find_value (charmap, utmp, 9); - - if (seq == NULL) - { - /* No, this isn't the case. Now determine from - the repertoire the name of the character and - find it in the charmap. */ - if (repertoire != NULL) - symbol = repertoire_find_symbol (repertoire, wch); - - if (symbol == NULL) - /* We cannot generate a string since we - cannot map from the Unicode number to the - character symbol. */ - illegal_string = 1; - else - { - seq = charmap_find_value (charmap, symbol, - strlen (symbol)); - - if (seq == NULL) - /* Not a known name. */ - illegal_string = 1; - } - } - - if (seq != NULL) - ADDS (seq->bytes, seq->nbytes); - - continue; - } - } - - /* We now have the symbolic name in buf[startidx] to - buf[bufact-1]. Now find out the value for this character - in the charmap as well as in the repertoire map (in this - order). */ - seq = charmap_find_value (charmap, &buf[startidx], - bufact - startidx); - - if (seq == NULL) - { - /* This name is not in the charmap. */ - lr_error (lr, _("symbol `%.*s' not in charmap"), - (int) (bufact - startidx), &buf[startidx]); - illegal_string = 1; - } - - if (return_widestr) - { - /* Now the same for the multibyte representation. */ - if (seq != NULL && seq->ucs4 != UNINITIALIZED_CHAR_VALUE) - wch = seq->ucs4; - else - { - wch = repertoire_find_value (repertoire, &buf[startidx], - bufact - startidx); - if (seq != NULL) - seq->ucs4 = wch; - } - - if (wch == ILLEGAL_CHAR_VALUE) - { - /* This name is not in the repertoire map. */ - lr_error (lr, _("symbol `%.*s' not in repertoire map"), - (int) (bufact - startidx), &buf[startidx]); - illegal_string = 1; - } - else - ADDWC (wch); - } - - /* Now forget about the name we just added. */ - bufact = startidx; - - /* And copy the bytes. */ - if (seq != NULL) - ADDS (seq->bytes, seq->nbytes); - } - - if (ch == '\n' || ch == EOF) - { - lr_error (lr, _("unterminated string")); - illegal_string = 1; - } - - if (illegal_string) - { - free (buf); - if (buf2 != NULL) - free (buf2); - lr->token.val.str.startmb = NULL; - lr->token.val.str.lenmb = 0; - lr->token.val.str.startwc = NULL; - lr->token.val.str.lenwc = 0; - - return &lr->token; - } - - ADDC ('\0'); - - if (return_widestr) - { - ADDWC (0); - lr->token.val.str.startwc = xrealloc (buf2, - buf2act * sizeof (uint32_t)); - lr->token.val.str.lenwc = buf2act; - } - } - - lr->token.val.str.startmb = xrealloc (buf, bufact); - lr->token.val.str.lenmb = bufact; - - return &lr->token; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/linereader.h b/src/system/libroot/posix/glibc/locale/programs/linereader.h deleted file mode 100644 index 69053cb02e..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/linereader.h +++ /dev/null @@ -1,172 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper, . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LINEREADER_H -#define _LINEREADER_H 1 - -#include -#include -#include -#include - -#include "charmap.h" -#include "error.h" -#include "locfile-token.h" -#include "repertoire.h" - - -typedef const struct keyword_t *(*kw_hash_fct_t) (const char *, unsigned int); -struct charset_t; - - -struct token -{ - enum token_t tok; - union - { - struct - { - char *startmb; - size_t lenmb; - uint32_t *startwc; - size_t lenwc; - } str; - unsigned long int num; - struct - { - /* This element is sized on the safe expectation that no single - character in any character set uses more then 16 bytes. */ - unsigned char bytes[16]; - int nbytes; - } charcode; - uint32_t ucs4; - } val; -}; - - -struct linereader -{ - FILE *fp; - const char *fname; - char *buf; - size_t bufsize; - size_t bufact; - size_t lineno; - - size_t idx; - - char comment_char; - char escape_char; - - struct token token; - - int translate_strings; - int return_widestr; - - kw_hash_fct_t hash_fct; -}; - - -/* Functions defined in linereader.c. */ -extern struct linereader *lr_open (const char *fname, kw_hash_fct_t hf); -extern struct linereader *lr_create (FILE *fp, const char *fname, kw_hash_fct_t hf); -extern int lr_eof (struct linereader *lr); -extern void lr_close (struct linereader *lr); -extern int lr_next (struct linereader *lr); -extern struct token *lr_token (struct linereader *lr, - const struct charmap_t *charmap, - const struct repertoire_t *repertoire, - int verbose); - - -#define lr_error(lr, fmt, args...) \ - error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args) - - - -static inline int -lr_getc (struct linereader *lr) -{ - if (lr->idx == lr->bufact) - { - if (lr->bufact != 0) - if (lr_next (lr) < 0) - return EOF; - - if (lr->bufact == 0) - return EOF; - } - - return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++]; -} - - -static inline int -lr_ungetc (struct linereader *lr, int ch) -{ - if (lr->idx == 0) - return -1; - - if (ch != EOF) - lr->buf[--lr->idx] = ch; - return 0; -} - - -static inline int -lr_ungetn (struct linereader *lr, size_t n) -{ - if (lr->idx < n) - return -1; - - lr->idx -= n; - return 0; -} - - -static inline void -lr_ignore_rest (struct linereader *lr, int verbose) -{ - if (verbose) - { - while (isspace (lr->buf[lr->idx]) && lr->buf[lr->idx] != '\n' - && lr->buf[lr->idx] != lr->comment_char) - if (lr->buf[lr->idx] == '\0') - { - if (lr_next (lr) < 0) - return; - } - else - ++lr->idx; - - if (lr->buf[lr->idx] != '\n' && ! feof (lr->fp) - && lr->buf[lr->idx] != lr->comment_char) - lr_error (lr, _("trailing garbage at end of line")); - } - - /* Ignore continued line. */ - while (lr->bufact > 0 && lr->buf[lr->bufact - 1] != '\n') - if (lr_next (lr) < 0) - break; - - lr->idx = lr->bufact; -} - - -#endif /* linereader.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/locale-spec.c b/src/system/libroot/posix/glibc/locale/programs/locale-spec.c deleted file mode 100644 index a1a3aba47f..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locale-spec.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Handle special requests. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include "localeinfo.h" - - -/* We provide support for some special names. This helps debugging - and may be useful for advanced usage of the provided information - outside C. */ -void -locale_special (const char *name, int show_category_name, - int show_keyword_name) -{ -#if 0 - /* "collate-elements": print collation elements of locale. */ - if (strcmp (name, "collate-elements") == 0) - { - size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_ELEM_HASH_SIZE); - - if (show_category_name) - puts ("LC_COLLATE"); - if (show_keyword_name) - fputs ("collate-elements=", stdout); - - if (nelem != 0) - { - int first = 1; - size_t cnt; - - for (cnt = 0; cnt < nelem; ++cnt) - if (__collate_element_hash[2 * cnt] != (~((u_int32_t) 0))) - { - size_t idx = __collate_element_hash[2 * cnt]; - - printf ("%s<%s>", first ? "" : ";", - &__collate_element_strings[idx]); - - /* We don't print the string. This is only confusing - because only the programs have to know the - encoding. The code is left in place because it - shows how to get the information. */ - { - const wchar_t *wp; - - idx = __collate_element_hash[2 * cnt + 1]; - wp = &__collate_element_values[idx]; - while (*wp != L'\0') - { - /********************************************\ - |* XXX The element values are really wide *| - |* chars. But we are currently not able to *| - |* print these so fake here. *| - \********************************************/ - int ch = wctob (*wp++); - if (ch != EOF) - putchar (ch); - else - fputs ("", stdout); - } - - putchar ('"'); - } - first = 0; - } - } - putchar ('\n'); - return; - } - - if (strcmp (name, "collate-classes") == 0) - { - size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZE); - size_t cnt; - int first = 1; - - if (show_category_name) - puts ("LC_COLLATE"); - if (show_keyword_name) - fputs ("collate-classes=", stdout); - - for (cnt = 0; cnt < nelem; ++cnt) - if (__collate_symbol_hash[2 * cnt] != 0xffffffff) - { - printf ("%s<%s>", first ? "" : ",", - &__collate_symbol_strings[__collate_symbol_hash[2 * cnt]]); -#if 0 - { - size_t idx = __collate_symbol_hash[2 * cnt + 1]; - size_t cls; - - putchar ('='); - for (cls = 0; cls < __collate_symbol_classes[idx]; ++cls) - printf ("%s%d", cls == 0 ? "" : ":", - __collate_symbol_classes[idx + 1 + cls]); - } -#endif - first = 0; - } - putchar ('\n'); - return; - } -#endif -} diff --git a/src/system/libroot/posix/glibc/locale/programs/locale.c b/src/system/libroot/posix/glibc/locale/programs/locale.c deleted file mode 100644 index 3377bcc286..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locale.c +++ /dev/null @@ -1,808 +0,0 @@ -/* Implementation of the locale program according to POSIX 9945-2. - Copyright (C) 1995-1997,1999,2000,2001,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "localeinfo.h" -#include "charmap-dir.h" - -extern void *xmalloc (size_t __n); -extern char *xstrdup (const char *__str); - - -/* If set print the name of the category. */ -static int show_category_name; - -/* If set print the name of the item. */ -static int show_keyword_name; - -/* Print names of all available locales. */ -static int do_all; - -/* Print names of all available character maps. */ -static int do_charmaps = 0; - -/* Nonzero if verbose output is wanted. */ -static int verbose; - -/* Name and version of program. */ -static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; - -/* Definitions of arguments for argp functions. */ -static const struct argp_option options[] = -{ - { NULL, 0, NULL, 0, N_("System information:") }, - { "all-locales", 'a', NULL, OPTION_NO_USAGE, - N_("Write names of available locales") }, - { "charmaps", 'm', NULL, OPTION_NO_USAGE, - N_("Write names of available charmaps") }, - { NULL, 0, NULL, 0, N_("Modify output format:") }, - { "category-name", 'c', NULL, 0, N_("Write names of selected categories") }, - { "keyword-name", 'k', NULL, 0, N_("Write names of selected keywords") }, - { "verbose", 'v', NULL, 0, N_("Print more information") }, - { NULL, 0, NULL, 0, NULL } -}; - -/* Short description of program. */ -static const char doc[] = N_("Get locale-specific information."); - -/* Strings for arguments in help texts. */ -static const char args_doc[] = N_("NAME\n[-a|-m]"); - -/* Prototype for option handler. */ -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -/* Function to print some extra text in the help message. */ -static char *more_help (int key, const char *text, void *input); - -/* Data structure to communicate with argp functions. */ -static struct argp argp = -{ - options, parse_opt, args_doc, doc, NULL, more_help -}; - - -/* We don't have these constants defined because we don't use them. Give - default values. */ -#define CTYPE_MB_CUR_MIN 0 -#define CTYPE_MB_CUR_MAX 0 -#define CTYPE_HASH_SIZE 0 -#define CTYPE_HASH_LAYERS 0 -#define CTYPE_CLASS 0 -#define CTYPE_TOUPPER_EB 0 -#define CTYPE_TOLOWER_EB 0 -#define CTYPE_TOUPPER_EL 0 -#define CTYPE_TOLOWER_EL 0 - -/* Definition of the data structure which represents a category and its - items. */ -struct category -{ - int cat_id; - const char *name; - size_t number; - struct cat_item - { - int item_id; - const char *name; - enum { std, opt } status; - enum value_type value_type; - int min; - int max; - } *item_desc; -}; - -/* Simple helper macro. */ -#define NELEMS(arr) ((sizeof (arr)) / (sizeof (arr[0]))) - -/* For some tricky stuff. */ -#define NO_PAREN(Item, More...) Item, ## More - -/* We have all categories defined in `categories.def'. Now construct - the description and data structure used for all categories. */ -#define DEFINE_ELEMENT(Item, More...) { Item, ## More }, -#define DEFINE_CATEGORY(category, name, items, postload) \ - static struct cat_item category##_desc[] = \ - { \ - NO_PAREN items \ - }; - -#include "categories.def" -#undef DEFINE_CATEGORY - -static struct category category[] = - { -#define DEFINE_CATEGORY(category, name, items, postload) \ - [category] = { _NL_NUM_##category, name, NELEMS (category##_desc), \ - category##_desc }, -#include "categories.def" -#undef DEFINE_CATEGORY - }; -#define NCATEGORIES NELEMS (category) - - -/* Automatically set variable. */ -extern const char *__progname; - -/* helper function for extended name handling. */ -extern void locale_special (const char *name, int show_category_name, - int show_keyword_name); - -/* Prototypes for local functions. */ -static void write_locales (void); -static void write_charmaps (void); -static void show_locale_vars (void); -static void show_info (const char *name); - - -int -main (int argc, char *argv[]) -{ - int remaining; - - /* Set initial values for global variables. */ - show_category_name = 0; - show_keyword_name = 0; - - /* Set locale. Do not set LC_ALL because the other categories must - not be affected (according to POSIX.2). */ - setlocale (LC_CTYPE, ""); - setlocale (LC_MESSAGES, ""); - - /* Initialize the message catalog. */ - textdomain (PACKAGE); - - /* Parse and process arguments. */ - argp_parse (&argp, argc, argv, 0, &remaining, NULL); - - /* `-a' requests the names of all available locales. */ - if (do_all != 0) - { - setlocale (LC_COLLATE, ""); - write_locales (); - exit (EXIT_SUCCESS); - } - - /* `m' requests the names of all available charmaps. The names can be - used for the -f argument to localedef(1). */ - if (do_charmaps != 0) - { - write_charmaps (); - exit (EXIT_SUCCESS); - } - - /* Specific information about the current locale are requested. - Change to this locale now. */ - setlocale (LC_ALL, ""); - - /* If no real argument is given we have to print the contents of the - current locale definition variables. These are LANG and the LC_*. */ - if (remaining == argc && show_keyword_name == 0 && show_category_name == 0) - { - show_locale_vars (); - exit (EXIT_SUCCESS); - } - - /* Process all given names. */ - while (remaining < argc) - show_info (argv[remaining++]); - - exit (EXIT_SUCCESS); -} - - -/* Handle program arguments. */ -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case 'a': - do_all = 1; - break; - case 'c': - show_category_name = 1; - break; - case 'm': - do_charmaps = 1; - break; - case 'k': - show_keyword_name = 1; - break; - case 'v': - verbose = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - - -static char * -more_help (int key, const char *text, void *input) -{ - switch (key) - { - case ARGP_KEY_HELP_EXTRA: - /* We print some extra information. */ - return xstrdup (gettext ("\ -Report bugs using the `glibcbug' script to .\n")); - default: - break; - } - return (char *) text; -} - -/* Print the version information. */ -static void -print_version (FILE *stream, struct argp_state *state) -{ - fprintf (stream, "locale (GNU %s) %s\n", PACKAGE, VERSION); - fprintf (stream, gettext ("\ -Copyright (C) %s Free Software Foundation, Inc.\n\ -This is free software; see the source for copying conditions. There is NO\n\ -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2002"); - fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); -} - - -/* Simple action function which prints arguments as strings. */ -static void -print_names (const void *nodep, VISIT value, int level) -{ - if (value == postorder || value == leaf) - puts (*(char **) nodep); -} - - -static int -select_dirs (const struct dirent *dirent) -{ - int result = 0; - - if (strcmp (dirent->d_name, ".") != 0 && strcmp (dirent->d_name, "..") != 0) - { - mode_t mode = 0; - -#ifdef _DIRENT_HAVE_D_TYPE - if (dirent->d_type != DT_UNKNOWN && dirent->d_type != DT_LNK) - mode = DTTOIF (dirent->d_type); - else -#endif - { - struct stat64 st; - char buf[sizeof (LOCALEDIR) + strlen (dirent->d_name) + 1]; - - stpcpy (stpcpy (stpcpy (buf, LOCALEDIR), "/"), dirent->d_name); - - if (stat64 (buf, &st) == 0) - mode = st.st_mode; - } - - result = S_ISDIR (mode); - } - - return result; -} - - -/* Write the names of all available locales to stdout. We have some - sources of the information: the contents of the locale directory - and the locale.alias file. To avoid duplicates and print the - result is a reasonable order we put all entries is a search tree - and print them afterwards. */ -static void -write_locales (void) -{ - char linebuf[80]; - void *all_data = NULL; - struct dirent **dirents; - int ndirents; - int cnt; - char *alias_path; - size_t alias_path_len; - char *entry; - int first_locale = 1; - -#define PUT(name) tsearch (name, &all_data, \ - (int (*) (const void *, const void *)) strcoll) - - /* Now read the locale.alias files. */ - if (argz_create_sep (LOCALE_ALIAS_PATH, ':', &alias_path, &alias_path_len)) - error (1, errno, gettext ("while preparing output")); - - entry = NULL; - while ((entry = argz_next (alias_path, alias_path_len, entry))) - { - static const char aliasfile[] = "/locale.alias"; - FILE *fp; - char full_name[strlen (entry) + sizeof aliasfile]; - - stpcpy (stpcpy (full_name, entry), aliasfile); - fp = fopen (full_name, "r"); - if (fp == NULL) - /* Ignore non-existing files. */ - continue; - - /* No threads present. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - while (! feof_unlocked (fp)) - { - /* It is a reasonable approach to use a fix buffer here - because - a) we are only interested in the first two fields - b) these fields must be usable as file names and so must - not be that long */ - char buf[BUFSIZ]; - char *alias; - char *value; - char *cp; - - if (fgets_unlocked (buf, BUFSIZ, fp) == NULL) - /* EOF reached. */ - break; - - cp = buf; - /* Ignore leading white space. */ - while (isspace (cp[0]) && cp[0] != '\n') - ++cp; - - /* A leading '#' signals a comment line. */ - if (cp[0] != '\0' && cp[0] != '#' && cp[0] != '\n') - { - alias = cp++; - while (cp[0] != '\0' && !isspace (cp[0])) - ++cp; - /* Terminate alias name. */ - if (cp[0] != '\0') - *cp++ = '\0'; - - /* Now look for the beginning of the value. */ - while (isspace (cp[0])) - ++cp; - - if (cp[0] != '\0') - { - value = cp++; - while (cp[0] != '\0' && !isspace (cp[0])) - ++cp; - /* Terminate value. */ - if (cp[0] == '\n') - { - /* This has to be done to make the following - test for the end of line possible. We are - looking for the terminating '\n' which do not - overwrite here. */ - *cp++ = '\0'; - *cp = '\n'; - } - else if (cp[0] != '\0') - *cp++ = '\0'; - - /* Add the alias. */ - if (! verbose) - PUT (xstrdup (alias)); - } - } - - /* Possibly not the whole line fits into the buffer. - Ignore the rest of the line. */ - while (strchr (cp, '\n') == NULL) - { - cp = buf; - if (fgets_unlocked (buf, BUFSIZ, fp) == NULL) - /* Make sure the inner loop will be left. The outer - loop will exit at the `feof' test. */ - *cp = '\n'; - } - } - - fclose (fp); - } - - memset (linebuf, '-', sizeof (linebuf) - 1); - linebuf[sizeof (linebuf) - 1] = '\0'; - - /* Now we can look for all files in the directory. */ - ndirents = scandir (LOCALEDIR, &dirents, select_dirs, alphasort); - for (cnt = 0; cnt < ndirents; ++cnt) - { - /* Test whether at least the LC_CTYPE data is there. Some - directories only contain translations. */ - char buf[sizeof (LOCALEDIR) + strlen (dirents[cnt]->d_name) - + sizeof "/LC_IDENTIFICATION"]; - char *enddir; - struct stat64 st; - - stpcpy (enddir = stpcpy (stpcpy (stpcpy (buf, LOCALEDIR), "/"), - dirents[cnt]->d_name), - "/LC_IDENTIFICATION"); - - if (stat64 (buf, &st) == 0 && S_ISREG (st.st_mode)) - { - if (verbose) - { - /* Provide some nice output of all kinds of - information. */ - int fd; - - if (! first_locale) - putchar_unlocked ('\n'); - first_locale = 0; - - printf ("locale: %-15.15s directory: %.*s\n%s\n", - dirents[cnt]->d_name, (int) (enddir - buf), buf, - linebuf); - - fd = open64 (buf, O_RDONLY); - if (fd != -1) - { - void *mapped = mmap64 (NULL, st.st_size, PROT_READ, - MAP_SHARED, fd, 0); - if (mapped != MAP_FAILED) - { - /* Read the information from the file. */ - struct - { - unsigned int magic; - unsigned int nstrings; - unsigned int strindex[0]; - } *filedata = mapped; - - if (filedata->magic == LIMAGIC (LC_IDENTIFICATION) - && (sizeof *filedata - + (filedata->nstrings - * sizeof (unsigned int)) - <= (size_t) st.st_size)) - { - const char *str; - -#define HANDLE(idx, name) \ - str = ((char *) mapped \ - + filedata->strindex[_NL_ITEM_INDEX (_NL_IDENTIFICATION_##idx)]); \ - if (*str != '\0') \ - printf ("%9s | %s\n", name, str) - HANDLE (TITLE, "title"); - HANDLE (SOURCE, "source"); - HANDLE (ADDRESS, "address"); - HANDLE (CONTACT, "contact"); - HANDLE (EMAIL, "email"); - HANDLE (TEL, "telephone"); - HANDLE (FAX, "fax"); - HANDLE (LANGUAGE, "language"); - HANDLE (TERRITORY, "territory"); - HANDLE (AUDIENCE, "audience"); - HANDLE (APPLICATION, "application"); - HANDLE (ABBREVIATION, "abbreviation"); - HANDLE (REVISION, "revision"); - HANDLE (DATE, "date"); - } - - munmap (mapped, st.st_size); - } - - close (fd); - - /* Now try to get the charset information. */ - strcpy (enddir, "/LC_CTYPE"); - fd = open64 (buf, O_RDONLY); - if (fd != -1 && fstat64 (fd, &st) >= 0 - && ((mapped = mmap64 (NULL, st.st_size, PROT_READ, - MAP_SHARED, fd, 0)) - != MAP_FAILED)) - { - struct - { - unsigned int magic; - unsigned int nstrings; - unsigned int strindex[0]; - } *filedata = mapped; - - if (filedata->magic == LIMAGIC (LC_CTYPE) - && (sizeof *filedata - + (filedata->nstrings - * sizeof (unsigned int)) - <= (size_t) st.st_size)) - { - const char *str; - - str = ((char *) mapped - + filedata->strindex[_NL_ITEM_INDEX (_NL_CTYPE_CODESET_NAME)]); - if (*str != '\0') - printf (" codeset | %s\n", str); - } - - munmap (mapped, st.st_size); - } - - if (fd != -1) - close (fd); - } - } - else - /* If the verbose format is not selected we simply - collect the names. */ - PUT (xstrdup (dirents[cnt]->d_name)); - } - } - if (ndirents > 0) - free (dirents); - - if (! verbose) - { - /* `POSIX' locale is always available (POSIX.2 4.34.3). */ - PUT ("POSIX"); - /* And so is the "C" locale. */ - PUT ("C"); - - twalk (all_data, print_names); - } -} - - -/* Write the names of all available character maps to stdout. */ -static void -write_charmaps (void) -{ - void *all_data = NULL; - CHARMAP_DIR *dir; - const char *dirent; - - /* Look for all files in the charmap directory. */ - dir = charmap_opendir (CHARMAP_PATH); - if (dir == NULL) - return; - - while ((dirent = charmap_readdir (dir)) != NULL) - { - char **aliases; - char **p; - - PUT (xstrdup (dirent)); - - aliases = charmap_aliases (CHARMAP_PATH, dirent); - -#if 0 - /* Add the code_set_name and the aliases. */ - for (p = aliases; *p; p++) - PUT (xstrdup (*p)); -#else - /* Add the code_set_name only. Most aliases are obsolete. */ - p = aliases; - if (*p) - PUT (xstrdup (*p)); -#endif - - charmap_free_aliases (aliases); - } - - charmap_closedir (dir); - - twalk (all_data, print_names); -} - - -/* We have to show the contents of the environments determining the - locale. */ -static void -show_locale_vars (void) -{ - size_t cat_no; - const char *lcall = getenv ("LC_ALL"); - const char *lang = getenv ("LANG") ? : "POSIX"; - - auto void get_source (const char *name); - - void get_source (const char *name) - { - char *val = getenv (name); - - if ((lcall ?: "")[0] != '\0' || val == NULL) - printf ("%s=\"%s\"\n", name, (lcall ?: "")[0] ? lcall : lang); - else - printf ("%s=%s\n", name, val); - } - - /* LANG has to be the first value. */ - printf ("LANG=%s\n", lang); - - /* Now all categories in an unspecified order. */ - for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no) - if (cat_no != LC_ALL) - get_source (category[cat_no].name); - - /* The last is the LC_ALL value. */ - printf ("LC_ALL=%s\n", lcall ? : ""); -} - - -/* Show the information request for NAME. */ -static void -show_info (const char *name) -{ - size_t cat_no; - - auto void print_item (struct cat_item *item); - - void print_item (struct cat_item *item) - { - switch (item->value_type) - { - case string: - if (show_keyword_name) - printf ("%s=\"", item->name); - fputs (nl_langinfo (item->item_id) ? : "", stdout); - if (show_keyword_name) - putchar ('"'); - putchar ('\n'); - break; - case stringarray: - { - int cnt; - const char *val; - - if (show_keyword_name) - printf ("%s=\"", item->name); - - for (cnt = 0; cnt < item->max - 1; ++cnt) - { - val = nl_langinfo (item->item_id + cnt); - if (val != NULL) - fputs (val, stdout); - putchar (';'); - } - - val = nl_langinfo (item->item_id + cnt); - if (val != NULL) - fputs (val, stdout); - - if (show_keyword_name) - putchar ('"'); - putchar ('\n'); - } - break; - case stringlist: - { - int first = 1; - const char *val = nl_langinfo (item->item_id) ? : ""; - int cnt; - - if (show_keyword_name) - printf ("%s=", item->name); - - for (cnt = 0; cnt < item->max && *val != '\0'; ++cnt) - { - printf ("%s%s%s%s", first ? "" : ";", - show_keyword_name ? "\"" : "", val, - show_keyword_name ? "\"" : ""); - val = strchr (val, '\0') + 1; - first = 0; - } - putchar ('\n'); - } - break; - case byte: - { - const char *val = nl_langinfo (item->item_id); - - if (show_keyword_name) - printf ("%s=", item->name); - - if (val != NULL) - printf ("%d", *val == CHAR_MAX ? -1 : *val); - putchar ('\n'); - } - break; - case bytearray: - { - const char *val = nl_langinfo (item->item_id); - int cnt = val ? strlen (val) : 0; - - if (show_keyword_name) - printf ("%s=", item->name); - - while (cnt > 1) - { - printf ("%d;", *val == CHAR_MAX ? -1 : *val); - --cnt; - ++val; - } - - printf ("%d\n", cnt == 0 || *val == CHAR_MAX ? -1 : *val); - } - break; - case word: - { - unsigned int val = - (unsigned int) (unsigned long int) nl_langinfo (item->item_id); - if (show_keyword_name) - printf ("%s=", item->name); - - printf ("%d\n", val); - } - break; - case wstring: - case wstringarray: - case wstringlist: - /* We don't print wide character information since the same - information is available in a multibyte string. */ - default: - break; - - } - } - - for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no) - if (cat_no != LC_ALL) - { - size_t item_no; - - if (strcmp (name, category[cat_no].name) == 0) - /* Print the whole category. */ - { - if (show_category_name != 0) - puts (category[cat_no].name); - - for (item_no = 0; item_no < category[cat_no].number; ++item_no) - print_item (&category[cat_no].item_desc[item_no]); - - return; - } - - for (item_no = 0; item_no < category[cat_no].number; ++item_no) - if (strcmp (name, category[cat_no].item_desc[item_no].name) == 0) - { - if (show_category_name != 0) - puts (category[cat_no].name); - - print_item (&category[cat_no].item_desc[item_no]); - return; - } - } - - /* The name is not a standard one. - For testing and perhaps advanced use allow some more symbols. */ - locale_special (name, show_category_name, show_keyword_name); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/localedef.c b/src/system/libroot/posix/glibc/locale/programs/localedef.c deleted file mode 100644 index 0bdef4be71..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/localedef.c +++ /dev/null @@ -1,548 +0,0 @@ -/* Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "error.h" -#include "charmap.h" -#include "locfile.h" - -/* Undefine the following line in the production version. */ -/* #define NDEBUG 1 */ -#include - - -/* List of copied locales. */ -struct copy_def_list_t *copy_list; - -/* If this is defined be POSIX conform. */ -int posix_conformance; - -/* If not zero give a lot more messages. */ -int verbose; - -/* If not zero suppress warnings and information messages. */ -int be_quiet; - -/* If not zero, produce old-style hash table instead of 3-level access tables. */ -int oldstyle_tables; - -/* If not zero force output even if warning were issued. */ -static int force_output; - -/* Prefix for output files. */ -const char *output_prefix; - -/* Name of the character map file. */ -static const char *charmap_file; - -/* Name of the locale definition file. */ -static const char *input_file; - -/* Name of the repertoire map file. */ -const char *repertoire_global; - -/* List of all locales. */ -static struct localedef_t *locales; - - -/* Name and version of program. */ -static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; - -#define OPT_POSIX 1 -#define OPT_QUIET 2 -#define OPT_OLDSTYLE 3 -#define OPT_PREFIX 4 - -/* Definitions of arguments for argp functions. */ -static const struct argp_option options[] = -{ - { NULL, 0, NULL, 0, N_("Input Files:") }, - { "charmap", 'f', "FILE", 0, - N_("Symbolic character names defined in FILE") }, - { "inputfile", 'i', "FILE", 0, N_("Source definitions are found in FILE") }, - { "repertoire-map", 'u', "FILE", 0, - N_("FILE contains mapping from symbolic names to UCS4 values") }, - - { NULL, 0, NULL, 0, N_("Output control:") }, - { "force", 'c', NULL, 0, - N_("Create output even if warning messages were issued") }, - { "old-style", OPT_OLDSTYLE, NULL, 0, N_("Create old-style tables") }, - { "prefix", OPT_PREFIX, "PATH", 0, N_("Optional output file prefix") }, - { "posix", OPT_POSIX, NULL, 0, N_("Be strictly POSIX conform") }, - { "quiet", OPT_QUIET, NULL, 0, - N_("Suppress warnings and information messages") }, - { "verbose", 'v', NULL, 0, N_("Print more messages") }, - { NULL, 0, NULL, 0, NULL } -}; - -/* Short description of program. */ -static const char doc[] = N_("Compile locale specification"); - -/* Strings for arguments in help texts. */ -static const char args_doc[] = N_("NAME"); - -/* Prototype for option handler. */ -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -/* Function to print some extra text in the help message. */ -static char *more_help (int key, const char *text, void *input); - -/* Data structure to communicate with argp functions. */ -static struct argp argp = -{ - options, parse_opt, args_doc, doc, NULL, more_help -}; - - -/* Prototypes for global functions. */ -extern void *xmalloc (size_t __n); - -/* Prototypes for local functions. */ -static void error_print (void); -static const char *construct_output_path (char *path); -static const char *normalize_codeset (const char *codeset, size_t name_len); - - -int -main (int argc, char *argv[]) -{ - const char *output_path; - int cannot_write_why; - struct charmap_t *charmap; - struct localedef_t global; - int remaining; - - /* Set initial values for global variables. */ - copy_list = NULL; - posix_conformance = getenv ("POSIXLY_CORRECT") != NULL; - error_print_progname = error_print; - - /* Set locale. Do not set LC_ALL because the other categories must - not be affected (according to POSIX.2). */ - setlocale (LC_MESSAGES, ""); - setlocale (LC_CTYPE, ""); - - /* Initialize the message catalog. */ - textdomain (_libc_intl_domainname); - - /* Parse and process arguments. */ - argp_err_exit_status = 4; - argp_parse (&argp, argc, argv, 0, &remaining, NULL); - - /* POSIX.2 requires to be verbose about missing characters in the - character map. */ - verbose |= posix_conformance; - - if (argc - remaining != 1) - { - /* We need exactly one non-option parameter. */ - argp_help (&argp, stdout, ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR, - program_invocation_short_name); - exit (4); - } - - /* The parameter describes the output path of the constructed files. - If the described files cannot be written return a NULL pointer. */ - output_path = construct_output_path (argv[remaining]); - cannot_write_why = errno; - - /* Now that the parameters are processed we have to reset the local - ctype locale. (P1003.2 4.35.5.2) */ - setlocale (LC_CTYPE, "POSIX"); - - /* Look whether the system really allows locale definitions. POSIX - defines error code 3 for this situation so I think it must be - a fatal error (see P1003.2 4.35.8). */ - if (sysconf (_SC_2_LOCALEDEF) < 0) - error (3, 0, _("FATAL: system does not define `_POSIX2_LOCALEDEF'")); - - /* Process charmap file. */ - charmap = charmap_read (charmap_file, verbose, be_quiet, 1); - - /* Add the first entry in the locale list. */ - memset (&global, '\0', sizeof (struct localedef_t)); - global.name = input_file ?: "/dev/stdin"; - global.needed = ALL_LOCALES; - locales = &global; - - /* Now read the locale file. */ - if (locfile_read (&global, charmap) != 0) - error (4, errno, _("cannot open locale definition file `%s'"), input_file); - - /* Perhaps we saw some `copy' instructions. */ - while (1) - { - struct localedef_t *runp = locales; - - while (runp != NULL && (runp->needed & runp->avail) == runp->needed) - runp = runp->next; - - if (runp == NULL) - /* Everything read. */ - break; - - if (locfile_read (runp, charmap) != 0) - error (4, errno, _("cannot open locale definition file `%s'"), - runp->name); - } - - /* Check the categories we processed in source form. */ - check_all_categories (locales, charmap); - - /* We are now able to write the data files. If warning were given we - do it only if it is explicitly requested (--force). */ - if (error_message_count == 0 || force_output != 0) - { - if (cannot_write_why != 0) - error (4, cannot_write_why, _("cannot write output files to `%s'"), - output_path); - else - write_all_categories (locales, charmap, output_path); - } - else - error (4, 0, _("no output file produced because warning were issued")); - - /* This exit status is prescribed by POSIX.2 4.35.7. */ - exit (error_message_count != 0); -} - - -/* Handle program arguments. */ -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case OPT_QUIET: - be_quiet = 1; - break; - case OPT_POSIX: - posix_conformance = 1; - break; - case OPT_OLDSTYLE: - oldstyle_tables = 1; - break; - case OPT_PREFIX: - output_prefix = arg; - break; - case 'c': - force_output = 1; - break; - case 'f': - charmap_file = arg; - break; - case 'i': - input_file = arg; - break; - case 'u': - repertoire_global = arg; - break; - case 'v': - verbose = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - - -static char * -more_help (int key, const char *text, void *input) -{ - char *cp; - - switch (key) - { - case ARGP_KEY_HELP_EXTRA: - /* We print some extra information. */ - asprintf (&cp, gettext ("\ -System's directory for character maps : %s\n\ - repertoire maps: %s\n\ - locale path : %s\n\ -%s"), - CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, gettext ("\ -Report bugs using the `glibcbug' script to .\n")); - return cp; - default: - break; - } - return (char *) text; -} - -/* Print the version information. */ -static void -print_version (FILE *stream, struct argp_state *state) -{ - fprintf (stream, "localedef (GNU %s) %s\n", PACKAGE, VERSION); - fprintf (stream, gettext ("\ -Copyright (C) %s Free Software Foundation, Inc.\n\ -This is free software; see the source for copying conditions. There is NO\n\ -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2002"); - fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); -} - - -/* The address of this function will be assigned to the hook in the error - functions. */ -static void -error_print (void) -{ -} - - -/* The parameter to localedef describes the output path. If it does - contain a '/' character it is a relative path. Otherwise it names the - locale this definition is for. */ -static const char * -construct_output_path (char *path) -{ - const char *normal = NULL; - char *result; - char *endp; - - if (strchr (path, '/') == NULL) - { - /* This is a system path. First examine whether the locale name - contains a reference to the codeset. This should be - normalized. */ - char *startp; - size_t n; - - startp = path; - /* We must be prepared for finding a CEN name or a location of - the introducing `.' where it is not possible anymore. */ - while (*startp != '\0' && *startp != '@' && *startp != '.' - && *startp != '+' && *startp != ',') - ++startp; - if (*startp == '.') - { - /* We found a codeset specification. Now find the end. */ - endp = ++startp; - while (*endp != '\0' && *endp != '@') - ++endp; - - if (endp > startp) - normal = normalize_codeset (startp, endp - startp); - } - else - /* This is to keep gcc quiet. */ - endp = NULL; - - /* We put an additional '\0' at the end of the string because at - the end of the function we need another byte for the trailing - '/'. */ - if (normal == NULL) - n = asprintf (&result, "%s%s/%s%c", - output_prefix ?: "", LOCALEDIR, path, '\0'); - else - n = asprintf (&result, "%s%s/%.*s%s%s%c", - output_prefix ?: "", LOCALEDIR, - (int) (startp - path), path, normal, endp, '\0'); - - endp = result + n - 1; - } - else - { - /* This is a user path. Please note the additional byte in the - memory allocation. */ - size_t len = strlen (path) + 1; - result = xmalloc (len + 1); - endp = mempcpy (result, path, len) - 1; - } - - errno = 0; - - if (euidaccess (result, W_OK) == -1) - /* Perhaps the directory does not exist now. Try to create it. */ - if (errno == ENOENT) - { - errno = 0; - mkdir (result, 0777); - } - - *endp++ = '/'; - *endp = '\0'; - - return result; -} - - -/* Normalize codeset name. There is no standard for the codeset - names. Normalization allows the user to use any of the common - names. */ -static const char * -normalize_codeset (codeset, name_len) - const char *codeset; - size_t name_len; -{ - int len = 0; - int only_digit = 1; - char *retval; - char *wp; - size_t cnt; - - for (cnt = 0; cnt < name_len; ++cnt) - if (isalnum (codeset[cnt])) - { - ++len; - - if (isalpha (codeset[cnt])) - only_digit = 0; - } - - retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1); - - if (retval != NULL) - { - if (only_digit) - wp = stpcpy (retval, "iso"); - else - wp = retval; - - for (cnt = 0; cnt < name_len; ++cnt) - if (isalpha (codeset[cnt])) - *wp++ = tolower (codeset[cnt]); - else if (isdigit (codeset[cnt])) - *wp++ = codeset[cnt]; - - *wp = '\0'; - } - - return (const char *) retval; -} - - -struct localedef_t * -add_to_readlist (int locale, const char *name, const char *repertoire_name, - int generate, struct localedef_t *copy_locale) -{ - struct localedef_t *runp = locales; - - while (runp != NULL && strcmp (name, runp->name) != 0) - runp = runp->next; - - if (runp == NULL) - { - /* Add a new entry at the end. */ - struct localedef_t *newp; - - assert (generate == 1); - - newp = xcalloc (1, sizeof (struct localedef_t)); - newp->name = name; - newp->repertoire_name = repertoire_name; - - if (locales == NULL) - runp = locales = newp; - else - { - runp = locales; - while (runp->next != NULL) - runp = runp->next; - runp = runp->next = newp; - } - } - - if (generate && (runp->needed & (1 << locale)) != 0) - error (5, 0, _("circular dependencies between locale definitions")); - - if (copy_locale != NULL) - { - if (runp->categories[locale].generic != NULL) - error (5, 0, _("cannot add already read locale `%s' a second time"), - name); - else - runp->categories[locale].generic = - copy_locale->categories[locale].generic; - } - - runp->needed |= 1 << locale; - - return runp; -} - - -struct localedef_t * -find_locale (int locale, const char *name, const char *repertoire_name, - struct charmap_t *charmap) -{ - struct localedef_t *result; - - /* Find the locale, but do not generate it since this would be a bug. */ - result = add_to_readlist (locale, name, repertoire_name, 0, NULL); - - assert (result != NULL); - - if ((result->avail & (1 << locale)) == 0 - && locfile_read (result, charmap) != 0) - error (4, errno, _("cannot open locale definition file `%s'"), - result->name); - - return result; -} - - -struct localedef_t * -load_locale (int locale, const char *name, const char *repertoire_name, - struct charmap_t *charmap, struct localedef_t *copy_locale) -{ - struct localedef_t *result; - - /* Generate the locale if it does not exist. */ - result = add_to_readlist (locale, name, repertoire_name, 1, copy_locale); - - assert (result != NULL); - - if ((result->avail & (1 << locale)) == 0 - && locfile_read (result, charmap) != 0) - error (4, errno, _("cannot open locale definition file `%s'"), - result->name); - - return result; -} - -static void -turn_on_mcheck (void) -{ - /* Enable `malloc' debugging. */ - mcheck (NULL); - /* Use the following line for a more thorough but much slower testing. */ - /* mcheck_pedantic (NULL); */ -} - -void (*__malloc_initialize_hook) (void) = turn_on_mcheck; diff --git a/src/system/libroot/posix/glibc/locale/programs/localedef.h b/src/system/libroot/posix/glibc/locale/programs/localedef.h deleted file mode 100644 index dc631e96ac..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/localedef.h +++ /dev/null @@ -1,142 +0,0 @@ -/* General definitions for localedef(1). - Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LOCALEDEF_H -#define _LOCALEDEF_H 1 - -/* Get the basic locale definitions. */ -#include -#include - -#include "repertoire.h" - - -/* We need a bitmask for the locales. */ -enum -{ - CTYPE_LOCALE = 1 << LC_CTYPE, - NUMERIC_LOCALE = 1 << LC_NUMERIC, - TIME_LOCALE = 1 << LC_TIME, - COLLATE_LOCALE = 1 << LC_COLLATE, - MONETARY_LOCALE = 1 << LC_MONETARY, - MESSAGES_LOCALE = 1 << LC_MESSAGES, - PAPER_LOCALE = 1 << LC_PAPER, - NAME_LOCALE = 1 << LC_NAME, - ADDRESS_LOCALE = 1 << LC_ADDRESS, - TELEPHONE_LOCALE = 1 << LC_TELEPHONE, - MEASUREMENT_LOCALE = 1 << LC_MEASUREMENT, - IDENTIFICATION_LOCALE = 1 << LC_IDENTIFICATION, - ALL_LOCALES = (1 << LC_CTYPE - | 1 << LC_NUMERIC - | 1 << LC_TIME - | 1 << LC_COLLATE - | 1 << LC_MONETARY - | 1 << LC_MESSAGES - | 1 << LC_PAPER - | 1 << LC_NAME - | 1 << LC_ADDRESS - | 1 << LC_TELEPHONE - | 1 << LC_MEASUREMENT - | 1 << LC_IDENTIFICATION) -}; - - -/* Opaque types for the different locales. */ -struct locale_ctype_t; -struct locale_collate_t; -struct locale_monetary_t; -struct locale_numeric_t; -struct locale_time_t; -struct locale_messages_t; -struct locale_paper_t; -struct locale_name_t; -struct locale_address_t; -struct locale_telephone_t; -struct locale_measurement_t; -struct locale_identification_t; - - -/* Definitions for the locale. */ -struct localedef_t -{ - struct localedef_t *next; - - const char *name; - - int needed; - int avail; - - union - { - void *generic; - struct locale_ctype_t *ctype; - struct locale_collate_t *collate; - struct locale_monetary_t *monetary; - struct locale_numeric_t *numeric; - struct locale_time_t *time; - struct locale_messages_t *messages; - struct locale_paper_t *paper; - struct locale_name_t *name; - struct locale_address_t *address; - struct locale_telephone_t *telephone; - struct locale_measurement_t *measurement; - struct locale_identification_t *identification; - } categories[__LC_LAST]; - - size_t len[__LC_LAST]; - - const char *copy_name[__LC_LAST]; - - const char *repertoire_name; -}; - - -/* Global variables of the localedef program. */ -extern int verbose; -extern int be_quiet; -extern int oldstyle_tables; -extern const char *repertoire_global; - - -/* Prototypes for a few program-wide used functions. */ -extern void *xmalloc (size_t __n); -extern void *xcalloc (size_t __n, size_t __size); -extern void *xrealloc (void *__p, size_t __n); -extern char *xstrdup (const char *__str); - - -/* Mark given locale as to be read. */ -extern struct localedef_t *add_to_readlist (int locale, const char *name, - const char *repertoire_name, - int generate, - struct localedef_t *copy_locale); - -/* Find the information for the locale NAME. */ -extern struct localedef_t *find_locale (int locale, const char *name, - const char *repertoire_name, - struct charmap_t *charmap); - -/* Load (if necessary) the information for the locale NAME. */ -extern struct localedef_t *load_locale (int locale, const char *name, - const char *repertoire_name, - struct charmap_t *charmap, - struct localedef_t *copy_locale); - -#endif /* localedef.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/locarchive.c b/src/system/libroot/posix/glibc/locale/programs/locarchive.c deleted file mode 100644 index 64e1467109..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locarchive.c +++ /dev/null @@ -1,1527 +0,0 @@ -/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../crypt/md5.h" -#include "../localeinfo.h" -#include "../locarchive.h" -#include "localedef.h" - -/* Define the hash function. We define the function as static inline. - We must change the name so as not to conflict with simple-hash.h. */ -#define compute_hashval static inline archive_hashval -#define hashval_t uint32_t -#include "hashval.h" -#undef compute_hashval - -extern const char *output_prefix; - -#define ARCHIVE_NAME LOCALEDIR "/locale-archive" - -static const char *locnames[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = category_name, -#include "categories.def" -#undef DEFINE_CATEGORY - }; - - -/* Size of the initial archive header. */ -#define INITIAL_NUM_NAMES 450 -#define INITIAL_SIZE_STRINGS 3500 -#define INITIAL_NUM_LOCREC 350 -#define INITIAL_NUM_SUMS 2000 - - -static void -create_archive (const char *archivefname, struct locarhandle *ah) -{ - int fd; - char fname[strlen (archivefname) + sizeof (".XXXXXX")]; - struct locarhead head; - void *p; - size_t total; - - strcpy (stpcpy (fname, archivefname), ".XXXXXX"); - - /* Create a temporary file in the correct directory. */ - fd = mkstemp (fname); - if (fd == -1) - error (EXIT_FAILURE, errno, _("cannot create temporary file")); - - /* Create the initial content of the archive. */ - head.magic = AR_MAGIC; - head.namehash_offset = sizeof (struct locarhead); - head.namehash_used = 0; - head.namehash_size = next_prime (INITIAL_NUM_NAMES); - - head.string_offset = (head.namehash_offset - + head.namehash_size * sizeof (struct namehashent)); - head.string_used = 0; - head.string_size = INITIAL_SIZE_STRINGS; - - head.locrectab_offset = head.string_offset + head.string_size; - head.locrectab_used = 0; - head.locrectab_size = INITIAL_NUM_LOCREC; - - head.sumhash_offset = (head.locrectab_offset - + head.locrectab_size * sizeof (struct locrecent)); - head.sumhash_used = 0; - head.sumhash_size = next_prime (INITIAL_NUM_SUMS); - - total = head.sumhash_offset + head.sumhash_size * sizeof (struct sumhashent); - - /* Write out the header and create room for the other data structures. */ - if (TEMP_FAILURE_RETRY (write (fd, &head, sizeof (head))) != sizeof (head)) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot initialize archive file")); - } - - if (ftruncate64 (fd, total) != 0) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot resize archive file")); - } - - /* Map the header and all the administration data structures. */ - p = mmap64 (NULL, total, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (p == MAP_FAILED) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot map archive header")); - } - - /* Now try to rename it. We don't use the rename function since - this would overwrite a file which has been created in - parallel. */ - if (link (fname, archivefname) == -1) - { - int errval = errno; - - /* We cannot use the just created file. */ - close (fd); - unlink (fname); - - if (errval == EEXIST) - { - /* There is already an archive. Must have been a localedef run - which happened in parallel. Simply open this file then. */ - open_archive (ah, false); - return; - } - - error (EXIT_FAILURE, errval, _("failed to create new locale archive")); - } - - /* Remove the temporary name. */ - unlink (fname); - - /* Make the file globally readable. */ - if (fchmod (fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) - { - int errval = errno; - unlink (archivefname); - error (EXIT_FAILURE, errval, - _("cannot change mode of new locale archive")); - } - - ah->fd = fd; - ah->addr = p; - ah->len = total; -} - - -/* This structure and qsort comparator function are used below to sort an - old archive's locrec table in order of data position in the file. */ -struct oldlocrecent -{ - unsigned int cnt; - struct locrecent *locrec; -}; - -static int -oldlocrecentcmp (const void *a, const void *b) -{ - struct locrecent *la = ((const struct oldlocrecent *) a)->locrec; - struct locrecent *lb = ((const struct oldlocrecent *) b)->locrec; - uint32_t start_a = -1, end_a = 0; - uint32_t start_b = -1, end_b = 0; - int cnt; - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - if (la->record[cnt].offset < start_a) - start_a = la->record[cnt].offset; - if (la->record[cnt].offset + la->record[cnt].len > end_a) - end_a = la->record[cnt].offset + la->record[cnt].len; - } - assert (start_a != (uint32_t)-1); - assert (end_a != 0); - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - if (lb->record[cnt].offset < start_b) - start_b = lb->record[cnt].offset; - if (lb->record[cnt].offset + lb->record[cnt].len > end_b) - end_b = lb->record[cnt].offset + lb->record[cnt].len; - } - assert (start_b != (uint32_t)-1); - assert (end_b != 0); - - if (start_a != start_b) - return (int)start_a - (int)start_b; - return (int)end_a - (int)end_b; -} - - -/* forward decl for below */ -static uint32_t add_locale (struct locarhandle *ah, const char *name, - locale_data_t data, bool replace); - -static void -enlarge_archive (struct locarhandle *ah, const struct locarhead *head) -{ - struct stat64 st; - int fd; - struct locarhead newhead; - size_t total; - void *p; - unsigned int cnt, loccnt; - struct namehashent *oldnamehashtab; - struct locrecent *oldlocrectab; - struct locarhandle new_ah; - size_t prefix_len = output_prefix ? strlen (output_prefix) : 0; - char archivefname[prefix_len + sizeof (ARCHIVE_NAME)]; - char fname[prefix_len + sizeof (ARCHIVE_NAME) + sizeof (".XXXXXX") - 1]; - struct oldlocrecent *oldlocrecarray; - - if (output_prefix) - memcpy (archivefname, output_prefix, prefix_len); - strcpy (archivefname + prefix_len, ARCHIVE_NAME); - strcpy (stpcpy (fname, archivefname), ".XXXXXX"); - - /* Not all of the old file has to be mapped. Change this now this - we will have to access the whole content. */ - if (fstat64 (ah->fd, &st) != 0 - || (ah->addr = mmap64 (NULL, st.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, ah->fd, 0)) == MAP_FAILED) - error (EXIT_FAILURE, errno, _("cannot map locale archive file")); - ah->len = st.st_size; - - /* Create a temporary file in the correct directory. */ - fd = mkstemp (fname); - if (fd == -1) - error (EXIT_FAILURE, errno, _("cannot create temporary file")); - - /* Copy the existing head information. */ - newhead = *head; - - /* Create the new archive header. The sizes of the various tables - should be double from what is currently used. */ - newhead.namehash_size = MAX (next_prime (2 * newhead.namehash_used), - newhead.namehash_size); - if (! be_quiet) - printf ("name: size: %u, used: %d, new: size: %u\n", - head->namehash_size, head->namehash_used, newhead.namehash_size); - - newhead.string_offset = (newhead.namehash_offset - + (newhead.namehash_size - * sizeof (struct namehashent))); - /* Keep the string table size aligned to 4 bytes, so that - all the struct { uint32_t } types following are happy. */ - newhead.string_size = MAX ((2 * newhead.string_used + 3) & -4, - newhead.string_size); - - newhead.locrectab_offset = newhead.string_offset + newhead.string_size; - newhead.locrectab_size = MAX (2 * newhead.locrectab_used, - newhead.locrectab_size); - - newhead.sumhash_offset = (newhead.locrectab_offset - + (newhead.locrectab_size - * sizeof (struct locrecent))); - newhead.sumhash_size = MAX (next_prime (2 * newhead.sumhash_used), - newhead.sumhash_size); - - total = (newhead.sumhash_offset - + newhead.sumhash_size * sizeof (struct sumhashent)); - - /* The new file is empty now. */ - newhead.namehash_used = 0; - newhead.string_used = 0; - newhead.locrectab_used = 0; - newhead.sumhash_used = 0; - - /* Write out the header and create room for the other data structures. */ - if (TEMP_FAILURE_RETRY (write (fd, &newhead, sizeof (newhead))) - != sizeof (newhead)) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot initialize archive file")); - } - - if (ftruncate64 (fd, total) != 0) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot resize archive file")); - } - - /* Map the header and all the administration data structures. */ - p = mmap64 (NULL, total, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (p == MAP_FAILED) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot map archive header")); - } - - /* Lock the new file. */ - if (lockf64 (fd, F_LOCK, total) != 0) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot lock new archive")); - } - - new_ah.len = total; - new_ah.addr = p; - new_ah.fd = fd; - - /* Walk through the hash name hash table to find out what data is - still referenced and transfer it into the new file. */ - oldnamehashtab = (struct namehashent *) ((char *) ah->addr - + head->namehash_offset); - oldlocrectab = (struct locrecent *) ((char *) ah->addr - + head->locrectab_offset); - - /* Sort the old locrec table in order of data position. */ - oldlocrecarray = (struct oldlocrecent *) - alloca (head->namehash_size - * sizeof (struct oldlocrecent)); - for (cnt = 0, loccnt = 0; cnt < head->namehash_size; ++cnt) - if (oldnamehashtab[cnt].locrec_offset != 0) - { - oldlocrecarray[loccnt].cnt = cnt; - oldlocrecarray[loccnt++].locrec - = (struct locrecent *) ((char *) ah->addr - + oldnamehashtab[cnt].locrec_offset); - } - qsort (oldlocrecarray, loccnt, sizeof (struct oldlocrecent), - oldlocrecentcmp); - - for (cnt = 0; cnt < loccnt; ++cnt) - { - /* Insert this entry in the new hash table. */ - locale_data_t old_data; - unsigned int idx; - struct locrecent *oldlocrec = oldlocrecarray[cnt].locrec; - - for (idx = 0; idx < __LC_LAST; ++idx) - if (idx != LC_ALL) - { - old_data[idx].size = oldlocrec->record[idx].len; - old_data[idx].addr - = ((char *) ah->addr + oldlocrec->record[idx].offset); - - __md5_buffer (old_data[idx].addr, old_data[idx].size, - old_data[idx].sum); - } - - if (add_locale (&new_ah, - ((char *) ah->addr - + oldnamehashtab[oldlocrecarray[cnt].cnt].name_offset), - old_data, 0) == 0) - error (EXIT_FAILURE, 0, _("cannot extend locale archive file")); - } - - /* Make the file globally readable. */ - if (fchmod (fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, - _("cannot change mode of resized locale archive")); - } - - /* Rename the new file. */ - if (rename (fname, archivefname) != 0) - { - int errval = errno; - unlink (fname); - error (EXIT_FAILURE, errval, _("cannot rename new archive")); - } - - /* Close the old file. */ - close_archive (ah); - - /* Add the information for the new one. */ - *ah = new_ah; -} - - -void -open_archive (struct locarhandle *ah, bool readonly) -{ - struct stat64 st; - struct stat64 st2; - int fd; - struct locarhead head; - int retry = 0; - size_t prefix_len = output_prefix ? strlen (output_prefix) : 0; - char archivefname[prefix_len + sizeof (ARCHIVE_NAME)]; - - if (output_prefix) - memcpy (archivefname, output_prefix, prefix_len); - strcpy (archivefname + prefix_len, ARCHIVE_NAME); - - while (1) - { - /* Open the archive. We must have exclusive write access. */ - fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR); - if (fd == -1) - { - /* Maybe the file does not yet exist. */ - if (errno == ENOENT) - { - if (readonly) - { - static const struct locarhead nullhead = - { - .namehash_used = 0, - .namehash_offset = 0, - .namehash_size = 0 - }; - - ah->addr = (void *) &nullhead; - ah->fd = -1; - } - else - create_archive (archivefname, ah); - - return; - } - else - error (EXIT_FAILURE, errno, _("cannot open locale archive \"%s\""), - archivefname); - } - - if (fstat64 (fd, &st) < 0) - error (EXIT_FAILURE, errno, _("cannot stat locale archive \"%s\""), - archivefname); - - if (!readonly && lockf64 (fd, F_LOCK, sizeof (struct locarhead)) == -1) - { - close (fd); - - if (retry++ < max_locarchive_open_retry) - { - struct timespec req; - - /* Wait for a bit. */ - req.tv_sec = 0; - req.tv_nsec = 1000000 * (random () % 500 + 1); - (void) nanosleep (&req, NULL); - - continue; - } - - error (EXIT_FAILURE, errno, _("cannot lock locale archive \"%s\""), - archivefname); - } - - /* One more check. Maybe another process replaced the archive file - with a new, larger one since we opened the file. */ - if (stat64 (archivefname, &st2) == -1 - || st.st_dev != st2.st_dev - || st.st_ino != st2.st_ino) - { - (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead)); - close (fd); - continue; - } - - /* Leave the loop. */ - break; - } - - /* Read the header. */ - if (TEMP_FAILURE_RETRY (read (fd, &head, sizeof (head))) != sizeof (head)) - { - (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead)); - error (EXIT_FAILURE, errno, _("cannot read archive header")); - } - - ah->fd = fd; - ah->len = (head.sumhash_offset - + head.sumhash_size * sizeof (struct sumhashent)); - - /* Now we know how large the administrative information part is. - Map all of it. */ - ah->addr = mmap64 (NULL, ah->len, PROT_READ | (readonly ? 0 : PROT_WRITE), - MAP_SHARED, fd, 0); - if (ah->addr == MAP_FAILED) - { - (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead)); - error (EXIT_FAILURE, errno, _("cannot map archive header")); - } -} - - -void -close_archive (struct locarhandle *ah) -{ - if (ah->fd != -1) - { - munmap (ah->addr, ah->len); - close (ah->fd); - } -} - -#include "../../intl/explodename.c" -#include "../../intl/l10nflist.c" - -static struct namehashent * -insert_name (struct locarhandle *ah, - const char *name, size_t name_len, bool replace) -{ - const struct locarhead *const head = ah->addr; - struct namehashent *namehashtab - = (struct namehashent *) ((char *) ah->addr + head->namehash_offset); - unsigned int insert_idx, idx, incr; - - /* Hash value of the locale name. */ - uint32_t hval = archive_hashval (name, name_len); - - insert_idx = -1; - idx = hval % head->namehash_size; - incr = 1 + hval % (head->namehash_size - 2); - - /* If the name_offset field is zero this means this is a - deleted entry and therefore no entry can be found. */ - while (namehashtab[idx].name_offset != 0) - { - if (namehashtab[idx].hashval == hval - && strcmp (name, - (char *) ah->addr + namehashtab[idx].name_offset) == 0) - { - /* Found the entry. */ - if (namehashtab[idx].locrec_offset != 0 && ! replace) - { - if (! be_quiet) - error (0, 0, _("locale '%s' already exists"), name); - return NULL; - } - - break; - } - - if (namehashtab[idx].hashval == hval && ! be_quiet) - { - error (0, 0, "hash collision (%u) %s, %s", - hval, name, (char *) ah->addr + namehashtab[idx].name_offset); - } - - /* Remember the first place we can insert the new entry. */ - if (namehashtab[idx].locrec_offset == 0 && insert_idx == -1) - insert_idx = idx; - - idx += incr; - if (idx >= head->namehash_size) - idx -= head->namehash_size; - } - - /* Add as early as possible. */ - if (insert_idx != -1) - idx = insert_idx; - - namehashtab[idx].hashval = hval; /* no-op if replacing an old entry. */ - return &namehashtab[idx]; -} - -static void -add_alias (struct locarhandle *ah, const char *alias, bool replace, - const char *oldname, uint32_t *locrec_offset_p) -{ - uint32_t locrec_offset = *locrec_offset_p; - struct locarhead *head = ah->addr; - const size_t name_len = strlen (alias); - struct namehashent *namehashent = insert_name (ah, alias, strlen (alias), - replace); - if (namehashent == NULL && ! replace) - return; - - if (namehashent->name_offset == 0) - { - /* We are adding a new hash entry for this alias. - Determine whether we have to resize the file. */ - if (head->string_used + name_len + 1 > head->string_size - || 100 * head->namehash_used > 75 * head->namehash_size) - { - /* The current archive is not large enough. */ - enlarge_archive (ah, head); - - /* The locrecent might have moved, so we have to look up - the old name afresh. */ - namehashent = insert_name (ah, oldname, strlen (oldname), true); - assert (namehashent->name_offset != 0); - assert (namehashent->locrec_offset != 0); - *locrec_offset_p = namehashent->locrec_offset; - - /* Tail call to try the whole thing again. */ - add_alias (ah, alias, replace, oldname, locrec_offset_p); - return; - } - - /* Add the name string. */ - memcpy (ah->addr + head->string_offset + head->string_used, - alias, name_len + 1); - namehashent->name_offset = head->string_offset + head->string_used; - head->string_used += name_len + 1; - - ++head->namehash_used; - } - - if (namehashent->locrec_offset != 0) - { - /* Replacing an existing entry. - Mark that we are no longer using the old locrecent. */ - struct locrecent *locrecent - = (struct locrecent *) ((char *) ah->addr - + namehashent->locrec_offset); - --locrecent->refs; - } - - /* Point this entry at the locrecent installed for the main name. */ - namehashent->locrec_offset = locrec_offset; -} - -static int /* qsort comparator used below */ -cmpcategorysize (const void *a, const void *b) -{ - if (*(const void **) a == NULL) - return 1; - if (*(const void **) b == NULL) - return -1; - return ((*(const struct locale_category_data **) a)->size - - (*(const struct locale_category_data **) b)->size); -} - -/* Check the content of the archive for duplicates. Add the content - of the files if necessary. Returns the locrec_offset. */ -static uint32_t -add_locale (struct locarhandle *ah, - const char *name, locale_data_t data, bool replace) -{ - /* First look for the name. If it already exists and we are not - supposed to replace it don't do anything. If it does not exist - we have to allocate a new locale record. */ - size_t name_len = strlen (name); - uint32_t file_offsets[__LC_LAST]; - unsigned int num_new_offsets = 0; - struct sumhashent *sumhashtab; - uint32_t hval; - unsigned int cnt, idx; - struct locarhead *head; - struct namehashent *namehashent; - unsigned int incr; - struct locrecent *locrecent; - off64_t lastoffset; - char *ptr; - struct locale_category_data *size_order[__LC_LAST]; - const size_t pagesz = getpagesize (); - int small_mask; - - head = ah->addr; - sumhashtab = (struct sumhashent *) ((char *) ah->addr - + head->sumhash_offset); - - memset (file_offsets, 0, sizeof (file_offsets)); - - size_order[LC_ALL] = NULL; - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - size_order[cnt] = &data[cnt]; - - /* Sort the array in ascending order of data size. */ - qsort (size_order, __LC_LAST, sizeof size_order[0], cmpcategorysize); - - small_mask = 0; - data[LC_ALL].size = 0; - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (size_order[cnt] != NULL) - { - const size_t rounded_size = (size_order[cnt]->size + 15) & -16; - if (data[LC_ALL].size + rounded_size > 2 * pagesz) - { - /* This category makes the small-categories block - stop being small, so this is the end of the road. */ - do - size_order[cnt++] = NULL; - while (cnt < __LC_LAST); - break; - } - data[LC_ALL].size += rounded_size; - small_mask |= 1 << (size_order[cnt] - data); - } - - /* Copy the data for all the small categories into the LC_ALL - pseudo-category. */ - - data[LC_ALL].addr = alloca (data[LC_ALL].size); - memset (data[LC_ALL].addr, 0, data[LC_ALL].size); - - ptr = data[LC_ALL].addr; - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (small_mask & (1 << cnt)) - { - memcpy (ptr, data[cnt].addr, data[cnt].size); - ptr += (data[cnt].size + 15) & -16; - } - __md5_buffer (data[LC_ALL].addr, data[LC_ALL].size, data[LC_ALL].sum); - - /* For each locale category data set determine whether the same data - is already somewhere in the archive. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (small_mask == 0 ? cnt != LC_ALL : !(small_mask & (1 << cnt))) - { - ++num_new_offsets; - - /* Compute the hash value of the checksum to determine a - starting point for the search in the MD5 hash value - table. */ - hval = archive_hashval (data[cnt].sum, 16); - - idx = hval % head->sumhash_size; - incr = 1 + hval % (head->sumhash_size - 2); - - while (sumhashtab[idx].file_offset != 0) - { - if (memcmp (data[cnt].sum, sumhashtab[idx].sum, 16) == 0) - { - /* Found it. */ - file_offsets[cnt] = sumhashtab[idx].file_offset; - --num_new_offsets; - break; - } - - idx += incr; - if (idx >= head->sumhash_size) - idx -= head->sumhash_size; - } - } - - /* Find a slot for the locale name in the hash table. */ - namehashent = insert_name (ah, name, name_len, replace); - if (namehashent == NULL) /* Already exists and !REPLACE. */ - return 0; - - /* Determine whether we have to resize the file. */ - if (100 * (head->sumhash_used + num_new_offsets) > 75 * head->sumhash_size - || (namehashent->locrec_offset == 0 - && (head->locrectab_used == head->locrectab_size - || head->string_used + name_len + 1 > head->string_size - || 100 * head->namehash_used > 75 * head->namehash_size))) - { - /* The current archive is not large enough. */ - enlarge_archive (ah, head); - return add_locale (ah, name, data, replace); - } - - /* Add the locale data which is not yet in the archive. */ - for (cnt = 0, lastoffset = 0; cnt < __LC_LAST; ++cnt) - if ((small_mask == 0 ? cnt != LC_ALL : !(small_mask & (1 << cnt))) - && file_offsets[cnt] == 0) - { - /* The data for this section is not yet available in the - archive. Append it. */ - off64_t lastpos; - uint32_t md5hval; - - lastpos = lseek64 (ah->fd, 0, SEEK_END); - if (lastpos == (off64_t) -1) - error (EXIT_FAILURE, errno, _("cannot add to locale archive")); - - /* If block of small categories would cross page boundary, - align it unless it immediately follows a large category. */ - if (cnt == LC_ALL && lastoffset != lastpos - && ((((lastpos & (pagesz - 1)) + data[cnt].size + pagesz - 1) - & -pagesz) - > ((data[cnt].size + pagesz - 1) & -pagesz))) - { - size_t sz = pagesz - (lastpos & (pagesz - 1)); - char *zeros = alloca (sz); - - memset (zeros, 0, sz); - if (TEMP_FAILURE_RETRY (write (ah->fd, zeros, sz) != sz)) - error (EXIT_FAILURE, errno, - _("cannot add to locale archive")); - - lastpos += sz; - } - - /* Align all data to a 16 byte boundary. */ - if ((lastpos & 15) != 0) - { - static const char zeros[15] = { 0, }; - - if (TEMP_FAILURE_RETRY (write (ah->fd, zeros, 16 - (lastpos & 15))) - != 16 - (lastpos & 15)) - error (EXIT_FAILURE, errno, _("cannot add to locale archive")); - - lastpos += 16 - (lastpos & 15); - } - - /* Remember the position. */ - file_offsets[cnt] = lastpos; - lastoffset = lastpos + data[cnt].size; - - /* Write the data. */ - if (TEMP_FAILURE_RETRY (write (ah->fd, data[cnt].addr, data[cnt].size)) - != data[cnt].size) - error (EXIT_FAILURE, errno, _("cannot add to locale archive")); - - /* Add the hash value to the hash table. */ - md5hval = archive_hashval (data[cnt].sum, 16); - - idx = md5hval % head->sumhash_size; - incr = 1 + md5hval % (head->sumhash_size - 2); - - while (sumhashtab[idx].file_offset != 0) - { - idx += incr; - if (idx >= head->sumhash_size) - idx -= head->sumhash_size; - } - - memcpy (sumhashtab[idx].sum, data[cnt].sum, 16); - sumhashtab[idx].file_offset = file_offsets[cnt]; - - ++head->sumhash_used; - } - - lastoffset = file_offsets[LC_ALL]; - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (small_mask & (1 << cnt)) - { - file_offsets[cnt] = lastoffset; - lastoffset += (data[cnt].size + 15) & -16; - } - - if (namehashent->name_offset == 0) - { - /* Add the name string. */ - memcpy ((char *) ah->addr + head->string_offset + head->string_used, - name, name_len + 1); - namehashent->name_offset = head->string_offset + head->string_used; - head->string_used += name_len + 1; - ++head->namehash_used; - } - - if (namehashent->locrec_offset == 0) - { - /* Allocate a name location record. */ - namehashent->locrec_offset = (head->locrectab_offset - + (head->locrectab_used++ - * sizeof (struct locrecent))); - locrecent = (struct locrecent *) ((char *) ah->addr - + namehashent->locrec_offset); - locrecent->refs = 1; - } - else - { - /* If there are other aliases pointing to this locrecent, - we still need a new one. If not, reuse the old one. */ - - locrecent = (struct locrecent *) ((char *) ah->addr - + namehashent->locrec_offset); - if (locrecent->refs > 1) - { - --locrecent->refs; - namehashent->locrec_offset = (head->locrectab_offset - + (head->locrectab_used++ - * sizeof (struct locrecent))); - locrecent = (struct locrecent *) ((char *) ah->addr - + namehashent->locrec_offset); - locrecent->refs = 1; - } - } - - /* Fill in the table with the locations of the locale data. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - { - locrecent->record[cnt].offset = file_offsets[cnt]; - locrecent->record[cnt].len = data[cnt].size; - } - - return namehashent->locrec_offset; -} - - -/* Check the content of the archive for duplicates. Add the content - of the files if necessary. Add all the names, possibly overwriting - old files. */ -int -add_locale_to_archive (ah, name, data, replace) - struct locarhandle *ah; - const char *name; - locale_data_t data; - bool replace; -{ - char *normalized_name = NULL; - uint32_t locrec_offset; - - /* First analyze the name to decide how to archive it. */ - const char *language; - const char *modifier; - const char *territory; - const char *codeset; - const char *normalized_codeset; - int mask = _nl_explode_name (strdupa (name), - &language, &modifier, &territory, - &codeset, &normalized_codeset); - - if (mask & XPG_NORM_CODESET) - /* This name contains a codeset in unnormalized form. - We will store it in the archive with a normalized name. */ - asprintf (&normalized_name, "%s%s%s.%s%s%s", - language, territory == NULL ? "" : "_", territory ?: "", - (mask & XPG_NORM_CODESET) ? normalized_codeset : codeset, - modifier == NULL ? "" : "@", modifier ?: ""); - - /* This call does the main work. */ - locrec_offset = add_locale (ah, normalized_name ?: name, data, replace); - if (locrec_offset == 0) - { - free (normalized_name); - if (mask & XPG_NORM_CODESET) - free ((char *) normalized_codeset); - return -1; - } - - if ((mask & XPG_CODESET) == 0) - { - /* This name lacks a codeset, so determine the locale's codeset and - add an alias for its name with normalized codeset appended. */ - - const struct - { - unsigned int magic; - unsigned int nstrings; - unsigned int strindex[0]; - } *filedata = data[LC_CTYPE].addr; - codeset = (char *) filedata - + filedata->strindex[_NL_ITEM_INDEX (_NL_CTYPE_CODESET_NAME)]; - char *normalized_codeset_name = NULL; - - normalized_codeset = _nl_normalize_codeset (codeset, strlen (codeset)); - mask |= XPG_NORM_CODESET; - - asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s", - language, territory == NULL ? "" : "_", territory ?: "", - normalized_codeset, - modifier == NULL ? "" : "@", modifier ?: ""); - - add_alias (ah, normalized_codeset_name, replace, - normalized_name ?: name, &locrec_offset); - free (normalized_codeset_name); - } - - /* Now read the locale.alias files looking for lines whose - right hand side matches our name after normalization. */ - if (alias_file != NULL) - { - FILE *fp; - fp = fopen (alias_file, "rm"); - if (fp == NULL) - error (1, errno, _("locale alias file `%s' not found"), - alias_file); - - /* No threads present. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - while (! feof_unlocked (fp)) - { - /* It is a reasonable approach to use a fix buffer here - because - a) we are only interested in the first two fields - b) these fields must be usable as file names and so must - not be that long */ - char buf[BUFSIZ]; - char *alias; - char *value; - char *cp; - - if (fgets_unlocked (buf, BUFSIZ, fp) == NULL) - /* EOF reached. */ - break; - - cp = buf; - /* Ignore leading white space. */ - while (isspace (cp[0]) && cp[0] != '\n') - ++cp; - - /* A leading '#' signals a comment line. */ - if (cp[0] != '\0' && cp[0] != '#' && cp[0] != '\n') - { - alias = cp++; - while (cp[0] != '\0' && !isspace (cp[0])) - ++cp; - /* Terminate alias name. */ - if (cp[0] != '\0') - *cp++ = '\0'; - - /* Now look for the beginning of the value. */ - while (isspace (cp[0])) - ++cp; - - if (cp[0] != '\0') - { - value = cp++; - while (cp[0] != '\0' && !isspace (cp[0])) - ++cp; - /* Terminate value. */ - if (cp[0] == '\n') - { - /* This has to be done to make the following - test for the end of line possible. We are - looking for the terminating '\n' which do not - overwrite here. */ - *cp++ = '\0'; - *cp = '\n'; - } - else if (cp[0] != '\0') - *cp++ = '\0'; - - /* Does this alias refer to our locale? We will - normalize the right hand side and compare the - elements of the normalized form. */ - { - const char *rhs_language; - const char *rhs_modifier; - const char *rhs_territory; - const char *rhs_codeset; - const char *rhs_normalized_codeset; - int rhs_mask = _nl_explode_name (value, - &rhs_language, - &rhs_modifier, - &rhs_territory, - &rhs_codeset, - &rhs_normalized_codeset); - if (!strcmp (language, rhs_language) - && ((rhs_mask & XPG_CODESET) - /* He has a codeset, it must match normalized. */ - ? !strcmp ((mask & XPG_NORM_CODESET) - ? normalized_codeset : codeset, - (rhs_mask & XPG_NORM_CODESET) - ? rhs_normalized_codeset : rhs_codeset) - /* He has no codeset, we must also have none. */ - : (mask & XPG_CODESET) == 0) - /* Codeset (or lack thereof) matches. */ - && !strcmp (territory ?: "", rhs_territory ?: "") - && !strcmp (modifier ?: "", rhs_modifier ?: "")) - /* We have a winner. */ - add_alias (ah, alias, replace, - normalized_name ?: name, &locrec_offset); - if (rhs_mask & XPG_NORM_CODESET) - free ((char *) rhs_normalized_codeset); - } - } - } - - /* Possibly not the whole line fits into the buffer. - Ignore the rest of the line. */ - while (strchr (cp, '\n') == NULL) - { - cp = buf; - if (fgets_unlocked (buf, BUFSIZ, fp) == NULL) - /* Make sure the inner loop will be left. The outer - loop will exit at the `feof' test. */ - *cp = '\n'; - } - } - - fclose (fp); - } - - free (normalized_name); - - if (mask & XPG_NORM_CODESET) - free ((char *) normalized_codeset); - - return 0; -} - - -int -add_locales_to_archive (nlist, list, replace) - size_t nlist; - char *list[]; - bool replace; -{ - struct locarhandle ah; - int result = 0; - - /* Open the archive. This call never returns if we cannot - successfully open the archive. */ - open_archive (&ah, false); - - while (nlist-- > 0) - { - const char *fname = *list++; - size_t fnamelen = strlen (fname); - struct stat64 st; - DIR *dirp; - struct dirent64 *d; - int seen; - locale_data_t data; - int cnt; - - if (! be_quiet) - printf (_("Adding %s\n"), fname); - - /* First see whether this really is a directory and whether it - contains all the require locale category files. */ - if (stat64 (fname, &st) < 0) - { - error (0, 0, _("stat of \"%s\" failed: %s: ignored"), fname, - strerror (errno)); - continue; - } - if (!S_ISDIR (st.st_mode)) - { - error (0, 0, _("\"%s\" is no directory; ignored"), fname); - continue; - } - - dirp = opendir (fname); - if (dirp == NULL) - { - error (0, 0, _("cannot open directory \"%s\": %s: ignored"), - fname, strerror (errno)); - continue; - } - - seen = 0; - while ((d = readdir64 (dirp)) != NULL) - { - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - if (strcmp (d->d_name, locnames[cnt]) == 0) - { - unsigned char d_type; - - /* We have an object of the required name. If it's - a directory we have to look at a file with the - prefix "SYS_". Otherwise we have found what we - are looking for. */ -#ifdef _DIRENT_HAVE_D_TYPE - d_type = d->d_type; - - if (d_type != DT_REG) -#endif - { - char fullname[fnamelen + 2 * strlen (d->d_name) + 7]; - -#ifdef _DIRENT_HAVE_D_TYPE - if (d_type == DT_UNKNOWN) -#endif - { - strcpy (stpcpy (stpcpy (fullname, fname), "/"), - d->d_name); - - if (stat64 (fullname, &st) == -1) - /* We cannot stat the file, ignore it. */ - break; - - d_type = IFTODT (st.st_mode); - } - - if (d_type == DT_DIR) - { - /* We have to do more tests. The file is a - directory and it therefore must contain a - regular file with the same name except a - "SYS_" prefix. */ - char *t = stpcpy (stpcpy (fullname, fname), "/"); - strcpy (stpcpy (stpcpy (t, d->d_name), "/SYS_"), - d->d_name); - - if (stat64 (fullname, &st) == -1) - /* There is no SYS_* file or we cannot - access it. */ - break; - - d_type = IFTODT (st.st_mode); - } - } - - /* If we found a regular file (eventually after - following a symlink) we are successful. */ - if (d_type == DT_REG) - ++seen; - break; - } - } - - closedir (dirp); - - if (seen != __LC_LAST - 1) - { - /* We don't have all locale category files. Ignore the name. */ - error (0, 0, _("incomplete set of locale files in \"%s\""), - fname); - continue; - } - - /* Add the files to the archive. To do this we first compute - sizes and the MD5 sums of all the files. */ - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - { - char fullname[fnamelen + 2 * strlen (locnames[cnt]) + 7]; - int fd; - - strcpy (stpcpy (stpcpy (fullname, fname), "/"), locnames[cnt]); - fd = open64 (fullname, O_RDONLY); - if (fd == -1 || fstat64 (fd, &st) == -1) - { - /* Cannot read the file. */ - if (fd != -1) - close (fd); - break; - } - - if (S_ISDIR (st.st_mode)) - { - char *t; - close (fd); - t = stpcpy (stpcpy (fullname, fname), "/"); - strcpy (stpcpy (stpcpy (t, locnames[cnt]), "/SYS_"), - locnames[cnt]); - - fd = open64 (fullname, O_RDONLY); - if (fd == -1 || fstat64 (fd, &st) == -1 - || !S_ISREG (st.st_mode)) - { - if (fd != -1) - close (fd); - break; - } - } - - /* Map the file. */ - data[cnt].addr = mmap64 (NULL, st.st_size, PROT_READ, MAP_SHARED, - fd, 0); - if (data[cnt].addr == MAP_FAILED) - { - /* Cannot map it. */ - close (fd); - break; - } - - data[cnt].size = st.st_size; - __md5_buffer (data[cnt].addr, st.st_size, data[cnt].sum); - - /* We don't need the file descriptor anymore. */ - close (fd); - } - - if (cnt != __LC_LAST) - { - while (cnt-- > 0) - if (cnt != LC_ALL) - munmap (data[cnt].addr, data[cnt].size); - - error (0, 0, _("cannot read all files in \"%s\": ignored"), fname); - - continue; - } - - result |= add_locale_to_archive (&ah, basename (fname), data, replace); - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL) - munmap (data[cnt].addr, data[cnt].size); - } - - /* We are done. */ - close_archive (&ah); - - return result; -} - - -int -delete_locales_from_archive (nlist, list) - size_t nlist; - char *list[]; -{ - struct locarhandle ah; - struct locarhead *head; - struct namehashent *namehashtab; - - /* Open the archive. This call never returns if we cannot - successfully open the archive. */ - open_archive (&ah, false); - - head = ah.addr; - namehashtab = (struct namehashent *) ((char *) ah.addr - + head->namehash_offset); - - while (nlist-- > 0) - { - const char *locname = *list++; - uint32_t hval; - unsigned int idx; - unsigned int incr; - - /* Search for this locale in the archive. */ - hval = archive_hashval (locname, strlen (locname)); - - idx = hval % head->namehash_size; - incr = 1 + hval % (head->namehash_size - 2); - - /* If the name_offset field is zero this means this is no - deleted entry and therefore no entry can be found. */ - while (namehashtab[idx].name_offset != 0) - { - if (namehashtab[idx].hashval == hval - && (strcmp (locname, - (char *) ah.addr + namehashtab[idx].name_offset) - == 0)) - { - /* Found the entry. Now mark it as removed by zero-ing - the reference to the locale record. */ - namehashtab[idx].locrec_offset = 0; - break; - } - - idx += incr; - if (idx >= head->namehash_size) - idx -= head->namehash_size; - } - - if (namehashtab[idx].name_offset == 0 && ! be_quiet) - error (0, 0, _("locale \"%s\" not in archive"), locname); - } - - close_archive (&ah); - - return 0; -} - - -struct nameent -{ - char *name; - uint32_t locrec_offset; -}; - - -struct dataent -{ - const unsigned char *sum; - uint32_t file_offset; - uint32_t nlink; -}; - - -static int -nameentcmp (const void *a, const void *b) -{ - return strcmp (((const struct nameent *) a)->name, - ((const struct nameent *) b)->name); -} - - -static int -dataentcmp (const void *a, const void *b) -{ - if (((const struct dataent *) a)->file_offset - < ((const struct dataent *) b)->file_offset) - return -1; - - if (((const struct dataent *) a)->file_offset - > ((const struct dataent *) b)->file_offset) - return 1; - - return 0; -} - - -void -show_archive_content (int verbose) -{ - struct locarhandle ah; - struct locarhead *head; - struct namehashent *namehashtab; - struct nameent *names; - size_t cnt, used; - - /* Open the archive. This call never returns if we cannot - successfully open the archive. */ - open_archive (&ah, true); - - head = ah.addr; - - names = (struct nameent *) xmalloc (head->namehash_used - * sizeof (struct nameent)); - - namehashtab = (struct namehashent *) ((char *) ah.addr - + head->namehash_offset); - for (cnt = used = 0; cnt < head->namehash_size; ++cnt) - if (namehashtab[cnt].locrec_offset != 0) - { - assert (used < head->namehash_used); - names[used].name = ah.addr + namehashtab[cnt].name_offset; - names[used++].locrec_offset = namehashtab[cnt].locrec_offset; - } - - /* Sort the names. */ - qsort (names, used, sizeof (struct nameent), nameentcmp); - - if (verbose) - { - struct dataent *files; - struct sumhashent *sumhashtab; - int sumused; - - files = (struct dataent *) xmalloc (head->sumhash_used - * sizeof (struct sumhashent)); - - sumhashtab = (struct sumhashent *) ((char *) ah.addr - + head->sumhash_offset); - for (cnt = sumused = 0; cnt < head->sumhash_size; ++cnt) - if (sumhashtab[cnt].file_offset != 0) - { - assert (sumused < head->sumhash_used); - files[sumused].sum = (const unsigned char *) sumhashtab[cnt].sum; - files[sumused].file_offset = sumhashtab[cnt].file_offset; - files[sumused++].nlink = 0; - } - - /* Sort by file locations. */ - qsort (files, sumused, sizeof (struct dataent), dataentcmp); - - /* Compute nlink fields. */ - for (cnt = 0; cnt < used; ++cnt) - { - struct locrecent *locrec; - int idx; - - locrec = (struct locrecent *) ((char *) ah.addr - + names[cnt].locrec_offset); - for (idx = 0; idx < __LC_LAST; ++idx) - if (locrec->record[LC_ALL].offset != 0 - ? (idx == LC_ALL - || (locrec->record[idx].offset - < locrec->record[LC_ALL].offset) - || (locrec->record[idx].offset + locrec->record[idx].len - > (locrec->record[LC_ALL].offset - + locrec->record[LC_ALL].len))) - : idx != LC_ALL) - { - struct dataent *data, dataent; - - dataent.file_offset = locrec->record[idx].offset; - data = (struct dataent *) bsearch (&dataent, files, sumused, - sizeof (struct dataent), - dataentcmp); - assert (data != NULL); - ++data->nlink; - } - } - - /* Print it. */ - for (cnt = 0; cnt < used; ++cnt) - { - struct locrecent *locrec; - int idx, i; - - locrec = (struct locrecent *) ((char *) ah.addr - + names[cnt].locrec_offset); - for (idx = 0; idx < __LC_LAST; ++idx) - if (idx != LC_ALL) - { - struct dataent *data, dataent; - - dataent.file_offset = locrec->record[idx].offset; - if (locrec->record[LC_ALL].offset != 0 - && dataent.file_offset >= locrec->record[LC_ALL].offset - && (dataent.file_offset + locrec->record[idx].len - <= (locrec->record[LC_ALL].offset - + locrec->record[LC_ALL].len))) - dataent.file_offset = locrec->record[LC_ALL].offset; - - data = (struct dataent *) bsearch (&dataent, files, sumused, - sizeof (struct dataent), - dataentcmp); - printf ("%6d %7x %3d%c ", - locrec->record[idx].len, locrec->record[idx].offset, - data->nlink, - dataent.file_offset == locrec->record[LC_ALL].offset - ? '+' : ' '); - for (i = 0; i < 16; i += 4) - printf ("%02x%02x%02x%02x", - data->sum[i], data->sum[i + 1], - data->sum[i + 2], data->sum[i + 3]); - printf (" %s/%s\n", names[cnt].name, - idx == LC_MESSAGES ? "LC_MESSAGES/SYS_LC_MESSAGES" - : locnames[idx]); - } - } - } - else - for (cnt = 0; cnt < used; ++cnt) - puts (names[cnt].name); - - close_archive (&ah); - - exit (EXIT_SUCCESS); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/locfile-kw.gperf b/src/system/libroot/posix/glibc/locale/programs/locfile-kw.gperf deleted file mode 100644 index 7a9285d97e..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locfile-kw.gperf +++ /dev/null @@ -1,201 +0,0 @@ -%{ -/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "locfile-token.h" -%} -struct keyword_t ; -%% -escape_char, tok_escape_char, 0 -comment_char, tok_comment_char, 0 -repertoiremap, tok_repertoiremap, 0 -include, tok_include, 0 -LC_CTYPE, tok_lc_ctype, 0 -END, tok_end, 0 -copy, tok_copy, 0 -upper, tok_upper, 0 -lower, tok_lower, 0 -alpha, tok_alpha, 0 -digit, tok_digit, 0 -outdigit, tok_outdigit, 0 -alnum, tok_alnum, 0 -space, tok_space, 0 -cntrl, tok_cntrl, 0 -punct, tok_punct, 0 -graph, tok_graph, 0 -print, tok_print, 0 -xdigit, tok_xdigit, 0 -blank, tok_blank, 0 -charclass, tok_charclass, 0 -class, tok_class, 0 -charconv, tok_charconv, 0 -toupper, tok_toupper, 0 -tolower, tok_tolower, 0 -map, tok_map, 0 -translit_start, tok_translit_start, 0 -translit_end, tok_translit_end, 0 -translit_ignore, tok_translit_ignore, 0 -default_missing, tok_default_missing, 0 -LC_COLLATE, tok_lc_collate, 0 -coll_weight_max, tok_coll_weight_max, 0 -section-symbol, tok_section_symbol, 0 -collating-element, tok_collating_element, 0 -collating-symbol, tok_collating_symbol, 0 -symbol-equivalence, tok_symbol_equivalence, 0 -script, tok_script, 0 -order_start, tok_order_start, 0 -order_end, tok_order_end, 0 -from, tok_from, 0 -forward, tok_forward, 0 -backward, tok_backward, 0 -position, tok_position, 0 -UNDEFINED, tok_undefined, 0 -IGNORE, tok_ignore, 0 -reorder-after, tok_reorder_after, 0 -reorder-end, tok_reorder_end, 0 -reorder-sections-after, tok_reorder_sections_after, 0 -reorder-sections-end, tok_reorder_sections_end, 0 -define, tok_define, 0 -undef, tok_undef, 0 -ifdef, tok_ifdef, 0 -else, tok_else, 0 -elif, tok_elif, 0 -endif, tok_endif, 0 -LC_MONETARY, tok_lc_monetary, 0 -int_curr_symbol, tok_int_curr_symbol, 0 -currency_symbol, tok_currency_symbol, 0 -mon_decimal_point, tok_mon_decimal_point, 0 -mon_thousands_sep, tok_mon_thousands_sep, 0 -mon_grouping, tok_mon_grouping, 0 -positive_sign, tok_positive_sign, 0 -negative_sign, tok_negative_sign, 0 -int_frac_digits, tok_int_frac_digits, 0 -frac_digits, tok_frac_digits, 0 -p_cs_precedes, tok_p_cs_precedes, 0 -p_sep_by_space, tok_p_sep_by_space, 0 -n_cs_precedes, tok_n_cs_precedes, 0 -n_sep_by_space, tok_n_sep_by_space, 0 -p_sign_posn, tok_p_sign_posn, 0 -n_sign_posn, tok_n_sign_posn, 0 -int_p_cs_precedes, tok_int_p_cs_precedes, 0 -int_p_sep_by_space, tok_int_p_sep_by_space, 0 -int_n_cs_precedes, tok_int_n_cs_precedes, 0 -int_n_sep_by_space, tok_int_n_sep_by_space, 0 -int_p_sign_posn, tok_int_p_sign_posn, 0 -int_n_sign_posn, tok_int_n_sign_posn, 0 -duo_int_curr_symbol, tok_duo_int_curr_symbol, 0 -duo_currency_symbol, tok_duo_currency_symbol, 0 -duo_int_frac_digits, tok_duo_int_frac_digits, 0 -duo_frac_digits, tok_duo_frac_digits, 0 -duo_p_cs_precedes, tok_duo_p_cs_precedes, 0 -duo_p_sep_by_space, tok_duo_p_sep_by_space, 0 -duo_n_cs_precedes, tok_duo_n_cs_precedes, 0 -duo_n_sep_by_space, tok_duo_n_sep_by_space, 0 -duo_int_p_cs_precedes, tok_duo_int_p_cs_precedes, 0 -duo_int_p_sep_by_space, tok_duo_int_p_sep_by_space, 0 -duo_int_n_cs_precedes, tok_duo_int_n_cs_precedes, 0 -duo_int_n_sep_by_space, tok_duo_int_n_sep_by_space, 0 -duo_p_sign_posn, tok_duo_p_sign_posn, 0 -duo_n_sign_posn, tok_duo_n_sign_posn, 0 -duo_int_p_sign_posn, tok_duo_int_p_sign_posn, 0 -duo_int_n_sign_posn, tok_duo_int_n_sign_posn, 0 -uno_valid_from, tok_uno_valid_from, 0 -uno_valid_to, tok_uno_valid_to, 0 -duo_valid_from, tok_duo_valid_from, 0 -duo_valid_to, tok_duo_valid_to, 0 -conversion_rate, tok_conversion_rate, 0 -LC_NUMERIC, tok_lc_numeric, 0 -decimal_point, tok_decimal_point, 0 -thousands_sep, tok_thousands_sep, 0 -grouping, tok_grouping, 0 -LC_TIME, tok_lc_time, 0 -abday, tok_abday, 0 -day, tok_day, 0 -week, tok_week, 0 -abmon, tok_abmon, 0 -mon, tok_mon, 0 -d_t_fmt, tok_d_t_fmt, 0 -d_fmt, tok_d_fmt, 0 -t_fmt, tok_t_fmt, 0 -am_pm, tok_am_pm, 0 -t_fmt_ampm, tok_t_fmt_ampm, 0 -era, tok_era, 0 -era_year, tok_era_year, 0 -era_d_fmt, tok_era_d_fmt, 0 -era_d_t_fmt, tok_era_d_t_fmt, 0 -era_t_fmt, tok_era_t_fmt, 0 -alt_digits, tok_alt_digits, 0 -first_weekday, tok_first_weekday, 0 -first_workday, tok_first_workday, 0 -cal_direction, tok_cal_direction, 0 -timezone, tok_timezone, 0 -date_fmt, tok_date_fmt, 0 -LC_MESSAGES, tok_lc_messages, 0 -yesexpr, tok_yesexpr, 0 -noexpr, tok_noexpr, 0 -yesstr, tok_yesstr, 0 -nostr, tok_nostr, 0 -LC_PAPER, tok_lc_paper, 0 -height, tok_height, 0 -width, tok_width, 0 -LC_NAME, tok_lc_name, 0 -name_fmt, tok_name_fmt, 0 -name_gen, tok_name_gen, 0 -name_mr, tok_name_mr, 0 -name_mrs, tok_name_mrs, 0 -name_miss, tok_name_miss, 0 -name_ms, tok_name_ms, 0 -LC_ADDRESS, tok_lc_address, 0 -postal_fmt, tok_postal_fmt, 0 -country_name, tok_country_name, 0 -country_post, tok_country_post, 0 -country_ab2, tok_country_ab2, 0 -country_ab3, tok_country_ab3, 0 -country_num, tok_country_num, 0 -country_car, tok_country_car, 0 -country_isbn, tok_country_isbn, 0 -lang_name, tok_lang_name, 0 -lang_ab, tok_lang_ab, 0 -lang_term, tok_lang_term, 0 -lang_lib, tok_lang_lib, 0 -LC_TELEPHONE, tok_lc_telephone, 0 -tel_int_fmt, tok_tel_int_fmt, 0 -tel_dom_fmt, tok_tel_dom_fmt, 0 -int_select, tok_int_select, 0 -int_prefix, tok_int_prefix, 0 -LC_MEASUREMENT, tok_lc_measurement, 0 -measurement, tok_measurement, 0 -LC_IDENTIFICATION, tok_lc_identification, 0 -title, tok_title, 0 -source, tok_source, 0 -address, tok_address, 0 -contact, tok_contact, 0 -email, tok_email, 0 -tel, tok_tel, 0 -fax, tok_fax, 0 -language, tok_language, 0 -territory, tok_territory, 0 -audience, tok_audience, 0 -application, tok_application, 0 -abbreviation, tok_abbreviation, 0 -revision, tok_revision, 0 -date, tok_date, 0 -category, tok_category, 0 diff --git a/src/system/libroot/posix/glibc/locale/programs/locfile-kw.h b/src/system/libroot/posix/glibc/locale/programs/locfile-kw.h deleted file mode 100644 index da4a63e033..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locfile-kw.h +++ /dev/null @@ -1,428 +0,0 @@ -/* ANSI-C code produced by gperf version 2.7.2 */ -/* Command-line: gperf -acCgopt -k'1,2,5,9,$' -L ANSI-C -N locfile_hash programs/locfile-kw.gperf */ -/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#include "locfile-token.h" -struct keyword_t ; - -#define TOTAL_KEYWORDS 175 -#define MIN_WORD_LENGTH 3 -#define MAX_WORD_LENGTH 22 -#define MIN_HASH_VALUE 3 -#define MAX_HASH_VALUE 687 -/* maximum key range = 685, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static unsigned int -hash (register const char *str, register unsigned int len) -{ - static const unsigned short asso_values[] = - { - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 5, 0, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 15, 688, 0, 0, 0, - 5, 0, 0, 0, 688, 688, 0, 688, 0, 5, - 688, 688, 15, 0, 5, 15, 688, 688, 688, 0, - 688, 688, 688, 688, 688, 75, 688, 0, 0, 65, - 5, 0, 85, 40, 5, 155, 688, 10, 105, 120, - 125, 35, 5, 20, 5, 190, 0, 125, 35, 10, - 30, 35, 0, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688, 688, 688, 688, 688, - 688, 688, 688, 688, 688, 688 - }; - register int hval = len; - - switch (hval) - { - default: - case 9: - hval += asso_values[(unsigned char)str[8]]; - case 8: - case 7: - case 6: - case 5: - hval += asso_values[(unsigned char)str[4]]; - case 4: - case 3: - case 2: - hval += asso_values[(unsigned char)str[1]]; - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval + asso_values[(unsigned char)str[len - 1]]; -} - -#ifdef __GNUC__ -__inline -#endif -const struct keyword_t * -locfile_hash (register const char *str, register unsigned int len) -{ - static const struct keyword_t wordlist[] = - { - {""}, {""}, {""}, - {"END", tok_end, 0}, - {""}, {""}, {""}, - {"LC_TIME", tok_lc_time, 0}, - {"era", tok_era, 0}, - {"date", tok_date, 0}, - {"LC_ADDRESS", tok_lc_address, 0}, - {"LC_MESSAGES", tok_lc_messages, 0}, - {"LC_TELEPHONE", tok_lc_telephone, 0}, - {"LC_CTYPE", tok_lc_ctype, 0}, - {"era_t_fmt", tok_era_t_fmt, 0}, - {"print", tok_print, 0}, - {"height", tok_height, 0}, - {"LC_IDENTIFICATION", tok_lc_identification, 0}, - {""}, - {"era_d_fmt", tok_era_d_fmt, 0}, - {"LC_COLLATE", tok_lc_collate, 0}, - {"IGNORE", tok_ignore, 0}, - {"LC_NAME", tok_lc_name, 0}, - {"backward", tok_backward, 0}, - {"week", tok_week, 0}, - {"LC_NUMERIC", tok_lc_numeric, 0}, - {"reorder-end", tok_reorder_end, 0}, - {""}, - {"reorder-after", tok_reorder_after, 0}, - {"UNDEFINED", tok_undefined, 0}, - {""}, - {"LC_MONETARY", tok_lc_monetary, 0}, - {""}, - {"repertoiremap", tok_repertoiremap, 0}, - {"LC_MEASUREMENT", tok_lc_measurement, 0}, - {""}, {""}, {""}, - {"LC_PAPER", tok_lc_paper, 0}, - {""}, {""}, {""}, {""}, - {"day", tok_day, 0}, - {""}, {""}, - {"yesstr", tok_yesstr, 0}, - {""}, {""}, {""}, {""}, {""}, - {"toupper", tok_toupper, 0}, - {"era_year", tok_era_year, 0}, - {""}, {""}, - {"order_start", tok_order_start, 0}, - {"tolower", tok_tolower, 0}, - {""}, {""}, - {"graph", tok_graph, 0}, - {""}, {""}, {""}, - {"order_end", tok_order_end, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, - {"abday", tok_abday, 0}, - {""}, - {"yesexpr", tok_yesexpr, 0}, - {""}, {""}, - {"t_fmt", tok_t_fmt, 0}, - {""}, {""}, {""}, {""}, - {"d_fmt", tok_d_fmt, 0}, - {""}, {""}, - {"date_fmt", tok_date_fmt, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"grouping", tok_grouping, 0}, - {""}, {""}, - {"tel_dom_fmt", tok_tel_dom_fmt, 0}, - {""}, {""}, {""}, {""}, - {"era_d_t_fmt", tok_era_d_t_fmt, 0}, - {"contact", tok_contact, 0}, - {"tel", tok_tel, 0}, - {"else", tok_else, 0}, - {"alpha", tok_alpha, 0}, - {"country_ab3", tok_country_ab3, 0}, - {""}, {""}, {""}, {""}, - {"country_ab2", tok_country_ab2, 0}, - {"country_post", tok_country_post, 0}, - {"fax", tok_fax, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"map", tok_map, 0}, - {""}, - {"blank", tok_blank, 0}, - {""}, - {"forward", tok_forward, 0}, - {"audience", tok_audience, 0}, - {""}, - {"punct", tok_punct, 0}, - {"define", tok_define, 0}, - {"abbreviation", tok_abbreviation, 0}, - {""}, - {"copy", tok_copy, 0}, - {""}, {""}, {""}, - {"decimal_point", tok_decimal_point, 0}, - {""}, - {"upper", tok_upper, 0}, - {""}, {""}, - {"category", tok_category, 0}, - {""}, - {"conversion_rate", tok_conversion_rate, 0}, - {""}, {""}, {""}, {""}, - {"lower", tok_lower, 0}, - {""}, - {"collating-element", tok_collating_element, 0}, - {"duo_p_sep_by_space", tok_duo_p_sep_by_space, 0}, - {""}, - {"title", tok_title, 0}, - {""}, {""}, - {"timezone", tok_timezone, 0}, - {""}, - {"digit", tok_digit, 0}, - {""}, {""}, {""}, {""}, - {"postal_fmt", tok_postal_fmt, 0}, - {""}, - {"d_t_fmt", tok_d_t_fmt, 0}, - {"position", tok_position, 0}, - {"p_sep_by_space", tok_p_sep_by_space, 0}, - {"nostr", tok_nostr, 0}, - {"noexpr", tok_noexpr, 0}, - {""}, - {"charconv", tok_charconv, 0}, - {""}, - {"width", tok_width, 0}, - {"country_car", tok_country_car, 0}, - {"comment_char", tok_comment_char, 0}, - {""}, {""}, {""}, {""}, - {"lang_ab", tok_lang_ab, 0}, - {"lang_lib", tok_lang_lib, 0}, - {"lang_name", tok_lang_name, 0}, - {""}, {""}, {""}, {""}, - {"elif", tok_elif, 0}, - {""}, - {"xdigit", tok_xdigit, 0}, - {""}, {""}, {""}, - {"space", tok_space, 0}, - {""}, - {"address", tok_address, 0}, - {""}, {""}, {""}, {""}, {""}, - {"name_fmt", tok_name_fmt, 0}, - {""}, - {"t_fmt_ampm", tok_t_fmt_ampm, 0}, - {""}, - {"name_mr", tok_name_mr, 0}, - {""}, - {"from", tok_from, 0}, - {""}, - {"escape_char", tok_escape_char, 0}, - {"duo_valid_to", tok_duo_valid_to, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"reorder-sections-end", tok_reorder_sections_end, 0}, - {""}, - {"reorder-sections-after", tok_reorder_sections_after, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"territory", tok_territory, 0}, - {""}, {""}, - {"country_name", tok_country_name, 0}, - {"language", tok_language, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, - {"tel_int_fmt", tok_tel_int_fmt, 0}, - {"mon_grouping", tok_mon_grouping, 0}, - {"positive_sign", tok_positive_sign, 0}, - {""}, - {"abmon", tok_abmon, 0}, - {"measurement", tok_measurement, 0}, - {""}, {""}, {""}, - {"coll_weight_max", tok_coll_weight_max, 0}, - {"collating-symbol", tok_collating_symbol, 0}, - {""}, {""}, {""}, {""}, - {"script", tok_script, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"cal_direction", tok_cal_direction, 0}, - {""}, {""}, {""}, {""}, - {"duo_n_sep_by_space", tok_duo_n_sep_by_space, 0}, - {""}, {""}, {""}, {""}, - {"mon", tok_mon, 0}, - {"translit_start", tok_translit_start, 0}, - {"translit_ignore", tok_translit_ignore, 0}, - {""}, - {"translit_end", tok_translit_end, 0}, - {"first_weekday", tok_first_weekday, 0}, - {""}, {""}, - {"p_sign_posn", tok_p_sign_posn, 0}, - {""}, - {"first_workday", tok_first_workday, 0}, - {"n_sep_by_space", tok_n_sep_by_space, 0}, - {""}, - {"source", tok_source, 0}, - {"mon_decimal_point", tok_mon_decimal_point, 0}, - {"symbol-equivalence", tok_symbol_equivalence, 0}, - {""}, - {"endif", tok_endif, 0}, - {""}, {""}, {""}, - {"duo_valid_from", tok_duo_valid_from, 0}, - {"default_missing", tok_default_missing, 0}, - {""}, {""}, - {"int_p_sep_by_space", tok_int_p_sep_by_space, 0}, - {""}, - {"alt_digits", tok_alt_digits, 0}, - {""}, - {"duo_int_p_sep_by_space", tok_duo_int_p_sep_by_space, 0}, - {""}, {""}, - {"duo_p_sign_posn", tok_duo_p_sign_posn, 0}, - {""}, {""}, {""}, - {"duo_currency_symbol", tok_duo_currency_symbol, 0}, - {""}, {""}, {""}, - {"outdigit", tok_outdigit, 0}, - {""}, {""}, {""}, {""}, - {"revision", tok_revision, 0}, - {""}, {""}, {""}, {""}, - {"name_gen", tok_name_gen, 0}, - {""}, - {"email", tok_email, 0}, - {""}, - {"uno_valid_to", tok_uno_valid_to, 0}, - {"negative_sign", tok_negative_sign, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, - {"alnum", tok_alnum, 0}, - {""}, {""}, {""}, {""}, {""}, - {"country_num", tok_country_num, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"am_pm", tok_am_pm, 0}, - {""}, - {"mon_thousands_sep", tok_mon_thousands_sep, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"currency_symbol", tok_currency_symbol, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"country_isbn", tok_country_isbn, 0}, - {""}, {""}, {""}, {""}, - {"name_ms", tok_name_ms, 0}, - {"name_mrs", tok_name_mrs, 0}, - {""}, {""}, {""}, {""}, - {"thousands_sep", tok_thousands_sep, 0}, - {""}, - {"cntrl", tok_cntrl, 0}, - {""}, {""}, {""}, {""}, {""}, - {"n_sign_posn", tok_n_sign_posn, 0}, - {"include", tok_include, 0}, - {""}, {""}, - {"ifdef", tok_ifdef, 0}, - {""}, - {"duo_p_cs_precedes", tok_duo_p_cs_precedes, 0}, - {""}, {""}, {""}, {""}, {""}, - {"p_cs_precedes", tok_p_cs_precedes, 0}, - {"uno_valid_from", tok_uno_valid_from, 0}, - {"undef", tok_undef, 0}, - {""}, {""}, - {"int_n_sep_by_space", tok_int_n_sep_by_space, 0}, - {"lang_term", tok_lang_term, 0}, - {""}, {""}, - {"duo_int_n_sep_by_space", tok_duo_int_n_sep_by_space, 0}, - {""}, - {"duo_int_p_sign_posn", tok_duo_int_p_sign_posn, 0}, - {"duo_n_sign_posn", tok_duo_n_sign_posn, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"application", tok_application, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, - {"int_p_sign_posn", tok_int_p_sign_posn, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"duo_int_curr_symbol", tok_duo_int_curr_symbol, 0}, - {""}, {""}, {""}, {""}, {""}, - {"int_prefix", tok_int_prefix, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, - {"duo_frac_digits", tok_duo_frac_digits, 0}, - {""}, {""}, {""}, {""}, {""}, - {"duo_int_p_cs_precedes", tok_duo_int_p_cs_precedes, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, - {"frac_digits", tok_frac_digits, 0}, - {""}, {""}, - {"charclass", tok_charclass, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, - {"duo_n_cs_precedes", tok_duo_n_cs_precedes, 0}, - {""}, {""}, - {"int_curr_symbol", tok_int_curr_symbol, 0}, - {""}, {""}, - {"n_cs_precedes", tok_n_cs_precedes, 0}, - {""}, - {"int_select", tok_int_select, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"duo_int_n_sign_posn", tok_duo_int_n_sign_posn, 0}, - {"class", tok_class, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, - {"int_p_cs_precedes", tok_int_p_cs_precedes, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, - {"duo_int_frac_digits", tok_duo_int_frac_digits, 0}, - {""}, {""}, {""}, {""}, {""}, - {"int_n_sign_posn", tok_int_n_sign_posn, 0}, - {""}, {""}, {""}, - {"name_miss", tok_name_miss, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, - {"duo_int_n_cs_precedes", tok_duo_int_n_cs_precedes, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, - {"int_frac_digits", tok_int_frac_digits, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"section-symbol", tok_section_symbol, 0}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, - {"int_n_cs_precedes", tok_int_n_cs_precedes, 0} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') - return &wordlist[key]; - } - } - return 0; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/locfile-token.h b/src/system/libroot/posix/glibc/locale/programs/locfile-token.h deleted file mode 100644 index cada206655..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locfile-token.h +++ /dev/null @@ -1,259 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _TOKEN_H -#define _TOKEN_H - -enum token_t -{ - tok_none = 0, - - tok_eof, - tok_eol, - tok_bsymbol, - tok_ident, - tok_ellipsis2, - tok_ellipsis3, - tok_ellipsis4, - tok_ellipsis2_2, - tok_ellipsis4_2, - tok_semicolon, - tok_comma, - tok_open_brace, - tok_close_brace, - tok_charcode, - tok_ucs4, - tok_number, - tok_minus1, - tok_string, - tok_include, - - tok_escape_char, - tok_comment_char, - tok_charmap, - tok_end, - tok_g0esc, - tok_g1esc, - tok_g2esc, - tok_g3esc, - tok_escseq, - tok_addset, - - tok_charids, - - tok_code_set_name, - tok_mb_cur_max, - tok_mb_cur_min, - tok_charconv, - tok_width, - tok_width_variable, - tok_width_default, - tok_repertoiremap, - - tok_lc_ctype, - tok_copy, - /* Keep the following entries up to the next comment in this order! */ - tok_upper, - tok_lower, - tok_alpha, - tok_digit, - tok_xdigit, - tok_space, - tok_print, - tok_graph, - tok_blank, - tok_cntrl, - tok_punct, - tok_alnum, - /* OK, shuffling allowed again. */ - tok_outdigit, - tok_charclass, - tok_class, - tok_toupper, - tok_tolower, - tok_map, - tok_translit_start, - tok_translit_end, - tok_translit_ignore, - tok_default_missing, - tok_lc_collate, - tok_coll_weight_max, - tok_section_symbol, - tok_collating_element, - tok_collating_symbol, - tok_symbol_equivalence, - tok_script, - tok_order_start, - tok_order_end, - tok_from, - tok_forward, - tok_backward, - tok_position, - tok_undefined, - tok_ignore, - tok_reorder_after, - tok_reorder_end, - tok_reorder_sections_after, - tok_reorder_sections_end, - tok_define, - tok_undef, - tok_ifdef, - tok_ifndef, - tok_else, - tok_elif, - tok_endif, - tok_lc_monetary, - tok_int_curr_symbol, - tok_currency_symbol, - tok_mon_decimal_point, - tok_mon_thousands_sep, - tok_mon_grouping, - tok_positive_sign, - tok_negative_sign, - tok_int_frac_digits, - tok_frac_digits, - tok_p_cs_precedes, - tok_p_sep_by_space, - tok_n_cs_precedes, - tok_n_sep_by_space, - tok_p_sign_posn, - tok_n_sign_posn, - tok_int_p_cs_precedes, - tok_int_p_sep_by_space, - tok_int_n_cs_precedes, - tok_int_n_sep_by_space, - tok_int_p_sign_posn, - tok_int_n_sign_posn, - tok_duo_int_curr_symbol, - tok_duo_currency_symbol, - tok_duo_int_frac_digits, - tok_duo_frac_digits, - tok_duo_p_cs_precedes, - tok_duo_p_sep_by_space, - tok_duo_n_cs_precedes, - tok_duo_n_sep_by_space, - tok_duo_int_p_cs_precedes, - tok_duo_int_p_sep_by_space, - tok_duo_int_n_cs_precedes, - tok_duo_int_n_sep_by_space, - tok_duo_p_sign_posn, - tok_duo_n_sign_posn, - tok_duo_int_p_sign_posn, - tok_duo_int_n_sign_posn, - tok_uno_valid_from, - tok_uno_valid_to, - tok_duo_valid_from, - tok_duo_valid_to, - tok_conversion_rate, - tok_lc_numeric, - tok_decimal_point, - tok_thousands_sep, - tok_grouping, - tok_lc_time, - tok_abday, - tok_day, - tok_abmon, - tok_mon, - tok_d_t_fmt, - tok_d_fmt, - tok_t_fmt, - tok_am_pm, - tok_t_fmt_ampm, - tok_era, - tok_era_year, - tok_era_d_fmt, - tok_era_d_t_fmt, - tok_era_t_fmt, - tok_alt_digits, - tok_week, - tok_first_weekday, - tok_first_workday, - tok_cal_direction, - tok_timezone, - tok_date_fmt, - tok_lc_messages, - tok_yesexpr, - tok_noexpr, - tok_yesstr, - tok_nostr, - tok_lc_paper, - tok_height, - tok_lc_name, - tok_name_fmt, - tok_name_gen, - tok_name_mr, - tok_name_mrs, - tok_name_miss, - tok_name_ms, - tok_lc_address, - tok_postal_fmt, - tok_country_name, - tok_country_post, - tok_country_ab2, - tok_country_ab3, - tok_country_num, - tok_country_car, - tok_country_isbn, - tok_lang_name, - tok_lang_ab, - tok_lang_term, - tok_lang_lib, - tok_lc_telephone, - tok_tel_int_fmt, - tok_tel_dom_fmt, - tok_int_select, - tok_int_prefix, - tok_lc_measurement, - tok_measurement, - tok_lc_identification, - tok_title, - tok_source, - tok_address, - tok_contact, - tok_email, - tok_tel, - tok_fax, - tok_language, - tok_territory, - tok_audience, - tok_application, - tok_abbreviation, - tok_revision, - tok_date, - tok_category, - - tok_error -}; - - -struct keyword_t -{ - const char *name; - enum token_t token; - int symname_or_ident; - - /* Only for locdef file. */ - int locale; - enum token_t base; - enum token_t group; - enum token_t list; -}; - - -#endif /* token.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/locfile.c b/src/system/libroot/posix/glibc/locale/programs/locfile.c deleted file mode 100644 index 3d774ef43d..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locfile.c +++ /dev/null @@ -1,715 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "localedef.h" -#include "locfile.h" - -#include "locfile-kw.h" - - -int -locfile_read (struct localedef_t *result, struct charmap_t *charmap) -{ - const char *filename = result->name; - const char *repertoire_name = result->repertoire_name; - int locale_mask = result->needed ^ result->avail; - struct linereader *ldfile; - int not_here = ALL_LOCALES; - - /* If no repertoire name was specified use the global one. */ - if (repertoire_name == NULL) - repertoire_name = repertoire_global; - - /* Open the locale definition file. */ - ldfile = lr_open (filename, locfile_hash); - if (ldfile == NULL) - { - if (filename != NULL && filename[0] != '/') - { - char *i18npath = getenv ("I18NPATH"); - if (i18npath != NULL && *i18npath != '\0') - { - char path[strlen (filename) + 1 + strlen (i18npath) - + sizeof ("/locales/") - 1]; - char *next; - i18npath = strdupa (i18npath); - - - while (ldfile == NULL - && (next = strsep (&i18npath, ":")) != NULL) - { - stpcpy (stpcpy (stpcpy (path, next), "/locales/"), filename); - - ldfile = lr_open (path, locfile_hash); - - if (ldfile == NULL) - { - stpcpy (stpcpy (path, next), filename); - - ldfile = lr_open (path, locfile_hash); - } - } - } - - /* Test in the default directory. */ - if (ldfile == NULL) - { - char path[strlen (filename) + 1 + sizeof (LOCSRCDIR)]; - - stpcpy (stpcpy (stpcpy (path, LOCSRCDIR), "/"), filename); - ldfile = lr_open (path, locfile_hash); - } - } - - if (ldfile == NULL) - return 1; - } - - /* Parse locale definition file and store result in RESULT. */ - while (1) - { - struct token *now = lr_token (ldfile, charmap, NULL, verbose); - enum token_t nowtok = now->tok; - struct token *arg; - - if (nowtok == tok_eof) - break; - - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - switch (nowtok) - { - case tok_escape_char: - case tok_comment_char: - /* We need an argument. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - - if (arg->tok != tok_ident) - { - SYNTAX_ERROR (_("bad argument")); - continue; - } - - if (arg->val.str.lenmb != 1) - { - lr_error (ldfile, _("\ -argument to `%s' must be a single character"), - nowtok == tok_escape_char - ? "escape_char" : "comment_char"); - - lr_ignore_rest (ldfile, 0); - continue; - } - - if (nowtok == tok_escape_char) - ldfile->escape_char = *arg->val.str.startmb; - else - ldfile->comment_char = *arg->val.str.startmb; - break; - - case tok_repertoiremap: - /* We need an argument. */ - arg = lr_token (ldfile, charmap, NULL, verbose); - - if (arg->tok != tok_ident) - { - SYNTAX_ERROR (_("bad argument")); - continue; - } - - if (repertoire_name == NULL) - { - repertoire_name = memcpy (xmalloc (arg->val.str.lenmb + 1), - arg->val.str.startmb, - arg->val.str.lenmb); - ((char *) repertoire_name)[arg->val.str.lenmb] = '\0'; - } - break; - - case tok_lc_ctype: - ctype_read (ldfile, result, charmap, repertoire_name, - (locale_mask & CTYPE_LOCALE) == 0); - result->avail |= locale_mask & CTYPE_LOCALE; - not_here ^= CTYPE_LOCALE; - continue; - - case tok_lc_collate: - collate_read (ldfile, result, charmap, repertoire_name, - (locale_mask & COLLATE_LOCALE) == 0); - result->avail |= locale_mask & COLLATE_LOCALE; - not_here ^= COLLATE_LOCALE; - continue; - - case tok_lc_monetary: - monetary_read (ldfile, result, charmap, repertoire_name, - (locale_mask & MONETARY_LOCALE) == 0); - result->avail |= locale_mask & MONETARY_LOCALE; - not_here ^= MONETARY_LOCALE; - continue; - - case tok_lc_numeric: - numeric_read (ldfile, result, charmap, repertoire_name, - (locale_mask & NUMERIC_LOCALE) == 0); - result->avail |= locale_mask & NUMERIC_LOCALE; - not_here ^= NUMERIC_LOCALE; - continue; - - case tok_lc_time: - time_read (ldfile, result, charmap, repertoire_name, - (locale_mask & TIME_LOCALE) == 0); - result->avail |= locale_mask & TIME_LOCALE; - not_here ^= TIME_LOCALE; - continue; - - case tok_lc_messages: - messages_read (ldfile, result, charmap, repertoire_name, - (locale_mask & MESSAGES_LOCALE) == 0); - result->avail |= locale_mask & MESSAGES_LOCALE; - not_here ^= MESSAGES_LOCALE; - continue; - - case tok_lc_paper: - paper_read (ldfile, result, charmap, repertoire_name, - (locale_mask & PAPER_LOCALE) == 0); - result->avail |= locale_mask & PAPER_LOCALE; - not_here ^= PAPER_LOCALE; - continue; - - case tok_lc_name: - name_read (ldfile, result, charmap, repertoire_name, - (locale_mask & NAME_LOCALE) == 0); - result->avail |= locale_mask & NAME_LOCALE; - not_here ^= NAME_LOCALE; - continue; - - case tok_lc_address: - address_read (ldfile, result, charmap, repertoire_name, - (locale_mask & ADDRESS_LOCALE) == 0); - result->avail |= locale_mask & ADDRESS_LOCALE; - not_here ^= ADDRESS_LOCALE; - continue; - - case tok_lc_telephone: - telephone_read (ldfile, result, charmap, repertoire_name, - (locale_mask & TELEPHONE_LOCALE) == 0); - result->avail |= locale_mask & TELEPHONE_LOCALE; - not_here ^= TELEPHONE_LOCALE; - continue; - - case tok_lc_measurement: - measurement_read (ldfile, result, charmap, repertoire_name, - (locale_mask & MEASUREMENT_LOCALE) == 0); - result->avail |= locale_mask & MEASUREMENT_LOCALE; - not_here ^= MEASUREMENT_LOCALE; - continue; - - case tok_lc_identification: - identification_read (ldfile, result, charmap, repertoire_name, - (locale_mask & IDENTIFICATION_LOCALE) == 0); - result->avail |= locale_mask & IDENTIFICATION_LOCALE; - not_here ^= IDENTIFICATION_LOCALE; - continue; - - default: - SYNTAX_ERROR (_("\ -syntax error: not inside a locale definition section")); - continue; - } - - /* The rest of the line must be empty. */ - lr_ignore_rest (ldfile, 1); - } - - /* We read all of the file. */ - lr_close (ldfile); - - /* Mark the categories which are not contained in the file. We assume - them to be available and the default data will be used. */ - result->avail |= not_here; - - return 0; -} - - -/* Semantic checking of locale specifications. */ - -static void (*const check_funcs[]) (struct localedef_t *, - struct charmap_t *) = -{ - [LC_CTYPE] = ctype_finish, - [LC_COLLATE] = collate_finish, - [LC_MESSAGES] = messages_finish, - [LC_MONETARY] = monetary_finish, - [LC_NUMERIC] = numeric_finish, - [LC_TIME] = time_finish, - [LC_PAPER] = paper_finish, - [LC_NAME] = name_finish, - [LC_ADDRESS] = address_finish, - [LC_TELEPHONE] = telephone_finish, - [LC_MEASUREMENT] = measurement_finish, - [LC_IDENTIFICATION] = identification_finish -}; - -void -check_all_categories (struct localedef_t *definitions, - struct charmap_t *charmap) -{ - int cnt; - - for (cnt = 0; cnt < sizeof (check_funcs) / sizeof (check_funcs[0]); ++cnt) - if (check_funcs[cnt] != NULL) - check_funcs[cnt] (definitions, charmap); -} - - -/* Writing the locale data files. All files use the same output_path. */ - -static void (*const write_funcs[]) (struct localedef_t *, struct charmap_t *, - const char *) = -{ - [LC_CTYPE] = ctype_output, - [LC_COLLATE] = collate_output, - [LC_MESSAGES] = messages_output, - [LC_MONETARY] = monetary_output, - [LC_NUMERIC] = numeric_output, - [LC_TIME] = time_output, - [LC_PAPER] = paper_output, - [LC_NAME] = name_output, - [LC_ADDRESS] = address_output, - [LC_TELEPHONE] = telephone_output, - [LC_MEASUREMENT] = measurement_output, - [LC_IDENTIFICATION] = identification_output -}; - -void -write_all_categories (struct localedef_t *definitions, - struct charmap_t *charmap, - const char *output_path) -{ - int cnt; - - for (cnt = 0; cnt < sizeof (write_funcs) / sizeof (write_funcs[0]); ++cnt) - if (write_funcs[cnt] != NULL) - write_funcs[cnt] (definitions, charmap, output_path); -} - -/* Return a NULL terminated list of the directories next to output_path - that have the same owner, group, permissions and device as output_path. */ -static const char ** -siblings_uncached (const char *output_path) -{ - size_t len; - char *base, *p; - struct stat output_stat; - DIR *dirp; - int nelems; - const char **elems; - - /* Remove trailing slashes and trailing pathname component. */ - len = strlen (output_path); - base = (char *) alloca (len); - memcpy (base, output_path, len); - p = base + len; - while (p > base && p[-1] == '/') - p--; - if (p == base) - return NULL; - do - p--; - while (p > base && p[-1] != '/'); - if (p == base) - return NULL; - *--p = '\0'; - len = p - base; - - /* Get the properties of output_path. */ - if (lstat (output_path, &output_stat) < 0 || !S_ISDIR (output_stat.st_mode)) - return NULL; - - /* Iterate through the directories in base directory. */ - dirp = opendir (base); - if (dirp == NULL) - return NULL; - nelems = 0; - elems = NULL; - for (;;) - { - struct dirent *other_dentry; - const char *other_name; - char *other_path; - struct stat other_stat; - - other_dentry = readdir (dirp); - if (other_dentry == NULL) - break; - - other_name = other_dentry->d_name; - if (strcmp (other_name, ".") == 0 || strcmp (other_name, "..") == 0) - continue; - - other_path = (char *) xmalloc (len + 1 + strlen (other_name) + 2); - memcpy (other_path, base, len); - other_path[len] = '/'; - strcpy (other_path + len + 1, other_name); - - if (lstat (other_path, &other_stat) >= 0 - && S_ISDIR (other_stat.st_mode) - && other_stat.st_uid == output_stat.st_uid - && other_stat.st_gid == output_stat.st_gid - && other_stat.st_mode == output_stat.st_mode - && other_stat.st_dev == output_stat.st_dev) - { - /* Found a subdirectory. Add a trailing slash and store it. */ - p = other_path + len + 1 + strlen (other_name); - *p++ = '/'; - *p = '\0'; - elems = (const char **) xrealloc ((char *) elems, - (nelems + 2) * sizeof (char **)); - elems[nelems++] = other_path; - } - else - free (other_path); - } - closedir (dirp); - - if (elems != NULL) - elems[nelems] = NULL; - return elems; -} - -/* Return a NULL terminated list of the directories next to output_path - that have the same owner, group, permissions and device as output_path. - Cache the result for future calls. */ -static const char ** -siblings (const char *output_path) -{ - static const char *last_output_path; - static const char **last_result; - - if (output_path != last_output_path) - { - if (last_result != NULL) - { - const char **p; - - for (p = last_result; *p != NULL; p++) - free ((char *) *p); - free (last_result); - } - - last_output_path = output_path; - last_result = siblings_uncached (output_path); - } - return last_result; -} - -/* Read as many bytes from a file descriptor as possible. */ -static ssize_t -full_read (int fd, void *bufarea, size_t nbyte) -{ - char *buf = (char *) bufarea; - - while (nbyte > 0) - { - ssize_t retval = read (fd, buf, nbyte); - - if (retval == 0) - break; - else if (retval > 0) - { - buf += retval; - nbyte -= retval; - } - else if (errno != EINTR) - return retval; - } - return buf - (char *) bufarea; -} - -/* Compare the contents of two regular files of the same size. Return 0 - if they are equal, 1 if they are different, or -1 if an error occurs. */ -static int -compare_files (const char *filename1, const char *filename2, size_t size, - size_t blocksize) -{ - int fd1, fd2; - int ret = -1; - - fd1 = open (filename1, O_RDONLY); - if (fd1 >= 0) - { - fd2 = open (filename2, O_RDONLY); - if (fd2 >= 0) - { - char *buf1 = (char *) xmalloc (2 * blocksize); - char *buf2 = buf1 + blocksize; - - ret = 0; - while (size > 0) - { - size_t bytes = (size < blocksize ? size : blocksize); - - if (full_read (fd1, buf1, bytes) < (ssize_t) bytes) - { - ret = -1; - break; - } - if (full_read (fd2, buf2, bytes) < (ssize_t) bytes) - { - ret = -1; - break; - } - if (memcmp (buf1, buf2, bytes) != 0) - { - ret = 1; - break; - } - size -= bytes; - } - - free (buf1); - close (fd2); - } - close (fd1); - } - return ret; -} - -/* Write a locale file, with contents given by N_ELEM and VEC. */ -void -write_locale_data (const char *output_path, const char *category, - size_t n_elem, struct iovec *vec) -{ - size_t cnt, step, maxiov; - int fd; - char *fname; - const char **other_paths; - - fname = xmalloc (strlen (output_path) + 2 * strlen (category) + 7); - - /* Normally we write to the directory pointed to by the OUTPUT_PATH. - But for LC_MESSAGES we have to take care for the translation - data. This means we need to have a directory LC_MESSAGES in - which we place the file under the name SYS_LC_MESSAGES. */ - sprintf (fname, "%s%s", output_path, category); - fd = -2; - if (strcmp (category, "LC_MESSAGES") == 0) - { - struct stat st; - - if (stat (fname, &st) < 0) - { - if (mkdir (fname, 0777) >= 0) - { - fd = -1; - errno = EISDIR; - } - } - else if (!S_ISREG (st.st_mode)) - { - fd = -1; - errno = EISDIR; - } - } - - /* Create the locale file with nlinks == 1; this avoids crashing processes - which currently use the locale and damaging files belonging to other - locales as well. */ - if (fd == -2) - { - unlink (fname); - fd = creat (fname, 0666); - } - - if (fd == -1) - { - int save_err = errno; - - if (errno == EISDIR) - { - sprintf (fname, "%1$s%2$s/SYS_%2$s", output_path, category); - unlink (fname); - fd = creat (fname, 0666); - if (fd == -1) - save_err = errno; - } - - if (fd == -1) - { - if (!be_quiet) - error (0, save_err, _("\ -cannot open output file `%s' for category `%s'"), - fname, category); - free (fname); - return; - } - } - -#ifdef UIO_MAXIOV - maxiov = UIO_MAXIOV; -#else - maxiov = sysconf (_SC_UIO_MAXIOV); -#endif - - /* Write the data using writev. But we must take care for the - limitation of the implementation. */ - for (cnt = 0; cnt < n_elem; cnt += step) - { - step = n_elem - cnt; - if (maxiov > 0) - step = MIN (maxiov, step); - - if (writev (fd, &vec[cnt], step) < 0) - { - if (!be_quiet) - error (0, errno, _("failure while writing data for category `%s'"), - category); - break; - } - } - - close (fd); - - /* Compare the file with the locale data files for the same category in - other locales, and see if we can reuse it, to save disk space. */ - other_paths = siblings (output_path); - if (other_paths != NULL) - { - struct stat fname_stat; - - if (lstat (fname, &fname_stat) >= 0 - && S_ISREG (fname_stat.st_mode)) - { - const char *fname_tail = fname + strlen (output_path); - const char **other_p; - int seen_count; - ino_t *seen_inodes; - - seen_count = 0; - for (other_p = other_paths; *other_p; other_p++) - seen_count++; - seen_inodes = (ino_t *) xmalloc (seen_count * sizeof (ino_t)); - seen_count = 0; - - for (other_p = other_paths; *other_p; other_p++) - { - const char *other_path = *other_p; - size_t other_path_len = strlen (other_path); - char *other_fname; - struct stat other_fname_stat; - - other_fname = - (char *) xmalloc (other_path_len + strlen (fname_tail) + 1); - memcpy (other_fname, other_path, other_path_len); - strcpy (other_fname + other_path_len, fname_tail); - - if (lstat (other_fname, &other_fname_stat) >= 0 - && S_ISREG (other_fname_stat.st_mode) - /* Consider only files on the same device. - Otherwise hard linking won't work anyway. */ - && other_fname_stat.st_dev == fname_stat.st_dev - /* Consider only files with the same permissions. - Otherwise there are security risks. */ - && other_fname_stat.st_uid == fname_stat.st_uid - && other_fname_stat.st_gid == fname_stat.st_gid - && other_fname_stat.st_mode == fname_stat.st_mode - /* Don't compare fname with itself. */ - && other_fname_stat.st_ino != fname_stat.st_ino - /* Files must have the same size, otherwise they - cannot be the same. */ - && other_fname_stat.st_size == fname_stat.st_size) - { - /* Skip this file if we have already read it (under a - different name). */ - int i; - - for (i = seen_count - 1; i >= 0; i--) - if (seen_inodes[i] == other_fname_stat.st_ino) - break; - if (i < 0) - { - /* Now compare fname and other_fname for real. */ - blksize_t blocksize; - -#ifdef _STATBUF_ST_BLKSIZE - blocksize = MAX (fname_stat.st_blksize, - other_fname_stat.st_blksize); - if (blocksize > 8 * 1024) - blocksize = 8 * 1024; -#else - blocksize = 8 * 1024; -#endif - - if (compare_files (fname, other_fname, - fname_stat.st_size, blocksize) == 0) - { - /* Found! other_fname is identical to fname. */ - /* Link other_fname to fname. But use a temporary - file, in case hard links don't work on the - particular filesystem. */ - char * tmp_fname = - (char *) xmalloc (strlen (fname) + 4 + 1); - - strcpy (tmp_fname, fname); - strcat (tmp_fname, ".tmp"); - - if (link (other_fname, tmp_fname) >= 0) - { - unlink (fname); - if (rename (tmp_fname, fname) < 0) - { - if (!be_quiet) - error (0, errno, _("\ -cannot create output file `%s' for category `%s'"), - fname, category); - } - free (tmp_fname); - free (other_fname); - break; - } - free (tmp_fname); - } - - /* Don't compare with this file a second time. */ - seen_inodes[seen_count++] = other_fname_stat.st_ino; - } - } - free (other_fname); - } - free (seen_inodes); - } - } - - free (fname); -} diff --git a/src/system/libroot/posix/glibc/locale/programs/locfile.h b/src/system/libroot/posix/glibc/locale/programs/locfile.h deleted file mode 100644 index 2693187f9b..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/locfile.h +++ /dev/null @@ -1,271 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _LOCFILE_H -#define _LOCFILE_H 1 - -#include - -#include "linereader.h" -#include "localedef.h" - - -/* Header of the locale data files. */ -struct locale_file -{ - int magic; - int n; -}; - - -/* Macros used in the parser. */ -#define SYNTAX_ERROR(string, args...) \ - do \ - { \ - lr_error (ldfile, string, ## args); \ - lr_ignore_rest (ldfile, 0); \ - } \ - while (0) - - -/* General handling of `copy'. */ -static inline void -handle_copy (struct linereader *ldfile, struct charmap_t *charmap, - const char *repertoire_name, struct localedef_t *result, - enum token_t token, int locale, const char *locale_name, - int ignore_content) -{ - struct token *now; - int warned = 0; - - now = lr_token (ldfile, charmap, NULL, verbose); - if (now->tok != tok_string) - lr_error (ldfile, _("expect string argument for `copy'")); - else if (!ignore_content) - { - if (now->val.str.startmb == NULL) - lr_error (ldfile, _("\ -locale name should consist only of portable characters")); - else - { - (void) add_to_readlist (locale, now->val.str.startmb, - repertoire_name, 1, NULL); - result->copy_name[locale] = now->val.str.startmb; - } - } - - lr_ignore_rest (ldfile, now->tok == tok_string); - - /* The rest of the line must be empty and the next keyword must be - `END xxx'. */ - while ((now = lr_token (ldfile, charmap, NULL, verbose))->tok != tok_end - && now->tok != tok_eof) - { - if (warned == 0) - { - lr_error (ldfile, _("\ -no other keyword shall be specified when `copy' is used")); - warned = 1; - } - - lr_ignore_rest (ldfile, 0); - } - - if (now->tok != tok_eof) - { - /* Handle `END xxx'. */ - now = lr_token (ldfile, charmap, NULL, verbose); - - if (now->tok != token) - lr_error (ldfile, _("\ -`%1$s' definition does not end with `END %1$s'"), locale_name); - - lr_ignore_rest (ldfile, now->tok == token); - } - else - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), locale_name); -} - - -/* Found in locfile.c. */ -extern int locfile_read (struct localedef_t *result, - struct charmap_t *charmap); - -/* Check validity of all the locale data. */ -extern void check_all_categories (struct localedef_t *definitions, - struct charmap_t *charmap); - -/* Write out all locale categories. */ -extern void write_all_categories (struct localedef_t *definitions, - struct charmap_t *charmap, - const char *output_path); - -/* Write out the data. */ -extern void write_locale_data (const char *output_path, const char *category, - size_t n_elem, struct iovec *vec); - - -/* Entrypoints for the parsers of the individual categories. */ - -/* Handle LC_CTYPE category. */ -extern void ctype_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void ctype_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void ctype_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_COLLATE category. */ -extern void collate_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void collate_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void collate_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_MONETARY category. */ -extern void monetary_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void monetary_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void monetary_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_NUMERIC category. */ -extern void numeric_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void numeric_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void numeric_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_MESSAGES category. */ -extern void messages_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void messages_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void messages_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_TIME category. */ -extern void time_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void time_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void time_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_PAPER category. */ -extern void paper_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void paper_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void paper_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_NAME category. */ -extern void name_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void name_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void name_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_ADDRESS category. */ -extern void address_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void address_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void address_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_TELEPHONE category. */ -extern void telephone_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void telephone_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void telephone_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_MEASUREMENT category. */ -extern void measurement_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void measurement_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void measurement_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -/* Handle LC_IDENTIFICATION category. */ -extern void identification_read (struct linereader *ldfile, - struct localedef_t *result, - struct charmap_t *charmap, - const char *repertoire_name, - int ignore_content); -extern void identification_finish (struct localedef_t *locale, - struct charmap_t *charmap); -extern void identification_output (struct localedef_t *locale, - struct charmap_t *charmap, - const char *output_path); - -#endif /* locfile.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/repertoire.c b/src/system/libroot/posix/glibc/locale/programs/repertoire.c deleted file mode 100644 index e66b24fe58..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/repertoire.c +++ /dev/null @@ -1,523 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "linereader.h" -#include "charmap.h" -#include "repertoire.h" -#include "simple-hash.h" -#include "localedef.h" - - -/* Simple keyword hashing for the repertoiremap. */ -static const struct keyword_t *repertoiremap_hash (const char *str, - unsigned int len); -static void repertoire_new_char (struct linereader *lr, hash_table *ht, - hash_table *rt, struct obstack *ob, - uint32_t value, const char *from, - const char *to, int decimal_ellipsis); -static int repertoire_compare (const void *p1, const void *p2); - -/* Already known repertoire maps. */ -static void *known; - -/* List of repertoire maps which are not available and which have been - reported to not be. */ -static void *unavailable; - - -struct repertoire_t * -repertoire_read (const char *filename) -{ - struct linereader *repfile; - struct repertoire_t *result; - struct repertoire_t **resultp; - struct repertoire_t search; - int state; - char *from_name = NULL; - char *to_name = NULL; - enum token_t ellipsis = tok_none; - - search.name = filename; - resultp = tfind (&search, &known, &repertoire_compare); - if (resultp != NULL) - return *resultp; - - /* Determine path. */ - repfile = lr_open (filename, repertoiremap_hash); - if (repfile == NULL) - { - if (strchr (filename, '/') == NULL) - { - char *i18npath = getenv ("I18NPATH"); - if (i18npath != NULL && *i18npath != '\0') - { - char path[strlen (filename) + 1 + strlen (i18npath) - + sizeof ("/repertoiremaps/") - 1]; - char *next; - i18npath = strdupa (i18npath); - - - while (repfile == NULL - && (next = strsep (&i18npath, ":")) != NULL) - { - stpcpy (stpcpy (stpcpy (path, next), "/repertoiremaps/"), - filename); - - repfile = lr_open (path, repertoiremap_hash); - - if (repfile == NULL) - { - stpcpy (stpcpy (path, next), filename); - - repfile = lr_open (path, repertoiremap_hash); - } - } - } - - if (repfile == NULL) - { - /* Look in the systems charmap directory. */ - char *buf = xmalloc (strlen (filename) + 1 - + sizeof (REPERTOIREMAP_PATH)); - - stpcpy (stpcpy (stpcpy (buf, REPERTOIREMAP_PATH), "/"), - filename); - repfile = lr_open (buf, repertoiremap_hash); - - if (repfile == NULL) - free (buf); - } - } - - if (repfile == NULL) - return NULL; - } - - /* We don't want symbolic names in string to be translated. */ - repfile->translate_strings = 0; - - /* Allocate room for result. */ - result = (struct repertoire_t *) xmalloc (sizeof (struct repertoire_t)); - memset (result, '\0', sizeof (struct repertoire_t)); - - result->name = xstrdup (filename); - -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free - obstack_init (&result->mem_pool); - - if (init_hash (&result->char_table, 256) - || init_hash (&result->reverse_table, 256) - || init_hash (&result->seq_table, 256)) - { - free (result); - return NULL; - } - - /* We use a state machine to describe the charmap description file - format. */ - state = 1; - while (1) - { - /* What's on? */ - struct token *now = lr_token (repfile, NULL, NULL, verbose); - enum token_t nowtok = now->tok; - struct token *arg; - - if (nowtok == tok_eof) - break; - - switch (state) - { - case 1: - /* We haven't yet read any character definition. This is where - we accept escape_char and comment_char definitions. */ - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (nowtok == tok_escape_char || nowtok == tok_comment_char) - { - /* We know that we need an argument. */ - arg = lr_token (repfile, NULL, NULL, verbose); - - if (arg->tok != tok_ident) - { - lr_error (repfile, _("syntax error in prolog: %s"), - _("bad argument")); - - lr_ignore_rest (repfile, 0); - continue; - } - - if (arg->val.str.lenmb != 1) - { - lr_error (repfile, _("\ -argument to <%s> must be a single character"), - nowtok == tok_escape_char ? "escape_char" - : "comment_char"); - - lr_ignore_rest (repfile, 0); - continue; - } - - if (nowtok == tok_escape_char) - repfile->escape_char = *arg->val.str.startmb; - else - repfile->comment_char = *arg->val.str.startmb; - - lr_ignore_rest (repfile, 1); - continue; - } - - if (nowtok == tok_charids) - { - lr_ignore_rest (repfile, 1); - - state = 2; - continue; - } - - /* Otherwise we start reading the character definitions. */ - state = 2; - /* FALLTHROUGH */ - - case 2: - /* We are now are in the body. Each line - must have the format "%s %s %s\n" or "%s...%s %s %s\n". */ - if (nowtok == tok_eol) - /* Ignore empty lines. */ - continue; - - if (nowtok == tok_end) - { - state = 90; - continue; - } - - if (nowtok != tok_bsymbol) - { - lr_error (repfile, - _("syntax error in repertoire map definition: %s"), - _("no symbolic name given")); - - lr_ignore_rest (repfile, 0); - continue; - } - - /* If the previous line was not completely correct free the - used memory. */ - if (from_name != NULL) - obstack_free (&result->mem_pool, from_name); - - from_name = (char *) obstack_copy0 (&result->mem_pool, - now->val.str.startmb, - now->val.str.lenmb); - to_name = NULL; - - state = 3; - continue; - - case 3: - /* We have two possibilities: We can see an ellipsis or an - encoding value. */ - if (nowtok == tok_ellipsis3 || nowtok == tok_ellipsis4 - || nowtok == tok_ellipsis2) - { - ellipsis = nowtok; - state = 4; - continue; - } - /* FALLTHROUGH */ - - case 5: - /* We expect a value of the form or where - the xxx mean a hexadecimal value. */ - state = 2; - - errno = 0; - if (nowtok != tok_ucs4) - { - lr_error (repfile, - _("syntax error in repertoire map definition: %s"), - _("no or value given")); - - lr_ignore_rest (repfile, 0); - continue; - } - - /* We've found a new valid definition. */ - repertoire_new_char (repfile, &result->char_table, - &result->reverse_table, &result->mem_pool, - now->val.ucs4, from_name, to_name, - ellipsis != tok_ellipsis2); - - /* Ignore the rest of the line. */ - lr_ignore_rest (repfile, 0); - - from_name = NULL; - to_name = NULL; - - continue; - - case 4: - if (nowtok != tok_bsymbol) - { - lr_error (repfile, - _("syntax error in repertoire map definition: %s"), - _("no symbolic name given for end of range")); - - lr_ignore_rest (repfile, 0); - state = 2; - continue; - } - - /* Copy the to-name in a safe place. */ - to_name = (char *) obstack_copy0 (&result->mem_pool, - repfile->token.val.str.startmb, - repfile->token.val.str.lenmb); - - state = 5; - continue; - - case 90: - if (nowtok != tok_charids) - lr_error (repfile, _("\ -`%1$s' definition does not end with `END %1$s'"), "CHARIDS"); - - lr_ignore_rest (repfile, nowtok == tok_charids); - break; - } - - break; - } - - if (state != 2 && state != 90 && !be_quiet) - error (0, 0, _("%s: premature end of file"), repfile->fname); - - lr_close (repfile); - - if (tsearch (result, &known, &repertoire_compare) == NULL) - /* Something went wrong. */ - error (0, errno, _("cannot safe new repertoire map")); - - return result; -} - - -void -repertoire_complain (const char *name) -{ - if (tfind (name, &unavailable, (__compar_fn_t) strcmp) == NULL) - { - error (0, errno, _("repertoire map file `%s' not found"), name); - - /* Remember that we reported this map. */ - tsearch (name, &unavailable, (__compar_fn_t) strcmp); - } -} - - -static int -repertoire_compare (const void *p1, const void *p2) -{ - struct repertoire_t *r1 = (struct repertoire_t *) p1; - struct repertoire_t *r2 = (struct repertoire_t *) p2; - - return strcmp (r1->name, r2->name); -} - - -static const struct keyword_t * -repertoiremap_hash (const char *str, unsigned int len) -{ - static const struct keyword_t wordlist[] = - { - {"escape_char", tok_escape_char, 0}, - {"comment_char", tok_comment_char, 0}, - {"CHARIDS", tok_charids, 0}, - {"END", tok_end, 0}, - }; - - if (len == 11 && memcmp (wordlist[0].name, str, 11) == 0) - return &wordlist[0]; - if (len == 12 && memcmp (wordlist[1].name, str, 12) == 0) - return &wordlist[1]; - if (len == 7 && memcmp (wordlist[2].name, str, 7) == 0) - return &wordlist[2]; - if (len == 3 && memcmp (wordlist[3].name, str, 3) == 0) - return &wordlist[3]; - - return NULL; -} - - -static void -repertoire_new_char (struct linereader *lr, hash_table *ht, hash_table *rt, - struct obstack *ob, uint32_t value, const char *from, - const char *to, int decimal_ellipsis) -{ - char *from_end; - char *to_end; - const char *cp; - char *buf = NULL; - int prefix_len, len1, len2; - unsigned int from_nr, to_nr, cnt; - - if (to == NULL) - { - insert_entry (ht, from, strlen (from), - (void *) (unsigned long int) value); - /* Please note that it isn't a bug if a symbol is defined more - than once. All later definitions are simply discarded. */ - - insert_entry (rt, obstack_copy (ob, &value, sizeof (value)), - sizeof (value), (void *) from); - - return; - } - - /* We have a range: the names must have names with equal prefixes - and an equal number of digits, where the second number is greater - or equal than the first. */ - len1 = strlen (from); - len2 = strlen (to); - - if (len1 != len2) - { - invalid_range: - lr_error (lr, _("invalid names for character range")); - return; - } - - cp = &from[len1 - 1]; - if (decimal_ellipsis) - while (isdigit (*cp) && cp >= from) - --cp; - else - while (isxdigit (*cp) && cp >= from) - { - if (!isdigit (*cp) && !isupper (*cp)) - lr_error (lr, _("\ -hexadecimal range format should use only capital characters")); - --cp; - } - - prefix_len = (cp - from) + 1; - - if (cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0) - goto invalid_range; - - errno = 0; - from_nr = strtoul (&from[prefix_len], &from_end, decimal_ellipsis ? 10 : 16); - if (*from_end != '\0' || (from_nr == ULONG_MAX && errno == ERANGE) - || ((to_nr = strtoul (&to[prefix_len], &to_end, - decimal_ellipsis ? 10 : 16)) == ULONG_MAX - && errno == ERANGE) - || *to_end != '\0') - { - lr_error (lr, _("<%s> and <%s> are invalid names for range"), - from, to); - return; - } - - if (from_nr > to_nr) - { - lr_error (lr, _("upper limit in range is not smaller then lower limit")); - return; - } - - for (cnt = from_nr; cnt <= to_nr; ++cnt) - { - uint32_t this_value = value + (cnt - from_nr); - - obstack_printf (ob, decimal_ellipsis ? "%.*s%0*d" : "%.*s%0*X", - prefix_len, from, len1 - prefix_len, cnt); - obstack_1grow (ob, '\0'); - - insert_entry (ht, buf, len1, - (void *) (unsigned long int) this_value); - /* Please note we don't examine the return value since it is no error - if we have two definitions for a symbol. */ - - insert_entry (rt, obstack_copy (ob, &this_value, sizeof (this_value)), - sizeof (this_value), (void *) from); - } -} - - -uint32_t -repertoire_find_value (const struct repertoire_t *rep, const char *name, - size_t len) -{ - void *result; - - if (rep == NULL) - return ILLEGAL_CHAR_VALUE; - - if (find_entry ((hash_table *) &rep->char_table, name, len, &result) < 0) - return ILLEGAL_CHAR_VALUE; - - return (uint32_t) ((unsigned long int) result); -} - - -const char * -repertoire_find_symbol (const struct repertoire_t *rep, uint32_t ucs) -{ - void *result; - - if (rep == NULL) - return NULL; - - if (find_entry ((hash_table *) &rep->reverse_table, &ucs, sizeof (ucs), - &result) < 0) - return NULL; - - return (const char *) result; -} - - -struct charseq * -repertoire_find_seq (const struct repertoire_t *rep, uint32_t ucs) -{ - void *result; - - if (rep == NULL) - return NULL; - - if (find_entry ((hash_table *) &rep->seq_table, &ucs, sizeof (ucs), - &result) < 0) - return NULL; - - return (struct charseq *) result; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/repertoire.h b/src/system/libroot/posix/glibc/locale/programs/repertoire.h deleted file mode 100644 index d463c81690..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/repertoire.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _REPERTOIREMAP_H -#define _REPERTOIREMAP_H 1 - -#include -#include - -#include "charmap.h" -#include "simple-hash.h" - -struct repertoire_t -{ - const char *name; - struct obstack mem_pool; - hash_table char_table; - hash_table reverse_table; - hash_table seq_table; -}; - - -/* We need one value to mark the error case. Let's use 0xffffffff. - I.e., it is placed in the last page of ISO 10646. For now only the - first is used and we have plenty of room. */ -#define ILLEGAL_CHAR_VALUE ((uint32_t) 0xffffffffu) - -/* Another value is needed to signal that a value is not yet determined. */ -#define UNINITIALIZED_CHAR_VALUE ((uint32_t) 0xfffffffeu) - - -/* Prototypes for repertoire map handling functions. */ -extern struct repertoire_t *repertoire_read (const char *filename); - -/* Report missing repertoire map. */ -extern void repertoire_complain (const char *name); - -/* Return UCS4 value of character with given NAME. */ -extern uint32_t repertoire_find_value (const struct repertoire_t *repertoire, - const char *name, size_t len); - -/* Return symbol for given UCS4 value. */ -extern const char *repertoire_find_symbol (const struct repertoire_t *repertoire, - uint32_t ucs); - -/* Query the has table to memoize mapping from UCS4 to byte sequences. */ -extern struct charseq *repertoire_find_seq (const struct repertoire_t *rep, - uint32_t ucs); - -#endif /* repertoiremap.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/simple-hash.c b/src/system/libroot/posix/glibc/locale/programs/simple-hash.c deleted file mode 100644 index 35e32ca51e..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/simple-hash.c +++ /dev/null @@ -1,400 +0,0 @@ -/* Implement simple hashing table with string based keys. - Copyright (C) 1994, 1995, 1996, 1997, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , October 1994. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#if HAVE_OBSTACK -# include -#else -# include "obstack.h" -#endif - -#ifdef HAVE_VALUES_H -# include -#endif - -#include "simple-hash.h" - -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free - -#ifndef BITSPERBYTE -# define BITSPERBYTE 8 -#endif - -#ifndef LONGBITS -# define LONGBITS (sizeof (long) * BITSPERBYTE) -#endif - -#ifndef bcopy -# define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif - -extern void *xmalloc (size_t __n); -extern void *xcalloc (size_t __n, size_t __m); - -typedef struct hash_entry -{ - unsigned long used; - const void *key; - size_t keylen; - void *data; - struct hash_entry *next; -} -hash_entry; - -/* Prototypes for local functions. */ -static void insert_entry_2 (hash_table *htab, const void *key, size_t keylen, - unsigned long hval, size_t idx, void *data); -static size_t lookup (hash_table *htab, const void *key, size_t keylen, - unsigned long int hval); -static size_t lookup_2 (hash_table *htab, const void *key, size_t keylen, - unsigned long int hval); -static unsigned long compute_hashval (const void *key, size_t keylen); -static int is_prime (unsigned long int candidate); - - -int -init_hash (htab, init_size) - hash_table *htab; - unsigned long int init_size; -{ - /* We need the size to be a prime. */ - init_size = next_prime (init_size); - - /* Initialize the data structure. */ - htab->size = init_size; - htab->filled = 0; - htab->first = NULL; - htab->table = (void *) xcalloc (init_size + 1, sizeof (hash_entry)); - if (htab->table == NULL) - return -1; - - obstack_init (&htab->mem_pool); - - return 0; -} - - -int -delete_hash (htab) - hash_table *htab; -{ - free (htab->table); - obstack_free (&htab->mem_pool, NULL); - return 0; -} - - -int -insert_entry (htab, key, keylen, data) - hash_table *htab; - const void *key; - size_t keylen; - void *data; -{ - unsigned long int hval = compute_hashval (key, keylen); - hash_entry *table = (hash_entry *) htab->table; - size_t idx = lookup (htab, key, keylen, hval); - - if (table[idx].used) - /* We don't want to overwrite the old value. */ - return -1; - else - { - /* An empty bucket has been found. */ - insert_entry_2 (htab, obstack_copy (&htab->mem_pool, key, keylen), - keylen, hval, idx, data); - return 0; - } -} - -static void -insert_entry_2 (htab, key, keylen, hval, idx, data) - hash_table *htab; - const void *key; - size_t keylen; - unsigned long int hval; - size_t idx; - void *data; -{ - hash_entry *table = (hash_entry *) htab->table; - - table[idx].used = hval; - table[idx].key = key; - table[idx].keylen = keylen; - table[idx].data = data; - - /* List the new value in the list. */ - if ((hash_entry *) htab->first == NULL) - { - table[idx].next = &table[idx]; - *(hash_entry **) &htab->first = &table[idx]; - } - else - { - table[idx].next = ((hash_entry *) htab->first)->next; - ((hash_entry *) htab->first)->next = &table[idx]; - *(hash_entry **) &htab->first = &table[idx]; - } - - ++htab->filled; - if (100 * htab->filled > 90 * htab->size) - { - /* Table is filled more than 90%. Resize the table. */ - unsigned long int old_size = htab->size; - - htab->size = next_prime (htab->size * 2); - htab->filled = 0; - htab->first = NULL; - htab->table = (void *) xcalloc (1 + htab->size, sizeof (hash_entry)); - - for (idx = 1; idx <= old_size; ++idx) - if (table[idx].used) - insert_entry_2 (htab, table[idx].key, table[idx].keylen, - table[idx].used, - lookup_2 (htab, table[idx].key, table[idx].keylen, - table[idx].used), - table[idx].data); - - free (table); - } -} - - -int -find_entry (htab, key, keylen, result) - hash_table *htab; - const void *key; - size_t keylen; - void **result; -{ - hash_entry *table = (hash_entry *) htab->table; - size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen)); - - if (table[idx].used == 0) - return -1; - - *result = table[idx].data; - return 0; -} - - -int -set_entry (htab, key, keylen, newval) - hash_table *htab; - const void *key; - size_t keylen; - void *newval; -{ - hash_entry *table = (hash_entry *) htab->table; - size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen)); - - if (table[idx].used == 0) - return -1; - - table[idx].data = newval; - return 0; -} - - -int -iterate_table (htab, ptr, key, keylen, data) - hash_table *htab; - void **ptr; - const void **key; - size_t *keylen; - void **data; -{ - if (*ptr == NULL) - { - if (htab->first == NULL) - return -1; - *ptr = (void *) ((hash_entry *) htab->first)->next; - } - else - { - if (*ptr == htab->first) - return -1; - *ptr = (void *) (((hash_entry *) *ptr)->next); - } - - *key = ((hash_entry *) *ptr)->key; - *keylen = ((hash_entry *) *ptr)->keylen; - *data = ((hash_entry *) *ptr)->data; - return 0; -} - - -static size_t -lookup (htab, key, keylen, hval) - hash_table *htab; - const void *key; - size_t keylen; - unsigned long hval; -{ - unsigned long hash; - size_t idx; - hash_entry *table = (hash_entry *) htab->table; - - /* First hash function: simply take the modul but prevent zero. */ - hash = 1 + hval % htab->size; - - idx = hash; - - if (table[idx].used) - { - if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (key, table[idx].key, keylen) == 0) - return idx; - - /* Second hash function as suggested in [Knuth]. */ - hash = 1 + hval % (htab->size - 2); - - do - { - if (idx <= hash) - idx = htab->size + idx - hash; - else - idx -= hash; - - /* If entry is found use it. */ - if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (key, table[idx].key, keylen) == 0) - return idx; - } - while (table[idx].used); - } - return idx; -} - - -/* References: - [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986 - [Knuth] The Art of Computer Programming, part3 (6.4) */ - -static size_t -lookup_2 (htab, key, keylen, hval) - hash_table *htab; - const void *key; - size_t keylen; - unsigned long int hval; -{ - unsigned long int hash; - size_t idx; - hash_entry *table = (hash_entry *) htab->table; - - /* First hash function: simply take the modul but prevent zero. */ - hash = 1 + hval % htab->size; - - idx = hash; - - if (table[idx].used) - { - if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (table[idx].key, key, keylen) == 0) - return idx; - - /* Second hash function as suggested in [Knuth]. */ - hash = 1 + hval % (htab->size - 2); - - do - { - if (idx <= hash) - idx = htab->size + idx - hash; - else - idx -= hash; - - /* If entry is found use it. */ - if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (table[idx].key, key, keylen) == 0) - return idx; - } - while (table[idx].used); - } - return idx; -} - - -static unsigned long -compute_hashval (key, keylen) - const void *key; - size_t keylen; -{ - size_t cnt; - unsigned long int hval, g; - - /* Compute the hash value for the given string. The algorithm - is taken from [Aho,Sethi,Ullman]. */ - cnt = 0; - hval = keylen; - while (cnt < keylen) - { - hval <<= 4; - hval += (unsigned long int) *(((char *) key) + cnt++); - g = hval & ((unsigned long) 0xf << (LONGBITS - 4)); - if (g != 0) - { - hval ^= g >> (LONGBITS - 8); - hval ^= g; - } - } - return hval != 0 ? hval : ~((unsigned long) 0); -} - - -unsigned long -next_prime (seed) - unsigned long int seed; -{ - /* Make it definitely odd. */ - seed |= 1; - - while (!is_prime (seed)) - seed += 2; - - return seed; -} - - -static int -is_prime (candidate) - unsigned long int candidate; -{ - /* No even number and none less than 10 will be passed here. */ - unsigned long int divn = 3; - unsigned long int sq = divn * divn; - - while (sq < candidate && candidate % divn != 0) - { - ++divn; - sq += 4 * divn; - ++divn; - } - - return candidate % divn != 0; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/simple-hash.h b/src/system/libroot/posix/glibc/locale/programs/simple-hash.h deleted file mode 100644 index baca76fb5c..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/simple-hash.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _SIMPLE_HASH_H -#define _SIMPLE_HASH_H - -#include - -typedef struct hash_table -{ - unsigned long int size; - unsigned long int filled; - void *first; - void *table; - struct obstack mem_pool; -} -hash_table; - - -extern int init_hash (hash_table *htab, unsigned long int init_size) __THROW; -extern int delete_hash (hash_table *htab) __THROW; -extern int insert_entry (hash_table *htab, const void *key, size_t keylen, - void *data) __THROW; -extern int find_entry (hash_table *htab, const void *key, size_t keylen, - void **result) __THROW; -extern int set_entry (hash_table *htab, const void *key, size_t keylen, - void *newval) __THROW; - -extern int iterate_table (hash_table *htab, void **ptr, - const void **key, size_t *keylen, void **data) - __THROW; - -extern unsigned long int next_prime (unsigned long int seed) __THROW; - -#endif /* simple-hash.h */ diff --git a/src/system/libroot/posix/glibc/locale/programs/xmalloc.c b/src/system/libroot/posix/glibc/locale/programs/xmalloc.c deleted file mode 100644 index c365bacf98..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/xmalloc.c +++ /dev/null @@ -1,117 +0,0 @@ -/* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990,91,92,93,94,95,96,97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#if __STDC__ -#define VOID void -#else -#define VOID char -#endif - -#include - -#if STDC_HEADERS || _LIBC -#include -static VOID *fixup_null_alloc __P ((size_t n)); -VOID *xmalloc __P ((size_t n)); -VOID *xcalloc __P ((size_t n, size_t s)); -VOID *xrealloc __P ((VOID *p, size_t n)); -#else -VOID *calloc (); -VOID *malloc (); -VOID *realloc (); -void free (); -#endif - -#include -#include "error.h" - -#ifndef _ -# define _(str) gettext (str) -#endif - -#ifndef EXIT_FAILURE -#define EXIT_FAILURE 4 -#endif - -/* Exit value when the requested amount of memory is not available. - The caller may set it to some other value. */ -int xmalloc_exit_failure = EXIT_FAILURE; - -static VOID * -fixup_null_alloc (n) - size_t n; -{ - VOID *p; - - p = 0; - if (n == 0) - p = malloc ((size_t) 1); - if (p == 0) - error (xmalloc_exit_failure, 0, _("memory exhausted")); - return p; -} - -/* Allocate N bytes of memory dynamically, with error checking. */ - -VOID * -xmalloc (n) - size_t n; -{ - VOID *p; - - p = malloc (n); - if (p == 0) - p = fixup_null_alloc (n); - return p; -} - -/* Allocate memory for N elements of S bytes, with error checking. */ - -VOID * -xcalloc (n, s) - size_t n, s; -{ - VOID *p; - - p = calloc (n, s); - if (p == 0) - p = fixup_null_alloc (n); - return p; -} - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. - If P is NULL, run xmalloc. */ - -VOID * -xrealloc (p, n) - VOID *p; - size_t n; -{ - if (p == 0) - return xmalloc (n); - p = realloc (p, n); - if (p == 0) - p = fixup_null_alloc (n); - return p; -} diff --git a/src/system/libroot/posix/glibc/locale/programs/xstrdup.c b/src/system/libroot/posix/glibc/locale/programs/xstrdup.c deleted file mode 100644 index 38c012c0fc..0000000000 --- a/src/system/libroot/posix/glibc/locale/programs/xstrdup.c +++ /dev/null @@ -1,39 +0,0 @@ -/* xstrdup.c -- copy a string with out of memory checking - Copyright (C) 1990, 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if defined STDC_HEADERS || defined HAVE_STRING_H || _LIBC -# include -#else -# include -#endif -void *xmalloc __P ((size_t n)); -char *xstrdup __P ((char *string)); - -/* Return a newly allocated copy of STRING. */ - -char * -xstrdup (string) - char *string; -{ - return strcpy (xmalloc (strlen (string) + 1), string); -} diff --git a/src/system/libroot/posix/glibc/locale/setlocale.c b/src/system/libroot/posix/glibc/locale/setlocale.c deleted file mode 100644 index 3953322434..0000000000 --- a/src/system/libroot/posix/glibc/locale/setlocale.c +++ /dev/null @@ -1,472 +0,0 @@ -/* Copyright (C) 1991, 92, 95-99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "localeinfo.h" - -/* For each category declare two external variables (with weak references): - extern const struct locale_data *_nl_current_CATEGORY; - This points to the current locale's in-core data for CATEGORY. - extern const struct locale_data _nl_C_CATEGORY; - This contains the built-in "C"/"POSIX" locale's data for CATEGORY. - Both are weak references; if &_nl_current_CATEGORY is zero, - then nothing is using the locale data. */ -#define DEFINE_CATEGORY(category, category_name, items, a) \ -extern struct locale_data *_nl_current_##category; \ -extern struct locale_data _nl_C_##category; -#include "categories.def" -#undef DEFINE_CATEGORY - -/* Array indexed by category of pointers to _nl_current_CATEGORY slots. - Elements are zero for categories whose data is never used. */ -struct locale_data * *const _nl_current[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = &_nl_current_##category, -#include "categories.def" -#undef DEFINE_CATEGORY - /* We need this additional element to simplify the code. It must - simply be != NULL. */ - [LC_ALL] = (struct locale_data **) ~0ul - }; - -/* Array indexed by category of pointers to _nl_C_CATEGORY slots. - Elements are zero for categories whose data is never used. */ -struct locale_data *const _nl_C[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = &_nl_C_##category, -#include "categories.def" -#undef DEFINE_CATEGORY - }; - - -/* Define an array of category names (also the environment variable names), - indexed by integral category. */ -const char *const _nl_category_names[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = category_name, -#include "categories.def" -#undef DEFINE_CATEGORY - [LC_ALL] = "LC_ALL" - }; -/* An array of their lengths, for convenience. */ -const size_t _nl_category_name_sizes[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = sizeof (category_name) - 1, -#include "categories.def" -#undef DEFINE_CATEGORY - [LC_ALL] = sizeof ("LC_ALL") - 1 - }; - - -/* Declare the postload functions used below. */ -#undef NO_POSTLOAD -#define NO_POSTLOAD _nl_postload_ctype /* Harmless thing known to exist. */ -#define DEFINE_CATEGORY(category, category_name, items, postload) \ -extern void postload (void); -#include "categories.def" -#undef DEFINE_CATEGORY -#undef NO_POSTLOAD - -/* Define an array indexed by category of postload functions to call after - loading and installing that category's data. */ -static void (*const _nl_category_postload[]) (void) = - { -#define DEFINE_CATEGORY(category, category_name, items, postload) \ - [category] = postload, -#include "categories.def" -#undef DEFINE_CATEGORY - }; - - -/* Name of current locale for each individual category. - Each is malloc'd unless it is nl_C_name. */ -static const char *_nl_current_names[] = - { -#define DEFINE_CATEGORY(category, category_name, items, a) \ - [category] = _nl_C_name, -#include "categories.def" -#undef DEFINE_CATEGORY - [LC_ALL] = _nl_C_name /* For LC_ALL. */ - }; - - -/* Lock for protecting global data. */ -__libc_lock_define_initialized (, __libc_setlocale_lock) - -/* Defined in loadmsgcat.c. */ -extern int _nl_msg_cat_cntr; - - -/* Use this when we come along an error. */ -#define ERROR_RETURN \ - do { \ - __set_errno (EINVAL); \ - return NULL; \ - } while (0) - - -/* Construct a new composite name. */ -static inline char * -new_composite_name (int category, const char *newnames[__LC_LAST]) -{ - size_t last_len = 0; - size_t cumlen = 0; - int i; - char *new, *p; - int same = 1; - - for (i = 0; i < __LC_LAST; ++i) - if (i != LC_ALL) - { - const char *name = (category == LC_ALL ? newnames[i] : - category == i ? newnames[0] : - _nl_current_names[i]); - last_len = strlen (name); - cumlen += _nl_category_name_sizes[i] + 1 + last_len + 1; - if (i > 0 && same && strcmp (name, newnames[0]) != 0) - same = 0; - } - - if (same) - { - /* All the categories use the same name. */ - if (strcmp (newnames[0], _nl_C_name) == 0 - || strcmp (newnames[0], _nl_POSIX_name) == 0) - return (char *) _nl_C_name; - - new = malloc (last_len + 1); - - return new == NULL ? NULL : memcpy (new, newnames[0], last_len + 1); - } - - new = malloc (cumlen); - if (new == NULL) - return NULL; - p = new; - for (i = 0; i < __LC_LAST; ++i) - if (i != LC_ALL) - { - /* Add "CATEGORY=NAME;" to the string. */ - const char *name = (category == LC_ALL ? newnames[i] : - category == i ? newnames[0] : - _nl_current_names[i]); - p = __stpcpy (p, _nl_category_names[i]); - *p++ = '='; - p = __stpcpy (p, name); - *p++ = ';'; - } - p[-1] = '\0'; /* Clobber the last ';'. */ - return new; -} - - -/* Put NAME in _nl_current_names. */ -static inline void -setname (int category, const char *name) -{ - if (_nl_current_names[category] == name) - return; - - if (_nl_current_names[category] != _nl_C_name) - free ((char *) _nl_current_names[category]); - - _nl_current_names[category] = name; -} - - -/* Put DATA in *_nl_current[CATEGORY]. */ -static inline void -setdata (int category, struct locale_data *data) -{ - if (_nl_current[category] != NULL) - { - *_nl_current[category] = data; - if (_nl_category_postload[category]) - (*_nl_category_postload[category]) (); - } -} - - -char * -setlocale (int category, const char *locale) -{ - char *locale_path; - size_t locale_path_len; - const char *locpath_var; - char *composite; - - /* Sanity check for CATEGORY argument. */ - if (__builtin_expect (category, 0) < 0 - || __builtin_expect (category, 0) >= __LC_LAST) - ERROR_RETURN; - - /* Does user want name of current locale? */ - if (locale == NULL) - return (char *) _nl_current_names[category]; - - if (strcmp (locale, _nl_current_names[category]) == 0) - /* Changing to the same thing. */ - return (char *) _nl_current_names[category]; - - /* We perhaps really have to load some data. So we determine the - path in which to look for the data now. The environment variable - `LOCPATH' must only be used when the binary has no SUID or SGID - bit set. */ - locale_path = NULL; - locale_path_len = 0; - - locpath_var = getenv ("LOCPATH"); - if (locpath_var != NULL && locpath_var[0] != '\0') - if (__argz_create_sep (locpath_var, ':', - &locale_path, &locale_path_len) != 0) - return NULL; - - if (__argz_add_sep (&locale_path, &locale_path_len, LOCALEDIR, ':') != 0) - return NULL; - - if (category == LC_ALL) - { - /* The user wants to set all categories. The desired locales - for the individual categories can be selected by using a - composite locale name. This is a semi-colon separated list - of entries of the form `CATEGORY=VALUE'. */ - const char *newnames[__LC_LAST]; - struct locale_data *newdata[__LC_LAST]; - - /* Set all name pointers to the argument name. */ - for (category = 0; category < __LC_LAST; ++category) - if (category != LC_ALL) - newnames[category] = (char *) locale; - - if (__builtin_expect (strchr (locale, ';') != NULL, 0)) - { - /* This is a composite name. Make a copy and split it up. */ - char *np = strdupa (locale); - char *cp; - int cnt; - - while ((cp = strchr (np, '=')) != NULL) - { - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL - && (size_t) (cp - np) == _nl_category_name_sizes[cnt] - && memcmp (np, _nl_category_names[cnt], cp - np) == 0) - break; - - if (cnt == __LC_LAST) - /* Bogus category name. */ - ERROR_RETURN; - - /* Found the category this clause sets. */ - newnames[cnt] = ++cp; - cp = strchr (cp, ';'); - if (cp != NULL) - { - /* Examine the next clause. */ - *cp = '\0'; - np = cp + 1; - } - else - /* This was the last clause. We are done. */ - break; - } - - for (cnt = 0; cnt < __LC_LAST; ++cnt) - if (cnt != LC_ALL && newnames[cnt] == locale) - /* The composite name did not specify all categories. */ - ERROR_RETURN; - } - - /* Protect global data. */ - __libc_lock_lock (__libc_setlocale_lock); - - /* Load the new data for each category. */ - while (category-- > 0) - if (category != LC_ALL) - { - newdata[category] = _nl_find_locale (locale_path, locale_path_len, - category, - &newnames[category]); - - if (newdata[category] == NULL) - break; - - /* We must not simply free a global locale since we have no - control over the usage. So we mark it as un-deletable. */ - if (newdata[category]->usage_count != UNDELETABLE) - newdata[category]->usage_count = UNDELETABLE; - - /* Make a copy of locale name. */ - if (newnames[category] != _nl_C_name) - { - newnames[category] = strdup (newnames[category]); - if (newnames[category] == NULL) - break; - } - } - - /* Create new composite name. */ - composite = (category >= 0 - ? NULL : new_composite_name (LC_ALL, newnames)); - if (composite != NULL) - { - /* Now we have loaded all the new data. Put it in place. */ - for (category = 0; category < __LC_LAST; ++category) - if (category != LC_ALL) - { - setdata (category, newdata[category]); - setname (category, newnames[category]); - } - setname (LC_ALL, composite); - - /* We successfully loaded a new locale. Let the message catalog - functions know about this. */ - ++_nl_msg_cat_cntr; - } - else - for (++category; category < __LC_LAST; ++category) - if (category != LC_ALL && newnames[category] != _nl_C_name) - free ((char *) newnames[category]); - - /* Critical section left. */ - __libc_lock_unlock (__libc_setlocale_lock); - - /* Free the resources (the locale path variable. */ - free (locale_path); - - return composite; - } - else - { - struct locale_data *newdata = NULL; - const char *newname[1] = { locale }; - - /* Protect global data. */ - __libc_lock_lock (__libc_setlocale_lock); - - if (_nl_current[category] != NULL) - { - /* Only actually load the data if anything will use it. */ - newdata = _nl_find_locale (locale_path, locale_path_len, category, - &newname[0]); - if (newdata == NULL) - goto abort_single; - - /* We must not simply free a global locale since we have no - control over the usage. So we mark it as un-deletable. - - Note: do not remove the `if', it's necessary to copy with - the builtin locale data. */ - if (newdata->usage_count != UNDELETABLE) - newdata->usage_count = UNDELETABLE; - } - - /* Make a copy of locale name. */ - if (newname[0] != _nl_C_name) - { - newname[0] = strdup (newname[0]); - if (newname[0] == NULL) - goto abort_single; - } - - /* Create new composite name. */ - composite = new_composite_name (category, newname); - if (composite == NULL) - { - if (newname[0] != _nl_C_name) - free ((char *) newname[0]); - - /* Say that we don't have any data loaded. */ - abort_single: - newname[0] = NULL; - } - else - { - if (_nl_current[category] != NULL) - setdata (category, newdata); - - setname (category, newname[0]); - setname (LC_ALL, composite); - - /* We successfully loaded a new locale. Let the message catalog - functions know about this. */ - ++_nl_msg_cat_cntr; - } - - /* Critical section left. */ - __libc_lock_unlock (__libc_setlocale_lock); - - /* Free the resources (the locale path variable. */ - free (locale_path); - - return (char *) newname[0]; - } -} - -extern struct loaded_l10nfile *_nl_locale_file_list[]; - -static void __attribute__ ((unused)) -free_mem (void) -{ - int category; - - for (category = 0; category < __LC_LAST; ++category) - if (category != LC_ALL) - { - struct locale_data *here = *_nl_current[category]; - struct loaded_l10nfile *runp = _nl_locale_file_list[category]; - - /* If this category is already "C" don't do anything. */ - if (here != _nl_C[category]) - { - /* We have to be prepared that sometime later me still - might need the locale information. */ - setdata (category, _nl_C[category]); - setname (category, _nl_C_name); - - _nl_unload_locale (here); - } - - while (runp != NULL) - { - struct loaded_l10nfile *curr = runp; - struct locale_data *data = (struct locale_data *) runp->data; - - if (data != NULL && data != here && data != _nl_C[category]) - _nl_unload_locale (data); - runp = runp->next; - free ((char *) curr->filename); - free (curr); - } - } - - setname (LC_ALL, _nl_C_name); -} -text_set_element (__libc_subfreeres, free_mem); diff --git a/src/system/libroot/posix/glibc/locale/strlen-hash.h b/src/system/libroot/posix/glibc/locale/strlen-hash.h deleted file mode 100644 index fd193ceff7..0000000000 --- a/src/system/libroot/posix/glibc/locale/strlen-hash.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Implements hashing function for string with known length. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -/* We assume to have `size_t' value with at least 32 bits. */ -#define HASHWORDBITS 32 - - -/* Defines the so called `hashpjw' function by P.J. Weinberger - [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, - 1986, 1987 Bell Telephone Laboratories, Inc.] */ -static size_t hash_string (const char *__str_param, size_t __len); - -static inline size_t -hash_string (const char *str_param, size_t len) -{ - size_t hval, g; - const char *end_str = str_param + len; - - /* Compute the hash value for the given string. */ - hval = len; - while (str_param != end_str) - { - hval <<= 4; - hval += (size_t) *str_param++; - g = hval & ((size_t) 0xf << (HASHWORDBITS - 4)); - if (g != 0) - { - hval ^= g >> (HASHWORDBITS - 8); - hval ^= g; - } - } - return hval; -} diff --git a/src/system/libroot/posix/glibc/locale/uselocale.c b/src/system/libroot/posix/glibc/locale/uselocale.c deleted file mode 100644 index e2f38c10ba..0000000000 --- a/src/system/libroot/posix/glibc/locale/uselocale.c +++ /dev/null @@ -1,73 +0,0 @@ -/* uselocale -- fetch and set the current per-thread locale - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include "localeinfo.h" -#include - -/* Switch the current thread's locale to DATASET. - If DATASET is null, instead just return the current setting. - The special value LC_GLOBAL_LOCALE is the initial setting - for all threads, and means the thread uses the global - setting controlled by `setlocale'. */ -locale_t -__uselocale (locale_t newloc) -{ - locale_t oldloc = __libc_tsd_get (LOCALE); - - if (newloc != NULL) - { - const locale_t locobj - = newloc == LC_GLOBAL_LOCALE ? &_nl_global_locale : newloc; - __libc_tsd_set (LOCALE, locobj); - -#ifdef NL_CURRENT_INDIRECT - /* Now we must update all the per-category thread-local variables to - point into the new current locale for this thread. The magic - symbols _nl_current_LC_FOO_used are defined to meaningless values - if _nl_current_LC_FOO was linked in. By using weak references to - both symbols and testing the address of _nl_current_LC_FOO_used, - we can avoid accessing the _nl_current_LC_FOO thread-local - variable at all when no code referring to it was linked in. We - need the special bogus symbol because while TLS symbols can be - weak, there is no reasonable way to test for the default-zero - value as with a heap symbol (taking the address would just use - some bogus offset from our thread pointer). */ - -# define DEFINE_CATEGORY(category, category_name, items, a) \ - { \ - extern char _nl_current_##category##_used; \ - weak_extern (_nl_current_##category##_used) \ - weak_extern (_nl_current_##category) \ - if (&_nl_current_##category##_used != 0) \ - _nl_current_##category = &locobj->__locales[category]; \ - } -# include "categories.def" -# undef DEFINE_CATEGORY -#endif - - /* Update the special tsd cache of some locale data. */ - __libc_tsd_set (CTYPE_B, (void *) locobj->__ctype_b); - __libc_tsd_set (CTYPE_TOLOWER, (void *) locobj->__ctype_tolower); - __libc_tsd_set (CTYPE_TOUPPER, (void *) locobj->__ctype_toupper); - } - - return oldloc == &_nl_global_locale ? LC_GLOBAL_LOCALE : oldloc; -} -weak_alias (__uselocale, uselocale) diff --git a/src/system/libroot/posix/glibc/locale/xlocale.c b/src/system/libroot/posix/glibc/locale/xlocale.c index dd1dbbf508..c10065b111 100644 --- a/src/system/libroot/posix/glibc/locale/xlocale.c +++ b/src/system/libroot/posix/glibc/locale/xlocale.c @@ -42,12 +42,6 @@ struct __locale_struct _nl_C_locobj = [LC_COLLATE] = &_nl_C_LC_COLLATE, [LC_MONETARY] = &_nl_C_LC_MONETARY, [LC_MESSAGES] = &_nl_C_LC_MESSAGES, - [LC_PAPER] = &_nl_C_LC_PAPER, - [LC_NAME] = &_nl_C_LC_NAME, - [LC_ADDRESS] = &_nl_C_LC_ADDRESS, - [LC_TELEPHONE] = &_nl_C_LC_TELEPHONE, - [LC_MEASUREMENT] = &_nl_C_LC_MEASUREMENT, - [LC_IDENTIFICATION] = &_nl_C_LC_IDENTIFICATION }, .__ctype_b = (const unsigned short int *) _nl_C_LC_CTYPE_class + 128, .__ctype_tolower = (const int *) _nl_C_LC_CTYPE_tolower + 128, diff --git a/src/system/libroot/posix/glibc/locale/xlocale.h b/src/system/libroot/posix/glibc/locale/xlocale.h index fa65e10a01..ce2446e67f 100644 --- a/src/system/libroot/posix/glibc/locale/xlocale.h +++ b/src/system/libroot/posix/glibc/locale/xlocale.h @@ -28,7 +28,7 @@ typedef struct __locale_struct { /* Note: LC_ALL is not a valid index into this array. */ - struct locale_data *__locales[13]; /* 13 = __LC_LAST. */ + struct locale_data *__locales[7]; /* 7 = __LC_LAST. */ /* To increase the speed of this solution we add some special members. */ const unsigned short int *__ctype_b; diff --git a/src/system/libroot/posix/glibc/stdlib/Makefile b/src/system/libroot/posix/glibc/stdlib/Makefile deleted file mode 100644 index 4d471c911b..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/Makefile +++ /dev/null @@ -1,119 +0,0 @@ -# Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Makefile for stdlib routines -# -subdir := stdlib - -headers := stdlib.h alloca.h monetary.h fmtmsg.h ucontext.h sys/ucontext.h \ - inttypes.h stdint.h bits/wordsize.h bits/wchar.h \ - errno.h sys/errno.h bits/errno.h - -routines := \ - atof atoi atol atoll \ - abort \ - bsearch qsort msort \ - getenv putenv setenv secure-getenv \ - exit on_exit atexit cxa_atexit cxa_finalize old_atexit \ - abs labs llabs \ - div ldiv lldiv \ - mblen mbstowcs mbtowc wcstombs wctomb \ - random random_r rand rand_r \ - drand48 erand48 lrand48 nrand48 mrand48 jrand48 \ - srand48 seed48 lcong48 \ - drand48_r erand48_r lrand48_r nrand48_r mrand48_r jrand48_r \ - srand48_r seed48_r lcong48_r \ - drand48-iter \ - strtol strtoul strtoll strtoull \ - strtol_l strtoul_l strtoll_l strtoull_l \ - strtof strtod strtold \ - strtof_l strtod_l strtold_l \ - system canonicalize \ - a64l l64a \ - rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg \ - strtoimax strtoumax wcstoimax wcstoumax \ - getcontext setcontext makecontext swapcontext - -# These routines will be omitted from the libc shared object. -# Instead the static object files will be included in a special archive -# linked against when the shared library will be used. -static-only-routines = atexit - -distribute := exit.h grouping.h abort-instr.h isomac.c tst-fmtmsg.sh \ - allocalim.h -test-srcs := tst-fmtmsg -tests := tst-strtol tst-strtod testmb testrand testsort testdiv \ - test-canon test-canon2 tst-strtoll tst-environ \ - tst-xpg-basename tst-random tst-bsearch tst-limits \ - tst-rand48 bug-strtod tst-setcontext test-a64l tst-qsort \ - tst-system - - -# Several mpn functions from GNU MP are used by the strtod function. -mpn-routines := inlines add_n addmul_1 cmp divmod_1 divrem udiv_qrnnd \ - lshift rshift mod_1 mul mul_1 mul_n sub_n submul_1 -mpn-headers = longlong.h gmp.h gmp-impl.h gmp-mparam.h asm-syntax.h - -routines := $(strip $(routines) $(mpn-routines)) \ - dbl2mpn ldbl2mpn \ - mpn2flt mpn2dbl mpn2ldbl -aux := fpioconst mp_clz_tab -distribute := $(distribute) $(mpn-headers) gen-mpn-copy fpioconst.h - -generated += isomac isomac.out - -CFLAGS-bsearch.c = $(exceptions) -CFLAGS-msort.c = $(exceptions) -CFLAGS-qsort.c = $(exceptions) - -include ../Makeconfig - -ifneq (,$(filter %REENTRANT, $(defines))) -CFLAGS-strfmon.c = -D_IO_MTSAFE_IO -CFLAGS-strfmon_l.c = -D_IO_MTSAFE_IO -endif - -ifeq (yes,$(have-protected)) -CFLAGS-atexit.c = -DHAVE_DOT_HIDDEN -endif - -include ../Rules - -# Testdir has to be named stdlib and needs to be writable -test-canon-ARGS = --test-dir=${common-objpfx}stdlib - -tst-strtod-ENV = LOCPATH=$(common-objpfx)localedata - -# Run a test on the header files we use. -tests: $(objpfx)isomac.out - -ifeq (no,$(cross-compiling)) -tests: $(objpfx)tst-fmtmsg.out -endif - -$(objpfx)isomac.out: $(objpfx)isomac - $(dir $<)$(notdir $<) '$(CC)' \ - '-I../include -I.. $(+sysdep-includes) $(sysincludes)' > $<.out - -isomac-CFLAGS = -O -$(objpfx)isomac: isomac.c - $(native-compile) - -$(objpfx)tst-fmtmsg.out: tst-fmtmsg.sh $(objpfx)tst-fmtmsg - $(SHELL) -e $< $(common-objpfx) '$(run-program-prefix)' $(common-objpfx)stdlib/ diff --git a/src/system/libroot/posix/glibc/stdlib/Versions b/src/system/libroot/posix/glibc/stdlib/Versions deleted file mode 100644 index fc1e5a1004..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/Versions +++ /dev/null @@ -1,105 +0,0 @@ -libc { - GLIBC_2.0 { - # functions with required interface outside normal name space - __xpg_basename; - - # functions used in inline functions or macros - __strto*_internal; - - # functions used in other libraries - __secure_getenv; - - # a* - a64l; abort; abs; atexit; atof; atoi; atol; atoll; - - # b* - bsearch; - - # c* - canonicalize_file_name; clearenv; - - # d* - div; drand48; drand48_r; - - # e* - erand48; erand48_r; exit; - - # g* - getenv; getsubopt; - - # i* - initstate; initstate_r; - - # l* - l64a; labs; lcong48; lcong48_r; ldiv; llabs; lldiv; lrand48; lrand48_r; - - # m* - mblen; mbrlen; mbrtowc; mbsinit; mbsnrtowcs; mbsrtowcs; mbstowcs; - mbtowc; mcheck; mcount; mrand48; mrand48_r; - - # n* - nrand48; nrand48_r; - - # o* - on_exit; - - # p* - putenv; - - # q* - qsort; - - # r* - rand; rand_r; random; random_r; realpath; rpmatch; - - # s* - seed48; seed48_r; setcontext; setenv; setstate; setstate_r; srand; srand48; - srand48_r; srandom; srandom_r; step; strfmon; strtod; strtof; strtol; - strtold; strtoll; strtoq; strtoul; strtoull; strtouq; system; - - # u* - unsetenv; - - # w* - wcstombs; wctomb; - } - GLIBC_2.1 { - # a* - addseverity; - - # f* - fmtmsg; - - # g* - getcontext; - - # m* - makecontext; - - # s* - strtoimax; strtoumax; swapcontext; - } - GLIBC_2.1.1 { - # _* - _Exit; - - # i* - imaxabs; imaxdiv; - } - GLIBC_2.1.3 { - # used by new G++ ABI - __cxa_atexit; __cxa_finalize; - } - GLIBC_2.3 { - # Silent change in SUS. - realpath; - } - GLIBC_PRIVATE { - # functions which have an additional interface since they are - # are cancelable. - __libc_system; - - # functions used in other libraries. - __on_exit; - } -} diff --git a/src/system/libroot/posix/glibc/stdlib/a64l.c b/src/system/libroot/posix/glibc/stdlib/a64l.c deleted file mode 100644 index 23faf2744f..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/a64l.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 1995, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , August 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#define TABLE_BASE 0x2e -#define TABLE_SIZE 0x4d - -#define XX ((char)0x40) - - -static const char a64l_table[TABLE_SIZE] = -{ - /* 0x2e */ 0, 1, - /* 0x30 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, XX, XX, XX, XX, XX, XX, - /* 0x40 */ XX, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - /* 0x50 */ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, XX, XX, XX, XX, XX, - /* 0x60 */ XX, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - /* 0x70 */ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 -}; - - -long int -a64l (string) - const char *string; -{ - const char *ptr = string; - unsigned long int result = 0ul; - const char *end = ptr + 6; - int shift = 0; - - do - { - unsigned index; - unsigned value; - - index = *ptr - TABLE_BASE; - if ((unsigned int) index >= TABLE_SIZE) - break; - value = (int) a64l_table[index]; - if (value == (int) XX) - break; - ++ptr; - result |= value << shift; - shift += 6; - } - while (ptr != end); - - return (long int) result; -} diff --git a/src/system/libroot/posix/glibc/stdlib/abs.c b/src/system/libroot/posix/glibc/stdlib/abs.c deleted file mode 100644 index 7a6ad36a1a..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/abs.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef abs - -/* Return the absolute value of I. */ -int -abs (int i) -{ - return i < 0 ? -i : i; -} diff --git a/src/system/libroot/posix/glibc/stdlib/atexit.c b/src/system/libroot/posix/glibc/stdlib/atexit.c deleted file mode 100644 index 024381dd43..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/atexit.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1991, 1996, 1999, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include "exit.h" - - -/* This is defined by newer gcc version unique for each module. */ -extern void *__dso_handle __attribute__ ((__weak__)); - - -/* Register FUNC to be executed by `exit'. */ -int -atexit (void (*func) (void)) -{ - return __cxa_atexit ((void (*) (void *)) func, NULL, - &__dso_handle == NULL ? NULL : __dso_handle); -} - -/* Hide the symbol so that no definition but the one locally in the - executable or DSO is used. */ -#ifdef HAVE_DOT_HIDDEN -asm (".hidden\tatexit"); -#endif diff --git a/src/system/libroot/posix/glibc/stdlib/atof.c b/src/system/libroot/posix/glibc/stdlib/atof.c deleted file mode 100644 index 2ce3483ef2..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/atof.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef atof - - -/* Convert a string to a double. */ -double -atof (const char *nptr) -{ - return strtod (nptr, (char **) NULL); -} diff --git a/src/system/libroot/posix/glibc/stdlib/atoi.c b/src/system/libroot/posix/glibc/stdlib/atoi.c deleted file mode 100644 index 217287586e..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/atoi.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef atoi - - -/* Convert a string to an int. */ -int -atoi (const char *nptr) -{ - return (int) strtol (nptr, (char **) NULL, 10); -} diff --git a/src/system/libroot/posix/glibc/stdlib/atol.c b/src/system/libroot/posix/glibc/stdlib/atol.c deleted file mode 100644 index ec77f44cb8..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/atol.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef atol - - -/* Convert a string to a long int. */ -long int -atol (const char *nptr) -{ - return strtol (nptr, (char **) NULL, 10); -} diff --git a/src/system/libroot/posix/glibc/stdlib/atoll.c b/src/system/libroot/posix/glibc/stdlib/atoll.c deleted file mode 100644 index f2fdd1abeb..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/atoll.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef atoll - - -/* Convert a string to a long long int. */ -long long int -atoll (const char *nptr) -{ - return strtoll (nptr, (char **) NULL, 10); -} diff --git a/src/system/libroot/posix/glibc/stdlib/bsearch.c b/src/system/libroot/posix/glibc/stdlib/bsearch.c deleted file mode 100644 index 1bc6c4ba43..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/bsearch.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - - -/* Perform a binary search for KEY in BASE which has NMEMB elements - of SIZE bytes each. The comparisons are done by (*COMPAR)(). */ -void * -bsearch (const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *)) -{ - size_t l, u, idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p); - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} -libc_hidden_def (bsearch) diff --git a/src/system/libroot/posix/glibc/stdlib/canonicalize.c b/src/system/libroot/posix/glibc/stdlib/canonicalize.c deleted file mode 100644 index 5c55c5dbd1..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/canonicalize.c +++ /dev/null @@ -1,240 +0,0 @@ -/* Return the canonical absolute name of a given file. - Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* Return the canonical absolute name of file NAME. A canonical name - does not contain any `.', `..' components nor any repeated path - separators ('/') or symlinks. All path components must exist. If - RESOLVED is null, the result is malloc'd; otherwise, if the - canonical name is PATH_MAX chars or more, returns null with `errno' - set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, - returns the name in RESOLVED. If the name cannot be resolved and - RESOLVED is non-NULL, it contains the path of the first component - that cannot be resolved. If the path can be resolved, RESOLVED - holds the same value as the value returned. */ - -char * -__realpath (const char *name, char *resolved) -{ - char *rpath, *dest, *extra_buf = NULL; - const char *start, *end, *rpath_limit; - long int path_max; - int num_links = 0; - - if (name == NULL) - { - /* As per Single Unix Specification V2 we must return an error if - either parameter is a null pointer. We extend this to allow - the RESOLVED parameter to be NULL in case the we are expected to - allocate the room for the return value. */ - __set_errno (EINVAL); - return NULL; - } - - if (name[0] == '\0') - { - /* As per Single Unix Specification V2 we must return an error if - the name argument points to an empty string. */ - __set_errno (ENOENT); - return NULL; - } - -#ifdef PATH_MAX - path_max = PATH_MAX; -#else - path_max = pathconf (name, _PC_PATH_MAX); - if (path_max <= 0) - path_max = 1024; -#endif - - if (resolved == NULL) - { - rpath = malloc (path_max); - if (rpath == NULL) - return NULL; - } - else - rpath = resolved; - rpath_limit = rpath + path_max; - - if (name[0] != '/') - { - if (!__getcwd (rpath, path_max)) - { - rpath[0] = '\0'; - goto error; - } - dest = strchr (rpath, '\0'); - } - else - { - rpath[0] = '/'; - dest = rpath + 1; - } - - for (start = end = name; *start; start = end) - { - struct stat64 st; - int n; - - /* Skip sequence of multiple path-separators. */ - while (*start == '/') - ++start; - - /* Find end of path component. */ - for (end = start; *end && *end != '/'; ++end) - /* Nothing. */; - - if (end - start == 0) - break; - else if (end - start == 1 && start[0] == '.') - /* nothing */; - else if (end - start == 2 && start[0] == '.' && start[1] == '.') - { - /* Back up to previous component, ignore if at root already. */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } - else - { - size_t new_size; - - if (dest[-1] != '/') - *dest++ = '/'; - - if (dest + (end - start) >= rpath_limit) - { - ptrdiff_t dest_offset = dest - rpath; - char *new_rpath; - - if (resolved) - { - __set_errno (ENAMETOOLONG); - if (dest > rpath + 1) - dest--; - *dest = '\0'; - goto error; - } - new_size = rpath_limit - rpath; - if (end - start + 1 > path_max) - new_size += end - start + 1; - else - new_size += path_max; - new_rpath = (char *) realloc (rpath, new_size); - if (new_rpath == NULL) - goto error; - rpath = new_rpath; - rpath_limit = rpath + new_size; - - dest = rpath + dest_offset; - } - - dest = __mempcpy (dest, start, end - start); - *dest = '\0'; - - if (__lxstat64 (_STAT_VER, rpath, &st) < 0) - goto error; - - if (S_ISLNK (st.st_mode)) - { - char *buf = __alloca (path_max); - size_t len; - - if (++num_links > MAXSYMLINKS) - { - __set_errno (ELOOP); - goto error; - } - - n = __readlink (rpath, buf, path_max); - if (n < 0) - goto error; - buf[n] = '\0'; - - if (!extra_buf) - extra_buf = __alloca (path_max); - - len = strlen (end); - if ((long int) (n + len) >= path_max) - { - __set_errno (ENAMETOOLONG); - goto error; - } - - /* Careful here, end may be a pointer into extra_buf... */ - memmove (&extra_buf[n], end, len + 1); - name = end = memcpy (extra_buf, buf, n); - - if (buf[0] == '/') - dest = rpath + 1; /* It's an absolute symlink */ - else - /* Back up to previous component, ignore if at root already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } - } - } - if (dest > rpath + 1 && dest[-1] == '/') - --dest; - *dest = '\0'; - - return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath; - -error: - if (resolved) - strcpy (resolved, rpath); - else - free (rpath); - return NULL; -} -versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); - - -#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3) -char * -__old_realpath (const char *name, char *resolved) -{ - if (resolved == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - return __realpath (name, resolved); -} -compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0); -#endif - - -char * -__canonicalize_file_name (const char *name) -{ - return __realpath (name, NULL); -} -weak_alias (__canonicalize_file_name, canonicalize_file_name) diff --git a/src/system/libroot/posix/glibc/stdlib/cxa_atexit.c b/src/system/libroot/posix/glibc/stdlib/cxa_atexit.c deleted file mode 100644 index a3d4c5037d..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/cxa_atexit.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include "exit.h" - -#undef __cxa_atexit - -/* Register a function to be called by exit or when a shared library - is unloaded. This function is only called from code generated by - the C++ compiler. */ -int -__cxa_atexit (void (*func) (void *), void *arg, void *d) -{ - struct exit_function *new = __new_exitfn (); - - if (new == NULL) - return -1; - - new->flavor = ef_cxa; - new->func.cxa.fn = (void (*) (void *, int)) func; - new->func.cxa.arg = arg; - new->func.cxa.dso_handle = d; - return 0; -} -INTDEF(__cxa_atexit) - - -/* We change global data, so we need locking. */ -__libc_lock_define_initialized (static, lock) - - -static struct exit_function_list initial; -struct exit_function_list *__exit_funcs = &initial; - -struct exit_function * -__new_exitfn (void) -{ - struct exit_function_list *l; - size_t i = 0; - - __libc_lock_lock (lock); - - for (l = __exit_funcs; l != NULL; l = l->next) - { - for (i = 0; i < l->idx; ++i) - if (l->fns[i].flavor == ef_free) - break; - if (i < l->idx) - break; - - if (l->idx < sizeof (l->fns) / sizeof (l->fns[0])) - { - i = l->idx++; - break; - } - } - - if (l == NULL) - { - l = (struct exit_function_list *) - malloc (sizeof (struct exit_function_list)); - if (l != NULL) - { - l->next = __exit_funcs; - __exit_funcs = l; - - l->idx = 1; - i = 0; - } - } - - /* Mark entry as used, but we don't know the flavor now. */ - if (l != NULL) - l->fns[i].flavor = ef_us; - - __libc_lock_unlock (lock); - - return l == NULL ? NULL : &l->fns[i]; -} diff --git a/src/system/libroot/posix/glibc/stdlib/cxa_finalize.c b/src/system/libroot/posix/glibc/stdlib/cxa_finalize.c deleted file mode 100644 index 16f50286e1..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/cxa_finalize.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include "exit.h" -#include - -/* If D is non-NULL, call all functions registered with `__cxa_atexit' - with the same dso handle. Otherwise, if D is NULL, do nothing. */ -void -__cxa_finalize (void *d) -{ - struct exit_function_list *funcs; - - for (funcs = __exit_funcs; funcs; funcs = funcs->next) - { - struct exit_function *f; - - for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f) - if ((d == NULL || d == f->func.cxa.dso_handle) - /* We don't want to run this cleanup more than once. */ - && compare_and_swap (&f->flavor, ef_cxa, ef_free)) - (*f->func.cxa.fn) (f->func.cxa.arg, 0); - } - - /* Remove the registered fork handlers. */ -#ifdef UNREGISTER_ATFORK - UNREGISTER_ATFORK (d); -#endif -} diff --git a/src/system/libroot/posix/glibc/stdlib/exit.c b/src/system/libroot/posix/glibc/stdlib/exit.c deleted file mode 100644 index ac247a1233..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/exit.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 1991,95,96,97,99,2001,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include "exit.h" - -#ifdef HAVE_GNU_LD -#include "set-hooks.h" -DEFINE_HOOK (__libc_atexit, (void)) -#endif - - -/* Call all functions registered with `atexit' and `on_exit', - in the reverse of the order in which they were registered - perform stdio cleanup, and terminate program execution with STATUS. */ -void -exit (int status) -{ - /* We do it this way to handle recursive calls to exit () made by - the functions registered with `atexit' and `on_exit'. We call - everyone on the list and use the status value in the last - exit (). */ - while (__exit_funcs != NULL) - { - struct exit_function_list *old; - - while (__exit_funcs->idx > 0) - { - const struct exit_function *const f = - &__exit_funcs->fns[--__exit_funcs->idx]; - switch (f->flavor) - { - case ef_free: - case ef_us: - break; - case ef_on: - (*f->func.on.fn) (status, f->func.on.arg); - break; - case ef_at: - (*f->func.at) (); - break; - case ef_cxa: - (*f->func.cxa.fn) (f->func.cxa.arg, status); - break; - } - } - - old = __exit_funcs; - __exit_funcs = __exit_funcs->next; - if (__exit_funcs != NULL) - /* Don't free the last element in the chain, this is the statically - allocate element. */ - free (old); - } - -#ifdef HAVE_GNU_LD - RUN_HOOK (__libc_atexit, ()); -#else - { - extern void _cleanup (void); - _cleanup (); - } -#endif - - _exit (status); -} -libc_hidden_def (exit) diff --git a/src/system/libroot/posix/glibc/stdlib/exit.h b/src/system/libroot/posix/glibc/stdlib/exit.h deleted file mode 100644 index 055506f04e..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/exit.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (C) 1991,1996,1997,1999,2001,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _EXIT_H -#define _EXIT_H 1 - - -enum -{ - ef_free, /* `ef_free' MUST be zero! */ - ef_us, - ef_on, - ef_at, - ef_cxa -}; - -struct exit_function - { - /* `flavour' should be of type of the `enum' above but since we need - this element in an atomic operation we have to use `long int'. */ - long int flavor; - union - { - void (*at) (void); - struct - { - void (*fn) (int status, void *arg); - void *arg; - } on; - struct - { - void (*fn) (void *arg, int status); - void *arg; - void *dso_handle; - } cxa; - } func; - }; -struct exit_function_list - { - struct exit_function_list *next; - size_t idx; - struct exit_function fns[32]; - }; -extern struct exit_function_list *__exit_funcs attribute_hidden; - -extern struct exit_function *__new_exitfn (void); - -#endif /* exit.h */ diff --git a/src/system/libroot/posix/glibc/stdlib/fmtmsg.c b/src/system/libroot/posix/glibc/stdlib/fmtmsg.c deleted file mode 100644 index 37c641c7ef..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/fmtmsg.c +++ /dev/null @@ -1,408 +0,0 @@ -/* Copyright (C) 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#ifdef USE_IN_LIBIO -# include -#endif - - -/* We have global data, protect the modification. */ -__libc_lock_define_initialized (static, lock) - - -enum -{ - label_mask = 0x01, - severity_mask = 0x02, - text_mask = 0x04, - action_mask = 0x08, - tag_mask = 0x10, - all_mask = label_mask | severity_mask | text_mask | action_mask | tag_mask -}; - -static const struct -{ - size_t len; - /* Adjust the size if new elements are added. */ - const char name[12]; -} keywords[] = - { - { 5, "label" }, - { 8, "severity" }, - { 4, "text" }, - { 6, "action"}, - { 3, "tag" } - }; -#define NKEYWORDS (sizeof( keywords) / sizeof (keywords[0])) - - -struct severity_info -{ - int severity; - const char *string; - struct severity_info *next; -}; - - -/* List of known severities. */ -static const struct severity_info nosev = -{ - MM_NOSEV, "", NULL -}; -static const struct severity_info haltsev = -{ - MM_HALT, "HALT", (struct severity_info *) &nosev -}; -static const struct severity_info errorsev = -{ - MM_ERROR, "ERROR", (struct severity_info *) &haltsev -}; -static const struct severity_info warningsev = -{ - MM_WARNING, "WARNING", (struct severity_info *) &errorsev -}; -static const struct severity_info infosev = -{ - MM_INFO, "INFO", (struct severity_info *) &warningsev -}; - -/* Start of the list. */ -static struct severity_info *severity_list = (struct severity_info *) &infosev; - -/* Mask of values we will print. */ -static int print; - -/* Prototypes for local functions. */ -static void init (void); -static int internal_addseverity (int severity, const char *string) - internal_function; - - -int -fmtmsg (long int classification, const char *label, int severity, - const char *text, const char *action, const char *tag) -{ - __libc_once_define (static, once); - int result = MM_OK; - struct severity_info *severity_rec; - - /* make sure everything is initialized. */ - __libc_once (once, init); - - /* Start the real work. First check whether the input is ok. */ - if (label != MM_NULLLBL) - { - /* Must be two fields, separated by a colon. */ - const char *cp = strchr (label, ':'); - if (cp == NULL) - return MM_NOTOK; - - /* The first field must not contain more then 10 bytes. */ - if (cp - label > 10 - /* The second field must not have more then 14 bytes. */ - || strlen (cp + 1) > 14) - return MM_NOTOK; - } - - for (severity_rec = severity_list; severity_rec != NULL; - severity_rec = severity_rec->next) - if (severity == severity_rec->severity) - /* Bingo. */ - break; - - /* If we don't know anything about the severity level return an error. */ - if (severity_rec == NULL) - return MM_NOTOK; - - - /* Now we can print. */ - if (classification & MM_PRINT) - { - int do_label = (print & label_mask) && label != MM_NULLLBL; - int do_severity = (print & severity_mask) && severity != MM_NULLSEV; - int do_text = (print & text_mask) && text != MM_NULLTXT; - int do_action = (print & action_mask) && action != MM_NULLACT; - int do_tag = (print & tag_mask) && tag != MM_NULLTAG; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - { - if (__fwprintf (stderr, L"%s%s%s%s%s%s%s%s%s%s\n", - do_label ? label : "", - do_label - && (do_severity | do_text | do_action | do_tag) - ? ": " : "", - do_severity ? severity_rec->string : "", - do_severity && (do_text | do_action | do_tag) - ? ": " : "", - do_text ? text : "", - do_text && (do_action | do_tag) ? "\n" : "", - do_action ? "TO FIX: " : "", - do_action ? action : "", - do_action && do_tag ? " " : "", - do_tag ? tag : "") < 0) - /* Oh, oh. An error occurred during the output. */ - result = MM_NOMSG; - } - else -#endif - if (fprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n", - do_label ? label : "", - do_label && (do_severity | do_text | do_action | do_tag) - ? ": " : "", - do_severity ? severity_rec->string : "", - do_severity && (do_text | do_action | do_tag) ? ": " : "", - do_text ? text : "", - do_text && (do_action | do_tag) ? "\n" : "", - do_action ? "TO FIX: " : "", - do_action ? action : "", - do_action && do_tag ? " " : "", - do_tag ? tag : "") < 0) - /* Oh, oh. An error occurred during the output. */ - result = MM_NOMSG; - } - - if (classification & MM_CONSOLE) - { - int do_label = label != MM_NULLLBL; - int do_severity = severity != MM_NULLSEV; - int do_text = text != MM_NULLTXT; - int do_action = action != MM_NULLACT; - int do_tag = tag != MM_NULLTAG; - - syslog (LOG_ERR, "%s%s%s%s%s%s%s%s%s%s\n", - do_label ? label : "", - do_label && (do_severity | do_text | do_action | do_tag) - ? ": " : "", - do_severity ? severity_rec->string : "", - do_severity && (do_text | do_action | do_tag) ? ": " : "", - do_text ? text : "", - do_text && (do_action | do_tag) ? "\n" : "", - do_action ? "TO FIX: " : "", - do_action ? action : "", - do_action && do_tag ? " " : "", - do_tag ? tag : ""); - } - - return result; -} - - -/* Initialize from environment variable content. */ -static void -init (void) -{ - const char *msgverb_var = getenv ("MSGVERB"); - const char *sevlevel_var = getenv ("SEV_LEVEL"); - - if (msgverb_var != NULL && msgverb_var[0] != '\0') - { - /* Using this extra variable allows us to work without locking. */ - do - { - size_t cnt; - - for (cnt = 0; cnt < NKEYWORDS; ++cnt) - if (memcmp (msgverb_var, - keywords[cnt].name, keywords[cnt].len) == 0 - && (msgverb_var[keywords[cnt].len] == ':' - || msgverb_var[keywords[cnt].len] == '\0')) - break; - - if (cnt < NKEYWORDS) - { - print |= 1 << cnt; - - msgverb_var += keywords[cnt].len; - if (msgverb_var[0] == ':') - ++msgverb_var; - } - else - { - /* We found an illegal keyword in the environment - variable. The specifications say that we print all - fields. */ - print = all_mask; - break; - } - } - while (msgverb_var[0] != '\0'); - } - else - print = all_mask; - - - if (sevlevel_var != NULL) - { - __libc_lock_lock (lock); - - while (sevlevel_var[0] != '\0') - { - const char *end = __strchrnul (sevlevel_var, ':'); - int level; - - /* First field: keyword. This is not used here but it must be - present. */ - while (sevlevel_var < end) - if (*sevlevel_var++ == ',') - break; - - if (sevlevel_var < end) - { - /* Second field: severity level, a number. */ - char *cp; - - level = strtol (sevlevel_var, &cp, 0); - if (cp != sevlevel_var && cp < end && *cp++ == ',' - && level > MM_INFO) - { - const char *new_string; - - new_string = __strndup (cp, end - cp); - - if (new_string != NULL - && (internal_addseverity (level, new_string) - != MM_OK)) - free ((char *) new_string); - } - } - - sevlevel_var = end + (*end == ':' ? 1 : 0); - } - } -} - - -/* Add the new entry to the list. */ -static int -internal_function -internal_addseverity (int severity, const char *string) -{ - struct severity_info *runp, *lastp; - int result = MM_OK; - - /* First see if there is already a record for the severity level. */ - for (runp = severity_list, lastp = NULL; runp != NULL; runp = runp-> next) - if (runp->severity == severity) - break; - else - lastp = runp; - - if (runp != NULL) - { - /* Release old string. */ - free ((char *) runp->string); - - if (string != NULL) - /* Change the string. */ - runp->string = string; - else - { - /* Remove the severity class. */ - if (lastp == NULL) - severity_list = runp->next; - else - lastp->next = runp->next; - - free (runp); - } - } - else if (string != NULL) - { - runp = malloc (sizeof (*runp)); - if (runp == NULL) - result = MM_NOTOK; - else - { - runp->severity = severity; - runp->next = severity_list; - runp->string = string; - severity_list = runp; - } - } - else - /* We tried to remove a non-existing severity class. */ - result = MM_NOTOK; - - return result; -} - - -/* Add new severity level or remove old one. */ -int -addseverity (int severity, const char *string) -{ - int result; - const char *new_string; - - /* Prevent illegal SEVERITY values. */ - if (severity <= MM_INFO) - return MM_NOTOK; - - if (string == NULL) - /* We want to remove the severity class. */ - new_string = NULL; - else - { - new_string = __strdup (string); - - if (new_string == NULL) - /* Allocation failed or illegal value. */ - return MM_NOTOK; - } - - /* Protect the global data. */ - __libc_lock_lock (lock); - - /* Do the real work. */ - result = internal_addseverity (severity, string); - - if (result != MM_OK) - /* Free the allocated string. */ - free ((char *) new_string); - - /* Release the lock. */ - __libc_lock_unlock (lock); - - return result; -} - - -libc_freeres_fn (free_mem) -{ - struct severity_info *runp = severity_list; - - while (runp != NULL) - if (runp->severity > MM_INFO) - { - /* This is data we have to release. */ - struct severity_info *here = runp; - free ((char *) runp->string); - runp = runp->next; - free (here); - } - else - runp = runp->next; -} diff --git a/src/system/libroot/posix/glibc/stdlib/fmtmsg.h b/src/system/libroot/posix/glibc/stdlib/fmtmsg.h deleted file mode 100644 index cd9bdeaffd..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/fmtmsg.h +++ /dev/null @@ -1,106 +0,0 @@ -/* Message display handling. - Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef __FMTMSG_H -#define __FMTMSG_H 1 - -#include - - -__BEGIN_DECLS - -/* Values to control `fmtmsg' function. */ -enum -{ - MM_HARD = 0x001, /* Source of the condition is hardware. */ -#define MM_HARD MM_HARD - MM_SOFT = 0x002, /* Source of the condition is software. */ -#define MM_SOFT MM_SOFT - MM_FIRM = 0x004, /* Source of the condition is firmware. */ -#define MM_FIRM MM_FIRM - MM_APPL = 0x008, /* Condition detected by application. */ -#define MM_APPL MM_APPL - MM_UTIL = 0x010, /* Condition detected by utility. */ -#define MM_UTIL MM_UTIL - MM_OPSYS = 0x020, /* Condition detected by operating system. */ -#define MM_OPSYS MM_OPSYS - MM_RECOVER = 0x040, /* Recoverable error. */ -#define MM_RECOVER MM_RECOVER - MM_NRECOV = 0x080, /* Non-recoverable error. */ -#define MM_NRECOV MM_NRECOV - MM_PRINT = 0x100, /* Display message in standard error. */ -#define MM_PRINT MM_PRINT - MM_CONSOLE = 0x200 /* Display message on system console. */ -#define MM_CONSOLE MM_CONSOLE -}; - -/* Values to be for SEVERITY parameter of `fmtmsg'. */ -enum -{ - MM_NOSEV = 0, /* No severity level provided for the message. */ -#define MM_NOSEV MM_NOSEV - MM_HALT, /* Error causing application to halt. */ -#define MM_HALT MM_HALT - MM_ERROR, /* Application has encountered a non-fatal fault. */ -#define MM_ERROR MM_ERROR - MM_WARNING, /* Application has detected unusual non-error - condition. */ -#define MM_WARNING MM_WARNING - MM_INFO /* Informative message. */ -#define MM_INFO MM_INFO -}; - - -/* Macros which can be used as null values for the arguments of `fmtmsg'. */ -#define MM_NULLLBL ((char *) 0) -#define MM_NULLSEV 0 -#define MM_NULLMC ((long int) 0) -#define MM_NULLTXT ((char *) 0) -#define MM_NULLACT ((char *) 0) -#define MM_NULLTAG ((char *) 0) - - -/* Possible return values of `fmtmsg'. */ -enum -{ - MM_NOTOK = -1, -#define MM_NOTOK MM_NOTOK - MM_OK = 0, -#define MM_OK MM_OK - MM_NOMSG = 1, -#define MM_NOMSG MM_NOMSG - MM_NOCON = 4 -#define MM_NOCON MM_NOCON -}; - - -/* Print message with given CLASSIFICATION, LABEL, SEVERITY, TEXT, ACTION - and TAG to console or standard error. */ -extern int fmtmsg (long int __classification, __const char *__label, - int __severity, __const char *__text, - __const char *__action, __const char *__tag) __THROW; - -#ifdef __USE_SVID -/* Add or remove severity level. */ -extern int addseverity (int __severity, __const char *__string) __THROW; -#endif - -__END_DECLS - -#endif /* fmtmsg.h */ diff --git a/src/system/libroot/posix/glibc/stdlib/gen-mpn-copy b/src/system/libroot/posix/glibc/stdlib/gen-mpn-copy deleted file mode 100644 index 01656ae54d..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/gen-mpn-copy +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -translations=' -sparc64 sparc/sparc64 -sparc32/v8 sparc/sparc8 -sparc32 sparc -x86/pentium i386/i586 -x86 i386 -m68k/mc68000 m68k/m68000 -m68k/mc68020 m68k/m68020 -m88k/mc88100 m88k/m88100 -m88k/mc88110 m88k/m88110 -mips3 mips/mips3 -mips2 mips -hppa/hppa1_1 hppa/hppa1.1 -alpha/ev5 alpha/alphaev5 -power rs6000 -am29000 a29k -' - -set $translations -while [ $# -ge 2 ]; do - gmp=$1 glibc=$2 - shift; shift - echo 'mpn-found-1 := $(filter $(gmp-srcdir)/mpn/'$gmp'/%,$(mpn-found)) -mpn-copy-1 := $(patsubst $(gmp-srcdir)/mpn/'$gmp'/%,$(sysdep_dir)/'$glibc\ -'/%,$(mpn-found-1)) -mpn-found := $(filter-out $(mpn-found-1),$(mpn-found)) -mpn-copy-sysdep := $(mpn-copy-sysdep) $(mpn-copy-1) -$(mpn-copy-1): $(sysdep_dir)/'$glibc'/%: \ - $(ignore gmp2glibc.sed) $(gmp-srcdir)/mpn/'$gmp'/% - $(gmp2glibc)' -done - -exit 0 diff --git a/src/system/libroot/posix/glibc/stdlib/getsubopt.c b/src/system/libroot/posix/glibc/stdlib/getsubopt.c deleted file mode 100644 index aac756d34c..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/getsubopt.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Parse comma separate list into words. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - - -/* Parse comma separated suboption from *OPTIONP and match against - strings in TOKENS. If found return index and set *VALUEP to - optional value introduced by an equal sign. If the suboption is - not part of TOKENS return in *VALUEP beginning of unknown - suboption. On exit *OPTIONP is set to the beginning of the next - token or at the terminating NUL character. */ -int -getsubopt (optionp, tokens, valuep) - char **optionp; - char *const *tokens; - char **valuep; -{ - char *endp, *vstart; - int cnt; - - if (**optionp == '\0') - return -1; - - /* Find end of next token. */ - endp = __strchrnul (*optionp, ','); - - /* Find start of value. */ - vstart = memchr (*optionp, '=', endp - *optionp); - if (vstart == NULL) - vstart = endp; - - /* Try to match the characters between *OPTIONP and VSTART against - one of the TOKENS. */ - for (cnt = 0; tokens[cnt] != NULL; ++cnt) - if (memcmp (*optionp, tokens[cnt], vstart - *optionp) == 0 - && tokens[cnt][vstart - *optionp] == '\0') - { - /* We found the current option in TOKENS. */ - *valuep = vstart != endp ? vstart + 1 : NULL; - - if (*endp != '\0') - *endp++ = '\0'; - *optionp = endp; - - return cnt; - } - - /* The current suboption does not match any option. */ - *valuep = *optionp; - - if (*endp != '\0') - *endp++ = '\0'; - *optionp = endp; - - return -1; -} diff --git a/src/system/libroot/posix/glibc/stdlib/isomac.c b/src/system/libroot/posix/glibc/stdlib/isomac.c deleted file mode 100644 index c0b9ad1db2..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/isomac.c +++ /dev/null @@ -1,445 +0,0 @@ -/* Check system header files for ISO 9899:1990 (ISO C) compliance. - Copyright (C) 1996,97,98,99,2001,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jens Schweikhardt , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This is a simple minded program that tries to find illegal macro - definitions in system header files. Illegal macro definitions are - those not from the implementation namespace (i.e. not starting with - an underscore) or not matching any identifier mandated by The - Standard. Some common macro names are considered okay, e.g. all those - beginning with E (which may be defined in ) or ending in - _MAX. See the arrays prefix[] and suffix[] below for details. - - In a compliant implementation no other macros can be defined, because - you could write strictly conforming programs that may fail to compile - due to syntax errors: suppose defines PIPE_BUF, then the - conforming - - #include - #include <- or where the bogus macro is defined - #include - #define STR(x) #x - #define XSTR(x) STR(x) - int main (void) - { - int PIPE_BUF = 0; - assert (strcmp ("PIPE_BUF", XSTR (PIPE_BUF)) == 0); - return 0; - } - - is expected to compile and meet the assertion. If it does not, your - compiler compiles some other language than Standard C. - - REQUIREMENTS: - This program calls gcc to get the list of defined macros. If you - don't have gcc you're probably out of luck unless your compiler or - preprocessor has something similar to gcc's -dM option. Tune - PRINT_MACROS in this case. This program assumes headers are found - under /usr/include and that there is a writable /tmp directory. - Tune SYSTEM_INCLUDE if your system differs. - #define BROKEN_SYSTEM if system(NULL) bombs -- one more violation - of ISO C, by the way. - - OUTPUT: - Each header file name is printed, followed by illegal macro names - and their definition. For the above example, you would see - ... - /usr/include/stdio.h - #define PIPE_BUF 5120 - ... - If your implementation does not yet incorporate Amendment 1 you - will see messages about iso646.h, wctype.h and wchar.h not being - found. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#include -#include -#include - -#define HEADER_MAX 256 - -static const char *macrofile; - -/* ISO C header names including Amendment 1 (without ".h" suffix). */ -static char *header[] = -{ - "assert", "ctype", "errno", "float", "iso646", "limits", "locale", - "math", "setjmp", "signal", "stdarg", "stddef", "stdio", "stdlib", - "string", "time", "wchar", "wctype" -}; - -/* Macros with these prefixes are considered okay. */ -static char *prefix[] = -{ - "_", "E", "is", "str", "mem", "SIG", "FLT_", "DBL_", "LDBL_", - "LC_", "wmem", "wcs" -}; - -/* Macros with these suffixes are considered okay. Will not work for - parametrized macros with arguments. */ -static char *suffix[] = -{ - "_MAX", "_MIN" -}; - -/* These macros are considered okay. In fact, these are just more prefixes. */ -static char *macros[] = -{ - "BUFSIZ", "CHAR_BIT", "CHAR_MAX", "CHAR_MIN", "CLOCKS_PER_SEC", - "DBL_DIG", "DBL_EPSILON", "DBL_MANT_DIG", "DBL_MAX", - "DBL_MAX_10_EXP", "DBL_MAX_EXP", "DBL_MIN", "DBL_MIN_10_EXP", - "DBL_MIN_EXP", "EDOM", "EILSEQ", "EOF", "ERANGE", "EXIT_FAILURE", - "EXIT_SUCCESS", "FILENAME_MAX", "FLT_DIG", "FLT_EPSILON", - "FLT_MANT_DIG", "FLT_MAX", "FLT_MAX_10_EXP", "FLT_MAX_EXP", - "FLT_MIN", "FLT_MIN_10_EXP", "FLT_MIN_EXP", "FLT_RADIX", - "FLT_ROUNDS", "FOPEN_MAX", "HUGE_VAL", "INT_MAX", "INT_MIN", - "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", "LC_NUMERIC", - "LC_TIME", "LDBL_DIG", "LDBL_EPSILON", "LDBL_MANT_DIG", "LDBL_MAX", - "LDBL_MAX_10_EXP", "LDBL_MAX_EXP", "LDBL_MIN", "LDBL_MIN_10_EXP", - "LDBL_MIN_EXP", "LONG_MAX", "LONG_MIN", "L_tmpnam", "MB_CUR_MAX", - "MB_LEN_MAX", "NDEBUG", "NULL", "RAND_MAX", "SCHAR_MAX", - "SCHAR_MIN", "SEEK_CUR", "SEEK_END", "SEEK_SET", "SHRT_MAX", - "SHRT_MIN", "SIGABRT", "SIGFPE", "SIGILL", "SIGINT", "SIGSEGV", - "SIGTERM", "SIG_DFL", "SIG_ERR", "SIG_IGN", "TMP_MAX", "UCHAR_MAX", - "UINT_MAX", "ULONG_MAX", "USHRT_MAX", "WCHAR_MAX", "WCHAR_MIN", - "WEOF", "_IOFBF", "_IOLBF", "_IONBF", "abort", "abs", "acos", - "acosf", "acosl", "and", "and_eq", "asctime", "asin", "asinf", - "asinl", "assert", "atan", "atan2", "atan2f", "atan2l", "atanf", - "atanl", "atexit", "atof", "atoi", "atol", "bitand", "bitor", - "bsearch", "btowc", "calloc", "ceil", "ceilf", "ceill", "clearerr", - "clock", "clock_t", "compl", "cos", "cosf", "cosh", "coshf", - "coshl", "cosl", "ctime", "difftime", "div", "div_t", "errno", - "exit", "exp", "expf", "expl", "fabs", "fabsf", "fabsl", "fclose", - "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets", "fgetwc", - "fgetws", "floor", "floorf", "floorl", "fmod", "fmodf", "fmodl", - "fopen", "fprintf", "fputc", "fputs", "fputwc", "fputws", "fread", - "free", "freopen", "frexp", "frexpf", "frexpl", "fscanf", "fseek", - "fsetpos", "ftell", "fwide", "fwprintf", "fwrite", "fwscanf", - "getc", "getchar", "getenv", "gets", "getwc", "getwchar", "gmtime", - "isalnum", "isalpha", "iscntrl", "isdigit", "isgraph", "islower", - "isprint", "ispunct", "isspace", "isupper", "iswalnum", "iswalpha", - "iswcntrl", "iswctype", "iswdigit", "iswgraph", "iswlower", - "iswprint", "iswpunct", "iswspace", "iswupper", "iswxdigit", - "isxdigit", "labs", "ldexp", "ldexpf", "ldexpl", "ldiv", "ldiv_t", - "localeconv", "localtime", "log", "log10", "log10f", "log10l", - "logf", "logl", "longjmp", "malloc", "mblen", "mbrlen", "mbrtowc", - "mbsinit", "mbsrtowcs", "mbstate_t", "mbstowcs", "mbtowc", "memchr", - "memcmp", "memcpy", "memmove", "memset", "mktime", "modf", "modff", - "modfl", "not", "not_eq", "offsetof", "or", "or_eq", "perror", - "pow", "powf", "powl", "printf", "ptrdiff_t", "putc", "putchar", - "puts", "putwc", "putwchar", "qsort", "raise", "rand", "realloc", - "remove", "rename", "rewind", "scanf", "setbuf", "setjmp", - "setlocale", "setvbuf", "sig_atomic_t", "signal", "sin", "sinf", - "sinh", "sinhf", "sinhl", "sinl", "size_t", "sprintf", "sqrt", - "sqrtf", "sqrtl", "srand", "sscanf", "stderr", "stdin", "stdout", - "strcat", "strchr", "strcmp", "strcoll", "strcpy", "strcspn", - "strerror", "strftime", "strlen", "strncat", "strncmp", "strncpy", - "strpbrk", "strrchr", "strspn", "strstr", "strtod", "strtok", - "strtol", "strtoul", "strxfrm", "swprintf", "swscanf", "system", - "tan", "tanf", "tanh", "tanhf", "tanhl", "tanl", "time", "time_t", - "tmpfile", "tmpnam", "tolower", "toupper", "towctrans", "towlower", - "towupper", "ungetc", "ungetwc", "va_arg", "va_copy", "va_end", "va_start", - "vfprintf", "vfwprintf", "vprintf", "vsprintf", "vswprintf", - "vwprintf", "wchar_t", "wcrtomb", "wcscat", "wcschr", "wcscmp", - "wcscoll", "wcscpy", "wcscspn", "wcsftime", "wcslen", "wcsncat", - "wcsncmp", "wcsncpy", "wcspbrk", "wcsrchr", "wcsrtombs", "wcsspn", - "wcsstr", "wcstod", "wcstok", "wcstol", "wcstombs", "wcstoul", - "wcsxfrm", "wctob", "wctomb", "wctrans", "wctrans_t", "wctype", - "wctype_t", "wint_t", "wmemchr", "wmemcmp", "wmemcpy", "wmemmove", - "wmemset", "wprintf", "wscanf", "xor", "xor_eq" -}; - -#define NUMBER_OF_HEADERS (sizeof header / sizeof *header) -#define NUMBER_OF_PREFIXES (sizeof prefix / sizeof *prefix) -#define NUMBER_OF_SUFFIXES (sizeof suffix / sizeof *suffix) -#define NUMBER_OF_MACROS (sizeof macros / sizeof *macros) - - -/* Format string to build command to invoke compiler. */ -static const char fmt[] = "\ -echo \"#include <%s>\" |\ -%s -E -dM -ansi -pedantic %s -D_LIBC -D_ISOMAC -DNOT_IN_libc -I. \ --isystem `%s --print-prog-name=include` - 2> /dev/null > %s"; - - -/* The compiler we use (given on the command line). */ -char *CC; -/* The -I parameters for CC to find all headers. */ -char *INC; - -static char *xstrndup (const char *, size_t); -static const char **get_null_defines (void); -static int check_header (const char *, const char **); - -int -main (int argc, char *argv[]) -{ - int h; - int result = 0; - const char **ignore_list; - - CC = argc > 1 ? argv[1] : "gcc"; - INC = argc > 2 ? argv[2] : ""; - - if (system (NULL) == 0) - { - puts ("Sorry, no command processor."); - return EXIT_FAILURE; - } - - /* First get list of symbols which are defined by the compiler. */ - ignore_list = get_null_defines (); - - fputs ("Tested files:\n", stdout); - - for (h = 0; h < NUMBER_OF_HEADERS; ++h) - { - char file_name[HEADER_MAX]; - sprintf (file_name, "%s.h", header[h]); - result |= check_header (file_name, ignore_list); - } - - /* The test suite should return errors but for now this is not - practical. Give a warning and ask the user to correct the bugs. */ - return result; -} - - -static char * -xstrndup (const char *s, size_t n) -{ - size_t len = n; - char *new = malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return memcpy (new, s, len); -} - - -static const char ** -get_null_defines (void) -{ - char line[BUFSIZ], *command; - char **result = NULL; - size_t result_len = 0; - size_t result_max = 0; - FILE *input; - int first = 1; - - macrofile = tmpnam (NULL); - - command = malloc (sizeof fmt + sizeof "/dev/null" + 2 * strlen (CC) - + strlen (INC) + strlen (macrofile)); - - if (command == NULL) - { - puts ("No more memory."); - exit (1); - } - - sprintf (command, fmt, "/dev/null", CC, INC, CC, macrofile); - - if (system (command)) - { - puts ("system() returned nonzero"); - return NULL; - } - free (command); - input = fopen (macrofile, "r"); - - if (input == NULL) - { - printf ("Could not read %s: ", macrofile); - perror (NULL); - return NULL; - } - - while (fgets (line, sizeof line, input) != NULL) - { - int i, okay = 0; - size_t endmac; - char *start, *end; - if (strlen (line) < 9 || line[7] != ' ') - { /* "#define A" */ - printf ("Malformed input, expected '#define MACRO'\ngot '%s'\n", - line); - continue; - } - if (line[8] == '_') - /* It's a safe identifier. */ - continue; - if (result_len == result_max) - { - result_max += 10; - result = realloc (result, result_max * sizeof (char **)); - if (result == NULL) - { - puts ("No more memory."); - exit (1); - } - } - start = &line[8]; - for (end = start + 1; !isspace (*end) && *end != '\0'; ++end) - ; - result[result_len] = xstrndup (start, end - start); - - if (strcmp (result[result_len], "NOT_IN_libc") != 0) - { - if (first) - { - fputs ("The following identifiers will be ignored since the compiler defines them\nby default:\n", stdout); - first = 0; - } - puts (result[result_len]); - } - ++result_len; - } - if (result_len == result_max) - { - result_max += 1; - result = realloc (result, result_max * sizeof (char **)); - if (result == NULL) - { - puts ("No more memory."); - exit (1); - } - } - result[result_len] = NULL; - fclose (input); - remove (macrofile); - - return (const char **) result; -} - - -static int -check_header (const char *file_name, const char **except) -{ - char line[BUFSIZ], *command; - FILE *input; - int result = 0; - - command = malloc (sizeof fmt + strlen (file_name) + 2 * strlen (CC) - + strlen (INC) + strlen (macrofile)); - - if (command == NULL) - { - puts ("No more memory."); - exit (1); - } - - puts (file_name); - sprintf (command, fmt, file_name, CC, INC, CC, macrofile); - - if (system (command)) - { - puts ("system() returned nonzero"); - result = 1; - } - free (command); - input = fopen (macrofile, "r"); - - if (input == NULL) - { - printf ("Could not read %s: ", macrofile); - perror (NULL); - return 1; - } - - while (fgets (line, sizeof line, input) != NULL) - { - int i, okay = 0; - size_t endmac; - const char **cpp; - if (strlen (line) < 9 || line[7] != ' ') - { /* "#define A" */ - printf ("Malformed input, expected '#define MACRO'\ngot '%s'\n", - line); - result = 1; - continue; - } - for (i = 0; i < NUMBER_OF_PREFIXES; ++i) - { - if (!strncmp (line+8, prefix[i], strlen (prefix[i]))) { - ++okay; - break; - } - } - if (okay) - continue; - for (i = 0; i < NUMBER_OF_MACROS; ++i) - { - if (!strncmp (line + 8, macros[i], strlen (macros[i]))) - { - ++okay; - break; - } - } - if (okay) - continue; - /* Find next char after the macro identifier; this can be either - a space or an open parenthesis. */ - endmac = strcspn (line + 8, " ("); - if (line[8+endmac] == '\0') - { - printf ("malformed input, expected '#define MACRO VALUE'\n" - "got '%s'\n", line); - result = 1; - continue; - } - for (i = 0; i < NUMBER_OF_SUFFIXES; ++i) - { - size_t len = strlen (suffix[i]); - if (!strncmp (line + 8 + endmac - len, suffix[i], len)) - { - ++okay; - break; - } - } - if (okay) - continue; - if (except != NULL) - for (cpp = except; *cpp != NULL; ++cpp) - { - size_t len = strlen (*cpp); - if (!strncmp (line + 8, *cpp, len) && isspace (line[8 + len])) - { - ++okay; - break; - } - } - if (!okay) - { - fputs (line, stdout); - result = 2; - } - } - fclose (input); - remove (macrofile); - - return result; -} - -/* EOF */ diff --git a/src/system/libroot/posix/glibc/stdlib/l64a.c b/src/system/libroot/posix/glibc/stdlib/l64a.c deleted file mode 100644 index f3a249fedf..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/l64a.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , August 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -/* Conversion table. */ -static const char conv_table[64] = -{ - '.', '/', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'A', 'B', 'C', 'D', - 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', - 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' -}; - -char * -l64a (n) - long int n; -{ - unsigned long int m = (unsigned long int) n; - static char result[7]; - int cnt; - - /* The standard says that only 32 bits are used. */ - m &= 0xffffffff; - - if (m == 0ul) - /* The value for N == 0 is defined to be the empty string. */ - return (char *) ""; - - for (cnt = 0; m > 0ul; ++cnt) - { - result[cnt] = conv_table[m & 0x3f]; - m >>= 6; - } - result[cnt] = '\0'; - - return result; -} diff --git a/src/system/libroot/posix/glibc/stdlib/msort.c b/src/system/libroot/posix/glibc/stdlib/msort.c deleted file mode 100644 index 45d6a99b83..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/msort.c +++ /dev/null @@ -1,156 +0,0 @@ -/* An alternative to qsort, with an identical interface. - This file is part of the GNU C Library. - Copyright (C) 1992,95-97,99,2000,01,02 Free Software Foundation, Inc. - Written by Mike Haertel, September 1988. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include - -static void msort_with_tmp (void *b, size_t n, size_t s, - __compar_fn_t cmp, char *t); - -static void -msort_with_tmp (void *b, size_t n, size_t s, __compar_fn_t cmp, - char *t) -{ - char *tmp; - char *b1, *b2; - size_t n1, n2; - - if (n <= 1) - return; - - n1 = n / 2; - n2 = n - n1; - b1 = b; - b2 = (char *) b + (n1 * s); - - msort_with_tmp (b1, n1, s, cmp, t); - msort_with_tmp (b2, n2, s, cmp, t); - - tmp = t; - - if (s == OPSIZ && (b1 - (char *) 0) % OPSIZ == 0) - /* We are operating on aligned words. Use direct word stores. */ - while (n1 > 0 && n2 > 0) - { - if ((*cmp) (b1, b2) <= 0) - { - --n1; - *((op_t *) tmp)++ = *((op_t *) b1)++; - } - else - { - --n2; - *((op_t *) tmp)++ = *((op_t *) b2)++; - } - } - else - while (n1 > 0 && n2 > 0) - { - if ((*cmp) (b1, b2) <= 0) - { - tmp = (char *) __mempcpy (tmp, b1, s); - b1 += s; - --n1; - } - else - { - tmp = (char *) __mempcpy (tmp, b2, s); - b2 += s; - --n2; - } - } - if (n1 > 0) - memcpy (tmp, b1, n1 * s); - memcpy (b, t, (n - n2) * s); -} - -void -qsort (void *b, size_t n, size_t s, __compar_fn_t cmp) -{ - const size_t size = n * s; - - if (size < 1024) - { - void *buf = __alloca (size); - - /* The temporary array is small, so put it on the stack. */ - msort_with_tmp (b, n, s, cmp, buf); - } - else - { - /* We should avoid allocating too much memory since this might - have to be backed up by swap space. */ - static long int phys_pages; - static int pagesize; - - if (phys_pages == 0) - { - phys_pages = __sysconf (_SC_PHYS_PAGES); - - if (phys_pages == -1) - /* Error while determining the memory size. So let's - assume there is enough memory. Otherwise the - implementer should provide a complete implementation of - the `sysconf' function. */ - phys_pages = (long int) (~0ul >> 1); - - /* The following determines that we will never use more than - a quarter of the physical memory. */ - phys_pages /= 4; - - pagesize = __sysconf (_SC_PAGESIZE); - } - - /* Just a comment here. We cannot compute - phys_pages * pagesize - and compare the needed amount of memory against this value. - The problem is that some systems might have more physical - memory then can be represented with a `size_t' value (when - measured in bytes. */ - - /* If the memory requirements are too high don't allocate memory. */ - if (size / pagesize > (size_t) phys_pages) - _quicksort (b, n, s, cmp); - else - { - /* It's somewhat large, so malloc it. */ - int save = errno; - char *tmp = malloc (size); - if (tmp == NULL) - { - /* Couldn't get space, so use the slower algorithm - that doesn't need a temporary array. */ - __set_errno (save); - _quicksort (b, n, s, cmp); - } - else - { - __set_errno (save); - msort_with_tmp (b, n, s, cmp, tmp); - free (tmp); - } - } - } -} -libc_hidden_def (qsort) diff --git a/src/system/libroot/posix/glibc/stdlib/old_atexit.c b/src/system/libroot/posix/glibc/stdlib/old_atexit.c deleted file mode 100644 index 45f330bec8..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/old_atexit.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2_2) -# define atexit __dyn_atexit -# include "atexit.c" -# undef atexit -compat_symbol (libc, __dyn_atexit, atexit, GLIBC_2_0); -#endif diff --git a/src/system/libroot/posix/glibc/stdlib/on_exit.c b/src/system/libroot/posix/glibc/stdlib/on_exit.c deleted file mode 100644 index d98fbb3a86..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/on_exit.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 1991, 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include "exit.h" - -/* Register a function to be called by exit. */ -int -__on_exit (void (*func) (int status, void *arg), void *arg) -{ - struct exit_function *new = __new_exitfn (); - - if (new == NULL) - return -1; - - new->flavor = ef_on; - new->func.on.fn = func; - new->func.on.arg = arg; - return 0; -} -weak_alias (__on_exit, on_exit) diff --git a/src/system/libroot/posix/glibc/stdlib/qsort.c b/src/system/libroot/posix/glibc/stdlib/qsort.c deleted file mode 100644 index 1ac268bec9..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/qsort.c +++ /dev/null @@ -1,248 +0,0 @@ -/* Copyright (C) 1991, 1992, 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Douglas C. Schmidt (schmidt@ics.uci.edu). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* If you consider tuning this algorithm, you should consult first: - Engineering a sort function; Jon Bentley and M. Douglas McIlroy; - Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ - -#include -#include -#include -#include - -/* Byte-wise swap two items of size SIZE. */ -#define SWAP(a, b, size) \ - do \ - { \ - register size_t __size = (size); \ - register char *__a = (a), *__b = (b); \ - do \ - { \ - char __tmp = *__a; \ - *__a++ = *__b; \ - *__b++ = __tmp; \ - } while (--__size > 0); \ - } while (0) - -/* Discontinue quicksort algorithm when partition gets below this size. - This particular magic number was chosen to work best on a Sun 4/260. */ -#define MAX_THRESH 4 - -/* Stack node declarations used to store unfulfilled partition obligations. */ -typedef struct - { - char *lo; - char *hi; - } stack_node; - -/* The next 4 #defines implement a very fast in-line stack abstraction. */ -/* The stack needs log (total_elements) entries (we could even subtract - log(MAX_THRESH)). Since total_elements has type size_t, we get as - upper bound for log (total_elements): - bits per byte (CHAR_BIT) * sizeof(size_t). */ -#define STACK_SIZE (CHAR_BIT * sizeof(size_t)) -#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) -#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) -#define STACK_NOT_EMPTY (stack < top) - - -/* Order size using quicksort. This implementation incorporates - four optimizations discussed in Sedgewick: - - 1. Non-recursive, using an explicit stack of pointer that store the - next array partition to sort. To save time, this maximum amount - of space required to store an array of SIZE_MAX is allocated on the - stack. Assuming a 32-bit (64 bit) integer for size_t, this needs - only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). - Pretty cheap, actually. - - 2. Chose the pivot element using a median-of-three decision tree. - This reduces the probability of selecting a bad pivot value and - eliminates certain extraneous comparisons. - - 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving - insertion sort to order the MAX_THRESH items within each partition. - This is a big win, since insertion sort is faster for small, mostly - sorted array segments. - - 4. The larger of the two sub-partitions is always pushed onto the - stack first, with the algorithm then concentrating on the - smaller partition. This *guarantees* no more than log (total_elems) - stack size is needed (actually O(1) in this case)! */ - -void -_quicksort (void *const pbase, size_t total_elems, size_t size, - __compar_fn_t cmp) -{ - register char *base_ptr = (char *) pbase; - - const size_t max_thresh = MAX_THRESH * size; - - if (total_elems == 0) - /* Avoid lossage with unsigned arithmetic below. */ - return; - - if (total_elems > MAX_THRESH) - { - char *lo = base_ptr; - char *hi = &lo[size * (total_elems - 1)]; - stack_node stack[STACK_SIZE]; - stack_node *top = stack + 1; - - while (STACK_NOT_EMPTY) - { - char *left_ptr; - char *right_ptr; - - /* Select median value from among LO, MID, and HI. Rearrange - LO and HI so the three values are sorted. This lowers the - probability of picking a pathological pivot value and - skips a comparison for both the LEFT_PTR and RIGHT_PTR in - the while loops. */ - - char *mid = lo + size * ((hi - lo) / size >> 1); - - if ((*cmp) ((void *) mid, (void *) lo) < 0) - SWAP (mid, lo, size); - if ((*cmp) ((void *) hi, (void *) mid) < 0) - SWAP (mid, hi, size); - else - goto jump_over; - if ((*cmp) ((void *) mid, (void *) lo) < 0) - SWAP (mid, lo, size); - jump_over:; - - left_ptr = lo + size; - right_ptr = hi - size; - - /* Here's the famous ``collapse the walls'' section of quicksort. - Gotta like those tight inner loops! They are the main reason - that this algorithm runs much faster than others. */ - do - { - while ((*cmp) ((void *) left_ptr, (void *) mid) < 0) - left_ptr += size; - - while ((*cmp) ((void *) mid, (void *) right_ptr) < 0) - right_ptr -= size; - - if (left_ptr < right_ptr) - { - SWAP (left_ptr, right_ptr, size); - if (mid == left_ptr) - mid = right_ptr; - else if (mid == right_ptr) - mid = left_ptr; - left_ptr += size; - right_ptr -= size; - } - else if (left_ptr == right_ptr) - { - left_ptr += size; - right_ptr -= size; - break; - } - } - while (left_ptr <= right_ptr); - - /* Set up pointers for next iteration. First determine whether - left and right partitions are below the threshold size. If so, - ignore one or both. Otherwise, push the larger partition's - bounds on the stack and continue sorting the smaller one. */ - - if ((size_t) (right_ptr - lo) <= max_thresh) - { - if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore both small partitions. */ - POP (lo, hi); - else - /* Ignore small left partition. */ - lo = left_ptr; - } - else if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore small right partition. */ - hi = right_ptr; - else if ((right_ptr - lo) > (hi - left_ptr)) - { - /* Push larger left partition indices. */ - PUSH (lo, right_ptr); - lo = left_ptr; - } - else - { - /* Push larger right partition indices. */ - PUSH (left_ptr, hi); - hi = right_ptr; - } - } - } - - /* Once the BASE_PTR array is partially sorted by quicksort the rest - is completely sorted using insertion sort, since this is efficient - for partitions below MAX_THRESH size. BASE_PTR points to the beginning - of the array to sort, and END_PTR points at the very last element in - the array (*not* one beyond it!). */ - -#define min(x, y) ((x) < (y) ? (x) : (y)) - - { - char *const end_ptr = &base_ptr[size * (total_elems - 1)]; - char *tmp_ptr = base_ptr; - char *thresh = min(end_ptr, base_ptr + max_thresh); - register char *run_ptr; - - /* Find smallest element in first threshold and place it at the - array's beginning. This is the smallest array element, - and the operation speeds up insertion sort's inner loop. */ - - for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) - if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0) - tmp_ptr = run_ptr; - - if (tmp_ptr != base_ptr) - SWAP (tmp_ptr, base_ptr, size); - - /* Insertion sort, running from left-hand-side up to right-hand-side. */ - - run_ptr = base_ptr + size; - while ((run_ptr += size) <= end_ptr) - { - tmp_ptr = run_ptr - size; - while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0) - tmp_ptr -= size; - - tmp_ptr += size; - if (tmp_ptr != run_ptr) - { - char *trav; - - trav = run_ptr + size; - while (--trav >= run_ptr) - { - char c = *trav; - char *hi, *lo; - - for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo) - *hi = *lo; - *hi = c; - } - } - } - } -} diff --git a/src/system/libroot/posix/glibc/stdlib/rand.c b/src/system/libroot/posix/glibc/stdlib/rand.c deleted file mode 100644 index d8458da970..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/rand.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#undef rand - - -/* Return a random integer between 0 and RAND_MAX. */ -int -rand () -{ - return (int) __random (); -} diff --git a/src/system/libroot/posix/glibc/stdlib/rand_r.c b/src/system/libroot/posix/glibc/stdlib/rand_r.c deleted file mode 100644 index 3d49c92de6..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/rand_r.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Reentrant random function frm POSIX.1c. - Copyright (C) 1996, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - - -/* This algorithm is mentioned in the ISO C standard, here extended - for 32 bits. */ -int -rand_r (unsigned int *seed) -{ - unsigned int next = *seed; - int result; - - next *= 1103515245; - next += 12345; - result = (unsigned int) (next / 65536) % 2048; - - next *= 1103515245; - next += 12345; - result <<= 10; - result ^= (unsigned int) (next / 65536) % 1024; - - next *= 1103515245; - next += 12345; - result <<= 10; - result ^= (unsigned int) (next / 65536) % 1024; - - *seed = next; - - return result; -} diff --git a/src/system/libroot/posix/glibc/stdlib/rpmatch.c b/src/system/libroot/posix/glibc/stdlib/rpmatch.c deleted file mode 100644 index f3cc520f8b..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/rpmatch.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Determine whether string value is affirmation or negative response - according to current locale's data. - This file is part of the GNU C Library. - Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - - -int -rpmatch (response) - const char *response; -{ - /* Match against one of the response patterns, compiling the pattern - first if necessary. */ - auto inline int try (const int tag, const int match, const int nomatch, - const char **lastp, regex_t *re); - - inline int try (const int tag, const int match, const int nomatch, - const char **lastp, regex_t *re) - { - const char *pattern = nl_langinfo (tag); - if (pattern != *lastp) - { - /* The pattern has changed. */ - if (*lastp) - { - /* Free the old compiled pattern. */ - __regfree (re); - *lastp = NULL; - } - /* Compile the pattern and cache it for future runs. */ - if (__regcomp (re, pattern, REG_EXTENDED) != 0) - return -1; - *lastp = pattern; - } - - /* Try the pattern. */ - return __regexec (re, response, 0, NULL, 0) == 0 ? match : nomatch; - } - - /* We cache the response patterns and compiled regexps here. */ - static const char *yesexpr, *noexpr; - static regex_t yesre, nore; - - return (try (YESEXPR, 1, 0, &yesexpr, &yesre) ?: - try (NOEXPR, 0, -1, &noexpr, &nore)); -} diff --git a/src/system/libroot/posix/glibc/stdlib/secure-getenv.c b/src/system/libroot/posix/glibc/stdlib/secure-getenv.c deleted file mode 100644 index 75a781b3d0..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/secure-getenv.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1991, 1992, 1994, 1996, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -/* Some programs and especially the libc itself have to be careful - what values to accept from the environment. This special version - checks for SUID or SGID first before doing any work. */ -char * -__secure_getenv (name) - const char *name; -{ - return __libc_enable_secure ? NULL : getenv (name); -} -libc_hidden_def (__secure_getenv) diff --git a/src/system/libroot/posix/glibc/stdlib/strfmon.c b/src/system/libroot/posix/glibc/stdlib/strfmon.c deleted file mode 100644 index e7183ec843..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/strfmon.c +++ /dev/null @@ -1,657 +0,0 @@ -/* Formatting a monetary value according to the current locale. - Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper - and Jochen Hein , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#ifdef USE_IN_LIBIO -# include "../libio/libioP.h" -# include "../libio/strfile.h" -#endif -#include -#include -#include -#include -#include "../locale/localeinfo.h" - - -#define out_char(Ch) \ - do { \ - if (dest >= s + maxsize - 1) \ - { \ - __set_errno (E2BIG); \ - va_end (ap); \ - return -1; \ - } \ - *dest++ = (Ch); \ - } while (0) - -#define out_string(String) \ - do { \ - const char *_s = (String); \ - while (*_s) \ - out_char (*_s++); \ - } while (0) - -#define out_nstring(String, N) \ - do { \ - int _n = (N); \ - const char *_s = (String); \ - while (_n-- > 0) \ - out_char (*_s++); \ - } while (0) - -#define to_digit(Ch) ((Ch) - '0') - - -/* We use this code also for the extended locale handling where the - function gets as an additional argument the locale which has to be - used. To access the values we have to redefine the _NL_CURRENT - macro. */ -#ifdef USE_IN_EXTENDED_LOCALE_MODEL -# undef _NL_CURRENT -# define _NL_CURRENT(category, item) \ - (current->values[_NL_ITEM_INDEX (item)].string) -#endif - -extern int __printf_fp (FILE *, const struct printf_info *, - const void *const *); -libc_hidden_proto (__printf_fp) -/* This function determines the number of digit groups in the output. - The definition is in printf_fp.c. */ -extern unsigned int __guess_grouping (unsigned int intdig_max, - const char *grouping, wchar_t sepchar); - - -/* We have to overcome some problems with this implementation. On the - one hand the strfmon() function is specified in XPG4 and of course - it has to follow this. But on the other hand POSIX.2 specifies - some information in the LC_MONETARY category which should be used, - too. Some of the information contradicts the information which can - be specified in format string. */ -#ifndef USE_IN_EXTENDED_LOCALE_MODEL -ssize_t -strfmon (char *s, size_t maxsize, const char *format, ...) -#else -ssize_t -__strfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format, ...) -#endif -{ -#ifdef USE_IN_EXTENDED_LOCALE_MODEL - struct locale_data *current = loc->__locales[LC_MONETARY]; -#endif -#ifdef USE_IN_LIBIO - _IO_strfile f; -# ifdef _IO_MTSAFE_IO - _IO_lock_t lock; -# endif -#else - FILE f; -#endif - struct printf_info info; - va_list ap; /* Scan through the varargs. */ - char *dest; /* Pointer so copy the output. */ - const char *fmt; /* Pointer that walks through format. */ - - va_start (ap, format); - - dest = s; - fmt = format; - - /* Loop through the format-string. */ - while (*fmt != '\0') - { - /* The floating-point value to output. */ - union - { - double dbl; - __long_double_t ldbl; - } - fpnum; - int print_curr_symbol; - int left_prec; - int left_pad; - int right_prec; - int group; - char pad; - int is_long_double; - int p_sign_posn; - int n_sign_posn; - int sign_posn; - int other_sign_posn; - int left; - int is_negative; - int sep_by_space; - int other_sep_by_space; - int cs_precedes; - int other_cs_precedes; - const char *sign_string; - const char *other_sign_string; - int done; - const char *currency_symbol; - size_t currency_symbol_len; - int width; - char *startp; - const void *ptr; - char space_char; - - /* Process all character which do not introduce a format - specification. */ - if (*fmt != '%') - { - out_char (*fmt++); - continue; - } - - /* "%%" means a single '%' character. */ - if (fmt[1] == '%') - { - out_char (*++fmt); - ++fmt; - continue; - } - - /* Defaults for formatting. */ - print_curr_symbol = 1; /* Print the currency symbol. */ - left_prec = -1; /* No left precision specified. */ - right_prec = -1; /* No right precision specified. */ - group = 1; /* Print digits grouped. */ - pad = ' '; /* Fill character is . */ - is_long_double = 0; /* Double argument by default. */ - p_sign_posn = -1; /* This indicates whether the */ - n_sign_posn = -1; /* '(' flag is given. */ - width = -1; /* No width specified so far. */ - left = 0; /* Right justified by default. */ - - /* Parse group characters. */ - while (1) - { - switch (*++fmt) - { - case '=': /* Set fill character. */ - pad = *++fmt; - if (pad == '\0') - { - /* Premature EOS. */ - __set_errno (EINVAL); - va_end (ap); - return -1; - } - continue; - case '^': /* Don't group digits. */ - group = 0; - continue; - case '+': /* Use +/- for sign of number. */ - if (n_sign_posn != -1) - { - __set_errno (EINVAL); - va_end (ap); - return -1; - } - p_sign_posn = *_NL_CURRENT (LC_MONETARY, P_SIGN_POSN); - n_sign_posn = *_NL_CURRENT (LC_MONETARY, N_SIGN_POSN); - continue; - case '(': /* Use ( ) for negative sign. */ - if (n_sign_posn != -1) - { - __set_errno (EINVAL); - va_end (ap); - return -1; - } - p_sign_posn = 0; - n_sign_posn = 0; - continue; - case '!': /* Don't print the currency symbol. */ - print_curr_symbol = 0; - continue; - case '-': /* Print left justified. */ - left = 1; - continue; - default: - /* Will stop the loop. */; - } - break; - } - - /* If not specified by the format string now find the values for - the format specification. */ - if (p_sign_posn == -1) - p_sign_posn = *_NL_CURRENT (LC_MONETARY, P_SIGN_POSN); - if (n_sign_posn == -1) - n_sign_posn = *_NL_CURRENT (LC_MONETARY, N_SIGN_POSN); - - if (isdigit (*fmt)) - { - /* Parse field width. */ - width = to_digit (*fmt); - - while (isdigit (*++fmt)) - { - width *= 10; - width += to_digit (*fmt); - } - - /* If we don't have enough room for the demanded width we - can stop now and return an error. */ - if (dest + width >= s + maxsize) - { - __set_errno (E2BIG); - va_end (ap); - return -1; - } - } - - /* Recognize left precision. */ - if (*fmt == '#') - { - if (!isdigit (*++fmt)) - { - __set_errno (EINVAL); - va_end (ap); - return -1; - } - left_prec = to_digit (*fmt); - - while (isdigit (*++fmt)) - { - left_prec *= 10; - left_prec += to_digit (*fmt); - } - } - - /* Recognize right precision. */ - if (*fmt == '.') - { - if (!isdigit (*++fmt)) - { - __set_errno (EINVAL); - va_end (ap); - return -1; - } - right_prec = to_digit (*fmt); - - while (isdigit (*++fmt)) - { - right_prec *= 10; - right_prec += to_digit (*fmt); - } - } - - /* Handle modifier. This is an extension. */ - if (*fmt == 'L') - { - ++fmt; - is_long_double = 1; - } - - /* Handle format specifier. */ - switch (*fmt++) - { - case 'i': /* Use international currency symbol. */ - currency_symbol = _NL_CURRENT (LC_MONETARY, INT_CURR_SYMBOL); - currency_symbol_len = 3; - space_char = currency_symbol[3]; - if (right_prec == -1) - { - if (*_NL_CURRENT (LC_MONETARY, INT_FRAC_DIGITS) == CHAR_MAX) - right_prec = 2; - else - right_prec = *_NL_CURRENT (LC_MONETARY, INT_FRAC_DIGITS); - } - break; - case 'n': /* Use national currency symbol. */ - currency_symbol = _NL_CURRENT (LC_MONETARY, CURRENCY_SYMBOL); - currency_symbol_len = strlen (currency_symbol); - space_char = ' '; - if (right_prec == -1) - { - if (*_NL_CURRENT (LC_MONETARY, FRAC_DIGITS) == CHAR_MAX) - right_prec = 2; - else - right_prec = *_NL_CURRENT (LC_MONETARY, FRAC_DIGITS); - } - break; - default: /* Any unrecognized format is an error. */ - __set_errno (EINVAL); - va_end (ap); - return -1; - } - - /* If we have to print the digits grouped determine how many - extra characters this means. */ - if (group && left_prec != -1) - left_prec += __guess_grouping (left_prec, - _NL_CURRENT (LC_MONETARY, MON_GROUPING), - *_NL_CURRENT (LC_MONETARY, - MON_THOUSANDS_SEP)); - - /* Now it's time to get the value. */ - if (is_long_double == 1) - { - fpnum.ldbl = va_arg (ap, long double); - is_negative = fpnum.ldbl < 0; - if (is_negative) - fpnum.ldbl = -fpnum.ldbl; - } - else - { - fpnum.dbl = va_arg (ap, double); - is_negative = fpnum.dbl < 0; - if (is_negative) - fpnum.dbl = -fpnum.dbl; - } - - /* We now know the sign of the value and can determine the format. */ - if (is_negative) - { - sign_string = _NL_CURRENT (LC_MONETARY, NEGATIVE_SIGN); - /* If the locale does not specify a character for the - negative sign we use a '-'. */ - if (*sign_string == '\0') - sign_string = (const char *) "-"; - cs_precedes = *_NL_CURRENT (LC_MONETARY, N_CS_PRECEDES); - sep_by_space = *_NL_CURRENT (LC_MONETARY, N_SEP_BY_SPACE); - sign_posn = n_sign_posn; - - other_sign_string = _NL_CURRENT (LC_MONETARY, POSITIVE_SIGN); - other_cs_precedes = *_NL_CURRENT (LC_MONETARY, P_CS_PRECEDES); - other_sep_by_space = *_NL_CURRENT (LC_MONETARY, P_SEP_BY_SPACE); - other_sign_posn = p_sign_posn; - } - else - { - sign_string = _NL_CURRENT (LC_MONETARY, POSITIVE_SIGN); - cs_precedes = *_NL_CURRENT (LC_MONETARY, P_CS_PRECEDES); - sep_by_space = *_NL_CURRENT (LC_MONETARY, P_SEP_BY_SPACE); - sign_posn = p_sign_posn; - - other_sign_string = _NL_CURRENT (LC_MONETARY, NEGATIVE_SIGN); - if (*other_sign_string == '\0') - other_sign_string = (const char *) "-"; - other_cs_precedes = *_NL_CURRENT (LC_MONETARY, N_CS_PRECEDES); - other_sep_by_space = *_NL_CURRENT (LC_MONETARY, N_SEP_BY_SPACE); - other_sign_posn = n_sign_posn; - } - - /* Set default values for unspecified information. */ - if (cs_precedes != 0) - cs_precedes = 1; - if (other_cs_precedes != 0) - other_cs_precedes = 1; - if (sep_by_space == CHAR_MAX) - sep_by_space = 0; - if (other_sep_by_space == CHAR_MAX) - other_sep_by_space = 0; - if (sign_posn == CHAR_MAX) - sign_posn = 1; - if (other_sign_posn == CHAR_MAX) - other_sign_posn = 1; - - /* Check for degenerate cases */ - if (sep_by_space == 2) - { - if (sign_posn == 0 || - (sign_posn == 1 && !cs_precedes) || - (sign_posn == 2 && cs_precedes)) - /* sign and symbol are not adjacent, so no separator */ - sep_by_space = 0; - } - if (other_sep_by_space == 2) - { - if (other_sign_posn == 0 || - (other_sign_posn == 1 && !other_cs_precedes) || - (other_sign_posn == 2 && other_cs_precedes)) - /* sign and symbol are not adjacent, so no separator */ - other_sep_by_space = 0; - } - - /* Set the left precision and padding needed for alignment */ - if (left_prec == -1) - { - left_prec = 0; - left_pad = 0; - } - else - { - /* Set left_pad to number of spaces needed to align positive - and negative formats */ - - int left_bytes = 0; - int other_left_bytes = 0; - - /* Work out number of bytes for currency string and separator - preceding the value */ - if (cs_precedes) - { - left_bytes += currency_symbol_len; - if (sep_by_space != 0) - ++left_bytes; - } - - if (other_cs_precedes) - { - other_left_bytes += currency_symbol_len; - if (other_sep_by_space != 0) - ++other_left_bytes; - } - - /* Work out number of bytes for the sign (or left parenthesis) - preceding the value */ - if (sign_posn == 0 && is_negative) - ++left_bytes; - else if (sign_posn == 1) - left_bytes += strlen (sign_string); - else if (cs_precedes && (sign_posn == 3 || sign_posn == 4)) - left_bytes += strlen (sign_string); - - if (other_sign_posn == 0 && !is_negative) - ++other_left_bytes; - else if (other_sign_posn == 1) - other_left_bytes += strlen (other_sign_string); - else if (other_cs_precedes && - (other_sign_posn == 3 || other_sign_posn == 4)) - other_left_bytes += strlen (other_sign_string); - - /* Compare the number of bytes preceding the value for - each format, and set the padding accordingly */ - if (other_left_bytes > left_bytes) - left_pad = other_left_bytes - left_bytes; - else - left_pad = 0; - } - - /* Perhaps we'll someday make these things configurable so - better start using symbolic names now. */ -#define left_paren '(' -#define right_paren ')' - - startp = dest; /* Remember start so we can compute length. */ - - while (left_pad-- > 0) - out_char (' '); - - if (sign_posn == 0 && is_negative) - out_char (left_paren); - - if (cs_precedes) - { - if (sign_posn != 0 && sign_posn != 2 && sign_posn != 4 - && sign_posn != 5) - { - out_string (sign_string); - if (sep_by_space == 2) - out_char (' '); - } - - if (print_curr_symbol) - { - out_string (currency_symbol); - - if (sign_posn == 4) - { - if (sep_by_space == 2) - out_char (space_char); - out_string (sign_string); - if (sep_by_space == 1) - /* POSIX.2 and SUS are not clear on this case, but C99 - says a space follows the adjacent-symbol-and-sign */ - out_char (' '); - } - else - if (sep_by_space == 1) - out_char (space_char); - } - } - else - if (sign_posn != 0 && sign_posn != 2 && sign_posn != 3 - && sign_posn != 4 && sign_posn != 5) - out_string (sign_string); - - /* Print the number. */ -#ifdef USE_IN_LIBIO -# ifdef _IO_MTSAFE_IO - f._sbf._f._lock = &lock; -# endif - INTUSE(_IO_init) ((_IO_FILE *) &f, 0); - _IO_JUMPS ((struct _IO_FILE_plus *) &f) = &_IO_str_jumps; - INTUSE(_IO_str_init_static) ((_IO_strfile *) &f, dest, - (s + maxsize) - dest, dest); -#else - memset ((void *) &f, 0, sizeof (f)); - f.__magic = _IOMAGIC; - f.__mode.__write = 1; - /* The buffer size is one less than MAXLEN - so we have space for the null terminator. */ - f.__bufp = f.__buffer = (char *) dest; - f.__bufsize = (s + maxsize) - dest; - f.__put_limit = f.__buffer + f.__bufsize; - f.__get_limit = f.__buffer; - /* After the buffer is full (MAXLEN characters have been written), - any more characters written will go to the bit bucket. */ - f.__room_funcs = __default_room_functions; - f.__io_funcs.__write = NULL; - f.__seen = 1; -#endif - /* We clear the last available byte so we can find out whether - the numeric representation is too long. */ - s[maxsize - 1] = '\0'; - - info.prec = right_prec; - info.width = left_prec + (right_prec ? (right_prec + 1) : 0); - info.spec = 'f'; - info.is_long_double = is_long_double; - info.is_short = 0; - info.is_long = 0; - info.alt = 0; - info.space = 0; - info.left = left; - info.showsign = 0; - info.group = group; - info.pad = pad; - info.extra = 1; /* This means use values from LC_MONETARY. */ - info.wide = 0; - - ptr = &fpnum; - done = __printf_fp ((FILE *) &f, &info, &ptr); - if (done < 0) - { - va_end (ap); - return -1; - } - - if (s[maxsize - 1] != '\0') - { - __set_errno (E2BIG); - return -1; - } - - dest += done; - - if (!cs_precedes) - { - if (sign_posn == 3) - { - if (sep_by_space == 1) - out_char (' '); - out_string (sign_string); - } - - if (print_curr_symbol) - { - if ((sign_posn == 3 && sep_by_space == 2) - || (sign_posn == 4 && sep_by_space == 1) - || (sign_posn == 2 && sep_by_space == 1) - || (sign_posn == 1 && sep_by_space == 1) - || (sign_posn == 0 && sep_by_space == 1)) - out_char (space_char); - out_nstring (currency_symbol, currency_symbol_len); - if (sign_posn == 4) - { - if (sep_by_space == 2) - out_char (' '); - out_string (sign_string); - } - } - } - - if (sign_posn == 2) - { - if (sep_by_space == 2) - out_char (' '); - out_string (sign_string); - } - - if (sign_posn == 0 && is_negative) - out_char (right_paren); - - /* Now test whether the output width is filled. */ - if (dest - startp < width) - { - if (left) - /* We simply have to fill using spaces. */ - do - out_char (' '); - while (dest - startp < width); - else - { - int dist = width - (dest - startp); - char *cp; - for (cp = dest - 1; cp >= startp; --cp) - cp[dist] = cp[0]; - - dest += dist; - - do - startp[--dist] = ' '; - while (dist > 0); - } - } - } - - /* Terminate the string. */ - *dest = '\0'; - - va_end (ap); - - return dest - s; -} diff --git a/src/system/libroot/posix/glibc/stdlib/strfmon_l.c b/src/system/libroot/posix/glibc/stdlib/strfmon_l.c deleted file mode 100644 index b0c82a337e..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/strfmon_l.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Formatting a monetary value according to the given locale. - Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 -#include - -weak_alias (__strfmon_l, strfmon_l) diff --git a/src/system/libroot/posix/glibc/stdlib/strtod_l.c b/src/system/libroot/posix/glibc/stdlib/strtod_l.c deleted file mode 100644 index e8449050d3..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/strtod_l.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Convert string representing a number to float value, using given locale. - Copyright (C) 1997,98,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 - -#include - -extern double ____strtod_l_internal (const char *, char **, int, __locale_t); -extern unsigned long long int ____strtoull_l_internal (const char *, char **, - int, int, __locale_t); - -#include - -weak_alias (__strtod_l, strtod_l) diff --git a/src/system/libroot/posix/glibc/stdlib/strtof_l.c b/src/system/libroot/posix/glibc/stdlib/strtof_l.c deleted file mode 100644 index 1187ffc73b..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/strtof_l.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Convert string representing a number to float value, using given locale. - Copyright (C) 1997,98,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 - -#include - -extern float ____strtof_l_internal (const char *, char **, int, __locale_t); -extern unsigned long long int ____strtoull_l_internal (const char *, char **, - int, int, __locale_t); - -#include - -weak_alias (__strtof_l, strtof_l) diff --git a/src/system/libroot/posix/glibc/stdlib/strtold_l.c b/src/system/libroot/posix/glibc/stdlib/strtold_l.c deleted file mode 100644 index c3a4e79390..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/strtold_l.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Convert string representing a number to float value, using given locale. - Copyright (C) 1997,98,99,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -#ifndef __NO_LONG_DOUBLE_MATH - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 - -extern long double ____strtold_l_internal (const char *, char **, int, - __locale_t); -extern unsigned long long int ____strtoull_l_internal (const char *, char **, - int, int, __locale_t); - -# include - -#else -/* There is no `long double' type, use the `double' implementations. */ -extern double ____strtod_l_internal (const char *, char **, int, - __locale_t); -long double -____strtold_l_internal (const char *nptr, char **endptr, int group, - __locale_t loc) -{ - return ____strtod_l_internal (nptr, endptr, group, loc); -} - -long double -__strtold_l (const char *nptr, char **endptr, __locale_t loc) -{ - return ____strtod_l_internal (nptr, endptr, 0, loc); -} -#endif - -weak_alias (__strtold_l, strtold_l) diff --git a/src/system/libroot/posix/glibc/stdlib/xpg_basename.c b/src/system/libroot/posix/glibc/stdlib/xpg_basename.c deleted file mode 100644 index cc1a1ab8e5..0000000000 --- a/src/system/libroot/posix/glibc/stdlib/xpg_basename.c +++ /dev/null @@ -1,72 +0,0 @@ -/* Return basename of given pathname according to the weird XPG specification. - Copyright (C) 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - - -char * -__xpg_basename (char *filename) -{ - char *p; - - if (filename == NULL || filename[0] == '\0') - /* We return a pointer to a static string containing ".". */ - p = (char *) "."; - else - { - p = strrchr (filename, '/'); - - if (p == NULL) - /* There is no slash in the filename. Return the whole string. */ - p = filename; - else - { - if (p[1] == '\0') - { - /* We must remove trailing '/'. */ - while (p > filename && p[-1] == '/') - --p; - - /* Now we can be in two situations: - a) the string only contains '/' characters, so we return - '/' - b) p points past the last component, but we have to remove - the trailing slash. */ - if (p > filename) - { - *p-- = '\0'; - while (p > filename && p[-1] != '/') - --p; - } - else - /* The last slash we already found is the right position - to return. */ - while (p[1] != '\0') - ++p; - } - else - /* Go to the first character of the name. */ - ++p; - } - } - - return p; -} diff --git a/src/system/libroot/posix/glibc/string/Depend b/src/system/libroot/posix/glibc/string/Depend deleted file mode 100644 index f3e1156a4e..0000000000 --- a/src/system/libroot/posix/glibc/string/Depend +++ /dev/null @@ -1 +0,0 @@ -localedata diff --git a/src/system/libroot/posix/glibc/string/Makefile b/src/system/libroot/posix/glibc/string/Makefile deleted file mode 100644 index 7e2220ec3d..0000000000 --- a/src/system/libroot/posix/glibc/string/Makefile +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright (C) 1991-1999,2000,2001,2002 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library 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 -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Sub-makefile for string portion of library. -# -subdir := string - -headers := string.h strings.h memory.h endian.h bits/endian.h \ - argz.h envz.h byteswap.h bits/byteswap.h bits/string.h \ - bits/string2.h - -routines := strcat strchr strcmp strcoll strcpy strcspn \ - strverscmp strdup strndup \ - strerror _strerror strlen strnlen \ - strncat strncmp strncpy \ - strrchr strpbrk strsignal strspn strstr strtok \ - strtok_r strxfrm memchr memcmp memmove memset \ - mempcpy bcopy bzero ffs ffsll stpcpy stpncpy \ - strcasecmp strncase strcasecmp_l strncase_l \ - memccpy memcpy wordcopy strsep strcasestr \ - swab strfry memfrob memmem rawmemchr strchrnul \ - $(addprefix argz-,append count create ctsep next \ - delete extract insert stringify \ - addsep replace) \ - envz basename \ - strcoll_l strxfrm_l string-inlines memrchr - -# Gcc internally generates calls to unbounded memcpy and memset -# for -fbounded-pointer compiles. Glibc uses memchr for explicit checks. -o-objects.ob := memcpy.o memset.o memchr.o - -strop-tests := memchr memcmp memcpy memmove mempcpy memset stpcpy \ - stpncpy strcat strchr strcmp strcpy strcspn strlen \ - strncmp strncpy strpbrk strrchr strspn -tests := tester inl-tester noinl-tester testcopy test-ffs \ - tst-strlen stratcliff tst-svc tst-inlcall \ - bug-strncat1 bug-strspn1 bug-strpbrk1 tst-bswap \ - tst-strtok tst-strxfrm bug-strcoll1 \ - $(addprefix test-,$(strop-tests)) -distribute := memcopy.h pagecopy.h tst-svc.expect test-string.h - - -include ../Rules - -tester-ENV = LANGUAGE=C -inl-tester-ENV = LANGUAGE=C -noinl-tester-ENV = LANGUAGE=C -tst-strxfrm-ENV = LOCPATH=$(common-objpfx)localedata -bug-strcoll1-ENV = LOCPATH=$(common-objpfx)localedata -CFLAGS-noinl-tester.c = -fno-builtin -CFLAGS-tst-strlen.c = -fno-builtin -CFLAGS-stratcliff.c = -fno-builtin -CFLAGS-test-ffs.c = -fno-builtin - -ifeq ($(cross-compiling),no) -tests: $(objpfx)tst-svc.out -$(objpfx)tst-svc.out: tst-svc.input $(objpfx)tst-svc - GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \ - $(built-program-cmd) < $(word 1,$^) > $@ - -cmp tst-svc.expect $(objpfx)tst-svc.out -endif diff --git a/src/system/libroot/posix/glibc/string/Versions b/src/system/libroot/posix/glibc/string/Versions deleted file mode 100644 index 2708091a4d..0000000000 --- a/src/system/libroot/posix/glibc/string/Versions +++ /dev/null @@ -1,76 +0,0 @@ -libc { - GLIBC_2.0 { - # functions with required interface outside normal name space - __argz_count; __argz_stringify; __argz_next; - - # functions used in inline functions or macros - __bzero; __strtok_r; - - # functions used in other libraries - __stpncpy; __stpcpy; __strdup; __mempcpy; __strcasecmp; __strerror_r; - __ffs; - - # a* - argz_add; argz_add_sep; argz_append; argz_count; argz_create; - argz_create_sep; argz_delete; argz_extract; argz_insert; argz_next; - argz_replace; argz_stringify; - - # b* - basename; bcmp; bcopy; bzero; - - # e* - envz_add; envz_entry; envz_get; envz_merge; envz_remove; - envz_strip; - - # f* - ffs; - - # i* - index; - - # m* - memccpy; memchr; memcmp; memcpy; memfrob; memmem; memmove; memset; - - # r* - rindex; - - # s* - stpcpy; stpncpy; strcasecmp; strcat; strchr; strcmp; strcoll; strcpy; - strcspn; strdup; strerror; strerror_r; strfry; strlen; strncasecmp; - strncat; strncmp; strncpy; strndup; strnlen; strpbrk; strrchr; strsep; - strsignal; strspn; strstr; strtok; strtok_r; strxfrm; swab; - } - GLIBC_2.1 { - # functions used in macros and other libraries - __rawmemchr; __strcasestr; - - # f* - ffsl; ffsll; - - # m* - mempcpy; - - # r* - rawmemchr; - - # s* - strcasestr; strverscmp; - } - GLIBC_2.1.1 { - # extern inline functions used by - __mempcpy_small; __stpcpy_small; __strcspn_c1; __strcspn_c2; __strcspn_c3; - __strcpy_small; __strspn_c1; __strspn_c2; __strspn_c3; __strpbrk_c2; - __strpbrk_c3; __strsep_1c; __strsep_2c; __strsep_3c; __strsep_g; - __strtok_r_1c; - - # s* - strchrnul; __strverscmp; - } - GLIBC_2.2 { - # functions used in macros. - __strndup; - - # m* - memrchr; - } -} diff --git a/src/system/libroot/posix/glibc/string/argz-addsep.c b/src/system/libroot/posix/glibc/string/argz-addsep.c deleted file mode 100644 index 0584b1f691..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-addsep.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - - -error_t -__argz_add_sep (char **argz, size_t *argz_len, const char *string, int delim) -{ - size_t nlen = strlen (string) + 1; - - if (nlen > 1) - { - const char *rp; - char *wp; - - *argz = (char *) realloc (*argz, *argz_len + nlen); - if (*argz == NULL) - return ENOMEM; - - wp = *argz + *argz_len; - rp = string; - do - if (*rp == delim) - { - if (wp > *argz && wp[-1] != '\0') - *wp++ = '\0'; - else - --nlen; - } - else - *wp++ = *rp; - while (*rp++ != '\0'); - - *argz_len += nlen; - } - - return 0; -} -weak_alias (__argz_add_sep, argz_add_sep) diff --git a/src/system/libroot/posix/glibc/string/argz-append.c b/src/system/libroot/posix/glibc/string/argz-append.c deleted file mode 100644 index 9437fde701..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-append.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ -error_t -__argz_append (char **argz, size_t *argz_len, const char *buf, size_t buf_len) -{ - size_t new_argz_len = *argz_len + buf_len; - char *new_argz = realloc (*argz, new_argz_len); - if (new_argz) - { - memcpy (new_argz + *argz_len, buf, buf_len); - *argz = new_argz; - *argz_len = new_argz_len; - return 0; - } - else - return ENOMEM; -} -weak_alias (__argz_append, argz_append) - -/* Add STR to the argz vector in ARGZ & ARGZ_LEN. This should be moved into - argz.c in libshouldbelibc. */ -error_t -__argz_add (char **argz, size_t *argz_len, const char *str) -{ - return __argz_append (argz, argz_len, str, strlen (str) + 1); -} -weak_alias (__argz_add, argz_add) diff --git a/src/system/libroot/posix/glibc/string/argz-count.c b/src/system/libroot/posix/glibc/string/argz-count.c deleted file mode 100644 index 39282e84a2..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-count.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -/* Returns the number of strings in ARGZ. */ -size_t -__argz_count (const char *argz, size_t len) -{ - size_t count = 0; - while (len > 0) - { - size_t part_len = strlen(argz); - argz += part_len + 1; - len -= part_len + 1; - count++; - } - return count; -} -INTDEF(__argz_count) -weak_alias (__argz_count, argz_count) diff --git a/src/system/libroot/posix/glibc/string/argz-create.c b/src/system/libroot/posix/glibc/string/argz-create.c deleted file mode 100644 index 7bfe14cb81..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-create.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Make a '\0' separated arg vector from a unix argv vector, returning it in - ARGZ, and the total length in LEN. If a memory allocation error occurs, - ENOMEM is returned, otherwise 0. */ -error_t -__argz_create (char *const argv[], char **argz, size_t *len) -{ - int argc; - size_t tlen = 0; - char *const *ap; - char *p; - - for (argc = 0; argv[argc] != NULL; ++argc) - tlen += strlen (argv[argc]) + 1; - - if (tlen == 0) - *argz = NULL; - else - { - *argz = malloc (tlen); - if (*argz == NULL) - return ENOMEM; - - for (p = *argz, ap = argv; *ap; ++ap, ++p) - p = __stpcpy (p, *ap); - } - *len = tlen; - - return 0; -} -weak_alias (__argz_create, argz_create) diff --git a/src/system/libroot/posix/glibc/string/argz-ctsep.c b/src/system/libroot/posix/glibc/string/argz-ctsep.c deleted file mode 100644 index 0f2b2f5e80..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-ctsep.c +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - - -error_t -__argz_create_sep (const char *string, int delim, char **argz, size_t *len) -{ - size_t nlen = strlen (string) + 1; - - if (nlen > 1) - { - const char *rp; - char *wp; - - *argz = (char *) malloc (nlen); - if (*argz == NULL) - return ENOMEM; - - rp = string; - wp = *argz; - do - if (*rp == delim) - { - if (wp > *argz && wp[-1] != '\0') - *wp++ = '\0'; - else - --nlen; - } - else - *wp++ = *rp; - while (*rp++ != '\0'); - - if (nlen == 0) - { - free (*argz); - *argz = NULL; - *len = 0; - } - - *len = nlen; - } - else - { - *argz = NULL; - *len = 0; - } - - return 0; -} -weak_alias (__argz_create_sep, argz_create_sep) diff --git a/src/system/libroot/posix/glibc/string/argz-delete.c b/src/system/libroot/posix/glibc/string/argz-delete.c deleted file mode 100644 index 508b837a8a..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-delete.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Delete ENTRY from ARGZ & ARGZ_LEN, if any. */ -void -argz_delete (char **argz, size_t *argz_len, char *entry) -{ - if (entry) - /* Get rid of the old value for NAME. */ - { - size_t entry_len = strlen (entry) + 1; - *argz_len -= entry_len; - memmove (entry, entry + entry_len, *argz_len - (entry - *argz)); - if (*argz_len == 0) - { - free (*argz); - *argz = 0; - } - } -} -libc_hidden_def (argz_delete) diff --git a/src/system/libroot/posix/glibc/string/argz-extract.c b/src/system/libroot/posix/glibc/string/argz-extract.c deleted file mode 100644 index 0a11ed81ba..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-extract.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into - ARGV, which must be large enough to hold them all. */ -void -__argz_extract (const char *argz, size_t len, char **argv) -{ - while (len > 0) - { - size_t part_len = strlen (argz); - *argv++ = (char *) argz; - argz += part_len + 1; - len -= part_len + 1; - } - *argv = 0; -} -weak_alias (__argz_extract, argz_extract) diff --git a/src/system/libroot/posix/glibc/string/argz-insert.c b/src/system/libroot/posix/glibc/string/argz-insert.c deleted file mode 100644 index 8ab9a8b4f3..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-insert.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an - existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. - Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN, - ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not - in ARGZ, EINVAL is returned, else if memory can't be allocated for the new - ARGZ, ENOMEM is returned, else 0. */ -error_t -__argz_insert (char **argz, size_t *argz_len, char *before, const char *entry) -{ - if (! before) - return __argz_add (argz, argz_len, entry); - - if (before < *argz || before >= *argz + *argz_len) - return EINVAL; - - if (before > *argz) - /* Make sure before is actually the beginning of an entry. */ - while (before[-1]) - before--; - - { - size_t after_before = *argz_len - (before - *argz); - size_t entry_len = strlen (entry) + 1; - size_t new_argz_len = *argz_len + entry_len; - char *new_argz = realloc (*argz, new_argz_len); - - if (new_argz) - { - before = new_argz + (before - *argz); - memmove (before + entry_len, before, after_before); - memmove (before, entry, entry_len); - *argz = new_argz; - *argz_len = new_argz_len; - return 0; - } - else - return ENOMEM; - } -} -weak_alias (__argz_insert, argz_insert) diff --git a/src/system/libroot/posix/glibc/string/argz-next.c b/src/system/libroot/posix/glibc/string/argz-next.c deleted file mode 100644 index 9854d22002..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-next.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Iterate through the elements of an argz block. - Copyright (C) 1995, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -char * -__argz_next (const char *argz, size_t argz_len, const char *entry) -{ - if (entry) - { - if (entry < argz + argz_len) - entry = strchr (entry, '\0') + 1; - - return entry >= argz + argz_len ? NULL : (char *) entry; - } - else - if (argz_len > 0) - return (char *) argz; - else - return NULL; -} -weak_alias (__argz_next, argz_next) diff --git a/src/system/libroot/posix/glibc/string/argz-replace.c b/src/system/libroot/posix/glibc/string/argz-replace.c deleted file mode 100644 index 3c4062488e..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-replace.c +++ /dev/null @@ -1,136 +0,0 @@ -/* String replacement in an argz vector - Copyright (C) 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Append BUF, of length BUF_LEN to *TO, of length *TO_LEN, reallocating and - updating *TO & *TO_LEN appropriately. If an allocation error occurs, - *TO's old value is freed, and *TO is set to 0. */ -static void -str_append (char **to, size_t *to_len, const char *buf, const size_t buf_len) -{ - size_t new_len = *to_len + buf_len; - char *new_to = realloc (*to, new_len + 1); - - if (new_to) - { - *((char *) __mempcpy (new_to + *to_len, buf, buf_len)) = '\0'; - *to = new_to; - *to_len = new_len; - } - else - { - free (*to); - *to = 0; - } -} - -/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating - ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be - incremented by number of replacements performed. */ -error_t -__argz_replace (char **argz, size_t *argz_len, const char *str, const char *with, - unsigned *replace_count) -{ - error_t err = 0; - - if (str && *str) - { - char *arg = 0; - char *src = *argz; - size_t src_len = *argz_len; - char *dst = 0; - size_t dst_len = 0; - int delayed_copy = 1; /* True while we've avoided copying anything. */ - size_t str_len = strlen (str), with_len = strlen (with); - - while (!err && (arg = argz_next (src, src_len, arg))) - { - char *match = strstr (arg, str); - if (match) - { - char *from = match + str_len; - size_t to_len = match - arg; - char *to = __strndup (arg, to_len); - - while (to && from) - { - str_append (&to, &to_len, with, with_len); - if (to) - { - match = strstr (from, str); - if (match) - { - str_append (&to, &to_len, from, match - from); - from = match + str_len; - } - else - { - str_append (&to, &to_len, from, strlen (from)); - from = 0; - } - } - } - - if (to) - { - if (delayed_copy) - /* We avoided copying SRC to DST until we found a match; - now that we've done so, copy everything from the start - of SRC. */ - { - if (arg > src) - err = __argz_append (&dst, &dst_len, src, (arg - src)); - delayed_copy = 0; - } - if (! err) - err = __argz_add (&dst, &dst_len, to); - free (to); - } - else - err = ENOMEM; - - if (replace_count) - (*replace_count)++; - } - else if (! delayed_copy) - err = __argz_add (&dst, &dst_len, arg); - } - - if (! err) - { - if (! delayed_copy) - /* We never found any instances of str. */ - { - if (src) - free (src); - *argz = dst; - *argz_len = dst_len; - } - } - else if (dst_len > 0) - free (dst); - } - - return err; -} -weak_alias (__argz_replace, argz_replace) diff --git a/src/system/libroot/posix/glibc/string/argz-stringify.c b/src/system/libroot/posix/glibc/string/argz-stringify.c deleted file mode 100644 index 46af8899c8..0000000000 --- a/src/system/libroot/posix/glibc/string/argz-stringify.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995,96,97,2000,2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's - except the last into the character SEP. */ -void -__argz_stringify (char *argz, size_t len, int sep) -{ - if (len > 0) - while (1) - { - size_t part_len = __strnlen (argz, len); - argz += part_len; - len -= part_len; - if (len-- <= 1) /* includes final '\0' we want to stop at */ - break; - *argz++ = sep; - } -} -INTDEF(__argz_stringify) -weak_alias (__argz_stringify, argz_stringify) diff --git a/src/system/libroot/posix/glibc/string/argz.h b/src/system/libroot/posix/glibc/string/argz.h deleted file mode 100644 index b083d8e1a9..0000000000 --- a/src/system/libroot/posix/glibc/string/argz.h +++ /dev/null @@ -1,187 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _ARGZ_H -#define _ARGZ_H 1 - -#include - -#define __need_error_t -#include -#include /* Need size_t, and strchr is called below. */ - -#ifndef __const -# define __const const -#endif - -#ifndef __error_t_defined -typedef int error_t; -#endif - - -__BEGIN_DECLS - -/* Make a '\0' separated arg vector from a unix argv vector, returning it in - ARGZ, and the total length in LEN. If a memory allocation error occurs, - ENOMEM is returned, otherwise 0. The result can be destroyed using free. */ -extern error_t __argz_create (char *__const __argv[], char **__restrict __argz, - size_t *__restrict __len) __THROW; -extern error_t argz_create (char *__const __argv[], char **__restrict __argz, - size_t *__restrict __len) __THROW; - -/* Make a '\0' separated arg vector from a SEP separated list in - STRING, returning it in ARGZ, and the total length in LEN. If a - memory allocation error occurs, ENOMEM is returned, otherwise 0. - The result can be destroyed using free. */ -extern error_t __argz_create_sep (__const char *__restrict __string, - int __sep, char **__restrict __argz, - size_t *__restrict __len) __THROW; -extern error_t argz_create_sep (__const char *__restrict __string, - int __sep, char **__restrict __argz, - size_t *__restrict __len) __THROW; - -/* Returns the number of strings in ARGZ. */ -extern size_t __argz_count (__const char *__argz, size_t __len) - __THROW __attribute_pure__; -extern size_t argz_count (__const char *__argz, size_t __len) - __THROW __attribute_pure__; - -/* Puts pointers to each string in ARGZ into ARGV, which must be large enough - to hold them all. */ -extern void __argz_extract (__const char *__restrict __argz, size_t __len, - char **__restrict __argv) __THROW; -extern void argz_extract (__const char *__restrict __argz, size_t __len, - char **__restrict __argv) __THROW; - -/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's - except the last into the character SEP. */ -extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW; -extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW; - -/* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ -extern error_t __argz_append (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __buf, size_t _buf_len) - __THROW; -extern error_t argz_append (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __buf, size_t __buf_len) - __THROW; - -/* Append STR to the argz vector in ARGZ & ARGZ_LEN. */ -extern error_t __argz_add (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __str) __THROW; -extern error_t argz_add (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __str) __THROW; - -/* Append SEP separated list in STRING to the argz vector in ARGZ & - ARGZ_LEN. */ -extern error_t __argz_add_sep (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __string, int __delim) - __THROW; -extern error_t argz_add_sep (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __string, int __delim) - __THROW; - -/* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */ -extern void __argz_delete (char **__restrict __argz, - size_t *__restrict __argz_len, - char *__restrict __entry) __THROW; -extern void argz_delete (char **__restrict __argz, - size_t *__restrict __argz_len, - char *__restrict __entry) __THROW; - -/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an - existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. - Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN, - ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not - in ARGZ, EINVAL is returned, else if memory can't be allocated for the new - ARGZ, ENOMEM is returned, else 0. */ -extern error_t __argz_insert (char **__restrict __argz, - size_t *__restrict __argz_len, - char *__restrict __before, - __const char *__restrict __entry) __THROW; -extern error_t argz_insert (char **__restrict __argz, - size_t *__restrict __argz_len, - char *__restrict __before, - __const char *__restrict __entry) __THROW; - -/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating - ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be - incremented by number of replacements performed. */ -extern error_t __argz_replace (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __str, - __const char *__restrict __with, - unsigned int *__restrict __replace_count); -extern error_t argz_replace (char **__restrict __argz, - size_t *__restrict __argz_len, - __const char *__restrict __str, - __const char *__restrict __with, - unsigned int *__restrict __replace_count); - -/* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there - are no more. If entry is NULL, then the first entry is returned. This - behavior allows two convenient iteration styles: - - char *entry = 0; - while ((entry = argz_next (argz, argz_len, entry))) - ...; - - or - - char *entry; - for (entry = argz; entry; entry = argz_next (argz, argz_len, entry)) - ...; -*/ -extern char *__argz_next (__const char *__restrict __argz, size_t __argz_len, - __const char *__restrict __entry) __THROW; -extern char *argz_next (__const char *__restrict __argz, size_t __argz_len, - __const char *__restrict __entry) __THROW; - -#ifdef __USE_EXTERN_INLINES -extern inline char * -__argz_next (__const char *__argz, size_t __argz_len, - __const char *__entry) __THROW -{ - if (__entry) - { - if (__entry < __argz + __argz_len) - __entry = strchr (__entry, '\0') + 1; - - return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry; - } - else - return __argz_len > 0 ? (char *) __argz : 0; -} -extern inline char * -argz_next (__const char *__argz, size_t __argz_len, - __const char *__entry) __THROW -{ - return __argz_next (__argz, __argz_len, __entry); -} -#endif /* Use extern inlines. */ - -__END_DECLS - -#endif /* argz.h */ diff --git a/src/system/libroot/posix/glibc/string/basename.c b/src/system/libroot/posix/glibc/string/basename.c deleted file mode 100644 index 5ea1bb0b6a..0000000000 --- a/src/system/libroot/posix/glibc/string/basename.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Return the name-within-directory of a file name. - Copyright (C) 1996,97,98,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#ifndef _LIBC -/* We cannot generally use the name `basename' since XPG defines an unusable - variant of the function but we cannot use it. */ -# define basename gnu_basename -#endif - - -char * -basename (filename) - const char *filename; -{ - char *p = strrchr (filename, '/'); - return p ? p + 1 : (char *) filename; -} -#ifdef _LIBC -libc_hidden_def (basename) -#endif diff --git a/src/system/libroot/posix/glibc/string/envz.c b/src/system/libroot/posix/glibc/string/envz.c deleted file mode 100644 index 5c5804c12b..0000000000 --- a/src/system/libroot/posix/glibc/string/envz.c +++ /dev/null @@ -1,173 +0,0 @@ -/* Routines for dealing with '\0' separated environment vectors - Copyright (C) 1995,96,97,98,2001,02 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -#include - -/* The character separating names from values in an envz. */ -#define SEP '=' - -/* Returns a pointer to the entry in ENVZ for NAME, or 0 if there is none. - If NAME contains the separator character, only the portion before it is - used in the comparison. */ -char * -envz_entry (const char *envz, size_t envz_len, const char *name) -{ - while (envz_len) - { - const char *p = name; - const char *entry = envz; /* Start of this entry. */ - - /* See how far NAME and ENTRY match. */ - while (envz_len && *p == *envz && *p && *p != SEP) - p++, envz++, envz_len--; - - if ((*envz == '\0' || *envz == SEP) && (*p == '\0' || *p == SEP)) - /* Bingo! */ - return (char *) entry; - - /* No match, skip to the next entry. */ - while (envz_len && *envz) - envz++, envz_len--; - if (envz_len) - envz++, envz_len--; /* skip '\0' */ - } - - return 0; -} -libc_hidden_def (envz_entry) - -/* Returns a pointer to the value portion of the entry in ENVZ for NAME, or 0 - if there is none. */ -char * -envz_get (const char *envz, size_t envz_len, const char *name) -{ - char *entry = envz_entry (envz, envz_len, name); - if (entry) - { - while (*entry && *entry != SEP) - entry++; - if (*entry) - entry++; - else - entry = 0; /* A null entry. */ - } - return entry; -} - -/* Remove the entry for NAME from ENVZ & ENVZ_LEN, if any. */ -void -envz_remove (char **envz, size_t *envz_len, const char *name) -{ - char *entry = envz_entry (*envz, *envz_len, name); - if (entry) - argz_delete (envz, envz_len, entry); -} -libc_hidden_def (envz_remove) - -/* Adds an entry for NAME with value VALUE to ENVZ & ENVZ_LEN. If an entry - with the same name already exists in ENVZ, it is removed. If VALUE is - NULL, then the new entry will a special null one, for which envz_get will - return NULL, although envz_entry will still return an entry; this is handy - because when merging with another envz, the null entry can override an - entry in the other one. Null entries can be removed with envz_strip (). */ -error_t -envz_add (char **envz, size_t *envz_len, const char *name, const char *value) -{ - envz_remove (envz, envz_len, name); - - if (value) - /* Add the new value, if there is one. */ - { - size_t name_len = strlen (name); - size_t value_len = strlen (value); - size_t old_envz_len = *envz_len; - size_t new_envz_len = old_envz_len + name_len + 1 + value_len + 1; - char *new_envz = realloc (*envz, new_envz_len); - - if (new_envz) - { - memcpy (new_envz + old_envz_len, name, name_len); - new_envz[old_envz_len + name_len] = SEP; - memcpy (new_envz + old_envz_len + name_len + 1, value, value_len); - new_envz[new_envz_len - 1] = 0; - - *envz = new_envz; - *envz_len = new_envz_len; - - return 0; - } - else - return ENOMEM; - } - else - /* Add a null entry. */ - return __argz_add (envz, envz_len, name); -} - -/* Adds each entry in ENVZ2 to ENVZ & ENVZ_LEN, as if with envz_add(). If - OVERRIDE is true, then values in ENVZ2 will supersede those with the same - name in ENV, otherwise not. */ -error_t -envz_merge (char **envz, size_t *envz_len, const char *envz2, - size_t envz2_len, int override) -{ - error_t err = 0; - - while (envz2_len && ! err) - { - char *old = envz_entry (*envz, *envz_len, envz2); - size_t new_len = strlen (envz2) + 1; - - if (! old) - err = __argz_append (envz, envz_len, envz2, new_len); - else if (override) - { - argz_delete (envz, envz_len, old); - err = __argz_append (envz, envz_len, envz2, new_len); - } - - envz2 += new_len; - envz2_len -= new_len; - } - - return err; -} - -/* Remove null entries. */ -void -envz_strip (char **envz, size_t *envz_len) -{ - char *entry = *envz; - size_t left = *envz_len; - while (left) - { - size_t entry_len = strlen (entry) + 1; - left -= entry_len; - if (! strchr (entry, SEP)) - /* Null entry. */ - memmove (entry + entry_len, entry, left); - else - entry += entry_len; - } - *envz_len = entry - *envz; -} diff --git a/src/system/libroot/posix/glibc/string/envz.h b/src/system/libroot/posix/glibc/string/envz.h deleted file mode 100644 index 3542ded721..0000000000 --- a/src/system/libroot/posix/glibc/string/envz.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Routines for dealing with '\0' separated environment vectors - Copyright (C) 1995, 96, 98, 99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _ENVZ_H -#define _ENVZ_H 1 - -#include - -#include - -/* Envz's are argz's too, and should be created etc., using the same - routines. */ -#include - -__BEGIN_DECLS - -/* Returns a pointer to the entry in ENVZ for NAME, or 0 if there is none. */ -extern char *envz_entry (__const char *__restrict __envz, size_t __envz_len, - __const char *__restrict __name) - __THROW __attribute_pure__; - -/* Returns a pointer to the value portion of the entry in ENVZ for NAME, or 0 - if there is none. */ -extern char *envz_get (__const char *__restrict __envz, size_t __envz_len, - __const char *__restrict __name) - __THROW __attribute_pure__; - -/* Adds an entry for NAME with value VALUE to ENVZ & ENVZ_LEN. If an entry - with the same name already exists in ENVZ, it is removed. If VALUE is - NULL, then the new entry will a special null one, for which envz_get will - return NULL, although envz_entry will still return an entry; this is handy - because when merging with another envz, the null entry can override an - entry in the other one. Null entries can be removed with envz_strip (). */ -extern error_t envz_add (char **__restrict __envz, - size_t *__restrict __envz_len, - __const char *__restrict __name, - __const char *__restrict __value) __THROW; - -/* Adds each entry in ENVZ2 to ENVZ & ENVZ_LEN, as if with envz_add(). If - OVERRIDE is true, then values in ENVZ2 will supersede those with the same - name in ENV, otherwise not. */ -extern error_t envz_merge (char **__restrict __envz, - size_t *__restrict __envz_len, - __const char *__restrict __envz2, - size_t __envz2_len, int __override) __THROW; - -/* Remove the entry for NAME from ENVZ & ENVZ_LEN, if any. */ -extern void envz_remove (char **__restrict __envz, - size_t *__restrict __envz_len, - __const char *__restrict __name) __THROW; - -/* Remove null entries. */ -extern void envz_strip (char **__restrict __envz, - size_t *__restrict __envz_len) __THROW; - -__END_DECLS - -#endif /* envz.h */ diff --git a/src/system/libroot/posix/glibc/string/inl-tester.c b/src/system/libroot/posix/glibc/string/inl-tester.c deleted file mode 100644 index 88528e5ed8..0000000000 --- a/src/system/libroot/posix/glibc/string/inl-tester.c +++ /dev/null @@ -1,6 +0,0 @@ -/* We want to test the inline functions here. */ - -#define DO_STRING_INLINES -#undef __USE_STRING_INLINES -#define __USE_STRING_INLINES 1 -#include "tester.c" diff --git a/src/system/libroot/posix/glibc/string/memfrob.c b/src/system/libroot/posix/glibc/string/memfrob.c deleted file mode 100644 index fe5b04f8ce..0000000000 --- a/src/system/libroot/posix/glibc/string/memfrob.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1992, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -void * -memfrob (s, n) - void *s; - size_t n; -{ - char *p = (char *) s; - - while (n-- > 0) - *p++ ^= 42; - - return s; -} diff --git a/src/system/libroot/posix/glibc/string/memory.h b/src/system/libroot/posix/glibc/string/memory.h deleted file mode 100644 index 743fa6a95b..0000000000 --- a/src/system/libroot/posix/glibc/string/memory.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* - * SVID - */ - -#ifndef _MEMORY_H -#define _MEMORY_H 1 - -#include - - -#ifndef _STRING_H -# include -#endif /* string.h */ - - -#endif /* memory.h */ diff --git a/src/system/libroot/posix/glibc/string/noinl-tester.c b/src/system/libroot/posix/glibc/string/noinl-tester.c deleted file mode 100644 index 2e994f73f9..0000000000 --- a/src/system/libroot/posix/glibc/string/noinl-tester.c +++ /dev/null @@ -1,4 +0,0 @@ -/* We don't want to test any of the inline functions here. */ - -#define __NO_STRING_INLINES 1 -#include "tester.c" diff --git a/src/system/libroot/posix/glibc/string/stratcliff.c b/src/system/libroot/posix/glibc/string/stratcliff.c deleted file mode 100644 index 9b0e4211a6..0000000000 --- a/src/system/libroot/posix/glibc/string/stratcliff.c +++ /dev/null @@ -1,312 +0,0 @@ -/* Test for string function add boundaries of usable memory. - Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define _GNU_SOURCE 1 - -/* Make sure we don't test the optimized inline functions if we want to - test the real implementation. */ -#undef __USE_STRING_INLINES - -#include -#include -#include -#include -#include -#include - -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - -int -main (int argc, char *argv[]) -{ - int size = sysconf (_SC_PAGESIZE); - char *adr, *dest; - int result = 0; - - adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, -1, 0); - dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, -1, 0); - if (adr == MAP_FAILED || dest == MAP_FAILED) - { - if (errno == ENOSYS) - puts ("No test, mmap not available."); - else - { - printf ("mmap failed: %m"); - result = 1; - } - } - else - { - int inner, middle, outer; - - mprotect(adr, size, PROT_NONE); - mprotect(adr + 2 * size, size, PROT_NONE); - adr += size; - - mprotect(dest, size, PROT_NONE); - mprotect(dest + 2 * size, size, PROT_NONE); - dest += size; - - memset (adr, 'T', size); - - /* strlen test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (inner = MAX (outer, size - 64); inner < size; ++inner) - { - adr[inner] = '\0'; - - if (strlen (&adr[outer]) != (size_t) (inner - outer)) - { - printf ("strlen flunked for outer = %d, inner = %d\n", - outer, inner); - result = 1; - } - - adr[inner] = 'T'; - } - } - - /* strchr test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (middle = MAX (outer, size - 64); middle < size; ++middle) - { - for (inner = middle; inner < size; ++inner) - { - char *cp; - adr[middle] = 'V'; - adr[inner] = '\0'; - - cp = strchr (&adr[outer], 'V'); - - if ((inner == middle && cp != NULL) - || (inner != middle - && (cp - &adr[outer]) != middle - outer)) - { - printf ("strchr flunked for outer = %d, middle = %d, " - "inner = %d\n", outer, middle, inner); - result = 1; - } - - adr[inner] = 'T'; - adr[middle] = 'T'; - } - } - } - - /* Special test. */ - adr[size - 1] = '\0'; - if (strchr (&adr[size - 1], '\n') != NULL) - { - puts ("strchr flunked for test of empty string at end of page"); - result = 1; - } - - /* strrchr test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (middle = MAX (outer, size - 64); middle < size; ++middle) - { - for (inner = middle; inner < size; ++inner) - { - char *cp; - adr[middle] = 'V'; - adr[inner] = '\0'; - - cp = strrchr (&adr[outer], 'V'); - - if ((inner == middle && cp != NULL) - || (inner != middle - && (cp - &adr[outer]) != middle - outer)) - { - printf ("strrchr flunked for outer = %d, middle = %d, " - "inner = %d\n", outer, middle, inner); - result = 1; - } - - adr[inner] = 'T'; - adr[middle] = 'T'; - } - } - } - - /* rawmemchr test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (middle = MAX (outer, size - 64); middle < size; ++middle) - { - char *cp; - adr[middle] = 'V'; - - cp = rawmemchr (&adr[outer], 'V'); - - if (cp - &adr[outer] != middle - outer) - { - printf ("rawmemchr flunked for outer = %d, middle = %d\n", - outer, middle); - result = 1; - } - - adr[middle] = 'T'; - } - } - - /* strcpy test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (inner = MAX (outer, size - 64); inner < size; ++inner) - { - adr[inner] = '\0'; - - if (strcpy (dest, &adr[outer]) != dest - || strlen (dest) != (size_t) (inner - outer)) - { - printf ("strcpy flunked for outer = %d, inner = %d\n", - outer, inner); - result = 1; - } - - adr[inner] = 'T'; - } - } - - /* strncpy tests */ - adr[size-1] = 'T'; - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - size_t len; - - for (len = 0; len < size - outer; ++len) - { - if (strncpy (dest, &adr[outer], len) != dest - || memcmp (dest, &adr[outer], len) != 0) - { - printf ("outer strncpy flunked for outer = %d, len = %Zd\n", - outer, len); - result = 1; - } - } - } - adr[size-1] = '\0'; - - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (inner = MAX (outer, size - 64); inner < size; ++inner) - { - size_t len; - - adr[inner] = '\0'; - - for (len = 0; len < size - outer + 64; ++len) - { - if (strncpy (dest, &adr[outer], len) != dest - || memcmp (dest, &adr[outer], - MIN (inner - outer, len)) != 0 - || (inner - outer < len - && strlen (dest) != (inner - outer))) - { - printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n", - outer, inner, len); - result = 1; - } - if (strncpy (dest + 1, &adr[outer], len) != dest + 1 - || memcmp (dest + 1, &adr[outer], - MIN (inner - outer, len)) != 0 - || (inner - outer < len - && strlen (dest + 1) != (inner - outer))) - { - printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n", - outer, inner, len); - result = 1; - } - } - - adr[inner] = 'T'; - } - } - - /* stpcpy test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (inner = MAX (outer, size - 64); inner < size; ++inner) - { - adr[inner] = '\0'; - - if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer) - { - printf ("stpcpy flunked for outer = %d, inner = %d\n", - outer, inner); - result = 1; - } - - adr[inner] = 'T'; - } - } - - /* stpncpy test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - { - for (middle = MAX (outer, size - 64); middle < size; ++middle) - { - adr[middle] = '\0'; - - for (inner = 0; inner < size - outer; ++ inner) - { - if ((stpncpy (dest, &adr[outer], inner) - dest) - != MIN (inner, middle - outer)) - { - printf ("stpncpy flunked for outer = %d, middle = %d, " - "inner = %d\n", outer, middle, inner); - result = 1; - } - } - - adr[middle] = 'T'; - } - } - - /* memcpy test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - for (inner = 0; inner < size - outer; ++inner) - if (memcpy (dest, &adr[outer], inner) != dest) - { - printf ("memcpy flunked for outer = %d, inner = %d\n", - outer, inner); - result = 1; - } - - /* mempcpy test */ - for (outer = size - 1; outer >= MAX (0, size - 128); --outer) - for (inner = 0; inner < size - outer; ++inner) - if (mempcpy (dest, &adr[outer], inner) != dest + inner) - { - printf ("mempcpy flunked for outer = %d, inner = %d\n", - outer, inner); - result = 1; - } - } - - return result; -} diff --git a/src/system/libroot/posix/glibc/string/strcoll_l.c b/src/system/libroot/posix/glibc/string/strcoll_l.c deleted file mode 100644 index 6611589ed0..0000000000 --- a/src/system/libroot/posix/glibc/string/strcoll_l.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 -#include - -weak_alias (__strcoll_l, strcoll_l) diff --git a/src/system/libroot/posix/glibc/string/strdup.c b/src/system/libroot/posix/glibc/string/strdup.c deleted file mode 100644 index 559df60e29..0000000000 --- a/src/system/libroot/posix/glibc/string/strdup.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#if defined _LIBC || defined STDC_HEADERS -# include -# include -#else -char *malloc (); -char *memcpy (); -#endif - -#undef __strdup -#undef strdup - -#ifndef weak_alias -# define __strdup strdup -#endif - -/* Duplicate S, returning an identical malloc'd string. */ -char * -__strdup (const char *s) -{ - size_t len = strlen (s) + 1; - void *new = malloc (len); - - if (new == NULL) - return NULL; - - return (char *) memcpy (new, s, len); -} -#ifdef libc_hidden_def -libc_hidden_def (__strdup) -#endif -#ifdef weak_alias -weak_alias (__strdup, strdup) -#endif diff --git a/src/system/libroot/posix/glibc/string/strerror.c b/src/system/libroot/posix/glibc/string/strerror.c deleted file mode 100644 index 5d829d0bf0..0000000000 --- a/src/system/libroot/posix/glibc/string/strerror.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 1991, 93, 94, 95, 96, 98, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -/* Return a string describing the errno code in ERRNUM. - The storage is good only until the next call to strerror. - Writing to the storage causes undefined behavior. */ -libc_freeres_ptr (static char *buf); - -char * -strerror (errnum) - int errnum; -{ - char *ret = __strerror_r (errnum, NULL, 0); - int saved_errno; - - if (__builtin_expect (ret != NULL, 1)) - return ret; - saved_errno = errno; - if (buf == NULL) - buf = malloc (1024); - __set_errno (saved_errno); - if (buf == NULL) - return _("Unknown error"); - return __strerror_r (errnum, buf, 1024); -} diff --git a/src/system/libroot/posix/glibc/string/strfry.c b/src/system/libroot/posix/glibc/string/strfry.c deleted file mode 100644 index 112dd4adb3..0000000000 --- a/src/system/libroot/posix/glibc/string/strfry.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 1992, 1996, 1999, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -char * -strfry (char *string) -{ - static int init; - static struct random_data rdata; - size_t len, i; - - if (!init) - { - static char state[32]; - rdata.state = NULL; - __initstate_r (time ((time_t *) NULL) ^ getpid (), - state, sizeof (state), &rdata); - init = 1; - } - - len = strlen (string); - for (i = 0; i < len; ++i) - { - int32_t j; - char c; - - __random_r (&rdata, &j); - j %= len; - - c = string[i]; - string[i] = string[j]; - string[j] = c; - } - - return string; -} diff --git a/src/system/libroot/posix/glibc/string/string-inlines.c b/src/system/libroot/posix/glibc/string/string-inlines.c deleted file mode 100644 index 7c9776c419..0000000000 --- a/src/system/libroot/posix/glibc/string/string-inlines.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1999, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* and declare some extern inline - functions. These functions are declared additionally here if - inlining is not possible. */ - -#undef __USE_STRING_INLINES -#define __USE_STRING_INLINES -#define _FORCE_INLINES -#define __STRING_INLINE /* empty */ - -/* This is to avoid PLT entries for the x86 version. */ -#define __memcpy_g __memcpy_g_internal -#define __strchr_g __strchr_g_internal - -#include - -#ifdef __memcpy_c -# undef __memcpy_g -strong_alias (__memcpy_g_internal, __memcpy_g) -# undef __strchr_g -strong_alias (__strchr_g_internal, __strchr_g) -#endif diff --git a/src/system/libroot/posix/glibc/string/string.h b/src/system/libroot/posix/glibc/string/string.h deleted file mode 100644 index db9bc00e5c..0000000000 --- a/src/system/libroot/posix/glibc/string/string.h +++ /dev/null @@ -1,381 +0,0 @@ -/* Copyright (C) 1991-1993, 1995-2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* - * ISO C99 Standard: 7.21 String handling - */ - -#ifndef _STRING_H -#define _STRING_H 1 - -#include - -__BEGIN_DECLS - -/* Get size_t and NULL from . */ -#define __need_size_t -#define __need_NULL -#include - - -__BEGIN_NAMESPACE_STD -/* Copy N bytes of SRC to DEST. */ -extern void *memcpy (void *__restrict __dest, - __const void *__restrict __src, size_t __n) __THROW; -/* Copy N bytes of SRC to DEST, guaranteeing - correct behavior for overlapping strings. */ -extern void *memmove (void *__dest, __const void *__src, size_t __n) - __THROW; -__END_NAMESPACE_STD - -/* Copy no more than N bytes of SRC to DEST, stopping when C is found. - Return the position in DEST one byte past where C was copied, - or NULL if C was not found in the first N bytes of SRC. */ -#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN -extern void *memccpy (void *__restrict __dest, __const void *__restrict __src, - int __c, size_t __n) - __THROW; -#endif /* SVID. */ - - -__BEGIN_NAMESPACE_STD -/* Set N bytes of S to C. */ -extern void *memset (void *__s, int __c, size_t __n) __THROW; - -/* Compare N bytes of S1 and S2. */ -extern int memcmp (__const void *__s1, __const void *__s2, size_t __n) - __THROW __attribute_pure__; - -/* Search N bytes of S for C. */ -extern void *memchr (__const void *__s, int __c, size_t __n) - __THROW __attribute_pure__; -__END_NAMESPACE_STD - -#ifdef __USE_GNU -/* Search in S for C. This is similar to `memchr' but there is no - length limit. */ -extern void *rawmemchr (__const void *__s, int __c) __THROW __attribute_pure__; - -/* Search N bytes of S for the final occurrence of C. */ -extern void *memrchr (__const void *__s, int __c, size_t __n) - __THROW __attribute_pure__; -#endif - - -__BEGIN_NAMESPACE_STD -/* Copy SRC to DEST. */ -extern char *strcpy (char *__restrict __dest, __const char *__restrict __src) - __THROW; -/* Copy no more than N characters of SRC to DEST. */ -extern char *strncpy (char *__restrict __dest, - __const char *__restrict __src, size_t __n) __THROW; - -/* Append SRC onto DEST. */ -extern char *strcat (char *__restrict __dest, __const char *__restrict __src) - __THROW; -/* Append no more than N characters from SRC onto DEST. */ -extern char *strncat (char *__restrict __dest, __const char *__restrict __src, - size_t __n) __THROW; - -/* Compare S1 and S2. */ -extern int strcmp (__const char *__s1, __const char *__s2) - __THROW __attribute_pure__; -/* Compare N characters of S1 and S2. */ -extern int strncmp (__const char *__s1, __const char *__s2, size_t __n) - __THROW __attribute_pure__; - -/* Compare the collated forms of S1 and S2. */ -extern int strcoll (__const char *__s1, __const char *__s2) - __THROW __attribute_pure__; -/* Put a transformation of SRC into no more than N bytes of DEST. */ -extern size_t strxfrm (char *__restrict __dest, - __const char *__restrict __src, size_t __n) __THROW; -__END_NAMESPACE_STD - -#ifdef __USE_GNU -/* The following functions are equivalent to the both above but they - take the locale they use for the collation as an extra argument. - This is not standardsized but something like will come. */ -# include - -/* Compare the collated forms of S1 and S2 using rules from L. */ -extern int strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) - __THROW __attribute_pure__; -/* Put a transformation of SRC into no more than N bytes of DEST. */ -extern size_t strxfrm_l (char *__dest, __const char *__src, size_t __n, - __locale_t __l) __THROW; -#endif - -#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED -/* Duplicate S, returning an identical malloc'd string. */ -extern char *strdup (__const char *__s) __THROW __attribute_malloc__; -#endif - -/* Return a malloc'd copy of at most N bytes of STRING. The - resultant string is terminated even if no null terminator - appears before STRING[N]. */ -#if defined __USE_GNU -extern char *strndup (__const char *__string, size_t __n) - __THROW __attribute_malloc__; -#endif - -#if defined __USE_GNU && defined __GNUC__ -/* Duplicate S, returning an identical alloca'd string. */ -# define strdupa(s) \ - (__extension__ \ - ({ \ - __const char *__old = (s); \ - size_t __len = strlen (__old) + 1; \ - char *__new = (char *) __builtin_alloca (__len); \ - (char *) memcpy (__new, __old, __len); \ - })) - -/* Return an alloca'd copy of at most N bytes of string. */ -# define strndupa(s, n) \ - (__extension__ \ - ({ \ - __const char *__old = (s); \ - size_t __len = strnlen (__old, (n)); \ - char *__new = (char *) __builtin_alloca (__len + 1); \ - __new[__len] = '\0'; \ - (char *) memcpy (__new, __old, __len); \ - })) -#endif - -__BEGIN_NAMESPACE_STD -/* Find the first occurrence of C in S. */ -extern char *strchr (__const char *__s, int __c) __THROW __attribute_pure__; -/* Find the last occurrence of C in S. */ -extern char *strrchr (__const char *__s, int __c) __THROW __attribute_pure__; -__END_NAMESPACE_STD - -#ifdef __USE_GNU -/* This function is similar to `strchr'. But it returns a pointer to - the closing NUL byte in case C is not found in S. */ -extern char *strchrnul (__const char *__s, int __c) __THROW __attribute_pure__; -#endif - -__BEGIN_NAMESPACE_STD -/* Return the length of the initial segment of S which - consists entirely of characters not in REJECT. */ -extern size_t strcspn (__const char *__s, __const char *__reject) - __THROW __attribute_pure__; -/* Return the length of the initial segment of S which - consists entirely of characters in ACCEPT. */ -extern size_t strspn (__const char *__s, __const char *__accept) - __THROW __attribute_pure__; -/* Find the first occurrence in S of any character in ACCEPT. */ -extern char *strpbrk (__const char *__s, __const char *__accept) - __THROW __attribute_pure__; -/* Find the first occurrence of NEEDLE in HAYSTACK. */ -extern char *strstr (__const char *__haystack, __const char *__needle) - __THROW __attribute_pure__; - - -/* Divide S into tokens separated by characters in DELIM. */ -extern char *strtok (char *__restrict __s, __const char *__restrict __delim) - __THROW; -__END_NAMESPACE_STD - -/* Divide S into tokens separated by characters in DELIM. Information - passed between calls are stored in SAVE_PTR. */ -extern char *__strtok_r (char *__restrict __s, - __const char *__restrict __delim, - char **__restrict __save_ptr) __THROW; -#if defined __USE_POSIX || defined __USE_MISC -extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim, - char **__restrict __save_ptr) __THROW; -#endif - -#ifdef __USE_GNU -/* Similar to `strstr' but this function ignores the case of both strings. */ -extern char *strcasestr (__const char *__haystack, __const char *__needle) - __THROW __attribute_pure__; -#endif - -#ifdef __USE_GNU -/* Find the first occurrence of NEEDLE in HAYSTACK. - NEEDLE is NEEDLELEN bytes long; - HAYSTACK is HAYSTACKLEN bytes long. */ -extern void *memmem (__const void *__haystack, size_t __haystacklen, - __const void *__needle, size_t __needlelen) - __THROW __attribute_pure__; - -/* Copy N bytes of SRC to DEST, return pointer to bytes after the - last written byte. */ -extern void *__mempcpy (void *__restrict __dest, - __const void *__restrict __src, size_t __n) __THROW; -extern void *mempcpy (void *__restrict __dest, - __const void *__restrict __src, size_t __n) __THROW; -#endif - - -__BEGIN_NAMESPACE_STD -/* Return the length of S. */ -extern size_t strlen (__const char *__s) __THROW __attribute_pure__; -__END_NAMESPACE_STD - -#ifdef __USE_GNU -/* Find the length of STRING, but scan at most MAXLEN characters. - If no '\0' terminator is found in that many characters, return MAXLEN. */ -extern size_t strnlen (__const char *__string, size_t __maxlen) - __THROW __attribute_pure__; -#endif - - -__BEGIN_NAMESPACE_STD -/* Return a string describing the meaning of the `errno' code in ERRNUM. */ -extern char *strerror (int __errnum) __THROW; -__END_NAMESPACE_STD -#if defined __USE_XOPEN2K || defined __USE_MISC -/* Reentrant version of `strerror'. If a temporary buffer is required, at - most BUFLEN bytes of BUF will be used. */ -extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) __THROW; -#endif - -/* We define this function always since `bzero' is sometimes needed when - the namespace rules does not allow this. */ -extern void __bzero (void *__s, size_t __n) __THROW; - -#ifdef __USE_BSD -/* Copy N bytes of SRC to DEST (like memmove, but args reversed). */ -extern void bcopy (__const void *__src, void *__dest, size_t __n) __THROW; - -/* Set N bytes of S to 0. */ -extern void bzero (void *__s, size_t __n) __THROW; - -/* Compare N bytes of S1 and S2 (same as memcmp). */ -extern int bcmp (__const void *__s1, __const void *__s2, size_t __n) - __THROW __attribute_pure__; - -/* Find the first occurrence of C in S (same as strchr). */ -extern char *index (__const char *__s, int __c) __THROW __attribute_pure__; - -/* Find the last occurrence of C in S (same as strrchr). */ -extern char *rindex (__const char *__s, int __c) __THROW __attribute_pure__; - -/* Return the position of the first bit set in I, or 0 if none are set. - The least-significant bit is position 1, the most-significant 32. */ -extern int ffs (int __i) __THROW __attribute__ ((__const__)); - -/* The following two functions are non-standard but necessary for non-32 bit - platforms. */ -# ifdef __USE_GNU -extern int ffsl (long int __l) __THROW __attribute__ ((__const__)); -# ifdef __GNUC__ -__extension__ extern int ffsll (long long int __ll) - __THROW __attribute__ ((__const__)); -# endif -# endif - -/* Compare S1 and S2, ignoring case. */ -extern int strcasecmp (__const char *__s1, __const char *__s2) - __THROW __attribute_pure__; - -/* Compare no more than N chars of S1 and S2, ignoring case. */ -extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n) - __THROW __attribute_pure__; -#endif /* Use BSD. */ - -#ifdef __USE_GNU -/* Again versions of a few functions which use the given locale instead - of the global one. */ -extern int strcasecmp_l (__const char *__s1, __const char *__s2, - __locale_t __loc) __THROW __attribute_pure__; - -extern int strncasecmp_l (__const char *__s1, __const char *__s2, - size_t __n, __locale_t __loc) - __THROW __attribute_pure__; -#endif - -#ifdef __USE_BSD -/* Return the next DELIM-delimited token from *STRINGP, - terminating it with a '\0', and update *STRINGP to point past it. */ -extern char *strsep (char **__restrict __stringp, - __const char *__restrict __delim) __THROW; -#endif - -#ifdef __USE_GNU -/* Compare S1 and S2 as strings holding name & indices/version numbers. */ -extern int strverscmp (__const char *__s1, __const char *__s2) - __THROW __attribute_pure__; - -/* Return a string describing the meaning of the signal number in SIG. */ -extern char *strsignal (int __sig) __THROW; - -/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ -extern char *__stpcpy (char *__restrict __dest, __const char *__restrict __src) - __THROW; -extern char *stpcpy (char *__restrict __dest, __const char *__restrict __src) - __THROW; - -/* Copy no more than N characters of SRC to DEST, returning the address of - the last character written into DEST. */ -extern char *__stpncpy (char *__restrict __dest, - __const char *__restrict __src, size_t __n) __THROW; -extern char *stpncpy (char *__restrict __dest, - __const char *__restrict __src, size_t __n) __THROW; - -/* Sautee STRING briskly. */ -extern char *strfry (char *__string) __THROW; - -/* Frobnicate N bytes of S. */ -extern void *memfrob (void *__s, size_t __n) __THROW; - -# ifndef basename -/* Return the file name within directory of FILENAME. We don't - declare the function if the `basename' macro is available (defined - in ) which makes the XPG version of this function - available. */ -extern char *basename (__const char *__filename) __THROW; -# endif -#endif - - -#if defined __GNUC__ && __GNUC__ >= 2 -# if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \ - && !defined __NO_INLINE__ && !defined __cplusplus -/* When using GNU CC we provide some optimized versions of selected - functions from this header. There are two kinds of optimizations: - - - machine-dependent optimizations, most probably using inline - assembler code; these might be quite expensive since the code - size can increase significantly. - These optimizations are not used unless the symbol - __USE_STRING_INLINES - is defined before including this header. - - - machine-independent optimizations which do not increase the - code size significantly and which optimize mainly situations - where one or more arguments are compile-time constants. - These optimizations are used always when the compiler is - taught to optimize. - - One can inhibit all optimizations by defining __NO_STRING_INLINES. */ - -/* Get the machine-dependent optimizations (if any). */ -# include - -/* These are generic optimizations which do not add too much inline code. */ -# include -# endif -#endif - -__END_DECLS - -#endif /* string.h */ diff --git a/src/system/libroot/posix/glibc/string/strings.h b/src/system/libroot/posix/glibc/string/strings.h deleted file mode 100644 index 3ba2b04c8e..0000000000 --- a/src/system/libroot/posix/glibc/string/strings.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 1991,92,96,97,99,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _STRINGS_H -#define _STRINGS_H 1 - -/* We don't need and should not read this file if was already - read. The one exception being that if __USE_BSD isn't defined, then - these aren't defined in string.h, so we need to define them here. */ -#if !defined _STRING_H || !defined __USE_BSD - -# include -# define __need_size_t -# include - -__BEGIN_DECLS - -/* Compare N bytes of S1 and S2 (same as memcmp). */ -extern int bcmp (__const void *__s1, __const void *__s2, size_t __n) - __THROW __attribute_pure__; - -/* Copy N bytes of SRC to DEST (like memmove, but args reversed). */ -extern void bcopy (__const void *__src, void *__dest, size_t __n) __THROW; - -/* Set N bytes of S to 0. */ -extern void bzero (void *__s, size_t __n) __THROW; - -/* Return the position of the first bit set in I, or 0 if none are set. - The least-significant bit is position 1, the most-significant 32. */ -extern int ffs (int __i) __THROW __attribute__ ((const)); - -/* Find the first occurrence of C in S (same as strchr). */ -extern char *index (__const char *__s, int __c) __THROW __attribute_pure__; - -/* Find the last occurrence of C in S (same as strrchr). */ -extern char *rindex (__const char *__s, int __c) __THROW __attribute_pure__; - -/* Compare S1 and S2, ignoring case. */ -extern int strcasecmp (__const char *__s1, __const char *__s2) - __THROW __attribute_pure__; - -/* Compare no more than N chars of S1 and S2, ignoring case. */ -extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n) - __THROW __attribute_pure__; - -__END_DECLS - -#endif /* string.h */ - -#endif /* strings.h */ diff --git a/src/system/libroot/posix/glibc/string/strndup.c b/src/system/libroot/posix/glibc/string/strndup.c deleted file mode 100644 index 68ba6c766b..0000000000 --- a/src/system/libroot/posix/glibc/string/strndup.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#if defined _LIBC || defined STDC_HEADERS -# include -# include -#else -char *malloc (); -#endif - -#undef __strndup -#undef strndup - -#ifndef weak_alias -# define __strndup strndup -#endif - -char * -__strndup (s, n) - const char *s; - size_t n; -{ - size_t len = __strnlen (s, n); - char *new = (char *) malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return (char *) memcpy (new, s, len); -} -#ifdef libc_hidden_def -libc_hidden_def (__strndup) -#endif -#ifdef weak_alias -weak_alias (__strndup, strndup) -#endif diff --git a/src/system/libroot/posix/glibc/string/strsignal.c b/src/system/libroot/posix/glibc/string/strsignal.c deleted file mode 100644 index 8ff01a4731..0000000000 --- a/src/system/libroot/posix/glibc/string/strsignal.c +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright (C) 1991, 1994-2000, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include - - -#ifndef HAVE_GNU_LD -#define _sys_siglist sys_siglist -#endif - -/* Defined in siglist.c. */ -extern const char *const _sys_siglist[]; -extern const char *const _sys_siglist_internal[] attribute_hidden; -static __libc_key_t key; - -/* If nonzero the key allocation failed and we should better use a - static buffer than fail. */ -#define BUFFERSIZ 100 -static char local_buf[BUFFERSIZ]; -static char *static_buf; - -/* Destructor for the thread-specific data. */ -static void init (void); -static void free_key_mem (void *mem); -static char *getbuffer (void); - - -/* Return a string describing the meaning of the signal number SIGNUM. */ -char * -strsignal (int signum) -{ - __libc_once_define (static, once); - const char *desc; - - /* If we have not yet initialized the buffer do it now. */ - __libc_once (once, init); - - if ( -#ifdef SIGRTMIN - (signum >= SIGRTMIN && signum <= SIGRTMAX) || -#endif - signum < 0 || signum >= NSIG - || (desc = INTUSE(_sys_siglist)[signum]) == NULL) - { - char *buffer = getbuffer (); - int len; -#ifdef SIGRTMIN - if (signum >= SIGRTMIN && signum <= SIGRTMAX) - len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"), - signum - SIGRTMIN); - else -#endif - len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"), - signum); - if (len >= BUFFERSIZ) - buffer = NULL; - else - buffer[len] = '\0'; - - return buffer; - } - - return (char *) _(desc); -} - - -/* Initialize buffer. */ -static void -init (void) -{ - if (__libc_key_create (&key, free_key_mem)) - /* Creating the key failed. This means something really went - wrong. In any case use a static buffer which is better than - nothing. */ - static_buf = local_buf; -} - - -/* Free the thread specific data, this is done if a thread terminates. */ -static void -free_key_mem (void *mem) -{ - free (mem); - __libc_setspecific (key, NULL); -} - - -/* Return the buffer to be used. */ -static char * -getbuffer (void) -{ - char *result; - - if (static_buf != NULL) - result = static_buf; - else - { - /* We don't use the static buffer and so we have a key. Use it - to get the thread-specific buffer. */ - result = __libc_getspecific (key); - if (result == NULL) - { - /* No buffer allocated so far. */ - result = malloc (BUFFERSIZ); - if (result == NULL) - /* No more memory available. We use the static buffer. */ - result = local_buf; - else - __libc_setspecific (key, result); - } - } - - return result; -} diff --git a/src/system/libroot/posix/glibc/string/strverscmp.c b/src/system/libroot/posix/glibc/string/strverscmp.c deleted file mode 100644 index 8efac30383..0000000000 --- a/src/system/libroot/posix/glibc/string/strverscmp.c +++ /dev/null @@ -1,113 +0,0 @@ -/* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jean-Franois Bignolles , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -/* states: S_N: normal, S_I: comparing integral part, S_F: comparing - fractionnal parts, S_Z: idem but with leading Zeroes only */ -#define S_N 0x0 -#define S_I 0x4 -#define S_F 0x8 -#define S_Z 0xC - -/* result_type: CMP: return diff; LEN: compare using len_diff/diff */ -#define CMP 2 -#define LEN 3 - - -/* Compare S1 and S2 as strings holding indices/version numbers, - returning less than, equal to or greater than zero if S1 is less than, - equal to or greater than S2 (for more info, see the texinfo doc). -*/ - -int -__strverscmp (s1, s2) - const char *s1; - const char *s2; -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; - - /* Symbol(s) 0 [1-9] others (padding) - Transition (10) 0 (01) d (00) x (11) - */ - static const unsigned int next_state[] = - { - /* state x d 0 - */ - /* S_N */ S_N, S_I, S_Z, S_N, - /* S_I */ S_N, S_I, S_I, S_I, - /* S_F */ S_N, S_F, S_F, S_F, - /* S_Z */ S_N, S_F, S_Z, S_Z - }; - - static const int result_type[] = - { - /* state x/x x/d x/0 x/- d/x d/d d/0 d/- - 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ - - /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, - +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, - /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, - -1, CMP, CMP, CMP - }; - - if (p1 == p2) - return 0; - - c1 = *p1++; - c2 = *p2++; - /* Hint: '0' is a digit too. */ - state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); - - while ((diff = c1 - c2) == 0 && c1 != '\0') - { - state = next_state[state]; - c1 = *p1++; - c2 = *p2++; - state |= (c1 == '0') + (isdigit (c1) != 0); - } - - state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; - - switch (state) - { - case CMP: - return diff; - - case LEN: - while (isdigit (*p1++)) - if (!isdigit (*p2++)) - return 1; - - return isdigit (*p2) ? -1 : diff; - - default: - return state; - } -} -libc_hidden_def (__strverscmp) -weak_alias (__strverscmp, strverscmp) diff --git a/src/system/libroot/posix/glibc/string/strxfrm_l.c b/src/system/libroot/posix/glibc/string/strxfrm_l.c deleted file mode 100644 index 264ab9bfe3..0000000000 --- a/src/system/libroot/posix/glibc/string/strxfrm_l.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Ulrich Drepper , 1995. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define USE_IN_EXTENDED_LOCALE_MODEL 1 -#include - -weak_alias (__strxfrm_l, strxfrm_l) diff --git a/src/system/libroot/posix/glibc/wctype/Jamfile b/src/system/libroot/posix/glibc/wctype/Jamfile deleted file mode 100644 index 872281fca0..0000000000 --- a/src/system/libroot/posix/glibc/wctype/Jamfile +++ /dev/null @@ -1,19 +0,0 @@ -SubDir HAIKU_TOP src system libroot posix glibc wctype ; - -SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch - $(TARGET_ARCH) ; -SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch generic ; -SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include ; -#SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc libio ; -#SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc wcsmbs ; -#SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc iconv ; -SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ; -SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ; - -MergeObject posix_gnu_wctype.o : - iswctype.c - towctrans.c - wcfuncs.c - wctrans.c - wctype.c -; diff --git a/src/system/libroot/posix/glibc/wctype/iswctype.c b/src/system/libroot/posix/glibc/wctype/iswctype.c deleted file mode 100644 index 68db36b603..0000000000 --- a/src/system/libroot/posix/glibc/wctype/iswctype.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 1996, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper, . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -#include "wchar-lookup.h" - - -int -__iswctype (wint_t wc, wctype_t desc) -{ - /* If the user passes in an invalid DESC valid (the one returned from - `wctype' in case of an error) simply return 0. */ - if (desc == (wctype_t) 0) - return 0; - - return wctype_table_lookup ((const char *) desc, wc); -} -weak_alias (__iswctype, iswctype) diff --git a/src/system/libroot/posix/glibc/wctype/towctrans.c b/src/system/libroot/posix/glibc/wctype/towctrans.c deleted file mode 100644 index 6e3c466a6e..0000000000 --- a/src/system/libroot/posix/glibc/wctype/towctrans.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Map wide character using given mapping. - Copyright (C) 1996, 1997, 2000, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -/* Define the lookup function. */ -#include "wchar-lookup.h" - -wint_t -__towctrans (wint_t wc, wctrans_t desc) -{ - /* If the user passes in an invalid DESC valid (the one returned from - `wctrans' in case of an error) simply return the value. */ - if (desc == (wctrans_t) 0) - return wc; - - return wctrans_table_lookup ((const char *) desc, wc); -} -libc_hidden_def (__towctrans) -weak_alias (__towctrans, towctrans) diff --git a/src/system/libroot/posix/glibc/wctype/wcfuncs.c b/src/system/libroot/posix/glibc/wctype/wcfuncs.c deleted file mode 100644 index cb79e3bb82..0000000000 --- a/src/system/libroot/posix/glibc/wctype/wcfuncs.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include - -#include "wchar-lookup.h" - -/* These are not exported. */ -extern const char *__ctype32_wctype[12]; -extern const char *__ctype32_wctrans[2]; - -/* Provide real-function versions of all the wctype macros. */ - -#define func(name, type) \ - extern int __##name (wint_t __wc); \ - int \ - __##name (wint_t wc) \ - { \ - return wctype_table_lookup (__ctype32_wctype[type], wc); \ - } \ - weak_alias (__##name, name) - -#undef iswalnum -func (iswalnum, __ISwalnum) -#undef iswalpha -func (iswalpha, __ISwalpha) -#undef iswblank -func (iswblank, __ISwblank) -#undef iswcntrl -func (iswcntrl, __ISwcntrl) -#undef iswdigit -func (iswdigit, __ISwdigit) -#undef iswlower -func (iswlower, __ISwlower) -#undef iswgraph -func (iswgraph, __ISwgraph) -#undef iswprint -func (iswprint, __ISwprint) -#undef iswpunct -func (iswpunct, __ISwpunct) -#undef iswspace -func (iswspace, __ISwspace) -#undef iswupper -func (iswupper, __ISwupper) -#undef iswxdigit -func (iswxdigit, __ISwxdigit) - -wint_t -(towlower) (wc) - wint_t wc; -{ - return wctrans_table_lookup (__ctype32_wctrans[__TOW_tolower], wc); -} - -wint_t -(towupper) (wc) - wint_t wc; -{ - return wctrans_table_lookup (__ctype32_wctrans[__TOW_toupper], wc); -} diff --git a/src/system/libroot/posix/glibc/wctype/wctrans.c b/src/system/libroot/posix/glibc/wctype/wctrans.c deleted file mode 100644 index 4384c7b2f8..0000000000 --- a/src/system/libroot/posix/glibc/wctype/wctrans.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include "../locale/localeinfo.h" - -wctrans_t -wctrans (const char *property) -{ - const char *names; - size_t cnt; - size_t i; - - names = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_MAP_NAMES); - cnt = 0; - while (names[0] != '\0') - { - if (strcmp (property, names) == 0) - break; - - names = strchr (names, '\0') + 1; - ++cnt; - } - - if (names[0] == '\0') - return 0; - - i = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_OFFSET) + cnt; - return (wctrans_t) _nl_current_LC_CTYPE->values[i].string; -} diff --git a/src/system/libroot/posix/glibc/wctype/wctype.c b/src/system/libroot/posix/glibc/wctype/wctype.c deleted file mode 100644 index fc1927c450..0000000000 --- a/src/system/libroot/posix/glibc/wctype/wctype.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include - -wctype_t -__wctype (const char *property) -{ - const char *names; - unsigned int result; - size_t proplen = strlen (property); - size_t i; - - names = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS_NAMES); - for (result = 0; ; result++) - { - size_t nameslen = strlen (names); - - if (proplen == nameslen && memcmp (property, names, proplen) == 0) - break; - - names += nameslen + 1; - if (names[0] == '\0') - return 0; - } - - i = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_CLASS_OFFSET) + result; - return (wctype_t) _nl_current_LC_CTYPE->values[i].string; -} -weak_alias (__wctype, wctype) diff --git a/src/system/libroot/posix/locale/Jamfile b/src/system/libroot/posix/locale/Jamfile index 750d1d7cbe..f019e58f69 100644 --- a/src/system/libroot/posix/locale/Jamfile +++ b/src/system/libroot/posix/locale/Jamfile @@ -1,12 +1,20 @@ SubDir HAIKU_TOP src system libroot posix locale ; +UsePrivateHeaders [ FDirName libroot locale ] ; +UsePrivateHeaders [ FDirName libroot time ] ; + MergeObject posix_locale.o : - #ctype.c - localeconv.c - setlocale.c + ctype.cpp + LocaleBackend.cpp + LocaleData.cpp + LocaleDataBridge.cpp + localeconv.cpp + nl_langinfo.cpp + setlocale.cpp #mb_none.c #mblen.c #mbrtowc.c #mbsinit.c #wcrtomb.c + wctype.cpp ; diff --git a/src/system/libroot/posix/locale/LocaleBackend.cpp b/src/system/libroot/posix/locale/LocaleBackend.cpp new file mode 100644 index 0000000000..dc0b7798ba --- /dev/null +++ b/src/system/libroot/posix/locale/LocaleBackend.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "LocaleBackend.h" + +#include +#include +#include + + +namespace BPrivate { + + +LocaleBackend* gLocaleBackend = NULL; + + +static LocaleDataBridge sLocaleDataBridge; +static pthread_once_t sBackendInitOnce = PTHREAD_ONCE_INIT; + + +static void +LoadBackend() +{ + void* imageHandle = dlopen("libroot-addon-icu.so", RTLD_LAZY); + if (imageHandle == NULL) + return; + + typedef LocaleBackend* (*symbolType)(); + symbolType createInstanceFunc + = (symbolType)dlsym(imageHandle, "CreateInstance"); + if (createInstanceFunc == NULL) + return; + + gLocaleBackend = createInstanceFunc(); +} + + +LocaleBackend::LocaleBackend() +{ +} + + +LocaleBackend::~LocaleBackend() +{ +} + + +status_t +LocaleBackend::LoadBackend() +{ + if (gLocaleBackend == NULL) { + pthread_once(&sBackendInitOnce, &BPrivate::LoadBackend); + if (gLocaleBackend != NULL) + gLocaleBackend->Initialize(&sLocaleDataBridge); + } + + return gLocaleBackend != NULL ? B_OK : B_ERROR; +} + + +} // namespace BPrivate diff --git a/src/system/libroot/posix/locale/ctype.c b/src/system/libroot/posix/locale/LocaleData.cpp similarity index 63% rename from src/system/libroot/posix/locale/ctype.c rename to src/system/libroot/posix/locale/LocaleData.cpp index ef45e3ff7d..a17ff232ed 100644 --- a/src/system/libroot/posix/locale/ctype.c +++ b/src/system/libroot/posix/locale/LocaleData.cpp @@ -1,36 +1,33 @@ -/* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ #include +#include + +#include +#include + +#ifndef _KERNEL_MODE +#include +#include +#include +#endif -// disable macros defined in ctype.h -#undef isalnum -#undef isalpha -#undef isascii -#undef isblank -#undef iscntrl -#undef isdigit -#undef islower -#undef isgraph -#undef isprint -#undef ispunct -#undef isspace -#undef isupper -#undef isxdigit -#undef toascii -#undef tolower -#undef toupper +/* + * The values below initialize the structs for the "C"/"POSIX" locale + * which is the default locale (and the only one supported without any locale + * backend). + */ -// standard ASCII tables -// ToDo: These should probably be revised for ISO-8859-1 -// ToDo: change the tables depending on the current locale +namespace BPrivate { -const unsigned short int *__ctype_b = (const unsigned short int[]) { + +const unsigned short gPosixClassInfo[256] = { /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, @@ -47,25 +44,25 @@ const unsigned short int *__ctype_b = (const unsigned short int[]) { /* 104 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, /* 112 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, /* 120 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _IScntrl, - /* 128 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 136 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 144 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 152 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 160 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 168 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 176 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 184 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 192 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 200 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 208 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 216 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 224 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 232 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 240 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, - /* 248 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 136 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 152 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 168 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 184 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 200 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 216 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 232 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 248 */ 0, 0, 0, 0, 0, 0, 0, 0 }; -const int *__ctype_tolower = (const int[]) { +const int gPosixToLowerMap[256] = { /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, @@ -97,10 +94,11 @@ const int *__ctype_tolower = (const int[]) { /* 224 */ 224, 225, 226, 227, 228, 229, 230, 231, /* 232 */ 232, 233, 234, 235, 236, 237, 238, 239, /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, - /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, + /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255 }; -const int *__ctype_toupper = (const int[]) { + +const int gPosixToUpperMap[256] = { /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, @@ -132,163 +130,143 @@ const int *__ctype_toupper = (const int[]) { /* 224 */ 224, 225, 226, 227, 228, 229, 230, 231, /* 232 */ 232, 233, 234, 235, 236, 237, 238, 239, /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, - /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, + /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255 }; -int -isalnum(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & (_ISupper | _ISlower | _ISdigit); - - return 0; -} +struct lconv gPosixLocaleConv = { + (char*)".", // decimal point + (char*)"", // thousands separator + (char*)"", // grouping + (char*)"", // international currency symbol + (char*)"", // local currency symbol + (char*)"", // monetary decimal point + (char*)"", // monetary thousands separator + (char*)"", // monetary grouping + (char*)"", // positive sign + (char*)"", // negative sign + CHAR_MAX, // int_frac_digits + CHAR_MAX, // frac_digits + CHAR_MAX, // p_cs_precedes + CHAR_MAX, // p_sep_by_space + CHAR_MAX, // n_cs_precedes + CHAR_MAX, // n_sep_by_space + CHAR_MAX, // p_sign_posn + CHAR_MAX, // n_sign_posn + CHAR_MAX, // int_p_cs_precedes + CHAR_MAX, // int_p_sep_by_space + CHAR_MAX, // int_n_cs_precedes + CHAR_MAX, // int_n_sep_by_space + CHAR_MAX, // int_p_sign_posn + CHAR_MAX // int_n_sign_posn +}; -int -isalpha(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & (_ISupper | _ISlower); +#ifndef _KERNEL_MODE - return 0; -} +const struct lc_time_t gPosixLCTimeInfo = { + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }, + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, + { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }, + { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday" + }, + "%H:%M:%S", + "%m/%d/%y", + "%a %b %e %H:%M:%S %Y", + "AM", + "PM", + "%a %b %e %H:%M:%S %Z %Y", + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, + "md", + "%I:%M:%S %p" +}; -int -isascii(int c) -{ - /* ASCII characters have bit 8 cleared */ - return (c & ~0x7f) == 0; -} +const char* gPosixLanginfo[_NL_LANGINFO_LAST] = { + "US-ASCII", + gPosixLCTimeInfo.c_fmt, + gPosixLCTimeInfo.x_fmt, + gPosixLCTimeInfo.X_fmt, + gPosixLCTimeInfo.ampm_fmt, + gPosixLCTimeInfo.am, + gPosixLCTimeInfo.pm, + + gPosixLCTimeInfo.weekday[0], + gPosixLCTimeInfo.weekday[1], + gPosixLCTimeInfo.weekday[2], + gPosixLCTimeInfo.weekday[3], + gPosixLCTimeInfo.weekday[4], + gPosixLCTimeInfo.weekday[5], + gPosixLCTimeInfo.weekday[6], + + gPosixLCTimeInfo.wday[0], + gPosixLCTimeInfo.wday[1], + gPosixLCTimeInfo.wday[2], + gPosixLCTimeInfo.wday[3], + gPosixLCTimeInfo.wday[4], + gPosixLCTimeInfo.wday[5], + gPosixLCTimeInfo.wday[6], + + gPosixLCTimeInfo.month[0], + gPosixLCTimeInfo.month[1], + gPosixLCTimeInfo.month[2], + gPosixLCTimeInfo.month[3], + gPosixLCTimeInfo.month[4], + gPosixLCTimeInfo.month[5], + gPosixLCTimeInfo.month[6], + gPosixLCTimeInfo.month[7], + gPosixLCTimeInfo.month[8], + gPosixLCTimeInfo.month[9], + gPosixLCTimeInfo.month[10], + gPosixLCTimeInfo.month[11], + + gPosixLCTimeInfo.mon[0], + gPosixLCTimeInfo.mon[1], + gPosixLCTimeInfo.mon[2], + gPosixLCTimeInfo.mon[3], + gPosixLCTimeInfo.mon[4], + gPosixLCTimeInfo.mon[5], + gPosixLCTimeInfo.mon[6], + gPosixLCTimeInfo.mon[7], + gPosixLCTimeInfo.mon[8], + gPosixLCTimeInfo.mon[9], + gPosixLCTimeInfo.mon[10], + gPosixLCTimeInfo.mon[11], + + "%EC, %Ey, %EY", + "%Ex", + "%Ec", + "%EX", + "%O", + + gPosixLocaleConv.decimal_point, + gPosixLocaleConv.thousands_sep, + + "^[yY]", + "^[nN]", + + gPosixLocaleConv.currency_symbol +}; + +#endif // !_KERNEL_MODE -int -isblank(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISblank; - - return 0; -} - - -int -iscntrl(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _IScntrl; - - return 0; -} - - -int -isdigit(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISdigit; - - return 0; -} - - -int -isgraph(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISgraph; - - return 0; -} - - -int -islower(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISlower; - - return 0; -} - - -int -isprint(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISprint; - - return 0; -} - - -int -ispunct(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISpunct; - - return 0; -} - - -int -isspace(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISspace; - - return 0; -} - - -int -isupper(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISupper; - - return 0; -} - - -int -isxdigit(int c) -{ - if (c >= 0 && c < 256) - return __ctype_b[c] & _ISxdigit; - - return 0; -} - - -int -toascii(int c) -{ - /* Clear higher bits */ - return c & 0x7f; -} - - -int -tolower(int c) -{ - if (c >= 0 && c < 256) - return __ctype_tolower[c]; - - return c; -} - - -int -toupper(int c) -{ - if (c >= 0 && c < 256) - return __ctype_toupper[c]; - - return c; -} +} // namespace BPrivate +const unsigned short* __ctype_b = BPrivate::gPosixClassInfo; +const int* __ctype_tolower = BPrivate::gPosixToLowerMap; +const int* __ctype_toupper = BPrivate::gPosixToUpperMap; diff --git a/src/system/libroot/posix/locale/LocaleDataBridge.cpp b/src/system/libroot/posix/locale/LocaleDataBridge.cpp new file mode 100644 index 0000000000..1b848f7c62 --- /dev/null +++ b/src/system/libroot/posix/locale/LocaleDataBridge.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ + + +#include "LocaleBackend.h" + +#include +#include + +#include +#include +#include +#include + + +// struct used by glibc to access locale info +struct locale_data +{ + const char* name; + const char* filedata; + off_t filesize; + int mmaped; + unsigned int usage_count; + int use_translit; + const char *options; + unsigned int nstrings; + union locale_data_value + { + const uint32_t* wstr; + const char* string; + unsigned int word; + } + values[]; +}; +extern struct locale_data _nl_C_LC_NUMERIC; + + +namespace BPrivate { + + +LocaleCtypeDataBridge::LocaleCtypeDataBridge() + : + addrOfClassInfoTable(&__ctype_b), + addrOfToLowerTable(&__ctype_tolower), + addrOfToUpperTable(&__ctype_toupper), + posixClassInfo(gPosixClassInfo), + posixToLowerMap(gPosixToLowerMap), + posixToUpperMap(gPosixToUpperMap) +{ +} + + +LocaleMessagesDataBridge::LocaleMessagesDataBridge() + : + posixLanginfo(gPosixLanginfo) +{ +} + + +LocaleMonetaryDataBridge::LocaleMonetaryDataBridge() + : + posixLocaleConv(&gPosixLocaleConv) +{ +} + + +LocaleNumericDataBridge::LocaleNumericDataBridge() + : + addrOfGlibcDecimalPoint(&_nl_C_LC_NUMERIC.values[0].string), + addrOfGlibcThousandsSep(&_nl_C_LC_NUMERIC.values[1].string), + addrOfGlibcGrouping(&_nl_C_LC_NUMERIC.values[2].string), + addrOfGlibcWCDecimalPoint(&_nl_C_LC_NUMERIC.values[3].word), + addrOfGlibcWCThousandsSep(&_nl_C_LC_NUMERIC.values[4].word), + posixLocaleConv(&gPosixLocaleConv) +{ +} + + +LocaleTimeDataBridge::LocaleTimeDataBridge() + : + posixLCTimeInfo(&gPosixLCTimeInfo) +{ +} + + +LocaleDataBridge::LocaleDataBridge() + : + posixLanginfo(gPosixLanginfo) +{ +} + + +} // namespace BPrivate diff --git a/src/system/libroot/posix/locale/ctype.cpp b/src/system/libroot/posix/locale/ctype.cpp new file mode 100644 index 0000000000..1dcd13a5bd --- /dev/null +++ b/src/system/libroot/posix/locale/ctype.cpp @@ -0,0 +1,185 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include +#include + + +// disable macros defined in ctype.h +#undef isalnum +#undef isalpha +#undef isascii +#undef isblank +#undef iscntrl +#undef isdigit +#undef islower +#undef isgraph +#undef isprint +#undef ispunct +#undef isspace +#undef isupper +#undef isxdigit +#undef toascii +#undef tolower +#undef toupper + + +int +isalnum(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & (_ISupper | _ISlower | _ISdigit); + + return 0; +} + + +int +isalpha(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & (_ISupper | _ISlower); + + return 0; +} + + +int +isascii(int c) +{ + /* ASCII characters have bit 8 cleared */ + return (c & ~0x7f) == 0; +} + + +int +isblank(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISblank; + + return 0; +} + + +int +iscntrl(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _IScntrl; + + return 0; +} + + +int +isdigit(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISdigit; + + return 0; +} + + +int +isgraph(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISgraph; + + return 0; +} + + +int +islower(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISlower; + + return 0; +} + + +int +isprint(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISprint; + + return 0; +} + + +int +ispunct(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISpunct; + + return 0; +} + + +int +isspace(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISspace; + + return 0; +} + + +int +isupper(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISupper; + + return 0; +} + + +int +isxdigit(int c) +{ + if (c >= 0 && c < 256) + return __ctype_b[c] & _ISxdigit; + + return 0; +} + + +int +toascii(int c) +{ + /* Clear higher bits */ + return c & 0x7f; +} + + +int +tolower(int c) +{ + if (c >= 0 && c < 256) + return __ctype_tolower[c]; + + return c; +} + + +int +toupper(int c) +{ + if (c >= 0 && c < 256) + return __ctype_toupper[c]; + + return c; +} + + diff --git a/src/system/libroot/posix/locale/localeconv.c b/src/system/libroot/posix/locale/localeconv.c deleted file mode 100644 index ed32f76169..0000000000 --- a/src/system/libroot/posix/locale/localeconv.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2007, Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Author: - * Daniel Reinhold, danielre@users.sf.net - */ - - -#include -#include - - -/* - * the values below initialize the struct to the "C" locale - * which is the default (and only required) locale - */ - -struct lconv _Locale = { - ".", // decimal point - - "", // thousands separator - "", // grouping - "", // international currency symbol - "", // local currency symbol - "", // monetary decimal point - "", // monetary thousands separator - "", // monetary grouping - "", // positive sign - "", // negative sign - - CHAR_MAX, // int_frac_digits - CHAR_MAX, // frac_digits - CHAR_MAX, // p_cs_precedes - CHAR_MAX, // p_sep_by_space - CHAR_MAX, // n_cs_precedes - CHAR_MAX, // n_sep_by_space - CHAR_MAX, // p_sign_posn - CHAR_MAX // n_sign_posn -}; - - - -struct lconv* -localeconv(void) -{ - // return pointer to the current locale - return &_Locale; -} diff --git a/src/system/libroot/posix/locale/localeconv.cpp b/src/system/libroot/posix/locale/localeconv.cpp new file mode 100644 index 0000000000..52ad10596d --- /dev/null +++ b/src/system/libroot/posix/locale/localeconv.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2002-2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Author: + * Daniel Reinhold, danielre@users.sf.net + * Oliver Tappe, zooey@hirschkaefer.de + */ + + +#include + +#ifndef _KERNEL_MODE +#include "LocaleBackend.h" +using BPrivate::gLocaleBackend; +#endif + + +extern "C" struct lconv* +localeconv(void) +{ +#ifndef _KERNEL_MODE + if (gLocaleBackend) + return const_cast(gLocaleBackend->LocaleConv()); +#endif + + return &BPrivate::gPosixLocaleConv; +} diff --git a/src/system/libroot/posix/locale/nl_langinfo.cpp b/src/system/libroot/posix/locale/nl_langinfo.cpp new file mode 100644 index 0000000000..8f2c1ee453 --- /dev/null +++ b/src/system/libroot/posix/locale/nl_langinfo.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include + +#include "LocaleBackend.h" + +#include + + +using BPrivate::gLocaleBackend; +using BPrivate::gPosixLanginfo; + + +extern "C" char* +nl_langinfo(nl_item item) +{ + if (item < 0 || item >= _NL_LANGINFO_LAST) + return ""; + + if (gLocaleBackend != NULL) + return const_cast(gLocaleBackend->GetLanginfo(item)); + + return const_cast(gPosixLanginfo[item]); +} diff --git a/src/system/libroot/posix/locale/setlocale.c b/src/system/libroot/posix/locale/setlocale.c deleted file mode 100644 index 1979cb6e03..0000000000 --- a/src/system/libroot/posix/locale/setlocale.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT License. - */ - - -#include -#include -#include - - -char * -setlocale(int category, const char *locale) -{ - if (locale == NULL || !locale[0] || strcmp(locale, "C") == 0) - return "C"; - - // TODO: this should check if liblocale.so is available and use its - // functions. - return NULL; -} diff --git a/src/system/libroot/posix/locale/setlocale.cpp b/src/system/libroot/posix/locale/setlocale.cpp new file mode 100644 index 0000000000..f79c90f6a1 --- /dev/null +++ b/src/system/libroot/posix/locale/setlocale.cpp @@ -0,0 +1,121 @@ +/* + * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include "LocaleBackend.h" + + +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + + +static status_t +GetLocalesFromEnvironment(int category, const char** locales) +{ + const char* locale = getenv("LC_ALL"); + if (locale && *locale) + locales[category] = locale; + else { + // the order of the names must match the one specified in locale.h + const char* categoryNames[] = { + "LC_ALL", + "LC_COLLATE", + "LC_CTYPE", + "LC_MONETARY", + "LC_NUMERIC", + "LC_TIME", + "LC_MESSAGES" + }; + int from, to; + if (category == LC_ALL) { + // we need to check each real category if all of them should be set + from = 1; + to = LC_LAST; + } else + from = to = category; + bool haveDifferentLocales = false; + locale = NULL; + for (int lc = from; lc <= to; lc++) { + const char* lastLocale = locale; + locale = getenv(categoryNames[lc]); + if (!locale || *locale == '\0') + locale = getenv("LANG"); + if (!locale || *locale == '\0') + locale = "POSIX"; + locales[lc] = locale; + if (lastLocale && strcmp(locale, lastLocale) != 0) + haveDifferentLocales = true; + } + if (!haveDifferentLocales) { + // we can set all locales at once + locales[LC_ALL] = locale; + } + } + + return B_OK; +} + + +extern "C" char* +setlocale(int category, const char* locale) +{ + if (category < 0 || category > LC_LAST) + return NULL; + + if (locale == NULL) { + // query the locale of the given category + if (gLocaleBackend != NULL) + return const_cast(gLocaleBackend->SetLocale(category, NULL)); + else + return const_cast("POSIX"); + } + + // we may have to invoke SetLocale once for each category, so we use an + // array to collect the locale per category + const char* locales[LC_LAST + 1]; + for (int lc = 0; lc <= LC_LAST; lc++) + locales[lc] = NULL; + + if (*locale == '\0') + GetLocalesFromEnvironment(category, locales); + else + locales[category] = locale; + + if (!gLocaleBackend) { + // for any locale other than POSIX/C, we try to activate the ICU + // backend + bool needBackend = false; + for (int lc = 0; lc <= LC_LAST; lc++) { + if (locales[lc] != NULL && strcmp(locales[lc], "POSIX") != 0 + && strcmp(locales[lc], "C") != 0) { + needBackend = true; + break; + } + } + if (needBackend && LocaleBackend::LoadBackend() != B_OK) + return NULL; + } + + if (gLocaleBackend != NULL) { + for (int lc = 0; lc <= LC_LAST; lc++) { + if (locales[lc] != NULL) { + locale = gLocaleBackend->SetLocale(lc, locales[lc]); + if (lc == LC_ALL) { + // skip the rest, LC_ALL overrides + return const_cast(locale); + } + } + } + return const_cast(gLocaleBackend->SetLocale(category, NULL)); + } + + return const_cast("POSIX"); +} diff --git a/src/system/libroot/posix/locale/wctype.cpp b/src/system/libroot/posix/locale/wctype.cpp new file mode 100644 index 0000000000..c09892659d --- /dev/null +++ b/src/system/libroot/posix/locale/wctype.cpp @@ -0,0 +1,243 @@ +/* +** Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#define B_USE_POSITIVE_POSIX_ERRORS +#include +#include +#include +#include + +#include "LocaleBackend.h" + + +using BPrivate::gLocaleBackend; + +/* + * In many of the following functions, we make use of the fact that with + * gLocaleBackend == NULL, the POSIX locale is active. Since the POSIX locale + * only contains chars 0-127 and those ASCII chars are compatible with the + * UTF32 values used in wint_t, we can delegate to the respective ctype + * function. + */ + +int +iswalnum(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISalnum); + + return gLocaleBackend->IsWCType(wc, _ISalnum); +} + + +int +iswalpha(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISalpha); + + return gLocaleBackend->IsWCType(wc, _ISalpha); +} + + +int +iswblank(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISblank); + + return gLocaleBackend->IsWCType(wc, _ISblank); +} + + +int +iswcntrl(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _IScntrl); + + return gLocaleBackend->IsWCType(wc, _IScntrl); +} + + +int +iswdigit(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISdigit); + + return gLocaleBackend->IsWCType(wc, _ISdigit); +} + + +int +iswgraph(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISgraph); + + return gLocaleBackend->IsWCType(wc, _ISgraph); +} + + +int +iswlower(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISlower); + + return gLocaleBackend->IsWCType(wc, _ISlower); +} + + +int +iswprint(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISprint); + + return gLocaleBackend->IsWCType(wc, _ISprint); +} + + +int +iswpunct(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISpunct); + + return gLocaleBackend->IsWCType(wc, _ISpunct); +} + + +int +iswspace(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISspace); + + return gLocaleBackend->IsWCType(wc, _ISspace); +} + + +int +iswupper(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISupper); + + return gLocaleBackend->IsWCType(wc, _ISupper); +} + + +int +iswxdigit(wint_t wc) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, _ISxdigit); + + return gLocaleBackend->IsWCType(wc, _ISxdigit); +} + + +int +iswctype(wint_t wc, wctype_t charClass) +{ + if (gLocaleBackend == NULL) + return __isctype(wc, charClass); + + return gLocaleBackend->IsWCType(wc, charClass); +} + + +wint_t +towlower(wint_t wc) +{ + if (gLocaleBackend == NULL) + return tolower(wc); + + wint_t result = 0; + gLocaleBackend->ToWCTrans(wc, _ISlower, result); + + return result; +} + + +wint_t +towupper(wint_t wc) +{ + if (gLocaleBackend == NULL) + return toupper(wc); + + wint_t result = 0; + gLocaleBackend->ToWCTrans(wc, _ISupper, result); + + return result; +} + + +wint_t +towctrans(wint_t wc, wctrans_t transition) +{ + if (gLocaleBackend == NULL) + return tolower(wc); + + wint_t result = 0; + status_t status = gLocaleBackend->ToWCTrans(wc, transition, result); + + if (status != B_OK) + errno = EINVAL; + + return result; +} + + +wctrans_t +wctrans(const char *charClass) +{ + if (charClass != NULL) { + // we do not know any locale-specific character classes + if (strcmp(charClass, "tolower") == 0) + return _ISlower; + if (strcmp(charClass, "toupper") == 0) + return _ISupper; + } + + errno = EINVAL; + return 0; +} + + +wctype_t +wctype(const char *property) +{ + // currently, we do not support any locale-specific properties + if (strcmp(property, "alnum") == 0) + return _ISalnum; + if (strcmp(property, "alpha") == 0) + return _ISalpha; + if (strcmp(property, "blank") == 0) + return _ISblank; + if (strcmp(property, "cntrl") == 0) + return _IScntrl; + if (strcmp(property, "digit") == 0) + return _ISdigit; + if (strcmp(property, "graph") == 0) + return _ISgraph; + if (strcmp(property, "lower") == 0) + return _ISlower; + if (strcmp(property, "print") == 0) + return _ISprint; + if (strcmp(property, "punct") == 0) + return _ISpunct; + if (strcmp(property, "space") == 0) + return _ISspace; + if (strcmp(property, "upper") == 0) + return _ISupper; + if (strcmp(property, "xdigit") == 0) + return _ISxdigit; + + return 0; +} diff --git a/src/system/libroot/posix/stdlib/Jamfile b/src/system/libroot/posix/stdlib/Jamfile index 008b461aac..5983951358 100644 --- a/src/system/libroot/posix/stdlib/Jamfile +++ b/src/system/libroot/posix/stdlib/Jamfile @@ -21,6 +21,7 @@ MergeObject posix_stdlib.o : rand.c random.c realpath.cpp + strfmon.c strtol.c strtoll.c strtoul.c diff --git a/src/system/libroot/posix/stdlib/strfmon.c b/src/system/libroot/posix/stdlib/strfmon.c new file mode 100644 index 0000000000..2e62624392 --- /dev/null +++ b/src/system/libroot/posix/stdlib/strfmon.c @@ -0,0 +1,613 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* internal flags */ +#define NEED_GROUPING 0x01 /* print digits grouped (default) */ +#define SIGN_POSN_USED 0x02 /* '+' or '(' usage flag */ +#define LOCALE_POSN 0x04 /* use locale defined +/- (default) */ +#define PARENTH_POSN 0x08 /* enclose negative amount in () */ +#define SUPRESS_CURR_SYMBOL 0x10 /* supress the currency from output */ +#define LEFT_JUSTIFY 0x20 /* left justify */ +#define USE_INTL_CURRENCY 0x40 /* use international currency symbol */ +#define IS_NEGATIVE 0x80 /* is argument value negative ? */ + +/* internal macros */ +#define PRINT(CH) do { \ + if (dst >= s + maxsize) \ + goto e2big_error; \ + *dst++ = CH; \ +} while (0) + +#define PRINTS(STR) do { \ + char *tmps = STR; \ + while (*tmps != '\0') \ + PRINT(*tmps++); \ +} while (0) + +#define GET_NUMBER(VAR) do { \ + VAR = 0; \ + while (isdigit((unsigned char)*fmt)) { \ + if (VAR > INT_MAX / 10) \ + goto e2big_error; \ + VAR *= 10; \ + VAR += *fmt - '0'; \ + if (VAR < 0) \ + goto e2big_error; \ + fmt++; \ + } \ +} while (0) + +#define GRPCPY(howmany) do { \ + int i = howmany; \ + while (i-- > 0) { \ + avalue_size--; \ + *--bufend = *(avalue+avalue_size+padded); \ + } \ +} while (0) + +#define GRPSEP do { \ + *--bufend = thousands_sep; \ + groups++; \ +} while (0) + + +static void __setup_vars(int, char *, char *, char *, char **); +static int __calc_left_pad(int, char *); +static char *__format_grouped_double(double, int *, int, int, int); + + +ssize_t +strfmon(char *s, size_t maxsize, const char *format, + ...) +{ + va_list ap; + char *dst; /* output destination pointer */ + const char *fmt; /* current format poistion pointer */ + struct lconv *lc; /* pointer to lconv structure */ + char *asciivalue; /* formatted double pointer */ + + int flags; /* formatting options */ + int pad_char; /* padding character */ + int pad_size; /* pad size */ + int width; /* field width */ + int left_prec; /* left precision */ + int right_prec; /* right precision */ + double value; /* just value */ + char space_char = ' '; /* space after currency */ + + char cs_precedes, /* values gathered from struct lconv */ + sep_by_space, + sign_posn, + *signstr, + *currency_symbol; + + char *tmpptr; /* temporary vars */ + int sverrno; + + va_start(ap, format); + + lc = localeconv(); + dst = s; + fmt = format; + asciivalue = NULL; + currency_symbol = NULL; + pad_size = 0; + + while (*fmt) { + /* pass nonformating characters AS IS */ + if (*fmt != '%') + goto literal; + + /* '%' found ! */ + + /* "%%" mean just '%' */ + if (*(fmt+1) == '%') { + fmt++; + literal: + PRINT(*fmt++); + continue; + } + + /* set up initial values */ + flags = (NEED_GROUPING|LOCALE_POSN); + pad_char = ' '; /* padding character is "space" */ + left_prec = -1; /* no left precision specified */ + right_prec = -1; /* no right precision specified */ + width = -1; /* no width specified */ + value = 0; /* we have no value to print now */ + + /* Flags */ + while (1) { + switch (*++fmt) { + case '=': /* fill character */ + pad_char = *++fmt; + if (pad_char == '\0') + goto format_error; + continue; + case '^': /* not group currency */ + flags &= ~(NEED_GROUPING); + continue; + case '+': /* use locale defined signs */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED|LOCALE_POSN); + continue; + case '(': /* enclose negatives with () */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED|PARENTH_POSN); + continue; + case '!': /* suppress currency symbol */ + flags |= SUPRESS_CURR_SYMBOL; + continue; + case '-': /* alignment (left) */ + flags |= LEFT_JUSTIFY; + continue; + default: + break; + } + break; + } + + /* field Width */ + if (isdigit((unsigned char)*fmt)) { + GET_NUMBER(width); + /* Do we have enough space to put number with + * required width ? + */ + if ((unsigned int)width >= maxsize - (dst - s)) + goto e2big_error; + } + + /* Left precision */ + if (*fmt == '#') { + if (!isdigit((unsigned char)*++fmt)) + goto format_error; + GET_NUMBER(left_prec); + if ((unsigned int)left_prec >= maxsize - (dst - s)) + goto e2big_error; + } + + /* Right precision */ + if (*fmt == '.') { + if (!isdigit((unsigned char)*++fmt)) + goto format_error; + GET_NUMBER(right_prec); + if ((unsigned int)right_prec >= maxsize - (dst - s) - left_prec) + goto e2big_error; + } + + /* Conversion Characters */ + switch (*fmt++) { + case 'i': /* use internaltion currency format */ + flags |= USE_INTL_CURRENCY; + break; + case 'n': /* use national currency format */ + flags &= ~(USE_INTL_CURRENCY); + break; + default: /* required character is missing or + premature EOS */ + goto format_error; + } + + if (currency_symbol != NULL) + free(currency_symbol); + if (flags & USE_INTL_CURRENCY) { + currency_symbol = strdup(lc->int_curr_symbol); + if (currency_symbol != NULL) { + space_char = currency_symbol[3]; + currency_symbol[3] = '\0'; + } + } else + currency_symbol = strdup(lc->currency_symbol); + + if (currency_symbol == NULL) + goto end_error; /* ENOMEM. */ + + /* value itself */ + value = va_arg(ap, double); + + /* detect sign */ + if (value < 0) { + flags |= IS_NEGATIVE; + value = -value; + } + + /* fill left_prec with amount of padding chars */ + if (left_prec >= 0) { + pad_size = __calc_left_pad((flags ^ IS_NEGATIVE), + currency_symbol) - __calc_left_pad(flags, currency_symbol); + if (pad_size < 0) + pad_size = 0; + } + + if (asciivalue != NULL) + free(asciivalue); + asciivalue = __format_grouped_double(value, &flags, left_prec, + right_prec, pad_char); + if (asciivalue == NULL) + goto end_error; /* errno already set */ + /* to ENOMEM by malloc() */ + + /* set some variables for later use */ + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); + + /* + * Description of some LC_MONETARY's values: + * + * p_cs_precedes & n_cs_precedes + * + * = 1 - $currency_symbol precedes the value + * for a monetary quantity with a non-negative value + * = 0 - symbol succeeds the value + * + * p_sep_by_space & n_sep_by_space + * + * = 0 - no space separates $currency_symbol + * from the value for a monetary quantity with a + * non-negative value + * = 1 - space separates the symbol from the value + * = 2 - space separates the symbol and the sign string, + * if adjacent. + * + * p_sign_posn & n_sign_posn + * + * = 0 - parentheses enclose the quantity and the + * $currency_symbol + * = 1 - the sign string precedes the quantity and the + * $currency_symbol + * = 2 - the sign string succeeds the quantity and the + * $currency_symbol + * = 3 - the sign string precedes the $currency_symbol + * = 4 - the sign string succeeds the $currency_symbol + * + */ + + tmpptr = dst; + + while (pad_size-- > 0) + PRINT(' '); + + if (sign_posn == 0 && (flags & IS_NEGATIVE)) + PRINT('('); + + if (cs_precedes == 1) { + if (sign_posn == 1 || sign_posn == 3) { + PRINTS(signstr); + if (sep_by_space == 2) /* XXX: ? */ + PRINT(' '); + } + + if (!(flags & SUPRESS_CURR_SYMBOL)) { + PRINTS(currency_symbol); + + if (sign_posn == 4) { + if (sep_by_space == 2) + PRINT(space_char); + PRINTS(signstr); + if (sep_by_space == 1) + PRINT(' '); + } else if (sep_by_space == 1) + PRINT(space_char); + } + } else if (sign_posn == 1) + PRINTS(signstr); + + PRINTS(asciivalue); + + if (cs_precedes == 0) { + if (sign_posn == 3) { + if (sep_by_space == 1) + PRINT(' '); + PRINTS(signstr); + } + + if (!(flags & SUPRESS_CURR_SYMBOL)) { + if ((sign_posn == 3 && sep_by_space == 2) + || (sep_by_space == 1 + && (sign_posn == 0 + || sign_posn == 1 + || sign_posn == 2 + || sign_posn == 4))) + PRINT(space_char); + PRINTS(currency_symbol); /* XXX: len */ + if (sign_posn == 4) { + if (sep_by_space == 2) + PRINT(' '); + PRINTS(signstr); + } + } + } + + if (sign_posn == 2) { + if (sep_by_space == 2) + PRINT(' '); + PRINTS(signstr); + } + + if (sign_posn == 0 && (flags & IS_NEGATIVE)) + PRINT(')'); + + if (dst - tmpptr < width) { + if (flags & LEFT_JUSTIFY) { + while (dst - tmpptr < width) + PRINT(' '); + } else { + pad_size = dst - tmpptr; + memmove(tmpptr + width - pad_size, tmpptr, pad_size); + memset(tmpptr, ' ', width - pad_size); + dst += width - pad_size; + } + } + } + + PRINT('\0'); + va_end(ap); + free(asciivalue); + free(currency_symbol); + return dst - s - 1; /* return size of put data except trailing '\0' */ + +e2big_error: + errno = E2BIG; + goto end_error; + +format_error: + errno = EINVAL; + +end_error: + sverrno = errno; + if (asciivalue != NULL) + free(asciivalue); + if (currency_symbol != NULL) + free(currency_symbol); + errno = sverrno; + va_end(ap); + return -1; +} + + +static void +__setup_vars(int flags, char *cs_precedes, char *sep_by_space, char *sign_posn, + char **signstr) +{ + struct lconv *lc = localeconv(); + + if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { + *cs_precedes = lc->int_n_cs_precedes; + *sep_by_space = lc->int_n_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; + *signstr = (lc->negative_sign == '\0') ? "-" : lc->negative_sign; + } else if (flags & USE_INTL_CURRENCY) { + *cs_precedes = lc->int_p_cs_precedes; + *sep_by_space = lc->int_p_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_p_sign_posn; + *signstr = lc->positive_sign; + } else if (flags & IS_NEGATIVE) { + *cs_precedes = lc->n_cs_precedes; + *sep_by_space = lc->n_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; + *signstr = (lc->negative_sign == '\0') ? "-" : lc->negative_sign; + } else { + *cs_precedes = lc->p_cs_precedes; + *sep_by_space = lc->p_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->p_sign_posn; + *signstr = lc->positive_sign; + } + + /* Set defult values for unspecified information. */ + if (*cs_precedes != 0) + *cs_precedes = 1; + if (*sep_by_space == CHAR_MAX) + *sep_by_space = 0; + if (*sign_posn == CHAR_MAX) + *sign_posn = 0; +} + + +static int +__calc_left_pad(int flags, char *cur_symb) +{ + char cs_precedes, sep_by_space, sign_posn, *signstr; + int left_chars = 0; + + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); + + if (cs_precedes != 0) { + left_chars += strlen(cur_symb); + if (sep_by_space != 0) + left_chars++; + } + + switch (sign_posn) { + case 1: + left_chars += strlen(signstr); + break; + case 3: + case 4: + if (cs_precedes != 0) + left_chars += strlen(signstr); + } + return left_chars; +} + + +static int +get_groups(int size, char *grouping) +{ + int chars = 0; + + if (*grouping == CHAR_MAX || *grouping <= 0) /* no grouping ? */ + return 0; + + while (size > (int)*grouping) { + chars++; + size -= (int)*grouping++; + /* no more grouping ? */ + if (*grouping == CHAR_MAX) + break; + /* rest grouping with same value ? */ + if (*grouping == 0) { + chars += (size - 1) / *(grouping - 1); + break; + } + } + return chars; +} + + +/* convert double to ASCII */ +static char * +__format_grouped_double(double value, int *flags, int left_prec, int right_prec, + int pad_char) +{ + char *rslt; + char *avalue; + int avalue_size; + char fmt[32]; + + size_t bufsize; + char *bufend; + + int padded; + + struct lconv *lc = localeconv(); + char *grouping; + char decimal_point; + char thousands_sep; + + int groups = 0; + + grouping = lc->mon_grouping; + decimal_point = *lc->mon_decimal_point; + if (decimal_point == '\0') + decimal_point = *lc->decimal_point; + thousands_sep = *lc->mon_thousands_sep; + if (thousands_sep == '\0') + thousands_sep = *lc->thousands_sep; + + /* fill left_prec with default value */ + if (left_prec == -1) + left_prec = 0; + + /* fill right_prec with default value */ + if (right_prec == -1) { + if (*flags & USE_INTL_CURRENCY) + right_prec = lc->int_frac_digits; + else + right_prec = lc->frac_digits; + + if (right_prec == CHAR_MAX) /* POSIX locale ? */ + right_prec = 2; + } + + if (*flags & NEED_GROUPING) + left_prec += get_groups(left_prec, grouping); + + /* convert to string */ + snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1, + right_prec); + avalue_size = asprintf(&avalue, fmt, value); + if (avalue_size < 0) + return NULL; + + /* make sure that we've enough space for result string */ + bufsize = strlen(avalue) * 2 + 1; + rslt = calloc(1, bufsize); + if (rslt == NULL) { + free(avalue); + return NULL; + } + bufend = rslt + bufsize - 1; /* reserve space for trailing '\0' */ + + /* skip spaces at beggining */ + padded = 0; + while (avalue[padded] == ' ') { + padded++; + avalue_size--; + } + + if (right_prec > 0) { + bufend -= right_prec; + memcpy(bufend, avalue + avalue_size + padded - right_prec, right_prec); + *--bufend = decimal_point; + avalue_size -= right_prec + 1; + } + + if ((*flags & NEED_GROUPING) && *grouping != CHAR_MAX && *grouping > 0 + && thousands_sep != '\0') { + while (avalue_size > (int)*grouping) { + GRPCPY(*grouping); + GRPSEP; + grouping++; + + /* no more grouping ? */ + if (*grouping == CHAR_MAX) + break; + + /* rest grouping with same value ? */ + if (*grouping == 0) { + grouping--; + while (avalue_size > *grouping) { + GRPCPY(*grouping); + GRPSEP; + } + } + } + if (avalue_size != 0) + GRPCPY(avalue_size); + padded -= groups; + } else { + bufend -= avalue_size; + memcpy(bufend, avalue + padded, avalue_size); + if (right_prec == 0) + padded--; /* decrease assumed $decimal_point */ + } + + /* do padding with pad_char */ + if (padded > 0) { + bufend -= padded; + memset(bufend, pad_char, padded); + } + + bufsize = bufsize - (bufend - rslt) + 1; + memmove(rslt, bufend, bufsize); + free(avalue); + + return rslt; +} diff --git a/src/system/libroot/posix/string/Jamfile b/src/system/libroot/posix/string/Jamfile index f4435c85a4..a3d76e4811 100644 --- a/src/system/libroot/posix/string/Jamfile +++ b/src/system/libroot/posix/string/Jamfile @@ -1,5 +1,7 @@ SubDir HAIKU_TOP src system libroot posix string ; +UsePrivateHeaders [ FDirName libroot locale ] ; + MergeObject posix_string.o : bcmp.c bcopy.c @@ -16,7 +18,7 @@ MergeObject posix_string.o : strchr.c strchrnul.c strcmp.c - strcoll.c + strcoll.cpp strcpy.c strcspn.c strdup.c @@ -35,7 +37,7 @@ MergeObject posix_string.o : strstr.c strtok.c strupr.c - strxfrm.c + strxfrm.cpp ; HaikuSubInclude arch $(TARGET_ARCH) ; diff --git a/src/system/libroot/posix/string/strcoll.c b/src/system/libroot/posix/string/strcoll.c deleted file mode 100644 index 26aba7e673..0000000000 --- a/src/system/libroot/posix/string/strcoll.c +++ /dev/null @@ -1,16 +0,0 @@ -/* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ - - -#include - - -int -strcoll(const char *a, const char *b) -{ - // ToDo: implement me properly! - return strcmp(a, b); -} - diff --git a/src/system/libroot/posix/string/strcoll.cpp b/src/system/libroot/posix/string/strcoll.cpp new file mode 100644 index 0000000000..906adb66cc --- /dev/null +++ b/src/system/libroot/posix/string/strcoll.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#define B_USE_POSITIVE_POSIX_ERRORS +#include +#include + +#include "LocaleBackend.h" + + +using BPrivate::gLocaleBackend; + + +extern "C" int +strcoll(const char *a, const char *b) +{ + if (gLocaleBackend != NULL) { + int result = 0; + status_t status = gLocaleBackend->Strcoll(a, b, result); + + if (status != B_OK) + errno = EINVAL; + + return result; + } + + return strcmp(a, b); +} diff --git a/src/system/libroot/posix/string/strxfrm.c b/src/system/libroot/posix/string/strxfrm.c deleted file mode 100644 index ac6b6a697b..0000000000 --- a/src/system/libroot/posix/string/strxfrm.c +++ /dev/null @@ -1,9 +0,0 @@ - -#include - -size_t -strxfrm(char *out, const char *in, size_t size) -{ - // TODO: To be implemented correctly when we have collation support. - return strlcpy(out, in, size); -} diff --git a/src/system/libroot/posix/string/strxfrm.cpp b/src/system/libroot/posix/string/strxfrm.cpp new file mode 100644 index 0000000000..daa97ece14 --- /dev/null +++ b/src/system/libroot/posix/string/strxfrm.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2005, Ingo Weinhold . + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#define B_USE_POSITIVE_POSIX_ERRORS +#include +#include + +#include "LocaleBackend.h" + + +using BPrivate::gLocaleBackend; + + +extern "C" size_t +strxfrm(char *out, const char *in, size_t size) +{ + if (gLocaleBackend != NULL) { + size_t outSize = 0; + status_t status = gLocaleBackend->Strxfrm(out, in, size, outSize); + + if (status != B_OK) + errno = EINVAL; + + return outSize; + } + + return strlcpy(out, in, size); +} diff --git a/src/system/libroot/posix/time/Jamfile b/src/system/libroot/posix/time/Jamfile index 6b358119d0..23d2c5430a 100644 --- a/src/system/libroot/posix/time/Jamfile +++ b/src/system/libroot/posix/time/Jamfile @@ -4,11 +4,12 @@ SubDir HAIKU_TOP src system libroot posix time ; SubDirCcFlags -DNOID -DTZDIR='get_timezones_directory()' -DUSG_COMPAT -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -DPCTS=1 -DSTD_INSPIRED ; +UsePrivateHeaders [ FDirName libroot locale ] ; UsePrivateHeaders [ FDirName libroot time ] ; UsePrivateSystemHeaders ; MergeObject posix_time.o : - asctime.c + asctime.cpp clock.c ctime.c difftime.c @@ -17,7 +18,7 @@ MergeObject posix_time.o : stime.c strftime.c strptime.c - timelocal.c + timelocal.cpp time.c wcsftime.c ; diff --git a/src/system/libroot/posix/time/asctime.c b/src/system/libroot/posix/time/asctime.cpp similarity index 55% rename from src/system/libroot/posix/time/asctime.c rename to src/system/libroot/posix/time/asctime.cpp index ec32e738d0..9761ad9b7d 100644 --- a/src/system/libroot/posix/time/asctime.c +++ b/src/system/libroot/posix/time/asctime.cpp @@ -1,5 +1,6 @@ -/* +/* * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -7,23 +8,18 @@ #include #include +#include "PosixLCTimeInfo.h" + + +using BPrivate::gPosixLCTimeInfo; + static char* print_time(char* buffer, size_t bufferSize, const struct tm* tm) { - // ToDo: this should probably use the locale kit to get these names - - static const char weekdays[][3] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - static const char months[][3] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - snprintf(buffer, bufferSize, "%.3s %.3s%3d %02d:%02d:%02d %d\n", - tm->tm_wday < 0 ? "???" : weekdays[tm->tm_wday % 7], - tm->tm_mon < 0 ? "???" : months[tm->tm_mon % 12], + tm->tm_wday < 0 ? "???" : gPosixLCTimeInfo.wday[tm->tm_wday % 7], + tm->tm_mon < 0 ? "???" : gPosixLCTimeInfo.mon[tm->tm_mon % 12], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, 1900 + tm->tm_year); @@ -31,17 +27,19 @@ print_time(char* buffer, size_t bufferSize, const struct tm* tm) } -char* +extern "C" char* asctime(const struct tm* tm) { - static char buffer[28]; - // is enough to hold normal dates + static char buffer[26]; + // That's enough to hold normal dates (i.e. with 4-digit years), for any + // other dates the behaviour of asctime() is undefined according to the + // POSIX Base Specifications Issue 7. return print_time(buffer, sizeof(buffer), tm); } -char* +extern "C" char* asctime_r(const struct tm* tm, char* buffer) { return print_time(buffer, 26, tm); diff --git a/src/system/libroot/posix/time/strftime.c b/src/system/libroot/posix/time/strftime.c index cf86bdc79e..8e029bba78 100644 --- a/src/system/libroot/posix/time/strftime.c +++ b/src/system/libroot/posix/time/strftime.c @@ -36,75 +36,9 @@ static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; #include "tzfile.h" #include "fcntl.h" #include "locale.h" +#include "timelocal.h" -struct lc_time_T { - const char * mon[MONSPERYEAR]; - const char * month[MONSPERYEAR]; - const char * wday[DAYSPERWEEK]; - const char * weekday[DAYSPERWEEK]; - const char * X_fmt; - const char * x_fmt; - const char * c_fmt; - const char * am; - const char * pm; - const char * date_fmt; -}; - -#ifdef LOCALE_HOME -#include "sys/stat.h" -static struct lc_time_T localebuf; -static struct lc_time_T * _loc P((void)); -#define Locale _loc() -#endif /* defined LOCALE_HOME */ -#ifndef LOCALE_HOME -#define Locale (&C_time_locale) -#endif /* !defined LOCALE_HOME */ - -static const struct lc_time_T C_time_locale = { - { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }, { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" - }, { - "Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat" - }, { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" - }, - - /* X_fmt */ - "%H:%M:%S", - - /* - ** x_fmt - ** C99 requires this format. - ** Using just numbers (as here) makes Quakers happier; - ** it's also compatible with SVR4. - */ - "%m/%d/%y", - - /* - ** c_fmt - ** C99 requires this format. - ** Previously this code used "%D %X", but we now conform to C99. - ** Note that - ** "%a %b %d %H:%M:%S %Y" - ** is used by Solaris 2.3. - */ - "%a %b %e %T %Y", - - /* am */ - "AM", - - /* pm */ - "PM", - - /* date_fmt */ - "%a %b %e %H:%M:%S %Z %Y" -}; +#define Locale __get_current_time_locale() static char * _add P((const char *, char *, const char *)); static char * _conv P((int, const char *, char *, const char *)); @@ -123,6 +57,8 @@ extern char * tzname[]; #define IN_THIS 2 #define IN_ALL 3 +#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU + size_t strftime(s, maxsize, format, t) char * const s; @@ -134,9 +70,6 @@ const struct tm * const t; int warn; tzset(); -#ifdef LOCALE_HOME - localebuf.mon[0] = 0; -#endif /* defined LOCALE_HOME */ warn = IN_NONE; p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn); #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU @@ -641,124 +574,3 @@ const char * const ptlim; pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim); return pt; } - -#ifdef LOCALE_HOME -static struct lc_time_T * -_loc P((void)) -{ - static const char locale_home[] = LOCALE_HOME; - static const char lc_time[] = "LC_TIME"; - static char * locale_buf; - - int fd; - int oldsun; /* "...ain't got nothin' to do..." */ - char * lbuf; - char * name; - char * p; - const char ** ap; - const char * plim; - char filename[FILENAME_MAX]; - struct stat st; - size_t namesize; - size_t bufsize; - - /* - ** Use localebuf.mon[0] to signal whether locale is already set up. - */ - if (localebuf.mon[0]) - return &localebuf; - name = setlocale(LC_TIME, (char *) NULL); - if (name == NULL || *name == '\0') - goto no_locale; - /* - ** If the locale name is the same as our cache, use the cache. - */ - lbuf = locale_buf; - if (lbuf != NULL && strcmp(name, lbuf) == 0) { - p = lbuf; - for (ap = (const char **) &localebuf; - ap < (const char **) (&localebuf + 1); - ++ap) - *ap = p += strlen(p) + 1; - return &localebuf; - } - /* - ** Slurp the locale file into the cache. - */ - namesize = strlen(name) + 1; - if (sizeof filename < - ((sizeof locale_home) + namesize + (sizeof lc_time))) - goto no_locale; - oldsun = 0; - (void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time); - fd = open(filename, O_RDONLY); - if (fd < 0) { - /* - ** Old Sun systems have a different naming and data convention. - */ - oldsun = 1; - (void) sprintf(filename, "%s/%s/%s", locale_home, - lc_time, name); - fd = open(filename, O_RDONLY); - if (fd < 0) - goto no_locale; - } - if (fstat(fd, &st) != 0) - goto bad_locale; - if (st.st_size <= 0) - goto bad_locale; - bufsize = namesize + st.st_size; - locale_buf = NULL; - lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize); - if (lbuf == NULL) - goto bad_locale; - (void) strcpy(lbuf, name); - p = lbuf + namesize; - plim = p + st.st_size; - if (read(fd, p, (size_t) st.st_size) != st.st_size) - goto bad_lbuf; - if (close(fd) != 0) - goto bad_lbuf; - /* - ** Parse the locale file into localebuf. - */ - if (plim[-1] != '\n') - goto bad_lbuf; - for (ap = (const char **) &localebuf; - ap < (const char **) (&localebuf + 1); - ++ap) { - if (p == plim) - goto bad_lbuf; - *ap = p; - while (*p != '\n') - ++p; - *p++ = '\0'; - } - if (oldsun) { - /* - ** SunOS 4 used an obsolescent format; see localdtconv(3). - ** c_fmt had the ``short format for dates and times together'' - ** (SunOS 4 date, "%a %b %e %T %Z %Y" in the C locale); - ** date_fmt had the ``long format for dates'' - ** (SunOS 4 strftime %C, "%A, %B %e, %Y" in the C locale). - ** Discard the latter in favor of the former. - */ - localebuf.date_fmt = localebuf.c_fmt; - } - /* - ** Record the successful parse in the cache. - */ - locale_buf = lbuf; - - return &localebuf; - -bad_lbuf: - free(lbuf); -bad_locale: - (void) close(fd); -no_locale: - localebuf = C_time_locale; - locale_buf = NULL; - return &localebuf; -} -#endif /* defined LOCALE_HOME */ diff --git a/src/system/libroot/posix/time/strptime.c b/src/system/libroot/posix/time/strptime.c index 9bf16a9fe8..02012365da 100644 --- a/src/system/libroot/posix/time/strptime.c +++ b/src/system/libroot/posix/time/strptime.c @@ -49,7 +49,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp) int i, len; int Ealternative, Oalternative; - struct lc_time_T *tptr = __get_current_time_locale(); + struct lc_time_t *tptr = __get_current_time_locale(); ptr = fmt; while (*ptr != 0) { diff --git a/src/system/libroot/posix/time/timelocal.c b/src/system/libroot/posix/time/timelocal.c deleted file mode 100644 index e457e48ff7..0000000000 --- a/src/system/libroot/posix/time/timelocal.c +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * Copyright (c) 2001 Alexey Zelkin - * Copyright (c) 1997 FreeBSD Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include "timelocal.h" - -#if 0 -static struct lc_time_T _time_locale; -static int _time_using_locale; -static char *time_locale_buf; -#endif - -#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) - -static const struct lc_time_T _C_time_locale = { - { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }, { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" - }, { - "Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat" - }, { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" - }, - - /* X_fmt */ - "%H:%M:%S", - - /* - * x_fmt - * Since the C language standard calls for - * "date, using locale's date format," anything goes. - * Using just numbers (as here) makes Quakers happier; - * it's also compatible with SVR4. - */ - "%m/%d/%y", - - /* - * c_fmt - */ - "%a %b %e %H:%M:%S %Y", - - /* am */ - "AM", - - /* pm */ - "PM", - - /* date_fmt */ - "%a %b %e %H:%M:%S %Z %Y", - - /* alt_month - * Standalone months forms for %OB - */ - { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" - }, - - /* md_order - * Month / day order in dates - */ - "md", - - /* ampm_fmt - * To determine 12-hour clock format time (empty, if N/A) - */ - "%I:%M:%S %p" -}; - -struct lc_time_T * -__get_current_time_locale(void) -{ - return -#if 0 - (_time_using_locale - ? &_time_locale - : -#endif - (struct lc_time_T *)&_C_time_locale; -} - -#if 0 -int -__time_load_locale(const char *name) -{ - return (__part_load_locale(name, &_time_using_locale, - &time_locale_buf, "LC_TIME", - LCTIME_SIZE, LCTIME_SIZE, - (const char **)&_time_locale)); -} -#endif diff --git a/src/system/libroot/posix/time/timelocal.cpp b/src/system/libroot/posix/time/timelocal.cpp new file mode 100644 index 0000000000..dc47773428 --- /dev/null +++ b/src/system/libroot/posix/time/timelocal.cpp @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * Copyright (c) 1997 FreeBSD Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include "timelocal.h" + +#include + +#include "LocaleBackend.h" +#include "PosixLCTimeInfo.h" + + +using BPrivate::gLocaleBackend; + + +extern "C" const lc_time_t* +__get_current_time_locale(void) +{ + if (gLocaleBackend) + return gLocaleBackend->LCTimeInfo(); + + return &BPrivate::gPosixLCTimeInfo; +} diff --git a/src/system/runtime_loader/Jamfile b/src/system/runtime_loader/Jamfile index 9bb0fe6b13..cfb8fc0e66 100644 --- a/src/system/runtime_loader/Jamfile +++ b/src/system/runtime_loader/Jamfile @@ -32,9 +32,8 @@ StaticLibrary libruntime_loader.a : errno.o fcntl.o - ctype-info.o - C-ctype.o - C_name.o + ctype.o + LocaleData.o memchr.o memcmp.o diff --git a/src/tests/system/libroot/posix/Jamfile b/src/tests/system/libroot/posix/Jamfile index 15c2ed0bbf..79cbd75c7c 100644 --- a/src/tests/system/libroot/posix/Jamfile +++ b/src/tests/system/libroot/posix/Jamfile @@ -3,12 +3,16 @@ SubDir HAIKU_TOP src tests system libroot posix ; UsePrivateHeaders libroot syslog_daemon ; +# filter warnings about strftime()-formats in locale_test +TARGET_WARNING_C++FLAGS on [ FGristFiles locale_test.o ] += -Wno-format ; + # POSIX/libc tests SimpleTest abort_test : abort_test.cpp ; SimpleTest SyslogTest : SyslogTest.cpp syslog.cpp ; SimpleTest clearenv : clearenv.cpp ; SimpleTest dirent_test : dirent_test.cpp ; SimpleTest flock_test : flock_test.cpp ; +SimpleTest locale_test : locale_test.cpp ; SimpleTest memalign_test : memalign_test.cpp ; SimpleTest mprotect_test : mprotect_test.cpp ; SimpleTest realtime_sem_test1 : realtime_sem_test1.cpp ; diff --git a/src/tests/system/libroot/posix/locale_test.cpp b/src/tests/system/libroot/posix/locale_test.cpp new file mode 100644 index 0000000000..63ce4a43e8 --- /dev/null +++ b/src/tests/system/libroot/posix/locale_test.cpp @@ -0,0 +1,1558 @@ +/* + * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de + * Distributed under the terms of the MIT License. + */ + +#define B_USE_POSITIVE_POSIX_ERRORS + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// #pragma mark - setlocale ---------------------------------------------------- + + +void +test_setlocale() +{ + const char* locales[] = { + "POSIX", + "C", + "de_DE", + "en_US", + "en_US.US-ASCII", + "hr_HR.ISO-8859-2", + "nl_NL", + "nb_NO", + "fr_FR.UTF-8@collation=phonebook", + "de_DE.iso8859-1", + "De_dE.IsO8859-15", + "de_DE.utf8", + "de_DE.UTF-8", + "de_DE@euro", + "de_DE@EURO", + "de_DE.utf-8@Euro", + "POSIX", + "C", + NULL + }; + const char* expectedLocales[] = { + "POSIX", + "POSIX", + "de_DE", + "en_US", + "en_US.US-ASCII", + "hr_HR.ISO-8859-2", + "nl_NL", + "nb_NO", + "fr_FR.UTF-8@collation=phonebook", + "de_DE.iso8859-1", + "De_dE.IsO8859-15", + "de_DE.utf8", + "de_DE.UTF-8", + "de_DE@euro", + "de_DE@EURO", + "de_DE.utf-8@Euro", + "POSIX", + "POSIX" + }; + const char* categoryNames[] = { + "LC_ALL", + "LC_COLLATE", + "LC_CTYPE", + "LC_MONETARY", + "LC_NUMERIC", + "LC_TIME", + "LC_MESSAGES" + }; + printf("setlocale()\n"); + + int problemCount = 0; + for (int i = 0; locales[i] != NULL; ++i) { + char* result = setlocale(LC_ALL, locales[i]); + if (!result || strcmp(result, expectedLocales[i]) != 0) { + printf("\tPROBLEM: setlocale(LC_ALL, \"%s\") = \"%s\" " + "(expected \"%s\")\n", + locales[i], result, expectedLocales[i]); + problemCount++; + } + } + + for (int i = 1; i <= LC_LAST; ++i) + setlocale(i, locales[i + 1]); + char* result = setlocale(LC_ALL, NULL); + const char* expectedResult + = "LC_COLLATE=de_DE;LC_CTYPE=en_US;LC_MESSAGES=nb_NO;" + "LC_MONETARY=en_US.US-ASCII;LC_NUMERIC=hr_HR.ISO-8859-2;" + "LC_TIME=nl_NL"; + if (!result || strcmp(result, expectedResult) != 0) { + printf("\tPROBLEM: setlocale(LC_ALL, NULL) = \"%s\" " + "(expected \"%s\")\n", result, expectedResult); + problemCount++; + } + + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +// #pragma mark - localeconv --------------------------------------------------- + + +void +dumpGrouping(const char* grouping, char* buf) +{ + for (char* bufPtr = buf; *grouping; ++grouping) + bufPtr += sprintf(bufPtr, "\\x%02x", *grouping); +} + + +void +test_localeconv(const char* locale, const lconv* localeConv) +{ + setlocale(LC_MONETARY, locale); + setlocale(LC_NUMERIC, locale); + printf("localeconv for '%s'\n", locale); + + int problemCount = 0; + struct lconv* lc = localeconv(); + if (!lc) + printf("not ok - got no result from localeconv()\n"); + else { + if (strcmp(lc->decimal_point, localeConv->decimal_point) != 0) { + printf("\tPROBLEM: lc.decimal_point = \"%s\" (expected \"%s\")\n", + lc->decimal_point, localeConv->decimal_point); + problemCount++; + } + if (strcmp(lc->thousands_sep, localeConv->thousands_sep) != 0) { + printf("\tPROBLEM: lc.thousands_sep = \"%s\" (expected \"%s\")\n", + lc->thousands_sep, localeConv->thousands_sep); + problemCount++; + } + if (strcmp(lc->grouping, localeConv->grouping) != 0) { + char gotGrouping[20], expectedGrouping[20]; + dumpGrouping(lc->grouping, gotGrouping); + dumpGrouping(localeConv->grouping, expectedGrouping); + printf("\tPROBLEM: lc.grouping = \"%s\" (expected \"%s\")\n", + gotGrouping, expectedGrouping); + problemCount++; + } + if (strcmp(lc->int_curr_symbol, localeConv->int_curr_symbol) != 0) { + printf("\tPROBLEM: lc.int_curr_symbol = \"%s\" (expected \"%s\")\n", + lc->int_curr_symbol, localeConv->int_curr_symbol); + problemCount++; + } + if (strcmp(lc->currency_symbol, localeConv->currency_symbol) != 0) { + printf("\tPROBLEM: lc.currency_symbol = \"%s\" (expected \"%s\")\n", + lc->currency_symbol, localeConv->currency_symbol); + problemCount++; + } + if (strcmp(lc->mon_decimal_point, localeConv->mon_decimal_point) != 0) { + printf("\tPROBLEM: lc.mon_decimal_point = \"%s\" " + "(expected \"%s\")\n", + lc->mon_decimal_point, localeConv->mon_decimal_point); + problemCount++; + } + if (strcmp(lc->mon_thousands_sep, localeConv->mon_thousands_sep) != 0) { + printf("\tPROBLEM: lc.mon_thousands_sep = \"%s\" " + "(expected \"%s\")\n", + lc->mon_thousands_sep, localeConv->mon_thousands_sep); + problemCount++; + } + if (strcmp(lc->mon_grouping, localeConv->mon_grouping) != 0) { + char gotGrouping[20], expectedGrouping[20]; + dumpGrouping(lc->mon_grouping, gotGrouping); + dumpGrouping(localeConv->mon_grouping, expectedGrouping); + printf("\tPROBLEM: lc.mon_grouping: \"%s\" (expected \"%s\")\n", + gotGrouping, expectedGrouping); + problemCount++; + } + if (strcmp(lc->positive_sign, localeConv->positive_sign) != 0) { + printf("\tPROBLEM: lc.positive_sign = \"%s\" (expected \"%s\")\n", + lc->positive_sign, localeConv->positive_sign); + problemCount++; + } + if (strcmp(lc->negative_sign, localeConv->negative_sign) != 0) { + printf("\tPROBLEM: lc.negative_sign = \"%s\" (expected \"%s\")\n", + lc->negative_sign, localeConv->negative_sign); + problemCount++; + } + if (lc->frac_digits != localeConv->frac_digits) { + printf("\tPROBLEM: lc.frac_digits = %d (expected %d)\n", + lc->frac_digits, localeConv->frac_digits); + problemCount++; + } + if (lc->int_frac_digits != localeConv->int_frac_digits) { + printf("\tPROBLEM: lc.int_frac_digits = %d (expected %d)\n", + lc->int_frac_digits, localeConv->int_frac_digits); + problemCount++; + } + if (lc->p_cs_precedes != localeConv->p_cs_precedes) { + printf("\tPROBLEM: lc.p_cs_precedes = %d (expected %d)\n", + lc->p_cs_precedes, localeConv->p_cs_precedes); + problemCount++; + } + if (lc->p_sep_by_space != localeConv->p_sep_by_space) { + printf("\tPROBLEM: lc.p_sep_by_space = %d (expected %d)\n", + lc->p_sep_by_space, localeConv->p_sep_by_space); + problemCount++; + } + if (lc->p_sign_posn != localeConv->p_sign_posn) { + printf("\tPROBLEM: lc.p_sign_posn = %d (expected %d)\n", + lc->p_sign_posn, localeConv->p_sign_posn); + problemCount++; + } + if (lc->n_cs_precedes != localeConv->n_cs_precedes) { + printf("\tPROBLEM: lc.n_cs_precedes = %d (expected %d)\n", + lc->n_cs_precedes, localeConv->n_cs_precedes); + problemCount++; + } + if (lc->n_sep_by_space != localeConv->n_sep_by_space) { + printf("\tPROBLEM: lc.n_sep_by_space = %d (expected %d)\n", + lc->n_sep_by_space, localeConv->n_sep_by_space); + problemCount++; + } + if (lc->n_sign_posn != localeConv->n_sign_posn) { + printf("\tPROBLEM: lc.n_sign_posn = %d (expected %d)\n", + lc->n_sign_posn, localeConv->n_sign_posn); + problemCount++; + } + if (lc->int_p_cs_precedes != localeConv->int_p_cs_precedes) { + printf("\tPROBLEM: lc.int_p_cs_precedes = %d (expected %d)\n", + lc->int_p_cs_precedes, localeConv->int_p_cs_precedes); + problemCount++; + } + if (lc->int_p_sep_by_space != localeConv->int_p_sep_by_space) { + printf("\tPROBLEM: lc.int_p_sep_by_space = %d (expected %d)\n", + lc->int_p_sep_by_space, localeConv->int_p_sep_by_space); + problemCount++; + } + if (lc->int_p_sign_posn != localeConv->int_p_sign_posn) { + printf("\tPROBLEM: lc.int_p_sign_posn = %d (expected %d)\n", + lc->int_p_sign_posn, localeConv->int_p_sign_posn); + problemCount++; + } + if (lc->int_n_cs_precedes != localeConv->int_n_cs_precedes) { + printf("\tPROBLEM: lc.int_n_cs_precedes = %d (expected %d)\n", + lc->int_n_cs_precedes, localeConv->int_n_cs_precedes); + problemCount++; + } + if (lc->int_n_sep_by_space != localeConv->int_n_sep_by_space) { + printf("\tPROBLEM: lc.int_n_sep_by_space = %d (expected %d)\n", + lc->int_n_sep_by_space, localeConv->int_n_sep_by_space); + problemCount++; + } + if (lc->int_n_sign_posn != localeConv->int_n_sign_posn) { + printf("\tPROBLEM: lc.int_n_sign_posn = %d (expected %d)\n", + lc->int_n_sign_posn, localeConv->int_n_sign_posn); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_localeconv() +{ + const lconv lconv_posix = { + (char*)".", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + (char*)"", + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX + }; + test_localeconv("POSIX", &lconv_posix); + + const lconv lconv_de = { + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"EUR ", + (char*)"€", + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 0, + 1, + 0, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 1, + 1 + }; + test_localeconv("de_DE", &lconv_de); + + const lconv lconv_de_iso = { + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"EUR ", + (char*)"EUR", + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 0, + 1, + 0, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 1, + 1 + }; + test_localeconv("de_DE.ISO8859-1", &lconv_de_iso); + + const lconv lconv_hr = { + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"HRK ", + (char*)"kn", + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 0, + 1, + 0, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 1, + 1 + }; + test_localeconv("hr_HR.ISO8859-2", &lconv_hr); + + const lconv lconv_de_CH = { + (char*)".", + (char*)"'", + (char*)"\x03", + (char*)"CHF ", + (char*)"CHF", + (char*)".", + (char*)"'", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 1, + 1, + 1, + 0, + 4, + 4, + 1, + 1, + 1, + 0, + 4, + 4 + }; + test_localeconv("de_CH", &lconv_de_CH); + + const lconv lconv_gu_IN = { + (char*)".", + (char*)",", + (char*)"\x03\x02", + (char*)"INR ", + (char*)"રુ", + (char*)".", + (char*)",", + (char*)"\x03\x02", + (char*)"", + (char*)"-", + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + }; + test_localeconv("gu_IN", &lconv_gu_IN); + + const lconv lconv_it = { + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"EUR ", + (char*)"€", + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + }; + test_localeconv("it_IT", &lconv_it); + + const lconv lconv_nl = { + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"EUR ", + (char*)"€", + (char*)",", + (char*)".", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 1, + 1, + 1, + 1, + 2, + 2, + 1, + 1, + 1, + 1, + 2, + 2 + }; + test_localeconv("nl_NL", &lconv_nl); + + const lconv lconv_nb = { + (char*)",", + (char*)" ", + (char*)"\x03", + (char*)"NOK ", + (char*)"kr", + (char*)",", + (char*)" ", + (char*)"\x03", + (char*)"", + (char*)"-", + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + }; + test_localeconv("nb_NO", &lconv_nb); +} + + +// #pragma mark - strftime ----------------------------------------------------- + + +struct strftime_data { + const char* format; + const char* result; +}; + + +void +test_strftime(const char* locale, const strftime_data data[]) +{ + setlocale(LC_TIME, locale); + printf("strftime for '%s'\n", locale); + + time_t nowSecs = 1279391169; // pure magic + tm* now = localtime(&nowSecs); + int problemCount = 0; + for(int i = 0; data[i].format != NULL; ++i) { + char buf[100]; + strftime(buf, 100, data[i].format, now); + if (strcmp(buf, data[i].result) != 0) { + printf("\tPROBLEM: strftime(\"%s\") = \"%s\" (expected \"%s\")\n", + data[i].format, buf, data[i].result); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_strftime() +{ + setenv("TZ", "GMT", 1); + + const strftime_data strftime_posix[] = { + { "%c", "Sat Jul 17 18:26:09 2010" }, + { "%x", "07/17/10" }, + { "%X", "18:26:09" }, + { "%a", "Sat" }, + { "%A", "Saturday" }, + { "%b", "Jul" }, + { "%B", "July" }, + { NULL, NULL } + }; + test_strftime("POSIX", strftime_posix); + + const strftime_data strftime_de[] = { + { "%c", "Samstag, 17. Juli 2010 18:26:09 GMT" }, + { "%x", "17.07.2010" }, + { "%X", "18:26:09" }, + { "%a", "Sa." }, + { "%A", "Samstag" }, + { "%b", "Jul" }, + { "%B", "Juli" }, + { NULL, NULL } + }; + test_strftime("de_DE.UTF-8", strftime_de); + + const strftime_data strftime_hr[] = { + { "%c", "subota, 17. srpnja 2010. 18:26:09 GMT" }, + { "%x", "17. 07. 2010." }, + { "%X", "18:26:09" }, + { "%a", "sub" }, + { "%A", "subota" }, + { "%b", "srp" }, + { "%B", "srpnja" }, + { NULL, NULL } + }; + test_strftime("hr_HR.ISO8859-2", strftime_hr); + + const strftime_data strftime_gu[] = { + { "%c", "શનિવાર, 17 જુલાઈ, 2010 06:26:09 PM GMT" }, + { "%x", "17 જુલાઈ, 2010" }, + { "%X", "06:26:09 PM" }, + { "%a", "શનિ" }, + { "%A", "શનિવાર" }, + { "%b", "જુલાઈ" }, + { "%B", "જુલાઈ" }, + { NULL, NULL } + }; + test_strftime("gu_IN", strftime_gu); + + const strftime_data strftime_it[] = { + { "%c", "sabato 17 luglio 2010 18:26:09 GMT" }, + { "%x", "17/lug/2010" }, + { "%X", "18:26:09" }, + { "%a", "sab" }, + { "%A", "sabato" }, + { "%b", "lug" }, + { "%B", "luglio" }, + { NULL, NULL } + }; + test_strftime("it_IT", strftime_it); + + const strftime_data strftime_nl[] = { + { "%c", "zaterdag 17 juli 2010 18:26:09 GMT" }, + { "%x", "17 jul. 2010" }, + { "%X", "18:26:09" }, + { "%a", "za" }, + { "%A", "zaterdag" }, + { "%b", "jul." }, + { "%B", "juli" }, + { NULL, NULL } + }; + test_strftime("nl_NL", strftime_nl); + + const strftime_data strftime_nb[] = { + { "%c", "lørdag 17. juli 2010 kl. 18:26:09 GMT" }, + { "%x", "17. juli 2010" }, + { "%X", "18:26:09" }, + { "%a", "lør." }, + { "%A", "lørdag" }, + { "%b", "juli" }, + { "%B", "juli" }, + { NULL, NULL } + }; + test_strftime("nb_NO", strftime_nb); +} + + +// #pragma mark - ctype -------------------------------------------------------- + + +unsigned short +determineFullClassInfo(int i) +{ + unsigned short classInfo = 0; + + if (isblank(i)) + classInfo |= _ISblank; + if (iscntrl(i)) + classInfo |= _IScntrl; + if (ispunct(i)) + classInfo |= _ISpunct; + if (isalnum(i)) + classInfo |= _ISalnum; + if (isupper(i)) + classInfo |= _ISupper; + if (islower(i)) + classInfo |= _ISlower; + if (isalpha(i)) + classInfo |= _ISalpha; + if (isdigit(i)) + classInfo |= _ISdigit; + if (isxdigit(i)) + classInfo |= _ISxdigit; + if (isspace(i)) + classInfo |= _ISspace; + if (isprint(i)) + classInfo |= _ISprint; + if (isgraph(i)) + classInfo |= _ISgraph; + + return classInfo; +} + + +void +test_ctype(const char* locale, const unsigned short int classInfos[], + const int toLowerMap[], const int toUpperMap[]) +{ + setlocale(LC_CTYPE, locale); + printf("ctype of %s locale\n", locale); + + int problemCount = 0; + for (int i = 0; i < 256; ++i) { + unsigned short classInfo = determineFullClassInfo(i); + + if (classInfo != classInfos[i]) { + printf("\tPROBLEM: %d = %x (expected %x)\n", i, classInfo, + classInfos[i]); + problemCount++; + } + int lower = tolower(i); + if (lower != toLowerMap[i]) { + printf("\tPROBLEM: tolower(%d) = %x (expected %x)\n", i, lower, + toLowerMap[i]); + problemCount++; + } + int upper = toupper(i); + if (upper != toUpperMap[i]) { + printf("\tPROBLEM: toupper(%d) = %x (expected %x)\n", i, upper, + toUpperMap[i]); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_ctype() +{ + const unsigned short int classInfos_posix[256] = { + /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, + /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 24 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 32 */ _ISblank|_ISspace|_ISprint, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 40 */ _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 48 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, + /* 56 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 64 */ _ISpunct|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 72 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 80 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 88 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 96 */ _ISpunct|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 104 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 112 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 120 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _IScntrl, + /* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 136 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 152 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 168 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 184 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 200 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 216 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 232 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 248 */ 0, 0, 0, 0, 0, 0, 0, 0, + }; + const int toLowerMap_posix[256] = { + /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, + /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, + /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, + /* 24 */ 24, 25, 26, 27, 28, 29, 30, 31, + /* 32 */ 32, 33, 34, 35, 36, 37, 38, 39, + /* 40 */ 40, 41, 42, 43, 44, 45, 46, 47, + /* 48 */ '0', '1', '2', '3', '4', '5', '6', '7', + /* 56 */ '8', '9', 58, 59, 60, 61, 62, 63, + /* 64 */ 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 72 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 80 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 88 */ 'x', 'y', 'z', 91, 92, 93, 94, 95, + /* 96 */ 96, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 104 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 112 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 120 */ 'x', 'y', 'z', 123, 124, 125, 126, 127, + /* 128 */ 128, 129, 130, 131, 132, 133, 134, 135, + /* 136 */ 136, 137, 138, 139, 140, 141, 142, 143, + /* 144 */ 144, 145, 146, 147, 148, 149, 150, 151, + /* 152 */ 152, 153, 154, 155, 156, 157, 158, 159, + /* 160 */ 160, 161, 162, 163, 164, 165, 166, 167, + /* 168 */ 168, 169, 170, 171, 172, 173, 174, 175, + /* 176 */ 176, 177, 178, 179, 180, 181, 182, 183, + /* 184 */ 184, 185, 186, 187, 188, 189, 190, 191, + /* 192 */ 192, 193, 194, 195, 196, 197, 198, 199, + /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, + /* 208 */ 208, 209, 210, 211, 212, 213, 214, 215, + /* 216 */ 216, 217, 218, 219, 220, 221, 222, 223, + /* 224 */ 224, 225, 226, 227, 228, 229, 230, 231, + /* 232 */ 232, 233, 234, 235, 236, 237, 238, 239, + /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, + /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, + }; + const int toUpperMap_posix[256] = { + /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, + /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, + /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, + /* 24 */ 24, 25, 26, 27, 28, 29, 30, 31, + /* 32 */ 32, 33, 34, 35, 36, 37, 38, 39, + /* 40 */ 40, 41, 42, 43, 44, 45, 46, 47, + /* 48 */ '0', '1', '2', '3', '4', '5', '6', '7', + /* 56 */ '8', '9', 58, 59, 60, 61, 62, 63, + /* 64 */ 64, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + /* 72 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + /* 80 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + /* 88 */ 'X', 'Y', 'Z', 91, 92, 93, 94, 95, + /* 96 */ 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + /* 104 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + /* 112 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + /* 120 */ 'X', 'Y', 'Z', 123, 124, 125, 126, 127, + /* 128 */ 128, 129, 130, 131, 132, 133, 134, 135, + /* 136 */ 136, 137, 138, 139, 140, 141, 142, 143, + /* 144 */ 144, 145, 146, 147, 148, 149, 150, 151, + /* 152 */ 152, 153, 154, 155, 156, 157, 158, 159, + /* 160 */ 160, 161, 162, 163, 164, 165, 166, 167, + /* 168 */ 168, 169, 170, 171, 172, 173, 174, 175, + /* 176 */ 176, 177, 178, 179, 180, 181, 182, 183, + /* 184 */ 184, 185, 186, 187, 188, 189, 190, 191, + /* 192 */ 192, 193, 194, 195, 196, 197, 198, 199, + /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, + /* 208 */ 208, 209, 210, 211, 212, 213, 214, 215, + /* 216 */ 216, 217, 218, 219, 220, 221, 222, 223, + /* 224 */ 224, 225, 226, 227, 228, 229, 230, 231, + /* 232 */ 232, 233, 234, 235, 236, 237, 238, 239, + /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, + /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, + }; + test_ctype("POSIX", classInfos_posix, toLowerMap_posix, toUpperMap_posix); + + const unsigned short int classInfos_de[256] = { + /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, + /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 24 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 32 */ _ISblank|_ISspace|_ISprint, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 40 */ _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 48 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, + /* 56 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 64 */ _ISpunct|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 72 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 80 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 88 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 96 */ _ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 104 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 112 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 120 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _IScntrl, + /* 128 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl|_ISspace, _IScntrl, _IScntrl, + /* 136 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 144 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 152 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 160 */ _ISprint|_ISspace|_ISblank, _ISprint|_ISgraph|_ISpunct, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, + /* 168 */ _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISpunct, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, + /* 176 */ _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph, _ISprint|_ISgraph|_ISpunct, + /* 184 */ _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISpunct, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph|_ISpunct, + /* 192 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, + /* 200 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, + /* 208 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph, + /* 216 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISupper, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, + /* 224 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, + /* 232 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, + /* 240 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph, + /* 248 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, + }; + const int toLowerMap_de[256] = { + /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, + /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, + /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, + /* 24 */ 24, 25, 26, 27, 28, 29, 30, 31, + /* 32 */ 32, 33, 34, 35, 36, 37, 38, 39, + /* 40 */ 40, 41, 42, 43, 44, 45, 46, 47, + /* 48 */ '0', '1', '2', '3', '4', '5', '6', '7', + /* 56 */ '8', '9', 58, 59, 60, 61, 62, 63, + /* 64 */ 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 72 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 80 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 88 */ 'x', 'y', 'z', 91, 92, 93, 94, 95, + /* 96 */ 96, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 104 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 112 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 120 */ 'x', 'y', 'z', 123, 124, 125, 126, 127, + /* 128 */ 128, 129, 130, 131, 132, 133, 134, 135, + /* 136 */ 136, 137, 138, 139, 140, 141, 142, 143, + /* 144 */ 144, 145, 146, 147, 148, 149, 150, 151, + /* 152 */ 152, 153, 154, 155, 156, 157, 158, 159, + /* 160 */ 160, 161, 162, 163, 164, 165, 166, 167, + /* 168 */ 168, 169, 170, 171, 172, 173, 174, 175, + /* 176 */ 176, 177, 178, 179, 180, 181, 182, 183, + /* 184 */ 184, 185, 186, 187, 188, 189, 190, 191, + /* 192 */ 224, 225, 226, 227, 228, 229, 230, 231, + /* 200 */ 232, 233, 234, 235, 236, 237, 238, 239, + /* 208 */ 240, 241, 242, 243, 244, 245, 246, 215, + /* 216 */ 248, 249, 250, 251, 252, 253, 254, 223, + /* 224 */ 224, 225, 226, 227, 228, 229, 230, 231, + /* 232 */ 232, 233, 234, 235, 236, 237, 238, 239, + /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, + /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, + }; + const int toUpperMap_de[256] = { + /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, + /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, + /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, + /* 24 */ 24, 25, 26, 27, 28, 29, 30, 31, + /* 32 */ 32, 33, 34, 35, 36, 37, 38, 39, + /* 40 */ 40, 41, 42, 43, 44, 45, 46, 47, + /* 48 */ '0', '1', '2', '3', '4', '5', '6', '7', + /* 56 */ '8', '9', 58, 59, 60, 61, 62, 63, + /* 64 */ 64, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + /* 72 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + /* 80 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + /* 88 */ 'X', 'Y', 'Z', 91, 92, 93, 94, 95, + /* 96 */ 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + /* 104 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + /* 112 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + /* 120 */ 'X', 'Y', 'Z', 123, 124, 125, 126, 127, + /* 128 */ 128, 129, 130, 131, 132, 133, 134, 135, + /* 136 */ 136, 137, 138, 139, 140, 141, 142, 143, + /* 144 */ 144, 145, 146, 147, 148, 149, 150, 151, + /* 152 */ 152, 153, 154, 155, 156, 157, 158, 159, + /* 160 */ 160, 161, 162, 163, 164, 165, 166, 167, + /* 168 */ 168, 169, 170, 171, 172, 173, 174, 175, + /* 176 */ 176, 177, 178, 179, 180, 181, 182, 183, + /* 184 */ 184, 185, 186, 187, 188, 189, 190, 191, + /* 192 */ 192, 193, 194, 195, 196, 197, 198, 199, + /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, + /* 208 */ 208, 209, 210, 211, 212, 213, 214, 215, + /* 216 */ 216, 217, 218, 219, 220, 221, 222, 223, + /* 224 */ 192, 193, 194, 195, 196, 197, 198, 199, + /* 232 */ 200, 201, 202, 203, 204, 205, 206, 207, + /* 240 */ 208, 209, 210, 211, 212, 213, 214, 247, + /* 248 */ 216, 217, 218, 219, 220, 221, 222, 255, + }; + test_ctype("de_DE.ISO8859-1", classInfos_de, toLowerMap_de, toUpperMap_de); + + const unsigned short int classInfos_utf8[256] = { + /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, + /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 24 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, + /* 32 */ _ISblank|_ISspace|_ISprint, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 40 */ _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 48 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, + /* 56 */ _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISdigit|_ISxdigit|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 64 */ _ISpunct|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 72 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 80 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, + /* 88 */ _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISupper|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, + /* 96 */ _ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISxdigit|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 104 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 112 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, + /* 120 */ _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISalnum|_ISlower|_ISalpha|_ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _ISpunct|_ISprint|_ISgraph, _ISprint|_ISgraph, _IScntrl, + /* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 136 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 152 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 168 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 184 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 200 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 216 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 232 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, + /* 248 */ 0, 0, 0, 0, 0, 0, 0, 0, + }; + test_ctype("de_DE.UTF-8", classInfos_utf8, toLowerMap_posix, + toUpperMap_posix); +} + + +// #pragma mark - wctype ------------------------------------------------------- + + +unsigned short +determineWideFullClassInfo(int i) +{ + unsigned short classInfo = 0; + + if (iswblank(i)) + classInfo |= _ISblank; + if (iswcntrl(i)) + classInfo |= _IScntrl; + if (iswpunct(i)) + classInfo |= _ISpunct; + if (iswalnum(i)) + classInfo |= _ISalnum; + if (iswupper(i)) + classInfo |= _ISupper; + if (iswlower(i)) + classInfo |= _ISlower; + if (iswalpha(i)) + classInfo |= _ISalpha; + if (iswdigit(i)) + classInfo |= _ISdigit; + if (iswxdigit(i)) + classInfo |= _ISxdigit; + if (iswspace(i)) + classInfo |= _ISspace; + if (iswprint(i)) + classInfo |= _ISprint; + if (iswgraph(i)) + classInfo |= _ISgraph; + + return classInfo; +} + + +void +test_wctype(const char* locale, const wchar_t* text, + const unsigned short int wcs[], const unsigned short int classInfos[]) +{ + setlocale(LC_CTYPE, locale); + printf("wctype of %s locale\n", locale); + + int problemCount = 0; + wint_t wc = *text; + for (int i = 0; i < 48; wc = *++text, ++i) { + unsigned short classInfo = determineWideFullClassInfo(wc); + if (wc != wcs[i]) { + printf("\tPROBLEM: wc for char #%d = %x (expected %x)\n", i, wc, + wcs[i]); + problemCount++; + } + + if (classInfo != classInfos[i]) { + printf("\tPROBLEM: classinfo for #%d = %x (expected %x)\n", i, + classInfo, classInfos[i]); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_wctype() +{ + // haiku wide chars are always in UTF32, so nothing should change between + // different locales + + const wchar_t* text = L"Hi there, how do you do? (äÜößáéúíó€'¤¹²$%#@) 12"; + + const unsigned short int wcs[48] = { + 0x48, 0x69, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, + 0x2c, 0x20, 0x68, 0x6f, 0x77, 0x20, 0x64, 0x6f, + 0x20, 0x79, 0x6f, 0x75, 0x20, 0x64, 0x6f, 0x3f, + 0x20, 0x28, 0xe4, 0xdc, 0xf6, 0xdf, 0xe1, 0xe9, + 0xfa, 0xed, 0xf3, 0x20ac, 0x27, 0xa4, 0xb9, 0xb2, + 0x24, 0x25, 0x23, 0x40, 0x29, 0x20, 0x31, 0x32 + }; + const unsigned short int classInfos[48] = { + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISupper, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower|_ISxdigit, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower|_ISxdigit, + _ISprint|_ISgraph|_ISpunct, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower|_ISxdigit, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower|_ISxdigit, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISpunct, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISpunct, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISupper, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph|_ISalpha|_ISalnum|_ISlower, + _ISprint|_ISgraph, + _ISprint|_ISgraph|_ISpunct, + _ISprint|_ISgraph, + _ISprint|_ISgraph, + _ISprint|_ISgraph, + _ISprint|_ISgraph, + _ISpunct|_ISprint|_ISgraph, + _ISpunct|_ISprint|_ISgraph, + _ISpunct|_ISprint|_ISgraph, + _ISpunct|_ISprint|_ISgraph, + _ISspace|_ISprint|_ISblank, + _ISprint|_ISgraph|_ISalnum|_ISdigit|_ISxdigit, + _ISprint|_ISgraph|_ISalnum|_ISdigit|_ISxdigit + }; + + test_wctype("POSIX", text, wcs, classInfos); + test_wctype("de_DE.ISO8859-1", text, wcs, classInfos); + test_wctype("de_DE.ISO8859-15", text, wcs, classInfos); + test_wctype("de_DE.UTF-8", text, wcs, classInfos); +} + + +void +test_wctrans(const char* locale, const wchar_t* text, wctrans_t transition, + const wchar_t* expectedResult) +{ + setlocale(LC_CTYPE, locale); + printf("towctrans(%s) of %s locale\n", + transition == _ISlower ? "tolower" : "toupper", locale); + + int problemCount = 0; + wint_t wc = *text; + for (int i = 0; wc != 0; wc = *++text, ++i) { + errno = 0; + wint_t result = towctrans(wc, transition); + if (result != expectedResult[i] || errno != 0) { + printf("\tPROBLEM: result for char #%d = %x (expected %x), " + "errno = %x (expected %x)\n", + i, result, expectedResult[i], errno, 0); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_wctrans() +{ + // haiku wide chars are always in UTF32, so nothing should change between + // different locales + + setlocale(LC_CTYPE, "POSIX"); + printf("wctrans setup\n"); + + int problemCount = 0; + errno = 0; + wctrans_t toU = wctrans("toupper"); + if (errno != 0 || toU != _ISupper) { + printf("\tPROBLEM: wctrans(\"upper\") = %x (expected %x), " + "errno=%x (expected %x)\n", + toU, _ISupper, errno, 0); + problemCount++; + } + errno = 0; + wctrans_t toL = wctrans("tolower"); + if (errno != 0 || toL != _ISlower) { + printf("\tPROBLEM: wctrans(\"lower\") = %x (expected %x), " + "errno=%x (expected %x)\n", + toL, _ISlower, errno, 0); + problemCount++; + } + errno = 0; + wctrans_t invalid1 = wctrans(NULL); + if (errno != EINVAL || invalid1 != 0) { + printf("\tPROBLEM: wctrans(NULL) = %x (expected %x), " + "errno=%x (expected %x)\n", + invalid1, 0, errno, EINVAL); + problemCount++; + } + errno = 0; + wctrans_t invalid2 = wctrans("invalid"); + if (errno != EINVAL || invalid2 != 0) { + printf("\tPROBLEM: wctrans(\"invalid\") = %x (expected %x), " + "errno=%x (expected %x)\n", + invalid2, 0, errno, EINVAL); + problemCount++; + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); + + const wchar_t* text = L"Hi there, how do you do? (äÜößáéúíó€'¤¹²$%#@) 12"; + const wchar_t* textU = L"HI THERE, HOW DO YOU DO? (ÄÜÖßÁÉÚÍÓ€'¤¹²$%#@) 12"; + const wchar_t* textL = L"hi there, how do you do? (äüößáéúíó€'¤¹²$%#@) 12"; + + test_wctrans("POSIX", text, toU, textU); + test_wctrans("de_DE.ISO8859-1", text, toU, textU); + test_wctrans("de_DE.ISO8859-15", text, toU, textU); + test_wctrans("de_DE.UTF-8", text, toU, textU); + test_wctrans("fr_Fr", text, toU, textU); + + test_wctrans("POSIX", text, toL, textL); + test_wctrans("de_DE.ISO8859-1", text, toL, textL); + test_wctrans("de_DE.ISO8859-15", text, toL, textL); + test_wctrans("de_DE.UTF-8", text, toL, textL); + test_wctrans("fr_Fr", text, toL, textL); +} + + +// #pragma mark - nl_langinfo -------------------------------------------------- + + +void +test_langinfo(const char* locale, const char* langinfos[]) +{ + setlocale(LC_ALL, locale); + printf("langinfo of %s locale\n", locale); + + int problemCount = 0; + for (int i = -1; langinfos[i + 1] != NULL; ++i) { + const char* langinfo = nl_langinfo(i); + if (strcmp(langinfo, langinfos[i + 1]) != 0) { + printf("\tPROBLEM: langinfo for #%d = '%s' (expected '%s')\n", i, + langinfo, langinfos[i + 1]); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_langinfo() +{ + const char* li_posix[] = { + "", // out of bounds + "US-ASCII", + "%a %b %e %H:%M:%S %Y", + "%m/%d/%y", + "%H:%M:%S", + "%I:%M:%S %p", + "AM", + "PM", + + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday", + + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December", + + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + + "%EC, %Ey, %EY", + "%Ex", + "%Ec", + "%EX", + "%O", + + ".", + "", + + "^[yY]", + "^[nN]", + + "", + + "", // out of bounds + NULL + }; + test_langinfo("POSIX", li_posix); + + const char* li_de[] = { + "", // out of bounds + "UTF-8", + "%A, %e. %B %Y %H:%M:%S %Z", + "%d.%m.%Y", + "%H:%M:%S", + "%I:%M:%S %p", + "vorm.", + "nachm.", + + "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", + "Samstag", + + "So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", + + "Januar", "Februar", "März", "April", "Mai", "Juni", + "Juli", "August", "September", "Oktober", "November", "Dezember", + + "Jan", "Feb", "Mär", "Apr", "Mai", "Jun", + "Jul", "Aug", "Sep", "Okt", "Nov", "Dez", + + "%EC, %Ey, %EY", + "%Ex", + "%Ec", + "%EX", + "%O", + + ",", + ".", + + "^[yY]", + "^[nN]", + + "€", + + "", // out of bounds + NULL, + }; + test_langinfo("de_DE.UTF-8", li_de); + + const char* li_de_iso[] = { + "", // out of bounds + "ISO8859-15", + "%A, %e. %B %Y %H:%M:%S %Z", + "%d.%m.%Y", + "%H:%M:%S", + "%I:%M:%S %p", + "vorm.", + "nachm.", + + "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", + "Samstag", + + "So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", + + "Januar", "Februar", "M\xE4rz", "April", "Mai", "Juni", + "Juli", "August", "September", "Oktober", "November", "Dezember", + + "Jan", "Feb", "M\xE4r", "Apr", "Mai", "Jun", + "Jul", "Aug", "Sep", "Okt", "Nov", "Dez", + + "%EC, %Ey, %EY", + "%Ex", + "%Ec", + "%EX", + "%O", + + ",", + ".", + + "^[yY]", + "^[nN]", + + "\xA4", + + "", // out of bounds + NULL + }; + test_langinfo("de_DE.ISO8859-15", li_de_iso); +} + + +// #pragma mark - collation ---------------------------------------------------- + + +struct coll_data { + const char* a; + const char* b; + int result; + int err; +}; + + +static int sign (int a) +{ + if (a < 0) + return -1; + if (a > 0) + return 1; + return 0; +} + + +void +test_coll(bool useStrxfrm, const char* locale, const coll_data coll[]) +{ + setlocale(LC_COLLATE, locale); + printf("%s in %s locale\n", useStrxfrm ? "strxfrm" : "strcoll", locale); + + int problemCount = 0; + for (unsigned int i = 0; i < sizeof(coll) / sizeof(coll_data); ++i) { + errno = 0; + int result; + char funcCall[100]; + if (useStrxfrm) { + char sortKeyA[100], sortKeyB[100]; + strxfrm(sortKeyA, coll[i].a, 100); + strxfrm(sortKeyB, coll[i].b, 100); + result = sign(strcmp(sortKeyA, sortKeyB)); + sprintf(funcCall, "strcmp(strxfrm(\"%s\"), strxfrm(\"%s\"))", + coll[i].a, coll[i].b); + } else { + result = sign(strcoll(coll[i].a, coll[i].b)); + sprintf(funcCall, "strcoll(\"%s\", \"%s\")", coll[i].a, coll[i].b); + } + + if (result != coll[i].result || errno != coll[i].err) { + printf( + "\tPROBLEM: %s = %d (expected %d), errno = %x (expected %x)\n", + funcCall, result, coll[i].result, errno, coll[i].err); + problemCount++; + } + } + if (problemCount) + printf("\t%d problem(s) found!\n", problemCount); + else + printf("\tall fine\n"); +} + + +void +test_collation() +{ + const coll_data coll_posix[] = { + { "", "", 0, 0 }, + { "test", "test", 0, 0 }, + { "tester", "test", 1, 0 }, + { "tEst", "teSt", -1, 0 }, + { "test", "tester", -1, 0 }, + { "tast", "täst", -1, EINVAL }, + { "tæst", "test", 1, EINVAL }, + }; + test_coll(0, "POSIX", coll_posix); + test_coll(1, "POSIX", coll_posix); + + const coll_data coll_en[] = { + { "", "", 0, 0 }, + { "test", "test", 0, 0 }, + { "tester", "test", 1, 0 }, + { "tEst", "test", 1, 0 }, + { "test", "tester", -1, 0 }, + { "täst", "täst", 0, 0 }, + { "tast", "täst", -1, 0 }, + { "tbst", "täst", 1, 0 }, + { "tbst", "tæst", 1, 0 }, + { "täst", "tÄst", -1, 0 }, + { "tBst", "tÄst", 1, 0 }, + { "tBst", "täst", 1, 0 }, + { "taest", "tæst", -1, 0 }, + { "tafst", "tæst", 1, 0 }, + { "taa", "täa", -1, 0 }, + { "tab", "täb", -1, 0 }, + { "tad", "täd", -1, 0 }, + { "tae", "täe", -1, 0 }, + { "taf", "täf", -1, 0 }, + { "cote", "coté", -1, 0 }, + { "coté", "côte", -1, 0 }, + { "côte", "côté", -1, 0 }, + }; + test_coll(0, "en_US.UTF-8", coll_en); + test_coll(1, "en_US.UTF-8", coll_en); + + const coll_data coll_de[] = { + { "", "", 0, 0 }, + { "test", "test", 0, 0 }, + { "tester", "test", 1, 0 }, + { "tEst", "test", 1, 0 }, + { "test", "tester", -1, 0 }, + { "täst", "täst", 0, 0 }, + { "tast", "täst", -1, 0 }, + { "tbst", "täst", 1, 0 }, + { "tbst", "tæst", 1, 0 }, + { "täst", "tÄst", -1, 0 }, + { "tBst", "tÄst", 1, 0 }, + { "tBst", "täst", 1, 0 }, + { "taest", "tæst", -1, 0 }, + { "tafst", "tæst", 1, 0 }, + { "taa", "tä", 1, 0 }, + { "tab", "tä", 1, 0 }, + { "tad", "tä", 1, 0 }, + { "tae", "tä", 1, 0 }, + { "taf", "tä", 1, 0 }, + { "cote", "coté", -1, 0 }, + { "coté", "côte", -1, 0 }, + { "côte", "côté", -1, 0 }, + }; + test_coll(0, "de_DE.UTF-8", coll_de); + test_coll(1, "de_DE.UTF-8", coll_de); + + const coll_data coll_de_phonebook[] = { + { "", "", 0, 0 }, + { "test", "test", 0, 0 }, + { "tester", "test", 1, 0 }, + { "tEst", "test", 1, 0 }, + { "test", "tester", -1, 0 }, + { "täst", "täst", 0, 0 }, + { "tast", "täst", 1, 0 }, + { "tbst", "täst", 1, 0 }, + { "tbst", "tæst", 1, 0 }, + { "täst", "tÄst", -1, 0 }, + { "tBst", "tÄst", 1, 0 }, + { "tBst", "täst", 1, 0 }, + { "taest", "tæst", -1, 0 }, + { "tafst", "tæst", 1, 0 }, + { "taa", "tä", -1, 0 }, + { "tab", "tä", -1, 0 }, + { "tad", "tä", -1, 0 }, + { "tae", "tä", -1, 0 }, + { "taf", "tä", 1, 0 }, + { "cote", "coté", -1, 0 }, + { "coté", "côte", -1, 0 }, + { "côte", "côté", -1, 0 }, + }; + test_coll(0, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook); + test_coll(1, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook); + + const coll_data coll_fr[] = { + { "", "", 0, 0 }, + { "test", "test", 0, 0 }, + { "tester", "test", 1, 0 }, + { "tEst", "test", 1, 0 }, + { "test", "tester", -1, 0 }, + { "täst", "täst", 0, 0 }, + { "tast", "täst", -1, 0 }, + { "tbst", "täst", 1, 0 }, + { "tbst", "tæst", 1, 0 }, + { "täst", "tÄst", -1, 0 }, + { "tBst", "tÄst", 1, 0 }, + { "tBst", "täst", 1, 0 }, + { "taest", "tæst", -1, 0 }, + { "tafst", "tæst", 1, 0 }, + { "taa", "tä", 1, 0 }, + { "tab", "tä", 1, 0 }, + { "tad", "tä", 1, 0 }, + { "tae", "tä", 1, 0 }, + { "taf", "tä", 1, 0 }, + { "cote", "coté", -1, 0 }, + { "coté", "côte", 1, 0 }, + { "côte", "côté", -1, 0 }, + }; + test_coll(0, "fr_FR.UTF-8", coll_fr); + test_coll(1, "fr_FR.UTF-8", coll_fr); +} + + +// #pragma mark - main --------------------------------------------------------- + + +/* + * Test several different aspects of the POSIX locale and the functions + * influenced by it. + */ +int +main(void) +{ + test_setlocale(); + test_localeconv(); + test_strftime(); + test_ctype(); + test_wctype(); + test_wctrans(); + test_langinfo(); + test_collation(); + + return 0; +}