From f682e2ea9ea4f96b1f395ceb166c7d2a59782c9d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 10 Jan 2011 13:05:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20sequelpro=20URL=20command=20Synta?= =?UTF-8?q?xHighlighting=20to=20be=20connection=20independent=20-=20added?= =?UTF-8?q?=20example=20BASH=20script=20at=20http://www.sequelpro.com/docs?= =?UTF-8?q?/URL=5Fscheme=5Fsequelpro://=5FUsage#Use=5FSequel=5FPro=5Fto=5F?= =?UTF-8?q?do=5Fa=5Fsyntax=5Fhighlighting=5Fof=5Fa=5Fgiven=5FSQL=5Fquery?= =?UTF-8?q?=5FHTML=5Fformatted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.m | 137 -------------------------------------------- 1 file changed, 137 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index b6979dfa..3ae454c3 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -56,18 +56,6 @@ #import "SPDatabaseRename.h" #import "SPServerSupport.h" #import "SPTooltip.h" -#import "SPEditorTokens.h" - -#pragma mark lex init - -/* -* Include all the extern variables and prototypes required for flex (used for syntax highlighting) -*/ -extern NSUInteger yylex(); -extern NSUInteger yyuoffset, yyuleng; -typedef struct yy_buffer_state *YY_BUFFER_STATE; -void yy_switch_to_buffer(YY_BUFFER_STATE); -YY_BUFFER_STATE yy_scan_string (const char *); @interface SPDatabaseDocument (PrivateAPI) @@ -4557,86 +4545,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); #pragma mark - #pragma mark Scheme scripting methods -/** - * Return an HTML formatted string representing the passed SQL string syntax highlighted - */ -- (NSString*)doSQLSyntaxHighlightForString:(NSString*)sqlText cssLike:(BOOL)cssLike -{ - - NSMutableString *sqlHTML = [[[NSMutableString alloc] initWithCapacity:[sqlText length]] autorelease]; - - NSRange textRange = NSMakeRange(0, [sqlText length]); - NSString *tokenColor; - NSString *cssId; - size_t token; - NSRange tokenRange; - - // initialise flex - yyuoffset = 0; yyuleng = 0; - yy_switch_to_buffer(yy_scan_string([sqlText UTF8String])); - BOOL skipFontTag; - - while (token=yylex()){ - skipFontTag = NO; - switch (token) { - case SPT_SINGLE_QUOTED_TEXT: - case SPT_DOUBLE_QUOTED_TEXT: - tokenColor = @"#A7221C"; - cssId = @"sp_sql_quoted"; - break; - case SPT_BACKTICK_QUOTED_TEXT: - tokenColor = @"#001892"; - cssId = @"sp_sql_backtick"; - break; - case SPT_RESERVED_WORD: - tokenColor = @"#0041F6"; - cssId = @"sp_sql_keyword"; - break; - case SPT_NUMERIC: - tokenColor = @"#67350F"; - cssId = @"sp_sql_numeric"; - break; - case SPT_COMMENT: - tokenColor = @"#265C10"; - cssId = @"sp_sql_comment"; - break; - case SPT_VARIABLE: - tokenColor = @"#6C6C6C"; - cssId = @"sp_sql_variable"; - break; - case SPT_WHITESPACE: - skipFontTag = YES; - cssId = @""; - break; - default: - skipFontTag = YES; - cssId = @""; - } - - tokenRange = NSMakeRange(yyuoffset, yyuleng); - - if(skipFontTag) - [sqlHTML appendString:[[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; - else { - if(cssLike) - [sqlHTML appendFormat:@"%@", cssId, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; - else - [sqlHTML appendFormat:@"%@", tokenColor, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; - } - - } - - // Wrap lines, and replace tabs with spaces - [sqlHTML replaceOccurrencesOfString:@"\n" withString:@"
" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; - [sqlHTML replaceOccurrencesOfString:@"\t" withString:@"    " options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; - - if(sqlHTML) - return sqlHTML; - else - return @""; - -} - /** * Called by handleSchemeCommand: to break a while loop */ @@ -4733,51 +4641,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - if([command isEqualToString:@"SyntaxHighlighting"]) { - - NSFileManager *fm = [NSFileManager defaultManager]; - BOOL isDir; - - NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; - NSString *resultFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, docProcessID]; - NSString *metaFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, docProcessID]; - NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, docProcessID]; - - NSError *inError = nil; - NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; - NSString *result = @""; - NSString *status = @"0"; - - if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { - - if(inError == nil && query && [query length]) { - if([params count] > 1) { - if([[params lastObject] isEqualToString:@"html"]) - result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:NO]]; - else if([[params lastObject] isEqualToString:@"htmlcss"]) - result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:YES]]; - } - } - } - - [fm removeItemAtPath:queryFileName error:nil]; - [fm removeItemAtPath:resultFileName error:nil]; - [fm removeItemAtPath:metaFileName error:nil]; - [fm removeItemAtPath:statusFileName error:nil]; - - if(![result writeToFile:resultFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]) - status = @"1"; - - // write status file as notification that query was finished - BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; - if(!succeed) { - NSBeep(); - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, - NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")); - } - return; - } - // ==== the following commands need an authentication for safety reasons // Authenticate command -- cgit v1.2.3