1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

also pass the uri as %u to external handlers

This commit is contained in:
sgerwk 2020-07-25 13:28:56 +02:00
parent 8e36753bbc
commit 153ea907a8
3 changed files with 35 additions and 15 deletions

View File

@ -91,7 +91,8 @@ choice if you want).
Attaching a program to it::
You must tell ELinks the exact command for running it (with any
options you wish). In place of the filename you must enter %.
options you wish). In place of the filename you must enter %f. Also the
uri can be used as %u.
Choosing whether you want confirmation before applying it::
@ -144,12 +145,12 @@ and value with the value you want to assign to the item. You must do so for
each of the available items: program, ask and block.
The value for program is a string with the exact command you want to be issued
to view the file, placing % were you would put the file name. The values for
ask and block are either 0 (no) or 1 (yes). Available contexts include unix
and unix-xwin, which mean UNIX text terminal and X respectively (others can be
os2, win32, beos, riscos, ...). The latter does not mean you are running
ELinks from X, just that the DISPLAY variable is set so that ELinks may run an
X program.
to view the file, placing %f were you would put the file name and %u the uri
(if needed). The values for ask and block are either 0 (no) or 1 (yes).
Available contexts include unix and unix-xwin, which mean UNIX text terminal
and X respectively (others can be os2, win32, beos, riscos, ...). The latter
does not mean you are running ELinks from X, just that the DISPLAY variable is
set so that ELinks may run an X program.
To illustrate it, here is an example. Suppose you want to define the
image_viewer handler which should be used to view images. The configuration
@ -162,8 +163,8 @@ set mime.handler.image_viewer.unix-xwin.ask = 0
set mime.handler.image_viewer.unix.block = 1
set mime.handler.image_viewer.unix-xwin.block = 0
set mime.handler.image_viewer.unix.program = "zgv %"
set mime.handler.image_viewer.unix-xwin.program = "xli %"
set mime.handler.image_viewer.unix.program = "zgv %f"
set mime.handler.image_viewer.unix-xwin.program = "xli %f"
--------------------------------------------------------------------------------
In this example the image_viewer handler uses the svgalib image viewer zgv

View File

@ -74,7 +74,8 @@ static union option_info default_mime_options[] = {
"program", 0, "",
/* xgettext:no-c-format */
N_("External viewer for this file type. "
"'%' in this string will be substituted by a file name. "
"'%f' in this string will be substituted by a file name, "
"'%u' by its uri. "
"Do _not_ put single- or double-quotes around the % sign.")),

View File

@ -1028,12 +1028,13 @@ get_temp_name(struct uri *uri)
static unsigned char *
subst_file(unsigned char *prog, unsigned char *file)
subst_file(unsigned char *prog, unsigned char *file, unsigned char *uri)
{
struct string name;
/* When there is no %s in the mailcap entry, the handler program reads
* data from stdin instead of a file. */
int input = 1;
char *replace, *original = "% ";
if (!init_string(&name)) return NULL;
@ -1046,6 +1047,21 @@ subst_file(unsigned char *prog, unsigned char *file)
prog += p;
if (*prog == '%') {
prog++;
if (*prog == 'f' || *prog == ' ' || *prog == '\0')
replace = file;
else if (*prog == 'u')
replace = uri;
else if (*prog == '%')
replace = "%";
else {
original[1] = *prog;
replace = original;
}
if (*prog == ' ' || *prog == '\0')
prog--;
input = 0;
#if defined(HAVE_CYGWIN_CONV_TO_FULL_WIN32_PATH)
#ifdef MAX_PATH
@ -1054,10 +1070,10 @@ subst_file(unsigned char *prog, unsigned char *file)
unsigned char new_path[1024];
#endif
cygwin_conv_to_full_win32_path(file, new_path);
cygwin_conv_to_full_win32_path(replace, new_path);
add_to_string(&name, new_path);
#else
add_shell_quoted_to_string(&name, file, strlen(file));
add_shell_quoted_to_string(&name, replace, strlen(replace));
#endif
prog++;
}
@ -1242,7 +1258,8 @@ continue_download_do(struct terminal *term, int fd, void *data,
if (type_query->external_handler) {
file_download->external_handler = subst_file(type_query->external_handler,
codw_hop->file);
codw_hop->file,
type_query->uri->string);
file_download->delete_ = 1;
file_download->copiousoutput = type_query->copiousoutput;
mem_free(codw_hop->file);
@ -1490,7 +1507,8 @@ tp_open(struct type_query *type_query)
if (file) {
decode_uri(file);
handler = subst_file(type_query->external_handler, file);
handler = subst_file(type_query->external_handler,
file, file);
mem_free(file);
}