Revision: 4186
http://skim-app.svn.sourceforge.net/skim-app/?rev=4186&view=rev
Author: hofman
Date: 2008-07-11 03:52:15 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
Enable synctex.
Modified Paths:
--------------
trunk/Files_SKExtensions.h
trunk/Files_SKExtensions.m
trunk/SKPDFSynchronizer.h
trunk/SKPDFSynchronizer.m
trunk/Skim.xcodeproj/project.pbxproj
Modified: trunk/Files_SKExtensions.h
===================================================================
--- trunk/Files_SKExtensions.h 2008-07-11 09:42:30 UTC (rev 4185)
+++ trunk/Files_SKExtensions.h 2008-07-11 10:52:15 UTC (rev 4186)
@@ -47,6 +47,7 @@
extern BOOL SKFileIsInTrash(NSURL *fileURL);
extern BOOL SKFileExistsAtPath(NSString *path);
extern NSDate *SKFileModificationDateAtPath(NSString *path);
+extern NSString *SKPathFromFileSystemRepresentation(const char *path);
extern NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create);
extern NSString *SKChewableItemsDirectory();
extern NSString *SKUniqueTemporaryDirectory();
Modified: trunk/Files_SKExtensions.m
===================================================================
--- trunk/Files_SKExtensions.m 2008-07-11 09:42:30 UTC (rev 4185)
+++ trunk/Files_SKExtensions.m 2008-07-11 10:52:15 UTC (rev 4186)
@@ -112,6 +112,18 @@
return nil;
}
+NSString *SKPathFromFileSystemRepresentation(const char *path) {
+ NSString *thePath = nil;
+ if (path != NULL) {
+ CFURLRef theURL =
CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8 *)path,
strlen(path), NO);
+ if (theURL != NULL) {
+ thePath = [(NSURL *)theURL path];
+ CFRelease(theURL);
+ }
+ }
+ return thePath;
+}
+
NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create) {
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *tmpDirName = [(NSString *)CFUUIDCreateString(NULL, uuid)
autorelease];
Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h 2008-07-11 09:42:30 UTC (rev 4185)
+++ trunk/SKPDFSynchronizer.h 2008-07-11 10:52:15 UTC (rev 4186)
@@ -38,6 +38,9 @@
#import <Cocoa/Cocoa.h>
#import <libkern/OSAtomic.h>
+
+#define SYNCTEX_FEATURE 1
+
#ifdef SYNCTEX_FEATURE
#import "synctex_parser.h"
#endif
@@ -61,8 +64,7 @@
NSConnection *localThreadConnection;
volatile int32_t shouldKeepRunning __attribute__ ((aligned (32)));
-
- BOOL serverReady;
+ volatile int32_t serverReady __attribute__ ((aligned (32)));
}
Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m 2008-07-11 09:42:30 UTC (rev 4185)
+++ trunk/SKPDFSynchronizer.m 2008-07-11 10:52:15 UTC (rev 4186)
@@ -90,10 +90,8 @@
#pragma mark -
[EMAIL PROTECTED] SKPDFSynchronizer (Private)
[EMAIL PROTECTED] SKPDFSynchronizer (SKPrivate)
- (void)runDOServerForPorts:(NSArray *)ports;
-// these following methods only be called on the server thread
-- (BOOL)parseSyncFileIfNeeded;
@end
#pragma mark -
@@ -108,8 +106,12 @@
pages = [[NSMutableArray alloc] init];
lines = [[NSMutableDictionary alloc] init];
fileName = nil;
+ syncFileName = nil;
lastModDate = nil;
isPdfsync = YES;
+#ifdef SYNCTEX_FEATURE
+ scanner = NULL;
+#endif
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
@@ -124,7 +126,7 @@
serverOnServerThread = nil;
shouldKeepRunning = 1;
- serverReady = NO;
+ serverReady = 1;
// run a background thread to connect to the remote server
// this will connect back to the connection we just set up
@@ -134,7 +136,7 @@
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
OSMemoryBarrier();
- } while (serverReady == NO && shouldKeepRunning == 1);
+ } while (serverReady == 1 && shouldKeepRunning == 1);
}
return self;
}
@@ -208,6 +210,11 @@
return date;
}
+- (BOOL)shouldKeepRunning {
+ OSMemoryBarrier();
+ return shouldKeepRunning == 1;
+}
+
#pragma mark API
#pragma mark | DO server
@@ -243,20 +250,18 @@
- (oneway void)setLocalServer:(byref id)anObject {
[anObject setProtocolForProxy:@protocol(SKPDFSynchronizerServerThread)];
serverOnServerThread = [anObject retain];
- serverReady = YES;
+ OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverReady);
}
#pragma mark | Finding
- (oneway void)serverFoundLine:(int)line inFile:(bycopy NSString *)file {
- OSMemoryBarrier();
- if (shouldKeepRunning && [delegate
respondsToSelector:@selector(synchronizer:foundLine:inFile:)])
+ if ([self shouldKeepRunning] && [delegate
respondsToSelector:@selector(synchronizer:foundLine:inFile:)])
[delegate synchronizer:self foundLine:line inFile:file];
}
- (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned
int)pageIndex {
- OSMemoryBarrier();
- if (shouldKeepRunning && [delegate
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:)])
+ if ([self shouldKeepRunning] && [delegate
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:)])
[delegate synchronizer:self foundLocation:point atPageIndex:pageIndex];
}
@@ -311,8 +316,7 @@
[pool release];
pool = [NSAutoreleasePool new];
didRun = [rl runMode:NSDefaultRunLoopMode beforeDate:[NSDate
distantFuture]];
- OSMemoryBarrier();
- } while (shouldKeepRunning == 1 && didRun);
+ } while ([self shouldKeepRunning] && didRun);
}
@catch(id exception) {
NSLog(@"Discarding exception \"[EMAIL PROTECTED]" raised in object
%@", exception, self);
@@ -377,8 +381,7 @@
[sc scanCharactersFromSet:[NSCharacterSet newlineCharacterSet]
intoString:NULL];
- OSMemoryBarrier();
- while (shouldKeepRunning && [sc scanCharacter:&ch]) {
+ while ([self shouldKeepRunning] && [sc scanCharacter:&ch]) {
if (ch == 'l') {
if ([sc scanInt:&recordIndex] && [sc scanInt:&line]) {
@@ -428,8 +431,6 @@
[sc scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet]
intoString:NULL];
[sc scanCharactersFromSet:[NSCharacterSet newlineCharacterSet]
intoString:NULL];
-
- OSMemoryBarrier();
}
[sc release];
@@ -443,8 +444,7 @@
[pages makeObjectsPerformSelector:@selector(sortUsingDescriptors:)
withObject:[NSArray
arrayWithObjects:ySortDescriptor, xSortDescriptor, nil]];
- OSMemoryBarrier();
- BOOL returnValue = shouldKeepRunning == 1;
+ BOOL returnValue = [self shouldKeepRunning];
return returnValue;
}
@@ -453,9 +453,8 @@
#ifdef SYNCTEX_FEATURE
if (scanner)
synctex_scanner_free(scanner);
- scanner = synctex_scanner_new_with_output_file([theFileName
fileSystemRepresentation]);
- if (scanner) {
- NSString *theSyncFileName = [NSString
stringWithUTF8String:synctex_scanner_get_synctex(scanner)];
+ if (scanner = synctex_scanner_new_with_output_file([theFileName
fileSystemRepresentation])) {
+ NSString *theSyncFileName =
SKPathFromFileSystemRepresentation(synctex_scanner_get_synctex(scanner));
[self setSyncFileName:theSyncFileName];
isPdfsync = NO;
return YES;
@@ -607,7 +606,7 @@
synctex_node_t node;
if (node = synctex_next_result(scanner)) {
*line = synctex_node_line(node);
- *file = [NSString
stringWithUTF8String:synctex_scanner_get_name(scanner, synctex_node_tag(node))];
+ *file =
[SKPathFromFileSystemRepresentation(synctex_scanner_get_name(scanner,
synctex_node_tag(node))) retain];
return YES;
}
}
@@ -633,10 +632,8 @@
int foundLine = -1;
NSString *foundFile = nil;
- OSMemoryBarrier();
- if (shouldKeepRunning && [self parseSyncFileIfNeeded]) {
- OSMemoryBarrier();
- if (shouldKeepRunning) {
+ if ([self shouldKeepRunning] && [self parseSyncFileIfNeeded]) {
+ if ([self shouldKeepRunning]) {
if (isPdfsync)
[self pdfsyncFindLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
else
@@ -644,8 +641,7 @@
}
}
- OSMemoryBarrier();
- if (shouldKeepRunning)
+ if ([self shouldKeepRunning])
[serverOnMainThread serverFoundLine:foundLine inFile:foundFile];
}
@@ -653,10 +649,8 @@
unsigned int foundPageIndex = NSNotFound;
NSPoint foundPoint = NSZeroPoint;
- OSMemoryBarrier();
- if (shouldKeepRunning && file && [self parseSyncFileIfNeeded] && [lines
objectForKey:file]) {
- OSMemoryBarrier();
- if (shouldKeepRunning) {
+ if ([self shouldKeepRunning] && file && [self parseSyncFileIfNeeded] &&
[lines objectForKey:file]) {
+ if ([self shouldKeepRunning]) {
if (isPdfsync)
[self pdfsyncFindPage:&foundPageIndex location:&foundPoint
forLine:line inFile:file];
else
@@ -664,8 +658,7 @@
}
}
- OSMemoryBarrier();
- if (shouldKeepRunning)
+ if ([self shouldKeepRunning])
[serverOnMainThread serverFoundLocation:foundPoint
atPageIndex:foundPageIndex];
}
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2008-07-11 09:42:30 UTC (rev
4185)
+++ trunk/Skim.xcodeproj/project.pbxproj 2008-07-11 10:52:15 UTC (rev
4186)
@@ -78,6 +78,8 @@
CE2DED6C0B86334900D0DA12 /* BDSKFindFieldEditor.m in Sources */
= {isa = PBXBuildFile; fileRef = CE2DED6B0B86334900D0DA12 /*
BDSKFindFieldEditor.m */; };
CE31A6180C01FC45003612A9 /* SKDocumentController.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE31A6160C01FC45003612A9 /*
SKDocumentController.m */; };
CE327A460C11BF6700DB4BEB /* NoteTypeSheet.nib in Resources */ =
{isa = PBXBuildFile; fileRef = CE327A440C11BF6700DB4BEB /* NoteTypeSheet.nib
*/; };
+ CE3364310E2761E9005F99E6 /* synctex_parser.c in Sources */ =
{isa = PBXBuildFile; fileRef = CE33639F0E26E120005F99E6 /* synctex_parser.c */;
};
+ CE3364320E2761EF005F99E6 /* libz.dylib in Frameworks */ = {isa
= PBXBuildFile; fileRef = CE3363CD0E26E378005F99E6 /* libz.dylib */; };
CE3400AC0E0034DF00A7FFE6 /* NSMenu_SKExtensions.m in Sources */
= {isa = PBXBuildFile; fileRef = CE3400AB0E0034DF00A7FFE6 /*
NSMenu_SKExtensions.m */; };
CE3401E00E01378A00A7FFE6 /* NSAttributedString_SKExtensions.m
in Sources */ = {isa = PBXBuildFile; fileRef = CE3401DF0E01378A00A7FFE6 /*
NSAttributedString_SKExtensions.m */; };
CE3401E60E01388700A7FFE6 /* NSNumber_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE3401E50E01388700A7FFE6 /*
NSNumber_SKExtensions.m */; };
@@ -960,6 +962,7 @@
CE7DC7450E0928A700D6D76D /* SkimNotes.framework
in Frameworks */,
CE2BB7D00E0DAFD30090E848 /* SkimNotes.framework
in Frameworks */,
CE2BB7D10E0DAFDE0090E848 /* Sparkle.framework
in Frameworks */,
+ CE3364320E2761EF005F99E6 /* libz.dylib in
Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2099,6 +2102,7 @@
CE3401E60E01388700A7FFE6 /*
NSNumber_SKExtensions.m in Sources */,
CE665A140E1BF43700D0704D /*
SKBookmarkOutlineView.m in Sources */,
CEC3AD240E23EC0300F40B0B /*
PDFAnnotationLink_SKExtensions.m in Sources */,
+ CE3364310E2761E9005F99E6 /* synctex_parser.c in
Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit