~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to synctex/synctex_parser.c

  • Committer: Adam Reichold
  • Date: 2023-02-07 10:14:00 UTC
  • Revision ID: adam.reichold@t-online.de-20230207101400-abr0l1umhs63sq3o
Import updated SyncTeX sources from TeXLive subversion repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
 *  First level objects are sheets and forms, containing boxes, glues, kerns...
84
84
 *  The third tree allows to browse leaves according to tag and line.
85
85
 */
 
86
/* Declare _GNU_SOURCE for accessing vasprintf. For MSC compiler, vasprintf is
 
87
 * defined in this file
 
88
 */
 
89
#define _GNU_SOURCE
 
90
 
86
91
#   if defined(SYNCTEX_USE_LOCAL_HEADER)
87
92
#       include "synctex_parser_local.h"
88
93
#   else
361
366
static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
362
367
    if (node) {\
363
368
        if (node->class_->navigator->WHAT>=0) {\
364
 
            return  synctex_YES; \
 
369
            return synctex_YES; \
365
370
        } else {\
366
371
            printf("WARNING: NO tree %s for %s\n", #WHAT, synctex_node_isa(node));\
367
372
        }\
369
374
    return synctex_NO;\
370
375
}
371
376
#else
372
 
#define SYNCTEX_PARAMETER_ASSERT(WHAT)
373
 
#define DEFINE_SYNCTEX_TREE_HAS(WHAT) \
374
 
static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
 
377
#   define SYNCTEX_PARAMETER_ASSERT(WHAT)
 
378
#   define DEFINE_SYNCTEX_TREE_HAS(WHAT) \
 
379
SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
375
380
    return (node && (node->class_->navigator->WHAT>=0));\
376
381
}
377
382
#endif
382
387
}
383
388
#   define DEFINE_SYNCTEX_TREE_GET(WHAT) \
384
389
DEFINE_SYNCTEX_TREE__GET(WHAT) \
385
 
static synctex_node_p _synctex_tree_##WHAT(synctex_node_p node) {\
 
390
SYNCTEX_INLINE static synctex_node_p _synctex_tree_##WHAT(synctex_node_p node) {\
386
391
    if (_synctex_tree_has_##WHAT(node)) {\
387
392
        return __synctex_tree_##WHAT(node);\
388
393
    }\
438
443
 *  The return value of _synctex_tree_set_child and 
439
444
 *  _synctex_tree_set_sibling must be released somehow.
440
445
 */
 
446
/* The next macro call creates:
 
447
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_sibling(synctex_node_p node)
 
448
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_value)
 
449
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_sibling(synctex_node_p node)
 
450
 */
441
451
DEFINE_SYNCTEX_TREE__GETSETRESET(sibling)
 
452
/* The next macro call creates:
 
453
 SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_parent(synctex_node_p node);
 
454
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_parent(synctex_non_null_node_p node);
 
455
 SYNCTEX_INLINE static synctex_node_p _synctex_tree_parent(synctex_node_p node);
 
456
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_parent(synctex_node_p node, synctex_node_p new_value);
 
457
 SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_parent(synctex_node_p node, synctex_node_p new_value);
 
458
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_parent(synctex_node_p node);
 
459
 SYNCTEX_INLINE static synctex_node_p _synctex_tree_reset_parent(synctex_node_p node);
 
460
 */
442
461
DEFINE_SYNCTEX_TREE_GETSETRESET(parent)
443
462
DEFINE_SYNCTEX_TREE_GETSETRESET(child)
444
463
DEFINE_SYNCTEX_TREE_GETSETRESET(friend)
 
464
/* The next macro call creates:
 
465
 SYNCTEX_INLINE static synctex_bool_t _synctex_tree_has_last(synctex_node_p node);
 
466
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_last(synctex_non_null_node_p node);
 
467
 SYNCTEX_INLINE static synctex_node_p _synctex_tree_last(synctex_node_p node);
 
468
 SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_last(synctex_node_p node, synctex_node_p new_value);
 
469
 SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_last(synctex_node_p node, synctex_node_p new_value);
 
470
 */
445
471
DEFINE_SYNCTEX_TREE_GETSET(last)
446
472
DEFINE_SYNCTEX_TREE_GETSET(next_hbox)
447
473
DEFINE_SYNCTEX_TREE_GETSET(arg_sibling)
470
496
 
471
497
#define SYNCTEX_HAS_CHILDREN(NODE) (NODE && _synctex_tree_child(NODE))
472
498
#       ifdef   __SYNCTEX_WORK__
473
 
#               include "/usr/include/zlib.h"
 
499
#               include "/usr/local/include/node/zlib.h"
474
500
#       else
475
501
#               include <zlib.h>
476
502
#       endif
892
918
 *  It is not owned by its parent, unless it is its first child.
893
919
 *  This destructor is for all handles.
894
920
 */
 
