From 58eae2e4caed0c45569ec666f6f1596e8e201a0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciar=C3=A1n=20Walsh?= Date: Sun, 22 Jun 2008 01:48:17 +0100 Subject: [PATCH] Syntax highlight source files using the PHP executable --- Source/BSSourceView.m | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index 46b8396..e5d2552 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -42,7 +42,25 @@ - (void)setFile:(NSString *)f { file = f; - [textView setString:[NSString stringWithContentsOfFile:f]]; + + @try + { + // Attempt to use the PHP CLI to highlight the source file as HTML + NSPipe* pipe = [NSPipe pipe]; + NSTask* task = [NSTask new]; + [task setLaunchPath:@"/usr/bin/php"]; // This is the path to the default Leopard PHP executable + [task setArguments:[NSArray arrayWithObjects:@"-s", f, nil]]; + [task setStandardOutput:pipe]; + [task launch]; + NSData* data = [[pipe fileHandleForReading] readDataToEndOfFile]; + NSAttributedString* source = [[NSAttributedString alloc] initWithHTML:data documentAttributes:NULL]; + [[textView textStorage] setAttributedString:source]; + } + @catch(NSException* exception) + { + // If the PHP executable is not available then the NSTask will throw an exception + [textView setString:[NSString stringWithContentsOfFile:f]]; + } } /** -- 2.22.5