From: José Aliste Date: Mon, 30 May 2011 15:11:07 +0000 (-0400) Subject: Revert "cut-n-paste: update synctex_parser to version 1.13" X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=evince.git;a=commitdiff_plain;h=3421b3c4a7f7fbfb4b50b6d0918fc3fe14ed5c1f Revert "cut-n-paste: update synctex_parser to version 1.13" This reverts commit cf38056739ba5eb0c15322d27f6e8a23c82d90c5. --- diff --git a/cut-n-paste/synctex/synctex_parser.c b/cut-n-paste/synctex/synctex_parser.c index 39770765..060f32d1 100644 --- a/cut-n-paste/synctex/synctex_parser.c +++ b/cut-n-paste/synctex/synctex_parser.c @@ -1,14 +1,13 @@ /* -Copyright (c) 2008, 2009, 2010 , 2011 jerome DOT laurens AT u-bourgogne DOT fr +Copyright (c) 2008, 2009; 2010 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 - +Version: 1.12 See synctex_parser_readme.txt for more details +Latest Revision: Mon Jul 19 21:50:36 UTC 2010 + License: -------- Permission is hereby granted, free of charge, to any person @@ -92,12 +91,14 @@ Thu Jun 19 09:39:21 UTC 2008 */ #include "synctex_parser.h" -#include "synctex_parser_utils.h" +#include /* These are the possible extensions of the synctex file */ const char * synctex_suffix = ".synctex"; const char * synctex_suffix_gz = ".gz"; +static const char * synctex_io_modes[synctex_io_mode_append+2] = {"r","rb","a","ab"}; + /* each synctex node has a class */ typedef struct __synctex_class_t _synctex_class_t; typedef _synctex_class_t * synctex_class_t; @@ -169,7 +170,7 @@ struct __synctex_class_t { /* This macro is some kind of objc_msg_send. * It takes care of sending the proper message if possible. */ -# define SYNCTEX_MSG_SEND(NODE,SELECTOR) if (NODE && SYNCTEX_CAN_PERFORM(NODE,SELECTOR)) {\ +# define SYNCTEX_MSG_SEND(NODE,SELECTOR) if(NODE && SYNCTEX_CAN_PERFORM(NODE,SELECTOR)) {\ (*((((NODE)->class))->SELECTOR))(NODE);\ } @@ -187,14 +188,14 @@ struct __synctex_class_t { /* Parent getter and setter */ # define SYNCTEX_PARENT(NODE) SYNCTEX_GET(NODE,parent) -# define SYNCTEX_SET_PARENT(NODE,NEW_PARENT) if (NODE && NEW_PARENT && SYNCTEX_CAN_PERFORM(NODE,parent)){\ +# define SYNCTEX_SET_PARENT(NODE,NEW_PARENT) if(NODE && NEW_PARENT && SYNCTEX_CAN_PERFORM(NODE,parent)){\ SYNCTEX_GETTER(NODE,parent)[0]=NEW_PARENT;\ } /* Child getter and setter */ # define SYNCTEX_CHILD(NODE) SYNCTEX_GET(NODE,child) -# define SYNCTEX_SET_CHILD(NODE,NEW_CHILD) if (NODE && NEW_CHILD){\ +# define SYNCTEX_SET_CHILD(NODE,NEW_CHILD) if(NODE && NEW_CHILD){\ SYNCTEX_GETTER(NODE,child)[0]=NEW_CHILD;\ SYNCTEX_GETTER(NEW_CHILD,parent)[0]=NODE;\ } @@ -202,9 +203,9 @@ struct __synctex_class_t { /* Sibling getter and setter */ # define SYNCTEX_SIBLING(NODE) SYNCTEX_GET(NODE,sibling) -# define SYNCTEX_SET_SIBLING(NODE,NEW_SIBLING) if (NODE && NEW_SIBLING) {\ +# define SYNCTEX_SET_SIBLING(NODE,NEW_SIBLING) if(NODE && NEW_SIBLING) {\ SYNCTEX_GETTER(NODE,sibling)[0]=NEW_SIBLING;\ - if (SYNCTEX_CAN_PERFORM(NEW_SIBLING,parent) && SYNCTEX_CAN_PERFORM(NODE,parent)) {\ + if(SYNCTEX_CAN_PERFORM(NEW_SIBLING,parent) && SYNCTEX_CAN_PERFORM(NODE,parent)) {\ SYNCTEX_GETTER(NEW_SIBLING,parent)[0]=SYNCTEX_GETTER(NODE,parent)[0];\ }\ } @@ -213,7 +214,7 @@ struct __synctex_class_t { * Friends are used mainly in forward synchronization aka from source to output. */ # define SYNCTEX_FRIEND(NODE) SYNCTEX_GET(NODE,friend) -# define SYNCTEX_SET_FRIEND(NODE,NEW_FRIEND) if (NODE && NEW_FRIEND){\ +# define SYNCTEX_SET_FRIEND(NODE,NEW_FRIEND) if(NODE && NEW_FRIEND){\ SYNCTEX_GETTER(NODE,friend)[0]=NEW_FRIEND;\ } @@ -221,7 +222,7 @@ struct __synctex_class_t { * Navigation starts with the deeper boxes. */ # define SYNCTEX_NEXT_HORIZ_BOX(NODE) SYNCTEX_GET(NODE,next_box) -# define SYNCTEX_SET_NEXT_HORIZ_BOX(NODE,NEXT_BOX) if (NODE && NEXT_BOX){\ +# define SYNCTEX_SET_NEXT_HORIZ_BOX(NODE,NEXT_BOX) if(NODE && NEXT_BOX){\ SYNCTEX_GETTER(NODE,next_box)[0]=NEXT_BOX;\ } @@ -233,7 +234,7 @@ void _synctex_free_leaf(synctex_node_t node); * This destructor is for all nodes with children. */ void _synctex_free_node(synctex_node_t node) { - if (node) { + if(node) { (*((node->class)->sibling))(node); SYNCTEX_FREE(SYNCTEX_SIBLING(node)); SYNCTEX_FREE(SYNCTEX_CHILD(node)); @@ -247,7 +248,7 @@ void _synctex_free_node(synctex_node_t node) { * This destructor is for nodes with no child. */ void _synctex_free_leaf(synctex_node_t node) { - if (node) { + if(node) { SYNCTEX_FREE(SYNCTEX_SIBLING(node)); free(node); } @@ -367,7 +368,7 @@ static _synctex_class_t synctex_class_sheet = { /* sheet node creator */ synctex_node_t _synctex_new_sheet(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_sheet_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_sheet:(synctex_class_t)&synctex_class_sheet; } return node; @@ -429,7 +430,7 @@ static _synctex_class_t synctex_class_vbox = { /* vertical box node creator */ synctex_node_t _synctex_new_vbox(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_vert_box_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_vbox:(synctex_class_t)&synctex_class_vbox; } return node; @@ -482,7 +483,7 @@ static _synctex_class_t synctex_class_hbox = { /* horizontal box node creator */ synctex_node_t _synctex_new_hbox(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_horiz_box_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_hbox:(synctex_class_t)&synctex_class_hbox; } return node; @@ -520,7 +521,7 @@ static _synctex_class_t synctex_class_void_vbox = { /* vertical void box node creator */ synctex_node_t _synctex_new_void_vbox(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_void_box_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_void_vbox:(synctex_class_t)&synctex_class_void_vbox; } return node; @@ -547,7 +548,7 @@ static _synctex_class_t synctex_class_void_hbox = { /* horizontal void box node creator */ synctex_node_t _synctex_new_void_hbox(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_void_box_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_void_hbox:(synctex_class_t)&synctex_class_void_hbox; } return node; @@ -592,7 +593,7 @@ static _synctex_class_t synctex_class_math = { synctex_node_t _synctex_new_math(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_medium_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_math:(synctex_class_t)&synctex_class_math; } return node; @@ -619,7 +620,7 @@ static _synctex_class_t synctex_class_kern = { synctex_node_t _synctex_new_kern(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_medium_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_kern:(synctex_class_t)&synctex_class_kern; } return node; @@ -654,7 +655,7 @@ static _synctex_class_t synctex_class_glue = { }; synctex_node_t _synctex_new_glue(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_medium_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_glue:(synctex_class_t)&synctex_class_glue; } return node; @@ -681,7 +682,7 @@ static _synctex_class_t synctex_class_boundary = { synctex_node_t _synctex_new_boundary(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_small_node_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_boundary:(synctex_class_t)&synctex_class_boundary; } return node; @@ -720,13 +721,13 @@ static _synctex_class_t synctex_class_input = { synctex_node_t _synctex_new_input(synctex_scanner_t scanner) { synctex_node_t node = _synctex_malloc(sizeof(synctex_input_t)); - if (node) { + if(node) { node->class = scanner?scanner->class+synctex_node_type_input:(synctex_class_t)&synctex_class_input; } return node; } void _synctex_free_input(synctex_node_t node){ - if (node) { + if(node) { SYNCTEX_FREE(SYNCTEX_SIBLING(node)); free(SYNCTEX_NAME(node)); free(node); @@ -757,15 +758,15 @@ synctex_node_t synctex_node_sibling(synctex_node_t node) return SYNCTEX_SIBLING(node); } synctex_node_t synctex_node_next(synctex_node_t node) { - if (SYNCTEX_CHILD(node)) { + if(SYNCTEX_CHILD(node)) { return SYNCTEX_CHILD(node); } sibling: - if (SYNCTEX_SIBLING(node)) { + if(SYNCTEX_SIBLING(node)) { return SYNCTEX_SIBLING(node); } - if ((node = SYNCTEX_PARENT(node))) { - if (node->class->type == synctex_node_type_sheet) {/* EXC_BAD_ACCESS? */ + if((node = SYNCTEX_PARENT(node))) { + if(node->class->type == synctex_node_type_sheet) {/* EXC_BAD_ACCESS? */ return NULL; } goto sibling; @@ -779,7 +780,7 @@ sibling: /* Public node accessor: the type */ synctex_node_type_t synctex_node_type(synctex_node_t node) { - if (node) { + if(node) { return (((node)->class))->type; } return synctex_node_type_error; @@ -818,7 +819,7 @@ void _synctex_display_input(synctex_node_t node) { } void _synctex_log_sheet(synctex_node_t sheet) { - if (sheet) { + if(sheet) { printf("%s:%i\n",synctex_node_isa(sheet),SYNCTEX_PAGE(sheet)); printf("SELF:%p",(void *)sheet); printf(" SYNCTEX_PARENT:%p",(void *)SYNCTEX_PARENT(sheet)); @@ -921,7 +922,7 @@ void _synctex_log_input(synctex_node_t node) { } void _synctex_display_sheet(synctex_node_t sheet) { - if (sheet) { + if(sheet) { printf("....{%i\n",SYNCTEX_PAGE(sheet)); SYNCTEX_DISPLAY(SYNCTEX_CHILD(sheet)); printf("....}\n"); @@ -1049,7 +1050,7 @@ typedef int synctex_status_t; # define SYNCTEX_FILE (scanner->file) /* Actually, the minimum buffer size is driven by integer and float parsing. - * ±0.123456789e123 + * ±0.123456789e123 */ # define SYNCTEX_BUFFER_MIN_SIZE 16 # define SYNCTEX_BUFFER_SIZE 32768 @@ -1075,7 +1076,6 @@ int _synctex_scan_postamble(synctex_scanner_t scanner); synctex_status_t _synctex_setup_visible_box(synctex_node_t box); synctex_status_t _synctex_horiz_box_setup_visible(synctex_node_t node,int h, int v); synctex_status_t _synctex_scan_sheet(synctex_scanner_t scanner, synctex_node_t parent); -synctex_status_t _synctex_scan_nested_sheet(synctex_scanner_t scanner); synctex_status_t _synctex_scan_content(synctex_scanner_t scanner); int synctex_scanner_pre_x_offset(synctex_scanner_t scanner); int synctex_scanner_pre_y_offset(synctex_scanner_t scanner); @@ -1095,30 +1095,30 @@ int _synctex_bail(void); * when there was an error reading the synctex file. */ synctex_status_t _synctex_buffer_get_available_size(synctex_scanner_t scanner, size_t * size_ptr) { size_t available = 0; - if (NULL == scanner || NULL == size_ptr) { + if(NULL == scanner || NULL == size_ptr) { return SYNCTEX_STATUS_BAD_ARGUMENT; } # define size (* size_ptr) - if (size>SYNCTEX_BUFFER_SIZE){ + if(size>SYNCTEX_BUFFER_SIZE){ size = SYNCTEX_BUFFER_SIZE; } available = SYNCTEX_END - SYNCTEX_CUR; /* available is the number of unparsed chars in the buffer */ - if (size<=available) { + if(size<=available) { /* There are already sufficiently many characters in the buffer */ size = available; return SYNCTEX_STATUS_OK; } - if (SYNCTEX_FILE) { + if(SYNCTEX_FILE) { /* Copy the remaining part of the buffer to the beginning, * then read the next part of the file */ int already_read = 0; - if (available) { + if(available) { memmove(SYNCTEX_START, SYNCTEX_CUR, available); } SYNCTEX_CUR = SYNCTEX_START + available; /* the next character after the move, will change. */ /* Fill the buffer up to its end */ already_read = gzread(SYNCTEX_FILE,(void *)SYNCTEX_CUR,SYNCTEX_BUFFER_SIZE - available); - if (already_read>0) { + if(already_read>0) { /* We assume that 0already_read) { - /* There is a possible error in reading the file */ + } else if(0>already_read) { + /* There is an error in zlib */ int errnum = 0; const char * error_string = gzerror(SYNCTEX_FILE, &errnum); - if (Z_ERRNO == errnum) { + if(Z_ERRNO == errnum) { /* There is an error in zlib caused by the file system */ _synctex_error("gzread error from the file system (%i)",errno); - return SYNCTEX_STATUS_ERROR; - } else if (errnum) { + } else { _synctex_error("gzread error (%i:%i,%s)",already_read,errnum,error_string); - return SYNCTEX_STATUS_ERROR; } + return SYNCTEX_STATUS_ERROR; + } else { + /* Nothing was read, we are at the end of the file. */ + gzclose(SYNCTEX_FILE); + SYNCTEX_FILE = NULL; + SYNCTEX_END = SYNCTEX_CUR; + SYNCTEX_CUR = SYNCTEX_START; + * SYNCTEX_END = '\0';/* Terminate the string properly.*/ + size = SYNCTEX_END - SYNCTEX_CUR; + return SYNCTEX_STATUS_EOF; /* there might be a bit of text left */ } - /* Nothing was read, we are at the end of the file. */ - gzclose(SYNCTEX_FILE); - SYNCTEX_FILE = NULL; - SYNCTEX_END = SYNCTEX_CUR; - SYNCTEX_CUR = SYNCTEX_START; - * SYNCTEX_END = '\0';/* Terminate the string properly.*/ - size = SYNCTEX_END - SYNCTEX_CUR; - return SYNCTEX_STATUS_EOF; /* there might be a bit of text left */ - } + /* At this point, the function has already returned from above */ + } /* We cannot enlarge the buffer because the end of the file was reached. */ size = available; return SYNCTEX_STATUS_EOF; @@ -1169,12 +1170,12 @@ synctex_status_t _synctex_buffer_get_available_size(synctex_scanner_t scanner, s synctex_status_t _synctex_next_line(synctex_scanner_t scanner) { synctex_status_t status = SYNCTEX_STATUS_OK; size_t available = 0; - if (NULL == scanner) { + if(NULL == scanner) { return SYNCTEX_STATUS_BAD_ARGUMENT; } infinite_loop: while(SYNCTEX_CUR=remaining_len) { + if(available>=remaining_len) { /* The buffer is sufficiently big to hold the expected number of characters. */ - if (strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) { + if(strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) { return SYNCTEX_STATUS_NOT_OK; } return_OK: /* Advance SYNCTEX_CUR to the next character after the_string. */ SYNCTEX_CUR += remaining_len; return SYNCTEX_STATUS_OK; - } else if (strncmp((char *)SYNCTEX_CUR,the_string,available)) { + } else if(strncmp((char *)SYNCTEX_CUR,the_string,available)) { /* No need to goo further, this is not the expected string in the buffer. */ return SYNCTEX_STATUS_NOT_OK; - } else if (SYNCTEX_FILE) { + } else if(SYNCTEX_FILE) { /* The buffer was too small to contain remaining_len characters. * We have to cut the string into pieces. */ z_off_t offset = 0L; @@ -1242,7 +1243,7 @@ return_OK: remaining_len -= available; tested_len += available; SYNCTEX_CUR += available; /* We validate the tested characters. */ - if (0 == remaining_len) { + if(0 == remaining_len) { /* Nothing left to test, we have found the given string, we return the length. */ return tested_len; } @@ -1267,13 +1268,13 @@ more_characters: * We will definitely have to recover the previous state in case we do not find the expected string. */ available = remaining_len; status = _synctex_buffer_get_available_size(scanner,&available); - if (statusptr) { + if(end>ptr) { SYNCTEX_CUR = end; - if (value_ref) { + if(value_ref) { * value_ref = result; } return SYNCTEX_STATUS_OK;/* Successfully scanned an int */ @@ -1383,17 +1384,17 @@ synctex_status_t _synctex_decode_string(synctex_scanner_t scanner, char ** value size_t len = 0;/* The number of bytes to copy */ size_t available = 0; synctex_status_t status = 0; - if (NULL == scanner || NULL == value_ref) { + if(NULL == scanner || NULL == value_ref) { return SYNCTEX_STATUS_BAD_ARGUMENT; } /* The buffer must at least contain one character: the '\n' end of line marker */ - if (SYNCTEX_CUR>=SYNCTEX_END) { + if(SYNCTEX_CUR>=SYNCTEX_END) { available = 1; status = _synctex_buffer_get_available_size(scanner,&available); - if (status < 0) { + if(status < 0) { return status; } - if (0 == available) { + if(0 == available) { return SYNCTEX_STATUS_EOF; } } @@ -1404,11 +1405,11 @@ synctex_status_t _synctex_decode_string(synctex_scanner_t scanner, char ** value * value_ref = NULL;/* Initialize, it will be realloc'ed */ /* We scan all the characters up to the next '\n' */ next_character: - if (endUINT_MAX-len-1) { + if(current_size>UINT_MAX-len-1) { /* But we have reached the limit: we do not have current_size+len+1>UINT_MAX. * We return the missing amount of memory. * This will never occur in practice. */ @@ -1418,8 +1419,8 @@ next_character: /* We have current_size+len+1<=UINT_MAX * or equivalently new_sizeUINT_MAX-len-1) { + if(current_size>UINT_MAX-len-1) { /* We have reached the limit. */ _synctex_error("limit reached (missing %i).",current_size-(UINT_MAX-len-1)); return SYNCTEX_STATUS_ERROR; } new_size = current_size+len; - if ((* value_ref = realloc(* value_ref,new_size+1)) != NULL) { - if (memcpy((*value_ref)+current_size,SYNCTEX_CUR,len)) { + if((* value_ref = realloc(* value_ref,new_size+1)) != NULL) { + if(memcpy((*value_ref)+current_size,SYNCTEX_CUR,len)) { (* value_ref)[new_size]='\0'; /* Terminate the string */ SYNCTEX_CUR = SYNCTEX_END;/* Advance the cursor to the end of the bufer */ return SYNCTEX_STATUS_OK; @@ -1468,22 +1469,22 @@ synctex_status_t _synctex_scan_input(synctex_scanner_t scanner) { synctex_status_t status = 0; size_t available = 0; synctex_node_t input = NULL; - if (NULL == scanner) { + if(NULL == scanner) { return SYNCTEX_STATUS_BAD_ARGUMENT; } status = _synctex_match_string(scanner,"Input:"); - if (statusversion),(synctex_decoder_t)&_synctex_decode_int); - if (statusoutput_fmt),(synctex_decoder_t)&_synctex_decode_string); - if (statuspre_magnification),(synctex_decoder_t)&_synctex_decode_int); - if (statuspre_unit),(synctex_decoder_t)&_synctex_decode_int); - if (statuspre_x_offset),(synctex_decoder_t)&_synctex_decode_int); - if (statuspre_y_offset),(synctex_decoder_t)&_synctex_decode_int); - if (status= SYNCTEX_STATUS_OK) { + if((status = _synctex_match_string(scanner,"in")) >= SYNCTEX_STATUS_OK) { f *= 72.27f*65536; - } else if (status= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"cm")) >= SYNCTEX_STATUS_OK) { f *= 72.27f*65536/2.54f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"mm")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"mm")) >= SYNCTEX_STATUS_OK) { f *= 72.27f*65536/25.4f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"pt")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"pt")) >= SYNCTEX_STATUS_OK) { f *= 65536.0f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"bp")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"bp")) >= SYNCTEX_STATUS_OK) { f *= 72.27f/72*65536.0f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"pc")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"pc")) >= SYNCTEX_STATUS_OK) { f *= 12.0*65536.0f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"sp")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"sp")) >= SYNCTEX_STATUS_OK) { f *= 1.0f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"dd")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"dd")) >= SYNCTEX_STATUS_OK) { f *= 1238.0f/1157*65536.0f; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"cc")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"cc")) >= SYNCTEX_STATUS_OK) { f *= 14856.0f/1157*65536; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"nd")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"nd")) >= SYNCTEX_STATUS_OK) { f *= 685.0f/642*65536; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; - } else if ((status = _synctex_match_string(scanner,"nc")) >= SYNCTEX_STATUS_OK) { + } else if((status = _synctex_match_string(scanner,"nc")) >= SYNCTEX_STATUS_OK) { f *= 1370.0f/107*65536; - } else if (status<0) { + } else if(status<0) { goto report_unit_error; } *value_ref = f; @@ -1699,20 +1700,20 @@ synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_t scanner) { #ifdef HAVE_SETLOCALE char * loc = setlocale(LC_NUMERIC, NULL); #endif - if (NULL == scanner) { + if(NULL == scanner) { return SYNCTEX_STATUS_BAD_ARGUMENT; } /* Scan the file until a post scriptum line is found */ post_scriptum_not_found: status = _synctex_match_string(scanner,"Post scriptum:"); - if (statusunit<=0) { + if(scanner->unit<=0) { _synctex_error("bad magnification in the post scriptum, a positive float was expected."); return SYNCTEX_STATUS_ERROR; } SYNCTEX_CUR = endptr; goto next_line; } - if (statusx_offset)); - if (statusy_offset)); - if (statuscount),(synctex_decoder_t)&_synctex_decode_int); - if (status < SYNCTEX_STATUS_EOF) { + if(status < SYNCTEX_STATUS_EOF) { return status; /* forward the error */ - } else if (status < SYNCTEX_STATUS_OK) { /* No Count record found */ + } else if(status < SYNCTEX_STATUS_OK) { /* No Count record found */ status = _synctex_next_line(scanner); /* Advance one more line */ - if (statusclass->type) { case synctex_node_type_hbox: - if (SYNCTEX_INFO(box) != NULL) { + if(SYNCTEX_INFO(box) != NULL) { SYNCTEX_HORIZ_V(box) = SYNCTEX_HORIZ(box); SYNCTEX_VERT_V(box) = SYNCTEX_VERT(box); SYNCTEX_WIDTH_V(box) = SYNCTEX_WIDTH(box); @@ -1841,89 +1842,31 @@ synctex_status_t _synctex_horiz_box_setup_visible(synctex_node_t node,int h, int # pragma unused(v) # endif int itsBtm, itsTop; - if (NULL == node || node->class->type != synctex_node_type_hbox) { + if(NULL == node || node->class->type != synctex_node_type_hbox) { return SYNCTEX_STATUS_BAD_ARGUMENT; } - if (SYNCTEX_WIDTH_V(node)<0) { + if(SYNCTEX_WIDTH_V(node)<0) { itsBtm = SYNCTEX_HORIZ_V(node); itsTop = SYNCTEX_HORIZ_V(node)-SYNCTEX_WIDTH_V(node); - if (hitsTop) { + } else if(h>itsTop) { SYNCTEX_WIDTH_V(node) = SYNCTEX_HORIZ_V(node) - h; } } else { itsBtm = SYNCTEX_HORIZ_V(node); itsTop = SYNCTEX_HORIZ_V(node)+SYNCTEX_WIDTH_V(node); - if (hitsTop) { + } else if(h>itsTop) { SYNCTEX_WIDTH_V(node) = h - SYNCTEX_HORIZ_V(node); } } return SYNCTEX_STATUS_OK; } -/* Here are the control characters that strat each line of the synctex output file. - * Their values define the meaning of the line. - */ -# define SYNCTEX_CHAR_BEGIN_SHEET '{' -# define SYNCTEX_CHAR_END_SHEET '}' -# define SYNCTEX_CHAR_BEGIN_VBOX '[' -# define SYNCTEX_CHAR_END_VBOX ']' -# define SYNCTEX_CHAR_BEGIN_HBOX '(' -# define SYNCTEX_CHAR_END_HBOX ')' -# define SYNCTEX_CHAR_ANCHOR '!' -# define SYNCTEX_CHAR_VOID_VBOX 'v' -# define SYNCTEX_CHAR_VOID_HBOX 'h' -# define SYNCTEX_CHAR_KERN 'k' -# define SYNCTEX_CHAR_GLUE 'g' -# define SYNCTEX_CHAR_MATH '$' -# define SYNCTEX_CHAR_BOUNDARY 'x' - -# define SYNCTEX_RETURN(STATUS) return STATUS; - -/* Used when parsing the synctex file. A '{' character has just been parsed. - * The purpose is to gobble everything until the closing '}'. - * Actually only one nesting depth has been observed when using the clip option - * of \includegraphics option. Here we use arbitrary level of depth. - */ -synctex_status_t _synctex_scan_nested_sheet(synctex_scanner_t scanner) { - unsigned int depth = 0; -deeper: - ++depth; - if (_synctex_next_line(scanner)0) { - goto scan_next_line; - } else { - SYNCTEX_RETURN(SYNCTEX_STATUS_OK); - } - } else if (*SYNCTEX_CUR == SYNCTEX_CHAR_BEGIN_SHEET) { - ++SYNCTEX_CUR; - goto deeper; - - } else if (_synctex_next_line(scanner)class->type != synctex_node_type_sheet + if(NULL == parent || parent->class->type != synctex_node_type_sheet || _synctex_next_line(scanner)0){ + if(status0){ _synctex_error("Uncomplete sheet(0)"); SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR); } else { @@ -2042,38 +1978,38 @@ scan_anchor: /* The child loop means that we go do one level, when we just created a box node, * the next node created is a child of this box. */ child_loop: - if (SYNCTEX_CURclass->type == synctex_node_type_vbox) { + if(NULL != parent && parent->class->type == synctex_node_type_vbox) { #define SYNCTEX_UPDATE_BOX_FRIEND(NODE)\ friend_index = ((SYNCTEX_INFO(NODE))[SYNCTEX_TAG_IDX].INT+(SYNCTEX_INFO(NODE))[SYNCTEX_LINE_IDX].INT)%(scanner->number_of_lists);\ SYNCTEX_SET_FRIEND(NODE,(scanner->lists_of_friends)[friend_index]);\ (scanner->lists_of_friends)[friend_index] = NODE; - if (NULL == SYNCTEX_CHILD(parent)) { + if(NULL == SYNCTEX_CHILD(parent)) { /* only void boxes are friends */ SYNCTEX_UPDATE_BOX_FRIEND(parent); } child = parent; parent = SYNCTEX_PARENT(child); } else { - _synctex_error("Unexpected end of vbox, ignored."); + _synctex_error("Unexpected ']', ignored."); } - if (_synctex_next_line(scanner)class->type == synctex_node_type_hbox) { - if (NULL == child) { + if((parent) && parent->class->type == synctex_node_type_hbox) { + if(NULL == child) { /* Only boxes with no children are friends, * boxes with children are indirectly friends through one of their descendants. */ SYNCTEX_UPDATE_BOX_FRIEND(parent); @@ -2084,18 +2020,18 @@ scan_xobh: child = parent; parent = SYNCTEX_PARENT(child); } else { - _synctex_error("Unexpected enf of hbox, ignored."); + _synctex_error("Unexpected ')', ignored."); } - if (_synctex_next_line(scanner)0){ + if(status0){ _synctex_error("Uncomplete sheet(0)"); SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR); } else { @@ -2258,12 +2186,12 @@ scan_xobh: /* The vertical loop means that we are on the same level, for example when we just ended a box. * If a node is created now, it will be a sibling of the current node, sharing the same parent. */ sibling_loop: - if (SYNCTEX_CUR0){ + if(status0){ goto sibling_loop; } else { _synctex_error("Uncomplete sheet(2)"); @@ -2482,14 +2410,14 @@ sibling_loop: synctex_status_t _synctex_scan_content(synctex_scanner_t scanner) { synctex_node_t sheet = NULL; synctex_status_t status = 0; - if (NULL == scanner) { + if(NULL == scanner) { return SYNCTEX_STATUS_BAD_ARGUMENT; } /* set up the lists of friends */ - if (NULL == scanner->lists_of_friends) { + if(NULL == scanner->lists_of_friends) { scanner->number_of_lists = 1024; scanner->lists_of_friends = (synctex_node_t *)_synctex_malloc(scanner->number_of_lists*sizeof(synctex_node_t)); - if (NULL == scanner->lists_of_friends) { + if(NULL == scanner->lists_of_friends) { _synctex_error("malloc:2"); return SYNCTEX_STATUS_ERROR; } @@ -2497,26 +2425,26 @@ synctex_status_t _synctex_scan_content(synctex_scanner_t scanner) { /* Find where this section starts */ content_not_found: status = _synctex_match_string(scanner,"Content:"); - if (statussizeof(void*)) { + if(sizeof(int)>sizeof(void*)) { _synctex_error("INTERNAL INCONSISTENCY: int's are unexpectedly bigger than pointers, bailing out."); return NULL; } /* We ensure that SYNCTEX_BUFFER_SIZE < UINT_MAX, I don't know if it makes sense... */ - if (SYNCTEX_BUFFER_SIZE >= UINT_MAX) { + if(SYNCTEX_BUFFER_SIZE >= UINT_MAX) { _synctex_error("SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (1)"); return NULL; } /* for integers: */ - if (SYNCTEX_BUFFER_SIZE < SYNCTEX_BUFFER_MIN_SIZE) { + if(SYNCTEX_BUFFER_SIZE < SYNCTEX_BUFFER_MIN_SIZE) { _synctex_error("SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (2)"); return NULL; } /* now open the synctex file */ - if (_synctex_open(output,build_directory,&synctex,&file,synctex_ADD_QUOTES,&io_mode) || !file) { - if (_synctex_open(output,build_directory,&synctex,&file,synctex_DONT_ADD_QUOTES,&io_mode) || !file) { + if(_synctex_open(output,build_directory,&synctex,&file,synctex_NO,&io_mode) || !file) { + if(_synctex_open(output,build_directory,&synctex,&file,synctex_YES,&io_mode) || !file) { return NULL; } } scanner = (synctex_scanner_t)_synctex_malloc(sizeof(_synctex_scanner_t)); - if (NULL == scanner) { + if(NULL == scanner) { _synctex_error("SyncTeX: malloc problem"); free(synctex); gzclose(file); return NULL; } /* make a private copy of output for the scanner */ - if (NULL == (scanner->output = (char *)malloc(strlen(output)+1))){ + if(NULL == (scanner->output = (char *)malloc(strlen(output)+1))){ _synctex_error("! synctex_scanner_new_with_output_file: Memory problem (2), scanner's output is not reliable."); - } else if (scanner->output != strcpy(scanner->output,output)) { + } else if(scanner->output != strcpy(scanner->output,output)) { _synctex_error("! synctex_scanner_new_with_output_file: Copy problem, scanner's output is not reliable."); } scanner->synctex = synctex;/* Now the scanner owns synctex */ @@ -2606,87 +2534,87 @@ synctex_scanner_t synctex_scanner_new_with_output_file(const char * output, cons return parse? synctex_scanner_parse(scanner):scanner; } -int __synctex_open(const char * output, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_mode_ref); +int __synctex_open(const char * output, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_modeRef); /* This functions opens the file at the "output" given location. - * It manages the problem of quoted filenames that appear with pdftex and filenames containing the space character. + * It manages the problem of quoted filenames that appear with pdftex an filenames containing the space character. * In TeXLive 2008, the synctex file created with pdftex did contain unexpected quotes. * This function will remove them if possible. - * All the reference arguments will take a value on return. They must be non NULL. * 0 on success, non 0 on error. */ -int __synctex_open(const char * output, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_mode_ref) { - if (synctex_name_ref && file_ref && io_mode_ref) { - /* 1 local variables that uses dynamic memory */ - char * synctex_name = NULL; - gzFile the_file = NULL; - char * quoteless_synctex_name = NULL; +int __synctex_open(const char * output, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_modeRef) { +# define synctex_name (*synctex_name_ref) +# define the_file (*file_ref) + if(synctex_name_ref && file_ref) { + char * quoteless = NULL; + synctex_io_mode_t io_mode = *io_modeRef; + const char * mode = synctex_io_modes[io_mode]; size_t size = 0; - synctex_io_mode_t io_mode = *io_mode_ref; - const char * mode = _synctex_get_io_mode_name(io_mode); /* now create the synctex file name */ size = strlen(output)+strlen(synctex_suffix)+strlen(synctex_suffix_gz)+1; synctex_name = (char *)malloc(size); - if (NULL == synctex_name) { + if(NULL == synctex_name) { _synctex_error("! __synctex_open: Memory problem (1)\n"); return 1; } - /* we have reserved for synctex enough memory to copy output (including its 2 eventual quotes), both suffices, + /* we have reserved for synctex enough memory to copy output, both suffices and 2 quotes, * including the terminating character. size is free now. */ - if (synctex_name != strcpy(synctex_name,output)) { + if(synctex_name != strcpy(synctex_name,output)) { _synctex_error("! __synctex_open: Copy problem\n"); return_on_error: free(synctex_name); - free(quoteless_synctex_name); + synctex_name = NULL;/* Don't forget to reinitialize. */ + the_file = NULL; /* Here as well */ + free(quoteless); return 2; } /* remove the last path extension if any */ _synctex_strip_last_path_extension(synctex_name); - if (!strlen(synctex_name)) { + if(!strlen(synctex_name)) { goto return_on_error; } /* now insert quotes. */ - if (add_quotes) { + if(add_quotes) { char * quoted = NULL; - if (_synctex_copy_with_quoting_last_path_component(synctex_name,"ed,size) || (NULL == quoted)) { + if(_synctex_copy_with_quoting_last_path_component(synctex_name,"ed,size) || (NULL == quoted)) { /* There was an error or quoting does not make sense: */ goto return_on_error; } - quoteless_synctex_name = synctex_name; + quoteless = synctex_name; synctex_name = quoted; } - /* Now add to synctex_name the first path extension. */ - if (synctex_name != strcat(synctex_name,synctex_suffix)){ + /* Now add the first path extension. */ + if(synctex_name != strcat(synctex_name,synctex_suffix)){ _synctex_error("! __synctex_open: Concatenation problem (can't add suffix '%s')\n",synctex_suffix); goto return_on_error; } - /* Add to quoteless_synctex_name as well, if relevant. */ - if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix))){ - free(quoteless_synctex_name); - quoteless_synctex_name = NULL; + /* To quoteless as well. */ + if(quoteless && (quoteless != strcat(quoteless,synctex_suffix))){ + free(quoteless); + quoteless = NULL; } - if (NULL == (the_file = gzopen(synctex_name,mode))) { + if(NULL == (the_file = gzopen(synctex_name,mode))) { /* Could not open this file */ - if (errno != ENOENT) { - /* The file does exist, this is a lower level error, I can't do anything. */ + if(errno != ENOENT) { + /* The file does exist, this is a lower lever error, I can't do anything. */ _synctex_error("SyncTeX: could not open %s, error %i\n",synctex_name,errno); goto return_on_error; } - /* Apparently, there is no uncompressed synctex file. Try the compressed version */ - if (synctex_name != strcat(synctex_name,synctex_suffix_gz)){ + /* Try the compressed version */ + if(synctex_name != strcat(synctex_name,synctex_suffix_gz)){ _synctex_error("! __synctex_open: Concatenation problem (can't add suffix '%s')\n",synctex_suffix_gz); goto return_on_error; } - io_mode |= synctex_io_gz_mask; - mode = _synctex_get_io_mode_name(io_mode); /* the file is a compressed and is a binary file, this caused errors on Windows */ - /* Add the suffix to the quoteless_synctex_name as well. */ - if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix_gz))){ - free(quoteless_synctex_name); - quoteless_synctex_name = NULL; + ++io_mode; + mode = synctex_io_modes[io_mode]; /* the file is a compressed and is a binary file, this caused errors on Windows */ + /* To quoteless as well. */ + if(quoteless && (quoteless != strcat(quoteless,synctex_suffix_gz))){ + free(quoteless); + quoteless = NULL; } - if (NULL == (the_file = gzopen(synctex_name,mode))) { + if(NULL == (the_file = gzopen(synctex_name,mode))) { /* Could not open this file */ - if (errno != ENOENT) { - /* The file does exist, this is a lower level error, I can't do anything. */ + if(errno != ENOENT) { + /* The file does exist, this is a lower lever error, I can't do anything. */ _synctex_error("SyncTeX: could not open %s, error %i\n",synctex_name,errno); } goto return_on_error; @@ -2694,84 +2622,82 @@ return_on_error: } /* At this point, the file is properly open. * If we are in the add_quotes mode, we change the file name by removing the quotes. */ - if (quoteless_synctex_name) { + if(quoteless) { gzclose(the_file); - if (rename(synctex_name,quoteless_synctex_name)) { - _synctex_error("SyncTeX: could not rename %s to %s, error %i\n",synctex_name,quoteless_synctex_name,errno); - /* We could not rename, reopen the file with the quoted name. */ - if (NULL == (the_file = gzopen(synctex_name,mode))) { - /* No luck, could not re open this file, something has happened meanwhile */ - if (errno != ENOENT) { - /* The file does not exist any more, it has certainly be removed somehow - * this is a lower level error, I can't do anything. */ + if(rename(synctex_name,quoteless)) { + _synctex_error("SyncTeX: could not rename %s to %s, error %i\n",synctex_name,quoteless,errno); + /* Reopen the file. */ + if(NULL == (the_file = gzopen(synctex_name,mode))) { + /* Could not open this file */ + if(errno != ENOENT) { + /* The file does exist, this is a lower lever error, I can't do anything. */ _synctex_error("SyncTeX: could not open again %s, error %i\n",synctex_name,errno); } goto return_on_error; } } else { - /* The file has been successfully renamed */ - if (NULL == (the_file = gzopen(quoteless_synctex_name,mode))) { + if(NULL == (the_file = gzopen(quoteless,mode))) { /* Could not open this file */ - if (errno != ENOENT) { - /* The file does exist, this is a lower level error, I can't do anything. */ - _synctex_error("SyncTeX: could not open renamed %s, error %i\n",quoteless_synctex_name,errno); + if(errno != ENOENT) { + /* The file does exist, this is a lower lever error, I can't do anything. */ + _synctex_error("SyncTeX: could not open renamed %s, error %i\n",quoteless,errno); } goto return_on_error; } /* The quote free file name should replace the old one:*/ free(synctex_name); - synctex_name = quoteless_synctex_name; - quoteless_synctex_name = NULL; + synctex_name = quoteless; + quoteless = NULL; } } - /* The operation is successfull, return the arguments by value. */ - * file_ref = the_file; - * io_mode_ref = io_mode; - * synctex_name_ref = synctex_name; + /* We are returning properly so we can also return the proper io_mode */ + *io_modeRef = io_mode; return 0; } return 3; /* Bad parameter. */ +# undef synctex_name +# undef the_file } /* Opens the ouput file, taking into account the eventual build_directory. * 0 on success, non 0 on error. */ -int _synctex_open(const char * output, const char * build_directory, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_mode_ref) { +int _synctex_open(const char * output, const char * build_directory, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_modeRef) { # define synctex_name (*synctex_name_ref) # define the_file (*file_ref) - int result = __synctex_open(output,synctex_name_ref,file_ref,add_quotes,io_mode_ref); - if ((result || !*file_ref) && build_directory && strlen(build_directory)) { + int result = __synctex_open(output,synctex_name_ref,file_ref,add_quotes,io_modeRef); + if((result || !*file_ref) && build_directory && strlen(build_directory)) { char * build_output; - const char *lpc; + const char * lpc; size_t size; synctex_bool_t is_absolute; build_output = NULL; lpc = _synctex_last_path_component(output); - size = strlen(build_directory)+strlen(lpc)+2; /* One for the '/' and one for the '\0'. */ + size = strlen(build_directory)+strlen(lpc)+2; is_absolute = _synctex_path_is_absolute(build_directory); - if (!is_absolute) { + if(!is_absolute) { size += strlen(output); } - if ((build_output = (char *)malloc(size))) { - if (is_absolute) { + if((build_output = (char *)malloc(size))) { + if(is_absolute) { build_output[0] = '\0'; } else { - if (build_output != strcpy(build_output,output)) { + if(build_output != strcpy(build_output,output)) { return -4; } build_output[lpc-output]='\0'; } - if (build_output == strcat(build_output,build_directory)) { + if(build_output == strcat(build_output,build_directory)) { /* Append a path separator if necessary. */ - if (!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) { - if (build_output != strcat(build_output,"/")) { + if(!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) { + if(build_output != strcat(build_output,"/")) { return -2; } } /* Append the last path component of the output. */ - if (build_output != strcat(build_output,lpc)) { + if(build_output != strcat(build_output,lpc)) { return -3; } - return __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref); + return __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_modeRef); } } return -1; @@ -2784,10 +2710,10 @@ int _synctex_open(const char * output, const char * build_directory, char ** syn /* The scanner destructor */ void synctex_scanner_free(synctex_scanner_t scanner) { - if (NULL == scanner) { + if(NULL == scanner) { return; } - if (SYNCTEX_FILE) { + if(SYNCTEX_FILE) { gzclose(SYNCTEX_FILE); SYNCTEX_FILE = NULL; } @@ -2804,7 +2730,7 @@ void synctex_scanner_free(synctex_scanner_t scanner) { /* Where the synctex scanner parses the contents of the file. */ synctex_scanner_t synctex_scanner_parse(synctex_scanner_t scanner) { synctex_status_t status = 0; - if (!scanner || scanner->flags.has_parsed) { + if(!scanner || scanner->flags.has_parsed) { return scanner; } scanner->flags.has_parsed=1; @@ -2835,7 +2761,7 @@ synctex_scanner_t synctex_scanner_parse(synctex_scanner_t scanner) { scanner->class[synctex_node_type_boundary] = synctex_class_boundary; (scanner->class[synctex_node_type_boundary]).scanner = scanner; SYNCTEX_START = (char *)malloc(SYNCTEX_BUFFER_SIZE+1); /* one more character for null termination */ - if (NULL == SYNCTEX_START) { + if(NULL == SYNCTEX_START) { _synctex_error("SyncTeX: malloc error"); synctex_scanner_free(scanner); return NULL; @@ -2847,14 +2773,14 @@ synctex_scanner_t synctex_scanner_parse(synctex_scanner_t scanner) { *SYNCTEX_END = '\0'; SYNCTEX_CUR = SYNCTEX_END; status = _synctex_scan_preamble(scanner); - if (statuspre_unit)/65536 pt = (scanner->pre_unit)/65781.76 bp * 1 pt = 65536 sp */ - if (scanner->pre_unit<=0) { + if(scanner->pre_unit<=0) { scanner->pre_unit = 8192; } - if (scanner->pre_magnification<=0) { + if(scanner->pre_magnification<=0) { scanner->pre_magnification = 1000; } - if (scanner->unit <= 0) { + if(scanner->unit <= 0) { /* no post magnification */ scanner->unit = scanner->pre_unit / 65781.76;/* 65781.76 or 65536.0*/ } else { @@ -2880,7 +2806,7 @@ bailey: scanner->unit *= scanner->pre_unit / 65781.76; } scanner->unit *= scanner->pre_magnification / 1000.0; - if (scanner->x_offset > 6e23) { + if(scanner->x_offset > 6e23) { /* no post offset */ scanner->x_offset = scanner->pre_x_offset * (scanner->pre_unit / 65781.76); scanner->y_offset = scanner->pre_y_offset * (scanner->pre_unit / 65781.76); @@ -2911,7 +2837,7 @@ float synctex_scanner_magnification(synctex_scanner_t scanner){ return scanner?scanner->unit:1; } void synctex_scanner_display(synctex_scanner_t scanner) { - if (NULL == scanner) { + if(NULL == scanner) { return; } printf("The scanner:\noutput:%s\noutput_fmt:%s\nversion:%i\n",scanner->output,scanner->output_fmt,scanner->version); @@ -2920,11 +2846,11 @@ void synctex_scanner_display(synctex_scanner_t scanner) { scanner->count,scanner->unit,scanner->x_offset,scanner->y_offset); printf("The input:\n"); SYNCTEX_DISPLAY(scanner->input); - if (scanner->count<1000) { + if(scanner->count<1000) { printf("The sheets:\n"); SYNCTEX_DISPLAY(scanner->sheet); printf("The friends:\n"); - if (scanner->lists_of_friends) { + if(scanner->lists_of_friends) { int i = scanner->number_of_lists; synctex_node_t node; while(i--) { @@ -2947,12 +2873,12 @@ void synctex_scanner_display(synctex_scanner_t scanner) { /* Public*/ const char * synctex_scanner_get_name(synctex_scanner_t scanner,int tag) { synctex_node_t input = NULL; - if (NULL == scanner) { + if(NULL == scanner) { return NULL; } input = scanner->input; do { - if (tag == SYNCTEX_TAG(input)) { + if(tag == SYNCTEX_TAG(input)) { return (SYNCTEX_NAME(input)); } } while((input = SYNCTEX_SIBLING(input)) != NULL); @@ -2962,12 +2888,12 @@ const char * synctex_scanner_get_name(synctex_scanner_t scanner,int tag) { int _synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name); int _synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { synctex_node_t input = NULL; - if (NULL == scanner) { + if(NULL == scanner) { return 0; } input = scanner->input; do { - if (_synctex_is_equivalent_file_name(name,(SYNCTEX_NAME(input)))) { + if(_synctex_is_equivalent_file_name(name,(SYNCTEX_NAME(input)))) { return SYNCTEX_TAG(input); } } while((input = SYNCTEX_SIBLING(input)) != NULL); @@ -2976,13 +2902,13 @@ int _synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { size_t char_index = strlen(name); - if ((scanner = synctex_scanner_parse(scanner)) && (0 < char_index)) { + if((scanner = synctex_scanner_parse(scanner)) && (0 < char_index)) { /* the name is not void */ char_index -= 1; - if (!SYNCTEX_IS_PATH_SEPARATOR(name[char_index])) { + if(!SYNCTEX_IS_PATH_SEPARATOR(name[char_index])) { /* the last character of name is not a path separator */ int result = _synctex_scanner_get_tag(scanner,name); - if (result) { + if(result) { return result; } else { /* the given name was not the one known by TeX @@ -2996,20 +2922,20 @@ int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { } /* Find the last path separator before relative */ while(relative > name) { - if (SYNCTEX_IS_PATH_SEPARATOR(*(relative-1))) { + if(SYNCTEX_IS_PATH_SEPARATOR(*(relative-1))) { break; } relative -= 1; } - if ((relative > name) && (result = _synctex_scanner_get_tag(scanner,relative))) { + if((relative > name) && (result = _synctex_scanner_get_tag(scanner,relative))) { return result; } - if (SYNCTEX_IS_PATH_SEPARATOR(name[0])) { + if(SYNCTEX_IS_PATH_SEPARATOR(name[0])) { /* No tag found for the given absolute name, * Try each relative path starting from the shortest one */ while(0class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } int synctex_node_box_v(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } - if (SYNCTEX_IS_BOX(node)) { + if(SYNCTEX_IS_BOX(node)) { result: return SYNCTEX_VERT(node); } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } int synctex_node_box_width(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } - if (SYNCTEX_IS_BOX(node)) { + if(SYNCTEX_IS_BOX(node)) { result: return SYNCTEX_WIDTH(node); } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } int synctex_node_box_height(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } - if (SYNCTEX_IS_BOX(node)) { + if(SYNCTEX_IS_BOX(node)) { result: return SYNCTEX_HEIGHT(node); } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } int synctex_node_box_depth(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } - if (SYNCTEX_IS_BOX(node)) { + if(SYNCTEX_IS_BOX(node)) { result: return SYNCTEX_DEPTH(node); } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; @@ -3125,25 +3051,25 @@ result: # pragma mark Public node visible attributes # endif float synctex_node_visible_h(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } return SYNCTEX_HORIZ(node)*node->class->scanner->unit+node->class->scanner->x_offset; } float synctex_node_visible_v(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } return SYNCTEX_VERT(node)*node->class->scanner->unit+node->class->scanner->y_offset; } float synctex_node_visible_width(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } return SYNCTEX_WIDTH(node)*node->class->scanner->unit; } float synctex_node_box_visible_h(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } switch(node->class->type) { @@ -3155,13 +3081,13 @@ float synctex_node_box_visible_h(synctex_node_t node){ result: return SYNCTEX_HORIZ_V(node)*node->class->scanner->unit+node->class->scanner->x_offset; } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } float synctex_node_box_visible_v(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } switch(node->class->type) { @@ -3173,13 +3099,13 @@ float synctex_node_box_visible_v(synctex_node_t node){ result: return SYNCTEX_VERT_V(node)*node->class->scanner->unit+node->class->scanner->y_offset; } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } float synctex_node_box_visible_width(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } switch(node->class->type) { @@ -3191,13 +3117,13 @@ float synctex_node_box_visible_width(synctex_node_t node){ result: return SYNCTEX_WIDTH_V(node)*node->class->scanner->unit; } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } float synctex_node_box_visible_height(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } switch(node->class->type) { @@ -3209,13 +3135,13 @@ float synctex_node_box_visible_height(synctex_node_t node){ result: return SYNCTEX_HEIGHT_V(node)*node->class->scanner->unit; } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; } float synctex_node_box_visible_depth(synctex_node_t node){ - if (!node) { + if(!node) { return 0; } switch(node->class->type) { @@ -3227,7 +3153,7 @@ float synctex_node_box_visible_depth(synctex_node_t node){ result: return SYNCTEX_DEPTH_V(node)*node->class->scanner->unit; } - if ((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { + if((node = SYNCTEX_PARENT(node)) && (node->class->type != synctex_node_type_sheet)) { goto result; } return 0; @@ -3239,7 +3165,7 @@ result: int synctex_node_page(synctex_node_t node){ synctex_node_t parent = NULL; - if (!node) { + if(!node) { return -1; } parent = SYNCTEX_PARENT(node); @@ -3247,7 +3173,7 @@ int synctex_node_page(synctex_node_t node){ node = parent; parent = SYNCTEX_PARENT(node); } - if (node->class->type == synctex_node_type_sheet) { + if(node->class->type == synctex_node_type_sheet) { return SYNCTEX_PAGE(node); } return -1; @@ -3270,10 +3196,10 @@ int synctex_node_column(synctex_node_t node) { # endif synctex_node_t synctex_sheet_content(synctex_scanner_t scanner,int page) { - if (scanner) { + if(scanner) { synctex_node_t sheet = scanner->sheet; while(sheet) { - if (page == SYNCTEX_PAGE(sheet)) { + if(page == SYNCTEX_PAGE(sheet)) { return SYNCTEX_CHILD(sheet); } sheet = SYNCTEX_SIBLING(sheet); @@ -3296,7 +3222,7 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i int friend_index = 0; int max_line = 0; synctex_node_t node = NULL; - if (tag == 0) { + if(tag == 0) { printf("SyncTeX Warning: No tag for %s\n",name); return -1; } @@ -3306,12 +3232,12 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i while(linenumber_of_lists); - if ((node = (scanner->lists_of_friends)[friend_index])) { + if((node = (scanner->lists_of_friends)[friend_index])) { do { - if ((synctex_node_type(node)>=synctex_node_type_boundary) + if((synctex_node_type(node)>=synctex_node_type_boundary) && (tag == SYNCTEX_TAG(node)) && (line == SYNCTEX_LINE(node))) { - if (SYNCTEX_CUR == SYNCTEX_END) { + if(SYNCTEX_CUR == SYNCTEX_END) { size += 16; SYNCTEX_END = realloc(SYNCTEX_START,size*sizeof(synctex_node_t *)); SYNCTEX_CUR += SYNCTEX_END - SYNCTEX_START; @@ -3322,14 +3248,14 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i SYNCTEX_CUR += sizeof(synctex_node_t); } } while((node = SYNCTEX_FRIEND(node))); - if (SYNCTEX_START == NULL) { + if(SYNCTEX_START == NULL) { /* We did not find any matching boundary, retry with glue or kern */ node = (scanner->lists_of_friends)[friend_index];/* no need to test it again, already done */ do { - if ((synctex_node_type(node)>=synctex_node_type_kern) + if((synctex_node_type(node)>=synctex_node_type_kern) && (tag == SYNCTEX_TAG(node)) && (line == SYNCTEX_LINE(node))) { - if (SYNCTEX_CUR == SYNCTEX_END) { + if(SYNCTEX_CUR == SYNCTEX_END) { size += 16; SYNCTEX_END = realloc(SYNCTEX_START,size*sizeof(synctex_node_t *)); SYNCTEX_CUR += SYNCTEX_END - SYNCTEX_START; @@ -3340,13 +3266,13 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i SYNCTEX_CUR += sizeof(synctex_node_t); } } while((node = SYNCTEX_FRIEND(node))); - if (SYNCTEX_START == NULL) { + if(SYNCTEX_START == NULL) { /* We did not find any matching glue or kern, retry with boxes */ node = (scanner->lists_of_friends)[friend_index];/* no need to test it again, already done */ do { - if ((tag == SYNCTEX_TAG(node)) + if((tag == SYNCTEX_TAG(node)) && (line == SYNCTEX_LINE(node))) { - if (SYNCTEX_CUR == SYNCTEX_END) { + if(SYNCTEX_CUR == SYNCTEX_END) { size += 16; SYNCTEX_END = realloc(SYNCTEX_START,size*sizeof(synctex_node_t *)); SYNCTEX_CUR += SYNCTEX_END - SYNCTEX_START; @@ -3361,7 +3287,7 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i } SYNCTEX_END = SYNCTEX_CUR; /* Now reverse the order to have nodes in display order, and keep just a few nodes */ - if ((SYNCTEX_START) && (SYNCTEX_END)) + if((SYNCTEX_START) && (SYNCTEX_END)) { synctex_node_t * start_ref = (synctex_node_t *)SYNCTEX_START; synctex_node_t * end_ref = (synctex_node_t *)SYNCTEX_END; @@ -3380,10 +3306,10 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i end_ref = (synctex_node_t *)SYNCTEX_START; next_end: end_ref += 1; /* we allways have start_ref<= end_ref*/ - if (end_ref < (synctex_node_t *)SYNCTEX_END) { + if(end_ref < (synctex_node_t *)SYNCTEX_END) { node = *end_ref; while((node = SYNCTEX_PARENT(node))) { - if (SYNCTEX_PARENT(*start_ref) == node) { + if(SYNCTEX_PARENT(*start_ref) == node) { goto next_end; } } @@ -3393,10 +3319,9 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i } start_ref += 1; SYNCTEX_END = (char *)start_ref; - return (SYNCTEX_END-SYNCTEX_START)/sizeof(synctex_node_t);// added on behalf Jan Sundermeyer - } + } SYNCTEX_CUR = NULL; - // return (SYNCTEX_END-SYNCTEX_START)/sizeof(synctex_node_t); removed on behalf Jan Sundermeyer + return (SYNCTEX_END-SYNCTEX_START)/sizeof(synctex_node_t); } # if defined(__SYNCTEX_STRONG_DISPLAY_QUERY__) break; @@ -3408,12 +3333,12 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i } synctex_node_t synctex_next_result(synctex_scanner_t scanner) { - if (NULL == SYNCTEX_CUR) { + if(NULL == SYNCTEX_CUR) { SYNCTEX_CUR = SYNCTEX_START; } else { SYNCTEX_CUR+=sizeof(synctex_node_t); } - if (SYNCTEX_CUR= scanner->unit) {/* scanner->unit must be >0 */ + if(NULL == (scanner = synctex_scanner_parse(scanner)) || 0 >= scanner->unit) {/* scanner->unit must be >0 */ return 0; } /* Convert the given point to scanner integer coordinates */ @@ -3495,7 +3420,7 @@ int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v) { while((sheet) && SYNCTEX_PAGE(sheet) != page) { sheet = SYNCTEX_SIBLING(sheet); } - if (NULL == sheet) { + if(NULL == sheet) { return -1; } /* Now sheet points to the sheet node with proper page number */ @@ -3504,30 +3429,30 @@ int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v) { * Then we try with the visible box dimensions. * We try to find a non void box containing the hit point. * We browse all the horizontal boxes until we find one containing the hit point. */ - if ((node = SYNCTEX_NEXT_HORIZ_BOX(sheet))) { + if((node = SYNCTEX_NEXT_HORIZ_BOX(sheet))) { do { - if (_synctex_point_in_box(hitPoint,node,synctex_YES)) { + if(_synctex_point_in_box(hitPoint,node,synctex_YES)) { /* Maybe the hitPoint belongs to a contained vertical box. */ end: /* This trick is for catching overlapping boxes */ - if ((other_node = SYNCTEX_NEXT_HORIZ_BOX(node))) { + if((other_node = SYNCTEX_NEXT_HORIZ_BOX(node))) { do { - if (_synctex_point_in_box(hitPoint,other_node,synctex_YES)) { + if(_synctex_point_in_box(hitPoint,other_node,synctex_YES)) { node = _synctex_smallest_container(other_node,node); } } while((other_node = SYNCTEX_NEXT_HORIZ_BOX(other_node))); } /* node is the smallest horizontal box that contains hitPoint. */ - if ((bestContainer = _synctex_eq_deepest_container(hitPoint,node,synctex_YES))) { + if((bestContainer = _synctex_eq_deepest_container(hitPoint,node,synctex_YES))) { node = bestContainer; } _synctex_eq_get_closest_children_in_box(hitPoint,node,&bestNodes,&bestDistances,synctex_YES); - if (bestNodes.right && bestNodes.left) { - if ((SYNCTEX_TAG(bestNodes.right)!=SYNCTEX_TAG(bestNodes.left)) + if(bestNodes.right && bestNodes.left) { + if((SYNCTEX_TAG(bestNodes.right)!=SYNCTEX_TAG(bestNodes.left)) || (SYNCTEX_LINE(bestNodes.right)!=SYNCTEX_LINE(bestNodes.left)) || (SYNCTEX_COLUMN(bestNodes.right)!=SYNCTEX_COLUMN(bestNodes.left))) { - if ((SYNCTEX_START = malloc(2*sizeof(synctex_node_t)))) { - if (bestDistances.left>bestDistances.right) { + if((SYNCTEX_START = malloc(2*sizeof(synctex_node_t)))) { + if(bestDistances.left>bestDistances.right) { ((synctex_node_t *)SYNCTEX_START)[0] = bestNodes.right; ((synctex_node_t *)SYNCTEX_START)[1] = bestNodes.left; } else { @@ -3542,16 +3467,16 @@ end: } /* both nodes have the same input coordinates * We choose the one closest to the hit point */ - if (bestDistances.left>bestDistances.right) { + if(bestDistances.left>bestDistances.right) { bestNodes.left = bestNodes.right; } bestNodes.right = NULL; - } else if (bestNodes.right) { + } else if(bestNodes.right) { bestNodes.left = bestNodes.right; - } else if (!bestNodes.left){ + } else if(!bestNodes.left){ bestNodes.left = node; } - if ((SYNCTEX_START = malloc(sizeof(synctex_node_t)))) { + if((SYNCTEX_START = malloc(sizeof(synctex_node_t)))) { * (synctex_node_t *)SYNCTEX_START = bestNodes.left; SYNCTEX_END = SYNCTEX_START + sizeof(synctex_node_t); SYNCTEX_CUR = NULL; @@ -3565,7 +3490,7 @@ end: */ } /* We are not lucky */ - if ((node = SYNCTEX_CHILD(sheet))) { + if((node = SYNCTEX_CHILD(sheet))) { goto end; } return 0; @@ -3586,7 +3511,7 @@ int _synctex_bail(void) { * if node is to the left of the hit point, this distance is negative.*/ int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, synctex_bool_t visible); int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, synctex_bool_t visible) { - if (node) { + if(node) { int min,med,max; switch(node->class->type) { /* The distance between a point and a box is special. @@ -3609,7 +3534,7 @@ int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, syn min = visible?SYNCTEX_HORIZ_V(node):SYNCTEX_HORIZ(node); max = min + (visible?SYNCTEX_ABS_WIDTH_V(node):SYNCTEX_ABS_WIDTH(node)); /* We allways have min <= max */ - if (hitPoint.h 0 */ } else if (hitPoint.h>max) { return max - hitPoint.h; /* regions 3+6+9, result is < 0 */ @@ -3625,7 +3550,7 @@ int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, syn min = SYNCTEX_HORIZ(node); max = min + SYNCTEX_ABS_WIDTH(node); /* We allways have min <= max */ - if (hitPoint.h 0 */ } else if (hitPoint.h>max) { return max - hitPoint.h; /* regions 3+6+9, result is < 0 */ @@ -3639,7 +3564,7 @@ int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, syn * in general, there is no text material in the kern, * this is why we compute the offset relative to the closest edge of the kern.*/ max = SYNCTEX_WIDTH(node); - if (max<0) { + if(max<0) { min = SYNCTEX_HORIZ(node); max = min - max; } else { @@ -3663,7 +3588,7 @@ int _synctex_point_h_distance(synctex_point_t hitPoint, synctex_node_t node, syn * It means that the best choice should be made according to the situation that occurs * most frequently. */ - if (hitPoint.hmax) { return max - hitPoint.h - 1; /* same kind of penalty */ @@ -3689,7 +3614,7 @@ int _synctex_point_v_distance(synctex_point_t hitPoint, synctex_node_t node,sync # ifdef __DARWIN_UNIX03 # pragma unused(visible) # endif - if (node) { + if(node) { int min,max; switch(node->class->type) { /* The distance between a point and a box is special. @@ -3713,7 +3638,7 @@ int _synctex_point_v_distance(synctex_point_t hitPoint, synctex_node_t node,sync max = min + SYNCTEX_ABS_DEPTH_V(node); min -= SYNCTEX_ABS_HEIGHT_V(node); /* We allways have min <= max */ - if (hitPoint.v 0 */ } else if (hitPoint.v>max) { return max - hitPoint.v; /* regions 7+8+9, result is < 0 */ @@ -3729,7 +3654,7 @@ int _synctex_point_v_distance(synctex_point_t hitPoint, synctex_node_t node,sync max = min + SYNCTEX_ABS_DEPTH(node); min -= SYNCTEX_ABS_HEIGHT(node); /* We allways have min <= max */ - if (hitPoint.v 0 */ } else if (hitPoint.v>max) { return max - hitPoint.v; /* regions 7+8+9, result is < 0 */ @@ -3748,26 +3673,26 @@ int _synctex_point_v_distance(synctex_point_t hitPoint, synctex_node_t node,sync SYNCTEX_INLINE static synctex_node_t _synctex_smallest_container(synctex_node_t node, synctex_node_t other_node) { float height, other_height; - if (SYNCTEX_ABS_WIDTH(node)SYNCTEX_ABS_WIDTH(other_node)) { + if(SYNCTEX_ABS_WIDTH(node)>SYNCTEX_ABS_WIDTH(other_node)) { return other_node; } height = SYNCTEX_ABS_DEPTH(node) + SYNCTEX_ABS_HEIGHT(node); other_height = SYNCTEX_ABS_DEPTH(other_node) + SYNCTEX_ABS_HEIGHT(other_node); - if (heightother_height) { + if(height>other_height) { return other_node; } return node; } synctex_bool_t _synctex_point_in_box(synctex_point_t hitPoint, synctex_node_t node, synctex_bool_t visible) { - if (node) { - if (0 == _synctex_point_h_distance(hitPoint,node,visible) + if(node) { + if(0 == _synctex_point_h_distance(hitPoint,node,visible) && 0 == _synctex_point_v_distance(hitPoint,node,visible)) { return synctex_YES; } @@ -3780,7 +3705,7 @@ int _synctex_node_distance_to_point(synctex_point_t hitPoint, synctex_node_t nod # pragma unused(visible) # endif int result = INT_MAX; /* when the distance is meaning less (sheet, input...) */ - if (node) { + if(node) { int minH,maxH,minV,maxV; switch(node->class->type) { /* The distance between a point and a box is special. @@ -3810,22 +3735,22 @@ int _synctex_node_distance_to_point(synctex_point_t hitPoint, synctex_node_t nod maxV = minV + SYNCTEX_ABS_DEPTH(node); minV -= SYNCTEX_ABS_HEIGHT(node); /* In what region is the point hitPoint=(H,V) ? */ - if (hitPoint.vminV) { + if(hitPoint.hminV) { result = hitPoint.v - minV + minH - hitPoint.h; } else { result = minV - hitPoint.v + minH - hitPoint.h; } } else if (hitPoint.h>maxH) { - if (hitPoint.v>minV) { + if(hitPoint.v>minV) { result = hitPoint.v - minV + hitPoint.h - maxH; } else { result = minV - hitPoint.v + hitPoint.h - maxH; } - } else if (hitPoint.v>minV) { + } else if(hitPoint.v>minV) { result = hitPoint.v - minV; } else { result = minV - hitPoint.v; @@ -3878,13 +3803,13 @@ int _synctex_node_distance_to_point(synctex_point_t hitPoint, synctex_node_t nod case synctex_node_type_math: minH = SYNCTEX_HORIZ(node); minV = SYNCTEX_VERT(node); - if (hitPoint.hminV) { + if(hitPoint.hminV) { result = hitPoint.v - minV + minH - hitPoint.h; } else { result = minV - hitPoint.v + minH - hitPoint.h; } - } else if (hitPoint.v>minV) { + } else if(hitPoint.v>minV) { result = hitPoint.v - minV + hitPoint.h - minH; } else { result = minV - hitPoint.v + hitPoint.h - minH; @@ -3896,31 +3821,31 @@ int _synctex_node_distance_to_point(synctex_point_t hitPoint, synctex_node_t nod } static synctex_node_t _synctex_eq_deepest_container(synctex_point_t hitPoint,synctex_node_t node, synctex_bool_t visible) { - if (node) { + if(node) { synctex_node_t result = NULL; synctex_node_t child = NULL; switch(node->class->type) { case synctex_node_type_vbox: case synctex_node_type_hbox: /* test the deep nodes first */ - if ((child = SYNCTEX_CHILD(node))) { + if((child = SYNCTEX_CHILD(node))) { do { - if ((result = _synctex_eq_deepest_container(hitPoint,child,visible))) { + if((result = _synctex_eq_deepest_container(hitPoint,child,visible))) { return result; } } while((child = SYNCTEX_SIBLING(child))); } /* is the hit point inside the box? */ - if (_synctex_point_in_box(hitPoint,node,visible)) { + if(_synctex_point_in_box(hitPoint,node,visible)) { /* for vboxes we try to use some node inside. * Walk through the list of siblings until we find the closest one. * Only consider siblings with children. */ - if ((node->class->type == synctex_node_type_vbox) && (child = SYNCTEX_CHILD(node))) { + if((node->class->type == synctex_node_type_vbox) && (child = SYNCTEX_CHILD(node))) { int bestDistance = INT_MAX; do { - if (SYNCTEX_CHILD(child)) { + if(SYNCTEX_CHILD(child)) { int distance = _synctex_node_distance_to_point(hitPoint,child,visible); - if (distance < bestDistance) { + if(distance < bestDistance) { bestDistance = distance; node = child; } @@ -3939,20 +3864,20 @@ static synctex_node_t _synctex_eq_deepest_container(synctex_point_t hitPoint,syn SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_point_t hitPoint, synctex_node_t node, synctex_node_set_t* bestNodesRef,synctex_distances_t* bestDistancesRef, synctex_bool_t visible); SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_point_t hitPoint, synctex_node_t node, synctex_node_set_t* bestNodesRef,synctex_distances_t* bestDistancesRef, synctex_bool_t visible) { int result = 0; - if ((node = SYNCTEX_CHILD(node))) { + if((node = SYNCTEX_CHILD(node))) { do { int off7 = _synctex_point_h_distance(hitPoint,node,visible); - if (off7 > 0) { + if(off7 > 0) { /* node is to the right of the hit point. * We compare node and the previously recorded one, through the recorded distance. * If the nodes have the same tag, prefer the one with the smallest line number, * if the nodes also have the same line number, prefer the one with the smallest column. */ - if (bestDistancesRef->right > off7) { + if(bestDistancesRef->right > off7) { bestDistancesRef->right = off7; bestNodesRef->right = node; result |= SYNCTEX_MASK_RIGHT; - } else if (bestDistancesRef->right == off7 && bestNodesRef->right) { - if (SYNCTEX_TAG(bestNodesRef->right) == SYNCTEX_TAG(node) + } else if(bestDistancesRef->right == off7 && bestNodesRef->right) { + if(SYNCTEX_TAG(bestNodesRef->right) == SYNCTEX_TAG(node) && (SYNCTEX_LINE(bestNodesRef->right) > SYNCTEX_LINE(node) || (SYNCTEX_LINE(bestNodesRef->right) == SYNCTEX_LINE(node) && SYNCTEX_COLUMN(bestNodesRef->right) > SYNCTEX_COLUMN(node)))) { @@ -3960,7 +3885,7 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_poin result |= SYNCTEX_MASK_RIGHT; } } - } else if (off7 == 0) { + } else if(off7 == 0) { /* hitPoint is inside node. */ bestDistancesRef->left = bestDistancesRef->right = 0; bestNodesRef->left = node; @@ -3968,12 +3893,12 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_poin result |= SYNCTEX_MASK_LEFT; } else { /* here off7 < 0, hitPoint is to the right of node */ off7 = -off7; - if (bestDistancesRef->left > off7) { + if(bestDistancesRef->left > off7) { bestDistancesRef->left = off7; bestNodesRef->left = node; result |= SYNCTEX_MASK_LEFT; - } else if (bestDistancesRef->left == off7 && bestNodesRef->left) { - if (SYNCTEX_TAG(bestNodesRef->left) == SYNCTEX_TAG(node) + } else if(bestDistancesRef->left == off7 && bestNodesRef->left) { + if(SYNCTEX_TAG(bestNodesRef->left) == SYNCTEX_TAG(node) && (SYNCTEX_LINE(bestNodesRef->left) > SYNCTEX_LINE(node) || (SYNCTEX_LINE(bestNodesRef->left) == SYNCTEX_LINE(node) && SYNCTEX_COLUMN(bestNodesRef->left) > SYNCTEX_COLUMN(node)))) { @@ -3983,21 +3908,21 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_poin } } } while((node = SYNCTEX_SIBLING(node))); - if (result & SYNCTEX_MASK_LEFT) { + if(result & SYNCTEX_MASK_LEFT) { /* the left node is new, try to narrow the result */ - if ((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->left,visible))) { + if((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->left,visible))) { bestNodesRef->left = node; } - if ((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->left,visible))) { + if((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->left,visible))) { bestNodesRef->left = node; } } - if (result & SYNCTEX_MASK_RIGHT) { + if(result & SYNCTEX_MASK_RIGHT) { /* the right node is new, try to narrow the result */ - if ((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->right,visible))) { + if((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->right,visible))) { bestNodesRef->right = node; } - if ((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->right,visible))) { + if((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->right,visible))) { bestNodesRef->right = node; } } @@ -4007,20 +3932,20 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_hbox(synctex_poin SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_vbox(synctex_point_t hitPoint, synctex_node_t node, synctex_node_set_t* bestNodesRef,synctex_distances_t* bestDistancesRef,synctex_bool_t visible); SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_vbox(synctex_point_t hitPoint, synctex_node_t node, synctex_node_set_t* bestNodesRef,synctex_distances_t* bestDistancesRef,synctex_bool_t visible) { int result = 0; - if ((node = SYNCTEX_CHILD(node))) { + if((node = SYNCTEX_CHILD(node))) { do { int off7 = _synctex_point_v_distance(hitPoint,node,visible);/* this is what makes the difference with the h version above */ - if (off7 > 0) { + if(off7 > 0) { /* node is to the top of the hit point (below because TeX is oriented from top to bottom. * We compare node and the previously recorded one, through the recorded distance. * If the nodes have the same tag, prefer the one with the smallest line number, * if the nodes also have the same line number, prefer the one with the smallest column. */ - if (bestDistancesRef->right > off7) { + if(bestDistancesRef->right > off7) { bestDistancesRef->right = off7; bestNodesRef->right = node; result |= SYNCTEX_MASK_RIGHT; - } else if (bestDistancesRef->right == off7 && bestNodesRef->right) { - if (SYNCTEX_TAG(bestNodesRef->right) == SYNCTEX_TAG(node) + } else if(bestDistancesRef->right == off7 && bestNodesRef->right) { + if(SYNCTEX_TAG(bestNodesRef->right) == SYNCTEX_TAG(node) && (SYNCTEX_LINE(bestNodesRef->right) > SYNCTEX_LINE(node) || (SYNCTEX_LINE(bestNodesRef->right) == SYNCTEX_LINE(node) && SYNCTEX_COLUMN(bestNodesRef->right) > SYNCTEX_COLUMN(node)))) { @@ -4028,19 +3953,19 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_vbox(synctex_poin result |= SYNCTEX_MASK_RIGHT; } } - } else if (off7 == 0) { + } else if(off7 == 0) { bestDistancesRef->left = bestDistancesRef->right = 0; bestNodesRef->left = node; bestNodesRef->right = NULL; result |= SYNCTEX_MASK_LEFT; } else { /* here off7 < 0 */ off7 = -off7; - if (bestDistancesRef->left > off7) { + if(bestDistancesRef->left > off7) { bestDistancesRef->left = off7; bestNodesRef->left = node; result |= SYNCTEX_MASK_LEFT; - } else if (bestDistancesRef->left == off7 && bestNodesRef->left) { - if (SYNCTEX_TAG(bestNodesRef->left) == SYNCTEX_TAG(node) + } else if(bestDistancesRef->left == off7 && bestNodesRef->left) { + if(SYNCTEX_TAG(bestNodesRef->left) == SYNCTEX_TAG(node) && (SYNCTEX_LINE(bestNodesRef->left) > SYNCTEX_LINE(node) || (SYNCTEX_LINE(bestNodesRef->left) == SYNCTEX_LINE(node) && SYNCTEX_COLUMN(bestNodesRef->left) > SYNCTEX_COLUMN(node)))) { @@ -4050,21 +3975,21 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_vbox(synctex_poin } } } while((node = SYNCTEX_SIBLING(node))); - if (result & SYNCTEX_MASK_LEFT) { + if(result & SYNCTEX_MASK_LEFT) { /* the left node is new, try to narrow the result */ - if ((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->left,visible))) { + if((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->left,visible))) { bestNodesRef->left = node; } - if ((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->left,visible))) { + if((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->left,visible))) { bestNodesRef->left = node; } } - if (result & SYNCTEX_MASK_RIGHT) { + if(result & SYNCTEX_MASK_RIGHT) { /* the right node is new, try to narrow the result */ - if ((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->right,visible))) { + if((node = _synctex_eq_deepest_container(hitPoint,bestNodesRef->right,visible))) { bestNodesRef->right = node; } - if ((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->right,visible))) { + if((node = _synctex_eq_closest_child(hitPoint,bestNodesRef->right,visible))) { bestNodesRef->right = node; } } @@ -4072,7 +3997,7 @@ SYNCTEX_INLINE static int __synctex_eq_get_closest_children_in_vbox(synctex_poin return result; } SYNCTEX_INLINE static int _synctex_eq_get_closest_children_in_box(synctex_point_t hitPoint, synctex_node_t node, synctex_node_set_t* bestNodesRef,synctex_distances_t* bestDistancesRef,synctex_bool_t visible) { - if (node) { + if(node) { switch(node->class->type) { case synctex_node_type_hbox: return __synctex_eq_get_closest_children_in_hbox(hitPoint, node, bestNodesRef, bestDistancesRef,visible); @@ -4086,18 +4011,18 @@ SYNCTEX_INLINE static int _synctex_eq_get_closest_children_in_box(synctex_point_ SYNCTEX_INLINE static synctex_node_t __synctex_eq_closest_child(synctex_point_t hitPoint, synctex_node_t node,int* distanceRef, synctex_bool_t visible); SYNCTEX_INLINE static synctex_node_t __synctex_eq_closest_child(synctex_point_t hitPoint, synctex_node_t node,int* distanceRef, synctex_bool_t visible) { synctex_node_t best_node = NULL; - if ((node = SYNCTEX_CHILD(node))) { + if((node = SYNCTEX_CHILD(node))) { do { int distance = _synctex_node_distance_to_point(hitPoint,node,visible); synctex_node_t candidate = NULL; - if (distance<=*distanceRef) { + if(distance<=*distanceRef) { *distanceRef = distance; best_node = node; } switch(node->class->type) { case synctex_node_type_vbox: case synctex_node_type_hbox: - if ((candidate = __synctex_eq_closest_child(hitPoint,node,distanceRef,visible))) { + if((candidate = __synctex_eq_closest_child(hitPoint,node,distanceRef,visible))) { best_node = candidate; } } @@ -4106,23 +4031,23 @@ SYNCTEX_INLINE static synctex_node_t __synctex_eq_closest_child(synctex_point_t return best_node; } SYNCTEX_INLINE static synctex_node_t _synctex_eq_closest_child(synctex_point_t hitPoint,synctex_node_t node, synctex_bool_t visible) { - if (node) { + if(node) { switch(node->class->type) { case synctex_node_type_hbox: case synctex_node_type_vbox: { int best_distance = INT_MAX; synctex_node_t best_node = __synctex_eq_closest_child(hitPoint,node,&best_distance,visible); - if ((best_node)) { + if((best_node)) { synctex_node_t child = NULL; switch(best_node->class->type) { case synctex_node_type_vbox: case synctex_node_type_hbox: - if ((child = SYNCTEX_CHILD(best_node))) { + if((child = SYNCTEX_CHILD(best_node))) { best_distance = _synctex_node_distance_to_point(hitPoint,child,visible); while((child = SYNCTEX_SIBLING(child))) { int distance = _synctex_node_distance_to_point(hitPoint,child,visible); - if (distance<=best_distance) { + if(distance<=best_distance) { best_distance = distance; best_node = child; } @@ -4162,29 +4087,27 @@ struct __synctex_updater_t { synctex_updater_t synctex_updater_new_with_output_file(const char * output, const char * build_directory) { synctex_updater_t updater = NULL; char * synctex = NULL; - synctex_io_mode_t io_mode = 0; - const char * mode = NULL; - /* prepare the updater, the memory is the only one dynamically allocated */ + synctex_io_mode_t io_mode = synctex_io_mode_read; + const char * mode; + /* prepare the updater */ updater = (synctex_updater_t)_synctex_malloc(sizeof(synctex_updater_t)); - if (NULL == updater) { + if(NULL == updater) { _synctex_error("! synctex_updater_new_with_file: malloc problem"); return NULL; } - if (_synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_ADD_QUOTES,&io_mode) - && _synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_DONT_ADD_QUOTES,&io_mode)) { + if(_synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_NO,&io_mode) + && _synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_YES,&io_mode)) { return_on_error: free(updater); - updater = NULL; return NULL; } - /* OK, the file exists, we close it and reopen it with the correct mode. - * The receiver is now the owner of the "synctex" variable. */ + /* OK, the file exists */ gzclose(SYNCTEX_FILE); SYNCTEX_FILE = NULL; - SYNCTEX_NO_GZ = (io_mode&synctex_io_gz_mask)?synctex_NO:synctex_YES; - mode = _synctex_get_io_mode_name(io_mode|synctex_io_append_mask);/* either "a" or "ab", depending on the file extension */ - if (SYNCTEX_NO_GZ) { - if (NULL == (SYNCTEX_FILE = (void *)fopen(synctex,mode))) { + SYNCTEX_NO_GZ = io_mode%2?synctex_NO:synctex_YES; + mode = synctex_io_modes[io_mode+synctex_io_mode_append];/* either "a" or "ab", depending on the file extension */ + if(SYNCTEX_NO_GZ) { + if(NULL == (SYNCTEX_FILE = (void *)fopen(synctex,mode))) { no_write_error: _synctex_error("! synctex_updater_new_with_file: Can't append to %s",synctex); free(synctex); @@ -4192,7 +4115,7 @@ no_write_error: } updater->fprintf = (synctex_fprintf_t)(&fprintf); } else { - if (NULL == (SYNCTEX_FILE = (void *)gzopen(synctex,mode))) { + if(NULL == (SYNCTEX_FILE = (void *)gzopen(synctex,mode))) { goto no_write_error; } updater->fprintf = (synctex_fprintf_t)(&gzprintf); @@ -4204,37 +4127,37 @@ no_write_error: void synctex_updater_append_magnification(synctex_updater_t updater, char * magnification){ - if (NULL==updater) { + if(NULL==updater) { return; } - if (magnification && strlen(magnification)) { + if(magnification && strlen(magnification)) { updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"Magnification:%s\n",magnification); } } void synctex_updater_append_x_offset(synctex_updater_t updater, char * x_offset){ - if (NULL==updater) { + if(NULL==updater) { return; } - if (x_offset && strlen(x_offset)) { + if(x_offset && strlen(x_offset)) { updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"X Offset:%s\n",x_offset); } } void synctex_updater_append_y_offset(synctex_updater_t updater, char * y_offset){ - if (NULL==updater) { + if(NULL==updater) { return; } - if (y_offset && strlen(y_offset)) { + if(y_offset && strlen(y_offset)) { updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"Y Offset:%s\n",y_offset); } } void synctex_updater_free(synctex_updater_t updater){ - if (NULL==updater) { + if(NULL==updater) { return; } - if (updater->length>0) { + if(updater->length>0) { SYNCTEX_fprintf(SYNCTEX_FILE,"!%i\n",updater->length); } if (SYNCTEX_NO_GZ) { diff --git a/cut-n-paste/synctex/synctex_parser.h b/cut-n-paste/synctex/synctex_parser.h index 87cff430..b164b7fb 100644 --- a/cut-n-paste/synctex/synctex_parser.h +++ b/cut-n-paste/synctex/synctex_parser.h @@ -1,12 +1,11 @@ /* -Copyright (c) 2008, 2009, 2010 , 2011 jerome DOT laurens AT u-bourgogne DOT fr +Copyright (c) 2008, 2009, 2010 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 Jul 1 11:16:51 UTC 2009 +Version: 1.12 See synctex_parser_readme.txt for more details License: @@ -90,7 +89,7 @@ typedef _synctex_scanner_t * synctex_scanner_t; * It is the directory where all the auxiliary stuff is created. * Sometimes, the synctex output file and the pdf, dvi or xdv files are not created in the same directory. * This is the case in MikTeX (I will include this into TeX Live). - * This directory path can be nil, it will be ignored then. + * This directory path can be nil, it will be ignored. * It can be either absolute or relative to the directory of the output pdf (dvi or xdv) file. * If no synctex file is found in the same directory as the output file, then we try to find one in the build directory. * Please note that this new "build_directory" is provided as a convenient argument but should not be used. diff --git a/cut-n-paste/synctex/synctex_parser_local.h b/cut-n-paste/synctex/synctex_parser_local.h index e4f88295..0a127afe 100644 --- a/cut-n-paste/synctex/synctex_parser_local.h +++ b/cut-n-paste/synctex/synctex_parser_local.h @@ -1,13 +1,9 @@ /* -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 - -See synctex_parser_readme.txt for more details +Latest Revision: Wed Jul 1 11:16:13 UTC 2009 License: -------- 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]; -} diff --git a/cut-n-paste/synctex/synctex_parser_utils.h b/cut-n-paste/synctex/synctex_parser_utils.h index 6d36d738..e28ff58a 100644 --- a/cut-n-paste/synctex/synctex_parser_utils.h +++ b/cut-n-paste/synctex/synctex_parser_utils.h @@ -1,12 +1,10 @@ /* -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 - +Version: 1.8 +Latest Revision: Wed Jul 1 11:16:01 UTC 2009 See synctex_parser_readme.txt for more details License: @@ -46,11 +44,7 @@ authorization from the copyright holder. # define synctex_bool_t int # define synctex_YES -1 -# define synctex_ADD_QUOTES -1 -# define synctex_COMPRESS -1 # define synctex_NO 0 -# define synctex_DONT_ADD_QUOTES 0 -# define synctex_DONT_COMPRESS 0 #ifndef __SYNCTEX_PARSER_UTILS__ # define __SYNCTEX_PARSER_UTILS__ @@ -109,22 +103,18 @@ int _synctex_copy_with_quoting_last_path_component(const char * src, char ** des extern const char * synctex_suffix; extern const char * synctex_suffix_gz; -typedef unsigned int synctex_io_mode_t; - typedef enum { - synctex_io_append_mask = 1, - synctex_io_gz_mask = synctex_io_append_mask<<1 -} synctex_io_mode_masks_t; + synctex_io_mode_read = 0, + synctex_io_mode_append = 2 +} synctex_io_mode_t; typedef enum { synctex_compress_mode_none = 0, synctex_compress_mode_gz = 1 } synctex_compress_mode_t; -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); -/* returns the correct mode required by fopen and gzopen from the given io_mode */ -const char * _synctex_get_io_mode_name(synctex_io_mode_t io_mode); #ifdef __cplusplus } diff --git a/cut-n-paste/synctex/synctex_parser_version.txt b/cut-n-paste/synctex/synctex_parser_version.txt index 9f76d37b..b8162070 100644 --- a/cut-n-paste/synctex/synctex_parser_version.txt +++ b/cut-n-paste/synctex/synctex_parser_version.txt @@ -1 +1 @@ -1.13 \ No newline at end of file +1.11 \ No newline at end of file