1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Bloody Hell! It just managed to say "Hello, world" in a terminal window!

I'd better check this lot in before something bad happens to it.

[originally from svn r56]
This commit is contained in:
Ben Harris 1999-02-21 18:09:41 +00:00
parent 7c491e865f
commit 8ac1a08339
5 changed files with 207 additions and 55 deletions

View File

@ -1,4 +1,4 @@
# $Id: PuTTY.make,v 1.1.2.5 1999/02/21 10:29:12 ben Exp $ # $Id: PuTTY.make,v 1.1.2.6 1999/02/21 18:09:41 ben Exp $
# This is the Makefile for building PuTTY for the Mac OS. # This is the Makefile for building PuTTY for the Mac OS.
# Users of non-Mac systems will see some pretty strange characters around. # Users of non-Mac systems will see some pretty strange characters around.
@ -12,6 +12,7 @@ COptions = {Includes} {Sym
Objects¥68K = ¶ Objects¥68K = ¶
"{ObjDir¥68K}mac.c.o" ¶ "{ObjDir¥68K}mac.c.o" ¶
"{ObjDir¥68K}macterm.c.o" ¶
"{ObjDir¥68K}misc.c.o" ¶ "{ObjDir¥68K}misc.c.o" ¶
# "{ObjDir¥68K}ssh.c.o" ¶ # "{ObjDir¥68K}ssh.c.o" ¶
# "{ObjDir¥68K}sshcrc.c.o" ¶ # "{ObjDir¥68K}sshcrc.c.o" ¶
@ -43,9 +44,12 @@ PuTTY
Rez mac_res.r -o {Targ} {Includes} -append Rez mac_res.r -o {Targ} {Includes} -append
"{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c putty.h macresid.h "{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c putty.h mac.h macresid.h
{C} mac.c -o {Targ} {COptions} {C} mac.c -o {Targ} {COptions}
"{ObjDir¥68K}macterm.c.o" Ä {¥MondoBuild¥} macterm.c mac.h putty.h
{C} macterm.c -o {Targ} {COptions}
"{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c putty.h "{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c putty.h
{C} misc.c -o {Targ} {COptions} {C} misc.c -o {Targ} {COptions}

21
mac.c
View File

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.1.2.5 1999/02/20 23:55:55 ben Exp $ */ /* $Id: mac.c,v 1.1.2.6 1999/02/21 18:09:41 ben Exp $ */
/* /*
* mac.c -- miscellaneous Mac-specific routines * mac.c -- miscellaneous Mac-specific routines
*/ */
@ -12,18 +12,23 @@
#include <Dialogs.h> #include <Dialogs.h>
#include <Devices.h> #include <Devices.h>
#include <DiskInit.h> #include <DiskInit.h>
#include <Gestalt.h>
#include <ToolUtils.h> #include <ToolUtils.h>
#include <limits.h> #include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> /* putty.h needs size_t */ #include <stdlib.h> /* putty.h needs size_t */
#define PUTTY_DO_GLOBALS
#include "macresid.h" #include "macresid.h"
#include "putty.h" #include "putty.h"
#include "mac.h"
QDGlobals qd; QDGlobals qd;
int cold = 1; static int cold = 1;
long mac_qdversion;
static void mac_startup(void); static void mac_startup(void);
static void mac_eventloop(void); static void mac_eventloop(void);
@ -64,6 +69,10 @@ static void mac_startup(void) {
InitDialogs(nil); InitDialogs(nil);
cold = 0; cold = 0;
/* Find out if we've got Color Quickdraw */
if (Gestalt(gestaltQuickdrawVersion, &mac_qdversion) != noErr)
mac_qdversion = gestaltOriginalQD;
menuBar = GetNewMBar(128); menuBar = GetNewMBar(128);
if (menuBar == NULL) if (menuBar == NULL)
fatalbox("Unable to create menu bar."); fatalbox("Unable to create menu bar.");
@ -172,7 +181,13 @@ static void mac_updatewindow(WindowPtr window) {
switch (mac_windowtype(window)) { switch (mac_windowtype(window)) {
case wTerminal: case wTerminal:
/* XXX: DO something */ BeginUpdate(window);
term_paint((struct mac_session *)GetWRefCon(window),
(*window->visRgn)->rgnBBox.left,
(*window->visRgn)->rgnBBox.top,
(*window->visRgn)->rgnBBox.right,
(*window->visRgn)->rgnBBox.bottom);
EndUpdate(window);
break; break;
case wAbout: case wAbout:
BeginUpdate(window); BeginUpdate(window);

View File

@ -1,4 +1,4 @@
/* $Id: mac_res.r,v 1.1.2.1 1999/02/21 10:29:13 ben Exp $ */ /* $Id: mac_res.r,v 1.1.2.2 1999/02/21 18:09:41 ben Exp $ */
/* PuTTY resources */ /* PuTTY resources */
#define PICT_RezTemplateVersion 1 #define PICT_RezTemplateVersion 1
@ -45,8 +45,8 @@ resource 'SIZE' (-1) {
reserved, reserved,
reserved, reserved,
reserved, reserved,
65536, /* Minimum size */ 1024 * 1024, /* Minimum size */
65536, /* Preferred size */ 1024 * 1024, /* Preferred size */
}; };
resource 'FREF' (128, purgeable) { resource 'FREF' (128, purgeable) {
@ -267,11 +267,11 @@ resource 'MENU' (mApple, preload) {
resource 'MENU' (mFile, preload) { resource 'MENU' (mFile, preload) {
mFile, mFile,
textMenuProc, textMenuProc,
0b11111111111111111111111111111101, 0b11111111111111111111111111111011,
enabled, enabled,
"File", "File",
{ {
"New Session" noicon, "N", nomark, plain, "New Session", noicon, "N", nomark, plain,
"Close", noicon, "W", nomark, plain, "Close", noicon, "W", nomark, plain,
"-", noicon, nokey, nomark, plain, "-", noicon, nokey, nomark, plain,
"Quit", noicon, "Q", nomark, plain, "Quit", noicon, "Q", nomark, plain,
@ -313,12 +313,12 @@ resource 'DITL' (wFatal, "fatalbox", purgeable) {
/* Terminal window */ /* Terminal window */
resource 'WIND' (wTerminal, "terminal", purgeable) { resource 'WIND' (wTerminal, "terminal", purgeable) {
{ 0, 0, 0, 0 }, { 0, 0, 200, 200 },
zoomDocProc, zoomDocProc,
invisible, invisible,
goAway, goAway,
0x0, 0x0,
"untitled" "untitled",
staggerParentWindowScreen staggerParentWindowScreen
}; };
@ -344,7 +344,7 @@ resource 'DITL' (wAbout, "about", purgeable) {
{ 13, 13, 29, 173 }, { 13, 13, 29, 173 },
StaticText { disabled, "PuTTY"}, StaticText { disabled, "PuTTY"},
{ 42, 13, 74, 173 }, { 42, 13, 74, 173 },
StaticText { disabled, "Mac Development\n© 1997-9 Simon Tatham"}, StaticText { disabled,"Experimantal Mac Port\n© 1997-9 Simon Tatham"},
} }
}; };

176
macterm.c
View File

@ -2,45 +2,175 @@
* macterm.c -- Macintosh terminal front-end * macterm.c -- Macintosh terminal front-end
*/ */
#include <MacTypes.h>
#include <Fonts.h>
#include <Gestalt.h>
#include <MacWindows.h> #include <MacWindows.h>
#include <QuickdrawText.h>
#include <Sound.h>
#include <stdlib.h> #include <stdlib.h>
#include "macresid.h" #include "macresid.h"
#include "putty.h" #include "putty.h"
#include "mac.h"
struct mac_session { struct mac_session {
short fnum; short fontnum;
int fsize; int font_ascent;
} WindowPtr(window);
};
static void mac_initfont(struct mac_session *);
/* Temporary hack till I get the terminal emulator supporting multiple sessions */
static struct mac_session *onlysession;
void mac_newsession(void) { void mac_newsession(void) {
WindowPtr window;
struct mac_session *s; struct mac_session *s;
/* This should obviously be initialised by other means */ /* This should obviously be initialised by other means */
s = smalloc(sizeof(*s)); s = smalloc(sizeof(*s));
s->fnum = GetFNum("\pMonaco"); strcpy(cfg.font, "Monaco");
s->fsize = 9; cfg.fontisbold = 0;
rows = 24; cfg.fontheight = 9;
cols = 80; onlysession = s;
/* XXX: non-Color-QuickDraw? Own storage management? */ /* XXX: non-Color-QuickDraw? Own storage management? */
window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); if (mac_qdversion == gestaltOriginalQD)
SetPort(window); s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
mac_initfont(s); else
s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
SetWRefCon(s->window, (long)s);
term_init(); term_init();
term_size(rows, cols); term_size(24, 80, 100);
mac_initfont(s);
ShowWindow(s->window);
} }
void mac_initfont(struct mac_session *s) { static void inbuf_putc(int c) {
FMetricRec metrics; inbuf[inbuf_head] = c;
inbuf_head = (inbuf_head+1) & INBUF_MASK;
TextFont(s->fnum); }
TextFace(0);
TextSize(s->fsize); static void inbuf_putstr(const char *c) {
FontMetrics(&metrics); while (*c)
font_width = metrics.widMax; inbuf_putc(*c++);
font_height = metrics.ascent + metrics.descent + metrics.leading; }
SizeWindow(window, cols * font_width, rows * font_height, TRUE);
static void mac_initfont(struct mac_session *s) {
Str255 macfont;
FontInfo fi;
SetPort(s->window);
macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
GetFNum(macfont, &s->fontnum);
TextFont(s->fontnum);
TextFace(cfg.fontisbold ? bold : 0);
TextSize(cfg.fontheight);
GetFontInfo(&fi);
font_width = fi.widMax;
font_height = fi.ascent + fi.descent + fi.leading;
s->font_ascent = fi.ascent;
SizeWindow(s->window, cols * font_width, rows * font_height, true);
inbuf_putstr("Hello,\007 world\007");
term_out();
}
/*
* Call from the terminal emulator to draw a bit of text
*
* x and y are text row and column (zero-based)
*/
void do_text(struct mac_session *s, int x, int y, char *text, int len,
unsigned long attr) {
int style = 0;
SetPort(s->window);
TextFont(s->fontnum);
if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
style |= bold;
if (attr & ATTR_UNDER)
style |= underline;
TextFace(style);
TextSize(cfg.fontheight);
TextMode(srcCopy);
SetFractEnable(FALSE); /* We want characters on pixel boundaries */
MoveTo(x * font_width, y * font_height + s->font_ascent);
DrawText(text, 0, len);
}
/*
* Call from the terminal emulator to get its graphics context.
* I feel this should disappear entirely (and do_text should take
* a Session as an argument. Simon may disagree.
*/
struct mac_session *get_ctx(void) {
return onlysession;
}
/*
* Presumably this does something in Windows
*/
void free_ctx(struct mac_session *ctx) {
}
/*
* Set the scroll bar position
*/
void set_sbar(int total, int start, int page) {
/* Do something once we actually have a scroll bar */
}
/*
* Beep
*/
void beep(void) {
SysBeep(30);
}
/*
* Set icon string -- a no-op here (WIndowshade?)
*/
void set_icon(char *icon) {
}
/*
* Set the window title
*/
void set_title(char *title) {
Str255 mactitle;
mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
SetWTitle(onlysession->window, mactitle);
}
/*
* Resize the window at the emulator's request
*/
void request_resize(int w, int h) {
/* XXX: Do something */
}
/*
* Set the logical palette
*/
void palette_set(int n, int r, int g, int b) {
/* XXX: Do something */
}
/*
* Reset to the default palette
*/
void palette_reset(void) {
/* XXX: Do something */
} }

41
putty.h
View File

@ -6,6 +6,7 @@
#ifdef macintosh #ifdef macintosh
#include <MacTypes.h> #include <MacTypes.h>
typedef UInt32 DWORD; typedef UInt32 DWORD;
struct mac_session;
#endif /* macintosh */ #endif /* macintosh */
#ifndef TRUE #ifndef TRUE
@ -41,7 +42,8 @@ typedef UInt32 DWORD;
#define CHAR_MASK 0x000000FFUL #define CHAR_MASK 0x000000FFUL
#ifdef macintosh #ifdef macintosh
typedef void *Context; /* Temporarily until I work out what it should really be */ struct mac_session;
typedef struct mac_session *Context;
#else /* not macintosh */ #else /* not macintosh */
typedef HDC Context; typedef HDC Context;
#endif /* not macintosh */ #endif /* not macintosh */
@ -59,24 +61,6 @@ typedef HDC Context;
#define GLOBAL extern #define GLOBAL extern
#endif #endif
struct session {
/* Display state */
int rows, cols, savelines;
int font_width, font_height;
int has_focus;
/* Buffers */
unsigned char inbuf[INBUF_SIZE];
int inbuf_head, inbuf_reap;
unsigned char outbuf[OUTBUF_SIZE];
int outbuf_head, outbuf_reap;
/* Emulator state */
int app_cursor_keys, app_keypad_keys;
/* Backend */
Backend *back;
/* Config that created this session */
Config cfg;
}
GLOBAL int rows, cols, savelines; GLOBAL int rows, cols, savelines;
GLOBAL int font_width, font_height; GLOBAL int font_width, font_height;
@ -171,6 +155,25 @@ typedef struct {
GLOBAL Config cfg; GLOBAL Config cfg;
typedef struct {
/* Display state */
int rows, cols, savelines;
int font_width, font_height;
int has_focus;
/* Buffers */
unsigned char inbuf[INBUF_SIZE];
int inbuf_head, inbuf_reap;
unsigned char outbuf[OUTBUF_SIZE];
int outbuf_head, outbuf_reap;
/* Emulator state */
int app_cursor_keys, app_keypad_keys;
/* Backend */
Backend *back;
/* Config that created this session */
Config cfg;
} Session;
/* /*
* Exports from window.c. * Exports from window.c.
*/ */