Expose the Ldisc structure tag throughout the code.

That's one fewer anonymous 'void *' which might be accidentally
confused with some other pointer type if I misremember the order of
function arguments.

While I'm here, I've made its pointer-nature explicit - that is,
'Ldisc' is now a typedef for the structure type itself rather than a
pointer to it. A stylistic change only, but it feels more natural to
me these days for a thing you're going to eventually pass to a 'free'
function.
This commit is contained in:
Simon Tatham 2018-09-11 15:02:59 +01:00
Родитель 566d4826f4
Коммит e72e8ebe59
19 изменённых файлов: 43 добавлений и 49 удалений

2
defs.h
Просмотреть файл

@ -44,6 +44,8 @@ typedef struct SockAddr_tag *SockAddr;
typedef struct Socket_vtable Socket_vtable; typedef struct Socket_vtable Socket_vtable;
typedef struct Plug_vtable Plug_vtable; typedef struct Plug_vtable Plug_vtable;
typedef struct Ldisc_tag Ldisc;
/* Note indirection: for historical reasons (it used to be closer to /* Note indirection: for historical reasons (it used to be closer to
* the OS socket type), the type that most code uses for a socket is * the OS socket type), the type that most code uses for a socket is
* 'Socket', not 'Socket *'. So an implementation of Socket or Plug * 'Socket', not 'Socket *'. So an implementation of Socket or Plug

Просмотреть файл

@ -71,8 +71,8 @@ void set_title(void *frontend, char *t) { }
void set_icon(void *frontend, char *t) { } void set_icon(void *frontend, char *t) { }
void set_sbar(void *frontend, int a, int b, int c) { } void set_sbar(void *frontend, int a, int b, int c) { }
void ldisc_send(void *handle, const void *buf, int len, int interactive) {} void ldisc_send(Ldisc *ldisc, const void *buf, int len, int interactive) {}
void ldisc_echoedit_update(void *handle) {} void ldisc_echoedit_update(Ldisc *ldisc) {}
Context get_ctx(void *frontend) { Context get_ctx(void *frontend) {
static char x; static char x;

28
ldisc.c
Просмотреть файл

@ -22,12 +22,12 @@
(ldisc->back->ldisc(ldisc->backhandle, LD_EDIT) || \ (ldisc->back->ldisc(ldisc->backhandle, LD_EDIT) || \
term_ldisc(ldisc->term, LD_EDIT)))) term_ldisc(ldisc->term, LD_EDIT))))
static void c_write(Ldisc ldisc, const void *buf, int len) static void c_write(Ldisc *ldisc, const void *buf, int len)
{ {
from_backend(ldisc->frontend, 0, buf, len); from_backend(ldisc->frontend, 0, buf, len);
} }
static int plen(Ldisc ldisc, unsigned char c) static int plen(Ldisc *ldisc, unsigned char c)
{ {
if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf(ldisc->term))) if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf(ldisc->term)))
return 1; return 1;
@ -42,7 +42,7 @@ static int plen(Ldisc ldisc, unsigned char c)
return 4; /* <XY> hex representation */ return 4; /* <XY> hex representation */
} }
static void pwrite(Ldisc ldisc, unsigned char c) static void pwrite(Ldisc *ldisc, unsigned char c)
{ {
if ((c >= 32 && c <= 126) || if ((c >= 32 && c <= 126) ||
(!in_utf(ldisc->term) && c >= 0xA0) || (!in_utf(ldisc->term) && c >= 0xA0) ||
@ -60,7 +60,7 @@ static void pwrite(Ldisc ldisc, unsigned char c)
} }
} }
static int char_start(Ldisc ldisc, unsigned char c) static int char_start(Ldisc *ldisc, unsigned char c)
{ {
if (in_utf(ldisc->term)) if (in_utf(ldisc->term))
return (c < 0x80 || c >= 0xC0); return (c < 0x80 || c >= 0xC0);
@ -68,7 +68,7 @@ static int char_start(Ldisc ldisc, unsigned char c)
return 1; return 1;
} }
static void bsb(Ldisc ldisc, int n) static void bsb(Ldisc *ldisc, int n)
{ {
while (n--) while (n--)
c_write(ldisc, "\010 \010", 3); c_write(ldisc, "\010 \010", 3);
@ -77,11 +77,11 @@ static void bsb(Ldisc ldisc, int n)
#define CTRL(x) (x^'@') #define CTRL(x) (x^'@')
#define KCTRL(x) ((x^'@') | 0x100) #define KCTRL(x) ((x^'@') | 0x100)
void *ldisc_create(Conf *conf, Terminal *term, Ldisc *ldisc_create(Conf *conf, Terminal *term,
Backend *back, void *backhandle, Backend *back, void *backhandle,
void *frontend) void *frontend)
{ {
Ldisc ldisc = snew(struct ldisc_tag); Ldisc *ldisc = snew(Ldisc);
ldisc->buf = NULL; ldisc->buf = NULL;
ldisc->buflen = 0; ldisc->buflen = 0;
@ -104,10 +104,8 @@ void *ldisc_create(Conf *conf, Terminal *term,
return ldisc; return ldisc;
} }
void ldisc_configure(void *handle, Conf *conf) void ldisc_configure(Ldisc *ldisc, Conf *conf)
{ {
Ldisc ldisc = (Ldisc) handle;
ldisc->telnet_keyboard = conf_get_int(conf, CONF_telnet_keyboard); ldisc->telnet_keyboard = conf_get_int(conf, CONF_telnet_keyboard);
ldisc->telnet_newline = conf_get_int(conf, CONF_telnet_newline); ldisc->telnet_newline = conf_get_int(conf, CONF_telnet_newline);
ldisc->protocol = conf_get_int(conf, CONF_protocol); ldisc->protocol = conf_get_int(conf, CONF_protocol);
@ -115,10 +113,8 @@ void ldisc_configure(void *handle, Conf *conf)
ldisc->localedit = conf_get_int(conf, CONF_localedit); ldisc->localedit = conf_get_int(conf, CONF_localedit);
} }
void ldisc_free(void *handle) void ldisc_free(Ldisc *ldisc)
{ {
Ldisc ldisc = (Ldisc) handle;
if (ldisc->term) if (ldisc->term)
ldisc->term->ldisc = NULL; ldisc->term->ldisc = NULL;
if (ldisc->back) if (ldisc->back)
@ -128,16 +124,14 @@ void ldisc_free(void *handle)
sfree(ldisc); sfree(ldisc);
} }
void ldisc_echoedit_update(void *handle) void ldisc_echoedit_update(Ldisc *ldisc)
{ {
Ldisc ldisc = (Ldisc) handle;
frontend_echoedit_update(ldisc->frontend, ECHOING, EDITING); frontend_echoedit_update(ldisc->frontend, ECHOING, EDITING);
} }
void ldisc_send(void *handle, const void *vbuf, int len, int interactive) void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, int interactive)
{ {
const char *buf = (const char *)vbuf; const char *buf = (const char *)vbuf;
Ldisc ldisc = (Ldisc) handle;
int keyflag = 0; int keyflag = 0;
assert(ldisc->term); assert(ldisc->term);

Просмотреть файл

@ -8,7 +8,7 @@
#ifndef PUTTY_LDISC_H #ifndef PUTTY_LDISC_H
#define PUTTY_LDISC_H #define PUTTY_LDISC_H
typedef struct ldisc_tag { struct Ldisc_tag {
Terminal *term; Terminal *term;
Backend *back; Backend *back;
void *backhandle; void *backhandle;
@ -21,6 +21,6 @@ typedef struct ldisc_tag {
char *buf; char *buf;
int buflen, bufsiz, quotenext; int buflen, bufsiz, quotenext;
} *Ldisc; };
#endif /* PUTTY_LDISC_H */ #endif /* PUTTY_LDISC_H */

Просмотреть файл

@ -12,10 +12,9 @@
#include "terminal.h" #include "terminal.h"
#include "ldisc.h" #include "ldisc.h"
void lpage_send(void *handle, void lpage_send(Ldisc *ldisc,
int codepage, const char *buf, int len, int interactive) int codepage, const char *buf, int len, int interactive)
{ {
Ldisc ldisc = (Ldisc)handle;
wchar_t *widebuffer = 0; wchar_t *widebuffer = 0;
int widesize = 0; int widesize = 0;
int wclen; int wclen;
@ -34,9 +33,8 @@ void lpage_send(void *handle,
sfree(widebuffer); sfree(widebuffer);
} }
void luni_send(void *handle, const wchar_t *widebuf, int len, int interactive) void luni_send(Ldisc *ldisc, const wchar_t *widebuf, int len, int interactive)
{ {
Ldisc ldisc = (Ldisc)handle;
int ratio = (in_utf(ldisc->term))?3:1; int ratio = (in_utf(ldisc->term))?3:1;
char *linebuffer; char *linebuffer;
int linesize; int linesize;

2
pscp.c
Просмотреть файл

@ -60,7 +60,7 @@ const char *const appname = "PSCP";
*/ */
#define MAX_SCP_BUFSIZE 16384 #define MAX_SCP_BUFSIZE 16384
void ldisc_echoedit_update(void *handle) { } void ldisc_echoedit_update(Ldisc *ldisc) { }
static void tell_char(FILE *stream, char c) static void tell_char(FILE *stream, char c)
{ {

Просмотреть файл

@ -2483,7 +2483,7 @@ void connection_fatal(void *frontend, const char *fmt, ...)
cleanup_exit(1); cleanup_exit(1);
} }
void ldisc_echoedit_update(void *handle) { } void ldisc_echoedit_update(Ldisc *ldisc) { }
/* /*
* In psftp, all agent requests should be synchronous, so this is a * In psftp, all agent requests should be synchronous, so this is a

16
putty.h
Просмотреть файл

@ -461,7 +461,7 @@ struct backend_tag {
* may be lost. */ * may be lost. */
int (*sendok) (void *handle); int (*sendok) (void *handle);
int (*ldisc) (void *handle, int); int (*ldisc) (void *handle, int);
void (*provide_ldisc) (void *handle, void *ldisc); void (*provide_ldisc) (void *handle, Ldisc *ldisc);
void (*provide_logctx) (void *handle, void *logctx); void (*provide_logctx) (void *handle, void *logctx);
/* /*
* back->unthrottle() tells the back end that the front end * back->unthrottle() tells the back end that the front end
@ -1174,18 +1174,18 @@ extern Backend ssh_backend;
/* /*
* Exports from ldisc.c. * Exports from ldisc.c.
*/ */
void *ldisc_create(Conf *, Terminal *, Backend *, void *, void *); Ldisc *ldisc_create(Conf *, Terminal *, Backend *, void *, void *);
void ldisc_configure(void *, Conf *); void ldisc_configure(Ldisc *, Conf *);
void ldisc_free(void *); void ldisc_free(Ldisc *);
void ldisc_send(void *handle, const void *buf, int len, int interactive); void ldisc_send(Ldisc *, const void *buf, int len, int interactive);
void ldisc_echoedit_update(void *handle); void ldisc_echoedit_update(Ldisc *);
/* /*
* Exports from ldiscucs.c. * Exports from ldiscucs.c.
*/ */
void lpage_send(void *, int codepage, const char *buf, int len, void lpage_send(Ldisc *, int codepage, const char *buf, int len,
int interactive); int interactive);
void luni_send(void *, const wchar_t * widebuf, int len, int interactive); void luni_send(Ldisc *, const wchar_t * widebuf, int len, int interactive);
/* /*
* Exports from sshrand.c. * Exports from sshrand.c.

2
raw.c
Просмотреть файл

@ -274,7 +274,7 @@ static int raw_ldisc(void *handle, int option)
return 0; return 0;
} }
static void raw_provide_ldisc(void *handle, void *ldisc) static void raw_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
/* This is a stub. */ /* This is a stub. */
} }

Просмотреть файл

@ -366,7 +366,7 @@ static int rlogin_ldisc(void *handle, int option)
return 0; return 0;
} }
static void rlogin_provide_ldisc(void *handle, void *ldisc) static void rlogin_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
/* This is a stub. */ /* This is a stub. */
} }

4
ssh.c
Просмотреть файл

@ -700,7 +700,7 @@ struct ssh_tag {
const Plug_vtable *plugvt; const Plug_vtable *plugvt;
void *ldisc; Ldisc *ldisc;
void *logctx; void *logctx;
unsigned char session_key[32]; unsigned char session_key[32];
@ -11428,7 +11428,7 @@ static int ssh_ldisc(void *handle, int option)
return FALSE; return FALSE;
} }
static void ssh_provide_ldisc(void *handle, void *ldisc) static void ssh_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
Ssh ssh = (Ssh) handle; Ssh ssh = (Ssh) handle;
ssh->ldisc = ldisc; ssh->ldisc = ldisc;

Просмотреть файл

@ -175,7 +175,7 @@ typedef struct telnet_tag {
int closed_on_socket_error; int closed_on_socket_error;
void *frontend; void *frontend;
void *ldisc; Ldisc *ldisc;
int term_width, term_height; int term_width, term_height;
int opt_states[NUM_OPTS]; int opt_states[NUM_OPTS];
@ -1059,7 +1059,7 @@ static int telnet_ldisc(void *handle, int option)
return FALSE; return FALSE;
} }
static void telnet_provide_ldisc(void *handle, void *ldisc) static void telnet_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
Telnet telnet = (Telnet) handle; Telnet telnet = (Telnet) handle;
telnet->ldisc = ldisc; telnet->ldisc = ldisc;

