Added GSPrintf()

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14714 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-10-11 09:14:14 +00:00
parent b517be3070
commit dfbdc838df
12 changed files with 241 additions and 92 deletions

View file

@ -1,3 +1,13 @@
2002-10-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSLog.m: Added GSPrintf()
* Tools/defaults.m: Use GSPrintf()
* Tools/pldes.m: ditto
* Tools/plser.m: ditto
* Tools/plmerge.m: ditto
* Tools/plparse.m: ditto
* Tools/sfparse.m: ditto
2002-10-09 Richard Frith-Macdonald <rfm@gnu.org> 2002-10-09 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/GNUmakefile: revert ... can't build if base library isn't * Tools/GNUmakefile: revert ... can't build if base library isn't

View file

@ -69,10 +69,11 @@ GS_EXPORT NSLog_printf_handler *_NSLog_printf_handler;
GS_EXPORT int _NSLogDescriptor; GS_EXPORT int _NSLogDescriptor;
@class NSRecursiveLock; @class NSRecursiveLock;
GS_EXPORT NSRecursiveLock *GSLogLock(); GS_EXPORT NSRecursiveLock *GSLogLock();
GS_EXPORT BOOL GSPrintf (FILE *fptr, NSString *format, ...);
#endif #endif
GS_EXPORT void NSLog (NSString* format, ...); GS_EXPORT void NSLog (NSString *format, ...);
GS_EXPORT void NSLogv (NSString* format, va_list args); GS_EXPORT void NSLogv (NSString *format, va_list args);
#ifndef YES #ifndef YES
#define YES 1 #define YES 1

View file

