Revision: 13504
          http://sourceforge.net/p/skim-app/code/13504
Author:   hofman
Date:     2023-06-23 22:46:12 +0000 (Fri, 23 Jun 2023)
Log Message:
-----------
remove command line tool based quicklook generation, as this does not work in 
the actual quicklookd, probably because it is sandboxed.

Modified Paths:
--------------
    trunk/QuickLook-Skim/GeneratePreviewForURL.m
    trunk/QuickLook-Skim/GenerateThumbnailForURL.m
    trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj
    trunk/QuickLook-Skim/SKQLConverter.h
    trunk/QuickLook-Skim/SKQLConverter.m

Removed Paths:
-------------
    trunk/QuickLook-Skim/BDSKTask.h
    trunk/QuickLook-Skim/BDSKTask.m

Deleted: trunk/QuickLook-Skim/BDSKTask.h
===================================================================
--- trunk/QuickLook-Skim/BDSKTask.h     2023-06-23 18:30:09 UTC (rev 13503)
+++ trunk/QuickLook-Skim/BDSKTask.h     2023-06-23 22:46:12 UTC (rev 13504)
@@ -1,84 +0,0 @@
-//
-//  BDSKTask.h
-//  Bibdesk
-//
-//  Created by Adam Maxwell on 8/25/08.
-/*
- This software is Copyright (c) 2008-2023
- Adam Maxwell. All rights reserved.
- 
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
- 
- - Neither the name of Adam Maxwell nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Cocoa/Cocoa.h>
-#import <stdatomic.h>
-
-/** @brief Concrete subclass of NSTask.
- 
- NSTask is not listed as thread safe in Apple's documentation.  At least in 
10.4 and prior, its implementation allows the parent/child relationship to be 
lost (somehow), possibly by observing SIGCHLD in a thread-unsafe way.  Among 
other problems, this causes unexpected exceptions to be raised, and termination 
to not work correctly.
- 
- BDSKTask is designed to be thread safe insofar as instances can be created 
and launched from threads other than the AppKit thread.  If the task is 
accessed from multiple threads, use a lock to protect it.
- 
- BDSKTask guarantees that NSTaskDidTerminateNotification will be posted on the 
thread that called BDSKTask::launch.
- 
- Exceptions should only be raised for violation of the API contract (e.g. 
calling BDSKTask::terminationStatus while the task is still running, or setting 
the launch path after the task has launched).
- 
- */
-
-@interface BDSKTask : NSTask {
-@private
-    NSString                *_launchPath;
-    NSArray                 *_arguments;
-    NSDictionary            *_environment;
-    NSString                *_currentDirectoryPath;
-    id                       _standardInput;
-    id                       _standardOutput;
-    id                       _standardError;
-    pid_t                    _processIdentifier;
-    _Atomic(int)             _terminationStatus;
-    NSTaskTerminationReason  _terminationReason;
-    _Atomic(BOOL)            _running;
-    _Atomic(BOOL)            _launched;
-    struct BDSKTaskInternal *_internal;
-}
-
-+ (BDSKTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray 
*)arguments;
-
-@end
-
-#ifndef HANDLE_EINTR
-// http://src.chromium.org/svn/trunk/src/base/eintr_wrapper.h
-#define HANDLE_EINTR(x) ({ \
-    typeof(x) __eintr_result__; \
-    do { \
-        __eintr_result__ = x; \
-    } while (__eintr_result__ == -1 && errno == EINTR); \
-    __eintr_result__;\
-})
-#endif

