Miscellaneous fixes to finish up `remove-statics'. rlogin.c had a
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 14 Jan 2003 18:43:45 +0000 (18:43 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 14 Jan 2003 18:43:45 +0000 (18:43 +0000)
holdout static I hadn't noticed; unicode.c had one too; and a large
number of statics that were perfectly OK due to being constants have
been made `const', with assorted `const' repercussions all over the
place. I now declare `remove-statics' to be fixed.

git-svn-id: svn://svn.tartarus.org/sgt/putty@2594 cda61777-01e9-0310-a592-d414129be87e

14 files changed:
portfwd.c
putty.h
rlogin.c
settings.c
storage.h
telnet.c
unicode.c
unix/pterm.c
unix/unix.h
unix/uxplink.c
unix/uxstore.c
windefs.c
winnet.c
winstore.c

index e1499de..1143714 100644 (file)
--- a/portfwd.c
+++ b/portfwd.c
@@ -57,7 +57,7 @@ struct pfwd_queue {
 };
 
 struct PFwdPrivate {
-    struct plug_function_table *fn;
+    const struct plug_function_table *fn;
     /* the above variable absolutely *must* be the first in this structure */
     void *c;                          /* (channel) data used by ssh.c */
     void *backhandle;                 /* instance of SSH backend itself */
@@ -111,7 +111,7 @@ static void pfd_sent(Plug plug, int bufsize)
 char *pfd_newconnect(Socket *s, char *hostname, int port, void *c,
                     const Config *cfg)
 {
-    static struct plug_function_table fn_table = {
+    static const struct plug_function_table fn_table = {
        pfd_closing,
        pfd_receive,
        pfd_sent,
@@ -157,7 +157,7 @@ char *pfd_newconnect(Socket *s, char *hostname, int port, void *c,
 
 static int pfd_accepting(Plug p, void *sock)
 {
-    static struct plug_function_table fn_table = {
+    static const struct plug_function_table fn_table = {
        pfd_closing,
        pfd_receive,
        pfd_sent,
@@ -208,7 +208,7 @@ static int pfd_accepting(Plug p, void *sock)
 char *pfd_addforward(char *desthost, int destport, char *srcaddr, int port,
                     void *backhandle, const Config *cfg)
 {
-    static struct plug_function_table fn_table = {
+    static const struct plug_function_table fn_table = {
        pfd_closing,
        pfd_receive,                   /* should not happen... */
        pfd_sent,                      /* also should not happen */
diff --git a/putty.h b/putty.h
index 12944ed..7f0f781 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -493,8 +493,8 @@ void registry_cleanup(void);
  * which I can reliably set aside to indicate `nil'. The string
  * function is perfectly all right returning NULL, of course.)
  */
-char *platform_default_s(char *name);
-int platform_default_i(char *name, int def);
+char *platform_default_s(const char *name);
+int platform_default_i(const char *name, int def);
 
 /*
  * Exports from terminal.c.
index 8e5e628..ff2af31 100644 (file)
--- a/rlogin.c
+++ b/rlogin.c
@@ -19,6 +19,7 @@ typedef struct rlogin_tag {
 
     Socket s;
     int bufsize;
+    int firstbyte;
     int term_width, term_height;
     void *frontend;
 } *Rlogin;
@@ -69,13 +70,12 @@ static int rlogin_receive(Plug plug, int urgent, char *data, int len)
         * byte is expected to be NULL and is ignored, and the rest
         * is printed.
         */
