Skip to content

Commit

Permalink
My OSX-fu is weak
Browse files Browse the repository at this point in the history
  • Loading branch information
rickosborne committed Apr 25, 2012
1 parent d9113fa commit 2c247a6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions wow/WoWLogSplit/WoWLogSplit.xcodeproj/project.pbxproj
Expand Up @@ -391,6 +391,7 @@
B973D77D151505A600401595 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_ENABLE_OBJC_GC = required;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "WoWLogSplit/WoWLogSplit-Prefix.pch";
INFOPLIST_FILE = "WoWLogSplit/WoWLogSplit-Info.plist";
Expand All @@ -402,6 +403,7 @@
B973D77E151505A600401595 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_ENABLE_OBJC_GC = required;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "WoWLogSplit/WoWLogSplit-Prefix.pch";
INFOPLIST_FILE = "WoWLogSplit/WoWLogSplit-Info.plist";
Expand Down
1 change: 1 addition & 0 deletions wow/WoWLogSplit/WoWLogSplit/FileReader.h
Expand Up @@ -19,6 +19,7 @@
unsigned long long m_totalFileLength; /**< Total number of bytes in file. */
NSString* m_lineDelimiter; /**< Character for line break or page break. */
NSUInteger m_chunkSize; /**< Standard block size. */
NSUInteger m_delimiterCount;
}

- (id)initWithFilePath:(NSString*)filePath;
Expand Down
15 changes: 12 additions & 3 deletions wow/WoWLogSplit/WoWLogSplit/FileReader.m
Expand Up @@ -49,7 +49,8 @@ - (id)initWithFilePath:(NSString*)filePath {
[m_fileHandle seekToEndOfFile];
m_totalFileLength = [m_fileHandle offsetInFile];
m_currentInset = m_totalFileLength;
m_prevDelimiterRange = NSMakeRange(m_currentInset, 1);
m_prevDelimiterRange = NSMakeRange(m_currentInset, 1);
m_delimiterCount = 0;

NSLog(@"%qu characters in %@", m_totalFileLength, [filePath lastPathComponent]); /* DEBUG LOG */
}
Expand All @@ -69,7 +70,9 @@ - (NSString*)readLine {
return nil;
}

NSData* newLineData = [m_lineDelimiter dataUsingEncoding:NSUTF8StringEncoding];
static NSData* newLineData = nil;
if (!newLineData)
newLineData = [m_lineDelimiter dataUsingEncoding:NSUTF8StringEncoding];
[m_fileHandle seekToFileOffset:m_currentOffset];
NSMutableData* currentData = [[NSMutableData alloc] init];
BOOL shouldReadMore = YES;
Expand All @@ -84,13 +87,19 @@ - (NSString*)readLine {
if (newLineRange.location != NSNotFound) {
// Include the length so we can include the delimiter in the string.
NSRange subDataRange = NSMakeRange(0, newLineRange.location + [newLineData length]);
NSData *subchunk = chunk;
chunk = [chunk subdataWithRange:subDataRange];
[subchunk release], subchunk = nil;
shouldReadMore = NO;
m_delimiterCount++;
m_chunkSize = MAX(m_chunkSize, MAX(10, 1 + ((m_currentOffset + [chunk length] + 2) / m_delimiterCount)));
if ((m_delimiterCount % 1000) == 0)
NSLog(@"chunkSize:%lu", m_chunkSize);
}
[currentData appendData:chunk];
m_currentOffset += [chunk length];
[chunk release], chunk = nil;
}

NSString* line = [currentData stringValueWithEncoding:NSUTF8StringEncoding];
// finished with data
[currentData release], currentData = nil;
Expand Down
7 changes: 7 additions & 0 deletions wow/WoWLogSplit/WoWLogSplit/WLSAppDelegate.m
Expand Up @@ -64,10 +64,17 @@ - (IBAction)splitLogFile:(id)sender {
NSLog(@"File:%@ (%@)", fileName, datePart);
[[NSFileManager defaultManager] createFileAtPath:fileName contents:nil attributes:nil];
out = [NSFileHandle fileHandleForWritingAtPath:fileName];
datePart = nil;
fileName = nil;
}
[out writeData:[line dataUsingEncoding:NSUTF8StringEncoding]];
[line release], line = nil;
[data release], data = nil;
}
[out closeFile];
out = nil;
[reader release], reader = nil;
[dateFormat release], dateFormat = nil;
}

- (IBAction)archiveSplitLogs:(id)sender {
Expand Down
2 changes: 1 addition & 1 deletion wow/WoWLogSplit/WoWLogSplit/WoWLogLine.m
Expand Up @@ -79,7 +79,7 @@ + (id) fromString:(NSString *) string
NSLog(@"Bad time, h:%d m:%d s:%d ms:%d parts:%@", timeHour, timeMinute, timeSecond, timeMS, timeParts);
return nil;
}
WoWLogLine *line = [[WoWLogLine alloc] init];
WoWLogLine *line = [[[WoWLogLine alloc] init] autorelease];
NSDateComponents *dc = [WoWLogLine dateComponents];
[dc setMonth:dateMonth];
[dc setDay:dateDay];
Expand Down

0 comments on commit 2c247a6

Please sign in to comment.