From d5e6687e6bccf03b6056a65dee9b7e03a7496995 Mon Sep 17 00:00:00 2001 From: neil Date: Thu, 29 Dec 2011 02:11:58 +0000 Subject: [PATCH] - Tabs to spaces. - Removed some MorphOS-only code. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@43286 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/libs/locale/catalog_funcs.c | 10 +- workbench/libs/locale/closecatalog.c | 45 +- workbench/libs/locale/closelocale.c | 156 +-- workbench/libs/locale/convtolower.c | 52 +- workbench/libs/locale/convtoupper.c | 55 +- workbench/libs/locale/defaultlocale.c | 6 +- workbench/libs/locale/formatdate.c | 783 ++++++----- workbench/libs/locale/formatstring.c | 1571 +++++++++++----------- workbench/libs/locale/getcatalogstr.c | 186 ++- workbench/libs/locale/getlocalestr.c | 38 +- workbench/libs/locale/initlocale.c | 332 ++--- workbench/libs/locale/isxxxx.c | 148 +- workbench/libs/locale/locale_init.c | 31 +- workbench/libs/locale/locale_intern.h | 90 +- workbench/libs/locale/locdatetostr.c | 2 - workbench/libs/locale/locdosgetlocalizedstring.c | 72 +- workbench/libs/locale/locrawdofmt.c | 583 ++++---- workbench/libs/locale/locstricmp.c | 68 +- workbench/libs/locale/locstrnicmp.c | 67 +- workbench/libs/locale/locstrtodate.c | 540 ++++---- workbench/libs/locale/loctolower.c | 52 +- workbench/libs/locale/loctoupper.c | 51 +- workbench/libs/locale/mmakefile.src | 12 +- workbench/libs/locale/opencataloga.c | 1165 ++++++++-------- workbench/libs/locale/openlocale.c | 382 +++--- workbench/libs/locale/parsedate.c | 958 ++++++------- workbench/libs/locale/patches.c | 288 ++-- workbench/libs/locale/prefsupdate.c | 244 ++-- workbench/libs/locale/rawdofmtsupport.c | 28 - workbench/libs/locale/rexxhost.c | 535 ++++---- workbench/libs/locale/strconvert.c | 203 ++- workbench/libs/locale/strncmp.c | 247 ++-- 32 files changed, 4489 insertions(+), 4511 deletions(-) rewrite workbench/libs/locale/closelocale.c (66%) rewrite workbench/libs/locale/formatdate.c (76%) rewrite workbench/libs/locale/formatstring.c (76%) rewrite workbench/libs/locale/getcatalogstr.c (71%) rewrite workbench/libs/locale/locrawdofmt.c (71%) rewrite workbench/libs/locale/locstrtodate.c (72%) rewrite workbench/libs/locale/opencataloga.c (88%) rewrite workbench/libs/locale/openlocale.c (73%) rewrite workbench/libs/locale/parsedate.c (85%) rewrite workbench/libs/locale/patches.c (66%) rewrite workbench/libs/locale/prefsupdate.c (67%) delete mode 100644 workbench/libs/locale/rawdofmtsupport.c rewrite workbench/libs/locale/rexxhost.c (70%) rewrite workbench/libs/locale/strconvert.c (74%) rewrite workbench/libs/locale/strncmp.c (79%) diff --git a/workbench/libs/locale/catalog_funcs.c b/workbench/libs/locale/catalog_funcs.c index fd6907b0a4..364c757341 100644 --- a/workbench/libs/locale/catalog_funcs.c +++ b/workbench/libs/locale/catalog_funcs.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ */ @@ -15,14 +15,14 @@ void dispose_catalog(struct IntCatalog * cat, { if (cat->ic_StringChunk) { - FreeVec(cat->ic_StringChunk); - cat->ic_StringChunk = NULL; + FreeVec(cat->ic_StringChunk); + cat->ic_StringChunk = NULL; } if (cat->ic_CatStrings) { - FreeVec(cat->ic_CatStrings); - cat->ic_CatStrings = NULL; + FreeVec(cat->ic_CatStrings); + cat->ic_CatStrings = NULL; } } diff --git a/workbench/libs/locale/closecatalog.c b/workbench/libs/locale/closecatalog.c index 6e9bb9b41e..b1e3d5a031 100644 --- a/workbench/libs/locale/closecatalog.c +++ b/workbench/libs/locale/closecatalog.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: Close a message catalog. @@ -9,33 +9,33 @@ #include #include "locale_intern.h" -#define DEBUG_CLOSECATALOG(x) ; +#define DEBUG_CLOSECATALOG(x) ; /***************************************************************************** NAME */ #include - AROS_LH1(void, CloseCatalog, + AROS_LH1(void, CloseCatalog, /* SYNOPSIS */ - AROS_LHA(struct Catalog *, catalog, A0), + AROS_LHA(struct Catalog *, catalog, A0), /* LOCATION */ - struct LocaleBase *, LocaleBase, 6, Locale) + struct LocaleBase *, LocaleBase, 6, Locale) /* FUNCTION - Conclude access to a message catalog, and decrement the use count. - If this use count is 0, the catalog can be expunged when the - system memory is running low. + Conclude access to a message catalog, and decrement the use count. + If this use count is 0, the catalog can be expunged when the + system memory is running low. INPUTS - catalog - the message catalog to close, note that NULL is - a valid catalog. + catalog - the message catalog to close, note that NULL is + a valid catalog. RESULT - The catalog is closed, and should no longer be used by the - application. + The catalog is closed, and should no longer be used by the + application. NOTES @@ -44,26 +44,23 @@ BUGS SEE ALSO - GetCatalogStr(), OpenCatalogA() + GetCatalogStr(), OpenCatalogA() INTERNALS - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - *****************************************************************************/ { AROS_LIBFUNC_INIT - DEBUG_CLOSECATALOG(dprintf("CloseCatalog: catalog 0x%lx\n",catalog)); + DEBUG_CLOSECATALOG(dprintf("CloseCatalog: catalog 0x%lx\n", + catalog)); - if(catalog != NULL) + if (catalog != NULL) { - ObtainSemaphore (&IntLB(LocaleBase)->lb_CatalogLock); + ObtainSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); - /* Decrement the use counter. */ - IntCat(catalog)->ic_UseCount--; + /* Decrement the use counter. */ + IntCat(catalog)->ic_UseCount--; if (0 == IntCat(catalog)->ic_UseCount) { @@ -78,6 +75,6 @@ } DEBUG_CLOSECATALOG(dprintf("CloseCatalog: done\n")); + AROS_LIBFUNC_EXIT - -} /* CloseCatalog */ +} diff --git a/workbench/libs/locale/closelocale.c b/workbench/libs/locale/closelocale.c dissimilarity index 66% index 76dda64dff..5aa2ac7fe4 100644 --- a/workbench/libs/locale/closelocale.c +++ b/workbench/libs/locale/closelocale.c @@ -1,78 +1,78 @@ -/* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. - $Id$ - - Desc: CloseLocale() - Close a locale structure. - Lang: english -*/ -#include -#include -#include "locale_intern.h" - -/***************************************************************************** - - NAME */ -#include - - AROS_LH1(void, CloseLocale, - -/* SYNOPSIS */ - AROS_LHA(struct Locale *, locale, A0), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 7, Locale) - -/* FUNCTION - Finish accessing a Locale. - - INPUTS - locale - An opened locale. Note that NULL is a valid - parameter here, and will simply be ignored. - - RESULT - The locale is released back to the system. - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - OpenLocale() - - INTERNALS - - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - /* Best make sure we actually have something freeable. */ - if(locale && (locale != (struct Locale *)IntLB(LocaleBase)->lb_DefaultLocale)) - { - /* Make sure we don't have any race conditions */ - ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - if(--IntL(locale)->il_Count == 0) - { - /* Free the locale structure if it's not the current locale */ - if (locale != (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale) - { - /* Close old .language, if any */ - if (IntLB(locale)->lb_CurrentLocale->il_CurrentLanguage) - CloseLibrary(IntLB(locale)->lb_CurrentLocale->il_CurrentLanguage); - - /* Close old dos.catalog */ - CloseCatalog(IntLB(locale)->lb_CurrentLocale->il_DosCatalog); - - FreeMem(locale, sizeof(struct IntLocale)); - } - } - ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - } - - AROS_LIBFUNC_EXIT -} /* CloseLocale */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: CloseLocale() - Close a locale structure. + Lang: english +*/ +#include +#include +#include "locale_intern.h" + +/***************************************************************************** + + NAME */ +#include + + AROS_LH1(void, CloseLocale, + +/* SYNOPSIS */ + AROS_LHA(struct Locale *, locale, A0), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 7, Locale) + +/* FUNCTION + Finish accessing a Locale. + + INPUTS + locale - An opened locale. Note that NULL is a valid + parameter here, and will simply be ignored. + + RESULT + The locale is released back to the system. + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + OpenLocale() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + /* Best make sure we actually have something freeable. */ + if (locale + && (locale != (struct Locale *)IntLB(LocaleBase)->lb_DefaultLocale)) + { + /* Make sure we don't have any race conditions */ + ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + if (--IntL(locale)->il_Count == 0) + { + /* Free the locale structure if it's not the current locale */ + if (locale != + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale) + { + /* Close old .language, if any */ + if (IntLB(locale)->lb_CurrentLocale->il_CurrentLanguage) + CloseLibrary(IntLB(locale)->lb_CurrentLocale-> + il_CurrentLanguage); + + /* Close old dos.catalog */ + CloseCatalog(IntLB(locale)->lb_CurrentLocale-> + il_DosCatalog); + + FreeMem(locale, sizeof(struct IntLocale)); + } + } + ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + } + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/convtolower.c b/workbench/libs/locale/convtolower.c index f8da43e9d5..2216852e78 100644 --- a/workbench/libs/locale/convtolower.c +++ b/workbench/libs/locale/convtolower.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: ConvToLower() - Stub for the Language tolower() function. @@ -9,7 +9,7 @@ #include "locale_intern.h" #include -#define DEBUG_CONVTOLOWER(x) ; +#define DEBUG_CONVTOLOWER(x) ; /***************************************************************************** @@ -19,27 +19,27 @@ AROS_LH2(ULONG, ConvToLower, /* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(ULONG , character, D0), + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(ULONG , character, D0), /* LOCATION */ - struct LocaleBase *, LocaleBase, 8, Locale) + struct LocaleBase *, LocaleBase, 8, Locale) /* FUNCTION - This function determine if the character supplied is upper case, - and if it is, the character will be converted to lower case. - Otherwise, the original character will be returned. + This function determine if the character supplied is upper case, + and if it is, the character will be converted to lower case. + Otherwise, the original character will be returned. INPUTS - locale - The Locale to use for this conversion. - character - The character to convert to lower case. + locale - The Locale to use for this conversion. + character - The character to convert to lower case. RESULT - The possibly converted character. + The possibly converted character. NOTES - This function requires a full 32-bit character in order to - support future multi-byte character sets. + This function requires a full 32-bit character in order to + support future multi-byte character sets. EXAMPLE @@ -52,29 +52,27 @@ *****************************************************************************/ { AROS_LIBFUNC_INIT - ULONG retval; + + ULONG retval; DEBUG_CONVTOLOWER(dprintf("ConvToLower: locale 0x%lx char 0x%lx\n", - locale, - character)); + locale, character)); DEBUG_CONVTOLOWER(dprintf("ConvToLower: func 0x%lx\n", - IntL(locale)->il_LanguageFunctions[0])); + IntL(locale)->il_LanguageFunctions[0])); #ifdef AROS_CALL1 retval = AROS_CALL1(ULONG, IntL(locale)->il_LanguageFunctions[0], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), struct LocaleBase *, LocaleBase); #else retval = AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[0], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif - - DEBUG_CONVTOLOWER(dprintf("ConvToLower: retval 0x%lx\n", - retval)); - return(retval); - + DEBUG_CONVTOLOWER(dprintf("ConvToLower: retval 0x%lx\n", retval)); + + return (retval); + AROS_LIBFUNC_EXIT -} /* ConvToLower */ +} diff --git a/workbench/libs/locale/convtoupper.c b/workbench/libs/locale/convtoupper.c index 2de03c8a89..41d7a8cdac 100644 --- a/workbench/libs/locale/convtoupper.c +++ b/workbench/libs/locale/convtoupper.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: ConvToUpper() - stub for the language toupper() function. @@ -10,44 +10,44 @@ #include "locale_intern.h" #include -#define DEBUG_CONVTOUPPER(x) ; +#define DEBUG_CONVTOUPPER(x) ; /***************************************************************************** NAME */ #include - AROS_LH2(ULONG, ConvToUpper, + AROS_LH2(ULONG, ConvToUpper, /* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(ULONG , character, D0), + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(ULONG , character, D0), /* LOCATION */ - struct LocaleBase *, LocaleBase, 9, Locale) + struct LocaleBase *, LocaleBase, 9, Locale) /* FUNCTION - ConvToUpper() will determine if a character is a lower case - character and if so convert it to the upper case equivalent. - Otherwise it will return the original character. + ConvToUpper() will determine if a character is a lower case + character and if so convert it to the upper case equivalent. + Otherwise it will return the original character. INPUTS - locale - The Locale to use for this conversion. - character - The character to convert. + locale - The Locale to use for this conversion. + character - The character to convert. RESULT - The possibly converted character. + The possibly converted character. NOTES - This function requires a full 32-bit character in order to support - future multi-byte character sets. + This function requires a full 32-bit character in order to support + future multi-byte character sets. EXAMPLE BUGS SEE ALSO - ConvToLower() + ConvToLower() INTERNALS @@ -55,29 +55,26 @@ { AROS_LIBFUNC_INIT - ULONG retval; + ULONG retval; DEBUG_CONVTOUPPER(dprintf("ConvToUpper: locale 0x%lx char 0x%lx\n", - locale, - character)); + locale, character)); DEBUG_CONVTOUPPER(dprintf("ConvToUpper: func 0x%lx\n", - IntL(locale)->il_LanguageFunctions[1])); + IntL(locale)->il_LanguageFunctions[1])); #ifdef AROS_CALL1 retval = AROS_CALL1(ULONG, IntL(locale)->il_LanguageFunctions[1], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), struct LocaleBase *, LocaleBase); #else - retval = AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[1], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + retval = AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[1], + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif - DEBUG_CONVTOUPPER(dprintf("ConvToUpper: retval 0x%lx\n", - retval)); + DEBUG_CONVTOUPPER(dprintf("ConvToUpper: retval 0x%lx\n", retval)); + + return (retval); - return(retval); - AROS_LIBFUNC_EXIT -} /* ConvToUpper */ +} diff --git a/workbench/libs/locale/defaultlocale.c b/workbench/libs/locale/defaultlocale.c index 0338a6703c..1b245b2428 100644 --- a/workbench/libs/locale/defaultlocale.c +++ b/workbench/libs/locale/defaultlocale.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: Default Locale Preferences @@ -25,8 +25,8 @@ const struct Locale defLocale = "united_states.country", /* Locale Name */ "english.language", /* Language Name */ { "english", NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL, NULL }, /* Prefered Languages */ + NULL, NULL, NULL, + NULL, NULL, NULL, NULL }, /* Prefered Languages */ 0, /* Flags */ 0, /* CodeSet */ diff --git a/workbench/libs/locale/formatdate.c b/workbench/libs/locale/formatdate.c dissimilarity index 76% index 60004036dc..8db1b5782f 100644 --- a/workbench/libs/locale/formatdate.c +++ b/workbench/libs/locale/formatdate.c @@ -1,395 +1,388 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ - - Desc: - Lang: English -*/ - -#include "locale_intern.h" -#include -#include -#include -#include -#include - -#include - -VOID PrintDigits(UWORD number, char fill, UWORD len, const struct Hook *hook, - const struct Locale *locale); -VOID _WriteChar(char token, const struct Hook *hook, - const struct Locale *locale); -VOID _WriteString(CONST_STRPTR string, const struct Hook *hook, - const struct Locale *locale); - -static const ULONG dayspermonth[13] = - {0 /* not used */,0,31,59,90,120,151,181,212,243,273,304,334}; - -/***************************************************************************** - - NAME */ -#include - - AROS_LH4(VOID, FormatDate, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(CONST_STRPTR, formatString, A1), - AROS_LHA(const struct DateStamp *, date, A2), - AROS_LHA(const struct Hook *, hook, A3), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 10, Locale) - -/* FUNCTION - - Generate a date string based on a template. The bytes generated are sent - to a user specified callback function. - - INPUTS - - locale -- the locale to use when formatting the string - formatString -- the formatting template string; this is much like the - printf() formatting style, i.e. a % followed by a - formatting command. The following commands exist: - - %a -- abbreviated weekday name - %A -- weekday name - %b -- abbreviated month name - %B -- month name - %c -- the same as "%a %b %d %H:%M:%S %Y" - %C -- the same as "%a %b %e %T %Z %Y" - %d -- day number with leading zeros - %D -- the same as "%m/%d/%y" - %e -- day number with leading spaces - %h -- abbreviated month name - %H -- hour using 24 hour style with leading zeros - %I -- hour using 12 hour style with leading zeros - %j -- julian date - %m -- month number with leading zeros - %M -- the number of minutes with leading zeros - %n -- linefeed - %p -- AM or PM string - %q -- hour using 24 hour style - %Q -- hour using 12 hour style - %r -- the same as "%I:%M:%S %p" - %R -- the same as "%H:%M" - %S -- the number of seconds with leading zeros - %t -- tab - %T -- the same as "%H:%M:%S" - %U -- the week number, taking Sunday as the first day - of the week - %w -- the weekday number - %W -- the week number, taking Monday as the first day - of the week - %x -- the same as "%m/%d/%y" - %X -- the same as "%H:%M:%S" - %y -- the year using two digits with leading zeros - %Y -- the year using four digits with leading zeros - - If the template parameter is NULL, a single null byte - is sent to the callback function. - - date -- the current date - hook -- callback function; this is called for every character - generated with the following arguments: - - * pointer to hook structure - * character - * pointer to locale - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - - ParseDate(), - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct ClockData cData; - ULONG week, days, tmp; - - if(/* locale == NULL || */ hook == NULL) - return; - - if(formatString == NULL) - { - _WriteChar(0, hook, locale); - return; - } - -/* TODO: Amiga2Date will fail around year 2114, because then the - * number of seconds since 1978 won't fit in a 32 bit variable anymore! - */ - - Amiga2Date(date->ds_Days*86400 + date->ds_Minute*60 + date->ds_Tick / 50, - &cData); - - while(*formatString != 0) - { - if(*formatString == '%') - { - switch(*(++formatString)) - { - case 'a': - _WriteString(GetLocaleStr(locale, ABDAY_1 + cData.wday), hook, - locale); - break; - - case 'A': - _WriteString(GetLocaleStr(locale, DAY_1 + cData.wday), hook, - locale); - break; - - case 'b': - _WriteString(GetLocaleStr(locale, ABMON_1 + cData.month - 1), - hook, locale); - break; - - case 'B': - _WriteString(GetLocaleStr(locale, MON_1 + cData.month - 1), hook, - locale); - break; - - case 'c': - FormatDate(locale, "%a %b %d %H:%M:%S %Y", date, hook); - break; - - case 'C': - FormatDate(locale, "%a %b %e %T %Z %Y", date, hook); - break; - - case 'd': - PrintDigits(cData.mday, '0', 2, hook, locale); - break; - - case 'x': - case 'D': - FormatDate(locale, "%m/%d/%y", date, hook); - break; - - case 'e': - PrintDigits(cData.mday, ' ', 2, hook, locale); - break; - - case 'h': - _WriteString(GetLocaleStr(locale, ABMON_1 + cData.month - 1), - hook, locale); - break; - - case 'H': - PrintDigits(cData.hour, '0', 2, hook, locale); - break; - - case 'I': - PrintDigits(cData.hour % 12, '0', 2, hook, locale); - break; - - case 'j': - /* TODO: Julian date not tested. */ - /* Julian date is DDD (1 - 366)*/ - PrintDigits( - cData.mday + dayspermonth[cData.month], - '0', - 3, - hook, - locale - ); - break; - - case 'm': - PrintDigits(cData.month, '0', 2, hook, locale); - break; - - case 'M': - PrintDigits(cData.min, '0', 2, hook, locale); - break; - - case 'n': - _WriteChar('\n', hook, locale); - break; - - case 'p': - _WriteString(GetLocaleStr(locale, - cData.hour < 12 ? AM_STR : PM_STR), - hook, locale); - break; - - case 'q': - PrintDigits(cData.hour, -1, 2, hook, locale); - break; - - case 'Q': - PrintDigits(cData.hour % 12, -1, 2, hook, locale); - break; - - case 'r': - FormatDate(locale, "%I:%M:%S %p", date, hook); - break; - - case 'R': - FormatDate(locale, "%H:%M", date, hook); - break; - - case 'S': - PrintDigits(cData.sec, '0', 2, hook, locale); - break; - - case 't': - _WriteChar('\t', hook, locale); - break; - - case 'X': - case 'T': - FormatDate(locale, "%H:%M:%S", date, hook); - break; - - case 'W': /* week number, Monday first day of week */ - case 'U': /* week number, Sunday first day of week */ - days = cData.mday + dayspermonth[cData.month]; - - /* leap year ? */ - if (0 == (cData.year % 4) && cData.month > 2) - { - /* - ** 1700, 1800, 1900, 2100, 2200 re not leap years. - ** 2000 is a leap year. - ** -> if a year is divisible by 100 but not by 400 then - ** it is not a leap year! - */ - if (0 == (cData.year % 100) && 0 != (cData.year % 400)) - ; - else - days++; - } - - /* - ** If January 1st is a Monday then the first week - ** will start with a Sunday January 7th if Sunday is the first day of the week - ** but if Monday is the first day of the week then Jan 1st will also be the - ** first day of the first week. - */ - /* - ** Go to Saturday = last day of week if Sunday is first day of week - ** Go to Sunday = last day of week if Monday is first day of week - */ - if ('U' == *formatString) - { - /* Sunday is first day of the week */ - tmp = days + (6 - cData.wday); - } - else - { - /* Monday is first day of week */ - if (0 != cData.wday) - tmp = days + (7 - cData.wday); - else - tmp = days; - } - - if (tmp < 7) - week = 0; - else - { - /* cut off the few days that belong to week 0 */ - tmp -= (tmp % 7); - /* Calculate the full amount of weeks */ - week = tmp / 7; - } - - PrintDigits(week, '0', 2, hook, locale); - break; - - case 'w': - PrintDigits(cData.wday, -1, 1, hook, locale); - break; - - case 'y': - PrintDigits(cData.year % 100, '0', 2, hook, locale); - break; - - case 'Y': - PrintDigits(cData.year, '0', 4, hook, locale); - break; - - case 'Z': - /* cuurent time zone Unimplemented in 3.1 */ - break; - - case 0: - break; - - default: - _WriteChar(*formatString, hook, locale); - break; - } - } - else - { - _WriteChar(*formatString, hook, locale); - } - - formatString++; - } - - _WriteChar(0, hook, locale); /* Write null terminator */ - - AROS_LIBFUNC_EXIT -} /* FormatDate */ - - -VOID _WriteString(CONST_STRPTR string, const struct Hook *hook, - const struct Locale *locale) -{ - while(*string != 0) - { - _WriteChar(*string++, hook, locale); - } -} - - -VOID _WriteChar(char token, const struct Hook *hook, - const struct Locale *locale) -{ - AROS_UFC3(VOID, hook->h_Entry, - AROS_UFCA(const struct Hook *, hook, A0), - AROS_UFCA(const struct Locale *, locale, A2), - AROS_UFCA(char, token, A1) - ); -} - - -VOID PrintDigits(UWORD number, char fill, UWORD len, const struct Hook *hook, - const struct Locale *locale) -{ - char buf[7]; - char *ptr = &buf[6]; - int i = 0; - - buf[6] = 0; - - while((number || !i) && i < len) - { - *--ptr = number % 10 + '0'; - number /= 10; - i++; - } - - while(len - i > 0 && (char)-1 != fill) - { - len--; - _WriteChar(fill, hook, locale); - } - - _WriteString((char *)ptr, hook, locale); -} +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: + Lang: English +*/ + +#include "locale_intern.h" +#include +#include +#include +#include +#include + +#include + +VOID PrintDigits(UWORD number, char fill, UWORD len, const struct Hook *hook, + const struct Locale *locale); +VOID _WriteChar(char token, const struct Hook *hook, + const struct Locale *locale); +VOID _WriteString(CONST_STRPTR string, const struct Hook *hook, + const struct Locale *locale); + +static const ULONG dayspermonth[13] = + {0 /* not used */,0,31,59,90,120,151,181,212,243,273,304,334}; + +/***************************************************************************** + + NAME */ +#include + + AROS_LH4(VOID, FormatDate, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(CONST_STRPTR, formatString, A1), + AROS_LHA(const struct DateStamp *, date, A2), + AROS_LHA(const struct Hook *, hook, A3), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 10, Locale) + +/* FUNCTION + + Generate a date string based on a template. The bytes generated are sent + to a user specified callback function. + + INPUTS + + locale -- the locale to use when formatting the string + formatString -- the formatting template string; this is much like the + printf() formatting style, i.e. a % followed by a + formatting command. The following commands exist: + + %a -- abbreviated weekday name + %A -- weekday name + %b -- abbreviated month name + %B -- month name + %c -- the same as "%a %b %d %H:%M:%S %Y" + %C -- the same as "%a %b %e %T %Z %Y" + %d -- day number with leading zeros + %D -- the same as "%m/%d/%y" + %e -- day number with leading spaces + %h -- abbreviated month name + %H -- hour using 24 hour style with leading zeros + %I -- hour using 12 hour style with leading zeros + %j -- julian date + %m -- month number with leading zeros + %M -- the number of minutes with leading zeros + %n -- linefeed + %p -- AM or PM string + %q -- hour using 24 hour style + %Q -- hour using 12 hour style + %r -- the same as "%I:%M:%S %p" + %R -- the same as "%H:%M" + %S -- the number of seconds with leading zeros + %t -- tab + %T -- the same as "%H:%M:%S" + %U -- the week number, taking Sunday as the first day + of the week + %w -- the weekday number + %W -- the week number, taking Monday as the first day + of the week + %x -- the same as "%m/%d/%y" + %X -- the same as "%H:%M:%S" + %y -- the year using two digits with leading zeros + %Y -- the year using four digits with leading zeros + + If the template parameter is NULL, a single null byte + is sent to the callback function. + + date -- the current date + hook -- callback function; this is called for every character + generated with the following arguments: + + * pointer to hook structure + * character + * pointer to locale + + RESULT + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + + ParseDate(), + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct ClockData cData; + ULONG week, days, tmp; + + if ( /* locale == NULL || */ hook == NULL) + return; + + if (formatString == NULL) + { + _WriteChar(0, hook, locale); + return; + } + + /* TODO: Amiga2Date will fail around year 2114, because then the + * number of seconds since 1978 won't fit in a 32 bit variable anymore! + */ + + Amiga2Date(date->ds_Days * 86400 + date->ds_Minute * 60 + + date->ds_Tick / 50, &cData); + + while (*formatString != 0) + { + if (*formatString == '%') + { + switch (*(++formatString)) + { + case 'a': + _WriteString(GetLocaleStr(locale, ABDAY_1 + cData.wday), + hook, locale); + break; + + case 'A': + _WriteString(GetLocaleStr(locale, DAY_1 + cData.wday), hook, + locale); + break; + + case 'b': + _WriteString(GetLocaleStr(locale, + ABMON_1 + cData.month - 1), hook, locale); + break; + + case 'B': + _WriteString(GetLocaleStr(locale, MON_1 + cData.month - 1), + hook, locale); + break; + + case 'c': + FormatDate(locale, "%a %b %d %H:%M:%S %Y", date, hook); + break; + + case 'C': + FormatDate(locale, "%a %b %e %T %Z %Y", date, hook); + break; + + case 'd': + PrintDigits(cData.mday, '0', 2, hook, locale); + break; + + case 'x': + case 'D': + FormatDate(locale, "%m/%d/%y", date, hook); + break; + + case 'e': + PrintDigits(cData.mday, ' ', 2, hook, locale); + break; + + case 'h': + _WriteString(GetLocaleStr(locale, + ABMON_1 + cData.month - 1), hook, locale); + break; + + case 'H': + PrintDigits(cData.hour, '0', 2, hook, locale); + break; + + case 'I': + PrintDigits(cData.hour % 12, '0', 2, hook, locale); + break; + + case 'j': + /* TODO: Julian date not tested. */ + /* Julian date is DDD (1 - 366) */ + PrintDigits(cData.mday + dayspermonth[cData.month], + '0', 3, hook, locale); + break; + + case 'm': + PrintDigits(cData.month, '0', 2, hook, locale); + break; + + case 'M': + PrintDigits(cData.min, '0', 2, hook, locale); + break; + + case 'n': + _WriteChar('\n', hook, locale); + break; + + case 'p': + _WriteString(GetLocaleStr(locale, + cData.hour < 12 ? AM_STR : PM_STR), hook, locale); + break; + + case 'q': + PrintDigits(cData.hour, -1, 2, hook, locale); + break; + + case 'Q': + PrintDigits(cData.hour % 12, -1, 2, hook, locale); + break; + + case 'r': + FormatDate(locale, "%I:%M:%S %p", date, hook); + break; + + case 'R': + FormatDate(locale, "%H:%M", date, hook); + break; + + case 'S': + PrintDigits(cData.sec, '0', 2, hook, locale); + break; + + case 't': + _WriteChar('\t', hook, locale); + break; + + case 'X': + case 'T': + FormatDate(locale, "%H:%M:%S", date, hook); + break; + + case 'W': /* week number, Monday first day of week */ + case 'U': /* week number, Sunday first day of week */ + days = cData.mday + dayspermonth[cData.month]; + + /* leap year ? */ + if (0 == (cData.year % 4) && cData.month > 2) + { + /* + ** 1700, 1800, 1900, 2100, 2200 re not leap years. + ** 2000 is a leap year. + ** -> if a year is divisible by 100 but not by 400 then + ** it is not a leap year! + */ + if (0 == (cData.year % 100) && 0 != (cData.year % 400)) + ; + else + days++; + } + + /* + ** If January 1st is a Monday then the first week + ** will start with a Sunday January 7th if Sunday is the first day of the week + ** but if Monday is the first day of the week then Jan 1st will also be the + ** first day of the first week. + */ + /* + ** Go to Saturday = last day of week if Sunday is first day of week + ** Go to Sunday = last day of week if Monday is first day of week + */ + if ('U' == *formatString) + { + /* Sunday is first day of the week */ + tmp = days + (6 - cData.wday); + } + else + { + /* Monday is first day of week */ + if (0 != cData.wday) + tmp = days + (7 - cData.wday); + else + tmp = days; + } + + if (tmp < 7) + week = 0; + else + { + /* cut off the few days that belong to week 0 */ + tmp -= (tmp % 7); + /* Calculate the full amount of weeks */ + week = tmp / 7; + } + + PrintDigits(week, '0', 2, hook, locale); + break; + + case 'w': + PrintDigits(cData.wday, -1, 1, hook, locale); + break; + + case 'y': + PrintDigits(cData.year % 100, '0', 2, hook, locale); + break; + + case 'Y': + PrintDigits(cData.year, '0', 4, hook, locale); + break; + + case 'Z': + /* cuurent time zone Unimplemented in 3.1 */ + break; + + case 0: + break; + + default: + _WriteChar(*formatString, hook, locale); + break; + } + } + else + { + _WriteChar(*formatString, hook, locale); + } + + formatString++; + } + + _WriteChar(0, hook, locale); /* Write null terminator */ + + AROS_LIBFUNC_EXIT +} + + +VOID _WriteString(CONST_STRPTR string, const struct Hook *hook, + const struct Locale *locale) +{ + while (*string != 0) + { + _WriteChar(*string++, hook, locale); + } +} + + +VOID _WriteChar(char token, const struct Hook *hook, + const struct Locale *locale) +{ + AROS_UFC3(VOID, hook->h_Entry, + AROS_UFCA(const struct Hook *, hook, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(char, token, A1)); +} + + +VOID PrintDigits(UWORD number, char fill, UWORD len, + const struct Hook *hook, const struct Locale *locale) +{ + char buf[7]; + char *ptr = &buf[6]; + int i = 0; + + buf[6] = 0; + + while ((number || !i) && i < len) + { + *--ptr = number % 10 + '0'; + number /= 10; + i++; + } + + while (len - i > 0 && (char)-1 != fill) + { + len--; + _WriteChar(fill, hook, locale); + } + + _WriteString((char *)ptr, hook, locale); +} diff --git a/workbench/libs/locale/formatstring.c b/workbench/libs/locale/formatstring.c dissimilarity index 76% index e6d89aed7a..e24fab634f 100644 --- a/workbench/libs/locale/formatstring.c +++ b/workbench/libs/locale/formatstring.c @@ -1,765 +1,806 @@ -/* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. - $Id$ - - Desc: - Lang: english -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "locale_intern.h" - -#include - -#if USE_QUADFMT -typedef QUAD FMTLARGESTTYPE; -typedef UQUAD UFMTLARGESTTYPE; -#else /* USE_QUADFMT */ -typedef LONG FMTLARGESTTYPE; -typedef ULONG UFMTLARGESTTYPE; -#endif /* USE_QUADFMT */ - -static const UBYTE hexarray [] = "0123456789abcdef"; -static const UBYTE HEXarray [] = "0123456789ABCDEF"; - -static inline APTR stream_addr(APTR *args, ULONG len) -{ - APTR ret = *args; - - /* LONG data are actually IPTR-aligned */ - *args += (len > sizeof(UWORD)) ? sizeof(IPTR) : len; - return ret; -} - -/* The stuff below is based on old gcc includes (where you can actually read how - varargs work) and ABI documentation. - It works in the same way as traditional va_arg() except it fetches - pointers to arguments, not arguments themselves (since on 32-bit machines - argument values may be larger than pointers). */ - -#if defined(__PPC__) - -static inline APTR va_addr(va_list args, ULONG len) -{ - APTR ret; - - if (len == sizeof(UQUAD)) { - /* On PPC UQUAD is aligned. and occupies 2 registers (plus may waste one more for alignment) */ - if (args->gpr < 7) { - ULONG *regsave = (ULONG *)args->reg_save_area; - - args->gpr += args->gpr & 1; - ret = ®save[args->gpr]; - args->gpr += 2; - } else { - args->gpr = 8; - ret = (APTR)(((IPTR)(args->overflow_arg_area + 7)) & ~7); - args->overflow_arg_area = ret + sizeof(UQUAD); - } - } else { - if (args->gpr < 8) { \ - ULONG *regsave = (ULONG *)args->reg_save_area; - - ret = ®save[args->gpr++]; - } else { - ret = args->overflow_arg_area; - args->overflow_arg_area += sizeof(ULONG); - } - } - return ret; -} - -#elif defined(__x86_64__) - -static inline APTR va_addr(va_list args, ULONG len) -{ - APTR ret; - - if (args->gp_offset < 48) { - ret = args->reg_save_area + args->gp_offset; - args->gp_offset += sizeof(IPTR); - } else { - ret = args->overflow_arg_area; - args->overflow_arg_area += sizeof(IPTR); - } - return ret; -} - -#elif defined(__arm__) - -#define va_addr(args, len) stream_addr(&args.__ap, len) -#define is_va_list(ap) ap.__ap -#define null_va_list(ap) va_list ap = {NULL} - -#else - -/* This works for i386 and m68k */ -static inline APTR _va_addr(va_list *args) -{ - va_list ret = *args; - - *args += sizeof(IPTR); - return ret; -} - -#define va_addr(args, len) _va_addr(&args) - -#endif - -#ifndef is_va_list - -#define is_va_list(ap) ap -#define null_va_list(ap) void *ap = NULL - -#endif - -APTR InternalFormatString(const struct Locale *locale, CONST_STRPTR fmtTemplate, CONST_APTR dataStream, const struct Hook *putCharFunc, va_list VaListStream) -{ - enum {OUTPUT = 0, - FOUND_FORMAT} state; - - ULONG template_pos; - BOOL end; - ULONG max_argpos; - ULONG arg_counter; - BOOL scanning; - -#define INDICES 256 - IPTR indices[INDICES]; - - if (!fmtTemplate) - return (APTR)dataStream; - - template_pos = 0; /* Current position in the template string */ - state = OUTPUT; /* current state of parsing */ - end = FALSE; - max_argpos = 0; - arg_counter = 0; - scanning = TRUE; /* The first time I will go through - and determine the width of the data in the dataStream */ - - memset(indices, sizeof(APTR), sizeof(indices)); - - while (!end) - { - /* - ** A format description starts here? - */ - if (fmtTemplate[template_pos] == '%') - { - arg_counter++; - state = FOUND_FORMAT; - } - - switch (state) - { - case OUTPUT: - /* - ** Call the hook for this character - */ - if (!scanning) - { - AROS_UFC3(VOID, putCharFunc->h_Entry, - AROS_UFCA(const struct Hook *, putCharFunc, A0), - AROS_UFCA(const struct Locale *, locale, A2), - AROS_UFCA(UBYTE, fmtTemplate[template_pos], A1)); - } - - /* - ** End of template string? -> End of this function. - */ - if (fmtTemplate[template_pos] == '\0') - { - if (scanning) - { - /* - ** The scanning phase is over. Next time we do the output. - */ - int i; - scanning = FALSE; - template_pos = 0; - arg_counter = 0; - - /* - ** prepare the indices array - */ - if (is_va_list(VaListStream)) { - for (i = 0; i <= max_argpos; i++) - indices[i] = (IPTR)va_addr(VaListStream, indices[i]); - } else { - for (i = 0; i <= max_argpos; i++) - indices[i] = (IPTR)stream_addr((APTR *)&dataStream, indices[i]); - } - - } - else - { - /* - ** We already went through the output phase. So this is - ** the end of it. - */ - end = TRUE; - } - } - else - template_pos++; - - //kprintf("OUTPUT: template_pos: %d\n",template_pos); - - break; - - case FOUND_FORMAT: - /* - ** The '%' was found in the template string - */ - template_pos++; - - //kprintf("FOUND_FORMAT: template_pos: %d\n",template_pos); - /* - ** Does the user want the '%' to be printed? - */ - if (fmtTemplate[template_pos] == '%') - { - if (!scanning) - { - AROS_UFC3(VOID, putCharFunc->h_Entry, - AROS_UFCA(const struct Hook * , putCharFunc, A0), - AROS_UFCA(const struct Locale *, locale, A2), - AROS_UFCA(UBYTE, fmtTemplate[template_pos], A1)); - } - template_pos++; - arg_counter--; //stegerg - } - else - { - /* - ** Now parsing... - ** Template format: %[arg_pos$][flags][width][.limit][length]type - ** - ** arg_pos specifies the position of the argument in the dataStream - ** flags only '-' is allowed - ** width - ** .limit - ** datasize size of the datatype - ** type b,d,D,u,U,x,X,s,c - */ - ULONG arg_pos = 1; - BOOL left = FALSE; // no flag was found - UBYTE fill = ' '; - ULONG minus; - ULONG width = 0; - ULONG limit = ~0; - ULONG buflen = 0; - ULONG datasize; - UFMTLARGESTTYPE tmp= 0; -#define BUFFERSIZE 128 - UBYTE buf[BUFFERSIZE]; - UBYTE *buffer = buf; - - /* - ** arg_pos - */ - - //kprintf("next char: %c\n",fmtTemplate[template_pos]); - - if (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9') - { - ULONG old_template_pos = template_pos; - - for (arg_pos = 0; (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9'); template_pos++) - { - arg_pos = arg_pos * 10 + fmtTemplate[template_pos] - '0'; - } - - if (fmtTemplate[template_pos] == '$') - template_pos++; - else - { - arg_pos = arg_counter; - template_pos = old_template_pos; - } - } - else - arg_pos = arg_counter; - - /* - ** flags - */ - if (fmtTemplate[template_pos] == '-') - { - template_pos++; - left = TRUE; - } - - /* - ** fill character a '0'? - */ - if (fmtTemplate[template_pos] == '0') - { - template_pos++; - fill = '0'; - } - - /* - ** width - */ - if (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9') - { - for (width = 0; (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9'); template_pos++) - { - width = width * 10 + fmtTemplate[template_pos] - '0'; - } - } - - /* - ** limit - */ - if (fmtTemplate[template_pos] == '.') - { - template_pos++; - - if (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9') - { - for (limit = 0; (fmtTemplate[template_pos] >= '0' && - fmtTemplate[template_pos] <= '9'); template_pos++) - { - limit = limit * 10 + fmtTemplate[template_pos] - '0'; - } - } - } - - /* - ** Length - */ - switch (fmtTemplate[template_pos]) - { -#if USE_QUADFMT - case 'L': - datasize = sizeof(UQUAD); - template_pos++; - break; -#endif /* USE_QUADFMT */ - - case 'l': - template_pos++; -#if USE_QUADFMT - if (fmtTemplate[template_pos] == 'l') - { - datasize = sizeof(UQUAD); - template_pos++; - } - else -#endif /* USE_QUADFMT */ - datasize = sizeof(ULONG); - break; - - default: - /* For C-style varargs default size is ULONG, single 'l' is effectively ignored */ - datasize = is_va_list(VaListStream) ? sizeof(ULONG) : sizeof(UWORD); - break; - } - - /* - ** Print it according to the given type info. - */ - switch (fmtTemplate[template_pos]) - { - case 'b': /* BSTR, see autodocs */ - /* - ** Important parameters: - ** arg_pos, left, buflen, limit - */ - if (!scanning) - { - BSTR s = (BSTR)*(UBYTE **)indices[arg_pos-1]; - - if (s != (BSTR)BNULL) { - buffer = AROS_BSTR_ADDR(s); - buflen = AROS_BSTR_strlen(s); - } else { - buffer = ""; - buflen = 0; - } - -#if !USE_GLOBALLIMIT - if (buflen > limit) - buflen = limit; -#endif /* !USE_GLOBALLIMIT */ - } - else - indices[arg_pos-1] = sizeof(BPTR); - break; - - case 'd': /* signed decimal */ - case 'u': /* unsigned decimal */ - - minus = fmtTemplate[template_pos] == 'd'; - - if (!scanning) - { - switch (datasize) - { -#if USE_QUADFMT - case 8: - tmp = *(UQUAD *)indices[arg_pos-1]; - //buffer = &buf[16+1]; - minus *= (FMTLARGESTTYPE) tmp < 0; - if (minus) - tmp = -tmp; - break; -#endif /* USE_QUADFMT */ - - case 4: - tmp = *(ULONG *)indices[arg_pos-1]; - //buffer = &buf[8+1]; - minus *= (LONG) tmp < 0; - if (minus) - tmp = (ULONG) -tmp; - break; - - default: /* 2 */ - tmp = *(UWORD *)indices[arg_pos-1]; - //buffer = &buf[4+1]; - minus *= (WORD) tmp < 0; - if (minus) - tmp = (UWORD) -tmp; - break; - } - - buffer = &buf[BUFFERSIZE]; - do - { - *--buffer = (tmp % 10) + '0'; - tmp /= 10; - buflen++; - } - while (tmp); - - if (minus) - { - *--buffer = '-'; - buflen++; - } - - } - else - indices[arg_pos-1] = datasize; - break; - - case 'D': /* signed decimal with locale's formatting conventions */ - case 'U': /* unsigned decimal with locale's formatting conventions */ - if (!scanning) - { - UBYTE groupsize; - ULONG group_index = 0; - - minus = fmtTemplate[template_pos] == 'D'; - - switch (datasize) - { -#if USE_QUADFMT - case 8: - tmp = *(UQUAD *)indices[arg_pos-1]; - minus *= (FMTLARGESTTYPE) tmp < 0; - if (minus) - tmp = -tmp; - break; -#endif /* USE_QUADFMT */ - - case 4: - tmp = *(ULONG *)indices[arg_pos-1]; - minus *= (LONG) tmp < 0; - if (minus) - tmp = (ULONG) -tmp; - break; - - default: /* 2 */ - tmp = *(UWORD *)indices[arg_pos-1]; - minus *= (WORD) tmp < 0; - if (minus) - tmp = (UWORD) -tmp; - break; - } - - /* BUFFERSIZE should be big enough to format a string - ** according to locale's formatting conventions - */ - buffer = &buf[BUFFERSIZE]; - groupsize = locale ? locale->loc_Grouping[group_index] : 255; - - do - { - *--buffer = (tmp % 10) + '0'; - tmp /= 10; - buflen++; - - groupsize--; - - if (groupsize == 0 && tmp != 0) - { - /* - ** Write the separator - */ - - *--buffer = locale->loc_GroupSeparator[group_index]; - - groupsize = locale->loc_Grouping[group_index+1]; - - if (groupsize == 0) - { - /* - ** Supposed to use the previous element - */ - groupsize = locale->loc_Grouping[group_index]; - } - else - group_index++; - - buflen++; - } - } - while (tmp); - - if (minus) - { - *--buffer = '-'; - buflen++; - } - } - else - indices[arg_pos-1] = datasize; - break; - - case 'p': /* lower case pointer string */ - case 'P': /* upper case pointer string */ - fill = '0'; - width = sizeof(APTR)*2; - /* %p is always at least natural pointer size */ - if (datasize < sizeof(APTR)) - datasize = sizeof(APTR); - case 'x': /* upper case hexadecimal string */ - case 'X': /* lower case hexadecimal string */ - - if (!scanning) - { - const UBYTE *hexa; - - switch (datasize) - { -#if USE_QUADFMT - case 8: - tmp = *(UQUAD *)indices[arg_pos-1]; - //buffer = &buf[16+1]; - break; -#endif /* USE_QUADFMT */ - - case 4: - tmp = *(ULONG *)indices[arg_pos-1]; - //buffer = &buf[8+1]; - break; - - default: /* 2 */ - tmp = *(UWORD *)indices[arg_pos-1]; - //buffer = &buf[4+1]; - break; - } - - buffer = &buf[BUFFERSIZE]; - - /* NOTE: x/X is reverse to printf, coz orig RawDoFmt %lx for uppercase. */ - hexa = (fmtTemplate[template_pos] == 'X' || - fmtTemplate[template_pos] == 'p') ? hexarray : HEXarray; - do - { - *--buffer = hexa[tmp&0x0f]; - tmp >>= 4; - buflen++; - } - while (tmp); - } - else - indices[arg_pos-1] = datasize; - break; - - case 's': /* NULL terminated string */ - { - if (!scanning) - { - buffer = *(UBYTE **)indices[arg_pos-1]; - - /* - * RawDoFmt() in original AmigaOS(tm) formats NULL pointers as empty strings, - * and not something like "(null)". Some software may rely on this behavior. - * %b is handled in similar manner. - */ - if (!buffer) - buffer = ""; - buflen = strlen(buffer); - -#if !USE_GLOBALLIMIT - if (buflen > limit) - buflen = limit; -#endif /* !USE_GLOBALLIMIT */ - } - else - indices[arg_pos-1] = sizeof(UBYTE *); /* the pointer has 4 bytes */ - } - break; - - case 'c': /* Character */ - if (!scanning) - { - switch (datasize) - { -#if USE_QUADFMT - case 8: - buf[0] = (UBYTE)*(UQUAD *)indices[arg_pos-1]; - break; -#endif /* USE_QUADFMT */ - - case 4: - buf[0] = (UBYTE)*(ULONG *)indices[arg_pos-1]; - break; - - default: /* 2 */ - buf[0] = (UBYTE)*(WORD *)indices[arg_pos-1]; - break; - } - - buflen = 1; - } - else - indices[arg_pos-1] = datasize; - break; - - default: - /* Ignore the faulty '%' */ - - if (!scanning) - { - buf[0] = fmtTemplate[template_pos]; - width = 1; - buflen = 1; - } - - arg_pos = --arg_counter; - break; - } - - - if (!scanning) - { - int i; - - /* - Now everything I need is known: - buffer - contains the string to be printed - buflen - size of the string - fill - the pad character - left - is 1 if the string should be left aligned - width - is the minimal width of the field - limit - maximum number of characters to output from a string, default ~0 - */ - -#if USE_GLOBALLIMIT - if (buflen > limit) - buflen = limit; -#endif /* USE_GLOBALLIMIT */ - - /* Print padding if right aligned */ - if (!left) - for (i = buflen; i < width; i++) - AROS_UFC3(VOID, putCharFunc->h_Entry, - AROS_UFCA(const struct Hook *, putCharFunc , A0), - AROS_UFCA(const struct Locale *, locale , A2), - AROS_UFCA(UBYTE, fill , A1) - ); - - /* Print body up to buflen */ - for (i = 0; i < buflen; i++) - { - AROS_UFC3(VOID, putCharFunc->h_Entry, - AROS_UFCA(const struct Hook *, putCharFunc , A0), - AROS_UFCA(const struct Locale *, locale , A2), - AROS_UFCA(UBYTE, *buffer++ , A1) - ); - } - - /* Pad right if left aligned */ - if (left) - for (i = buflen; i < width; i++) - AROS_UFC3(VOID, putCharFunc->h_Entry, - AROS_UFCA(const struct Hook *, putCharFunc , A0), - AROS_UFCA(const struct Locale *, locale , A2), - AROS_UFCA(UBYTE, fill , A1) - ); - } - - template_pos++; - - if (arg_pos > max_argpos) - max_argpos = arg_pos; - - } - state = OUTPUT; - break; - } - } - - return (APTR) indices[max_argpos]; -} - -/***************************************************************************** - - NAME */ -#include - - AROS_LH4(APTR, FormatString, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(CONST_STRPTR, fmtTemplate, A1), - AROS_LHA(CONST_APTR , dataStream, A2), - AROS_LHA(const struct Hook *, putCharFunc, A3), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 11, Locale) - -/* FUNCTION - - INPUTS - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - null_va_list(vaListStream); - - return InternalFormatString(locale, fmtTemplate, dataStream, putCharFunc, vaListStream); - - AROS_LIBFUNC_EXIT -} /* FormatString */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: + Lang: english +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "locale_intern.h" + +#include + +#if USE_QUADFMT +typedef QUAD FMTLARGESTTYPE; +typedef UQUAD UFMTLARGESTTYPE; +#else /* USE_QUADFMT */ +typedef LONG FMTLARGESTTYPE; +typedef ULONG UFMTLARGESTTYPE; +#endif /* USE_QUADFMT */ + +static const UBYTE hexarray[] = "0123456789abcdef"; +static const UBYTE HEXarray[] = "0123456789ABCDEF"; + +static inline APTR stream_addr(APTR *args, ULONG len) +{ + APTR ret = *args; + + /* LONG data are actually IPTR-aligned */ + *args += (len > sizeof(UWORD)) ? sizeof(IPTR) : len; + return ret; +} + +/* The stuff below is based on old gcc includes (where you can actually read how + varargs work) and ABI documentation. + It works in the same way as traditional va_arg() except it fetches + pointers to arguments, not arguments themselves (since on 32-bit machines + argument values may be larger than pointers). */ + +#if defined(__PPC__) + +static inline APTR va_addr(va_list args, ULONG len) +{ + APTR ret; + + if (len == sizeof(UQUAD)) + { + /* On PPC UQUAD is aligned. and occupies 2 registers (plus may waste one more for alignment) */ + if (args->gpr < 7) + { + ULONG *regsave = (ULONG *)args->reg_save_area; + + args->gpr += args->gpr & 1; + ret = ®save[args->gpr]; + args->gpr += 2; + } + else + { + args->gpr = 8; + ret = (APTR)(((IPTR)(args->overflow_arg_area + 7)) & ~7); + args->overflow_arg_area = ret + sizeof(UQUAD); + } + } + else + { + if (args->gpr < 8) + { + ULONG *regsave = (ULONG *)args->reg_save_area; + + ret = ®save[args->gpr++]; + } + else + { + ret = args->overflow_arg_area; + args->overflow_arg_area += sizeof(ULONG); + } + } + return ret; +} + +#elif defined(__x86_64__) + +static inline APTR va_addr(va_list args, ULONG len) +{ + APTR ret; + + if (args->gp_offset < 48) + { + ret = args->reg_save_area + args->gp_offset; + args->gp_offset += sizeof(IPTR); + } + else + { + ret = args->overflow_arg_area; + args->overflow_arg_area += sizeof(IPTR); + } + return ret; +} + +#elif defined(__arm__) + +#define va_addr(args, len) stream_addr(&args.__ap, len) +#define is_va_list(ap) ap.__ap +#define null_va_list(ap) va_list ap = {NULL} + +#else + +/* This works for i386 and m68k */ +static inline APTR _va_addr(va_list *args) +{ + va_list ret = *args; + + *args += sizeof(IPTR); + return ret; +} + +#define va_addr(args, len) _va_addr(&args) + +#endif + +#ifndef is_va_list + +#define is_va_list(ap) ap +#define null_va_list(ap) void *ap = NULL + +#endif + +APTR InternalFormatString(const struct Locale * locale, + CONST_STRPTR fmtTemplate, CONST_APTR dataStream, + const struct Hook * putCharFunc, va_list VaListStream) +{ + enum + { OUTPUT = 0, + FOUND_FORMAT + } state; + + ULONG template_pos; + BOOL end; + ULONG max_argpos; + ULONG arg_counter; + BOOL scanning; + +#define INDICES 256 + IPTR indices[INDICES]; + + if (!fmtTemplate) + return (APTR) dataStream; + + template_pos = 0; /* Current position in the template string */ + state = OUTPUT; /* current state of parsing */ + end = FALSE; + max_argpos = 0; + arg_counter = 0; + scanning = TRUE; /* The first time I will go through + and determine the width of the data in the dataStream */ + + memset(indices, sizeof(APTR), sizeof(indices)); + + while (!end) + { + /* + ** A format description starts here? + */ + if (fmtTemplate[template_pos] == '%') + { + arg_counter++; + state = FOUND_FORMAT; + } + + switch (state) + { + case OUTPUT: + /* + ** Call the hook for this character + */ + if (!scanning) + { + AROS_UFC3(VOID, putCharFunc->h_Entry, + AROS_UFCA(const struct Hook *, putCharFunc, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(UBYTE, fmtTemplate[template_pos], A1)); + } + + /* + ** End of template string? -> End of this function. + */ + if (fmtTemplate[template_pos] == '\0') + { + if (scanning) + { + /* + ** The scanning phase is over. Next time we do the output. + */ + int i; + scanning = FALSE; + template_pos = 0; + arg_counter = 0; + + /* + ** prepare the indices array + */ + if (is_va_list(VaListStream)) + { + for (i = 0; i <= max_argpos; i++) + indices[i] = + (IPTR) va_addr(VaListStream, indices[i]); + } + else + { + for (i = 0; i <= max_argpos; i++) + indices[i] = + (IPTR) stream_addr((APTR *) & dataStream, + indices[i]); + } + + } + else + { + /* + ** We already went through the output phase. So this is + ** the end of it. + */ + end = TRUE; + } + } + else + template_pos++; + + //kprintf("OUTPUT: template_pos: %d\n",template_pos); + + break; + + case FOUND_FORMAT: + /* + ** The '%' was found in the template string + */ + template_pos++; + + //kprintf("FOUND_FORMAT: template_pos: %d\n",template_pos); + /* + ** Does the user want the '%' to be printed? + */ + if (fmtTemplate[template_pos] == '%') + { + if (!scanning) + { + AROS_UFC3(VOID, putCharFunc->h_Entry, + AROS_UFCA(const struct Hook *, putCharFunc, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(UBYTE, fmtTemplate[template_pos], A1)); + } + template_pos++; + arg_counter--; //stegerg + } + else + { + /* + ** Now parsing... + ** Template format: %[arg_pos$][flags][width][.limit][length]type + ** + ** arg_pos specifies the position of the argument in the dataStream + ** flags only '-' is allowed + ** width + ** .limit + ** datasize size of the datatype + ** type b,d,D,u,U,x,X,s,c + */ + ULONG arg_pos = 1; + BOOL left = FALSE; // no flag was found + UBYTE fill = ' '; + ULONG minus; + ULONG width = 0; + ULONG limit = ~0; + ULONG buflen = 0; + ULONG datasize; + UFMTLARGESTTYPE tmp = 0; +#define BUFFERSIZE 128 + UBYTE buf[BUFFERSIZE]; + UBYTE *buffer = buf; + + /* + ** arg_pos + */ + + //kprintf("next char: %c\n",fmtTemplate[template_pos]); + + if (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9') + { + ULONG old_template_pos = template_pos; + + for (arg_pos = 0; (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9'); + template_pos++) + { + arg_pos = + arg_pos * 10 + fmtTemplate[template_pos] - '0'; + } + + if (fmtTemplate[template_pos] == '$') + template_pos++; + else + { + arg_pos = arg_counter; + template_pos = old_template_pos; + } + } + else + arg_pos = arg_counter; + + /* + ** flags + */ + if (fmtTemplate[template_pos] == '-') + { + template_pos++; + left = TRUE; + } + + /* + ** fill character a '0'? + */ + if (fmtTemplate[template_pos] == '0') + { + template_pos++; + fill = '0'; + } + + /* + ** width + */ + if (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9') + { + for (width = 0; (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9'); + template_pos++) + { + width = + width * 10 + fmtTemplate[template_pos] - '0'; + } + } + + /* + ** limit + */ + if (fmtTemplate[template_pos] == '.') + { + template_pos++; + + if (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9') + { + for (limit = 0; (fmtTemplate[template_pos] >= '0' && + fmtTemplate[template_pos] <= '9'); + template_pos++) + { + limit = + limit * 10 + fmtTemplate[template_pos] - + '0'; + } + } + } + + /* + ** Length + */ + switch (fmtTemplate[template_pos]) + { +#if USE_QUADFMT + case 'L': + datasize = sizeof(UQUAD); + template_pos++; + break; +#endif /* USE_QUADFMT */ + + case 'l': + template_pos++; +#if USE_QUADFMT + if (fmtTemplate[template_pos] == 'l') + { + datasize = sizeof(UQUAD); + template_pos++; + } + else +#endif /* USE_QUADFMT */ + datasize = sizeof(ULONG); + break; + + default: + /* For C-style varargs default size is ULONG, single 'l' is effectively ignored */ + datasize = + is_va_list(VaListStream) ? sizeof(ULONG) : + sizeof(UWORD); + break; + } + + /* + ** Print it according to the given type info. + */ + switch (fmtTemplate[template_pos]) + { + case 'b': /* BSTR, see autodocs */ + /* + ** Important parameters: + ** arg_pos, left, buflen, limit + */ + if (!scanning) + { + BSTR s = (BSTR) * (UBYTE **) indices[arg_pos - 1]; + + if (s != (BSTR) BNULL) + { + buffer = AROS_BSTR_ADDR(s); + buflen = AROS_BSTR_strlen(s); + } + else + { + buffer = ""; + buflen = 0; + } + +#if !USE_GLOBALLIMIT + if (buflen > limit) + buflen = limit; +#endif /* !USE_GLOBALLIMIT */ + } + else + indices[arg_pos - 1] = sizeof(BPTR); + break; + + case 'd': /* signed decimal */ + case 'u': /* unsigned decimal */ + + minus = fmtTemplate[template_pos] == 'd'; + + if (!scanning) + { + switch (datasize) + { +#if USE_QUADFMT + case 8: + tmp = *(UQUAD *) indices[arg_pos - 1]; + //buffer = &buf[16+1]; + minus *= (FMTLARGESTTYPE) tmp < 0; + if (minus) + tmp = -tmp; + break; +#endif /* USE_QUADFMT */ + + case 4: + tmp = *(ULONG *) indices[arg_pos - 1]; + //buffer = &buf[8+1]; + minus *= (LONG) tmp < 0; + if (minus) + tmp = (ULONG) - tmp; + break; + + default: /* 2 */ + tmp = *(UWORD *) indices[arg_pos - 1]; + //buffer = &buf[4+1]; + minus *= (WORD) tmp < 0; + if (minus) + tmp = (UWORD) - tmp; + break; + } + + buffer = &buf[BUFFERSIZE]; + do + { + *--buffer = (tmp % 10) + '0'; + tmp /= 10; + buflen++; + } + while (tmp); + + if (minus) + { + *--buffer = '-'; + buflen++; + } + + } + else + indices[arg_pos - 1] = datasize; + break; + + case 'D': /* signed decimal with locale's formatting conventions */ + case 'U': /* unsigned decimal with locale's formatting conventions */ + if (!scanning) + { + UBYTE groupsize; + ULONG group_index = 0; + + minus = fmtTemplate[template_pos] == 'D'; + + switch (datasize) + { +#if USE_QUADFMT + case 8: + tmp = *(UQUAD *) indices[arg_pos - 1]; + minus *= (FMTLARGESTTYPE) tmp < 0; + if (minus) + tmp = -tmp; + break; +#endif /* USE_QUADFMT */ + + case 4: + tmp = *(ULONG *) indices[arg_pos - 1]; + minus *= (LONG) tmp < 0; + if (minus) + tmp = (ULONG) - tmp; + break; + + default: /* 2 */ + tmp = *(UWORD *) indices[arg_pos - 1]; + minus *= (WORD) tmp < 0; + if (minus) + tmp = (UWORD) - tmp; + break; + } + + /* BUFFERSIZE should be big enough to format a string + ** according to locale's formatting conventions + */ + buffer = &buf[BUFFERSIZE]; + groupsize = + locale ? locale-> + loc_Grouping[group_index] : 255; + + do + { + *--buffer = (tmp % 10) + '0'; + tmp /= 10; + buflen++; + + groupsize--; + + if (groupsize == 0 && tmp != 0) + { + /* + ** Write the separator + */ + + *--buffer = + locale->loc_GroupSeparator[group_index]; + + groupsize = + locale->loc_Grouping[group_index + 1]; + + if (groupsize == 0) + { + /* + ** Supposed to use the previous element + */ + groupsize = + locale->loc_Grouping[group_index]; + } + else + group_index++; + + buflen++; + } + } + while (tmp); + + if (minus) + { + *--buffer = '-'; + buflen++; + } + } + else + indices[arg_pos - 1] = datasize; + break; + + case 'p': /* lower case pointer string */ + case 'P': /* upper case pointer string */ + fill = '0'; + width = sizeof(APTR) * 2; + /* %p is always at least natural pointer size */ + if (datasize < sizeof(APTR)) + datasize = sizeof(APTR); + case 'x': /* upper case hexadecimal string */ + case 'X': /* lower case hexadecimal string */ + + if (!scanning) + { + const UBYTE *hexa; + + switch (datasize) + { +#if USE_QUADFMT + case 8: + tmp = *(UQUAD *) indices[arg_pos - 1]; + //buffer = &buf[16+1]; + break; +#endif /* USE_QUADFMT */ + + case 4: + tmp = *(ULONG *) indices[arg_pos - 1]; + //buffer = &buf[8+1]; + break; + + default: /* 2 */ + tmp = *(UWORD *) indices[arg_pos - 1]; + //buffer = &buf[4+1]; + break; + } + + buffer = &buf[BUFFERSIZE]; + + /* NOTE: x/X is reverse to printf, coz orig RawDoFmt %lx for uppercase. */ + hexa = (fmtTemplate[template_pos] == 'X' || + fmtTemplate[template_pos] == + 'p') ? hexarray : HEXarray; + do + { + *--buffer = hexa[tmp & 0x0f]; + tmp >>= 4; + buflen++; + } + while (tmp); + } + else + indices[arg_pos - 1] = datasize; + break; + + case 's': /* NULL terminated string */ + { + if (!scanning) + { + buffer = *(UBYTE **) indices[arg_pos - 1]; + + /* + * RawDoFmt() in original AmigaOS(tm) formats NULL pointers as empty strings, + * and not something like "(null)". Some software may rely on this behavior. + * %b is handled in similar manner. + */ + if (!buffer) + buffer = ""; + buflen = strlen(buffer); + +#if !USE_GLOBALLIMIT + if (buflen > limit) + buflen = limit; +#endif /* !USE_GLOBALLIMIT */ + } + else + indices[arg_pos - 1] = sizeof(UBYTE *); /* the pointer has 4 bytes */ + } + break; + + case 'c': /* Character */ + if (!scanning) + { + switch (datasize) + { +#if USE_QUADFMT + case 8: + buf[0] = + (UBYTE) * (UQUAD *) indices[arg_pos - 1]; + break; +#endif /* USE_QUADFMT */ + + case 4: + buf[0] = + (UBYTE) * (ULONG *) indices[arg_pos - 1]; + break; + + default: /* 2 */ + buf[0] = + (UBYTE) * (WORD *) indices[arg_pos - 1]; + break; + } + + buflen = 1; + } + else + indices[arg_pos - 1] = datasize; + break; + + default: + /* Ignore the faulty '%' */ + + if (!scanning) + { + buf[0] = fmtTemplate[template_pos]; + width = 1; + buflen = 1; + } + + arg_pos = --arg_counter; + break; + } + + + if (!scanning) + { + int i; + + /* + Now everything I need is known: + buffer - contains the string to be printed + buflen - size of the string + fill - the pad character + left - is 1 if the string should be left aligned + width - is the minimal width of the field + limit - maximum number of characters to output from a string, default ~0 + */ + +#if USE_GLOBALLIMIT + if (buflen > limit) + buflen = limit; +#endif /* USE_GLOBALLIMIT */ + + /* Print padding if right aligned */ + if (!left) + for (i = buflen; i < width; i++) + AROS_UFC3(VOID, putCharFunc->h_Entry, + AROS_UFCA(const struct Hook *, putCharFunc, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(UBYTE, fill, A1)); + + /* Print body up to buflen */ + for (i = 0; i < buflen; i++) + { + AROS_UFC3(VOID, putCharFunc->h_Entry, + AROS_UFCA(const struct Hook *, putCharFunc, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(UBYTE, *buffer++, A1)); + } + + /* Pad right if left aligned */ + if (left) + for (i = buflen; i < width; i++) + AROS_UFC3(VOID, putCharFunc->h_Entry, + AROS_UFCA(const struct Hook *, putCharFunc, A0), + AROS_UFCA(const struct Locale *, locale, A2), + AROS_UFCA(UBYTE, fill, A1)); + } + + template_pos++; + + if (arg_pos > max_argpos) + max_argpos = arg_pos; + + } + state = OUTPUT; + break; + } + } + + return (APTR) indices[max_argpos]; +} + +/***************************************************************************** + + NAME */ +#include + + AROS_LH4(APTR, FormatString, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(CONST_STRPTR, fmtTemplate, A1), + AROS_LHA(CONST_APTR, dataStream, A2), + AROS_LHA(const struct Hook *, putCharFunc, A3), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 11, Locale) + +/* FUNCTION + + INPUTS + + RESULT + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + null_va_list(vaListStream); + + return InternalFormatString(locale, fmtTemplate, dataStream, + putCharFunc, vaListStream); + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/getcatalogstr.c b/workbench/libs/locale/getcatalogstr.c dissimilarity index 71% index 7c09effe4c..5ada000518 100644 --- a/workbench/libs/locale/getcatalogstr.c +++ b/workbench/libs/locale/getcatalogstr.c @@ -1,95 +1,91 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ - - Desc: - Lang: english -*/ - -#include -#include -#include "locale_intern.h" - -/***************************************************************************** - - NAME */ -#include - - AROS_LH3(CONST_STRPTR, GetCatalogStr, - -/* SYNOPSIS */ - AROS_LHA(const struct Catalog *, catalog, A0), - AROS_LHA(ULONG, stringNum, D0), /* Not a typo! Needs to be unsigned for ICF_INORDER */ - AROS_LHA(CONST_STRPTR, defaultString, A1), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 12, Locale) - -/* FUNCTION - This function will return the string specified by the - stringNum from the given message catalog, or the defaultString - if the string could not be found. - - If the catalog == NULL, then the defaultString will also be - returned. - - INPUTS - catalog - Message catalog to search. May be NULL. - stringNum - ID of the string to find. - defaultString - String to return in case catalog is NULL or - string could not be found. - - RESULT - A pointer to a READ ONLY NULL terminated string. This string - pointer is valid as long as the catalog remains open. - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - OpenCatalogA(), CloseCatalog() - - INTERNALS - - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - CONST_STRPTR str = defaultString; - - if(catalog != NULL) - { - struct CatStr *cs = IntCat(catalog)->ic_CatStrings; - ULONG numstrings = IntCat(catalog)->ic_NumStrings; - ULONG i = 0; - - for(i = 0; i < numstrings; i++, cs++) - { - if(cs->cs_Id == stringNum) - { - str = cs->cs_String; - break; - } - else - { - if((IntCat(catalog)->ic_Flags & ICF_INORDER) && - (cs->cs_Id > stringNum)) - { - break; - } - } - } - } - - return str; - - AROS_LIBFUNC_EXIT - -} /* GetCatalogStr */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: + Lang: english +*/ + +#include +#include +#include "locale_intern.h" + +/***************************************************************************** + + NAME */ +#include + + AROS_LH3(CONST_STRPTR, GetCatalogStr, + +/* SYNOPSIS */ + AROS_LHA(const struct Catalog *, catalog, A0), + AROS_LHA(ULONG, stringNum, D0), /* Not a typo! Needs to be unsigned for ICF_INORDER */ + AROS_LHA(CONST_STRPTR, defaultString, A1), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 12, Locale) + +/* FUNCTION + This function will return the string specified by the + stringNum from the given message catalog, or the defaultString + if the string could not be found. + + If the catalog == NULL, then the defaultString will also be + returned. + + INPUTS + catalog - Message catalog to search. May be NULL. + stringNum - ID of the string to find. + defaultString - String to return in case catalog is NULL or + string could not be found. + + RESULT + A pointer to a READ ONLY NULL terminated string. This string + pointer is valid as long as the catalog remains open. + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + OpenCatalogA(), CloseCatalog() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + CONST_STRPTR str = defaultString; + + if (catalog != NULL) + { + struct CatStr *cs = IntCat(catalog)->ic_CatStrings; + ULONG numstrings = IntCat(catalog)->ic_NumStrings; + ULONG i = 0; + + for (i = 0; i < numstrings; i++, cs++) + { + if (cs->cs_Id == stringNum) + { + str = cs->cs_String; + + break; + } + else + { + if ((IntCat(catalog)->ic_Flags & ICF_INORDER) && + (cs->cs_Id > stringNum)) + { + break; + } + } + } + } + + return str; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/getlocalestr.c b/workbench/libs/locale/getlocalestr.c index 802b6e1268..9f0c720cde 100644 --- a/workbench/libs/locale/getlocalestr.c +++ b/workbench/libs/locale/getlocalestr.c @@ -1,10 +1,11 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: GetLocaleStr() - Get a built-in system string. Lang: english */ + #include #include #include "locale_intern.h" @@ -15,29 +16,29 @@ NAME */ #include - AROS_LH2(CONST_STRPTR, GetLocaleStr, + AROS_LH2(CONST_STRPTR, GetLocaleStr, /* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(ULONG , stringNum, D0), + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(ULONG, stringNum, D0), /* LOCATION */ - struct LocaleBase *, LocaleBase, 13, Locale) + struct LocaleBase *, LocaleBase, 13, Locale) /* FUNCTION - This function will return a system standard string from - the current Locale. + This function will return a system standard string from + the current Locale. INPUTS - locale - The current locale. - stringNum - The number of the string to get a pointer to. - See the include file - for a list of possible values. + locale - The current locale. + stringNum - The number of the string to get a pointer to. + See the include file + for a list of possible values. RESULT - A pointer to a NULL-terminated string, or NULL if the string - requested was unknown. The returned string is READ-ONLY and - is valid only as long as the Locale remains open. + A pointer to a NULL-terminated string, or NULL if the string + requested was unknown. The returned string is READ-ONLY and + is valid only as long as the Locale remains open. NOTES @@ -55,13 +56,12 @@ #ifdef AROS_CALL1 return AROS_CALL1(CONST_STRPTR, IntL(locale)->il_LanguageFunctions[3], - AROS_LCA(ULONG, stringNum, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, stringNum, D0), struct LocaleBase *, LocaleBase); #else return AROS_UFC2(CONST_STRPTR, IntL(locale)->il_LanguageFunctions[3], - AROS_UFCA(ULONG, stringNum, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, stringNum, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT -} /* GetLocaleStr */ +} diff --git a/workbench/libs/locale/initlocale.c b/workbench/libs/locale/initlocale.c index 40a8ace087..17490ffb09 100644 --- a/workbench/libs/locale/initlocale.c +++ b/workbench/libs/locale/initlocale.c @@ -31,8 +31,7 @@ AROS_LD4(ULONG, strcompare, AROS_UFPA(STRPTR, string2, A2), AROS_UFPA(ULONG, length, D0), AROS_UFPA(ULONG, how, D1), - struct LocaleBase *, LocaleBase, 22, english -); + struct LocaleBase *, LocaleBase, 22, english); extern void *__eng_functable[]; @@ -45,10 +44,10 @@ extern void *__eng_functable[]; } /* - void SetLocaleLanguage(struct IntLocale *, struct LocaleBase *) + void SetLocaleLanguage(struct IntLocale *, struct LocaleBase *) - Try and set up the language of a Locale structure. -*/ + Try and set up the language of a Locale structure. + */ void SetLocaleLanguage(struct IntLocale *il, struct LocaleBase *LocaleBase) { @@ -57,207 +56,228 @@ void SetLocaleLanguage(struct IntLocale *il, struct LocaleBase *LocaleBase) STRPTR fileBuf; int i = 0; - DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: Locale 0x%lx\n",il)); + DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: Locale 0x%lx\n", il)); fileBuf = AllocMem(PATH_MAX, MEMF_ANY); if (!fileBuf) - return; + return; - while(lang == NULL && i < 10) + while (lang == NULL && i < 10) { - STRPTR lName = il->il_Locale.loc_PrefLanguages[i]; + STRPTR lName = il->il_Locale.loc_PrefLanguages[i]; ULONG ret; - if (lName != NULL) - { + if (lName != NULL) + { + + /* Is this english? If not try and load the language */ + void *fn = AROS_SLIB_ENTRY(strcompare, english, 22); + + ret = AROS_CALL4(ULONG, fn, + AROS_LCA(STRPTR, defLocale.loc_PrefLanguages[0], A1), + AROS_LCA(STRPTR, lName, A2), + AROS_LCA(ULONG, 7, D0), + AROS_LCA(ULONG, SC_ASCII, D1), + struct LocaleBase *, LocaleBase); + + if (ret != 0) + { + snprintf(fileBuf, PATH_MAX, "%s.language", lName); + fileBuf[PATH_MAX - 1] = 0; + + /* Try and open the specified language */ + lang = OpenLibrary(fileBuf, 0); + +#ifdef __MORPHOS + if (lang == NULL) + { + /* + Ok, so the language didn't open, lets try for + MOSSYS:LOCALE/Languages/xxx.language + */ + + snprintf(fileBuf, PATH_MAX, + "MOSSYS:LOCALE/Languages/%s.language", lName); + fileBuf[PATH_MAX - 1] = 0; + + { + APTR oldwinptr; + struct Process *me = + (struct Process *)FindTask(NULL); + oldwinptr = me->pr_WindowPtr; + me->pr_WindowPtr = (APTR) - 1; + lang = OpenLibrary(fileBuf, 0); + me->pr_WindowPtr = oldwinptr; + } + } +#endif - /* Is this english? If not try and load the language */ - void *fn = AROS_SLIB_ENTRY(strcompare, english, 22); - - ret = AROS_CALL4(ULONG, fn, - AROS_LCA(STRPTR, defLocale.loc_PrefLanguages[0], A1), - AROS_LCA(STRPTR, lName, A2), - AROS_LCA(ULONG, 7, D0), - AROS_LCA(ULONG, SC_ASCII, D1), - struct LocaleBase *, LocaleBase); - - if (ret != 0) - { - snprintf(fileBuf, PATH_MAX, "%s.language", lName); - fileBuf[PATH_MAX-1] = 0; - - /* Try and open the specified language */ - lang = OpenLibrary(fileBuf, 0); - - #ifdef __MORPHOS - if(lang == NULL) - { - /* - Ok, so the language didn't open, lets try for - MOSSYS:LOCALE/Languages/xxx.language - */ - - snprintf(fileBuf, PATH_MAX, "MOSSYS:LOCALE/Languages/%s.language", lName); - fileBuf[PATH_MAX-1] = 0; - - { APTR oldwinptr; - struct Process *me=(struct Process *)FindTask(NULL); - oldwinptr = me->pr_WindowPtr; - me->pr_WindowPtr = (APTR) -1; - lang = OpenLibrary(fileBuf, 0); - me->pr_WindowPtr = oldwinptr; - } - } - #endif - - if(lang == NULL) - { - /* - Ok, so the language didn't open, lets try for - LOCALE:Languages/xxx.language - */ - - snprintf(fileBuf, PATH_MAX, "LOCALE:Languages/%s.language", lName); - fileBuf[PATH_MAX-1] = 0; - - lang = OpenLibrary(fileBuf, 0); - } - - if((lang == NULL) && ((((struct Process *)FindTask(NULL))->pr_HomeDir) != BNULL)) - { - /* - Ok, so we are still NULL, lets then try for - PROGDIR:Languages/xxx.language - */ - snprintf(fileBuf, PATH_MAX, "PROGDIR:Languages/%s.language", lName); - fileBuf[PATH_MAX-1] = 0; - - lang = OpenLibrary(fileBuf, 0); - } - - if (lang) - { - strncpy(il->LanguageName, FilePart(fileBuf), 30); - } - - /* If it is still no good, then we have no hope */ - } - } - i++; + if (lang == NULL) + { + /* + Ok, so the language didn't open, lets try for + LOCALE:Languages/xxx.language + */ + + snprintf(fileBuf, PATH_MAX, + "LOCALE:Languages/%s.language", lName); + fileBuf[PATH_MAX - 1] = 0; + + lang = OpenLibrary(fileBuf, 0); + } + + if ((lang == NULL) + && ((((struct Process *)FindTask(NULL))->pr_HomeDir) != + BNULL)) + { + /* + Ok, so we are still NULL, lets then try for + PROGDIR:Languages/xxx.language + */ + snprintf(fileBuf, PATH_MAX, + "PROGDIR:Languages/%s.language", lName); + fileBuf[PATH_MAX - 1] = 0; + + lang = OpenLibrary(fileBuf, 0); + } + + if (lang) + { + strncpy(il->LanguageName, FilePart(fileBuf), 30); + } + + /* If it is still no good, then we have no hope */ + } + } + i++; } if (lang == NULL) { - strcpy(il->LanguageName, defLocale.loc_LanguageName); + strcpy(il->LanguageName, defLocale.loc_LanguageName); } il->il_Locale.loc_LanguageName = &il->LanguageName[0]; - + /* - Ok so we now should have a language, or nothing. Either way - we now fill in the locale functions in the structure. - I remember there was a VERY big bug in here once, which I - finally managed to fix, only to blow away the only copy - of the file (and the rest of the locale.library) from all - existance. Sigh. + Ok so we now should have a language, or nothing. Either way + we now fill in the locale functions in the structure. + I remember there was a VERY big bug in here once, which I + finally managed to fix, only to blow away the only copy + of the file (and the rest of the locale.library) from all + existance. Sigh. - If we could open any of the libraries, replace its function, - otherwise replace none of them. - */ + If we could open any of the libraries, replace its function, + otherwise replace none of them. + */ il->il_CurrentLanguage = lang; - if(lang != NULL) + if (lang != NULL) { - mask = AROS_LC0(ULONG, mask, struct Library *, lang, 5, Language); + mask = AROS_LC0(ULONG, mask, struct Library *, lang, 5, Language); } else - mask = 0; + mask = 0; - DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: Language Mask 0x%lx\n",mask)); - /* CONST: If we add any more functions we need to increase this number */ - for(i = 0; i < 17; i++) + DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: Language Mask 0x%lx\n", + mask)); + /* CONST: If we add any more functions we need to increase this number */ + for (i = 0; i < 17; i++) { - if(mask & (1<il_LanguageFunctions[i] = (APTR)(((ULONG)lang) - ((i+6)*6)); - #else - il->il_LanguageFunctions[i] = __AROS_GETVECADDR(lang, (i+6)); - #endif - DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: use Lanugage Entry %ld Func 0x%lx\n",i,il->il_LanguageFunctions[i])); - } - else - { + if (mask & (1 << i)) + { +#ifdef __MORPHOS__ + il->il_LanguageFunctions[i] = + (APTR) (((ULONG) lang) - ((i + 6) * 6)); +#else + il->il_LanguageFunctions[i] = __AROS_GETVECADDR(lang, (i + 6)); +#endif + DEBUG_INITLOCALE(dprintf + ("SetLocaleLanguage: use Lanugage Entry %ld Func 0x%lx\n", + i, il->il_LanguageFunctions[i])); + } + else + { il->il_LanguageFunctions[i] = __eng_functable[i]; - DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: use Default Entry %ld Func 0x%lx\n",i,il->il_LanguageFunctions[i])); - } + DEBUG_INITLOCALE(dprintf + ("SetLocaleLanguage: use Default Entry %ld Func 0x%lx\n", i, + il->il_LanguageFunctions[i])); + } } /* Open dos.catalog (needed for DosGetLocalizedString patch) */ - il->il_DosCatalog = OpenCatalogA((struct Locale *)il, "System/Libs/dos.catalog", NULL); + il->il_DosCatalog = + OpenCatalogA((struct Locale *)il, "System/Libs/dos.catalog", NULL); - DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: DosCatalog 0x%lx\n",il->il_DosCatalog)); + DEBUG_INITLOCALE(dprintf("SetLocaleLanguage: DosCatalog 0x%lx\n", + il->il_DosCatalog)); FreeMem(fileBuf, PATH_MAX); } /* InitLocale(IntLocale *, LocalePrefs *) - This procedure will extract all the relevant information out of - a LocalePrefs structure, and stuff it into a IntLocale structure. + This procedure will extract all the relevant information out of + a LocalePrefs structure, and stuff it into a IntLocale structure. - This is really a silly way of doing things, but unfortunately it - is the only way that doesn't keep the entire chunk in memory, - (by duplicating the LocalePrefs chunk), or by doing extra loops - on things (counting string sizes, then allocating). + This is really a silly way of doing things, but unfortunately it + is the only way that doesn't keep the entire chunk in memory, + (by duplicating the LocalePrefs chunk), or by doing extra loops + on things (counting string sizes, then allocating). - This puts it smack bang in the centre of speed/memory use. - This is mainly a separate procedure to get rid of the indentation. -*/ + This puts it smack bang in the centre of speed/memory use. + This is mainly a separate procedure to get rid of the indentation. + */ void InitLocale(STRPTR filename, struct IntLocale *locale, - struct LocalePrefs *lp, struct LocaleBase *LocaleBase) + struct LocalePrefs *lp, struct LocaleBase *LocaleBase) { struct CountryPrefs *cp; int i, i2; - DEBUG_INITLOCALE(dprintf("InitLocale: filename <%s> Locale 0x%lx LocalePrefs 0x%lx\n",filename,locale,lp)); + DEBUG_INITLOCALE(dprintf + ("InitLocale: filename <%s> Locale 0x%lx LocalePrefs 0x%lx\n", + filename, locale, lp)); cp = &lp->lp_CountryData; strncpy(locale->LocaleName, FilePart(filename), 30); locale->il_Locale.loc_LocaleName = &locale->LocaleName[0]; - + /* - We can copy 300 bytes straight away since - the prefered languages are all in a row. - */ + We can copy 300 bytes straight away since + the prefered languages are all in a row. + */ CopyMem(lp->lp_PreferredLanguages[0], - locale->PreferredLanguages[0], 300); + locale->PreferredLanguages[0], 300); - for(i = 0, i2 = 0; i < 10; i++) + for (i = 0, i2 = 0; i < 10; i++) { - if (locale->PreferredLanguages[i][0]) - { - locale->il_Locale.loc_PrefLanguages[i2++] = locale->PreferredLanguages[i]; - } + if (locale->PreferredLanguages[i][0]) + { + locale->il_Locale.loc_PrefLanguages[i2++] = + locale->PreferredLanguages[i]; + } } if (i2 == 0) { - /* The user did not set any preferred Language. So we automatically - poke "english" into the array (Tested on the Amiga where this - does seem to happen, too!) */ - - DEBUG_INITLOCALE(dprintf("InitLocale: user set no preferred lang\n")); - strcpy(locale->PreferredLanguages[0], defLocale.loc_PrefLanguages[0]); - locale->il_Locale.loc_PrefLanguages[0] = locale->PreferredLanguages[0]; + /* The user did not set any preferred Language. So we automatically + poke "english" into the array (Tested on the Amiga where this + does seem to happen, too!) */ + + DEBUG_INITLOCALE(dprintf + ("InitLocale: user set no preferred lang\n")); + strcpy(locale->PreferredLanguages[0], + defLocale.loc_PrefLanguages[0]); + locale->il_Locale.loc_PrefLanguages[0] = + locale->PreferredLanguages[0]; } - + /* - If we cannot open ANY of the languages, then all the language - function vectors would have the default language data. - */ + If we cannot open ANY of the languages, then all the language + function vectors would have the default language data. + */ SetLocaleLanguage(locale, LocaleBase); locale->il_Locale.loc_Flags = lp->lp_Flags; @@ -275,28 +295,31 @@ void InitLocale(STRPTR filename, struct IntLocale *locale, #endif /* Another really large section to copy, - from cp_DateTimeFormat[] to cp_MonFracGrouping[] incl - 80 + 40 + 40 + 80 + 40 + 40 + (10 * 10) - */ + from cp_DateTimeFormat[] to cp_MonFracGrouping[] incl + 80 + 40 + 40 + 80 + 40 + 40 + (10 * 10) + */ CopyMem(&cp->cp_DateTimeFormat[0], &locale->DateTimeFormat[0], 420); locale->il_Locale.loc_DateTimeFormat = &locale->DateTimeFormat[0]; locale->il_Locale.loc_DateFormat = &locale->DateFormat[0]; locale->il_Locale.loc_TimeFormat = &locale->TimeFormat[0]; - locale->il_Locale.loc_ShortDateTimeFormat = &locale->ShortDateTimeFormat[0]; + locale->il_Locale.loc_ShortDateTimeFormat = + &locale->ShortDateTimeFormat[0]; locale->il_Locale.loc_ShortDateFormat = &locale->ShortDateFormat[0]; locale->il_Locale.loc_ShortTimeFormat = &locale->ShortTimeFormat[0]; locale->il_Locale.loc_DecimalPoint = &locale->DecimalPoint[0]; locale->il_Locale.loc_GroupSeparator = &locale->GroupSeparator[0]; - locale->il_Locale.loc_FracGroupSeparator = &locale->FracGroupSeparator[0]; + locale->il_Locale.loc_FracGroupSeparator = + &locale->FracGroupSeparator[0]; locale->il_Locale.loc_Grouping = &locale->Grouping[0]; locale->il_Locale.loc_FracGrouping = &locale->FracGrouping[0]; locale->il_Locale.loc_MonDecimalPoint = &locale->MonDecimalPoint[0]; locale->il_Locale.loc_MonGroupSeparator = &locale->MonGroupSeparator[0]; - locale->il_Locale.loc_MonFracGroupSeparator = &locale->MonFracGroupSeparator[0]; + locale->il_Locale.loc_MonFracGroupSeparator = + &locale->MonFracGroupSeparator[0]; locale->il_Locale.loc_MonGrouping = &locale->MonGrouping[0]; locale->il_Locale.loc_MonFracGrouping = &locale->MonFracGrouping[0]; @@ -324,4 +347,3 @@ void InitLocale(STRPTR filename, struct IntLocale *locale, DEBUG_INITLOCALE(dprintf("InitLocale: done\n")); } - diff --git a/workbench/libs/locale/isxxxx.c b/workbench/libs/locale/isxxxx.c index 0d90a13df4..77c3be5eae 100644 --- a/workbench/libs/locale/isxxxx.c +++ b/workbench/libs/locale/isxxxx.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: IsXXXX() - Stub for Language isXXXXX() functions. @@ -14,48 +14,48 @@ NAME #include - AROS_LH2(BOOL, IsXXXX, + AROS_LH2(BOOL, IsXXXX, SYNOPSIS - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(ULONG, character, D0), + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(ULONG, character, D0), LOCATION - struct LocaleBase *, LocaleBase, 0, Locale) + struct LocaleBase *, LocaleBase, 0, Locale) FUNCTION - These functions allow you to find out whether a character - matches a certain type according to the current Locale - settings. - - The functions available are: - - IsAlNum() - is this an alphanumeric character - IsAlpha() - is this an alphabet character - IsCntrl() - is this a control character - IsDigit() - is this a decimal digit character - IsGraph() - is this a graphical character - IsLower() - is this a lowercase character - IsPrint() - is this a printable character - IsPunct() - is this a punctuation character - IsSpace() - is this a whitespace character - IsUpper() - is this an uppercase character - IsXDigit() - is this a hexadecimal digit + These functions allow you to find out whether a character + matches a certain type according to the current Locale + settings. + + The functions available are: + + IsAlNum() - is this an alphanumeric character + IsAlpha() - is this an alphabet character + IsCntrl() - is this a control character + IsDigit() - is this a decimal digit character + IsGraph() - is this a graphical character + IsLower() - is this a lowercase character + IsPrint() - is this a printable character + IsPunct() - is this a punctuation character + IsSpace() - is this a whitespace character + IsUpper() - is this an uppercase character + IsXDigit() - is this a hexadecimal digit INPUTS - locale - The Locale to use for this function. - character - the character to test + locale - The Locale to use for this function. + character - the character to test RESULT - ind - An indication of whether the character matches the type. - TRUE - if the character is of the required type, - FALSE - otherwise + ind - An indication of whether the character matches the type. + TRUE - if the character is of the required type, + FALSE - otherwise NOTES - The Locale MUST be supplied. + The Locale MUST be supplied. - These functions require a 32-bit character to support future - multi-byte character sets. + These functions require a 32-bit character to support future + multi-byte character sets. EXAMPLE @@ -77,12 +77,12 @@ AROS_LH2(ULONG, IsAlNum, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[4], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[4], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -97,12 +97,12 @@ AROS_LH2(ULONG, IsAlpha, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[5], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[5], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -117,12 +117,12 @@ AROS_LH2(ULONG, IsCntrl, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[6], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[6], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -137,12 +137,12 @@ AROS_LH2(ULONG, IsDigit, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[7], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[7], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -157,12 +157,12 @@ AROS_LH2(ULONG, IsGraph, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[8], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[8], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -177,12 +177,12 @@ AROS_LH2(ULONG, IsLower, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[9], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[9], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -197,12 +197,12 @@ AROS_LH2(ULONG, IsPrint, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[10], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[10], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -217,12 +217,12 @@ AROS_LH2(ULONG, IsPunct, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[11], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[11], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -237,12 +237,12 @@ AROS_LH2(ULONG, IsSpace, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[12], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[12], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -257,12 +257,12 @@ AROS_LH2(ULONG, IsUpper, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[13], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[13], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT @@ -277,12 +277,12 @@ AROS_LH2(ULONG, IsXDigit, #ifdef AROS_CALL1 return AROS_CALL1(BOOL, IntL(locale)->il_LanguageFunctions[14], - AROS_LCA(ULONG, character, D0), - struct LocaleBase *, LocaleBase); + AROS_LCA(ULONG, character, D0), + struct LocaleBase *, LocaleBase); #else return AROS_UFC2(ULONG, IntL(locale)->il_LanguageFunctions[14], - AROS_UFCA(ULONG, character, D0), - AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); + AROS_UFCA(ULONG, character, D0), + AROS_UFCA(struct LocaleBase *, LocaleBase, A6)); #endif AROS_LIBFUNC_EXIT diff --git a/workbench/libs/locale/locale_init.c b/workbench/libs/locale/locale_init.c index 69cc9daaf5..ba55a8bf25 100644 --- a/workbench/libs/locale/locale_init.c +++ b/workbench/libs/locale/locale_init.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2006, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: Initialisation for the locale.library. @@ -33,30 +33,31 @@ static int Init(LIBBASETYPEPTR LIBBASE) /* A few internal functions need to access a global LocaleBase pointer, because they're used to patch dos.library functions, and thus don't directly get a LocaleBase pointer. Someday, with TLS, this will go away. */ - globallocalebase = (struct LocaleBase *) LIBBASE; - + globallocalebase = (struct LocaleBase *)LIBBASE; + /* Do whatever static initialisation you need here */ InitSemaphore(&((struct IntLocaleBase *)LIBBASE)->lb_LocaleLock); InitSemaphore(&((struct IntLocaleBase *)LIBBASE)->lb_CatalogLock); NEWLIST(&((struct IntLocaleBase *)LIBBASE)->lb_CatalogList); - IntLB(LIBBASE)->lb_DefaultLocale = def = AllocMem(sizeof(struct IntLocale), MEMF_CLEAR|MEMF_ANY); - if(def != NULL) + IntLB(LIBBASE)->lb_DefaultLocale = def = + AllocMem(sizeof(struct IntLocale), MEMF_CLEAR | MEMF_ANY); + if (def != NULL) { - /* Copy the defaults to our new structure */ - CopyMem(&defLocale, def, sizeof(struct Locale)); + /* Copy the defaults to our new structure */ + CopyMem(&defLocale, def, sizeof(struct Locale)); + + /* Set lb_CurrentLocale *BEFORE* SetLocaleLanguage */ + IntLB(LIBBASE)->lb_CurrentLocale = def; - /* Set lb_CurrentLocale *BEFORE* SetLocaleLanguage */ - IntLB(LIBBASE)->lb_CurrentLocale = def; + /* Setup the languages - will not fail here. */ + SetLocaleLanguage(def, (struct LocaleBase *)LIBBASE); - /* Setup the languages - will not fail here. */ - SetLocaleLanguage(def, (struct LocaleBase *) LIBBASE); + def->il_Count = 0; + InstallPatches(); - def->il_Count = 0; - InstallPatches(); - - return TRUE; + return TRUE; } return FALSE; diff --git a/workbench/libs/locale/locale_intern.h b/workbench/libs/locale/locale_intern.h index 2708a2892f..5edb7aeff7 100644 --- a/workbench/libs/locale/locale_intern.h +++ b/workbench/libs/locale/locale_intern.h @@ -1,5 +1,5 @@ /* - Copyright © 1995-2006, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: Internal definitions for the locale.library. @@ -42,7 +42,7 @@ tokens not just s and b. 1 = yes. 0 = no. exec.doc/RawDoFmt autodoc is wrong %d and %x do support this, too, so this should be set to 1. */ -#define USE_GLOBALLIMIT 1 +#define USE_GLOBALLIMIT 1 /* [New]FormatString: Should formatting routine support 64bit formatting %L and %ll. 1 = yes. 0 = no. Current implementation use @@ -54,8 +54,8 @@ struct IntLocaleBase { struct LocaleBase lb_LocaleBase; - struct IntLocale *lb_DefaultLocale; - struct IntLocale *lb_CurrentLocale; + struct IntLocale *lb_DefaultLocale; + struct IntLocale *lb_CurrentLocale; struct SignalSemaphore lb_LocaleLock; struct SignalSemaphore lb_CatalogLock; struct MinList lb_CatalogList; @@ -71,10 +71,10 @@ struct IntLocale APTR il_LanguageFunctions[32]; /* Need to put all sorts of crap here later. */ - UBYTE LocaleName[30]; - UBYTE LanguageName[30]; + UBYTE LocaleName[30]; + UBYTE LanguageName[30]; - UBYTE PreferredLanguages[10][30]; + UBYTE PreferredLanguages[10][30]; /* ** Don't change the order of the following field, @@ -83,36 +83,36 @@ struct IntLocale ** as well! */ - UBYTE DateTimeFormat[80]; - UBYTE DateFormat[40]; - UBYTE TimeFormat[40]; - UBYTE ShortDateTimeFormat[80]; - UBYTE ShortDateFormat[40]; - UBYTE ShortTimeFormat[40]; - - UBYTE DecimalPoint[10]; - UBYTE GroupSeparator[10]; - UBYTE FracGroupSeparator[10]; - UBYTE Grouping[10]; - UBYTE FracGrouping[10]; - UBYTE MonDecimalPoint[10]; - UBYTE MonGroupSeparator[10]; - UBYTE MonFracGroupSeparator[10]; - UBYTE MonGrouping[10]; - UBYTE MonFracGrouping[10]; - - UBYTE MonCS[10]; - UBYTE MonSmallCS[10]; - UBYTE MonIntCS[10]; - UBYTE MonPositiveSign[10]; - - UBYTE MonNegativeSign[10]; + UBYTE DateTimeFormat[80]; + UBYTE DateFormat[40]; + UBYTE TimeFormat[40]; + UBYTE ShortDateTimeFormat[80]; + UBYTE ShortDateFormat[40]; + UBYTE ShortTimeFormat[40]; + + UBYTE DecimalPoint[10]; + UBYTE GroupSeparator[10]; + UBYTE FracGroupSeparator[10]; + UBYTE Grouping[10]; + UBYTE FracGrouping[10]; + UBYTE MonDecimalPoint[10]; + UBYTE MonGroupSeparator[10]; + UBYTE MonFracGroupSeparator[10]; + UBYTE MonGrouping[10]; + UBYTE MonFracGrouping[10]; + + UBYTE MonCS[10]; + UBYTE MonSmallCS[10]; + UBYTE MonIntCS[10]; + UBYTE MonPositiveSign[10]; + + UBYTE MonNegativeSign[10]; }; struct CatStr { - STRPTR cs_String; - ULONG cs_Id; /* Really signed, but need it to be unsigned for ICF_INORDER */ + STRPTR cs_String; + ULONG cs_Id; /* Really signed, but needs to be unsigned for ICF_INORDER */ }; /* see Amiga Developer CD 2.1:NDK/NDK_3.1/Examples1/locale/SelfLoad/catalog.c */ @@ -126,20 +126,20 @@ struct CodeSet struct IntCatalog { struct Catalog ic_Catalog; - struct CodeSet ic_CodeSet; + struct CodeSet ic_CodeSet; struct CatStr *ic_CatStrings; - UBYTE *ic_StringChunk; - ULONG ic_NumStrings; - ULONG ic_DataSize; - UWORD ic_UseCount; - ULONG ic_Flags; - UBYTE ic_LanguageName[30]; - UBYTE ic_Name[0]; // name of the file as passed to OpenCatalogA - /* structure sizes depends on length of ic_Name string */ + UBYTE *ic_StringChunk; + ULONG ic_NumStrings; + ULONG ic_DataSize; + UWORD ic_UseCount; + ULONG ic_Flags; + UBYTE ic_LanguageName[30]; + UBYTE ic_Name[0]; // name of file passed to OpenCatalogA() + /* structure size depends on length of ic_Name string */ }; /* Catalog strings are in order, so we don't have to search them all */ -#define ICF_INORDER (1L<<0) +#define ICF_INORDER (1L<<0) /* Shortcuts to the internal structures */ #define IntLB(lb) ((struct IntLocaleBase *)(lb)) @@ -168,7 +168,9 @@ void SetLocaleLanguage(struct IntLocale *, struct LocaleBase *); void InstallPatches(void); -APTR InternalFormatString(const struct Locale *locale, CONST_STRPTR fmtTemplate, CONST_APTR dataStream, const struct Hook *putCharFunc, va_list VaListStream); +APTR InternalFormatString(const struct Locale *locale, + CONST_STRPTR fmtTemplate, CONST_APTR dataStream, + const struct Hook *putCharFunc, va_list VaListStream); extern const struct Locale defLocale; diff --git a/workbench/libs/locale/locdatetostr.c b/workbench/libs/locale/locdatetostr.c index 918dc3caa5..2893e4935d 100644 --- a/workbench/libs/locale/locdatetostr.c +++ b/workbench/libs/locale/locdatetostr.c @@ -74,8 +74,6 @@ AROS_UFH3(void, LocDateToStrPutCharFunc, INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT diff --git a/workbench/libs/locale/locdosgetlocalizedstring.c b/workbench/libs/locale/locdosgetlocalizedstring.c index 8b0eacf96b..f3e0bc7bfc 100644 --- a/workbench/libs/locale/locdosgetlocalizedstring.c +++ b/workbench/libs/locale/locdosgetlocalizedstring.c @@ -3,9 +3,9 @@ $Id$ Desc: LocStrToDateGetCharFunc - locale.library's private replacement - of dos.library/DosGetLocalizedString function. IPrefs will install - the patch. - + of dos.library/DosGetLocalizedString function. IPrefs will install + the patch. + Lang: english */ @@ -20,40 +20,39 @@ NAME */ #include - AROS_PLH1(CONST_STRPTR, LocDosGetLocalizedString, + AROS_PLH1(CONST_STRPTR, LocDosGetLocalizedString, /* SYNOPSIS */ - AROS_LHA(LONG, stringNum, D1), + AROS_LHA(LONG, stringNum, D1), /* LOCATION */ - struct DosLibrary *, DOSBase, 38, Locale) + struct DosLibrary *, DOSBase, 38, Locale) /* FUNCTION - See dos.library/DosGetString - + See dos.library/DosGetString + INPUTS - See dos.library/DosGetString + See dos.library/DosGetString RESULT NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to DOSBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. + This function is not called by apps directly. Instead + dos.library/DosGetLocalizedString is patched to use this function. + This means that the LocaleBase parameter above actually points to + DOSBase, so we make use of the global LocaleBase variable. This + function is marked as private, therefore the headers generator won't + mind the different basename in the header. EXAMPLE BUGS SEE ALSO - dos.library/DosGetString() + dos.library/DosGetString() INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT @@ -62,32 +61,33 @@ UBYTE *q = DOSBase->dl_Errors->estr_Strings; STRPTR defstr = NULL; - /* We should really call the original DosGetString(), but ahwell... */ + /* We should really call the original DosGetString(), but ah well... */ do { - LONG n = p[0]; - LONG m = p[1]; - - while (n <= m) - { - if (n == stringNum) - { - defstr = q + 1; - break; - } - - q += q[0] + 1; - ++n; - } - - p += 2; + LONG n = p[0]; + LONG m = p[1]; + + while (n <= m) + { + if (n == stringNum) + { + defstr = q + 1; + break; + } + + q += q[0] + 1; + ++n; + } + + p += 2; } while (p[0] != 0); - return GetCatalogStr(IntLB(LocaleBase)->lb_CurrentLocale->il_DosCatalog, stringNum, defstr); + return GetCatalogStr(IntLB(LocaleBase)->lb_CurrentLocale->il_DosCatalog, + stringNum, defstr); AROS_LIBFUNC_EXIT -} /* LocDosGetLocalizedString */ +} #undef LocaleBase diff --git a/workbench/libs/locale/locrawdofmt.c b/workbench/libs/locale/locrawdofmt.c dissimilarity index 71% index 6793c7f555..22949c9a5c 100644 --- a/workbench/libs/locale/locrawdofmt.c +++ b/workbench/libs/locale/locrawdofmt.c @@ -1,358 +1,225 @@ -/* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. - $Id$ - - Desc: Locale_RawDoFmt - locale.library's private replacement - of exec.library/RawDoFmt function. IPrefs will install - the patch. - - Lang: english -*/ - -#include -#include -#include -#include -#include "locale_intern.h" -#include -#include - - -#ifdef __MORPHOS__ - -/* move.b d0,(a3)+ - rts -*/ -#define ARRAY_FUNC 0x16c04e75 - -/* KPutChar - MOVE.L A6,-(SP) ;2F0E - MOVEA.L (4).L,A6 ;2C7900000004 - JSR (-$0204,A6) ;4EAEFDFC - MOVEA.L (SP)+,A6 ;2C5F - RTS ;4E75 -*/ - -#define SERIAL_FUNC0 0x2f0e2c79 -#define SERIAL_FUNC1 0x00000004 -#define SERIAL_FUNC2 0x4eaefdfc -#define SERIAL_FUNC3 0x2c5f4e75 - -struct HookData -{ - char *PutChData; - ULONG OldA4; -}; - -/* Quick reg layout function - */ -#if 0 -char *_PPCCallM68k_RawDoFmt(char MyChar, - char *(*PutChProc)(char*,char), - char *PutChData, - ULONG OldA4, - struct ExecBase *sysBase); - -char *PPCCallM68k_RawDoFmt(char MyChar, - char *(*PutChProc)(char*,char), - char *PutChData, - ULONG OldA4, - struct ExecBase *sysBase) -{ - /* As we call a *QUICK REG LAYOUT* function - * below we must make sure that this function backups/restores - * all registers - */ - asm volatile ("" - : - : - : "r13"); - - return _PPCCallM68k_RawDoFmt(MyChar, - PutChProc, - PutChData, - OldA4, - sysBase); -} -#else -char *PPCCallM68k_RawDoFmt(char MyChar, - char *(*PutChProc)(char*,char), - char *PutChData, - ULONG OldA4, - struct ExecBase *sysBase); - -/* Shitty workaround for release/cisc - ignores r13 clobber */ - -__asm(".section \".text\"\n\t" - ".align 2\n\t" - ".globl PPCCallM68k_RawDoFmt\n\t" - ".type PPCCallM68k_RawDoFmt, @function\n" - "PPCCallM68k_RawDoFmt:\n\t" - "stwu 1, -96(1)\n\t" - "mflr 0\n\t" - "stmw 13, 20(1)\n\t" - "stw 0, 100(1)\n\t" - "bl _PPCCallM68k_RawDoFmt\n\t" - "lwz 0, 100(1)\n\t" - "mtlr 0\n\t" - "lmw 13, 20(1)\n\t" - "la 1, 96(1)\n\t" - "blr\n" - ".LfeN:\n\t" - ".size PPCCallM68k_RawDoFmt, .LfeN - PPCCallM68k_RawDoFmt" - ); -#endif - -#endif - - -AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc, - AROS_UFHA(struct Hook *, hook, A0), - AROS_UFHA(struct Locale *, locale, A2), - AROS_UFHA(char, fill, A1)) -{ - AROS_USERFUNC_INIT - -#ifdef __mc68000__ - register char *pdata asm("a3") = hook->h_Data; -#else - char *pdata = hook->h_Data; -#endif - - switch ((IPTR)hook->h_SubEntry) - { - case (IPTR)RAWFMTFUNC_STRING: - /* Standard Array Function */ - *pdata++ = fill; - break; - case (IPTR)RAWFMTFUNC_SERIAL: - /* Standard Serial Function */ - RawPutChar(fill); - break; - case (IPTR)RAWFMTFUNC_COUNT: - /* Standard Count Function */ - (*((ULONG *)pdata))++; - break; - default: - AROS_UFC3(void, hook->h_SubEntry, - AROS_UFCA(char, fill, D0), - AROS_UFCA(APTR, pdata, A3), - AROS_UFCA(struct ExecBase *, SysBase, A6)); - } - hook->h_Data = pdata; - - AROS_USERFUNC_EXIT -} - -AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc_SysV, - AROS_UFHA(struct Hook *, hook, A0), - AROS_UFHA(struct Locale *, locale, A2), - AROS_UFHA(char, fill, A1)) -{ - AROS_USERFUNC_INIT - - APTR (*proc)(APTR, UBYTE) = (APTR)hook->h_SubEntry; - char *pdata = hook->h_Data; - - switch ((IPTR)hook->h_SubEntry) - { - case (IPTR)RAWFMTFUNC_STRING: - /* Standard Array Function */ - *pdata++ = fill; - break; - - case (IPTR)RAWFMTFUNC_SERIAL: - /* Standard Serial Function */ - RawPutChar(fill); - break; - - case (IPTR)RAWFMTFUNC_COUNT: - /* Standard Count Function */ - (*((ULONG *)pdata))++; - break; - - default: - pdata = proc(pdata, fill); - } - hook->h_Data = pdata; - - AROS_USERFUNC_EXIT -} - -#undef LocaleBase - - /***************************************************************************** - - NAME */ -#include - - AROS_PLH4(APTR, LocRawDoFmt, - -/* SYNOPSIS */ - AROS_LHA(CONST_STRPTR, FormatString, A0), - AROS_LHA(APTR , DataStream, A1), - AROS_LHA(VOID_FUNC , PutChProc, A2), - AROS_LHA(APTR , PutChData, A3), - -/* LOCATION */ - struct ExecBase *, SysBase, 31, Locale) - -/* FUNCTION - See exec.library/RawDoFmt - - INPUTS - See exec.library/RawDoFmt - - RESULT - - NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to SysBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. - - EXAMPLE - - BUGS - - SEE ALSO - RawDoFmt(), FormatString(). - - INTERNALS - - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct Hook hook; - APTR retval; - -#ifdef __MORPHOS__ - struct HookData data; - - if ((ULONG) PutChProc > 1) - { - if (*((ULONG*) PutChProc) == ARRAY_FUNC) - { - PutChProc = 0; - } -#if 0 -/* - * This is the job of exec - */ - else if ((((ULONG*) PutChProc)[0] == SERIAL_FUNC0) && - (((ULONG*) PutChProc)[1] == SERIAL_FUNC1) && - (((ULONG*) PutChProc)[2] == SERIAL_FUNC2) && - (((ULONG*) PutChProc)[3] == SERIAL_FUNC3)) - { - PutChProc = (APTR) 1; - } -#endif - } - - hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc); - hook.h_SubEntry = (HOOKFUNC)PutChProc; - hook.h_Data = &data; - data.PutChData = PutChData; - data.OldA4 = REG_A4; - -#else - - hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc); - hook.h_SubEntry = (HOOKFUNC)PutChProc; - hook.h_Data = PutChData; - -#endif - - //kprintf("LocRawDoFmt: FormatString = \"%s\"\n", FormatString); - - REPLACEMENT_LOCK; - - retval = FormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale), - (STRPTR)FormatString, - DataStream, - &hook); - - REPLACEMENT_UNLOCK; - - //kprintf("LocRawDoFmt: FormatString: returning %x\n", retval); - - return retval; - - AROS_LIBFUNC_EXIT - -} /* LocRawDoFmt */ - - /***************************************************************************** - - NAME */ -#include - - AROS_PLH4(APTR, LocVNewRawDoFmt, - -/* SYNOPSIS */ - AROS_LHA(CONST_STRPTR, FormatString, A0), - AROS_LHA(VOID_FUNC , PutChProc, A2), - AROS_LHA(APTR , PutChData, A3), - AROS_LHA(va_list , DataStream, A1), - -/* LOCATION */ - struct ExecBase *, SysBase, 39, Locale) - -/* FUNCTION - See exec.library/VNewRawDoFmt - - INPUTS - See exec.library/VNewRawDoFmt - - RESULT - - NOTES - This function is not called by apps directly. Instead exec.library/VNewRawDoFmt - is patched to use this function. This means, that the library base parameter above - actually points to SysBase, so we make use of the global LocaleBase variable. - This function is marked as private, thus the headers generator won't mind the - different basename in the header. - - EXAMPLE - - BUGS - - SEE ALSO - RawDoFmt(), FormatString(). - - INTERNALS - - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct Hook hook; - - hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc_SysV); - hook.h_SubEntry = (HOOKFUNC)PutChProc; - hook.h_Data = PutChData; - - REPLACEMENT_LOCK; - - InternalFormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale), - (STRPTR)FormatString, - NULL, - &hook, DataStream); - - REPLACEMENT_UNLOCK; - - return hook.h_Data; - - AROS_LIBFUNC_EXIT - -} /* LocRawDoFmt */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: Locale_RawDoFmt - locale.library's private replacement + of exec.library/RawDoFmt function. IPrefs will install + the patch. + + Lang: english +*/ + +#include +#include +#include +#include +#include "locale_intern.h" +#include +#include + + +AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc, + AROS_UFHA(struct Hook *, hook, A0), + AROS_UFHA(struct Locale *, locale, A2), + AROS_UFHA(char, fill, A1)) +{ + AROS_USERFUNC_INIT + +#ifdef __mc68000__ + register char *pdata asm("a3") = hook->h_Data; +#else + char *pdata = hook->h_Data; +#endif + + switch ((IPTR) hook->h_SubEntry) + { + case (IPTR) RAWFMTFUNC_STRING: + /* Standard Array Function */ + *pdata++ = fill; + break; + case (IPTR) RAWFMTFUNC_SERIAL: + /* Standard Serial Function */ + RawPutChar(fill); + break; + case (IPTR) RAWFMTFUNC_COUNT: + /* Standard Count Function */ + (*((ULONG *) pdata))++; + break; + default: + AROS_UFC3(void, hook->h_SubEntry, + AROS_UFCA(char, fill, D0), + AROS_UFCA(APTR, pdata, A3), + AROS_UFCA(struct ExecBase *, SysBase, A6)); + } + hook->h_Data = pdata; + + AROS_USERFUNC_EXIT +} + +AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc_SysV, + AROS_UFHA(struct Hook *, hook, A0), + AROS_UFHA(struct Locale *, locale, A2), AROS_UFHA(char, fill, A1)) +{ + AROS_USERFUNC_INIT + + APTR(*proc) (APTR, UBYTE) = (APTR) hook->h_SubEntry; + char *pdata = hook->h_Data; + + switch ((IPTR) hook->h_SubEntry) + { + case (IPTR) RAWFMTFUNC_STRING: + /* Standard Array Function */ + *pdata++ = fill; + break; + + case (IPTR) RAWFMTFUNC_SERIAL: + /* Standard Serial Function */ + RawPutChar(fill); + break; + + case (IPTR) RAWFMTFUNC_COUNT: + /* Standard Count Function */ + (*((ULONG *) pdata))++; + break; + + default: + pdata = proc(pdata, fill); + } + hook->h_Data = pdata; + + AROS_USERFUNC_EXIT +} + +#undef LocaleBase + + /***************************************************************************** + + NAME */ +#include + + AROS_PLH4(APTR, LocRawDoFmt, + +/* SYNOPSIS */ + AROS_LHA(CONST_STRPTR, FormatString, A0), + AROS_LHA(APTR , DataStream, A1), + AROS_LHA(VOID_FUNC , PutChProc, A2), + AROS_LHA(APTR , PutChData, A3), + +/* LOCATION */ + struct ExecBase *, SysBase, 31, Locale) + +/* FUNCTION + See exec.library/RawDoFmt + + INPUTS + See exec.library/RawDoFmt + + RESULT + + NOTES + This function is not called by apps directly. Instead dos.library/DosGet- + LocalizedString is patched to use this function. This means, that the + LocaleBase parameter above actually points to SysBase, so we make use of + the global LocaleBase variable. This function is marked as private, + thus the headers generator won't mind the different basename in the header. + + EXAMPLE + + BUGS + + SEE ALSO + RawDoFmt(), FormatString(). + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct Hook hook; + APTR retval; + + hook.h_Entry = (HOOKFUNC) AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc); + hook.h_SubEntry = (HOOKFUNC) PutChProc; + hook.h_Data = PutChData; + + //kprintf("LocRawDoFmt: FormatString = \"%s\"\n", FormatString); + + REPLACEMENT_LOCK; + + retval = FormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale), + (STRPTR) FormatString, DataStream, &hook); + + REPLACEMENT_UNLOCK; + + //kprintf("LocRawDoFmt: FormatString: returning %x\n", retval); + + return retval; + + AROS_LIBFUNC_EXIT + +} + + /***************************************************************************** + + NAME */ +#include + + AROS_PLH4(APTR, LocVNewRawDoFmt, + +/* SYNOPSIS */ + AROS_LHA(CONST_STRPTR, FormatString, A0), + AROS_LHA(VOID_FUNC , PutChProc, A2), + AROS_LHA(APTR , PutChData, A3), + AROS_LHA(va_list , DataStream, A1), + +/* LOCATION */ + struct ExecBase *, SysBase, 39, Locale) + +/* FUNCTION + See exec.library/VNewRawDoFmt + + INPUTS + See exec.library/VNewRawDoFmt + + RESULT + + NOTES + This function is not called by apps directly. Instead exec.library/VNewRawDoFmt + is patched to use this function. This means, that the library base parameter above + actually points to SysBase, so we make use of the global LocaleBase variable. + This function is marked as private, thus the headers generator won't mind the + different basename in the header. + + EXAMPLE + + BUGS + + SEE ALSO + RawDoFmt(), FormatString(). + + INTERNALS + +*****************************************************************************/ + +{ + AROS_LIBFUNC_INIT + + struct Hook hook; + + hook.h_Entry = + (HOOKFUNC) AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc_SysV); + hook.h_SubEntry = (HOOKFUNC) PutChProc; + hook.h_Data = PutChData; + + REPLACEMENT_LOCK; + + InternalFormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale), + (STRPTR) FormatString, NULL, &hook, DataStream); + + REPLACEMENT_UNLOCK; + + return hook.h_Data; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/locstricmp.c b/workbench/libs/locale/locstricmp.c index 9b5d2960a2..786bd97b73 100644 --- a/workbench/libs/locale/locstricmp.c +++ b/workbench/libs/locale/locstricmp.c @@ -1,11 +1,11 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: LocStricmp - locale.library's private replacement - of utility.library/Stricmp function. IPrefs will install - the patch. - + of utility.library/Stricmp function. IPrefs will install + the patch. + Lang: english */ @@ -15,77 +15,67 @@ #include "locale_intern.h" #include -#define DEBUG_STRCMP(x) ; +#define DEBUG_STRCMP(x) ; /***************************************************************************** NAME */ #include - AROS_PLH2(LONG, LocStricmp, + AROS_PLH2(LONG, LocStricmp, /* SYNOPSIS */ - AROS_LHA(CONST_STRPTR, string1, A0), - AROS_LHA(CONST_STRPTR, string2, A1), + AROS_LHA(CONST_STRPTR, string1, A0), + AROS_LHA(CONST_STRPTR, string2, A1), /* LOCATION */ - struct UtilityBase *, UtilityBase, 33, Locale) + struct UtilityBase *, UtilityBase, 33, Locale) /* FUNCTION - See utility.library/Stricmp - + See utility.library/Stricmp + INPUTS - See utility.library/Stricmp + See utility.library/Stricmp RESULT NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to UtilityBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. - + This function is not called by apps directly. Instead dos.library/DosGet- + LocalizedString is patched to use this function. This means, that the + LocaleBase parameter above actually points to UtilityBase, so we make use of + the global LocaleBase variable. This function is marked as private, + thus the headers generator won't mind the different basename in the header. + EXAMPLE BUGS SEE ALSO - utility.library/Stricmp(), locale.library/StrnCmp(). + utility.library/Stricmp(), locale.library/StrnCmp(). INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT LONG retval; - + REPLACEMENT_LOCK; - - DEBUG_STRCMP(dprintf("locStrCmp: <%s> <%s>\n", - string1, - string2)); + + DEBUG_STRCMP(dprintf("locStrCmp: <%s> <%s>\n", string1, string2)); DEBUG_STRCMP(dprintf("locStrCmp: CurrentLocale 0x%lx\n", - (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); retval = StrnCmp((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, - (STRPTR)string1, - (STRPTR)string2, - -1, - SC_ASCII); - - DEBUG_STRCMP(dprintf("StrCmp: retval 0x%lx\n", - retval)); + (STRPTR) string1, (STRPTR) string2, -1, SC_ASCII); + + DEBUG_STRCMP(dprintf("StrCmp: retval 0x%lx\n", retval)); REPLACEMENT_UNLOCK; - + return retval; - - AROS_LIBFUNC_EXIT - -} /* LocStricmp */ + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/locstrnicmp.c b/workbench/libs/locale/locstrnicmp.c index e961f8f270..7f0a070143 100644 --- a/workbench/libs/locale/locstrnicmp.c +++ b/workbench/libs/locale/locstrnicmp.c @@ -1,11 +1,11 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: LocStrnicmp - locale.library's private replacement - of utility.library/Strnicmp function. IPrefs will install - the patch. - + of utility.library/Strnicmp function. IPrefs will install + the patch. + Lang: english */ @@ -16,79 +16,70 @@ #include -#define DEBUG_STRNCMP(x) ; +#define DEBUG_STRNCMP(x) ; /***************************************************************************** NAME */ #include - AROS_PLH3(LONG, LocStrnicmp, + AROS_PLH3(LONG, LocStrnicmp, /* SYNOPSIS */ - AROS_LHA(CONST_STRPTR, string1, A0), - AROS_LHA(CONST_STRPTR, string2, A1), - AROS_LHA(LONG , length , D0), + AROS_LHA(CONST_STRPTR, string1, A0), + AROS_LHA(CONST_STRPTR, string2, A1), + AROS_LHA(LONG , length , D0), /* LOCATION */ - struct UtilityBase *, UtilityBase, 32, Locale) + struct UtilityBase *, UtilityBase, 32, Locale) /* FUNCTION - See utility.library/Strnicmp - + See utility.library/Strnicmp + INPUTS - See utility.library/Strnicmp + See utility.library/Strnicmp RESULT NOTES NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to UtilityBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. - + This function is not called by apps directly. Instead dos.library/DosGet- + LocalizedString is patched to use this function. This means, that the + LocaleBase parameter above actually points to UtilityBase, so we make use of + the global LocaleBase variable. This function is marked as private, + thus the headers generator won't mind the different basename in the header. + EXAMPLE BUGS SEE ALSO - utility.library/Strnicmp(), locale.library/StrnCmp(). + utility.library/Strnicmp(), locale.library/StrnCmp(). INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT LONG retval; - + REPLACEMENT_LOCK; - + DEBUG_STRNCMP(dprintf("locStrnCmp: <%s> <%s> len %ld\n", - string1, - string2, - length)); + string1, string2, length)); DEBUG_STRNCMP(dprintf("locStrnCmp: CurrentLocale 0x%lx\n", - (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); retval = StrnCmp((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, - (STRPTR)string1, - (STRPTR)string2, - length, - SC_ASCII); + (STRPTR) string1, (STRPTR) string2, length, SC_ASCII); - DEBUG_STRNCMP(dprintf("StrnCmp: retval 0x%lx\n", - retval)); + DEBUG_STRNCMP(dprintf("StrnCmp: retval 0x%lx\n", retval)); REPLACEMENT_UNLOCK; - + return retval; - + AROS_LIBFUNC_EXIT - -} /* LocStrnicmp */ +} diff --git a/workbench/libs/locale/locstrtodate.c b/workbench/libs/locale/locstrtodate.c dissimilarity index 72% index a759c0ec55..2833420048 100644 --- a/workbench/libs/locale/locstrtodate.c +++ b/workbench/libs/locale/locstrtodate.c @@ -1,269 +1,271 @@ -/* - Copyright © 1995-2010, The AROS Development Team. All rights reserved. - $Id$ - - Desc: LocStrToDate - locale.library's private replacement - of dos.library/StrToDate function. IPrefs will install - the patch. - - Lang: english -*/ - -#include -#include -#include -#include -#include -#include "locale_intern.h" -#include - -#include - -#define YEAR_FORMAT "%y" - -#ifndef FORMAT_DEF -#define FORMAT_DEF 4 -#endif - -static const TEXT long_dos_time_format[] = "%H:%M:%S"; -static const TEXT short_dos_time_format[] = "%H:%M"; - -AROS_UFH3(ULONG, LocStrToDateGetCharFunc, - AROS_UFHA(struct Hook *, hook, A0), - AROS_UFHA(struct Locale *, locale, A2), - AROS_UFHA(ULONG, null, A1)) -{ - AROS_USERFUNC_INIT - - STRPTR *buf = (STRPTR *)hook->h_Data; - - return *(*buf)++; - - AROS_USERFUNC_EXIT -} - - /***************************************************************************** - - NAME */ -#include - - AROS_PLH1(LONG, LocStrToDate, - -/* SYNOPSIS */ - AROS_LHA(struct DateTime *, datetime, D1), - -/* LOCATION */ - struct DosLibrary *, DOSBase, 37, Locale) - -/* FUNCTION - See dos.library/StrToDate - - INPUTS - See dos.library/StrToDate - - RESULT - - NOTES - This function is not called by apps directly. Instead - dos.library/StrToDate() is patched to use this function. This means - that the LocaleBase parameter above actually points to DOSBase, so we - make use of the global LocaleBase variable. This function is marked as - private, thus the headers generator won't mind the different basename - in the header. - - EXAMPLE - - BUGS - - SEE ALSO - dos.library/StrToDate, locale.library/ParseDate. - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct Locale *loc; - struct Hook hook; - CONST_STRPTR buf, fstring, altfstring; - LONG days; - LONG retval = TRUE; - - hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocStrToDateGetCharFunc); - hook.h_Data = &buf; - - REPLACEMENT_LOCK; - - loc = (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale; - - if (datetime->dat_StrDate) - { - struct DateStamp curr; - - buf = datetime->dat_StrDate; - - DateStamp(&curr); - - if (!strnicmp(buf, GetLocaleStr(loc, YESTERDAYSTR), strlen(GetLocaleStr(loc, YESTERDAYSTR)))) - { - datetime->dat_Stamp.ds_Days = curr.ds_Days - 1; - } - else if (!strnicmp(buf, GetLocaleStr(loc, TODAYSTR), strlen(GetLocaleStr(loc, TODAYSTR)))) - { - datetime->dat_Stamp.ds_Days = curr.ds_Days; - } - else if (!strnicmp(buf, GetLocaleStr(loc, TOMORROWSTR), strlen(GetLocaleStr(loc, TOMORROWSTR)))) - { - datetime->dat_Stamp.ds_Days = curr.ds_Days + 1; - } - else - { - WORD i; - - for(i = 0; i < 7; i++) - { - if (!strnicmp(buf, GetLocaleStr(loc, DAY_1 + i), strlen(GetLocaleStr(loc, DAY_1 + i)))) - break; - } - - if (i != 7) - { -#if 1 - LONG diffdays; - - days = curr.ds_Days; - - diffdays = i - (days % 7); - - if (datetime->dat_Flags & DTF_FUTURE) - { - if (diffdays > 0) - { - days += diffdays; - } - else - { - days += 7 + diffdays; - } - } - else - { - if (diffdays < 0) - { - days += diffdays; - } - else - { - days += diffdays - 7; - } - } - datetime->dat_Stamp.ds_Days = days; -#else - days = curr.ds_Days; - - if ((days %7) == 0) - days -= 7; - else - days -= (days % 7); - - days += i; - - if (datetime->dat_Flags & DTF_FUTURE) - days += 7; - - datetime->dat_Stamp.ds_Days = days; -#endif - } - else - { - - switch(datetime->dat_Format) - { - case FORMAT_INT: - fstring = YEAR_FORMAT "-%b-%d"; - altfstring = YEAR_FORMAT "-%m-%d"; - break; - - case FORMAT_USA: - altfstring = fstring = "%m-%d-" YEAR_FORMAT; - break; - - case FORMAT_CDN: - altfstring = fstring = "%d-%m-" YEAR_FORMAT; - break; - - case FORMAT_DEF: - altfstring = fstring = loc->loc_ShortDateFormat; - break; - - default: /* FORMAT_DOS */ - fstring = "%d-%b-" YEAR_FORMAT; - altfstring = "%d-%m-" YEAR_FORMAT; - break; - - } - - if (ParseDate(loc, &curr, fstring, &hook)) - { - datetime->dat_Stamp.ds_Days = curr.ds_Days; - } - else - { - buf = datetime->dat_StrDate; - if (ParseDate(loc, &curr, altfstring, &hook)) - { - datetime->dat_Stamp.ds_Days = curr.ds_Days; - } - else - { - retval = FALSE; - } - } - - } - - } - - } /* if (datetime->dat_StrDate) */ - - - if (retval && datetime->dat_StrTime) - { - struct DateStamp ds; - - buf = datetime->dat_StrTime; - - switch(datetime->dat_Format) - { - case FORMAT_DEF: - fstring = loc->loc_ShortTimeFormat; - break; - - default: - if (ParseDate(loc, NULL, long_dos_time_format, &hook)) - fstring = long_dos_time_format; - else - fstring = short_dos_time_format; - buf = datetime->dat_StrTime; - break; - } - - if (ParseDate(loc, &ds, fstring, &hook)) - { - datetime->dat_Stamp.ds_Minute = ds.ds_Minute; - datetime->dat_Stamp.ds_Tick = ds.ds_Tick; - } - else - { - retval = FALSE; - } - } - - REPLACEMENT_UNLOCK; - - return retval; - - AROS_LIBFUNC_EXIT - -} /* LocStrToDate */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: LocStrToDate - locale.library's private replacement + of dos.library/StrToDate function. IPrefs will install + the patch. + + Lang: english +*/ + +#include +#include +#include +#include +#include +#include "locale_intern.h" +#include + +#include + +#define YEAR_FORMAT "%y" + +#ifndef FORMAT_DEF +#define FORMAT_DEF 4 +#endif + +static const TEXT long_dos_time_format[] = "%H:%M:%S"; +static const TEXT short_dos_time_format[] = "%H:%M"; + +AROS_UFH3(ULONG, LocStrToDateGetCharFunc, + AROS_UFHA(struct Hook *, hook, A0), + AROS_UFHA(struct Locale *, locale, A2), + AROS_UFHA(ULONG, null, A1)) +{ + AROS_USERFUNC_INIT + + STRPTR *buf = (STRPTR *)hook->h_Data; + + return *(*buf)++; + + AROS_USERFUNC_EXIT +} + + /***************************************************************************** + + NAME */ +#include + + AROS_PLH1(LONG, LocStrToDate, + +/* SYNOPSIS */ + AROS_LHA(struct DateTime *, datetime, D1), + +/* LOCATION */ + struct DosLibrary *, DOSBase, 37, Locale) + +/* FUNCTION + See dos.library/StrToDate + + INPUTS + See dos.library/StrToDate + + RESULT + + NOTES + This function is not called by apps directly. Instead + dos.library/StrToDate() is patched to use this function. This means + that the LocaleBase parameter above actually points to DOSBase, so we + make use of the global LocaleBase variable. This function is marked as + private, thus the headers generator won't mind the different basename + in the header. + + EXAMPLE + + BUGS + + SEE ALSO + dos.library/StrToDate, locale.library/ParseDate. + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct Locale *loc; + struct Hook hook; + CONST_STRPTR buf, fstring, altfstring; + LONG days; + LONG retval = TRUE; + + hook.h_Entry = (HOOKFUNC) AROS_ASMSYMNAME(LocStrToDateGetCharFunc); + hook.h_Data = &buf; + + REPLACEMENT_LOCK; + + loc = (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale; + + if (datetime->dat_StrDate) + { + struct DateStamp curr; + + buf = datetime->dat_StrDate; + + DateStamp(&curr); + + if (!strnicmp(buf, GetLocaleStr(loc, YESTERDAYSTR), + strlen(GetLocaleStr(loc, YESTERDAYSTR)))) + { + datetime->dat_Stamp.ds_Days = curr.ds_Days - 1; + } + else if (!strnicmp(buf, GetLocaleStr(loc, TODAYSTR), + strlen(GetLocaleStr(loc, TODAYSTR)))) + { + datetime->dat_Stamp.ds_Days = curr.ds_Days; + } + else if (!strnicmp(buf, GetLocaleStr(loc, TOMORROWSTR), + strlen(GetLocaleStr(loc, TOMORROWSTR)))) + { + datetime->dat_Stamp.ds_Days = curr.ds_Days + 1; + } + else + { + WORD i; + + for (i = 0; i < 7; i++) + { + if (!strnicmp(buf, GetLocaleStr(loc, DAY_1 + i), + strlen(GetLocaleStr(loc, DAY_1 + i)))) + break; + } + + if (i != 7) + { +#if 1 + LONG diffdays; + + days = curr.ds_Days; + + diffdays = i - (days % 7); + + if (datetime->dat_Flags & DTF_FUTURE) + { + if (diffdays > 0) + { + days += diffdays; + } + else + { + days += 7 + diffdays; + } + } + else + { + if (diffdays < 0) + { + days += diffdays; + } + else + { + days += diffdays - 7; + } + } + datetime->dat_Stamp.ds_Days = days; +#else + days = curr.ds_Days; + + if ((days % 7) == 0) + days -= 7; + else + days -= (days % 7); + + days += i; + + if (datetime->dat_Flags & DTF_FUTURE) + days += 7; + + datetime->dat_Stamp.ds_Days = days; +#endif + } + else + { + + switch (datetime->dat_Format) + { + case FORMAT_INT: + fstring = YEAR_FORMAT "-%b-%d"; + altfstring = YEAR_FORMAT "-%m-%d"; + break; + + case FORMAT_USA: + altfstring = fstring = "%m-%d-" YEAR_FORMAT; + break; + + case FORMAT_CDN: + altfstring = fstring = "%d-%m-" YEAR_FORMAT; + break; + + case FORMAT_DEF: + altfstring = fstring = loc->loc_ShortDateFormat; + break; + + default: /* FORMAT_DOS */ + fstring = "%d-%b-" YEAR_FORMAT; + altfstring = "%d-%m-" YEAR_FORMAT; + break; + + } + + if (ParseDate(loc, &curr, fstring, &hook)) + { + datetime->dat_Stamp.ds_Days = curr.ds_Days; + } + else + { + buf = datetime->dat_StrDate; + if (ParseDate(loc, &curr, altfstring, &hook)) + { + datetime->dat_Stamp.ds_Days = curr.ds_Days; + } + else + { + retval = FALSE; + } + } + + } + + } + + } + + if (retval && datetime->dat_StrTime) + { + struct DateStamp ds; + + buf = datetime->dat_StrTime; + + switch (datetime->dat_Format) + { + case FORMAT_DEF: + fstring = loc->loc_ShortTimeFormat; + break; + + default: + if (ParseDate(loc, NULL, long_dos_time_format, &hook)) + fstring = long_dos_time_format; + else + fstring = short_dos_time_format; + buf = datetime->dat_StrTime; + break; + } + + if (ParseDate(loc, &ds, fstring, &hook)) + { + datetime->dat_Stamp.ds_Minute = ds.ds_Minute; + datetime->dat_Stamp.ds_Tick = ds.ds_Tick; + } + else + { + retval = FALSE; + } + } + + REPLACEMENT_UNLOCK; + + return retval; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/loctolower.c b/workbench/libs/locale/loctolower.c index fd101881da..1943f155c7 100644 --- a/workbench/libs/locale/loctolower.c +++ b/workbench/libs/locale/loctolower.c @@ -1,11 +1,11 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: LocToLower - locale.library's private replacement - of utility.library/ToLower function. IPrefs will install - the patch. - + of utility.library/ToLower function. IPrefs will install + the patch. + Lang: english */ @@ -15,47 +15,45 @@ #include "locale_intern.h" #include -#define DEBUG_CONVTOLOWER(x) ; +#define DEBUG_CONVTOLOWER(x) ; /***************************************************************************** NAME */ #include - AROS_PLH1(ULONG, LocToLower, + AROS_PLH1(ULONG, LocToLower, /* SYNOPSIS */ - AROS_LHA(ULONG, character, D0), + AROS_LHA(ULONG, character, D0), /* LOCATION */ - struct UtilityBase *, UtilityBase, 34, Locale) + struct UtilityBase *, UtilityBase, 34, Locale) /* FUNCTION - See utility.library/ToLower - + See utility.library/ToLower + INPUTS - See utility.library/ToLower + See utility.library/ToLower RESULT NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to UtilityBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. - + This function is not called by apps directly. Instead dos.library/DosGet- + LocalizedString is patched to use this function. This means, that the + LocaleBase parameter above actually points to UtilityBase, so we make use of + the global LocaleBase variable. This function is marked as private, + thus the headers generator won't mind the different basename in the header. + EXAMPLE BUGS SEE ALSO - utility.library/ToLower(), locale.library/ConvToLower(). + utility.library/ToLower(), locale.library/ConvToLower(). INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT @@ -64,23 +62,21 @@ REPLACEMENT_LOCK; - DEBUG_CONVTOLOWER(dprintf("locToLower: char 0x%lx\n", - character)); + DEBUG_CONVTOLOWER(dprintf("locToLower: char 0x%lx\n", character)); DEBUG_CONVTOLOWER(dprintf("locToLower: locale 0x%lx\n", - (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); - retval = ConvToLower((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, character); + retval = ConvToLower((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, + character); - DEBUG_CONVTOLOWER(dprintf("locToLower: retval 0x%lx\n", - retval)); + DEBUG_CONVTOLOWER(dprintf("locToLower: retval 0x%lx\n", retval)); REPLACEMENT_UNLOCK; return retval; AROS_LIBFUNC_EXIT - -} /* LocToLower */ +} #undef LocaleBase diff --git a/workbench/libs/locale/loctoupper.c b/workbench/libs/locale/loctoupper.c index 9d2320fd2b..d9653a6d14 100644 --- a/workbench/libs/locale/loctoupper.c +++ b/workbench/libs/locale/loctoupper.c @@ -1,11 +1,11 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ Desc: LocToUpper - locale.library's private replacement - of utility.library/ToUper function. IPrefs will install - the patch. - + of utility.library/ToUper function. IPrefs will install + the patch. + Lang: english */ @@ -15,47 +15,45 @@ #include "locale_intern.h" #include -#define DEBUG_CONVTOUPPER(x) ; +#define DEBUG_CONVTOUPPER(x) ; /***************************************************************************** NAME */ #include - AROS_PLH1(ULONG, LocToUpper, + AROS_PLH1(ULONG, LocToUpper, /* SYNOPSIS */ - AROS_LHA(ULONG, character, D0), + AROS_LHA(ULONG, character, D0), /* LOCATION */ - struct UtilityBase *, UtilityBase, 35, Locale) + struct UtilityBase *, UtilityBase, 35, Locale) /* FUNCTION - See utility.library/ToUpper - + See utility.library/ToUpper + INPUTS - See utility.library/ToUpper + See utility.library/ToUpper RESULT NOTES - This function is not called by apps directly. Instead dos.library/DosGet- - LocalizedString is patched to use this function. This means, that the - LocaleBase parameter above actually points to UtilityBase, so we make use of - the global LocaleBase variable. This function is marked as private, - thus the headers generator won't mind the different basename in the header. - + This function is not called by apps directly. Instead dos.library/DosGet- + LocalizedString is patched to use this function. This means, that the + LocaleBase parameter above actually points to UtilityBase, so we make use of + the global LocaleBase variable. This function is marked as private, + thus the headers generator won't mind the different basename in the header. + EXAMPLE BUGS SEE ALSO - utility.library/ToUpper(), locale.library/ConvToUpper(). + utility.library/ToUpper(), locale.library/ConvToUpper(). INTERNALS - HISTORY - *****************************************************************************/ { AROS_LIBFUNC_INIT @@ -64,20 +62,19 @@ REPLACEMENT_LOCK; - DEBUG_CONVTOUPPER(dprintf("locToUpper: char 0x%lx\n", - character)); + DEBUG_CONVTOUPPER(dprintf("locToUpper: char 0x%lx\n", character)); DEBUG_CONVTOUPPER(dprintf("locToUpper: locale 0x%lx\n", - (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale)); - retval = ConvToUpper((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, character); + retval = ConvToUpper((struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale, + character); - DEBUG_CONVTOUPPER(dprintf("locToUpperr: retval 0x%lx\n", - retval)); + DEBUG_CONVTOUPPER(dprintf("locToUpperr: retval 0x%lx\n", retval)); REPLACEMENT_UNLOCK; return retval; AROS_LIBFUNC_EXIT -} /* LocToUpper */ +} diff --git a/workbench/libs/locale/mmakefile.src b/workbench/libs/locale/mmakefile.src index d4cda0a9ee..201eecde81 100644 --- a/workbench/libs/locale/mmakefile.src +++ b/workbench/libs/locale/mmakefile.src @@ -3,12 +3,12 @@ include $(TOP)/config/make.cfg FILES := defaultlocale english initlocale catalog_funcs patches FUNCS := \ - closecatalog closelocale convtolower convtoupper \ - formatdate formatstring getcatalogstr getlocalestr \ - isxxxx opencataloga openlocale parsedate prefsupdate \ - strconvert strncmp locrawdofmt locstrnicmp locstricmp \ - loctolower loctoupper locdatetostr locstrtodate \ - locdosgetlocalizedstring + closecatalog closelocale convtolower convtoupper \ + formatdate formatstring getcatalogstr getlocalestr \ + isxxxx opencataloga openlocale parsedate prefsupdate \ + strconvert strncmp locrawdofmt locstrnicmp locstricmp \ + loctolower loctoupper locdatetostr locstrtodate \ + locdosgetlocalizedstring #MM workbench-libs-locale-includes : \ #MM kernel-exec-includes \ diff --git a/workbench/libs/locale/opencataloga.c b/workbench/libs/locale/opencataloga.c dissimilarity index 88% index 9e61d17293..3ef6b91c9e 100644 --- a/workbench/libs/locale/opencataloga.c +++ b/workbench/libs/locale/opencataloga.c @@ -1,562 +1,603 @@ -/* - Copyright © 1995-2010, The AROS Development Team. All rights reserved. - $Id$ -*/ -#define AROS_ALMOST_COMPATIBLE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "locale_intern.h" - -#include - -#define DEBUG_OPENCATALOG(x) ; - -struct header -{ - unsigned char id[4]; - unsigned char len[4]; -}; - -/***************************************************************************** - - NAME */ -#include - - AROS_LH3(struct Catalog *, OpenCatalogA, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(CONST_STRPTR, name, A1), - AROS_LHA(const struct TagItem *, tags, A2), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 25, Locale) - -/* FUNCTION - - INPUTS - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct Locale * def_locale = NULL; - struct IntCatalog * catalog = NULL; - char * language; - char * app_language; /* Language given with tag OC_BuiltInLanguage */ - char * specific_language; /* Language given with tag OC_Language */ - struct Process * MyProcess; -#define FILENAMESIZE 256 - - char filename[FILENAMESIZE]; - char buf[100]; - LONG chars; - ULONG version; - ULONG catversion,catrevision; - WORD pref_language; - UWORD i; - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: locale 0x%lx name <%s> Tags 0x%lx localebase 0x%lx\n", - locale, - name, - tags, - LocaleBase)); - - SetIoErr(0); - - if (!locale) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: no locale\n")); - locale = def_locale = OpenLocale(NULL); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: def_locale 0x%lx\n", - def_locale)); - } - - if (!locale) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: nolocale..done\n")); - return NULL; - } - - MyProcess=(struct Process *)FindTask(NULL); - - specific_language = (char *)GetTagData(OC_Language, (IPTR)0, tags); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: specific lang 0x%lx\n",specific_language)); - if (specific_language) - { - language = specific_language; - pref_language = -1; - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n",language)); - } - else - { - language = locale->loc_PrefLanguages[0]; - pref_language = 0; - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n",language)); - } - - if (language == NULL) - { - if (def_locale) CloseLocale(def_locale); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: nolanguage..done\n")); - return NULL; - } - - /* - ** Check whether the built in language of the application matches - ** the language of the default locale. If it matches, then I - ** don't need to load anything. - */ - - app_language = "english"; - app_language = (char *)GetTagData(OC_BuiltInLanguage, - (IPTR)app_language, - tags); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: app_language 0x%lx\n", - app_language)); - - if (NULL != app_language && 0 == strcasecmp(app_language, language)) - { - if (def_locale) CloseLocale(def_locale); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: failure..done\n")); - return NULL; - } - - version = GetTagData(OC_Version, - 0, - tags); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: version %ld\n",version)); - - if (NULL != name) - { - struct IFFHandle * iff = NULL; - - /* - ** The wanted catalog might be in the list of catalogs that are - ** already loaded. So check that list first. - */ - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: CatalogLock 0x%lx\n", - &IntLB(LocaleBase)->lb_CatalogLock)); - - ObtainSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: search cached Catalog\n")); - - ForeachNode(&IntLB(LocaleBase)->lb_CatalogList, catalog) - { - if (catalog->ic_Name && - 0 == strcmp(catalog->ic_Name, name) && - catalog->ic_Catalog.cat_Language && - 0 == strcmp(catalog->ic_Catalog.cat_Language, language)) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: found Catalog 0x%lx\n",catalog)); - catalog->ic_UseCount++; - ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); - - if (def_locale) - { - CloseLocale(def_locale); - } - - SetIoErr(ERROR_ACTION_NOT_KNOWN); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: return Catalog 0x%lx\n",catalog)); - return (struct Catalog *)catalog; - } - } - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: found none\n")); - - ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); - - - /* Clear error condition before we start. */ - SetIoErr(0); - - iff = AllocIFF(); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iff 0x%lx\n",iff)); - if (NULL == iff) - { - if (def_locale) CloseLocale(def_locale); - SetIoErr(ERROR_NO_FREE_STORE); - - return NULL; - } - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: pref_language %ld language 0x%lx\n", - pref_language, - language)); - - while ((pref_language < 10) && language) - { - if (app_language && (strcmp(language, app_language) == 0)) - { - FreeIFF(iff); - if (def_locale) CloseLocale(def_locale); - SetIoErr(0); - return NULL; - } - - if ((MyProcess->pr_HomeDir) != BNULL) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: HomeDir != BNULL..try progdir\n")); - strcpy(filename, "PROGDIR:Catalogs"); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, language, FILENAMESIZE); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, name , FILENAMESIZE); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iffstream 0x%lx\n", - iff->iff_Stream)); - } - if (iff->iff_Stream) break; - -#ifdef __MORPHOS__ - strcpy(filename, "MOSSYS:LOCALE/Catalogs"); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, language, FILENAMESIZE); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, name , FILENAMESIZE); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: try filename <%s>\n",filename)); - - { APTR oldwinptr=MyProcess->pr_WindowPtr; - MyProcess->pr_WindowPtr=(APTR)-1; - iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE); - MyProcess->pr_WindowPtr=oldwinptr; - } - - if (iff->iff_Stream) break; -#endif - strcpy(filename, "LOCALE:Catalogs"); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, language, FILENAMESIZE); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n",filename)); - AddPart(filename, name , FILENAMESIZE); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: try filename <%s>\n",filename)); - - iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iffstream 0x%lx\n", - iff->iff_Stream)); - - if (iff->iff_Stream) break; - - pref_language++; - language = locale->loc_PrefLanguages[pref_language]; - } - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n",language)); - - /* I no longer need the locale. So close it if we opened it */ - - if (def_locale) - { - CloseLocale(def_locale); - def_locale = NULL; - } - -#undef FILENAMESIZE - - if (iff->iff_Stream == 0) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: end..nostream\n")); - FreeIFF(iff); - SetIoErr(ERROR_OBJECT_NOT_FOUND); - return NULL; - } - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog name <%s>\n",name)); - catalog = AllocVec(sizeof(struct IntCatalog) + strlen(name) + 1, MEMF_CLEAR | MEMF_PUBLIC); - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog 0x%lx\n",catalog)); - if (NULL == catalog) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: end..no catalog\n")); - Close((BPTR)iff->iff_Stream); - FreeIFF(iff); - SetIoErr(ERROR_NO_FREE_STORE); - return NULL; - } - - catalog->ic_UseCount = 1; - catalog->ic_Catalog.cat_Language = catalog->ic_LanguageName; - strcpy(catalog->ic_Name, name); - catalog->ic_Catalog.cat_Link.ln_Name = catalog->ic_Name; /* Scout expects this */ - - InitIFFasDOS(iff); - - if (!OpenIFF(iff, IFFF_READ)) - { - while (1) - { - LONG error = ParseIFF(iff, IFFPARSE_STEP); - - if (IFFERR_EOF == error) - { - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: parsed catalog\n")); - /* Did everything go fine? */ - - if (!(catalog->ic_LanguageName[0])) - { - /* No ID_LANG chunk found. So setup languagename ourselves. - Hmm ... maybe this should be done anyway always. Because - if the catalog file *does* contain an ID_LANG chunk then - this should be the same as "language" anyway. And if it - is not, then maybe OpenCatalogA() should fail :-\ */ - - strcpy(catalog->ic_LanguageName, language); - } - - /* Connect this catalog to the list of catalogs */ - ObtainSemaphore (&IntLB(LocaleBase)->lb_CatalogLock); - AddHead((struct List *)&IntLB(LocaleBase)->lb_CatalogList, - &catalog->ic_Catalog.cat_Link); - ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); - - CloseIFF(iff); - Close((BPTR)iff->iff_Stream); - FreeIFF(iff); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: return catalog 0x%lx\n",catalog)); - - return &catalog->ic_Catalog; - } - - if (IFFERR_EOC == error) /* end of chunk */ - continue; - - if (0 == error) - { - struct ContextNode * top = CurrentChunk(iff); - - switch (top->cn_ID) - { - case ID_FORM: - break; - - case ID_FVER: - - if (top->cn_Size > 100) break; /*max 100 bytes*/ - - error = ReadChunkBytes(iff, buf, top->cn_Size); - if (error == top->cn_Size) - { - error = 0; - } - else - { - break; - } - - buf[99] = 0; - - /*Ok now we want to get the version and the revision. - They are separated by a blank space*/ - - i = 0; - while (buf[i] && (buf[i] != ' ')) - i++; - while (buf[i] && (buf[i] == ' ')) - i++; - while (buf[i] && (buf[i] != ' ')) - i++; - - if (buf[i]) - { - if ((chars = StrToLong(&buf[i],(LONG *)&catversion)) < 0) - break; - - i += chars; - if (buf[i++]) - { - if (StrToLong(&buf[i],(LONG *)&catrevision) < 0) - break; - } - - catalog->ic_Catalog.cat_Version = catversion; - catalog->ic_Catalog.cat_Revision = catrevision; - - if (version && (catversion != version)) - { - error = RETURN_ERROR; - } - - break; - } - - - case ID_LANG: - /* The IntCatalog structure has only 30 bytes reserved for - the language name. So make sure the chunk is not bigger. */ - - if (top->cn_Size > 30) break; - - error = ReadChunkBytes(iff, catalog->ic_LanguageName, top->cn_Size); - if (error == top->cn_Size) - { - error = 0; - } - break; - - case ID_CSET: - if (top->cn_Size != sizeof(struct CodeSet)) break; - if (top->cn_Size == ReadChunkBytes(iff, - &catalog->ic_CodeSet, - top->cn_Size)) - { - /* Who cares: codeset is not used at the moment */ - } - break; - - case ID_STRS: - if (!(catalog->ic_StringChunk = AllocVec(top->cn_Size, MEMF_PUBLIC | MEMF_CLEAR))) - { - error = ERROR_NO_FREE_STORE; - SetIoErr(error); - break; - } - - error = ReadChunkBytes(iff, catalog->ic_StringChunk, top->cn_Size); - if (error == top->cn_Size) - { - error = 0; - } - else - { - break; - } - - /* Count the number of strings */ - - { - UBYTE *buffer = catalog->ic_StringChunk; - LONG c = 0, strlen; - - catalog->ic_NumStrings = 0; - - while(c < top->cn_Size) - { - catalog->ic_NumStrings++; - - strlen = (buffer[4] << 24) + - (buffer[5] << 16) + - (buffer[6] << 8) + - (buffer[7]); - - strlen = 8 + strlen + (strlen & 1); - if (strlen & 3) strlen += 4 - (strlen & 3); - - c += strlen; buffer += strlen; - } - - } - - if (catalog->ic_NumStrings == 0) break; /* Paranoia? */ - - if (!(catalog->ic_CatStrings = AllocVec(catalog->ic_NumStrings * sizeof(struct CatStr), MEMF_PUBLIC | MEMF_CLEAR))) - { - error = ERROR_NO_FREE_STORE; - SetIoErr(error); - break; - } - - /* Fill out catalog->ic_CatStrings array */ - - { - UBYTE *buffer = catalog->ic_StringChunk; - ULONG i, strlen, id, previd = 0; - BOOL inorder = TRUE; - - for(i = 0; i < catalog->ic_NumStrings; i++) - { - id = (buffer[0] << 24) + - (buffer[1] << 16) + - (buffer[2] << 8) + - (buffer[3]); - - strlen = (buffer[4] << 24) + - (buffer[5] << 16) + - (buffer[6] << 8) + - (buffer[7]); - - catalog->ic_CatStrings[i].cs_String = &buffer[8]; - catalog->ic_CatStrings[i].cs_Id = id; - - //kprintf("Catalog String #%d id=%d string=\"%s\"\n", i, id, catalog->ic_CatStrings[i].cs_String); - - strlen = 8 + strlen + (strlen & 1); - if (strlen & 3) strlen += 4 - (strlen & 3); - - if (id < previd) inorder = FALSE; - - buffer += strlen; - previd = id; - } - - if (inorder) catalog->ic_Flags |= ICF_INORDER; - } - break; - - } /* switch (top->cn_ID) */ - - } /* if (0 == error) */ - - if (error) - { - dispose_catalog(catalog, LocaleBase); - /* - ** An error with the file occurred - */ - break; - } - - } /* while (1) */ - - CloseIFF(iff); - - } /* if (!OpenIFF(iff, IFFF_READ)) */ - - - Close((BPTR)iff->iff_Stream); - FreeIFF(iff); - FreeVec(catalog); - - } /* if (NULL != name) */ - - if (def_locale) CloseLocale(def_locale); - - DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog not loaded\n")); - return NULL; - - AROS_LIBFUNC_EXIT - -} /* OpenCatalogA */ - +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ +*/ +#define AROS_ALMOST_COMPATIBLE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "locale_intern.h" + +#include + +#define DEBUG_OPENCATALOG(x) ; + +struct header +{ + unsigned char id[4]; + unsigned char len[4]; +}; + +/***************************************************************************** + + NAME */ +#include + + AROS_LH3(struct Catalog *, OpenCatalogA, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(CONST_STRPTR, name, A1), + AROS_LHA(const struct TagItem *, tags, A2), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 25, Locale) + +/* FUNCTION + + INPUTS + + RESULT + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct Locale *def_locale = NULL; + struct IntCatalog *catalog = NULL; + char *language; + char *app_language; /* Language given with tag OC_BuiltInLanguage */ + char *specific_language; /* Language given with tag OC_Language */ + struct Process *MyProcess; +#define FILENAMESIZE 256 + + char filename[FILENAMESIZE]; + char buf[100]; + LONG chars; + ULONG version; + ULONG catversion, catrevision; + WORD pref_language; + UWORD i; + + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: locale 0x%lx name <%s> Tags 0x%lx localebase 0x%lx\n", + locale, name, tags, LocaleBase)); + + SetIoErr(0); + + if (!locale) + { + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: no locale\n")); + locale = def_locale = OpenLocale(NULL); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: def_locale 0x%lx\n", + def_locale)); + } + + if (!locale) + { + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: nolocale..done\n")); + return NULL; + } + + MyProcess = (struct Process *)FindTask(NULL); + + specific_language = (char *)GetTagData(OC_Language, (IPTR) 0, tags); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: specific lang 0x%lx\n", + specific_language)); + if (specific_language) + { + language = specific_language; + pref_language = -1; + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n", + language)); + } + else + { + language = locale->loc_PrefLanguages[0]; + pref_language = 0; + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n", + language)); + } + + if (language == NULL) + { + if (def_locale) + CloseLocale(def_locale); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: nolanguage..done\n")); + return NULL; + } + + /* + ** Check whether the built in language of the application matches + ** the language of the default locale. If it matches, then I + ** don't need to load anything. + */ + + app_language = "english"; + app_language = (char *)GetTagData(OC_BuiltInLanguage, + (IPTR) app_language, tags); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: app_language 0x%lx\n", + app_language)); + + if (NULL != app_language && 0 == strcasecmp(app_language, language)) + { + if (def_locale) + CloseLocale(def_locale); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: failure..done\n")); + return NULL; + } + + version = GetTagData(OC_Version, 0, tags); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: version %ld\n", version)); + + if (NULL != name) + { + struct IFFHandle *iff = NULL; + + /* + ** The wanted catalog might be in the list of catalogs that are + ** already loaded. So check that list first. + */ + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: CatalogLock 0x%lx\n", + &IntLB(LocaleBase)->lb_CatalogLock)); + + ObtainSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: search cached Catalog\n")); + + ForeachNode(&IntLB(LocaleBase)->lb_CatalogList, catalog) + { + if (catalog->ic_Name && + 0 == strcmp(catalog->ic_Name, name) && + catalog->ic_Catalog.cat_Language && + 0 == strcmp(catalog->ic_Catalog.cat_Language, language)) + { + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: found Catalog 0x%lx\n", catalog)); + catalog->ic_UseCount++; + ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); + + if (def_locale) + { + CloseLocale(def_locale); + } + + SetIoErr(ERROR_ACTION_NOT_KNOWN); + + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: return Catalog 0x%lx\n", catalog)); + return (struct Catalog *)catalog; + } + } + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: found none\n")); + + ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); + + /* Clear error condition before we start. */ + SetIoErr(0); + + iff = AllocIFF(); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iff 0x%lx\n", iff)); + if (NULL == iff) + { + if (def_locale) + CloseLocale(def_locale); + SetIoErr(ERROR_NO_FREE_STORE); + + return NULL; + } + + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: pref_language %ld language 0x%lx\n", + pref_language, language)); + + while ((pref_language < 10) && language) + { + if (app_language && (strcmp(language, app_language) == 0)) + { + FreeIFF(iff); + if (def_locale) + CloseLocale(def_locale); + SetIoErr(0); + return NULL; + } + + if ((MyProcess->pr_HomeDir) != BNULL) + { + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: HomeDir != BNULL..try progdir\n")); + strcpy(filename, "PROGDIR:Catalogs"); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, language, FILENAMESIZE); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, name, FILENAMESIZE); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + iff->iff_Stream = (IPTR) Open(filename, MODE_OLDFILE); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iffstream 0x%lx\n", + iff->iff_Stream)); + } + if (iff->iff_Stream) + break; + +#ifdef __MORPHOS__ + strcpy(filename, "MOSSYS:LOCALE/Catalogs"); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, language, FILENAMESIZE); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, name, FILENAMESIZE); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: try filename <%s>\n", + filename)); + + { + APTR oldwinptr = MyProcess->pr_WindowPtr; + MyProcess->pr_WindowPtr = (APTR) - 1; + iff->iff_Stream = (IPTR) Open(filename, MODE_OLDFILE); + MyProcess->pr_WindowPtr = oldwinptr; + } + + if (iff->iff_Stream) + break; +#endif + strcpy(filename, "LOCALE:Catalogs"); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, language, FILENAMESIZE); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: filename <%s>\n", + filename)); + AddPart(filename, name, FILENAMESIZE); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: try filename <%s>\n", + filename)); + + iff->iff_Stream = (IPTR) Open(filename, MODE_OLDFILE); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: iffstream 0x%lx\n", + iff->iff_Stream)); + + if (iff->iff_Stream) + break; + + pref_language++; + language = locale->loc_PrefLanguages[pref_language]; + } + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: language 0x%lx\n", + language)); + + /* I no longer need the locale. So close it if we opened it */ + + if (def_locale) + { + CloseLocale(def_locale); + def_locale = NULL; + } + +#undef FILENAMESIZE + + if (iff->iff_Stream == 0) + { + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: end... no stream\n")); + FreeIFF(iff); + SetIoErr(ERROR_OBJECT_NOT_FOUND); + return NULL; + } + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog name <%s>\n", + name)); + catalog = + AllocVec(sizeof(struct IntCatalog) + strlen(name) + 1, + MEMF_CLEAR | MEMF_PUBLIC); + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog 0x%lx\n", + catalog)); + if (NULL == catalog) + { + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: end..no catalog\n")); + Close((BPTR) iff->iff_Stream); + FreeIFF(iff); + SetIoErr(ERROR_NO_FREE_STORE); + return NULL; + } + + catalog->ic_UseCount = 1; + catalog->ic_Catalog.cat_Language = catalog->ic_LanguageName; + strcpy(catalog->ic_Name, name); + catalog->ic_Catalog.cat_Link.ln_Name = catalog->ic_Name; /* Scout expects this */ + + InitIFFasDOS(iff); + + if (!OpenIFF(iff, IFFF_READ)) + { + while (1) + { + LONG error = ParseIFF(iff, IFFPARSE_STEP); + + if (IFFERR_EOF == error) + { + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: parsed catalog\n")); + /* Did everything go fine? */ + + if (!(catalog->ic_LanguageName[0])) + { + /* No ID_LANG chunk found. So setup languagename ourselves. + Hmm ... maybe this should be done anyway always. Because + if the catalog file *does* contain an ID_LANG chunk then + this should be the same as "language" anyway. And if it + is not, then maybe OpenCatalogA() should fail :-\ */ + + strcpy(catalog->ic_LanguageName, language); + } + + /* Connect this catalog to the list of catalogs */ + ObtainSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); + AddHead((struct List *)&IntLB(LocaleBase)-> + lb_CatalogList, &catalog->ic_Catalog.cat_Link); + ReleaseSemaphore(&IntLB(LocaleBase)->lb_CatalogLock); + + CloseIFF(iff); + Close((BPTR) iff->iff_Stream); + FreeIFF(iff); + + DEBUG_OPENCATALOG(dprintf + ("OpenCatalogA: return catalog 0x%lx\n", catalog)); + + return &catalog->ic_Catalog; + } + + if (IFFERR_EOC == error) /* end of chunk */ + continue; + + if (0 == error) + { + struct ContextNode *top = CurrentChunk(iff); + + switch (top->cn_ID) + { + case ID_FORM: + break; + + case ID_FVER: + + if (top->cn_Size > 100) + break; /*max 100 bytes */ + + error = ReadChunkBytes(iff, buf, top->cn_Size); + if (error == top->cn_Size) + { + error = 0; + } + else + { + break; + } + + buf[99] = 0; + + /*Ok now we want to get the version and the revision. + They are separated by a blank space */ + + i = 0; + while (buf[i] && (buf[i] != ' ')) + i++; + while (buf[i] && (buf[i] == ' ')) + i++; + while (buf[i] && (buf[i] != ' ')) + i++; + + if (buf[i]) + { + if ((chars = + StrToLong(&buf[i], + (LONG *) & catversion)) < 0) + break; + + i += chars; + if (buf[i++]) + { + if (StrToLong(&buf[i], + (LONG *) & catrevision) < 0) + break; + } + + catalog->ic_Catalog.cat_Version = catversion; + catalog->ic_Catalog.cat_Revision = catrevision; + + if (version && (catversion != version)) + { + error = RETURN_ERROR; + } + + break; + } + + + case ID_LANG: + /* The IntCatalog structure has only 30 bytes reserved for + the language name. So make sure the chunk is not bigger. */ + + if (top->cn_Size > 30) + break; + + error = + ReadChunkBytes(iff, catalog->ic_LanguageName, + top->cn_Size); + if (error == top->cn_Size) + { + error = 0; + } + break; + + case ID_CSET: + if (top->cn_Size != sizeof(struct CodeSet)) + break; + if (top->cn_Size == ReadChunkBytes(iff, + &catalog->ic_CodeSet, top->cn_Size)) + { + /* Who cares: codeset is not used at the moment */ + } + break; + + case ID_STRS: + if (!(catalog->ic_StringChunk = + AllocVec(top->cn_Size, + MEMF_PUBLIC | MEMF_CLEAR))) + { + error = ERROR_NO_FREE_STORE; + SetIoErr(error); + break; + } + + error = + ReadChunkBytes(iff, catalog->ic_StringChunk, + top->cn_Size); + if (error == top->cn_Size) + { + error = 0; + } + else + { + break; + } + + /* Count the number of strings */ + + { + UBYTE *buffer = catalog->ic_StringChunk; + LONG c = 0, strlen; + + catalog->ic_NumStrings = 0; + + while (c < top->cn_Size) + { + catalog->ic_NumStrings++; + + strlen = (buffer[4] << 24) + + (buffer[5] << 16) + + (buffer[6] << 8) + (buffer[7]); + + strlen = 8 + strlen + (strlen & 1); + if (strlen & 3) + strlen += 4 - (strlen & 3); + + c += strlen; + buffer += strlen; + } + + } + + if (catalog->ic_NumStrings == 0) + break; /* Paranoia? */ + + if (!(catalog->ic_CatStrings = + AllocVec(catalog->ic_NumStrings * + sizeof(struct CatStr), + MEMF_PUBLIC | MEMF_CLEAR))) + { + error = ERROR_NO_FREE_STORE; + SetIoErr(error); + break; + } + + /* Fill out catalog->ic_CatStrings array */ + + { + UBYTE *buffer = catalog->ic_StringChunk; + ULONG i, strlen, id, previd = 0; + BOOL inorder = TRUE; + + for (i = 0; i < catalog->ic_NumStrings; i++) + { + id = (buffer[0] << 24) + + (buffer[1] << 16) + + (buffer[2] << 8) + (buffer[3]); + + strlen = (buffer[4] << 24) + + (buffer[5] << 16) + + (buffer[6] << 8) + (buffer[7]); + + catalog->ic_CatStrings[i].cs_String = + &buffer[8]; + catalog->ic_CatStrings[i].cs_Id = id; + + //kprintf("Catalog String #%d id=%d string=\"%s\"\n", i, id, catalog->ic_CatStrings[i].cs_String); + + strlen = 8 + strlen + (strlen & 1); + if (strlen & 3) + strlen += 4 - (strlen & 3); + + if (id < previd) + inorder = FALSE; + + buffer += strlen; + previd = id; + } + + if (inorder) + catalog->ic_Flags |= ICF_INORDER; + } + break; + + } /* switch (top->cn_ID) */ + + } /* if (0 == error) */ + + if (error) + { + dispose_catalog(catalog, LocaleBase); + /* + ** An error with the file occurred + */ + break; + } + + } /* while (1) */ + + CloseIFF(iff); + + } /* if (!OpenIFF(iff, IFFF_READ)) */ + + + Close((BPTR) iff->iff_Stream); + FreeIFF(iff); + FreeVec(catalog); + + } /* if (NULL != name) */ + + if (def_locale) + CloseLocale(def_locale); + + DEBUG_OPENCATALOG(dprintf("OpenCatalogA: catalog not loaded\n")); + return NULL; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/openlocale.c b/workbench/libs/locale/openlocale.c dissimilarity index 73% index a2b649fe70..73d13fb758 100644 --- a/workbench/libs/locale/openlocale.c +++ b/workbench/libs/locale/openlocale.c @@ -1,187 +1,195 @@ -/* - Copyright © 1995-2010, The AROS Development Team. All rights reserved. - $Id$ - - OpenLocale() - Give access to a new locale. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "locale_intern.h" - -#define DEBUG_OPENLOCALE(x) ; - -extern void InitLocale( - CONST_STRPTR filename, - struct IntLocale *, - struct LocalePrefs *, - struct LocaleBase *); - -/***************************************************************************** - - NAME */ -#include - - AROS_LH1(struct Locale *, OpenLocale, - -/* SYNOPSIS */ - AROS_LHA(CONST_STRPTR, name, A0), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 26, Locale) - -/* FUNCTION - This function will open for use a named locale. A locale is a - data structure that contains many different parameters that - an application needs in order to localise itself. Using this - information, an application can dynamically adapt to the user's - environment. - - Locales are created using the Locale Preferences Editor. If - you pass NULL instead of a name, then you will receive the - current default Locale. This is the normal procedure. - - INPUTS - name - The name of the locale you wish opened, or NULL - to open the current default locale. This will - be an IFF PREF file which contains both LCLE - and CTRY chunks. - - RESULT - A pointer to an initialised Locale structure, or NULL if none - could be opened. If NULL is returned you can use IoErr() - to find out what caused this error. - - If you pass NULL, you will always succeed. - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - CloseLocale() - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct IntLocale *locale = NULL; - - DEBUG_OPENLOCALE(dprintf("OpenLocale: name <%s> localebase 0x%lx\n", - name, - LocaleBase)); - - /* Have we been asked for a disk-based locale? */ - if(name != NULL) - { - struct IFFHandle *iff; - ULONG error; - struct LocalePrefs *lp; - struct ContextNode *cn; - - /* Clear error condition before we start. */ - - SetIoErr(0); - - lp = AllocMem(sizeof(struct LocalePrefs), MEMF_CLEAR); - - DEBUG_OPENLOCALE(dprintf("OpenLocale: lp 0x%lx\n",lp)); - - if( lp == NULL ) - { - SetIoErr(ERROR_NO_FREE_STORE); - - return NULL; - } - - iff = AllocIFF(); - - DEBUG_OPENLOCALE(dprintf("OpenLocale: iff 0x%lx\n",iff)); - - if(iff == NULL) - { - FreeMem(lp, sizeof(struct LocalePrefs)); - SetIoErr(ERROR_NO_FREE_STORE); - return NULL; - } - - iff->iff_Stream = (IPTR)Open(name, MODE_OLDFILE); - - DEBUG_OPENLOCALE(dprintf("OpenLocale: stream 0x%lx\n",iff->iff_Stream)); - - if(iff->iff_Stream == 0) - { - FreeMem(lp, sizeof(struct LocalePrefs)); - FreeIFF(iff); - return NULL; - } - - InitIFFasDOS(iff); - - if(!OpenIFF(iff, IFFF_READ)) - { - if(!StopChunk(iff, ID_PREF, ID_LCLE)) - { - while(1) - { - error = ParseIFF(iff, IFFPARSE_SCAN); - if(error == 0) - { - cn = CurrentChunk(iff); - if((cn->cn_ID == ID_LCLE) && (cn->cn_Type == ID_PREF)) - { - if(ReadChunkBytes(iff, lp, sizeof(struct LocalePrefs)) == sizeof(struct LocalePrefs)) - { - locale = AllocMem(sizeof(struct IntLocale), MEMF_CLEAR|MEMF_PUBLIC); - DEBUG_OPENLOCALE(dprintf("OpenLocale: locale 0x%lx\n",locale)); - if(locale) - { - InitLocale(name, locale, lp, LocaleBase); - break; - } - else - SetIoErr(ERROR_NO_FREE_STORE); - } - } - } /* from a stop chunk */ - else if(error != IFFERR_EOC) - break; - - } /* while(1) */ - } /* StopChunk() */ - - CloseIFF(iff); - } - Close((BPTR)iff->iff_Stream); - FreeIFF(iff); - FreeMem(lp, sizeof(struct LocalePrefs)); - } - else - { - /* Return the current default */ - - DEBUG_OPENLOCALE(dprintf("OpenLocale: LocaleLock 0x%lx\n",&IntLB(LocaleBase)->lb_LocaleLock)); - - ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - locale = IntLB(LocaleBase)->lb_CurrentLocale; - locale->il_Count++; - ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - } - - DEBUG_OPENLOCALE(dprintf("OpenLocale: Locale 0x%lx\n",locale)); - /* We let the optimiser do some CSE above */ - return (struct Locale *)locale; - - AROS_LIBFUNC_EXIT -} /* OpenLocale */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + OpenLocale() - Give access to a new locale. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "locale_intern.h" + +#define DEBUG_OPENLOCALE(x) ; + +extern void InitLocale( + CONST_STRPTR filename, + struct IntLocale *, + struct LocalePrefs *, + struct LocaleBase *); + +/***************************************************************************** + + NAME */ +#include + + AROS_LH1(struct Locale *, OpenLocale, + +/* SYNOPSIS */ + AROS_LHA(CONST_STRPTR, name, A0), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 26, Locale) + +/* FUNCTION + This function will open for use a named locale. A locale is a + data structure that contains many different parameters that + an application needs in order to localise itself. Using this + information, an application can dynamically adapt to the user's + environment. + + Locales are created using the Locale Preferences Editor. If + you pass NULL instead of a name, then you will receive the + current default Locale. This is the normal procedure. + + INPUTS + name - The name of the locale you wish opened, or NULL + to open the current default locale. This will + be an IFF PREF file which contains both LCLE + and CTRY chunks. + + RESULT + A pointer to an initialised Locale structure, or NULL if none + could be opened. If NULL is returned you can use IoErr() + to find out what caused this error. + + If you pass NULL, you will always succeed. + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + CloseLocale() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct IntLocale *locale = NULL; + + DEBUG_OPENLOCALE(dprintf("OpenLocale: name <%s> localebase 0x%lx\n", + name, LocaleBase)); + + /* Have we been asked for a disk-based locale? */ + if (name != NULL) + { + struct IFFHandle *iff; + ULONG error; + struct LocalePrefs *lp; + struct ContextNode *cn; + + /* Clear error condition before we start. */ + + SetIoErr(0); + + lp = AllocMem(sizeof(struct LocalePrefs), MEMF_CLEAR); + + DEBUG_OPENLOCALE(dprintf("OpenLocale: lp 0x%lx\n", lp)); + + if (lp == NULL) + { + SetIoErr(ERROR_NO_FREE_STORE); + + return NULL; + } + + iff = AllocIFF(); + + DEBUG_OPENLOCALE(dprintf("OpenLocale: iff 0x%lx\n", iff)); + + if (iff == NULL) + { + FreeMem(lp, sizeof(struct LocalePrefs)); + SetIoErr(ERROR_NO_FREE_STORE); + return NULL; + } + + iff->iff_Stream = (IPTR) Open(name, MODE_OLDFILE); + + DEBUG_OPENLOCALE(dprintf("OpenLocale: stream 0x%lx\n", + iff->iff_Stream)); + + if (iff->iff_Stream == 0) + { + FreeMem(lp, sizeof(struct LocalePrefs)); + FreeIFF(iff); + return NULL; + } + + InitIFFasDOS(iff); + + if (!OpenIFF(iff, IFFF_READ)) + { + if (!StopChunk(iff, ID_PREF, ID_LCLE)) + { + while (1) + { + error = ParseIFF(iff, IFFPARSE_SCAN); + if (error == 0) + { + cn = CurrentChunk(iff); + if ((cn->cn_ID == ID_LCLE) + && (cn->cn_Type == ID_PREF)) + { + if (ReadChunkBytes(iff, lp, + sizeof(struct LocalePrefs)) == + sizeof(struct LocalePrefs)) + { + locale = + AllocMem(sizeof(struct IntLocale), + MEMF_CLEAR | MEMF_PUBLIC); + DEBUG_OPENLOCALE(dprintf + ("OpenLocale: locale 0x%lx\n", locale)); + if (locale) + { + InitLocale(name, locale, lp, + LocaleBase); + break; + } + else + SetIoErr(ERROR_NO_FREE_STORE); + } + } + } /* from a stop chunk */ + else if (error != IFFERR_EOC) + break; + + } /* while(1) */ + } /* StopChunk() */ + + CloseIFF(iff); + } + Close((BPTR) iff->iff_Stream); + FreeIFF(iff); + FreeMem(lp, sizeof(struct LocalePrefs)); + } + else + { + /* Return the current default */ + + DEBUG_OPENLOCALE(dprintf("OpenLocale: LocaleLock 0x%lx\n", + &IntLB(LocaleBase)->lb_LocaleLock)); + + ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + locale = IntLB(LocaleBase)->lb_CurrentLocale; + locale->il_Count++; + ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + } + + DEBUG_OPENLOCALE(dprintf("OpenLocale: Locale 0x%lx\n", locale)); + /* We let the optimiser do some CSE above */ + return (struct Locale *)locale; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/parsedate.c b/workbench/libs/locale/parsedate.c dissimilarity index 85% index d85f0c5e99..52ff4cf61b 100644 --- a/workbench/libs/locale/parsedate.c +++ b/workbench/libs/locale/parsedate.c @@ -1,472 +1,486 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ -*/ - -#include -#include -#include -#include -#include -#include "locale_intern.h" - -static const UWORD monthdays[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; -static const UBYTE monthday[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - -BOOL _getnum(LONG numchars, - LONG *valPtr, - ULONG *cPtr, - CONST_STRPTR *fmtTemplatePtr, - BOOL *checkEOFPtr, - const struct Locale *locale, - const struct Hook *getCharFunc, - struct LocaleBase *LocaleBase); -#define get2num(x) _getnum(2, (x), &c, &fmtTemplate, &checkEOF, locale, getCharFunc, LocaleBase) -#define get4num(x) _getnum(4, (x), &c, &fmtTemplate, &checkEOF, locale, getCharFunc, LocaleBase) - -/***************************************************************************** - - NAME */ -#include - - AROS_LH4(BOOL, ParseDate, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(struct DateStamp *, date, A1), - AROS_LHA(CONST_STRPTR , fmtTemplate, A2), - AROS_LHA(const struct Hook *, getCharFunc, A3), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 27, Locale) - -/* FUNCTION - This function will convert a stream of characters into an AmigaDOS - DateStamp structure. It will obtain its characters from the - getCharFunc callback hook, and the given formatting template will - be used to direct the parse. - - INPUTS - locale - the locale to use for the formatting - date - where to put the converted date. If this is NULL, - then this function can be used to verify a date - string. - fmtTemplate - the date template used to direct the parse of the - data. The following FormatDate() formatting - controls can be used: - %a %A %b %B %d %e %h %H %I %m %M %p %S %y %Y - - See FormatDate() autodoc for more information. - getCharFunc - A callback Hook which is used to read the data - from a stream. The hook is called with: - - A0 - address of the Hook structure - A2 - locale pointer - A1 - NULL - - BTW: The AmigaOS autodocs which state that A1 - gets locale pointer and A2 NULL are wrong!! - - The read character should be returned in D0. Note - that this is a 32 bit character not an 8 bit - character. Return a NULL character if you reach the - end of the stream. - - RESULT - TRUE - If the parse could be performed. - FALSE - If the format of the data did not match the formatting - string. - - NOTES - This has a few differences from the implementation in locale.library - v38. In particular: - - %p does not have to be at the end of the line. - - %d and %e are not effectively the same: leading spaces are - allowed before %e, but not before %d. - - EXAMPLE - - BUGS - %p, %b, %A and probably others accept substrings and superstrings of - valid strings. - - SEE ALSO - FormatDate() - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - ULONG c; - LONG day = 0, month = 0, hour = 0, min = 0, sec = 0; - LONG year = 1978; - BOOL leap, ampm = FALSE, checkEOF = TRUE; - if ( (fmtTemplate == NULL) - || (getCharFunc == NULL) - || (locale == NULL) - || (*fmtTemplate == '\0') - ) - return FALSE; - -#define GetChar()\ - AROS_UFC3(ULONG, getCharFunc->h_Entry, \ - AROS_UFCA(const struct Hook *, getCharFunc, A0), \ - AROS_UFCA(const struct Locale *, locale, A2), \ - AROS_UFCA(ULONG, 0, A1)) - - while (*fmtTemplate) - { - /* Check for EOF if we leave the loop */ - checkEOF = TRUE; - - if (*fmtTemplate == '%') - { - UBYTE strOffs = 0; - fmtTemplate++; - - switch(*fmtTemplate++) - { - /* abbreviated weekday name */ - case 'a': - strOffs = 7; - /* weekday name */ - case 'A': - { - CONST_STRPTR dayStr[7]; - BOOL dayOk[7]; - ULONG i, a; - - for (i= 0; i < 7; i++) - { - dayOk[i] = TRUE; - dayStr[i] = GetLocaleStr(locale, i + strOffs + 1); - } - - c = GetChar(); - while ((c != '\0') && (c != *fmtTemplate)) - { - for (i=0; i < 7; i++) - { - a = ConvToUpper(locale, *(dayStr[i])++); - c = ConvToUpper(locale, c); - - if (dayOk[i] && a) - if (a != c) dayOk[i] = FALSE; - } - c = GetChar(); - } - - /* End of stream in wrong place, or invalid */ - if (((c == '\0') && *fmtTemplate) || (c != *fmtTemplate)) - return FALSE; - - /* If we didn't get a valid day, fail */ - i = 0; - while ((i < 7) && !dayOk[i++]) - ; - if ((i == 7) && !dayOk[6]) - return FALSE; - - if (*fmtTemplate) fmtTemplate++; - checkEOF = FALSE; - } break; /* case 'A': */ - - /* abbreviated month name */ - case 'b': - /* abbreviated month name */ - case 'h': - strOffs = 12; - /* month name */ - case 'B': - { - CONST_STRPTR monthStr[12]; - BOOL monthOk[12]; - ULONG i, a; - - for (i = 0; i < 12; i++) - { - monthOk[i] = TRUE; - monthStr[i] = GetLocaleStr(locale, i + strOffs + MON_1); - } - - c = GetChar(); - while ((c != '\0') && (c != *fmtTemplate)) - { - for (i=0; i < 12; i++) - { - a = ConvToUpper(locale, *(monthStr[i])++); - c = ConvToUpper(locale, c); - - if (monthOk[i] && a) - if (a != c) monthOk[i] = FALSE; - } - c = GetChar(); - } - - /* End of stream in wrong place, or invalid */ - if (((c == '\0') && *fmtTemplate) || (c != *fmtTemplate)) - return FALSE; - - /* If we didn't get a valid month, fail */ - i = 0; - while ((i < 12) && !monthOk[i++]) - ; - if ((i == 12) && !monthOk[11]) - return FALSE; - month = i; - - if (*fmtTemplate) fmtTemplate++; - checkEOF = FALSE; - - break; - } /* case 'B': */ - - /* Day no */ - case 'd': - day = 0; - c = GetChar(); - if (!get2num(&day)) - return FALSE; - if (day-- == 0) - return FALSE; - - break; - /* Day no., leading spaces. */ - case 'e': - day = 0; - c = GetChar(); - while (IsSpace(locale, c)) - c = GetChar(); - if (!get2num(&day)) - return FALSE; - if (day-- == 0) - return FALSE; - - break; - - /* hour 24-hr style */ - case 'H': - ampm = FALSE; - c = GetChar(); - if (!get2num(&hour)) - return FALSE; - if (hour > 23) return FALSE; - break; - - /* hour 12-hr style */ - case 'I': - c = GetChar(); - if (!get2num(&hour)) - return FALSE; - if (hour > 11) return FALSE; - break; - - /* month num */ - case 'm': - c = GetChar(); - if (!get2num(&month)) - return FALSE; - if ((month > 12) || (month == 0)) - return FALSE; - break; - - /* minutes */ - case 'M': - c = GetChar(); - if (!get2num(&min)) - return FALSE; - - if (min > 59) return FALSE; - break; - - /* AM or PM string */ - case 'p': - { - CONST_STRPTR amStr, pmStr; - BOOL amOk = TRUE, pmOk = TRUE; - ULONG a, b; - amStr = GetLocaleStr(locale, AM_STR); - pmStr = GetLocaleStr(locale, PM_STR); - - c = GetChar(); - while ((c != '\0') && (c != *fmtTemplate)) - { - a = ConvToUpper(locale, *amStr++); - b = ConvToUpper(locale, *pmStr++); - c = ConvToUpper(locale, c); - - if (amOk && a) - if (a != c) amOk = FALSE; - - if (pmOk && b) - if (b != c) pmOk = FALSE; - - c = GetChar(); - } - - /* End of stream in wrong place, or invalid */ - if (c != *fmtTemplate) - return FALSE; - - /* Check whether we got AM or PM */ - ampm = pmOk; - - if (*fmtTemplate) fmtTemplate++; - checkEOF = FALSE; - break; - } - - /* the number of seconds */ - case 'S': - c = GetChar(); - if (!get2num(&sec)) - return FALSE; - if (sec > 59) return FALSE; - break; - - /* the year using two or four digits */ - case 'y': - c = GetChar(); - if (!get4num(&year)) - return FALSE; - - if (year >= 100 && year < 1978) - return FALSE; - if (year < 78) - year += 100; - if (year < 1900) - year += 1900; - break; - - /* the year using four digits */ - case 'Y': - c = GetChar(); - if (IsDigit(locale, c) == FALSE) - return FALSE; - year = (c - '0') * 1000; - - c = GetChar(); - if (IsDigit(locale, c) == FALSE) - return FALSE; - year += (c - '0') * 100; - - c = GetChar(); - if (IsDigit(locale, c) == FALSE) - return FALSE; - year += (c - '0') * 10; - - c = GetChar(); - if (IsDigit(locale, c) == FALSE) - return FALSE; - year += (c - '0'); - - if (year < 1978) - return FALSE; - break; - - default: - return FALSE; - break; - } /* switch() */ - } /* if (char == '%') */ - else - { - c = GetChar(); - if (c != *fmtTemplate++) - return FALSE; - } - } /* while (*fmtTemplate) */ - - /* Reached end of fmtTemplate, end of input stream? */ - if (checkEOF) - if ((GetChar() != 0)) return FALSE; - - /* Is this year a leap year ? */ - leap = (((year % 400) == 0) || - (((year % 4) == 0) && !((year % 100) == 0))); - - /* Sanity check */ - if (month != 0 && day >= - (monthday[month - 1] + ((leap && (month == 2)) ? 1 : 0))) - { - return FALSE; - } - - if (date) - { - /* Add the days for all years (without leap years) */ - day += (year - 1978) * 365; - - year--; - - /* Add leap years */ - day += ((year / 4) - (year / 100) + (year / 400) - - (494 - 19 + 4)); - - /* Add days of months */ - day += monthdays[month - 1]; - - /* - in monthdays, February has 28 days. Correct this in - leap years if month is >= March. - */ - - if (leap && (month >= 3)) day++; - - date->ds_Days = day; - - date->ds_Minute = hour * 60 + min; - if ((hour < 12) && ampm) - date->ds_Minute += 720; - date->ds_Tick = sec * TICKS_PER_SECOND; - } - return TRUE; - - AROS_LIBFUNC_EXIT -} /* ParseDate */ - - -BOOL _getnum(LONG numchars, - LONG *valPtr, - ULONG *cPtr, - CONST_STRPTR *fmtTemplatePtr, - BOOL *checkEOFPtr, - const struct Locale *locale, - const struct Hook *getCharFunc, - struct LocaleBase *LocaleBase) -{ - LONG val; - ULONG c; - - c = *cPtr; - //*c = GetChar(); - if (IsDigit(locale, c) == FALSE) - return FALSE; - - val = c - '0'; - - while (--numchars >= 1) - { - c = GetChar(); - if (IsDigit(locale, c)) - val = val * 10 + c - '0'; - else - { - *cPtr = c; - if (c != **fmtTemplatePtr) - return FALSE; - if (c == '\0') - *checkEOFPtr = FALSE; - else - (*fmtTemplatePtr)++; - - break; - } - } - - *valPtr = val; - - return TRUE; -} +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ +*/ + +#include +#include +#include +#include +#include +#include "locale_intern.h" + +static const UWORD monthdays[12] = + { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; +static const UBYTE monthday[12] = + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +BOOL _getnum(LONG numchars, + LONG * valPtr, + ULONG * cPtr, + CONST_STRPTR * fmtTemplatePtr, + BOOL * checkEOFPtr, + const struct Locale *locale, + const struct Hook *getCharFunc, struct LocaleBase *LocaleBase); +#define get2num(x) _getnum(2, (x), &c, &fmtTemplate, &checkEOF, locale, getCharFunc, LocaleBase) +#define get4num(x) _getnum(4, (x), &c, &fmtTemplate, &checkEOF, locale, getCharFunc, LocaleBase) + +/***************************************************************************** + + NAME */ +#include + + AROS_LH4(BOOL, ParseDate, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(struct DateStamp *, date, A1), + AROS_LHA(CONST_STRPTR , fmtTemplate, A2), + AROS_LHA(const struct Hook *, getCharFunc, A3), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 27, Locale) + +/* FUNCTION + This function will convert a stream of characters into an AmigaDOS + DateStamp structure. It will obtain its characters from the + getCharFunc callback hook, and the given formatting template will + be used to direct the parse. + + INPUTS + locale - the locale to use for the formatting + date - where to put the converted date. If this is NULL, + then this function can be used to verify a date + string. + fmtTemplate - the date template used to direct the parse of the + data. The following FormatDate() formatting + controls can be used: + %a %A %b %B %d %e %h %H %I %m %M %p %S %y %Y + + See FormatDate() autodoc for more information. + getCharFunc - A callback Hook which is used to read the data + from a stream. The hook is called with: + + A0 - address of the Hook structure + A2 - locale pointer + A1 - NULL + + BTW: The AmigaOS autodocs which state that A1 + gets locale pointer and A2 NULL are wrong!! + + The read character should be returned in D0. Note + that this is a 32 bit character not an 8 bit + character. Return a NULL character if you reach the + end of the stream. + + RESULT + TRUE - If the parse could be performed. + FALSE - If the format of the data did not match the formatting + string. + + NOTES + This has a few differences from the implementation in locale.library + v38. In particular: + - %p does not have to be at the end of the line. + - %d and %e are not effectively the same: leading spaces are + allowed before %e, but not before %d. + + EXAMPLE + + BUGS + %p, %b, %A and probably others accept substrings and superstrings of + valid strings. + + SEE ALSO + FormatDate() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + ULONG c; + LONG day = 0, month = 0, hour = 0, min = 0, sec = 0; + LONG year = 1978; + BOOL leap, ampm = FALSE, checkEOF = TRUE; + if ((fmtTemplate == NULL) + || (getCharFunc == NULL) + || (locale == NULL) || (*fmtTemplate == '\0')) + return FALSE; + +#define GetChar()\ + AROS_UFC3(ULONG, getCharFunc->h_Entry, \ + AROS_UFCA(const struct Hook *, getCharFunc, A0), \ + AROS_UFCA(const struct Locale *, locale, A2), \ + AROS_UFCA(ULONG, 0, A1)) + + while (*fmtTemplate) + { + /* Check for EOF if we leave the loop */ + checkEOF = TRUE; + + if (*fmtTemplate == '%') + { + UBYTE strOffs = 0; + fmtTemplate++; + + switch (*fmtTemplate++) + { + /* abbreviated weekday name */ + case 'a': + strOffs = 7; + /* weekday name */ + case 'A': + { + CONST_STRPTR dayStr[7]; + BOOL dayOk[7]; + ULONG i, a; + + for (i = 0; i < 7; i++) + { + dayOk[i] = TRUE; + dayStr[i] = GetLocaleStr(locale, i + strOffs + 1); + } + + c = GetChar(); + while ((c != '\0') && (c != *fmtTemplate)) + { + for (i = 0; i < 7; i++) + { + a = ConvToUpper(locale, *(dayStr[i])++); + c = ConvToUpper(locale, c); + + if (dayOk[i] && a) + if (a != c) + dayOk[i] = FALSE; + } + c = GetChar(); + } + + /* End of stream in wrong place, or invalid */ + if (((c == '\0') && *fmtTemplate) + || (c != *fmtTemplate)) + return FALSE; + + /* If we didn't get a valid day, fail */ + i = 0; + while ((i < 7) && !dayOk[i++]) + ; + if ((i == 7) && !dayOk[6]) + return FALSE; + + if (*fmtTemplate) + fmtTemplate++; + checkEOF = FALSE; + } + break; /* case 'A': */ + + /* abbreviated month name */ + case 'b': + /* abbreviated month name */ + case 'h': + strOffs = 12; + /* month name */ + case 'B': + { + CONST_STRPTR monthStr[12]; + BOOL monthOk[12]; + ULONG i, a; + + for (i = 0; i < 12; i++) + { + monthOk[i] = TRUE; + monthStr[i] = + GetLocaleStr(locale, i + strOffs + MON_1); + } + + c = GetChar(); + while ((c != '\0') && (c != *fmtTemplate)) + { + for (i = 0; i < 12; i++) + { + a = ConvToUpper(locale, *(monthStr[i])++); + c = ConvToUpper(locale, c); + + if (monthOk[i] && a) + if (a != c) + monthOk[i] = FALSE; + } + c = GetChar(); + } + + /* End of stream in wrong place, or invalid */ + if (((c == '\0') && *fmtTemplate) + || (c != *fmtTemplate)) + return FALSE; + + /* If we didn't get a valid month, fail */ + i = 0; + while ((i < 12) && !monthOk[i++]) + ; + if ((i == 12) && !monthOk[11]) + return FALSE; + month = i; + + if (*fmtTemplate) + fmtTemplate++; + checkEOF = FALSE; + + break; + } /* case 'B': */ + + /* Day no */ + case 'd': + day = 0; + c = GetChar(); + if (!get2num(&day)) + return FALSE; + if (day-- == 0) + return FALSE; + + break; + /* Day no., leading spaces. */ + case 'e': + day = 0; + c = GetChar(); + while (IsSpace(locale, c)) + c = GetChar(); + if (!get2num(&day)) + return FALSE; + if (day-- == 0) + return FALSE; + + break; + + /* hour 24-hr style */ + case 'H': + ampm = FALSE; + c = GetChar(); + if (!get2num(&hour)) + return FALSE; + if (hour > 23) + return FALSE; + break; + + /* hour 12-hr style */ + case 'I': + c = GetChar(); + if (!get2num(&hour)) + return FALSE; + if (hour > 11) + return FALSE; + break; + + /* month num */ + case 'm': + c = GetChar(); + if (!get2num(&month)) + return FALSE; + if ((month > 12) || (month == 0)) + return FALSE; + break; + + /* minutes */ + case 'M': + c = GetChar(); + if (!get2num(&min)) + return FALSE; + + if (min > 59) + return FALSE; + break; + + /* AM or PM string */ + case 'p': + { + CONST_STRPTR amStr, pmStr; + BOOL amOk = TRUE, pmOk = TRUE; + ULONG a, b; + amStr = GetLocaleStr(locale, AM_STR); + pmStr = GetLocaleStr(locale, PM_STR); + + c = GetChar(); + while ((c != '\0') && (c != *fmtTemplate)) + { + a = ConvToUpper(locale, *amStr++); + b = ConvToUpper(locale, *pmStr++); + c = ConvToUpper(locale, c); + + if (amOk && a) + if (a != c) + amOk = FALSE; + + if (pmOk && b) + if (b != c) + pmOk = FALSE; + + c = GetChar(); + } + + /* End of stream in wrong place, or invalid */ + if (c != *fmtTemplate) + return FALSE; + + /* Check whether we got AM or PM */ + ampm = pmOk; + + if (*fmtTemplate) + fmtTemplate++; + checkEOF = FALSE; + break; + } + + /* the number of seconds */ + case 'S': + c = GetChar(); + if (!get2num(&sec)) + return FALSE; + if (sec > 59) + return FALSE; + break; + + /* the year using two or four digits */ + case 'y': + c = GetChar(); + if (!get4num(&year)) + return FALSE; + + if (year >= 100 && year < 1978) + return FALSE; + if (year < 78) + year += 100; + if (year < 1900) + year += 1900; + break; + + /* the year using four digits */ + case 'Y': + c = GetChar(); + if (IsDigit(locale, c) == FALSE) + return FALSE; + year = (c - '0') * 1000; + + c = GetChar(); + if (IsDigit(locale, c) == FALSE) + return FALSE; + year += (c - '0') * 100; + + c = GetChar(); + if (IsDigit(locale, c) == FALSE) + return FALSE; + year += (c - '0') * 10; + + c = GetChar(); + if (IsDigit(locale, c) == FALSE) + return FALSE; + year += (c - '0'); + + if (year < 1978) + return FALSE; + break; + + default: + return FALSE; + break; + } /* switch() */ + } /* if (char == '%') */ + else + { + c = GetChar(); + if (c != *fmtTemplate++) + return FALSE; + } + } /* while (*fmtTemplate) */ + + /* Reached end of fmtTemplate, end of input stream? */ + if (checkEOF) + if ((GetChar() != 0)) + return FALSE; + + /* Is this year a leap year ? */ + leap = (((year % 400) == 0) || + (((year % 4) == 0) && !((year % 100) == 0))); + + /* Sanity check */ + if (month != 0 && day >= + (monthday[month - 1] + ((leap && (month == 2)) ? 1 : 0))) + { + return FALSE; + } + + if (date) + { + /* Add the days for all years (without leap years) */ + day += (year - 1978) * 365; + + year--; + + /* Add leap years */ + day += ((year / 4) - (year / 100) + (year / 400) - (494 - 19 + 4)); + + /* Add days of months */ + day += monthdays[month - 1]; + + /* + in monthdays, February has 28 days. Correct this in + leap years if month is >= March. + */ + + if (leap && (month >= 3)) + day++; + + date->ds_Days = day; + + date->ds_Minute = hour * 60 + min; + if ((hour < 12) && ampm) + date->ds_Minute += 720; + date->ds_Tick = sec * TICKS_PER_SECOND; + } + return TRUE; + + AROS_LIBFUNC_EXIT +} + + +BOOL _getnum(LONG numchars, + LONG * valPtr, + ULONG * cPtr, + CONST_STRPTR * fmtTemplatePtr, + BOOL * checkEOFPtr, + const struct Locale * locale, + const struct Hook * getCharFunc, struct LocaleBase * LocaleBase) +{ + LONG val; + ULONG c; + + c = *cPtr; + //*c = GetChar(); + if (IsDigit(locale, c) == FALSE) + return FALSE; + + val = c - '0'; + + while (--numchars >= 1) + { + c = GetChar(); + if (IsDigit(locale, c)) + val = val * 10 + c - '0'; + else + { + *cPtr = c; + if (c != **fmtTemplatePtr) + return FALSE; + if (c == '\0') + *checkEOFPtr = FALSE; + else + (*fmtTemplatePtr)++; + + break; + } + } + + *valPtr = val; + + return TRUE; +} diff --git a/workbench/libs/locale/patches.c b/workbench/libs/locale/patches.c dissimilarity index 66% index b2bbd62c4e..ad86fa6108 100644 --- a/workbench/libs/locale/patches.c +++ b/workbench/libs/locale/patches.c @@ -1,145 +1,143 @@ -/* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. - $Id$ -*/ - -/*********************************************************************************************/ - -#include "locale_intern.h" - -#include -#include - -#include -#include -#include -#include - -/*********************************************************************************************/ - -#define LIB_EXEC 1 -#define LIB_UTILITY 2 -#define LIB_DOS 3 -#define LIB_LOCALE 4 - -/*********************************************************************************************/ - -AROS_LD4(APTR, LocRawDoFmt, - AROS_LDA(CONST_STRPTR, FormatString, A0), - AROS_LDA(APTR , DataStream, A1), - AROS_LDA(VOID_FUNC , PutChProc, A2), - AROS_LDA(APTR , PutChData, A3), - struct ExecBase *, SysBase, 31, Locale); -AROS_LD4(APTR, LocVNewRawDoFmt, - AROS_LDA(CONST_STRPTR, FormatString, A0), - AROS_LDA(VOID_FUNC , PutChProc, A2), - AROS_LDA(APTR , PutChData, A3), - AROS_LDA(va_list , DataStream, A1), - struct ExecBase *, SysBase, 39, Locale); -AROS_LD3(LONG, LocStrnicmp, - AROS_LDA(CONST_STRPTR, string1, A0), - AROS_LDA(CONST_STRPTR, string2, A1), - AROS_LDA(LONG , length , D0), - struct UtilityBase *, UtilityBase, 32, Locale); -AROS_LD2(LONG, LocStricmp, - AROS_LDA(CONST_STRPTR, string1, A0), - AROS_LDA(CONST_STRPTR, string2, A1), - struct UtilityBase *, UtilityBase, 33, Locale); -AROS_LD1(ULONG, LocToLower, - AROS_LDA(ULONG, character, D0), - struct UtilityBase *, UtilityBase, 34, Locale); -AROS_LD1(ULONG, LocToUpper, - AROS_LDA(ULONG, character, D0), - struct UtilityBase *, UtilityBase, 35, Locale); -AROS_LD1(LONG, LocDateToStr, - AROS_LDA(struct DateTime *, datetime, D1), - struct DosLibrary *, DOSBase, 36, Locale); -AROS_LD1(LONG, LocStrToDate, - AROS_LDA(struct DateTime *, datetime, D1), - struct DosLibrary *, DOSBase, 37, Locale); -AROS_LD1(CONST_STRPTR, LocDosGetLocalizedString, - AROS_LDA(LONG, stringNum, D1), - struct DosLibrary *, DOSBase, 38, Locale); - -/*********************************************************************************************/ - -static struct patchinfo -{ - WORD library; - WORD whichfunc; - APTR whichpatchfunc; -} pi [] = { - - {LIB_EXEC , 87 , AROS_SLIB_ENTRY(LocRawDoFmt , Locale, 31)}, - {LIB_UTILITY, 28 , AROS_SLIB_ENTRY(LocStrnicmp , Locale, 32)}, - {LIB_UTILITY, 27 , AROS_SLIB_ENTRY(LocStricmp , Locale, 33)}, - {LIB_UTILITY, 30 , AROS_SLIB_ENTRY(LocToLower , Locale, 34)}, - {LIB_UTILITY, 29 , AROS_SLIB_ENTRY(LocToUpper , Locale, 35)}, - {LIB_DOS , 124, AROS_SLIB_ENTRY(LocDateToStr , Locale, 36)}, - {LIB_DOS , 125, AROS_SLIB_ENTRY(LocStrToDate , Locale, 37)}, - {LIB_DOS , 163, AROS_SLIB_ENTRY(LocDosGetLocalizedString , Locale, 38)}, - {LIB_EXEC , 137, AROS_SLIB_ENTRY(LocVNewRawDoFmt , Locale, 39)}, - {0} -}; - -/*********************************************************************************************/ - -static struct Library *GetLib(WORD which) -{ - struct Library *lib = NULL; - - switch(which) - { - case LIB_EXEC: - lib = (struct Library *)SysBase; - break; - - case LIB_DOS: - lib = (struct Library *)DOSBase; - break; - - case LIB_UTILITY: - lib = (struct Library *)UtilityBase; - break; - - case LIB_LOCALE: - lib = (struct Library *)LocaleBase; - break; - } - - return lib; -} - -/*********************************************************************************************/ - -void InstallPatches(void) -{ - WORD i; - -#ifdef __MORPHOS__ - static const struct TagItem PatchTags[] = - { - {SETFUNCTAG_MACHINE, MACHINE_PPC}, - {SETFUNCTAG_TYPE, SETFUNCTYPE_NORMAL}, - {SETFUNCTAG_IDNAME, (ULONG) "locale.library Language Patch"}, - {SETFUNCTAG_DELETE, TRUE}, - {TAG_DONE} - }; -#endif - - Forbid(); - for(i = 0; pi[i].library; i++) - { -#ifdef __MORPHOS__ - NewSetFunction(GetLib(pi[i].library), pi[i].whichpatchfunc, -pi[i].whichfunc * LIB_VECTSIZE, PatchTags); -#else - SetFunction(GetLib(pi[i].library), - -pi[i].whichfunc * LIB_VECTSIZE, pi[i].whichpatchfunc); -#endif - } - Permit(); - LocaleBase->lb_SysPatches = TRUE; - -} - -/*********************************************************************************************/ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + */ + +/**************************************************************************/ + +#include "locale_intern.h" + +#include +#include + +#include +#include +#include +#include + +/**************************************************************************/ + +#define LIB_EXEC 1 +#define LIB_UTILITY 2 +#define LIB_DOS 3 +#define LIB_LOCALE 4 + +/**************************************************************************/ + +AROS_LD4(APTR, LocRawDoFmt, + AROS_LDA(CONST_STRPTR, FormatString, A0), + AROS_LDA(APTR, DataStream, A1), + AROS_LDA(VOID_FUNC, PutChProc, A2), + AROS_LDA(APTR, PutChData, A3), struct ExecBase *, SysBase, 31, Locale); +AROS_LD4(APTR, LocVNewRawDoFmt, + AROS_LDA(CONST_STRPTR, FormatString, A0), + AROS_LDA(VOID_FUNC, PutChProc, A2), + AROS_LDA(APTR, PutChData, A3), + AROS_LDA(va_list, DataStream, A1), + struct ExecBase *, SysBase, 39, Locale); +AROS_LD3(LONG, LocStrnicmp, + AROS_LDA(CONST_STRPTR, string1, A0), + AROS_LDA(CONST_STRPTR, string2, A1), + AROS_LDA(LONG, length, D0), + struct UtilityBase *, UtilityBase, 32, Locale); +AROS_LD2(LONG, LocStricmp, + AROS_LDA(CONST_STRPTR, string1, A0), + AROS_LDA(CONST_STRPTR, string2, A1), + struct UtilityBase *, UtilityBase, 33, Locale); +AROS_LD1(ULONG, LocToLower, + AROS_LDA(ULONG, character, D0), + struct UtilityBase *, UtilityBase, 34, Locale); +AROS_LD1(ULONG, LocToUpper, + AROS_LDA(ULONG, character, D0), + struct UtilityBase *, UtilityBase, 35, Locale); +AROS_LD1(LONG, LocDateToStr, + AROS_LDA(struct DateTime *, datetime, D1), + struct DosLibrary *, DOSBase, 36, Locale); +AROS_LD1(LONG, LocStrToDate, + AROS_LDA(struct DateTime *, datetime, D1), + struct DosLibrary *, DOSBase, 37, Locale); +AROS_LD1(CONST_STRPTR, LocDosGetLocalizedString, + AROS_LDA(LONG, stringNum, D1), + struct DosLibrary *, DOSBase, 38, Locale); + +/**************************************************************************/ + +static struct patchinfo +{ + WORD library; + WORD whichfunc; + APTR whichpatchfunc; +} pi[] = +{ + {LIB_EXEC, 87, AROS_SLIB_ENTRY(LocRawDoFmt, Locale, 31)}, + {LIB_UTILITY, 28, AROS_SLIB_ENTRY(LocStrnicmp, Locale, 32)}, + {LIB_UTILITY, 27, AROS_SLIB_ENTRY(LocStricmp, Locale, 33)}, + {LIB_UTILITY, 30, AROS_SLIB_ENTRY(LocToLower, Locale, 34)}, + {LIB_UTILITY, 29, AROS_SLIB_ENTRY(LocToUpper, Locale, 35)}, + {LIB_DOS, 124, AROS_SLIB_ENTRY(LocDateToStr, Locale, 36)}, + {LIB_DOS, 125, AROS_SLIB_ENTRY(LocStrToDate, Locale, 37)}, + {LIB_DOS, 163, AROS_SLIB_ENTRY(LocDosGetLocalizedString, Locale, 38)}, + {LIB_EXEC, 137, AROS_SLIB_ENTRY(LocVNewRawDoFmt, Locale, 39)}, + {0} +}; + +/**************************************************************************/ + +static struct Library *GetLib(WORD which) +{ + struct Library *lib = NULL; + + switch (which) + { + case LIB_EXEC: + lib = (struct Library *)SysBase; + break; + + case LIB_DOS: + lib = (struct Library *)DOSBase; + break; + + case LIB_UTILITY: + lib = (struct Library *)UtilityBase; + break; + + case LIB_LOCALE: + lib = (struct Library *)LocaleBase; + break; + } + + return lib; +} + +/**************************************************************************/ + +void InstallPatches(void) +{ + WORD i; + +#ifdef __MORPHOS__ + static const struct TagItem PatchTags[] = { + {SETFUNCTAG_MACHINE, MACHINE_PPC}, + {SETFUNCTAG_TYPE, SETFUNCTYPE_NORMAL}, + {SETFUNCTAG_IDNAME, (ULONG) "locale.library Language Patch"}, + {SETFUNCTAG_DELETE, TRUE}, + {TAG_DONE} + }; +#endif + + Forbid(); + for (i = 0; pi[i].library; i++) + { +#ifdef __MORPHOS__ + NewSetFunction(GetLib(pi[i].library), pi[i].whichpatchfunc, + -pi[i].whichfunc * LIB_VECTSIZE, PatchTags); +#else + SetFunction(GetLib(pi[i].library), + -pi[i].whichfunc * LIB_VECTSIZE, pi[i].whichpatchfunc); +#endif + } + Permit(); + LocaleBase->lb_SysPatches = TRUE; +} + +/**************************************************************************/ diff --git a/workbench/libs/locale/prefsupdate.c b/workbench/libs/locale/prefsupdate.c dissimilarity index 67% index 683dc949eb..a3fb903e51 100644 --- a/workbench/libs/locale/prefsupdate.c +++ b/workbench/libs/locale/prefsupdate.c @@ -1,123 +1,121 @@ -/* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. - $Id$ - - Desc: Tell locale that the preferences have been changed. - Lang: english -*/ - -#include -#include -#include -#include -#include -#include -#include -#include "locale_intern.h" - -static const char *langlist[] = -{ - "english", - "deutsch", - "français", - "español", - "italiano", - "português", - "dansk", - "nederlands", - "norsk", - "suomi", - "svenska", - NULL -}; - -/*****i*********************************************************************** - - NAME */ -#include - - AROS_LH1(struct Locale *, LocalePrefsUpdate, - -/* SYNOPSIS */ - AROS_LHA(struct Locale *, locale, A0), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 28, Locale) - -/* FUNCTION - This internal function is called by the IPrefs program to - notify the locale.library that the system preferences have - been changed. - - INPUTS - locale - A pointer to the new locale preferences. - - RESULT - The address of the old locale preferences data. This should - have CloseLocale() called upon it. - - NOTES - You can safely call CloseLocale() on the new Locale as this - function will ensure that the Locale will not be freed until - PrefsUpdate() is called again. - - EXAMPLE - - BUGS - - SEE ALSO - - INTERNALS - - HISTORY - 27-11-96 digulla automatically created from - locale_lib.fd and clib/locale_protos.h - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct IntLocale *old = NULL; - STRPTR language, dotptr; - ULONG index = 0; - - if(locale != NULL) - { - /* Lock the locale structures */ - ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - - /* Remote the old locale, and decrease its user count. */ - old = IntLB(LocaleBase)->lb_CurrentLocale; - old->il_Count--; - - /* Update the count and install the new locale. */ - IntL(locale)->il_Count++; - IntLB(LocaleBase)->lb_CurrentLocale = IntL(locale); - ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); - - /* Let's be mean to save some hassle */ - language = locale->loc_LanguageName; - if ((dotptr = strchr(language, '.'))) *dotptr = 0; - - /* Update ENV:Language */ - SetVar("Language", language, -1, LV_VAR | GVF_GLOBAL_ONLY); - - /* Update UtilityBase->ub_Language */ - while (langlist[index] != NULL) - { - if (strcmp(language, langlist[index++]) == 0) - { - /* Check for american-english */ - if (index == 1 && locale->loc_MeasuringSystem == MS_AMERICAN) --index; - - UtilityBase->ub_Language = index+1; - break; - } - } - - if (dotptr) *dotptr = '.'; - } - return (struct Locale *)old; - - AROS_LIBFUNC_EXIT -} /* PrefsUpdate */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: Tell locale that the preferences have been changed. + Lang: english +*/ + +#include +#include +#include +#include +#include +#include +#include +#include "locale_intern.h" + +static const char *langlist[] = +{ + "english", + "deutsch", + "français", + "español", + "italiano", + "português", + "dansk", + "nederlands", + "norsk", + "suomi", + "svenska", + NULL +}; + +/*****i*********************************************************************** + + NAME */ +#include + + AROS_LH1(struct Locale *, LocalePrefsUpdate, + +/* SYNOPSIS */ + AROS_LHA(struct Locale *, locale, A0), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 28, Locale) + +/* FUNCTION + This internal function is called by the IPrefs program to + notify the locale.library that the system preferences have + been changed. + + INPUTS + locale - A pointer to the new locale preferences. + + RESULT + The address of the old locale preferences data. This should + have CloseLocale() called upon it. + + NOTES + You can safely call CloseLocale() on the new Locale as this + function will ensure that the Locale will not be freed until + PrefsUpdate() is called again. + + EXAMPLE + + BUGS + + SEE ALSO + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct IntLocale *old = NULL; + STRPTR language, dotptr; + ULONG index = 0; + + if(locale != NULL) + { + /* Lock the locale structures */ + ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + + /* Remote the old locale, and decrease its user count. */ + old = IntLB(LocaleBase)->lb_CurrentLocale; + old->il_Count--; + + /* Update the count and install the new locale. */ + IntL(locale)->il_Count++; + IntLB(LocaleBase)->lb_CurrentLocale = IntL(locale); + ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock); + + /* Let's be mean to save some hassle */ + language = locale->loc_LanguageName; + if ((dotptr = strchr(language, '.'))) + *dotptr = 0; + + /* Update ENV:Language */ + SetVar("Language", language, -1, LV_VAR | GVF_GLOBAL_ONLY); + + /* Update UtilityBase->ub_Language */ + while (langlist[index] != NULL) + { + if (strcmp(language, langlist[index++]) == 0) + { + /* Check for american-english */ + if (index == 1 && locale->loc_MeasuringSystem == MS_AMERICAN) + --index; + + UtilityBase->ub_Language = index+1; + break; + } + } + + if (dotptr) *dotptr = '.'; + } + return (struct Locale *)old; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/rawdofmtsupport.c b/workbench/libs/locale/rawdofmtsupport.c deleted file mode 100644 index 9c33546612..0000000000 --- a/workbench/libs/locale/rawdofmtsupport.c +++ /dev/null @@ -1,28 +0,0 @@ -/* This used QUICK reg layout - */ -#define EMUL_QUICKMODE -#include -#include -#include - -#define DEBUG(x) ; - -char *_PPCCallM68k_RawDoFmt(char MyChar, - char* (*PutChProc)(char*,char), - char *PutChData, - ULONG OldA4, - struct ExecBase *sysBase) - -{ -struct EmulCaos MyCaos; - - MyCaos.caos_Un.Function = PutChProc; - MyCaos.reg_d0 =(ULONG) MyChar; - MyCaos.reg_a2 =(ULONG) PutChProc; - MyCaos.reg_a3 =(ULONG) PutChData; - MyCaos.reg_a4 = OldA4; - MyCaos.reg_a6 =(ULONG) sysBase; - (*MyEmulHandle->EmulCallQuick68k)(&MyCaos); - - return(REG_A3); -} diff --git a/workbench/libs/locale/rexxhost.c b/workbench/libs/locale/rexxhost.c dissimilarity index 70% index d8416602c4..f65a31b398 100644 --- a/workbench/libs/locale/rexxhost.c +++ b/workbench/libs/locale/rexxhost.c @@ -1,232 +1,303 @@ -#include - -#ifdef __MORPHOS__ -#define CVa2i(__p0) \ - LP1(300, LONG , CVa2i, \ - STRPTR , __p0, a0, \ - , RexxSysBase, 0, 0, 0, 0, 0, 0) - -#define CVi2az(__p0, __p1, __p2) \ - LP3(318, LONG , CVi2az, \ - STRPTR , __p0, a0, \ - LONG , __p1, d0, \ - LONG , __p2, d1, \ - , RexxSysBase, 0, 0, 0, 0, 0, 0) -#endif - -#include -#include -#include -#include -#include "locale_intern.h" -#include - -#include -#include - - -static LONG rxGetCatalogStr(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - *resstr = GetCatalogStr((struct Catalog *)CVa2i(rxmsg->rm_Args[1]), atol(rxmsg->rm_Args[2]), rxmsg->rm_Args[3]); - return strlen(*resstr); -} - -static LONG rxGetLocaleStr(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - *resstr = GetLocaleStr(locale, atol(rxmsg->rm_Args[1])); - return strlen(*resstr); -} - -static LONG rxOpenCatalog(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - APTR cat = OpenCatalog(locale, rxmsg->rm_Args[1], OC_BuiltInLanguage, (ULONG)rxmsg->rm_Args[2], OC_Version, atol(rxmsg->rm_Args[3]), TAG_DONE); - return CVi2az(*resstr, (LONG)cat, 12); -} - -static LONG rxCloseCatalog(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - CloseCatalog((struct Catalog *)CVa2i(rxmsg->rm_Args[1])); - return 0; -} - -static LONG rxStrnCmp(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - LONG reslen = StrnCmp(locale, rxmsg->rm_Args[1], rxmsg->rm_Args[2], -1, atol(rxmsg->rm_Args[3])); - - if (reslen < 0) { *resstr[0] = '-'; *resstr[1] = '1'; reslen = 2; } - else if (reslen > 0) { *resstr[0] = '1'; reslen = 1; } - else { *resstr[0] = '0'; reslen = 1; } - - return reslen; -} - -static LONG rxConvToLower(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - *resstr[0] = (UBYTE)ConvToLower(locale, *rxmsg->rm_Args[1]); - return 1; -} - -static LONG rxConvToUpper(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - *resstr[0] = (UBYTE)ConvToUpper(locale, *rxmsg->rm_Args[1]); - return 1; -} - -static LONG rxIsAlpha(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsAlpha(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsSpace(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsSpace(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsDigit(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsDigit(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsGraph(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsGraph(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsAlNum(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsAlNum(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsCntrl(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsCntrl(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsLower(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsLower(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsPunct(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsPunct(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsUpper(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsUpper(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsPrint(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsPrint(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -static LONG rxIsXDigit(struct LocaleBase *LocaleBase, struct Locale *locale, struct RexxMsg *rxmsg, STRPTR *resstr) -{ - if (IsXDigit(locale, *rxmsg->rm_Args[1])) *resstr[0] = '1'; - else *resstr[0] = '0'; - return 1; -} - -struct dispentry -{ - CONST_STRPTR FuncName; - LONG (*Function)(struct LocaleBase *, struct Locale *, struct RexxMsg *, STRPTR *); - ULONG NumArgs; -}; - -/* MUST be alphabetically sorted! */ -struct dispentry disptable[] = { - { "CLOSECATALOG", rxCloseCatalog, 1 }, - { "CONVTOLOWER", rxConvToLower, 1 }, - { "CONVTOUPPER", rxConvToUpper, 1 }, - { "GETCATALOGSTR", rxGetCatalogStr, 3 }, - { "GETLOCALESTR", rxGetLocaleStr, 1 }, /*** NEW ***/ - { "ISALNUM", rxIsAlNum, 1 }, - { "ISALPHA", rxIsAlpha, 1 }, - { "ISCNTRL", rxIsCntrl, 1 }, - { "ISDIGIT", rxIsDigit, 1 }, - { "ISGRAPH", rxIsGraph, 1 }, - { "ISLOWER", rxIsLower, 1 }, - { "ISPRINT", rxIsPrint, 1 }, - { "ISPUNCT", rxIsPunct, 1 }, - { "ISSPACE", rxIsSpace, 1 }, - { "ISUPPER", rxIsUpper, 1 }, - { "ISXDIGIT", rxIsXDigit, 1 }, - { "OPENCATALOG", rxOpenCatalog, 3 }, - { "STRNCMP", rxStrnCmp, 3 } -}; - -int dispcomp(const void *name, const void *dispentry) -{ - return stricmp(name, ((const struct dispentry *)dispentry)->FuncName); -} - - -/***************************************************************************** - - NAME */ - - AROS_LH1(ULONG, RexxHost, - -/* SYNOPSIS */ - AROS_LHA(struct RexxMsg *, rxmsg, A0), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 5, Locale) - -/* FUNCTION - locale.library rexxhost interface - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - struct Locale *locale = (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale; - struct dispentry *dispentry; - LONG reslen; - UBYTE resbuf[12]; - STRPTR argstr = resbuf; - - if (!RexxSysBase) return(ERR10_014); - if (!rxmsg || !IsRexxMsg(rxmsg) || !(rxmsg->rm_Action & RXFUNC) || !rxmsg->rm_Args[0]) return(ERR10_010); - - if (!(dispentry = bsearch(rxmsg->rm_Args[0], disptable, sizeof(disptable)/sizeof(struct dispentry), sizeof(struct dispentry), dispcomp))) return(ERR10_001); - if ((rxmsg->rm_Action & RXARGMASK) != dispentry->NumArgs) return(ERR10_017); - - reslen = dispentry->Function(LocaleBase, locale, rxmsg, &argstr); - - if (!(argstr = CreateArgstring(argstr, reslen))) return(ERR10_003); - -#ifdef __MORPHOS__ - REG_A0 = (ULONG)argstr; -#else -#error register a0 must be set to argstr before returning... -#endif - - return 0; - - AROS_LIBFUNC_EXIT -} /* RexxHost */ - +#include + +#ifdef __MORPHOS__ +#define CVa2i(__p0) \ + LP1(300, LONG , CVa2i, \ + STRPTR , __p0, a0, \ + , RexxSysBase, 0, 0, 0, 0, 0, 0) + +#define CVi2az(__p0, __p1, __p2) \ + LP3(318, LONG , CVi2az, \ + STRPTR , __p0, a0, \ + LONG , __p1, d0, \ + LONG , __p2, d1, \ + , RexxSysBase, 0, 0, 0, 0, 0, 0) +#endif + +#include +#include +#include +#include +#include "locale_intern.h" +#include + +#include +#include + + +static LONG rxGetCatalogStr(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + *resstr = + GetCatalogStr((struct Catalog *)CVa2i(rxmsg->rm_Args[1]), + atol(rxmsg->rm_Args[2]), rxmsg->rm_Args[3]); + return strlen(*resstr); +} + +static LONG rxGetLocaleStr(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + *resstr = GetLocaleStr(locale, atol(rxmsg->rm_Args[1])); + return strlen(*resstr); +} + +static LONG rxOpenCatalog(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + APTR cat = + OpenCatalog(locale, rxmsg->rm_Args[1], OC_BuiltInLanguage, + (ULONG) rxmsg->rm_Args[2], OC_Version, atol(rxmsg->rm_Args[3]), + TAG_DONE); + return CVi2az(*resstr, (LONG) cat, 12); +} + +static LONG rxCloseCatalog(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + CloseCatalog((struct Catalog *)CVa2i(rxmsg->rm_Args[1])); + return 0; +} + +static LONG rxStrnCmp(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + LONG reslen = + StrnCmp(locale, rxmsg->rm_Args[1], rxmsg->rm_Args[2], -1, + atol(rxmsg->rm_Args[3])); + + if (reslen < 0) + { + *resstr[0] = '-'; + *resstr[1] = '1'; + reslen = 2; + } + else if (reslen > 0) + { + *resstr[0] = '1'; + reslen = 1; + } + else + { + *resstr[0] = '0'; + reslen = 1; + } + + return reslen; +} + +static LONG rxConvToLower(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + *resstr[0] = (UBYTE) ConvToLower(locale, *rxmsg->rm_Args[1]); + return 1; +} + +static LONG rxConvToUpper(struct LocaleBase *LocaleBase, + struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr) +{ + *resstr[0] = (UBYTE) ConvToUpper(locale, *rxmsg->rm_Args[1]); + return 1; +} + +static LONG rxIsAlpha(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsAlpha(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsSpace(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsSpace(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsDigit(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsDigit(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsGraph(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsGraph(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsAlNum(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsAlNum(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsCntrl(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsCntrl(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsLower(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsLower(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsPunct(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsPunct(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsUpper(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsUpper(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsPrint(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsPrint(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +static LONG rxIsXDigit(struct LocaleBase *LocaleBase, struct Locale *locale, + struct RexxMsg *rxmsg, STRPTR * resstr) +{ + if (IsXDigit(locale, *rxmsg->rm_Args[1])) + *resstr[0] = '1'; + else + *resstr[0] = '0'; + return 1; +} + +struct dispentry +{ + CONST_STRPTR FuncName; + LONG(*Function) (struct LocaleBase *, struct Locale *, + struct RexxMsg *, STRPTR *); + ULONG NumArgs; +}; + +/* MUST be alphabetically sorted! */ +struct dispentry disptable[] = { + {"CLOSECATALOG", rxCloseCatalog, 1}, + {"CONVTOLOWER", rxConvToLower, 1}, + {"CONVTOUPPER", rxConvToUpper, 1}, + {"GETCATALOGSTR", rxGetCatalogStr, 3}, + {"GETLOCALESTR", rxGetLocaleStr, 1}, /*** NEW ***/ + {"ISALNUM", rxIsAlNum, 1}, + {"ISALPHA", rxIsAlpha, 1}, + {"ISCNTRL", rxIsCntrl, 1}, + {"ISDIGIT", rxIsDigit, 1}, + {"ISGRAPH", rxIsGraph, 1}, + {"ISLOWER", rxIsLower, 1}, + {"ISPRINT", rxIsPrint, 1}, + {"ISPUNCT", rxIsPunct, 1}, + {"ISSPACE", rxIsSpace, 1}, + {"ISUPPER", rxIsUpper, 1}, + {"ISXDIGIT", rxIsXDigit, 1}, + {"OPENCATALOG", rxOpenCatalog, 3}, + {"STRNCMP", rxStrnCmp, 3} +}; + +int dispcomp(const void *name, const void *dispentry) +{ + return stricmp(name, ((const struct dispentry *)dispentry)->FuncName); +} + + +/***************************************************************************** + + NAME */ + + AROS_LH1(ULONG, RexxHost, + +/* SYNOPSIS */ + AROS_LHA(struct RexxMsg *, rxmsg, A0), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 5, Locale) + +/* FUNCTION + locale.library rexxhost interface + +*****************************************************************************/ + +{ + AROS_LIBFUNC_INIT + + struct Locale *locale = + (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale; + struct dispentry *dispentry; + LONG reslen; + UBYTE resbuf[12]; + STRPTR argstr = resbuf; + + if (!RexxSysBase) + return (ERR10_014); + if (!rxmsg || !IsRexxMsg(rxmsg) || !(rxmsg->rm_Action & RXFUNC) + || !rxmsg->rm_Args[0]) + return (ERR10_010); + + if (!(dispentry = + bsearch(rxmsg->rm_Args[0], disptable, + sizeof(disptable) / sizeof(struct dispentry), + sizeof(struct dispentry), dispcomp))) + return (ERR10_001); + if ((rxmsg->rm_Action & RXARGMASK) != dispentry->NumArgs) + return (ERR10_017); + + reslen = dispentry->Function(LocaleBase, locale, rxmsg, &argstr); + + if (!(argstr = CreateArgstring(argstr, reslen))) + return (ERR10_003); + +#ifdef __MORPHOS__ + REG_A0 = (ULONG) argstr; +#else +#error register a0 must be set to argstr before returning... +#endif + + return 0; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/strconvert.c b/workbench/libs/locale/strconvert.c dissimilarity index 74% index 8a9f1698d9..d5b91cf8ce 100644 --- a/workbench/libs/locale/strconvert.c +++ b/workbench/libs/locale/strconvert.c @@ -1,104 +1,99 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ - - Desc: StrConvert - Stub for the Locale StrConvert function. - Lang: english -*/ -#include -#include -#include "locale_intern.h" -#include - -#define DEBUG_STRCONVERT(x) ; - -/***************************************************************************** - - NAME */ -#include - - AROS_LH5(ULONG, StrConvert, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(CONST_STRPTR , string, A1), - AROS_LHA(APTR , buffer, A2), - AROS_LHA(ULONG , bufferSize, D0), - AROS_LHA(ULONG , type, D1), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 29, Locale) - -/* FUNCTION - This function will transform the string given and place the - result in the supplied buffers, copying at most bufferSize - bytes. - - The transformation is such that if the C strcmp() function - was called on two strings transformed by this function then - the result will be the same as calling the Locale StrnCmp() - function on the two strings. - - INPUTS - locale - the Locale to use for the transformation. - string - the string to be transformed - buffer - the destination for the transformed string. - This buffer may need to be larger than the - untransformed string. - bufferSize - the maximum number of bytes to place in - buffer. - type - how to transform the string. See the - StrnCmp() function for possible values. - - RESULT - Length of the number of BYTES placed in the buffer by - the transformation process minus 1 (for NULL termination). - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - StrnCmp() - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - LONG Result; - - DEBUG_STRCONVERT(dprintf("StrConvert: locale 0x%lx <%s> buffer 0x%lx size %ld type 0x%lx\n", - locale, - string, - buffer, - bufferSize, - type)); - - DEBUG_STRCONVERT(dprintf("StrConvert: Function 0x%lx\n", - IntL(locale)->il_LanguageFunctions[15])); - -#ifdef AROS_CALL4 - Result = AROS_CALL4(ULONG, IntL(locale)->il_LanguageFunctions[15], - AROS_LCA(CONST_STRPTR, string, A1), - AROS_LCA(APTR, buffer, A2), - AROS_LCA(ULONG, bufferSize, D0), - AROS_LCA(ULONG, type, D1), - struct LocaleBase *, LocaleBase); -#else - Result = AROS_UFC4(ULONG, IntL(locale)->il_LanguageFunctions[15], - AROS_UFCA(CONST_STRPTR, string, A1), - AROS_UFCA(APTR, buffer, A2), - AROS_UFCA(ULONG, bufferSize, D0), - AROS_UFCA(ULONG, type, D1)); -#endif - - DEBUG_STRCONVERT(dprintf("StrConvert: retval %lu\n", - Result)); - - return(Result); - AROS_LIBFUNC_EXIT -} /* StrConvert */ +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: StrConvert - Stub for the Locale StrConvert function. + Lang: english +*/ +#include +#include +#include "locale_intern.h" +#include + +#define DEBUG_STRCONVERT(x) ; + +/***************************************************************************** + + NAME */ +#include + + AROS_LH5(ULONG, StrConvert, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(CONST_STRPTR , string, A1), + AROS_LHA(APTR , buffer, A2), + AROS_LHA(ULONG , bufferSize, D0), + AROS_LHA(ULONG , type, D1), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 29, Locale) + +/* FUNCTION + This function will transform the string given and place the + result in the supplied buffers, copying at most bufferSize + bytes. + + The transformation is such that if the C strcmp() function + was called on two strings transformed by this function then + the result will be the same as calling the Locale StrnCmp() + function on the two strings. + + INPUTS + locale - the Locale to use for the transformation. + string - the string to be transformed + buffer - the destination for the transformed string. + This buffer may need to be larger than the + untransformed string. + bufferSize - the maximum number of bytes to place in + buffer. + type - how to transform the string. See the + StrnCmp() function for possible values. + + RESULT + Length of the number of BYTES placed in the buffer by + the transformation process minus 1 (for NULL termination). + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + StrnCmp() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + LONG result; + + DEBUG_STRCONVERT(dprintf + ("StrConvert: locale 0x%lx <%s> buffer 0x%lx size %ld type 0x%lx\n", + locale, string, buffer, bufferSize, type)); + + DEBUG_STRCONVERT(dprintf("StrConvert: Function 0x%lx\n", + IntL(locale)->il_LanguageFunctions[15])); + +#ifdef AROS_CALL4 + result = AROS_CALL4(ULONG, IntL(locale)->il_LanguageFunctions[15], + AROS_LCA(CONST_STRPTR, string, A1), + AROS_LCA(APTR, buffer, A2), + AROS_LCA(ULONG, bufferSize, D0), + AROS_LCA(ULONG, type, D1), struct LocaleBase *, LocaleBase); +#else + result = AROS_UFC4(ULONG, IntL(locale)->il_LanguageFunctions[15], + AROS_UFCA(CONST_STRPTR, string, A1), + AROS_UFCA(APTR, buffer, A2), + AROS_UFCA(ULONG, bufferSize, D0), AROS_UFCA(ULONG, type, D1)); +#endif + + DEBUG_STRCONVERT(dprintf("StrConvert: retval %lu\n", result)); + + return result; + + AROS_LIBFUNC_EXIT +} diff --git a/workbench/libs/locale/strncmp.c b/workbench/libs/locale/strncmp.c dissimilarity index 79% index 8fc7376356..db52de5545 100644 --- a/workbench/libs/locale/strncmp.c +++ b/workbench/libs/locale/strncmp.c @@ -1,127 +1,120 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ - - Desc: StrnCmp() - Stub for the Locale StrnCmp() function. - Lang: english -*/ -#include -#include -#include "locale_intern.h" -#include - -#define DEBUG_STRNCMP(x) ; - -/***************************************************************************** - - NAME */ -#include - - AROS_LH5(LONG, StrnCmp, - -/* SYNOPSIS */ - AROS_LHA(const struct Locale *, locale, A0), - AROS_LHA(CONST_STRPTR , string1, A1), - AROS_LHA(CONST_STRPTR , string2, A2), - AROS_LHA(LONG , length, D0), - AROS_LHA(ULONG , type, D1), - -/* LOCATION */ - struct LocaleBase *, LocaleBase, 30, Locale) - -/* FUNCTION - StrnCmp() will compare two strings, up to a maximum length - of length using a specific kind of collation information - according to the locale. - - The result will be less than zero, zero, or greater than zero - depending upon whether the string string1 is less than, equal - to, or greater than the string pointed to string2. - - INPUTS - locale - Which locale to use for this comparison. - string1 - NULL terminated string. - string2 - NULL terminated string. - length - Maximum length of string to compare, or -1 to - compare entire strings. - type - How to compare the strings, values are: - - SC_ASCII - Perform a simple ASCII case-insensitive comparison. - This is the fastest comparison, but considers that - accented characters are different to non-accented - characters. - - SC_COLLATE1 - This sorts using the "primary sorting order". This - means that characters such as 'e' and 'é' will be - considered the same. This method also ignores - case. - - SC_COLLATE2 - This will sort using both the primary and secondary - sorting order. This is the slowest sorting method - and should be used when presenting data to a user. - - The first pass is the same as SC_COLLATE1, meaning - that two strings such as "role" and "rôle" would - be sorted identically. The second pass will - compare the diacritical marks. - - RESULT - The relationship between the two strings. - - < 0 means string1 < string2 - = 0 means string1 == string2 - > 0 means string1 > string2 - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - OpenLocale(), CloseLocale(), StrConvert() - - INTERNALS - -*****************************************************************************/ -{ - AROS_LIBFUNC_INIT - - LONG Result; - - DEBUG_STRNCMP(dprintf("StrnCmp: locale 0x%lx <%s> <%s> len %ld type 0x%lx\n", - locale, - string1, - string2, - length, - type)); - - DEBUG_STRNCMP(dprintf("StrnCmp: Function 0x%lx\n", - IntL(locale)->il_LanguageFunctions[16])); - -#ifdef AROS_CALL4 - Result = AROS_CALL4(ULONG, IntL(locale)->il_LanguageFunctions[16], - AROS_LCA(CONST_STRPTR, string1, A1), - AROS_LCA(CONST_STRPTR, string2, A2), - AROS_LCA(ULONG, length, D0), - AROS_LCA(ULONG, type, D1), - struct LocaleBase *, LocaleBase); -#else - Result = AROS_UFC4(ULONG, IntL(locale)->il_LanguageFunctions[16], - AROS_UFCA(CONST_STRPTR, string1, A1), - AROS_UFCA(CONST_STRPTR, string2, A2), - AROS_UFCA(ULONG, length, D0), - AROS_UFCA(ULONG, type, D1)); -#endif - - DEBUG_STRNCMP(dprintf("StrnCmp: retval %ld\n", - Result)); - - return(Result); - - AROS_LIBFUNC_EXIT -} /* StrnCmp */ - +/* + Copyright © 1995-2011, The AROS Development Team. All rights reserved. + $Id$ + + Desc: StrnCmp() - Stub for the Locale StrnCmp() function. + Lang: english +*/ +#include +#include +#include "locale_intern.h" +#include + +#define DEBUG_STRNCMP(x) ; + +/***************************************************************************** + + NAME */ +#include + + AROS_LH5(LONG, StrnCmp, + +/* SYNOPSIS */ + AROS_LHA(const struct Locale *, locale, A0), + AROS_LHA(CONST_STRPTR , string1, A1), + AROS_LHA(CONST_STRPTR , string2, A2), + AROS_LHA(LONG , length, D0), + AROS_LHA(ULONG , type, D1), + +/* LOCATION */ + struct LocaleBase *, LocaleBase, 30, Locale) + +/* FUNCTION + StrnCmp() will compare two strings, up to a maximum length + of length using a specific kind of collation information + according to the locale. + + The result will be less than zero, zero, or greater than zero + depending upon whether the string string1 is less than, equal + to, or greater than the string pointed to string2. + + INPUTS + locale - Which locale to use for this comparison. + string1 - NULL terminated string. + string2 - NULL terminated string. + length - Maximum length of string to compare, or -1 to + compare entire strings. + type - How to compare the strings, values are: + + SC_ASCII + Perform a simple ASCII case-insensitive comparison. + This is the fastest comparison, but considers that + accented characters are different to non-accented + characters. + + SC_COLLATE1 + This sorts using the "primary sorting order". This + means that characters such as 'e' and 'é' will be + considered the same. This method also ignores + case. + + SC_COLLATE2 + This will sort using both the primary and secondary + sorting order. This is the slowest sorting method + and should be used when presenting data to a user. + + The first pass is the same as SC_COLLATE1, meaning + that two strings such as "role" and "rôle" would + be sorted identically. The second pass will + compare the diacritical marks. + + RESULT + The relationship between the two strings. + + < 0 means string1 < string2 + = 0 means string1 == string2 + > 0 means string1 > string2 + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + OpenLocale(), CloseLocale(), StrConvert() + + INTERNALS + +*****************************************************************************/ +{ + AROS_LIBFUNC_INIT + + LONG result; + + DEBUG_STRNCMP(dprintf + ("StrnCmp: locale 0x%lx <%s> <%s> len %ld type 0x%lx\n", locale, + string1, string2, length, type)); + + DEBUG_STRNCMP(dprintf("StrnCmp: Function 0x%lx\n", + IntL(locale)->il_LanguageFunctions[16])); + +#ifdef AROS_CALL4 + result = AROS_CALL4(ULONG, IntL(locale)->il_LanguageFunctions[16], + AROS_LCA(CONST_STRPTR, string1, A1), + AROS_LCA(CONST_STRPTR, string2, A2), + AROS_LCA(ULONG, length, D0), + AROS_LCA(ULONG, type, D1), struct LocaleBase *, LocaleBase); +#else + result = AROS_UFC4(ULONG, IntL(locale)->il_LanguageFunctions[16], + AROS_UFCA(CONST_STRPTR, string1, A1), + AROS_UFCA(CONST_STRPTR, string2, A2), + AROS_UFCA(ULONG, length, D0), AROS_UFCA(ULONG, type, D1)); +#endif + + DEBUG_STRNCMP(dprintf("StrnCmp: retval %ld\n", result)); + + return result; + + AROS_LIBFUNC_EXIT +} -- 2.11.4.GIT