Deleted: trunk/QuickLook-Skim/BDSKTask.m
===================================================================
--- trunk/QuickLook-Skim/BDSKTask.m     2023-06-23 18:30:09 UTC (rev 13503)
+++ trunk/QuickLook-Skim/BDSKTask.m     2023-06-23 22:46:12 UTC (rev 13504)
@@ -1,680 +0,0 @@
-//
-//  BDSKTask.m
-//  Bibdesk
-//
-//  Created by Adam Maxwell on 8/25/08.
-/*
- This software is Copyright (c) 2008-2023
- Adam Maxwell. All rights reserved.
- 
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
- 
- - Neither the name of Adam Maxwell nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "BDSKTask.h"
-#import <crt_externs.h>
-#import <sys/types.h>
-#import <sys/event.h>
-#import <sys/time.h>
-#import <sys/resource.h>
-#import <pthread.h>
-
-@interface BDSKTask (Private)
-
-+ (void)_watchQueue;
-- (void)_taskSignaled;
-- (void)_disableNotification;
-- (void)_taskExited;
-
-@end
-
-struct BDSKTaskInternal {
-    BOOL               _canNotify;
-    struct kevent      _event;
-    CFRunLoopRef       _rl;
-    CFRunLoopSourceRef _rlsource;
-    pthread_mutex_t    _lock;
-    id                 _task;
-};
-
-@implementation BDSKTask
-
-static int _kqueue = -1;
-
-+ (void)initialize
-{
-    if ([BDSKTask class] != self) return;
-    _kqueue = kqueue();
-    // persistent thread to watch all tasks
-    [NSThread detachNewThreadSelector:@selector(_watchQueue) toTarget:self 
withObject:nil];
-}
-
-+ (BDSKTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray 
*)arguments;
-{
-    BDSKTask *task = [[self new] autorelease];
-    [task setLaunchPath:path];
-    [task setArguments:arguments];
-    [task launch];
-    return task;
-}
-
-#define ASSERT_LAUNCH do { if (!atomic_load(&_launched)) { [NSException 
raise:@"BDSKTaskException" format:@"Task has not been launched"]; } } while (0)
-#define ASSERT_NOTLAUNCHED do { if (atomic_load(&_launched)) { [NSException 
raise:@"BDSKTaskException" format:@"Task has already been launched"]; } } while 
(0)
-
-- (id)init
-{
-    self = [super init];
-    if (self) {
-        _internal = NSZoneCalloc([self zone], 1, sizeof(struct 
BDSKTaskInternal));
-        memset(&_internal->_event, 0, sizeof(struct kevent));
-        pthread_mutex_init(&_internal->_lock, NULL);
-        _internal->_canNotify = 1;
-        _internal->_task = self;
-    }
-    return self;
-}
-
-- (void)dealloc
-{
-    [self _disableNotification];
-    [_launchPath release];
-    [_arguments release];
-    [_environment release];
-    [_currentDirectoryPath release];
-    [_standardInput release];
-    [_standardOutput release];
-    [_standardError release];
-    [super dealloc];
-}
-
-- (void)finalize
-{
-    [self _disableNotification];
-    [super finalize];
-}
-
-- (void)setLaunchPath:(NSString *)path;
-{
-    ASSERT_NOTLAUNCHED;
-    [_launchPath autorelease];
-    _launchPath = [path copy];
-}
-
-- (void)setArguments:(NSArray *)arguments;
-{
-    ASSERT_NOTLAUNCHED;
-    [_arguments autorelease];
-    _arguments = [arguments copy];
-}
-
-- (void)setEnvironment:(NSDictionary *)dict;
-{
-    ASSERT_NOTLAUNCHED;
-    [_environment autorelease];
-    _environment = [dict copy];
-}
-
-- (void)setCurrentDirectoryPath:(NSString *)path;
-{
-    ASSERT_NOTLAUNCHED;
-    [_currentDirectoryPath autorelease];
-    _currentDirectoryPath = [path copy];
-}
-
-// set standard I/O channels; may be either an NSFileHandle or an NSPipe
-- (void)setStandardInput:(id)input;
-{
-    ASSERT_NOTLAUNCHED;
-    [_standardInput autorelease];
-    _standardInput = [input retain];
-}
-
-- (void)setStandardOutput:(id)output;
-{
-    ASSERT_NOTLAUNCHED;
-    [_standardOutput autorelease];
-    _standardOutput = [output retain];
-}
-
-- (void)setStandardError:(id)error;
-{
-    ASSERT_NOTLAUNCHED;
-    [_standardError autorelease];
-    _standardError = [error retain];
-}
-
-// get parameters
-- (NSString *)launchPath; { return _launchPath; }
-- (NSArray *)arguments; { return _arguments; }
-- (NSDictionary *)environment; { return _environment; }
-- (NSString *)currentDirectoryPath; { return _currentDirectoryPath; }
-
-// get standard I/O channels; could be either an NSFileHandle or an NSPipe
-- (id)standardInput; { return _standardInput; }
-- (id)standardOutput; { return _standardOutput; }
-- (id)standardError; { return _standardError; }
-
-static void __BDSKTaskNotify(void *info)
-{
-    // note: we have a hard retain at this point, so -dealloc and 
_disableNotification can't be called
-    BDSKTask *task = info;
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:NSTaskDidTerminateNotification object:task];
-    
-    pthread_mutex_lock(&task->_internal->_lock);
-    
-    // trivial sanity check here
-    NSCParameterAssert(task->_internal->_task == task);
-    task->_internal->_task = nil;
-    
-    // source is retained by the runloop; invalidate it and then make sure we 
no longer have a reference
-    CFRunLoopSourceInvalidate(task->_internal->_rlsource);
-    task->_internal->_rlsource = NULL;
-    
-    // release the task's reference to the runloop and clear it
-    NSCParameterAssert(NULL != task->_internal->_rl);
-    if (task->_internal->_rl) {
-        CFRelease(task->_internal->_rl);
-        task->_internal->_rl = NULL;
-    }
-    pthread_mutex_unlock(&task->_internal->_lock);
-    
-    // only freed when the child exits, so the kevent callout always has a 
valid udata pointer
-    pthread_mutex_destroy(&task->_internal->_lock);
-    NSZoneFree(NSZoneFromPointer(task->_internal), task->_internal);
-    task->_internal = NULL;
-    
-    // balance additional retain in _taskExited
-    [task release];
-}
-
-/*
- Undocumented behavior of -[NSFileManager fileSystemRepresentationWithPath:]
- is to raise an exception when passed an empty string.  Since this is called by
- -[NSString fileSystemRepresentation], use CF.  rdar://problem/9565599
- 
- https://bitbucket.org/jfh/machg/issue/244/p1d3-crash-during-view-differences
- 
- Have to copy all -[NSString fileSystemRepresentation] pointers to avoid 
garbage collection
- issues with -fileSystemRepresentation, anyway.  How tedious compared to 
-autorelease...
- 
- http://lists.apple.com/archives/objc-language/2011/Mar/msg00122.html
- */
-static char *__BDSKCopyFileSystemRepresentation(NSString *str)
-{
-    if (nil == str) return NULL;
-    
-    CFIndex len = 
CFStringGetMaximumSizeOfFileSystemRepresentation((CFStringRef)str);
-    char *cstr = NSZoneCalloc(NSDefaultMallocZone(), len, sizeof(char));
-    if (CFStringGetFileSystemRepresentation((CFStringRef)str, cstr, len) == 
FALSE) {
-        NSZoneFree(NSDefaultMallocZone(), cstr);
-        cstr = NULL;
-    }
-    return cstr;
-}
-
-- (void)launch;
-{
-    ASSERT_NOTLAUNCHED;
-    
-    const NSUInteger argCount = [_arguments count];
-    char *workingDir = 
__BDSKCopyFileSystemRepresentation(_currentDirectoryPath);
-    
-    // fill with pointers to copied C strings
-    char **args = NSZoneCalloc([self zone], (argCount + 2), sizeof(char *));
-    NSUInteger i;
-    args[0] = __BDSKCopyFileSystemRepresentation(_launchPath);
-    for (i = 0; i < argCount; i++) {
-        args[i + 1] = __BDSKCopyFileSystemRepresentation([_arguments 
objectAtIndex:i]);
-    }
-    args[argCount + 1] = NULL;
-    
-    char ***nsEnvironment = _NSGetEnviron();
-    char **env = *nsEnvironment;
-    
-    NSDictionary *environment = [self environment];
-    if (environment) {
-        // fill with pointers to copied C strings
-        env = NSZoneCalloc([self zone], [environment count] + 1, sizeof(char 
*));
-        NSString *key;
-        NSUInteger envIndex = 0;
-        for (key in environment) {
-            env[envIndex++] = __BDSKCopyFileSystemRepresentation([NSString 
stringWithFormat:@"%@=%@", key, [environment objectForKey:key]]);
-        }
-        env[envIndex] = NULL;
-    }
-    
-    // fileHandleWithNullDevice returns a descriptor of -1, so use fd_null 
instead
-    int fd_out = -1, fd_inp = -1, fd_err = -1, fd_null = open("/dev/null", 
O_WRONLY);
-    id fh = nil;
-    
-    // the end of a pipe passed to the child needs to be closed in the parent 
process
-    NSMutableSet *handlesToClose = [NSMutableSet set];
-    NSFileHandle *nullHandle = [NSFileHandle fileHandleWithNullDevice];
-    [handlesToClose addObject:nullHandle];
-    
-    fh = [self standardInput];
-    if ([fh isKindOfClass:[NSPipe class]]) {
-        [handlesToClose addObject:[fh fileHandleForReading]];
-        fd_inp = [[fh fileHandleForReading] fileDescriptor];
-    }
-    else if (nil != fh) {
-        fd_inp = [fh isEqual:nullHandle] ? fd_null : [fh fileDescriptor];
-    }
-    
-    fh = [self standardOutput];
-    if ([fh isKindOfClass:[NSPipe class]]) {
-        [handlesToClose addObject:[fh fileHandleForWriting]];
-        fd_out = [[fh fileHandleForWriting] fileDescriptor];
-    }
-    else if (nil != fh) {
-        fd_out = [fh isEqual:nullHandle] ? fd_null : [fh fileDescriptor];
-    }
-    
-    fh = [self standardError];
-    if ([fh isKindOfClass:[NSPipe class]]) {
-        [handlesToClose addObject:[fh fileHandleForWriting]];
-        fd_err = [[fh fileHandleForWriting] fileDescriptor];
-    }
-    else if (nil != fh) {
-        fd_err = [fh isEqual:nullHandle] ? fd_null : [fh fileDescriptor];
-    }
-    
-    // avoid a race between exec and setting up our kqueue
-    int blockpipe[2] = { -1, -1 };
-    if (pipe(blockpipe))
-        perror("failed to create blockpipe");
-    
-    /*
-     Figure out the max number of file descriptors for a process; getrlimit is 
not listed as
-     async-signal safe in the sigaction(2) man page, so we assume it's not 
safe to call after
-     fork().  The fork(2) page says that child rlimits are set to zero.
-     */
-    rlim_t maxOpenFiles = OPEN_MAX;
-    struct rlimit openFileLimit;
-    if (getrlimit(RLIMIT_NOFILE, &openFileLimit) == 0)
-        maxOpenFiles = openFileLimit.rlim_cur;
-    
-    // !!! No CF or Cocoa after this point in the child process!
-    _processIdentifier = fork();
-    
-    if (0 == _processIdentifier) {
-        // child process
-        
-        // set process group for killpg()
-        (void)setpgid(getpid(), getpid());
-                
-        // setup stdio descriptors (if not inheriting from parent)
-        if (-1 != fd_inp) dup2(fd_inp, STDIN_FILENO);
-        if (-1 != fd_out) dup2(fd_out, STDOUT_FILENO);
-        if (-1 != fd_err) dup2(fd_err, STDERR_FILENO);
-                
-        if (workingDir) chdir(workingDir);
-        
-        /*
-         Unfortunately, a side effect of blocking on a pipe is that other 
processes inherit our blockpipe
-         descriptors as well.  Consequently, if taskB calls fork() while taskA 
is still setting up its
-         kevent, taskB inherits the pipe for taskA, and taskA will never 
launch since taskB doesn't close
-         them.  This was a very confusing race to debug, and it resulted in a 
bunch of orphaned child
-         processes.
-         
-         Using a class-scope lock is one possible solution, but NSTask 
couldn't use that lock, and subclasses
-         that override -launch would also not benefit from locking (e.g., 
TLMTask).  Since TLMTask sets up
-         NSPipes in -launch before calling -[super launch], those pipes and 
any created by Cocoa would not
-         be protected by that lock.  Closing all remaining file descriptors in 
the child doesn't break any
-         documented behavior of NSTask, and it should take care of that 
problem.  It's not a great solution,
-         since inheriting other descriptors could possibly be useful, but I 
don't need to share arbitrary file
-         descriptors, whereas I do need subclassing and threads to work 
properly.
-         */
-        rlim_t j;
-        for (j = (STDERR_FILENO + 1); j < maxOpenFiles; j++) {
-            
-            // don't close this until we're done reading from it!
-            if ((unsigned)blockpipe[0] != j)
-                (void) close(j);
-        }
-        
-        char ignored;
-        // block until the parent has setup complete
-        (void) HANDLE_EINTR(read(blockpipe[0], &ignored, 1));
-        close(blockpipe[0]);
-        
-        int ret = execve(args[0], args, env);
-        _exit(ret);
-    }
-    else if (-1 == _processIdentifier) {
-        // parent: error
-        int forkError = errno;
-        NSLog(@"fork() failed in task %@: %s", self, strerror(forkError));
-        atomic_store(&_terminationStatus, 2);
-        
-        // clean up what we can
-        [handlesToClose makeObjectsPerformSelector:@selector(closeFile)];
-        if (-1 != fd_null) (void) close(fd_null);
-        close(blockpipe[0]);
-        close(blockpipe[1]);
-    }
-    else {
-        // parent process
-                
-        // CASB probably not necessary anymore...
-        atomic_store(&_running, YES);
-        atomic_store(&_launched, YES);
-        
-        // NSTask docs say that these descriptors are closed in the parent 
task; required to make pipes work properly
-        [handlesToClose makeObjectsPerformSelector:@selector(closeFile)];
-        
-        if (-1 != fd_null) (void) close(fd_null);
-
-        /*
-         The kevent will have a strong reference to the _internal pointer, 
which has a weak reference to the task
-         itself.  This allows -dealloc to occur without waiting for 
notification, as documented for NSTask.
-         Presumably this is so you can fire it off and not have any resources 
hanging around after the exec.
-         */
-        EV_SET(&_internal->_event, _processIdentifier, EVFILT_PROC, EV_ADD, 
NOTE_EXIT | NOTE_SIGNAL, 0, _internal);
-        (void) HANDLE_EINTR(kevent(_kqueue, &_internal->_event, 1, NULL, 0, 
NULL));
-        
-        // use a runloop source to ensure that the notification is posted on 
the correct thread
-        _internal->_rl = (CFRunLoopRef)CFRetain(CFRunLoopGetCurrent());
-        
-        // weak reference in runloop context
-        CFRunLoopSourceContext rlcontext = { 0, self, NULL, NULL, 
CFCopyDescription, CFEqual, CFHash, NULL, NULL, __BDSKTaskNotify };
-        _internal->_rlsource = CFRunLoopSourceCreate(CFAllocatorGetDefault(), 
0, &rlcontext);
-        CFRunLoopAddSource(_internal->_rl, _internal->_rlsource, 
kCFRunLoopCommonModes);
-        CFRelease(_internal->_rlsource);
-        
-        // all setup is complete, so now widow the pipe and exec in the child
-        close(blockpipe[0]);
-        close(blockpipe[1]);
-    }
-    
-    // executed by child and parent
-    
-    /*
-     Free all the copied C strings.  Don't modify the base pointer of args or 
env, since we have to
-     free those too!
-     */
-    free(workingDir);
-    char **freePtr = args;
-    while (NULL != *freePtr) {
-        free(*freePtr++);
-    }
-    
-    NSZoneFree(NSZoneFromPointer(args), args);
-    if (*nsEnvironment != env) {
-        freePtr = env;
-        while (NULL != *freePtr) {
-            free(*freePtr++);
-        }
-        NSZoneFree(NSZoneFromPointer(env), env);
-    }
-    
-}
-
-- (void)interrupt;
-{
-    ASSERT_LAUNCH;
-    killpg(_processIdentifier, SIGINT);
-}
-
-- (void)terminate;
-{
-    ASSERT_LAUNCH;
-    killpg(_processIdentifier, SIGTERM);
-}
-
-- (BOOL)suspend;
-{
-    ASSERT_LAUNCH;
-    return (killpg(_processIdentifier, SIGSTOP) == 0);
-}
-
-- (BOOL)resume;
-{
-    ASSERT_LAUNCH;
-    return (killpg(_processIdentifier, SIGCONT) == 0);
-}
-
-- (int)processIdentifier;
-{
-    ASSERT_LAUNCH;
-    return _processIdentifier;
-}
-
-- (BOOL)isRunning; { return atomic_load(&_running); }
-
-- (int)terminationStatus;
-{
-    ASSERT_LAUNCH;
-    if ([self isRunning]) [NSException raise:NSInternalInconsistencyException 
format:@"Task is still running"];
-    return atomic_load(&_terminationStatus);
-}
-
-- (NSTaskTerminationReason)terminationReason;
-{
-    ASSERT_LAUNCH;
-    if ([self isRunning]) [NSException raise:NSInternalInconsistencyException 
format:@"Task is still running"];
-    return _terminationReason;
-}
-
-- (void)waitUntilExit;
-{
-    ASSERT_LAUNCH;
-    while ([self isRunning]) {
-        NSDate *next = [[NSDate allocWithZone:[self zone]] 
initWithTimeIntervalSinceNow:0.1];
-        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
beforeDate:next];
-        [next release];
-    }
-}
-
-@end
-
-@implementation BDSKTask (Private)
-
-+ (void)_watchQueue
-{
-    do {
-        
-        NSAutoreleasePool *pool = [NSAutoreleasePool new];
-        struct kevent evt;
-        
-        if (HANDLE_EINTR(kevent(_kqueue, NULL, 0, &evt, 1, NULL))) {
-            
-            struct BDSKTaskInternal *internal = evt.udata;
-            pthread_mutex_lock(&internal->_lock);
-            
-            // can only fail if _disableNotification is called immediately 
after kevent unblocks
-            if (internal->_canNotify) {
-                                
-                // retain a pointer to the task before unlocking
-                BDSKTask *task = [internal->_task retain];
-                pthread_mutex_unlock(&internal->_lock);
-
-                // may be called multiple times; no need to free anything
-                if (evt.fflags & NOTE_SIGNAL)
-                    [task _taskSignaled];
-                
-                /*
-                 Only called once; can free stuff on this code path, as 
-dealloc will not be called
-                 while it's executing because we have a retain on the task.
-                 */
-                if (evt.fflags & NOTE_EXIT)
-                    [task _taskExited];
-                
-                [task release];
-                
-            }
-            else {
-
-                //NSLog(@"Not posting NSTaskDidTerminateNotification for 
deallocated task %p", internal->_task);
-
-                // delete this event to make sure we don't get anything else
-                internal->_event.flags = EV_DELETE;
-                (void) HANDLE_EINTR(kevent(_kqueue, &internal->_event, 1, 
NULL, 0, NULL));
-
-                /*
-                 -dealloc or -finalize have called _disableNotification, and it
-                 is now our responsibility to free the _internal pointer.
-                 */
-                pthread_mutex_unlock(&internal->_lock);
-                pthread_mutex_destroy(&internal->_lock);
-
-                // runloop and source were freed in _disableNotification
-                NSParameterAssert(NULL == internal->_rl);
-                NSParameterAssert(NULL == internal->_rlsource);
-                NSZoneFree(NSZoneFromPointer(internal), internal);
-                
-            }
-            
-        }
-        [pool drain];
-        
-    } while (1);
-}
-
-// presently just informational; _taskExited is called when the process exits 
due to a signal
-- (void)_taskSignaled
-{
-    int status;
-    if (HANDLE_EINTR(waitpid(_processIdentifier, &status, WNOHANG))) {
-        if (WIFSIGNALED(status))
-            NSLog(@"task terminated with signal %d", WTERMSIG(status));
-        else if (WIFSTOPPED(status))
-            NSLog(@"task stopped with signal %d", WSTOPSIG(status));
-    }
-}
-
-/*
- This is only called from -dealloc.  The kevent thread retains when it 
unblocks and handles the event,
- so we can never get this during a callout from kevent.  Locking here is 
required so that the kevent
- thread won't do callout during/after dealloc.
- */
-- (void)_disableNotification
-{
-    // !!! early return if task has already exited
-    if (NULL == _internal)
-        return;
-    
-    // Unset _canNotify in case kevent unblocks before we can remove it from 
the queue.
-    pthread_mutex_lock(&_internal->_lock);
-    _internal->_canNotify = NO;
-    
-    /*
-     Called unconditionally from -dealloc, so we may have already notified and 
freed this source,
-     (in which case _internal would be NULL), or we are dealing with an object 
that failed to
-     launch and thus doesn't have a runloop source.
-     */
-    if (_internal->_rlsource) {
-        
-        /*
-         After this point, _taskExited and __BDSKTaskNotify will never be 
called, so account for their teardown.
-         Could do some of this in the kevent handler when the child exits, but 
best to get rid of these
-         resources now.
-         */
-        CFRunLoopSourceInvalidate(_internal->_rlsource);
-        _internal->_rlsource = NULL;
-        
-        // release the task's reference to the runloop and clear it
-        NSCParameterAssert(NULL != _internal->_rl);
-        if (_internal->_rl) {
-            CFRelease(_internal->_rl);
-            _internal->_rl = NULL;
-        }
-    }
-    
-    pthread_mutex_unlock(&_internal->_lock);
-    
-    // runloop and source are freed in __BDSKTaskNotify or _disableNotification
-    NSParameterAssert(NULL == _internal->_rl);
-    NSParameterAssert(NULL == _internal->_rlsource);
-    
-    /*
-     Lock and _internal pointer itself are only freed when the kevent is 
received
-     after the child task exits, but we no longer need a reference to it.
-    */
-    _internal = NULL;
-}
-
-// kevent thread has a retain, so no contention with _disableNotification 
since we can't dealloc
-- (void)_taskExited
-{
-    pthread_mutex_lock(&_internal->_lock);
-    
-    NSParameterAssert(_launched);
-    NSParameterAssert(_running);
-    NSParameterAssert(_internal->_event.udata == _internal);
-    
-    _internal->_event.flags = EV_DELETE;
-    kevent(_kqueue, &_internal->_event, 1, NULL, 0, NULL);
-    
-    /*
-     Was passing WNOHANG, but 
http://lists.apple.com/archives/darwin-dev/2009/Nov/msg00100.html describes
-     a race condition between kqueue and wait.  Since we know the child has 
exited, we can allow waitpid
-     to block without fear that it will block indefinitely.
-     */
-    int ret, status;
-    
-    ret = HANDLE_EINTR(waitpid(_processIdentifier, &status, 0));
-    
-    // happens if you call waitpid() on the child process elsewhere; don't do 
that
-    if (-1 == ret)
-        perror(__func__);
-    
-    if (0 == ret)
-        NSLog(@"*** ERROR *** task %@ (child pid = %d) still running", self, 
_processIdentifier);
-    
-    _processIdentifier = -1;
-    
-    _terminationReason = WIFSIGNALED(status) ? 
NSTaskTerminationReasonUncaughtSignal : NSTaskTerminationReasonExit;
-    
-    ret = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
-    bool swap;
-    
-    // set return value, then set isRunning to false
-    do {
-        int expect = _terminationStatus;
-        swap = atomic_compare_exchange_strong(&_terminationStatus, &expect, 
ret);
-    } while (false == swap);
-    
-    do {
-        BOOL expect = _running;
-        swap = atomic_compare_exchange_strong(&_running, &expect, NO);
-    } while (false == swap);
-    
-    /*
-     Transfer ownership through the callout to avoid dealloc.  Lock runloop 
source access
-     since the source may be handled before CFRunLoopWakeUp() is called, and 
it is
-     never handled in this thread.
-     */
-    [self retain];
-    CFRunLoopSourceSignal(_internal->_rlsource);
-    CFRunLoopWakeUp(_internal->_rl);
-    pthread_mutex_unlock(&_internal->_lock);
-}
-
-@end
-

