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

We now have a fairly minimal Mac application.

I'm about to try lashing in the terminal emulator...

[originally from svn r52]
This commit is contained in:
Ben Harris 1999-02-20 22:10:34 +00:00
parent 36cbe625d4
commit e230e36e2f
7 changed files with 389 additions and 51 deletions

View File

@ -1,4 +1,4 @@
# $Id: PuTTY.make,v 1.1.2.3 1999/02/19 21:44:14 ben Exp $
# $Id: PuTTY.make,v 1.1.2.4 1999/02/20 22:10:33 ben Exp $
# This is the Makefile for building PuTTY for the Mac OS.
# Users of non-Mac systems will see some pretty strange characters around.
@ -39,14 +39,14 @@ PuTTY
"{Libraries}Interface.o"
PuTTY ÄÄ {¥MondoBuild¥} bjh21:putty:putty.r
Rez bjh21:putty:putty.r -o {Targ} {Includes} -append
PuTTY ÄÄ {¥MondoBuild¥} putty.r macresid.h
Rez putty.r -o {Targ} {Includes} -append
"{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c
"{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c putty.h macresid.h
{C} mac.c -o {Targ} {COptions}
"{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c
"{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c putty.h
{C} misc.c -o {Targ} {COptions}
"{ObjDir¥68K}ssh.c.o" Ä {¥MondoBuild¥} ssh.c
@ -73,6 +73,6 @@ PuTTY
"{ObjDir¥68K}telnet.c.o" Ä {¥MondoBuild¥} telnet.c
{C} telnet.c -o {Targ} {COptions}
"{ObjDir¥68K}terminal.c.o" Ä {¥MondoBuild¥} terminal.c
"{ObjDir¥68K}terminal.c.o" Ä {¥MondoBuild¥} terminal.c putty.h
{C} terminal.c -o {Targ} {COptions}

