Skip to content
This repository
Browse code

Add missing braces.

Also fix the weird SPInvocationGrabber initializer.
  • Loading branch information...
commit bb3d8d6f818c4cb4af7133946600e6da24b9dc50 1 parent b4fb01c
martinh authored March 10, 2012
20  app/NSObject+SPInvocationGrabbing.h
@@ -9,22 +9,22 @@
9 9
     BOOL onMainAfterForward;
10 10
     BOOL waitUntilDone;
11 11
 }
12  
--(id)initWithObject:(id)obj;
13  
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
  12
+- (id)initWithObject:(id)obj;
  13
+- (id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
14 14
 @property(nonatomic, readonly, retain, nonatomic) id object;
15 15
 @property(nonatomic, readonly, retain, nonatomic) NSInvocation *invocation;
16 16
 @property(nonatomic) BOOL backgroundAfterForward;
17 17
 @property(nonatomic) BOOL onMainAfterForward;
18 18
 @property(nonatomic) BOOL waitUntilDone;
19  
--(void)invoke; // will release object and invocation
20  
--(void)printBacktrace;
21  
--(void)saveBacktrace;
  19
+- (void)invoke; // will release object and invocation
  20
+- (void)printBacktrace;
  21
+- (void)saveBacktrace;
22 22
 @end
23 23
 
24 24
 @interface NSObject (SPInvocationGrabbing)
25  
--(id)grab;
26  
--(id)invokeAfter:(NSTimeInterval)delta;
27  
--(id)nextRunloop;
28  
--(id)inBackground;
29  
--(id)onMainAsync:(BOOL)async;
  25
+- (id)grab;
  26
+- (id)invokeAfter:(NSTimeInterval)delta;
  27
+- (id)nextRunloop;
  28
+- (id)inBackground;
  29
+- (id)onMainAsync:(BOOL)async;
30 30
 @end
33  app/NSObject+SPInvocationGrabbing.m
@@ -19,18 +19,18 @@ - (id)initWithObject:(id)obj
19 19
 	return [self initWithObject:obj stacktraceSaving:NO];
20 20
 }
21 21
 
22  
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack
  22
