-
Notifications
You must be signed in to change notification settings - Fork 19
/
synctex_parser.c
9828 lines (9409 loc) · 356 KB
/
synctex_parser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2008-2024 jerome DOT laurens AT u-bourgogne DOT fr
This file is part of the __SyncTeX__ package.
Version: see synctex_version.h
Latest Revision: Thu Mar 21 14:12:58 UTC 2024
See `synctex_parser_readme.md` for more details
## License
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE
Except as contained in this notice, the name of the copyright holder
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization from the copyright holder.
Acknowledgments:
----------------
The author received useful remarks from the pdfTeX developers, especially Hahn The Thanh,
and significant help from XeTeX developer Jonathan Kew
Nota Bene:
----------
If you include or use a significant part of the synctex package into a software,
I would appreciate to be listed as contributor and see "SyncTeX" highlighted.
*/
/* We assume that high level application like pdf viewers will want
* to embed this code as is. We assume that they also have locale.h and setlocale.
* For other tools such as TeXLive tools, you must define SYNCTEX_USE_LOCAL_HEADER,
* when building. You also have to create and customize synctex_parser_local.h to fit your system.
* In particular, the HAVE_LOCALE_H and HAVE_SETLOCALE macros should be properly defined.
* With this design, you should not need to edit this file. */
/**
* @file synctex_parser.c
* @brief SyncTeX file parser and controller.
* @author: Jérôme LAURENS
* @version 1.22
* @date Tue Mar 5 21:16:33 UTC 2024
*
* Reads and parse *.synctex[.gz] files,
* performs edit and display queries.
*
* See
* - synctex_scanner_new_with_output_file
* - synctex_scanner_parse
* - synctex_scanner_free
* - synctex_display_query
* - synctex_edit_query
* - synctex_scanner_next_result
* - synctex_scanner_reset_result
*
* The data is organized in a graph with multiple entries.
* The root object is a scanner, it is created with the contents on a synctex file.
* Each node of the tree is a private `_synctex_node_t` object.
* There are 3 subtrees, two of them sharing the same leaves.
* The first tree is the list of input records, where input file names are associated with tags.
* The second tree is the box tree as given by TeX when shipping pages out.
* First level objects are sheets and forms, containing boxes, glues, kerns...
* The third tree allows to browse leaves according to tag and line.
*/
/* Declare _GNU_SOURCE for accessing vasprintf. For MSC compiler, vasprintf is
* defined in this file
*/
/** @cond */
#define _GNU_SOURCE
# if defined(SYNCTEX_USE_LOCAL_HEADER)
# include "synctex_parser_local.h"
# else
# define HAVE_LOCALE_H 1
# define HAVE_SETLOCALE 1
# if defined(_MSC_VER)
# define SYNCTEX_INLINE __inline
# else
# define SYNCTEX_INLINE inline
# endif
# endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#if defined(HAVE_LOCALE_H)
#include <locale.h>
#endif
/* Mark unused parameters, so that there will be no compile warnings. */
#ifdef __DARWIN_UNIX03
# define SYNCTEX_UNUSED(x) SYNCTEX_PRAGMA(unused(x))
# define SYNCTEX_PRAGMA(x) _Pragma ( #x )
#else
# define SYNCTEX_UNUSED(x) (void)(x);
#endif
#include "synctex_parser_advanced.h"
SYNCTEX_INLINE static int _synctex_abs(int x) {
return x>0? x: -x;
}
/** @endcond */
/* These are the possible extensions of the synctex file */
/**
* @brief Extension of uncompressed synctex file
*/
const char * synctex_suffix = ".synctex";
/**
* @brief Extension of compressed synctex file
*/
const char * synctex_suffix_gz = ".gz";
/** @cond */
typedef synctex_node_p(*_synctex_node_new_f)(synctex_scanner_p);
typedef void(*_synctex_node_fld_f)(synctex_node_p);
typedef char *(*_synctex_node_str_f)(synctex_node_p);
/**
* @brief A tree model structure
* @author: Jérôme LAURENS
*
* 8 fields + size: `spcflnat` referring to the first letters of each field.
*/
typedef struct synctex_tree_model_t {
/** A sibling node, if any */
int sibling;
/** The parent node, if any */
int parent;
/** The first child node, if any */
int child;
/** The first friend node, if any */
int friend;
/** The last node, if any */
int last;
/** The next hbox node, if any */
int next_hbox;
/** Undocumented */
int arg_sibling;
/** Undocumented */
int target;
/** Undocumented */
int size;
} _synctex_tree_model_s;
/**
* @brief A pointer to a constant tree model structure
* @author: Jérôme LAURENS
*/
typedef const _synctex_tree_model_s * _synctex_tree_model_p;
typedef struct _synctex_data_model_t {
int tag;
int line;
int column;
int h;
int v;
int width;
int height;
int depth;
int mean_line;
int weight;
int h_V;
int v_V;
int width_V;
int height_V;
int depth_V;
int name;
int page;
int size;
} _synctex_data_model_s;
/**
* @brief A pointer to a constant data model structure
* @author: Jérôme LAURENS
*/
typedef const _synctex_data_model_s * _synctex_data_model_p;
/**
* @brief node -> integer function type
* @author: Jérôme LAURENS
*
*/
typedef int (*_synctex_int_getter_f)(synctex_node_p);
/**
* @brief tlc inspector structure
*
*/
typedef struct _synctex_tlcpector_t {
/** tag getter */
_synctex_int_getter_f tag;
/** line getter */
_synctex_int_getter_f line;
/** column getter */
_synctex_int_getter_f column;
} _synctex_tlcpector_s;
typedef const _synctex_tlcpector_s * _synctex_tlcpector_p;
static int _synctex_int_none(synctex_node_p node) {
SYNCTEX_UNUSED(node)
return 0;
}
static const _synctex_tlcpector_s synctex_tlcpector_none = {
&_synctex_int_none, /* tag */
&_synctex_int_none, /* line */
&_synctex_int_none, /* column */
};
/**
* @brief Geometry inspector structure
*
*/
typedef struct _synctex_inspector_t {
/** h getter */
_synctex_int_getter_f h;
/** v getter */
_synctex_int_getter_f v;
/** width getter */
_synctex_int_getter_f width;
/** height getter */
_synctex_int_getter_f height;
/** depth getter */
_synctex_int_getter_f depth;
} _synctex_inspector_s;
typedef const _synctex_inspector_s * _synctex_inspector_p;
static const _synctex_inspector_s synctex_inspector_none = {
&_synctex_int_none, /* h */
&_synctex_int_none, /* v */
&_synctex_int_none, /* width */
&_synctex_int_none, /* height */
&_synctex_int_none, /* depth */
};
typedef float (*_synctex_float_getter_f)(synctex_node_p);
/**
* @brief vi inspector data structure.
*
*/
typedef struct _synctex_vispector_t {
/** h attribute getter */
_synctex_float_getter_f h;
/** v attribute getter */
_synctex_float_getter_f v;
/** width attribute getter */
_synctex_float_getter_f width;
/** height attribute getter */
_synctex_float_getter_f height;
/** depth attribute getter */
_synctex_float_getter_f depth;
} _synctex_vispector_s;
static float _synctex_float_none(synctex_node_p node) {
SYNCTEX_UNUSED(node)
return 0;
}
static const _synctex_vispector_s synctex_vispector_none = {
&_synctex_float_none, /* h */
&_synctex_float_none, /* v */
&_synctex_float_none, /* width */
&_synctex_float_none, /* height */
&_synctex_float_none, /* depth */
};
typedef const _synctex_vispector_s * _synctex_vispector_p;
struct _synctex_class_t {
synctex_scanner_p scanner;
synctex_node_type_t type;
_synctex_node_new_f new;
_synctex_node_fld_f free;
_synctex_node_fld_f log;
_synctex_node_fld_f display;
_synctex_node_str_f abstract;
_synctex_tree_model_p navigator;
_synctex_data_model_p modelator;
_synctex_tlcpector_p tlcpector;
_synctex_inspector_p inspector;
_synctex_vispector_p vispector;
};
/**
* Nota bene: naming convention.
* For static API, when the name contains "proxy", it applies to proxies.
* When the name contains "noxy", it applies to non proxies only.
* When the name contains "node", well it depends...
*/
typedef synctex_node_p _synctex_proxy_p;
typedef synctex_node_p _synctex_noxy_p;
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Abstract OBJECTS and METHODS
# endif
/**
* @def SYNCTEX_MSG_SEND
* @brief Takes care of sending the given message if possible.
* - parameter NODE: of type synctex_node_p
* - parameter SELECTOR: one of the class_ pointer properties
*/
# define SYNCTEX_MSG_SEND(NODE,SELECTOR) do {\
synctex_node_p N__ = NODE;\
if (N__ && N__->class_->SELECTOR) {\
(*(N__->class_->SELECTOR))(N__);\
}\
} while (synctex_NO)
/**
* Free the given node by sending the free message.
* - parameter NODE: of type synctex_node_p
*/
static void _synctex_node_free(synctex_node_p node) {
SYNCTEX_MSG_SEND(node,free);
}
# if defined(SYNCTEX_TESTING)
# if !defined(SYNCTEX_USE_HANDLE)
# define SYNCTEX_USE_HANDLE 1
# endif
# if !defined(SYNCTEX_USE_CHARINDEX)
# define SYNCTEX_USE_CHARINDEX 1
# endif
# endif
SYNCTEX_INLINE static synctex_node_p _synctex_new_handle_with_target(synctex_node_p target);
# if defined(SYNCTEX_USE_HANDLE)
# define SYNCTEX_SCANNER_FREE_HANDLE(SCANR) \
__synctex_scanner_free_handle(SCANR)
# define SYNCTEX_SCANNER_REMOVE_HANDLE_TO(WHAT) \
__synctex_scanner_remove_handle_to(WHAT)
# define SYNCTEX_REGISTER_HANDLE_TO(NODE) \
__synctex_scanner_register_handle_to(NODE)
# else
# define SYNCTEX_SCANNER_FREE_HANDLE(SCANR)
# define SYNCTEX_SCANNER_REMOVE_HANDLE_TO(WHAT)
# define SYNCTEX_REGISTER_HANDLE_TO(NODE)
# endif
# if defined(SYNCTEX_USE_CHARINDEX)
# define SYNCTEX_CHARINDEX(NODE) (NODE->char_index)
# define SYNCTEX_LINEINDEX(NODE) (NODE->line_index)
# define SYNCTEX_PRINT_CHARINDEX_FMT "#%i"
# define SYNCTEX_PRINT_CHARINDEX_WHAT ,SYNCTEX_CHARINDEX(node)
# define SYNCTEX_PRINT_CHARINDEX \
printf(SYNCTEX_PRINT_CHARINDEX_FMT SYNCTEX_PRINT_CHARINDEX_WHAT)
# define SYNCTEX_PRINT_LINEINDEX_FMT "L#%i"
# define SYNCTEX_PRINT_LINEINDEX_WHAT ,SYNCTEX_LINEINDEX(node)
# define SYNCTEX_PRINT_LINEINDEX \
printf(SYNCTEX_PRINT_LINEINDEX_FMT SYNCTEX_PRINT_LINEINDEX_WHAT)
# define SYNCTEX_PRINT_CHARINDEX_NL \
printf(SYNCTEX_PRINT_CHARINDEX_FMT "\n" SYNCTEX_PRINT_CHARINDEX_WHAT)
# define SYNCTEX_PRINT_LINEINDEX_NL \
printf(SYNCTEX_PRINT_CHARINDEX_FMT "\n"SYNCTEX_PRINT_LINEINDEX_WHAT)
# define SYNCTEX_IMPLEMENT_CHARINDEX(NODE,CORRECTION)\
NODE->char_index = (synctex_charindex_t)(scanner->reader->charindex_offset+SYNCTEX_CUR-SYNCTEX_START+(CORRECTION)); \
NODE->line_index = scanner->reader->line_number;
# else
# define SYNCTEX_CHARINDEX(NODE) 0
# define SYNCTEX_LINEINDEX(NODE) 0
# define SYNCTEX_PRINT_CHARINDEX_FMT
# define SYNCTEX_PRINT_CHARINDEX_WHAT
# define SYNCTEX_PRINT_CHARINDEX
# define SYNCTEX_PRINT_CHARINDEX
# define SYNCTEX_PRINT_LINEINDEX_FMT
# define SYNCTEX_PRINT_LINEINDEX_WHAT
# define SYNCTEX_PRINT_LINEINDEX
# define SYNCTEX_PRINT_CHARINDEX_NL printf("\n")
# define SYNCTEX_PRINT_LINEINDEX_NL printf("\n")
# define SYNCTEX_IMPLEMENT_CHARINDEX(NODE,CORRECTION)
# endif
/**
* The next macros are used to access the node tree info
* SYNCTEX_DATA(node) points to the first synctex integer or pointer data of node
* SYNCTEX_DATA(node)[index] is the information at index
* for example, the page of a sheet is stored in SYNCTEX_DATA(sheet)[_synctex_data_page_idx]
* - parameter NODE: of type synctex_node_p
* If the name starts with "__", the argument is nonullable
*/
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Tree SETGET
# endif
#if SYNCTEX_DEBUG > 1000
#define SYNCTEX_PARAMETER_ASSERT(WHAT) \
do { \
if (!(WHAT)) { \
printf("! Parameter failure: %s\n",#WHAT); \
} \
} while (synctex_NO)
#define DEFINE_SYNCTEX_TREE_HAS(WHAT)\
static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
if (node) {\
if (node->class_->navigator->WHAT>=0) {\
return synctex_YES; \
} else {\
printf("WARNING: NO tree %s for %s\n", #WHAT, synctex_node_isa(node));\
}\
}\
return synctex_NO;\
}
#else
# define SYNCTEX_PARAMETER_ASSERT(WHAT)
# define DEFINE_SYNCTEX_TREE_HAS(WHAT) \
SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
return (node && (node->class_->navigator->WHAT>=0));\
}
#endif
# define DEFINE_SYNCTEX_TREE__GET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_##WHAT(synctex_non_null_node_p node) {\
return node->data[node->class_->navigator->WHAT].as_node;\
}
# define DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE__GET(WHAT) \
SYNCTEX_INLINE static synctex_node_p _synctex_tree_##WHAT(synctex_node_p node) {\
if (_synctex_tree_has_##WHAT(node)) {\
return __synctex_tree_##WHAT(node);\
}\
return NULL;\
}
# define DEFINE_SYNCTEX_TREE__RESET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_##WHAT(synctex_non_null_node_p node) {\
synctex_node_p old = node->data[node->class_->navigator->WHAT].as_node;\
node->data[node->class_->navigator->WHAT].as_node=NULL;\
return old;\
}
# define DEFINE_SYNCTEX_TREE_RESET(WHAT) \
DEFINE_SYNCTEX_TREE__RESET(WHAT) \
SYNCTEX_INLINE static synctex_node_p _synctex_tree_reset_##WHAT(synctex_node_p node) {\
return _synctex_tree_has_##WHAT(node)? \
__synctex_tree_reset_##WHAT(node): NULL; \
}
# define DEFINE_SYNCTEX_TREE__SET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_##WHAT(synctex_non_null_node_p node, synctex_node_p new_value) {\
synctex_node_p old = __synctex_tree_##WHAT(node);\
node->data[node->class_->navigator->WHAT].as_node=new_value;\
return old;\
}
# define DEFINE_SYNCTEX_TREE_SET(WHAT) \
DEFINE_SYNCTEX_TREE__SET(WHAT) \
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_##WHAT(synctex_node_p node, synctex_node_p new_value) {\
return _synctex_tree_has_##WHAT(node)?\
__synctex_tree_set_##WHAT(node,new_value):NULL;\
}
# define DEFINE_SYNCTEX_TREE__GETSETRESET(WHAT) \
DEFINE_SYNCTEX_TREE__GET(WHAT) \
DEFINE_SYNCTEX_TREE__SET(WHAT) \
DEFINE_SYNCTEX_TREE__RESET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETSET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_SET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETRESET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_RESET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETSETRESET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_SET(WHAT) \
DEFINE_SYNCTEX_TREE_RESET(WHAT)
/*
* _synctex_tree_set_... methods return the old value.
* The return value of _synctex_tree_set_child and
* _synctex_tree_set_sibling must be released somehow.
*/
/* The next macro call creates:
SYNCTEX_INLINE static synctex_node_p __synctex_tree_sibling(synctex_node_p node)
SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_value)
SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_sibling(synctex_node_p node)
*/
/** @fn __synctex_tree_sibling
@brief Get the sibling of the given node.
@param node
@return node
Private function.
Get the sibling of the given node assuming the node type declares a sibling.
*/
/** @fn __synctex_tree_set_sibling
@brief Set the sibling of the given node.
@param node
@param sibling
@return old sibling if any
Private function.
Set the sibling of the given node assuming the node type declares a sibling.
When the sibling is not `NULL`, it is owned by the node.
When the old sibling is not `NULL`, it is no longer owned by the node
and must be released somehow.
*/
/** @fn __synctex_tree_reset_sibling
@brief Reset the sibling of the given node.
@param node
@return sibling
Private function.
Set the sibling of the given node to NULL assuming the node type
declares a sibling.
Returns the old sibling.
When the old sibling is not `NULL`, it is no longer owned by the node
and must be released somehow.
*/
DEFINE_SYNCTEX_TREE__GETSETRESET(sibling)
/* The next macro call creates:
SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_parent(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p __synctex_tree_parent(synctex_non_null_node_p node);
SYNCTEX_INLINE static synctex_node_p _synctex_tree_parent(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_parent(synctex_node_p node, synctex_node_p new_value);
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_parent(synctex_node_p node, synctex_node_p new_value);
SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_parent(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p _synctex_tree_reset_parent(synctex_node_p node);
*/
/** @fn __synctex_tree_has_parent
@brief Whether a node possibly has a parent.
@param node
@return boolean
Private function.
Whether the type of the given node declares a parent.
*/
/** @fn __synctex_tree_parent
@brief Get the parent of the given node.
@param node
@return parent
Private function.
Get the parent of the given node assuming the node type declares a parent.
*/
/** @fn _synctex_tree_parent
@brief Get the parent of the given node.
@param node
@return parent or NULL
Private function.
Get the parent of the given node.
If the node type does not declare a parent, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_parent
@brief Set the parent of the given node.
@param node
@param parent
@return node
Private function.
Set the parent of the given node assuming the node type declares a parent.
The node is not yet the child of the parent:
`__synctex_tree_set_child` must also be called.
When the parent is not `NULL`, it is the owner of the node.
*/
/** @fn _synctex_tree_set_parent
@brief Set the parent of the given node.
@param node
@param parent
@return node
Private function.
If the the node type declares a parent, set it to the given node.
In that case, set the parent of the given node.
When the parent is not `NULL`, it becomes the owner of the node.
The node is not yet the child of the parent:
`__synctex_tree_set_child` must also be called.
The old child must be managed as well, if any.
If the the node type does not declare a parent,
nothing is done.
*/
/** @fn __synctex_tree_reset_parent
@brief Reset the parent of the given node.
@param node
@return old parent
Private function.
Synonym of `__synctex_tree_set_parent` to `NULL`.
*/
/** @fn _synctex_tree_reset_parent
@brief Reset the parent of the given node.
@param node
@return old parent
Private function.
Synonym of `_synctex_tree_set_parent` to `NULL`.
*/
DEFINE_SYNCTEX_TREE_GETSETRESET(parent)
/** @fn __synctex_tree_has_child
@brief Whether a node possibly has a child.
@param node
@return boolean
Private function.
Whether the type of the given node declares a child.
*/
/** @fn __synctex_tree_child
@brief Get the child of the given node.
@param node
@return child
Private function.
Get the child of the given node assuming the node type declares a child.
*/
/** @fn _synctex_tree_child
@brief Get the child of the given node.
@param node
@return child or NULL
Private function.
Get the child of the given node.
If the node type does not declare a child, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_child
@brief Set the child of the given node.
@param node
@param child
@return old child
Private function.
Set the child of the given node assuming the node type declares a child.
The node is not yet the parent of the child:
`__synctex_tree_set_parent` must also be called.
When the child is not `NULL`, it is owned by the node.
*/
/** @fn _synctex_tree_set_child
@brief Set the child of the given node.
@param node
@param child
@return old child
Private function.
If the the node type declares a child, set it to the given node.
When the child is not `NULL`, it becomes owned by the node.
The node is not yet the parent of the child:
`__synctex_tree_set_parent` must also be called.
The old child must be managed as well, if any.
If the the node type does not declare a child,
nothing is done.
*/
/** @fn __synctex_tree_reset_child
@brief Reset the child of the given node.
@param node
@return old child
Private function.
Synonym of `__synctex_tree_set_child` to `NULL`.
*/
/** @fn _synctex_tree_reset_child
@brief Reset the child of the given node.
@param node
@return old child
Private function.
Synonym of `_synctex_tree_set_child` to `NULL`.
*/
DEFINE_SYNCTEX_TREE_GETSETRESET(child)
/** @fn __synctex_tree_has_friend
@brief Whether a node possibly has a friend.
@param node
@return boolean
Private function.
Whether the type of the given node declares a friend.
*/
/** @fn __synctex_tree_friend
@brief Get the friend of the given node.
@param node
@return friend
Private function.
Get the friend of the given node assuming the node type declares a friend.
*/
/** @fn _synctex_tree_friend
@brief Get the friend of the given node.
@param node
@return friend
Private function.
Get the friend of the given node.
If the node type does not declare a friend, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_friend
@brief Set the friend of the given node.
@param node
@param friend
@return old friend
Private function.
Set the friend of the given node assuming the node type declares a friend.
*/
/** @fn _synctex_tree_set_friend
@brief Set the friend of the given node.
@param node
@param friend
@return old friend
Private function.
If the the node type declares a friend, set it to the given node.
If the the node type does not declare a friend,
nothing is done.
*/
/** @fn __synctex_tree_reset_friend
@brief Reset the friend of the given node.
@param node
@return old friend
Private function.
Synonym of `__synctex_tree_set_friend` to `NULL`.
*/
/** @fn _synctex_tree_reset_friend
@brief Reset the friend of the given node.
@param node
@return old friend
Private function.
Synonym of `_synctex_tree_set_friend` to `NULL`.
*/
DEFINE_SYNCTEX_TREE_GETSETRESET(friend)
/* The next macro call creates:
SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_last(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p __synctex_tree_last(synctex_non_null_node_p node);
SYNCTEX_INLINE static synctex_node_p _synctex_tree_last(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_last(synctex_node_p node, synctex_node_p new_value);
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_last(synctex_node_p node, synctex_node_p new_value);
*/
DEFINE_SYNCTEX_TREE_GETSET(last)
/** @fn __synctex_tree_has_last
@brief Whether a node possibly has a last.
@param node
@return boolean
Private function.
Whether the type of the given node declares a last.
*/
/** @fn __synctex_tree_last
@brief Get the last of the given node.
@param node
@return last node
Private function.
Get the last node of the given node assuming the node type declares a last node.
*/
/** @fn _synctex_tree_last
@brief Get the last of the given node.
@param node
@return last node or NULL
Private function.
Get the last node of the given node.
If the node type does not declare a last node, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_last
@brief Set the last of the given node.
@param node
@param last
@return old last
Private function.
Set the last of the given node assuming the node type declares a last node.
*/
/** @fn _synctex_tree_set_last
@brief Set the last of the given node.
@param node
@param last
@return old last
Private function.
If the the node type declares a last node, set it to the given node.
If the the node type does not declare a last node,
nothing is done.
*/
DEFINE_SYNCTEX_TREE_GETSET(next_hbox)
/** @fn __synctex_tree_has_next_hbox
@brief Whether a node possibly has a next_hbox.
@param node
@return boolean
Private function.
Whether the type of the given node declares a next_hbox.
*/
/** @fn __synctex_tree_next_hbox
@brief Get the next_hbox of the given node.
@param node
@return next_hbox node
Private function.
Get the next_hbox node of the given node assuming the node type declares a next_hbox node.
*/
/** @fn _synctex_tree_next_hbox
@brief Get the next_hbox of the given node.
@param node
@return next_hbox node or NULL
Private function.
Get the next_hbox node of the given node.
If the node type does not declare a next_hbox node, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_next_hbox
@brief Set the next_hbox of the given node.
@param node
@param next_hbox
@return old next_hbox
Private function.
Set the next_hbox of the given node assuming the node type declares a next_hbox node.
*/
/** @fn _synctex_tree_set_next_hbox
@brief Set the next_hbox of the given node.
@param node
@param next_hbox
@return old next_hbox
Private function.
If the the node type declares a next_hbox node, set it to the given node.
If the the node type does not declare a next_hbox node,
nothing is done.
*/
DEFINE_SYNCTEX_TREE_GETSET(arg_sibling)
/** @fn __synctex_tree_has_arg_sibling
@brief Whether a node possibly has a arg_sibling.
@param node
@return boolean
Private function.
Whether the type of the given node declares a arg_sibling.
*/
/** @fn __synctex_tree_arg_sibling
@brief Get the arg_sibling of the given node.
@param node
@return arg_sibling node
Private function.
Get the arg_sibling node of the given node assuming the node type declares a arg_sibling node.
*/
/** @fn _synctex_tree_arg_sibling
@brief Get the arg_sibling of the given node.
@param node
@return arg_sibling node or NULL
Private function.
Get the arg_sibling node of the given node.
If the node type does not declare a arg_sibling node, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_arg_sibling
@brief Set the arg_sibling of the given node.
@param node
@param arg_sibling
@return old arg_sibling
Private function.
Set the arg_sibling of the given node assuming the node type declares a arg_sibling node.
*/
/** @fn _synctex_tree_set_arg_sibling
@brief Set the arg_sibling of the given node.
@param node
@param arg_sibling
@return old arg_sibling
Private function.
If the the node type declares a arg_sibling node, set it to the given node.
If the the node type does not declare a arg_sibling node,
nothing is done.
*/
DEFINE_SYNCTEX_TREE_GETSETRESET(target)
/** @fn __synctex_tree_has_target
@brief Whether a node possibly has a target.
@param node
@return boolean
Private function.
Whether the type of the given node declares a target.
*/
/** @fn __synctex_tree_target
@brief Get the target of the given node.
@param node
@return target node
Private function.
Get the target node of the given node assuming the node type declares a target node.
*/
/** @fn _synctex_tree_target
@brief Get the target of the given node.
@param node
@return target node or NULL
Private function.
Get the target node of the given node.
If the node type does not declare a target node, then `NULL` is returned.
*/
/** @fn __synctex_tree_set_target
@brief Set the target of the given node.
@param node
@param target
@return old target
Private function.
Set the target of the given node assuming the node type declares a target node.
*/
/** @fn _synctex_tree_set_target
@brief Set the target of the given node.
@param node
@param target
@return old target
Private function.
If the the node type declares a target node, set it to the given node.
If the the node type does not declare a target node,
nothing is done.
*/
#if SYNCTEX_DEBUG > 1000
# undef SYNCTEX_USE_NODE_COUNT
# define SYNCTEX_USE_NODE_COUNT 1
#endif
#if SYNCTEX_USE_NODE_COUNT>0
# define SYNCTEX_DECLARE_NODE_COUNT int node_count;
# define SYNCTEX_INIT_NODE_COUNT \
do { node_count = 0; } while(synctex_NO)
#else
# define SYNCTEX_DECLARE_NODE_COUNT
# define SYNCTEX_INIT_NODE_COUNT
#endif
#if SYNCTEX_USE_NODE_COUNT>10
# define SYNCTEX_DID_NEW(N) _synctex_did_new(N)
# define SYNCTEX_WILL_FREE(N) _synctex_will_free(N)
#else
# define SYNCTEX_DID_NEW(N)
# define SYNCTEX_WILL_FREE(N)
#endif
#define SYNCTEX_HAS_CHILDREN(NODE) (NODE && _synctex_tree_child(NODE))
# ifdef SYNCTEX_STANDALONE
# include "/usr/local/include/node/zlib.h"
# else
# include <zlib.h>
# endif
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark STATUS
# endif
/* When the end of the synctex file has been reached: */
# define SYNCTEX_STATUS_EOF 0
/* When the function could not return the value it was asked for: */
# define SYNCTEX_STATUS_NOT_OK (SYNCTEX_STATUS_EOF+1)
/* When the function returns the value it was asked for:
It must be the biggest one */
# define SYNCTEX_STATUS_OK (SYNCTEX_STATUS_NOT_OK+1)
/* Generic error: */
# define SYNCTEX_STATUS_ERROR (SYNCTEX_STATUS_EOF-1)
/* Parameter error: */
# define SYNCTEX_STATUS_BAD_ARGUMENT (SYNCTEX_STATUS_ERROR-1)
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark File reader
# endif
/* We ensure that SYNCTEX_BUFFER_SIZE < UINT_MAX, I don't know if it makes sense... */
/* Actually, the minimum buffer size is driven by integer and float parsing, including the unit.
* ±0.123456789e123??
*/
# define SYNCTEX_BUFFER_MIN_SIZE 32
# define SYNCTEX_BUFFER_SIZE 32768
#if SYNCTEX_BUFFER_SIZE >= UINT_MAX
# error BAD BUFFER SIZE(1)
#endif
#if SYNCTEX_BUFFER_SIZE < SYNCTEX_BUFFER_MIN_SIZE
# error BAD BUFFER SIZE(2)
#endif
/** @endcond */