mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 11:26:01 +01:00
Add synctex_get_input_line_column
This commit is contained in:
parent
d0bb3b8983
commit
fd13cf5921
2 changed files with 78 additions and 44 deletions
78
synctex.c
78
synctex.c
|
@ -15,6 +15,52 @@
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
synctex_get_input_line_column(const char* filename, unsigned int page, int x, int y,
|
||||||
|
char** input_file, unsigned int* line, unsigned int* column)
|
||||||
|
{
|
||||||
|
if (filename == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
synctex_scanner_t scanner = synctex_scanner_new_with_output_file(filename, NULL, 1);
|
||||||
|
if (scanner == NULL) {
|
||||||
|
girara_debug("Failed to create synctex scanner.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
synctex_scanner_t temp = synctex_scanner_parse(scanner);
|
||||||
|
if (temp == NULL) {
|
||||||
|
girara_debug("Failed to parse synctex file.");
|
||||||
|
synctex_scanner_free(scanner);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if (synctex_edit_query(scanner, page + 1u, x, y) > 0) {
|
||||||
|
/* Assume that a backward search returns at most one result. */
|
||||||
|
synctex_node_t node = synctex_next_result(scanner);
|
||||||
|
if (node != NULL) {
|
||||||
|
if (input_file != NULL) {
|
||||||
|
*input_file = g_strdup(synctex_scanner_get_name(scanner, synctex_node_tag(node)));
|
||||||
|
}
|
||||||
|
if (line != NULL) {
|
||||||
|
*line = synctex_node_line(node);
|
||||||
|
}
|
||||||
|
if (column != NULL) {
|
||||||
|
*column = synctex_node_column(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synctex_scanner_free(scanner);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
|
synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -27,32 +73,17 @@ synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *filename = zathura_document_get_path(document);
|
const char* filename = zathura_document_get_path(document);
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
synctex_scanner_t scanner = synctex_scanner_new_with_output_file(filename, NULL, 1);
|
unsigned int line = 0;
|
||||||
if (scanner == NULL) {
|
unsigned int column = 0;
|
||||||
girara_debug("Failed to create synctex scanner.");
|
char* input_file = NULL;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
synctex_scanner_t temp = synctex_scanner_parse(scanner);
|
|
||||||
if (temp == NULL) {
|
|
||||||
girara_debug("Failed to parse synctex file.");
|
|
||||||
synctex_scanner_free(scanner);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (synctex_edit_query(scanner, zathura_page_get_index(page) + 1, x, y) > 0) {
|
|
||||||
/* Assume that a backward search returns either at most one result. */
|
|
||||||
synctex_node_t node = synctex_next_result(scanner);
|
|
||||||
if (node != NULL) {
|
|
||||||
const char* input_file = synctex_scanner_get_name(scanner, synctex_node_tag(node));
|
|
||||||
const int line = synctex_node_line(node);
|
|
||||||
const int column = synctex_node_column (node);
|
|
||||||
|
|
||||||
|
if (synctex_get_input_line_column(filename, zathura_page_get_index(page), x, y,
|
||||||
|
&input_file, &line, &column) == true) {
|
||||||
char* linestr = g_strdup_printf("%d", line);
|
char* linestr = g_strdup_printf("%d", line);
|
||||||
char* columnstr = g_strdup_printf("%d", column);
|
char* columnstr = g_strdup_printf("%d", column);
|
||||||
|
|
||||||
|
@ -77,10 +108,9 @@ synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
|
||||||
|
|
||||||
g_free(linestr);
|
g_free(linestr);
|
||||||
g_free(columnstr);
|
g_free(columnstr);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synctex_scanner_free(scanner);
|
g_free(input_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_list_t*
|
girara_list_t*
|
||||||
|
|
|
@ -10,7 +10,11 @@ typedef struct synctex_page_rect_s {
|
||||||
zathura_rectangle_t rect;
|
zathura_rectangle_t rect;
|
||||||
} synctex_page_rect_t;
|
} synctex_page_rect_t;
|
||||||
|
|
||||||
|
bool synctex_get_input_line_column(const char* filename, unsigned int page,
|
||||||
|
int x, int y, char** input_file, unsigned int* line, unsigned int* column);
|
||||||
|
|
||||||
void synctex_edit(const char* editor, zathura_page_t* page, int x, int y);
|
void synctex_edit(const char* editor, zathura_page_t* page, int x, int y);
|
||||||
|
|
||||||
girara_list_t* synctex_rectangles_from_position(const char* filename,
|
girara_list_t* synctex_rectangles_from_position(const char* filename,
|
||||||
const char* input_file, int line, int column, unsigned int* page,
|
const char* input_file, int line, int column, unsigned int* page,
|
||||||
girara_list_t** secondary_rects);
|
girara_list_t** secondary_rects);
|
||||||
|
|
Loading…
Reference in a new issue