diff options
Diffstat (limited to 'cut-n-paste/synctex/synctex_parser_utils.c')
-rw-r--r-- | cut-n-paste/synctex/synctex_parser_utils.c | 174 |
1 files changed, 116 insertions, 58 deletions
diff --git a/cut-n-paste/synctex/synctex_parser_utils.c b/cut-n-paste/synctex/synctex_parser_utils.c index 62ac0ad2..c4f200d8 100644 --- a/cut-n-paste/synctex/synctex_parser_utils.c +++ b/cut-n-paste/synctex/synctex_parser_utils.c @@ -1,41 +1,40 @@ -/* -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.18 - -See synctex_parser_readme.txt for more details - -License: --------- -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -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 -authorization from the copyright holder. +/* + Copyright (c) 2008-2017 jerome DOT laurens AT u-bourgogne DOT fr + + This file is part of the __SyncTeX__ package. + + [//]: # (Latest Revision: Fri Jul 14 16:20:41 UTC 2017) + [//]: # (Version: 1.21) + + See `synctex_parser_readme.md` for more details + + ## License + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + 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 + authorization from the copyright holder. */ @@ -61,7 +60,7 @@ authorization from the copyright holder. #define SYNCTEX_OS2 1 #endif -#ifdef _WIN32_WINNT_WINXP +#if defined(_WIN32) #define SYNCTEX_RECENT_WINDOWS 1 #endif @@ -71,18 +70,25 @@ authorization from the copyright holder. #endif void *_synctex_malloc(size_t size) { - void * ptr = malloc(size); - if(ptr) { -/* There used to be a switch to use bzero because it is more secure. JL */ - memset(ptr,0, size); - } - return (void *)ptr; + void * ptr = malloc(size); + if(ptr) { + memset(ptr,0, size);/* ensures null termination of strings */ + } + return (void *)ptr; } -int _synctex_error(const char * reason,...) { - va_list arg; +void _synctex_free(void * ptr) { + if (ptr) { + free(ptr); + } +} + +#if !defined(_WIN32) +# include <syslog.h> +#endif + +int _synctex_log(int level, const char * prompt, const char * reason,va_list arg) { int result; - va_start (arg, reason); # ifdef SYNCTEX_RECENT_WINDOWS {/* This code is contributed by William Blum. As it does not work on some older computers, @@ -94,23 +100,65 @@ int _synctex_error(const char * reason,...) { JL.*/ char *buff; size_t len; - OutputDebugStringA("SyncTeX ERROR: "); + OutputDebugStringA(prompt); len = _vscprintf(reason, arg) + 1; buff = (char*)malloc( len * sizeof(char) ); - result = vsprintf(buff, reason, arg) +strlen("SyncTeX ERROR: "); + result = vsprintf(buff, reason, arg) +strlen(prompt); OutputDebugStringA(buff); OutputDebugStringA("\n"); free(buff); } +# elif SYNCTEX_USE_SYSLOG + char * buffer1 = NULL; + char * buffer2 = NULL; + openlog ("SyncTeX", LOG_CONS | LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_LOCAL0); + if (vasprintf(&buffer1,reason,arg)>=0 + && asprintf(&buffer2,"%s%s",prompt, buffer1)>=0) { + syslog (level, "%s", buffer2); + result = (int)strlen(buffer2); + } else { + syslog (level, "%s",prompt); + vsyslog(level,reason,arg); + result = (int)strlen(prompt); + } + free(buffer1); + free(buffer2); + closelog(); # else - result = fprintf(stderr,"SyncTeX ERROR: "); - result += vfprintf(stderr, reason, arg); - result += fprintf(stderr,"\n"); + FILE * where = level == LOG_ERR? stderr: stdout; + result = fputs(prompt,where); + result += vfprintf(where, reason, arg); + result += fprintf(where,"\n"); # endif - va_end (arg); return result; } +int _synctex_error(const char * reason,...) { + va_list arg; + int result; + va_start (arg, reason); +#if defined(SYNCTEX_RECENT_WINDOWS) /* LOG_ERR is not used */ + result = _synctex_log(0, "! SyncTeX Error : ", reason, arg); +#else + result = _synctex_log(LOG_ERR, "! SyncTeX Error : ", reason, arg); +#endif + va_end (arg); + return result; +} + +int _synctex_debug(const char * reason,...) { + va_list arg; + int result; + va_start (arg, reason); +#if defined(SYNCTEX_RECENT_WINDOWS) /* LOG_DEBUG is not used */ + result = _synctex_log(0, "! SyncTeX Error : ", reason, arg); +#else + result = _synctex_log(LOG_DEBUG, "! SyncTeX Error : ", reason, arg); +#endif + va_end (arg); + return result; +} + /* strip the last extension of the given string, this string is modified! */ void _synctex_strip_last_path_extension(char * string) { if(NULL != string){ @@ -250,8 +298,8 @@ const char * _synctex_last_path_component(const char * name) { } int _synctex_copy_with_quoting_last_path_component(const char * src, char ** dest_ref, size_t size) { - const char * lpc; if(src && dest_ref) { + const char * lpc; # define dest (*dest_ref) dest = NULL; /* Default behavior: no change and sucess. */ lpc = _synctex_last_path_component(src); @@ -335,7 +383,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. @@ -396,7 +444,6 @@ int _synctex_get_name(const char * output, const char * build_directory, char ** if(NULL == (dir_name = (char *)malloc(size+1))) { _synctex_error("! _synctex_get_name: Memory problem"); free(core_name); - dir_name = NULL; return -1; } if(dir_name != strncpy(dir_name,output,size)) { @@ -497,6 +544,17 @@ int _synctex_get_name(const char * output, const char * build_directory, char ** # undef CLEAN_AND_REMOVE /* set up the returned values */ * synctex_name_ref = synctex_name; + /* synctex_name won't always end in .gz, even when compressed. */ + FILE * F = fopen(synctex_name, "r"); + if (F != NULL) { + if (!feof(F) + && 31 == fgetc(F) + && !feof(F) + && 139 == fgetc(F)) { + io_mode = synctex_compress_mode_gz; + } + fclose(F); + } * io_mode_ref = io_mode; return 0; } @@ -506,7 +564,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]; } |