1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-04 04:52:47 -05:00

Start using C99 variadic macros.

In the past, I've had a lot of macros which you call with double
parentheses, along the lines of debug(("format string", params)), so
that the inner parens protect the commas and permit the macro to treat
the whole printf-style argument list as one macro argument.

That's all very well, but it's a bit inconvenient (it doesn't leave
you any way to implement such a macro by prepending another argument
to the list), and now this code base's rules allow C99isms, I can
switch all those macros to using a single pair of parens, using the
C99 ability to say '...' in the parameter list of the #define and get
at the corresponding suffix of the arguments as __VA_ARGS__.

So I'm doing it. I've made the following printf-style macros variadic:
bpp_logevent, ppl_logevent, ppl_printf and debug.

While I'm here, I've also fixed up a collection of conditioned-out
calls to debug() in the Windows front end which were clearly expecting
a macro with a different calling syntax, because they had an integer
parameter first. If I ever have a need to condition those back in,
they should actually work now.
This commit is contained in:
Simon Tatham
2018-12-08 20:32:31 +00:00
parent 383a16d5e5
commit e08641c912
26 changed files with 525 additions and 532 deletions

View File

@ -127,7 +127,7 @@ static void mainchan_open_confirmation(Channel *chan)
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
seat_update_specials_menu(mc->ppl->seat);
ppl_logevent(("Opened main channel"));
ppl_logevent("Opened main channel");
if (mc->is_simple)
sshfwd_hint_channel_is_simple(mc->sc);
@ -146,8 +146,8 @@ static void mainchan_open_confirmation(Channel *chan)
if ((x11disp = x11_setup_display(
conf_get_str(mc->conf, CONF_x11_display),
mc->conf, &x11_setup_err)) == NULL) {
ppl_logevent(("X11 forwarding not enabled: unable to"
" initialise X display: %s", x11_setup_err));
ppl_logevent("X11 forwarding not enabled: unable to"
" initialise X display: %s", x11_setup_err);
sfree(x11_setup_err);
} else {
x11auth = ssh_add_x11_display(
@ -178,7 +178,7 @@ static void mainchan_open_confirmation(Channel *chan)
mc->n_req_env++;
}
if (mc->n_req_env)
ppl_logevent(("Sent %d environment variables", mc->n_req_env));
ppl_logevent("Sent %d environment variables", mc->n_req_env);
cmd = conf_get_str(mc->conf, CONF_remote_cmd);
if (conf_get_bool(mc->conf, CONF_ssh_subsys)) {
@ -222,10 +222,10 @@ static void mainchan_request_response(Channel *chan, bool success)
mc->req_x11 = false;
if (success) {
ppl_logevent(("X11 forwarding enabled"));
ppl_logevent("X11 forwarding enabled");
ssh_enable_x_fwd(mc->cl);
} else {
ppl_logevent(("X11 forwarding refused"));
ppl_logevent("X11 forwarding refused");
}
return;
}
@ -234,10 +234,10 @@ static void mainchan_request_response(Channel *chan, bool success)
mc->req_agent = false;
if (success) {
ppl_logevent(("Agent forwarding enabled"));
ppl_logevent("Agent forwarding enabled");
ssh_enable_agent_fwd(mc->cl);
} else {
ppl_logevent(("Agent forwarding refused"));
ppl_logevent("Agent forwarding refused");
}
return;
}
@ -246,11 +246,11 @@ static void mainchan_request_response(Channel *chan, bool success)
mc->req_pty = false;
if (success) {
ppl_logevent(("Allocated pty"));
ppl_logevent("Allocated pty");
mc->got_pty = true;
} else {
ppl_logevent(("Server refused to allocate pty"));
ppl_printf(("Server refused to allocate pty\r\n"));
ppl_logevent("Server refused to allocate pty");
ppl_printf("Server refused to allocate pty\r\n");
ssh_set_ldisc_option(mc->cl, LD_ECHO, true);
ssh_set_ldisc_option(mc->cl, LD_EDIT, true);
}
@ -260,22 +260,22 @@ static void mainchan_request_response(Channel *chan, bool success)
if (mc->n_env_replies < mc->n_req_env) {
int j = mc->n_env_replies++;
if (!success) {
ppl_logevent(("Server refused to set environment variable %s",
conf_get_str_nthstrkey(mc->conf,
CONF_environmt, j)));
ppl_logevent("Server refused to set environment variable %s",
conf_get_str_nthstrkey(mc->conf,
CONF_environmt, j));
mc->n_env_fails++;
}
if (mc->n_env_replies == mc->n_req_env) {
if (mc->n_env_fails == 0) {
ppl_logevent(("All environment variables successfully set"));
ppl_logevent("All environment variables successfully set");
} else if (mc->n_env_fails == mc->n_req_env) {
ppl_logevent(("All environment variables refused"));
ppl_printf(("Server refused to set environment "
"variables\r\n"));
ppl_logevent("All environment variables refused");
ppl_printf("Server refused to set environment "
"variables\r\n");
} else {
ppl_printf(("Server refused to set all environment "
"variables\r\n"));
ppl_printf("Server refused to set all environment "
"variables\r\n");
}
}
return;
@ -285,10 +285,10 @@ static void mainchan_request_response(Channel *chan, bool success)
mc->req_cmd_primary = false;
if (success) {
ppl_logevent(("Started a shell/command"));
ppl_logevent("Started a shell/command");
mainchan_ready(mc);
} else if (*conf_get_str(mc->conf, CONF_remote_cmd2)) {
ppl_logevent(("Primary command failed; attempting fallback"));
ppl_logevent("Primary command failed; attempting fallback");
mainchan_try_fallback_command(mc);
} else {
/*
@ -305,7 +305,7 @@ static void mainchan_request_response(Channel *chan, bool success)
mc->req_cmd_fallback = false;
if (success) {
ppl_logevent(("Started a shell/command"));
ppl_logevent("Started a shell/command");
ssh_got_fallback_cmd(mc->ppl->ssh);
mainchan_ready(mc);
} else {
@ -385,7 +385,7 @@ static void mainchan_send_eof(Channel *chan)
* isn't a particularly meaningful concept.
*/
sshfwd_write_eof(mc->sc);
ppl_logevent(("Sent EOF message"));
ppl_logevent("Sent EOF message");
mc->eof_sent = true;
ssh_set_wants_user_input(mc->cl, false); /* stop reading from stdin */
}
@ -417,7 +417,7 @@ static bool mainchan_rcvd_exit_status(Channel *chan, int status)
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
ssh_got_exitcode(mc->ppl->ssh, status);
ppl_logevent(("Session sent command exit status %d", status));
ppl_logevent("Session sent command exit status %d", status);
return true;
}
@ -430,8 +430,8 @@ static void mainchan_log_exit_signal_common(
const char *core_msg = core_dumped ? " (core dumped)" : "";
const char *msg_pre = (msg.len ? " (" : "");
const char *msg_post = (msg.len ? ")" : "");
ppl_logevent(("Session exited on %s%s%s%.*s%s",
sigdesc, core_msg, msg_pre, PTRLEN_PRINTF(msg), msg_post));
ppl_logevent("Session exited on %s%s%s%.*s%s",
sigdesc, core_msg, msg_pre, PTRLEN_PRINTF(msg), msg_post);
}
static bool mainchan_rcvd_exit_signal(
@ -544,7 +544,7 @@ void mainchan_special_cmd(mainchan *mc, SessionSpecialCode code, int arg)
} else if ((signame = ssh_signal_lookup(code)) != NULL) {
/* It's a signal. */
sshfwd_send_signal(mc->sc, false, signame);
ppl_logevent(("Sent signal SIG%s", signame));
ppl_logevent("Sent signal SIG%s", signame);
}
}