+- (id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack
23 23
 {
24  
-	self.object = obj;
25  
-
26  
-	if (saveStack) {
27  
-		[self saveBacktrace];
  24
+	if ((self = [super init]) != nil) {
  25
+		_object = [obj retain];
  26
+		if (saveStack) {
  27
+			[self saveBacktrace];
  28
+		}
28 29
 	}
29  
-
30 30
 	return self;
31 31
 }
32 32
 
33  
--(void)dealloc
  33
+- (void)dealloc
34 34
 {
35 35
 	free(frameStrings);
36 36
 	[_object release];
@@ -66,15 +66,15 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation
66 66
 - (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector
67 67
 {
68 68
 	NSMethodSignature *signature = [super methodSignatureForSelector:inSelector];
69  
-	if (signature == NULL)
  69
+	if (signature == NULL) {
70 70
 		signature = [_object methodSignatureForSelector:inSelector];
  71
+	}
71 72
     
72 73
 	return signature;
73 74
 }
74 75
 
75 76
 - (void)invoke
76 77
 {
77  
-
78 78
 	@try {
79 79
 		[_invocation invoke];
80 80
 	}
@@ -89,14 +89,14 @@ - (void)invoke
89 89
 	self.object = nil;
90 90
 }
91 91
 
92  
--(void)saveBacktrace
  92
+- (void)saveBacktrace
93 93
 {
94 94
 	void *backtraceFrames[128];
95 95
 	frameCount = backtrace(&backtraceFrames[0], 128);
96 96
 	frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
97 97
 }
98 98
 
99  
--(void)printBacktrace
  99
+- (void)printBacktrace
100 100
 {
101 101
 	for (int x = 3; x < frameCount; x++) {
102 102
 		if (frameStrings[x] == NULL) {
@@ -105,15 +105,18 @@ -(void)printBacktrace
105 105
 		printf("%s\n", frameStrings[x]);
106 106
 	}
107 107
 }
  108
+
108 109
 @end
109 110
 
  111
+
110 112
 @implementation NSObject (SPInvocationGrabbing)
111  
--(id)grab
  113
+
  114
+- (id)grab
112 115
 {
113 116
 	return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease];
114 117
 }
115 118
 
116  
--(id)invokeAfter:(NSTimeInterval)delta
  119
+- (id)invokeAfter:(NSTimeInterval)delta
117 120
 {
118 121
 	id grabber = [self grab];
119 122
 	[NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO];
@@ -125,14 +128,14 @@ - (id)nextRunloop
125 128
 	return [self invokeAfter:0];
126 129
 }
127 130
 
128  
--(id)inBackground
  131
+- (id)inBackground
129 132
 {
130 133
 	SPInvocationGrabber *grabber = [self grab];
131 134
 	grabber.backgroundAfterForward = YES;
132 135
 	return grabber;
133 136
 }
134 137
 
135  
--(id)onMainAsync:(BOOL)async
  138
+- (id)onMainAsync:(BOOL)async
136 139
 {
137 140
 	SPInvocationGrabber *grabber = [self grab];
138 141
 	grabber.onMainAfterForward = YES;
59  app/SFTPConnection.m
@@ -166,10 +166,11 @@ - (void)response:(SFTPMessage *)msg
166 166
 		DEBUG(@"got wait response %@ for %@", msg, _waitRequest);
167 167
 	}
168 168
 
169  
-	if (_responseCallback)
  169
+	if (_responseCallback) {
170 170
 		_responseCallback(msg);
171  
-	else
  171
+	} else {
172 172
 		DEBUG(@"NULL response callback for request id %u", _requestId);
  173
+	}
173 174
 	_finished = YES;
174 175
 
175 176
 	if (gotWaitResponse) {
@@ -1284,15 +1285,16 @@ - (SFTPRequest *)contentsOfDirectoryAtURL:(NSURL *)aURL
1284 1285
 					openRequest.subRequest = [self closeHandle:handle
1285 1286
 									onResponse:^(NSError *error) {
1286 1287
 						openRequest.subRequest = nil;
1287  
-						if (error)
  1288
+						if (error) {
1288 1289
 							originalCallback(nil, error);
1289  
-						else {
  1290
+						} else {
1290 1291
 							openRequest.subRequest = [self resolveSymlinksInEntries:entries
1291 1292
 												  relativeToURL:aURL
1292 1293
 												   onCompletion:^(NSArray *resolvedEntries, NSError *error) {
1293 1294
 								openRequest.subRequest = nil;
1294  
-								if (error)
  1295
+								if (error) {
1295 1296
 									resolvedEntries = nil;
  1297
+								}
1296 1298
 								originalCallback(resolvedEntries, error);
1297 1299
 							}];
1298 1300
 						}
@@ -1351,10 +1353,11 @@ - (SFTPRequest *)createDirectory:(NSString *)path
1351 1353
 	SFTPRequest *req = [self addRequest:SSH2_FXP_MKDIR format:"sa", path, [NSDictionary dictionary]];
1352 1354
 	req.onResponse = ^(SFTPMessage *msg) {
1353 1355
 		NSError *error;
1354  
-		if (![msg expectStatus:SSH2_FX_OK error:&error])
  1356
+		if (![msg expectStatus:SSH2_FX_OK error:&error]) {
1355 1357
 			originalCallback(error);
1356  
-		else
  1358
+		} else {
1357 1359
 			originalCallback(nil);
  1360
+		}
1358 1361
 	};
1359 1362
 	req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
1360 1363
 	return req;
@@ -1406,10 +1409,11 @@ - (SFTPRequest *)openFile:(NSString *)path
1406 1409
 	       onResponse:(void (^)(NSData *handle, NSError *error))responseCallback
1407 1410
 {
1408 1411
 	uint32_t mode;
1409  
-	if (isWrite)
  1412
+	if (isWrite) {
1410 1413
 		mode = SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_EXCL;
1411  
-	else
  1414
+	} else {
1412 1415
 		mode = SSH2_FXF_READ;
  1416
+	}
1413 1417
 
1414 1418
 	void (^originalCallback)(NSData *, NSError *) = [[responseCallback copy] autorelease];
1415 1419
 
@@ -1523,20 +1527,24 @@ - (SFTPRequest *)dataWithContentsOfURL:(NSURL *)url
1523 1527
 				}
1524 1528
 
1525 1529
 				DEBUG(@"got %lu bytes of data, requested %u", [data length], len);
1526  
-				if (dataCallback)
  1530
+				if (dataCallback) {
1527 1531
 					dataCallback(data);
  1532
+				}
1528 1533
 				offset += [data length];
1529  
-				if (fileSize > 0)
  1534
+				if (fileSize > 0) {
1530 1535
 					statRequest.progress = (CGFloat)offset / (CGFloat)fileSize;
1531  
-				else
  1536
+				} else {
1532 1537
 					statRequest.progress = -1.0; /* unknown/indefinite progress */
  1538
+				}
1533 1539
 
1534 1540
 				/* Data callback may have cancelled us. */
1535  
-				if (statRequest.cancelled)
  1541
+				if (statRequest.cancelled) {
1536 1542
 					return;
  1543
+				}
1537 1544
 
1538  
-				if ([data length] < len)
  1545
+				if ([data length] < len) {
1539 1546
 					len = (uint32_t)[data length];
  1547
+				}
1540 1548
 
1541 1549
 				/* Dispatch next read request. */
1542 1550
 				for (int i = 0; i < 1/*max_req*/; i++) {
@@ -1580,10 +1588,11 @@ - (SFTPRequest *)setAttributes:(NSDictionary *)attributes
1580 1588
 	SFTPRequest *req = [self addRequest:SSH2_FXP_FSETSTAT format:"da", handle, attributes];
1581 1589
 	req.onResponse = ^(SFTPMessage *msg) {
1582 1590
 		NSError *error;
1583  
-		if (![msg expectStatus:SSH2_FX_OK error:&error])
  1591
+		if (![msg expectStatus:SSH2_FX_OK error:&error]) {
1584 1592
 			originalCallback(error);
1585  
-		else
  1593
+		} else {
1586 1594
 			originalCallback(nil);
  1595
+		}
1587 1596
 	};
1588 1597
 	req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
1589 1598
 	return req;
@@ -1651,8 +1660,9 @@ - (SFTPRequest *)uploadData:(NSData *)data
1651 1660
 
1652 1661
 			/* Dispatch next read request. */
1653 1662
 			uint32_t len = _transfer_buflen;
1654  
-			if (offset + len > [data length])
  1663
+			if (offset + len > [data length]) {
1655 1664
 				len = (uint32_t)([data length] - offset);
  1665
+			}
1656 1666
 			NSData *chunk = [NSData dataWithBytesNoCopy:(void *)[data bytes] + offset length:len freeWhenDone:NO];
1657 1667
 			DEBUG(@"writing %u bytes at offset %lu", len, offset);
1658 1668
 			SFTPRequest *req = [self addRequest:SSH2_FXP_WRITE format:"dqd", handle, offset, chunk];
@@ -1665,8 +1675,9 @@ - (SFTPRequest *)uploadData:(NSData *)data
1665 1675
 
1666 1676
 		/* Dispatch first read request. */
1667 1677
 		uint32_t len = _transfer_buflen;
1668  
-		if (offset + len > [data length])
  1678
+		if (offset + len > [data length]) {
1669 1679
 			len = (uint32_t)([data length] - offset);
  1680
+		}
1670 1681
 		NSData *chunk = [NSData dataWithBytesNoCopy:(void *)[data bytes] + offset length:len freeWhenDone:NO];
1671 1682
 		DEBUG(@"writing %u bytes at offset %lu", len, offset);
1672 1683
 		SFTPRequest *req = [self addRequest:SSH2_FXP_WRITE format:"dqd", handle, offset, chunk];
@@ -1688,10 +1699,11 @@ - (SFTPRequest *)removeItemAtPath:(NSString *)path
1688 1699
 	SFTPRequest *req = [self addRequest:SSH2_FXP_REMOVE format:"s", path];
1689 1700
 	req.onResponse = ^(SFTPMessage *msg) {
1690 1701
 		NSError *error;
1691  
-		if (![msg expectStatus:SSH2_FX_OK error:&error])
  1702
+		if (![msg expectStatus:SSH2_FX_OK error:&error]) {
1692 1703
 			originalCallback(error);
1693  
-		else
  1704
+		} else {
1694 1705
 			originalCallback(nil);
  1706
+		}
1695 1707
 	};
1696 1708
 	req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
1697 1709
 	return req;
@@ -1708,10 +1720,12 @@ - (SFTPRequest *)removeItemsAtURLs:(NSArray *)urls
1708 1720
 	for (NSURL *url in mutableURLs) {
1709 1721
 		req = [self removeItemAtPath:[url path] onResponse:^(NSError *error) {
1710 1722
 			[mutableURLs removeObject:url];
1711  
-			if (error)
  1723
+			if (error) {
1712 1724
 				originalCallback(error);
1713  
-			if ([mutableURLs count] == 0)
  1725
+			}
  1726
+			if ([mutableURLs count] == 0) {
1714 1727
 				originalCallback(nil);
  1728
+			}
1715 1729
 		}];
1716 1730
 	}
1717 1731
 
@@ -1905,4 +1919,3 @@ - (NSString *)stderr
1905 1919
 }
1906 1920
 
1907 1921
 @end
1908  
-
23  app/ViURLManager.m
@@ -289,8 +289,9 @@ - (BOOL)shouldRescanDirectoryAtURL:(NSURL *)aURL
289 289
 		ViWindowController *wincon = [window windowController];
290 290
 		if ([wincon respondsToSelector:@selector(explorer)]) {
291 291
 			ViFileExplorer *explorer = [wincon explorer];
292  
-			if ([explorer displaysURL:aURL])
  292
+			if ([explorer displaysURL:aURL]) {
293 293
 				return YES;
  294
+			}
294 295
 		}
295 296
 	}
296 297
 
@@ -312,27 +313,32 @@ - (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
312 313
 
313 314
 	DEBUG(@"directory %@ has changed, recursive = %s", aURL, recursiveFlush ? "YES" : "NO");
314 315
 
  316
+	// XXX: Why is this event not triggered by the file explorer itself!?
315 317
 	[[ViEventManager defaultManager] emit:ViEventDirectoryChanged for:nil with:aURL, nil];
316 318
 	for (NSWindow *window in [NSApp windows]) {
317 319
 		ViWindowController *wincon = [window windowController];
318 320
 		if ([wincon respondsToSelector:@selector(explorer)]) {
319 321
 			ViFileExplorer *explorer = [wincon explorer];
320 322
 			if ([explorer displaysURL:aURL])
321  
-				[[ViEventManager defaultManager] emit:ViEventExplorerDirectoryChanged for:explorer with:explorer, aURL, nil];
  323
+				[[ViEventManager defaultManager] emit:ViEventExplorerDirectoryChanged
  324
+								  for:explorer
  325
+								 with:explorer, aURL, nil];
322 326
 		}
323 327
 	}
324 328
 
325 329
 	if (!recursiveFlush) {
326  
-		if (![self directoryIsCachedAtURL:aURL])
  330
+		if (![self directoryIsCachedAtURL:aURL]) {
327 331
 			return;
  332
+		}
328 333
 		[self flushCachedContentsOfDirectoryAtURL:aURL];
329 334
 		if ([self shouldRescanDirectoryAtURL:aURL]) {
330 335
 			[self contentsOfDirectoryAtURL:aURL onCompletion:^(NSArray *contents, NSError *error) {
331 336
 				/* Any interested project explorer will get a notification. */
332 337
 				DEBUG(@"rescanned URL %@, error %@", aURL, error);
333 338
 			}];
334  
-		} else if ([aURL isFileURL])
  339
+		} else if ([aURL isFileURL]) {
335 340
 			[self restartEvents]; /* To un-monitor the flushed directory. */
  341
+		}
336 342
 		return;
337 343
 	}
338 344
 
@@ -352,13 +358,15 @@ - (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
352 358
 					/* Any interested project explorer will get a notification. */
353 359
 					DEBUG(@"rescanned URL %@, error %@", url, error);
354 360
 				}];
355  
-			} else
  361
+			} else {
356 362
 				restart = YES;
  363
+			}
357 364
 		}
358 365
 	}
359 366
 
360  
-	if (restart && [aURL isFileURL])
  367
+	if (restart && [aURL isFileURL]) {
361 368
 		[self restartEvents];
  369
+	}
362 370
 }
363 371
 
364 372
 - (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
@@ -413,12 +421,13 @@ - (BOOL)URLIsMonitored:(NSURL *)aURL
413 421
 
414 422
 	NSString *path = [aURL path];
415 423
 	NSArray *pathsBeingWatched = (NSArray *)FSEventStreamCopyPathsBeingWatched(_evstream);
416  
-	for (NSString *p in pathsBeingWatched)
  424
+	for (NSString *p in pathsBeingWatched) {
417 425
 		if ([path hasPrefix:p]) {
418 426
 			DEBUG(@"URL %@ is already being watched", aURL);
419 427
 			CFRelease(pathsBeingWatched);
420 428
 			return YES;
421 429
 		}
  430
+	}
422 431
 
423 432
 	CFRelease(pathsBeingWatched);
424 433
 	return NO;

0 notes on commit bb3d8d6

Please sign in to comment.
Something went wrong with that request. Please try again.