X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=cut-n-paste%2Fsynctex%2Fsynctex_parser_utils.c;h=0aef5777dbbade95207a79c41624ded25b36a850;hb=3421b3c4a7f7fbfb4b50b6d0918fc3fe14ed5c1f;hp=ee0544389ce650bda1acc0709be40550e95de67c;hpb=d7f24a354ba037541b40f562c02cccf67c3bf59c;p=evince.git diff --git a/cut-n-paste/synctex/synctex_parser_utils.c b/cut-n-paste/synctex/synctex_parser_utils.c index ee054438..0aef5777 100644 --- a/cut-n-paste/synctex/synctex_parser_utils.c +++ b/cut-n-paste/synctex/synctex_parser_utils.c @@ -1,12 +1,11 @@ /* -Copyright (c) 2008, 2009, 2010 , 2011 jerome DOT laurens AT u-bourgogne DOT fr +Copyright (c) 2008, 2009 jerome DOT laurens AT u-bourgogne DOT fr This file is part of the SyncTeX package. -Latest Revision: Fri Mar 11 07:39:12 UTC 2011 - -Version: 1.13 +Latest Revision: Wed Nov 4 11:52:35 UTC 2009 +Version: 1.9 See synctex_parser_readme.txt for more details License: @@ -295,115 +294,121 @@ char * _synctex_merge_strings(const char * first,...) { * There is a list of possible filenames from which we return the most recent one and try to remove all the others. * With two runs of pdftex or xetex we are sure the the synctex file is really the most appropriate. */ -int _synctex_get_name(const char * output, const char * build_directory, char ** synctex_name_ref, synctex_io_mode_t * io_mode_ref) +int _synctex_get_name(const char * output, const char * build_directory, char ** synctex_name_ref, synctex_compress_mode_t * compress_mode_ref) { - if(output && synctex_name_ref && io_mode_ref) { + if(output && synctex_name_ref && compress_mode_ref) { +# define synctex_name (*synctex_name_ref) +# define compress_mode (*compress_mode_ref) /* If output is already absolute, we just have to manage the quotes and the compress mode */ + const char * basename = NULL; /* base name of output*/ size_t size = 0; - char * synctex_name = NULL; - synctex_io_mode_t io_mode = *io_mode_ref; - const char * base_name = _synctex_last_path_component(output); /* do not free, output is the owner. base name of output*/ + /* Initialize the return values. */ + synctex_name = NULL; + compress_mode = synctex_compress_mode_none; + basename = _synctex_last_path_component(output); /* do not free, output is the owner. */ /* Do we have a real base name ? */ - if(strlen(base_name)>0) { + if((size = strlen(basename))>0) { /* Yes, we do. */ const char * temp = NULL; - char * core_name = NULL; /* base name of output without path extension. */ - char * dir_name = NULL; /* dir name of output */ - char * quoted_core_name = NULL; - char * basic_name = NULL; - char * gz_name = NULL; - char * quoted_name = NULL; - char * quoted_gz_name = NULL; - char * build_name = NULL; - char * build_gz_name = NULL; - char * build_quoted_name = NULL; - char * build_quoted_gz_name = NULL; + char * corename = NULL; /* base name of output without path extension. */ + char * dirname = NULL; /* dir name of output */ + char * quoted_corename = NULL; + char * none = NULL; + char * gz = NULL; + char * quoted = NULL; + char * quoted_gz = NULL; + char * build = NULL; + char * build_gz = NULL; + char * build_quoted = NULL; + char * build_quoted_gz = NULL; struct stat buf; - time_t the_time = 0; - /* Create core_name: let temp point to the dot before the path extension of base_name; + time_t time = 0; + /* Create corename: let temp point to the dot before the path extension of basename; * We start form the \0 terminating character and scan the string upward until we find a dot. - * The leading dot is not accepted. */ - if((temp = strrchr(base_name,'.')) && (size = temp - base_name)>0) { - /* There is a dot and it is not at the leading position */ - if(NULL == (core_name = (char *)malloc(size+1))) { + * The first dot is not accepted. */ + temp = strrchr(basename,'.'); + size = temp - basename; + if(size>0) { + /* dot properly found, now create corename */ + if(NULL == (corename = (char *)malloc(size+1))) { _synctex_error("! _synctex_get_name: Memory problem 1"); return -1; } - if(core_name != strncpy(core_name,base_name,size)) { + if(corename != strncpy(corename,basename,size)) { _synctex_error("! _synctex_get_name: Copy problem 1"); - free(core_name); - dir_name = NULL; + free(corename); + dirname = NULL; return -2; } - core_name[size] = '\0'; + corename[size] = '\0'; } else { /* There is no path extension, - * Just make a copy of base_name */ - core_name = _synctex_merge_strings(base_name); + * Just make a copy of basename */ + corename = _synctex_merge_strings(basename); } - /* core_name is properly set up, owned by "self". */ - /* creating dir_name. */ - size = strlen(output)-strlen(base_name); + /* corename is properly set up, owned by "self". */ + /* creating dirname. */ + size = strlen(output)-strlen(basename); if(size>0) { /* output contains more than one path component */ - if(NULL == (dir_name = (char *)malloc(size+1))) { + if(NULL == (dirname = (char *)malloc(size+1))) { _synctex_error("! _synctex_get_name: Memory problem"); - free(core_name); - dir_name = NULL; + free(corename); + dirname = NULL; return -1; } - if(dir_name != strncpy(dir_name,output,size)) { + if(dirname != strncpy(dirname,output,size)) { _synctex_error("! _synctex_get_name: Copy problem"); - free(dir_name); - dir_name = NULL; - free(core_name); - dir_name = NULL; + free(dirname); + dirname = NULL; + free(corename); + dirname = NULL; return -2; } - dir_name[size] = '\0'; + dirname[size] = '\0'; } - /* dir_name is properly set up. It ends with a path separator, if non void. */ - /* creating quoted_core_name. */ - if(strchr(core_name,' ')) { - quoted_core_name = _synctex_merge_strings("\"",core_name,"\""); + /* dirname is properly set up. It ends with a path separator, if non void. */ + /* creating quoted_corename. */ + if(strchr(corename,' ')) { + quoted_corename = _synctex_merge_strings("\"",corename,"\""); } - /* quoted_core_name is properly set up. */ - if(dir_name &&strlen(dir_name)>0) { - basic_name = _synctex_merge_strings(dir_name,core_name,synctex_suffix,NULL); - if(quoted_core_name && strlen(quoted_core_name)>0) { - quoted_name = _synctex_merge_strings(dir_name,quoted_core_name,synctex_suffix,NULL); + /* quoted_corename is properly set up. */ + if(dirname &&strlen(dirname)>0) { + none = _synctex_merge_strings(dirname,corename,synctex_suffix,NULL); + if(quoted_corename && strlen(quoted_corename)>0) { + quoted = _synctex_merge_strings(dirname,quoted_corename,synctex_suffix,NULL); } } else { - basic_name = _synctex_merge_strings(core_name,synctex_suffix,NULL); - if(quoted_core_name && strlen(quoted_core_name)>0) { - quoted_name = _synctex_merge_strings(quoted_core_name,synctex_suffix,NULL); + none = _synctex_merge_strings(corename,synctex_suffix,NULL); + if(quoted_corename && strlen(quoted_corename)>0) { + quoted = _synctex_merge_strings(quoted_corename,synctex_suffix,NULL); } } if(!_synctex_path_is_absolute(output) && build_directory && (size = strlen(build_directory))) { temp = build_directory + size - 1; if(_synctex_path_is_absolute(temp)) { - build_name = _synctex_merge_strings(build_directory,basic_name,NULL); - if(quoted_core_name && strlen(quoted_core_name)>0) { - build_quoted_name = _synctex_merge_strings(build_directory,quoted_name,NULL); + build = _synctex_merge_strings(build_directory,none,NULL); + if(quoted_corename && strlen(quoted_corename)>0) { + build_quoted = _synctex_merge_strings(build_directory,quoted,NULL); } } else { - build_name = _synctex_merge_strings(build_directory,"/",basic_name,NULL); - if(quoted_core_name && strlen(quoted_core_name)>0) { - build_quoted_name = _synctex_merge_strings(build_directory,"/",quoted_name,NULL); + build = _synctex_merge_strings(build_directory,"/",none,NULL); + if(quoted_corename && strlen(quoted_corename)>0) { + build_quoted = _synctex_merge_strings(build_directory,"/",quoted,NULL); } } } - if(basic_name) { - gz_name = _synctex_merge_strings(basic_name,synctex_suffix_gz,NULL); + if(none) { + gz = _synctex_merge_strings(none,synctex_suffix_gz,NULL); } - if(quoted_name) { - quoted_gz_name = _synctex_merge_strings(quoted_name,synctex_suffix_gz,NULL); + if(quoted) { + quoted_gz = _synctex_merge_strings(quoted,synctex_suffix_gz,NULL); } - if(build_name) { - build_gz_name = _synctex_merge_strings(build_name,synctex_suffix_gz,NULL); + if(build) { + build_gz = _synctex_merge_strings(build,synctex_suffix_gz,NULL); } - if(build_quoted_name) { - build_quoted_gz_name = _synctex_merge_strings(build_quoted_name,synctex_suffix_gz,NULL); + if(build_quoted) { + build_quoted_gz = _synctex_merge_strings(build_quoted,synctex_suffix_gz,NULL); } /* All the others names are properly set up... */ /* retain the most recently modified file */ @@ -412,24 +417,22 @@ int _synctex_get_name(const char * output, const char * build_directory, char ** if (stat(FILENAME, &buf)) { \ free(FILENAME);\ FILENAME = NULL;\ - } else if (buf.st_mtime>the_time) { \ - the_time=buf.st_mtime; \ - synctex_name = FILENAME; \ - if (COMPRESS_MODE) { \ - io_mode |= synctex_io_gz_mask; \ - } else { \ - io_mode &= ~synctex_io_gz_mask; \ - } \ + } else { \ + if(buf.st_mtime>time) { \ + time=buf.st_mtime; \ + synctex_name = FILENAME; \ + compress_mode = COMPRESS_MODE; \ + } \ } \ } - TEST(basic_name,synctex_DONT_COMPRESS); - TEST(gz_name,synctex_COMPRESS); - TEST(quoted_name,synctex_DONT_COMPRESS); - TEST(quoted_gz_name,synctex_COMPRESS); - TEST(build_name,synctex_DONT_COMPRESS); - TEST(build_gz_name,synctex_COMPRESS); - TEST(build_quoted_name,synctex_DONT_COMPRESS); - TEST(build_quoted_gz_name,synctex_COMPRESS); + TEST(none,synctex_compress_mode_none); + TEST(gz,synctex_compress_mode_gz); + TEST(quoted,synctex_compress_mode_none); + TEST(quoted_gz,synctex_compress_mode_gz); + TEST(build,synctex_compress_mode_none); + TEST(build_gz,synctex_compress_mode_gz); + TEST(build_quoted,synctex_compress_mode_none); + TEST(build_quoted_gz,synctex_compress_mode_gz); # undef TEST /* Free all the intermediate filenames, except the one that will be used as returned value. */ # define CLEAN_AND_REMOVE(FILENAME) \ @@ -439,27 +442,21 @@ int _synctex_get_name(const char * output, const char * build_directory, char ** free(FILENAME);\ FILENAME = NULL;\ } - CLEAN_AND_REMOVE(basic_name); - CLEAN_AND_REMOVE(gz_name); - CLEAN_AND_REMOVE(quoted_name); - CLEAN_AND_REMOVE(quoted_gz_name); - CLEAN_AND_REMOVE(build_name); - CLEAN_AND_REMOVE(build_gz_name); - CLEAN_AND_REMOVE(build_quoted_name); - CLEAN_AND_REMOVE(build_quoted_gz_name); + CLEAN_AND_REMOVE(none); + CLEAN_AND_REMOVE(gz); + CLEAN_AND_REMOVE(quoted); + CLEAN_AND_REMOVE(quoted_gz); + CLEAN_AND_REMOVE(build); + CLEAN_AND_REMOVE(build_gz); + CLEAN_AND_REMOVE(build_quoted); + CLEAN_AND_REMOVE(build_quoted_gz); # undef CLEAN_AND_REMOVE - /* set up the returned values */ - * synctex_name_ref = synctex_name; - * io_mode_ref = io_mode; return 0; } return -1;/* bad argument */ +# undef synctex_name +# undef compress_mode } return -2; } -const char * _synctex_get_io_mode_name(synctex_io_mode_t io_mode) { - static const char * synctex_io_modes[4] = {"r","rb","a","ab"}; - unsigned index = (io_mode & synctex_io_gz_mask) + 2 * (io_mode & synctex_io_append_mask); - return synctex_io_modes[index]; -}