-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathyes.m
32 lines (28 loc) · 782 Bytes
/
yes.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
#import <Foundation/Foundation.h>
///////////////////////////////////
// How to build and execute
//
// Build:
// clang -framework Foundation -o yes yes.m
//
// option 1 - output 'yes'
// ./yes
//
// option 2 - output argument list
// ./yes argument_list
int main() {
NSArray* args = [[NSProcessInfo processInfo] arguments];
NSFileHandle* stdout = [NSFileHandle fileHandleWithStandardOutput];
NSData* data = nil;
if ([args count] == 1) {
data = [@"y\n" dataUsingEncoding: NSUTF8StringEncoding];
} else {
NSRange rn;
rn.location = 1;
rn.length = [args count] - 1;
data = [[NSString stringWithFormat:@"%@\n", [[args subarrayWithRange: rn] componentsJoinedByString: @" "]] dataUsingEncoding: NSUTF8StringEncoding];
}
while (true) {
[stdout writeData:data];
}
}