1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 11:02:48 -05:00

Major destabilisation, phase 1. In this phase I've moved (I think)

all the global and function-static variables out of terminal.c into
a dynamically allocated data structure. Note that this does not yet
confer the ability to run more than one of them in the same process,
because other things (the line discipline, the back end) are still
global, and also in particular the address of the dynamically
allocated terminal-data structure is held in a global variable
`term'. But what I've got here represents a reasonable stopping
point at which to check things in. In _theory_ this should all still
work happily, on both Unix and Windows. In practice, who knows?

[originally from svn r2115]
This commit is contained in:
Simon Tatham
2002-10-22 16:11:33 +00:00
parent 48314f7dc0
commit 0a80c983e2
15 changed files with 1577 additions and 1608 deletions

View File

@ -18,6 +18,7 @@
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
#include "putty.h"
#include "terminal.h"
#define CAT2(x,y) x ## y
#define CAT(x,y) CAT2(x,y)
@ -161,7 +162,7 @@ void set_zorder(int top)
*/
void refresh_window(void)
{
term_invalidate();
term_invalidate(term);
}
/*
@ -286,7 +287,7 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
}
if (need_size) {
term_size(h, w, cfg.savelines);
term_size(term, h, w, cfg.savelines);
}
return TRUE;
@ -410,11 +411,11 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
* at all.
*/
if (event->keyval == GDK_Page_Up && (event->state & GDK_SHIFT_MASK)) {
term_scroll(0, -cfg.height/2);
term_scroll(term, 0, -cfg.height/2);
return TRUE;
}
if (event->keyval == GDK_Page_Down && (event->state & GDK_SHIFT_MASK)) {
term_scroll(0, +cfg.height/2);
term_scroll(term, 0, +cfg.height/2);
return TRUE;
}
@ -517,7 +518,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
/*
* Application keypad mode.
*/
if (app_keypad_keys && !cfg.no_applic_k) {
if (term->app_keypad_keys && !cfg.no_applic_k) {
int xkey = 0;
switch (event->keyval) {
case GDK_Num_Lock: xkey = 'P'; break;
@ -555,7 +556,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
case GDK_KP_Decimal: case GDK_KP_Delete: xkey = 'n'; break;
}
if (xkey) {
if (vt52_mode) {
if (term->vt52_mode) {
if (xkey >= 'P' && xkey <= 'S')
end = 1 + sprintf(output+1, "\033%c", xkey);
else
@ -663,7 +664,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
if (cfg.funky_type == 3 && code <= 6)
code = "\0\2\1\4\5\3\6"[code];
if (vt52_mode && code > 0 && code <= 6) {
if (term->vt52_mode && code > 0 && code <= 6) {
end = 1 + sprintf(output+1, "\x1B%c", " HLMEIG"[code]);
goto done;
}
@ -702,13 +703,14 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
}
goto done;
}
if ((vt52_mode || cfg.funky_type == 4) && code >= 11 && code <= 24) {
if ((term->vt52_mode || cfg.funky_type == 4) &&
code >= 11 && code <= 24) {
int offt = 0;
if (code > 15)
offt++;
if (code > 21)
offt++;
if (vt52_mode)
if (term->vt52_mode)
end = 1 + sprintf(output+1,
"\x1B%c", code + 'P' - 11 - offt);
else
@ -721,7 +723,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
goto done;
}
if (cfg.funky_type == 2 && code >= 11 && code <= 14) {
if (vt52_mode)
if (term->vt52_mode)
end = 1 + sprintf(output+1, "\x1B%c", code + 'P' - 11);
else
end = 1 + sprintf(output+1, "\x1BO%c", code + 'P' - 11);
@ -759,9 +761,9 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
* app cursor keys mode they do ESC O A instead.
* Ctrl toggles the two modes.
*/
if (vt52_mode) {
if (term->vt52_mode) {
end = 1 + sprintf(output+1, "\033%c", xkey);
} else if (!app_cursor_keys ^
} else if (!term->app_cursor_keys ^
!(event->state & GDK_CONTROL_MASK)) {
end = 1 + sprintf(output+1, "\033O%c", xkey);
} else {
@ -786,8 +788,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
ldisc_send(output+start, end-start, 1);
show_mouseptr(0);
term_seen_key_event();
term_out();
term_seen_key_event(term);
term_out(term);
}
return TRUE;
@ -801,11 +803,11 @@ gint button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
show_mouseptr(1);
if (event->button == 4 && event->type == GDK_BUTTON_PRESS) {
term_scroll(0, -5);
term_scroll(term, 0, -5);
return TRUE;
}
if (event->button == 5 && event->type == GDK_BUTTON_PRESS) {
term_scroll(0, +5);
term_scroll(term, 0, +5);
return TRUE;
}
@ -836,7 +838,7 @@ gint button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
term_mouse(button, act, x, y, shift, ctrl, alt);
term_mouse(term, button, act, x, y, shift, ctrl, alt);
return TRUE;
}
@ -863,7 +865,7 @@ gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
term_mouse(button, MA_DRAG, x, y, shift, ctrl, alt);
term_mouse(term, button, MA_DRAG, x, y, shift, ctrl, alt);
return TRUE;
}
@ -885,8 +887,8 @@ gint timer_func(gpointer data)
exit(0);
}
term_update();
term_blink(0);
term_update(term);
term_blink(term, 0);
return TRUE;
}
@ -912,9 +914,9 @@ void pty_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
exit(1);
}
if (ret > 0)
from_backend(0, buf, ret);
term_blink(1);
term_out();
from_backend(term, 0, buf, ret);
term_blink(term, 1);
term_out(term);
}
void destroy(GtkWidget *widget, gpointer data)
@ -924,9 +926,9 @@ void destroy(GtkWidget *widget, gpointer data)
gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
{
has_focus = event->in;
term_out();
term_update();
term->has_focus = event->in;
term_out(term);
term_update(term);
show_mouseptr(1);
return FALSE;
}
@ -1100,7 +1102,7 @@ void selection_get(GtkWidget *widget, GtkSelectionData *seldata,
gint selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gpointer data)
{
term_deselect();
term_deselect(term);
if (inst->pasteout_data)
sfree(inst->pasteout_data);
inst->pasteout_data = NULL;
@ -1136,9 +1138,9 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
mb_to_wc(0, 0, seldata->data, seldata->length,
inst->pastein_data, inst->pastein_data_len);
term_do_paste();
term_do_paste(term);
if (term_paste_pending())
if (term_paste_pending(term))
inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
}
@ -1146,8 +1148,8 @@ gint idle_paste_func(gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
if (term_paste_pending())
term_paste();
if (term_paste_pending(term))
term_paste(term);
else
gtk_idle_remove(inst->term_paste_idle_id);
@ -1197,7 +1199,7 @@ void scrollbar_moved(GtkAdjustment *adj, gpointer data)
if (!cfg.scrollbar)
return;
if (!inst->ignore_sbar)
term_scroll(1, (int)adj->value);
term_scroll(term, 1, (int)adj->value);
}
void sys_cursor(int x, int y)
@ -1280,10 +1282,10 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len,
if (lattr != LATTR_NORM) {
x *= 2;
if (x >= cols)
if (x >= term->cols)
return;
if (x + len*2 > cols)
len = (cols-x)/2; /* trim to LH half */
if (x + len*2 > term->cols)
len = (term->cols-x)/2; /* trim to LH half */
}
gdk_gc_set_foreground(gc, &inst->cols[nbg]);
@ -1362,10 +1364,10 @@ void do_text(Context ctx, int x, int y, char *text, int len,
if (lattr != LATTR_NORM) {
x *= 2;
if (x >= cols)
if (x >= term->cols)
return;
if (x + len*2 > cols)
len = (cols-x)/2; /* trim to LH half */
if (x + len*2 > term->cols)
len = (term->cols-x)/2; /* trim to LH half */
len *= 2;
}
@ -1395,10 +1397,10 @@ void do_cursor(Context ctx, int x, int y, char *text, int len,
if (lattr != LATTR_NORM) {
x *= 2;
if (x >= cols)
if (x >= term->cols)
return;
if (x + len*2 > cols)
len = (cols-x)/2; /* trim to LH half */
if (x + len*2 > term->cols)
len = (term->cols-x)/2; /* trim to LH half */
len *= 2;
}
@ -1875,14 +1877,16 @@ int main(int argc, char **argv)
inst->currcursor = inst->textcursor;
show_mouseptr(1);
term = term_init();
back = &pty_backend;
back->init(NULL, 0, NULL, 0);
back->init((void *)term, NULL, 0, NULL, 0);
term_size(term, cfg.height, cfg.width, cfg.savelines);
ldisc_send(NULL, 0, 0); /* cause ldisc to notice changes */
gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_func, inst);
term_init();
term_size(cfg.height, cfg.width, cfg.savelines);
gtk_main();
return 0;

View File

@ -18,6 +18,7 @@
#include <sys/ioctl.h>
#include "putty.h"
#include "terminal.h"
#ifndef FALSE
#define FALSE 0
@ -372,7 +373,8 @@ void pty_pre_init(void)
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static char *pty_init(char *host, int port, char **realhost, int nodelay)
static char *pty_init(void *frontend,
char *host, int port, char **realhost, int nodelay)
{
int slavefd;
pid_t pid, pgrp;
@ -521,10 +523,10 @@ static void pty_size(void)
{
struct winsize size;
size.ws_row = (unsigned short)rows;
size.ws_col = (unsigned short)cols;
size.ws_xpixel = (unsigned short) cols * font_dimension(0);
size.ws_ypixel = (unsigned short) rows * font_dimension(1);
size.ws_row = (unsigned short)term->rows;
size.ws_col = (unsigned short)term->cols;
size.ws_xpixel = (unsigned short) term->cols * font_dimension(0);
size.ws_ypixel = (unsigned short) term->rows * font_dimension(1);
ioctl(pty_master_fd, TIOCSWINSZ, (void *)&size);
return;
}

View File

@ -4,6 +4,7 @@
#include <time.h>
#include "putty.h"
#include "terminal.h"
#include "misc.h"
/*
@ -22,7 +23,7 @@ void luni_send(wchar_t * widebuf, int len, int interactive)
{
static char *linebuffer = 0;
static int linesize = 0;
int ratio = (in_utf)?6:1;
int ratio = (in_utf(term))?6:1;
int i;
char *p;
@ -32,7 +33,7 @@ void luni_send(wchar_t * widebuf, int len, int interactive)
linesize = len * ratio * 2;
}
if (in_utf) {
if (in_utf(term)) {
/* UTF is a simple algorithm */
for (p = linebuffer, i = 0; i < len; i++) {
wchar_t ch = widebuf[i];