/* 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 */ 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 */ return synctex_NO; } ++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 (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; } else if(!*rhs) {/* rhs is at the end of the string but not lhs */ return synctex_NO; } ++lhs; ++rhs; goto next_character; }
/* Compare two file names, windows is sometimes case insensitive... */ synctex_bool_t _synctex_is_equivalent_file_name(const char *lhs, const char *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. */ next_character: 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 */ return synctex_NO; } else if(toupper(*lhs) != toupper(*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; } else if(!*rhs) {/* rhs is at the end of the string but not lhs */ return synctex_NO; } ++lhs; ++rhs; goto next_character; # else return 0 == strcmp(lhs,rhs)?synctex_YES:synctex_NO; # endif }
const char * synctex_ignore_leading_dot_slash(const char * name) { while(SYNCTEX_IS_DOT(*name) && SYNCTEX_IS_PATH_SEPARATOR(name[1])) { name += 2; while (SYNCTEX_IS_PATH_SEPARATOR(*name)) { ++name; } } return name; }
synctex_bool_t _synctex_path_is_absolute(const char * name) { if(!strlen(name)) { return synctex_NO; } # if SYNCTEX_WINDOWS if(strlen(name)>2) { return (name[1]==':' && SYNCTEX_IS_PATH_SEPARATOR(name[2]))?synctex_YES:synctex_NO; } return synctex_NO; # else return SYNCTEX_IS_PATH_SEPARATOR(name[0])?synctex_YES:synctex_NO; # endif }
synctex_bool_t synctex_ignore_leading_dot_slash_in_path(const char ** name_ref) { 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)[1])) { ++(*name_ref); } } while(SYNCTEX_IS_DOT((*name_ref)[0]) && SYNCTEX_IS_PATH_SEPARATOR((*name_ref)[1])); return synctex_YES; } return synctex_NO; }
/* We do not take care of UTF-8 */ const char * _synctex_last_path_component(const char * name) { const char * c = name+strlen(name); if(c>name) { if(!SYNCTEX_IS_PATH_SEPARATOR(*c)) { do { --c; if(SYNCTEX_IS_PATH_SEPARATOR(*c)) { return c+1; } } while(c>name); } return c;/* the last path component is the void string*/ } return c; }
/* 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); # ifdef 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. */ next_character: 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 */ return synctex_NO; } else if(toupper(*lhs) != toupper(*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; } else if(!*rhs) {/* rhs is at the end of the string but not lhs */ return synctex_NO; } ++lhs; ++rhs; goto next_character; # else if (lhs[0] == '/' && rhs[0] == '/') { /* for absolute paths compare the real paths */ char *lhsreal = realpath(lhs, 0); char *rhsreal = realpath(rhs, 0); synctex_bool_t result = lhsreal && rhsreal && 0 == strcmp(lhsreal,rhsreal)?synctex_YES:synctex_NO; free (lhsreal); free (rhsreal); return result; } else { return 0 == strcmp(lhs,rhs)?synctex_YES:synctex_NO; } # endif }
/* 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; }