Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (36 sloc) 1.431 kB
ee99867 @ccgus oh geeze
authored
1 #import <Cocoa/Cocoa.h>
2 #import "JSTListener.h"
3 #import "JSTalk.h"
4
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
5
6 @interface JSCErrorHandler : NSObject {
7
8 }
9 @end
10
11 @implementation JSCErrorHandler
12
13 - (void) JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
14
15 NSLog(@"Error line %d, %@", lineNumber, error);
16
17 exit(1);
18 }
19
20
21 @end
22
23
24
ee99867 @ccgus oh geeze
authored
25 int main(int argc, char *argv[]) {
26
27 if (argc < 2) {
28 printf("usage: %s <path to file>\n", argv[0]);
29 return 1;
30 }
31
32 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
33
34 NSString *s = [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:argv[1]]
35 encoding:NSUTF8StringEncoding
36 error:nil];
37
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
38 JSCErrorHandler *eh = [[[JSCErrorHandler alloc] init] autorelease];
39
ee99867 @ccgus oh geeze
authored
40 JSTalk *t = [[[JSTalk alloc] init] autorelease];
41
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
42 JSCocoaController *jsController = [t jsController];
43 jsController.delegate = eh;
44
45 [t.env setObject:[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] forKey:@"scriptURL"];
46
ee99867 @ccgus oh geeze
authored
47 if ([s hasPrefix:@"#!"]) {
48
49 NSRange r = [s rangeOfString:@"\n"];
50
51 if (r.location != NSNotFound) {
52 s = [s substringFromIndex:r.location];
53 }
54 }
55
56 [t executeString:s];
57
58 [pool release];
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
59
60 return 0;
ee99867 @ccgus oh geeze
authored
61 }
Something went wrong with that request. Please try again.