Add synctex_get_input_line_column

This commit is contained in:
Sebastian Ramacher 2014-08-22 20:09:18 +02:00
parent d0bb3b8983
commit fd13cf5921
2 changed files with 78 additions and 44 deletions

View File

@ -15,6 +15,52 @@
#include "document.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
synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
{
@ -32,27 +78,12 @@ synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
return;
}
synctex_scanner_t scanner = synctex_scanner_new_with_output_file(filename, NULL, 1);
if (scanner == NULL) {
girara_debug("Failed to create synctex scanner.");
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);
unsigned int line = 0;
unsigned int column = 0;
char* input_file = NULL;
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* 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(columnstr);
}
}
synctex_scanner_free(scanner);
g_free(input_file);
}
}
girara_list_t*

View File

@ -10,7 +10,11 @@ typedef struct synctex_page_rect_s {
zathura_rectangle_t rect;
} 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);
girara_list_t* synctex_rectangles_from_position(const char* filename,
const char* input_file, int line, int column, unsigned int* page,
girara_list_t** secondary_rects);