1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Handle the -batch option centrally in cmdline.c.

This removes one case from several of the individual tools'
command-line parsers, and moves it into a central place where it will
automatically be supported by any tool containing console.c.

In order to make that not cause a link failure, there's now a
stubs/no-console.c which GUI clients of cmdline.c must include.
This commit is contained in:
Simon Tatham 2022-11-24 20:00:48 +00:00
parent 819efc3c21
commit 1625fd8fcb
10 changed files with 43 additions and 11 deletions

View File

@ -130,10 +130,15 @@ SeatPromptResult cmdline_get_passwd_input(
return SPR_OK;
}
static void cmdline_report_unavailable(const char *p)
{
cmdline_error("option \"%s\" not available in this tool", p);
}
static bool cmdline_check_unavailable(int flag, const char *p)
{
if (cmdline_tooltype & flag) {
cmdline_error("option \"%s\" not available in this tool", p);
cmdline_report_unavailable(p);
return true;
}
return false;
@ -906,6 +911,15 @@ int cmdline_process_param(const char *p, char *value,
conf_set_str(conf, CONF_proxy_telnet_command, value);
}
if (!strcmp(p, "-batch")) {
RETURN(1);
SAVEABLE(0);
if (!console_set_batch_mode(true)) {
cmdline_report_unavailable(p);
return ret;
}
}
#ifdef _WINDOWS
/*
* Cross-tool options only available on Windows.

View File

@ -36,6 +36,12 @@ const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat)
bool console_batch_mode = false;
bool console_set_batch_mode(bool newvalue)
{
console_batch_mode = newvalue;
return true;
}
/*
* Error message and/or fatal exit functions, all based on
* console_print_error_msg which the platform front end provides.

2
pscp.c
View File

@ -2298,8 +2298,6 @@ int psftp_main(int argc, char *argv[])
version();
} else if (strcmp(argv[i], "-ls") == 0) {
list = true;
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = true;
} else if (strcmp(argv[i], "-unsafe") == 0) {
scp_unsafe_mode = true;
} else if (strcmp(argv[i], "-sftp") == 0) {

View File

@ -2836,8 +2836,6 @@ int psftp_main(int argc, char *argv[])
} else if (strcmp(argv[i], "-V") == 0 ||
strcmp(argv[i], "--version") == 0) {
version();
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = true;
} else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) {
mode = 1;
batchfile = argv[++i];

View File

@ -2562,6 +2562,7 @@ bool have_ssh_host_key(const char *host, int port, const char *keytype);
* that aren't equivalents to things in windlg.c et al.
*/
extern bool console_batch_mode, console_antispoof_prompt;
extern bool console_set_batch_mode(bool);
SeatPromptResult console_get_userpass_input(prompts_t *p);
bool is_interactive(void);
void console_print_error_msg(const char *prefix, const char *msg);
@ -2627,6 +2628,7 @@ extern const unsigned cmdline_tooltype;
X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \
X(TOOLTYPE_PORT_ARG) \
X(TOOLTYPE_NO_VERBOSE_OPTION) \
X(TOOLTYPE_GUI) \
/* end of list */
#define BITFLAG_INDEX(val) val ## _bitflag_index,
enum { TOOLTYPE_LIST(BITFLAG_INDEX) };

10
stubs/no-console.c Normal file
View File

@ -0,0 +1,10 @@
/*
* Stub functions for when console.c is not linked into a program.
*/
#include "putty.h"
bool console_set_batch_mode(bool newvalue)
{
return false;
}

View File

@ -137,6 +137,7 @@ if(GTK_FOUND)
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pty.c)
be_list(pterm pterm)
@ -152,6 +153,7 @@ if(GTK_FOUND)
${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pty.c)
be_list(ptermapp pterm)
@ -162,7 +164,8 @@ if(GTK_FOUND)
add_executable(putty
putty.c
main-gtk-simple.c)
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c)
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
target_link_libraries(putty
guiterminal eventloop sshclient otherbackends settings
@ -176,7 +179,8 @@ if(GTK_FOUND)
add_executable(puttyapp
putty.c
main-gtk-application.c
${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c)
${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c)
be_list(puttyapp PuTTY SSH SERIAL OTHERBACKENDS)
target_link_libraries(puttyapp
guiterminal eventloop sshclient otherbackends settings
@ -189,6 +193,7 @@ if(GTK_FOUND)
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
${CMAKE_SOURCE_DIR}/stubs/no-rand.c
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c)

View File

@ -735,8 +735,6 @@ int main(int argc, char **argv)
--argc, ++argv;
} else if (ret == 1) {
continue;
} else if (!strcmp(p, "-batch")) {
console_batch_mode = true;
} else if (!strcmp(p, "-s")) {
/* Save status to write to conf later. */
use_subsystem = true;

View File

@ -101,6 +101,7 @@ add_executable(putty
window.c
putty.c
help.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
putty.rc)
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
add_dependencies(putty generated_licence_h)
@ -119,6 +120,7 @@ add_executable(puttytel
help.c
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
${CMAKE_SOURCE_DIR}/stubs/no-rand.c
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
@ -161,6 +163,7 @@ if(HAVE_CONPTY)
conpty.c
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
${CMAKE_SOURCE_DIR}/stubs/no-console.c
${CMAKE_SOURCE_DIR}/stubs/no-rand.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pterm.rc)

View File

@ -340,8 +340,6 @@ int main(int argc, char **argv)
--argc, ++argv;
} else if (ret == 1) {
continue;
} else if (!strcmp(p, "-batch")) {
console_batch_mode = true;
} else if (!strcmp(p, "-s")) {
/* Save status to write to conf later. */
use_subsystem = true;