summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/synctex
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/synctex')
-rw-r--r--Build/source/texk/web2c/synctex/synctex-mem.ch018
-rw-r--r--Build/source/texk/web2c/synctex/synctex-rec.ch019
-rw-r--r--Build/source/texk/web2c/synctex/synctex.c511
-rw-r--r--Build/source/texk/web2c/synctex/synctex.defines3
-rw-r--r--Build/source/texk/web2c/synctex/synctex.h6
-rw-r--r--Build/source/texk/web2c/synctex/synctex_main.c174
-rw-r--r--Build/source/texk/web2c/synctex/synctex_parser.c624
-rw-r--r--Build/source/texk/web2c/synctex/synctex_parser.h10
8 files changed, 742 insertions, 623 deletions
diff --git a/Build/source/texk/web2c/synctex/synctex-mem.ch0 b/Build/source/texk/web2c/synctex/synctex-mem.ch0
index 5b8cf19e99e..bf4e5265ba7 100644
--- a/Build/source/texk/web2c/synctex/synctex-mem.ch0
+++ b/Build/source/texk/web2c/synctex/synctex-mem.ch0
@@ -197,7 +197,14 @@ penalty_node: begin r:=get_node(small_node_size);
end
@z
-@x
+@x tex.web l. 24264
+history:=spotless; {ready to go!}
+@y
+history:=spotless; {ready to go!}
+@<Initialize synctex primitive@>
+@z
+
+@x tex.web l. 24945
@* \[54] System-dependent changes.
@y
@* \[54/SyncTeX] The {\sl Synchronize \TeX nology}.
@@ -229,7 +236,7 @@ except the definitions.
|synctexoption| is used for that purpose.
This global integer variable is declared here but it is not used here.
This is just a placeholder where the command line controller will put
-the {\sl {\sl Sync\TeX}} related options, and the {\sl Sync\TeX} controller will read them.
+the {\sl Sync\TeX} related options, and the {\sl Sync\TeX} controller will read them.
@ @<Glob...@>=
@!synctexoption:integer;
@@ -238,6 +245,11 @@ the {\sl {\sl Sync\TeX}} related options, and the {\sl Sync\TeX} controller will
\.{\\synctex=1} in the input source file enables synchronization whereas
\.{\\synctex=0} disables it.
Its memory address is |synctex_code|.
+It is initialized by the {\sl Sync\TeX} controller to the command-line option if given.
+The controller may filter some reserved bits.
+
+@ @<Initialize synctex primitive@>=
+synctex_init_command;
@ @<Put each...@>=
primitive("synctex",assign_int,int_base+synctex_code);@/
@@ -245,7 +257,7 @@ primitive("synctex",assign_int,int_base+synctex_code);@/
@ In order to give the {\sl Sync\TeX} controller read and write access to
the contents of the \.{\\synctex} primitive, we declare |synctexoffset|,
-such that |mem[synctexoffset]| and \.{\\synctex} correpond to
+such that |mem[synctexoffset]| and \.{\\synctex} correspond to
the same memory storage. |synctexoffset| is initialized to
the correct value when quite everything is initialized.
diff --git a/Build/source/texk/web2c/synctex/synctex-rec.ch0 b/Build/source/texk/web2c/synctex/synctex-rec.ch0
index 8868214409c..e81a9c1a7e8 100644
--- a/Build/source/texk/web2c/synctex/synctex-rec.ch0
+++ b/Build/source/texk/web2c/synctex/synctex-rec.ch0
@@ -228,18 +228,13 @@ temp_ptr:=lig_stack; lig_stack:=link(temp_ptr);
free_node(temp_ptr,small_node_size); {{\sl Sync\TeX} watch point: proper size!}
@z
-@x
-history:=spotless; {ready to go!}
-@y
-synctex:=synctexoption; {{\sl Sync\TeX}: read command-line option if given}
-history:=spotless; {ready to go!}
-@z
-
@x tex.web l.24288
-begin @<Finish the extensions@>;
+if log_opened then
+ begin wlog_cr; a_close(log_file); selector:=selector-2;
@y
-begin @<Finish the extensions@>;
-@<Terminate {\sl Sync\TeX} information recording@>
+@<Close {\sl Sync\TeX} file and write status@>;
+if log_opened then
+ begin wlog_cr; a_close(log_file); selector:=selector-2;
@z
@x tex.web + synctex-mem.ch0
@@ -318,8 +313,8 @@ synctex_start_input; {Give control to the {\sl Sync\TeX} controller}
@ @<Prepare terminal input {\sl Sync\TeX} information@>=
synctex_tag:=0;
-@ @<Terminate {\sl Sync\TeX} information recording@>=
-synctex_terminate; {Let the {\sl Sync\TeX} controller close its files.}
+@ @<Close {\sl Sync\TeX} file and write status@>=
+synctex_terminate(log_opened); {Let the {\sl Sync\TeX} controller close its files.}
@ Synchronized nodes are boxes, math, kern and glue nodes.
Other nodes should be synchronized too, in particular math noads.
diff --git a/Build/source/texk/web2c/synctex/synctex.c b/Build/source/texk/web2c/synctex/synctex.c
index f32eaa94836..90bcce98ab8 100644
--- a/Build/source/texk/web2c/synctex/synctex.c
+++ b/Build/source/texk/web2c/synctex/synctex.c
@@ -53,13 +53,13 @@ from TeX as long as the extensions do not break too much the core design.
Moreover, the synchronize texnology only relies on code concept and not
implementation details, so it can be ported to other TeX systems. In order to
support SyncTeX, one can start reading the dedicated section in synctex.ch,
-sync-pdftex.ch and sync-xetex.ch.
+sync-pdftex.ch and sync-xetex.ch. Actually, support is provided for TeX, e-TeX,
+pdfTeX and XeTeX.
Other existing public synchronization technologies are defined by srcltx.sty -
also used by source specials - and pdfsync.sty. Like them, the synchronize
texnology is meant to be shared by various text editors, viewers and TeX
-engines. A centralized reference and source of information is available on
-CTAN, in directory support/synctex.
+engines. A centralized reference and source of information is available in TeX-Live.
Versioning:
-----------
@@ -72,19 +72,17 @@ Please, do not remove these explanations.
*/
-# define SYNCTEX_VERSION 1
+# define SYNCTEX_VERSION 1
-# define SYNCTEX_DEBUG 0
+# define SYNCTEX_DEBUG 0
-# define SYNCTEX_GZ 1
+/* Debugging: define the next macro to "return;" in order to disable the synctex code
+ * only suplemental function calls will be used. The compiler may optimize them. */
+# define SYNCTEX_RETURN_IF_DISABLED ;
-/* Debugging: define the next macro to "return;" in order to disable the synctex code
- * only suplemental function calls will be used. The compiler may optimize them. */
-# define SYNCTEX_RETURN_IF_DISABLED ;
+# define SYNCTEX_NOERR 0
-# define SYNCTEX_NOERR 0
-
-# define EXTERN extern
+# define EXTERN extern
# ifdef xfree
# define SYNCTEX_FREE xfree
@@ -104,15 +102,11 @@ EXTERN char *gettexstring(int n);
*/
# warning These structures MUST be kept in synchronization with the main program
/* synctexoption is a global integer variable defined in *tex.web
- * it is set to 1 by texmfmp.c if the command line has the '-synchronize=1'
+ * it is set to 1 by texmfmp.c if the command line has the '-synctex=1'
* option. */
# define synctex_options synctexoption
-# define SYNCTEX_DISABLED_MASK 0x80000000
-/* if the SYNCTEX_DISABLED_MASK bit of synctex_options is set, the
- * synchronization is definitely disabled. */
-# define SYNCTEX_IGNORE_CLI_MASK 0x40000000
-/* if the SYNCTEX_IGNORE_CLI_MASK bit of synctex_options is set, the option
- * given from the command line is ignored. */
+# define SYNCTEX_NO_OPTION INT_MAX
+/* if synctex_options is set to SYNCTEX_NO_OPTION, no command line option was provided. */
/* glue code: really define the main memory,
* this is exactly the same "mem" as in *tex.web. */
@@ -120,7 +114,7 @@ EXTERN char *gettexstring(int n);
/* glue code: synctexoffset is a global integer variable defined in *tex.web
* it is set to the offset where the primitive \synctex reads and writes its
* value. */
-# define SYNCTEX_IS_ENABLED zeqtb[synctexoffset].cint
+# define SYNCTEX_VALUE zeqtb[synctexoffset].cint
/* if there were a mean to share the value of synctex_code between *tex.web
* and this file, it would be great. */
@@ -202,9 +196,7 @@ EXTERN char *gettexstring(int n);
* a change in the context, this is the macro SYNCTEX_CONTEXT_DID_CHANGE. The
* SYNCTEX_IGNORE macro is used to detect unproperly initialized nodes. See
* details in the implementation of the functions below. */
-# define SYNCTEX_IGNORE(NODE) (0 != (synctex_options & SYNCTEX_DISABLED_MASK) ) \
- || (SYNCTEX_IS_ENABLED == 0) \
- || (st_FILE == 0)
+# define SYNCTEX_IGNORE(NODE) SYNCTEX_IS_OFF || !SYNCTEX_VALUE || !SYNCTEX_FILE
/* Some parts of the code may differ depending on the ouput mode,
* dvi or xdv vs pdf, in particular the management of magnification.
@@ -214,45 +206,75 @@ EXTERN char *gettexstring(int n);
# define SYNCTEX_OUTPUT "dvi"
# define SYNCTEX_OFFSET_IS_PDF 0
-#include "synctex-TEX-OR-MF-OR-MP.h"
+# define SYNCTEX_YES (-1)
+# define SYNCTEX_NO (0)
+
+# include "synctex-TEX-OR-MF-OR-MP.h"
# if defined(__SyncTeX__)
# include <stdio.h>
# include <stdarg.h>
+# include "zlib.h"
-#if SYNCTEX_GZ
-# include "zlib.h"
-# define FPRINTF gzprintf
-#else
-# define FPRINTF fprintf
-#endif
+typedef void (*synctex_recorder_t)(halfword); /* recorders know how to record a node */
+typedef int (*synctex_fprintf_t)(void *, const char * , ...); /* print formatted to either FILE * or gzFile */
+
+# define SYNCTEX_BITS_PER_BYTE 8
/* Here are all the local variables gathered in one "synchronization context" */
static struct {
-#if SYNCTEX_GZ
- gzFile file; /* the foo.synctex I/O identifier */
-#else
- FILE *file; /* the foo.synctex I/O identifier */
-#endif
- char *name; /* the real "foo.synctex" name */
+ void *file; /* the foo.synctex or foo.synctex.gz I/O identifier */
+ synctex_fprintf_t fprintf; /* either fprintf or gzprintf */
+ char *busy_name; /* the real "foo.synctex(busy)" or "foo.synctex.gz(busy)" name */
char *root_name; /* in general jobname.tex */
integer count; /* The number of interesting records in "foo.synctex" */
/* next concern the last sync record encountered */
halfword node; /* the last synchronized node, must be set
* before the recorder */
- void (*recorder) (halfword);/* the recorder of the node above, the
+ synctex_recorder_t recorder;/* the recorder of the node above, the
* routine that knows how to record the
* node to the .synctex file */
integer tag, line; /* current tag and line */
integer curh, curv; /* current point */
integer magnification; /* The magnification as given by \mag */
- integer unit; /* The unit, defaults to 8192, fixed */
+ integer unit; /* The unit, defaults to 1, use 8192 to produce shorter but less accurate info */
integer total_length; /* The total length of the bytes written since the last check point */
+ struct _flags {
+ unsigned int option_read:1; /* Command line option read (in case of problem or at the end) */
+ unsigned int off:1; /* Definitely turn off synctex */
+ unsigned int no_gz:1; /* Whether zlib is used or not */
+ unsigned int reserved:SYNCTEX_BITS_PER_BYTE*sizeof(int)-3; /* Align */
+ } flags;
} synctex_ctxt = {
-NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0};
+NULL, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, {0,0,0,0}};
+
+#define SYNCTEX_FILE synctex_ctxt.file
+#define SYNCTEX_IS_OFF (synctex_ctxt.flags.off)
+#define SYNCTEX_NO_GZ (synctex_ctxt.flags.no_gz)
+#define SYNCTEX_fprintf (*synctex_ctxt.fprintf)
-#define st_FILE synctex_ctxt.file
+void synctexinitcommand(void)
+{
+ if (synctex_ctxt.flags.option_read) {
+ return;
+ }
+ if (SYNCTEX_NO_OPTION == synctex_options) {
+ /* No option given from the command line */
+ SYNCTEX_VALUE = 0;
+ } else if (!synctex_options) {
+ /* -synctex=0 was given: SyncTeX must be disabled */
+ SYNCTEX_IS_OFF = SYNCTEX_YES;
+ } else {
+ /* the command line options are not ignored */
+ if(synctex_options<0) {
+ SYNCTEX_NO_GZ = SYNCTEX_YES;
+ }
+ SYNCTEX_VALUE = synctex_options;
+ }
+ synctex_ctxt.flags.option_read = SYNCTEX_YES;
+ return;
+}
/* Free all memory used and close the file,
* sent by close_files_and_terminate in tex.web
@@ -263,29 +285,26 @@ void synctex_abort(void)
#if SYNCTEX_DEBUG
printf("\nSynchronize DEBUG: synctex_abort\n");
#endif
- if (NULL != st_FILE) {
-#if SYNCTEX_GZ
- gzclose(st_FILE);
-#else
- xfclose(st_FILE, synctex_ctxt.name);
-#endif
- SYNCTEX_FREE(synctex_ctxt.name);
- synctex_ctxt.name = NULL;
+ if (SYNCTEX_FILE) {
+ if (SYNCTEX_NO_GZ) {
+ xfclose((FILE *)SYNCTEX_FILE, synctex_ctxt.busy_name);
+ } else {
+ gzclose((gzFile)SYNCTEX_FILE);
+ }
+ SYNCTEX_FREE(synctex_ctxt.busy_name);
+ synctex_ctxt.busy_name = NULL;
}
SYNCTEX_FREE(synctex_ctxt.root_name);
synctex_ctxt.root_name = NULL;
- synctex_options = SYNCTEX_DISABLED_MASK; /* disable synctex */
+ SYNCTEX_IS_OFF = SYNCTEX_YES; /* disable synctex */
}
static inline int synctex_record_preamble(void);
static inline int synctex_record_input(integer tag, char *name);
-#if SYNCTEX_GZ
-static char *synctex_suffix = ".synctex.gz";
-#else
static char *synctex_suffix = ".synctex";
-#endif
-static char *synctex_working = "(working)";
+static char *synctex_suffix_gz = ".gz";
+static char *synctex_suffix_busy = "(busy)";
/* synctex_dot_open ensures that the foo.synctex file is open.
* In case of problem, it definitely disables synchronization.
@@ -295,82 +314,90 @@ static char *synctex_working = "(working)";
* For example foo-i.synctex would contain input synchronization
* information for page i alone.
*/
-static FILE *synctex_dot_open(void)
+static void *synctex_dot_open(void)
{
-#if SYNCTEX_DISABLED
- return NULL;
-#endif
+ SYNCTEX_RETURN_IF_DISABLED;
#if SYNCTEX_DEBUG
printf("\nwarning: Synchronize DEBUG: synctex_dot_open\n");
- printf("\nwarning: SYNCTEX_IS_ENABLED=%0X\n", SYNCTEX_IS_ENABLED);
+ printf("\nwarning: SYNCTEX_VALUE=%0X\n", SYNCTEX_VALUE);
printf("\nwarning: synctex_options=%0X\n", synctex_options);
# endif
- if (0 != (synctex_options & SYNCTEX_DISABLED_MASK)) {
- return 0; /* synchronization is definitely disabled: do nothing */
+ if (SYNCTEX_IS_OFF || !SYNCTEX_VALUE) {
+ return NULL; /* synchronization is disabled: do nothing */
+ }
+ if (SYNCTEX_FILE) {
+ return SYNCTEX_FILE; /* synchronization is alerady enabled */
}
#if SYNCTEX_DEBUG
printf("\nwarning: Synchronize DEBUG: synctex_dot_open 1\n");
# endif
- if (NULL == st_FILE) {
- /* this is the first time we are asked to open the file
- this part of code is executed only once:
- either st_FILE is nonnegative or synchronization is
- definitely disabled. */
- /* jobname was set by the \jobname command on the *TeX side */
- char *tmp = gettexstring(jobname);
- /* jobname was set by the \jobname command on the *TeX side */
- char *the_syncname = xmalloc(strlen(tmp) + strlen(synctex_suffix) + strlen(synctex_working) + 1);
- if(NULL == the_syncname) {
+ SYNCTEX_NO_GZ = synctex_options<0? SYNCTEX_YES:SYNCTEX_NO;
+ /* this is the first time we are asked to open the file
+ this part of code is executed only once:
+ either SYNCTEX_FILE is nonnegative or synchronization is
+ definitely disabled. */
+ /* jobname was set by the \jobname command on the *TeX side */
+ {
+ char *tmp = gettexstring(jobname);
+ /* jobname was set by the \jobname command on the *TeX side */
+ char * the_busy_name = xmalloc(strlen(tmp) + strlen(synctex_suffix) + strlen(synctex_suffix_gz) + strlen(synctex_suffix_busy) + 1);
+ if(!the_busy_name) {
SYNCTEX_FREE(tmp);
synctex_abort();
return NULL;
}
- strcpy(the_syncname, tmp);
- SYNCTEX_FREE(tmp);
- strcat(the_syncname, synctex_suffix);
- strcat(the_syncname, synctex_working);
-#if SYNCTEX_GZ
- st_FILE = gzopen(the_syncname, FOPEN_WBIN_MODE);
-#else
- st_FILE = xfopen(the_syncname, FOPEN_WBIN_MODE);
-#endif
+ strcpy(the_busy_name, tmp);
+ SYNCTEX_FREE(tmp);
+ strcat(the_busy_name, synctex_suffix);
+ if (!SYNCTEX_NO_GZ) {
+ strcat(the_busy_name, synctex_suffix_gz);
+ }
+ strcat(the_busy_name, synctex_suffix_busy);
+ if (SYNCTEX_NO_GZ) {
+ SYNCTEX_FILE = xfopen(the_busy_name, FOPEN_WBIN_MODE);
+ synctex_ctxt.fprintf = (synctex_fprintf_t)(&fprintf);
+ } else {
+ SYNCTEX_FILE = gzopen(the_busy_name, FOPEN_WBIN_MODE);
+ synctex_ctxt.fprintf = (synctex_fprintf_t)(&gzprintf);
+ }
#if SYNCTEX_DEBUG
- printf("\nwarning: Synchronize DEBUG: synctex_dot_open 2\n");
+ printf("\nwarning: Synchronize DEBUG: synctex_dot_open 2\n");
#endif
- if (NULL != st_FILE) {
+ if (SYNCTEX_FILE) {
if(synctex_record_preamble()) {
synctex_abort();
return NULL;
}
- /* Initialization of the context */
+ /* Initialization of the context */
synctex_ctxt.magnification = 1000;
- synctex_ctxt.unit = SYNCTEX_UNIT_FACTOR;
- /* synctex_ctxt.name was NULL before, it now owns the_syncname */
- synctex_ctxt.name = the_syncname;
- /* print the preamble, this is an quite an UTF8 file */
- if (NULL != synctex_ctxt.root_name) {
- synctex_record_input(1,synctex_ctxt.root_name);
- SYNCTEX_FREE(synctex_ctxt.root_name);
- synctex_ctxt.root_name = NULL;
- }
- synctex_ctxt.count = 0;
+ synctex_ctxt.unit = SYNCTEX_UNIT_FACTOR;
+ /* synctex_ctxt.busy_name was NULL before, it now owns the_busy_name */
+ synctex_ctxt.busy_name = the_busy_name;
+ the_busy_name = NULL;
+ /* print the preamble, this is an quite an UTF8 file */
+ if (NULL != synctex_ctxt.root_name) {
+ synctex_record_input(1,synctex_ctxt.root_name);
+ SYNCTEX_FREE(synctex_ctxt.root_name);
+ synctex_ctxt.root_name = NULL;
+ }
+ synctex_ctxt.count = 0;
#if SYNCTEX_DEBUG
- fprintf(stdout,
- "\nwarning: Synchronize DEBUG: synctex_dot_open SYNCTEX AVAILABLE\n");
+ fprintf(stdout,
+ "\nwarning: Synchronize DEBUG: synctex_dot_open SYNCTEX AVAILABLE\n");
#endif
- } else {
- /* no .synctex file available, so disable synchronization */
- synctex_options = SYNCTEX_DISABLED_MASK;
- /* and free the_syncname */
- SYNCTEX_FREE(the_syncname);
- the_syncname = NULL;
+ } else {
+ /* no .synctex file available, so disable synchronization */
+ SYNCTEX_IS_OFF = SYNCTEX_YES;
+ /* and free the_busy_name */
+ SYNCTEX_FREE(the_busy_name);
+ the_busy_name = NULL;
#if SYNCTEX_DEBUG
- fprintf(stdout,
- "\nwarning: Synchronize DEBUG: synctex_dot_open SYNCTEX DISABLED\n");
+ fprintf(stdout,
+ "\nwarning: Synchronize DEBUG: synctex_dot_open SYNCTEX DISABLED\n");
#endif
- }
- }
- return st_FILE;
+ }
+ }
+ return SYNCTEX_FILE;
}
/* Each time TeX opens a file, it sends a syncstartinput message and enters
@@ -381,12 +408,12 @@ static FILE *synctex_dot_open(void)
* will read the .synctex file and retrieve this mapping, it will be able to
* open the correct file just knowing its tag. If the same file is read
* multiple times, it might be associated to different tags. Synchronization
- * controller, either in viewers, editors or standalone should be prepared to
+ * controllers, either in viewers, editors or standalone should be prepared to
* handle this situation and take the appropriate action of they want to
* optimize memory. No two different files will have the same positive tag.
* It is not advisable to definitely store the file names here. If the file
* names ever have to be stored, it should definitely be done at the TeX level
- * just like src-specials do such that other components of the program can use
+ * just like src-specials do, such that other components of the program can use
* it. This function does not make any difference between the files, it
* treats the same way .tex, .aux, .sty ... files, even if many of them do not
* contain any material meant to be typeset.
@@ -399,14 +426,11 @@ void synctexstartinput(void)
#if SYNCTEX_DEBUG
printf("\nwarning: Synchronize DEBUG: synctexstartinput %i",
synctex_tag_counter);
- printf("\nwarning: SYNCTEX_IS_ENABLED=%i", SYNCTEX_IS_ENABLED);
+ printf("\nwarning: SYNCTEX_VALUE=%i", SYNCTEX_VALUE);
printf("\nwarning: synctex_options=%0X", synctex_options);
- printf("\nwarning: SYNCTEX_DISABLED_MASK=%0X",
- SYNCTEX_DISABLED_MASK);
#endif
- if (0 != (synctex_options & SYNCTEX_DISABLED_MASK)) {
- /* this is where we disable synchronization -synctex=-1 */
+ if (SYNCTEX_IS_OFF) {
return;
}
/* synctex_tag_counter is a counter uniquely identifying the file actually
@@ -422,15 +446,6 @@ void synctexstartinput(void)
curinput.synctextagfield = 0;
return;
}
- if (0 == (synctex_options & SYNCTEX_IGNORE_CLI_MASK)) {
- /* the command line options are not ignored */
- SYNCTEX_IS_ENABLED = synctex_options>SYNCTEX_IS_ENABLED?
- synctex_options:SYNCTEX_IS_ENABLED;
- synctex_options |= SYNCTEX_IGNORE_CLI_MASK;
- /* the command line options will be ignored from now on. Every
- * subsequent call of syncstartinput won't get there
- * synctex_options is now the list of option flags */
- }
curinput.synctextagfield = synctex_tag_counter; /* -> *TeX.web */
if (synctex_tag_counter == 1) {
/* this is the first file TeX ever opens, in general \jobname.tex we
@@ -447,8 +462,7 @@ void synctexstartinput(void)
# endif
return;
}
- if ((NULL != st_FILE)
- || ((SYNCTEX_IS_ENABLED && synctex_dot_open()) != 0)) {
+ if (SYNCTEX_FILE || (SYNCTEX_VALUE && synctex_dot_open())) {
char *tmp = gettexstring(curinput.namefield);
synctex_record_input(curinput.synctextagfield,tmp);
SYNCTEX_FREE(tmp);
@@ -473,41 +487,63 @@ static inline int synctex_record_postamble(void);
/* synctexterminate() is called when the TeX run terminates.
* If synchronization was active, the working synctex file is moved to
- * The final synctex file name.
- * If synchronization was not active, the synctex file is removed is any.
+ * the final synctex file name.
+ * If synchronization was not active of if there is no output,
+ * the synctex file is removed if any.
* That way we can be sure that any synctex file is in sync with a tex run.
* However, it does not mean that it will be in sync with the pdf, especially
* when the output is dvi or xdv and the dvi (or xdv) to pdf driver has not been applied.
*/
-void synctexterminate(void)
+void synctexterminate(boolean log_opened)
{
+ char *tmp = NULL;
+ char * the_real_syncname = NULL;
SYNCTEX_RETURN_IF_DISABLED;
#if SYNCTEX_DEBUG
printf("\nSynchronize DEBUG: synctexterminate\n");
#endif
- char *tmp = gettexstring(jobname);
- char * the_real_syncname = xmalloc(strlen(tmp) + strlen(synctex_suffix) + 1);
- if(NULL == the_real_syncname) {
+ tmp = gettexstring(jobname);
+ the_real_syncname = xmalloc(strlen(tmp) + strlen(synctex_suffix) + strlen(synctex_suffix_gz) + 1);
+ if(!the_real_syncname) {
SYNCTEX_FREE(tmp);
synctex_abort();
return;
}
strcpy(the_real_syncname, tmp);
strcat(the_real_syncname, synctex_suffix);
+ remove(the_real_syncname);/* I don't know if the previous run was made with the uncompressed mode */
+ strcat(the_real_syncname, synctex_suffix_gz);
remove(the_real_syncname);
- if (NULL != st_FILE) {
+ if (SYNCTEX_NO_GZ) {
+ strcpy(the_real_syncname, tmp);
+ strcat(the_real_syncname, synctex_suffix);
+ }
+ if (SYNCTEX_FILE) {
if (totalpages > 0) {
synctex_record_postamble();
+ /* close the synctex file*/
+ if (SYNCTEX_NO_GZ) {
+ xfclose((FILE *)SYNCTEX_FILE, synctex_ctxt.busy_name);
+ } else {
+ gzclose((gzFile)SYNCTEX_FILE);
+ }
+ /* renaming the working synctex file */
+ if((0 == rename(synctex_ctxt.busy_name,the_real_syncname)) && log_opened) {
+ printf("\nSyncTeX written on %s",the_real_syncname); /* SyncTeX also refers to the contents */
+ }
+ } else {
+ /* close and remove the synctex file because there are no pages of output */
+ if (SYNCTEX_NO_GZ) {
+ xfclose((FILE *)SYNCTEX_FILE, synctex_ctxt.busy_name);
+ } else {
+ gzclose((gzFile)SYNCTEX_FILE);
+ }
+ remove(synctex_ctxt.busy_name);
}
- /* renaming the working synctex file */
- char *the_working_syncname = xmalloc(strlen(the_real_syncname) + strlen(synctex_working) + 1);
- if(NULL != the_working_syncname) {
- strcpy(the_working_syncname, the_real_syncname);
- strcat(the_working_syncname, synctex_working);
- rename(the_working_syncname,the_real_syncname);
- SYNCTEX_FREE(the_working_syncname);
- }
+ SYNCTEX_FILE = NULL;
}
+ SYNCTEX_FREE(synctex_ctxt.busy_name);
+ synctex_ctxt.busy_name = NULL;
SYNCTEX_FREE(the_real_syncname);
SYNCTEX_FREE(tmp);
synctex_abort();
@@ -526,11 +562,10 @@ void synctexsheet(integer mag)
#if SYNCTEX_DEBUG
printf("\nSynchronize DEBUG: synctexsheet %i\n",mag);
#endif
- if (0 != (synctex_options & SYNCTEX_DISABLED_MASK)) {
+ if (SYNCTEX_IS_OFF) {
return;
}
- if ((st_FILE != NULL)
- || ((SYNCTEX_IS_ENABLED != 0) && (synctex_dot_open() != 0))) {
+ if (SYNCTEX_FILE || (SYNCTEX_VALUE && synctex_dot_open())) {
/* tries to open the .synctex, useful if synchronization was enabled
* from the source file and not from the CLI
* totalpages is defined in tex.web */
@@ -567,7 +602,7 @@ void synctexteehs(void)
#if SYNCTEX_DEBUG
printf("\nSynchronize DEBUG: synctexteehs\n");
#endif
- if ((0 != (synctex_options & SYNCTEX_DISABLED_MASK)) || (st_FILE == NULL) ) {
+ if (SYNCTEX_IS_OFF || !SYNCTEX_FILE ) {
return;
}
synctex_record_teehs(totalpages);/* not totalpages+1*/
@@ -577,15 +612,11 @@ void synctexteehs(void)
return;
}
-#define SYNCTEX_DEBUG_SAVINGS /*if(NULL!=synctex_ctxt.recorder){\
- FPRINTF(st_FILE, "SAVED ");\
- (*synctex_ctxt.recorder) (synctex_ctxt.node);}*/
-
static inline void synctex_record_vlist(halfword p);
/* This message is sent when a vlist will be shipped out, more precisely at
- * the beginning of the vlist_out procedure in *TeX.web. It will be balanced
- * by a synctex_tsilv, sent at the end of the vlist_out procedure. p is the
+ * the beginning of the vliSYNCTEX_out procedure in *TeX.web. It will be balanced
+ * by a synctex_tsilv, sent at the end of the vliSYNCTEX_out procedure. p is the
* address of the vlist We assume that p is really a vlist node! */
void synctexvlist(halfword this_box)
{
@@ -596,7 +627,6 @@ void synctexvlist(halfword this_box)
if (SYNCTEX_IGNORE(this_box)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
synctex_ctxt.node = this_box; /* 0 to reset */
synctex_ctxt.recorder = NULL; /* reset */
synctex_ctxt.tag = SYNCTEX_TAG_MODEL(this_box,box_node_size);
@@ -610,7 +640,7 @@ static inline void synctex_record_tsilv(halfword p);
/* Recording a "f" line ending a vbox: this message is sent whenever a vlist
* has been shipped out. It is used to close the vlist nesting level. It is
- * sent at the end of the vlist_out procedure in *TeX.web to balance a former
+ * sent at the end of the vliSYNCTEX_out procedure in *TeX.web to balance a former
* synctex_vlist sent at the beginning of that procedure. */
void synctextsilv(halfword this_box)
{
@@ -644,7 +674,6 @@ void synctexvoidvlist(halfword p, halfword this_box)
if (SYNCTEX_IGNORE(p)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
synctex_ctxt.node = p; /* reset */
synctex_ctxt.tag = SYNCTEX_TAG_MODEL(p,box_node_size);
synctex_ctxt.line = SYNCTEX_LINE_MODEL(p,box_node_size);
@@ -657,8 +686,8 @@ void synctexvoidvlist(halfword p, halfword this_box)
static inline void synctex_record_hlist(halfword p);
/* This message is sent when an hlist will be shipped out, more precisely at
- * the beginning of the hlist_out procedure in *TeX.web. It will be balanced
- * by a synctex_tsilh, sent at the end of the hlist_out procedure. p is the
+ * the beginning of the hliSYNCTEX_out procedure in *TeX.web. It will be balanced
+ * by a synctex_tsilh, sent at the end of the hliSYNCTEX_out procedure. p is the
* address of the hlist We assume that p is really an hlist node! */
void synctexhlist(halfword this_box)
{
@@ -669,7 +698,6 @@ void synctexhlist(halfword this_box)
if (SYNCTEX_IGNORE(this_box)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
synctex_ctxt.node = this_box; /* 0 to reset */
synctex_ctxt.tag = SYNCTEX_TAG_MODEL(this_box,box_node_size);
synctex_ctxt.line = SYNCTEX_LINE_MODEL(this_box,box_node_size);
@@ -683,7 +711,7 @@ static inline void synctex_record_tsilh(halfword p);
/* Recording a ")" line ending an hbox this message is sent whenever an hlist
* has been shipped out it is used to close the hlist nesting level. It is
- * sent at the end of the hlist_out procedure in *TeX.web to balance a former
+ * sent at the end of the hliSYNCTEX_out procedure in *TeX.web to balance a former
* synctex_hlist sent at the beginning of that procedure. */
void synctextsilh(halfword this_box)
{
@@ -694,7 +722,6 @@ void synctextsilh(halfword this_box)
if (SYNCTEX_IGNORE(this_box)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
/* Ignoring any pending info to be recorded */
synctex_ctxt.node = this_box; /* 0 to force next node to be recorded! */
synctex_ctxt.tag = SYNCTEX_TAG_MODEL(this_box,box_node_size);
@@ -718,7 +745,6 @@ void synctexvoidhlist(halfword p, halfword this_box)
if (SYNCTEX_IGNORE(p)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
/* the sync context has changed */
if (synctex_ctxt.recorder != NULL) {
/* but was not yet recorded */
@@ -742,11 +768,9 @@ void synctexvoidhlist(halfword p, halfword this_box)
/* IN THE SEQUEL, ALL NODE ARE medium_node_size'd, UNTIL THE CONTRARY IS MENTIONNED */
# undef SYNCTEX_IGNORE
-# define SYNCTEX_IGNORE(NODE) (0 != (synctex_options & SYNCTEX_DISABLED_MASK) ) \
- || (0 == SYNCTEX_IS_ENABLED) \
+# define SYNCTEX_IGNORE(NODE) SYNCTEX_IS_OFF || !SYNCTEX_VALUE \
|| (0 >= SYNCTEX_TAG_MODEL(NODE,medium_node_size)) \
- || (0 >= SYNCTEX_LINE_MODEL(NODE,medium_node_size)) \
- || (0 == st_FILE)
+ || (0 >= SYNCTEX_LINE_MODEL(NODE,medium_node_size))
/* This macro will detect a change in the synchronization context. As long as
* the synchronization context remains the same, there is no need to write
@@ -769,7 +793,6 @@ void synctexmath(halfword p, halfword this_box)
if (SYNCTEX_IGNORE(p)) {
return;
}
- SYNCTEX_DEBUG_SAVINGS;
if ((synctex_ctxt.recorder != NULL) && SYNCTEX_CONTEXT_DID_CHANGE(p)) {
/* the sync context did change */
(*synctex_ctxt.recorder) (synctex_ctxt.node);
@@ -858,8 +881,7 @@ void synctexkern(halfword p, halfword this_box)
synctex_kern_recorder(p);
}
} else {
- SYNCTEX_DEBUG_SAVINGS;
- /* just update the geometry and type (for future improvements) */
+ /* just update the geometry and type (for future improvements) */
synctex_ctxt.node = p;
synctex_ctxt.tag = SYNCTEX_TAG_MODEL(p,medium_node_size);
synctex_ctxt.line = SYNCTEX_LINE_MODEL(p,medium_node_size);
@@ -870,10 +892,9 @@ void synctexkern(halfword p, halfword this_box)
/* This last part is used as a tool to infer TeX behaviour,
* but not for direct synchronization. */
# undef SYNCTEX_IGNORE
-# define SYNCTEX_IGNORE(NODE) (0 != (synctex_options & SYNCTEX_DISABLED_MASK) ) \
- || (0 == SYNCTEX_IS_ENABLED) \
- || (NULL == st_FILE) \
+# define SYNCTEX_IGNORE(NODE) SYNCTEX_IS_OFF || !SYNCTEX_VALUE || !SYNCTEX_FILE \
|| (synctex_ctxt.count>2000)
+
void synctex_char_recorder(halfword p);
/* this message is sent whenever a char node ships out */
@@ -901,9 +922,8 @@ void synctexchar(halfword p, halfword this_box)
void synctex_node_recorder(halfword p);
# undef SYNCTEX_IGNORE
-# define SYNCTEX_IGNORE(NODE) (0 != (synctex_options & SYNCTEX_DISABLED_MASK) \
- || (0 == SYNCTEX_IS_ENABLED) \
- || (NULL == st_FILE))
+# define SYNCTEX_IGNORE(NODE) (SYNCTEX_IS_OFF || !SYNCTEX_VALUE || !SYNCTEX_FILE)
+
/* this message should be sent to record information
for a node of an unknown type */
void synctexnode(halfword p, halfword this_box)
@@ -929,13 +949,14 @@ void synctexcurrent(void)
#endif
if (SYNCTEX_IGNORE(nothing)) {
return;
- }
- size_t len = FPRINTF(st_FILE,"x%i,%i:%i,%i\n",
- synctex_ctxt.tag,synctex_ctxt.line,
- curh UNIT,curv UNIT);
- if(len) {
- synctex_ctxt.total_length += len;
- return;
+ } else {
+ size_t len = SYNCTEX_fprintf(SYNCTEX_FILE,"x%i,%i:%i,%i\n",
+ synctex_ctxt.tag,synctex_ctxt.line,
+ curh UNIT,curv UNIT);
+ if(len>0) {
+ synctex_ctxt.total_length += len;
+ return;
+ }
}
synctex_abort();
return;
@@ -950,17 +971,17 @@ static inline int synctex_record_settings(void)
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_settings\n");
#endif
- if(NULL == st_FILE) {
- return 0;
+ if(NULL == SYNCTEX_FILE) {
+ return SYNCTEX_NOERR;
}
- if(st_FILE) {
- size_t len = FPRINTF(st_FILE,"Output:%s\nMagnification:%i\nUnit:%i\nX Offset:%i\nY Offset:%i\n",
+ if(SYNCTEX_FILE) {
+ size_t len = SYNCTEX_fprintf(SYNCTEX_FILE,"Output:%s\nMagnification:%i\nUnit:%i\nX Offset:%i\nY Offset:%i\n",
SYNCTEX_OUTPUT,synctex_ctxt.magnification,synctex_ctxt.unit,
((SYNCTEX_OFFSET_IS_PDF != 0) ? 0 : 4736287 UNIT),
((SYNCTEX_OFFSET_IS_PDF != 0) ? 0 : 4736287 UNIT));
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
- return 0;
+ return SYNCTEX_NOERR;
}
}
synctex_abort();
@@ -970,13 +991,14 @@ static inline int synctex_record_settings(void)
/* Recording a "SyncTeX..." line */
static inline int synctex_record_preamble(void)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_preamble\n");
#endif
- size_t len = FPRINTF(st_FILE,"SyncTeX Version:%i\n",SYNCTEX_VERSION);
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"SyncTeX Version:%i\n",SYNCTEX_VERSION);
+ if(len>0) {
synctex_ctxt.total_length = len;
- return 0;
+ return SYNCTEX_NOERR;
}
synctex_abort();
return -1;
@@ -985,13 +1007,14 @@ static inline int synctex_record_preamble(void)
/* Recording a "Input:..." line */
static inline int synctex_record_input(integer tag, char *name)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_input\n");
#endif
- size_t len = FPRINTF(st_FILE,"Input:%i:%s\n",tag,name);
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"Input:%i:%s\n",tag,name);
+ if(len>0) {
synctex_ctxt.total_length += len;
- return 0;
+ return SYNCTEX_NOERR;
}
synctex_abort();
return -1;
@@ -1000,14 +1023,15 @@ static inline int synctex_record_input(integer tag, char *name)
/* Recording a "!..." line */
static inline int synctex_record_anchor(void)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_anchor\n");
#endif
- size_t len = FPRINTF(st_FILE,"!%i\n",synctex_ctxt.total_length);
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"!%i\n",synctex_ctxt.total_length);
+ if(len>0) {
synctex_ctxt.total_length = len;
++synctex_ctxt.count;
- return 0;
+ return SYNCTEX_NOERR;
}
synctex_abort();
return -1;
@@ -1016,13 +1040,14 @@ static inline int synctex_record_anchor(void)
/* Recording a "Content" line */
static inline int synctex_record_content(void)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_content\n");
#endif
- size_t len = FPRINTF(st_FILE,"Content:\n");
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"Content:\n");
+ if(len>0) {
synctex_ctxt.total_length += len;
- return 0;
+ return SYNCTEX_NOERR;
}
synctex_abort();
return -1;
@@ -1035,11 +1060,11 @@ static inline int synctex_record_sheet(integer sheet)
printf("\nSynchronize DEBUG: synctex_record_sheet\n");
#endif
if(SYNCTEX_NOERR == synctex_record_anchor()) {
- size_t len = FPRINTF(st_FILE,"{%i\n",sheet);
- if(len) {
+ size_t len = SYNCTEX_fprintf(SYNCTEX_FILE,"{%i\n",sheet);
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
- return 0;
+ return SYNCTEX_NOERR;
}
}
synctex_abort();
@@ -1053,11 +1078,11 @@ static inline int synctex_record_teehs(integer sheet)
printf("\nSynchronize DEBUG: synctex_record_teehs\n");
#endif
if(SYNCTEX_NOERR == synctex_record_anchor()) {
- size_t len = FPRINTF(st_FILE,"}%i\n",sheet);
- if(len) {
+ size_t len = SYNCTEX_fprintf(SYNCTEX_FILE,"}%i\n",sheet);
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
- return 0;
+ return SYNCTEX_NOERR;
}
}
synctex_abort();
@@ -1067,17 +1092,18 @@ static inline int synctex_record_teehs(integer sheet)
/* Recording a "v..." line */
static inline void synctex_record_void_vlist(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_void_vlist\n");
#endif
- size_t len = FPRINTF(st_FILE,"v%i,%i:%i,%i:%i,%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"v%i,%i:%i,%i:%i,%i,%i\n",
SYNCTEX_TAG_MODEL(p,box_node_size),
SYNCTEX_LINE_MODEL(p,box_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT,
SYNCTEX_HEIGHT(p) UNIT,
SYNCTEX_DEPTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1089,17 +1115,18 @@ static inline void synctex_record_void_vlist(halfword p)
/* Recording a "[..." line */
static inline void synctex_record_vlist(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_vlist\n");
#endif
- size_t len = FPRINTF(st_FILE,"[%i,%i:%i,%i:%i,%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"[%i,%i:%i,%i:%i,%i,%i\n",
SYNCTEX_TAG_MODEL(p,box_node_size),
SYNCTEX_LINE_MODEL(p,box_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT,
SYNCTEX_HEIGHT(p) UNIT,
SYNCTEX_DEPTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1111,11 +1138,12 @@ static inline void synctex_record_vlist(halfword p)
/* Recording a "]..." line */
static inline void synctex_record_tsilv(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_tsilv\n");
#endif
- size_t len = FPRINTF(st_FILE,"]\n");
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"]\n");
+ if(len>0) {
synctex_ctxt.total_length += len;
return;
}
@@ -1126,17 +1154,18 @@ static inline void synctex_record_tsilv(halfword p)
/* Recording a "h..." line */
static inline void synctex_record_void_hlist(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_void_hlist\n");
#endif
- size_t len = FPRINTF(st_FILE,"h%i,%i:%i,%i:%i,%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"h%i,%i:%i,%i:%i,%i,%i\n",
SYNCTEX_TAG_MODEL(p,box_node_size),
SYNCTEX_LINE_MODEL(p,box_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT,
SYNCTEX_HEIGHT(p) UNIT,
SYNCTEX_DEPTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1148,17 +1177,18 @@ static inline void synctex_record_void_hlist(halfword p)
/* Recording a "(..." line */
static inline void synctex_record_hlist(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_hlist\n");
#endif
- size_t len = FPRINTF(st_FILE,"(%i,%i:%i,%i:%i,%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"(%i,%i:%i,%i:%i,%i,%i\n",
SYNCTEX_TAG_MODEL(p,box_node_size),
SYNCTEX_LINE_MODEL(p,box_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT,
SYNCTEX_HEIGHT(p) UNIT,
SYNCTEX_DEPTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1170,11 +1200,12 @@ static inline void synctex_record_hlist(halfword p)
/* Recording a ")..." line */
static inline void synctex_record_tsilh(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_tsilh\n");
#endif
- size_t len = FPRINTF(st_FILE,")\n");
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,")\n");
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1185,13 +1216,14 @@ static inline void synctex_record_tsilh(halfword p)
/* Recording a "Count..." line */
static inline int synctex_record_count(void) {
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_count\n");
#endif
- size_t len = FPRINTF(st_FILE,"Count:%i\n",synctex_ctxt.count);
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"Count:%i\n",synctex_ctxt.count);
+ if(len>0) {
synctex_ctxt.total_length += len;
- return 0;
+ return SYNCTEX_NOERR;
}
synctex_abort();
return -1;
@@ -1204,15 +1236,15 @@ static inline int synctex_record_postamble(void)
printf("\nSynchronize DEBUG: synctex_record_postamble\n");
#endif
if(SYNCTEX_NOERR == synctex_record_anchor()) {
- size_t len = FPRINTF(st_FILE,"Postamble:\n");
- if(len) {
+ size_t len = SYNCTEX_fprintf(SYNCTEX_FILE,"Postamble:\n");
+ if(len>0) {
synctex_ctxt.total_length += len;
if(synctex_record_count() || synctex_record_anchor()) {
} else {
- len = FPRINTF(st_FILE,"Post scriptum:\n");
- if(len) {
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"Post scriptum:\n");
+ if(len>0) {
synctex_ctxt.total_length += len;
- return 0;
+ return SYNCTEX_NOERR;
}
}
}
@@ -1224,14 +1256,15 @@ static inline int synctex_record_postamble(void)
/* Recording a "g..." line */
static inline void synctex_record_glue(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_glue_recorder\n");
#endif
- size_t len = FPRINTF(st_FILE,"g%i,%i:%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"g%i,%i:%i,%i\n",
SYNCTEX_TAG_MODEL(p,medium_node_size),
SYNCTEX_LINE_MODEL(p,medium_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1243,15 +1276,16 @@ static inline void synctex_record_glue(halfword p)
/* Recording a "k..." line */
static inline void synctex_record_kern(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_kern_recorder\n");
#endif
- size_t len = FPRINTF(st_FILE,"k%i,%i:%i,%i:%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"k%i,%i:%i,%i:%i\n",
SYNCTEX_TAG_MODEL(p,medium_node_size),
SYNCTEX_LINE_MODEL(p,medium_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1263,17 +1297,18 @@ static inline void synctex_record_kern(halfword p)
/* Recording a "r..." line */
static inline void synctex_record_rule(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_record_tsilh\n");
#endif
- size_t len = FPRINTF(st_FILE,"r%i,%i:%i,%i:%i,%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"r%i,%i:%i,%i:%i,%i,%i\n",
SYNCTEX_TAG_MODEL(p,rule_node_size),
SYNCTEX_LINE_MODEL(p,rule_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
rulewd UNIT,
ruleht UNIT,
ruledp UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1289,14 +1324,15 @@ static inline void synctex_record_rule(halfword p)
/* Recording a "$..." line */
void synctex_math_recorder(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_math_recorder\n");
#endif
- size_t len = FPRINTF(st_FILE,"$%i,%i:%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"$%i,%i:%i,%i\n",
SYNCTEX_TAG_MODEL(p,medium_node_size),
SYNCTEX_LINE_MODEL(p,medium_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1308,15 +1344,16 @@ void synctex_math_recorder(halfword p)
/* Recording a "k..." line */
void synctex_kern_recorder(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_kern_recorder\n");
#endif
- size_t len = FPRINTF(st_FILE,"k%i,%i:%i,%i:%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"k%i,%i:%i,%i:%i\n",
SYNCTEX_TAG_MODEL(p,medium_node_size),
SYNCTEX_LINE_MODEL(p,medium_node_size),
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
SYNCTEX_WIDTH(p) UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1328,12 +1365,13 @@ void synctex_kern_recorder(halfword p)
/* Recording a "c..." line */
void synctex_char_recorder(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_char_recorder\n");
#endif
- size_t len = FPRINTF(st_FILE,"c%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"c%i,%i\n",
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
@@ -1345,13 +1383,14 @@ void synctex_char_recorder(halfword p)
/* Recording a "?..." line, type, subtype and position */
void synctex_node_recorder(halfword p)
{
+ size_t len = 0;
#if SYNCTEX_DEBUG > 999
printf("\nSynchronize DEBUG: synctex_node_recorder(0x%x)\n",p);
#endif
- size_t len = FPRINTF(st_FILE,"?%i,%i:%i,%i\n",
+ len = SYNCTEX_fprintf(SYNCTEX_FILE,"?%i,%i:%i,%i\n",
synctex_ctxt.curh UNIT, synctex_ctxt.curv UNIT,
mem[p].hh.b0,mem[p].hh.b1);
- if(len) {
+ if(len>0) {
synctex_ctxt.total_length += len;
++synctex_ctxt.count;
return;
diff --git a/Build/source/texk/web2c/synctex/synctex.defines b/Build/source/texk/web2c/synctex/synctex.defines
index 8fb9c592169..6c6db7b24f2 100644
--- a/Build/source/texk/web2c/synctex/synctex.defines
+++ b/Build/source/texk/web2c/synctex/synctex.defines
@@ -40,8 +40,9 @@ from web to c (See the convert shell script).
}
{ functions from the synctex controller in synctex.c }
+@define procedure synctexinitcommand;
@define procedure synctexstartinput;
-@define procedure synctexterminate;
+@define procedure synctexterminate();
@define procedure synctexsheet();
@define procedure synctexteehs;
@define procedure synctexvlist();
diff --git a/Build/source/texk/web2c/synctex/synctex.h b/Build/source/texk/web2c/synctex/synctex.h
index 10996392877..ab49e9038e3 100644
--- a/Build/source/texk/web2c/synctex/synctex.h
+++ b/Build/source/texk/web2c/synctex/synctex.h
@@ -28,11 +28,15 @@ OTHER DEALINGS IN THE SOFTWARE
# ifndef __SYNCTEX_HEADER__
# define __SYNCTEX_HEADER__
+/* Send this message to init the synctex command value to the command line option.
+ * Sending this message too early will cause a bus error. */
+extern void synctexinitcommand(void);
+
/* Send this message when starting a new input. */
extern void synctexstartinput(void);
/* Send this message to clean memory. */
-extern void synctexterminate(void);
+extern void synctexterminate(boolean log_opened);
/* Recording the "{..." line. In *tex.web, use synctex_sheet(pdf_output) at
* the very beginning of the ship_out procedure.
diff --git a/Build/source/texk/web2c/synctex/synctex_main.c b/Build/source/texk/web2c/synctex/synctex_main.c
index 655f559bfe9..8ae5246c073 100644
--- a/Build/source/texk/web2c/synctex/synctex_main.c
+++ b/Build/source/texk/web2c/synctex/synctex_main.c
@@ -85,7 +85,7 @@ void synctex_usage(char * error,va_list ap) {
if(error) {
fprintf(stderr,"SyncTeX ERROR: ");
vfprintf(stderr,error,ap);
- fprintf(stderr,"%s\n");
+ fprintf(stderr,"\n");
}
fprintf((error?stderr:stdout),
"usage: synctex <subcommand> [options] [args]\n"
@@ -120,7 +120,7 @@ void synctex_help_view(char * error,...) {
synctex_usage(error, v);
va_end(v);
fprintf((error?stderr:stdout),
- "synctex view: forwards synchronization,\n"
+ "synctex view: forwards or direct synchronization,\n"
"command sent by the editor to view the output corresponding to the position under the mouse\n"
"\n"
"usage: synctex view -i line:column:input -o output [-x viewer-command] [-h before/offset:middle/after]\n"
@@ -140,21 +140,21 @@ void synctex_help_view(char * error,...) {
"-x viewer-command\n"
" Normally the synctex tool outputs its result to the stdout.\n"
" It is possible to launch an external tool with the result.\n"
- " The viewer-command is a printf like format string with numbered specifiers.\n"
- " %{output} is the name of the main document, without path extension.\n"
- " %{page} is the 0 based page number, %{page+1} is the 1 based page number.\n"
- " To synchronize by point, %{x} is the x coordinate, %{y} is the y coordinate,\n"
+ " The viewer-command is a printf like format string with following specifiers.\n"
+ " %{output} is the name specifier of the main document, without path extension.\n"
+ " %{page} is the 0 based page number specifier, %{page+1} is the 1 based page number specifier.\n"
+ " To synchronize by point, %{x} is the x coordinate specifier, %{y} is the y coordinate specifier,\n"
" both in dots and relative to the top left corner of the page.\n"
" To synchronize by box,\n"
- " %{h} is the horizontal coordinate of the origin of the enclosing box,\n"
- " %{v} is the vertical coordinate of the origin of the enclosing box,\n"
+ " %{h} is the horizontal coordinate specifier of the origin of the enclosing box,\n"
+ " %{v} is the vertical coordinate specifier of the origin of the enclosing box,\n"
" both in dots and relative to the upper left corner of the page.\n"
" They may be different from the preceding pair of coordinates.\n"
- " %{width} is the width, %{height} is the height of the enclosing box.\n"
+ " %{width} is the width specifier, %{height} is the height specifier of the enclosing box.\n"
" The latter dimension is naturally counted from bottom to top.\n"
" There is no notion of depth for such a box.\n"
" To synchronize by content, %{before} is the word before,\n"
- " %{offset} is the offset, %{middle} is the middle word, and %{after} is the word after.\n"
+ " %{offset} is the offset specifier, %{middle} is the middle word, and %{after} is the word after.\n"
"\n"
" If no viewer command is provided, the content of the SYNCTEX_VIEWER environment variable is used instead.\n"
"\n"
@@ -163,8 +163,8 @@ void synctex_help_view(char * error,...) {
" Instead of giving a character offset in a line, you can give full words.\n"
" A full word is a sequence of characters (excepting '/').\n"
" You will choose full words in the source document that will certainly appear unaltered in the output.\n"
- " The middle word contains the character under the mouse at position offset.\n"
- " before is a full word preceding middle and after is following it.\n"
+ " The \"middle\" word contains the character under the mouse at position offset.\n"
+ " \"before\" is a full word preceding middle and \"after\" is following it.\n"
" The before or after word can be missing, they are then considered as void strings.\n"
" \n"
);
@@ -183,13 +183,22 @@ int synctex_view(int argc, char *argv[]) {
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)) {
synctex_help_view("Missing -i required argument");
return -1;
}
- char * start = argv[arg_index];
- char * end = NULL;
+ start = argv[arg_index];
line = strtol(start,&end,10);
if(end>start && strlen(end)>0 && *end==':') {
start = end+1;
@@ -257,9 +266,6 @@ option_hint:
}
}
/* Now proceed, ignore any other argument */
- synctex_scanner_t scanner = NULL;
- char * synctex = NULL;
- size_t size = 0;
proceed:
#if SYNCTEX_DEBUG
printf("line:%i\n",line);
@@ -273,7 +279,7 @@ proceed:
printf("output:%s\n",output);
printf("cwd:%s\n",getcwd(NULL,0));
#endif
- size = strlen(output)+9;
+ size = strlen(output)+strlen(suffix)+strlen(suffix_gz)+1;
synctex = (char *)malloc(size);
if(NULL == synctex) {
synctex_help_view("No more memory");
@@ -283,8 +289,7 @@ proceed:
synctex_help_view("Copy problem");
return -1;
}
- char * ptr = synctex;
- char * where = NULL;
+ ptr = synctex;
/* remove the path extension of the last path component. */
# define SYNCTEX_PATH_COMPONENTS_SEPARATOR "/"
if(where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) {
@@ -299,12 +304,23 @@ proceed:
} while(where = strstr(ptr+1,SYNCTEX_PATH_EXTENSION_SEPARATOR));
*ptr = '\0';
}
- if(0 == strlcat(synctex,".synctex",size)){
- synctex_help_view("Concatenation problem");
+ if(0 == strlcat(synctex,suffix,size)){
+ synctex_help_view("Concatenation problem (can't add suffix '%s')",suffix);
return -1;
}
- size = 0;
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;
if(scanner && synctex_display_query(scanner,input,line,column)) {
@@ -314,19 +330,6 @@ proceed:
if(viewer && strlen(viewer)) {
/* Replace %{ by &{, then remove all unescaped '%'*/
char * where = NULL;
- while(where = strstr(viewer,"%{")) {
- *where = '&';
- }
- where = viewer;
- while(where = strstr(viewer,"%")) {
- if(strlen(++where)) {
- if(*where == '%') {
- ++where;
- } else {
- *(where-1)='&';
- }
- }
- }
char * dictionary [] = {
"&{output}","%1$s",
"&{page}","%2$i",
@@ -342,6 +345,21 @@ proceed:
"&{middle}","%12$s",
"&{after}","%13$s"};
int i = 26;
+ char * buffer = NULL;
+ int status = 0;
+ while(where = strstr(viewer,"%{")) {
+ *where = '&';
+ }
+ where = viewer;
+ while(where = strstr(viewer,"%")) {
+ if(strlen(++where)) {
+ if(*where == '%') {
+ ++where;
+ } else {
+ *(where-1)='&';
+ }
+ }
+ }
while(i>0) {
char * value = dictionary[--i];
char * key = dictionary[--i];
@@ -354,7 +372,7 @@ find_a_key:
}
}
size = strlen(viewer)+3*sizeof(int)+6*sizeof(float)+4*(65536)+1;
- char * buffer = malloc(size);
+ buffer = malloc(size);
if(NULL == buffer) {
synctex_help_view("No memory available");
return -1;
@@ -380,7 +398,7 @@ find_a_key:
return -1;
}
printf("SyncTeX: Executing\n%s\n",buffer);
- int status = system(buffer);
+ status = system(buffer);
free(buffer);
buffer = NULL;
return status;
@@ -426,7 +444,7 @@ void synctex_help_edit(char * error,...) {
synctex_usage(error, v);
va_end(v);
fputs(
- "synctex edit: backwards synchronization,\n"
+ "synctex edit: backwards or reverse synchronization,\n"
"command sent by the viewer to edit the source corresponding to the position under the mouse\n\n"
"\n"
"usage: synctex edit -o page:x:y:file [-x editor-command] [-h offset:context]\n"
@@ -441,19 +459,19 @@ void synctex_help_edit(char * error,...) {
" \n"
"-x editor-command\n"
" Normally the synctex tool outputs its result to the stdout.\n"
- " It is possible to execute an external tool with the result.\n"
+ " It is possible to execute an external tool with the result of the query.\n"
" The editor-command is a printf like format string with following specifiers.\n"
" They will be replaced by their value before the command is executed.\n"
- " %{output} is the full path of the output document, with no extension.\n"
- " %{input} is the name of the input document.\n"
- " %{line} is the 0 based line number. %{line+1} is the 1 based line number.\n"
- " %{column} is the 0 based column number or -1. %{column+1} is the 1 based column number or -1.\n"
- " %{offset} is the 0 based offset and %{context} is the context of the hint.\n"
+ " %{output} is the full path specifier of the output document, with no extension.\n"
+ " %{input} is the name specifier of the input document.\n"
+ " %{line} is the 0 based line number specifier. %{line+1} is the 1 based line number specifier.\n"
+ " %{column} is the 0 based column number specifier or -1. %{column+1} is the 1 based column number or -1.\n"
+ " %{offset} is the 0 based offset specifier and %{context} is the context specifier of the hint.\n"
" \n"
- " If no editor command is provided, the content of the SYNCTEX_EDITOR environment variable is used instead.\n"
+ " If no editor-command is provided, the content of the SYNCTEX_EDITOR environment variable is used instead.\n"
" \n"
"-h offset:context\n"
- " This hint allows a backwards synchronization by contents.\n"
+ " This hint allows a backwards or reverse synchronization by contents.\n"
" You give a context including the character at the mouse location, and\n"
" the offset of this character relative to the beginning of this bunch of text.\n"
" \n",
@@ -472,13 +490,19 @@ int synctex_edit(int argc, char *argv[]) {
char * editor = NULL;
int offset = 0;
char * context = NULL;
+ char * start = NULL;
+ char * end = NULL;
+ synctex_scanner_t scanner = NULL;
+ char * synctex = NULL;
+ size_t size = 0;
+ char * ptr = NULL;
+ char * where = NULL;
/* required */
if((arg_index>=argc) || strcmp("-o",argv[arg_index]) || (++arg_index>=argc)) {
synctex_help_view("Missing -o required argument");
return -1;
}
- char * start = argv[arg_index];
- char * end = NULL;
+ start = argv[arg_index];
page = strtol(start,&end,10);
if(end>start && strlen(end)>1 && *end==':') {
start = end+1;
@@ -530,9 +554,6 @@ option_hint:
return -1;
}
}
- synctex_scanner_t scanner = NULL;
- char * synctex = NULL;
- size_t size = 0;
proceed:
#if SYNCTEX_DEBUG
printf("page:%i\n",page);
@@ -554,8 +575,7 @@ proceed:
synctex_help_edit("Copy problem");
return -1;
}
- char * ptr = synctex;
- char * where = NULL;
+ ptr = synctex;
/* remove the path extension of the last path component. */
if(where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) {
do {
@@ -583,6 +603,16 @@ proceed:
&& (input = (char *)synctex_scanner_get_name(scanner,synctex_node_tag(node)))) {
/* filtering the command */
if(strlen(editor)) {
+ char * buffer = NULL;
+ int status;
+ char * dictionary [] = {
+ "&{output}","%1$s",
+ "&{input}","%2$s",
+ "&{line}","%3$i",
+ "&{column}","%4$i",
+ "&{offset}","%5$i",
+ "&{context}","%6$s"};
+ int i = 12;
/* Replace %{ by &{, then remove all unescaped '%'*/
while(where = strstr(editor,"%{")) {
*where = '&';
@@ -597,14 +627,6 @@ proceed:
}
}
}
- char * dictionary [] = {
- "&{output}","%1$s",
- "&{input}","%2$s",
- "&{line}","%3$i",
- "&{column}","%4$i",
- "&{offset}","%5$i",
- "&{context}","%6$s"};
- int i = 12;
while(i>0) {
char * value = dictionary[--i];
char * key = dictionary[--i];
@@ -617,7 +639,7 @@ find_a_key:
}
}
size = strlen(editor)+3*sizeof(int)+6*sizeof(float)+4*(65536)+1;
- char * buffer = malloc(size);
+ buffer = malloc(size);
if(NULL == buffer) {
printf("SyncTeX ERROR: No memory available\n",editor);
return -1;
@@ -636,7 +658,7 @@ find_a_key:
return -1;
}
printf("SyncTeX: Executing\n%s\n",buffer);
- int status = system(buffer);
+ status = system(buffer);
free(buffer);
buffer = NULL;
return status;
@@ -688,14 +710,20 @@ void synctex_help_update(char * error,...) {
/* "usage: synctex update -o output [-m number] [-x dimension] [-y dim output\n" */
int synctex_update(int argc, char *argv[]) {
int arg_index = 0;
- if(arg_index>=argc) {
- synctex_help_update("Bad update command");
- return -1;
- }
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;
+ if(arg_index>=argc) {
+ synctex_help_update("Bad update command");
+ return -1;
+ }
/* required */
if((arg_index>=argc) || strcmp("-o",argv[arg_index]) || (++arg_index>=argc)) {
synctex_help_update("Missing -o required argument");
@@ -732,8 +760,8 @@ prepare_next_argument:
goto prepare_next_argument;
}
/* Arguments parsed */
- size_t size = strlen(output)+9;
- char * synctex = (char *)malloc(size);
+ size = strlen(output)+9;
+ synctex = (char *)malloc(size);
if(NULL == synctex) {
synctex_help_update("No more memory");
return -1;
@@ -749,8 +777,7 @@ prepare_next_argument:
printf("SyncTeX: Nothing to update\n");
return 0;
}
- char * ptr = synctex;
- char * where = NULL;
+ ptr = synctex;
/* remove the path extension of the last path component. */
if(where = strstr(ptr,SYNCTEX_PATH_COMPONENTS_SEPARATOR)) {
do {
@@ -767,13 +794,12 @@ prepare_next_argument:
synctex_help_update("Concatenation problem");
return -1;
}
- FILE * F = fopen(synctex,"a");
+ F = fopen(synctex,"a");
if(NULL == F) {
synctex_help_update("No file at: %s",synctex);
return -1;
}
printf("SyncTeX: updating %s...",synctex);
- int len = 0;
if(magnification) {
len += fprintf(F,"Magnification:%s\n",magnification);
}
diff --git a/Build/source/texk/web2c/synctex/synctex_parser.c b/Build/source/texk/web2c/synctex/synctex_parser.c
index f68e32d99d7..6e0fb7f02ef 100644
--- a/Build/source/texk/web2c/synctex/synctex_parser.c
+++ b/Build/source/texk/web2c/synctex/synctex_parser.c
@@ -46,7 +46,7 @@ authorization from the copyright holder.
void *_synctex_malloc(size_t size) {
void * ptr = malloc(size);
if(ptr) {
- memset(ptr,0,size);
+ bzero(ptr,size);
}
return (void *)ptr;
}
@@ -202,11 +202,14 @@ void _synctex_free_leaf(synctex_node_t node) {
return;
}
+#include <zlib.h>
+
/* The synctex scanner is the root object.
* Is is initiated with the contents of a text file.
* The buffer_? are first used to parse the text.
*/
struct __synctex_scanner_t {
+ gzFile file; /* The (compressed) file */
unsigned char * buffer_ptr; /* current location in the buffer */
unsigned char * buffer_start; /* start of the buffer */
unsigned char * buffer_end; /* end of the buffer */
@@ -602,7 +605,7 @@ sibling:
return SIBLING(node);
}
if(node = PARENT(node)) {
- if(node->class->type == synctex_node_type_sheet) {// EXC_BAD_ACCESS?
+ if(node->class->type == synctex_node_type_sheet) {/* EXC_BAD_ACCESS? */
return NULL;
}
goto sibling;
@@ -833,6 +836,56 @@ void _synctex_display_input(synctex_node_t node) {
#define SYNCTEX_NOERR 0
+#define F scanner->file
+#define SYNCTEX_BUF_SIZE 32768
+
+/* Ensures that the buffer contains at least size bytes.
+ * Passing a negative size argument means the whole buffer length.
+ * The return value is the number of bytes now available in the buffer.
+ * -1 is returned in case of error. */
+int _synctex_fill_buffer_up_to_size(synctex_scanner_t scanner, int size) {
+ int count = END - PTR; /* count is the number of unparsed chars in the buffer */
+ if(size<0) {
+ size = SYNCTEX_BUF_SIZE;
+ }
+ if(size<=count) {
+ return count;
+ }
+ if(F) {
+ /* Copy the remaining part of the buffer to the beginning,
+ * then read the next part of the file */
+ int read = 0;
+ if(count) {
+ memmove(START, PTR, count);
+ }
+ PTR = START + count; /* the next character after the move, will change. */
+ /* Fill the buffer up to its end */
+ read = gzread(F,(void *)PTR,SYNCTEX_BUF_SIZE - count);
+ if(read>0) {
+ END = PTR + read;
+ PTR = START;
+ if(SYNCTEX_BUF_SIZE==size || size<=END-PTR) {
+ return END - PTR;
+ }
+ return -1;
+ } else if(read<0) {
+ /*This is an error */
+ printf("SyncTeX Error: gzread error (1)");
+ return -1;
+ } else {
+ gzclose(F);
+ F = NULL;
+ END = PTR;
+ PTR = START;
+ return END - PTR; /* there might be a bit of text left */
+ }
+ }
+ if(END-PTR > 0)
+ return END - PTR;
+ /* There was nothing left in the file */
+ return -1;
+}
+
/* Used when parsing the synctex file.
* Advance to the next character starting a line.
* Actually, only \n is recognized as end of line marker. */
@@ -840,13 +893,15 @@ int _synctex_next_line(synctex_scanner_t scanner) {
if(NULL == scanner) {
return -1;
}
- while(PTR<END) {
- if(*PTR == '\n') {
+ do {
+ while(PTR<END) {
+ if(*PTR == '\n') {
+ ++PTR;
+ return 0;
+ }
++PTR;
- return 0;
}
- ++PTR;
- }
+ } while(_synctex_fill_buffer_up_to_size(scanner, -1)>0);
return 1;
}
@@ -855,14 +910,19 @@ int _synctex_next_line(synctex_scanner_t scanner) {
* First file separators are skipped
*/
int _synctex_decode_int(synctex_scanner_t scanner, int* valueRef) {
+ unsigned char * ptr;
+ unsigned char * end = NULL;
+ int result = 0;
if(NULL == scanner) return -1;
+ if(END-PTR<=15) {
+ _synctex_fill_buffer_up_to_size(scanner, -1);
+ }
+ ptr = PTR;
if(PTR>=END) return -1;
- unsigned char * ptr = PTR;
if(*ptr==':' || *ptr==',') {
++ptr;
}
- unsigned char * end;
- int result = (int)strtol((char *)ptr, (char **)&end, 10);
+ result = (int)strtol((char *)ptr, (char **)&end, 10);
if(end>ptr) {
PTR = end;
if(valueRef) {
@@ -874,23 +934,58 @@ int _synctex_decode_int(synctex_scanner_t scanner, int* valueRef) {
}
int _synctex_decode_string(synctex_scanner_t scanner, char ** valueRef) {
+ unsigned char * end = PTR;
+ size_t current_size = 0;
+ size_t len = 0;/* The number of bytes to copy */
if(NULL == scanner || NULL == valueRef) return -1;
if(PTR>=END) return -1;
- char * end = (char *)PTR;
- while(end<(char *)END && *end != '\n') {
- ++end;
- }
- size_t len = end - (char *)PTR;
- if(* valueRef = malloc(len+1)) {
- if(memcpy((*valueRef),(synctex_node_t)PTR,len)) {
- (* valueRef)[len]='\0';
+ /* We scan all the characters up to the next '\n'
+ * There is a problem with the buffer. */
+next_character:
+ if(end<END) {
+ if(*end == '\n') {
+ /* OK, we found where to stop */
+ len = end - PTR;
+ if(* valueRef = realloc(* valueRef,current_size+len+1)) {
+ if(memcpy((*valueRef)+current_size,PTR,len)) {
+ current_size += len;/* update the current_size to the new value */
+ (* valueRef)[current_size]='\0'; /* Terminate the string */
+ PTR += len;
+ return SYNCTEX_NOERR;
+ }
+ free(* valueRef);
+ * valueRef = NULL;
+ return -1;
+ }
+ /* Huge memory problem */
PTR += len;
- return 0;
+ return -1;
+ } else {
+ ++end;
+ goto next_character;
}
- free(* valueRef);
- * valueRef = NULL;
+ } else {
+ len = end - PTR;
+ if(* valueRef = realloc(* valueRef,current_size+len+1)) {
+ if(memcpy((*valueRef)+current_size,PTR,len)) {
+ current_size += len;/* update the current_size to the new value */
+ (* valueRef)[current_size]='\0'; /* Terminate the string */
+ PTR += len;
+ if(_synctex_fill_buffer_up_to_size(scanner,-1)>0) {
+ end = PTR;
+ goto next_character;
+ } else {
+ return 0;
+ }
+ }
+ free(* valueRef);
+ * valueRef = NULL;
+ return -1;
+ }
+ /* Huge memory problem */
+ PTR += len;
+ return -1;
}
- return -1;
}
/* Used when parsing the synctex file.
@@ -900,8 +995,7 @@ int _synctex_scan_input(synctex_scanner_t scanner) {
if(NULL == scanner) {
return -1;
}
- if(0 == strncmp((char *)PTR,"Input:",6)) {
- PTR += 6;
+ if(0 == _synctex_scan_string(scanner,"Input:")) {
synctex_node_t input = _synctex_new_input(scanner);
if(_synctex_decode_int(scanner,INFO(input)+TAG)
|| (++PTR,_synctex_decode_string(scanner,(char **)(INFO(input)+NAME)))
@@ -923,52 +1017,47 @@ int _synctex_scan_settings(synctex_scanner_t scanner) {
if(NULL == scanner) {
return -1;
}
- while(strncmp((char *)PTR,"Output:",7)) {
+ while(_synctex_scan_string(scanner,"Output:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 7;
if(_synctex_decode_string(scanner,&(scanner->output))
|| _synctex_next_line(scanner)) {
return -1;
}
- while(strncmp((char *)PTR,"Magnification:",14)) {
+ while(_synctex_scan_string(scanner,"Magnification:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 14;
if(_synctex_decode_int(scanner,(int *)&(scanner->pre_magnification))
|| _synctex_next_line(scanner)) {
return -1;
}
- while(strncmp((char *)PTR,"Unit:",5)) {
+ while(_synctex_scan_string(scanner,"Unit:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 5;
if(_synctex_decode_int(scanner,(int *)&(scanner->pre_unit))
|| _synctex_next_line(scanner)) {
return -1;
}
- while(strncmp((char *)PTR,"X Offset:",9)) {
+ while(_synctex_scan_string(scanner,"X Offset:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 9;
if(_synctex_decode_int(scanner,&(scanner->pre_x_offset))
|| _synctex_next_line(scanner)) {
return -1;
}
- while(strncmp((char *)PTR,"Y Offset:",9)) {
+ while(_synctex_scan_string(scanner,"Y Offset:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 9;
if(_synctex_decode_int(scanner,&(scanner->pre_y_offset))
|| _synctex_next_line(scanner)) {
return -1;
@@ -976,16 +1065,42 @@ int _synctex_scan_settings(synctex_scanner_t scanner) {
return 0;
}
+/* Scan the given string. No 0 length string as argument.
+ */
+int _synctex_scan_string(synctex_scanner_t scanner, const char * the_string) {
+ size_t len = 0;
+ if(NULL == scanner) {
+ return -1;
+ }
+ len = strlen(the_string);
+ if(0 == len) {
+ printf("SyncTeX Error: No string given\n");
+ return -1;
+ }
+ if(_synctex_fill_buffer_up_to_size(scanner,len)<0) {
+ return -1;
+ }
+ if(len>END-PTR) {
+ return -1;
+ }
+ if(strncmp((char *)PTR,the_string,len)) {
+ return -1;
+ }
+ PTR += len;
+ return 0;
+}
+
/* Used when parsing the synctex file.
- * Read the preamplesss.
+ * Read the preamble.
*/
int _synctex_scan_preamble(synctex_scanner_t scanner) {
if(NULL == scanner) {
return -1;
}
- if(strncmp((char *)PTR,"SyncTeX Version:",1)
- || ((PTR+=16),_synctex_decode_int(scanner,&(scanner->version)))
+ if(_synctex_scan_string(scanner,"SyncTeX Version:")
+ || _synctex_decode_int(scanner,&(scanner->version))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Missing version\n");
return -1;
}
while(SYNCTEX_NOERR == _synctex_scan_input(scanner)) {
@@ -996,76 +1111,69 @@ int _synctex_scan_preamble(synctex_scanner_t scanner) {
/* parse the post scriptum */
#include "xlocale.h"
int _synctex_scan_post_scriptum(synctex_scanner_t scanner) {
- while(strncmp((char *)PTR,"Post scriptum:",14)) {
+ int status = 0;
+ while(_synctex_scan_string(scanner,"Post scriptum:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 14;
/* Scanning the information */
/* initialize the offset with a fake value */
scanner->x_offset = 6.027e23;
scanner->y_offset = scanner->x_offset;
- /* By default, C programs start in the "C" locale
- * But we are in a library, so we cannot assume that. */
- locale_t locale = newlocale(LC_ALL_MASK, NULL, NULL);
- int status = 0;
+ /* By default, all "*_l" functions are used with a C locale. */
next_record:
- if(0 == strncmp((char *)PTR,"Magnification:",14)) {
- PTR += 14;
+ if(0 == _synctex_scan_string(scanner,"Magnification:")) {
if(PTR<END) {
- scanner->unit = strtof_l((char *)PTR,(char **)&PTR,locale);
+ scanner->unit = strtof_l((char *)PTR,(char **)&PTR,NULL);
next_line:
status = _synctex_next_line(scanner);
if(status<0) {
- freelocale(locale);
return -1;
} else if(0 == status) {
goto next_record;
}
}
- freelocale(locale);
return 0;
- } else if(0 == strncmp((char *)PTR,"X Offset:",9)) {
- PTR += 9;
+ } else if(0 == _synctex_scan_string(scanner,"X Offset:")) {
if(PTR<END) {
unsigned char * end = NULL;
- float f = strtof_l((char *)PTR,(char **)&end,locale);
+ float f = strtof_l((char *)PTR,(char **)&end,NULL);
if(end>PTR) {
/* scan the x offset */
- //72/72.27/65536*16384+0.5;
+ /* 72/72.27/65536*16384+0.5; */
PTR = end;
- if(strncmp((char *)PTR,"in",2) == 0) {
+ if(_synctex_scan_string(scanner,"in") == 0) {
f *= 72.27*65536;
}
- else if(strncmp((char *)PTR,"cm",2) == 0) {
+ else if(_synctex_scan_string(scanner,"cm") == 0) {
f *= 72.27*65536/2.54;
}
- else if(strncmp((char *)PTR,"mm",2) == 0) {
+ else if(_synctex_scan_string(scanner,"mm") == 0) {
f *= 72.27*65536/25.4;
}
- else if(strncmp((char *)PTR,"pt",2) == 0) {
+ else if(_synctex_scan_string(scanner,"pt") == 0) {
f *= 65536.0;
}
- else if(strncmp((char *)PTR,"bp",2) == 0) {
+ else if(_synctex_scan_string(scanner,"bp") == 0) {
f *= 72.27/72*65536;
}
- else if(strncmp((char *)PTR,"pc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"pc") == 0) {
f *= 12.0*65536;
}
- else if(strncmp((char *)PTR,"sp",2) == 0) {
+ else if(_synctex_scan_string(scanner,"sp") == 0) {
f *= 1.0;
}
- else if(strncmp((char *)PTR,"dd",2) == 0) {
+ else if(_synctex_scan_string(scanner,"dd") == 0) {
f *= 1238.0/1157*65536;
}
- else if(strncmp((char *)PTR,"cc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"cc") == 0) {
f *= 14856.0/1157*65536;
}
- else if(strncmp((char *)PTR,"nd",2) == 0) {
+ else if(_synctex_scan_string(scanner,"nd") == 0) {
f *= 685.0/642*65536;
}
- else if(strncmp((char *)PTR,"nc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"nc") == 0) {
f *= 1370.0/107*65536;
}
else {
@@ -1076,48 +1184,46 @@ next_line:
}
goto next_line;
}
- freelocale(locale);
return 0;
- } else if(0 == strncmp((char *)PTR,"Y Offset:",9)) {
- PTR += 9;
+ } else if(0 == _synctex_scan_string(scanner,"Y Offset:")) {
if(PTR<END) {
unsigned char * end = NULL;
- float f = strtof_l((char *)PTR,(char **)&end,locale);
+ float f = strtof_l((char *)PTR,(char **)&end,NULL);
if(end>PTR) {
/* scan the x offset */
- //72/72.27/65536*16384+0.5;
+ /* 72/72.27/65536*16384+0.5; */
PTR = end;
- if(strncmp((char *)PTR,"in",2) == 0) {
+ if(_synctex_scan_string(scanner,"in") == 0) {
f *= 72.27*65536;
}
- else if(strncmp((char *)PTR,"cm",2) == 0) {
+ else if(_synctex_scan_string(scanner,"cm") == 0) {
f *= 72.27*65536/2.54;
}
- else if(strncmp((char *)PTR,"mm",2) == 0) {
+ else if(_synctex_scan_string(scanner,"mm") == 0) {
f *= 72.27*65536/25.4;
}
- else if(strncmp((char *)PTR,"pt",2) == 0) {
+ else if(_synctex_scan_string(scanner,"pt") == 0) {
f *= 65536.0;
}
- else if(strncmp((char *)PTR,"bp",2) == 0) {
+ else if(_synctex_scan_string(scanner,"bp") == 0) {
f *= 72.27/72*65536;
}
- else if(strncmp((char *)PTR,"pc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"pc") == 0) {
f *= 12.0*65536;
}
- else if(strncmp((char *)PTR,"sp",2) == 0) {
+ else if(_synctex_scan_string(scanner,"sp") == 0) {
f *= 1.0;
}
- else if(strncmp((char *)PTR,"dd",2) == 0) {
+ else if(_synctex_scan_string(scanner,"dd") == 0) {
f *= 1238.0/1157*65536;
}
- else if(strncmp((char *)PTR,"cc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"cc") == 0) {
f *= 14856.0/1157*65536;
}
- else if(strncmp((char *)PTR,"nd",2) == 0) {
+ else if(_synctex_scan_string(scanner,"nd") == 0) {
f *= 685.0/642*65536;
}
- else if(strncmp((char *)PTR,"nc",2) == 0) {
+ else if(_synctex_scan_string(scanner,"nc") == 0) {
f *= 1370.0/107*65536;
}
else {
@@ -1128,7 +1234,6 @@ next_line:
}
goto next_line;
}
- freelocale(locale);
return 0;
}
goto next_line;
@@ -1138,12 +1243,11 @@ int _synctex_scan_postamble(synctex_scanner_t scanner) {
if(NULL == scanner) {
return -1;
}
- if(strncmp((char *)PTR,"Postamble:",10)
- || ((PTR += 10),_synctex_next_line(scanner))) {
+ if(_synctex_scan_string(scanner,"Postamble:")
+ || _synctex_next_line(scanner)) {
return -1;
}
- if(!strncmp((char *)PTR,"Count:",6)) {
- PTR += 6;
+ if(!_synctex_scan_string(scanner,"Count:")) {
if(_synctex_decode_int(scanner,&(scanner->count))
|| _synctex_next_line(scanner)) {
return -1;
@@ -1163,10 +1267,11 @@ int _synctex_scan_postamble(synctex_scanner_t scanner) {
* At creation time, the visible size is set to the values of the real size.
*/
int _synctex_setup_visible_box(synctex_node_t box) {
+ int * info = NULL;
if(NULL == box || box->class->type != synctex_node_type_hbox) {
return -1;
}
- int * info = INFO(box);
+ info = INFO(box);
if(info) {
info[HORIZ_V] = info[HORIZ];
info[VERT_V] = info[VERT];
@@ -1183,11 +1288,12 @@ int _synctex_setup_visible_box(synctex_node_t box) {
* With this method, one can enlarge the box to contain the given point (h,v).
*/
int _synctex_horiz_box_setup_visible(synctex_node_t node,int h, int v) {
+ int * itsINFO = NULL;
+ int itsBtm, itsTop;
if(NULL == node || node->class->type != synctex_node_type_hbox) {
return -1;
}
- int * itsINFO = INFO(node);
- int itsBtm, itsTop;
+ itsINFO = INFO(node);
if(itsINFO[WIDTH_V]<0) {
itsBtm = itsINFO[HORIZ_V]+itsINFO[WIDTH_V];
itsTop = itsINFO[HORIZ_V];
@@ -1216,18 +1322,21 @@ int _synctex_horiz_box_setup_visible(synctex_node_t node,int h, int v) {
return 0;
}
+int synctex_bail(void);
+
/* Used when parsing the synctex file.
* The parent is a newly created sheet node that will hold the contents.
* Something is returned in case of error.
*/
int _synctex_scan_sheet(synctex_scanner_t scanner, synctex_node_t parent) {
- if((NULL == scanner) || (NULL == parent))return -1;
synctex_node_t child = NULL;
synctex_node_t sibling = NULL;
int friend_index = 0;
int * info = NULL;
int curh, curv;
+ if((NULL == scanner) || (NULL == parent))return -1;
vertical_loop:
+// printf("H loop:%i\n",++loop);
if(PTR<END) {
if(*PTR == '[') {
++PTR;
@@ -1240,6 +1349,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad vbox record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1247,6 +1357,7 @@ vertical_loop:
child = NULL;
goto vertical_loop;
} else {
+ printf("SyncTeX Error: Can't create vbox record.\n");
return -1;
}
} else if(*PTR == ']') {
@@ -1263,9 +1374,10 @@ vertical_loop:
child = parent;
parent = PARENT(child);
} else {
- printf("Unexpected ]\n");
+ printf("SyncTeX Error: Unexpected ']', ignored.\n");
}
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Uncomplete sheet.\n");
return -1;
}
goto horizontal_loop;
@@ -1281,6 +1393,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_setup_visible_box(child)
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad hbox record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1288,6 +1401,7 @@ vertical_loop:
child = NULL;
goto vertical_loop;
} else {
+ printf("SyncTeX Error: Can't create hbox record.\n");
return -1;
}
} else if(*PTR == ')') {
@@ -1299,9 +1413,10 @@ vertical_loop:
child = parent;
parent = PARENT(child);
} else {
- printf("Unexpected )\n");
+ printf("SyncTeX Error: Unexpected ')', ignored.\n");
}
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Uncomplete sheet.\n");
return -1;
}
goto horizontal_loop;
@@ -1316,6 +1431,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad void vbox record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1326,6 +1442,7 @@ vertical_loop:
UPDATE_FRIEND(child);
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create vbox record.\n");
return -1;
}
} else if(*PTR == 'h') {
@@ -1339,6 +1456,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad void hbox record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1347,6 +1465,7 @@ vertical_loop:
_synctex_horiz_box_setup_visible(parent,synctex_node_h(child)+synctex_node_width(child),synctex_node_v(child));
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create void hbox record.\n");
return -1;
}
} else if(*PTR == 'k') {
@@ -1358,6 +1477,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_decode_int(scanner,(int*)(info+WIDTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad kern record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1370,6 +1490,7 @@ vertical_loop:
}
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create kern record.\n");
return -1;
}
} else if(*PTR == 'x') {
@@ -1379,6 +1500,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,&curh)
|| _synctex_decode_int(scanner,&curv)
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad x record.\n");
return -1;
}
_synctex_horiz_box_setup_visible(parent,curh,curv);
@@ -1391,6 +1513,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+HORIZ))
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad glue record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1398,6 +1521,7 @@ vertical_loop:
UPDATE_FRIEND(child);
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create glue record.\n");
return -1;
}
} else if(*PTR == '$') {
@@ -1408,6 +1532,7 @@ vertical_loop:
|| _synctex_decode_int(scanner,(int*)(info+HORIZ))
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad math record.\n");
return -1;
}
SET_CHILD(parent,child);
@@ -1415,34 +1540,42 @@ vertical_loop:
UPDATE_FRIEND(child);
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create math record.\n");
return -1;
}
} else if(*PTR == '}') {
++PTR;
if(!parent || parent->class->type != synctex_node_type_sheet
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Unexpected end of sheet.\n");
return -1;
}
return 0;
} else if(*PTR == '!') {
++PTR;
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Missing anchor.\n");
return -1;
}
goto vertical_loop;
} else {
- printf("Ignored:<%c>\n",*PTR);
+ printf("SyncTeX Error: Ignored record %c\n",*PTR);
++PTR;
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Unexpected end.\n");
return -1;
}
goto vertical_loop;
}
+ } else if(_synctex_fill_buffer_up_to_size(scanner,-1)>0){
+ goto vertical_loop;
} else {
+ printf("SyncTeX Error: Uncomplete sheet(0)\n");
return -1;
}
synctex_bail();
horizontal_loop:
+// printf("V loop:%i\n",++loop);
if(PTR<END) {
if(*PTR == '[') {
++PTR;
@@ -1455,6 +1588,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad vbox record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1462,6 +1596,7 @@ horizontal_loop:
child = NULL;
goto vertical_loop;
} else {
+ printf("SyncTeX Error: Can't create vbox record (2).\n");
return -1;
}
} else if(*PTR == ']') {
@@ -1473,9 +1608,10 @@ horizontal_loop:
child = parent;
parent = PARENT(child);
} else {
- printf("Unexpected ]\n");
+ printf("SyncTeX Error: Unexpected end of vbox record (2), ignored.\n");
}
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Unexpected end of file (2).\n");
return -1;
}
goto horizontal_loop;
@@ -1491,6 +1627,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_setup_visible_box(sibling)
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad hbox record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1498,6 +1635,7 @@ horizontal_loop:
child = NULL;
goto vertical_loop;
} else {
+ printf("SyncTeX Error: Can't create hbox record (2).\n");
return -1;
}
} else if(*PTR == ')') {
@@ -1509,10 +1647,10 @@ horizontal_loop:
child = parent;
parent = PARENT(child);
} else {
- printf("Unexpected )\n");
+ printf("SyncTeX Error: Unexpected end of hbox record (2).\n");
}
if(_synctex_next_line(scanner)) {
- LOG(child);
+ printf("SyncTeX Error: Unexpected end of file (2,')').\n");
return -1;
}
goto horizontal_loop;
@@ -1527,6 +1665,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad void vbox record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1534,6 +1673,7 @@ horizontal_loop:
child = sibling;
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: can't create void vbox record (2).\n");
return -1;
}
} else if(*PTR == 'h') {
@@ -1547,6 +1687,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+HEIGHT))
|| _synctex_decode_int(scanner,(int*)(info+DEPTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad void hbox record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1556,6 +1697,7 @@ horizontal_loop:
_synctex_horiz_box_setup_visible(parent,synctex_node_h(child)+synctex_node_width(child),synctex_node_v(child));
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: can't create void hbox record (2).\n");
return -1;
}
} else if(*PTR == 'x') {
@@ -1565,6 +1707,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,&curh)
|| _synctex_decode_int(scanner,&curv)
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad x record (2).\n");
return -1;
}
_synctex_horiz_box_setup_visible(parent,curh,curv);
@@ -1578,6 +1721,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_decode_int(scanner,(int*)(info+WIDTH))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad kern record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1586,6 +1730,7 @@ horizontal_loop:
_synctex_horiz_box_setup_visible(parent,synctex_node_h(child),synctex_node_v(child));
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create kern record (2).\n");
return -1;
}
} else if(*PTR == 'g') {
@@ -1596,6 +1741,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+HORIZ))
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad glue record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1604,6 +1750,7 @@ horizontal_loop:
_synctex_horiz_box_setup_visible(parent,synctex_node_h(child),synctex_node_v(child));
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create glue record (2).\n");
return -1;
}
} else if(*PTR == '$') {
@@ -1614,6 +1761,7 @@ horizontal_loop:
|| _synctex_decode_int(scanner,(int*)(info+HORIZ))
|| _synctex_decode_int(scanner,(int*)(info+VERT))
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Bad math record (2).\n");
return -1;
}
SET_SIBLING(child,sibling);
@@ -1622,29 +1770,35 @@ horizontal_loop:
child = sibling;
goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Can't create math record (2).\n");
return -1;
}
} else if(*PTR == '}') {
++PTR;
if(!parent || parent->class->type != synctex_node_type_sheet
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Unexpected end of vbox (2).\n");
return -1;
}
return 0;
} else if(*PTR == '!') {
++PTR;
if(_synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Missing anchor (2).\n");
return -1;
}
goto horizontal_loop;
} else {
- printf("SyncTeX: Ignored record %c\n",*PTR);
+ printf("SyncTeX Error: Ignored record %c(2)\n",*PTR);
if(_synctex_next_line(scanner)) {
return -1;
}
goto horizontal_loop;
}
+ } else if(_synctex_fill_buffer_up_to_size(scanner,-1)>0){
+ goto horizontal_loop;
} else {
+ printf("SyncTeX Error: Uncomplete sheet(2)\n");
return -1;
}
}
@@ -1652,6 +1806,7 @@ horizontal_loop:
/* Used when parsing the synctex file
*/
int _synctex_scan_content(synctex_scanner_t scanner) {
+ synctex_node_t sheet = NULL;
if(NULL == scanner) {
return -1;
}
@@ -1660,24 +1815,25 @@ int _synctex_scan_content(synctex_scanner_t scanner) {
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) {
- printf("malloc:2\n");
+ printf("SyncTeX Error: malloc:2\n");
return -1;
}
}
/* Find where this section starts */
- while(strncmp((char *)PTR,"Content:",8)) {
+ while(_synctex_scan_string(scanner,"Content:")) {
if(_synctex_next_line(scanner)) {
return -1;
}
}
- PTR += 8;
if(_synctex_next_line(scanner)) {
+printf("SyncTeX Error: Uncomplete file.\n");
return -1;
}
next_sheet:
if(*PTR != '{') {
if(_synctex_scan_postamble(scanner)) {
if(_synctex_next_line(scanner)) {
+printf("SyncTeX Error: Uncomplete sheet.\n");
return -1;
}
goto next_sheet;
@@ -1686,14 +1842,16 @@ next_sheet:
}
++PTR;
/* Create a new sheet node */
- synctex_node_t sheet = _synctex_new_sheet(scanner);
+ sheet = _synctex_new_sheet(scanner);
if(_synctex_decode_int(scanner,INFO(sheet)+PAGE)
|| _synctex_next_line(scanner)) {
+ printf("SyncTeX Error: Missing sheet number.\n");
bail:
FREE(sheet);
return -1;
}
if(_synctex_scan_sheet(scanner,sheet)) {
+ printf("SyncTeX Error: Bad sheet content.\n");
goto bail;
}
SET_SIBLING(sheet,scanner->sheet);
@@ -1704,9 +1862,10 @@ bail:
}
/* Where the synctex scanner is created.
- * name is the full path of the synctex file. */
+ * name is the full path of the uncompressed synctex file. */
synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name) {
synctex_scanner_t scanner = (synctex_scanner_t)_synctex_malloc(sizeof(_synctex_scanner_t));
+ int size = 0;
if(NULL == scanner) {
return NULL;
}
@@ -1731,42 +1890,41 @@ synctex_scanner_t synctex_scanner_new_with_contents_of_file(const char * name) {
(scanner->class[synctex_node_type_math]).scanner = scanner;
scanner->class[synctex_node_type_input] = synctex_class_input;
(scanner->class[synctex_node_type_input]).scanner = scanner;
-
- FILE * F = fopen(name,"r");
+ F = gzopen(name,"r");
if(NULL == F) {
printf("SyncTeX: could not open %s, error %i\n",name,errno);
bail:
synctex_scanner_free(scanner);
return NULL;
}
- if(fseek(F, 0, SEEK_END)) {
- close(F);
- goto bail;
- }
- size_t size = ftell(F);
- rewind(F);
- START = (unsigned char *)malloc(size+1);
+ START = (unsigned char *)malloc(SYNCTEX_BUF_SIZE+1);
if(NULL == START) {
- printf("malloc error\n");
- close(F);
+ printf("SyncTeX: malloc error\n");
+ gzclose(F);
goto bail;
}
- if(size != fread((void *)START, 1, size, F)) {
+ START[SYNCTEX_BUF_SIZE] = '\0';
+ PTR = START;
+ END = START+SYNCTEX_BUF_SIZE;
+ size = gzread(F,(void *)START, SYNCTEX_BUF_SIZE);
+ if(!size) {
+ printf("SyncTeX: No gzread content\n");
bailey:
- close(F);
+ gzclose(F);
goto bail;
}
- close(F);
- START[size] = '\0'; /* ensure null termination */
- /* first read the beginning */
- END = START + size;
- PTR = START;
- if(_synctex_scan_preamble(scanner)
- || _synctex_scan_content(scanner)) {
+ if(_synctex_scan_preamble(scanner)) {
+ printf("SyncTeX: Bad preamble\n");
+ goto bailey;
+ }
+ if(_synctex_scan_content(scanner)) {
+ printf("SyncTeX: Bad content\n");
goto bailey;
}
free((void *)START);
START = PTR = END = NULL;
+ gzclose(F);
+ F = NULL;
/* Everything is finished, final tuning */
/* 1 pre_unit = (scanner->pre_unit)/65536 pt = (scanner->pre_unit)/65781.76 bp
* 1 pt = 65536 sp */
@@ -1794,6 +1952,7 @@ bailey:
scanner->y_offset /= 65781.76;
}
return scanner;
+ #undef F
}
/* The scanner destructor
@@ -1863,22 +2022,24 @@ 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) {
return "";
}
- synctex_node_t input = scanner->input;
+ input = scanner->input;
do {
if(tag == INFO(input)[TAG]) {
return (char *)(INFO(input)[NAME]);
}
} while(input = SIBLING(input));
- return 0;
+ return NULL;
}
int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name) {
+ synctex_node_t input = NULL;
if(NULL == scanner) {
return 0;
}
- synctex_node_t input = scanner->input;
+ input = scanner->input;
do {
if((strlen(name) == strlen((char *)(INFO(input)[NAME]))) &&
(0 == strncmp(name,(char *)(INFO(input)[NAME]),strlen(name)))) {
@@ -2107,10 +2268,11 @@ result:
#pragma mark -
#pragma mark Other public node attributes
int synctex_node_page(synctex_node_t node){
+ synctex_node_t parent = NULL;
if(!node) {
return -1;
}
- synctex_node_t parent = PARENT(node);
+ parent = PARENT(node);
while(parent) {
node = parent;
parent = PARENT(node);
@@ -2147,15 +2309,17 @@ synctex_node_t synctex_sheet_content(synctex_scanner_t scanner,int page) {
int synctex_display_query(synctex_scanner_t scanner,const char * name,int line,int column) {
int tag = synctex_scanner_get_tag(scanner,name);
+ size_t size = 0;
+ int friend_index = 0;
+ synctex_node_t node = NULL;
if(tag == 0) {
printf("No tag for %s\n",name);
return -1;
}
free(START);
PTR = END = START = NULL;
- size_t size = 0;
- int friend_index = (tag+line)%(scanner->number_of_lists);
- synctex_node_t node = (scanner->lists_of_friends)[friend_index];
+ friend_index = (tag+line)%(scanner->number_of_lists);
+ node = (scanner->lists_of_friends)[friend_index];
while(node) {
if((tag == INFO(node)[TAG]) && (line == INFO(node)[LINE])) {
if(PTR == END) {
@@ -2204,12 +2368,19 @@ int _synctex_point_in_visible_box(float h, float v, synctex_node_t node) {
}
int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v) {
+ synctex_node_t sheet = NULL;
+ synctex_node_t * start = NULL;
+ synctex_node_t * end = NULL;
+ synctex_node_t * ptr = NULL;
+ size_t size = 0;
+ synctex_node_t node = NULL;
+ synctex_node_t next = NULL;
if(NULL == scanner) {
return 0;
}
free(START);
START = END = PTR = NULL;
- synctex_node_t sheet = scanner->sheet;
+ sheet = scanner->sheet;
while(INFO(sheet)[PAGE] != page) {
sheet = SIBLING(sheet);
}
@@ -2218,12 +2389,7 @@ int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v) {
}
/* Now sheet points to the sheet node with proper page number */
/* Declare memory storage, a buffer to hold found nodes */
- synctex_node_t * start = NULL;
- synctex_node_t * end = NULL;
- synctex_node_t * ptr = NULL;
- size_t size = 0;
- synctex_node_t node = CHILD(sheet); /* start with the child of the sheet */
- synctex_node_t next;
+ node = CHILD(sheet); /* start with the child of the sheet */
has_node_any_child:
if(next = CHILD(node)) {
/* node is a non void box */
@@ -2278,14 +2444,17 @@ next_sibling:
}
/* This is the last node at this level
* The next step is the parent's sibling */
- next = PARENT(node);
- if(ptr && *ptr == next) {
- /* No included box does contain the point
- * next was already tagged to contain the hit point
- * but was not fully registered at that time, now we can increment ptr */
- ++ptr;
- *ptr = NULL;
- } else if(next == sheet) {
+ next = PARENT(node);
+ if(ptr && *ptr == next) {
+ /* No included box does contain the point
+ * next was already tagged to contain the hit point
+ * but was not fully registered at that time, now we can increment ptr */
+ ++ptr;
+ *ptr = NULL;
+ } else if(next == sheet) {
+ float best;
+ float candidate;
+ synctex_node_t * best_node_ref = NULL;
we_are_done:
end = ptr;
ptr = NULL;
@@ -2298,9 +2467,7 @@ we_are_done:
* This is in general the expected box in LaTeX picture environment. */
ptr = start;
node = *ptr;
- float best = synctex_node_box_visible_width(node);
- float candidate;
- synctex_node_t * best_node_ref = NULL;
+ best = synctex_node_box_visible_width(node);
while(node = *(++ptr)) {
candidate = synctex_node_box_visible_width(node);
if(candidate<best) {
@@ -2317,8 +2484,8 @@ we_are_done:
* Working with boxes is not very accurate because in general boxes are created asynchronously.
* The glue, kern, math are more appropriate for synchronization. */
if(node = CHILD(*start)) {
- best = INFINITY;
synctex_node_t best_node = NULL;
+ best = INFINITY;
do {
switch((node->class)->type) {
default:
@@ -2375,9 +2542,25 @@ int synctex_bail(void) {
#pragma mark -
#pragma mark TESTS
/* This is not public, it is not up to date */
+int _synctex_scan_next_line_header(synctex_scanner_t scanner, unsigned char * valueRef) {
+ if(NULL == scanner || NULL == valueRef) return -1;
+ /* read until the next '\0' byte, return the following one */
+ while(PTR<END) {
+ if(*PTR=='\0') {
+ if(++PTR<END) {
+ *valueRef = *(PTR++);
+ return 0;
+ }
+ } else {
+ ++PTR;
+ }
+ }
+ return -1;
+}
synctex_scanner_t synctex_scanner_new_with_data(const void * bytes, unsigned int length) {
synctex_scanner_t scanner = (synctex_scanner_t)_synctex_malloc(sizeof(_synctex_scanner_t));
if(NULL != scanner) {
+ unsigned char the_char;
START = (void *)bytes;
if(UINT_MAX-length<(int)(START)) {
bail:
@@ -2387,7 +2570,6 @@ bail:
END = START+length;
scanner->pre_unit = 8192;
scanner->pre_x_offset = scanner->pre_y_offset = 578;
- unsigned char the_char;
if(_synctex_scan_preamble(scanner)) {
goto bail;
}
@@ -2403,21 +2585,6 @@ bail:
return scanner;
}
-int _synctex_scan_next_line_header(synctex_scanner_t scanner, unsigned char * valueRef) {
- if(NULL == scanner || NULL == valueRef) return -1;
- /* read until the next '\0' byte, return the following one */
- while(PTR<END) {
- if(*PTR=='\0') {
- if(++PTR<END) {
- *valueRef = *(PTR++);
- return 0;
- }
- } else {
- ++PTR;
- }
- }
- return -1;
-}
int synctex_jump(synctex_scanner_t scanner)
{
unsigned char the_char;
@@ -2467,136 +2634,3 @@ next:
}
return 0;
}
-int synctex_test(void) {
- printf("sizeof(synctex_sheet_t):%i\n",sizeof(synctex_sheet_t));
- printf("sizeof(synctex_vert_box_node_t):%i\n",sizeof(synctex_vert_box_node_t));
- printf("sizeof(synctex_horiz_box_node_t):%i\n",sizeof(synctex_horiz_box_node_t));
- printf("sizeof(synctex_void_box_node_t):%i\n",sizeof(synctex_void_box_node_t));
- printf("sizeof(synctex_medium_node_t):%i\n",sizeof(synctex_medium_node_t));
- /* TESTING */
- synctex_node_t node;
- synctex_node_t child;
- synctex_node_t next;
- #define TEST(LABEL,constructor)\
- printf("TESTING constructor:%s\n",LABEL);\
- node = constructor(NULL);\
- LOG(node);\
- FREE(node);
- TEST(("_synctex_new_sheet"),_synctex_new_sheet);
- TEST(("_synctex_new_vbox"),_synctex_new_vbox);
- TEST(("_synctex_new_hbox"),_synctex_new_hbox);
- TEST(("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST(("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST(("_synctex_new_math"),_synctex_new_math);
- TEST(("_synctex_new_kern"),_synctex_new_kern);
- TEST(("_synctex_new_glue"),_synctex_new_glue);
- printf("...... ALL constructor tested\n\n\n\n");
- #undef TEST
- #define TEST(PARENT_LABEL,PARENT_CONSTRUCTOR,CHILD_LABEL,CHILD_CONSTRUCTOR)\
- printf("TESTING parent:%s -> child:%s\n",PARENT_LABEL,CHILD_LABEL);\
- node = PARENT_CONSTRUCTOR(NULL);\
- child = CHILD_CONSTRUCTOR(NULL);\
- DISPLAY(node);\
- DISPLAY(child);\
- SET_CHILD(node,child);\
- DISPLAY(node);\
- DISPLAY(child);\
- if((CHILD(node) != child) || (node != PARENT(child))) {\
- return synctex_bail();\
- }\
- FREE(node);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_sheet",_synctex_new_sheet,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_glue"),_synctex_new_glue);
-// TEST("_synctex_new_sheet","",_synctex_new_sheet,);
-// TEST("","",,);
- #undef TEST
- #define TEST(CHILD_LABEL,CHILD_CONSTRUCTOR,SIBLING_LABEL,SIBLING_CONSTRUCTOR)\
- printf("TESTING child:%s -> next:%s\n",CHILD_LABEL,SIBLING_LABEL);\
- node = _synctex_new_sheet(NULL);\
- child = CHILD_CONSTRUCTOR(NULL);\
- next = SIBLING_CONSTRUCTOR(NULL);\
- DISPLAY(node);\
- DISPLAY(child);\
- DISPLAY(next);\
- SET_CHILD(node,child);\
- SET_SIBLING(child,next);\
- DISPLAY(node);\
- DISPLAY(child);\
- DISPLAY(next);\
- if((SIBLING(child) != next) || (node != PARENT(next))) {\
- return synctex_bail();\
- }\
- FREE(node);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_vbox",_synctex_new_vbox,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_hbox",_synctex_new_hbox,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_void_vbox",_synctex_new_void_vbox,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_void_hbox",_synctex_new_void_hbox,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_math",_synctex_new_math,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_kern",_synctex_new_kern,("_synctex_new_glue"),_synctex_new_glue);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_vbox"),_synctex_new_vbox);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_hbox"),_synctex_new_hbox);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_void_vbox"),_synctex_new_void_vbox);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_void_hbox"),_synctex_new_void_hbox);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_math"),_synctex_new_math);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_kern"),_synctex_new_kern);
- TEST("_synctex_new_glue",_synctex_new_glue,("_synctex_new_glue"),_synctex_new_glue);
-
- return 0;
-
-}
-
diff --git a/Build/source/texk/web2c/synctex/synctex_parser.h b/Build/source/texk/web2c/synctex/synctex_parser.h
index e0bce6523a6..02804f3a4d4 100644
--- a/Build/source/texk/web2c/synctex/synctex_parser.h
+++ b/Build/source/texk/web2c/synctex/synctex_parser.h
@@ -45,6 +45,10 @@ typedef struct _synctex_node * synctex_node_t;
typedef struct __synctex_scanner_t _synctex_scanner_t;
typedef _synctex_scanner_t * synctex_scanner_t;
+#ifdef __cplusplus
+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.
@@ -211,4 +215,8 @@ 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);
-#endif \ No newline at end of file
+#ifdef __cplusplus
+};
+#endif
+
+#endif