diff --git a/ChangeLog b/ChangeLog index 2f27fdcab..14bb7ddc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +Fri Oct 17 09:16:36 1997 Adam Fedor + + * checks/Makefile.postamble: Add English.lproj dir to copy-dist. + + * src/NSCalendarDate.m (-descriptionWithCalendarFormat:locale): + Use VSPRINTF_LENGTH macro to return string length. + * src/NSData.m ([NSMutableDataMalloc -setCapacity:): Use realloc + instead of objc_realloc. + * src/NSHost.m (-_initWithHostEntry:): Use memcpy instead of + memmove. + * src/UnixFileHandle.m (getAddr): Remove uneeded htonl. + Changes from Richard Frith-Macdonald . + + * src/NSTimeZone.m: Reformat with better spacing. + ([NSTimeZone +initialize]): Find local time zone. + Changes from Yoo C. Chung . + Thu Oct 16 16:14:31 1997 Scott Christley * checks/Makefile: Add variables to create bundle example. diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index 7dcb13933..b63020682 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -612,9 +612,9 @@ static id long_month[12] = {@"January", case 'y': ++i; if (ycent) - k = sprintf(&(buf[j]), "%04d", yd); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%04d", yd)); else - k = sprintf(&(buf[j]), "%02d", (yd - 1900)); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", (yd - 1900))); j += k; break; @@ -629,12 +629,12 @@ static id long_month[12] = {@"January", { // +++ Translate to locale character string if (mname) - k = sprintf(&(buf[j]), "%s", [short_month[md-1] cString]); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [short_month[md-1] cString])); else - k = sprintf(&(buf[j]), "%s", [long_month[md-1] cString]); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [long_month[md-1] cString])); } else - k = sprintf(&(buf[j]), "%02d", md); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", md)); j += k; break; @@ -654,7 +654,7 @@ static id long_month[12] = {@"January", k = 0; } else - k = sprintf(&(buf[j]), "%02d", dd); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dd)); j += k; break; @@ -665,21 +665,21 @@ static id long_month[12] = {@"January", nhd = 12; // 12pm not 0pm case 'H': ++i; - k = sprintf(&(buf[j]), "%02d", nhd); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", nhd)); j += k; break; // is it the minute case 'M': ++i; - k = sprintf(&(buf[j]), "%02d", mnd); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", mnd)); j += k; break; // is it the second case 'S': ++i; - k = sprintf(&(buf[j]), "%02d", sd); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", sd)); j += k; break; @@ -687,17 +687,17 @@ static id long_month[12] = {@"January", case 'p': ++i; if (hd >= 12) - k = sprintf(&(buf[j]), "PM"); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "PM")); else - k = sprintf(&(buf[j]), "AM"); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "AM")); j += k; break; // is it the zone name case 'Z': ++i; - k = sprintf(&(buf[j]), "%s", - [[time_zone timeZoneAbbreviation] cStringNoCopy]); + k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", + [[time_zone timeZoneAbbreviation] cStringNoCopy])); j += k; break; diff --git a/Source/NSData.m b/Source/NSData.m index 80c6e4544..e3932f9cf 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -1626,7 +1626,12 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len) { if (size != capacity) { - void* tmp = objc_realloc(bytes, size); + void* tmp; + + if (bytes) + tmp = realloc(bytes, size); + else + tmp = malloc(size); if (tmp == 0) [NSException raise:NSMallocException diff --git a/Source/NSHost.m b/Source/NSHost.m index d3fd5fb2b..1cc3e20f7 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -109,7 +109,7 @@ static NSMutableDictionary *_hostCache = nil; for (i = 0, ptr = entry->h_addr_list[0]; ptr != NULL; i++, ptr = entry->h_addr_list[i]) { - memmove((void *)&in.s_addr, (const void *)ptr, + memcpy((void *)&in.s_addr, (const void *)ptr, entry->h_length); [addresses addObject:[NSString stringWithCString:inet_ntoa(in)]]; diff --git a/Source/NSPortCoder.m b/Source/NSPortCoder.m index 8e1eb8c37..987d36ebd 100644 --- a/Source/NSPortCoder.m +++ b/Source/NSPortCoder.m @@ -184,13 +184,14 @@ static BOOL debug_connected_coder = NO; - (void) _doEncodeBycopyObject: anObj { - BOOL old = _is_by_copy; - id obj; + BOOL old = _is_by_copy; + id obj; + Class cls; _is_by_copy = YES; - obj = [anObj classForPortCoder]; - [self encodeClass: obj]; obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self]; + cls = [obj classForPortCoder]; + [self encodeClass: cls]; [obj encodeWithCoder: (NSCoder*)self]; _is_by_copy = old; } diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index ad74ff346..55435a063 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -6,17 +6,17 @@ This file is part of the GNUstep Base Library. - This library is free software; you can redistribute it and/or + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ @@ -31,9 +31,9 @@ time and such for every entry in the dictionary. The local time zone can be specified with the user defaults - database (when it's properly implemented, that is), the TZ - environment variable, or the fallback local time zone, with the - ones listed first having precedence. + database, the TZ environment variable, the file LOCAL_TIME_FILE, or + the fallback local time zone, with the ones listed first having + precedence. Any time zone must be a file name in ZONES_DIR. @@ -46,13 +46,13 @@ #include #include #include - #include - #include +#include +#include #include #include #include #include - #include +#include #include #include #include @@ -85,6 +85,9 @@ whitespace, and each line must not be longer than 80 characters. */ #define REGIONS_FILE TIME_ZONE_DIR "regions" +/* Name of the file that contains the name of the local time zone. */ +#define LOCAL_TIME_FILE TIME_ZONE_DIR "localtime" + /* Directory that contains the actual time zones. */ #define ZONES_DIR TIME_ZONE_DIR "zones/" @@ -144,10 +147,10 @@ decode (const void *ptr) @interface NSInternalTimeTransition : NSObject - { +{ int trans_time; // When the transition occurs char detail_index; // Index of time zone detail - } +} - initWithTime: (int)aTime withIndex: (char)anIndex; - (int)transTime; @@ -164,19 +167,20 @@ decode (const void *ptr) - initWithName: (NSString*)aName withTransitions: (NSArray*)trans withDetails: (NSArray*)zoneDetails; - @end +@end @interface NSConcreteAbsoluteTimeZone : NSTimeZone { NSString *name; + id detail; int offset; // Offset from UTC in seconds. } + timeZoneWithOffset: (int)anOffset; - initWithOffset: (int)anOffset withName: (NSString*)aName; - @end +@end @interface NSConcreteTimeZoneDetail : NSTimeZoneDetail @@ -188,7 +192,7 @@ decode (const void *ptr) - initWithAbbrev: (NSString*)anAbbrev withOffset: (int)anOffset withDST: (BOOL)isDST; - @end +@end @implementation NSInternalAbbrevDict @@ -196,25 +200,25 @@ decode (const void *ptr) + allocWithZone: (NSZone*)zone { return NSAllocateObject(self, 0, zone); - } +} - init - { +{ return self; - } +} - (unsigned)count - { +{ return [[NSTimeZone abbreviationMap] count]; - } +} - (NSEnumerator*)keyEnumerator - { +{ return [[NSTimeZone abbreviationMap] keyEnumerator]; - } +} - (NSEnumerator*)objectEnumerator - { +{ /* FIXME: this is a memory hungry implementation */ id e, name, a; @@ -224,20 +228,20 @@ decode (const void *ptr) [a addObject: [[[NSTimeZone abbreviationMap] objectForKey: name] objectAtIndex: 0]]; return [a objectEnumerator]; - } +} - objectForKey: key - { +{ return [[[NSTimeZone abbreviationMap] objectForKey: key] objectAtIndex: 0]; - } +} - @end +@end @implementation NSInternalTimeTransition - (NSString*)description - { +{ return [NSString stringWithFormat: @"(trans: %d, idx: %d)", trans_time, (int)detail_index]; @@ -249,40 +253,40 @@ decode (const void *ptr) trans_time = aTime; detail_index = anIndex; return self; - } +} - (int)transTime - { +{ return trans_time; - } +} - (char)detailIndex - { +{ return detail_index; - } +} - @end +@end @implementation NSConcreteTimeZone - initWithName: (NSString*)aName withTransitions: (NSArray*)trans withDetails: (NSArray*)zoneDetails - { +{ [super init]; name = [aName retain]; transitions = [trans retain]; details = [zoneDetails retain]; return self; - } +} - (void)dealloc - { +{ [name release]; [transitions release]; [details release]; [super dealloc]; - } +} - (void)encodeWithCoder: aCoder { @@ -291,14 +295,14 @@ decode (const void *ptr) } - initWithDecoder: aDecoder - { +{ /* FIXME?: is this right? */ self = [super initWithCoder: aDecoder]; return (self = (id)[NSTimeZone timeZoneWithName: [aDecoder decodeObject]]); - } +} - (NSString*)description - { +{ return [NSString stringWithFormat: @"(trans: %@, details: %@)", [transitions description], [details description]]; } @@ -341,24 +345,22 @@ decode (const void *ptr) - (NSArray*)timeZoneDetailArray { return details; - } +} - (NSString*)timeZoneName - { +{ return name; - } +} - @end +@end @implementation NSConcreteAbsoluteTimeZone + timeZoneWithOffset: (int)anOffset - { +{ id newName, zone; - - newName = [NSString stringWithFormat: @"%d", anOffset]; zone = [zoneDictionary objectForKey: newName]; if (zone == nil) @@ -373,15 +375,18 @@ decode (const void *ptr) { [super init]; name = [aName retain]; + detail = [[NSConcreteTimeZoneDetail alloc] + initWithAbbrev: name withOffset: offset withDST: NO]; offset = anOffset; return self; - } +} - (void)dealloc - { +{ [name release]; + [detail release]; [super dealloc]; - } +} - (void)encodeWithCoder: aCoder { @@ -390,7 +395,7 @@ decode (const void *ptr) } - initWithCoder: aDecoder - { +{ self = [super initWithCoder: aDecoder]; name = [aDecoder decodeObject]; offset = [name intValue]; @@ -400,23 +405,21 @@ decode (const void *ptr) - (NSString*)description { return [NSString stringWithFormat: @"(offset: %d)", offset]; - } +} - (NSTimeZoneDetail*)timeZoneDetailForDate: (NSDate*)date - { - return [[[NSConcreteTimeZoneDetail alloc] - initWithAbbrev: name withOffset: offset withDST: NO] - autorelease]; +{ + return detail; } - (NSString*)timeZoneName { return name; - } +} - (NSArray*)timeZoneDetailArray - { - return [NSArray arrayWithObject: [self timeZoneDetailForDate: nil]]; +{ + return [NSArray arrayWithObject: detail]; } @end @@ -426,16 +429,16 @@ decode (const void *ptr) - initWithAbbrev: (NSString*)anAbbrev withOffset: (int)anOffset withDST: (BOOL)isDST - { +{ [super init]; abbrev = [anAbbrev retain]; offset = anOffset; is_dst = isDST; return self; - } +} - (void)dealloc - { +{ [abbrev release]; [super dealloc]; } @@ -455,16 +458,16 @@ decode (const void *ptr) [aDecoder decodeValueOfObjCType: @encode(int) at: &offset]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_dst]; return self; - } +} - (NSString*)description - { +{ return [NSString stringWithFormat: @"(abbrev: %@, offset: %d, is_dst: %d)", abbrev, offset, (int)is_dst]; - } +} - (BOOL)isDaylightSavingTimeZone - { +{ return is_dst; } @@ -476,7 +479,7 @@ decode (const void *ptr) - (int)timeZoneSecondsFromGMT { return offset; - } +} @end @@ -484,21 +487,33 @@ decode (const void *ptr) @implementation NSTimeZone + (void)initialize - { +{ if (self == [NSTimeZone class]) { id localZoneString = nil; zone_mutex = [NSLock new]; - /* Don't use this for now. */ -#if 0 localZoneString = [[NSUserDefaults standardUserDefaults] stringForKey: @LOCALDBKEY]; -#endif if (localZoneString == nil) + /* Try to get timezone from environment. */ localZoneString = [[[NSProcessInfo processInfo] environment] objectForKey: @"TZ"]; + if (localZoneString == nil) + /* Try to get timezone from LOCAL_TIME_FILE. */ + { + char zone_name[80]; + FILE *fp; + + fp = fopen(LOCAL_TIME_FILE, "r"); + if (fp != NULL) + { + fscanf(fp, "%79s", zone_name); + localZoneString = [NSString stringWithCString: zone_name]; + fclose(fp); + } + } if (localZoneString != nil) localTimeZone = [NSTimeZone timeZoneWithName: localZoneString]; else @@ -510,10 +525,8 @@ decode (const void *ptr) if (localTimeZone == nil) localTimeZone = [NSTimeZone timeZoneForSecondsFromGMT: 0]; - [localTimeZone retain]; - fake_abbrev_dict = [[NSInternalAbbrevDict alloc] init]; - zoneDictionary = [[NSMutableDictionary dictionary] retain]; + zoneDictionary = [[NSMutableDictionary alloc] init]; [zoneDictionary setObject: localTimeZone forKey: [localTimeZone timeZoneName]]; } @@ -653,7 +666,7 @@ decode (const void *ptr) NSZoneFree(NSDefaultMallocZone(), zone_abbrevs); /* Create time zone details. */ - detailsArray = [NSMutableArray array]; + detailsArray = [[NSMutableArray alloc] init]; for (i = 0; i < n_types; i++) [detailsArray addObject: [[NSConcreteTimeZoneDetail alloc] @@ -663,7 +676,7 @@ decode (const void *ptr) NSZoneFree(NSDefaultMallocZone(), abbrevsArray); NSZoneFree(NSDefaultMallocZone(), types); zone = [[NSConcreteTimeZone alloc] - initWithName: aTimeZoneName + initWithName: [aTimeZoneName copy] withTransitions: transArray withDetails: detailsArray]; [zoneDictionary setObject: zone forKey: aTimeZoneName]; @@ -713,12 +726,12 @@ decode (const void *ptr) return abbreviationDictionary; /* Read dictionary from file. */ - abbreviationDictionary = [[NSMutableDictionary dictionary] retain]; + abbreviationDictionary = [[NSMutableDictionary alloc] init]; file = fopen(ABBREV_DICT, "r"); if (file == NULL) [NSException raise: NSInternalInconsistencyException format: @"Failed to open time zone abbreviation dictionary"]; - while (fscanf(file, "%s %s", abbrev, name) == 2) + while (fscanf(file, "%79s %79s", abbrev, name) == 2) { id a, the_name, the_abbrev; @@ -727,7 +740,7 @@ decode (const void *ptr) a = [abbreviationDictionary objectForKey: the_abbrev]; if (a == nil) { - a = [NSMutableArray array]; + a = [[NSMutableArray alloc] init]; [abbreviationDictionary setObject: a forKey: the_abbrev]; } [a addObject: the_name]; @@ -735,15 +748,15 @@ decode (const void *ptr) fclose(file); return abbreviationDictionary; - } +} - (NSString*)timeZoneName - { +{ return [self subclassResponsibility: _cmd]; - } +} + (NSArray*)timeZoneArray - { +{ /* We create the array only when we need it to reduce overhead. */ static NSArray *regionsArray = nil; @@ -756,25 +769,25 @@ decode (const void *ptr) return regionsArray; for (i = 0; i < 24; i++) - temp_array[i] = [NSMutableArray array]; + temp_array[i] = [[NSMutableArray alloc] init]; file = fopen(REGIONS_FILE, "r"); if (file == NULL) [NSException raise: NSInternalInconsistencyException format: @"Failed to open regions array file"]; while (fscanf(file, "%d %s", &index, name) == 2) - [temp_array[index] addObject: [NSString stringWithCString: name]]; + [temp_array[index] addObject: [[NSString alloc] initWithCString: name]]; fclose(file); regionsArray = [[NSArray alloc] initWithObjects: temp_array count: 24]; return regionsArray; - } +} - (NSArray*)timeZoneDetailArray - { +{ return [self subclassResponsibility: _cmd]; - } +} - @end +@end @implementation NSTimeZoneDetail @@ -785,18 +798,26 @@ decode (const void *ptr) } - (BOOL)isDaylightSavingTimeZone - { +{ [self subclassResponsibility: _cmd]; return NO; - } +} - (NSString*)timeZoneAbbreviation - { +{ return [self subclassResponsibility: _cmd]; - } +} - (int)timeZoneSecondsFromGMT - { +{ [self subclassResponsibility: _cmd]; return 0; - } +} + +@end + + + + + + diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index c4b0beff9..3155b1708 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -90,7 +90,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) name = [host address]; #ifndef HAVE_INET_ATON - sin->sin_addr.s_addr = htonl(inet_addr([name cStringNoCopy])); + sin->sin_addr.s_addr = inet_addr([name cStringNoCopy]); #else if (inet_aton([name cStringNoCopy], &sin->sin_addr.s_addr) == 0) return NO; diff --git a/Testing/Makefile b/Testing/Makefile index 8914e3335..ecf0f4ed0 100644 --- a/Testing/Makefile +++ b/Testing/Makefile @@ -143,7 +143,7 @@ MyCategory.h \ SecondClass.h DIST_FILES = $(SRCS) $(HDRS) $(DYNAMIC_MFILES) $(DYNAMIC_HFILES) \ - Makefile Makefile.preamble Makefile.postamble NXStringTable.example + Makefile Makefile.preamble Makefile.postamble -include Makefile.preamble diff --git a/Testing/Makefile.postamble b/Testing/Makefile.postamble index 27e444bb0..4ce63375d 100644 --- a/Testing/Makefile.postamble +++ b/Testing/Makefile.postamble @@ -76,3 +76,5 @@ copy-dist: $(DIST_FILES) for f in $(DIST_FILES); do \ cp $$f ../snap/checks ; \ done + mkdir ../snap/checks/English.lproj + cp English.lproj/NXStringTable.example ../snap/checks/English.lproj