mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +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:
parent
819efc3c21
commit
1625fd8fcb
16
cmdline.c
16
cmdline.c
@ -130,10 +130,15 @@ SeatPromptResult cmdline_get_passwd_input(
|
|||||||
return SPR_OK;
|
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)
|
static bool cmdline_check_unavailable(int flag, const char *p)
|
||||||
{
|
{
|
||||||
if (cmdline_tooltype & flag) {
|
if (cmdline_tooltype & flag) {
|
||||||
cmdline_error("option \"%s\" not available in this tool", p);
|
cmdline_report_unavailable(p);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -906,6 +911,15 @@ int cmdline_process_param(const char *p, char *value,
|
|||||||
conf_set_str(conf, CONF_proxy_telnet_command, 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
|
#ifdef _WINDOWS
|
||||||
/*
|
/*
|
||||||
* Cross-tool options only available on Windows.
|
* Cross-tool options only available on Windows.
|
||||||
|
@ -36,6 +36,12 @@ const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat)
|
|||||||
|
|
||||||
bool console_batch_mode = false;
|
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
|
* Error message and/or fatal exit functions, all based on
|
||||||
* console_print_error_msg which the platform front end provides.
|
* console_print_error_msg which the platform front end provides.
|
||||||
|
2
pscp.c
2
pscp.c
@ -2298,8 +2298,6 @@ int psftp_main(int argc, char *argv[])
|
|||||||
version();
|
version();
|
||||||
} else if (strcmp(argv[i], "-ls") == 0) {
|
} else if (strcmp(argv[i], "-ls") == 0) {
|
||||||
list = true;
|
list = true;
|
||||||
} else if (strcmp(argv[i], "-batch") == 0) {
|
|
||||||
console_batch_mode = true;
|
|
||||||
} else if (strcmp(argv[i], "-unsafe") == 0) {
|
} else if (strcmp(argv[i], "-unsafe") == 0) {
|
||||||
scp_unsafe_mode = true;
|
scp_unsafe_mode = true;
|
||||||
} else if (strcmp(argv[i], "-sftp") == 0) {
|
} else if (strcmp(argv[i], "-sftp") == 0) {
|
||||||
|
2
psftp.c
2
psftp.c
@ -2836,8 +2836,6 @@ int psftp_main(int argc, char *argv[])
|
|||||||
} else if (strcmp(argv[i], "-V") == 0 ||
|
} else if (strcmp(argv[i], "-V") == 0 ||
|
||||||
strcmp(argv[i], "--version") == 0) {
|
strcmp(argv[i], "--version") == 0) {
|
||||||
version();
|
version();
|
||||||
} else if (strcmp(argv[i], "-batch") == 0) {
|
|
||||||
console_batch_mode = true;
|
|
||||||
} else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) {
|
||||||
mode = 1;
|
mode = 1;
|
||||||
batchfile = argv[++i];
|
batchfile = argv[++i];
|
||||||
|
2
putty.h
2
putty.h
@ -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.
|
* that aren't equivalents to things in windlg.c et al.
|
||||||
*/
|
*/
|
||||||
extern bool console_batch_mode, console_antispoof_prompt;
|
extern bool console_batch_mode, console_antispoof_prompt;
|
||||||
|
extern bool console_set_batch_mode(bool);
|
||||||
SeatPromptResult console_get_userpass_input(prompts_t *p);
|
SeatPromptResult console_get_userpass_input(prompts_t *p);
|
||||||
bool is_interactive(void);
|
bool is_interactive(void);
|
||||||
void console_print_error_msg(const char *prefix, const char *msg);
|
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_HOST_ARG_FROM_LAUNCHABLE_LOAD) \
|
||||||
X(TOOLTYPE_PORT_ARG) \
|
X(TOOLTYPE_PORT_ARG) \
|
||||||
X(TOOLTYPE_NO_VERBOSE_OPTION) \
|
X(TOOLTYPE_NO_VERBOSE_OPTION) \
|
||||||
|
X(TOOLTYPE_GUI) \
|
||||||
/* end of list */
|
/* end of list */
|
||||||
#define BITFLAG_INDEX(val) val ## _bitflag_index,
|
#define BITFLAG_INDEX(val) val ## _bitflag_index,
|
||||||
enum { TOOLTYPE_LIST(BITFLAG_INDEX) };
|
enum { TOOLTYPE_LIST(BITFLAG_INDEX) };
|
||||||
|
10
stubs/no-console.c
Normal file
10
stubs/no-console.c
Normal 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;
|
||||||
|
}
|
@ -137,6 +137,7 @@ if(GTK_FOUND)
|
|||||||
main-gtk-simple.c
|
main-gtk-simple.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
|
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
|
||||||
|
${CMAKE_SOURCE_DIR}/stubs/no-console.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
||||||
pty.c)
|
pty.c)
|
||||||
be_list(pterm pterm)
|
be_list(pterm pterm)
|
||||||
@ -152,6 +153,7 @@ if(GTK_FOUND)
|
|||||||
${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c
|
${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
|
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c
|
||||||
|
${CMAKE_SOURCE_DIR}/stubs/no-console.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
||||||
pty.c)
|
pty.c)
|
||||||
be_list(ptermapp pterm)
|
be_list(ptermapp pterm)
|
||||||
@ -162,7 +164,8 @@ if(GTK_FOUND)
|
|||||||
|
|
||||||
add_executable(putty
|
add_executable(putty
|
||||||
putty.c
|
putty.c
|
||||||
main-gtk-simple.c)
|
main-gtk-simple.c
|
||||||
|
${CMAKE_SOURCE_DIR}/stubs/no-console.c)
|
||||||
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
|
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
|
||||||
target_link_libraries(putty
|
target_link_libraries(putty
|
||||||
guiterminal eventloop sshclient otherbackends settings
|
guiterminal eventloop sshclient otherbackends settings
|
||||||
@ -176,7 +179,8 @@ if(GTK_FOUND)
|
|||||||
add_executable(puttyapp
|
add_executable(puttyapp
|
||||||
putty.c
|
putty.c
|
||||||
main-gtk-application.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)
|
be_list(puttyapp PuTTY SSH SERIAL OTHERBACKENDS)
|
||||||
target_link_libraries(puttyapp
|
target_link_libraries(puttyapp
|
||||||
guiterminal eventloop sshclient otherbackends settings
|
guiterminal eventloop sshclient otherbackends settings
|
||||||
@ -189,6 +193,7 @@ if(GTK_FOUND)
|
|||||||
main-gtk-simple.c
|
main-gtk-simple.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.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}/stubs/no-rand.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c)
|
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c)
|
||||||
|
@ -735,8 +735,6 @@ int main(int argc, char **argv)
|
|||||||
--argc, ++argv;
|
--argc, ++argv;
|
||||||
} else if (ret == 1) {
|
} else if (ret == 1) {
|
||||||
continue;
|
continue;
|
||||||
} else if (!strcmp(p, "-batch")) {
|
|
||||||
console_batch_mode = true;
|
|
||||||
} else if (!strcmp(p, "-s")) {
|
} else if (!strcmp(p, "-s")) {
|
||||||
/* Save status to write to conf later. */
|
/* Save status to write to conf later. */
|
||||||
use_subsystem = true;
|
use_subsystem = true;
|
||||||
|
@ -101,6 +101,7 @@ add_executable(putty
|
|||||||
window.c
|
window.c
|
||||||
putty.c
|
putty.c
|
||||||
help.c
|
help.c
|
||||||
|
${CMAKE_SOURCE_DIR}/stubs/no-console.c
|
||||||
putty.rc)
|
putty.rc)
|
||||||
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
|
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
|
||||||
add_dependencies(putty generated_licence_h)
|
add_dependencies(putty generated_licence_h)
|
||||||
@ -119,6 +120,7 @@ add_executable(puttytel
|
|||||||
help.c
|
help.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.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}/stubs/no-rand.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
||||||
@ -161,6 +163,7 @@ if(HAVE_CONPTY)
|
|||||||
conpty.c
|
conpty.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
${CMAKE_SOURCE_DIR}/stubs/no-gss.c
|
||||||
${CMAKE_SOURCE_DIR}/stubs/no-ca-config.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}/stubs/no-rand.c
|
||||||
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
|
||||||
pterm.rc)
|
pterm.rc)
|
||||||
|
@ -340,8 +340,6 @@ int main(int argc, char **argv)
|
|||||||
--argc, ++argv;
|
--argc, ++argv;
|
||||||
} else if (ret == 1) {
|
} else if (ret == 1) {
|
||||||
continue;
|
continue;
|
||||||
} else if (!strcmp(p, "-batch")) {
|
|
||||||
console_batch_mode = true;
|
|
||||||
} else if (!strcmp(p, "-s")) {
|
} else if (!strcmp(p, "-s")) {
|
||||||
/* Save status to write to conf later. */
|
/* Save status to write to conf later. */
|
||||||
use_subsystem = true;
|
use_subsystem = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user