mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 20:06:00 +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
118
synctex.c
118
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,60 +73,44 @@ 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 (synctex_get_input_line_column(filename, zathura_page_get_index(page), x, y,
|
||||||
if (temp == NULL) {
|
&input_file, &line, &column) == true) {
|
||||||
girara_debug("Failed to parse synctex file.");
|
char* linestr = g_strdup_printf("%d", line);
|
||||||
synctex_scanner_free(scanner);
|
char* columnstr = g_strdup_printf("%d", column);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (synctex_edit_query(scanner, zathura_page_get_index(page) + 1, x, y) > 0) {
|
gchar** argv = NULL;
|
||||||
/* Assume that a backward search returns either at most one result. */
|
gint argc = 0;
|
||||||
synctex_node_t node = synctex_next_result(scanner);
|
if (g_shell_parse_argv(editor, &argc, &argv, NULL) == TRUE) {
|
||||||
if (node != NULL) {
|
for (gint i = 0; i != argc; ++i) {
|
||||||
const char* input_file = synctex_scanner_get_name(scanner, synctex_node_tag(node));
|
char* temp = girara_replace_substring(argv[i], "%{line}", linestr);
|
||||||
const int line = synctex_node_line(node);
|
g_free(argv[i]);
|
||||||
const int column = synctex_node_column (node);
|
argv[i] = temp;
|
||||||
|
temp = girara_replace_substring(argv[i], "%{column}", columnstr);
|
||||||
char* linestr = g_strdup_printf("%d", line);
|
g_free(argv[i]);
|
||||||
char* columnstr = g_strdup_printf("%d", column);
|
argv[i] = temp;
|
||||||
|
temp = girara_replace_substring(argv[i], "%{input}", input_file);
|
||||||
gchar** argv = NULL;
|
g_free(argv[i]);
|
||||||
gint argc = 0;
|
argv[i] = temp;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(linestr);
|
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||||
g_free(columnstr);
|
g_strfreev(argv);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
synctex_scanner_free(scanner);
|
g_free(linestr);
|
||||||
|
g_free(columnstr);
|
||||||
|
|
||||||
|
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