226
mac.c
View File

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.1.2.3 1999/02/19 23:51:21 ben Exp $ */
/* $Id: mac.c,v 1.1.2.4 1999/02/20 22:10:33 ben Exp $ */
/*
* mac.c -- miscellaneous Mac-specific routines
*/
@ -10,11 +10,15 @@
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Devices.h>
#include <DiskInit.h>
#include <ToolUtils.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h> /* putty.h needs size_t */
#include "macresid.h"
#include "putty.h"
QDGlobals qd;
@ -23,6 +27,17 @@ int cold = 1;
static void mac_startup(void);
static void mac_eventloop(void);
static void mac_event(EventRecord *);
static void mac_contentclick(WindowPtr, EventRecord *);
static void mac_updatewindow(WindowPtr);
static void mac_keypress(EventRecord *);
static int mac_windowtype(WindowPtr);
static void mac_menucommand(long);
static void mac_adjustcursor(void);
static void mac_adjustmenus(void);
static void mac_closewindow(WindowPtr);
static void mac_zoomwindow(WindowPtr, short);
static void mac_shutdown(void);
int main (int argc, char **argv) {
@ -45,16 +60,16 @@ static void mac_startup(void) {
TEInit();
/* Init Dialog Manager */
InitDialogs(nil);
InitCursor();
cold = 0;
menuBar = GetNewMBar(128);
if (menuBar == NULL)
fatalbox("Unable to create menu bar.");
SetMenuBar(menuBar);
AppendResMenu(GetMenuHandle(128), 'DRVR');
/* adjustmenus */
AppendResMenu(GetMenuHandle(mApple), 'DRVR');
mac_adjustmenus();
DrawMenuBar();
InitCursor();
}
static void mac_eventloop(void) {
@ -62,10 +77,209 @@ static void mac_eventloop(void) {
EventRecord event;
int i;
for (i = 0; i < 100; i++) {
for (;;) {
mac_adjustcursor();
gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, NULL);
mac_adjustcursor();
if (gotevent)
mac_event(&event);
}
fatalbox("I'm bored.");
}
static void mac_event(EventRecord *event) {
short part;
WindowPtr window;
Point pt;
switch (event->what) {
case mouseDown:
part = FindWindow(event->where, &window);
switch (part) {
case inMenuBar:
mac_adjustmenus();
mac_menucommand(MenuSelect(event->where));
break;
case inSysWindow:
SystemClick(event, window);
break;
case inContent:
if (window != FrontWindow())
/* XXX: check for movable modal dboxes? */
SelectWindow(window);
else
mac_contentclick(window, event);
break;
case inGoAway:
if (TrackGoAway(window, event->where))
mac_closewindow(window);
break;
case inDrag:
/* XXX: moveable modal check? */
DragWindow(window, event->where, &qd.screenBits.bounds);
break;
case inGrow:
break;
case inZoomIn:
case inZoomOut:
if (TrackBox(window, event->where, part))
mac_zoomwindow(window, part);
break;
}
break;
case keyDown:
case autoKey:
mac_keypress(event);
break;
case activateEvt:
/* FIXME: Do something */
break;
case updateEvt:
mac_updatewindow((WindowPtr)event->message);
break;
case diskEvt:
if (HiWord(event->message) != noErr) {
SetPt(&pt, 120, 120);
DIBadMount(pt, event->message);
}
break;
}
}
static void mac_contentclick(WindowPtr window, EventRecord *event) {
short item;
switch (mac_windowtype(window)) {
case wTerminal:
/* XXX: Do something. */
break;
case wAbout:
if (DialogSelect(event, &(DialogPtr)window, &item))
switch (item) {
case wiAboutClose:
mac_closewindow(window);
break;
case wiAboutLicence:
/* XXX: Do something */
break;
}
break;
}
}
static void mac_updatewindow(WindowPtr window) {
switch (mac_windowtype(window)) {
case wTerminal:
/* XXX: DO something */
break;
case wAbout:
BeginUpdate(window);
UpdateDialog(window, window->visRgn);
EndUpdate(window);
break;
}
}
/*
* Work out what kind of window we're dealing with.
* Concept shamelessly nicked from SurfWriter.
*/
static int mac_windowtype(WindowPtr window) {
int kind;
if (window == NULL)
return wNone;
kind = ((WindowPeek)window)->windowKind;
if (kind < 0)
return wDA;
else if (kind == userKind)
return wTerminal;
else
return GetWRefCon(window);
}
/*
* Handle a key press
*/
static void mac_keypress(EventRecord *event) {
char key;
if (event->what == keyDown && (event->modifiers & cmdKey)) {
mac_adjustmenus();
mac_menucommand(MenuKey(event->message & charCodeMask));
}
}
static void mac_menucommand(long result) {
short menu, item;
Str255 da;
menu = HiWord(result);
item = LoWord(result);
switch (menu) {
case mApple:
switch (item) {
case iAbout:
GetNewDialog(wAbout, NULL, (GrafPort *)-1);
break;
default:
GetMenuItemText(GetMenuHandle(mApple), item, da);
OpenDeskAcc(da);
break;
}
break;
case mFile:
switch (item) {
case iClose:
mac_closewindow(FrontWindow());
break;
case iQuit:
mac_shutdown();
break;
}
break;
}
HiliteMenu(0);
}
static void mac_closewindow(WindowPtr window) {
switch (mac_windowtype(window)) {
case wDA:
CloseDeskAcc(((WindowPeek)window)->windowKind);
break;
case wTerminal:
/* FIXME: end session and stuff */
break;
default:
CloseWindow(window);
break;
}
}
static void mac_zoomwindow(WindowPtr window, short part) {
/* FIXME: do something */
}
/*
* Make the menus look right before the user gets to see them.
*/
static void mac_adjustmenus(void) {
}
/*
* Make sure the right cursor's being displayed.
*/
static void mac_adjustcursor(void) {
SetCursor(&qd.arrow);
}
static void mac_shutdown(void) {
ExitToShell();
}
void fatalbox(const char *fmt, ...) {

32
macresid.h Normal file
View File

@ -0,0 +1,32 @@
/* $Id: macresid.h,v 1.1.2.1 1999/02/20 22:10:34 ben Exp $ */
/*
* macresid.h -- Mac resource IDs
*
* This file is shared by C and Rez source files
*/
/* Menu bar IDs */
#define MBAR_Main 128
/* Menu IDs */
#define mApple 128
#define mFile 129
/* Menu Items */
/* Apple menu */
#define iAbout 1
/* File menu */
#define iClose 1
#define iQuit 3
/* Window types (and resource IDs) */
#define wNone 0 /* Dummy value for no window */
#define wDA 1 /* DUmmy value for desk accessory */
#define wFatal 128
#define wAbout 129
#define wiAboutClose 1
#define wiAboutLicence 2
#define wTerminal 130
#define wLicence 131

116
putty.r
View File

@ -1,8 +1,13 @@
/* $Id: putty.r,v 1.1.2.4 1999/02/19 23:41:24 ben Exp $ */
/* $Id: putty.r,v 1.1.2.5 1999/02/20 22:10:34 ben Exp $ */
/* PuTTY resources */
#define PICT_RezTemplateVersion 1
#include "Types.r"
/* Get resource IDs we share with C code */
#include "macresid.h"
/*
* Finder-related resources
*/
@ -243,12 +248,12 @@ resource 'icl8' (130, purgeable) {
/* Menu bar */
resource 'MBAR' (128, preload) {
{ 128, 129 }
resource 'MBAR' (MBAR_Main, preload) {
{ mApple, mFile }
};
resource 'MENU' (128, preload) {
128,
resource 'MENU' (mApple, preload) {
mApple,
textMenuProc,
0b11111111111111111111111111111101,
enabled,
@ -259,27 +264,29 @@ resource 'MENU' (128, preload) {
}
};
resource 'MENU' (129, preload) {
129,
resource 'MENU' (mFile, preload) {
mFile,
textMenuProc,
0b11111111111111111111111111111111,
0b11111111111111111111111111111101,
enabled,
"File",
{
"Close", noicon, "W", nomark, plain,
"-", noicon, nokey, nomark, plain,
"Quit", noicon, "Q", nomark, plain,
}
};
/* Fatal error box. Stolen from the Finder. */
resource 'ALRT' (128, "fatalbox", purgeable) {
resource 'ALRT' (wFatal, "fatalbox", purgeable) {
{54, 67, 152, 435},
128,
wFatal,
beepStages,
alertPositionMainScreen
};
resource 'DITL' (128, "fatalbox", purgeable) {
resource 'DITL' (wFatal, "fatalbox", purgeable) {
{ /* array DITLarray: 3 elements */
/* [1] */
{68, 299, 88, 358},
@ -302,3 +309,90 @@ resource 'DITL' (128, "fatalbox", purgeable) {
}
};
/* "About" box */
resource 'DLOG' (wAbout, "about", purgeable) {
{ 0, 0, 120, 186 },
noGrowDocProc,
visible,
goAway,
wAbout, /* RefCon -- identifies the window to PuTTY */
wAbout, /* DITL ID */
"About PuTTY",
alertPositionMainScreen
};
resource 'DITL' (wAbout, "about", purgeable) {
{
{ 87, 116, 107, 173 },
Button { enabled, "Close" },
{ 87, 13, 107, 103 },
Button { enabled, "View Licence" },
{ 13, 13, 29, 173 },
StaticText { disabled, "PuTTY"},
{ 42, 13, 74, 173 },
StaticText { disabled, "Mac Development\n© 1997-9 Simon Tatham"},
}
};
/* Licence box */
resource 'DLOG' (wLicence, "licence", purgeable) {
{ 0, 0, 300, 300 },
noGrowDocProc,
visible,
goAway,
wLicence,
wLicence,
"PuTTY Licence",
alertPositionParentWindowScreen
};
type 'TEXT' {
string;
};
resource 'TEXT' (wLicence, "licence", purgeable) {
"Copyright © 1997-9 Simon Tatham\n"
"Portions copyright Gary S. Brown and Eric Young\n\n"
"Permission is hereby granted, free of charge, to any person "
"obtaining a copy of this software and associated documentation "
"files (the \"Software\"), to deal in the Software without "
"restriction, including without limitation the rights to use, "
"copy, modify, merge, publish, distribute, sublicense, and/or "
"sell copies of the Software, and to permit persons to whom the "
"Software is furnished to do so, subject to the following "
"conditions:\n\n"
"The above copyright notice and this permission notice shall be "
"included in all copies or substantial portions of the Software.\n\n"
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, "
"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "
"MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND "
"NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR "
"ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF "
"CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN "
"CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
"SOFTWARE."
};
#if 0
resource 'DITL' (wLicence, "licence", purgeable) {
{
{ 13, 23, 287, 277 },
Picture { enabled, wLicence }
}
};
resource 'PICT' (wLicence, "licence", purgeable) {
{ 0, 0, 274, 254 },
VersionTwo {
{
LongText { { 16, 0 }, "Copyright © 1997-9 Simon Tatham" },
LongText { { 32, 0 }, "Portions copyright Gary S. Brown and Eric Young" },
}
}
};
#endif

41
ssh.c
View File

@ -1,16 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifndef macintosh
#include <winsock.h>
#endif /* not macintosh */
#include "putty.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#include "ssh.h"
/* Coroutine mechanics for the sillier bits of the code */
@ -30,14 +24,9 @@
#define crStop(z) do{ crLine = 0; return (z); }while(0)
#define crStopV do{ crLine = 0; return; }while(0)
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef macintosh
static SOCKET s = INVALID_SOCKET;
#endif
static unsigned char session_key[32];
static struct ssh_cipher *cipher = NULL;
@ -52,6 +41,11 @@ static enum {
static int size_needed = FALSE;
#ifdef macintosh
static void s_write (unsigned char *buf, int len) {
panic("s_write not implemented");
}
#else /* not macintosh */
static void s_write (char *buf, int len) {
while (len > 0) {
int i = send (s, buf, len, 0);
@ -59,7 +53,13 @@ static void s_write (char *buf, int len) {
len -= i, buf += i;
}
}
#endif /* not macintosh */
#ifdef macintosh
static int s_read (unsigned char *buf, int len) {
panic("s_read not implemented");
}
#else /* not macintosh */
static int s_read (char *buf, int len) {
int ret = 0;
while (len > 0) {
@ -71,6 +71,7 @@ static int s_read (char *buf, int len) {
}
return ret;
}
#endif
static void c_write (char *buf, int len) {
while (len--) {
@ -174,8 +175,8 @@ static void s_wrpkt_start(int type, int len) {
pktout.length = len-5;
if (pktout.maxlen < biglen) {
pktout.maxlen = biglen;
pktout.data = (pktout.data == NULL ? malloc(biglen+4) :
realloc(pktout.data, biglen+4));
pktout.data = (pktout.data == NULL ? malloc(biglen) :
realloc(pktout.data, biglen));
if (!pktout.data)
fatalbox("Out of memory");
}
@ -214,7 +215,7 @@ static void s_wrpkt(void) {
}
static int do_ssh_init(void) {
char c;
unsigned char c;
char version[10];
char vstring[40];
int i;
@ -250,7 +251,7 @@ static int do_ssh_init(void) {
sprintf(vstring, "SSH-%s-7.7.7\n",
(strcmp(version, "1.5") <= 0 ? version : "1.5"));
s_write(vstring, strlen(vstring));
s_write((unsigned char *)vstring, strlen(vstring));
return 1;
}
@ -476,7 +477,7 @@ static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
long len = 0;
for (i = 0; i < 4; i++)
len = (len << 8) + pktin.body[i];
c_write(pktin.body+4, len);
c_write((char *)pktin.body+4, len);
} else if (pktin.type == 1) {
/* SSH_MSG_DISCONNECT: do nothing */
} else if (pktin.type == 14) {

View File

@ -1,17 +1,12 @@
#ifndef macintosh
#include <windows.h>
#include <winsock.h>
#endif /* not macintosh */
#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>
#include "putty.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
static SOCKET s = INVALID_SOCKET;
#define IAC 255 /* interpret as command: */

View File

@ -1,4 +1,6 @@
#ifndef macintosh
#include <windows.h>
#endif /* not macintosh */
#include <stdio.h>
#include <stdlib.h>