5 // Copyright (c) 2008 A. Karl Keller (http://karlk.net)
7 // This code is open-source, free software, made available without warranty under
8 // the terms of the GNU General Public License, either version 2 or later (see
9 // http://www.gnu.org/licenses/gpl.html or included copy); as such, it may be
10 // redistributed and/or modified in accordance with that document.
13 #import <Cocoa/Cocoa.h>
14 #import "RTKConvertor.h"
15 #import "RTKStringCategory.h"
17 // This is likely temporary, a nasty relic of the project
18 // that the transcription code was borrowed from
19 id RTKSharedConvertor = nil;
20 id RTKSharedDatabase = nil;
21 id RTKClass = @"RTKClass";
24 //BOOL generateMetaStrings = YES;
25 BOOL generateMetaStrings = NO;
27 int processArguments(int argc, char *argv[])
29 NSMutableArray * arguments = [NSMutableArray new];
31 while(argv[i] != nil) {
32 [arguments addObject:[NSString stringWithCString:argv[i++]]];
35 if([arguments count] < 4) {
36 NSLog(@"Not enough arguments.");
40 NSString *inputDefinitionPath = [arguments objectAtIndex:1];
41 NSString *scriptDefinitionPath = [arguments objectAtIndex:2];
42 NSString *encodingDefinitionPath = [arguments objectAtIndex:3];
44 /* NSLog([NSString stringWithFormat:@"\nInput Definition Path: %@\nScript Definition Path: %@\nEncoding Definition Path: %@",
45 inputDefinitionPath, scriptDefinitionPath, encodingDefinitionPath]);
47 NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput];
48 NSFileHandle *standardOutput = [NSFileHandle fileHandleWithStandardOutput];
50 if(!RTKSharedConvertor)
51 RTKSharedConvertor = [[RTKConvertor alloc] init];
52 if(!RTKSharedDatabase)
53 RTKSharedDatabase = [RTKSharedConvertor generalDatabase];
56 NSData *inputData = [standardInput availableData]; // TODO: Fix for buffer length.
57 if([inputData length] == 0)
60 NSString *inputString = [NSString stringWithCString:(const char *)[inputData bytes]
61 length:[inputData length]];
63 NSDictionary * output = [RTKSharedConvertor convertString:inputString
64 inputSystem:inputDefinitionPath
65 scriptSystem:scriptDefinitionPath
66 fontSystem:encodingDefinitionPath
67 withMetaStrings:generateMetaStrings
68 checkForPunctuation:NO];
70 if(generateMetaStrings)
71 NSLog(@"%@", [output description]);
73 NSString *outputString = [output objectForKey:@"RTKFont"];
75 // TODO: figure out why I need 0xefbbbf at the start of each line, rather than just top of file
76 NSData *outputData = [outputString utf8Data];
77 // [NSData dataWithBytes:[outputString cString] length:[outputString length]];
79 [standardOutput writeData:outputData];
80 [standardOutput writeData:[NSData dataWithBytes:"\n" length:1]];
86 int main(int argc, char *argv[])
88 NSAutoreleasePool * pool = [NSAutoreleasePool new];
90 int result = processArguments(argc, argv);