Minor fix and output improvements.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9166 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2001-02-19 05:03:09 +00:00
parent 5cbddd279d
commit 000d0cc4e6
3 changed files with 158 additions and 61 deletions

View file

@ -1,3 +1,9 @@
2001-02-19 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSLocale.m: Tidy, defined __USE_GNU to get YESSTR and NOSTR
on later versions of glibc.
* Source/NSString.m: Log more info when parsing a property list fails.
2001-02-13 Adam Fedor <fedor@gnu.org> 2001-02-13 Adam Fedor <fedor@gnu.org>
* Version: 0.9.1 * Version: 0.9.1
@ -11,8 +17,8 @@
-GSXMLNode name -GSXMLNode name
-GSXMLNode ns -GSXMLNode ns
-GSXMLNode nsDef -GSXMLNode nsDef
* NSString.m: handle NULL bytes in -initWithUTF8String: (Treat it as zero * NSString.m: handle NULL bytes in -initWithUTF8String:
length string and NSDebugMLog a warning). (Treat it as zero length string and NSDebugMLog a warning).
2001-02-09 Jonathan Gapen <jagapen@home.com> 2001-02-09 Jonathan Gapen <jagapen@home.com>

View file

@ -30,6 +30,10 @@
#include <locale.h> #include <locale.h>
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
/*
* Define __USE_GNU to get YESSTR and NOSTR in glibc-2.2.2
*/
#define __USE_GNU
#include <langinfo.h> #include <langinfo.h>
#endif #endif
#include <Foundation/NSUserDefaults.h> #include <Foundation/NSUserDefaults.h>
@ -47,17 +51,23 @@ GSSetLocale(NSString *locale)
const char *clocale; const char *clocale;
clocale = NULL; clocale = NULL;
if (locale) if (locale != nil)
clocale = [locale cString]; {
clocale = [locale cString];
}
clocale = setlocale(LC_ALL, clocale); clocale = setlocale(LC_ALL, clocale);
if (clocale == NULL || strcmp(clocale, "C") == 0 if (clocale == NULL || strcmp(clocale, "C") == 0
|| strcmp(clocale, "POSIX") == 0) || strcmp(clocale, "POSIX") == 0)
clocale = NULL; {
clocale = NULL;
}
locale = nil; locale = nil;
if (clocale) if (clocale != 0)
locale = [NSString stringWithCString: clocale]; {
locale = [NSString stringWithCString: clocale];
}
return locale; return locale;
} }
@ -70,74 +80,102 @@ NSDictionary *
GSDomainFromDefaultLocale(void) GSDomainFromDefaultLocale(void)
{ {
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
int i; int i;
struct lconv *lconv; struct lconv *lconv;
NSMutableDictionary *dict; NSMutableDictionary *dict;
NSMutableArray *arr; NSMutableArray *arr;
NSString *str1, *str2; NSString *str1;
NSString *str2;
dict = [NSMutableDictionary dictionary]; dict = [NSMutableDictionary dictionary];
/* Time/Date Information */ /* Time/Date Information */
arr = [NSMutableArray arrayWithCapacity: 7]; arr = [NSMutableArray arrayWithCapacity: 7];
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
[arr addObject: GSLanginfo(DAY_1+i)]; {
[arr addObject: GSLanginfo(DAY_1+i)];
}
[dict setObject: arr forKey: NSWeekDayNameArray]; [dict setObject: arr forKey: NSWeekDayNameArray];
arr = [NSMutableArray arrayWithCapacity: 7]; arr = [NSMutableArray arrayWithCapacity: 7];
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
[arr addObject: GSLanginfo(ABDAY_1+i)]; {
[arr addObject: GSLanginfo(ABDAY_1+i)];
}
[dict setObject: arr forKey: NSShortWeekDayNameArray]; [dict setObject: arr forKey: NSShortWeekDayNameArray];
arr = [NSMutableArray arrayWithCapacity: 12]; arr = [NSMutableArray arrayWithCapacity: 12];
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
[arr addObject: GSLanginfo(MON_1+i)]; {
[arr addObject: GSLanginfo(MON_1+i)];
}
[dict setObject: arr forKey: NSMonthNameArray]; [dict setObject: arr forKey: NSMonthNameArray];
arr = [NSMutableArray arrayWithCapacity: 12]; arr = [NSMutableArray arrayWithCapacity: 12];
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
[arr addObject: GSLanginfo(ABMON_1+i)]; {
[arr addObject: GSLanginfo(ABMON_1+i)];
}
[dict setObject: arr forKey: NSShortMonthNameArray]; [dict setObject: arr forKey: NSShortMonthNameArray];
str1 = GSLanginfo(AM_STR); str1 = GSLanginfo(AM_STR);
str2 = GSLanginfo(PM_STR); str2 = GSLanginfo(PM_STR);
if (str1 && str2) if (str1 != nil && str2 != nil)
[dict setObject: [NSArray arrayWithObjects: str1, str2, nil] {
forKey: NSAMPMDesignation]; [dict setObject: [NSArray arrayWithObjects: str1, str2, nil]
forKey: NSAMPMDesignation];
}
[dict setObject: GSLanginfo(D_T_FMT) forKey: NSTimeDateFormatString]; [dict setObject: GSLanginfo(D_T_FMT)
[dict setObject: GSLanginfo(D_FMT) forKey: NSShortDateFormatString]; forKey: NSTimeDateFormatString];
[dict setObject: GSLanginfo(T_FMT) forKey: NSTimeFormatString]; [dict setObject: GSLanginfo(D_FMT)
forKey: NSShortDateFormatString];
[dict setObject: GSLanginfo(T_FMT)
forKey: NSTimeFormatString];
lconv = localeconv(); lconv = localeconv();
/* Currency Information */ /* Currency Information */
if (lconv->currency_symbol) if (lconv->currency_symbol)
[dict setObject: [NSString stringWithCString: lconv->currency_symbol ] {
forKey: NSCurrencySymbol]; [dict setObject: [NSString stringWithCString: lconv->currency_symbol]
forKey: NSCurrencySymbol];
}
if (lconv->int_curr_symbol) if (lconv->int_curr_symbol)
[dict setObject: [NSString stringWithCString: lconv->int_curr_symbol] {
forKey: NSInternationalCurrencyString ]; [dict setObject: [NSString stringWithCString: lconv->int_curr_symbol]
forKey: NSInternationalCurrencyString];
}
if (lconv->mon_decimal_point) if (lconv->mon_decimal_point)
[dict setObject: [NSString stringWithCString: lconv->mon_decimal_point] {
forKey: NSInternationalCurrencyString ]; [dict setObject: [NSString stringWithCString: lconv->mon_decimal_point]
forKey: NSInternationalCurrencyString];
}
if (lconv->mon_thousands_sep) if (lconv->mon_thousands_sep)
[dict setObject: [NSString stringWithCString: lconv->mon_thousands_sep] {
forKey: NSInternationalCurrencyString ]; [dict setObject: [NSString stringWithCString: lconv->mon_thousands_sep]
forKey: NSInternationalCurrencyString];
}
/* FIXME: Get currency format from localeconv */ /* FIXME: Get currency format from localeconv */
/* Miscellaneous */ /* Miscellaneous */
if (nl_langinfo(YESSTR)) if (nl_langinfo(YESSTR))
[dict setObject: GSLanginfo(YESSTR) forKey: @"NSYesStr"]; {
[dict setObject: GSLanginfo(YESSTR) forKey: @"NSYesStr"];
}
if (nl_langinfo(NOSTR)) if (nl_langinfo(NOSTR))
[dict setObject: GSLanginfo(NOSTR) forKey: @"NSNoStr"]; {
[dict setObject: GSLanginfo(NOSTR) forKey: @"NSNoStr"];
}
str1 = [NSString stringWithCString: setlocale(LC_ALL, NULL)]; str1 = [NSString stringWithCString: setlocale(LC_ALL, NULL)];
[dict setObject: str1 forKey: NSLocale]; [dict setObject: str1 forKey: NSLocale];
str2 = GSLanguageFromLocale(str1); str2 = GSLanguageFromLocale(str1);
if (str2) if (str2)
[dict setObject: str2 forKey: NSLanguageName]; {
[dict setObject: str2 forKey: NSLanguageName];
}
return dict; return dict;
#else /* HAVE_LANGINFO_H */ #else /* HAVE_LANGINFO_H */
@ -148,8 +186,8 @@ GSDomainFromDefaultLocale(void)
NSString * NSString *
GSLanguageFromLocale(NSString *locale) GSLanguageFromLocale(NSString *locale)
{ {
NSString *language = nil; NSString *language = nil;
NSString *aliases = nil; NSString *aliases = nil;
if (locale == nil || [locale isEqual: @"C"] || [locale isEqual: @"POSIX"]) if (locale == nil || [locale isEqual: @"C"] || [locale isEqual: @"POSIX"])
return @"English"; return @"English";
@ -157,12 +195,13 @@ GSLanguageFromLocale(NSString *locale)
aliases = [NSBundle pathForGNUstepResource: @"Locale" aliases = [NSBundle pathForGNUstepResource: @"Locale"
ofType: @"aliases" ofType: @"aliases"
inDirectory: @"Resources/Languages"]; inDirectory: @"Resources/Languages"];
if (aliases) if (aliases != nil)
{ {
NSDictionary *dict; NSDictionary *dict;
dict = [NSDictionary dictionaryWithContentsOfFile: aliases]; dict = [NSDictionary dictionaryWithContentsOfFile: aliases];
language = [dict objectForKey: locale]; language = [dict objectForKey: locale];
if (language == nil && [locale pathExtension]) if (language == nil && [locale pathExtension] != nil)
{ {
locale = [locale stringByDeletingPathExtension]; locale = [locale stringByDeletingPathExtension];
language = [dict objectForKey: locale]; language = [dict objectForKey: locale];
@ -199,5 +238,3 @@ GSLanguageFromLocale(NSString *locale)
#endif /* !HAVE_LOCALE_H */ #endif /* !HAVE_LOCALE_H */

View file

@ -4083,11 +4083,24 @@ GSPropertyList(NSString *string)
pldata *pld = &_pld; pldata *pld = &_pld;
unsigned length = [string length]; unsigned length = [string length];
NSData *d; NSData *d;
id pl;
#if HAVE_LIBXML #if HAVE_LIBXML
unsigned index = 0; unsigned index = 0;
#endif
/*
* An empty string is a nil property list.
*/
if (length == 0)
{
return nil;
}
#if HAVE_LIBXML
if (whitespce == nil) if (whitespce == nil)
setupWhitespce(); {
setupWhitespce();
}
while (index < length) while (index < length)
{ {
unsigned c = [string characterAtIndex: index]; unsigned c = [string characterAtIndex: index];
@ -4122,7 +4135,8 @@ GSPropertyList(NSString *string)
[[[parser doc] root] name]); [[[parser doc] root] name]);
return nil; return nil;
} }
return AUTORELEASE(RETAIN(nodeToObject([[[parser doc] root] children]))); pl = AUTORELEASE(RETAIN(nodeToObject([[[parser doc] root] children])));
return pl;
} }
#endif #endif
d = [string dataUsingEncoding: NSUnicodeStringEncoding]; d = [string dataUsingEncoding: NSUnicodeStringEncoding];
@ -4132,8 +4146,16 @@ GSPropertyList(NSString *string)
_pld.err = nil; _pld.err = nil;
_pld.lin = 1; _pld.lin = 1;
if (plAlloc == 0) if (plAlloc == 0)
setupPl(); {
return AUTORELEASE(parsePlItem(pld)); setupPl();
}
pl = AUTORELEASE(parsePlItem(pld));
if (pl == nil && _pld.err != nil)
{
NSLog(@"Parse failed at line %d (char %d) - %@",
_pld.lin, _pld.pos, _pld.err);
}
return pl;
} }
static id static id
@ -4145,6 +4167,14 @@ GSPropertyListFromStringsFormat(NSString *string)
unsigned length = [string length]; unsigned length = [string length];
NSData *d; NSData *d;
/*
* An empty string is a nil property list.
*/
if (length == 0)
{
return nil;
}
d = [string dataUsingEncoding: NSUnicodeStringEncoding]; d = [string dataUsingEncoding: NSUnicodeStringEncoding];
_pld.ptr = (unichar*)[d bytes]; _pld.ptr = (unichar*)[d bytes];
_pld.pos = 1; _pld.pos = 1;
@ -4152,7 +4182,9 @@ GSPropertyListFromStringsFormat(NSString *string)
_pld.err = nil; _pld.err = nil;
_pld.lin = 1; _pld.lin = 1;
if (plAlloc == 0) if (plAlloc == 0)
setupPl(); {
setupPl();
}
dict = [[plDictionary allocWithZone: NSDefaultMallocZone()] dict = [[plDictionary allocWithZone: NSDefaultMallocZone()]
initWithCapacity: 0]; initWithCapacity: 0];
@ -4162,16 +4194,24 @@ GSPropertyListFromStringsFormat(NSString *string)
id val; id val;
if (pld->ptr[pld->pos] == '"') if (pld->ptr[pld->pos] == '"')
key = parseQuotedString(pld); {
key = parseQuotedString(pld);
}
else else
key = parseUnquotedString(pld); {
key = parseUnquotedString(pld);
}
if (key == nil) if (key == nil)
return nil; {
DESTROY(dict);
break;
}
if (skipSpace(pld) == NO) if (skipSpace(pld) == NO)
{ {
pld->err = @"incomplete final entry (no semicolon?)"; pld->err = @"incomplete final entry (no semicolon?)";
RELEASE(key); RELEASE(key);
return nil; DESTROY(dict);
break;
} }
if (pld->ptr[pld->pos] == ';') if (pld->ptr[pld->pos] == ';')
{ {
@ -4185,44 +4225,58 @@ GSPropertyListFromStringsFormat(NSString *string)
if (skipSpace(pld) == NO) if (skipSpace(pld) == NO)
{ {
RELEASE(key); RELEASE(key);
return nil; DESTROY(dict);
break;
} }
if (pld->ptr[pld->pos] == '"') if (pld->ptr[pld->pos] == '"')
val = parseQuotedString(pld); {
val = parseQuotedString(pld);
}
else else
val = parseUnquotedString(pld); {
val = parseUnquotedString(pld);
}
if (val == nil) if (val == nil)
{ {
RELEASE(key); RELEASE(key);
return nil; DESTROY(dict);
break;
} }
if (skipSpace(pld) == NO) if (skipSpace(pld) == NO)
{ {
pld->err = @"missing final semicolon"; pld->err = @"missing final semicolon";
RELEASE(key); RELEASE(key);
RELEASE(val); RELEASE(val);
return nil; DESTROY(dict);
break;
} }
(*plSet)(dict, @selector(setObject:forKey:), val, key); (*plSet)(dict, @selector(setObject:forKey:), val, key);
RELEASE(key); RELEASE(key);
RELEASE(val); RELEASE(val);
if (pld->ptr[pld->pos] == ';') if (pld->ptr[pld->pos] == ';')
pld->pos++; {
pld->pos++;
}
else else
{ {
pld->err = @"unexpected character (wanted ';')"; pld->err = @"unexpected character (wanted ';')";
RELEASE(dict); DESTROY(dict);
return nil; break;
} }
} }
else else
{ {
RELEASE(key);
RELEASE(dict);
pld->err = @"unexpected character (wanted '=' or ';')"; pld->err = @"unexpected character (wanted '=' or ';')";
return nil; RELEASE(key);
DESTROY(dict);
break;
} }
} }
if (dict == nil && _pld.err != nil)
{
NSLog(@"Parse failed at line %d (char %d) - %@",
_pld.lin, _pld.pos, _pld.err);
}
return AUTORELEASE(dict); return AUTORELEASE(dict);
} }
#endif /* NO_GNUSTEP */ #endif /* NO_GNUSTEP */