mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-11 01:33:47 +01:00
Add synctex_get_input_line_column
This commit is contained in:
parent
d0bb3b8983
commit
fd13cf5921
118
synctex.c
118
synctex.c
@ -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)
|
||||
{
|
||||
@ -27,60 +73,44 @@ synctex_edit(const char* editor, zathura_page_t* page, int x, int y)
|
||||
return;
|
||||
}
|
||||
|
||||
const char *filename = zathura_document_get_path(document);
|
||||
const char* filename = zathura_document_get_path(document);
|
||||
if (filename == NULL) {
|
||||
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;
|
||||
}
|
||||
unsigned int line = 0;
|
||||
unsigned int column = 0;
|
||||
char* input_file = NULL;
|
||||
|
||||
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_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);
|
||||
|
||||
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);
|
||||
|
||||
char* linestr = g_strdup_printf("%d", line);
|
||||
char* columnstr = g_strdup_printf("%d", column);
|
||||
|
||||
gchar** argv = NULL;
|
||||
gint argc = 0;
|
||||
if (g_shell_parse_argv(editor, &argc, &argv, NULL) == TRUE) {
|
||||
for (gint i = 0; i != argc; ++i) {
|
||||
char* temp = girara_replace_substring(argv[i], "%{line}", linestr);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
temp = girara_replace_substring(argv[i], "%{column}", columnstr);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
temp = girara_replace_substring(argv[i], "%{input}", input_file);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
}
|
||||
|
||||
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||
g_strfreev(argv);
|
||||
gchar** argv = NULL;
|
||||
gint argc = 0;
|
||||
if (g_shell_parse_argv(editor, &argc, &argv, NULL) == TRUE) {
|
||||
for (gint i = 0; i != argc; ++i) {
|
||||
char* temp = girara_replace_substring(argv[i], "%{line}", linestr);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
temp = girara_replace_substring(argv[i], "%{column}", columnstr);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
temp = girara_replace_substring(argv[i], "%{input}", input_file);
|
||||
g_free(argv[i]);
|
||||
argv[i] = temp;
|
||||
}
|
||||
|
||||
g_free(linestr);
|
||||
g_free(columnstr);
|
||||
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||
g_strfreev(argv);
|
||||
}
|
||||
}
|
||||
|
||||
synctex_scanner_free(scanner);
|
||||
g_free(linestr);
|
||||
g_free(columnstr);
|
||||
|
||||
g_free(input_file);
|
||||
}
|
||||
}
|
||||
|
||||
girara_list_t*
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user