@ -256,8 +256,9 @@ GSTimeNow()
unsigned dtoIndex; unsigned dtoIndex;
if (locale == nil) if (locale == nil)
locale = GSUserDefaultsDictionaryRepresentation(); {
locale = GSUserDefaultsDictionaryRepresentation();
}
ws = [NSCharacterSet whitespaceAndNewlineCharacterSet]; ws = [NSCharacterSet whitespaceAndNewlineCharacterSet];
digits = [NSCharacterSet decimalDigitCharacterSet]; digits = [NSCharacterSet decimalDigitCharacterSet];
scanner = [NSScanner scannerWithString: string]; scanner = [NSScanner scannerWithString: string];
@ -521,14 +522,18 @@ GSTimeNow()
if (dto == nil) if (dto == nil)
{ {
if (debug) if (debug)
NSLog(@"no NSDateTimeOrdering - default to DMYH.\n"); {
NSLog(@"no NSDateTimeOrdering - default to DMYH.");
}
dto = @"DMYH"; dto = @"DMYH";
} }
length = [dto length]; length = [dto length];
if (length > 4) if (length > 4)
{ {
if (debug) if (debug)
NSLog(@"too many characters in NSDateTimeOrdering - truncating.\n"); {
NSLog(@"too many characters in NSDateTimeOrdering - truncating.");
}
length = 4; length = 4;
} }
@ -557,9 +562,13 @@ GSTimeNow()
if (num > 23) if (num > 23)
{ {
if (debug) if (debug)
NSLog(@"hour (%d) too large - ignored.\n", num); {
NSLog(@"hour (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -574,9 +583,13 @@ GSTimeNow()
if (num > 59) if (num > 59)
{ {
if (debug) if (debug)
NSLog(@"minute (%d) too large - ignored.\n", num); {
NSLog(@"minute (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -590,9 +603,13 @@ GSTimeNow()
if (num > 59) if (num > 59)
{ {
if (debug) if (debug)
NSLog(@"second (%d) too large - ignored.\n", num); {
NSLog(@"second (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -603,7 +620,9 @@ GSTimeNow()
else else
{ {
if (debug) if (debug)
NSLog(@"odd time spec - excess numbers ignored.\n"); {
NSLog(@"odd time spec - excess numbers ignored.");
}
} }
done = YES; done = YES;
@ -661,8 +680,10 @@ GSTimeNow()
default: default:
if (debug) if (debug)
NSLog(@"odd char (unicode %d) in NSDateTimeOrdering.\n", {
[dto characterAtIndex: dtoIndex]); NSLog(@"odd char (unicode %d) in NSDateTimeOrdering.",
[dto characterAtIndex: dtoIndex]);
}
dtoIndex++; dtoIndex++;
break; break;
} }
@ -670,7 +691,9 @@ GSTimeNow()
if (dtoIndex >= [dto length]) if (dtoIndex >= [dto length])
{ {
if (debug) if (debug)
NSLog(@"odd date specification - excess numbers ignored.\n"); {
NSLog(@"odd date specification - excess numbers ignored.");
}
break; break;
} }
switch ([dto characterAtIndex: dtoIndex]) switch ([dto characterAtIndex: dtoIndex])
@ -679,16 +702,24 @@ GSTimeNow()
if (num < 1) if (num < 1)
{ {
if (debug) if (debug)
NSLog(@"day (0) too small - ignored.\n"); {
NSLog(@"day (0) too small - ignored.");
}
else else
return nil; {
return nil;
}
} }
else if (num > 31) else if (num > 31)
{ {
if (debug) if (debug)
NSLog(@"day (%d) too large - ignored.\n", num); {
NSLog(@"day (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -700,16 +731,24 @@ GSTimeNow()
if (num < 1) if (num < 1)
{ {
if (debug) if (debug)
NSLog(@"month (0) too small - ignored.\n"); {
NSLog(@"month (0) too small - ignored.");
}
else else
return nil; {
return nil;
}
} }
else if (num > 12) else if (num > 12)
{ {
if (debug) if (debug)
NSLog(@"month (%d) too large - ignored.\n", num); {
NSLog(@"month (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -729,7 +768,9 @@ GSTimeNow()
Y = num + 1900; Y = num + 1900;
} }
if (debug) if (debug)
NSLog(@"year (%d) adjusted to %d.\n", num, Y); {
NSLog(@"year (%d) adjusted to %d.", num, Y);
}
} }
else else
{ {
@ -757,10 +798,13 @@ GSTimeNow()
if (num > 11) if (num > 11)
{ {
if (debug) if (debug)
NSLog(@"hour (%d) too large - ignored.\n", {
num); NSLog(@"hour (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
shouldIgnore = YES; shouldIgnore = YES;
} }
else if (mod == [ampm objectAtIndex: 1]) else if (mod == [ampm objectAtIndex: 1])
@ -774,9 +818,13 @@ GSTimeNow()
if (num > 23) if (num > 23)
{ {
if (debug) if (debug)
NSLog(@"hour (%d) too large - ignored.\n", num); {
NSLog(@"hour (%d) too large - ignored.", num);
}
else else
return nil; {
return nil;
}
} }
else else
{ {
@ -788,8 +836,10 @@ GSTimeNow()
} }
default: default:
if (debug) if (debug)
NSLog(@"unexpected char (unicode%d) in NSDateTimeOrdering.\n", {
[dto characterAtIndex: dtoIndex]); NSLog(@"unexpected char (unicode%d) in NSDateTimeOrdering.",
[dto characterAtIndex: dtoIndex]);
}
break; break;
} }
} }
@ -843,7 +893,9 @@ GSTimeNow()
if (hadWeekDay && [theDate dayOfWeek] != weekDay) if (hadWeekDay && [theDate dayOfWeek] != weekDay)
{ {
if (debug) if (debug)
NSLog(@"Date resulted in wrong day of week.\n"); {
NSLog(@"Date resulted in wrong day of week.");
}
return nil; return nil;
} }
if (theDate == nil) if (theDate == nil)

View file

@ -20,7 +20,7 @@
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
<title>NSLog class reference</title> <title>NSLog reference</title>
$Date$ $Revision$ $Date$ $Revision$
*/ */
@ -182,7 +182,15 @@ _NSLog_standard_printf_handler (NSString* message)
NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler; NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
/** /**
* Provides a standard logging facility via NSLogv(). * <p>Provides the standard OpenStep logging facility. For details see
* the lower level NSLogv() function (which this function uses).
* </p>
* <p>GNUstep provides powerful alternatives for logging ... see
* NSDebugLog(), NSWarnLog(), and GSPrintf() for example. We recommend
* the use of NSDebugLog() and its relatives for debug purposes, and
* GSPrintf() for general log messages, with NSLog() being reserved
* for reporting possible/likely errors.
* </p>
*/ */
void void
NSLog (NSString* format, ...) NSLog (NSString* format, ...)
@ -264,3 +272,61 @@ NSLogv (NSString* format, va_list args)
RELEASE(arp); RELEASE(arp);
} }
/**
* <p>Prints a message to fptr using the format string provided and any
* additional arguments. The format string is interpreted as by
* the NSString formatted initialisers, and understands the '%@' syntax
* for printing an object.
* </p>
* <p>The data is written to the file pointer in the default CString
* encoding if possible, as a UTF8 string otherwise.
* </p>
* <p>This function is recommended for printing general log messages.
* For debug messages use NSDebugLog() and friends. For error logging
* use NSLog(), and for warnings you might consider NSWarnLog().
*/
BOOL
GSPrintf (FILE *fptr, NSString* format, ...)
{
static Class stringClass = 0;
static NSStringEncoding enc;
CREATE_AUTORELEASE_POOL(arp);
va_list ap;
NSString *message;
NSData *data;
BOOL ok = NO;
if (stringClass == 0)
{
[gnustep_global_lock lock];
if (stringClass == 0)
{
stringClass = [NSString class];
enc = [stringClass defaultCStringEncoding];
}
[gnustep_global_lock unlock];
}
message = [stringClass allocWithZone: NSDefaultMallocZone()];
va_start (ap, format);
message = [message initWithFormat: format locale: nil arguments: ap];
va_end (ap);
data = [message dataUsingEncoding: enc];
if (data == nil)
{
data = [message dataUsingEncoding: NSUTF8StringEncoding];
}
RELEASE(message);
if (data != nil)
{
unsigned int length = [data length];
if (length == 0 || fwrite([data bytes], 1, length, fptr) == length)
{
ok = YES;
}
}
RELEASE(arp);
return ok;
}

View file

@ -25,6 +25,9 @@ main()
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"01-08-2002 00:00:00"]);
NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"31-08-2002 23:59:59"]);
if ([(NSDate*) [NSCalendarDate date] compare: if ([(NSDate*) [NSCalendarDate date] compare:
[NSCalendarDate dateWithString:@"Feb 2 00:00:00 2001" [NSCalendarDate dateWithString:@"Feb 2 00:00:00 2001"
calendarFormat:@"%b %d %H:%M:%S %Y"]] == NSOrderedDescending) { calendarFormat:@"%b %d %H:%M:%S %Y"]] == NSOrderedDescending) {

View file

@ -55,7 +55,7 @@ main(int argc, char** argv, char **env)
proc = [NSProcessInfo processInfo]; proc = [NSProcessInfo processInfo];
if (proc == nil) if (proc == nil)
{ {
NSLog(@"defaults: unable to get process information!\n"); GSPrintf(stderr, @"defaults: unable to get process information!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -178,7 +178,7 @@ main(int argc, char** argv, char **env)
i = 1; i = 1;
if ([args count] <= i) if ([args count] <= i)
{ {
NSLog(@"defaults: too few arguments supplied!\n"); GSPrintf(stderr, @"defaults: too few arguments supplied!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -190,7 +190,7 @@ main(int argc, char** argv, char **env)
} }
else else
{ {
NSLog(@"defaults: no name supplied for -u option!\n"); GSPrintf(stderr, @"defaults: no name supplied for -u option!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -206,7 +206,7 @@ main(int argc, char** argv, char **env)
} }
if (defs == nil) if (defs == nil)
{ {
NSLog(@"defaults: unable to access defaults database!\n"); GSPrintf(stderr, @"defaults: unable to access defaults database!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -215,7 +215,7 @@ main(int argc, char** argv, char **env)
if ([args count] <= i) if ([args count] <= i)
{ {
NSLog(@"defaults: too few arguments supplied!\n"); GSPrintf(stderr, @"defaults: too few arguments supplied!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -245,7 +245,7 @@ main(int argc, char** argv, char **env)
{ {
if ([args count] == ++i) if ([args count] == ++i)
{ {
NSLog(@"defaults: too few arguments supplied!\n"); GSPrintf(stderr, @"defaults: too few arguments supplied!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -528,7 +528,7 @@ main(int argc, char** argv, char **env)
owner = [args objectAtIndex: i++]; owner = [args objectAtIndex: i++];
if ([args count] <= i) if ([args count] <= i)
{ {
NSLog(@"defaults: no dictionary or key for write!\n"); GSPrintf(stderr, @"defaults: no dictionary or key for write!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -571,7 +571,8 @@ main(int argc, char** argv, char **env)
if (domain == nil || if (domain == nil ||
[domain isKindOfClass: [NSDictionary class]] == NO) [domain isKindOfClass: [NSDictionary class]] == NO)
{ {
NSLog(@"defaults write: domain is not a dictionary!\n"); GSPrintf(stderr,
@"defaults write: domain is not a dictionary!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -580,8 +581,9 @@ main(int argc, char** argv, char **env)
if ([defs synchronize] == NO) if ([defs synchronize] == NO)
{ {
NSLog(@"defaults: unable to write to defaults database - %s\n", GSPrintf(stderr,
strerror(errno)); @"defaults: unable to write to defaults database - %s\n",
strerror(errno));
} }
} }
else if ([[args objectAtIndex: i] isEqual: @"delete"]) else if ([[args objectAtIndex: i] isEqual: @"delete"])
@ -682,8 +684,9 @@ main(int argc, char** argv, char **env)
} }
if ([defs synchronize] == NO) if ([defs synchronize] == NO)
{ {
NSLog(@"defaults: unable to write to defaults database - %s\n", GSPrintf(stderr,
strerror(errno)); @"defaults: unable to write to defaults database - %s\n",
strerror(errno));
} }
} }
else if ([[args objectAtIndex: i] isEqual: @"domains"]) else if ([[args objectAtIndex: i] isEqual: @"domains"])
@ -700,7 +703,7 @@ main(int argc, char** argv, char **env)
{ {
if ([args count] == ++i) if ([args count] == ++i)
{ {
NSLog(@"defaults: no arguments for find!\n"); GSPrintf(stderr, @"defaults: no arguments for find!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -756,7 +759,7 @@ main(int argc, char** argv, char **env)
} }
else else
{ {
NSLog(@"defaults: unknown option supplied!\n"); GSPrintf(stderr, @"defaults: unknown option supplied!\n");
} }
[pool release]; [pool release];

View file

@ -59,8 +59,8 @@ main(int argc, char** argv, char **env)
if ([args count] < 2) if ([args count] < 2)
{ {
NSLog(@"Usage: %@ input-file [destination-file]", GSPrintf(stderr, @"Usage: %@ input-file [destination-file]\n",
[procinfo processName]); [procinfo processName]);
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -82,13 +82,15 @@ main(int argc, char** argv, char **env)
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Parsing '%@' - %@", sourceName, [localException reason]); GSPrintf(stderr, @"Parsing '%@' - %@\n", sourceName,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]]) if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
{ {
NSLog(@"The source property list must contain an NSDictionary."); GSPrintf(stderr,
@"The source property list must contain an NSDictionary.\n");
[pool release]; [pool release];
exit(1); exit(1);
} }
@ -146,9 +148,10 @@ main(int argc, char** argv, char **env)
} }
if ([[fileContents dataUsingEncoding: NSUTF8StringEncoding] if ([[fileContents dataUsingEncoding: NSUTF8StringEncoding]
writeToFile: destName atomically: YES] == NO) writeToFile: destName atomically: YES] == NO)
NSLog(@"Error writing property list to '%@'", destName); {
GSPrintf(stderr, @"Error writing property list to '%@'\n", destName);
}
[pool release]; [pool release];
exit(0); exit(0);
} }

View file

@ -55,7 +55,7 @@ main(int argc, char** argv, char **env)
if ([args count] <= 1) if ([args count] <= 1)
{ {
NSLog(@"No file names given to deserialize."); GSPrintf(stderr, @"No file names given to deserialize.\n");
} }
else else
{ {
@ -76,7 +76,7 @@ main(int argc, char** argv, char **env)
result = [NSDeserializer deserializePropertyListFromData: myData result = [NSDeserializer deserializePropertyListFromData: myData
mutableContainers: NO]; mutableContainers: NO];
if (result == nil) if (result == nil)
NSLog(@"Loading '%@' - nil property list", file); GSPrintf(stderr, @"Loading '%@' - nil property list\n", file);
else else
{ {
NSFileHandle *out; NSFileHandle *out;
@ -90,7 +90,8 @@ main(int argc, char** argv, char **env)
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Loading '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Loading '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }

View file

@ -55,8 +55,8 @@ main(int argc, char** argv, char **env)
if ([args count] < 3) if ([args count] < 3)
{ {
NSLog(@"Usage: %@ [destination-file] [input-file ...]", GSPrintf(stderr, @"Usage: %@ [destination-file] [input-file ...]\n",
[procinfo processName]); [procinfo processName]);
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -71,13 +71,15 @@ main(int argc, char** argv, char **env)
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Parsing '%@' - %@", destName, [localException reason]); GSPrintf(stderr, @"Parsing '%@' - %@\n", destName,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]]) if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
{ {
NSLog(@"The destination property list must contain an NSDictionary."); GSPrintf(stderr,
@"The destination property list must contain an NSDictionary.\n");
[pool release]; [pool release];
exit(1); exit(1);
} }
@ -100,7 +102,8 @@ main(int argc, char** argv, char **env)
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Parsing '%@' - %@", filename, [localException reason]); GSPrintf(stderr, @"Parsing '%@' - %@\n", filename,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
@ -110,7 +113,7 @@ main(int argc, char** argv, char **env)
} }
if (object == nil) if (object == nil)
NSLog(@"Parsing '%@' - nil property list", filename); GSPrintf(stderr, @"Parsing '%@' - nil property list\n", filename);
else if ([object isKindOfClass: [NSArray class]] == YES) else if ([object isKindOfClass: [NSArray class]] == YES)
[plist setObject: object forKey: key]; [plist setObject: object forKey: key];
else if ([object isKindOfClass: [NSData class]] == YES) else if ([object isKindOfClass: [NSData class]] == YES)
@ -120,12 +123,12 @@ main(int argc, char** argv, char **env)
else if ([object isKindOfClass: [NSString class]] == YES) else if ([object isKindOfClass: [NSString class]] == YES)
[plist setObject: object forKey: key]; [plist setObject: object forKey: key];
else else
NSLog(@"Parsing '%@' - unexpected class - %@", GSPrintf(stderr, @"Parsing '%@' - unexpected class - %@\n",
filename, [[object class] description]); filename, [[object class] description]);
} }
if ([plist writeToFile: destName atomically: YES] == NO) if ([plist writeToFile: destName atomically: YES] == NO)
NSLog(@"Error writing property list to '%@'", destName); GSPrintf(stderr, @"Error writing property list to '%@'\n", destName);
[pool release]; [pool release];
exit(0); exit(0);

View file

@ -53,7 +53,7 @@ main(int argc, char** argv, char **env)
if ([args count] <= 1) if ([args count] <= 1)
{ {
NSLog(@"No file names given to parse."); GSPrintf(stderr, @"No file names given to parse.\n");
} }
else else
{ {
@ -69,22 +69,23 @@ main(int argc, char** argv, char **env)
myString = [NSString stringWithContentsOfFile: file]; myString = [NSString stringWithContentsOfFile: file];
result = [myString propertyList]; result = [myString propertyList];
if (result == nil) if (result == nil)
NSLog(@"Parsing '%@' - nil property list", file); GSPrintf(stderr, @"Parsing '%@' - nil property list\n", file);
else if ([result isKindOfClass: [NSDictionary class]] == YES) else if ([result isKindOfClass: [NSDictionary class]] == YES)
NSLog(@"Parsing '%@' - a dictionary", file); GSPrintf(stderr, @"Parsing '%@' - a dictionary\n", file);
else if ([result isKindOfClass: [NSArray class]] == YES) else if ([result isKindOfClass: [NSArray class]] == YES)
NSLog(@"Parsing '%@' - an array", file); GSPrintf(stderr, @"Parsing '%@' - an array\n", file);
else if ([result isKindOfClass: [NSData class]] == YES) else if ([result isKindOfClass: [NSData class]] == YES)
NSLog(@"Parsing '%@' - a data object", file); GSPrintf(stderr, @"Parsing '%@' - a data object\n", file);
else if ([result isKindOfClass: [NSString class]] == YES) else if ([result isKindOfClass: [NSString class]] == YES)
NSLog(@"Parsing '%@' - a string", file); GSPrintf(stderr, @"Parsing '%@' - a string\n", file);
else else
NSLog(@"Parsing '%@' - unexpected class - %@", GSPrintf(stderr, @"Parsing '%@' - unexpected class - %@\n",
file, [[result class] description]); file, [[result class] description]);
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Parsing '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Parsing '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }

View file

@ -55,7 +55,7 @@ main(int argc, char** argv, char **env)
if ([args count] <= 1) if ([args count] <= 1)
{ {
NSLog(@"No file names given to serialize."); GSPrintf(stderr, @"No file names given to serialize.\n");
} }
else else
{ {
@ -72,7 +72,7 @@ main(int argc, char** argv, char **env)
myString = [NSString stringWithContentsOfFile: file]; myString = [NSString stringWithContentsOfFile: file];
result = [myString propertyList]; result = [myString propertyList];
if (result == nil) if (result == nil)
NSLog(@"Loading '%@' - nil property list", file); GSPrintf(stderr, @"Loading '%@' - nil property list\n", file);
else else
{ {
NSFileHandle *out; NSFileHandle *out;
@ -85,7 +85,8 @@ main(int argc, char** argv, char **env)
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Loading '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Loading '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }

View file

@ -45,19 +45,22 @@ convert_unicode(NSArray *args)
data = [NSData dataWithContentsOfFile: file]; data = [NSData dataWithContentsOfFile: file];
myString = [[NSString alloc] initWithData: data myString = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding]; encoding: NSUTF8StringEncoding];
AUTORELEASE(myString); AUTORELEASE(myString);
if ([myString length] == 0) if ([myString length] == 0)
myString = [[NSString alloc] initWithData: data {
encoding: [NSString defaultCStringEncoding]]; myString = [[NSString alloc] initWithData: data
encoding: [NSString defaultCStringEncoding]];
}
output = [[file lastPathComponent] output = [[file lastPathComponent]
stringByAppendingPathExtension: @"unicode"]; stringByAppendingPathExtension: @"unicode"];
data = [myString dataUsingEncoding: NSUnicodeStringEncoding]; data = [myString dataUsingEncoding: NSUnicodeStringEncoding];
[data writeToFile: output atomically: YES]; [data writeToFile: output atomically: YES];
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Converting '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Converting '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }
@ -81,13 +84,14 @@ convert_utf8(NSArray *args)
myString = [NSString stringWithContentsOfFile: file]; myString = [NSString stringWithContentsOfFile: file];
output = [[file lastPathComponent] output = [[file lastPathComponent]
stringByAppendingPathExtension: @"utf8"]; stringByAppendingPathExtension: @"utf8"];
data = [myString dataUsingEncoding: NSUTF8StringEncoding]; data = [myString dataUsingEncoding: NSUTF8StringEncoding];
[data writeToFile: output atomically: YES]; [data writeToFile: output atomically: YES];
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Converting '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Converting '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }
@ -109,7 +113,7 @@ main(int argc, char** argv, char **env)
proc = [NSProcessInfo processInfo]; proc = [NSProcessInfo processInfo];
if (proc == nil) if (proc == nil)
{ {
NSLog(@"defaults: unable to get process information!\n"); GSPrintf(stderr, @"defaults: unable to get process information!\n");
[pool release]; [pool release];
exit(0); exit(0);
} }
@ -145,16 +149,17 @@ main(int argc, char** argv, char **env)
myString = [NSString stringWithContentsOfFile: file]; myString = [NSString stringWithContentsOfFile: file];
result = [myString propertyListFromStringsFileFormat]; result = [myString propertyListFromStringsFileFormat];
if (result == nil) if (result == nil)
NSLog(@"Parsing '%@' - nil property list", file); GSPrintf(stderr, @"Parsing '%@' - nil property list\n", file);
else if ([result isKindOfClass: [NSDictionary class]] == YES) else if ([result isKindOfClass: [NSDictionary class]] == YES)
NSLog(@"Parsing '%@' - seems ok", file); GSPrintf(stderr, @"Parsing '%@' - seems ok\n", file);
else else
NSLog(@"Parsing '%@' - unexpected class - %@", GSPrintf(stderr, @"Parsing '%@' - unexpected class - %@\n",
file, [[result class] description]); file, [[result class] description]);
} }
NS_HANDLER NS_HANDLER
{ {
NSLog(@"Parsing '%@' - %@", file, [localException reason]); GSPrintf(stderr, @"Parsing '%@' - %@\n", file,
[localException reason]);
} }
NS_ENDHANDLER NS_ENDHANDLER
} }