| 1 |
/* |
| 2 |
Copyright (c) 2008-2017 jerome DOT laurens AT u-bourgogne DOT fr |
| 3 |
|
| 4 |
This file is part of the __SyncTeX__ package. |
| 5 |
|
| 6 |
[//]: # (Latest Revision: Fri Jul 14 16:20:41 UTC 2017) |
| 7 |
[//]: # (Version: 1.21) |
| 8 |
|
| 9 |
See `synctex_parser_readme.md` for more details |
| 10 |
|
| 11 |
## License |
| 12 |
|
| 13 |
Permission is hereby granted, free of charge, to any person |
| 14 |
obtaining a copy of this software and associated documentation |
| 15 |
files (the "Software"), to deal in the Software without |
| 16 |
restriction, including without limitation the rights to use, |
| 17 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 18 |
copies of the Software, and to permit persons to whom the |
| 19 |
Software is furnished to do so, subject to the following |
| 20 |
conditions: |
| 21 |
|
| 22 |
The above copyright notice and this permission notice shall be |
| 23 |
included in all copies or substantial portions of the Software. |
| 24 |
|
| 25 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 27 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 29 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 30 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 31 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 32 |
OTHER DEALINGS IN THE SOFTWARE |
| 33 |
|
| 34 |
Except as contained in this notice, the name of the copyright holder |
| 35 |
shall not be used in advertising or otherwise to promote the sale, |
| 36 |
use or other dealings in this Software without prior written |
| 37 |
authorization from the copyright holder. |
| 38 |
|
| 39 |
*/ |
| 40 |
|
| 41 |
#ifndef SYNCTEX_PARSER_UTILS_H |
| 42 |
#define SYNCTEX_PARSER_UTILS_H |
| 43 |
|
| 44 |
/* The utilities declared here are subject to conditional implementation. |
| 45 |
* All the operating system special stuff goes here. |
| 46 |
* The problem mainly comes from file name management: path separator, encoding... |
| 47 |
*/ |
| 48 |
|
| 49 |
#include "synctex_version.h" |
| 50 |
|
| 51 |
typedef int synctex_bool_t; |
| 52 |
# define synctex_YES (0==0) |
| 53 |
# define synctex_NO (0==1) |
| 54 |
|
| 55 |
# define synctex_ADD_QUOTES -1 |
| 56 |
# define synctex_COMPRESS -1 |
| 57 |
# define synctex_DONT_ADD_QUOTES 0 |
| 58 |
# define synctex_DONT_COMPRESS 0 |
| 59 |
|
| 60 |
#ifndef __SYNCTEX_PARSER_UTILS__ |
| 61 |
# define __SYNCTEX_PARSER_UTILS__ |
| 62 |
|
| 63 |
#include <stdlib.h> |
| 64 |
|
| 65 |
#ifdef __cplusplus |
| 66 |
extern "C" { |
| 67 |
#endif |
| 68 |
|
| 69 |
# if defined(_WIN32) || defined(__OS2__) |
| 70 |
# define SYNCTEX_CASE_SENSITIVE_PATH 0 |
| 71 |
# define SYNCTEX_IS_PATH_SEPARATOR(c) ('/' == c || '\\' == c) |
| 72 |
# else |
| 73 |
# define SYNCTEX_CASE_SENSITIVE_PATH 1 |
| 74 |
# define SYNCTEX_IS_PATH_SEPARATOR(c) ('/' == c) |
| 75 |
# endif |
| 76 |
|
| 77 |
# if defined(_WIN32) || defined(__OS2__) |
| 78 |
# define SYNCTEX_IS_DOT(c) ('.' == c) |
| 79 |
# else |
| 80 |
# define SYNCTEX_IS_DOT(c) ('.' == c) |
| 81 |
# endif |
| 82 |
|
| 83 |
# if SYNCTEX_CASE_SENSITIVE_PATH |
| 84 |
# define SYNCTEX_ARE_PATH_CHARACTERS_EQUAL(left,right) (left != right) |
| 85 |
# else |
| 86 |
# define SYNCTEX_ARE_PATH_CHARACTERS_EQUAL(left,right) (toupper(left) != toupper(right)) |
| 87 |
# endif |
| 88 |
|
| 89 |
# if defined(_MSC_VER) |
| 90 |
# define SYNCTEX_ATTRIBUTE_FORMAT_PRINTF(STRING_INDEX, FIRST_TO_CHECK) ATTRIBUTE_FORMAT_PRINTF(STRING_INDEX, FIRST_TO_CHECK) |
| 91 |
# else |
| 92 |
# define SYNCTEX_ATTRIBUTE_FORMAT_PRINTF(STRING_INDEX, FIRST_TO_CHECK) __attribute__((__format__ (__printf__, (STRING_INDEX), (FIRST_TO_CHECK)))) |
| 93 |
# endif |
| 94 |
|
| 95 |
/* This custom malloc functions initializes to 0 the newly allocated memory. |
| 96 |
* There is no bzero function on windows. */ |
| 97 |
void *_synctex_malloc(size_t size); |
| 98 |
|
| 99 |
/* To balance _synctex_malloc. |
| 100 |
* ptr might be NULL. */ |
| 101 |
void _synctex_free(void * ptr); |
| 102 |
|
| 103 |
/* This is used to log some informational message to the standard error stream. |
| 104 |
* On Windows, the stderr stream is not exposed and another method is used. |
| 105 |
* The return value is the number of characters printed. */ |
| 106 |
int _synctex_error(const char * reason,...); |
| 107 |
int _synctex_debug(const char * reason,...); |
| 108 |
|
| 109 |
/* strip the last extension of the given string, this string is modified! |
| 110 |
* This function depends on the OS because the path separator may differ. |
| 111 |
* This should be discussed more precisely. */ |
| 112 |
void _synctex_strip_last_path_extension(char * string); |
| 113 |
|
| 114 |
/* Compare two file names, windows is sometimes case insensitive... |
| 115 |
* The given strings may differ stricto sensu, but represent the same file name. |
| 116 |
* It might not be the real way of doing things. |
| 117 |
* The return value is an undefined non 0 value when the two file names are equivalent. |
| 118 |
* It is 0 otherwise. */ |
| 119 |
synctex_bool_t _synctex_is_equivalent_file_name(const char *lhs, const char *rhs); |
| 120 |
|
| 121 |
/* Description forthcoming.*/ |
| 122 |
synctex_bool_t _synctex_path_is_absolute(const char * name); |
| 123 |
|
| 124 |
/* Description forthcoming...*/ |
| 125 |
const char * _synctex_last_path_component(const char * name); |
| 126 |
|
| 127 |
/* Description forthcoming...*/ |
| 128 |
const char * _synctex_base_name(const char *path); |
| 129 |
|
| 130 |
/* If the core of the last path component of src is not already enclosed with double quotes ('"') |
| 131 |
* and contains a space character (' '), then a new buffer is created, the src is copied and quotes are added. |
| 132 |
* In all other cases, no destination buffer is created and the src is not copied. |
| 133 |
* 0 on success, which means no error, something non 0 means error, mainly due to memory allocation failure, or bad parameter. |
| 134 |
* This is used to fix a bug in the first version of pdftex with synctex (1.40.9) for which names with spaces |
| 135 |
* were not managed in a standard way. |
| 136 |
* On success, the caller owns the buffer pointed to by dest_ref (is any) and |
| 137 |
* is responsible of freeing the memory when done. |
| 138 |
* The size argument is the size of the src buffer. On return the dest_ref points to a buffer sized size+2.*/ |
| 139 |
int _synctex_copy_with_quoting_last_path_component(const char * src, char ** dest_ref, size_t size); |
| 140 |
|
| 141 |
/* These are the possible extensions of the synctex file */ |
| 142 |
extern const char * synctex_suffix; |
| 143 |
extern const char * synctex_suffix_gz; |
| 144 |
|
| 145 |
typedef unsigned int synctex_io_mode_t; |
| 146 |
|
| 147 |
typedef enum { |
| 148 |
synctex_io_append_mask = 1, |
| 149 |
synctex_io_gz_mask = synctex_io_append_mask<<1 |
| 150 |
} synctex_io_mode_masks_t; |
| 151 |
|
| 152 |
typedef enum { |
| 153 |
synctex_compress_mode_none = 0, |
| 154 |
synctex_compress_mode_gz = 1 |
| 155 |
} synctex_compress_mode_t; |
| 156 |
|
| 157 |
int _synctex_get_name(const char * output, const char * build_directory, char ** synctex_name_ref, synctex_io_mode_t * io_mode_ref); |
| 158 |
|
| 159 |
/* returns the correct mode required by fopen and gzopen from the given io_mode */ |
| 160 |
const char * _synctex_get_io_mode_name(synctex_io_mode_t io_mode); |
| 161 |
|
| 162 |
synctex_bool_t synctex_ignore_leading_dot_slash_in_path(const char ** name); |
| 163 |
|
| 164 |
#ifdef __cplusplus |
| 165 |
} |
| 166 |
#endif |
| 167 |
|
| 168 |
#endif |
| 169 |
#endif /* SYNCTEX_PARSER_UTILS_H */ |