# line.
# GUI front end and terminal emulator (putty, puttytel).
-GUITERM = window windlg winctrls terminal sizetip wcwidth unicode
+GUITERM = window windlg winctrls terminal sizetip wcwidth unicode ldiscucs
+ logging printing winutils
# Non-SSH back ends (putty, puttytel, plink).
+ sshrand noise sshsha winstore misc winctrls sshrsa sshdss
+ sshpubk sshaes sshsh512 import winutils puttygen.res LIBS
-pterm : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc
+pterm : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs
+ logging uxprint settings pty be_none uxstore
#include "putty.h"
#include "terminal.h"
-
-typedef struct ldisc_tag {
- Terminal *term;
- Backend *back;
- void *backhandle;
- void *frontend;
-
- char *buf;
- int buflen, bufsiz, quotenext;
-} *Ldisc;
+#include "ldisc.h"
#define ECHOING (cfg.localecho == LD_YES || \
(cfg.localecho == LD_BACKEND && \
GLOBAL int default_protocol;
GLOBAL int default_port;
-GLOBAL Terminal *term; /* temporary while changes are made */
-
struct RSAKey; /* be a little careful of scope */
/*
/*
* Exports from ldisc.c.
*/
-
void *ldisc_create(Terminal *, Backend *, void *, void *);
void ldisc_send(void *handle, char *buf, int len, int interactive);
/*
+ * Exports from ldiscucs.c.
+ */
+void lpage_send(void *, int codepage, char *buf, int len, int interactive);
+void luni_send(void *, wchar_t * widebuf, int len, int interactive);
+
+/*
* Exports from sshrand.c.
*/
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
-void init_ucs_tables(void);
-void lpage_send(void *, int codepage, char *buf, int len, int interactive);
-void luni_send(void *, wchar_t * widebuf, int len, int interactive);
+void init_ucs(void);
+int is_dbcs_leadbyte(int codepage, char byte);
+int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
+ wchar_t *wcstr, int wclen);
+int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
+ char *mbstr, int mblen, char *defchr, int *defused);
wchar_t xlat_uskbd2cyrllic(int ch);
int check_compose(int first, int second);
int decode_codepage(char *cp_name);
break;
case SSH_STATE_SESSION:
if (!cfg.nopty) {
- if (!term)
- return;
if (ssh->version == 1) {
send_packet(ssh, SSH1_CMSG_WINDOW_SIZE,
PKT_INT, ssh->term_height,
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-
#include <time.h>
+#include <assert.h>
+
#include "putty.h"
#include "terminal.h"
#include "misc.h"
static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr);
-void init_ucs_tables(void)
+void init_ucs(void)
{
int i, j;
int used_dtf = 0;
}
}
-void lpage_send(void *ldisc, int codepage, char *buf, int len, int interactive)
-{
- static wchar_t *widebuffer = 0;
- static int widesize = 0;
- int wclen;
-
- if (codepage < 0) {
- ldisc_send(ldisc, buf, len, interactive);
- return;
- }
-
- if (len > widesize) {
- sfree(widebuffer);
- widebuffer = smalloc(len * 2 * sizeof(wchar_t));
- widesize = len * 2;
- }
-
- wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
- luni_send(ldisc, widebuffer, wclen, interactive);
-}
-
-void luni_send(void *ldisc, wchar_t * widebuf, int len, int interactive)
-{
- static char *linebuffer = 0;
- static int linesize = 0;
- int ratio = (in_utf(term))?3:1;
- int i;
- char *p;
-
- if (len * ratio > linesize) {
- sfree(linebuffer);
- linebuffer = smalloc(len * ratio * 2 * sizeof(wchar_t));
- linesize = len * ratio * 2;
- }
-
- if (in_utf(term)) {
- /* UTF is a simple algorithm */
- for (p = linebuffer, i = 0; i < len; i++) {
- wchar_t ch = widebuf[i];
- /* Windows wchar_t is UTF-16 */
- if ((ch&0xF800) == 0xD800) ch = '.';
-
- if (ch < 0x80) {
- *p++ = (char) (ch);
- } else if (ch < 0x800) {
- *p++ = (0xC0 | (ch >> 6));
- *p++ = (0x80 | (ch & 0x3F));
- } else {
- *p++ = (0xE0 | (ch >> 12));
- *p++ = (0x80 | ((ch >> 6) & 0x3F));
- *p++ = (0x80 | (ch & 0x3F));
- }
- }
- } else if (!uni_tbl) {
- int rv;
- rv = wc_to_mb(line_codepage, 0, widebuf, len,
- linebuffer, linesize, NULL, NULL);
- if (rv >= 0)
- p = linebuffer + rv;
- else
- p = linebuffer;
- } else {
- /* Others are a lookup in an array */
- for (p = linebuffer, i = 0; i < len; i++) {
- wchar_t ch = widebuf[i];
- int by;
- char *p1;
- if (uni_tbl && (p1 = uni_tbl[(ch >> 8) & 0xFF])
- && (by = p1[ch & 0xFF]))
- *p++ = by;
- else if (ch < 0x80)
- *p++ = (char) ch;
-#if 1
- else
- *p++ = '.';
-#endif
- }
- }
- if (p > linebuffer)
- ldisc_send(ldisc, linebuffer, p - linebuffer, interactive);
-}
-
wchar_t xlat_uskbd2cyrllic(int ch)
{
static wchar_t cyrtab[] = {
unitab[i] = cp_list[codepage & 0xFFFF].cp_table[i - j];
}
}
+
+int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
+ char *mbstr, int mblen, char *defchr, int *defused)
+{
+ char *p;
+ int i;
+ if (codepage == line_codepage && uni_tbl) {
+ /* Do this by array lookup if we can. */
+ if (wclen < 0) {
+ for (wclen = 0; wcstr[wclen++] ;); /* will include the NUL */
+ }
+ for (p = mbstr, i = 0; i < wclen; i++) {
+ wchar_t ch = wcstr[i];
+ int by;
+ char *p1;
+ if (uni_tbl && (p1 = uni_tbl[(ch >> 8) & 0xFF])
+ && (by = p1[ch & 0xFF]))
+ *p++ = by;
+ else if (ch < 0x80)
+ *p++ = (char) ch;
+ else if (defchr) {
+ int j;
+ for (j = 0; defchr[j]; j++)
+ *p++ = defchr[j];
+ if (defused) *defused = 1;
+ }
+#if 1
+ else
+ *p++ = '.';
+#endif
+ assert(p - mbstr < mblen);
+ }
+ return p - mbstr;
+ } else
+ return WideCharToMultiByte(codepage, flags, wcstr, wclen,
+ mbstr, mblen, defchr, defused);
+}
+
+int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
+ wchar_t *wcstr, int wclen)
+{
+ return MultiByteToWideChar(codepage, flags, mbstr, mblen, wcstr, wclen);
+}
+
+int is_dbcs_leadbyte(int codepage, char byte)
+{
+ return IsDBCSLeadByteEx(codepage, byte);
+}
void *ldisc;
Backend *back;
void *backhandle;
+ Terminal *term;
};
static struct gui_data the_inst;
*/
void refresh_window(void)
{
- term_invalidate(term);
+ term_invalidate(inst->term);
}
/*
}
if (need_size) {
- term_size(term, h, w, cfg.savelines);
+ term_size(inst->term, h, w, cfg.savelines);
}
return TRUE;
* at all.
*/
if (event->keyval == GDK_Page_Up && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(term, 0, -cfg.height/2);
+ term_scroll(inst->term, 0, -cfg.height/2);
return TRUE;
}
if (event->keyval == GDK_Page_Down && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(term, 0, +cfg.height/2);
+ term_scroll(inst->term, 0, +cfg.height/2);
return TRUE;
}
/*
* Application keypad mode.
*/
- if (term->app_keypad_keys && !cfg.no_applic_k) {
+ if (inst->term->app_keypad_keys && !cfg.no_applic_k) {
int xkey = 0;
switch (event->keyval) {
case GDK_Num_Lock: xkey = 'P'; break;
case GDK_KP_Decimal: case GDK_KP_Delete: xkey = 'n'; break;
}
if (xkey) {
- if (term->vt52_mode) {
+ if (inst->term->vt52_mode) {
if (xkey >= 'P' && xkey <= 'S')
end = 1 + sprintf(output+1, "\033%c", xkey);
else
if (cfg.funky_type == 3 && code <= 6)
code = "\0\2\1\4\5\3\6"[code];
- if (term->vt52_mode && code > 0 && code <= 6) {
+ if (inst->term->vt52_mode && code > 0 && code <= 6) {
end = 1 + sprintf(output+1, "\x1B%c", " HLMEIG"[code]);
goto done;
}
}
goto done;
}
- if ((term->vt52_mode || cfg.funky_type == 4) &&
+ if ((inst->term->vt52_mode || cfg.funky_type == 4) &&
code >= 11 && code <= 24) {
int offt = 0;
if (code > 15)
offt++;
if (code > 21)
offt++;
- if (term->vt52_mode)
+ if (inst->term->vt52_mode)
end = 1 + sprintf(output+1,
"\x1B%c", code + 'P' - 11 - offt);
else
goto done;
}
if (cfg.funky_type == 2 && code >= 11 && code <= 14) {
- if (term->vt52_mode)
+ if (inst->term->vt52_mode)
end = 1 + sprintf(output+1, "\x1B%c", code + 'P' - 11);
else
end = 1 + sprintf(output+1, "\x1BO%c", code + 'P' - 11);
* app cursor keys mode they do ESC O A instead.
* Ctrl toggles the two modes.
*/
- if (term->vt52_mode) {
+ if (inst->term->vt52_mode) {
end = 1 + sprintf(output+1, "\033%c", xkey);
- } else if (!term->app_cursor_keys ^
+ } else if (!inst->term->app_cursor_keys ^
!(event->state & GDK_CONTROL_MASK)) {
end = 1 + sprintf(output+1, "\033O%c", xkey);
} else {
ldisc_send(inst->ldisc, output+start, end-start, 1);
show_mouseptr(0);
- term_seen_key_event(term);
- term_out(term);
+ term_seen_key_event(inst->term);
+ term_out(inst->term);
}
return TRUE;
show_mouseptr(1);
if (event->button == 4 && event->type == GDK_BUTTON_PRESS) {
- term_scroll(term, 0, -5);
+ term_scroll(inst->term, 0, -5);
return TRUE;
}
if (event->button == 5 && event->type == GDK_BUTTON_PRESS) {
- term_scroll(term, 0, +5);
+ term_scroll(inst->term, 0, +5);
return TRUE;
}
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
- term_mouse(term, button, act, x, y, shift, ctrl, alt);
+ term_mouse(inst->term, button, act, x, y, shift, ctrl, alt);
return TRUE;
}
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
- term_mouse(term, button, MA_DRAG, x, y, shift, ctrl, alt);
+ term_mouse(inst->term, button, MA_DRAG, x, y, shift, ctrl, alt);
return TRUE;
}
" %d (%.400s)]\r\n", WTERMSIG(exitcode),
strsignal(WTERMSIG(exitcode)));
#endif
- from_backend((void *)term, 0, message, strlen(message));
+ from_backend((void *)inst->term, 0, message, strlen(message));
}
inst->exited = 1;
}
done_with_pty(inst);
}
- term_update(term);
- term_blink(term, 0);
+ term_update(inst->term);
+ term_blink(inst->term, 0);
return TRUE;
}
perror("read pty master");
exit(1);
} else if (ret > 0)
- from_backend(term, 0, buf, ret);
- term_blink(term, 1);
- term_out(term);
+ from_backend(inst->term, 0, buf, ret);
+ term_blink(inst->term, 1);
+ term_out(inst->term);
}
void destroy(GtkWidget *widget, gpointer data)
gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
{
- term->has_focus = event->in;
- term_out(term);
- term_update(term);
+ inst->term->has_focus = event->in;
+ term_out(inst->term);
+ term_update(inst->term);
show_mouseptr(1);
return FALSE;
}
gint selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gpointer data)
{
- term_deselect(term);
+ term_deselect(inst->term);
if (inst->pasteout_data)
sfree(inst->pasteout_data);
inst->pasteout_data = NULL;
mb_to_wc(0, 0, seldata->data, seldata->length,
inst->pastein_data, inst->pastein_data_len);
- term_do_paste(term);
+ term_do_paste(inst->term);
- if (term_paste_pending(term))
+ if (term_paste_pending(inst->term))
inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
}
{
struct gui_data *inst = (struct gui_data *)data;
- if (term_paste_pending(term))
- term_paste(term);
+ if (term_paste_pending(inst->term))
+ term_paste(inst->term);
else
gtk_idle_remove(inst->term_paste_idle_id);
if (!cfg.scrollbar)
return;
if (!inst->ignore_sbar)
- term_scroll(term, 1, (int)adj->value);
+ term_scroll(inst->term, 1, (int)adj->value);
}
void sys_cursor(int x, int y)
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
}
gdk_gc_set_foreground(gc, &inst->cols[nbg]);
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
len *= 2;
}
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
len *= 2;
}
inst->currcursor = inst->textcursor;
show_mouseptr(1);
- term = term_init();
+ inst->term = term_init();
inst->back = &pty_backend;
- inst->back->init((void *)term, &inst->backhandle, NULL, 0, NULL, 0);
+ inst->back->init((void *)inst->term, &inst->backhandle, NULL, 0, NULL, 0);
- term_provide_resize_fn(term, inst->back->size, inst->backhandle);
+ term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
- term_size(term, cfg.height, cfg.width, cfg.savelines);
+ term_size(inst->term, cfg.height, cfg.width, cfg.savelines);
- inst->ldisc = ldisc_create(term, inst->back, inst->backhandle, inst);
+ inst->ldisc = ldisc_create(inst->term, inst->back, inst->backhandle, inst);
ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
inst->master_fd = pty_master_fd;
#define WCHAR wchar_t
#define BYTE unsigned char
-int is_dbcs_leadbyte(int codepage, char byte);
-int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
- wchar_t *wcstr, int wclen);
-int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
- char *mbstr, int mblen, char *defchr, int *defused);
-void init_ucs(void);
-
/* Things pty.c needs from pterm.c */
char *get_x_display(void);
int font_dimension(int which); /* 0 for width, 1 for height */
* are ISO8859-1.
*/
-void lpage_send(void *ldisc, int codepage, char *buf, int len, int interactive)
-{
- ldisc_send(ldisc, buf, len, interactive);
-}
-
-void luni_send(void *ldisc, wchar_t * widebuf, int len, int interactive)
-{
- static char *linebuffer = 0;
- static int linesize = 0;
- int ratio = (in_utf(term))?6:1;
- int i;
- char *p;
-
- if (len * ratio > linesize) {
- sfree(linebuffer);
- linebuffer = smalloc(len * ratio * 2 * sizeof(wchar_t));
- linesize = len * ratio * 2;
- }
-
- if (in_utf(term)) {
- /* UTF is a simple algorithm */
- for (p = linebuffer, i = 0; i < len; i++) {
- wchar_t ch = widebuf[i];
-
- if ((ch&0xF800) == 0xD800) ch = '.';
-
- if (ch < 0x80) {
- *p++ = (char) (ch);
- } else if (ch < 0x800) {
- *p++ = (0xC0 | (ch >> 6));
- *p++ = (0x80 | (ch & 0x3F));
- } else if (ch < 0x10000) {
- *p++ = (0xE0 | (ch >> 12));
- *p++ = (0x80 | ((ch >> 6) & 0x3F));
- *p++ = (0x80 | (ch & 0x3F));
- } else if (ch < 0x200000) {
- *p++ = (0xF0 | (ch >> 18));
- *p++ = (0x80 | ((ch >> 12) & 0x3F));
- *p++ = (0x80 | ((ch >> 6) & 0x3F));
- *p++ = (0x80 | (ch & 0x3F));
- } else if (ch < 0x4000000) {
- *p++ = (0xF8 | (ch >> 24));
- *p++ = (0x80 | ((ch >> 18) & 0x3F));
- *p++ = (0x80 | ((ch >> 12) & 0x3F));
- *p++ = (0x80 | ((ch >> 6) & 0x3F));
- *p++ = (0x80 | (ch & 0x3F));
- } else {
- *p++ = (0xFC | (ch >> 30));
- *p++ = (0x80 | ((ch >> 24) & 0x3F));
- *p++ = (0x80 | ((ch >> 18) & 0x3F));
- *p++ = (0x80 | ((ch >> 12) & 0x3F));
- *p++ = (0x80 | ((ch >> 6) & 0x3F));
- *p++ = (0x80 | (ch & 0x3F));
- }
- }
- } else {
- for (p = linebuffer, i = 0; i < len; i++) {
- wchar_t ch = widebuf[i];
- if (ch < 0x100)
- *p++ = (char) ch;
- else
- *p++ = '.';
- }
- }
- if (p > linebuffer)
- ldisc_send(ldisc, linebuffer, p - linebuffer, interactive);
-}
-
int is_dbcs_leadbyte(int codepage, char byte)
{
return 0; /* we don't do DBCS */
if (defchr)
*mbstr++ = *defchr;
else
- *mbstr++ = '\xBF';
+ *mbstr++ = '.';
if (defused)
*defused = 1;
} else
static void *ldisc;
static Backend *back;
static void *backhandle;
+static Terminal *term;
#define FONT_NORMAL 0
#define FONT_BOLD 1
}
fontflag[0] = fontflag[1] = fontflag[2] = 1;
- init_ucs_tables();
+ init_ucs();
}
static void another_font(int fontno)
void UpdateSizeTip(HWND src, int cx, int cy);
void EnableSizeTip(int bEnable);
-/*
- * Unicode and multi-byte character handling stuff.
- */
-#define is_dbcs_leadbyte(cp, c) IsDBCSLeadByteEx(cp, c)
-#define mb_to_wc(cp, flags, mbstr, mblen, wcstr, wclen) \
- MultiByteToWideChar(cp, flags, mbstr, mblen, wcstr, wclen)
-#define wc_to_mb(cp, flags, wcstr, wclen, mbstr, mblen, def, defused) \
- WideCharToMultiByte(cp, flags, wcstr, wclen, mbstr, mblen, def,defused)
-
#endif