forked from erkyrath/Inform7-IDE-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFRuntimeErrorParser.m
129 lines (99 loc) · 3.41 KB
/
IFRuntimeErrorParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// IFRuntimeErrorParser.m
// Inform-xc2
//
// Created by Andrew Hunter on 10/10/2005.
// Copyright 2005 Andrew Hunter. All rights reserved.
//
#import "IFRuntimeErrorParser.h"
@implementation IFRuntimeErrorParser
- (id) init {
self = [super init];
if (self) {
accumulator = [[NSMutableString alloc] init];
}
return self;
}
- (void) dealloc {
[accumulator release];
[super dealloc];
}
- (void) setDelegate: (id) newDelegate {
delegate = newDelegate;
}
- (void) outputText: (NSString*) outputText {
// Scan for '*** Run-time problem XX' at the beginning of a line: this indicates that runtime problem XX
// has occured (and we should probably be showing file RTP_XX.html)
NSString* runtimeIndicator = @"*** Run-time problem ";
NSString* problemType = nil;
int len = [outputText length];
int pos;
int indicatorLen = [runtimeIndicator length];
for (pos = 0; pos<len-indicatorLen-1; pos++) {
unichar chr = [outputText characterAtIndex: pos];
if (chr == '\n') {
// Characters following pos might be the run-time problem indicator
NSString* mightMatch = [outputText substringWithRange: NSMakeRange(pos+1, indicatorLen)];
if ([mightMatch isEqualToString: runtimeIndicator]) {
// We've got a match for the string: find the problem identifier
pos += indicatorLen+1;
int startOfId = pos;
for (;pos<len; pos++) {
chr = [outputText characterAtIndex: pos];
if (chr == ' ' || chr == '\t' || chr == '\n' || chr == '\r' || chr == ':') {
// We've found the end of the ID
break;
}
// Copy the problem type
problemType = [outputText substringWithRange: NSMakeRange(startOfId, pos-startOfId+1)];
}
break;
}
}
}
if (problemType != nil) {
// A problem was encountered: inform the delegate
if (delegate && [delegate respondsToSelector: @selector(runtimeError:)]) {
[delegate runtimeError: problemType];
}
}
}
// Notifications about events that have occured in the view (when using this automation object for output)
- (void) receivedCharacters: (NSString*) characters // Text has arrived at the specified text buffer window (from the game)
window: (int) windowNumber
fromView: (GlkView*) view {
unichar* chrs = malloc(sizeof(unichar)*[characters length]);
[characters getCharacters: chrs];
int start = 0;
int x;
for (x=0; x<[characters length]; x++) {
if (chrs[x] == '\n') {
[accumulator appendString: [NSString stringWithCharacters: chrs + start
length: x - start]];
[self outputText: accumulator];
[accumulator release];
accumulator = [[NSMutableString alloc] init];
start = x;
}
}
[accumulator appendString: [NSString stringWithCharacters: chrs + start
length: x - start]];
[accumulator appendString: characters];
[self outputText: characters];
}
- (void) userTyped: (NSString*) userInput // The user has typed the specified string into the specified window (which is any window that is waiting for input)
window: (int) windowNumber
lineInput: (BOOL) isLineInput
fromView: (GlkView*) view {
}
- (void) userClickedAtXPos: (int) xpos // The user has clicked at a specified position in the given window
ypos: (int) ypos
window: (int) windowNumber
fromView: (GlkView*) view {
}
- (void) viewWaiting: (GlkView*) view {
}
// Using this automation object for input
- (void) viewIsWaitingForInput: (GlkView*) view {
}
@end