diff options
author | Jonathan Kew <jfkthame@googlemail.com> | 2008-05-30 08:32:13 +0000 |
---|---|---|
committer | Jonathan Kew <jfkthame@googlemail.com> | 2008-05-30 08:32:13 +0000 |
commit | 7e2b28525984e00197cb1ddf7499f8d38714bf02 (patch) | |
tree | ac445714a3dcae5c6bb2a92e42644a548d0a315c /Build | |
parent | 24166fd2be0b84b2ce72f58e7ec0da93280b394a (diff) |
synctex update from JL
git-svn-id: svn://tug.org/texlive/trunk@8415 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r-- | Build/source/texk/web2c/synctex/synctex.mk | 2 | ||||
-rw-r--r-- | Build/source/texk/web2c/synctex/synctex_main.c | 272 | ||||
-rw-r--r-- | Build/source/texk/web2c/synctex/synctex_parser.c | 902 | ||||
-rw-r--r-- | Build/source/texk/web2c/synctex/synctex_parser.h | 30 |
4 files changed, 689 insertions, 517 deletions
diff --git a/Build/source/texk/web2c/synctex/synctex.mk b/Build/source/texk/web2c/synctex/synctex.mk index 711c7cb50c1..7a6acf6a38e 100644 --- a/Build/source/texk/web2c/synctex/synctex.mk +++ b/Build/source/texk/web2c/synctex/synctex.mk @@ -41,7 +41,7 @@ Makefile: $(synctex_dir)/synctex.mk # for all the engines, this trick allows to enable or disable SyncTeX support from here. # One of the synctex functions is called before the main_control routine -# this is why we must include synctex.h header +# this is why we must include synctex-common.h header synctex_common_texd = \ echo "Enabling SyncTeX Support.";\ echo "s|\#include \"texmfmp.h\"|&\\"> synctex_sed_command.txt;\ diff --git a/Build/source/texk/web2c/synctex/synctex_main.c b/Build/source/texk/web2c/synctex/synctex_main.c index 9b19205cf9e..b223edd527e 100644 --- a/Build/source/texk/web2c/synctex/synctex_main.c +++ b/Build/source/texk/web2c/synctex/synctex_main.c @@ -41,6 +41,7 @@ This is the command line interface to the synctex_parser.c. # include <stdio.h> # include <string.h> # include <stdarg.h> +# include <math.h> # include "synctex_parser.h" /* The code below uses strlcat and strlcpy, which avoids security warnings with some compilers. @@ -54,6 +55,12 @@ This is the command line interface to the synctex_parser.c. #define strlcpy(dst, src, size) strcpy((dst), (src)) #endif +#define SYNCTEX_DEBUG 0 + +#if SYNCTEX_DEBUG +# include "unistd.h" +#endif + int main(int argc, char *argv[]); void synctex_help(char * error,...); @@ -67,6 +74,7 @@ int synctex_update(int argc, char *argv[]); int main(int argc, char *argv[]) { int arg_index = 1; + printf("This is SyncTeX command line utility, version 1.0\n"); if(arg_index<argc) { if(0==strcmp("help",argv[arg_index])) { if(++arg_index<argc) { @@ -120,7 +128,6 @@ void synctex_help(char * error,...) { " update to update a synctex file after a dvi/xdv to pdf filter\n" " help this help\n\n" "Type 'synctex help <subcommand>' for help on a specific subcommand.\n" - "Type 'synctex --version' to see the program version number.\n\n" ); return; } @@ -142,10 +149,12 @@ void synctex_help_view(char * error,...) { " column is the offset of a character relative to the containing line.\n" " Pass 0 if this information is not relevant.\n" " input is either the name of the main source file or an included document.\n" - " It must be the very name as understood by TeX.\n" + " It must be the very name as understood by TeX, id est the name exactly as it appears in the log file.\n" + " It does not matter if the file actually exists or not, except that the command is not really useful.\n" " \n" "-o output\n" - " is the full path of the output file (with any relevant path extension).\n" + " is the full or relative path of the output file (with any relevant path extension).\n" + " This file must exist.\n" " \n" "-x viewer-command\n" " Normally the synctex tool outputs its result to the stdout.\n" @@ -190,19 +199,14 @@ int synctex_view(int argc, char *argv[]) { char * input = NULL; char * viewer = NULL; char * before = NULL; - int offset = 0; + unsigned int offset = 0; char * middle = NULL; char * after = NULL; char * output = NULL; char * start = NULL; char * end = NULL; synctex_scanner_t scanner = NULL; - char * synctex = NULL; size_t size = 0; - const char * suffix = ".synctex"; - const char * suffix_gz = ".gz"; - char * ptr = NULL; - char * where = NULL; /* required */ if((arg_index>=argc) || strcmp("-i",argv[arg_index]) || (++arg_index>=argc)) { @@ -260,8 +264,8 @@ option_hint: before = argv[arg_index]; *after = '\0'; ++after; - offset = strtol(after,&middle,10); - if(middle>after && offset>=0 && strlen(middle)>2) { + offset = strtoul(after,&middle,10); + if(middle>after && strlen(middle)>2) { after = strstr(++middle,"/"); if(NULL != after) { *after = '\0'; @@ -292,54 +296,11 @@ proceed: #endif /* We assume that viewer is not so big: */ # define SYNCTEX_STR_SIZE 65536 - if(viewer && strlen(viewer)>=65536) { + if(viewer && strlen(viewer)>=SYNCTEX_STR_SIZE) { synctex_help_view("Viewer command is too long"); return -1; } - size = strlen(output)+strlen(suffix)+strlen(suffix_gz)+1; - synctex = (char *)malloc(size); - if(NULL == synctex) { - synctex_help_view("No more memory"); - return -1; - } - if(0 == strlcpy(synctex,output,size)) { - synctex_help_view("Copy problem"); - return -1; - } - ptr = synctex; - /* remove the path extension of the last path component. */ -# define SYNCTEX_PATH_COMPONENTS_SEPARATOR "/" - if((where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL); - } -# define SYNCTEX_PATH_EXTENSION_SEPARATOR "." - if((where = strstr(ptr,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL); - *ptr = '\0'; - } - if(0 == strlcat(synctex,suffix,size)){ - synctex_help_view("Concatenation problem (can't add suffix '%s')",suffix); - return -1; - } - scanner = synctex_scanner_new_with_contents_of_file(synctex); - if(!scanner) { - if(0 == strlcat(synctex,suffix_gz,size)){ - synctex_help_view("Concatenation problem (can't add suffix '%s')",suffix_gz); - return -1; - } - scanner = synctex_scanner_new_with_contents_of_file(synctex); - if(!scanner) { - synctex_help_view("No SyncTeX available"); - return -1; - } - } - size = 0; - free(synctex); - synctex = NULL; + scanner = synctex_scanner_new_with_output_file(output); if(scanner && synctex_display_query(scanner,input,line,column)) { synctex_node_t node = NULL; if((node = synctex_next_result(scanner)) != NULL) { @@ -381,39 +342,44 @@ proceed: /* find the next occurrence of a format key */ where = viewer; while(viewer && (where = strstr(viewer,"&{"))) { - char * format_key = NULL; #define TEST(KEY,FORMAT,WHAT)\ - format_key="&{output}";\ - if(!strcmp(viewer,format_key)) {\ + if(!strncmp(where,KEY,strlen(KEY))) {\ printed = where-viewer;\ - if(buffer != memcpy(buffer_cur,viewer,(size_t)printed)) {\ + if(buffer_cur != memcpy(buffer_cur,viewer,(size_t)printed)) {\ synctex_help_view("Memory copy problem");\ free(buffer);\ return -1;\ }\ buffer_cur += printed;size-=printed;\ - printed = snprintf(buffer_cur,size,"%s","<main output>");\ + printed = snprintf(buffer_cur,size,FORMAT,WHAT);\ buffer_cur += printed;size-=printed;\ *buffer_cur='\0';\ - viewer = where+strlen(format_key);\ + viewer = where+strlen(KEY);\ continue;\ } - TEST("&{output}","%s","<main output>"); + #define SYNCTEX_MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) + TEST("&{output}","%s",synctex_scanner_get_output(scanner)); TEST("&{page}", "%i",synctex_node_page(node)-1); TEST("&{page+1}","%i",synctex_node_page(node)); - TEST("&{x}", "%f",synctex_node_h(node)); - TEST("&{y}", "%f",synctex_node_v(node)); - TEST("&{h}", "%f",synctex_node_visible_h(node)); - TEST("&{v}", "%f",synctex_node_visible_v(node)); - TEST("&{width}", "%f",synctex_node_visible_width(node)); - TEST("&{height}","%f",synctex_node_visible_height(node)); - TEST("&{before}","%s",(strlen(before)<SYNCTEX_STR_SIZE?before:"")); + TEST("&{x}", "%f",synctex_node_visible_h(node)); + TEST("&{y}", "%f",synctex_node_visible_v(node)); + TEST("&{h}", "%f",synctex_node_box_visible_h(node)); + TEST("&{v}", "%f",synctex_node_box_visible_v(node)+synctex_node_box_visible_depth(node)); + TEST("&{width}", "%f",fabsf(synctex_node_box_visible_width(node))); + TEST("&{height}","%f",SYNCTEX_MAX((synctex_node_box_visible_height(node)+synctex_node_box_visible_depth(node)),1)); + TEST("&{before}","%s",(before && strlen(before)<SYNCTEX_STR_SIZE?before:"")); TEST("&{offset}","%i",offset); - TEST("&{here}", "%s",(strlen(here)<SYNCTEX_STR_SIZE?here:"")); - TEST("&{after}", "%s",(strlen(after)<SYNCTEX_STR_SIZE?after:"")); + TEST("&{middle}","%s",(middle && strlen(middle)<SYNCTEX_STR_SIZE?middle:"")); + TEST("&{after}", "%s",(after && strlen(after)<SYNCTEX_STR_SIZE?after:"")); #undef TEST break; } + /* copy the rest of viewer into the buffer */ + if(buffer_cur != memcpy(buffer_cur,viewer,strlen(viewer))) { + synctex_help_view("Memory copy problem"); + free(buffer); + return -1; + }\ printf("SyncTeX: Executing\n%s\n",buffer); status = system(buffer); free(buffer); @@ -421,7 +387,7 @@ proceed: return status; } else { /* just print out the results */ - puts("SyncTeX result begin\n"); + puts("SyncTeX result begin"); do { printf( "Output:%s\n" "Page:%i\n" @@ -448,7 +414,7 @@ proceed: (middle?middle:""), (after?after:"")); } while((node = synctex_next_result(scanner)) != NULL); - puts("SyncTeX result end\n"); + puts("SyncTeX result end"); } } } @@ -472,7 +438,9 @@ void synctex_help_edit(char * error,...) { " Coordinates x and y are counted from the top left corner of the page.\n" " Their unit is the big point (72 dpi).\n" " \n" - " file is the full path of a tex file (including the synctex path extension)\n" + " file is in general the path of a pdf or dvi file.\n" + " It can be either absolute or relative to the current directory.\n" + " This named file must always exist.\n" " \n" "-x editor-command\n" " Normally the synctex tool outputs its result to the stdout.\n" @@ -510,11 +478,7 @@ int synctex_edit(int argc, char *argv[]) { char * start = NULL; char * end = NULL; synctex_scanner_t scanner = NULL; - char * synctex = NULL; size_t size = 0; - const char * suffix = ".synctex"; - const char * suffix_gz = ".gz"; - char * ptr = NULL; char * where = NULL; /* required */ if((arg_index>=argc) || strcmp("-o",argv[arg_index]) || (++arg_index>=argc)) { @@ -579,59 +543,22 @@ proceed: printf("page:%i\n",page); printf("x:%f\n",x); printf("y:%f\n",y); - printf("output:%s\n",output); + printf("almost output:%s\n",output); printf("editor:%s\n",editor); printf("offset:%i\n",offset); printf("context:%s\n",context); printf("cwd:%s\n",getcwd(NULL,0)); #endif - size = strlen(output)+strlen(suffix)+strlen(suffix_gz)+1; - synctex = (char *)malloc(size); - if(NULL == synctex) { - synctex_help_edit("No more memory"); - return -1; - } - if(0 == strlcpy(synctex,output,size)) { - synctex_help_edit("Copy problem"); + scanner = synctex_scanner_new_with_output_file(output); + if(NULL == scanner) { + synctex_help_view("No SyncTeX available for %s",output); return -1; } - ptr = synctex; - /* remove the path extension of the last path component. */ - if((where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL); - } - if((where = strstr(ptr,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL); - *ptr = '\0'; - } - if(0 == strlcat(synctex,suffix,size)){ - synctex_help_edit("Concatenation problem"); - return -1; - } - scanner = synctex_scanner_new_with_contents_of_file(synctex); - if(!scanner) { - if(0 == strlcat(synctex,suffix_gz,size)){ - synctex_help_view("Concatenation problem (can't add suffix '%s')",suffix_gz); - return -1; - } - scanner = synctex_scanner_new_with_contents_of_file(synctex); - if(!scanner) { - synctex_help_view("No SyncTeX available"); - return -1; - } - } - free(synctex); - synctex = NULL; - size = 0; - if(scanner && synctex_edit_query(scanner,page,x,y)) { + if(synctex_edit_query(scanner,page,x,y)) { synctex_node_t node = NULL; - char * input = NULL; - if((node = synctex_next_result(scanner)) - && (input = (char *)synctex_scanner_get_name(scanner,synctex_node_tag(node)))) { + const char * input = NULL; + if(NULL != (node = synctex_next_result(scanner)) + && NULL != (input = (char *)synctex_scanner_get_name(scanner,synctex_node_tag(node)))) { /* filtering the command */ if(editor && strlen(editor)) { char * buffer = NULL; @@ -663,32 +590,36 @@ proceed: /* find the next occurrence of a format key */ where = editor; while(editor && (where = strstr(editor,"&{"))) { - char * format_key = NULL; #define TEST(KEY,FORMAT,WHAT)\ - format_key="&{output}";\ - if(!strcmp(editor,format_key)) {\ + if(!strncmp(where,KEY,strlen(KEY))) {\ printed = where-editor;\ - if(buffer != memcpy(buffer_cur,editor,(size_t)printed)) {\ + if(buffer_cur != memcpy(buffer_cur,editor,(size_t)printed)) {\ synctex_help_view("Memory copy problem");\ free(buffer);\ return -1;\ }\ buffer_cur += printed;size-=printed;\ - printed = snprintf(buffer_cur,size,"%s","<main output>");\ + printed = snprintf(buffer_cur,size,FORMAT,WHAT);\ buffer_cur += printed;size-=printed;\ *buffer_cur='\0';\ - editor = where+strlen(format_key);\ + editor = where+strlen(KEY);\ continue;\ } TEST("&{output}", "%s",output); TEST("&{input}", "%s",input); - TEST("&{line}", "%i",line); - TEST("&{column}", "%i",column); + TEST("&{line}", "%i",synctex_node_line(node)); + TEST("&{column}", "%i",-1); TEST("&{offset}", "%i",offset); TEST("&{context}","%s",context); #undef TEST break; } + /* copy the rest of editor into the buffer */ + if(buffer_cur != memcpy(buffer_cur,editor,strlen(editor))) { + fputs("! synctex_edit: Memory copy problem",stderr); + free(buffer); + return -1; + }\ printf("SyncTeX: Executing\n%s\n",buffer); status = system(buffer); free(buffer); @@ -696,7 +627,7 @@ proceed: return status; } else { /* just print out the results */ - puts("SyncTeX result begin\n"); + puts("SyncTeX result begin"); do { printf( "Output:%s\n" "Input:%s\n" @@ -711,7 +642,7 @@ proceed: offset, (context?context:"")); } while((node = synctex_next_result(scanner)) != NULL); - puts("SyncTeX result end\n"); + puts("SyncTeX result end"); } } } @@ -729,7 +660,9 @@ void synctex_help_update(char * error,...) { "\n" "usage: synctex update -o output [-m number] [-x dimension] [-y dimension]\n" "\n" - "-o output is the file to which the filter applies.\n" + "-o output is the full or relative path of an existing file,.\n" + " either the real synctex file you wish to update\n" + " or a related file: foo.tex, foo.pdf, foo.dvi...\n" "-m number Set additional magnification\n" "-x dimension Set horizontal offset\n" "-y dimension Set vertical offset\n" @@ -739,19 +672,15 @@ void synctex_help_update(char * error,...) { return; } -/* "usage: synctex update -o output [-m number] [-x dimension] [-y dim output\n" */ +/* "usage: synctex update -o output [-m number] [-x dimension] [-y dimension]\n" */ int synctex_update(int argc, char *argv[]) { int arg_index = 0; + synctex_updater_t updater = NULL; char * magnification = NULL; char * x = NULL; char * y = NULL; char * output = NULL; - size_t size = 0; - char * synctex = NULL; - char * ptr = NULL; - char * where = NULL; - FILE * F = NULL; - int len = 0; + #define SYNCTEX_fprintf (*synctex_fprintf) if(arg_index>=argc) { synctex_help_update("Bad update command"); return -1; @@ -792,59 +721,10 @@ prepare_next_argument: goto prepare_next_argument; } /* Arguments parsed */ - size = strlen(output)+9; - synctex = (char *)malloc(size); - if(NULL == synctex) { - synctex_help_update("No more memory"); - return -1; - } - if(0 == strlcpy(synctex,output,size)) { - synctex_help_update("Copy problem"); - return -1; - } - if(NULL == x - && NULL == y - && NULL == magnification) { - /* Nothing to update */ - printf("SyncTeX: Nothing to update\n"); - return 0; - } - ptr = synctex; - /* remove the path extension of the last path component. */ - if((where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) != NULL); - } - if((where = strstr(ptr,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL) { - do { - ptr = where; - } while((where = strstr(ptr+1,SYNCTEX_PATH_EXTENSION_SEPARATOR)) != NULL); - *ptr = '\0'; - } - if(0 == strlcat(synctex,".synctex",size)){ - synctex_help_update("Concatenation problem"); - return -1; - } - F = fopen(synctex,"a"); - if(NULL == F) { - synctex_help_update("No file at: %s",synctex); - return -1; - } - printf("SyncTeX: updating %s...",synctex); - if(magnification) { - len += fprintf(F,"Magnification:%s\n",magnification); - } - if(x) { - len += fprintf(F,"X Offset:%s\n",x); - } - if(y) { - len += fprintf(F,"Y Offset:%s\n",y); - } - if(len) { - fprintf(F,"!%i\n",len); - } - fclose(F); - printf(" done\n"); + updater = synctex_updater_new_with_output_file(output); + synctex_updater_append_magnification(updater,magnification); + synctex_updater_append_x_offset(updater,x); + synctex_updater_append_y_offset(updater,y); + synctex_updater_free(updater); return 0; } diff --git a/Build/source/texk/web2c/synctex/synctex_parser.c b/Build/source/texk/web2c/synctex/synctex_parser.c index a54f9d920a6..57717ca7279 100644 --- a/Build/source/texk/web2c/synctex/synctex_parser.c +++ b/Build/source/texk/web2c/synctex/synctex_parser.c @@ -82,14 +82,14 @@ typedef _synctex_class_t * synctex_class_t; * thus different nodes will have different private data. * There is no inheritancy overhead. */ -typedef union __synctex_info_t { +typedef union _synctex_info_t { int INT; char * PTR; -} INFO; +} synctex_info_t; struct _synctex_node { synctex_class_t class; - INFO * implementation; + synctex_info_t * implementation; }; /* Each node of the tree, except the scanner itself belongs to a class. @@ -107,7 +107,7 @@ struct _synctex_node { */ typedef synctex_node_t *(*_synctex_node_getter_t)(synctex_node_t); -typedef INFO *(*_synctex_info_getter_t)(synctex_node_t); +typedef synctex_info_t *(*_synctex_info_getter_t)(synctex_node_t); struct __synctex_class_t { synctex_scanner_t scanner; @@ -127,12 +127,7 @@ struct __synctex_class_t { # pragma mark Abstract OBJECTS and METHODS /* These macros are shortcuts - * SYNCTEX_INFO(node) points to the first synctex integer data of node - * SYNCTEX_INFO(node)[index] is the information at index - */ -# define SYNCTEX_INFO(NODE) ((*((((NODE)->class))->info))(NODE)) - -/* This macro checks if a message can be sent. + * This macro checks if a message can be sent. */ # define SYNCTEX_CAN_PERFORM(NODE,SELECTOR)\ (NULL!=((((NODE)->class))->SELECTOR)) @@ -223,7 +218,8 @@ struct __synctex_scanner_t { unsigned char * buffer_cur; /* current location in the buffer */ unsigned char * buffer_start; /* start of the buffer */ unsigned char * buffer_end; /* end of the buffer */ - char * output; /* dvi or pdf, not yet used */ + char * output_fmt; /* dvi or pdf, not yet used */ + char * output; /* the output name used to create the scanner */ int version; /* 1, not yet used */ int pre_magnification; /* magnification from the synctex preamble */ int pre_unit; /* unit from the synctex preamble */ @@ -249,6 +245,13 @@ struct __synctex_scanner_t { # pragma mark - # pragma mark OBJECTS, their creators and destructors. +/* Here, we define the indices for the different informations. + * They are used to declare the size of the implementation. + * For example, if one object uses SYNCTEX_HORIZ_IDX is its size, + * then its info will contain a tag, line, column, horiz but no width nor height nor depth + */ +# define SYNCTEX_PAGE_IDX 0 + /* The sheet is a first level node. * It has no parent (the parent is the scanner itself) * Its sibling points to another sheet. @@ -256,18 +259,23 @@ struct __synctex_scanner_t { * A sheet node contains only one synctex information: the page. * This is the 1 based page index as given by TeX. */ +/* The next macros are used to access the node info + * SYNCTEX_INFO(node) points to the first synctex integer or pointer data of node + * SYNCTEX_INFO(node)[index] is the information at index + * for example, the page of a sheet is stored in SYNCTEX_INFO(sheet)[SYNCTEX_PAGE_IDX] + */ +# define SYNCTEX_INFO(NODE) ((*((((NODE)->class))->info))(NODE)) +# define SYNCTEX_PAGE_IDX 0 +# define SYNCTEX_PAGE(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_PAGE_IDX].INT + typedef struct { synctex_class_t class; - INFO implementation[2+1];/* child, sibling - * PAGE */ + synctex_info_t implementation[2+SYNCTEX_PAGE_IDX+1];/* child, sibling + * SYNCTEX_PAGE_IDX */ } synctex_sheet_t; -/* The next macros is used to access the node info - * for example, the page of a sheet is stored in SYNCTEX_INFO(sheet)[PAGE] - */ -# define PAGE 0 - /* This macro defines implementation offsets + * It is only used for pointer values */ # define SYNCTEX_MAKE_GET(SYNCTEX_GETTER,OFFSET)\ synctex_node_t * SYNCTEX_GETTER (synctex_node_t node) {\ @@ -310,22 +318,31 @@ synctex_node_t _synctex_new_sheet(synctex_scanner_t scanner) { * There are different kind of boxes. * Only horizontal boxes are treated differently because of their visible size. */ +# define SYNCTEX_TAG_IDX 0 +# define SYNCTEX_LINE_IDX (SYNCTEX_TAG_IDX+1) +# define SYNCTEX_COLUMN_IDX (SYNCTEX_LINE_IDX+1) +# define SYNCTEX_HORIZ_IDX (SYNCTEX_COLUMN_IDX+1) +# define SYNCTEX_VERT_IDX (SYNCTEX_HORIZ_IDX+1) +# define SYNCTEX_WIDTH_IDX (SYNCTEX_VERT_IDX+1) +# define SYNCTEX_HEIGHT_IDX (SYNCTEX_WIDTH_IDX+1) +# define SYNCTEX_DEPTH_IDX (SYNCTEX_HEIGHT_IDX+1) +/* the corresponding info accessors */ +# define SYNCTEX_TAG(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_TAG_IDX].INT +# define SYNCTEX_LINE(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_LINE_IDX].INT +# define SYNCTEX_COLUMN(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_COLUMN_IDX].INT +# define SYNCTEX_HORIZ(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HORIZ_IDX].INT +# define SYNCTEX_VERT(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_VERT_IDX].INT +# define SYNCTEX_WIDTH(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_WIDTH_IDX].INT +# define SYNCTEX_HEIGHT(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HEIGHT_IDX].INT +# define SYNCTEX_DEPTH(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_DEPTH_IDX].INT + typedef struct { synctex_class_t class; - INFO implementation[4+3+5]; /* parent,child,sibling,friend, + synctex_info_t implementation[4+SYNCTEX_DEPTH_IDX+1]; /* parent,child,sibling,friend, * SYNCTEX_TAG,SYNCTEX_LINE,SYNCTEX_COLUMN, * SYNCTEX_HORIZ,SYNCTEX_VERT,SYNCTEX_WIDTH,SYNCTEX_HEIGHT,SYNCTEX_DEPTH */ } synctex_vert_box_node_t; -# define SYNCTEX_TAG 0 -# define SYNCTEX_LINE (SYNCTEX_TAG+1) -# define SYNCTEX_COLUMN (SYNCTEX_LINE+1) -# define SYNCTEX_HORIZ (SYNCTEX_COLUMN+1) -# define SYNCTEX_VERT (SYNCTEX_HORIZ+1) -# define SYNCTEX_WIDTH (SYNCTEX_VERT+1) -# define SYNCTEX_HEIGHT (SYNCTEX_WIDTH+1) -# define SYNCTEX_DEPTH (SYNCTEX_HEIGHT+1) - synctex_node_t _synctex_new_vbox(synctex_scanner_t scanner); void _synctex_log_box(synctex_node_t sheet); void _synctex_display_vbox(synctex_node_t node); @@ -355,21 +372,27 @@ synctex_node_t _synctex_new_vbox(synctex_scanner_t scanner) { return node; } +# define SYNCTEX_HORIZ_V_IDX (SYNCTEX_DEPTH_IDX+1) +# define SYNCTEX_VERT_V_IDX (SYNCTEX_HORIZ_V_IDX+1) +# define SYNCTEX_WIDTH_V_IDX (SYNCTEX_VERT_V_IDX+1) +# define SYNCTEX_HEIGHT_V_IDX (SYNCTEX_WIDTH_V_IDX+1) +# define SYNCTEX_DEPTH_V_IDX (SYNCTEX_HEIGHT_V_IDX+1) +/* the corresponding info accessors */ +# define SYNCTEX_HORIZ_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HORIZ_V_IDX].INT +# define SYNCTEX_VERT_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_VERT_V_IDX].INT +# define SYNCTEX_WIDTH_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_WIDTH_V_IDX].INT +# define SYNCTEX_HEIGHT_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_HEIGHT_V_IDX].INT +# define SYNCTEX_DEPTH_V(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_DEPTH_V_IDX].INT + /* Horizontal boxes must contain visible size, because 0 width does not mean emptiness */ typedef struct { synctex_class_t class; - INFO implementation[4+3+5+5]; /*parent,child,sibling,friend, + synctex_info_t implementation[4+SYNCTEX_DEPTH_V_IDX+1]; /*parent,child,sibling,friend, * SYNCTEX_TAG,SYNCTEX_LINE,SYNCTEX_COLUMN, * SYNCTEX_HORIZ,SYNCTEX_VERT,SYNCTEX_WIDTH,SYNCTEX_HEIGHT,SYNCTEX_DEPTH, * SYNCTEX_HORIZ_V,SYNCTEX_VERT_V,SYNCTEX_WIDTH_V,SYNCTEX_HEIGHT_V,SYNCTEX_DEPTH_V*/ } synctex_horiz_box_node_t; -# define SYNCTEX_HORIZ_V (SYNCTEX_DEPTH+1) -# define SYNCTEX_VERT_V (SYNCTEX_HORIZ_V+1) -# define SYNCTEX_WIDTH_V (SYNCTEX_VERT_V+1) -# define SYNCTEX_HEIGHT_V (SYNCTEX_WIDTH_V+1) -# define SYNCTEX_DEPTH_V (SYNCTEX_HEIGHT_V+1) - synctex_node_t _synctex_new_hbox(synctex_scanner_t scanner); void _synctex_display_hbox(synctex_node_t node); void _synctex_log_horiz_box(synctex_node_t sheet); @@ -403,7 +426,7 @@ synctex_node_t _synctex_new_hbox(synctex_scanner_t scanner) { */ typedef struct { synctex_class_t class; - INFO implementation[3+3+5]; /* parent,sibling,friend, + synctex_info_t implementation[3+SYNCTEX_DEPTH_IDX+1]; /* parent,sibling,friend, * SYNCTEX_TAG,SYNCTEX_LINE,SYNCTEX_COLUMN, * SYNCTEX_HORIZ,SYNCTEX_VERT,SYNCTEX_WIDTH,SYNCTEX_HEIGHT,SYNCTEX_DEPTH*/ } synctex_void_box_node_t; @@ -464,7 +487,7 @@ synctex_node_t _synctex_new_void_hbox(synctex_scanner_t scanner) { /* The medium nodes correspond to kern, glue and math nodes. */ typedef struct { synctex_class_t class; - INFO implementation[3+3+3]; /* parent,sibling,friend, + synctex_info_t implementation[3+SYNCTEX_WIDTH_IDX+1]; /* parent,sibling,friend, * SYNCTEX_TAG,SYNCTEX_LINE,SYNCTEX_COLUMN, * SYNCTEX_HORIZ,SYNCTEX_VERT,SYNCTEX_WIDTH */ } synctex_medium_node_t; @@ -547,18 +570,19 @@ synctex_node_t _synctex_new_kern(synctex_scanner_t scanner) { return node; } +# define SYNCTEX_NAME_IDX (SYNCTEX_TAG_IDX+1) +# define SYNCTEX_NAME(NODE) SYNCTEX_INFO(NODE)[SYNCTEX_NAME_IDX].PTR + /* Input nodes only know about their sibling, which is another input node. * The synctex information is the SYNCTEX_TAG and SYNCTEX_NAME*/ typedef struct { synctex_class_t class; - INFO implementation[1+2]; /* sibling, + synctex_info_t implementation[1+SYNCTEX_NAME_IDX+1]; /* sibling, * SYNCTEX_TAG,SYNCTEX_NAME */ } synctex_input_t; -/* The SYNCTEX_TAG previously defined is also used here */ -# define SYNCTEX_NAME 1 - synctex_node_t _synctex_new_input(synctex_scanner_t scanner); +void _synctex_free_input(synctex_node_t node); void _synctex_display_input(synctex_node_t node); void _synctex_log_input(synctex_node_t sheet); @@ -566,7 +590,7 @@ static const _synctex_class_t synctex_class_input = { NULL, /* No scanner yet */ synctex_node_type_input, /* Node type */ &_synctex_new_input, /* creator */ - &_synctex_free_leaf, /* destructor */ + &_synctex_free_input, /* destructor */ &_synctex_log_input, /* log */ &_synctex_display_input, /* display */ NULL, /* No parent */ @@ -583,7 +607,13 @@ synctex_node_t _synctex_new_input(synctex_scanner_t scanner) { } return node; } - +void _synctex_free_input(synctex_node_t node){ + if(node) { + SYNCTEX_FREE(SYNCTEX_SIBLING(node)); + free(SYNCTEX_NAME(node)); + free(node); + } +} #pragma mark - #pragma mark Navigation synctex_node_t synctex_node_parent(synctex_node_t node) @@ -652,7 +682,7 @@ void synctex_node_log(synctex_node_t node) { void _synctex_log_sheet(synctex_node_t sheet) { if(sheet) { - printf("%s:%i\n",synctex_node_isa(sheet),SYNCTEX_INFO(sheet)[PAGE].INT); + printf("%s:%i\n",synctex_node_isa(sheet),SYNCTEX_PAGE(sheet)); printf("SELF:%p",sheet); printf(" SYNCTEX_PARENT:%p",SYNCTEX_PARENT(sheet)); printf(" SYNCTEX_CHILD:%p",SYNCTEX_CHILD(sheet)); @@ -664,11 +694,11 @@ void _synctex_log_sheet(synctex_node_t sheet) { void _synctex_log_medium_node(synctex_node_t node) { printf("%s:%i,%i:%i,%i:%i\n", synctex_node_isa(node), - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node)); printf("SELF:%p",node); printf(" SYNCTEX_PARENT:%p",SYNCTEX_PARENT(node)); printf(" SYNCTEX_CHILD:%p",SYNCTEX_CHILD(node)); @@ -677,16 +707,15 @@ void _synctex_log_medium_node(synctex_node_t node) { } void _synctex_log_void_box(synctex_node_t node) { - INFO * info = SYNCTEX_INFO(node); printf("%s",synctex_node_isa(node)); - printf(":%i",info[SYNCTEX_TAG].INT); - printf(",%i",info[SYNCTEX_LINE].INT); + printf(":%i",SYNCTEX_TAG(node)); + printf(",%i",SYNCTEX_LINE(node)); printf(",%i",0); - printf(":%i",info[SYNCTEX_HORIZ].INT); - printf(",%i",info[SYNCTEX_VERT].INT); - printf(":%i",info[SYNCTEX_WIDTH].INT); - printf(",%i",info[SYNCTEX_HEIGHT].INT); - printf(",%i",info[SYNCTEX_DEPTH].INT); + printf(":%i",SYNCTEX_HORIZ(node)); + printf(",%i",SYNCTEX_VERT(node)); + printf(":%i",SYNCTEX_WIDTH(node)); + printf(",%i",SYNCTEX_HEIGHT(node)); + printf(",%i",SYNCTEX_DEPTH(node)); printf("\nSELF:%p",node); printf(" SYNCTEX_PARENT:%p",SYNCTEX_PARENT(node)); printf(" SYNCTEX_CHILD:%p",SYNCTEX_CHILD(node)); @@ -695,16 +724,15 @@ void _synctex_log_void_box(synctex_node_t node) { } void _synctex_log_box(synctex_node_t node) { - INFO * info = SYNCTEX_INFO(node); printf("%s",synctex_node_isa(node)); - printf(":%i",info[SYNCTEX_TAG].INT); - printf(",%i",info[SYNCTEX_LINE].INT); + printf(":%i",SYNCTEX_TAG(node)); + printf(",%i",SYNCTEX_LINE(node)); printf(",%i",0); - printf(":%i",info[SYNCTEX_HORIZ].INT); - printf(",%i",info[SYNCTEX_VERT].INT); - printf(":%i",info[SYNCTEX_WIDTH].INT); - printf(",%i",info[SYNCTEX_HEIGHT].INT); - printf(",%i",info[SYNCTEX_DEPTH].INT); + printf(":%i",SYNCTEX_HORIZ(node)); + printf(",%i",SYNCTEX_VERT(node)); + printf(":%i",SYNCTEX_WIDTH(node)); + printf(",%i",SYNCTEX_HEIGHT(node)); + printf(",%i",SYNCTEX_DEPTH(node)); printf("\nSELF:%p",node); printf(" SYNCTEX_PARENT:%p",SYNCTEX_PARENT(node)); printf(" SYNCTEX_CHILD:%p",SYNCTEX_CHILD(node)); @@ -713,21 +741,20 @@ void _synctex_log_box(synctex_node_t node) { } void _synctex_log_horiz_box(synctex_node_t node) { - INFO * info = SYNCTEX_INFO(node); printf("%s",synctex_node_isa(node)); - printf(":%i",info[SYNCTEX_TAG].INT); - printf(",%i",info[SYNCTEX_LINE].INT); + printf(":%i",SYNCTEX_TAG(node)); + printf(",%i",SYNCTEX_LINE(node)); printf(",%i",0); - printf(":%i",info[SYNCTEX_HORIZ].INT); - printf(",%i",info[SYNCTEX_VERT].INT); - printf(":%i",info[SYNCTEX_WIDTH].INT); - printf(",%i",info[SYNCTEX_HEIGHT].INT); - printf(",%i",info[SYNCTEX_DEPTH].INT); - printf(":%i",info[SYNCTEX_HORIZ_V].INT); - printf(",%i",info[SYNCTEX_VERT_V].INT); - printf(":%i",info[SYNCTEX_WIDTH_V].INT); - printf(",%i",info[SYNCTEX_HEIGHT_V].INT); - printf(",%i",info[SYNCTEX_DEPTH_V].INT); + printf(":%i",SYNCTEX_HORIZ(node)); + printf(",%i",SYNCTEX_VERT(node)); + printf(":%i",SYNCTEX_WIDTH(node)); + printf(",%i",SYNCTEX_HEIGHT(node)); + printf(",%i",SYNCTEX_DEPTH(node)); + printf(":%i",SYNCTEX_HORIZ_V(node)); + printf(",%i",SYNCTEX_VERT_V(node)); + printf(":%i",SYNCTEX_WIDTH_V(node)); + printf(",%i",SYNCTEX_HEIGHT_V(node)); + printf(",%i",SYNCTEX_DEPTH_V(node)); printf("\nSELF:%p",node); printf(" SYNCTEX_PARENT:%p",SYNCTEX_PARENT(node)); printf(" SYNCTEX_CHILD:%p",SYNCTEX_CHILD(node)); @@ -736,10 +763,9 @@ void _synctex_log_horiz_box(synctex_node_t node) { } void _synctex_log_input(synctex_node_t node) { - INFO * info = SYNCTEX_INFO(node); printf("%s",synctex_node_isa(node)); - printf(":%i",info[SYNCTEX_TAG].INT); - printf(",%s",info[SYNCTEX_NAME].PTR); + printf(":%i",SYNCTEX_TAG(node)); + printf(",%s",SYNCTEX_NAME(node)); printf(" SYNCTEX_SIBLING:%p",SYNCTEX_SIBLING(node)); } @@ -747,7 +773,7 @@ void _synctex_log_input(synctex_node_t node) { void _synctex_display_sheet(synctex_node_t sheet) { if(sheet) { - printf("....{%i\n",SYNCTEX_INFO(sheet)[PAGE].INT); + printf("....{%i\n",SYNCTEX_PAGE(sheet)); SYNCTEX_DISPLAY(SYNCTEX_CHILD(sheet)); printf("....}\n"); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(sheet)); @@ -756,13 +782,13 @@ void _synctex_display_sheet(synctex_node_t sheet) { void _synctex_display_vbox(synctex_node_t node) { printf("....[%i,%i:%i,%i:%i,%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT, - SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT, - SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node), + SYNCTEX_HEIGHT(node), + SYNCTEX_DEPTH(node)); SYNCTEX_DISPLAY(SYNCTEX_CHILD(node)); printf("....]\n"); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); @@ -770,13 +796,13 @@ void _synctex_display_vbox(synctex_node_t node) { void _synctex_display_hbox(synctex_node_t node) { printf("....(%i,%i:%i,%i:%i,%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT, - SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT, - SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node), + SYNCTEX_HEIGHT(node), + SYNCTEX_DEPTH(node)); SYNCTEX_DISPLAY(SYNCTEX_CHILD(node)); printf("....)\n"); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); @@ -784,60 +810,60 @@ void _synctex_display_hbox(synctex_node_t node) { void _synctex_display_void_vbox(synctex_node_t node) { printf("....v%i,%i;%i,%i:%i,%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT, - SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT, - SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node), + SYNCTEX_HEIGHT(node), + SYNCTEX_DEPTH(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } void _synctex_display_void_hbox(synctex_node_t node) { printf("....h%i,%i:%i,%i:%i,%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT, - SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT, - SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node), + SYNCTEX_HEIGHT(node), + SYNCTEX_DEPTH(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } void _synctex_display_glue(synctex_node_t node) { printf("....glue:%i,%i:%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } void _synctex_display_math(synctex_node_t node) { printf("....math:%i,%i:%i,%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } void _synctex_display_kern(synctex_node_t node) { printf("....kern:%i,%i:%i,%i:%i\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT, - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT, - SYNCTEX_INFO(node)[SYNCTEX_VERT].INT, - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT); + SYNCTEX_TAG(node), + SYNCTEX_LINE(node), + SYNCTEX_HORIZ(node), + SYNCTEX_VERT(node), + SYNCTEX_WIDTH(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } void _synctex_display_input(synctex_node_t node) { printf("....Input:%i:%s\n", - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_NAME].PTR); + SYNCTEX_TAG(node), + SYNCTEX_NAME(node)); SYNCTEX_DISPLAY(SYNCTEX_SIBLING(node)); } @@ -880,16 +906,16 @@ typedef int synctex_status_t; inline static int _synctex_error(char * reason,...) { va_list arg; int result; - result = printf("SyncTeX ERROR: "); + result = fprintf(stderr,"SyncTeX ERROR: "); va_start (arg, reason); - result += vfprintf(stdout, reason, arg); + result += vfprintf(stderr, reason, arg); va_end (arg); - result = printf("\n"); + result = fprintf(stderr,"\n"); return result; } /* Try to ensure that the buffer contains at least size bytes. - * Passing a negative size argument means the whole buffer length. + * Passing a huge size argument means the whole buffer length. * Passing a null size argument means return the available buffer length, without reading the file. * In that case, the return status is always SYNCTEX_STATUS_OK unless the given scanner is NULL, * in which case, SYNCTEX_STATUS_BAD_ARGUMENT is returned. @@ -1074,7 +1100,7 @@ more_characters: return_NOT_OK: if(offset != gzseek(SYNCTEX_FILE,offset,SEEK_SET)) { /* This is a critical error, we could not recover the previous state. */ - printf("SyncTeX critical ERROR: can't seek file\n"); + fprintf(stderr,"SyncTeX critical ERROR: can't seek file\n"); return SYNCTEX_STATUS_ERROR; } /* Next time we are asked to fill the buffer, @@ -1281,7 +1307,7 @@ synctex_status_t _synctex_scan_input(synctex_scanner_t scanner) { return SYNCTEX_STATUS_ERROR; } /* Decode the synctag */ - status = _synctex_decode_int(scanner,&(SYNCTEX_INFO(input)[SYNCTEX_TAG].INT)); + status = _synctex_decode_int(scanner,&(SYNCTEX_TAG(input))); if(status<SYNCTEX_STATUS_OK) { _synctex_error("bad format of input node."); SYNCTEX_FREE(input); @@ -1300,7 +1326,7 @@ synctex_status_t _synctex_scan_input(synctex_scanner_t scanner) { ++SYNCTEX_CUR; --available; /* Then we scan the file name */ - status = _synctex_decode_string(scanner,(char **)&(SYNCTEX_INFO(input)[SYNCTEX_NAME].PTR)); + status = _synctex_decode_string(scanner,&(SYNCTEX_NAME(input))); if(status<SYNCTEX_STATUS_OK) { SYNCTEX_FREE(input); return status; @@ -1309,6 +1335,7 @@ synctex_status_t _synctex_scan_input(synctex_scanner_t scanner) { SYNCTEX_SET_SIBLING(input,scanner->input); scanner->input = input; return _synctex_next_line(scanner);/* read the line termination character, if any */ + /* Now, set up the path */ } typedef synctex_status_t (*synctex_decoder_t)(synctex_scanner_t,void *); @@ -1366,7 +1393,7 @@ synctex_status_t _synctex_scan_preamble(synctex_scanner_t scanner) { } while(status == SYNCTEX_STATUS_OK); /* the loop exits when status == SYNCTEX_STATUS_NOT_OK */ /* Now read all the required settings. */ - status = _synctex_scan_named(scanner,"Output:",&(scanner->output),(synctex_decoder_t)&_synctex_decode_string); + status = _synctex_scan_named(scanner,"Output:",&(scanner->output_fmt),(synctex_decoder_t)&_synctex_decode_string); if(status<SYNCTEX_STATUS_NOT_OK) { return status; } @@ -1522,7 +1549,6 @@ next_line: return SYNCTEX_STATUS_OK;/* The EOF is found, we have properly scanned the file */ } /* Scanning the information */ -/*next_record:*/ status = _synctex_match_string(scanner,"Magnification:"); if(status == SYNCTEX_STATUS_OK ) { #ifdef HAVE_SETLOCALE @@ -1612,17 +1638,15 @@ count_again: * At creation time, the visible size is set to the values of the real size. */ synctex_status_t _synctex_setup_visible_box(synctex_node_t box) { - INFO * info = NULL; if(NULL == box || box->class->type != synctex_node_type_hbox) { return SYNCTEX_STATUS_BAD_ARGUMENT; } - info = SYNCTEX_INFO(box); - if(info) { - info[SYNCTEX_HORIZ_V] = info[SYNCTEX_HORIZ]; - info[SYNCTEX_VERT_V] = info[SYNCTEX_VERT]; - info[SYNCTEX_WIDTH_V] = info[SYNCTEX_WIDTH]; - info[SYNCTEX_HEIGHT_V] = info[SYNCTEX_HEIGHT]; - info[SYNCTEX_DEPTH_V] = info[SYNCTEX_DEPTH]; + 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); + SYNCTEX_HEIGHT_V(box) = SYNCTEX_HEIGHT(box); + SYNCTEX_DEPTH_V(box) = SYNCTEX_DEPTH(box); return SYNCTEX_STATUS_OK; } return SYNCTEX_STATUS_ERROR; @@ -1634,35 +1658,33 @@ 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) { #pragma unused(v) - INFO * itsINFO = NULL; int itsBtm, itsTop; if(NULL == node || node->class->type != synctex_node_type_hbox) { return SYNCTEX_STATUS_BAD_ARGUMENT; } - itsINFO = SYNCTEX_INFO(node); - if(itsINFO[SYNCTEX_WIDTH_V].INT<0) { - itsBtm = itsINFO[SYNCTEX_HORIZ_V].INT+itsINFO[SYNCTEX_WIDTH_V].INT; - itsTop = itsINFO[SYNCTEX_HORIZ_V].INT; + if(SYNCTEX_WIDTH_V(node)<0) { + itsBtm = SYNCTEX_HORIZ_V(node)+SYNCTEX_WIDTH_V(node); + itsTop = SYNCTEX_HORIZ_V(node); if(h<itsBtm) { itsBtm -= h; - itsINFO[SYNCTEX_WIDTH_V].INT -= itsBtm; + SYNCTEX_WIDTH_V(node) -= itsBtm; } if(h>itsTop) { h -= itsTop; - itsINFO[SYNCTEX_WIDTH_V].INT -= h; - itsINFO[SYNCTEX_HORIZ_V].INT += h; + SYNCTEX_WIDTH_V(node) -= h; + SYNCTEX_HORIZ_V(node) += h; } } else { - itsBtm = itsINFO[SYNCTEX_HORIZ_V].INT; - itsTop = itsINFO[SYNCTEX_HORIZ_V].INT+itsINFO[SYNCTEX_WIDTH_V].INT; + itsBtm = SYNCTEX_HORIZ_V(node); + itsTop = SYNCTEX_HORIZ_V(node)+SYNCTEX_WIDTH_V(node); if(h<itsBtm) { itsBtm -= h; - itsINFO[SYNCTEX_HORIZ_V].INT -= itsBtm; - itsINFO[SYNCTEX_WIDTH_V].INT += itsBtm; + SYNCTEX_HORIZ_V(node) -= itsBtm; + SYNCTEX_WIDTH_V(node) += itsBtm; } if(h>itsTop) { h -= itsTop; - itsINFO[SYNCTEX_WIDTH_V].INT += h; + SYNCTEX_WIDTH_V(node) += h; } } return SYNCTEX_STATUS_OK; @@ -1678,7 +1700,7 @@ synctex_status_t _synctex_scan_sheet(synctex_scanner_t scanner, synctex_node_t p synctex_node_t child = NULL; synctex_node_t sibling = NULL; int friend_index = 0; - INFO * info = NULL; + synctex_info_t * info = NULL; int curh, curv; synctex_status_t status = 0; size_t available = 0; @@ -1689,16 +1711,17 @@ vertical_loop: if(SYNCTEX_CUR<SYNCTEX_END) { if(*SYNCTEX_CUR == '[') { ++SYNCTEX_CUR; - if((child = _synctex_new_vbox(scanner)) && (info = SYNCTEX_INFO(child))) { + if(NULL != (child = _synctex_new_vbox(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { # define SYNCTEX_DECODE_FAILED(WHAT) \ (_synctex_decode_int(scanner,&(info[WHAT].INT))<SYNCTEX_STATUS_OK) - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad vbox record."); return SYNCTEX_STATUS_ERROR; @@ -1713,9 +1736,9 @@ vertical_loop: } } else if(*SYNCTEX_CUR == ']') { ++SYNCTEX_CUR; - if(parent && parent->class->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].INT+(SYNCTEX_INFO(NODE))[SYNCTEX_LINE].INT)%(scanner->number_of_lists);\ + 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)) { @@ -1734,14 +1757,15 @@ vertical_loop: goto horizontal_loop; } else if(*SYNCTEX_CUR == '(') { ++SYNCTEX_CUR; - if((child = _synctex_new_hbox(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (child = _synctex_new_hbox(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || _synctex_setup_visible_box(child)<SYNCTEX_STATUS_OK || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad hbox record."); @@ -1757,7 +1781,7 @@ vertical_loop: } } else if(*SYNCTEX_CUR == ')') { ++SYNCTEX_CUR; - if(parent && parent->class->type == synctex_node_type_hbox) { + if(NULL != parent && parent->class->type == synctex_node_type_hbox) { if(NULL == child) { SYNCTEX_UPDATE_BOX_FRIEND(parent); } @@ -1773,21 +1797,22 @@ vertical_loop: goto horizontal_loop; } else if(*SYNCTEX_CUR == 'v') { ++SYNCTEX_CUR; - if((child = _synctex_new_void_vbox(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (child = _synctex_new_void_vbox(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad void vbox record."); return SYNCTEX_STATUS_ERROR; } SYNCTEX_SET_CHILD(parent,child); #define SYNCTEX_UPDATE_FRIEND(NODE)\ - friend_index = (info[SYNCTEX_TAG].INT+info[SYNCTEX_LINE].INT)%(scanner->number_of_lists);\ + friend_index = (info[SYNCTEX_TAG_IDX].INT+info[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; SYNCTEX_UPDATE_FRIEND(child); @@ -1798,14 +1823,15 @@ vertical_loop: } } else if(*SYNCTEX_CUR == 'h') { ++SYNCTEX_CUR; - if((child = _synctex_new_void_hbox(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (child = _synctex_new_void_hbox(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad void hbox record."); return SYNCTEX_STATUS_ERROR; @@ -1821,12 +1847,13 @@ vertical_loop: } } else if(*SYNCTEX_CUR == 'k') { ++SYNCTEX_CUR; - if((child = _synctex_new_kern(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) + if(NULL != (child = _synctex_new_kern(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad kern record."); return SYNCTEX_STATUS_ERROR; @@ -1834,7 +1861,7 @@ vertical_loop: SYNCTEX_SET_CHILD(parent,child); _synctex_horiz_box_setup_visible(parent,synctex_node_h(child),synctex_node_v(child)); SYNCTEX_UPDATE_FRIEND(child); - if(!parent) { + if(NULL == parent) { _synctex_error("Missing parent for Child"); synctex_node_log(child); return SYNCTEX_STATUS_ERROR; @@ -1858,11 +1885,12 @@ vertical_loop: goto vertical_loop; } else if(*SYNCTEX_CUR == 'g') { ++SYNCTEX_CUR; - if((child = _synctex_new_glue(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) + if(NULL != (child = _synctex_new_glue(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad glue record."); return SYNCTEX_STATUS_ERROR; @@ -1877,11 +1905,12 @@ vertical_loop: } } else if(*SYNCTEX_CUR == '$') { ++SYNCTEX_CUR; - if((child = _synctex_new_math(scanner)) && (info = SYNCTEX_INFO(child))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) + if(NULL != (child = _synctex_new_math(scanner)) + && NULL != (info = SYNCTEX_INFO(child))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad math record."); return SYNCTEX_STATUS_ERROR; @@ -1896,7 +1925,7 @@ vertical_loop: } } else if(*SYNCTEX_CUR == '}') { ++SYNCTEX_CUR; - if(!parent || parent->class->type != synctex_node_type_sheet + if(NULL == parent || parent->class->type != synctex_node_type_sheet || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Unexpected end of sheet."); return SYNCTEX_STATUS_ERROR; @@ -1933,14 +1962,15 @@ horizontal_loop: if(SYNCTEX_CUR<SYNCTEX_END) { if(*SYNCTEX_CUR == '[') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_vbox(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (sibling = _synctex_new_vbox(scanner)) + && NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad vbox record (2)."); return SYNCTEX_STATUS_ERROR; @@ -1955,7 +1985,7 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == ']') { ++SYNCTEX_CUR; - if(parent && parent->class->type == synctex_node_type_vbox) { + if(NULL != parent && parent->class->type == synctex_node_type_vbox) { if(NULL == child) { SYNCTEX_UPDATE_BOX_FRIEND(parent); } @@ -1971,14 +2001,15 @@ horizontal_loop: goto horizontal_loop; } else if(*SYNCTEX_CUR == '(') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_hbox(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (sibling = _synctex_new_hbox(scanner)) && + NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || _synctex_setup_visible_box(sibling)<SYNCTEX_STATUS_OK || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad hbox record (2)."); @@ -1994,7 +2025,7 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == ')') { ++SYNCTEX_CUR; - if(parent && parent->class->type == synctex_node_type_hbox) { + if(NULL != parent && parent->class->type == synctex_node_type_hbox) { if(NULL == child) { SYNCTEX_UPDATE_BOX_FRIEND(parent); } @@ -2010,14 +2041,15 @@ horizontal_loop: goto horizontal_loop; } else if(*SYNCTEX_CUR == 'v') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_void_vbox(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (sibling = _synctex_new_void_vbox(scanner)) && + NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad void vbox record (2)."); return SYNCTEX_STATUS_ERROR; @@ -2032,14 +2064,15 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == 'h') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_void_hbox(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH) + if(NULL != (sibling = _synctex_new_void_hbox(scanner)) && + NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HEIGHT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_DEPTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad void hbox record (2)."); return SYNCTEX_STATUS_ERROR; @@ -2068,12 +2101,13 @@ horizontal_loop: goto horizontal_loop; } else if(*SYNCTEX_CUR == 'k') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_kern(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) - || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH) + if(NULL != (sibling = _synctex_new_kern(scanner)) + && NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_WIDTH_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad kern record (2)."); return SYNCTEX_STATUS_ERROR; @@ -2089,11 +2123,12 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == 'g') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_glue(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) + if(NULL != (sibling = _synctex_new_glue(scanner)) + && NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad glue record (2)."); return SYNCTEX_STATUS_ERROR; @@ -2109,11 +2144,12 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == '$') { ++SYNCTEX_CUR; - if((sibling = _synctex_new_math(scanner)) && (info = SYNCTEX_INFO(sibling))) { - if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG) - || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE) - || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ) - || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT) + if(NULL != (sibling = _synctex_new_math(scanner)) + && NULL != (info = SYNCTEX_INFO(sibling))) { + if(SYNCTEX_DECODE_FAILED(SYNCTEX_TAG_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_LINE_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_HORIZ_IDX) + || SYNCTEX_DECODE_FAILED(SYNCTEX_VERT_IDX) || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Bad math record (2)."); return SYNCTEX_STATUS_ERROR; @@ -2129,7 +2165,7 @@ horizontal_loop: } } else if(*SYNCTEX_CUR == '}') { ++SYNCTEX_CUR; - if(!parent || parent->class->type != synctex_node_type_sheet + if(NULL == parent || parent->class->type != synctex_node_type_sheet || (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK)) { _synctex_error("Unexpected end of sheet (2)."); return SYNCTEX_STATUS_ERROR; @@ -2213,7 +2249,7 @@ next_sheet: ++SYNCTEX_CUR; /* Create a new sheet node */ sheet = _synctex_new_sheet(scanner); - status = _synctex_decode_int(scanner,&(SYNCTEX_INFO(sheet)[PAGE].INT)); + status = _synctex_decode_int(scanner,&(SYNCTEX_PAGE(sheet))); if(status<SYNCTEX_STATUS_OK) { _synctex_error("Missing sheet number."); bail: @@ -2245,25 +2281,119 @@ bail: goto next_sheet; } +/* These are the possible extensions of the synctex file */ +static const char * synctex_suffix = ".synctex"; +static const char * synctex_suffix_gz = ".gz"; + +/* strip the last extension of the given string */ +void synctex_strip_last_path_extension(char * string) { + if(NULL != string){ + char * last_component = NULL; + char * last_extension = NULL; + char * next = NULL; + /* first we find the last path component */ + if(NULL == (last_component = strstr(string,"/"))){ + last_component = string; + } else { + ++last_component; + while(NULL != (next = strstr(last_component,"/"))){ + last_component = next+1; + } + } + /* then we find the last path extension */ + if(NULL != (last_extension = strstr(last_component,"."))){ + ++last_extension; + while(NULL != (next = strstr(last_extension,"."))){ + last_extension = next+1; + } + --last_extension;/* back to the "."*/ + if(last_extension>last_component){/* filter out paths like ....my/dir/.hidden"*/ + last_extension[0] = '\0'; + } + } + } +} + +synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name); + +/* Where the synctex scanner is created. + * output is the full or relative path of the uncompressed or compressed synctex file. + * On error, NULL is returned. + * This can be due to allocation error, or an internal inconsistency (bad SYNCTEX_BUFFER_SIZE). */ +synctex_scanner_t synctex_scanner_new_with_output_file(const char * output) { + synctex_scanner_t scanner = NULL; + char * synctex = NULL; + size_t size = 0; + /* Here we assume that int are smaller than void * */ + if(sizeof(int)>sizeof(void*)) { + fputs("SyncTeX INTERNAL INCONSISTENCY: int's are unexpectedly bigger than pointers, bailing out.",stderr); + return NULL; + } + /* now create the synctex file name */ + size = strlen(output)+strlen(synctex_suffix)+strlen(synctex_suffix_gz)+1; + synctex = (char *)malloc(size); + if(NULL == synctex) { + fprintf(stderr,"! synctex_scanner_new_with_output_file: Memory problem (1)\n"); + return NULL; + } + /* we have reserved for synctex enough memory to copy output and both suffices, + * including the terminating character */ + if(synctex != strcpy(synctex,output)) { + fprintf(stderr,"! synctex_scanner_new_with_output_file: Copy problem\n"); +return_on_error: + free(synctex); + return NULL; + } + /* remove the last path extension if any */ + synctex_strip_last_path_extension(synctex); + if(synctex != strcat(synctex,synctex_suffix)){ + fprintf(stderr,"! synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix '%s')\n",synctex_suffix); + goto return_on_error; + } + scanner = synctex_scanner_new_with_contents_of_file(synctex); + if(NULL == scanner) { + if(synctex != strcat(synctex,synctex_suffix_gz)){ + fprintf(stderr,"! synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix '%s')\n",synctex_suffix_gz); + goto return_on_error; + } + scanner = synctex_scanner_new_with_contents_of_file(synctex); + } + /* make a private copy of output for the scanner */ + if(NULL != scanner) { + if(NULL == (scanner->output = (char *)malloc(strlen(output)+1))){ + fputs("! synctex_scanner_new_with_output_file: Memory problem (2)",stderr); + goto return_on_error; + } + if(scanner->output != strcpy(scanner->output,output)) { + fprintf(stderr,"! synctex_scanner_new_with_output_file: Copy problem\n"); + goto return_on_error; + } + } + free(synctex); + return scanner; +} + /* Where the synctex scanner is created. - * name is the full path of the uncompressed synctex file. + * name is the full path of the uncompressed or compressed synctex file. + * It is not the designated initializer because the scanner's core_path field is not initialized here. * On error, NULL is returned. * This can be due to allocation error, or an internal inconsistency (bad SYNCTEX_BUFFER_SIZE). */ synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name) { synctex_scanner_t scanner = NULL; synctex_status_t status = 0; - /* We ensure that SYNCTEX_BUFFER_SIZE < UINT_MAX */ + /* We ensure that SYNCTEX_BUFFER_SIZE < UINT_MAX, I don't know if it makes sense... */ if(SYNCTEX_BUFFER_SIZE >= UINT_MAX) { - printf("SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (1)"); + fprintf(stderr,"SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (1)"); return NULL; } /* for integers: */ if(SYNCTEX_BUFFER_SIZE < SYNCTEX_BUFFER_MIN_SIZE) { - printf("SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (2)"); + fprintf(stderr,"SyncTeX BUG: Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (2)"); return NULL; } scanner = (synctex_scanner_t)_synctex_malloc(sizeof(_synctex_scanner_t)); if(NULL == scanner) { + fprintf(stderr,"SyncTeX: malloc problem"); return NULL; } scanner->pre_magnification = 1000; @@ -2293,7 +2423,7 @@ synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name) { SYNCTEX_FILE = gzopen(name,"r"); if(NULL == SYNCTEX_FILE) { if(errno != ENOENT) { - printf("SyncTeX: could not open %s, error %i\n",name,errno); + fprintf(stderr,"SyncTeX: could not open %s, error %i\n",name,errno); } bail: synctex_scanner_free(scanner); @@ -2301,7 +2431,7 @@ bail: } SYNCTEX_START = (unsigned char *)malloc(SYNCTEX_BUFFER_SIZE+1); /* one more character for null termination */ if(NULL == SYNCTEX_START) { - printf("SyncTeX: malloc error"); + fprintf(stderr,"SyncTeX: malloc error"); gzclose(SYNCTEX_FILE); goto bail; } @@ -2313,14 +2443,14 @@ bail: SYNCTEX_CUR = SYNCTEX_END; status = _synctex_scan_preamble(scanner); if(status<SYNCTEX_STATUS_OK) { - printf("SyncTeX Error: Bad preamble\n"); + fprintf(stderr,"SyncTeX Error: Bad preamble\n"); bailey: gzclose(SYNCTEX_FILE); goto bail; } status = _synctex_scan_content(scanner); if(status<SYNCTEX_STATUS_OK) { - printf("SyncTeX Error: Bad content\n"); + fprintf(stderr,"SyncTeX Error: Bad content\n"); goto bailey; } /* Everything is finished, free the buffer, close he file */ @@ -2365,9 +2495,10 @@ void synctex_scanner_free(synctex_scanner_t scanner) { return; } SYNCTEX_FREE(scanner->sheet); + SYNCTEX_FREE(scanner->input); free(SYNCTEX_START); + free(scanner->output_fmt); free(scanner->output); - free(scanner->input); free(scanner->lists_of_friends); free(scanner); } @@ -2393,7 +2524,7 @@ void synctex_scanner_display(synctex_scanner_t scanner) { if(NULL == scanner) { return; } - printf("The scanner:\noutput:%s\nversion:%i\n",scanner->output,scanner->version); + printf("The scanner:\noutput:%s\noutput_fmt:%s\nversion:%i\n",scanner->output,scanner->output_fmt,scanner->version); printf("pre_unit:%i\nx_offset:%i\ny_offset:%i\n",scanner->pre_unit,scanner->pre_x_offset,scanner->pre_y_offset); printf("count:%i\npost_magnification:%f\npost_x_offset:%f\npost_y_offset:%f\n", scanner->count,scanner->unit,scanner->x_offset,scanner->y_offset); @@ -2412,8 +2543,8 @@ void synctex_scanner_display(synctex_scanner_t scanner) { while(node) { printf("%s:%i,%i\n", synctex_node_isa(node), - SYNCTEX_INFO(node)[SYNCTEX_TAG].INT, - SYNCTEX_INFO(node)[SYNCTEX_LINE].INT + SYNCTEX_TAG(node), + SYNCTEX_LINE(node) ); node = SYNCTEX_FRIEND(node); } @@ -2427,12 +2558,12 @@ void synctex_scanner_display(synctex_scanner_t scanner) { const char * synctex_scanner_get_name(synctex_scanner_t scanner,int tag) { synctex_node_t input = NULL; if(NULL == scanner) { - return ""; + return NULL; } input = scanner->input; do { - if(tag == SYNCTEX_INFO(input)[SYNCTEX_TAG].INT) { - return (char *)(SYNCTEX_INFO(input)[SYNCTEX_NAME].PTR); + if(tag == SYNCTEX_TAG(input)) { + return (SYNCTEX_NAME(input)); } } while((input = SYNCTEX_SIBLING(input)) != NULL); return NULL; @@ -2444,9 +2575,9 @@ int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { } input = scanner->input; do { - if((strlen(name) == strlen((char *)(SYNCTEX_INFO(input)[SYNCTEX_NAME].PTR))) && - (0 == strncmp(name,(char *)(SYNCTEX_INFO(input)[SYNCTEX_NAME].PTR),strlen(name)))) { - return SYNCTEX_INFO(input)[SYNCTEX_TAG].INT; + if((strlen(name) == strlen((SYNCTEX_NAME(input)))) && + (0 == strncmp(name,(SYNCTEX_NAME(input)),strlen(name)))) { + return SYNCTEX_TAG(input); } } while((input = SYNCTEX_SIBLING(input)) != NULL); return 0; @@ -2454,25 +2585,31 @@ int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) { synctex_node_t synctex_scanner_input(synctex_scanner_t scanner) { return scanner?scanner->input:NULL; } +const char * synctex_scanner_get_output_fmt(synctex_scanner_t scanner) { + return NULL != scanner && scanner->output_fmt?scanner->output_fmt:""; +} +const char * synctex_scanner_get_output(synctex_scanner_t scanner) { + return NULL != scanner && scanner->output?scanner->output:""; +} #pragma mark - #pragma mark Public node attributes float synctex_node_h(synctex_node_t node){ if(!node) { return 0; } - return (float)SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT; + return (float)SYNCTEX_HORIZ(node); } float synctex_node_v(synctex_node_t node){ if(!node) { return 0; } - return (float)SYNCTEX_INFO(node)[SYNCTEX_VERT].INT; + return (float)SYNCTEX_VERT(node); } float synctex_node_width(synctex_node_t node){ if(!node) { return 0; } - return (float)SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT; + return (float)SYNCTEX_WIDTH(node); } float synctex_node_box_h(synctex_node_t node){ if(!node) { @@ -2484,7 +2621,7 @@ float synctex_node_box_h(synctex_node_t node){ && (node->class->type != synctex_node_type_void_hbox)) { node = SYNCTEX_PARENT(node); } - return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT); + return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_HORIZ(node)); } float synctex_node_box_v(synctex_node_t node){ if(!node) { @@ -2496,7 +2633,7 @@ float synctex_node_box_v(synctex_node_t node){ && (node->class->type != synctex_node_type_void_hbox)) { node = SYNCTEX_PARENT(node); } - return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_INFO(node)[SYNCTEX_VERT].INT); + return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_VERT(node)); } float synctex_node_box_width(synctex_node_t node){ if(!node) { @@ -2508,7 +2645,7 @@ float synctex_node_box_width(synctex_node_t node){ && (node->class->type != synctex_node_type_void_hbox)) { node = SYNCTEX_PARENT(node); } - return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT); + return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_WIDTH(node)); } float synctex_node_box_height(synctex_node_t node){ if(!node) { @@ -2520,7 +2657,7 @@ float synctex_node_box_height(synctex_node_t node){ && (node->class->type != synctex_node_type_void_hbox)) { node = SYNCTEX_PARENT(node); } - return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT); + return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_HEIGHT(node)); } float synctex_node_box_depth(synctex_node_t node){ if(!node) { @@ -2532,7 +2669,7 @@ float synctex_node_box_depth(synctex_node_t node){ && (node->class->type != synctex_node_type_void_hbox)) { node = SYNCTEX_PARENT(node); } - return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT); + return (node->class->type == synctex_node_type_sheet)?0:(float)(SYNCTEX_DEPTH(node)); } #pragma mark - #pragma mark Public node visible attributes @@ -2540,19 +2677,19 @@ float synctex_node_visible_h(synctex_node_t node){ if(!node) { return 0; } - return SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT*node->class->scanner->unit+node->class->scanner->x_offset; + return SYNCTEX_HORIZ(node)*node->class->scanner->unit+node->class->scanner->x_offset; } float synctex_node_visible_v(synctex_node_t node){ if(!node) { return 0; } - return SYNCTEX_INFO(node)[SYNCTEX_VERT].INT*node->class->scanner->unit+node->class->scanner->y_offset; + return SYNCTEX_VERT(node)*node->class->scanner->unit+node->class->scanner->y_offset; } float synctex_node_visible_width(synctex_node_t node){ if(!node) { return 0; } - return SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT*node->class->scanner->unit; + return SYNCTEX_WIDTH(node)*node->class->scanner->unit; } float synctex_node_box_visible_h(synctex_node_t node){ if(!node) { @@ -2562,9 +2699,9 @@ float synctex_node_box_visible_h(synctex_node_t node){ || (node->class->type == synctex_node_type_void_hbox) || (node->class->type == synctex_node_type_void_vbox)) { result: - return SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT<0? - (SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT+SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT)*node->class->scanner->unit+node->class->scanner->x_offset: - SYNCTEX_INFO(node)[SYNCTEX_HORIZ].INT*node->class->scanner->unit+node->class->scanner->x_offset; + return SYNCTEX_WIDTH(node)<0? + (SYNCTEX_HORIZ(node)+SYNCTEX_WIDTH(node))*node->class->scanner->unit+node->class->scanner->x_offset: + SYNCTEX_HORIZ(node)*node->class->scanner->unit+node->class->scanner->x_offset; } if(node->class->type != synctex_node_type_hbox) { node = SYNCTEX_PARENT(node); @@ -2575,9 +2712,9 @@ result: if(node->class->type == synctex_node_type_vbox) { goto result; } - return SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V].INT<0? - (SYNCTEX_INFO(node)[SYNCTEX_HORIZ_V].INT+SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V].INT)*node->class->scanner->unit+node->class->scanner->x_offset: - SYNCTEX_INFO(node)[SYNCTEX_HORIZ_V].INT*node->class->scanner->unit+node->class->scanner->x_offset; + return SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V_IDX].INT<0? + (SYNCTEX_INFO(node)[SYNCTEX_HORIZ_V_IDX].INT+SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V_IDX].INT)*node->class->scanner->unit+node->class->scanner->x_offset: + SYNCTEX_INFO(node)[SYNCTEX_HORIZ_V_IDX].INT*node->class->scanner->unit+node->class->scanner->x_offset; } float synctex_node_box_visible_v(synctex_node_t node){ if(!node) { @@ -2587,7 +2724,7 @@ float synctex_node_box_visible_v(synctex_node_t node){ || (node->class->type == synctex_node_type_void_hbox) || (node->class->type == synctex_node_type_void_vbox)) { result: - return (float)(SYNCTEX_INFO(node)[SYNCTEX_VERT].INT)*node->class->scanner->unit+node->class->scanner->y_offset; + return (float)(SYNCTEX_VERT(node))*node->class->scanner->unit+node->class->scanner->y_offset; } if((node->class->type != synctex_node_type_vbox) && (node->class->type != synctex_node_type_hbox)) { @@ -2599,7 +2736,7 @@ result: if(node->class->type == synctex_node_type_vbox) { goto result; } - return SYNCTEX_INFO(node)[SYNCTEX_VERT_V].INT*node->class->scanner->unit+node->class->scanner->y_offset; + return SYNCTEX_INFO(node)[SYNCTEX_VERT_V_IDX].INT*node->class->scanner->unit+node->class->scanner->y_offset; } float synctex_node_box_visible_width(synctex_node_t node){ if(!node) { @@ -2609,9 +2746,9 @@ float synctex_node_box_visible_width(synctex_node_t node){ || (node->class->type == synctex_node_type_void_hbox) || (node->class->type == synctex_node_type_void_vbox)) { result: - return SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT<0? - -SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT*node->class->scanner->unit: - SYNCTEX_INFO(node)[SYNCTEX_WIDTH].INT*node->class->scanner->unit; + return SYNCTEX_WIDTH(node)<0? + -SYNCTEX_WIDTH(node)*node->class->scanner->unit: + SYNCTEX_WIDTH(node)*node->class->scanner->unit; } if(node->class->type != synctex_node_type_hbox) { node = SYNCTEX_PARENT(node); @@ -2622,9 +2759,9 @@ result: if(node->class->type == synctex_node_type_vbox) { goto result; } - return SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V].INT<0? - -SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V].INT*node->class->scanner->unit: - SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V].INT*node->class->scanner->unit; + return SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V_IDX].INT<0? + -SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V_IDX].INT*node->class->scanner->unit: + SYNCTEX_INFO(node)[SYNCTEX_WIDTH_V_IDX].INT*node->class->scanner->unit; } float synctex_node_box_visible_height(synctex_node_t node){ if(!node) { @@ -2634,7 +2771,7 @@ float synctex_node_box_visible_height(synctex_node_t node){ || (node->class->type == synctex_node_type_void_hbox) || (node->class->type == synctex_node_type_void_vbox)) { result: - return (float)(SYNCTEX_INFO(node)[SYNCTEX_HEIGHT].INT)*node->class->scanner->unit; + return (float)(SYNCTEX_HEIGHT(node))*node->class->scanner->unit; } if(node->class->type != synctex_node_type_hbox) { node = SYNCTEX_PARENT(node); @@ -2645,7 +2782,7 @@ result: if(node->class->type == synctex_node_type_vbox) { goto result; } - return SYNCTEX_INFO(node)[SYNCTEX_HEIGHT_V].INT*node->class->scanner->unit; + return SYNCTEX_INFO(node)[SYNCTEX_HEIGHT_V_IDX].INT*node->class->scanner->unit; } float synctex_node_box_visible_depth(synctex_node_t node){ if(!node) { @@ -2655,7 +2792,7 @@ float synctex_node_box_visible_depth(synctex_node_t node){ || (node->class->type == synctex_node_type_void_hbox) || (node->class->type == synctex_node_type_void_vbox)) { result: - return (float)(SYNCTEX_INFO(node)[SYNCTEX_DEPTH].INT)*node->class->scanner->unit; + return (float)(SYNCTEX_DEPTH(node))*node->class->scanner->unit; } if(node->class->type != synctex_node_type_hbox) { node = SYNCTEX_PARENT(node); @@ -2666,7 +2803,7 @@ result: if(node->class->type == synctex_node_type_vbox) { goto result; } - return SYNCTEX_INFO(node)[SYNCTEX_DEPTH_V].INT*node->class->scanner->unit; + return SYNCTEX_INFO(node)[SYNCTEX_DEPTH_V_IDX].INT*node->class->scanner->unit; } #pragma mark - #pragma mark Other public node attributes @@ -2681,15 +2818,15 @@ int synctex_node_page(synctex_node_t node){ parent = SYNCTEX_PARENT(node); } if(node->class->type == synctex_node_type_sheet) { - return SYNCTEX_INFO(node)[PAGE].INT; + return SYNCTEX_PAGE(node); } return -1; } int synctex_node_tag(synctex_node_t node) { - return node?SYNCTEX_INFO(node)[SYNCTEX_TAG].INT:-1; + return node?SYNCTEX_TAG(node):-1; } int synctex_node_line(synctex_node_t node) { - return node?SYNCTEX_INFO(node)[SYNCTEX_LINE].INT:-1; + return node?SYNCTEX_LINE(node):-1; } int synctex_node_column(synctex_node_t node) { #pragma unused(node) @@ -2702,7 +2839,7 @@ synctex_node_t synctex_sheet_content(synctex_scanner_t scanner,int page) { if(scanner) { synctex_node_t sheet = scanner->sheet; while(sheet) { - if(page == SYNCTEX_INFO(sheet)[PAGE].INT) { + if(page == SYNCTEX_PAGE(sheet)) { return SYNCTEX_CHILD(sheet); } sheet = SYNCTEX_SIBLING(sheet); @@ -2726,7 +2863,7 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i friend_index = (tag+line)%(scanner->number_of_lists); node = (scanner->lists_of_friends)[friend_index]; while(node) { - if((tag == SYNCTEX_INFO(node)[SYNCTEX_TAG].INT) && (line == SYNCTEX_INFO(node)[SYNCTEX_LINE].INT)) { + if((tag == SYNCTEX_TAG(node)) && (line == SYNCTEX_LINE(node))) { if(SYNCTEX_CUR == SYNCTEX_END) { size += 16; SYNCTEX_END = realloc(SYNCTEX_START,size*sizeof(synctex_node_t *)); @@ -2787,7 +2924,7 @@ int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v) { free(SYNCTEX_START); SYNCTEX_START = SYNCTEX_END = SYNCTEX_CUR = NULL; sheet = scanner->sheet; - while(sheet != NULL && SYNCTEX_INFO(sheet)[PAGE].INT != page) { + while(sheet != NULL && SYNCTEX_PAGE(sheet) != page) { sheet = SYNCTEX_SIBLING(sheet); } if(NULL == sheet) { @@ -2823,7 +2960,6 @@ has_node_any_child: goto has_node_any_child; } /* node has no child */ -/*node_has_no_child:*/ if(_synctex_point_in_visible_box(h,v,node)) { /* we found a void box containing the hit point */ if(ptr == end) { @@ -2942,6 +3078,138 @@ synctex_node_t synctex_next_result(synctex_scanner_t scanner) { } int synctex_bail(void) { - printf("SyncTeX ERROR\n"); + fprintf(stderr,"SyncTeX ERROR\n"); return -1; } + +#pragma mark ===== updater + +typedef int (*synctex_fprintf_t)(void *, const char * , ...); /* print formatted to either FILE * or gzFile */ + +# define SYNCTEX_BITS_PER_BYTE 8 + +struct __synctex_updater_t { + void *file; /* the foo.synctex or foo.synctex.gz I/O identifier */ + synctex_fprintf_t fprintf; /* either fprintf or gzprintf */ + int length; /* the number of chars appended */ + struct _flags { + unsigned int no_gz:1; /* Whether zlib is used or not */ + unsigned int reserved:SYNCTEX_BITS_PER_BYTE*sizeof(int)-1; /* Align */ + } flags; +}; +# define SYNCTEX_FILE updater->file +# define SYNCTEX_NO_GZ ((updater->flags).no_gz) +# define SYNCTEX_fprintf (*(updater->fprintf)) +# define SYNCTEX_YES (-1) +# define SYNCTEX_NO (0) + +synctex_updater_t synctex_updater_new_with_output_file(const char * output){ + synctex_updater_t updater = NULL; + char * synctex = NULL; + size_t size = 0; + /* prepare the updater */ + updater = (synctex_updater_t)_synctex_malloc(sizeof(synctex_updater_t)); + if(NULL == updater) { + fprintf(stderr,"! synctex_updater_new_with_file: malloc problem"); + return NULL; + } + size = strlen(output)+strlen(synctex_suffix)+strlen(synctex_suffix_gz)+1; + synctex = (char *)malloc(size); + if(NULL == synctex) { + fprintf(stderr,"! synctex_updater_new_with_output_file: Memory problem (1)\n"); +return_on_error1: + free(updater); + return NULL; + } + /* we have reserved for synctex enough memory to copy output and both suffices, + * including the terminating character */ + if(synctex != strcpy(synctex,output)) { + fprintf(stderr,"! synctex_updater_new_with_output_file: Copy problem\n"); +return_on_error2: + free(synctex); + goto return_on_error1; + } + /* remove the last path extension if any */ + synctex_strip_last_path_extension(synctex); + /* append the synctex suffix */ + if(synctex != strcat(synctex,synctex_suffix)){ + fprintf(stderr,"! synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix '%s')\n",synctex_suffix); + goto return_on_error2; + } + if(NULL != (SYNCTEX_FILE = fopen(synctex,"r"))){ + /* OK, the file exists */ + fclose(SYNCTEX_FILE); + if(NULL == (SYNCTEX_FILE = (void *)fopen(synctex,"a"))) { +no_write_error: + fprintf(stderr,"! synctex_updater_new_with_file: Can't append to %s",synctex); + goto return_on_error2; + } + SYNCTEX_NO_GZ = SYNCTEX_YES; + updater->fprintf = (synctex_fprintf_t)(&fprintf); +return_updater: + printf("SyncTeX: updating %s...",synctex); + free(synctex); + return updater; + } + /* append the gz suffix */ + if(synctex != strcat(synctex,synctex_suffix_gz)){ + fprintf(stderr,"! synctex_scanner_new_with_output_file: Concatenation problem (can't add suffix '%s')\n",synctex_suffix_gz); + goto return_on_error2; + } + if(NULL != (SYNCTEX_FILE = gzopen(synctex,"r"))){ + gzclose(SYNCTEX_FILE); + if(NULL == (SYNCTEX_FILE = gzopen(synctex,"a"))) { + goto no_write_error; + } + SYNCTEX_NO_GZ = SYNCTEX_NO; + updater->fprintf = (synctex_fprintf_t)(&gzprintf); + goto return_updater; + } + goto return_on_error2; +} + +void synctex_updater_append_magnification(synctex_updater_t updater, char * magnification){ + if(NULL==updater) { + return; + } + 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) { + return; + } + 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) { + return; + } + 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) { + return; + } + if(updater->length>0) { + SYNCTEX_fprintf(SYNCTEX_FILE,"!%i\n",updater->length); + } + if (SYNCTEX_NO_GZ) { + fclose((FILE *)SYNCTEX_FILE); + } else { + gzclose((gzFile)SYNCTEX_FILE); + } + free(updater); + printf("... done.\n"); + return; +} + + diff --git a/Build/source/texk/web2c/synctex/synctex_parser.h b/Build/source/texk/web2c/synctex/synctex_parser.h index 02804f3a4d4..5c1e7295af4 100644 --- a/Build/source/texk/web2c/synctex/synctex_parser.h +++ b/Build/source/texk/web2c/synctex/synctex_parser.h @@ -50,10 +50,12 @@ extern "C" { #endif /* This is the designated method to create a new synctex scanner object. - * name is the full path of the synctex file to be parsed. - * NULL is returned in case of an error. + * name can be the tex file that originated the synctex file. + * The ".tex" file extension is removed and replaced by the proper extension. + * Then the synctex_scanner_new_with_contents_of_file is called. + * NULL is returned in case of an error or non existent file. */ -synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name); +synctex_scanner_t synctex_scanner_new_with_output_file(const char * output); /* This is the designated method to delete a synctex scanner object. */ @@ -88,6 +90,7 @@ float synctex_scanner_magnification(synctex_scanner_t scanner); const char * synctex_scanner_get_name(synctex_scanner_t scanner,int tag); int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name); synctex_node_t synctex_scanner_input(synctex_scanner_t scanner); +const char * synctex_scanner_get_output(synctex_scanner_t scanner); /* Browsing the nodes * parent, child and sibling are standard names for tree nodes. @@ -215,6 +218,27 @@ int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,i int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v); synctex_node_t synctex_next_result(synctex_scanner_t scanner); +/* The main synctex updater object. + * This object is used to append information to the synctex file. + * Its implementation is considered private. + */ +typedef struct __synctex_updater_t _synctex_updater_t; +typedef _synctex_updater_t * synctex_updater_t; + +/* Designated initializer. + * Once you are done with your whole job, + * free the updater */ +synctex_updater_t synctex_updater_new_with_output_file(const char * output); + +/* Use the next functions to append records to the synctex file, + * no consistency tests made on the arguments */ +void synctex_updater_append_magnification(synctex_updater_t updater, char * magnification); +void synctex_updater_append_x_offset(synctex_updater_t updater, char * x_offset); +void synctex_updater_append_y_offset(synctex_updater_t updater, char * y_offset); + +/* You MUST free the updater, once everything is properly appended */ +void synctex_updater_free(synctex_updater_t updater); + #ifdef __cplusplus }; #endif |