Removed old commented-out code.
[CleverRabbit.git] / transliterate.m
blobc08725b20ce1777dc39b2b5330605ffe3b8bb51f
1 //
2 //  transliterate.m
3 //   (CleverRabbit.app)
4 //
5 //   Copyright (c) 2008 A. Karl Keller (http://karlk.net)
6 //
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";
23 // Test flag
24 //BOOL generateMetaStrings = YES;
25 BOOL generateMetaStrings = NO;
27 int processArguments(int argc, char *argv[]) 
29         NSMutableArray * arguments = [NSMutableArray new];
30     int i = 0;
31     while(argv[i] != nil) {
32         [arguments addObject:[NSString stringWithCString:argv[i++]]];
33     }
34     
35     if([arguments count] < 4) {
36         NSLog(@"Not enough arguments.");
37         return 0;
38     }
39     
40     NSString *inputDefinitionPath = [arguments objectAtIndex:1];
41     NSString *scriptDefinitionPath = [arguments objectAtIndex:2];
42     NSString *encodingDefinitionPath = [arguments objectAtIndex:3];
43     
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];
49     
50     if(!RTKSharedConvertor)
51         RTKSharedConvertor = [[RTKConvertor alloc] init];
52     if(!RTKSharedDatabase)
53         RTKSharedDatabase = [RTKSharedConvertor generalDatabase];
54     
55     while(1) {
56         NSData *inputData = [standardInput availableData]; // TODO: Fix for buffer length. 
57         if([inputData length] == 0)
58             continue;
60         NSString *inputString = [NSString stringWithCString:(const char *)[inputData bytes]  
61                                                      length:[inputData length]];
62         
63         NSDictionary * output = [RTKSharedConvertor convertString:inputString
64                                                       inputSystem:inputDefinitionPath
65                                                      scriptSystem:scriptDefinitionPath
66                                                        fontSystem:encodingDefinitionPath
67                                                   withMetaStrings:generateMetaStrings
68                                               checkForPunctuation:NO];
69         
70         if(generateMetaStrings)
71             NSLog(@"%@", [output description]);
72         
73         NSString *outputString = [output objectForKey:@"RTKFont"];
74         
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]];
78         
79         [standardOutput writeData:outputData];
80         [standardOutput writeData:[NSData dataWithBytes:"\n" length:1]];
81     }
82     
83     return 0;   
86 int main(int argc, char *argv[])
88     NSAutoreleasePool * pool = [NSAutoreleasePool new];
89     
90     int result = processArguments(argc, argv);
91     
92     [pool release];
93     
94     return result;