Modified: trunk/QuickLook-Skim/GeneratePreviewForURL.m
===================================================================
--- trunk/QuickLook-Skim/GeneratePreviewForURL.m        2023-06-23 18:30:09 UTC 
(rev 13503)
+++ trunk/QuickLook-Skim/GeneratePreviewForURL.m        2023-06-23 22:46:12 UTC 
(rev 13504)
@@ -85,13 +85,7 @@
         
     } else if (UTTypeEqual(CFSTR("com.adobe.postscript"), contentTypeUTI)) {
         
-        if (floor(NSAppKitVersionNumber) > 2299.0) {
-            NSData *data = [SKQLConverter PDFDataForURL:(NSURL *)url 
ofType:(NSString *)contentTypeUTI allPages:YES];
-            if (data) {
-                QLPreviewRequestSetDataRepresentation(preview, 
(CFDataRef)data, kUTTypePDF, NULL);
-                err = noErr;
-            }
-        } else {
+        if (floor(NSAppKitVersionNumber) <= 2299.0) {
             bool converted = false;
             CGPSConverterCallbacks converterCallbacks = { 0, NULL, NULL, NULL, 
NULL, NULL, NULL, NULL };
             CGPSConverterRef converter = CGPSConverterCreate(NULL, 
&converterCallbacks, NULL);

Modified: trunk/QuickLook-Skim/GenerateThumbnailForURL.m
===================================================================
--- trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2023-06-23 18:30:09 UTC 
(rev 13503)
+++ trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2023-06-23 22:46:12 UTC 
(rev 13504)
@@ -163,56 +163,46 @@
         
     } else if (UTTypeEqual(CFSTR("com.adobe.postscript"), contentTypeUTI)) {
         
-        bool converted = false;
-        CFDataRef pdfData = NULL;
-        
-        if (floor(NSAppKitVersionNumber) > 2299.0) {
-            NSData *data = [SKQLConverter PDFDataForURL:(NSURL *)url 
ofType:(NSString *)contentTypeUTI allPages:NO];
-            if (data) {
-                pdfData = (CFDataRef)[data retain];
-                converted = true;
-            }
-        } else {
+        if (floor(NSAppKitVersionNumber) <= 2299.0) {
+            bool converted = false;
             CGPSConverterCallbacks converterCallbacks = { 0, NULL, NULL, NULL, 
NULL, NULL, NULL, NULL };
             CGPSConverterRef converter = CGPSConverterCreate(NULL, 
&converterCallbacks, NULL);
             CGDataProviderRef provider = CGDataProviderCreateWithURL(url);
-            CFMutableDataRef mutableData = CFDataCreateMutable(NULL, 0);
-            CGDataConsumerRef consumer = 
CGDataConsumerCreateWithCFData(mutableData);
+            CFMutableDataRef pdfData = CFDataCreateMutable(NULL, 0);
+            CGDataConsumerRef consumer = 
CGDataConsumerCreateWithCFData(pdfData);
             if (provider != NULL && consumer != NULL)
                 converted = CGPSConverterConvert(converter, provider, 
consumer, NULL);
             CGDataProviderRelease(provider);
             CGDataConsumerRelease(consumer);
             CFRelease(converter);
-            if (converted)
-                pdfData = mutableData;
-        }
-        if (converted) {
-            // sadly, we can't use the system's QL generator from inside 
quicklookd, so we don't get the fancy binder on the left edge
-            CGDataProviderRef provider = 
CGDataProviderCreateWithCFData(pdfData);
-            CGPDFDocumentRef pdfDoc = 
CGPDFDocumentCreateWithProvider(provider);
-            CGPDFPageRef pdfPage = NULL;
-            if (pdfDoc && CGPDFDocumentGetNumberOfPages(pdfDoc) > 0)
-                pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);
-            
-            if (pdfPage) {
-                CGRect pageRect = CGPDFPageGetBoxRect(pdfPage, kCGPDFCropBox);
-                CGRect thumbRect = {{0.0, 0.0}, {CGRectGetWidth(pageRect), 
CGRectGetHeight(pageRect)}};
-                CGFloat color[4] = {1.0, 1.0, 1.0, 1.0};
-                CGContextRef ctxt = QLThumbnailRequestCreateContext(thumbnail, 
thumbRect.size, FALSE, NULL);
-                CGAffineTransform t = CGPDFPageGetDrawingTransform(pdfPage, 
kCGPDFCropBox, thumbRect, 0, true);
-                CGContextConcatCTM(ctxt, t);
-                CGContextClipToRect(ctxt, pageRect);
-                CGContextSetFillColor(ctxt, color);
-                CGContextFillRect(ctxt, pageRect);
-                CGContextDrawPDFPage(ctxt, pdfPage);
-                QLThumbnailRequestFlushContext(thumbnail, ctxt);
-                CGContextRelease(ctxt);
-                didGenerate = true;
+            if (converted) {
+                // sadly, we can't use the system's QL generator from inside 
quicklookd, so we don't get the fancy binder on the left edge
+                provider = CGDataProviderCreateWithCFData(pdfData);
+                CGPDFDocumentRef pdfDoc = 
CGPDFDocumentCreateWithProvider(provider);
+                CGPDFPageRef pdfPage = NULL;
+                if (pdfDoc && CGPDFDocumentGetNumberOfPages(pdfDoc) > 0)
+                    pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);
+                
+                if (pdfPage) {
+                    CGRect pageRect = CGPDFPageGetBoxRect(pdfPage, 
kCGPDFCropBox);
+                    CGRect thumbRect = {{0.0, 0.0}, {CGRectGetWidth(pageRect), 
CGRectGetHeight(pageRect)}};
+                    CGFloat color[4] = {1.0, 1.0, 1.0, 1.0};
+                    CGContextRef ctxt = 
QLThumbnailRequestCreateContext(thumbnail, thumbRect.size, FALSE, NULL);
+                    CGAffineTransform t = 
CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, thumbRect, 0, true);
+                    CGContextConcatCTM(ctxt, t);
+                    CGContextClipToRect(ctxt, pageRect);
+                    CGContextSetFillColor(ctxt, color);
+                    CGContextFillRect(ctxt, pageRect);
+                    CGContextDrawPDFPage(ctxt, pdfPage);
+                    QLThumbnailRequestFlushContext(thumbnail, ctxt);
+                    CGContextRelease(ctxt);
+                    didGenerate = true;
+                }
+                CGPDFDocumentRelease(pdfDoc);
+                CGDataProviderRelease(provider);
             }
-            CGPDFDocumentRelease(pdfDoc);
-            CGDataProviderRelease(provider);
+            if (pdfData) CFRelease(pdfData);
         }
-        if (pdfData) CFRelease(pdfData);
         
     } else if (UTTypeEqual(CFSTR("net.sourceforge.skim-app.skimnotes"), 
contentTypeUTI)) {
         

Modified: trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj       
2023-06-23 18:30:09 UTC (rev 13503)
+++ trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj       
2023-06-23 22:46:12 UTC (rev 13504)
@@ -17,8 +17,6 @@
                CE4F80EC0CFB06EE00DBEA14 /* SKQLConverter.m in Sources */ = 
{isa = PBXBuildFile; fileRef = CE4F80EA0CFB06EE00DBEA14 /* SKQLConverter.m */; 
};
                CE82D0AB0ED347B100020950 /* Ink.png in Resources */ = {isa = 
PBXBuildFile; fileRef = CE82D0AA0ED347B100020950 /* Ink.png */; };
                CE861AAE2A0AABE6002FFA1D /* Widget.png in Resources */ = {isa = 
PBXBuildFile; fileRef = CE861AAD2A0AABE6002FFA1D /* Widget.png */; };
-               CE9648032A461B7800E1820B /* BDSKTask.h in Headers */ = {isa = 
PBXBuildFile; fileRef = CE9648012A461B7800E1820B /* BDSKTask.h */; };
-               CE9648042A461B7800E1820B /* BDSKTask.m in Sources */ = {isa = 
PBXBuildFile; fileRef = CE9648022A461B7800E1820B /* BDSKTask.m */; };
                CEC7BCE20CF763A0008CCD63 /* StrikeOut.png in Resources */ = 
{isa = PBXBuildFile; fileRef = CEC7BCDA0CF7639E008CCD63 /* StrikeOut.png */; };
                CEC7BCE30CF763A0008CCD63 /* Note.png in Resources */ = {isa = 
PBXBuildFile; fileRef = CEC7BCDB0CF7639E008CCD63 /* Note.png */; };
                CEC7BCE40CF763A0008CCD63 /* Line.png in Resources */ = {isa = 
PBXBuildFile; fileRef = CEC7BCDC0CF7639E008CCD63 /* Line.png */; };
@@ -49,8 +47,6 @@
                CE4F80EA0CFB06EE00DBEA14 /* SKQLConverter.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= SKQLConverter.m; sourceTree = "<group>"; };
                CE82D0AA0ED347B100020950 /* Ink.png */ = {isa = 
PBXFileReference; lastKnownFileType = image.png; path = Ink.png; sourceTree = 
"<group>"; };
                CE861AAD2A0AABE6002FFA1D /* Widget.png */ = {isa = 
PBXFileReference; lastKnownFileType = image.png; path = Widget.png; sourceTree 
= "<group>"; };
-               CE9648012A461B7800E1820B /* BDSKTask.h */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BDSKTask.h; 
sourceTree = "<group>"; };
-               CE9648022A461B7800E1820B /* BDSKTask.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BDSKTask.m; 
sourceTree = "<group>"; };
                CEB5409B0F261EEF00723C1F /* zh_TW */ = {isa = PBXFileReference; 
fileEncoding = 10; lastKnownFileType = text.plist.strings; name = zh_TW; path = 
zh_TW.lproj/InfoPlist.strings; sourceTree = "<group>"; };
                CEC7BCDA0CF7639E008CCD63 /* StrikeOut.png */ = {isa = 
PBXFileReference; lastKnownFileType = image.png; path = StrikeOut.png; 
sourceTree = "<group>"; };
                CEC7BCDB0CF7639E008CCD63 /* Note.png */ = {isa = 
PBXFileReference; lastKnownFileType = image.png; path = Note.png; sourceTree = 
"<group>"; };
@@ -147,8 +143,6 @@
                                08FB77B6FE84183AC02AAC07 /* main.c */,
                                CE4F80E90CFB06EE00DBEA14 /* SKQLConverter.h */,
                                CE4F80EA0CFB06EE00DBEA14 /* SKQLConverter.m */,
-                               CE9648012A461B7800E1820B /* BDSKTask.h */,
-                               CE9648022A461B7800E1820B /* BDSKTask.m */,
                        );
                        name = Source;
                        sourceTree = "<group>";