Просмотреть файл

@ -230,7 +230,7 @@ struct terminal_tag {
void (*resize_fn)(void *, int, int); void (*resize_fn)(void *, int, int);
void *resize_ctx; void *resize_ctx;
void *ldisc; Ldisc *ldisc;
void *frontend; void *frontend;

Просмотреть файл

@ -49,7 +49,7 @@ static int null_connected(void *);
static int null_exitcode(void *); static int null_exitcode(void *);
static int null_sendok(void *); static int null_sendok(void *);
static int null_ldisc(void *, int); static int null_ldisc(void *, int);
static void null_provide_ldisc(void *, void *); static void null_provide_ldisc(void *, Ldisc *);
static void null_provide_logctx(void *, void *); static void null_provide_logctx(void *, void *);
static void null_unthrottle(void *, int); static void null_unthrottle(void *, int);
static int null_cfg_info(void *); static int null_cfg_info(void *);
@ -157,7 +157,7 @@ static int null_ldisc(void *handle, int option) {
return 0; return 0;
} }
static void null_provide_ldisc (void *handle, void *ldisc) { static void null_provide_ldisc (void *handle, Ldisc *ldisc) {
} }

Просмотреть файл

@ -158,7 +158,7 @@ struct gui_data {
char *wintitle; char *wintitle;
char *icontitle; char *icontitle;
int master_fd, master_func_id; int master_fd, master_func_id;
void *ldisc; Ldisc *ldisc;
Backend *back; Backend *back;
void *backhandle; void *backhandle;
Terminal *term; Terminal *term;

Просмотреть файл

@ -1206,7 +1206,7 @@ static int pty_ldisc(void *handle, int option)
return 0; /* neither editing nor echoing */ return 0; /* neither editing nor echoing */
} }
static void pty_provide_ldisc(void *handle, void *ldisc) static void pty_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
/* Pty pty = (Pty)handle; */ /* Pty pty = (Pty)handle; */
/* This is a stub. */ /* This is a stub. */

Просмотреть файл

@ -544,7 +544,7 @@ static int serial_ldisc(void *handle, int option)
return 0; return 0;
} }
static void serial_provide_ldisc(void *handle, void *ldisc) static void serial_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
/* This is a stub. */ /* This is a stub. */
} }

Просмотреть файл

@ -125,7 +125,7 @@ static int caret_x = -1, caret_y = -1;
static int kbd_codepage; static int kbd_codepage;
static void *ldisc; static Ldisc *ldisc;
static Backend *back; static Backend *back;
static void *backhandle; static void *backhandle;

Просмотреть файл

@ -409,7 +409,7 @@ static int serial_ldisc(void *handle, int option)
return 0; return 0;
} }
static void serial_provide_ldisc(void *handle, void *ldisc) static void serial_provide_ldisc(void *handle, Ldisc *ldisc)
{ {
/* This is a stub. */ /* This is a stub. */
} }