+/* Here are the control characters that strat each line of the synctex output file.
+ * Their values define the meaning of the line.
+ */
+# define SYNCTEX_CHAR_BEGIN_SHEET '{'
+# define SYNCTEX_CHAR_END_SHEET '}'
+# define SYNCTEX_CHAR_BEGIN_VBOX '['
+# define SYNCTEX_CHAR_END_VBOX ']'
+# define SYNCTEX_CHAR_BEGIN_HBOX '('
+# define SYNCTEX_CHAR_END_HBOX ')'
+# define SYNCTEX_CHAR_ANCHOR '!'
+# define SYNCTEX_CHAR_VOID_VBOX 'v'
+# define SYNCTEX_CHAR_VOID_HBOX 'h'
+# define SYNCTEX_CHAR_KERN 'k'
+# define SYNCTEX_CHAR_GLUE 'g'
+# define SYNCTEX_CHAR_MATH '$'
+# define SYNCTEX_CHAR_BOUNDARY 'x'
+
+# define SYNCTEX_RETURN(STATUS) return STATUS;
+
+/* Used when parsing the synctex file. A '{' character has just been parsed.
+ * The purpose is to gobble everything until the closing '}'.
+ * Actually only one nesting depth has been observed when using the clip option
+ * of \includegraphics option. Here we use arbitrary level of depth.
+ */
+synctex_status_t _synctex_scan_nested_sheet(synctex_scanner_t scanner) {
+ unsigned int depth = 0;
+deeper:
+ ++depth;
+ if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
+ _synctex_error("Unexpected end of nested sheet (1).");
+ SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
+ }
+scan_next_line:
+ if (SYNCTEX_CUR<SYNCTEX_END) {
+ if (*SYNCTEX_CUR == SYNCTEX_CHAR_END_SHEET) {
+ ++SYNCTEX_CUR;
+ if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
+ _synctex_error("Unexpected end of nested sheet (2).");
+ SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
+ }
+ if (--depth>0) {
+ goto scan_next_line;
+ } else {
+ SYNCTEX_RETURN(SYNCTEX_STATUS_OK);
+ }
+ } else if (*SYNCTEX_CUR == SYNCTEX_CHAR_BEGIN_SHEET) {
+ ++SYNCTEX_CUR;
+ goto deeper;
+
+ } else if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
+ _synctex_error("Unexpected end of nested sheet (3).");
+ SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
+ }
+ }
+ _synctex_error("Unexpected end of nested sheet (4).");
+ SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
+}
+