From fb5da46c4826f5bfbbe158c05b88de49e1c3b930 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 2 Feb 2020 10:00:43 +0000 Subject: [PATCH] Make more file-scope variables static. In the previous trawl of this, I didn't bother with the statics in main-program modules, on the grounds that my main aim was to avoid 'library' objects (shared between multiple programs) from polluting the global namespace. But I think it's worth being more strict after all, so this commit adds 'static' to a lot more file-scope variables that aren't needed outside their own module. --- cmdgen.c | 8 ++++---- pscp.c | 2 +- psftp.c | 4 ++-- unix/gtkwin.c | 2 +- unix/uxpgnt.c | 18 +++++++++--------- unix/uxplink.c | 12 ++++++------ windows/window.c | 6 +++--- windows/winplink.c | 12 ++++++------ 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cmdgen.c b/cmdgen.c index 8e2d07a5..a6dd1991 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -34,7 +34,7 @@ * I define another main() which calls the former repeatedly to * run tests. */ -bool cgtest_verbose = false; +static bool cgtest_verbose = false; #define get_random_data get_random_data_diagnostic char *get_random_data(int len, const char *device) { @@ -43,8 +43,8 @@ char *get_random_data(int len, const char *device) return buf; } #define console_get_userpass_input console_get_userpass_input_diagnostic -int nprompts, promptsgot; -const char *prompts[3]; +static int nprompts, promptsgot; +static const char *prompts[3]; int console_get_userpass_input(prompts_t *p) { size_t i; @@ -1118,7 +1118,7 @@ int main(int argc, char **argv) #include -int passes, fails; +static int passes, fails; void setup_passphrases(char *first, ...) { diff --git a/pscp.c b/pscp.c index f17eb983..0fde461f 100644 --- a/pscp.c +++ b/pscp.c @@ -43,7 +43,7 @@ static bool uploading = false; static Backend *backend; static Conf *conf; -bool sent_eof = false; +static bool sent_eof = false; static void source(const char *src); static void rsource(const char *src); diff --git a/psftp.c b/psftp.c index cb1657b1..c30e6fbd 100644 --- a/psftp.c +++ b/psftp.c @@ -31,11 +31,11 @@ static void do_sftp_cleanup(void); * sftp client state. */ -char *pwd, *homedir; +static char *pwd, *homedir; static LogContext *psftp_logctx = NULL; static Backend *backend; static Conf *conf; -bool sent_eof = false; +static bool sent_eof = false; /* ------------------------------------------------------------ * Seat vtable. diff --git a/unix/gtkwin.c b/unix/gtkwin.c index b8571776..edd620bc 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -49,7 +49,7 @@ #define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS) GdkAtom compound_text_atom, utf8_string_atom; -GdkAtom clipboard_atom +static GdkAtom clipboard_atom #if GTK_CHECK_VERSION(2,0,0) /* GTK1 will have to fill this in at startup */ = GDK_SELECTION_CLIPBOARD #endif diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 5743795a..594fd716 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -28,7 +28,7 @@ void cmdline_error(const char *fmt, ...) exit(1); } -FILE *pageant_logfp = NULL; +static FILE *pageant_logfp = NULL; struct uxpgnt_client { PageantListenerClient plc; @@ -173,7 +173,7 @@ struct X11Connection { Plug plug; }; -char *socketname; +static char *socketname; static enum { SHELL_AUTO, SHELL_SH, SHELL_CSH } shell_type = SHELL_AUTO; void pageant_print_env(int pid) { @@ -256,7 +256,7 @@ void pageant_fork_and_print_env(bool retain_tty) } } -int signalpipe[2]; +static int signalpipe[2]; void sigchld(int signum) { @@ -265,7 +265,7 @@ void sigchld(int signum) } #define TTY_LIFE_POLL_INTERVAL (TICKSPERSEC * 30) -void *dummy_timer_ctx; +static void *dummy_timer_ctx; static void tty_life_timer(void *ctx, unsigned long now) { schedule_timer(TTY_LIFE_POLL_INTERVAL, tty_life_timer, &dummy_timer_ctx); @@ -291,7 +291,7 @@ bool is_agent_action(keyact action) return action == KEYACT_AGENT_LOAD; } -struct cmdline_key_action *keyact_head = NULL, *keyact_tail = NULL; +static struct cmdline_key_action *keyact_head = NULL, *keyact_tail = NULL; void add_keyact(keyact action, const char *filename) { @@ -321,12 +321,12 @@ bool have_controlling_tty(void) } } -char **exec_args = NULL; -enum { +static char **exec_args = NULL; +static enum { LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC } life = LIFE_UNSPEC; -const char *display = NULL; -enum { +static const char *display = NULL; +static enum { PROMPT_UNSPEC, PROMPT_TTY, PROMPT_GUI } prompt_type = PROMPT_UNSPEC; diff --git a/unix/uxplink.c b/unix/uxplink.c index 10f33548..a341d88b 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -315,12 +315,12 @@ void cleanup_termios(void) tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); } -bufchain stdout_data, stderr_data; -bufchain_sink stdout_bcs, stderr_bcs; -StripCtrlChars *stdout_scc, *stderr_scc; -BinarySink *stdout_bs, *stderr_bs; +static bufchain stdout_data, stderr_data; +static bufchain_sink stdout_bcs, stderr_bcs; +static StripCtrlChars *stdout_scc, *stderr_scc; +static BinarySink *stdout_bs, *stderr_bs; -enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; +static enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; size_t try_output(bool is_stderr) { @@ -476,7 +476,7 @@ static void from_tty(void *vbuf, unsigned len) } } -int signalpipe[2]; +static int signalpipe[2]; void sigwinch(int signum) { diff --git a/windows/window.c b/windows/window.c index 42289bee..9e60984d 100644 --- a/windows/window.c +++ b/windows/window.c @@ -156,8 +156,8 @@ struct wm_netevent_params { }; static void conf_cache_data(void); -int cursor_type; -int vtmode; +static int cursor_type; +static int vtmode; static struct sesslist sesslist; /* for saved-session menu */ @@ -192,7 +192,7 @@ static int descent; #define NEXTCOLOURS 240 #define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS) static COLORREF colours[NALLCOLOURS]; -struct rgb { +static struct rgb { int r, g, b; } colours_rgb[NALLCOLOURS]; static HPALETTE pal; diff --git a/windows/winplink.c b/windows/winplink.c index fa56c1e7..47f27c58 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -21,12 +21,12 @@ void cmdline_error(const char *fmt, ...) exit(1); } -HANDLE inhandle, outhandle, errhandle; -struct handle *stdin_handle, *stdout_handle, *stderr_handle; -handle_sink stdout_hs, stderr_hs; -StripCtrlChars *stdout_scc, *stderr_scc; -BinarySink *stdout_bs, *stderr_bs; -DWORD orig_console_mode; +static HANDLE inhandle, outhandle, errhandle; +static struct handle *stdin_handle, *stdout_handle, *stderr_handle; +static handle_sink stdout_hs, stderr_hs; +static StripCtrlChars *stdout_scc, *stderr_scc; +static BinarySink *stdout_bs, *stderr_bs; +static DWORD orig_console_mode; static Backend *backend; static LogContext *logctx;