@@ -180,7 +174,6 @@
                        buildActionMask = 2147483647;
                        files = (
                                CE4F80EB0CFB06EE00DBEA14 /* SKQLConverter.h in 
Headers */,
-                               CE9648032A461B7800E1820B /* BDSKTask.h in 
Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -283,7 +276,6 @@
                                2C05A19C06CAA52B00D84F6F /* 
GeneratePreviewForURL.m in Sources */,
                                61E3BCFB0870B4F2002186A0 /* 
GenerateThumbnailForURL.m in Sources */,
                                CE4F80EC0CFB06EE00DBEA14 /* SKQLConverter.m in 
Sources */,
-                               CE9648042A461B7800E1820B /* BDSKTask.m in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };

Modified: trunk/QuickLook-Skim/SKQLConverter.h
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.h        2023-06-23 18:30:09 UTC (rev 
13503)
+++ trunk/QuickLook-Skim/SKQLConverter.h        2023-06-23 22:46:12 UTC (rev 
13504)
@@ -40,5 +40,4 @@
 + (NSArray *)notesWithData:(NSData *)data;
 + (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes 
forThumbnail:(QLThumbnailRequestRef)thumbnail;
 + (NSString *)htmlStringWithNotes:(NSArray *)notes;
-+ (NSData *)PDFDataForURL:(NSURL *)url ofType:(NSString *)type 
allPages:(BOOL)allPages;
 @end

Modified: trunk/QuickLook-Skim/SKQLConverter.m
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.m        2023-06-23 18:30:09 UTC (rev 
13503)
+++ trunk/QuickLook-Skim/SKQLConverter.m        2023-06-23 22:46:12 UTC (rev 
13504)
@@ -33,7 +33,6 @@
 
 #import "SKQLConverter.h"
 #include <tgmath.h>
-#include "BDSKTask.h"
 
 static NSString *_noteFontName = @"LucidaHandwriting-Italic";
 static const CGFloat _noteIndent = 20.0;
@@ -269,76 +268,4 @@
     return htmlString;
 }
 
-+ (NSData *)PDFDataForURL:(NSURL *)url ofType:(NSString *)type 
allPages:(BOOL)allPages {
-    
-    NSData *output = nil;
-    
-    NSString *commandPath = nil;
-    if (UTTypeEqual(CFSTR("com.adobe.postscript"), (CFStringRef)type))
-        commandPath = @"/usr/local/bin/ps2pdf";
-    else if (UTTypeEqual(CFSTR("org.tug.tex.dvi"), (CFStringRef)type))
-        commandPath = floor(NSFoundationVersionNumber) > 
NSFoundationVersionNumber10_10 ? @"/Library/TeX/texbin/dvipdfmx" : 
@"/usr/texbin/dvipdfmx";
-    else if (UTTypeEqual(CFSTR("org.tug.tex.xdv"), (CFStringRef)type))
-        commandPath = floor(NSFoundationVersionNumber) > 
NSFoundationVersionNumber10_10 ? @"/Library/TeX/texbin/xdvipdfmx" : 
@"/usr/texbin/xdvipdfmx";
-    
-    NSFileManager *fm = [[NSFileManager alloc] init];
-    
-    if (commandPath && [fm isExecutableFileAtPath:commandPath]) {
-        
-        NSTask *task = [[BDSKTask alloc] init];
-        [task setLaunchPath:commandPath];
-        [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
-        [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
-        
-        NSString *tempDir = NSTemporaryDirectory() ?: @"/tmp";
-        const char *tmpPath = [[tempDir 
stringByAppendingPathComponent:@"skimql.XXXXXX"] fileSystemRepresentation];
-        char *tempName = strdup(tmpPath);
-        int fd = mkstemp(tempName);
-        assert(tempName);
-        
-        if (fd != -1)
-            close(fd);
-        
-        NSString *outputPath = [fm stringWithFileSystemRepresentation:tempName 
length:strlen(tempName)];
-        free(tempName);
-
-        NSMutableArray *arguments = [[NSMutableArray alloc] init];
-        if (UTTypeEqual(CFSTR("com.adobe.postscript"), (CFStringRef)type)) {
-            if (allPages == NO)
-                [arguments addObject:@"-dLastPage=1"];
-            [arguments addObject:[url path]];
-            [arguments addObject:outputPath];
-        } else {
-            [arguments addObject:@"-q"];
-            if (allPages == NO) {
-                [arguments addObject:@"-s"];
-                [arguments addObject:@"1"];
-            }
-            [arguments addObject:@"-o"];
-            [arguments addObject:outputPath];
-            [arguments addObject:[url path]];
-        }
-        [task setArguments:arguments];
-        [arguments release];
-        
-        int status = -1;
-        @try {
-            [task launch];
-            [task waitUntilExit];
-            status = [task terminationStatus];
-        }
-        @catch (id e) {}
-        [task release];
-        
-        if (0 == status)
-            output = [NSData dataWithContentsOfFile:outputPath 
options:NSUncachedRead error:NULL];
-        
-        [fm removeItemAtPath:outputPath error:NULL];
-    }
-    
-    [fm release];
-    
-    return output;
-}
-
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to