summaryrefslogtreecommitdiff
path: root/server/synctex_parser_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/synctex_parser_utils.c')
-rw-r--r--server/synctex_parser_utils.c99
1 files changed, 66 insertions, 33 deletions
diff --git a/server/synctex_parser_utils.c b/server/synctex_parser_utils.c
index d5107ec..0e9fd0e 100644
--- a/server/synctex_parser_utils.c
+++ b/server/synctex_parser_utils.c
@@ -1,11 +1,11 @@
-/*
+/*
Copyright (c) 2008, 2009, 2010 , 2011 jerome DOT laurens AT u-bourgogne DOT fr
This file is part of the SyncTeX package.
Latest Revision: Tue Jun 14 08:23:30 UTC 2011
-Version: 1.16
+Version: 1.18
See synctex_parser_readme.txt for more details
@@ -32,9 +32,9 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE
-Except as contained in this notice, the name of the copyright holder
-shall not be used in advertising or otherwise to promote the sale,
-use or other dealings in this Software without prior written
+Except as contained in this notice, the name of the copyright holder
+shall not be used in advertising or otherwise to promote the sale,
+use or other dealings in this Software without prior written
authorization from the copyright holder.
*/
@@ -57,12 +57,17 @@ authorization from the copyright holder.
#define SYNCTEX_WINDOWS 1
#endif
+#if defined(__OS2__)
+#define SYNCTEX_OS2 1
+#endif
+
#ifdef _WIN32_WINNT_WINXP
#define SYNCTEX_RECENT_WINDOWS 1
#endif
#ifdef SYNCTEX_WINDOWS
#include <windows.h>
+#include <shlwapi.h> /* Use shlwapi.lib */
#endif
void *_synctex_malloc(size_t size) {
@@ -111,6 +116,15 @@ void _synctex_strip_last_path_extension(char * string) {
if(NULL != string){
char * last_component = NULL;
char * last_extension = NULL;
+# if defined(SYNCTEX_WINDOWS)
+ last_component = PathFindFileName(string);
+ last_extension = PathFindExtension(string);
+ if(last_extension == NULL)return;
+ if(last_component == NULL)last_component = string;
+ if(last_extension>last_component){/* filter out paths like "my/dir/.hidden" */
+ last_extension[0] = '\0';
+ }
+# else
char * next = NULL;
/* first we find the last path component */
if(NULL == (last_component = strstr(string,"/"))){
@@ -121,12 +135,12 @@ void _synctex_strip_last_path_extension(char * string) {
last_component = next+1;
}
}
-# ifdef SYNCTEX_WINDOWS
- /* On Windows, the '\' is also a path separator. */
+# if defined(SYNCTEX_OS2)
+ /* On OS2, the '\' is also a path separator. */
while((next = strstr(last_component,"\\"))){
last_component = next+1;
}
-# endif
+# endif /* SYNCTEX_OS2 */
/* then we find the last path extension */
if((last_extension = strstr(last_component,"."))){
++last_extension;
@@ -138,39 +152,61 @@ void _synctex_strip_last_path_extension(char * string) {
last_extension[0] = '\0';
}
}
+# endif /* SYNCTEX_WINDOWS */
}
}
-const char * synctex_ignore_leading_dot_slash(const char * name)
+synctex_bool_t synctex_ignore_leading_dot_slash_in_path(const char ** name_ref)
{
- while(SYNCTEX_IS_DOT(*name) && SYNCTEX_IS_PATH_SEPARATOR(name[1])) {
- name += 2;
- while (SYNCTEX_IS_PATH_SEPARATOR(*name)) {
- ++name;
- }
+ if (SYNCTEX_IS_DOT((*name_ref)[0]) && SYNCTEX_IS_PATH_SEPARATOR((*name_ref)[1])) {
+ do {
+ (*name_ref) += 2;
+ while (SYNCTEX_IS_PATH_SEPARATOR((*name_ref)[0])) {
+ ++(*name_ref);
+ }
+ } while(SYNCTEX_IS_DOT((*name_ref)[0]) && SYNCTEX_IS_PATH_SEPARATOR((*name_ref)[1]));
+ return synctex_YES;
}
- return name;
+ return synctex_NO;
+}
+
+/* The base name is necessary to deal with the 2011 file naming convention...
+ * path is a '\0' terminated string
+ * The return value is the trailing part of the argument,
+ * just following the first occurrence of the regexp pattern "[^|/|\].[\|/]+".*/
+const char * _synctex_base_name(const char *path) {
+ const char * ptr = path;
+ do {
+ if (synctex_ignore_leading_dot_slash_in_path(&ptr)) {
+ return ptr;
+ }
+ do {
+ if (!*(++ptr)) {
+ return path;
+ }
+ } while (!SYNCTEX_IS_PATH_SEPARATOR(*ptr));
+ } while (*(++ptr));
+ return path;
}
/* Compare two file names, windows is sometimes case insensitive... */
synctex_bool_t _synctex_is_equivalent_file_name(const char *lhs, const char *rhs) {
/* Remove the leading regex '(\./+)*' in both rhs and lhs */
- lhs = synctex_ignore_leading_dot_slash(lhs);
- rhs = synctex_ignore_leading_dot_slash(rhs);
-# if SYNCTEX_WINDOWS
- /* On Windows, filename should be compared case insensitive.
- * The characters '/' and '\' are both valid path separators.
- * There will be a very serious problem concerning UTF8 because
- * not all the characters must be toupper...
- * I would like to have URL's instead of filenames. */
+ synctex_ignore_leading_dot_slash_in_path(&lhs);
+ synctex_ignore_leading_dot_slash_in_path(&rhs);
next_character:
- if(SYNCTEX_IS_PATH_SEPARATOR(*lhs)) {/* lhs points to a path separator */
- if(!SYNCTEX_IS_PATH_SEPARATOR(*rhs)) {/* but not rhs */
+ if (SYNCTEX_IS_PATH_SEPARATOR(*lhs)) {/* lhs points to a path separator */
+ if (!SYNCTEX_IS_PATH_SEPARATOR(*rhs)) {/* but not rhs */
return synctex_NO;
}
- } else if(SYNCTEX_IS_PATH_SEPARATOR(*rhs)) {/* rhs points to a path separator but not lhs */
+ ++lhs;
+ ++rhs;
+ synctex_ignore_leading_dot_slash_in_path(&lhs);
+ synctex_ignore_leading_dot_slash_in_path(&rhs);
+ goto next_character;
+ } else if (SYNCTEX_IS_PATH_SEPARATOR(*rhs)) {/* rhs points to a path separator but not lhs */
return synctex_NO;
- } else if(toupper(*lhs) != toupper(*rhs)){/* uppercase do not match */
+ } else if (SYNCTEX_ARE_PATH_CHARACTERS_EQUAL(*lhs,*rhs)){/* uppercase do not match */
return synctex_NO;
} else if (!*lhs) {/* lhs is at the end of the string */
return *rhs ? synctex_NO : synctex_YES;
@@ -180,16 +216,13 @@ next_character:
++lhs;
++rhs;
goto next_character;
-# else
- return 0 == strcmp(lhs,rhs)?synctex_YES:synctex_NO;
-# endif
}
synctex_bool_t _synctex_path_is_absolute(const char * name) {
if(!strlen(name)) {
return synctex_NO;
}
-# if SYNCTEX_WINDOWS
+# if defined(SYNCTEX_WINDOWS) || defined(SYNCTEX_OS2)
if(strlen(name)>2) {
return (name[1]==':' && SYNCTEX_IS_PATH_SEPARATOR(name[2]))?synctex_YES:synctex_NO;
}
@@ -302,7 +335,7 @@ char * _synctex_merge_strings(const char * first,...) {
_synctex_error("! _synctex_merge_strings: Memory problem");
return NULL;
}
- return NULL;
+ return NULL;
}
/* The purpose of _synctex_get_name is to find the name of the synctex file.
@@ -473,7 +506,7 @@ int _synctex_get_name(const char * output, const char * build_directory, char **
}
const char * _synctex_get_io_mode_name(synctex_io_mode_t io_mode) {
- static const char * synctex_io_modes[4] = {"r","rb","a","ab"};
+ static const char * synctex_io_modes[4] = {"r","rb","a","ab"};
unsigned index = ((io_mode & synctex_io_gz_mask)?1:0) + ((io_mode & synctex_io_append_mask)?2:0);// bug pointed out by Jose Alliste
return synctex_io_modes[index];
}