-       static int firstbyte = 1;
-       if (firstbyte) {
+       if (rlogin->firstbyte) {
            if (data[0] == '\0') {
                data++;
                len--;
            }
-           firstbyte = 0;
+           rlogin->firstbyte = 0;
        }
        if (len > 0)
             c_write(rlogin, data, len);
@@ -116,6 +116,7 @@ static char *rlogin_init(void *frontend_handle, void **backend_handle,
     rlogin->frontend = frontend_handle;
     rlogin->term_width = cfg->width;
     rlogin->term_height = cfg->height;
+    rlogin->firstbyte = 1;
     *backend_handle = rlogin;
 
     /*
index 6827eb3..ed9007d 100644 (file)
@@ -20,7 +20,8 @@ static const struct keyval ciphernames[] = {
     { "des",       CIPHER_DES }
 };
 
-static void gpps(void *handle, char *name, char *def, char *val, int len)
+static void gpps(void *handle, const char *name, const char *def,
+                char *val, int len)
 {
     if (!read_setting_s(handle, name, val, len)) {
        char *pdef;
@@ -518,7 +519,7 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg)
     gppi(sesskey, "TryPalette", 0, &cfg->try_palette);
     gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour);
     for (i = 0; i < 22; i++) {
-       static char *defaults[] = {
+       static const char *const defaults[] = {
            "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
            "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
            "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
@@ -541,7 +542,7 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg)
     gppi(sesskey, "RectSelect", 0, &cfg->rect_select);
     gppi(sesskey, "MouseOverride", 1, &cfg->mouse_override);
     for (i = 0; i < 256; i += 32) {
-       static char *defaults[] = {
+       static const char *const defaults[] = {
            "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
            "0,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1",
            "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2",
index 1b71627..46e6350 100644 (file)
--- a/storage.h
+++ b/storage.h
@@ -26,9 +26,9 @@
  * Keys may be up to 255 characters long.  String values have no length
  * limit.
  */
-void *open_settings_w(char *sessionname);
-void write_setting_s(void *handle, char *key, char *value);
-void write_setting_i(void *handle, char *key, int value);
+void *open_settings_w(const char *sessionname);
+void write_setting_s(void *handle, const char *key, const char *value);
+void write_setting_i(void *handle, const char *key, int value);
 void close_settings_w(void *handle);
 
 /*
@@ -45,15 +45,15 @@ void close_settings_w(void *handle);
  * should invent a sensible default. If an integer setting is not
  * present, read_setting_i() returns its provided default.
  */
-void *open_settings_r(char *sessionname);
-char *read_setting_s(void *handle, char *key, char *buffer, int buflen);
-int read_setting_i(void *handle, char *key, int defvalue);
+void *open_settings_r(const char *sessionname);
+char *read_setting_s(void *handle, const char *key, char *buffer, int buflen);
+int read_setting_i(void *handle, const char *key, int defvalue);
 void close_settings_r(void *handle);
 
 /*
  * Delete a whole saved session.
  */
-void del_settings(char *sessionname);
+void del_settings(const char *sessionname);
 
 /*
  * Enumerate all saved sessions.
@@ -71,13 +71,15 @@ void enum_settings_finish(void *handle);
  * be 0 (entry matches database), 1 (entry is absent in database),
  * or 2 (entry exists in database and is different).
  */
-int verify_host_key(char *hostname, int port, char *keytype, char *key);
+int verify_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key);
 
 /*
  * Write a host key into the database, overwriting any previous
  * entry that might have been there.
  */
-void store_host_key(char *hostname, int port, char *keytype, char *key);
+void store_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key);
 
 /* ----------------------------------------------------------------------
  * Functions to access PuTTY's random number seed file.
index 53ad180..91d0cab 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -758,10 +758,10 @@ static int telnet_send(void *handle, char *buf, int len)
 {
     Telnet telnet = (Telnet) handle;
     unsigned char *p, *end;
-    static unsigned char iac[2] = { IAC, IAC };
-    static unsigned char cr[2] = { CR, NUL };
+    static const unsigned char iac[2] = { IAC, IAC };
+    static const unsigned char cr[2] = { CR, NUL };
 #if 0
-    static unsigned char nl[2] = { CR, LF };
+    static const unsigned char nl[2] = { CR, LF };
 #endif
 
     if (telnet->s == NULL)
index fdfa08d..24dfd44 100644 (file)
--- a/unicode.c
+++ b/unicode.c
@@ -560,11 +560,11 @@ void init_ucs(Config *cfg, struct unicode_data *ucsdata)
 
     /* Last chance, if !unicode then try poorman links. */
     if (cfg->vtmode != VT_UNICODE) {
-       static char poorman_scoacs[] = 
+       static const char poorman_scoacs[] = 
            "CueaaaaceeeiiiAAE**ooouuyOUc$YPsaiounNao?++**!<>###||||++||++++++--|-+||++--|-+----++++++++##||#aBTPEsyt******EN=+><++-=... n2* ";
-       static char poorman_latin1[] =
+       static const char poorman_latin1[] =
            " !cL.Y|S\"Ca<--R~o+23'u|.,1o>///?AAAAAAACEEEEIIIIDNOOOOOxOUUUUYPBaaaaaaaceeeeiiiionooooo/ouuuuypy";
-       static char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
+       static const char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
 
        for (i = 160; i < 256; i++)
            if (!DIRECT_FONT(ucsdata->unitab_line[i]) &&
@@ -603,7 +603,7 @@ static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr)
 
 wchar_t xlat_uskbd2cyrllic(int ch)
 {
-    static wchar_t cyrtab[] = {
+    static const wchar_t cyrtab[] = {
             0,      1,       2,      3,      4,      5,      6,      7,
             8,      9,      10,     11,     12,     13,     14,     15,
             16,     17,     18,     19,     20,     21,     22,     23,
@@ -624,10 +624,10 @@ wchar_t xlat_uskbd2cyrllic(int ch)
     return cyrtab[ch&0x7F];
 }
 
-int check_compose(int first, int second)
+int check_compose_internal(int first, int second, int recurse)
 {
 
-    static struct {
+    static const struct {
        char first, second;
        wchar_t composed;
     } composetbl[] = {
@@ -961,7 +961,6 @@ int check_compose(int first, int second)
        0, 0, 0}
     }, *c;
 
-    static int recurse = 0;
     int nc = -1;
 
     for (c = composetbl; c->first; c++) {
@@ -970,17 +969,20 @@ int check_compose(int first, int second)
     }
 
     if (recurse == 0) {
-       recurse = 1;
-       nc = check_compose(second, first);
+       nc = check_compose_internal(second, first, 1);
        if (nc == -1)
-           nc = check_compose(toupper(first), toupper(second));
+           nc = check_compose(toupper(first), toupper(second), 1);
        if (nc == -1)
-           nc = check_compose(toupper(second), toupper(first));
-       recurse = 0;
+           nc = check_compose(toupper(second), toupper(first), 1);
     }
     return nc;
 }
 
+int check_compose(int first, int second)
+{
+    return check_compose_internal(first, second, 0);
+}
+
 int decode_codepage(char *cp_name)
 {
     char *s, *d;
index c207195..402a4e7 100644 (file)
@@ -80,7 +80,7 @@ static int send_raw_mouse;
 
 static char *app_name = "pterm";
 
-char *x_get_default(char *key)
+char *x_get_default(const char *key)
 {
     return XGetDefault(GDK_DISPLAY(), app_name, key);
 }
@@ -88,14 +88,14 @@ char *x_get_default(char *key)
 /*
  * Default settings that are specific to pterm.
  */
-char *platform_default_s(char *name)
+char *platform_default_s(const char *name)
 {
     if (!strcmp(name, "Font"))
        return "fixed";        /* COE_NORMAL works badly in an xterm */
     return NULL;
 }
 
-int platform_default_i(char *name, int def)
+int platform_default_i(const char *name, int def)
 {
     if (!strcmp(name, "CloseOnExit"))
        return COE_ALWAYS;             /* COE_NORMAL works badly in an xterm */
index 65f374d..abe8cfd 100644 (file)
@@ -39,7 +39,7 @@ char *get_x_display(void *frontend);
 int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */
 
 /* Things uxstore.c needs from pterm.c */
-char *x_get_default(char *key);
+char *x_get_default(const char *key);
 
 /* Things uxstore.c provides to pterm.c */
 void provide_xrm_string(char *string);
index eda68d2..2778bc5 100644 (file)
@@ -77,7 +77,7 @@ static Config cfg;
 /*
  * Default settings that are specific to pterm.
  */
-char *platform_default_s(char *name)
+char *platform_default_s(const char *name)
 {
     if (!strcmp(name, "X11Display"))
        return getenv("DISPLAY");
@@ -125,7 +125,7 @@ char *platform_default_s(char *name)
     return NULL;
 }
 
-int platform_default_i(char *name, int def)
+int platform_default_i(const char *name, int def)
 {
     if (!strcmp(name, "TermWidth") ||
        !strcmp(name, "TermHeight")) {
@@ -136,7 +136,7 @@ int platform_default_i(char *name, int def)
     return def;
 }
 
-char *x_get_default(char *key)
+char *x_get_default(const char *key)
 {
     return NULL;                      /* this is a stub */
 }
index 670c67b..10e33c0 100644 (file)
  * file somewhere or other.
  */
 
-void *open_settings_w(char *sessionname)
+void *open_settings_w(const char *sessionname)
 {
     return NULL;
 }
 
-void write_setting_s(void *handle, char *key, char *value)
+void write_setting_s(void *handle, const char *key, const char *value)
 {
 }
 
-void write_setting_i(void *handle, char *key, int value)
+void write_setting_i(void *handle, const char *key, int value)
 {
 }
 
@@ -48,8 +48,8 @@ void close_settings_w(void *handle)
  */
 
 struct xrm_string {
-    char *key;
-    char *value;
+    const char *key;
+    const char *value;
 };
 
 static tree234 *xrmtree = NULL;
@@ -63,7 +63,7 @@ int xrmcmp(void *av, void *bv)
 
 void provide_xrm_string(char *string)
 {
-    char *p, *q;
+    char *p, *q, *key;
     struct xrm_string *xrms, *ret;
 
     p = q = strchr(string, ':');
@@ -76,9 +76,10 @@ void provide_xrm_string(char *string)
     while (p > string && p[-1] != '.' && p[-1] != '*')
        p--;
     xrms = smalloc(sizeof(struct xrm_string));
-    xrms->key = smalloc(q-p);
-    memcpy(xrms->key, p, q-p);
-    xrms->key[q-p-1] = '\0';
+    key = smalloc(q-p);
+    memcpy(key, p, q-p);
+    key[q-p-1] = '\0';
+    xrms->key = key;
     while (*q && isspace(*q))
        q++;
     xrms->value = dupstr(q);
@@ -94,7 +95,7 @@ void provide_xrm_string(char *string)
     }
 }
 
-char *get_setting(char *key)
+const char *get_setting(const char *key)
 {
     struct xrm_string tmp, *ret;
     tmp.key = key;
@@ -106,15 +107,15 @@ char *get_setting(char *key)
     return x_get_default(key);
 }
 
-void *open_settings_r(char *sessionname)
+void *open_settings_r(const char *sessionname)
 {
     static int thing_to_return_an_arbitrary_non_null_pointer_to;
     return &thing_to_return_an_arbitrary_non_null_pointer_to;
 }
 
-char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
+char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
 {
-    char *val = get_setting(key);
+    const char *val = get_setting(key);
     if (!val)
        return NULL;
     else {
@@ -124,9 +125,9 @@ char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
     }
 }
 
-int read_setting_i(void *handle, char *key, int defvalue)
+int read_setting_i(void *handle, const char *key, int defvalue)
 {
-    char *val = get_setting(key);
+    const char *val = get_setting(key);
     if (!val)
        return defvalue;
     else
@@ -137,7 +138,7 @@ void close_settings_r(void *handle)
 {
 }
 
-void del_settings(char *sessionname)
+void del_settings(const char *sessionname)
 {
 }
 
@@ -206,7 +207,8 @@ static char *fgetline(FILE *fp)
  * 
  *   rsa@22:foovax.example.org 0x23,0x293487364395345345....2343
  */
-int verify_host_key(char *hostname, int port, char *keytype, char *key)
+int verify_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key)
 {
     FILE *fp;
     char filename[FILENAME_MAX];
@@ -272,7 +274,8 @@ int verify_host_key(char *hostname, int port, char *keytype, char *key)
     return ret;
 }
 
-void store_host_key(char *hostname, int port, char *keytype, char *key)
+void store_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key)
 {
     FILE *fp;
     int fd;
index 88e9fe6..80e186d 100644 (file)
--- a/windefs.c
+++ b/windefs.c
 
 #include "putty.h"
 
-char *platform_default_s(char *name)
+char *platform_default_s(const char *name)
 {
     if (!strcmp(name, "Font"))
        return "Courier New";
     return NULL;
 }
 
-int platform_default_i(char *name, int def)
+int platform_default_i(const char *name, int def)
 {
     if (!strcmp(name, "FontCharSet"))
        return ANSI_CHARSET;
index 56d1500..f617b0f 100644 (file)
--- a/winnet.c
+++ b/winnet.c
@@ -59,7 +59,7 @@
        ((ntohl(addr.s_addr) & 0xFF000000L) == 0x7F000000L)
 
 struct Socket_tag {
-    struct socket_function_table *fn;
+    const struct socket_function_table *fn;
     /* the above variable absolutely *must* be the first in this structure */
     char *error;
     SOCKET s;
@@ -471,7 +471,7 @@ extern char *do_select(SOCKET skt, int startup);
 
 Socket sk_register(void *sock, Plug plug)
 {
-    static struct socket_function_table fn_table = {
+    static const struct socket_function_table fn_table = {
        sk_tcp_plug,
        sk_tcp_close,
        sk_tcp_write,
@@ -528,7 +528,7 @@ Socket sk_register(void *sock, Plug plug)
 Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
              int nodelay, Plug plug)
 {
-    static struct socket_function_table fn_table = {
+    static const struct socket_function_table fn_table = {
        sk_tcp_plug,
        sk_tcp_close,
        sk_tcp_write,
@@ -706,7 +706,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
 
 Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
 {
-    static struct socket_function_table fn_table = {
+    static const struct socket_function_table fn_table = {
        sk_tcp_plug,
        sk_tcp_close,
        sk_tcp_write,
index bc7bb5b..3199c1c 100644 (file)
@@ -13,9 +13,9 @@ static const char *const puttystr = PUTTY_REG_POS "\\Sessions";
 
 static char seedpath[2 * MAX_PATH + 10] = "\0";
 
-static char hex[16] = "0123456789ABCDEF";
+static const char hex[16] = "0123456789ABCDEF";
 
-static void mungestr(char *in, char *out)
+static void mungestr(const char *in, char *out)
 {
     int candot = 0;
 
@@ -35,7 +35,7 @@ static void mungestr(char *in, char *out)
     return;
 }
 
-static void unmungestr(char *in, char *out, int outlen)
+static void unmungestr(const char *in, char *out, int outlen)
 {
     while (*in) {
        if (*in == '%' && in[1] && in[2]) {
@@ -60,7 +60,7 @@ static void unmungestr(char *in, char *out, int outlen)
     return;
 }
 
-void *open_settings_w(char *sessionname)
+void *open_settings_w(const char *sessionname)
 {
     HKEY subkey1, sesskey;
     int ret;
@@ -82,14 +82,14 @@ void *open_settings_w(char *sessionname)
     return (void *) sesskey;
 }
 
-void write_setting_s(void *handle, char *key, char *value)
+void write_setting_s(void *handle, const char *key, const char *value)
 {
     if (handle)
        RegSetValueEx((HKEY) handle, key, 0, REG_SZ, value,
                      1 + strlen(value));
 }
 
-void write_setting_i(void *handle, char *key, int value)
+void write_setting_i(void *handle, const char *key, int value)
 {
     if (handle)
        RegSetValueEx((HKEY) handle, key, 0, REG_DWORD,
@@ -101,7 +101,7 @@ void close_settings_w(void *handle)
     RegCloseKey((HKEY) handle);
 }
 
-void *open_settings_r(char *sessionname)
+void *open_settings_r(const char *sessionname)
 {
     HKEY subkey1, sesskey;
     char *p;
@@ -123,7 +123,7 @@ void *open_settings_r(char *sessionname)
     return (void *) sesskey;
 }
 
-char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
+char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
 {
     DWORD type, size;
     size = buflen;
@@ -136,7 +136,7 @@ char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
        return buffer;
 }
 
-int read_setting_i(void *handle, char *key, int defvalue)
+int read_setting_i(void *handle, const char *key, int defvalue)
 {
     DWORD type, val, size;
     size = sizeof(val);
@@ -155,7 +155,7 @@ void close_settings_r(void *handle)
     RegCloseKey((HKEY) handle);
 }
 
-void del_settings(char *sessionname)
+void del_settings(const char *sessionname)
 {
     HKEY subkey1;
     char *p;
@@ -215,8 +215,8 @@ void enum_settings_finish(void *handle)
     sfree(e);
 }
 
-static void hostkey_regname(char *buffer, char *hostname,
-                           int port, char *keytype)
+static void hostkey_regname(char *buffer, const char *hostname,
+                           int port, const char *keytype)
 {
     int len;
     strcpy(buffer, keytype);
@@ -226,7 +226,8 @@ static void hostkey_regname(char *buffer, char *hostname,
     mungestr(hostname, buffer + strlen(buffer));
 }
 
-int verify_host_key(char *hostname, int port, char *keytype, char *key)
+int verify_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key)
 {
     char *otherstr, *regname;
     int len;
@@ -331,7 +332,8 @@ int verify_host_key(char *hostname, int port, char *keytype, char *key)
        return 0;                      /* key matched OK in registry */
 }
 
-void store_host_key(char *hostname, int port, char *keytype, char *key)
+void store_host_key(const char *hostname, int port,
+                   const char *keytype, const char *key)
 {
     char *regname;
     HKEY rkey;