Revision: 4771
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4771&view=rev
Author:   hofman
Date:     2008-10-11 18:12:35 +0000 (Sat, 11 Oct 2008)

Log Message:
-----------
Add fix for synctex with filename containing spaces to synctex parser

Modified Paths:
--------------
    trunk/SKPDFSynchronizer.m
    trunk/vendorsrc/jeromelaurens/synctex-parser/synctex_parser.m

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2008-10-11 09:57:19 UTC (rev 4770)
+++ trunk/SKPDFSynchronizer.m   2008-10-11 18:12:35 UTC (rev 4771)
@@ -579,14 +579,6 @@
     if (scanner)
         synctex_scanner_free(scanner);
     scanner = synctex_scanner_new_with_output_file([theFileName 
fileSystemRepresentation]);
-    if (scanner == NULL) {
-        // synctex has the weird bug where it adds quotes around file names 
contining spaces
-        NSString *quotedFileName = [[theFileName lastPathComponent] 
stringByDeletingPathExtension];
-        quotedFileName = [NSString stringWithFormat:@"\"[EMAIL PROTECTED]"", 
quotedFileName];
-        quotedFileName = [[theFileName stringByDeletingLastPathComponent] 
stringByAppendingPathComponent:quotedFileName];
-        quotedFileName = [quotedFileName 
stringByAppendingPathExtension:[theFileName pathExtension]];
-        scanner = synctex_scanner_new_with_output_file([quotedFileName 
fileSystemRepresentation]);
-    }
     if (scanner) {
         [self setSyncFileName:[self 
sourceFileForFileSystemRepresentation:synctex_scanner_get_synctex(scanner) 
defaultExtension:nil]];
         if (filenames)

Modified: trunk/vendorsrc/jeromelaurens/synctex-parser/synctex_parser.m
===================================================================
--- trunk/vendorsrc/jeromelaurens/synctex-parser/synctex_parser.m       
2008-10-11 09:57:19 UTC (rev 4770)
+++ trunk/vendorsrc/jeromelaurens/synctex-parser/synctex_parser.m       
2008-10-11 18:12:35 UTC (rev 4771)
@@ -1086,6 +1086,7 @@
 synctex_status_t _synctex_scan_sheet(synctex_scanner_t scanner, synctex_node_t 
parent);
 synctex_status_t _synctex_scan_content(synctex_scanner_t scanner);
 void _synctex_strip_last_path_extension(char * string);
+void _synctex_quote_last_path_component(char * string);
 synctex_scanner_t _synctex_scanner_new_with_contents_of_file(const char * 
name);
 int synctex_scanner_pre_x_offset(synctex_scanner_t scanner);
 int synctex_scanner_pre_y_offset(synctex_scanner_t scanner);
@@ -2523,6 +2524,29 @@
        }
 }
 
+/*  put double quotes around the last path component of the given string */
+void _synctex_quote_last_path_component(char * string) {
+       if(NULL != string){
+               char * last_component = NULL;
+               char * next = NULL;
+               char * end = string + strlen(string);
+               /* first we find the last path component */
+               if(NULL == (last_component = strstr(string,"/"))){
+                       last_component = string;
+               } else {
+                       ++last_component;
+                       while(NULL != (next = strstr(last_component,"/"))){
+                               last_component = next+1;
+                       }
+               }
+               /* then we shift the last components and add double-quotes */
+               memmove(last_component+1, last_component, end-last_component);
+               last_component[0] = '"';
+               end[1] = '"';
+               end[2] = '\0';
+       }
+}
+
 /*  Where the synctex scanner is created.
  *  output is the full or relative path of the uncompressed or compressed 
synctex file.
  *  On error, NULL is returned.
@@ -2565,7 +2589,29 @@
                }
                scanner = _synctex_scanner_new_with_contents_of_file(synctex);
                if(NULL == scanner) {
-                       goto return_on_error;
+                       /*  including the terminating character */
+                       if(synctex != strcpy(synctex,output)) {
+                               fprintf(stderr,"!  
synctex_scanner_new_with_output_file: Copy problem\n");
+                               goto return_on_error;
+                       }
+                       /*  remove the last path extension if any and add 
double-quotes around the file name */
+                       _synctex_strip_last_path_extension(synctex);
+                       _synctex_quote_last_path_component(synctex);
+                       if(synctex != strcat(synctex,synctex_suffix)){
+                               fprintf(stderr,"!  
synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix 
'%s')\n",synctex_suffix);
+                               goto return_on_error;
+                       }
+                       scanner = 
_synctex_scanner_new_with_contents_of_file(synctex);
+                       if(NULL == scanner) {
+                               if(synctex != 
strcat(synctex,synctex_suffix_gz)){
+                                       fprintf(stderr,"!  
synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix 
'%s')\n",synctex_suffix_gz);
+                                       goto return_on_error;
+                               }
+                               scanner = 
_synctex_scanner_new_with_contents_of_file(synctex);
+                               if(NULL == scanner) {
+                                       goto return_on_error;
+                               }
+                       }
                }
        }
        /* make a private copy of output for the scanner */


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to