62 # if defined(SYNCTEX_USE_LOCAL_HEADER)
65 # define HAVE_LOCALE_H 1
66 # define HAVE_SETLOCALE 1
67 # if defined(_MSC_VER)
68 # define SYNCTEX_INLINE __inline
70 # define SYNCTEX_INLINE inline
80 #if defined(HAVE_LOCALE_H)
121 # if defined(SYNCTEX_USE_CHARINDEX)
122 # define SYNCTEX_DECLARE_CHARINDEX synctex_charindex_t char_index;
123 # define SYNCTEX_CHARINDEX(NODE) (NODE->char_index)
124 # define SYNCTEX_PRINT_CHARINDEX printf("#%i\n",SYNCTEX_CHARINDEX(node))
125 # define SYNCTEX_DECLARE_CHAR_OFFSET synctex_charindex_t charindex_offset
126 # define SYNCTEX_IMPLEMENT_CHARINDEX(NODE,CORRECTION) NODE->char_index = (synctex_charindex_t)(scanner->charindex_offset+SYNCTEX_CUR-SYNCTEX_START+(CORRECTION));
128 # define SYNCTEX_DECLARE_CHARINDEX
129 # define SYNCTEX_CHARINDEX(NODE) 0
130 # define SYNCTEX_PRINT_CHARINDEX printf("\n")
131 # define SYNCTEX_DECLARE_CHAR_OFFSET synctex_charindex_t charindex_offset
132 # define SYNCTEX_IMPLEMENT_CHARINDEX(NODE,CORRECTION)
173 # ifdef SYNCTEX_NOTHING
175 # pragma mark Abstract OBJECTS and METHODS
181 # define SYNCTEX_CAN_PERFORM(NODE,SELECTOR)\
182 (NULL!=((((NODE)->class))->SELECTOR))
187 # define SYNCTEX_MSG_SEND(NODE,SELECTOR) if (NODE && SYNCTEX_CAN_PERFORM(NODE,SELECTOR)) {\
188 (*((((NODE)->class))->SELECTOR))(NODE);\
193 # define SYNCTEX_GET(NODE,SELECTOR)((NODE && SYNCTEX_CAN_PERFORM(NODE,SELECTOR))?SYNCTEX_GETTER(NODE,SELECTOR)[0]:(NULL))
197 # define SYNCTEX_GETTER(NODE,SELECTOR)\
198 ((synctex_node_t *)((*((((NODE)->class))->SELECTOR))(NODE)))
200 # define SYNCTEX_FREE(NODE) SYNCTEX_MSG_SEND(NODE,free);
204 # define SYNCTEX_PARENT(NODE) SYNCTEX_GET(NODE,parent)
205 # define SYNCTEX_SET_PARENT(NODE,NEW_PARENT) if (NODE && NEW_PARENT && SYNCTEX_CAN_PERFORM(NODE,parent)){\
206 SYNCTEX_GETTER(NODE,parent)[0]=NEW_PARENT;\
211 # define SYNCTEX_CHILD(NODE) SYNCTEX_GET(NODE,child)
212 # define SYNCTEX_SET_CHILD(NODE,NEW_CHILD) if (NODE && NEW_CHILD){\
213 SYNCTEX_GETTER(NODE,child)[0]=NEW_CHILD;\
214 SYNCTEX_GETTER(NEW_CHILD,parent)[0]=NODE;\
219 # define SYNCTEX_SIBLING(NODE) SYNCTEX_GET(NODE,sibling)
220 # define SYNCTEX_SET_SIBLING(NODE,NEW_SIBLING) if (NODE && NEW_SIBLING) {\
221 SYNCTEX_GETTER(NODE,sibling)[0]=NEW_SIBLING;\
222 if (SYNCTEX_CAN_PERFORM(NEW_SIBLING,parent) && SYNCTEX_CAN_PERFORM(NODE,parent)) {\
223 SYNCTEX_GETTER(NEW_SIBLING,parent)[0]=SYNCTEX_GETTER(NODE,parent)[0];\
230 # define SYNCTEX_FRIEND(NODE) SYNCTEX_GET(NODE,friend)
231 # define SYNCTEX_SET_FRIEND(NODE,NEW_FRIEND) if (NODE && NEW_FRIEND){\
232 SYNCTEX_GETTER(NODE,friend)[0]=NEW_FRIEND;\
238 # define SYNCTEX_NEXT_hbox(NODE) SYNCTEX_GET(NODE,next_hbox)
239 # define SYNCTEX_SET_NEXT_hbox(NODE,NEXT_HBOX) if (NODE && NEXT_HBOX){\
240 SYNCTEX_GETTER(NODE,next_hbox)[0]=NEXT_HBOX;\
252 (*((node->
class)->sibling))(node);
272 # ifdef __SYNCTEX_WORK__
273 # include "/usr/include/zlib.h"
313 # define SYNCTEX_CUR (scanner->buffer_cur)
314 # define SYNCTEX_START (scanner->buffer_start)
315 # define SYNCTEX_END (scanner->buffer_end)
317 # ifdef SYNCTEX_NOTHING
319 # pragma mark OBJECTS, their creators and destructors.
340 # define SYNCTEX_INFO(NODE) ((*((((NODE)->class))->info))(NODE))
341 # define SYNCTEX_PAGE_IDX 0
342 # define SYNCTEX_PAGE(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_PAGE_IDX].INT
347 # define SYNCTEX_MAKE_GET(SYNCTEX_GETTER,OFFSET)\
348 synctex_node_t * SYNCTEX_GETTER (synctex_node_t node);\
349 synctex_node_t * SYNCTEX_GETTER (synctex_node_t node) {\
350 return node?(synctex_node_t *)((&((node)->implementation))+OFFSET):NULL;\
378 &_synctex_implementation_0,
379 &_synctex_implementation_1,
381 &_synctex_implementation_2,
387 #define DEFINE_synctex_new_NODE(NAME)\
388 synctex_node_t _synctex_new_##NAME(synctex_scanner_t scanner) {\
390 synctex_node_t node = _synctex_malloc(sizeof(synctex_node_##NAME##_t));\
392 SYNCTEX_IMPLEMENT_CHARINDEX(node,0);\
394 node->class = scanner->class+synctex_node_type_##NAME;\
406 # define SYNCTEX_TAG_IDX 0
407 # define SYNCTEX_LINE_IDX (SYNCTEX_TAG_IDX+1)
408 # define SYNCTEX_COLUMN_IDX (SYNCTEX_LINE_IDX+1)
409 # define SYNCTEX_HORIZ_IDX (SYNCTEX_COLUMN_IDX+1)
410 # define SYNCTEX_VERT_IDX (SYNCTEX_HORIZ_IDX+1)
411 # define SYNCTEX_WIDTH_IDX (SYNCTEX_VERT_IDX+1)
412 # define SYNCTEX_HEIGHT_IDX (SYNCTEX_WIDTH_IDX+1)
413 # define SYNCTEX_DEPTH_IDX (SYNCTEX_HEIGHT_IDX+1)
415 # define SYNCTEX_TAG(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_TAG_IDX].INT
416 # define SYNCTEX_LINE(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_LINE_IDX].INT
417 # define SYNCTEX_COLUMN(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_COLUMN_IDX].INT
418 # define SYNCTEX_HORIZ(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HORIZ_IDX].INT
419 # define SYNCTEX_VERT(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_VERT_IDX].INT
420 # define SYNCTEX_WIDTH(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_WIDTH_IDX].INT
421 # define SYNCTEX_HEIGHT(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HEIGHT_IDX].INT
422 # define SYNCTEX_DEPTH(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_DEPTH_IDX].INT
423 # define SYNCTEX_ABS_WIDTH(NODE) ((SYNCTEX_WIDTH(NODE)>0?SYNCTEX_WIDTH(NODE):-SYNCTEX_WIDTH(NODE)))
424 # define SYNCTEX_ABS_HEIGHT(NODE) ((SYNCTEX_HEIGHT(NODE)>0?SYNCTEX_HEIGHT(NODE):-SYNCTEX_HEIGHT(NODE)))
425 # define SYNCTEX_ABS_DEPTH(NODE) ((SYNCTEX_DEPTH(NODE)>0?SYNCTEX_DEPTH(NODE):-SYNCTEX_DEPTH(NODE)))
448 &_synctex_implementation_0,
449 &_synctex_implementation_1,
450 &_synctex_implementation_2,
451 &_synctex_implementation_3,
452 &_synctex_implementation_4,
461 # define SYNCTEX_MEAN_LINE_IDX (SYNCTEX_DEPTH_IDX+1)
462 # define SYNCTEX_NODE_WEIGHT_IDX (SYNCTEX_MEAN_LINE_IDX+1)
463 # define SYNCTEX_HORIZ_V_IDX (SYNCTEX_NODE_WEIGHT_IDX+1)
464 # define SYNCTEX_VERT_V_IDX (SYNCTEX_HORIZ_V_IDX+1)
465 # define SYNCTEX_WIDTH_V_IDX (SYNCTEX_VERT_V_IDX+1)
466 # define SYNCTEX_HEIGHT_V_IDX (SYNCTEX_WIDTH_V_IDX+1)
467 # define SYNCTEX_DEPTH_V_IDX (SYNCTEX_HEIGHT_V_IDX+1)
469 # define SYNCTEX_MEAN_LINE(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_MEAN_LINE_IDX].INT
470 # define SYNCTEX_NODE_WEIGHT(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_NODE_WEIGHT_IDX].INT
471 # define SYNCTEX_HORIZ_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HORIZ_V_IDX].INT
472 # define SYNCTEX_VERT_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_VERT_V_IDX].INT
473 # define SYNCTEX_WIDTH_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_WIDTH_V_IDX].INT
474 # define SYNCTEX_HEIGHT_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HEIGHT_V_IDX].INT
475 # define SYNCTEX_DEPTH_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_DEPTH_V_IDX].INT
476 # define SYNCTEX_ABS_WIDTH_V(NODE) ((SYNCTEX_WIDTH_V(NODE)>0?SYNCTEX_WIDTH_V(NODE):-SYNCTEX_WIDTH_V(NODE)))
477 # define SYNCTEX_ABS_HEIGHT_V(NODE) ((SYNCTEX_HEIGHT_V(NODE)>0?SYNCTEX_HEIGHT_V(NODE):-SYNCTEX_HEIGHT_V(NODE)))
478 # define SYNCTEX_ABS_DEPTH_V(NODE) ((SYNCTEX_DEPTH_V(NODE)>0?SYNCTEX_DEPTH_V(NODE):-SYNCTEX_DEPTH_V(NODE)))
502 &_synctex_implementation_0,
503 &_synctex_implementation_1,
504 &_synctex_implementation_2,
505 &_synctex_implementation_3,
506 &_synctex_implementation_4,
535 &_synctex_implementation_0,
537 &_synctex_implementation_1,
538 &_synctex_implementation_2,
554 &_synctex_new_void_hbox,
558 &_synctex_implementation_0,
560 &_synctex_implementation_1,
561 &_synctex_implementation_2,
579 #define SYNCTEX_IS_BOX(NODE)\
580 ((NODE->class->type == synctex_node_type_vbox)\
581 || (NODE->class->type == synctex_node_type_void_vbox)\
582 || (NODE->class->type == synctex_node_type_hbox)\
583 || (NODE->class->type == synctex_node_type_void_hbox))
585 #define SYNCTEX_HAS_CHILDREN(NODE) (NODE && SYNCTEX_CHILD(NODE))
602 &_synctex_implementation_0,
604 &_synctex_implementation_1,
605 &_synctex_implementation_2,
625 &_synctex_implementation_0,
627 &_synctex_implementation_1,
628 &_synctex_implementation_2,
658 &_synctex_implementation_0,
660 &_synctex_implementation_1,
661 &_synctex_implementation_2,
675 &_synctex_new_boundary,
679 &_synctex_implementation_0,
681 &_synctex_implementation_1,
682 &_synctex_implementation_2,
689 # define SYNCTEX_NAME_IDX (SYNCTEX_TAG_IDX+1)
690 # define SYNCTEX_NAME(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_NAME_IDX].PTR
715 &_synctex_implementation_0,
721 # define SYNCTEX_INPUT_MARK "Input:"
741 # ifdef SYNCTEX_NOTHING
743 # pragma mark Navigation
751 while(node && node->
class->
type != synctex_node_type_sheet) {
774 if (node->
class->
type == synctex_node_type_sheet) {
781 # ifdef SYNCTEX_NOTHING
789 return (((node)->
class))->type;
797 {
"Not a node",
"input",
"sheet",
"vbox",
"void vbox",
"hbox",
"void hbox",
"kern",
"glue",
"math",
"boundary"};
801 # ifdef SYNCTEX_NOTHING
803 # pragma mark SYNCTEX_LOG
806 # define SYNCTEX_LOG(NODE) SYNCTEX_MSG_SEND(NODE,log)
824 printf(
"SELF:%p",(
void *)node);
835 printf(
"%s:%i,%i:%i,%i",
842 printf(
"SELF:%p",(
void *)node);
852 printf(
"%s:%i,%i:%i,%i:%i",
860 printf(
"SELF:%p",(
void *)node);
880 printf(
"SELF:%p",(
void *)node);
900 printf(
"SELF:%p",(
void *)node);
926 printf(
"SELF:%p",(
void *)node);
935 # define SYNCTEX_DISPLAY(NODE) SYNCTEX_MSG_SEND(NODE,display)
943 printf(
"....Input:%i:%s",
963 printf(
"....[%i,%i:%i,%i:%i,%i,%i",
980 printf(
"....(%i,%i~%i*%i:%i,%i:%i,%i,%i",
999 printf(
"....v%i,%i;%i,%i:%i,%i,%i",
1014 printf(
"....h%i,%i:%i,%i:%i,%i,%i",
1029 printf(
"....glue:%i,%i:%i,%i",
1041 printf(
"....math:%i,%i:%i,%i",
1053 printf(
"....kern:%i,%i:%i,%i:%i",
1066 printf(
"....boundary:%i,%i:%i,%i",
1076 # ifdef SYNCTEX_NOTHING
1078 # pragma mark SCANNER
1094 # define SYNCTEX_STATUS_EOF 0
1096 # define SYNCTEX_STATUS_NOT_OK (SYNCTEX_STATUS_EOF+1)
1098 # define SYNCTEX_STATUS_OK (SYNCTEX_STATUS_NOT_OK+1)
1100 # define SYNCTEX_STATUS_ERROR -1
1102 # define SYNCTEX_STATUS_BAD_ARGUMENT -2
1104 # define SYNCTEX_FILE (scanner->file)
1109 # define SYNCTEX_BUFFER_MIN_SIZE 16
1110 # define SYNCTEX_BUFFER_SIZE 32768
1112 # ifdef SYNCTEX_NOTHING
1114 # pragma mark Prototypes
1148 size_t available = 0;
1149 if (NULL == scanner || NULL == size_ptr) {
1152 # define size (* size_ptr)
1157 if (
size<=available) {
1165 int already_read = 0;
1166 # if defined(SYNCTEX_USE_CHARINDEX)
1170 memmove(SYNCTEX_START, SYNCTEX_CUR, available);
1172 SYNCTEX_CUR = SYNCTEX_START + available;
1175 if (already_read>0) {
1186 }
else if (0>already_read) {
1189 const char * error_string = gzerror(
SYNCTEX_FILE, &errnum);
1190 if (Z_ERRNO == errnum) {
1194 }
else if (errnum) {
1195 _synctex_error(
"gzread error (%i:%i,%s)",already_read,errnum,error_string);
1225 size_t available = 0;
1226 if (NULL == scanner) {
1259 size_t tested_len = 0;
1260 size_t remaining_len = 0;
1261 size_t available = 0;
1262 synctex_status_t status = 0;
1263 if (NULL == scanner || NULL == the_string) {
1266 remaining_len = strlen(the_string);
1267 if (0 == remaining_len) {
1271 available = remaining_len;
1277 if (available>=remaining_len) {
1279 if (strncmp((
char *)
SYNCTEX_CUR,the_string,remaining_len)) {
1286 }
else if (strncmp((
char *)
SYNCTEX_CUR,the_string,available)) {
1292 z_off_t offset = 0L;
1294 the_string += available;
1296 remaining_len -= available;
1297 tested_len += available;
1299 if (0 == remaining_len) {
1316 offset -= available;
1322 available = remaining_len;
1340 if (available<remaining_len) {
1342 if (strncmp((
char *)
SYNCTEX_CUR,the_string,available)) {
1347 the_string += available;
1349 remaining_len -= available;
1350 tested_len += available;
1352 if (0 == remaining_len) {
1356 goto more_characters;
1359 if (strncmp((
char *)
SYNCTEX_CUR,the_string,remaining_len)) {
1384 size_t available = 0;
1385 synctex_status_t status = 0;
1386 if (NULL == scanner) {
1398 if (*ptr==
':' || *ptr==
',') {
1405 result = (int)strtol(ptr, &end, 10);
1409 * value_ref = result;
1435 size_t current_size = 0;
1436 size_t new_size = 0;
1438 size_t available = 0;
1439 synctex_status_t status = 0;
1440 if (NULL == scanner || NULL == value_ref) {
1450 if (0 == available) {
1465 if (current_size>UINT_MAX-len-1) {
1469 return UINT_MAX-len-1 - current_size;
1471 new_size = current_size+len;
1475 if ((* value_ref = realloc(* value_ref,new_size+1)) != NULL) {
1476 if (
memcpy((*value_ref)+current_size,SYNCTEX_CUR,len)) {
1477 (* value_ref)[new_size]=
'\0';
1490 goto next_character;
1495 if (current_size>UINT_MAX-len-1) {
1497 _synctex_error(
"limit reached (missing %i).",current_size-(UINT_MAX-len-1));
1500 new_size = current_size+len;
1501 if ((* value_ref = realloc(* value_ref,new_size+1)) != NULL) {
1502 if (
memcpy((*value_ref)+current_size,SYNCTEX_CUR,len)) {
1503 (* value_ref)[new_size]=
'\0';
1522 synctex_status_t status = 0;
1523 size_t available = 0;
1525 if (NULL == scanner) {
1534 if (NULL == input) {
1551 if (0 == available) {
1565 scanner->
input = input;
1566 # if SYNCTEX_VERBOSE
1586 synctex_status_t status = 0;
1587 if (NULL == scanner || NULL == name || NULL == value_ref || NULL == decoder) {
1602 return (*decoder)(scanner,value_ref);
1609 synctex_status_t status = 0;
1610 if (NULL == scanner) {
1671 synctex_status_t status = 0;
1672 char * endptr = NULL;
1674 #ifdef HAVE_SETLOCALE
1675 char * loc = setlocale(LC_NUMERIC, NULL);
1677 size_t available = 0;
1678 if (NULL == scanner || NULL == value_ref) {
1687 #ifdef HAVE_SETLOCALE
1688 setlocale(LC_NUMERIC,
"C");
1691 #ifdef HAVE_SETLOCALE
1692 setlocale(LC_NUMERIC, loc);
1706 f *= 72.27f*65536/2.54f;
1707 }
else if (status<0) {
1708 goto report_unit_error;
1710 f *= 72.27f*65536/25.4f;
1711 }
else if (status<0) {
1712 goto report_unit_error;
1715 }
else if (status<0) {
1716 goto report_unit_error;
1718 f *= 72.27f/72*65536.0f;
1719 }
else if (status<0) {
1720 goto report_unit_error;
1723 }
else if (status<0) {
1724 goto report_unit_error;
1727 }
else if (status<0) {
1728 goto report_unit_error;
1730 f *= 1238.0f/1157*65536.0f;
1731 }
else if (status<0) {
1732 goto report_unit_error;
1734 f *= 14856.0f/1157*65536;
1735 }
else if (status<0) {
1736 goto report_unit_error;
1738 f *= 685.0f/642*65536;
1739 }
else if (status<0) {
1740 goto report_unit_error;
1742 f *= 1370.0f/107*65536;
1743 }
else if (status<0) {
1744 goto report_unit_error;
1754 synctex_status_t status = 0;
1755 char * endptr = NULL;
1756 #ifdef HAVE_SETLOCALE
1757 char * loc = setlocale(LC_NUMERIC, NULL);
1759 if (NULL == scanner) {
1763 post_scriptum_not_found:
1775 goto post_scriptum_not_found;
1788 #ifdef HAVE_SETLOCALE
1789 setlocale(LC_NUMERIC,
"C");
1792 #ifdef HAVE_SETLOCALE
1793 setlocale(LC_NUMERIC, loc);
1796 _synctex_error(
"bad magnification in the post scriptum, a float was expected.");
1799 if (scanner->
unit<=0) {
1800 _synctex_error(
"bad magnification in the post scriptum, a positive float was expected.");
1807 report_record_problem:
1820 goto report_record_problem;
1831 goto report_record_problem;
1843 if (NULL == scanner) {
1877 case synctex_node_type_hbox:
1897 # ifdef __DARWIN_UNIX03
1901 if (NULL == node || node->
class->
type != synctex_node_type_hbox) {
1910 }
else if (h>itsTop) {
1919 }
else if (h>itsTop) {
1929 # define SYNCTEX_CHAR_BEGIN_SHEET '{'
1930 # define SYNCTEX_CHAR_END_SHEET '}'
1931 # define SYNCTEX_CHAR_BEGIN_VBOX '['
1932 # define SYNCTEX_CHAR_END_VBOX ']'
1933 # define SYNCTEX_CHAR_BEGIN_HBOX '('
1934 # define SYNCTEX_CHAR_END_HBOX ')'
1935 # define SYNCTEX_CHAR_ANCHOR '!'
1936 # define SYNCTEX_CHAR_VOID_VBOX 'v'
1937 # define SYNCTEX_CHAR_VOID_HBOX 'h'
1938 # define SYNCTEX_CHAR_KERN 'k'
1939 # define SYNCTEX_CHAR_GLUE 'g'
1940 # define SYNCTEX_CHAR_MATH '$'
1941 # define SYNCTEX_CHAR_BOUNDARY 'x'
1943 # define SYNCTEX_RETURN(STATUS) return STATUS;
1951 unsigned int depth = 0;
1967 goto scan_next_line;
1993 int friend_index = 0;
1995 synctex_status_t status = 0;
1996 size_t available = 0;
1997 if ((NULL == scanner) || (NULL == sheet)) {
2006 # define SYNCTEX_DECODE_FAILED(WHAT) \
2007 (_synctex_decode_int(scanner,&(info[WHAT].INT))<SYNCTEX_STATUS_OK)
2055 if (NULL == parent || parent->
class->
type != synctex_node_type_sheet
2060 # if SYNCTEX_VERBOSE
2092 if (status<SYNCTEX_STATUS_OK && available>0){
2108 if (NULL != parent && parent->
class->
type == synctex_node_type_vbox) {
2109 #define SYNCTEX_UPDATE_BOX_FRIEND(NODE)\
2110 friend_index = ((SYNCTEX_INFO(NODE))[SYNCTEX_TAG_IDX].INT+(SYNCTEX_INFO(NODE))[SYNCTEX_LINE_IDX].INT)%(scanner->number_of_lists);\
2111 SYNCTEX_SET_FRIEND(NODE,(scanner->lists_of_friends)[friend_index]);\
2112 (scanner->lists_of_friends)[friend_index] = NODE;
2126 # if SYNCTEX_VERBOSE
2135 if ((parent) && parent->
class->
type == synctex_node_type_hbox) {
2139 unsigned int node_weight = 0;
2140 unsigned int cumulated_line_numbers = 0;
2161 if (NULL == child) {
2178 # if SYNCTEX_VERBOSE
2197 #define SYNCTEX_UPDATE_FRIEND(NODE)\
2198 friend_index = (info[SYNCTEX_TAG_IDX].INT+info[SYNCTEX_LINE_IDX].INT)%(scanner->number_of_lists);\
2199 SYNCTEX_SET_FRIEND(NODE,(scanner->lists_of_friends)[friend_index]);\
2200 (scanner->lists_of_friends)[friend_index] = NODE;
2202 # if SYNCTEX_VERBOSE
2211 if (NULL != (child = _synctex_new_void_hbox(scanner))
2228 # if SYNCTEX_VERBOSE
2237 if (NULL != (child = _synctex_new_kern(scanner))
2252 # if SYNCTEX_VERBOSE
2274 # if SYNCTEX_VERBOSE
2296 # if SYNCTEX_VERBOSE
2305 if (NULL != (child = _synctex_new_boundary(scanner))
2318 # if SYNCTEX_VERBOSE
2350 if (status<SYNCTEX_STATUS_OK && available>0){
2405 # if SYNCTEX_VERBOSE
2433 # if SYNCTEX_VERBOSE
2443 if (NULL != (sibling = _synctex_new_void_hbox(scanner)) &&
2458 # if SYNCTEX_VERBOSE
2470 if (NULL != (sibling = _synctex_new_kern(scanner))
2483 # if SYNCTEX_VERBOSE
2507 # if SYNCTEX_VERBOSE
2530 # if SYNCTEX_VERBOSE
2541 if (NULL != (sibling = _synctex_new_boundary(scanner))
2553 # if SYNCTEX_VERBOSE
2583 if (status<SYNCTEX_STATUS_OK && available>0){
2590 # undef SYNCTEX_DECODE_FAILED
2593 # define SYNCTEX_APPEND_SHEET(SCANNER,SHEET) if (SCANNER->sheet) {\
2594 synctex_node_t last_sheet = SCANNER->sheet;\
2595 synctex_node_t next_sheet = NULL;\
2596 while ((next_sheet = SYNCTEX_SIBLING(last_sheet))) {\
2597 last_sheet = next_sheet;\
2599 SYNCTEX_SET_SIBLING(last_sheet,SHEET);\
2601 SCANNER->sheet = SHEET;\
2608 synctex_status_t status = 0;
2609 if (NULL == scanner) {
2632 goto content_not_found;
2689 char * synctex = NULL;
2690 synctex_scanner_t scanner = NULL;
2693 if (
sizeof(
int)>
sizeof(
void*)) {
2694 _synctex_error(
"INTERNAL INCONSISTENCY: int's are unexpectedly bigger than pointers, bailing out.");
2699 _synctex_error(
"Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (1)");
2704 _synctex_error(
"Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (2)");
2714 if (NULL == scanner) {
2721 if (NULL == (scanner->
output = (
char *)malloc(strlen(output)+1))){
2722 _synctex_error(
"! synctex_scanner_new_with_output_file: Memory problem (2), scanner's output is not reliable.");
2723 }
else if (scanner->
output != strcpy(scanner->
output,output)) {
2724 _synctex_error(
"! synctex_scanner_new_with_output_file: Copy problem, scanner's output is not reliable.");
2740 if (synctex_name_ref && file_ref && io_mode_ref) {
2744 char * quoteless_synctex_name = NULL;
2750 synctex_name = (
char *)malloc(size);
2751 if (NULL == synctex_name) {
2757 if (synctex_name != strcpy(synctex_name,output)) {
2761 free(quoteless_synctex_name);
2766 if (!strlen(synctex_name)) {
2767 goto return_on_error;
2771 char * quoted = NULL;
2774 goto return_on_error;
2776 quoteless_synctex_name = synctex_name;
2777 synctex_name = quoted;
2782 goto return_on_error;
2785 if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,
synctex_suffix))){
2786 free(quoteless_synctex_name);
2787 quoteless_synctex_name = NULL;
2789 if (NULL == (the_file = gzopen(synctex_name,mode))) {
2791 if (errno != ENOENT) {
2793 _synctex_error(
"could not open %s, error %i\n",synctex_name,errno);
2794 goto return_on_error;
2799 goto return_on_error;
2804 if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,
synctex_suffix_gz))){
2805 free(quoteless_synctex_name);
2806 quoteless_synctex_name = NULL;
2808 if (NULL == (the_file = gzopen(synctex_name,mode))) {
2810 if (errno != ENOENT) {
2812 _synctex_error(
"Could not open %s, error %i\n",synctex_name,errno);
2814 goto return_on_error;
2819 if (quoteless_synctex_name) {
2821 if (rename(synctex_name,quoteless_synctex_name)) {
2822 _synctex_error(
"Could not rename %s to %s, error %i\n",synctex_name,quoteless_synctex_name,errno);
2824 if (NULL == (the_file = gzopen(synctex_name,mode))) {
2826 if (errno != ENOENT) {
2829 _synctex_error(
"Could not open again %s, error %i\n",synctex_name,errno);
2831 goto return_on_error;
2835 if (NULL == (the_file = gzopen(quoteless_synctex_name,mode))) {
2837 if (errno != ENOENT) {
2839 _synctex_error(
"Could not open renamed %s, error %i\n",quoteless_synctex_name,errno);
2841 goto return_on_error;
2845 synctex_name = quoteless_synctex_name;
2846 quoteless_synctex_name = NULL;
2850 * file_ref = the_file;
2851 * io_mode_ref = io_mode;
2852 * synctex_name_ref = synctex_name;
2861 # define synctex_name (*synctex_name_ref)
2862 # define the_file (*file_ref)
2863 int result =
__synctex_open(output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
2864 if ((result || !*file_ref) && build_directory && strlen(build_directory)) {
2865 char * build_output;
2869 build_output = NULL;
2871 size = strlen(build_directory)+strlen(lpc)+2;
2874 size += strlen(output);
2876 if ((build_output = (
char *)malloc(size))) {
2878 build_output[0] =
'\0';
2880 if (build_output != strcpy(build_output,output)) {
2883 build_output[lpc-output]=
'\0';
2885 if (build_output == strcat(build_output,build_directory)) {
2888 if (build_output != strcat(build_output,
"/")) {
2893 if (build_output != strcat(build_output,lpc)) {
2896 return __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
2902 # undef synctex_name
2909 if (NULL == scanner) {
2928 synctex_status_t status = 0;
2939 # define DEFINE_synctex_scanner_class(NAME)\
2940 scanner->class[synctex_node_type_##NAME] = synctex_class_##NAME;\
2941 (scanner->class[synctex_node_type_##NAME]).scanner = scanner
2964 # if defined(SYNCTEX_USE_CHARINDEX)
2993 if (scanner->
unit <= 0) {
3023 return scanner?scanner->
x_offset:0;
3026 return scanner?scanner->
y_offset:0;
3029 return scanner?scanner->
unit:1;
3032 if (NULL == scanner) {
3035 printf(
"The scanner:\noutput:%s\noutput_fmt:%s\nversion:%i\n",scanner->
output,scanner->
output_fmt,scanner->
version);
3037 printf(
"count:%i\npost_magnification:%f\npost_x_offset:%f\npost_y_offset:%f\n",
3039 printf(
"The input:\n");
3041 if (scanner->
count<1000) {
3042 printf(
"The sheets:\n");
3044 printf(
"The friends:\n");
3049 printf(
"Friend index:%i\n",i);
3052 printf(
"%s:%i,%i\n",
3062 printf(
"SyncTeX Warning: Too many objects\n");
3068 if (NULL == scanner) {
3071 input = scanner->
input;
3083 if (NULL == scanner) {
3086 input = scanner->
input;
3094 input = scanner->
input;
3113 size_t char_index = strlen(name);
3125 const char * relative =
name;
3126 const char * ptr = scanner->
output;
3127 while((strlen(relative) > 0) && (strlen(ptr) > 0) && (*relative == *ptr))
3133 while(relative > name) {
3145 while(0<char_index) {
3160 return scanner?scanner->
input:NULL;
3166 return NULL != scanner && scanner->
output?scanner->
output:
"";
3171 # ifdef SYNCTEX_NOTHING
3173 # pragma mark Public node attributes
3258 # ifdef SYNCTEX_NOTHING
3260 # pragma mark Public node visible attributes
3285 case synctex_node_type_vbox:
3286 case synctex_node_type_void_vbox:
3287 case synctex_node_type_void_hbox:
3289 case synctex_node_type_hbox:
3303 case synctex_node_type_vbox:
3304 case synctex_node_type_void_vbox:
3305 case synctex_node_type_void_hbox:
3307 case synctex_node_type_hbox:
3321 case synctex_node_type_vbox:
3322 case synctex_node_type_void_vbox:
3323 case synctex_node_type_void_hbox:
3325 case synctex_node_type_hbox:
3339 case synctex_node_type_vbox:
3340 case synctex_node_type_void_vbox:
3341 case synctex_node_type_void_hbox:
3343 case synctex_node_type_hbox:
3357 case synctex_node_type_vbox:
3358 case synctex_node_type_void_vbox:
3359 case synctex_node_type_void_hbox:
3361 case synctex_node_type_hbox:
3370 # ifdef SYNCTEX_NOTHING
3372 # pragma mark Other public node attributes
3385 if (node->
class->
type == synctex_node_type_sheet) {
3406 # ifdef __DARWIN_UNIX03
3407 # pragma unused(node)
3411 # ifdef SYNCTEX_NOTHING
3436 # ifdef SYNCTEX_NOTHING
3442 # ifdef __DARWIN_UNIX03
3443 # pragma unused(column)
3447 int friend_index = 0;
3451 printf(
"SyncTeX Warning: No tag for %s\n",name);
3457 while(line<max_line) {
3517 unsigned int best_match = -1;
3518 unsigned int next_match = -1;
3519 unsigned int best_weight = 0;
3524 while (start_ref < end_ref) {
3526 *start_ref = *end_ref;
3541 while (++start_ref<end_ref) {
3546 if (next_match < best_match
3548 best_match = next_match;
3549 best_ref = start_ref;
3571 *start_ref = *end_ref;
3582 # if defined(__SYNCTEX_STRONG_DISPLAY_QUERY__)
3654 #define SYNCTEX_MASK_LEFT 1
3655 #define SYNCTEX_MASK_RIGHT 2
3675 sheet = scanner->
sheet;
3679 if (NULL == sheet) {
3703 node = bestContainer;
3706 if (bestNodes.
right && bestNodes.
left) {
3711 if (bestDistances.
left>bestDistances.
right) {
3726 if (bestDistances.
left>bestDistances.
right) {
3729 bestNodes.
right = NULL;
3730 }
else if (bestNodes.
right) {
3732 }
else if (!bestNodes.
left){
3733 bestNodes.
left = node;
3755 # ifdef SYNCTEX_NOTHING
3757 # pragma mark Utilities
3788 case synctex_node_type_hbox:
3793 if (hitPoint.
h<min) {
3794 return min - hitPoint.
h;
3795 }
else if (hitPoint.
h>max) {
3796 return max - hitPoint.
h;
3801 case synctex_node_type_vbox:
3802 case synctex_node_type_void_vbox:
3803 case synctex_node_type_void_hbox:
3809 if (hitPoint.
h<min) {
3810 return min - hitPoint.
h;
3811 }
else if (hitPoint.
h>max) {
3812 return max - hitPoint.
h;
3817 case synctex_node_type_kern:
3847 if (hitPoint.
h<min) {
3848 return min - hitPoint.
h + 1;
3849 }
else if (hitPoint.
h>max) {
3850 return max - hitPoint.
h - 1;
3851 }
else if (hitPoint.
h>med) {
3853 return max - hitPoint.
h + 1;
3855 return min - hitPoint.
h - 1;
3857 case synctex_node_type_glue:
3858 case synctex_node_type_math:
3870 # ifdef __DARWIN_UNIX03
3871 # pragma unused(visible)
3891 case synctex_node_type_hbox:
3897 if (hitPoint.
v<min) {
3898 return min - hitPoint.
v;
3899 }
else if (hitPoint.
v>max) {
3900 return max - hitPoint.
v;
3905 case synctex_node_type_vbox:
3906 case synctex_node_type_void_vbox:
3907 case synctex_node_type_void_hbox:
3913 if (hitPoint.
v<min) {
3914 return min - hitPoint.
v;
3915 }
else if (hitPoint.
v>max) {
3916 return max - hitPoint.
v;
3921 case synctex_node_type_kern:
3922 case synctex_node_type_glue:
3923 case synctex_node_type_math:
3931 float height, other_height;
3940 if (height<other_height) {
3943 if (height>other_height) {
3960 # ifdef __DARWIN_UNIX03
3961 # pragma unused(visible)
3963 int result = INT_MAX;
3965 int minH,maxH,minV,maxV;
3983 case synctex_node_type_vbox:
3984 case synctex_node_type_void_vbox:
3985 case synctex_node_type_hbox:
3986 case synctex_node_type_void_hbox:
3994 if (hitPoint.
v<minV) {
3995 if (hitPoint.
h<minH) {
3997 result = minV - hitPoint.
v + minH - hitPoint.
h;
3998 }
else if (hitPoint.
h<=maxH) {
4000 result = minV - hitPoint.
v;
4003 result = minV - hitPoint.
v + hitPoint.
h - maxH;
4005 }
else if (hitPoint.
v<=maxV) {
4006 if (hitPoint.
h<minH) {
4008 result = minH - hitPoint.
h;
4009 }
else if (hitPoint.
h<=maxH) {
4014 result = hitPoint.
h - maxH;
4017 if (hitPoint.
h<minH) {
4019 result = hitPoint.
v - maxV + minH - hitPoint.
h;
4020 }
else if (hitPoint.
h<=maxH) {
4022 result = hitPoint.
v - maxV;
4025 result = hitPoint.
v - maxV + hitPoint.
h - maxH;
4029 case synctex_node_type_kern:
4040 if (hitPoint.
h<minH) {
4041 if (hitPoint.
v>minV) {
4042 result = hitPoint.
v - minV + minH - hitPoint.
h;
4044 result = minV - hitPoint.
v + minH - hitPoint.
h;
4046 }
else if (hitPoint.
h>maxH) {
4047 if (hitPoint.
v>minV) {
4048 result = hitPoint.
v - minV + hitPoint.
h - maxH;
4050 result = minV - hitPoint.
v + hitPoint.
h - maxH;
4052 }
else if (hitPoint.
v>minV) {
4053 result = hitPoint.
v - minV;
4055 result = minV - hitPoint.
v;
4058 case synctex_node_type_glue:
4059 case synctex_node_type_math:
4062 if (hitPoint.
h<minH) {
4063 if (hitPoint.
v>minV) {
4064 result = hitPoint.
v - minV + minH - hitPoint.
h;
4066 result = minV - hitPoint.
v + minH - hitPoint.
h;
4068 }
else if (hitPoint.
v>minV) {
4069 result = hitPoint.
v - minV + hitPoint.
h - minH;
4071 result = minV - hitPoint.
v + hitPoint.
h - minH;
4084 case synctex_node_type_vbox:
4085 case synctex_node_type_hbox:
4100 int bestDistance = INT_MAX;
4104 if (distance < bestDistance) {
4105 bestDistance = distance;
4131 if (bestDistancesRef->
right > off7) {
4132 bestDistancesRef->
right = off7;
4133 bestNodesRef->
right = node;
4135 }
else if (bestDistancesRef->
right == off7 && bestNodesRef->
right) {
4140 bestNodesRef->
right = node;
4144 }
else if (off7 == 0) {
4146 bestDistancesRef->
left = bestDistancesRef->
right = 0;
4147 bestNodesRef->
left = node;
4148 bestNodesRef->
right = NULL;
4152 if (bestDistancesRef->
left > off7) {
4153 bestDistancesRef->
left = off7;
4154 bestNodesRef->
left = node;
4156 }
else if (bestDistancesRef->
left == off7 && bestNodesRef->
left) {
4161 bestNodesRef->
left = node;
4170 bestNodesRef->
left = node;
4173 bestNodesRef->
left = node;
4179 bestNodesRef->
right = node;
4182 bestNodesRef->
right = node;
4199 if (bestDistancesRef->
right > off7) {
4200 bestDistancesRef->
right = off7;
4201 bestNodesRef->
right = node;
4203 }
else if (bestDistancesRef->
right == off7 && bestNodesRef->
right) {
4208 bestNodesRef->
right = node;
4212 }
else if (off7 == 0) {
4213 bestDistancesRef->
left = bestDistancesRef->
right = 0;
4214 bestNodesRef->
left = node;
4215 bestNodesRef->
right = NULL;
4219 if (bestDistancesRef->
left > off7) {
4220 bestDistancesRef->
left = off7;
4221 bestNodesRef->
left = node;
4223 }
else if (bestDistancesRef->
left == off7 && bestNodesRef->
left) {
4228 bestNodesRef->
left = node;
4237 bestNodesRef->
left = node;
4240 bestNodesRef->
left = node;
4246 bestNodesRef->
right = node;
4249 bestNodesRef->
right = node;
4258 case synctex_node_type_hbox:
4260 case synctex_node_type_vbox:
4274 if (distance<=*distanceRef) {
4275 *distanceRef = distance;
4279 case synctex_node_type_vbox:
4280 case synctex_node_type_hbox:
4282 best_node = candidate;
4292 case synctex_node_type_hbox:
4293 case synctex_node_type_vbox:
4295 int best_distance = INT_MAX;
4300 case synctex_node_type_vbox:
4301 case synctex_node_type_hbox:
4306 if (distance<=best_distance) {
4307 best_distance = distance;
4321 # ifdef SYNCTEX_NOTHING
4323 # pragma mark Updater
4328 # define SYNCTEX_BITS_PER_BYTE 8
4339 # define SYNCTEX_FILE updater->file
4340 # define SYNCTEX_NO_GZ ((updater->flags).no_gz)
4341 # define SYNCTEX_fprintf (*(updater->fprintf))
4345 char * synctex = NULL;
4347 const char * mode = NULL;
4350 if (NULL == updater) {
4351 _synctex_error(
"! synctex_updater_new_with_file: malloc problem");
4368 if (NULL == (
SYNCTEX_FILE = (
void *)fopen(synctex,mode))) {
4370 _synctex_error(
"! synctex_updater_new_with_file: Can't append to %s",synctex);
4372 goto return_on_error;
4376 if (NULL == (
SYNCTEX_FILE = (
void *)gzopen(synctex,mode))) {
4377 goto no_write_error;
4381 printf(
"SyncTeX: updating %s...",synctex);
4388 if (NULL==updater) {
4391 if (magnification && strlen(magnification)) {
4397 if (NULL==updater) {
4400 if (x_offset && strlen(x_offset)) {
4406 if (NULL==updater) {
4409 if (y_offset && strlen(y_offset)) {
4415 if (NULL==updater) {
4427 printf(
"... done.\n");