921
static void _synctex_free_handle_old(synctex_node_p handle) {
 
922
  if (handle) {
 
923
    _synctex_free_handle_old(__synctex_tree_sibling(handle));
 
924
    _synctex_free_handle_old(_synctex_tree_child(handle));
 
925
    _synctex_free(handle);
 
926
  }
 
927
  return;
 
928
}
895
929
static void _synctex_free_handle(synctex_node_p handle) {
896
 
    if (handle) {
897
 
        _synctex_free_handle(__synctex_tree_sibling(handle));
898
 
        _synctex_free_handle(_synctex_tree_child(handle));
899
 
        _synctex_free(handle);
900
 
    }
901
 
    return;
 
930
  if (handle) {
 
931
    synctex_node_p n = handle;
 
932
    synctex_node_p nn;
 
933
    __synctex_tree_set_parent(n, NULL);
 
934
  down:
 
935
    while ((nn = _synctex_tree_child(n))) {
 
936
      __synctex_tree_set_parent(nn, n);
 
937
      n = nn;
 
938
    };
 
939
  right:
 
940
    nn = __synctex_tree_sibling(n);
 
941
    if (nn) {
 
942
      _synctex_free(n);
 
943
      n = nn;
 
944
      goto down;
 
945
    }
 
946
    nn = __synctex_tree_parent(n);
 
947
    _synctex_free(n);
 
948
    if (nn) {
 
949
      n = nn;
 
950
      goto right;
 
951
    }
 
952
  }
 
953
  return;
902
954
}
903
955
 
904
956
/**
4510
4562
            _synctex_error("Problem with Y offset in the Post Scriptum.");
4511
4563
            return fs.status;
4512
4564
        }
4513
 
        scanner->x_offset = fs.value;
 
4565
        scanner->y_offset = fs.value;
4514
4566
        goto next_line;
4515
4567
    } else if (status<SYNCTEX_STATUS_EOF){
4516
4568
        goto report_record_problem;
6006
6058
        _synctex_error("malloc problem");
6007
6059
        return NULL;
6008
6060
    }
6009
 
    if ((scanner->reader = synctex_reader_init_with_output_file(scanner->reader, output, build_directory))) {
 
6061
    if (synctex_reader_init_with_output_file(scanner->reader, output, build_directory)) {
6010
6062
        return parse? synctex_scanner_parse(scanner):scanner;
6011
6063
    }
6012
6064
    // don't warn to terminal if no file is present, this is a library.
6013
6065
    // _synctex_error("No file?");
 
6066
    synctex_scanner_free(scanner);
6014
6067
    return NULL;
6015
6068
}
6016
6069
 
6019
6072
int synctex_scanner_free(synctex_scanner_p scanner) {
6020
6073
    int node_count = 0;
6021
6074
    if (scanner) {
6022
 
        if (SYNCTEX_FILE) {
6023
 
            gzclose(SYNCTEX_FILE);
6024
 
            SYNCTEX_FILE = NULL;
6025
 
        }
6026
6075
        synctex_node_free(scanner->sheet);
6027
6076
        synctex_node_free(scanner->form);
6028
6077
        synctex_node_free(scanner->input);
6054
6103
    scanner->x_offset = scanner->y_offset = 6.027e23f;
6055
6104
    scanner->reader->line_number = 1;
6056
6105
    
6057
 
    SYNCTEX_START = (char *)malloc(SYNCTEX_BUFFER_SIZE+1); /*  one more character for null termination */
6058
 
    if (NULL == SYNCTEX_START) {
6059
 
        _synctex_error("!  malloc error in synctex_scanner_parse.");
6060
 
    bailey:
6061
 
#ifdef SYNCTEX_DEBUG
6062
 
        return scanner;
6063
 
#else
6064
 
        synctex_scanner_free(scanner);
6065
 
        return NULL;
6066
 
#endif
6067
 
    }
6068
6106
    synctex_scanner_set_display_switcher(scanner, 1000);
6069
6107
    SYNCTEX_END = SYNCTEX_START+SYNCTEX_BUFFER_SIZE;
6070
6108
    /*  SYNCTEX_END always points to a null terminating character.
6078
6116
    status = _synctex_scan_preamble(scanner);
6079
6117
    if (status<SYNCTEX_STATUS_OK) {
6080
6118
        _synctex_error("Bad preamble\n");
6081
 
        goto bailey;
 
6119
        bailey:
 
6120
#ifdef SYNCTEX_DEBUG
 
6121
            return scanner;
 
6122
#else
 
6123
            synctex_scanner_free(scanner);
 
6124
            return NULL;
 
6125
#endif
6082
6126
    }
6083
6127
    status = _synctex_scan_content(scanner);
6084
6128
    if (status<SYNCTEX_STATUS_OK) {
8390
8434
    int length;             /*  the number of chars appended */
8391
8435
};
8392
8436
 
 
8437
__attribute__((__format__ (__printf__, 2, 3)))
8393
8438
static int _synctex_updater_print(synctex_updater_p updater, const char * format, ...) {
8394
8439
    int result = 0;
8395
8440
    if (updater) {
8426
8471
/**
8427
8472
 *  gzvprintf is not available until OSX 10.10
8428
8473
 */
 
8474
__attribute__((__format__ (__printf__, 2, 3)))
8429
8475
static int _synctex_updater_print_gz(synctex_updater_p updater, const char * format, ...) {
8430
8476
    int result = 0;
8431
8477
    if (updater) {