From: simon Date: Sat, 25 Sep 2010 07:30:08 +0000 (+0000) Subject: Retire the old Mac Classic port directory! It's been unused for X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/2ff340bdd3941537211af374feaa6023a20529be Retire the old Mac Classic port directory! It's been unused for ages, is increasingly irrelevant now that 'Mac' pretty much universally means something running OS X, is probably bit-rotted past usefulness already, and certainly will be after the next time some major reengineering takes place. git-svn-id: svn://svn.tartarus.org/sgt/putty@9004 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/mac/README.mac b/mac/README.mac deleted file mode 100644 index 4b141e5a..00000000 --- a/mac/README.mac +++ /dev/null @@ -1,104 +0,0 @@ -$Id$ - -Information about PuTTY for the Mac OS --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -This is a port of PuTTY to the Classic Mac OS. It is a work in -progress and should be considered unfinished and insecure. It is -not considered to be of release quality, even if you found it (and -you're reading this) in a PuTTY release source archive. Unless you -know what you're doing, don't use it. - -Compiling it: - - See ../README for generic information. - - To compile PuTTY for Mac OS you will need: - - MPW - - Install this in the usual way. - - Universal Headers - - Install using the script in "Documentation:MPW Users - ReadMe". - - Text Encoding Converter SDK - - Copy contents of "68K Static Libraries" to - "Interfaces&Libraries:Libraries:Libraries". - Copy contents of "Stub Libraries" to - "Interfaces&Libraries:Libraries:SharedLibraries". - - CarbonStdCLib.o - - Copy contents of "CIncludes" to - "Interfaces&Libraries:Interfaces:CIncludes". - Copy contents of "PPCLibraries" to - "Interfaces&Libraries:Libraries:PPCLibraries". - - The "mkputty.mpw" script does all the work, and currently producess a - Classic 68K build of PuTTY called "PuTTY.68k", a non-Carbon PowerPC - build called "PuTTY.ppc", and similar builds of PuTTYtel called - "PuTTYtel.68k" and "PuTTYtel.ppc". The CFM-68K build is currently - disabled because it overflows the global data space and I can't work - out how to stop this happening. The Carbon build doesn't work yet. - -Runtime requirements: - - The Classic 68K build of PuTTY should work on any Macintosh running - System 7.0 or later. It runs in the Classic environment in Mac OS X. - - The CFM-68K build of PuTTY should work on any Macintosh with a 68020, - 68030 or 68040 processor and with either the CFM-68K Runtime Enabler - or Mac OS 7.6.1 or later installed. - - The PowerPC build of PuTTY should work on any Power Macintosh. It - runs in the Classic environment in Mac OS X. - - The Carbon build of PuTTY (when it works) should work on any Power - Macintosh with CarbonLib (and Mac OS 8.1 or later), Mac OS 9 or - Mac OS X installed. - -Known bugs: - * Display is far too slow. - * Real bold doesn't compensate for changing character widths without Color - QuickDraw. [MAYBE FIXED] - * When the last terminal window closes, the Edit menu doesn't get disabled - immediately, which it should. - * When using the "VT100" font, text copied to the clipboard doesn't - get newlines in it, because that font has a graphic character at - position 0x0d. Even if we did insert 0x0d manually, TextEdit - insists on displaying the graphic version, so I think we need a - font switch at this point. This can be seen as a special case of - the need to switch fonts to get odd characters. - * Pasting large blocks of text doesn't work. - * The host key database is currently limited by its implementation to - 2727 host keys. - -Unimplemented features (should be done before release): - * TCP urgent data. - * Listening sockets. - * Changing font size in reponse to resize requests. - * Full screen mode. - * Session configuration. - * Entropy collection. - * Private key files. - * Pageant and PuTTYgen. - * Do something with Open Application Apple Events. - * Close-on-exit. - * Warn-on-quit. - * Non-block cursors. - -Wishlist (after release): - * SFTP client (GUI?) - * Carbon compatibility (requires Open Transport and Navigation Services). - * 'styl' paste, for script codes. - * Handle 'gurl' Apple Events. - -Local Variables: -mode: text -End: diff --git a/mac/mac.c b/mac/mac.c deleted file mode 100644 index 25362061..00000000 --- a/mac/mac.c +++ /dev/null @@ -1,877 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ -/* - * mac.c -- miscellaneous Mac-specific routines - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include /* putty.h needs size_t */ -#include /* for vsprintf */ - -#define PUTTY_DO_GLOBALS - -#include "macresid.h" -#include "putty.h" -#include "ssh.h" -#include "terminal.h" -#include "mac.h" - -Session *sesslist; - -static int cold = 1; -static int borednow = FALSE; -struct mac_gestalts mac_gestalts; -UInt32 sleeptime; -static long timing_next_time; - -static void mac_startup(void); -static void mac_eventloop(void); -#pragma noreturn (mac_eventloop) -static void mac_event(EventRecord *); -static void mac_contentclick(WindowPtr, EventRecord *); -static void mac_growwindow(WindowPtr, EventRecord *); -static void mac_activatewindow(WindowPtr, EventRecord *); -static void mac_suspendresume(EventRecord *); -static void mac_activateabout(WindowPtr, EventRecord *); -static void mac_updatewindow(WindowPtr); -static void mac_updatelicence(WindowPtr); -static void mac_keypress(EventRecord *); -static int mac_windowtype(WindowPtr); -static void mac_menucommand(long); -static void mac_openlicence(void); -static void mac_adjustcursor(RgnHandle); -static void mac_adjustmenus(void); -static void mac_closewindow(WindowPtr); -static void mac_zoomwindow(WindowPtr, short); -#pragma noreturn (cleanup_exit) - -struct mac_windows { - WindowPtr about; - WindowPtr licence; -}; - -struct mac_windows windows; - -int main (int argc, char **argv) { - - mac_startup(); - mac_eventloop(); -} - -#pragma noreturn (main) - -static void mac_startup(void) { - Handle menuBar; - TECInfoHandle ti; - -#if !TARGET_API_MAC_CARBON - /* Init Memory Manager */ - MaxApplZone(); - /* Init QuickDraw */ - InitGraf(&qd.thePort); - /* Init Font Manager */ - InitFonts(); - /* Init Window Manager */ - InitWindows(); - /* Init Menu Manager */ - InitMenus(); - /* Init TextEdit */ - TEInit(); - /* Init Dialog Manager */ - InitDialogs(NULL); -#endif - cold = 0; - - /* Get base system version (only used if there's no better selector) */ - if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || - (mac_gestalts.sysvers &= 0xffff) < 0x700) - fatalbox("PuTTY requires System 7 or newer"); - /* Find out if we've got Color Quickdraw */ - if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) - mac_gestalts.qdvers = gestaltOriginalQD; - /* ... and the Appearance Manager? */ - if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr) - if (Gestalt(gestaltAppearanceAttr, NULL) == noErr) - mac_gestalts.apprvers = 0x0100; - else - mac_gestalts.apprvers = 0; -#if TARGET_RT_MAC_CFM - /* Paranoia: Did we manage to pull in AppearanceLib? */ - if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) - mac_gestalts.apprvers = 0; -#endif -#if TARGET_CPU_68K - mac_gestalts.cntlattr = 0; - mac_gestalts.windattr = 0; -#else - /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ - if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || - &SetControlViewSize == kUnresolvedCFragSymbolAddress) - mac_gestalts.cntlattr = 0; - /* Mac OS 8.5 Window Manager? */ - if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || - &SetWindowContentColor == kUnresolvedCFragSymbolAddress) - mac_gestalts.windattr = 0; - /* Mac OS 8.5 Menu Manager? */ - if (Gestalt(gestaltMenuMgrAttr, &mac_gestalts.menuattr) != noErr) - mac_gestalts.menuattr = 0; -#endif - /* Text Encoding Conversion Manager? */ - if ( -#if TARGET_RT_MAC_CFM - &TECGetInfo == kUnresolvedCFragSymbolAddress || -#else - InitializeUnicodeConverter(NULL) != noErr || -#endif - TECGetInfo(&ti) != noErr) - mac_gestalts.encvvers = 0; - else { - mac_gestalts.encvvers = (*ti)->tecVersion; - mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; - DisposeHandle((Handle)ti); - } - /* Navigation Services? */ - if (NavServicesAvailable()) - mac_gestalts.navsvers = NavLibraryVersion(); - else - mac_gestalts.navsvers = 0; - - sk_init(); - - /* We've been tested with the Appearance Manager */ - if (mac_gestalts.apprvers != 0) - RegisterAppearanceClient(); - - menuBar = GetNewMBar(128); - if (menuBar == NULL) - fatalbox("Unable to create menu bar."); - SetMenuBar(menuBar); - AppendResMenu(GetMenuHandle(mApple), 'DRVR'); - if (mac_gestalts.menuattr & gestaltMenuMgrAquaLayoutMask) { - DeleteMenuItem(GetMenuHandle(mFile), iQuit); - /* Also delete the separator above the Quit item. */ - DeleteMenuItem(GetMenuHandle(mFile), iQuit - 1); - } - mac_adjustmenus(); - DrawMenuBar(); - InitCursor(); - windows.about = NULL; - windows.licence = NULL; - - default_protocol = be_default_protocol; - /* Find the appropriate default port. */ - { - Backend *b = backend_from_proto(default_protocol); - default_port = 0; /* illegal */ - if (b) - default_port = b->default_port; - } - flags = FLAG_INTERACTIVE; - -#if !TARGET_API_MAC_CARBON - { - short vol; - long dirid; - - /* Set the default directory for loading and saving settings. */ - /* XXX Should we create it? */ - if (get_session_dir(FALSE, &vol, &dirid) == noErr) { - LMSetSFSaveDisk(-vol); - LMSetCurDirStore(dirid); - } - } -#endif - - /* Install Apple Event handlers. */ - AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, - NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); - AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, - NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); -} - -void timer_change_notify(long next) -{ - timing_next_time = next; -} - -static void mac_eventloop(void) { - Boolean gotevent; - EventRecord event; - RgnHandle cursrgn; - long next; - long ticksleft; - - cursrgn = NewRgn(); - sleeptime = 0; - for (;;) { - ticksleft=timing_next_time-GETTICKCOUNT(); - if (sleeptime > ticksleft && ticksleft >=0) - sleeptime=ticksleft; - gotevent = WaitNextEvent(everyEvent, &event, sleeptime, cursrgn); - if (timing_next_time <= GETTICKCOUNT()) { - if (run_timers(timing_next_time, &next)) { - timer_change_notify(next); - } - } - - /* - * XXX For now, limit sleep time to 1/10 s to work around - * wake-before-sleep race in MacTCP code. - */ - sleeptime = 6; - mac_adjustcursor(cursrgn); - if (gotevent) { - /* Ensure we get a null event when the real ones run out. */ - sleeptime = 0; - mac_event(&event); - if (borednow) - cleanup_exit(0); - } - if (!gotevent) - sk_poll(); - if (mac_gestalts.apprvers >= 0x100 && mac_frontwindow() != NULL) - IdleControls(mac_frontwindow()); - } - DisposeRgn(cursrgn); -} - -static void mac_event(EventRecord *event) { - short part; - WindowPtr window; - - switch (event->what) { - case mouseDown: - part = FindWindow(event->where, &window); - switch (part) { - case inMenuBar: - mac_adjustmenus(); - mac_menucommand(MenuSelect(event->where)); - break; -#if !TARGET_API_MAC_CARBON - case inSysWindow: - SystemClick(event, window); - break; -#endif - 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? */ -#if TARGET_API_MAC_CARBON - { - BitMap screenBits; - - GetQDGlobalsScreenBits(&screenBits); - DragWindow(window, event->where, &screenBits.bounds); - } -#else - DragWindow(window, event->where, &qd.screenBits.bounds); -#endif - break; - case inGrow: - mac_growwindow(window, event); - 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: - mac_activatewindow((WindowPtr)event->message, event); - break; - case updateEvt: - mac_updatewindow((WindowPtr)event->message); - break; -#if !TARGET_API_MAC_CARBON - case diskEvt: - if (HiWord(event->message) != noErr) { - Point pt; - - SetPt(&pt, 120, 120); - DIBadMount(pt, event->message); - } - break; -#endif - case osEvt: - switch ((event->message & osEvtMessageMask) >> 24) { - case suspendResumeMessage: - mac_suspendresume(event); - break; - } - break; - case kHighLevelEvent: - AEProcessAppleEvent(event); /* errors? */ - break; - } -} - -static void mac_contentclick(WindowPtr window, EventRecord *event) -{ - - if (mac_wininfo(window)->click != NULL) - (*mac_wininfo(window)->click)(window, event); -} - -static void mac_growwindow(WindowPtr window, EventRecord *event) -{ - - if (mac_wininfo(window)->grow != NULL) - (*mac_wininfo(window)->grow)(window, event); -} - -static void mac_activatewindow(WindowPtr window, EventRecord *event) -{ - - mac_adjustmenus(); - if (mac_wininfo(window)->activate != NULL) - (*mac_wininfo(window)->activate)(window, event); -} - -static void mac_updatewindow(WindowPtr window) -{ - - if (mac_wininfo(window)->update != NULL) - (*mac_wininfo(window)->update)(window); -} - -/* - * Work out what kind of window we're dealing with. - */ -static int mac_windowtype(WindowPtr window) -{ - -#if !TARGET_API_MAC_CARBON - if (GetWindowKind(window) < 0) - return wDA; -#endif - return ((WinInfo *)GetWRefCon(window))->wtype; -} - -/* - * Handle a key press - */ -static void mac_keypress(EventRecord *event) { - WindowPtr window; - - window = mac_frontwindow(); - /* - * Check for a command-key combination, but ignore it if it counts - * as a meta-key combination and we're in a terminal window. - */ - if (event->what == keyDown && (event->modifiers & cmdKey) /*&& - !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && - mac_windowtype(window) == wTerminal)*/) { - mac_adjustmenus(); - mac_menucommand(MenuKey(event->message & charCodeMask)); - } else { - if (window != NULL && mac_wininfo(window)->key != NULL) - (*mac_wininfo(window)->key)(window, event); - } -} - -static void mac_menucommand(long result) { - short menu, item; - WindowPtr window; -#if !TARGET_API_MAC_CARBON - Str255 da; -#endif - - menu = HiWord(result); - item = LoWord(result); - window = mac_frontwindow(); - /* Things which do the same whatever window we're in. */ - switch (menu) { - case mApple: - switch (item) { - case iAbout: - mac_openabout(); - goto done; -#if !TARGET_API_MAC_CARBON - default: - GetMenuItemText(GetMenuHandle(mApple), item, da); - OpenDeskAcc(da); - goto done; -#endif - } - break; - case mFile: - switch (item) { - case iNew: - mac_newsession(); - goto done; - case iOpen: - mac_opensession(); - goto done; - case iChange: - mac_reconfig(); - goto done; - case iClose: - mac_closewindow(window); - goto done; - case iSave: - mac_savesession(); - goto done; - case iSaveAs: - mac_savesessionas(); - goto done; - case iDuplicate: - mac_dupsession(); - goto done; - case iQuit: - cleanup_exit(0); - goto done; - } - break; - } - /* If we get here, handling is up to window-specific code. */ - if (window != NULL && mac_wininfo(window)->menu != NULL) - (*mac_wininfo(window)->menu)(window, menu, item); - - done: - HiliteMenu(0); -} - -static void mac_closewindow(WindowPtr window) { - - switch (mac_windowtype(window)) { -#if !TARGET_API_MAC_CARBON - case wDA: - CloseDeskAcc(GetWindowKind(window)); - break; -#endif - default: - if (mac_wininfo(window)->close != NULL) - (*mac_wininfo(window)->close)(window); - break; - } -} - -static void mac_suspendresume(EventRecord *event) -{ - WindowPtr front; - EventRecord fakeevent; - - /* - * We're called either before we're suspended or after we're - * resumed, so we're the front application at this point. - */ - front = FrontWindow(); - if (front != NULL) { - fakeevent.what = activateEvt; - fakeevent.message = (UInt32)front; - fakeevent.when = event->when; - fakeevent.where = event->where; - fakeevent.modifiers = - (event->message & resumeFlag) ? activeFlag : 0; - mac_activatewindow(front, &fakeevent); - } -} - -static void mac_zoomwindow(WindowPtr window, short part) { - - /* FIXME: do something */ -} - -/* - * Make the menus look right before the user gets to see them. - */ -#if TARGET_API_MAC_CARBON -#define EnableItem EnableMenuItem -#define DisableItem DisableMenuItem -#endif -static void mac_adjustmenus(void) { - WindowPtr window; - MenuHandle menu; - - window = mac_frontwindow(); - menu = GetMenuHandle(mApple); - EnableItem(menu, 0); - EnableItem(menu, iAbout); - - menu = GetMenuHandle(mFile); - EnableItem(menu, 0); - EnableItem(menu, iNew); - if (window != NULL) - EnableItem(menu, iClose); - else - DisableItem(menu, iClose); - EnableItem(menu, iQuit); - - if (window != NULL && mac_wininfo(window)->adjustmenus != NULL) - (*mac_wininfo(window)->adjustmenus)(window); - else { - DisableItem(menu, iChange); - DisableItem(menu, iSave); - DisableItem(menu, iSaveAs); - DisableItem(menu, iDuplicate); - menu = GetMenuHandle(mEdit); - DisableItem(menu, 0); - menu = GetMenuHandle(mWindow); - DisableItem(menu, 0); /* Until we get more than 1 item on it. */ - } - DrawMenuBar(); -} - -/* - * Make sure the right cursor's being displayed. - */ -static void mac_adjustcursor(RgnHandle cursrgn) { - Point mouse; - WindowPtr window, front; - short part; -#if TARGET_API_MAC_CARBON - Cursor arrow; - RgnHandle visrgn; -#endif - - GetMouse(&mouse); - LocalToGlobal(&mouse); - part = FindWindow(mouse, &window); - front = FrontWindow(); - if (part != inContent || window == NULL || window != front) { - /* Cursor isn't in the front window, so switch to arrow */ -#if TARGET_API_MAC_CARBON - GetQDGlobalsArrow(&arrow); - SetCursor(&arrow); -#else - SetCursor(&qd.arrow); -#endif - SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); - if (front != NULL) { -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(front), visrgn); - DiffRgn(cursrgn, visrgn, cursrgn); - DisposeRgn(visrgn); -#else - DiffRgn(cursrgn, front->visRgn, cursrgn); -#endif - } - } else { - if (mac_wininfo(window)->adjustcursor != NULL) - (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); - else { -#if TARGET_API_MAC_CARBON - GetQDGlobalsArrow(&arrow); - SetCursor(&arrow); - GetPortVisibleRegion(GetWindowPort(window), cursrgn); -#else - SetCursor(&qd.arrow); - CopyRgn(window->visRgn, cursrgn); -#endif - } - } -} - -pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, - long refcon) -{ - DescType type; - Size size; - - if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, - &type, NULL, 0, &size) == noErr) - return errAEParamMissed; - - borednow = 1; - return noErr; -} - -void cleanup_exit(int status) -{ - -#if !TARGET_RT_MAC_CFM - if (mac_gestalts.encvvers != 0) - TerminateUnicodeConverter(); -#endif - sk_cleanup(); - exit(status); -} - -/* This should only kill the current session, not the whole application. */ -void connection_fatal(void *frontend, char *fmt, ...) { - va_list ap; - Str255 stuff; - Session *s = frontend; - - va_start(ap, fmt); - /* We'd like stuff to be a Pascal string */ - stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); - va_end(ap); - ParamText(stuff, NULL, NULL, NULL); - StopAlert(128, NULL); - - s->session_closed = TRUE; - - if (s->cfg.close_on_exit == FORCE_ON) - mac_closewindow(s->window); -} - -/* Null SSH agent client -- never finds an agent. */ - -int agent_exists(void) -{ - - return FALSE; -} - -int agent_query(void *in, int inlen, void **out, int *outlen, - void (*callback)(void *, void *, int), void *callback_ctx) -{ - - *out = NULL; - *outlen = 0; - return 1; -} - -/* Temporary null routines for testing. */ - -int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, - char *keystr, char *fingerprint, - void (*callback)(void *ctx, int result), void *ctx) -{ - Str255 pappname; - Str255 pfingerprint; - Str255 pkeytype; - Session *s = frontend; - int ret, alertret; - - c2pstrcpy(pappname, appname); - c2pstrcpy(pkeytype, keytype); - c2pstrcpy(pfingerprint, fingerprint); - - /* - * The alert shouldn't be modal, it should be movable modal, or - * a sheet in Aqua. Also, PuTTY might be in the background, in - * which case we should use the Notification Manager to wake up - * the user. In any case, we shouldn't hold up processing of - * other connections' data just because this one's waiting for - * the user. - */ - - /* Verify the key against the cache */ - - ret = verify_host_key(host, port, keytype, keystr); - - if (ret == 0) { /* success - key matched OK */ - return 1; - } else if (ret == 2) { /* key was different */ - ParamText(pappname, pkeytype, pfingerprint, NULL); - alertret=CautionAlert(wWrong, NULL); - if (alertret == 8) { - /* Cancel */ - return 0; - } else if (alertret == 9) { - /* Connect Just Once */ - return 1; - } else { - /* Update Key */ - store_host_key(host, port, keytype, keystr); - return 1; - } - } else /* ret == 1 */ { /* key was absent */ - ParamText(pkeytype, pfingerprint, pappname, NULL); - alertret=CautionAlert(wAbsent, NULL); - if (alertret == 7) { - /* Cancel */ - return 0; - } else if (alertret == 8) { - /* Connect Just Once */ - return 1; - } else { - /* Update Key */ - store_host_key(host, port, keytype, keystr); - return 1; - } - } -} - -int askalg(void *frontend, const char *algtype, const char *algname, - void (*callback)(void *ctx, int result), void *ctx) -{ - return 0; -} - -void old_keyfile_warning(void) -{ - -} - -FontSpec platform_default_fontspec(char const *name) -{ - FontSpec ret; - long smfs; - - if (!strcmp(name, "Font")) { - smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); - if (smfs == 0) - smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); - if (smfs != 0) { - GetFontName(HiWord(smfs), ret.name); - if (ret.name[0] == 0) - memcpy(ret.name, "\pMonaco", 7); - ret.size = LoWord(smfs); - } else { - memcpy(ret.name, "\pMonaco", 7); - ret.size = 9; - } - ret.face = 0; - } else { - ret.name[0] = 0; - } - - return ret; -} - -Filename platform_default_filename(const char *name) -{ - Filename ret; - if (!strcmp(name, "LogFileName")) - FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss); - else - memset(&ret, 0, sizeof(ret)); - return ret; -} - -char *platform_default_s(char const *name) -{ - return NULL; -} - -int platform_default_i(char const *name, int def) -{ - - /* Non-raw cut and paste of line-drawing chars works badly on the - * current Unix stub implementation of the Unicode functions. - * So I'm going to temporarily set the default to raw mode so - * that the failure mode isn't quite so drastically horrid. - * When Unicode comes in, this can all be put right. */ - if (!strcmp(name, "RawCNP")) - return 1; - return def; -} - -void platform_get_x11_auth(char *display, int *proto, - unsigned char *data, int *datalen) -{ - /* SGT: I have no idea whether Mac X servers need anything here. */ -} - -void update_specials_menu(void *frontend) -{ - Session *s = frontend; - WindowPtr front; - - front = mac_frontwindow(); - if (front != NULL && mac_windowsession(front) == s) - mac_adjustmenus(); -} - -void notify_remote_exit(void *frontend) -{ - Session *s = frontend; - int exitcode; - - if (!s->session_closed && - (exitcode = s->back->exitcode(s->backhandle)) >=0) { - s->session_closed = TRUE; - if (s->cfg.close_on_exit == FORCE_ON || - (s->cfg.close_on_exit == AUTO && exitcode == 0)) { - mac_closewindow(s->window); - return; - } - - /* The session's dead */ - - if (s->ldisc) { - ldisc_free(s->ldisc); - s->ldisc = NULL; - } - - if (s->back) { - s->back->free(s->backhandle); - s->backhandle = NULL; - s->back = NULL; - update_specials_menu(s); - } - - { - char title[100]; - sprintf(title, "%.70s (inactive)", appname); - set_title(s, title); - } - } -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/mac.h b/mac/mac.h deleted file mode 100644 index c1dcc74f..00000000 --- a/mac/mac.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * mac.h -- macintosh-specific declarations - */ - -#ifndef PUTTY_MAC_H -#define PUTTY_MAC_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "charset.h" -#include "tree234.h" - -#define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY') -#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI') -#define SESS_TYPE FOUR_CHAR_CODE('Sess') -#define SEED_TYPE FOUR_CHAR_CODE('Seed') -#define HKYS_TYPE FOUR_CHAR_CODE('Hkys') - -struct mac_gestalts { - long sysvers; - long qdvers; - long apprvers; - long cntlattr; - long windattr; - long menuattr; - long encvvers; /* TEC version (from TECGetInfo()) */ - long uncvattr; /* Unicode Converter attributes (frem TECGetInfo()) */ - long navsvers; /* Navigation Services version */ -}; - -extern struct mac_gestalts mac_gestalts; -extern UInt32 sleeptime; - -#if TARGET_RT_MAC_CFM -/* All systems that can use CFM have Color QuickDraw */ -#define HAVE_COLOR_QD() 1 -#else -#define HAVE_COLOR_QD() (mac_gestalts.qdvers > gestaltOriginalQD) -#endif - -/* Every window used by PuTTY has a refCon field pointing to one of these. */ -typedef struct { - struct Session *s; /* Only used in PuTTY */ - struct KeyState *ks; /* Only used in PuTTYgen */ - struct macctrls *mcs; - - void (*activate) (WindowPtr, EventRecord *); - void (*adjustcursor)(WindowPtr, Point, RgnHandle); - void (*adjustmenus) (WindowPtr); - void (*update) (WindowPtr); - void (*click) (WindowPtr, EventRecord *); - void (*grow) (WindowPtr, EventRecord *); - void (*key) (WindowPtr, EventRecord *); - void (*menu) (WindowPtr, short, short); - void (*close) (WindowPtr); - - int wtype; -} WinInfo; - -#define mac_wininfo(w) ((WinInfo *)GetWRefCon(w)) -#define mac_windowsession(w) (((WinInfo *)GetWRefCon(w))->s) -#define mac_winctrls(w) (((WinInfo *)GetWRefCon(w))->mcs) - -union macctrl; - -struct macctrls { - WindowPtr window; - void (*end)(WindowPtr, int); - tree234 *byctrl; - void *data; /* private data for config box */ - unsigned int npanels; - unsigned int curpanel; - union macctrl **panels; /* lists of controls by panel */ - union macctrl *focus; /* Input focus for System 7 */ - union macctrl *defbutton; /* Default button */ - union macctrl *canbutton; /* Cancel button */ - Boolean gotcolour; - RGBColor thecolour; -}; - -typedef struct Session { - struct Session *next; - struct Session **prev; - /* Config that created this session */ - Config cfg; - /* Temporary config for passing to Change Settings */ - Config temp_cfg; - /* Terminal emulator internal state */ - Terminal *term; - /* Display state */ - int font_width, font_height; - /* Line discipline */ - void *ldisc; - /* Backend */ - Backend *back; - void *backhandle; - char *realhost; - /* Logging */ - void *logctx; - /* Unicode stuff */ - struct unicode_data ucsdata; - /* Session closed flag */ - int session_closed; - - /* Mac-specific elements */ - short fontnum; - int font_ascent; - int font_leading; - int font_boldadjust; - Point font_stdnumer; - Point font_stddenom; - Point font_widenumer; - Point font_widedenom; - Point font_bignumer; - Point font_bigdenom; - WindowPtr window; - WindowPtr eventlog_window; - ListHandle eventlog; - PaletteHandle palette; - ControlHandle scrollbar; - WCTabHandle wctab; - int raw_mouse; - UnicodeToTextInfo uni_to_font; /* Only one of uni_to_font and */ - charset_t font_charset; /* font_charset is used at a time. */ - int hasfile; - FSSpec savefile; - - /* Config dialogue bits */ - WindowPtr settings_window; - struct controlbox *ctrlbox; - struct macctrls settings_ctrls; -} Session; - -extern Session *sesslist; - -/* PuTTYgen per-window state */ -typedef struct KeyState { - DialogPtr box; - int collecting_entropy; - int entropy_got, entropy_required, entropy_size; - unsigned *entropy; - ControlHandle progress; -} KeyState; - -#define mac_windowkey(w) (((WinInfo *)GetWRefCon(w))->ks) - -/* from macmisc.c */ -extern WindowPtr mac_frontwindow(void); -/* from macdlg.c */ -extern void mac_newsession(void); -extern void mac_reconfig(void); -extern void mac_dupsession(void); -extern void mac_savesession(void); -extern void mac_savesessionas(void); -/* from maceventlog.c */ -extern void mac_freeeventlog(Session *); -extern void mac_showeventlog(Session *); -/* from macterm.c */ -extern void mac_opensession(void); -extern void mac_startsession(Session *); -/* from macstore.c */ -extern OSErr get_putty_dir(Boolean makeit, short *pVRefNum, long *pDirID); -extern OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID); -extern void *open_settings_r_fsp(FSSpec *); -extern void *open_settings_w_fsp(FSSpec *); -extern int verify_host_key(const char *, int, const char *, const char*); -extern void store_host_key(const char *, int, const char *, const char*); -/* from macucs.c */ -extern void init_ucs(Session *); -/* from macnet.c */ -extern void sk_poll(void); -/* from mtcpnet.c */ -extern OSErr mactcp_init(void); -extern void mactcp_cleanup(void); -extern void mactcp_poll(void); -extern SockAddr mactcp_namelookup(char const *, char **); -extern SockAddr mactcp_nonamelookup(char const *); -extern void mactcp_getaddr(SockAddr, char *, int); -extern int mactcp_hostname_is_local(char *); -extern int mactcp_address_is_local(SockAddr); -extern int mactcp_addrtype(SockAddr); -extern void mactcp_addrcopy(SockAddr, char *); -extern void mactcp_addr_free(SockAddr); -extern Socket mactcp_register(void *, Plug); -extern Socket mactcp_new(SockAddr addr, int, int, int, int, int, Plug); -extern Socket mactcp_newlistener(char *, int, Plug, int, int); -extern char *mactcp_addr_error(SockAddr); -/* from otnet.c */ -extern OSErr ot_init(void); -extern void ot_cleanup(void); -extern void ot_poll(void); -extern SockAddr ot_namelookup(char const *, char **); -extern SockAddr ot_nonamelookup(char const *); -extern void ot_getaddr(SockAddr, char *, int); -extern int ot_hostname_is_local(char *); -extern int ot_address_is_local(SockAddr); -extern int ot_addrtype(SockAddr); -extern void ot_addrcopy(SockAddr, char *); -extern void ot_addr_free(SockAddr); -extern Socket ot_register(void *, Plug); -extern Socket ot_new(SockAddr addr, int, int, int, int, int, Plug); -extern Socket ot_newlistener(char *, int, Plug, int, int); -extern char *ot_addr_error(SockAddr); -/* from macabout.c */ -extern void mac_openabout(void); -/* from macctrls.c */ -extern void macctrl_layoutbox(struct controlbox *, WindowPtr, - struct macctrls *); -extern void macctrl_activate(WindowPtr, EventRecord *); -extern void macctrl_click(WindowPtr, EventRecord *); -extern void macctrl_key(WindowPtr, EventRecord *); -extern void macctrl_update(WindowPtr); -extern void macctrl_adjustmenus(WindowPtr); -extern void macctrl_close(WindowPtr); - - -/* from macpgkey.c */ -extern void mac_newkey(void); -/* Apple Event Handlers (in various files) */ -extern pascal OSErr mac_aevt_oapp(const AppleEvent *, AppleEvent *, long); -extern pascal OSErr mac_aevt_odoc(const AppleEvent *, AppleEvent *, long); -extern pascal OSErr mac_aevt_pdoc(const AppleEvent *, AppleEvent *, long); -extern pascal OSErr mac_aevt_quit(const AppleEvent *, AppleEvent *, long); - -#endif - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/mac_res.r b/mac/mac_res.r deleted file mode 100644 index 35a18dfd..00000000 --- a/mac/mac_res.r +++ /dev/null @@ -1,1300 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2002, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* PuTTY resources */ - -/* - * The space after the # for system includes is to stop mkfiles.pl - * trying to chase them (Rez doesn't support the angle-bracket - * syntax). - */ - -# include "Types.r" -# include "Dialogs.r" -# include "Palettes.r" -# include "Script.r" - -/* Get resource IDs we share with C code */ -#include "macresid.h" - -#include "version.r" - -/* - * Finder-related resources - */ - -/* 'pTTY' is now registered with Apple as PuTTY's signature */ - -type 'pTTY' as 'STR '; - -resource 'pTTY' (0, purgeable) { - "PuTTY experimental Mac port" -}; - -resource 'SIZE' (-1) { - reserved, - acceptSuspendResumeEvents, - reserved, - canBackground, - doesActivateOnFGSwitch, - backgroundAndForeground, - dontGetFrontClicks, - ignoreAppDiedEvents, - is32BitCompatible, - isHighLevelEventAware, - localandRemoteHLEvents, - isStationeryAware, - dontUseTextEditServices, - reserved, - reserved, - reserved, - 2048 * 1024, /* Preferred size */ - 1024 * 1024, /* Minimum size */ -}; - -#define FREF_APPL 128 -#define FREF_Sess 129 -#define FREF_Sesss 130 -#define FREF_HKey 131 -#define FREF_Seed 132 - -resource 'FREF' (FREF_APPL, purgeable) { - /* The application itself */ - 'APPL', FREF_APPL, "" -}; - -resource 'FREF' (FREF_Sess, purgeable) { - /* Saved session */ - 'Sess', FREF_Sess, "" -}; - -resource 'FREF' (FREF_Sesss, purgeable) { - /* Saved session stationery pad*/ - 'sess', FREF_Sesss, "" -}; - -resource 'FREF' (FREF_HKey, purgeable) { - /* SSH host keys database */ - 'HKey', FREF_HKey, "" -}; - -resource 'FREF' (FREF_Seed, purgeable) { - /* Random seed */ - 'Seed', FREF_Seed, "" -}; - -resource 'BNDL' (128, purgeable) { - 'pTTY', 0, - { - 'ICN#', { - FREF_APPL, FREF_APPL, - FREF_Sess, FREF_Sess, - FREF_Sesss, FREF_Sesss - }, - 'FREF', { - FREF_APPL, FREF_APPL, - FREF_Sess, FREF_Sess, - FREF_Sesss, FREF_Sesss, - }; - }; -}; - -/* "Internal" file types, which can't be opened */ -resource 'BNDL' (129, purgeable) { - 'pTTI', 0, - { - 'ICN#', { - FREF_HKey, FREF_HKey, - FREF_Seed, FREF_Seed, - }, - 'FREF', { - FREF_HKey, FREF_HKey, - FREF_Seed, FREF_Seed, - }; - }; -}; - -/* Open resource, for the Translation Manager and Navigation Services */ -resource 'open' (open_pTTY) { - 'pTTY', - { 'Sess' } -}; - -/* Kind resources, for Navigation services etc. */ -resource 'kind' (128) { - 'pTTY', - verBritain, - { - 'Sess', "PuTTY saved session", - } -}; - -resource 'kind' (129) { - 'pTTI', - verBritain, - { - 'HKey', "PuTTY host key database", - 'Seed', "PuTTY random number seed", - } -}; - -#if TARGET_API_MAC_CARBON -/* - * Mac OS X Info.plist. - * See Tech Note TN2013 for details. - * We don't bother with things that Mac OS X seems to be able to get from - * other resources. - */ -type 'plst' as 'TEXT'; - -resource 'plst' (0) { - "\n" - "\n" - "\n" - " \n" - " CFBundleInfoDictionaryVersion 6.0\n" - " CFBundleIdentifier\n" - " org.tartarus.projects.putty.putty\n" - " CFBundleName PuTTY\n" - " CFBundlePackageType APPL\n" - " CFBundleSignature pTTY\n" - " \n" - "\n" -}; - -/* Mac OS X doesn't use this, but Mac OS 9 does. */ -type 'carb' as 'TEXT'; -resource 'carb' (0) { "" }; -#endif - -/* Icons, courtesy of DeRez */ - -/* Application icon */ -resource 'ICN#' (FREF_APPL, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"00003FFE 00004001 00004FF9 00005005" - $"00005355 00004505 00005A05 00002405" - $"00004A85 00019005 000223F9 00047C01" - $"00180201 7FA00C7D 801F1001 9FE22001" - $"A004DFFE AA892002 A0123FFE A82C0000" - $"A0520000 AA6A0000 A00A0000 9FF20000" - $"80020000 80020000 90FA0000 80020000" - $"80020000 7FFC0000 40040000 7FFC", - /* [2] */ - $"00003FFE 00007FFF 00007FFF 00007FFF" - $"00007FFF 00007FFF 00007FFF 00007FFF" - $"00007FFF 0001FFFF 0003FFFF 0007FFFF" - $"001FFFFF 7FFFFFFF FFFFFFFF FFFFFFFF" - $"FFFFFFFE FFFF3FFE FFFE3FFE FFFE0000" - $"FFFE0000 FFFE0000 FFFE0000 FFFE0000" - $"FFFE0000 FFFE0000 FFFE0000 FFFE0000" - $"FFFE0000 7FFC0000 7FFC0000 7FFC" - } -}; -resource 'icl4' (FREF_APPL, purgeable) { - $"000000000000000000FFFFFFFFFFFFF0" - $"00000000000000000FCCCCCCCCCCCCCF" - $"00000000000000000FCEEEEEEEEEEECF" - $"00000000000000000FCE0D0D0D0D0CCF" - $"00000000000000000FCED0FFD0D0D0CF" - $"00000000000000000FCE0F1F0D0D0CCF" - $"00000000000000000FCFF1F0D0D0D0CF" - $"00000000000000000FF11F0D0D0D0CCF" - $"00000000000000000F11F0D0D0D0D0CF" - $"000000000000000FF11F0D0D0D0D0CCF" - $"00000000000000F111FEC0C0C0C0C0CF" - $"0000000000000F111FFFFFCCCCCCCCCF" - $"00000000000FF111111111FCCCCCCCCF" - $"0FFFFFFFFFF111111111FFCCCFFFFFCF" - $"FCCCCCCCCCCFFFFF111F3CCCCCCCCCCF" - $"FCEEEEEEEEEEECF111FCCCCCCCCCCCCF" - $"FCE0D0D0D0D0CF11FFFFFFFFFFFFFFF0" - $"FCED0D0D0D0DF11F00FCCCDDDEEEEAF0" - $"FCE0D0D0D0DF11F000FFFFFFFFFFFFF0" - $"FCED0D0D0DF1FFF00000000000000000" - $"FCE0D0D0DF1FCCF00000000000000000" - $"FCED0D0D0FFD0CF00000000000000000" - $"FCE0D0D0D0D0CCF00000000000000000" - $"FCEC0C0C0C0C0CF00000000000000000" - $"FCCCCCCCCCCCCCF00000000000000000" - $"FCCCCCCCCCCCCCF00000000000000000" - $"FC88CCCCFFFFFCF00000000000000000" - $"FC33CCCCCCCCCCF00000000000000000" - $"FCCCCCCCCCCCCCF00000000000000000" - $"0FFFFFFFFFFFFF000000000000000000" - $"0FCCCDDDEEEEAF000000000000000000" - $"0FFFFFFFFFFFFF" -}; -resource 'icl8' (FREF_APPL, purgeable) { - $"000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFF00" - $"0000000000000000000000000000000000FF2B2B2B2B2B2B2B2B2B2B2B2B2BFF" - $"0000000000000000000000000000000000FF2BFCFCFCFCFCFCFCFCFCFCFC2BFF" - $"0000000000000000000000000000000000FF2BFC2A2A2A2A2A2A2A2A2A002BFF" - $"0000000000000000000000000000000000FF2BFC2A2AFFFF2A2A2A2A2A002BFF" - $"0000000000000000000000000000000000FF2BFC2AFF05FF2A2A2A2A2A002BFF" - $"0000000000000000000000000000000000FF2BFFFF05FF2A2A2A2A2A2A002BFF" - $"0000000000000000000000000000000000FFFF0505FF2A2A2A2A2A2A2A002BFF" - $"0000000000000000000000000000000000FF0505FF2A2A2A2A2A2A2A2A002BFF" - $"000000000000000000000000000000FFFF0505FF2A2A2A2A2A2A2A2A2A002BFF" - $"0000000000000000000000000000FF050505FFFC000000000000000000002BFF" - $"00000000000000000000000000FF050505FFFFFFFFFF2B2B2B2B2B2B2B2B2BFF" - $"0000000000000000000000FFFF050505050505050505FF2B2B2B2B2B2B2B2BFF" - $"00FFFFFFFFFFFFFFFFFFFF050505050505050505FFFF2B2B2BFFFFFFFFFF2BFF" - $"FF2B2B2B2B2B2B2B2B2B2BFFFFFFFFFF050505FFD82B2B2B2B2B2B2B2B2B2BFF" - $"FF2BFCFCFCFCFCFCFCFCFCFCFC2BFF050505FF2B2B2B2B2B2B2B2B2B2B2B2BFF" - $"FF2BFC2A2A2A2A2A2A2A2A2A00FF0505FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00" - $"FF2BFC2A2A2A2A2A2A2A2A2AFF0505FF0000FF2BF7F8F9FAFAFBFBFCFCFDFF00" - $"FF2BFC2A2A2A2A2A2A2A2AFF0505FF000000FFFFFFFFFFFFFFFFFFFFFFFFFF00" - $"FF2BFC2A2A2A2A2A2A2AFF05FFFFFF0000000000000000000000000000000000" - $"FF2BFC2A2A2A2A2A2AFF05FF002BFF0000000000000000000000000000000000" - $"FF2BFC2A2A2A2A2A2AFFFF2A002BFF0000000000000000000000000000000000" - $"FF2BFC2A2A2A2A2A2A2A2A2A002BFF0000000000000000000000000000000000" - $"FF2BFC000000000000000000002BFF0000000000000000000000000000000000" - $"FF2B2B2B2B2B2B2B2B2B2B2B2B2BFF0000000000000000000000000000000000" - $"FF2B2B2B2B2B2B2B2B2B2B2B2B2BFF0000000000000000000000000000000000" - $"FF2BE3E32B2B2B2BFFFFFFFFFF2BFF0000000000000000000000000000000000" - $"FF2BD8D82B2B2B2B2B2B2B2B2B2BFF0000000000000000000000000000000000" - $"FF2B2B2B2B2B2B2B2B2B2B2B2B2BFF0000000000000000000000000000000000" - $"00FFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000000000000000000" - $"00FF2BF7F8F9FAFAFBFBFCFCFDFF000000000000000000000000000000000000" - $"00FFFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'ics#' (FREF_APPL, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"00FF 0081 008D 0035 00D5 0325 F441 822D" - $"B4C1 AB3E AC00 B100 8100 8D00 8100 7E", - /* [2] */ - $"00FF 00FF 00FF 00FF 00FF 03FF FFFF FFFF" - $"FFFF FF7E FF00 FF00 FF00 FF00 FF00 7E" - } -}; -resource 'ics4' (FREF_APPL) { - $"00000000FFFFFFFF" - $"00000000FCCCCCCF" - $"00000000FCEEEECF" - $"00000000FCFFC0CF" - $"00000000FF1FC0CF" - $"000000FF11F000CF" - $"FFFFFF111FCCCCCF" - $"FCCCCCF111FCFFCF" - $"FCEEEF11FFCCCCCF" - $"FCECF1FF0FFFFFF0" - $"FCECFFCF00000000" - $"FCE000CF00000000" - $"FCCCCCCF00000000" - $"FCCCFFCF00000000" - $"FCCCCCCF00000000" - $"0FFFFFF0" -}; -resource 'ics8' (FREF_APPL) { - $"0000000000000000FFFFFFFFFFFFFFFF" - $"0000000000000000FF2B2B2B2B2B2BFF" - $"0000000000000000FF2BFCFCFCFC2BFF" - $"0000000000000000FF2BFFFF2A002BFF" - $"0000000000000000FFFF05FF2A002BFF" - $"000000000000FFFF0505FF0000002BFF" - $"FFFFFFFFFFFF050505FF2B2B2B2B2BFF" - $"FF2B2B2B2B2BFF050505FF2BFFFF2BFF" - $"FF2BFCFCFCFF0505FFFF2B2B2B2B2BFF" - $"FF2BFC2AFF05FFFF00FFFFFFFFFFFF00" - $"FF2BFC2AFFFF2BFF0000000000000000" - $"FF2BFC0000002BFF0000000000000000" - $"FF2B2B2B2B2B2BFF0000000000000000" - $"FF2B2B2BFFFF2BFF0000000000000000" - $"FF2B2B2B2B2B2BFF0000000000000000" - $"00FFFFFFFFFFFF" -}; - -/* Saved-session icon */ - -resource 'ICN#' (FREF_Sess) { - { /* array: 2 elements */ - /* [1] */ - $"1FFFFC00 10000600 10200500 103FFC80" - $"10200440 10000420 17AAAFF0 12000510" - $"12201A10 12002510 12204810 12019510" - $"12222210 12047FD0 12380290 12200D90" - $"123F1090 12022190 1224C090 12090190" - $"12128090 122C4190 12504090 177555D0" - $"10000010 10400110 107FFF10 10400110" - $"10000010 10000010 10000010 1FFFFFF0", - /* [2] */ - $"1FFFFC00 1FFFFE00 1FFFFF00 1FFFFF80" - $"1FFFFFC0 1FFFFFE0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - } -}; -resource 'icl4' (FREF_Sess) { - $"000FFFFFFFFFFFFFFFFFFF0000000000" - $"000F0C0C0C0C0C0C0C0C0FF000000000" - $"000FC0C0C0F0C0C0C0C0CFCF00000000" - $"000F0C0C0CFFFFFFFFFFFFCCF0000000" - $"000FC0C0C0F0C0C0C0C0CFCCCF000000" - $"000F0C0C0CDC0C0C0C0C0FCCCCF00000" - $"000FCFFFDDDDDDDDDDDDDFFFFFFF0000" - $"000F0CFC0CDC0C0C0C0C0F1F0C0F0000" - $"000FC0F0C0D0C0C0C0CFF1FDC0CF0000" - $"000F0CFC0CDC0C0C0CF11F0D0C0F0000" - $"000FC0F0C0D0C0C0CF11F0CDC0CF0000" - $"000F0CFC0CDC0C0FF11F0F0D0C0F0000" - $"000FC0F0C0D0C0F111F0C0FDC0CF0000" - $"000F0CFC0CDC0F111FFFFFFFFF0F0000" - $"000FC0F0C0DFF111111111FDF0CF0000" - $"000F0CFC0CF111111111FF0DFC0F0000" - $"000FC0F0C0DFFFFF111FC0CDF0CF0000" - $"000F0CFC0CDC0CF111FC0C0DFC0F0000" - $"000FC0F0C0C0CF11FFC0C0CDF0CF0000" - $"000F0CFC0C0CF11F0C0C0C0DFC0F0000" - $"000FC0F0C0CF11F0F0C0C0CDF0CF0000" - $"000F0CFC0CF1FF0C0F0C0C0DFC0F0000" - $"000FC0F0CF1FC0C0CEC0C0CDF0CF0000" - $"000F0FFFDFFDDDDDDEDDDDDFFF0F0000" - $"000FC0C0CDC0C0C0C0C0C0CDC0CF0000" - $"000F0C0C0F0C0C0C0C0C0C0F0C0F0000" - $"000FC0C0CFFFFFFFFFFFFFFFC0CF0000" - $"000F0C0C0F0C0C0C0C0C0C0F0C0F0000" - $"000FC0C0C0C0C0C0C0C0C0C0C0CF0000" - $"000F0C0C0C0C0C0C0C0C0C0C0C0F0000" - $"000FC0C0C0C0C0C0C0C0C0C0C0CF0000" - $"000FFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'icl8' (FREF_Sess, purgeable) { - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FFFF000000000000000000" - $"000000FFF5F5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5FF2BFF0000000000000000" - $"000000FFF5F5F5F5F5F5FFFFFFFFFFFFFFFFFFFFFFFF2B2BFF00000000000000" - $"000000FFF5F5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5FF2B2B2BFF000000000000" - $"000000FFF5F5F5F5F5F5F9F5F5F5F5F5F5F5F5F5F5FF2B2B2B2BFF0000000000" - $"000000FFF5FFFFFFF9F9F9F9F9F9F9F9F9F9F9F9F9FFFFFFFFFFFFFF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5F5F5F5FF05FFF5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5F5FFFF05FFF9F5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5FF0505FFF5F9F5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5F5F5F5FF0505FFF5F5F9F5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5F5FFFF0505FFF5FFF5F9F5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5FF050505FFF5F5F5FFF9F5F5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5FF050505FFFFFFFFFFFFFFFFFFF5FF00000000" - $"000000FFF5F5FFF5F5F5F9FFFF050505050505050505FFF9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5FF050505050505050505FFFFF5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9FFFFFFFFFF050505FFF5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5F9F5F5F5FF050505FFF5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5F5F5F5FF0505FFFFF5F5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5F5F5FF0505FFF5F5F5F5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5F5FF0505FFF5FFF5F5F5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5F5FF05FFFFF5F5F5FCF5F5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5F5FFF5F5FF05FFF5F5F5F5F5FCF5F5F5F5F5F9FFF5F5FF00000000" - $"000000FFF5FFFFFFF9FFFFF9F9F9F9F9F9FCF9F9F9F9F9FFFFFFF5FF00000000" - $"000000FFF5F5F5F5F5F9F5F5F5F5F5F5F5F5F5F5F5F5F5F9F5F5F5FF00000000" - $"000000FFF5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5F5F5FFF5F5F5FF00000000" - $"000000FFF5F5F5F5F5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F5F5FF00000000" - $"000000FFF5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5F5F5FFF5F5F5FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'ics#' (FREF_Sess, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"7FE0 4030 4028 403C 5AB4 50D4 5334 5444" - $"5234 54C4 5B14 5544 4814 4FF4 4004 7FFC", - /* [2] */ - $"7FE0 7FF0 7FF8 7FFC 7FFC 7FFC 7FFC 7FFC" - $"7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC" - } -}; -resource 'ics4' (FREF_Sess) { - $"0FFFFFFFFFF00000" - $"0F0C0C0C0CFF0000" - $"0FC0C0C0C0FCF000" - $"0F0C0C0C0CFFFF00" - $"0FCFDDDDDDFFCF00" - $"0F0F0C0CFF1F0F00" - $"0FCFC0FF11FDCF00" - $"0F0F0F111F0D0F00" - $"0FCFC0F111FDCF00" - $"0F0F0F11FF0D0F00" - $"0FCFF1FFC0CDCF00" - $"0F0FCFDDDDDD0F00" - $"0FC0F0C0C0CFCF00" - $"0F0CFFFFFFFF0F00" - $"0FC0C0C0C0C0CF00" - $"0FFFFFFFFFFFFF" -}; -resource 'ics8' (FREF_Sess) { - $"00FFFFFFFFFFFFFFFFFFFF0000000000" - $"00FFF5F5F5F5F5F5F5F5FFFF00000000" - $"00FFF5F5F5F5F5F5F5F5FF2BFF000000" - $"00FFF5F5F5F5F5F5F5F5FFFFFFFF0000" - $"00FFF5FFF9F9F9F9F9F9FFFFF5FF0000" - $"00FFF5FFF5F5F5F5FFFF05FFF5FF0000" - $"00FFF5FFF5F5FFFF0505FFF9F5FF0000" - $"00FFF5FFF5FF050505FFF5F9F5FF0000" - $"00FFF5FFF5F5FF050505FFF9F5FF0000" - $"00FFF5FFF5FF0505FFFFF5F9F5FF0000" - $"00FFF5FFFF05FFFFF5F5F5F9F5FF0000" - $"00FFF5FFF8FFF9F9F9F9F9F9F5FF0000" - $"00FFF5F5FFF5F5F5F5F5F5FFF5FF0000" - $"00FFF5F5FFFFFFFFFFFFFFFFF5FF0000" - $"00FFF5F5F5F5F5F5F5F5F5F5F5FF0000" - $"00FFFFFFFFFFFFFFFFFFFFFFFFFF" -}; - -/* Saved session stationery pad icon */ -resource 'ICN#' (FREF_Sesss, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"3FFFFFE0 20000020 20400238 207FFE28" - $"20400228 20000028 2F555628 24000A28" - $"24403428 24004A28 24409028 24032A28" - $"24444428 2408FFA8 24700528 24401B28" - $"247E2128 24044328 24498128 24120328" - $"24250128 24588328 24A08128 2EEAAFE8" - $"20000848 20800888 20FFF908 20800A08" - $"20000C08 3FFFF808 08000008 0FFFFFF8", - /* [2] */ - $"3FFFFFE0 3FFFFFE0 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 3FFFFFF8 3FFFFFF8" - $"3FFFFFF8 3FFFFFF8 0FFFFFF8 0FFFFFF8" - } -}; -resource 'icl4' (FREF_Sesss, purgeable) { - $"00FFFFFFFFFFFFFFFFFFFFFFFFF00000" - $"00FC0C0C0C0C0C0C0C0C0C0C0CF00000" - $"00F0C0C0CFC0C0C0C0C0C0F0C0FFF000" - $"00FC0C0C0FFFFFFFFFFFFFFC0CFDF000" - $"00F0C0C0CFC0C0C0C0C0C0F0C0FDF000" - $"00FC0C0C0D0C0C0C0C0C0CDC0CFDF000" - $"00F0FFFDDDDDDDDDDDDDDFF0C0FDF000" - $"00FC0F0C0D0C0C0C0C0CF1FC0CFDF000" - $"00F0CFC0CDC0C0C0C0FF1FD0C0FDF000" - $"00FC0F0C0D0C0C0C0F11FCDC0CFDF000" - $"00F0CFC0CDC0C0C0F11FC0D0C0FDF000" - $"00FC0F0C0D0C0CFF11FCFCDC0CFDF000" - $"00F0CFC0CDC0CF111FC0CFD0C0FDF000" - $"00FC0F0C0D0CF111FFFFFFFFFCFDF000" - $"00F0CFC0CDFF111111111FDFC0FDF000" - $"00FC0F0C0F111111111FFCDF0CFDF000" - $"00F0CFC0CDFFFFF111F0C0DFC0FDF000" - $"00FC0F0C0D0C0F111F0C0CDF0CFDF000" - $"00F0CFC0C0C0F11FF0C0C0DFC0FDF000" - $"00FC0F0C0C0F11FC0C0C0CDF0CFDF000" - $"00F0CFC0C0F11FCFC0C0C0DFC0FDF000" - $"00FC0F0C0F1FFC0CFC0C0CDF0CFDF000" - $"00F0CFC0F1F0C0C0E0C0C0DFC0FDF000" - $"00FCFFFDFFDDDDDDEDDDFFFFFFFDF000" - $"00F0C0C0D0C0C0C0C0C0FCCCCFDDF000" - $"00FC0C0CFC0C0C0C0C0CFCCCFDDCF000" - $"00F0C0C0FFFFFFFFFFFFFCCFDDCCF000" - $"00FC0C0CFC0C0C0C0C0CFCFDDCCCF000" - $"00F0C0C0C0C0C0C0C0C0FFDDCCCCF000" - $"00FFFFFFFFFFFFFFFFFFFDDCCCCCF000" - $"0000FDDDDDDDDDDDDDDDDDCCCCCCF000" - $"0000FFFFFFFFFFFFFFFFFFFFFFFFF0" -}; -resource 'icl8' (FREF_Sesss, purgeable) { - $"0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000" - $"0000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF0000000000" - $"0000FFF5F5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5F5FFF5F5F5FFFFFF000000" - $"0000FFF5F5F5F5F5F5FFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F5F5FFF9FF000000" - $"0000FFF5F5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5F5FFF5F5F5FFF9FF000000" - $"0000FFF5F5F5F5F5F5F9F5F5F5F5F5F5F5F5F5F5F5F5F9F5F5F5FFF9FF000000" - $"0000FFF5FFFFFFF9F9F9F9F9F9F9F9F9F9F9F9F9F9FFFFF5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5F5F5F5FF05FFF5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5F5FFFF05FFF9F5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5F5F5F5F5FF0505FFF5F9F5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5F5F5F5FF0505FFF5F5F9F5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5F5FFFF0505FFF5FFF5F9F5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5FF050505FFF5F5F5FFF9F5F5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5FF050505FFFFFFFFFFFFFFFFFFF5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9FFFF050505050505050505FFF9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5FF050505050505050505FFFFF5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9FFFFFFFFFF050505FFF5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F9F5F5F5FF050505FFF5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F5F5F5FF0505FFFFF5F5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F5F5FF0505FFF5F5F5F5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5F5FF0505FFF5FFF5F5F5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5F5FF05FFFFF5F5F5FCF5F5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5F5FFF5F5FF05FFF5F5F5F5F5FCF5F5F5F5F5F9FFF5F5FFF9FF000000" - $"0000FFF5FFFFFFF9FFFFF9F9F9F9F9F9FCF9F9F9FFFFFFFFFFFFFFF9FF000000" - $"0000FFF5F5F5F5F5F9F5F5F5F5F5F5F5F5F5F5F5FF2B2B2BF7FFF9F7FF000000" - $"0000FFF5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5FF2B2BF7FFF9F72BFF000000" - $"0000FFF5F5F5F5F5FFFFFFFFFFFFFFFFFFFFFFFFFF2BF7FFF9F72BF6FF000000" - $"0000FFF5F5F5F5F5FFF5F5F5F5F5F5F5F5F5F5F5FFF7FFF9F72BF6F6FF000000" - $"0000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FFFFF9F72BF6F6F6FF000000" - $"0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F72BF6F6F6F6FF000000" - $"00000000FFF9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F72BF6F6F6F6F6FF000000" - $"00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'ics#' (FREF_Sesss, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"7FF8 4008 756E 61AA 666A 688A 646A 698A" - $"762A 6A8A 507A 5FD2 4062 7FC2 1002 1FFE", - /* [2] */ - $"7FF8 7FF8 7FFE 7FFE 7FFE 7FFE 7FFE 7FFE" - $"7FFE 7FFE 7FFE 7FFE 7FFE 7FFE 1FFE 1FFE" - } -}; -resource 'ics4' (FREF_Sesss, purgeable) { - $"0FFFFFFFFFFFF000" - $"0FC0C0C0C0C0F000" - $"0FFDDDDDDFFCFFF0" - $"0FF0C0CFF1F0FDF0" - $"0FFC0FF11FDCFDF0" - $"0FF0F111F0D0FDF0" - $"0FFC0F111FDCFDF0" - $"0FF0F11FF0D0FDF0" - $"0FFF1FFC0CDCFDF0" - $"0FFCFDDDDDD0FDF0" - $"0F0F0C0C0FFFFDF0" - $"0FCFFFFFFFCFDDF0" - $"0F0C0C0C0FFDDCF0" - $"0FFFFFFFFFDDC0F0" - $"000FDDDDDDDC0CF0" - $"000FFFFFFFFFFFF0" -}; -resource 'ics8' (FREF_Sesss, purgeable) { - $"00FFFFFFFFFFFFFFFFFFFFFFFF000000" - $"00FFF5F5F5F5F5F5F5F5F5F5FF000000" - $"00FFFFF9F9F9F9F9F9FFFFF5FFFFFF00" - $"00FFFFF5F5F5F5FFFF05FFF5FFF9FF00" - $"00FFFFF5F5FFFF0505FFF9F5FFF9FF00" - $"00FFFFF5FF050505FFF5F9F5FFF9FF00" - $"00FFFFF5F5FF050505FFF9F5FFF9FF00" - $"00FFFFF5FF0505FFFFF5F9F5FFF9FF00" - $"00FFFFFF05FFFFF5F5F5F9F5FFF9FF00" - $"00FFFFF8FFF9F9F9F9F9F9F5FFF9FF00" - $"00FFF5FFF5F5F5F5F5FFFFFFFFF9FF00" - $"00FFF5FFFFFFFFFFFFFF2BFFF9F9FF00" - $"00FFF5F5F5F5F5F5F5FFFFF9F9F5FF00" - $"00FFFFFFFFFFFFFFFFFFF9F9F5F5FF00" - $"000000FFF9F9F9F9F9F9F9F5F5F5FF00" - $"000000FFFFFFFFFFFFFFFFFFFFFFFF" -}; - -/* Known hosts icon */ -resource 'ICN#' (FREF_HKey, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"1FFFFC00 10000600 10000500 1FFFFC80" - $"10000440 10000420 1FFFFFF0 10000010" - $"13FC0F90 1C03F0F0 15FA8090 150A8090" - $"1D0B80F0 150A8050 15FA8050 1C038070" - $"143A8050 14028050 1FFFABF0 12048110" - $"13FCFF10 1AAAAAB0 10000010 17FFFFD0" - $"14000050 15252250 15555550 15252250" - $"14000050 17FFFFD0 10000010 1FFFFFF0", - /* [2] */ - $"1FFFFC00 1FFFFE00 1FFFFF00 1FFFFF80" - $"1FFFFFC0 1FFFFFE0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - } -}; -resource 'icl4' (FREF_HKey, purgeable) { - $"000FFFFFFFFFFFFFFFFFFF0000000000" - $"000F00000000000000000FF000000000" - $"000F00000000000000000FCF00000000" - $"000FFFFFFFFFFFFFFFFFFFCCF0000000" - $"000F00000000000000000FCCCF000000" - $"000F00000000000000000FCCCCF00000" - $"000FFFFFFFFFFFFFFFFFFFFFFFFF0000" - $"000F00000000000000000000000F0000" - $"000F00FFFFFFFF000000FFFFF00F0000" - $"000FFFCCCCCCCCFFFFFFCCCCFFFF0000" - $"000F0FCEEEEECCF0FCCCCCCCF00F0000" - $"000F0FCE0D0D0CF0FCCCCCCCF00F0000" - $"000FFFCED0D0CCFFFCCCCCCCFFFF0000" - $"000F0FCE0D0D0CF0FCCCCCCCCF0F0000" - $"000F0FCCC0C0CCF0FCCCCCCCCF0F0000" - $"000FFFCCCCCCCCFFFCCCCCCCCFFF0000" - $"000F0FCCCCFFFCF0FCCCCCCCCF0F0000" - $"000F0FCCCCCCCCF0FCCCCCCCCF0F0000" - $"000FFFFFFFFFFFFFFDDDDDDFFFFF0000" - $"000F00FCCDDEEF00FDDDDDDF000F0000" - $"000F00FFFFFFFF00FFFFFFFF000F0000" - $"000F0C0C0C0C0C0C0C0C0C0C0C0F0000" - $"000FC0C0C0C0C0C0C0C0C0C0C0CF0000" - $"000F0FFFFFFFFFFFFFFFFFFFFF0F0000" - $"000FCF0000000000000000000FCF0000" - $"000F0F0F00F00F0F00F000F00F0F0000" - $"000FCF0F0F0F0F0F0F0F0F0F0FCF0000" - $"000F0F0F00F00F0F00F000F00F0F0000" - $"000FCF0000000000000000000FCF0000" - $"000F0FFFFFFFFFFFFFFFFFFFFF0F0000" - $"000FC0C0C0C0C0C0C0C0C0C0C0CF0000" - $"000FFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'icl8' (FREF_HKey, purgeable) { - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000" - $"000000FF0000000000000000000000000000000000FFFF000000000000000000" - $"000000FF0000000000000000000000000000000000FFF6FF0000000000000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F6FF00000000000000" - $"000000FF0000000000000000000000000000000000FFF6F6F6FF000000000000" - $"000000FF0000000000000000000000000000000000FFF6F6F6F6FF0000000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000" - $"000000FF0000000000000000000000000000000000000000000000FF00000000" - $"000000FF0000FFFFFFFFFFFFFFFF000000000000FFFFFFFFFF0000FF00000000" - $"000000FFFFFF2B2B2B2B2B2B2B2BFFFFFFFFFFFF2B2B2B2BFFFFFFFF00000000" - $"000000FF00FF2BFCFCFCFCFCF82BFF00FF2B2B2B2B2B2B2BFF0000FF00000000" - $"000000FF00FF2BFC2A2A2A2A002BFF00FF2B2B2B2B2B2B2BFF0000FF00000000" - $"000000FFFFFF2BFC2A2A2A2A002BFFFFFF2B2B2B2B2B2B2BFFFFFFFF00000000" - $"000000FF00FF2BFC2A2A2A2A002BFF00FF2B2B2B2B2B2B2B2BFF00FF00000000" - $"000000FF00FF2BF800000000002BFF00FF2B2B2B2B2B2B2B2BFF00FF00000000" - $"000000FFFFFF2B2B2B2B2B2B2B2BFFFFFF2B2B2B2B2B2B2B2BFFFFFF00000000" - $"000000FF00FF2B2B2B2BFFFFFF2BFF00FF2B2B2B2B2B2B2B2BFF00FF00000000" - $"000000FF00FF2B2B2B2B2B2B2B2BFF00FF2B2B2B2B2B2B2B2BFF00FF00000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F9F9F9F9F9FFFFFFFFFF00000000" - $"000000FF0000FFF7F8F9FAFBFCFF0000FFF9F9F9F9F9F9FF000000FF00000000" - $"000000FF0000FFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF000000FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFF5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FF00000000" - $"000000FFF5FF00000000000000000000000000000000000000FFF5FF00000000" - $"000000FFF5FF00FF0000FF0000FF00FF0000FF000000FF0000FFF5FF00000000" - $"000000FFF5FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FFF5FF00000000" - $"000000FFF5FF00FF0000FF0000FF00FF0000FF000000FF0000FFF5FF00000000" - $"000000FFF5FF00000000000000000000000000000000000000FFF5FF00000000" - $"000000FFF5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FF00000000" - $"000000FFF5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5FF00000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" -}; - -/* Random seed icon */ - -resource 'ICN#' (FREF_Seed, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"1FFFFC00 18F36600 161EF500 1CC92C80" - $"1CF2EC40 10662C20 108E07F0 151F0490" - $"1E00C4F0 1803BBD0 1FC5BE10 108B5A90" - $"1B3C4F50 1267AC90 14B60470 1BB791B0" - $"17F4D2B0 1DC1F830 1B029450 1B753DD0" - $"145A8170 11390DD0 1E15A8B0 1CC4CD90" - $"154ECED0 15C9CF30 172CDB50 12617970" - $"15E45C90 1D4B9890 15CE4430 1FFFFFF0", - /* [2] */ - $"1FFFFC00 1FFFFE00 1FFFFF00 1FFFFF80" - $"1FFFFFC0 1FFFFFE0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - } -}; -resource 'icl4' (FREF_Seed) { - $"000FFFFFFFFFFFFFFFFFFF0000000000" - $"000FFC0CFFFF0CFF1FFC0FF000000000" - $"000F0FF0C0CFFFF1FFFFCFCF00000000" - $"000FFF0CFF0CF11F0CFCFFCCF0000000" - $"000FFFC0FFFF11F0FFF0FFCCCF000000" - $"000F0C0C0FF11FFC0CFCFFCCCCF00000" - $"000FC0C0F111FFF0C0C0CFFFFFFF0000" - $"000F0F0F111FFFFF0C0C0F0CFC0F0000" - $"000FFFF111111111FFC0CFC0FFFF0000" - $"000FF111111111FFFCFFF0FFFF0F0000" - $"000FFFFFFF111FCFF0FFFFF0C0CF0000" - $"000F0C0CF111FCFF0F0FFCFCFC0F0000" - $"000FF0FF11FFFFC0CFC0FFFFCFCF0000" - $"000F0CF11FFC0FFFFCFCFF0CFC0F0000" - $"000FCF11F0FFCFF0C0C0CFC0CFFF0000" - $"000FF1FFFCFF0FFFFC0F0C0FFCFF0000" - $"000F1FFFFFFFCFC0FFCFC0F0F0FF0000" - $"000FFF0FFF0C0C0FFFFFFC0C0CFF0000" - $"000FF0FFC0C0C0F0F0CF0FC0CFCF0000" - $"000FFCFF0FFF0F0F0CFFFF0FFF0F0000" - $"000FCFC0CF0FF0F0F0C0C0CFCFFF0000" - $"000F0C0F0CFFFC0F0C0CFF0FFF0F0000" - $"000FFFF0C0CFCFCFF0F0F0C0F0FF0000" - $"000FFF0CFF0C0F0CFF0CFF0FFC0F0000" - $"000FCFCF0FC0FFF0FFC0FFF0FFCF0000" - $"000F0F0FFF0CFC0FFF0CFFFF0CFF0000" - $"000FCFFFC0F0FFC0FFCFF0FFCFCF0000" - $"000F0CFC0FFC0C0F0FFFFC0F0FFF0000" - $"000FCFCFFFF0CFC0CFCFFFC0F0CF0000" - $"000FFF0F0F0CF0FFFC0FFC0CFC0F0000" - $"000FCFCFFFC0FFF0CFC0CFC0C0FF0000" - $"000FFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'icl8' (FREF_Seed) { - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000" - $"000000FFFFF5F5F5FFFFFFFFF5F5FFFF05FFFFF5F5FFFF000000000000000000" - $"000000FFF5FFFFF5F5F5F5FFFFFFFF05FFFFFFFFF5FF2BFF0000000000000000" - $"000000FFFFFFF5F5FFFFF5F5FF0505FF0000FFF5FFFF2B2BFF00000000000000" - $"000000FFFFFFF5F5FFFFFFFF0505FFF5FFFFFFF5FFFF2B2B2BFF000000000000" - $"000000FFF5F5F5F5F5FFFF0505FFFFF5F5F5FFF5FFFF2B2B2B2BFF0000000000" - $"000000FFF5F5F5F5FF050505FFFFFFF5F5F5F5F5F5FFFFFFFFFFFFFF00000000" - $"000000FFF5FFF5FF050505FFFFFFFFFFF5F5F5F5F5FFF5F5FFF5F5FF00000000" - $"000000FFFFFFFF050505050505050505FFFFF5F5F5FFF5F5FFFFFFFF00000000" - $"000000FFFF050505050505050505FFFFFFF5FFFFFFF5FFFFFFFFF5FF00000000" - $"000000FFFFFFFFFFFFFF050505FFF5FFFFF5FFFFFFFFFFF5F5F5F5FF00000000" - $"000000FFF5F5F5F5FF050505FFF5FFFFF5FFF5FFFFF5FFF5FFF5F5FF00000000" - $"000000FFFFF5FFFF0505FFFFFFFFF5F5F5FFF5F5FFFFFFFFF5FFF5FF00000000" - $"000000FFF5F5FF0505FFFFF5F5FFFFFFFFF5FFF5FFFFF5F5FFF5F5FF00000000" - $"000000FFF5FF0505FFF5FFFFF5FFFFF5F5F5F5F5F5FFF5F5F5FFFFFF00000000" - $"000000FFFF05FFFFFFF5FFFFF5FFFFFFFFF5F5FFF5F5F5FFFFF5FFFF00000000" - $"000000FF05FFFFFFFFFFFFFFF5FFF5F5FFFFF5FFF5F5FFF5FFF5FFFF00000000" - $"000000FFFFFFF5FFFFFFF5F5F5F5F5FFFFFFFFFFFFF5F5F5F5F5FFFF00000000" - $"000000FFFFF5FFFFF5F5F5F5F5F5FF00FFF5F5FFF5FFF5F5F5FFF5FF00000000" - $"000000FFFFF5FFFFF5FFFFFFF5FF00FFF5F5FFFFFFFFF5FFFFFFF5FF00000000" - $"000000FFF5FFF5F5F5FFF5FFFF00FF00FFF5F5F5F5F5F5FFF5FFFFFF00000000" - $"000000FFF5F5F5FFF5F5FFFFFF0000FFF5F5F5F5FFFFF5FFFFFF00FF00000000" - $"000000FFFFFFFFF5F5F5F5FFF5FF00FFFFF5FFF5FFF5F5F5FF00FFFF00000000" - $"000000FFFFFFF5F5FFFFF5F5F5FF0000FFFFF5F5FFFFF5FFFF0000FF00000000" - $"000000FFF5FFF5FFF5FFF5F5FFFFFF00FFFFF5F5FFFFFFF5FFFF00FF00000000" - $"000000FFF5FFF5FFFFFFF5F5FFF5F5FFFFFFF5F5FFFFFFFFF5F5FFFF00000000" - $"000000FFF5FFFFFFF5F5FFF5FFFFF5F5FFFFF5FFFFF5FFFFF5FFF5FF00000000" - $"000000FFF5F5FFF5F5FFFFF5F5F5F5FFF5FFFFFFFFF5F5FFF5FFFFFF00000000" - $"000000FFF5FFF5FFFFFFFFF5F5FFF5F5F5FFF5FFFFFFF5F5FFF5F5FF00000000" - $"000000FFFFFFF5FFF5FFF5F5FFF5FFFFFFF5F5FFFFF5F5F5FFF5F5FF00000000" - $"000000FFF5FFF5FFFFFFF5F5FFFFFFF5F5FFF5F5F5FFF5F5F5F5FFFF00000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'ics#' (FREF_Seed) { - { /* array: 2 elements */ - /* [1] */ - $"7FE0 56B0 59A8 637C 51DC 6794 59AC 76EC" - $"7224 7C6C 743C 71AC 505C 459C 4424 7FFC", - /* [2] */ - $"7FE0 7FF0 7FF8 7FFC 7FFC 7FFC 7FFC 7FFC" - $"7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC" - } -}; -resource 'ics4' (FREF_Seed) { - $"0FFFFFFFFFF00000" - $"0F0F0FF1FCFF0000" - $"0FCFF11FF0FCF000" - $"0FF111FF0FFFFF00" - $"0FCF111FFFCFFF00" - $"0FF11FFFFC0F0F00" - $"0F1FF0CFF0F0FF00" - $"0FFF0FFCFFFCFF00" - $"0FFFC0F0C0F0CF00" - $"0FFFFF0C0FFCFF00" - $"0FFFCFC0C0FFFF00" - $"0FFF0C0FFCFCFF00" - $"0FCFC0C0CFCFFF00" - $"0F0C0F0FFC0FFF00" - $"0FC0CFC0C0F0CF00" - $"0FFFFFFFFFFFFF" -}; -resource 'ics8' (FREF_Seed) { - $"00FFFFFFFFFFFFFFFFFFFF0000000000" - $"00FFF5FFF5FFFF05FFF5FFFF00000000" - $"00FFF5FFFF0505FFFFF5FF2BFF000000" - $"00FFFF050505FFFFF5FFFFFFFFFF0000" - $"00FFF5FF050505FFFFFFF5FFFFFF0000" - $"00FFFF0505FFFFFFFFF5F5FFF5FF0000" - $"00FF05FFFFF5F5FFFFF5FFF5FFFF0000" - $"00FFFFFFF5FFFFF5FFFFFFF5FFFF0000" - $"00FFFFFFF5F5FFF5F5F5FFF5F5FF0000" - $"00FFFFFFFFFFF5F5F5FFFFF5FFFF0000" - $"00FFFFFFF5FFF5F5F5F5FFFFFFFF0000" - $"00FFFFFFF5F5F5FFFFF5FFF5FFFF0000" - $"00FFF5FFF5F5F5F5F5FFF5FFFFFF0000" - $"00FFF5F5F5FFF5FFFFF5F5FFFFFF0000" - $"00FFF5F5F5FFF5F5F5F5FFF5F5FF0000" - $"00FFFFFFFFFFFFFFFFFFFFFFFFFF" -}; - -/* - * Resources to copy into created files - */ - -/* - * Application-missing message string, for random seed and host key database - * files. - */ -resource 'STR ' (-16397, purgeable) { - "This file is used internally by PuTTY. It cannot be opened." -}; - -/* Missing-application name string, for saved sessions. */ -resource 'STR ' (-16396, purgeable) { - "PuTTY" -}; - -/* ResEdit template resource for saved sessions. */ - -type 'TMPL' { - array { - pstring; - literal longint; - }; -}; - -resource 'TMPL' (TMPL_Int, "Int ", purgeable) { - { "Value", 'DLNG' } -}; - -/* - * Internal resources - */ - -/* Menu bar */ - -resource 'MBAR' (MBAR_Main, preload) { - { mApple, mFile, mEdit, mWindow } -}; - -resource 'MENU' (mApple, preload) { - mApple, - textMenuProc, - 0b11111111111111111111111111111101, - enabled, - apple, - { - "About PuTTY\0xc9", noicon, nokey, nomark, plain, - "-", noicon, nokey, nomark, plain, - } -}; - -resource 'MENU' (mFile, preload) { - mFile, - textMenuProc, - 0b11111111111111111111110111101011, - enabled, - "File", - { - "New", noicon, "N", nomark, plain, - "Open\0xc9", noicon, "O", nomark, plain, - "-", noicon, nokey, nomark, plain, - "Change Settings", noicon, nokey, nomark, plain, - "-", noicon, nokey, nomark, plain, - "Close", noicon, "W", nomark, plain, - "Save", noicon, "S", nomark, plain, - "Save As\0xc9", noicon, nokey, nomark, plain, - "Duplicate", noicon, "D", nomark, plain, - "-", noicon, nokey, nomark, plain, - "Quit", noicon, "Q", nomark, plain, - } -}; - -resource 'MENU' (mEdit, preload) { - mEdit, - textMenuProc, - 0b11111111111111111111111111111101, - enabled, - "Edit", - { - "Undo", noicon, "Z", nomark, plain, - "-", noicon, nokey, nomark, plain, - "Cut", noicon, "X", nomark, plain, - "Copy", noicon, "C", nomark, plain, - "Paste", noicon, "V", nomark, plain, - "Clear", noicon, nokey, nomark, plain, - "Select All", noicon, "A", nomark, plain, - } -}; - -resource 'MENU' (mWindow, preload) { - mWindow, - textMenuProc, - 0b11111111111111111111111111111111, - enabled, - "Window", - { - "Show Event Log", noicon, nokey, nomark, plain, - } -}; - -/* Fatal error box. Stolen from the Finder. */ - -resource 'ALRT' (wFatal, "fatalbox", purgeable) { - {54, 67, 152, 435}, - wFatal, - beepStages, - alertPositionMainScreen -}; - -resource 'DITL' (wFatal, "fatalbox", purgeable) { - { /* array DITLarray: 3 elements */ - /* [1] */ - {68, 299, 88, 358}, - Button { - enabled, - "OK" - }, - /* [2] */ - {68, 227, 88, 286}, - StaticText { - disabled, - "" - }, - /* [3] */ - {7, 74, 55, 358}, - StaticText { - disabled, - "^0" - } - } -}; - -/* Caution box. Stolen from the Finder. */ - -resource 'ALRT' (wQuestion, "questionbox", purgeable) { - {54, 67, 152, 435}, - wQuestion, - beepStages, - alertPositionMainScreen -}; - -resource 'DITL' (wQuestion, "fatalbox", purgeable) { - { /* array DITLarray: 3 elements */ - /* [1] */ - {68, 299, 88, 358}, - Button { - enabled, - "OK" - }, - /* [2] */ - {68, 227, 88, 286}, - Button { - enabled, - "Cancel" - }, - /* [3] */ - {7, 74, 55, 358}, - StaticText { - disabled, - "^0" - } - } -}; - -/* Absent host key */ - -resource 'ALRT' (wAbsent, "absent", purgeable) { - {37, 67, 337, 435}, - wAbsent, - beepStages, - alertPositionMainScreen -}; - -resource 'DITL' (wAbsent, "absent", purgeable) { - { /* array DITLarray: 8 elements */ - /* [1] */ - {10, 72, 60, 357}, - StaticText { - disabled, - "The server's host key is not cached. You " - "have no guarantee that the server is the " - "computer you think it is." - }, - /* [2] */ - {65, 72, 113, 355}, - StaticText { - disabled, - "The server's ^0 key fingerprint is:\n^1" - }, - /* [3] */ - {121, 72, 172, 354}, - StaticText { - disabled, - "If you trust this host, hit Add Key to add " - "the key to ^2's cache and carry on " - "connecting." - }, - /* [4] */ - {178, 72, 226, 354}, - StaticText { - disabled, - "If you want to carry on connecting just " - "once, without adding the key to the cache, " - "select Just Once." - }, - /* [5] */ - {233, 72, 271, 353}, - StaticText { - disabled, - "If you do not trust this host, hit Cancel " - "to abandon the connection." - }, - /* [6] */ - {275, 72, 295, 139}, - Button { - enabled, - "Add Key" - }, - /* [7] */ - {275, 217, 295, 277}, - Button { - enabled, - "Cancel" - }, - /* [8] */ - {275, 290, 295, 360}, - Button { - enabled, - "Just Once" - } - } -}; - -/* Wrong host key */ - -resource 'ALRT' (wWrong, "wrong", purgeable) { - {32, 67, 422, 435}, - wWrong, - beepStages, - alertPositionMainScreen -}; - -resource 'DITL' (wWrong, "wrong", purgeable) { - { /* array DITLarray: 9 elements */ - /* [1] */ - {10, 72, 26, 358}, - StaticText { - disabled, - "WARNING - POTENTIAL SECURITY BREACH!" - }, - /* [2] */ - {32, 72, 131, 357}, - StaticText { - disabled, - "The server's host key does not match the " - "one ^0 has cached. This means that either " - "the server administrator has changed " - "the host key, or you have actually connected " - "to another computer pretending to be the " - "server." - }, - /* [3] */ - {136, 72, 190, 356}, - StaticText { - disabled, - "The new ^1 key fingerprint is:\n^2" - }, - /* [4] */ - {190, 72, 238, 357}, - StaticText { - disabled, - "If you were expecting this change and " - "trust the new key, hit Update Key to update " - "^0's cache and continue connecting." - }, - /* [5] */ - {246, 72, 294, 358}, - StaticText { - disabled, - "If you want to carry on connecting just " - "once, without adding the key to the cache, " - "select Just Once." - }, - /* [6] */ - {301, 72, 349, 358}, - StaticText { - disabled, - "If you do not trust this host, hit Cancel " - "to abandon the connection. This is the " - "ONLY guaranteed safe choice." - }, - /* [7] */ - {360, 72, 380, 163}, - Button { - enabled, - "Update Key" - }, - /* [8] */ - {360, 217, 380, 277}, - Button { - enabled, - "Cancel" - }, - /* [9] */ - {360, 290, 380, 360}, - Button { - enabled, - "Just Once" - } - } -}; - -/* Terminal window */ - -resource 'WIND' (wTerminal, "terminal", purgeable) { - { 0, 0, 200, 200 }, - zoomDocProc, - invisible, - goAway, - 0x0, - "untitled", - staggerParentWindowScreen -}; - -resource 'CNTL' (cVScroll, "vscroll", purgeable) { - { 0, 0, 48, 16 }, - 0, invisible, 0, 0, - scrollBarProc, 0, "" -}; - -/* Settings dialogue */ - -resource 'WIND' (wSettings, "settings", purgeable) { - { 0, 0, 432, 626 }, - noGrowDocProc, - invisible, - goAway, - 0x0, - "untitled", - staggerParentWindowScreen -}; - -/* Event log */ -resource 'WIND' (wEventLog, "event log", purgeable) { - { 0, 0, 200, 200 }, - zoomDocProc, - invisible, - goAway, - 0x0, - "PuTTY Event Log", - staggerParentWindowScreen -}; - -/* "About" box */ - -resource 'DLOG' (wAbout, "about", purgeable) { - { 0, 0, 120, 240 }, - noGrowDocProc, - invisible, - goAway, - wAbout, /* RefCon -- identifies the window to PuTTY */ - wAbout, /* DITL ID */ - "About PuTTY", - alertPositionMainScreen -}; - -resource 'dlgx' (wAbout, "about", purgeable) { - versionZero { - kDialogFlagsUseThemeBackground | kDialogFlagsUseThemeControls - } -}; - -resource 'DITL' (wAbout, "about", purgeable) { - { - { 87, 13, 107, 227 }, - Button { enabled, "View Licence" }, - { 13, 13, 29, 227 }, - StaticText { disabled, "PuTTY"}, - { 42, 13, 74, 227 }, - StaticText { disabled, "Some version or other\n" - "Copyright © 1997-2010 Simon Tatham"}, - } -}; - -/* Licence box */ - -resource 'WIND' (wLicence, "licence", purgeable) { - { 0, 0, 250, 400 }, - noGrowDocProc, - visible, - goAway, - wLicence, - "PuTTY Licence", - alertPositionParentWindowScreen -}; - -type 'TEXT' { - string; -}; - -resource 'TEXT' (wLicence, "licence", purgeable) { - "PuTTY is copyright 1997-2010 Simon Tatham.\n" - "\n" - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry, " - "Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus " - "Kuhn, Colin Watson, and CORE SDI S.A.\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." -}; - -/* Custom xDEFs */ - -data 'CDEF' (CDEF_EditBox) { - $"4EF9 00000000" -}; -data 'CDEF' (CDEF_Default) { - $"4EF9 00000000" -}; -data 'CDEF' (CDEF_ListBox) { - $"4EF9 00000000" -}; -data 'CDEF' (CDEF_GroupBox) { - $"43F9 00000000" -}; - -/* List box template */ - -resource 'ldes' (ldes_Default) { - versionZero { - 0, /* rows */ - 1, /* cols */ - 0, 0, /* default cell size */ - hasVertScroll, noHorizScroll, - 0, /* LDEF number */ - noGrowSpace - } -}; diff --git a/mac/macabout.c b/mac/macabout.c deleted file mode 100644 index 4711b06a..00000000 --- a/mac/macabout.c +++ /dev/null @@ -1,189 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2002, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "mac.h" -#include "macresid.h" - -static struct mac_windows { - WindowPtr about; - WindowPtr licence; -} windows; - -static void mac_openlicence(void); - -static void mac_clickabout(WindowPtr window, EventRecord *event) -{ - short item; - DialogRef dialog; - - dialog = GetDialogFromWindow(window); - if (DialogSelect(event, &dialog, &item)) - switch (item) { - case wiAboutLicence: - mac_openlicence(); - break; - } -} - -static void mac_activateabout(WindowPtr window, EventRecord *event) -{ - DialogRef dialog; - DialogItemType itemtype; - Handle itemhandle; - short item; - Rect itemrect; - int active; - - dialog = GetDialogFromWindow(window); - active = (event->modifiers & activeFlag) != 0; - GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); - HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); - DialogSelect(event, &dialog, &item); -} - -static void mac_updateabout(WindowPtr window) -{ -#if TARGET_API_MAC_CARBON - RgnHandle rgn; -#endif - - BeginUpdate(window); -#if TARGET_API_MAC_CARBON - rgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), rgn); - UpdateDialog(GetDialogFromWindow(window), rgn); - DisposeRgn(rgn); -#else - UpdateDialog(window, window->visRgn); -#endif - EndUpdate(window); -} - -static void mac_closeabout(WindowPtr window) -{ - - windows.about = NULL; - DisposeDialog(GetDialogFromWindow(window)); -} - -static void mac_updatelicence(WindowPtr window) -{ - Handle h; - int len; - long fondsize; - Rect textrect; - - SetPort((GrafPtr)GetWindowPort(window)); - BeginUpdate(window); - fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); - TextFont(HiWord(fondsize)); - TextSize(LoWord(fondsize)); - h = Get1Resource('TEXT', wLicence); - len = GetResourceSizeOnDisk(h); -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(window), &textrect); -#else - textrect = window->portRect; -#endif - if (h != NULL) { - HLock(h); - TETextBox(*h, len, &textrect, teFlushDefault); - HUnlock(h); - } - EndUpdate(window); -} - -static void mac_closelicence(WindowPtr window) -{ - - windows.licence = NULL; - DisposeWindow(window); -} - -void mac_openabout(void) -{ - DialogItemType itemtype; - Handle item; - VersRecHndl vers; - Rect box; - StringPtr longvers; - WinInfo *wi; - - if (windows.about) - SelectWindow(windows.about); - else { - windows.about = - GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->wtype = wAbout; - wi->update = &mac_updateabout; - wi->click = &mac_clickabout; - wi->activate = &mac_activateabout; - wi->close = &mac_closeabout; - SetWRefCon(windows.about, (long)wi); - vers = (VersRecHndl)Get1Resource('vers', 1); - if (vers != NULL && *vers != NULL) { - longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; - GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, - &itemtype, &item, &box); - assert(itemtype & kStaticTextDialogItem); - SetDialogItemText(item, longvers); - } - ShowWindow(windows.about); - } -} - -static void mac_openlicence(void) -{ - WinInfo *wi; - - if (windows.licence) - SelectWindow(windows.licence); - else { - windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->wtype = wLicence; - wi->update = &mac_updatelicence; - wi->close = &mac_closelicence; - SetWRefCon(windows.licence, (long)wi); - ShowWindow(windows.licence); - } -} - diff --git a/mac/macctrls.c b/mac/macctrls.c deleted file mode 100644 index e5e774d9..00000000 --- a/mac/macctrls.c +++ /dev/null @@ -1,2345 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "mac.h" -#include "macresid.h" -#include "dialog.h" -#include "tree234.h" - -/* Range of menu IDs for popup menus */ -#define MENU_MIN 1024 -#define MENU_MAX 2048 - - -union macctrl { - struct macctrl_generic { - enum { - MACCTRL_TEXT, - MACCTRL_EDITBOX, - MACCTRL_RADIO, - MACCTRL_CHECKBOX, - MACCTRL_BUTTON, - MACCTRL_LISTBOX, - MACCTRL_POPUP, - MACCTRL_GROUPBOX - } type; - /* Template from which this was generated */ - union control *ctrl; - /* Next control in this panel */ - union macctrl *next; - void *privdata; - int freeprivdata; - } generic; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - } text; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - ControlRef tblabel; - ControlRef tbbutton; - MenuRef menu; - int menuid; - unsigned int nids; - int *ids; - } editbox; - struct { - struct macctrl_generic generic; - ControlRef *tbctrls; - ControlRef tblabel; - } radio; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - } checkbox; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - ControlRef tbring; - } button; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - ControlRef tbup; - ControlRef tbdown; - ListHandle list; - unsigned int nids; - int *ids; - } listbox; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - MenuRef menu; - int menuid; - unsigned int nids; - int *ids; - } popup; - struct { - struct macctrl_generic generic; - ControlRef tbctrl; - } groupbox; -}; - -struct mac_layoutstate { - Point pos; - Point boxpos; - char *boxname; - unsigned int width; - unsigned int panelnum; -}; - -#define ctrlevent(mcs, mc, event) do { \ - if ((mc)->generic.ctrl->generic.handler != NULL) \ - (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\ - (mcs)->data, (event)); \ -} while (0) - -#define findbyctrl(mcs, ctrl) \ - find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find) - -static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *, - WindowPtr, struct macctrls *); -static void macctrl_hideshowpanel(struct macctrls *, unsigned int, int); -static void macctrl_switchtopanel(struct macctrls *, unsigned int); -static void macctrl_setfocus(struct macctrls *, union macctrl *); -static void macctrl_text(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_editbox(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_radio(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_checkbox(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_button(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_listbox(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_popup(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void macctrl_groupbox(struct macctrls *, WindowPtr, - struct mac_layoutstate *, union control *); -static void draglist_up(union macctrl *, struct macctrls *); -static void draglist_down(union macctrl *, struct macctrls *); - -#if !TARGET_API_MAC_CARBON -static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef, - ControlDefProcMessage, SInt32); -static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef, - ControlDefProcMessage, SInt32); -static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16, ControlRef, - ControlDefProcMessage, SInt32); -static pascal SInt32 macctrl_sys7_groupbox_cdef(SInt16, ControlRef, - ControlDefProcMessage, SInt32); -#endif - -#if !TARGET_API_MAC_CARBON -/* - * This trick enables us to keep all the CDEF code in the main - * application, which makes life easier. For details, see - * . - */ - -#pragma options align=mac68k -typedef struct { - short jmpabs; /* 4EF9 */ - ControlDefUPP theUPP; -} **PatchCDEF; -#pragma options align=reset -#endif - -static void macctrl_init() -{ -#if !TARGET_API_MAC_CARBON - static int inited = 0; - PatchCDEF cdef; - - if (inited) return; - cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox); - (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef); - cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default); - (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef); - cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_ListBox); - (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_listbox_cdef); - cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_GroupBox); - (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_groupbox_cdef); - inited = 1; -#endif -} - - -static int macctrl_cmp_byctrl(void *av, void *bv) -{ - union macctrl *a = (union macctrl *)av; - union macctrl *b = (union macctrl *)bv; - - if (a->generic.ctrl < b->generic.ctrl) - return -1; - else if (a->generic.ctrl > b->generic.ctrl) - return +1; - else - return 0; -} - -static int macctrl_cmp_byctrl_find(void *av, void *bv) -{ - union control *a = (union control *)av; - union macctrl *b = (union macctrl *)bv; - - if (a < b->generic.ctrl) - return -1; - else if (a > b->generic.ctrl) - return +1; - else - return 0; -} - -static union control panellist; - -static void panellist_handler(union control *ctrl, void *dlg, void *data, - int event) -{ - struct macctrls *mcs = dlg; - - /* XXX what if there's no selection? */ - if (event == EVENT_SELCHANGE) - macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1); -} - -void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, - struct macctrls *mcs) -{ - int i; - struct mac_layoutstate curstate; - ControlRef root; - Rect rect; - - macctrl_init(); - if (mac_gestalts.apprvers >= 0x100) - CreateRootControl(window, &root); -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(window), &rect); -#else - rect = window->portRect; -#endif - mcs->window = window; - mcs->byctrl = newtree234(macctrl_cmp_byctrl); - mcs->focus = NULL; - mcs->defbutton = NULL; - mcs->canbutton = NULL; - mcs->curpanel = 1; - /* Count the number of panels */ - mcs->npanels = 1; - for (i = 1; i < cb->nctrlsets; i++) - if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname)) - mcs->npanels++; - mcs->panels = snewn(mcs->npanels, union macctrl *); - memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels); - curstate.panelnum = 0; - - curstate.pos.h = rect.left + 13; - curstate.pos.v = rect.top + 13; - curstate.width = 160; - panellist.listbox.type = CTRL_LISTBOX; - panellist.listbox.handler = &panellist_handler; - panellist.listbox.height = 20; - panellist.listbox.percentwidth = 100; - macctrl_listbox(mcs, window, &curstate, &panellist); - /* XXX Start with panel 1 active */ - - curstate.pos.h = rect.left + 13 + 160 + 13; - curstate.pos.v = rect.bottom - 33; - curstate.width = rect.right - (rect.left + 13 + 160) - (13 * 2); - for (i = 0; i < cb->nctrlsets; i++) { - if (i > 0 && strcmp(cb->ctrlsets[i]->pathname, - cb->ctrlsets[i-1]->pathname)) { - curstate.pos.v = rect.top + 13; - curstate.panelnum++; - assert(curstate.panelnum < mcs->npanels); - dlg_listbox_add(&panellist, mcs, cb->ctrlsets[i]->pathname); - } - macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs); - } - macctrl_switchtopanel(mcs, 1); - macctrl_hideshowpanel(mcs, 0, TRUE); - /* 14 = proxies, 19 = portfwd, 20 = SSH bugs */ -} - - - -#define MAXCOLS 16 - -static void macctrl_layoutset(struct mac_layoutstate *curstate, - struct controlset *s, - WindowPtr window, struct macctrls *mcs) -{ - unsigned int i, j, ncols, colstart, colspan; - struct mac_layoutstate cols[MAXCOLS], pos; - - /* Start a containing box, if we have a boxname. */ - if (s->boxname && *s->boxname) { - curstate->boxpos = curstate->pos; - if (s->boxtitle) { - curstate->boxname = s->boxtitle; - curstate->pos.v += 10; /* XXX determine font height */ - } else { - curstate->boxname = NULL; - } - curstate->pos.v += 6; - curstate->pos.h += 12; - curstate->width -= 24; - } - - /* Draw a title, if we have one. */ - if (!s->boxname && s->boxtitle) { - union control *ctrl = snew(union control); - ctrl->generic.handler = NULL; - ctrl->text.label = dupstr(s->boxtitle); - macctrl_text(mcs, window, curstate, ctrl); - /* FIXME: should be highlighted, centred or boxed */ - } - - cols[0] = *curstate; - ncols = 1; - - for (i = 0; i < s->ncontrols; i++) { - union control *ctrl = s->ctrls[i]; - - colstart = COLUMN_START(ctrl->generic.column); - colspan = COLUMN_SPAN(ctrl->generic.column); - if (ctrl->generic.type == CTRL_COLUMNS) { - if (ctrl->columns.ncols != 1) { - ncols = ctrl->columns.ncols; - assert(ncols <= MAXCOLS); - for (j = 0; j < ncols; j++) { - cols[j] = cols[0]; - if (j > 0) - cols[j].pos.h = cols[j-1].pos.h + cols[j-1].width + 6; - if (j == ncols - 1) - cols[j].width = curstate->width - - (cols[j].pos.h - curstate->pos.h); - else - cols[j].width = (curstate->width + 6) * - ctrl->columns.percentages[j] / 100 - 6; - } - } else { - for (j = 0; j < ncols; j++) - if (cols[j].pos.v > cols[0].pos.v) - cols[0].pos.v = cols[j].pos.v; - cols[0].width = curstate->width; - ncols = 1; - } - } else { - pos = cols[colstart]; - pos.width = cols[colstart + colspan - 1].width + - (cols[colstart + colspan - 1].pos.h - cols[colstart].pos.h); - - for (j = colstart; j < colstart + colspan; j++) - if (pos.pos.v < cols[j].pos.v) - pos.pos.v = cols[j].pos.v; - - switch (ctrl->generic.type) { - case CTRL_TEXT: - macctrl_text(mcs, window, &pos, ctrl); - break; - case CTRL_EDITBOX: - macctrl_editbox(mcs, window, &pos, ctrl); - break; - case CTRL_RADIO: - macctrl_radio(mcs, window, &pos, ctrl); - break; - case CTRL_CHECKBOX: - macctrl_checkbox(mcs, window, &pos, ctrl); - break; - case CTRL_BUTTON: - macctrl_button(mcs, window, &pos, ctrl); - break; - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - macctrl_popup(mcs, window, &pos, ctrl); - else - macctrl_listbox(mcs, window, &pos, ctrl); - break; - } - for (j = colstart; j < colstart + colspan; j++) - cols[j].pos.v = pos.pos.v; - } - } - for (j = 0; j < ncols; j++) - if (cols[j].pos.v > curstate->pos.v) - curstate->pos.v = cols[j].pos.v; - - if (s->boxname && *s->boxname) { - union control *ctrl = snew(union control); - /* We're coming out of a box, so set the width back */ - curstate->pos.h -= 12; - curstate->width += 24; - /* And draw the box to the original width */ - macctrl_groupbox(mcs, window, curstate, ctrl); - } -} - -static void macctrl_hideshowpanel(struct macctrls *mcs, unsigned int panel, - int showit) -{ - union macctrl *mc; - int j; - -#define hideshow(c) do { \ - if (showit) ShowControl(c); else HideControl(c); \ -} while (0) - - for (mc = mcs->panels[panel]; mc != NULL; mc = mc->generic.next) { -#if !TARGET_API_MAC_CARBON - if (mcs->focus == mc) - macctrl_setfocus(mcs, NULL); -#endif - switch (mc->generic.type) { - case MACCTRL_TEXT: - hideshow(mc->text.tbctrl); - break; - case MACCTRL_EDITBOX: - hideshow(mc->editbox.tbctrl); - if (mc->editbox.tblabel != NULL) - hideshow(mc->editbox.tblabel); - if (mc->editbox.tbbutton != NULL) - hideshow(mc->editbox.tbbutton); - break; - case MACCTRL_RADIO: - for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) - hideshow(mc->radio.tbctrls[j]); - if (mc->radio.tblabel != NULL) - hideshow(mc->radio.tblabel); - break; - case MACCTRL_CHECKBOX: - hideshow(mc->checkbox.tbctrl); - break; - case MACCTRL_BUTTON: - hideshow(mc->button.tbctrl); - if (mc->button.tbring != NULL) - hideshow(mc->button.tbring); - break; - case MACCTRL_LISTBOX: - hideshow(mc->listbox.tbctrl); - if (mc->listbox.tbup != NULL) - hideshow(mc->listbox.tbup); - if (mc->listbox.tbdown != NULL) - hideshow(mc->listbox.tbdown); - /* - * At least under Mac OS 8.1, hiding a list box - * doesn't hide its scroll bars. - */ -#if TARGET_API_MAC_CARBON - hideshow(GetListVerticalScrollBar(mc->listbox.list)); -#else - hideshow((*mc->listbox.list)->vScroll); -#endif - break; - case MACCTRL_POPUP: - hideshow(mc->popup.tbctrl); - break; - case MACCTRL_GROUPBOX: - hideshow(mc->groupbox.tbctrl); - break; - } - } -} - -static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) -{ - - macctrl_hideshowpanel(mcs, mcs->curpanel, FALSE); - macctrl_hideshowpanel(mcs, which, TRUE); - mcs->curpanel = which; -} - -#if !TARGET_API_MAC_CARBON -/* - * System 7 focus manipulation - */ -static void macctrl_defocus(union macctrl *mc) -{ - - assert(mac_gestalts.apprvers < 0x100); - switch (mc->generic.type) { - case MACCTRL_EDITBOX: - TEDeactivate((TEHandle)(*mc->editbox.tbctrl)->contrlData); - break; - } -} - -static void macctrl_enfocus(union macctrl *mc) -{ - - assert(mac_gestalts.apprvers < 0x100); - switch (mc->generic.type) { - case MACCTRL_EDITBOX: - TEActivate((TEHandle)(*mc->editbox.tbctrl)->contrlData); - break; - } -} - -static void macctrl_setfocus(struct macctrls *mcs, union macctrl *mc) -{ - - if (mcs->focus == mc) - return; - if (mcs->focus != NULL) - macctrl_defocus(mcs->focus); - mcs->focus = mc; - if (mc != NULL) - macctrl_enfocus(mc); -} -#endif - -static void macctrl_text(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds; - SInt16 height; - - assert(ctrl->text.label != NULL); - mc->generic.type = MACCTRL_TEXT; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 16; - if (mac_gestalts.apprvers >= 0x100) { - Size olen; - - mc->text.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, - kControlStaticTextProc, (long)mc); - SetControlData(mc->text.tbctrl, kControlEntireControl, - kControlStaticTextTextTag, - strlen(ctrl->text.label), ctrl->text.label); - GetControlData(mc->text.tbctrl, kControlEntireControl, - kControlStaticTextTextHeightTag, - sizeof(height), &height, &olen); - } -#if !TARGET_API_MAC_CARBON - else { - TEHandle te; - - mc->text.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, - SYS7_TEXT_PROC, (long)mc); - te = (TEHandle)(*mc->text.tbctrl)->contrlData; - TESetText(ctrl->text.label, strlen(ctrl->text.label), te); - height = TEGetHeight(1, (*te)->nLines, te); - } -#endif - SizeControl(mc->text.tbctrl, curstate->width, height); - curstate->pos.v += height + 6; - add234(mcs->byctrl, mc); - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; -} - -static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect lbounds, bounds, butbounds; - static int nextmenuid = MENU_MIN; - int menuid; - MenuRef menu; - - mc->generic.type = MACCTRL_EDITBOX; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - lbounds.left = curstate->pos.h; - lbounds.top = curstate->pos.v; - if (ctrl->editbox.percentwidth == 100) { - if (ctrl->editbox.label != NULL) { - lbounds.right = lbounds.left + curstate->width; - lbounds.bottom = lbounds.top + 16; - curstate->pos.v += 18; - } - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - } else { - lbounds.right = lbounds.left + - curstate->width * (100 - ctrl->editbox.percentwidth) / 100; - lbounds.bottom = lbounds.top + 22; - bounds.left = lbounds.right; - bounds.right = lbounds.left + curstate->width; - } - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 22; - - if (ctrl->editbox.has_list) { - butbounds = bounds; - butbounds.left = butbounds.right - 20; - bounds.right -= 26; /* enough for 6 px gap and a button */ - } - - if (mac_gestalts.apprvers >= 0x100) { - if (ctrl->editbox.label == NULL) - mc->editbox.tblabel = NULL; - else { - mc->editbox.tblabel = NewControl(window, &lbounds, NULL, FALSE, - 0, 0, 0, kControlStaticTextProc, - (long)mc); - SetControlData(mc->editbox.tblabel, kControlEntireControl, - kControlStaticTextTextTag, - strlen(ctrl->editbox.label), ctrl->editbox.label); - } - InsetRect(&bounds, 3, 3); - mc->editbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, - ctrl->editbox.password ? - kControlEditTextPasswordProc : - kControlEditTextProc, (long)mc); - } -#if !TARGET_API_MAC_CARBON - else { - if (ctrl->editbox.label == NULL) - mc->editbox.tblabel = NULL; - else { - mc->editbox.tblabel = NewControl(window, &lbounds, NULL, FALSE, - 0, 0, 0, SYS7_TEXT_PROC, - (long)mc); - TESetText(ctrl->editbox.label, strlen(ctrl->editbox.label), - (TEHandle)(*mc->editbox.tblabel)->contrlData); - } - mc->editbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, - SYS7_EDITBOX_PROC, (long)mc); - } -#endif - - if (ctrl->editbox.has_list) { - while (GetMenuHandle(nextmenuid) != NULL) - if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN; - menuid = nextmenuid++; - menu = NewMenu(menuid, "\pdummy"); - if (menu == NULL) goto nomenu; - mc->editbox.menu = menu; - mc->editbox.menuid = menuid; - InsertMenu(menu, kInsertHierarchicalMenu); - mc->editbox.nids = 0; - mc->editbox.ids = NULL; - - mc->editbox.tbbutton = NewControl(window, &butbounds, NULL, FALSE, - popupTitleLeftJust, menuid, 0, - popupMenuProc + popupFixedWidth, - (long)mc); - } - - nomenu: - - curstate->pos.v += 28; - add234(mcs->byctrl, mc); - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - ctrlevent(mcs, mc, EVENT_REFRESH); -} - -#if !TARGET_API_MAC_CARBON -static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant, - ControlRef control, - ControlDefProcMessage msg, - SInt32 param) -{ - RgnHandle rgn; - Rect rect; - TEHandle te; - long ssfs; - Point mouse; - - switch (msg) { - case initCntl: - rect = (*control)->contrlRect; - if (variant == SYS7_EDITBOX_VARIANT) - InsetRect(&rect, 3, 3); /* 2 if it's 20 pixels high */ - te = TENew(&rect, &rect); - ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize); - (*te)->txSize = LoWord(ssfs); - (*te)->txFont = HiWord(ssfs); - (*control)->contrlData = (Handle)te; - return noErr; - case dispCntl: - TEDispose((TEHandle)(*control)->contrlData); - return 0; - case drawCntl: - if ((*control)->contrlVis) { - rect = (*control)->contrlRect; - if (variant == SYS7_EDITBOX_VARIANT) { - PenNormal(); - FrameRect(&rect); - InsetRect(&rect, 3, 3); - } - EraseRect(&rect); - (*(TEHandle)(*control)->contrlData)->viewRect = rect; - TEUpdate(&rect, (TEHandle)(*control)->contrlData); - } - return 0; - case testCntl: - if (variant == SYS7_TEXT_VARIANT) - return kControlNoPart; - mouse.h = LoWord(param); - mouse.v = HiWord(param); - rect = (*control)->contrlRect; - InsetRect(&rect, 3, 3); - return PtInRect(mouse, &rect) ? kControlEditTextPart : kControlNoPart; - case calcCRgns: - if (param & (1 << 31)) { - param &= ~(1 << 31); - goto calcthumbrgn; - } - /* FALLTHROUGH */ - case calcCntlRgn: - rgn = (RgnHandle)param; - RectRgn(rgn, &(*control)->contrlRect); - return 0; - case calcThumbRgn: - calcthumbrgn: - rgn = (RgnHandle)param; - SetEmptyRgn(rgn); - return 0; - } - - return 0; -} -#endif - -static void macctrl_radio(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds; - Str255 title; - unsigned int i, colwidth; - - mc->generic.type = MACCTRL_RADIO; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - mc->radio.tbctrls = snewn(ctrl->radio.nbuttons, ControlRef); - colwidth = (curstate->width + 13) / ctrl->radio.ncolumns; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 16; - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - if (ctrl->radio.label == NULL) - mc->radio.tblabel = NULL; - else { - if (mac_gestalts.apprvers >= 0x100) { - mc->radio.tblabel = NewControl(window, &bounds, NULL, FALSE, - 0, 0, 0, kControlStaticTextProc, - (long)mc); - SetControlData(mc->radio.tblabel, kControlEntireControl, - kControlStaticTextTextTag, - strlen(ctrl->radio.label), ctrl->radio.label); - } -#if !TARGET_API_MAC_CARBON - else { - mc->radio.tblabel = NewControl(window, &bounds, NULL, FALSE, - 0, 0, 0, SYS7_TEXT_PROC, (long)mc); - TESetText(ctrl->radio.label, strlen(ctrl->radio.label), - (TEHandle)(*mc->radio.tblabel)->contrlData); - } -#endif - curstate->pos.v += 18; - } - for (i = 0; i < ctrl->radio.nbuttons; i++) { - bounds.top = curstate->pos.v - 2; - bounds.bottom = bounds.top + 18; - bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns); - if (i == ctrl->radio.nbuttons - 1 || - i % ctrl->radio.ncolumns == ctrl->radio.ncolumns - 1) { - bounds.right = curstate->pos.h + curstate->width; - curstate->pos.v += 18; - } else - bounds.right = bounds.left + colwidth - 13; - c2pstrcpy(title, ctrl->radio.buttons[i]); - mc->radio.tbctrls[i] = NewControl(window, &bounds, title, FALSE, - 0, 0, 1, radioButProc, (long)mc); - } - curstate->pos.v += 4; - add234(mcs->byctrl, mc); - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - ctrlevent(mcs, mc, EVENT_REFRESH); -} - -static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds; - Str255 title; - - assert(ctrl->checkbox.label != NULL); - mc->generic.type = MACCTRL_CHECKBOX; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 16; - c2pstrcpy(title, ctrl->checkbox.label); - mc->checkbox.tbctrl = NewControl(window, &bounds, title, FALSE, 0, 0, 1, - checkBoxProc, (long)mc); - add234(mcs->byctrl, mc); - curstate->pos.v += 22; - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - ctrlevent(mcs, mc, EVENT_REFRESH); -} - -static void macctrl_button(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds; - Str255 title; - - assert(ctrl->button.label != NULL); - mc->generic.type = MACCTRL_BUTTON; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 20; - c2pstrcpy(title, ctrl->button.label); - mc->button.tbctrl = NewControl(window, &bounds, title, FALSE, 0, 0, 1, - pushButProc, (long)mc); - mc->button.tbring = NULL; - if (mac_gestalts.apprvers >= 0x100) { - Boolean isdefault = ctrl->button.isdefault; - - SetControlData(mc->button.tbctrl, kControlEntireControl, - kControlPushButtonDefaultTag, - sizeof(isdefault), &isdefault); - } else if (ctrl->button.isdefault) { - InsetRect(&bounds, -4, -4); - mc->button.tbring = NewControl(window, &bounds, title, FALSE, 0, 0, 1, - SYS7_DEFAULT_PROC, (long)mc); - } - if (mac_gestalts.apprvers >= 0x110) { - Boolean iscancel = ctrl->button.iscancel; - - SetControlData(mc->button.tbctrl, kControlEntireControl, - kControlPushButtonCancelTag, - sizeof(iscancel), &iscancel); - } - if (ctrl->button.isdefault) - mcs->defbutton = mc; - if (ctrl->button.iscancel) - mcs->canbutton = mc; - add234(mcs->byctrl, mc); - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - curstate->pos.v += 26; -} - -#if !TARGET_API_MAC_CARBON -static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant, - ControlRef control, - ControlDefProcMessage msg, - SInt32 param) -{ - RgnHandle rgn; - Rect rect; - int oval; - PenState savestate; - - switch (msg) { - case drawCntl: - if ((*control)->contrlVis) { - rect = (*control)->contrlRect; - GetPenState(&savestate); - PenNormal(); - PenSize(3, 3); - if ((*control)->contrlHilite == kControlInactivePart) - PenPat(&qd.gray); - oval = (rect.bottom - rect.top) / 2 + 2; - FrameRoundRect(&rect, oval, oval); - SetPenState(&savestate); - } - return 0; - case calcCRgns: - if (param & (1 << 31)) { - param &= ~(1 << 31); - goto calcthumbrgn; - } - /* FALLTHROUGH */ - case calcCntlRgn: - rgn = (RgnHandle)param; - RectRgn(rgn, &(*control)->contrlRect); - return 0; - case calcThumbRgn: - calcthumbrgn: - rgn = (RgnHandle)param; - SetEmptyRgn(rgn); - return 0; - } - - return 0; -} -#endif - -static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds, upbounds, downbounds; - Size olen; - - /* XXX Use label */ - assert(ctrl->listbox.percentwidth == 100); - mc->generic.type = MACCTRL_LISTBOX; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - /* The list starts off empty */ - mc->listbox.nids = 0; - mc->listbox.ids = NULL; - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 16 * ctrl->listbox.height + 2; - - if (ctrl->listbox.draglist) { - upbounds = downbounds = bounds; - upbounds.left = upbounds.right - 58; - upbounds.bottom = upbounds.top + 20; - downbounds.left = downbounds.right - 58; - downbounds.top = upbounds.bottom + 6; - downbounds.bottom = downbounds.top + 20; - bounds.right -= 64; /* enough for 6 px gap and a button */ - } - - if (mac_gestalts.apprvers >= 0x100) { - InsetRect(&bounds, 3, 3); - mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, - ldes_Default, 0, 0, - kControlListBoxProc, (long)mc); - if (GetControlData(mc->listbox.tbctrl, kControlEntireControl, - kControlListBoxListHandleTag, - sizeof(mc->listbox.list), &mc->listbox.list, - &olen) != noErr) { - DisposeControl(mc->listbox.tbctrl); - sfree(mc); - return; - } - } -#if !TARGET_API_MAC_CARBON - else { - InsetRect(&bounds, -3, -3); - mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, - 0, 0, 0, - SYS7_LISTBOX_PROC, (long)mc); - mc->listbox.list = (ListHandle)(*mc->listbox.tbctrl)->contrlData; - (*mc->listbox.list)->refCon = (long)mc; - } -#endif - if (!ctrl->listbox.multisel) { -#if TARGET_API_MAC_CARBON - SetListSelectionFlags(mc->listbox.list, lOnlyOne); -#else - (*mc->listbox.list)->selFlags = lOnlyOne; -#endif - } - - if (ctrl->listbox.draglist) { - mc->listbox.tbup = NewControl(window, &upbounds, "\pUp", FALSE, 0, 0, 1, - pushButProc, (long)mc); - mc->listbox.tbdown = NewControl(window, &downbounds, "\pDown", FALSE, 0, 0, 1, - pushButProc, (long)mc); - } - - add234(mcs->byctrl, mc); - curstate->pos.v += 6 + 16 * ctrl->listbox.height + 2; - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - ctrlevent(mcs, mc, EVENT_REFRESH); -#if TARGET_API_MAC_CARBON - HideControl(GetListVerticalScrollBar(mc->listbox.list)); -#else - HideControl((*mc->listbox.list)->vScroll); -#endif -} - -#if !TARGET_API_MAC_CARBON -static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16 variant, - ControlRef control, - ControlDefProcMessage msg, - SInt32 param) -{ - RgnHandle rgn; - Rect rect; - ListHandle list; - long ssfs; - Point mouse; - ListBounds bounds; - Point csize; - short savefont; - short savesize; - GrafPtr curport; - - switch (msg) { - case initCntl: - rect = (*control)->contrlRect; - InsetRect(&rect, 4, 4); - rect.right -= 15; /* scroll bar */ - bounds.top = bounds.bottom = bounds.left = 0; - bounds.right = 1; - csize.h = csize.v = 0; - GetPort(&curport); - savefont = curport->txFont; - savesize = curport->txSize; - ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize); - TextFont(HiWord(ssfs)); - TextSize(LoWord(ssfs)); - list = LNew(&rect, &bounds, csize, 0, (*control)->contrlOwner, - TRUE, FALSE, FALSE, TRUE); - SetControlReference((*list)->vScroll, (long)list); - (*control)->contrlData = (Handle)list; - TextFont(savefont); - TextSize(savesize); - return noErr; - case dispCntl: - /* - * If the dialogue box is being destroyed, the scroll bar - * might have gone already. In our situation, this is the - * only time we destroy a control, so NULL out the scroll bar - * handle to prevent LDispose trying to free it. - */ - list = (ListHandle)(*control)->contrlData; - (*list)->vScroll = NULL; - LDispose(list); - return 0; - case drawCntl: - if ((*control)->contrlVis) { - rect = (*control)->contrlRect; - /* XXX input focus highlighting? */ - InsetRect(&rect, 3, 3); - PenNormal(); - FrameRect(&rect); - list = (ListHandle)(*control)->contrlData; - LActivate((*control)->contrlHilite != kControlInactivePart, list); - GetPort(&curport); - LUpdate(curport->visRgn, list); - } - return 0; - case testCntl: - mouse.h = LoWord(param); - mouse.v = HiWord(param); - rect = (*control)->contrlRect; - InsetRect(&rect, 4, 4); - /* - * We deliberately exclude the scrollbar so that LClick() can see it. - */ - rect.right -= 15; - return PtInRect(mouse, &rect) ? kControlListBoxPart : kControlNoPart; - case calcCRgns: - if (param & (1 << 31)) { - param &= ~(1 << 31); - goto calcthumbrgn; - } - /* FALLTHROUGH */ - case calcCntlRgn: - rgn = (RgnHandle)param; - RectRgn(rgn, &(*control)->contrlRect); - return 0; - case calcThumbRgn: - calcthumbrgn: - rgn = (RgnHandle)param; - SetEmptyRgn(rgn); - return 0; - } - - return 0; -} -#endif - -#if !TARGET_API_MAC_CARBON -static pascal SInt32 macctrl_sys7_groupbox_cdef(SInt16 variant, - ControlRef control, - ControlDefProcMessage msg, - SInt32 param) -{ - RgnHandle rgn; - Rect rect; - PenState savestate; - - switch (msg) { - case drawCntl: - if ((*control)->contrlVis) { - rect = (*control)->contrlRect; - GetPenState(&savestate); - PenNormal(); - PenSize(3, 3); - PenPat(&qd.gray); - FrameRect(&rect); - SetPenState(&savestate); - } - return 0; - case calcCRgns: - if (param & (1 << 31)) { - param &= ~(1 << 31); - goto calcthumbrgn; - } - /* FALLTHROUGH */ - case calcCntlRgn: - rgn = (RgnHandle)param; - RectRgn(rgn, &(*control)->contrlRect); - return 0; - case calcThumbRgn: - calcthumbrgn: - rgn = (RgnHandle)param; - SetEmptyRgn(rgn); - return 0; - } - return 0; -} -#endif - -static void macctrl_popup(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew(union macctrl); - Rect bounds; - Str255 title; - unsigned int labelwidth; - static int nextmenuid = MENU_MIN; - int menuid; - MenuRef menu; - - /* - * explains how to - * create a popup menu with dynamic content. - */ - assert(ctrl->listbox.height == 0); - assert(!ctrl->listbox.draglist); - assert(!ctrl->listbox.multisel); - - mc->generic.type = MACCTRL_POPUP; - mc->generic.ctrl = ctrl; - mc->generic.privdata = NULL; - c2pstrcpy(title, ctrl->button.label == NULL ? "" : ctrl->button.label); - - /* Find a spare menu ID and create the menu */ - while (GetMenuHandle(nextmenuid) != NULL) - if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN; - menuid = nextmenuid++; - menu = NewMenu(menuid, "\pdummy"); - if (menu == NULL) return; - mc->popup.menu = menu; - mc->popup.menuid = menuid; - InsertMenu(menu, kInsertHierarchicalMenu); - - /* The menu starts off empty */ - mc->popup.nids = 0; - mc->popup.ids = NULL; - - bounds.left = curstate->pos.h; - bounds.right = bounds.left + curstate->width; - bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 20; - /* XXX handle percentwidth == 100 */ - labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100; - mc->popup.tbctrl = NewControl(window, &bounds, title, FALSE, - popupTitleLeftJust, menuid, labelwidth, - popupMenuProc + popupFixedWidth, (long)mc); - add234(mcs->byctrl, mc); - curstate->pos.v += 26; - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; - ctrlevent(mcs, mc, EVENT_REFRESH); -} - -static void macctrl_groupbox(struct macctrls *mcs, WindowPtr window, - struct mac_layoutstate *curstate, - union control *ctrl) -{ - union macctrl *mc = snew (union macctrl); - Str255 ptitle; - Rect r; - - r.top = curstate->boxpos.v; - r.left = curstate->boxpos.h; - r.bottom = curstate->pos.v; - r.right = curstate->boxpos.h + curstate->width; - - mc->generic.type = MACCTRL_GROUPBOX; - mc->generic.privdata = NULL; - mc->generic.ctrl = ctrl; - mc->generic.ctrl->generic.handler = NULL; - - if (curstate->boxname) - c2pstrcpy(ptitle, curstate->boxname); - else - c2pstrcpy(ptitle, ""); - if (mac_gestalts.apprvers >= 0x100) { /* Appearance Manager */ - mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1, - kControlGroupBoxTextTitleProc, (long)mc); - } else { - mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1, - SYS7_GROUPBOX_PROC, (long)mc); - } - add234(mcs->byctrl, mc); - mc->generic.next = mcs->panels[curstate->panelnum]; - mcs->panels[curstate->panelnum] = mc; -} - -void macctrl_activate(WindowPtr window, EventRecord *event) -{ - struct macctrls *mcs = mac_winctrls(window); - Boolean active = (event->modifiers & activeFlag) != 0; - GrafPtr saveport; - int i, j; - ControlPartCode state; - union macctrl *mc; - - GetPort(&saveport); - SetPort((GrafPtr)GetWindowPort(window)); - if (mac_gestalts.apprvers >= 0x100) - SetThemeWindowBackground(window, active ? - kThemeBrushModelessDialogBackgroundActive : - kThemeBrushModelessDialogBackgroundInactive, - TRUE); - state = active ? kControlNoPart : kControlInactivePart; - for (i = 0; i <= mcs->curpanel; i += mcs->curpanel) - for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) { - switch (mc->generic.type) { - case MACCTRL_TEXT: - HiliteControl(mc->text.tbctrl, state); - break; - case MACCTRL_EDITBOX: - HiliteControl(mc->editbox.tbctrl, state); - if (mc->editbox.tblabel != NULL) - HiliteControl(mc->editbox.tblabel, state); - if (mc->editbox.tbbutton != NULL) - HiliteControl(mc->editbox.tbbutton, state); - break; - case MACCTRL_RADIO: - for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) - HiliteControl(mc->radio.tbctrls[j], state); - if (mc->radio.tblabel != NULL) - HiliteControl(mc->radio.tblabel, state); - break; - case MACCTRL_CHECKBOX: - HiliteControl(mc->checkbox.tbctrl, state); - break; - case MACCTRL_BUTTON: - HiliteControl(mc->button.tbctrl, state); - if (mc->button.tbring != NULL) - HiliteControl(mc->button.tbring, state); - break; - case MACCTRL_LISTBOX: - HiliteControl(mc->listbox.tbctrl, state); - if (mc->listbox.tbup != NULL) - HiliteControl(mc->listbox.tbup, state); - if (mc->listbox.tbdown != NULL) - HiliteControl(mc->listbox.tbdown, state); - break; - case MACCTRL_POPUP: - HiliteControl(mc->popup.tbctrl, state); - break; - case MACCTRL_GROUPBOX: - HiliteControl(mc->popup.tbctrl, state); - } -#if !TARGET_API_MAC_CARBON - if (mcs->focus == mc) { - if (active) - macctrl_enfocus(mc); - else - macctrl_defocus(mc); - } -#endif - } - SetPort(saveport); -} - -void macctrl_click(WindowPtr window, EventRecord *event) -{ - Point mouse; - ControlHandle control, oldfocus; - int part, trackresult; - GrafPtr saveport; - union macctrl *mc; - struct macctrls *mcs = mac_winctrls(window); - int i; - UInt32 features; - - GetPort(&saveport); - SetPort((GrafPtr)GetWindowPort(window)); - mouse = event->where; - GlobalToLocal(&mouse); - part = FindControl(mouse, window, &control); - if (control != NULL) { -#if !TARGET_API_MAC_CARBON - /* - * Special magic for scroll bars in list boxes, whose refcon - * is the list. - */ - if (part == kControlUpButtonPart || part == kControlDownButtonPart || - part == kControlPageUpPart || part == kControlPageDownPart || - part == kControlIndicatorPart) - mc = (union macctrl *) - (*(ListHandle)GetControlReference(control))->refCon; - else -#endif - mc = (union macctrl *)GetControlReference(control); - if (mac_gestalts.apprvers >= 0x100) { - if (GetControlFeatures(control, &features) == noErr && - (features & kControlSupportsFocus) && - (features & kControlGetsFocusOnClick) && - GetKeyboardFocus(window, &oldfocus) == noErr && - control != oldfocus) - SetKeyboardFocus(window, control, part); - trackresult = HandleControlClick(control, mouse, event->modifiers, - (ControlActionUPP)-1); - } else { -#if !TARGET_API_MAC_CARBON - if (mc->generic.type == MACCTRL_EDITBOX && - control == mc->editbox.tbctrl) { - TEHandle te = (TEHandle)(*control)->contrlData; - - macctrl_setfocus(mcs, mc); - TEClick(mouse, !!(event->modifiers & shiftKey), te); - goto done; - } - if (mc->generic.type == MACCTRL_EDITBOX && - control == mc->editbox.tbbutton) { - dlg_editbox_set(mc->generic.ctrl, mcs, - cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs))); - ctrlevent(mcs, mc, EVENT_VALCHANGE); - } - if (mc->generic.type == MACCTRL_LISTBOX && - (control == mc->listbox.tbctrl || - control == (*mc->listbox.list)->vScroll)) { - - macctrl_setfocus(mcs, mc); - if (LClick(mouse, event->modifiers, mc->listbox.list)) - /* double-click */ - ctrlevent(mcs, mc, EVENT_ACTION); - else - ctrlevent(mcs, mc, EVENT_SELCHANGE); - goto done; - } - if (mc->generic.type == MACCTRL_LISTBOX && - control == mc->listbox.tbup) - draglist_up(mc, mcs); - if (mc->generic.type == MACCTRL_LISTBOX && - control == mc->listbox.tbdown) - draglist_down(mc, mcs); -#endif - trackresult = TrackControl(control, mouse, (ControlActionUPP)-1); - } - switch (mc->generic.type) { - case MACCTRL_RADIO: - if (trackresult != 0) { - for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++) - if (mc->radio.tbctrls[i] == control) - SetControlValue(mc->radio.tbctrls[i], - kControlRadioButtonCheckedValue); - else - SetControlValue(mc->radio.tbctrls[i], - kControlRadioButtonUncheckedValue); - ctrlevent(mcs, mc, EVENT_VALCHANGE); - } - break; - case MACCTRL_CHECKBOX: - if (trackresult != 0) { - SetControlValue(control, !GetControlValue(control)); - ctrlevent(mcs, mc, EVENT_VALCHANGE); - } - break; - case MACCTRL_BUTTON: - if (trackresult != 0) - ctrlevent(mcs, mc, EVENT_ACTION); - break; - case MACCTRL_EDITBOX: - if (control == mc->editbox.tbbutton) { - dlg_editbox_set(mc->generic.ctrl, mcs, - cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs))); - ctrlevent(mcs, mc, EVENT_VALCHANGE); - } - break; - case MACCTRL_LISTBOX: - if (control == mc->listbox.tbup) - draglist_up(mc, mcs); - if (control == mc->listbox.tbdown) - draglist_down(mc, mcs); - - /* FIXME spot double-click */ - ctrlevent(mcs, mc, EVENT_SELCHANGE); - break; - case MACCTRL_POPUP: - ctrlevent(mcs, mc, EVENT_SELCHANGE); - break; - } - } - done: - SetPort(saveport); -} - -void macctrl_key(WindowPtr window, EventRecord *event) -{ - ControlRef control; - struct macctrls *mcs = mac_winctrls(window); - union macctrl *mc; - unsigned long dummy; - - switch (event->message & charCodeMask) { - case kEnterCharCode: - case kReturnCharCode: - if (mcs->defbutton != NULL) { - assert(mcs->defbutton->generic.type == MACCTRL_BUTTON); - HiliteControl(mcs->defbutton->button.tbctrl, kControlButtonPart); - /* - * I'd like to delay unhilighting the button until after - * the event has been processed, but by them the entire - * dialgue box might have been destroyed. - */ - Delay(6, &dummy); - HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart); - ctrlevent(mcs, mcs->defbutton, EVENT_ACTION); - } - return; - case kEscapeCharCode: - if (mcs->canbutton != NULL) { - assert(mcs->canbutton->generic.type == MACCTRL_BUTTON); - HiliteControl(mcs->canbutton->button.tbctrl, kControlButtonPart); - Delay(6, &dummy); - HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart); - ctrlevent(mcs, mcs->canbutton, EVENT_ACTION); - } - return; - } - if (mac_gestalts.apprvers >= 0x100) { - if (GetKeyboardFocus(window, &control) == noErr && control != NULL) { - HandleControlKey(control, (event->message & keyCodeMask) >> 8, - event->message & charCodeMask, event->modifiers); - mc = (union macctrl *)GetControlReference(control); - switch (mc->generic.type) { - case MACCTRL_LISTBOX: - ctrlevent(mcs, mc, EVENT_SELCHANGE); - break; - default: - ctrlevent(mcs, mc, EVENT_VALCHANGE); - break; - } - } - } -#if !TARGET_API_MAC_CARBON - else { - TEHandle te; - - if (mcs->focus != NULL) { - mc = mcs->focus; - switch (mc->generic.type) { - case MACCTRL_EDITBOX: - te = (TEHandle)(*mc->editbox.tbctrl)->contrlData; - TEKey(event->message & charCodeMask, te); - ctrlevent(mcs, mc, EVENT_VALCHANGE); - break; - } - } - } -#endif -} - -void macctrl_update(WindowPtr window) -{ -#if TARGET_API_MAC_CARBON - RgnHandle visrgn; -#endif - Rect rect; - GrafPtr saveport; - - BeginUpdate(window); - GetPort(&saveport); - SetPort((GrafPtr)GetWindowPort(window)); - if (mac_gestalts.apprvers >= 0x101) { -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(window), &rect); -#else - rect = window->portRect; -#endif - InsetRect(&rect, -1, -1); - DrawThemeModelessDialogFrame(&rect, mac_frontwindow() == window ? - kThemeStateActive : kThemeStateInactive); - } -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), visrgn); - UpdateControls(window, visrgn); - DisposeRgn(visrgn); -#else - UpdateControls(window, window->visRgn); -#endif - SetPort(saveport); - EndUpdate(window); -} - -#if TARGET_API_MAC_CARBON -#define EnableItem EnableMenuItem -#define DisableItem DisableMenuItem -#endif -void macctrl_adjustmenus(WindowPtr window) -{ - MenuHandle menu; - - menu = GetMenuHandle(mFile); - DisableItem(menu, iSave); /* XXX enable if modified */ - EnableItem(menu, iSaveAs); - EnableItem(menu, iDuplicate); - - menu = GetMenuHandle(mEdit); - DisableItem(menu, 0); -} - -void macctrl_close(WindowPtr window) -{ - struct macctrls *mcs = mac_winctrls(window); - union macctrl *mc; - - /* - * Mostly, we don't bother disposing of the Toolbox controls, - * since that will happen automatically when the window is - * disposed of. Popup menus are an exception, because we have to - * dispose of the menu ourselves, and doing that while the control - * still holds a reference to it seems rude. - */ - while ((mc = index234(mcs->byctrl, 0)) != NULL) { - if (mc->generic.privdata != NULL && mc->generic.freeprivdata) - sfree(mc->generic.privdata); - switch (mc->generic.type) { - case MACCTRL_POPUP: - DisposeControl(mc->popup.tbctrl); - DeleteMenu(mc->popup.menuid); - DisposeMenu(mc->popup.menu); - break; - } - del234(mcs->byctrl, mc); - sfree(mc); - } - - freetree234(mcs->byctrl); - mcs->byctrl = NULL; - sfree(mcs->panels); - mcs->panels = NULL; -} - -void dlg_update_start(union control *ctrl, void *dlg) -{ - - /* No-op for now */ -} - -void dlg_update_done(union control *ctrl, void *dlg) -{ - - /* No-op for now */ -} - -void dlg_set_focus(union control *ctrl, void *dlg) -{ - - if (mac_gestalts.apprvers >= 0x100) { - /* Use SetKeyboardFocus() */ - } else { - /* Do our own mucking around */ - } -} - -union control *dlg_last_focused(union control *ctrl, void *dlg) -{ - - return NULL; -} - -void dlg_beep(void *dlg) -{ - - SysBeep(30); -} - -void dlg_error_msg(void *dlg, char *msg) -{ - Str255 pmsg; - - c2pstrcpy(pmsg, msg); - ParamText(pmsg, NULL, NULL, NULL); - StopAlert(128, NULL); -} - -void dlg_end(void *dlg, int value) -{ - struct macctrls *mcs = dlg; - - if (mcs->end != NULL) - (*mcs->end)(mcs->window, value); -}; - -void dlg_refresh(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc; - int i; - - if (ctrl == NULL) { - /* NULL means refresh every control */ - for (i = 0 ; i < mcs->npanels; i++) { - for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) { - ctrlevent(mcs, mc, EVENT_REFRESH); - } - } - return; - } - /* Just refresh a specific control */ - mc = findbyctrl(mcs, ctrl); - assert(mc != NULL); - ctrlevent(mcs, mc, EVENT_REFRESH); -}; - -void *dlg_get_privdata(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - assert(mc != NULL); - return mc->generic.privdata; -} - -void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - assert(mc != NULL); - mc->generic.privdata = ptr; - mc->generic.freeprivdata = FALSE; -} - -void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - assert(mc != NULL); - mc->generic.privdata = smalloc(size); - mc->generic.freeprivdata = TRUE; - return mc->generic.privdata; -} - - -/* - * Radio Button control - */ - -void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - int i; - - if (mc == NULL) return; - for (i = 0; i < ctrl->radio.nbuttons; i++) { - if (i == whichbutton) - SetControlValue(mc->radio.tbctrls[i], - kControlRadioButtonCheckedValue); - else - SetControlValue(mc->radio.tbctrls[i], - kControlRadioButtonUncheckedValue); - } - -}; - -int dlg_radiobutton_get(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - int i; - - assert(mc != NULL); - for (i = 0; i < ctrl->radio.nbuttons; i++) { - if (GetControlValue(mc->radio.tbctrls[i]) == - kControlRadioButtonCheckedValue) - return i; - } - return -1; -}; - - -/* - * Check Box control - */ - -void dlg_checkbox_set(union control *ctrl, void *dlg, int checked) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - if (mc == NULL) return; - SetControlValue(mc->checkbox.tbctrl, - checked ? kControlCheckBoxCheckedValue : - kControlCheckBoxUncheckedValue); -} - -int dlg_checkbox_get(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - assert(mc != NULL); - return GetControlValue(mc->checkbox.tbctrl); -} - - -/* - * Edit Box control - */ - -void dlg_editbox_set(union control *ctrl, void *dlg, char const *text) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - GrafPtr saveport; - - if (mc == NULL) return; - assert(mc->generic.type == MACCTRL_EDITBOX); - GetPort(&saveport); - SetPort((GrafPtr)(GetWindowPort(mcs->window))); - if (mac_gestalts.apprvers >= 0x100) - SetControlData(mc->editbox.tbctrl, kControlEntireControl, - ctrl->editbox.password ? - kControlEditTextPasswordTag : - kControlEditTextTextTag, - strlen(text), text); -#if !TARGET_API_MAC_CARBON - else - TESetText(text, strlen(text), - (TEHandle)(*mc->editbox.tbctrl)->contrlData); -#endif - DrawOneControl(mc->editbox.tbctrl); - SetPort(saveport); -} - -void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - Size olen; - - assert(mc != NULL); - assert(mc->generic.type == MACCTRL_EDITBOX); - if (mac_gestalts.apprvers >= 0x100) { - if (GetControlData(mc->editbox.tbctrl, kControlEntireControl, - ctrl->editbox.password ? - kControlEditTextPasswordTag : - kControlEditTextTextTag, - length - 1, buffer, &olen) != noErr) - olen = 0; - if (olen > length - 1) - olen = length - 1; - } -#if !TARGET_API_MAC_CARBON - else { - TEHandle te = (TEHandle)(*mc->editbox.tbctrl)->contrlData; - - olen = (*te)->teLength; - if (olen > length - 1) - olen = length - 1; - memcpy(buffer, *(*te)->hText, olen); - } -#endif - buffer[olen] = '\0'; -} - - -/* - * List Box control - */ - -static void dlg_macpopup_clear(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->popup.menu; - unsigned int i, n; - - if (mc == NULL) return; - n = CountMenuItems(menu); - for (i = 0; i < n; i++) - DeleteMenuItem(menu, n - i); - mc->popup.nids = 0; - sfree(mc->popup.ids); - mc->popup.ids = NULL; - SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); -} - -static void dlg_macedit_clear(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->editbox.menu; - unsigned int i, n; - - if (mc == NULL) return; - n = CountMenuItems(menu); - for (i = 0; i < n; i++) - DeleteMenuItem(menu, n - i); - mc->editbox.nids = 0; - sfree(mc->editbox.ids); - mc->editbox.ids = NULL; - SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu)); -} - -static void dlg_maclist_clear(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - if (mc == NULL) return; - LDelRow(0, 0, mc->listbox.list); - mc->listbox.nids = 0; - sfree(mc->listbox.ids); - mc->listbox.ids = NULL; - DrawOneControl(mc->listbox.tbctrl); -} - -void dlg_listbox_clear(union control *ctrl, void *dlg) -{ - - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - dlg_macpopup_clear(ctrl, dlg); - else - dlg_maclist_clear(ctrl, dlg); - break; - case CTRL_EDITBOX: - dlg_macedit_clear(ctrl, dlg); - } -} - -static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->popup.menu; - - if (mc == NULL) return; - DeleteMenuItem(menu, index + 1); - if (mc->popup.ids != NULL) - memcpy(mc->popup.ids + index, mc->popup.ids + index + 1, - (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids)); - SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); -} - -static void dlg_macedit_del(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->editbox.menu; - - if (mc == NULL) return; - DeleteMenuItem(menu, index + 1); - if (mc->editbox.ids != NULL) - memcpy(mc->editbox.ids + index, mc->editbox.ids + index + 1, - (mc->editbox.nids - index - 1) * sizeof(*mc->editbox.ids)); - SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu)); -} - -static void dlg_maclist_del(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - if (mc == NULL) return; - LDelRow(1, index, mc->listbox.list); - if (mc->listbox.ids != NULL) - memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1, - (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids)); - DrawOneControl(mc->listbox.tbctrl); -} - -void dlg_listbox_del(union control *ctrl, void *dlg, int index) -{ - - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - dlg_macpopup_del(ctrl, dlg, index); - else - dlg_maclist_del(ctrl, dlg, index); - break; - case CTRL_EDITBOX: - dlg_macedit_del(ctrl, dlg, index); - } -} - -static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->popup.menu; - Str255 itemstring; - - if (mc == NULL) return; - assert(text[0] != '\0'); - c2pstrcpy(itemstring, text); - AppendMenu(menu, "\pdummy"); - SetMenuItemText(menu, CountMenuItems(menu), itemstring); - SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); -} - -static void dlg_macedit_add(union control *ctrl, void *dlg, char const *text) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->editbox.menu; - Str255 itemstring; - - if (mc == NULL) return; - assert(text[0] != '\0'); - c2pstrcpy(itemstring, text); - AppendMenu(menu, "\pdummy"); - SetMenuItemText(menu, CountMenuItems(menu), itemstring); - SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu)); -} - -static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - ListBounds bounds; - Cell cell = { 0, 0 }; - - if (mc == NULL) return; -#if TARGET_API_MAC_CARBON - GetListDataBounds(mc->listbox.list, &bounds); -#else - bounds = (*mc->listbox.list)->dataBounds; -#endif - cell.v = bounds.bottom; - LAddRow(1, cell.v, mc->listbox.list); - LSetCell(text, strlen(text), cell, mc->listbox.list); - DrawOneControl(mc->listbox.tbctrl); -} - -void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) -{ - - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - dlg_macpopup_add(ctrl, dlg, text); - else - dlg_maclist_add(ctrl, dlg, text); - break; - case CTRL_EDITBOX: - dlg_macedit_add(ctrl, dlg, text); - break; - } -} - -static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, - char const *text, int id) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->popup.menu; - unsigned int index; - - if (mc == NULL) return; - dlg_macpopup_add(ctrl, dlg, text); - index = CountMenuItems(menu) - 1; - if (mc->popup.nids <= index) { - mc->popup.nids = index + 1; - mc->popup.ids = sresize(mc->popup.ids, mc->popup.nids, int); - } - mc->popup.ids[index] = id; -} - -static void dlg_macedit_addwithid(union control *ctrl, void *dlg, - char const *text, int id) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - MenuRef menu = mc->editbox.menu; - unsigned int index; - - if (mc == NULL) return; - dlg_macedit_add(ctrl, dlg, text); - index = CountMenuItems(menu) - 1; - if (mc->editbox.nids <= index) { - mc->editbox.nids = index + 1; - mc->editbox.ids = sresize(mc->editbox.ids, mc->editbox.nids, int); - } - mc->editbox.ids[index] = id; -} - -static void dlg_maclist_addwithid(union control *ctrl, void *dlg, - char const *text, int id) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - ListBounds bounds; - int index; - - if (mc == NULL) return; - dlg_maclist_add(ctrl, dlg, text); -#if TARGET_API_MAC_CARBON - GetListDataBounds(mc->listbox.list, &bounds); -#else - bounds = (*mc->listbox.list)->dataBounds; -#endif - index = bounds.bottom; - if (mc->listbox.nids <= index) { - mc->listbox.nids = index + 1; - mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int); - } - mc->listbox.ids[index] = id; -} - -void dlg_listbox_addwithid(union control *ctrl, void *dlg, - char const *text, int id) -{ - - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - dlg_macpopup_addwithid(ctrl, dlg, text, id); - else - dlg_maclist_addwithid(ctrl, dlg, text, id); - break; - case CTRL_EDITBOX: - dlg_macedit_addwithid(ctrl, dlg, text, id); - break; - } -} - -int dlg_listbox_getid(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - assert(mc != NULL); - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) { - assert(mc->popup.ids != NULL && mc->popup.nids > index); - return mc->popup.ids[index]; - } else { - assert(mc->listbox.ids != NULL && mc->listbox.nids > index); - return mc->listbox.ids[index]; - } - case CTRL_EDITBOX: - assert(mc->editbox.ids != NULL && mc->editbox.nids > index); - return mc->editbox.ids[index]; - } - return -1; -} - -int dlg_listbox_index(union control *ctrl, void *dlg) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - Cell cell = { 0, 0 }; - - assert(mc != NULL); - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - return GetControlValue(mc->popup.tbctrl) - 1; - else { - if (LGetSelect(TRUE, &cell, mc->listbox.list)) - return cell.v; - else - return -1; - } - case CTRL_EDITBOX: - return GetControlValue(mc->editbox.tbbutton) - 1; - } - return -1; -} - -int dlg_listbox_issel(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - Cell cell = { 0, 0 }; - - assert(mc != NULL); - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - return GetControlValue(mc->popup.tbctrl) - 1 == index; - else { - cell.v = index; - return LGetSelect(FALSE, &cell, mc->listbox.list); - } - case CTRL_EDITBOX: - return GetControlValue(mc->editbox.tbbutton) - 1 == index; - } - return FALSE; -} - -void dlg_listbox_select(union control *ctrl, void *dlg, int index) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - if (mc == NULL) return; - switch (ctrl->generic.type) { - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - SetControlValue(mc->popup.tbctrl, index + 1); - break; - case CTRL_EDITBOX: - SetControlValue(mc->editbox.tbbutton, index + 1); - } -} - -static void draglist_move(union macctrl *mc, struct macctrls *mcs, - int direction) -{ - ListBounds bounds; - Cell cell = {0, 0}; - char current[255]; - char new[255]; - short curlength = 255; - short newlength = 255; - int curid, newid; - - int index = dlg_listbox_index(mc->generic.ctrl, mcs); - -#if TARGET_API_MAC_CARBON - GetListDataBounds(mc->listbox.list, &bounds); -#else - bounds = (*mc->listbox.list)->dataBounds; -#endif - - if ((index < 0) || - (index == 0 && direction < 0) || - (index == bounds.bottom-1 && direction > 0)) { - SysBeep(30); - return; - } - - /* Swap the contents of the selected and target list cells */ - - cell.v = index; - LGetCell(current, &curlength, cell, mc->listbox.list); - current[curlength] = '\0'; - cell.v += direction; - LGetCell(new, &newlength, cell, mc->listbox.list); - new[newlength] = '\0'; - - cell.v = index; - LSetCell(new, newlength, cell, mc->listbox.list); - cell.v += direction; - LSetCell(current, curlength, cell, mc->listbox.list); - - /* Move the selection to the target list cell */ - - cell.v = index; - LSetSelect(FALSE, cell, mc->listbox.list); - cell.v += direction; - LSetSelect(TRUE, cell, mc->listbox.list); - DrawOneControl(mc->listbox.tbctrl); - - /* Swap the ids of the list cells */ - - curid = mc->listbox.ids[index]; - newid = mc->listbox.ids[index + direction]; - mc->listbox.ids[index] = newid; - mc->listbox.ids[index + direction] = curid; - - ctrlevent(mcs, mc, EVENT_VALCHANGE); -} - -static void draglist_up(union macctrl *mc, struct macctrls *mcs) -{ - draglist_move(mc, mcs, -1); -} - -static void draglist_down(union macctrl *mc, struct macctrls *mcs) -{ - draglist_move(mc, mcs, +1); -} - -/* - * Text control - */ - -void dlg_text_set(union control *ctrl, void *dlg, char const *text) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - - if (mc == NULL) return; - if (mac_gestalts.apprvers >= 0x100) - SetControlData(mc->text.tbctrl, kControlEntireControl, - kControlStaticTextTextTag, strlen(text), text); -#if !TARGET_API_MAC_CARBON - else - TESetText(text, strlen(text), - (TEHandle)(*mc->text.tbctrl)->contrlData); -#endif -} - - -/* - * File Selector control - */ - -void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn) -{ - -} - -void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn) -{ - -} - - -/* - * Font Selector control - */ - -void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn) -{ - -} - -void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn) -{ - -} - - -/* - * Printer enumeration - */ - -printer_enum *printer_start_enum(int *nprinters) -{ - - *nprinters = 0; - return NULL; -} - -char *printer_get_name(printer_enum *pe, int thing) -{ - - return ""; -} - -void printer_finish_enum(printer_enum *pe) -{ - -} - - -/* - * Colour selection stuff - */ - -void dlg_coloursel_start(union control *ctrl, void *dlg, - int r, int g, int b) -{ - struct macctrls *mcs = dlg; - union macctrl *mc = findbyctrl(mcs, ctrl); - Point where = {-1, -1}; /* Screen with greatest colour depth */ - RGBColor incolour; - - if (HAVE_COLOR_QD()) { - incolour.red = r * 0x0101; - incolour.green = g * 0x0101; - incolour.blue = b * 0x0101; - mcs->gotcolour = GetColor(where, "\pModify Colour:", &incolour, - &mcs->thecolour); - ctrlevent(mcs, mc, EVENT_CALLBACK); - } else - dlg_beep(dlg); -} - -int dlg_coloursel_results(union control *ctrl, void *dlg, - int *r, int *g, int *b) -{ - struct macctrls *mcs = dlg; - - if (mcs->gotcolour) { - *r = mcs->thecolour.red >> 8; - *g = mcs->thecolour.green >> 8; - *b = mcs->thecolour.blue >> 8; - return 1; - } else - return 0; -} - -void dlg_label_change(union control *ctrl, void *dlg, char const *text) -{ - /* - * This function is currently only used by the config box to - * switch the labels on the host and port boxes between serial - * and network modes. Since the Mac port does not have a serial - * back end, this function can safely do nothing. - */ -} - - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macdlg.c b/mac/macdlg.c deleted file mode 100644 index 0b28cf9f..00000000 --- a/mac/macdlg.c +++ /dev/null @@ -1,408 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 2002 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* - * macdlg.c - settings dialogue box for Mac OS. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "dialog.h" -#include "mac.h" -#include "macresid.h" -#include "storage.h" - -static void mac_config(int); -static void mac_closedlg(WindowPtr); -static void mac_enddlg_config(WindowPtr, int); -static void mac_enddlg_reconfig(WindowPtr, int); - -void mac_newsession(void) -{ - mac_config(FALSE); -} - -void mac_reconfig(void) -{ - mac_config(TRUE); -} - -static void mac_config(int midsession) -{ - Session *s; - WinInfo *wi; - Str255 mactitle; - char *str; - - if (midsession) { - s = mac_windowsession(FrontWindow()); - } else { - s = snew(Session); - memset(s, 0, sizeof(*s)); - do_defaults(NULL, &s->cfg); - s->hasfile = FALSE; - s->session_closed = FALSE; - } - - /* Copy the configuration somewhere else in case this is a * - * reconfiguration and the user cancels the operation */ - - s->temp_cfg = s->cfg; - - if (HAVE_COLOR_QD()) - s->settings_window = GetNewCWindow(wSettings, NULL, (WindowPtr)-1); - else - s->settings_window = GetNewWindow(wSettings, NULL, (WindowPtr)-1); - - s->ctrlbox = ctrl_new_box(); - setup_config_box(s->ctrlbox, midsession, 0, 0); - - s->settings_ctrls.data = &s->temp_cfg; - if (midsession) - s->settings_ctrls.end = &mac_enddlg_reconfig; - else - s->settings_ctrls.end = &mac_enddlg_config; - - macctrl_layoutbox(s->ctrlbox, s->settings_window, &s->settings_ctrls); - - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->s = s; - wi->mcs = &s->settings_ctrls; - wi->wtype = wSettings; - wi->update = &macctrl_update; - wi->click = &macctrl_click; - wi->key = &macctrl_key; - wi->activate = &macctrl_activate; - wi->adjustmenus = &macctrl_adjustmenus; - wi->close = &mac_closedlg; - SetWRefCon(s->settings_window, (long)wi); - if (midsession) - str = dupprintf("%s Reconfiguration", appname); - else - str = dupprintf("%s Configuration", appname); - c2pstrcpy(mactitle, str); - sfree(str); - SetWTitle(s->settings_window, mactitle); - ShowWindow(s->settings_window); -} - -static void mac_closedlg(WindowPtr window) -{ - Session *s = mac_windowsession(window); - - macctrl_close(window); - DisposeWindow(window); - if (s->window == NULL) - sfree(s); -} - -static void mac_enddlg_config(WindowPtr window, int value) -{ - Session *s = mac_windowsession(window); - - if (value == 0) - mac_closedlg(window); - else { - s->cfg = s->temp_cfg; - mac_startsession(s); - mac_closedlg(window); - } -} - -static void mac_enddlg_reconfig(WindowPtr window, int value) -{ - Session *s = mac_windowsession(window); - - if (value == 0) - mac_closedlg(window); - else { - Config prev_cfg = s->cfg; - s->cfg = s->temp_cfg; - mac_closedlg(window); - - /* Pass new config data to the logging module */ - log_reconfig(s->logctx, &s->cfg); - - /* - * Flush the line discipline's edit buffer in the - * case where local editing has just been disabled. - */ - if (s->ldisc) - ldisc_send(s->ldisc, NULL, 0, 0); - - /* Change the palette */ - palette_reset(s); - - /* Reinitialise line codepage */ - init_ucs(s); - - /* Pass new config data to the terminal */ - term_reconfig(s->term, &s->cfg); - - /* Pass new config data to the back end */ - if (s->back) - s->back->reconfig(s->backhandle, &s->cfg); - - /* Screen size changed ? */ - if (s->cfg.height != prev_cfg.height || - s->cfg.width != prev_cfg.width || - s->cfg.savelines != prev_cfg.savelines) { - request_resize(s, s->cfg.width, s->cfg.height); - } - - /* Set the window title */ - if (s->cfg.wintitle[0]) - set_title(s, s->cfg.wintitle); - - /* Scroll bar */ - if (s->cfg.scrollbar != prev_cfg.scrollbar) - request_resize(s, s->cfg.width, s->cfg.height); - - /* TODO: zoom, font */ - } -} - -void mac_dupsession(void) -{ - Session *s1 = mac_windowsession(FrontWindow()); - Session *s2; - - s2 = snew(Session); - memset(s2, 0, sizeof(*s2)); - s2->cfg = s1->cfg; - s2->hasfile = s1->hasfile; - s2->savefile = s1->savefile; - - mac_startsession(s2); -} - -static OSErr mac_opensessionfrom(FSSpec *fss) -{ - FInfo fi; - Session *s; - void *sesshandle; - OSErr err; - - s = snew(Session); - memset(s, 0, sizeof(*s)); - - err = FSpGetFInfo(fss, &fi); - if (err != noErr) return err; - if (fi.fdFlags & kIsStationery) - s->hasfile = FALSE; - else { - s->hasfile = TRUE; - s->savefile = *fss; - } - - sesshandle = open_settings_r_fsp(fss); - if (sesshandle == NULL) { - /* XXX need a way to pass up an error number */ - err = -9999; - goto fail; - } - load_open_settings(sesshandle, &s->cfg); - close_settings_r(sesshandle); - - mac_startsession(s); - return noErr; - - fail: - sfree(s); - return err; -} - -static OSErr mac_openlist(AEDesc docs) -{ - OSErr err; - long ndocs, i; - FSSpec fss; - AEKeyword keywd; - DescType type; - Size size; - - err = AECountItems(&docs, &ndocs); - if (err != noErr) return err; - - for (i = 0; i < ndocs; i++) { - err = AEGetNthPtr(&docs, i + 1, typeFSS, - &keywd, &type, &fss, sizeof(fss), &size); - if (err != noErr) return err;; - err = mac_opensessionfrom(&fss); - if (err != noErr) return err; - } - return noErr; -} - -void mac_opensession(void) -{ - - if (mac_gestalts.navsvers > 0) { - NavReplyRecord navr; - NavDialogOptions navopts; - NavTypeListHandle navtypes; - AEDesc defaultloc = { 'null', NULL }; - AEDesc *navdefault = NULL; - short vol; - long dirid; - FSSpec fss; - - if (NavGetDefaultDialogOptions(&navopts) != noErr) return; - /* XXX should we create sessions dir? */ - if (get_session_dir(FALSE, &vol, &dirid) == noErr && - FSMakeFSSpec(vol, dirid, NULL, &fss) == noErr && - AECreateDesc(typeFSS, &fss, sizeof(fss), &defaultloc) == noErr) - navdefault = &defaultloc; - /* Can't meaningfully preview a saved session yet */ - navopts.dialogOptionFlags &= ~kNavAllowPreviews; - navtypes = (NavTypeListHandle)GetResource('open', open_pTTY); - if (NavGetFile(navdefault, &navr, &navopts, NULL, NULL, NULL, navtypes, - NULL) == noErr && navr.validRecord) - mac_openlist(navr.selection); - NavDisposeReply(&navr); - if (navtypes != NULL) - ReleaseResource((Handle)navtypes); - } -#if !TARGET_API_MAC_CARBON /* XXX Navigation Services */ - else { - StandardFileReply sfr; - static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; - - StandardGetFile(NULL, 1, sftypes, &sfr); - if (!sfr.sfGood) return; - - mac_opensessionfrom(&sfr.sfFile); - /* XXX handle error */ - } -#endif -} - -void mac_savesession(void) -{ - Session *s = mac_windowsession(FrontWindow()); - void *sesshandle; - - assert(s->hasfile); - sesshandle = open_settings_w_fsp(&s->savefile); - if (sesshandle == NULL) return; /* XXX report error */ - save_open_settings(sesshandle, &s->cfg); - close_settings_w(sesshandle); -} - -void mac_savesessionas(void) -{ -#if !TARGET_API_MAC_CARBON /* XXX Navigation Services */ - Session *s = mac_windowsession(FrontWindow()); - StandardFileReply sfr; - void *sesshandle; - - StandardPutFile("\pSave session as:", - s->hasfile ? s->savefile.name : "\puntitled", &sfr); - if (!sfr.sfGood) return; - - if (!sfr.sfReplacing) { - FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript); - if (ResError() != noErr) return; /* XXX report error */ - } - sesshandle = open_settings_w_fsp(&sfr.sfFile); - if (sesshandle == NULL) return; /* XXX report error */ - save_open_settings(sesshandle, &s->cfg); - close_settings_w(sesshandle); - s->hasfile = TRUE; - s->savefile = sfr.sfFile; -#endif -} - -pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply, - long refcon) -{ - DescType type; - Size size; - - if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, - &type, NULL, 0, &size) == noErr) - return errAEParamMissed; - - /* XXX we should do something here. */ - return noErr; -} - -pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply, - long refcon) -{ - DescType type; - Size size; - AEDescList docs = { typeNull, NULL }; - OSErr err; - - err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs); - if (err != noErr) goto out; - - if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, - &type, NULL, 0, &size) == noErr) { - err = errAEParamMissed; - goto out; - } - - err = mac_openlist(docs); - - out: - AEDisposeDesc(&docs); - return err; -} - -pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, - long refcon) -{ - DescType type; - Size size; - - if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, - &type, NULL, 0, &size) == noErr) - return errAEParamMissed; - - /* We can't meaningfully do anything here. */ - return errAEEventNotHandled; -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macevlog.c b/mac/macevlog.c deleted file mode 100644 index 9c99f69f..00000000 --- a/mac/macevlog.c +++ /dev/null @@ -1,277 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "mac.h" -#include "macresid.h" -#include "terminal.h" - -static void mac_draweventloggrowicon(Session *s); -static void mac_adjusteventlogscrollbar(Session *s); -static void mac_clickeventlog(WindowPtr, EventRecord *); -static void mac_activateeventlog(WindowPtr, EventRecord *); -static void mac_groweventlog(WindowPtr, EventRecord *); -static void mac_updateeventlog(WindowPtr); -static void mac_closeeventlog(WindowPtr); - -static void mac_createeventlog(Session *s) -{ - Rect view; - ListBounds bounds = { 0, 0, 0, 1 }; /* 1 column, 0 rows */ - Point csize = { 0, 0 }; - GrafPtr saveport; - long fondsize; - WinInfo *wi; - - s->eventlog_window = GetNewWindow(wEventLog, NULL, (WindowPtr)-1); - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->s = s; - wi->wtype = wEventLog; - wi->click = &mac_clickeventlog; - wi->activate = &mac_activateeventlog; - wi->grow = &mac_groweventlog; - wi->update = &mac_updateeventlog; - wi->close = &mac_closeeventlog; - SetWRefCon(s->eventlog_window, (long)wi); - GetPort(&saveport); - SetPort((GrafPtr)GetWindowPort(s->eventlog_window)); - fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); - TextFont(HiWord(fondsize)); - TextSize(LoWord(fondsize)); - SetPort(saveport); -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(s->eventlog_window), &view); -#else - view = s->eventlog_window->portRect; -#endif - view.right -= 15; /* Scrollbar */ - s->eventlog = LNew(&view, &bounds, csize, 0, s->eventlog_window, - TRUE, TRUE, FALSE, TRUE); - mac_adjusteventlogscrollbar(s); -#if TARGET_API_MAC_CARBON - SetListSelectionFlags(s->eventlog, lExtendDrag | lNoDisjoint | lNoExtend); -#else - (*s->eventlog)->selFlags = lExtendDrag | lNoDisjoint | lNoExtend; -#endif -} - -void mac_freeeventlog(Session *s) -{ - - if (s->eventlog != NULL) - LDispose(s->eventlog); - if (s->eventlog_window != NULL) { - sfree((WinInfo *)GetWRefCon(s->eventlog_window)); - DisposeWindow(s->eventlog_window); - } -} - -void logevent(void *frontend, const char *str) -{ - Session *s = frontend; - ListBounds bounds, visible; - Cell cell = { 0, 0 }; - char timebuf[40]; - struct tm tm; - char *string; - - tm=ltime(); - strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm); - - string=snewn(strlen(timebuf) + strlen(str) +1, char); - strcpy(string, timebuf); - strcat(string, str); - - if (s->eventlog == NULL) - mac_createeventlog(s); - if (s->eventlog == NULL) - return; - -#if TARGET_API_MAC_CARBON - GetListDataBounds(s->eventlog, &bounds); - GetListVisibleCells(s->eventlog, &visible); -#else - bounds = (*s->eventlog)->dataBounds; - visible = (*s->eventlog)->visible; -#endif - - cell.v = bounds.bottom; - LAddRow(1, cell.v, s->eventlog); - LSetCell(string, strlen(string), cell, s->eventlog); - /* ">=" and "2" because there can be a blank cell below the last one. */ - if (visible.bottom >= bounds.bottom) - LScroll(0, 2, s->eventlog); - sfree(string); -} - -static void mac_draweventloggrowicon(Session *s) -{ - Rect clip; - RgnHandle savergn; - - SetPort((GrafPtr)GetWindowPort(s->eventlog_window)); - /* - * Stop DrawGrowIcon giving us space for a horizontal scrollbar - * See Tech Note TB575 for details. - */ -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(s->eventlog_window), &clip); -#else - clip = s->eventlog_window->portRect; -#endif - clip.left = clip.right - 15; - savergn = NewRgn(); - GetClip(savergn); - ClipRect(&clip); - DrawGrowIcon(s->eventlog_window); - SetClip(savergn); - DisposeRgn(savergn); -} - -/* - * For some reason, LNew doesn't seem to respect the hasGrow - * parameter, so we hammer the scrollbar into shape ourselves. - */ -static void mac_adjusteventlogscrollbar(Session *s) -{ -#if TARGET_API_MAC_CARBON - Rect winrect; - - GetPortBounds(GetWindowPort(s->eventlog_window), &winrect); - SizeControl(GetListVerticalScrollBar(s->eventlog), - 16, winrect.bottom - 13); -#else - SizeControl((*s->eventlog)->vScroll, - 16, s->eventlog_window->portRect.bottom - 13); -#endif -} - -void mac_clickeventlog(WindowPtr window, EventRecord *event) -{ - Session *s = mac_windowsession(window); - Point mouse; - GrafPtr saveport; - - GetPort(&saveport); - SetPort((GrafPtr)GetWindowPort(window)); - mouse = event->where; - GlobalToLocal(&mouse); - LClick(mouse, event->modifiers, s->eventlog); - SetPort(saveport); -} - -static void mac_groweventlog(WindowPtr window, EventRecord *event) -{ - Session *s = mac_windowsession(window); - Rect limits; - long grow_result; -#if TARGET_API_MAC_CARBON - Rect rect; - Point cellsize; -#else - GrafPtr saveport; -#endif - - SetRect(&limits, 15, 0, SHRT_MAX, SHRT_MAX); - grow_result = GrowWindow(window, event->where, &limits); - if (grow_result == 0) return; - SizeWindow(window, LoWord(grow_result), HiWord(grow_result), TRUE); - LSize(LoWord(grow_result) - 15, HiWord(grow_result), s->eventlog); - mac_adjusteventlogscrollbar(s); - /* We would use SetListCellSize in Carbon, but it's missing. */ - (*s->eventlog)->cellSize.h = LoWord(grow_result) - 15; -#if TARGET_API_MAC_CARBON - cellsize.h = LoWord(grow_result) - 15; - GetListViewBounds(s->eventlog, &rect); - InvalWindowRect(window, &rect); -#else - GetPort(&saveport); - SetPort(window); - InvalRect(&(*s->eventlog)->rView); - SetPort(saveport); -#endif -} - -static void mac_activateeventlog(WindowPtr window, EventRecord *event) -{ - Session *s = mac_windowsession(window); - int active = (event->modifiers & activeFlag) != 0; - - LActivate(active, s->eventlog); - mac_draweventloggrowicon(s); -} - -static void mac_updateeventlog(WindowPtr window) -{ - Session *s = mac_windowsession(window); -#if TARGET_API_MAC_CARBON - RgnHandle visrgn; -#endif - - SetPort((GrafPtr)GetWindowPort(window)); - BeginUpdate(window); -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), visrgn); - LUpdate(visrgn, s->eventlog); - DisposeRgn(visrgn); -#else - LUpdate(window->visRgn, s->eventlog); -#endif - mac_draweventloggrowicon(s); - EndUpdate(window); -} - -static void mac_closeeventlog(WindowPtr window) -{ - - HideWindow(window); -} - -void mac_showeventlog(Session *s) -{ - - SelectWindow(s->eventlog_window); - ShowWindow(s->eventlog_window); -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macmisc.c b/mac/macmisc.c deleted file mode 100644 index a1a88f5a..00000000 --- a/mac/macmisc.c +++ /dev/null @@ -1,207 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "mac.h" -#include "ssh.h" - -#if TARGET_API_MAC_CARBON -/* - * This is used by (I think) CarbonStdCLib, but only exists in - * CarbonLib 1.1 and later. Muppets. Happily, it's documented to be - * a synonym for NULL. - */ -#include -const CFAllocatorRef kCFAllocatorDefault = NULL; -#else -QDGlobals qd; -#endif - -/* - * Like FrontWindow(), but return NULL if we aren't the front process - * (i.e. the front window isn't one of ours). - */ -WindowPtr mac_frontwindow(void) -{ - ProcessSerialNumber frontpsn; - ProcessSerialNumber curpsn = { 0, kCurrentProcess }; - Boolean result; - - GetFrontProcess(&frontpsn); - if (SameProcess(&frontpsn, &curpsn, &result) == noErr && result) - return FrontWindow(); - return NULL; -} - -void fatalbox(char *fmt, ...) { - va_list ap; - Str255 stuff; - - va_start(ap, fmt); - /* We'd like stuff to be a Pascal string */ - stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); - va_end(ap); - ParamText(stuff, NULL, NULL, NULL); - StopAlert(128, NULL); - cleanup_exit(1); -} - -void modalfatalbox(char *fmt, ...) { - va_list ap; - Str255 stuff; - - va_start(ap, fmt); - /* We'd like stuff to be a Pascal string */ - stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); - va_end(ap); - ParamText(stuff, NULL, NULL, NULL); - StopAlert(128, NULL); - cleanup_exit(1); -} - -Filename filename_from_str(const char *str) -{ - Filename ret; - Str255 tmp; - - /* XXX This fails for filenames over 255 characters long. */ - c2pstrcpy(tmp, str); - FSMakeFSSpec(0, 0, tmp, &ret.fss); - return ret; -} - -/* - * Convert a filename to a string for display purposes. - * See pp 2-44--2-46 of IM:Files - * - * XXX static storage considered harmful - */ -const char *filename_to_str(const Filename *fn) -{ - CInfoPBRec pb; - Str255 dirname; - OSErr err; - static char *path = NULL; - char *newpath; - - if (path != NULL) sfree(path); - path = snewn(fn->fss.name[0], char); - p2cstrcpy(path, fn->fss.name); - pb.dirInfo.ioNamePtr = dirname; - pb.dirInfo.ioVRefNum = fn->fss.vRefNum; - pb.dirInfo.ioDrParID = fn->fss.parID; - pb.dirInfo.ioFDirIndex = -1; - do { - pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; - err = PBGetCatInfoSync(&pb); - - /* XXX Assume not A/UX */ - newpath = snewn(strlen(path) + dirname[0] + 2, char); - p2cstrcpy(newpath, dirname); - strcat(newpath, ":"); - strcat(newpath, path); - sfree(path); - path = newpath; - } while (pb.dirInfo.ioDrDirID != fsRtDirID); - return path; -} - -int filename_equal(Filename f1, Filename f2) -{ - - return f1.fss.vRefNum == f2.fss.vRefNum && - f1.fss.parID == f2.fss.parID && - f1.fss.name[0] == f2.fss.name[0] && - memcmp(f1.fss.name + 1, f2.fss.name + 1, f1.fss.name[0]) == 0; -} - -int filename_is_null(Filename fn) -{ - - return fn.fss.vRefNum == 0 && fn.fss.parID == 0 && fn.fss.name[0] == 0; -} - -FILE *f_open(Filename fn, char const *mode, int is_private) -{ - short savevol; - long savedir; - char tmp[256]; - FILE *ret; - - HGetVol(NULL, &savevol, &savedir); - if (HSetVol(NULL, fn.fss.vRefNum, fn.fss.parID) == noErr) { - p2cstrcpy(tmp, fn.fss.name); - ret = fopen(tmp, mode); - } else - ret = NULL; - HSetVol(NULL, savevol, savedir); - return ret; -} - -struct tm ltime(void) -{ - struct tm tm; - DateTimeRec d; - GetTime(&d); - - tm.tm_sec=d.second; - tm.tm_min=d.minute; - tm.tm_hour=d.hour; - tm.tm_mday=d.day; - tm.tm_mon=d.month-1; - tm.tm_year=d.year-1900; - tm.tm_wday=d.dayOfWeek; - tm.tm_yday=1; /* GetTime doesn't tell us */ - tm.tm_isdst=0; /* Have to do DST ourselves */ - - /* XXX find out DST adjustment and add it */ - - return tm; -} - -const int platform_uses_x11_unix_by_default = FALSE; - -char *platform_get_x_display(void) { - return NULL; -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macnet.c b/mac/macnet.c deleted file mode 100644 index fc022dc7..00000000 --- a/mac/macnet.c +++ /dev/null @@ -1,189 +0,0 @@ -#include "putty.h" -#include "network.h" -#include "mac.h" -#include "ssh.h" - -struct macnet_stack { - SockAddr (*namelookup)(char const *, char **); - SockAddr (*nonamelookup)(char const *); - void (*getaddr)(SockAddr, char *, int); - int (*hostname_is_local)(char *); - int (*address_is_local)(SockAddr); - int (*addrtype)(SockAddr); - void (*addrcopy)(SockAddr, char *); - void (*addr_free)(SockAddr); - Socket (*skregister)(void *, Plug); /* "register" is a reserved word */ - Socket (*new)(SockAddr, int, int, int, int, int, Plug); - Socket (*newlistener)(char *, int, Plug, int, int); - char *(*addr_error)(SockAddr); - void (*poll)(void); - void (*cleanup)(void); -}; - -static struct macnet_stack *stack; - -static struct macnet_stack ot = { - ot_namelookup, ot_nonamelookup, ot_getaddr, ot_hostname_is_local, - ot_address_is_local, ot_addrtype, ot_addrcopy, ot_addr_free, - ot_register, ot_new, ot_newlistener, ot_addr_error, ot_poll, ot_cleanup -}; - -#if !TARGET_API_MAC_CARBON -static struct macnet_stack mactcp = { - mactcp_namelookup, mactcp_nonamelookup, mactcp_getaddr, - mactcp_hostname_is_local, mactcp_address_is_local, mactcp_addrtype, - mactcp_addrcopy, mactcp_addr_free, mactcp_register, mactcp_new, - mactcp_newlistener, mactcp_addr_error, mactcp_poll, mactcp_cleanup -}; -#endif - -void sk_init(void) -{ - -#ifndef NO_OT - if (ot_init() == noErr) - stack = &ot; - else -#endif -#if !TARGET_API_MAC_CARBON - if (mactcp_init() == noErr) - stack = &mactcp; - else -#endif - stack = NULL; -} - -/* - * Network functions exported to the world. These choose whether to call - * MacTCP or OpenTransport and behave accordingly. - */ -SockAddr sk_namelookup(char const *host, char **canonicalname, int address_family) -{ - - if (stack != NULL) - return stack->namelookup(host, canonicalname); - return NULL; -} - -SockAddr sk_nonamelookup(char const *host) -{ - - if (stack != NULL) - return stack->nonamelookup(host); - return NULL; -} - -void sk_getaddr(SockAddr addr, char *buf, int buflen) -{ - - if (stack != NULL) - stack->getaddr(addr, buf, buflen); - else - *buf = '\0'; -} - -int sk_hostname_is_local(char *name) -{ - - if (stack != NULL) - return stack->hostname_is_local(name); - return 0; -} - -int sk_address_is_local(SockAddr addr) -{ - - if (stack != NULL) - return stack->address_is_local(addr); - return 0; -} - -int sk_addrtype(SockAddr addr) -{ - - if (stack != NULL) - return stack->addrtype(addr); - return 0; -} - -void sk_addrcopy(SockAddr addr, char *buf) -{ - - if (stack != NULL) - stack->addrcopy(addr, buf); -} - -void sk_addr_free(SockAddr addr) -{ - - if (stack != NULL) - stack->addr_free(addr); -} - -Socket sk_register(void *sock, Plug plug) -{ - - if (stack != NULL) - return stack->skregister(sock, plug); - return NULL; -} - -Socket sk_new(SockAddr addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug plug) -{ - - if (stack != NULL) - return stack->new(addr, port, privport, oobinline, nodelay, keepalive, - plug); - return NULL; -} - -Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, int address_family) -{ - - if (stack != NULL) - return stack->newlistener(srcaddr, port, plug, local_host_only, address_family); - return NULL; -} - -const char *sk_addr_error(SockAddr addr) -{ - - if (stack != NULL) - return stack->addr_error(addr); - return "No TCP/IP stack installed"; -} - -void sk_poll(void) -{ - - if (stack != NULL) - stack->poll(); -} - -void sk_cleanup(void) -{ - - if (stack != NULL) - stack->cleanup(); -} - -/* We should use Internet Config here. */ -int net_service_lookup(char *service) -{ - - return 0; -} - -SockAddr platform_get_x11_unix_address(const char *display, int displaynum, - char **canonicalname) -{ - return NULL; -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ - diff --git a/mac/macnoise.c b/mac/macnoise.c deleted file mode 100644 index 9d843355..00000000 --- a/mac/macnoise.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Noise generation for PuTTY's cryptographic random number - * generator. - */ - -#include -#include -#include - -#include "putty.h" -#include "ssh.h" -#include "storage.h" - -/* - * This function is called once, at PuTTY startup, and will do some - * seriously silly things like listing directories and getting disk - * free space and a process snapshot. - */ - -static void noise_get_processes(void (*func) (void *, int)) -{ - ProcessSerialNumber psn = {0, kNoProcess}; - ProcessInfoRec info; - - for (;;) { - GetNextProcess(&psn); - if (psn.highLongOfPSN == 0 && psn.lowLongOfPSN == kNoProcess) return; - info.processInfoLength = sizeof(info); - info.processName = NULL; - info.processAppSpec = NULL; - GetProcessInformation(&psn, &info); - func(&info, sizeof(info)); - } -} - -void noise_get_heavy(void (*func) (void *, int)) -{ - - noise_get_light(func); - noise_get_processes(func); - read_random_seed(func); - /* Update the seed immediately, in case another instance uses it. */ - random_save_seed(); -} - -void random_save_seed(void) -{ - int len; - void *data; - - if (random_active) { - random_get_savedata(&data, &len); - write_random_seed(data, len); - sfree(data); - } -} - -/* - * This function is called every time the random pool needs - * stirring, and will acquire the system time. - */ -void noise_get_light(void (*func) (void *, int)) -{ - UnsignedWide utc; - - Microseconds(&utc); - func(&utc, sizeof(utc)); -} - -/* - * This function is called on a timer, and grabs as much changeable - * system data as it can quickly get its hands on. - */ -void noise_regular(void) -{ - /* XXX */ -} - -/* - * This function is called on every keypress or mouse move, and - * will add the current time to the noise pool. It gets the scan - * code or mouse position passed in, and adds that too. - */ -void noise_ultralight(unsigned long data) -{ - UnsignedWide utc; - - Microseconds(&utc); - random_add_noise(&utc, sizeof(utc)); - random_add_noise(&data, sizeof(data)); -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macpgen.c b/mac/macpgen.c deleted file mode 100644 index f8765c43..00000000 --- a/mac/macpgen.c +++ /dev/null @@ -1,593 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* - * macpgen.c - PuTTYgen for Mac OS - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include /* putty.h needs size_t */ -#include /* for vsprintf */ - -#define PUTTY_DO_GLOBALS - -#include "macpgrid.h" -#include "putty.h" -#include "ssh.h" -#include "mac.h" - -static void mac_startup(void); -static void mac_eventloop(void); -#pragma noreturn (mac_eventloop) -static void mac_event(EventRecord *); -static void mac_contentclick(WindowPtr, EventRecord *); -static void mac_growwindow(WindowPtr, EventRecord *); -static void mac_activatewindow(WindowPtr, EventRecord *); -static void mac_suspendresume(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(RgnHandle); -static void mac_adjustmenus(void); -static void mac_closewindow(WindowPtr); -static void mac_zoomwindow(WindowPtr, short); -#pragma noreturn (cleanup_exit) - -struct mac_windows { - WindowPtr about; - WindowPtr licence; -}; - -struct mac_windows windows; -int borednow; -struct mac_gestalts mac_gestalts; - -int main (int argc, char **argv) { - - mac_startup(); - mac_eventloop(); -} - -#pragma noreturn (main) - -static void mac_startup(void) { - Handle menuBar; - TECInfoHandle ti; - -#if !TARGET_API_MAC_CARBON - /* Init Memory Manager */ - MaxApplZone(); - /* Init QuickDraw */ - InitGraf(&qd.thePort); - /* Init Font Manager */ - InitFonts(); - /* Init Window Manager */ - InitWindows(); - /* Init Menu Manager */ - InitMenus(); - /* Init TextEdit */ - TEInit(); - /* Init Dialog Manager */ - InitDialogs(NULL); -#endif - - /* Get base system version (only used if there's no better selector) */ - if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || - (mac_gestalts.sysvers &= 0xffff) < 0x700) - fatalbox("PuTTYgen requires System 7 or newer"); - /* Find out if we've got Color Quickdraw */ - if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) - mac_gestalts.qdvers = gestaltOriginalQD; - /* ... and the Appearance Manager? */ - if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr) - if (Gestalt(gestaltAppearanceAttr, NULL) == noErr) - mac_gestalts.apprvers = 0x0100; - else - mac_gestalts.apprvers = 0; -#if TARGET_RT_MAC_CFM - /* Paranoia: Did we manage to pull in AppearanceLib? */ - if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) - mac_gestalts.apprvers = 0; -#endif -#if TARGET_CPU_68K - mac_gestalts.cntlattr = 0; - mac_gestalts.windattr = 0; -#else - /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ - if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || - &SetControlViewSize == kUnresolvedCFragSymbolAddress) - mac_gestalts.cntlattr = 0; - /* Mac OS 8.5 Window Manager? */ - if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || - &SetWindowContentColor == kUnresolvedCFragSymbolAddress) - mac_gestalts.windattr = 0; -#endif - /* Text Encoding Conversion Manager? */ - if ( -#if TARGET_RT_MAC_CFM - &TECGetInfo == kUnresolvedCFragSymbolAddress || -#else - InitializeUnicodeConverter(NULL) != noErr || -#endif - TECGetInfo(&ti) != noErr) - mac_gestalts.encvvers = 0; - else { - mac_gestalts.encvvers = (*ti)->tecVersion; - mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; - DisposeHandle((Handle)ti); - } - /* Navigation Services? */ - if (NavServicesAvailable()) - mac_gestalts.navsvers = NavLibraryVersion(); - else - mac_gestalts.navsvers = 0; - - /* We've been tested with the Appearance Manager */ - if (mac_gestalts.apprvers != 0) - RegisterAppearanceClient(); - - menuBar = GetNewMBar(128); - if (menuBar == NULL) - fatalbox("Unable to create menu bar."); - SetMenuBar(menuBar); - AppendResMenu(GetMenuHandle(mApple), 'DRVR'); - mac_adjustmenus(); - DrawMenuBar(); - InitCursor(); - windows.about = NULL; - windows.licence = NULL; - - flags = FLAG_INTERACTIVE; - - /* Install Apple Event handlers. */ -#if 0 - AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, - NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); - AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, - NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); -#endif - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); -} - -static void mac_eventloop(void) { - Boolean gotevent; - EventRecord event; - RgnHandle cursrgn; - Point mousenow, mousethen; - KeyState *ks; - WindowPtr front; - - cursrgn = NewRgn(); - GetMouse(&mousethen); - for (;;) { - mac_adjustcursor(cursrgn); - gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn); - mac_adjustcursor(cursrgn); - front = mac_frontwindow(); - if (front != NULL) { - ks = mac_windowkey(front); - if (ks->collecting_entropy) { - GetMouse(&mousenow); - if (mousenow.h != mousethen.h || mousenow.v != mousethen.v) { - ks->entropy[ks->entropy_got++] = *(unsigned *)&mousenow; - ks->entropy[ks->entropy_got++] = TickCount(); - if (ks->entropy_got >= ks->entropy_required) - ks->collecting_entropy = 0; - SetControlValue(ks->progress, ks->entropy_got); - mousethen = mousenow; - } - SetEmptyRgn(cursrgn); - } - } - - if (gotevent) - mac_event(&event); - if (borednow) - cleanup_exit(0); - } - DisposeRgn(cursrgn); -} - -static void mac_event(EventRecord *event) { - short part; - WindowPtr window; - - switch (event->what) { - case mouseDown: - part = FindWindow(event->where, &window); - switch (part) { - case inMenuBar: - mac_adjustmenus(); - mac_menucommand(MenuSelect(event->where)); - break; -#if !TARGET_API_MAC_CARBON - case inSysWindow: - SystemClick(event, window); - break; -#endif - 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? */ -#if TARGET_API_MAC_CARBON - { - BitMap screenBits; - - GetQDGlobalsScreenBits(&screenBits); - DragWindow(window, event->where, &screenBits.bounds); - } -#else - DragWindow(window, event->where, &qd.screenBits.bounds); -#endif - break; - case inGrow: - mac_growwindow(window, event); - 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: - mac_activatewindow((WindowPtr)event->message, event); - break; - case updateEvt: - mac_updatewindow((WindowPtr)event->message); - break; -#if !TARGET_API_MAC_CARBON - case diskEvt: - if (HiWord(event->message) != noErr) { - Point pt; - - SetPt(&pt, 120, 120); - DIBadMount(pt, event->message); - } - break; -#endif - case osEvt: - switch ((event->message & osEvtMessageMask) >> 24) { - case suspendResumeMessage: - mac_suspendresume(event); - break; - } - break; - case kHighLevelEvent: - AEProcessAppleEvent(event); /* errors? */ - break; - } -} - -static void mac_contentclick(WindowPtr window, EventRecord *event) -{ - - if (mac_wininfo(window)->click != NULL) - (*mac_wininfo(window)->click)(window, event); -} - -static void mac_growwindow(WindowPtr window, EventRecord *event) -{ - - if (mac_wininfo(window)->grow != NULL) - (*mac_wininfo(window)->grow)(window, event); -} - -static void mac_activatewindow(WindowPtr window, EventRecord *event) -{ - - mac_adjustmenus(); - if (mac_wininfo(window)->activate != NULL) - (*mac_wininfo(window)->activate)(window, event); -} - -static void mac_updatewindow(WindowPtr window) -{ - - if (mac_wininfo(window)->update != NULL) - (*mac_wininfo(window)->update)(window); -} - -/* - * Work out what kind of window we're dealing with. - */ -static int mac_windowtype(WindowPtr window) -{ - -#if !TARGET_API_MAC_CARBON - if (GetWindowKind(window) < 0) - return wDA; -#endif - return ((WinInfo *)GetWRefCon(window))->wtype; -} - -/* - * Handle a key press - */ -static void mac_keypress(EventRecord *event) -{ - WindowPtr window; - - window = FrontWindow(); - if (event->what == keyDown && (event->modifiers & cmdKey)) { - mac_adjustmenus(); - mac_menucommand(MenuKey(event->message & charCodeMask)); - } else { - if (mac_wininfo(window)->key != NULL) - (*mac_wininfo(window)->key)(window, event); - } -} - -static void mac_menucommand(long result) -{ - short menu, item; - WindowPtr window; -#if !TARGET_API_MAC_CARBON - Str255 da; -#endif - - menu = HiWord(result); - item = LoWord(result); - window = FrontWindow(); - /* Things which do the same whatever window we're in. */ - switch (menu) { - case mApple: - switch (item) { - case iAbout: - mac_openabout(); - goto done; -#if !TARGET_API_MAC_CARBON - default: - GetMenuItemText(GetMenuHandle(mApple), item, da); - OpenDeskAcc(da); - goto done; -#endif - } - break; - case mFile: - switch (item) { - case iNew: - mac_newkey(); - goto done; - case iClose: - mac_closewindow(window); - goto done; - case iQuit: - cleanup_exit(0); - goto done; - } - break; - } - /* If we get here, handling is up to window-specific code. */ - if (mac_wininfo(window)->menu != NULL) - (*mac_wininfo(window)->menu)(window, menu, item); - - done: - HiliteMenu(0); -} - -static void mac_closewindow(WindowPtr window) -{ - - switch (mac_windowtype(window)) { -#if !TARGET_API_MAC_CARBON - case wDA: - CloseDeskAcc(GetWindowKind(window)); - break; -#endif - default: - if (mac_wininfo(window)->close != NULL) - (*mac_wininfo(window)->close)(window); - } -} - -static void mac_suspendresume(EventRecord *event) -{ - WindowPtr front; - EventRecord fakeevent; - - /* - * We're called either before we're suspended or after we're - * resumed, so we're the front application at this point. - */ - front = FrontWindow(); - if (front != NULL) { - fakeevent.what = activateEvt; - fakeevent.message = (UInt32)front; - fakeevent.when = event->when; - fakeevent.where = event->where; - fakeevent.modifiers = - (event->message & resumeFlag) ? activeFlag : 0; - mac_activatewindow(front, &fakeevent); - } -} - -static void mac_zoomwindow(WindowPtr window, short part) { - - /* FIXME: do something */ -} - -/* - * Make the menus look right before the user gets to see them. - */ -#if TARGET_API_MAC_CARBON -#define EnableItem EnableMenuItem -#define DisableItem DisableMenuItem -#endif -static void mac_adjustmenus(void) { - WindowPtr window; - MenuHandle menu; - - window = FrontWindow(); - menu = GetMenuHandle(mApple); - EnableItem(menu, 0); - EnableItem(menu, iAbout); - - menu = GetMenuHandle(mFile); - EnableItem(menu, 0); - EnableItem(menu, iNew); - if (window != NULL) - EnableItem(menu, iClose); - else - DisableItem(menu, iClose); - EnableItem(menu, iQuit); - - if (mac_wininfo(window)->adjustmenus != NULL) - (*mac_wininfo(window)->adjustmenus)(window); - else { - DisableItem(menu, iSave); - DisableItem(menu, iSaveAs); - menu = GetMenuHandle(mEdit); - DisableItem(menu, 0); - menu = GetMenuHandle(mWindow); - DisableItem(menu, 0); /* Until we get more than 1 item on it. */ - } - DrawMenuBar(); -} - -/* - * Make sure the right cursor's being displayed. - */ -static void mac_adjustcursor(RgnHandle cursrgn) -{ - Point mouse; - WindowPtr window, front; - short part; -#if TARGET_API_MAC_CARBON - Cursor arrow; - RgnHandle visrgn; -#endif - - GetMouse(&mouse); - LocalToGlobal(&mouse); - part = FindWindow(mouse, &window); - front = FrontWindow(); - if (part != inContent || window == NULL || window != front) { - /* Cursor isn't in the front window, so switch to arrow */ -#if TARGET_API_MAC_CARBON - GetQDGlobalsArrow(&arrow); - SetCursor(&arrow); -#else - SetCursor(&qd.arrow); -#endif - SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); - if (front != NULL) { -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(front), visrgn); - DiffRgn(cursrgn, visrgn, cursrgn); - DisposeRgn(visrgn); -#else - DiffRgn(cursrgn, front->visRgn, cursrgn); -#endif - } - } else { - if (mac_wininfo(window)->adjustcursor != NULL) - (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); - else { -#if TARGET_API_MAC_CARBON - GetQDGlobalsArrow(&arrow); - SetCursor(&arrow); - GetPortVisibleRegion(GetWindowPort(window), cursrgn); -#else - SetCursor(&qd.arrow); - CopyRgn(window->visRgn, cursrgn); -#endif - } - } -} - -pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, - long refcon) -{ - DescType type; - Size size; - - if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, - &type, NULL, 0, &size) == noErr) - return errAEParamMissed; - - borednow = 1; - return noErr; -} - -void cleanup_exit(int status) -{ - -#if !TARGET_RT_MAC_CFM - if (mac_gestalts.encvvers != 0) - TerminateUnicodeConverter(); -#endif - exit(status); -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macpgen.r b/mac/macpgen.r deleted file mode 100644 index fa04d998..00000000 --- a/mac/macpgen.r +++ /dev/null @@ -1,509 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999, 2002, 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* PuTTYgen resources */ - -/* - * The space after the # for system includes is to stop mkfiles.pl - * trying to chase them (Rez doesn't support the angle-bracket - * syntax). - */ - -# include "Types.r" -# include "Dialogs.r" -# include "Palettes.r" -# include "Script.r" - - -/* Get resource IDs we share with C code */ -#include "macpgrid.h" - -#include "version.r" - -/* - * Finder-related resources - */ - -/* 'pGen' is now registered with Apple as PuTTYgen's signature */ - -type 'pGen' as 'STR '; - -resource 'pGen' (0, purgeable) { - "PuTTYgen experimental Mac port" -}; - -resource 'SIZE' (-1) { - reserved, - acceptSuspendResumeEvents, - reserved, - canBackground, - doesActivateOnFGSwitch, - backgroundAndForeground, - dontGetFrontClicks, - ignoreAppDiedEvents, - is32BitCompatible, - isHighLevelEventAware, - localandRemoteHLEvents, - isStationeryAware, - dontUseTextEditServices, - reserved, - reserved, - reserved, - 1024 * 1024, /* Minimum size */ - 1024 * 1024, /* Preferred size */ -}; - -#define FREF_APPL 128 -#define FREF_Seed 132 - -resource 'FREF' (FREF_APPL, purgeable) { - /* The application itself */ - 'APPL', FREF_APPL, "" -}; - -resource 'FREF' (FREF_Seed, purgeable) { - /* Random seed */ - 'Seed', FREF_Seed, "" -}; - -/* "Internal" file types, which can't be opened */ -resource 'BNDL' (129, purgeable) { - 'pTTI', 0, - { - 'ICN#', { - FREF_Seed, FREF_Seed, - }, - 'FREF', { - FREF_Seed, FREF_Seed, - }; - }; -}; - -resource 'kind' (129) { - 'pTTI', - verBritain, - { - 'Seed', "PuTTY random number seed", - } -}; - -#if TARGET_API_MAC_CARBON -/* - * Mac OS X Info.plist. - * See Tech Note TN2013 for details. - * We don't bother with things that Mac OS X seems to be able to get from - * other resources. - */ -type 'plst' as 'TEXT'; - -resource 'plst' (0) { - "\n" - "\n" - "\n" - " \n" - " CFBundleInfoDictionaryVersion 6.0\n" - " CFBundleIdentifier\n" - " org.tartarus.projects.putty.puttygen\n" - " CFBundleName PuTTYgen\n" - " CFBundlePackageType APPL\n" - " CFBundleSignature pGen\n" - " \n" - "\n" -}; - -/* Mac OS X doesn't use this, but Mac OS 9 does. */ -type 'carb' as 'TEXT'; -resource 'carb' (0) { "" }; -#endif - -/* Icons, courtesy of DeRez */ - -/* Random seed icon */ - -resource 'ICN#' (FREF_Seed, purgeable) { - { /* array: 2 elements */ - /* [1] */ - $"1FFFFC00 18F36600 161EF500 1CC92C80" - $"1CF2EC40 10662C20 108E07F0 151F0490" - $"1E00C4F0 1803BBD0 1FC5BE10 108B5A90" - $"1B3C4F50 1267AC90 14B60470 1BB791B0" - $"17F4D2B0 1DC1F830 1B029450 1B753DD0" - $"145A8170 11390DD0 1E15A8B0 1CC4CD90" - $"154ECED0 15C9CF30 172CDB50 12617970" - $"15E45C90 1D4B9890 15CE4430 1FFFFFF0", - /* [2] */ - $"1FFFFC00 1FFFFE00 1FFFFF00 1FFFFF80" - $"1FFFFFC0 1FFFFFE0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - $"1FFFFFF0 1FFFFFF0 1FFFFFF0 1FFFFFF0" - } -}; -resource 'icl4' (FREF_Seed) { - $"000FFFFFFFFFFFFFFFFFFF0000000000" - $"000FFC0CFFFF0CFF1FFC0FF000000000" - $"000F0FF0C0CFFFF1FFFFCFCF00000000" - $"000FFF0CFF0CF11F0CFCFFCCF0000000" - $"000FFFC0FFFF11F0FFF0FFCCCF000000" - $"000F0C0C0FF11FFC0CFCFFCCCCF00000" - $"000FC0C0F111FFF0C0C0CFFFFFFF0000" - $"000F0F0F111FFFFF0C0C0F0CFC0F0000" - $"000FFFF111111111FFC0CFC0FFFF0000" - $"000FF111111111FFFCFFF0FFFF0F0000" - $"000FFFFFFF111FCFF0FFFFF0C0CF0000" - $"000F0C0CF111FCFF0F0FFCFCFC0F0000" - $"000FF0FF11FFFFC0CFC0FFFFCFCF0000" - $"000F0CF11FFC0FFFFCFCFF0CFC0F0000" - $"000FCF11F0FFCFF0C0C0CFC0CFFF0000" - $"000FF1FFFCFF0FFFFC0F0C0FFCFF0000" - $"000F1FFFFFFFCFC0FFCFC0F0F0FF0000" - $"000FFF0FFF0C0C0FFFFFFC0C0CFF0000" - $"000FF0FFC0C0C0F0F0CF0FC0CFCF0000" - $"000FFCFF0FFF0F0F0CFFFF0FFF0F0000" - $"000FCFC0CF0FF0F0F0C0C0CFCFFF0000" - $"000F0C0F0CFFFC0F0C0CFF0FFF0F0000" - $"000FFFF0C0CFCFCFF0F0F0C0F0FF0000" - $"000FFF0CFF0C0F0CFF0CFF0FFC0F0000" - $"000FCFCF0FC0FFF0FFC0FFF0FFCF0000" - $"000F0F0FFF0CFC0FFF0CFFFF0CFF0000" - $"000FCFFFC0F0FFC0FFCFF0FFCFCF0000" - $"000F0CFC0FFC0C0F0FFFFC0F0FFF0000" - $"000FCFCFFFF0CFC0CFCFFFC0F0CF0000" - $"000FFF0F0F0CF0FFFC0FFC0CFC0F0000" - $"000FCFCFFFC0FFF0CFC0CFC0C0FF0000" - $"000FFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'icl8' (FREF_Seed) { - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000" - $"000000FFFFF5F5F5FFFFFFFFF5F5FFFF05FFFFF5F5FFFF000000000000000000" - $"000000FFF5FFFFF5F5F5F5FFFFFFFF05FFFFFFFFF5FF2BFF0000000000000000" - $"000000FFFFFFF5F5FFFFF5F5FF0505FF0000FFF5FFFF2B2BFF00000000000000" - $"000000FFFFFFF5F5FFFFFFFF0505FFF5FFFFFFF5FFFF2B2B2BFF000000000000" - $"000000FFF5F5F5F5F5FFFF0505FFFFF5F5F5FFF5FFFF2B2B2B2BFF0000000000" - $"000000FFF5F5F5F5FF050505FFFFFFF5F5F5F5F5F5FFFFFFFFFFFFFF00000000" - $"000000FFF5FFF5FF050505FFFFFFFFFFF5F5F5F5F5FFF5F5FFF5F5FF00000000" - $"000000FFFFFFFF050505050505050505FFFFF5F5F5FFF5F5FFFFFFFF00000000" - $"000000FFFF050505050505050505FFFFFFF5FFFFFFF5FFFFFFFFF5FF00000000" - $"000000FFFFFFFFFFFFFF050505FFF5FFFFF5FFFFFFFFFFF5F5F5F5FF00000000" - $"000000FFF5F5F5F5FF050505FFF5FFFFF5FFF5FFFFF5FFF5FFF5F5FF00000000" - $"000000FFFFF5FFFF0505FFFFFFFFF5F5F5FFF5F5FFFFFFFFF5FFF5FF00000000" - $"000000FFF5F5FF0505FFFFF5F5FFFFFFFFF5FFF5FFFFF5F5FFF5F5FF00000000" - $"000000FFF5FF0505FFF5FFFFF5FFFFF5F5F5F5F5F5FFF5F5F5FFFFFF00000000" - $"000000FFFF05FFFFFFF5FFFFF5FFFFFFFFF5F5FFF5F5F5FFFFF5FFFF00000000" - $"000000FF05FFFFFFFFFFFFFFF5FFF5F5FFFFF5FFF5F5FFF5FFF5FFFF00000000" - $"000000FFFFFFF5FFFFFFF5F5F5F5F5FFFFFFFFFFFFF5F5F5F5F5FFFF00000000" - $"000000FFFFF5FFFFF5F5F5F5F5F5FF00FFF5F5FFF5FFF5F5F5FFF5FF00000000" - $"000000FFFFF5FFFFF5FFFFFFF5FF00FFF5F5FFFFFFFFF5FFFFFFF5FF00000000" - $"000000FFF5FFF5F5F5FFF5FFFF00FF00FFF5F5F5F5F5F5FFF5FFFFFF00000000" - $"000000FFF5F5F5FFF5F5FFFFFF0000FFF5F5F5F5FFFFF5FFFFFF00FF00000000" - $"000000FFFFFFFFF5F5F5F5FFF5FF00FFFFF5FFF5FFF5F5F5FF00FFFF00000000" - $"000000FFFFFFF5F5FFFFF5F5F5FF0000FFFFF5F5FFFFF5FFFF0000FF00000000" - $"000000FFF5FFF5FFF5FFF5F5FFFFFF00FFFFF5F5FFFFFFF5FFFF00FF00000000" - $"000000FFF5FFF5FFFFFFF5F5FFF5F5FFFFFFF5F5FFFFFFFFF5F5FFFF00000000" - $"000000FFF5FFFFFFF5F5FFF5FFFFF5F5FFFFF5FFFFF5FFFFF5FFF5FF00000000" - $"000000FFF5F5FFF5F5FFFFF5F5F5F5FFF5FFFFFFFFF5F5FFF5FFFFFF00000000" - $"000000FFF5FFF5FFFFFFFFF5F5FFF5F5F5FFF5FFFFFFF5F5FFF5F5FF00000000" - $"000000FFFFFFF5FFF5FFF5F5FFF5FFFFFFF5F5FFFFF5F5F5FFF5F5FF00000000" - $"000000FFF5FFF5FFFFFFF5F5FFFFFFF5F5FFF5F5F5FFF5F5F5F5FFFF00000000" - $"000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" -}; -resource 'ics#' (FREF_Seed) { - { /* array: 2 elements */ - /* [1] */ - $"7FE0 56B0 59A8 637C 51DC 6794 59AC 76EC" - $"7224 7C6C 743C 71AC 505C 459C 4424 7FFC", - /* [2] */ - $"7FE0 7FF0 7FF8 7FFC 7FFC 7FFC 7FFC 7FFC" - $"7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC" - } -}; -resource 'ics4' (FREF_Seed) { - $"0FFFFFFFFFF00000" - $"0F0F0FF1FCFF0000" - $"0FCFF11FF0FCF000" - $"0FF111FF0FFFFF00" - $"0FCF111FFFCFFF00" - $"0FF11FFFFC0F0F00" - $"0F1FF0CFF0F0FF00" - $"0FFF0FFCFFFCFF00" - $"0FFFC0F0C0F0CF00" - $"0FFFFF0C0FFCFF00" - $"0FFFCFC0C0FFFF00" - $"0FFF0C0FFCFCFF00" - $"0FCFC0C0CFCFFF00" - $"0F0C0F0FFC0FFF00" - $"0FC0CFC0C0F0CF00" - $"0FFFFFFFFFFFFF" -}; -resource 'ics8' (FREF_Seed) { - $"00FFFFFFFFFFFFFFFFFFFF0000000000" - $"00FFF5FFF5FFFF05FFF5FFFF00000000" - $"00FFF5FFFF0505FFFFF5FF2BFF000000" - $"00FFFF050505FFFFF5FFFFFFFFFF0000" - $"00FFF5FF050505FFFFFFF5FFFFFF0000" - $"00FFFF0505FFFFFFFFF5F5FFF5FF0000" - $"00FF05FFFFF5F5FFFFF5FFF5FFFF0000" - $"00FFFFFFF5FFFFF5FFFFFFF5FFFF0000" - $"00FFFFFFF5F5FFF5F5F5FFF5F5FF0000" - $"00FFFFFFFFFFF5F5F5FFFFF5FFFF0000" - $"00FFFFFFF5FFF5F5F5F5FFFFFFFF0000" - $"00FFFFFFF5F5F5FFFFF5FFF5FFFF0000" - $"00FFF5FFF5F5F5F5F5FFF5FFFFFF0000" - $"00FFF5F5F5FFF5FFFFF5F5FFFFFF0000" - $"00FFF5F5F5FFF5F5F5F5FFF5F5FF0000" - $"00FFFFFFFFFFFFFFFFFFFFFFFFFF" -}; - -/* - * Application-missing message string, for random seed and host key database - * files. - */ -resource 'STR ' (-16397, purgeable) { - "This file is used internally by PuTTY. It cannot be opened." -}; - -/* Missing-application name string, for private keys. */ -/* XXX Private keys should eventually be owned by Pageant */ -resource 'STR ' (-16396, purgeable) { - "PuTTYgen" -}; - -/* - * Internal resources - */ - -/* Menu bar */ - -resource 'MBAR' (MBAR_Main, preload) { - { mApple, mFile, mEdit, mWindow } -}; - -resource 'MENU' (mApple, preload) { - mApple, - textMenuProc, - 0b11111111111111111111111111111101, - enabled, - apple, - { - "About PuTTYgen\0xc9", noicon, nokey, nomark, plain, - "-", noicon, nokey, nomark, plain, - } -}; - -resource 'MENU' (mFile, preload) { - mFile, - textMenuProc, - 0b11111111111111111111111101111011, - enabled, - "File", - { - "New", noicon, "N", nomark, plain, - "Open\0xc9", noicon, "O", nomark, plain, - "-", noicon, nokey, nomark, plain, - "Close", noicon, "W", nomark, plain, - "Save", noicon, "S", nomark, plain, - "Save As\0xc9", noicon, nokey, nomark, plain, - "-", noicon, nokey, nomark, plain, - "Quit", noicon, "Q", nomark, plain, - } -}; - -resource 'MENU' (mEdit, preload) { - mEdit, - textMenuProc, - 0b11111111111111111111111111111101, - enabled, - "Edit", - { - "Undo", noicon, "Z", nomark, plain, - "-", noicon, nokey, nomark, plain, - "Cut", noicon, "X", nomark, plain, - "Copy", noicon, "C", nomark, plain, - "Paste", noicon, "V", nomark, plain, - "Clear", noicon, nokey, nomark, plain, - "Select All", noicon, "A", nomark, plain, - } -}; - -resource 'MENU' (mWindow, preload) { - mWindow, - textMenuProc, - 0b11111111111111111111111111111111, - enabled, - "Window", - { - } -}; - -/* Fatal error box. Stolen from the Finder. */ - -resource 'ALRT' (wFatal, "fatalbox", purgeable) { - {54, 67, 152, 435}, - wFatal, - beepStages, - alertPositionMainScreen -}; - -resource 'DITL' (wFatal, "fatalbox", purgeable) { - { /* array DITLarray: 3 elements */ - /* [1] */ - {68, 299, 88, 358}, - Button { - enabled, - "OK" - }, - /* [2] */ - {68, 227, 88, 286}, - StaticText { - disabled, - "" - }, - /* [3] */ - {7, 74, 55, 358}, - StaticText { - disabled, - "^0" - } - } -}; - -/* "About" box */ - -resource 'DLOG' (wAbout, "about", purgeable) { - { 0, 0, 120, 240 }, - noGrowDocProc, - invisible, - goAway, - wAbout, /* RefCon -- identifies the window to PuTTY */ - wAbout, /* DITL ID */ - "About PuTTYgen", - alertPositionMainScreen -}; - -resource 'dlgx' (wAbout, "about", purgeable) { - versionZero { - kDialogFlagsUseThemeBackground | kDialogFlagsUseThemeControls - } -}; - -resource 'DITL' (wAbout, "about", purgeable) { - { - { 87, 13, 107, 227 }, - Button { enabled, "View Licence" }, - { 13, 13, 29, 227 }, - StaticText { disabled, "PuTTYgen"}, - { 42, 13, 74, 227 }, - StaticText { disabled, "Some version or other\n" - "Copyright © 1997-2010 Simon Tatham"}, - } -}; - -/* Licence box */ - -resource 'WIND' (wLicence, "licence", purgeable) { - { 0, 0, 250, 400 }, - noGrowDocProc, - visible, - goAway, - wLicence, - "PuTTYgen Licence", - alertPositionParentWindowScreen -}; - -type 'TEXT' { - string; -}; - -resource 'TEXT' (wLicence, "licence", purgeable) { - "Copyright 1997-2010 Simon Tatham.\n" - "\n" - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry, " - "Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus " - "Kuhn, Colin Watson, and CORE SDI S.A.\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." -}; - -/* Key box */ - -resource 'DLOG' (wKey, "key", purgeable) { - { 0, 0, 120, 240 }, - noGrowDocProc, - invisible, - goAway, - wKey, /* RefCon -- identifies the window to PuTTY */ - wKey, /* DITL ID */ - "untitled", - staggerParentWindowScreen -}; - -resource 'dlgx' (wKey, "key", purgeable) { - versionZero { - kDialogFlagsUseThemeBackground | kDialogFlagsUseThemeControls - } -}; - -#define cProgress 129 - -resource 'DITL' (wKey, "key", purgeable) { - { - { 13, 13, 33, 227 }, - Button { enabled, "Generate" }, - { 46, 13, 12, 227 }, - Control { enabled, cProgress }, - } -}; - -resource 'CNTL' (cProgress) { - { 46, 13, 12, 227 }, - 0, visible, 0, 0, - kControlProgressBarProc, 0, "" -}; diff --git a/mac/macpgkey.c b/mac/macpgkey.c deleted file mode 100644 index f78f338d..00000000 --- a/mac/macpgkey.c +++ /dev/null @@ -1,196 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 2003 Ben Harris - * Copyright (c) 1997-2003 Simon Tatham - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* Stuff to handle the key window in PuTTYgen */ - -#include -#include -#include -#include - -#include "putty.h" -#include "mac.h" -#include "macpgrid.h" -#include "ssh.h" - -/* ---------------------------------------------------------------------- - * Progress report code. This is really horrible :-) - */ -#define PROGRESSRANGE 65535 -#define MAXPHASE 5 -struct progress { - int nphases; - struct { - int exponential; - unsigned startpoint, total; - unsigned param, current, n; /* if exponential */ - unsigned mult; /* if linear */ - } phases[MAXPHASE]; - unsigned total, divisor, range; - ControlHandle progbar; -}; - -static void progress_update(void *param, int action, int phase, int iprogress) -{ - struct progress *p = (struct progress *) param; - unsigned progress = iprogress; - int position; - - if (action < PROGFN_READY && p->nphases < phase) - p->nphases = phase; - switch (action) { - case PROGFN_INITIALISE: - p->nphases = 0; - break; - case PROGFN_LIN_PHASE: - p->phases[phase-1].exponential = 0; - p->phases[phase-1].mult = p->phases[phase].total / progress; - break; - case PROGFN_EXP_PHASE: - p->phases[phase-1].exponential = 1; - p->phases[phase-1].param = 0x10000 + progress; - p->phases[phase-1].current = p->phases[phase-1].total; - p->phases[phase-1].n = 0; - break; - case PROGFN_PHASE_EXTENT: - p->phases[phase-1].total = progress; - break; - case PROGFN_READY: - { - unsigned total = 0; - int i; - for (i = 0; i < p->nphases; i++) { - p->phases[i].startpoint = total; - total += p->phases[i].total; - } - p->total = total; - p->divisor = ((p->total + PROGRESSRANGE - 1) / PROGRESSRANGE); - p->range = p->total / p->divisor; - SetControlMaximum(p->progbar, p->range); - } - break; - case PROGFN_PROGRESS: - if (p->phases[phase-1].exponential) { - while (p->phases[phase-1].n < progress) { - p->phases[phase-1].n++; - p->phases[phase-1].current *= p->phases[phase-1].param; - p->phases[phase-1].current /= 0x10000; - } - position = (p->phases[phase-1].startpoint + - p->phases[phase-1].total - p->phases[phase-1].current); - } else { - position = (p->phases[phase-1].startpoint + - progress * p->phases[phase-1].mult); - } - SetControlValue(p->progbar, position / p->divisor); - break; - } -} - -static void mac_clickkey(WindowPtr window, EventRecord *event) -{ - short item; - DialogRef dialog; - KeyState *ks = mac_windowkey(window); - - dialog = GetDialogFromWindow(window); - if (DialogSelect(event, &dialog, &item)) - switch (item) { - case wiKeyGenerate: - SetControlMaximum(ks->progress, 1024); - ks->entropy = snewn(1024, unsigned int); - ks->entropy_required = 1024; - ks->entropy_got = 0; - ks->collecting_entropy = TRUE; - /* Do something */ - break; - } -} - -static void mac_activatekey(WindowPtr window, EventRecord *event) -{ - DialogRef dialog; - DialogItemType itemtype; - Handle itemhandle; - short item; - Rect itemrect; - int active; - - dialog = GetDialogFromWindow(window); - active = (event->modifiers & activeFlag) != 0; - GetDialogItem(dialog, wiKeyGenerate, &itemtype, &itemhandle, &itemrect); - HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); - DialogSelect(event, &dialog, &item); -} - -static void mac_updatekey(WindowPtr window) -{ -#if TARGET_API_MAC_CARBON - RgnHandle rgn; -#endif - - BeginUpdate(window); -#if TARGET_API_MAC_CARBON - rgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), rgn); - UpdateDialog(GetDialogFromWindow(window), rgn); - DisposeRgn(rgn); -#else - UpdateDialog(window, window->visRgn); -#endif - EndUpdate(window); -} - -void mac_newkey(void) -{ - KeyState *ks; - WinInfo *wi; - Handle h; - short type; - Rect rect; - - ks = snew(KeyState); - ks->box = GetNewDialog(wKey, NULL, (WindowPtr)-1); - GetDialogItem(ks->box, wiKeyProgress, &type, &h, &rect); - ks->progress = (ControlHandle)h; - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->ks = ks; - wi->wtype = wKey; - wi->update = &mac_updatekey; - wi->click = &mac_clickkey; - wi->activate = &mac_activatekey; - SetWRefCon(GetDialogWindow(ks->box), (long)wi); - ShowWindow(GetDialogWindow(ks->box)); -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macpgrid.h b/mac/macpgrid.h deleted file mode 100644 index 7f843954..00000000 --- a/mac/macpgrid.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $Id$ */ - -/* - * macpgrid.h -- Mac resource IDs for PuTTYgen - * - * 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 -#define mEdit 130 -#define mWindow 131 - -/* Menu Items */ -/* Apple menu */ -#define iAbout 1 -/* File menu */ -#define iNew 1 -#define iOpen 2 -#define iClose 4 -#define iSave 5 -#define iSaveAs 6 -#define iQuit 8 -/* Edit menu */ -#define iUndo 1 -#define iCut 3 -#define iCopy 4 -#define iPaste 5 -#define iClear 6 -#define iSelectAll 7 -/* Window menu */ - -/* 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 wiAboutLicence 1 -#define wiAboutVersion 3 -#define wLicence 131 -#define wKey 134 -#define wiKeyGenerate 1 -#define wiKeyProgress 2 - diff --git a/mac/macresid.h b/mac/macresid.h deleted file mode 100644 index 654938c1..00000000 --- a/mac/macresid.h +++ /dev/null @@ -1,79 +0,0 @@ -/* $Id$ */ - -/* - * macresid.h -- Mac resource IDs - * - * This file is shared by C and Rez source files - */ - -/* TMPL for saved sessions */ -#define TMPL_Int 128 - -/* Menu bar IDs */ -#define MBAR_Main 128 - -/* Open IDs */ -#define open_pTTY 128 - -/* Menu IDs */ -#define mApple 128 -#define mFile 129 -#define mEdit 130 -#define mWindow 131 - -/* Menu Items */ -/* Apple menu */ -#define iAbout 1 -/* File menu */ -#define iNew 1 -#define iOpen 2 -#define iChange 4 -#define iClose 6 -#define iSave 7 -#define iSaveAs 8 -#define iDuplicate 9 -#define iQuit 11 -/* Edit menu */ -#define iUndo 1 -#define iCut 3 -#define iCopy 4 -#define iPaste 5 -#define iClear 6 -#define iSelectAll 7 -/* Window menu */ -#define iShowEventLog 1 - -/* 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 wiAboutLicence 1 -#define wiAboutVersion 3 -#define wTerminal 130 -#define wLicence 131 -#define wSettings 132 -#define wiSettingsOpen 1 -#define wEventLog 133 -#define wQuestion 134 -#define wAbsent 135 -#define wWrong 136 - -/* Controls */ -#define cVScroll 128 - -/* ldes for list box controls */ -#define ldes_Default 128 - -/* xDEFs */ -#define CDEF_EditBox 129 -#define SYS7_EDITBOX_VARIANT 0 -#define SYS7_TEXT_VARIANT 1 -#define SYS7_EDITBOX_PROC ((CDEF_EditBox << 4) + SYS7_EDITBOX_VARIANT) -#define SYS7_TEXT_PROC ((CDEF_EditBox << 4) + SYS7_TEXT_VARIANT) -#define CDEF_Default 130 -#define SYS7_DEFAULT_PROC (CDEF_Default << 4) -#define CDEF_ListBox 131 -#define SYS7_LISTBOX_PROC (CDEF_ListBox << 4) -#define CDEF_GroupBox 132 -#define SYS7_GROUPBOX_PROC (CDEF_GroupBox << 4) diff --git a/mac/macstore.c b/mac/macstore.c deleted file mode 100644 index 35f31bdb..00000000 --- a/mac/macstore.c +++ /dev/null @@ -1,739 +0,0 @@ -/* $Id$ */ - -/* - * macstore.c: Macintosh-specific impementation of the interface - * defined in storage.h - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "putty.h" -#include "storage.h" -#include "mac.h" -#include "macresid.h" - - -OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit); - -/* - * We store each session as a file in the "PuTTY" sub-directory of the - * preferences folder. Each (key,value) pair is stored as a resource. - */ - -OSErr get_putty_dir(Boolean makeit, short *pVRefNum, long *pDirID) -{ - OSErr error = noErr; - short prefVRefNum; - FSSpec puttydir; - long prefDirID, puttyDirID; - - error = FindFolder(kOnSystemDisk, kPreferencesFolderType, makeit, - &prefVRefNum, &prefDirID); - if (error != noErr) goto out; - - error = FSMakeFSSpec(prefVRefNum, prefDirID, "\pPuTTY", &puttydir); - if (error != noErr && error != fnfErr) goto out; - error = FSpGetDirID(&puttydir, &puttyDirID, makeit); - if (error != noErr) goto out; - - *pVRefNum = prefVRefNum; - *pDirID = puttyDirID; - - out: - return error; -} - -OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID) { - OSErr error = noErr; - short puttyVRefNum; - FSSpec sessdir; - long puttyDirID, sessDirID; - - error = get_putty_dir(makeit, &puttyVRefNum, &puttyDirID); - if (error != noErr) goto out; - error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pSaved Sessions", - &sessdir); - if (error != noErr && error != fnfErr) goto out; - error = FSpGetDirID(&sessdir, &sessDirID, makeit); - if (error != noErr) goto out; - - *pVRefNum = puttyVRefNum; - *pDirID = sessDirID; - - out: - return error; -} - -OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit) { - CInfoPBRec pb; - OSErr error = noErr; - - pb.dirInfo.ioNamePtr = f->name; - pb.dirInfo.ioVRefNum = f->vRefNum; - pb.dirInfo.ioDrDirID = f->parID; - pb.dirInfo.ioFDirIndex = 0; - error = PBGetCatInfoSync(&pb); - if (error == fnfErr && makeit) - return FSpDirCreate(f, smSystemScript, idp); - if (error != noErr) goto out; - if ((pb.dirInfo.ioFlAttrib & ioDirMask) == 0) { - error = dirNFErr; - goto out; - } - *idp = pb.dirInfo.ioDrDirID; - - out: - return error; -} - -/* Copy a resource into the current resource file */ -static OSErr copy_resource(ResType restype, short resid) -{ - Handle h; - Str255 resname; - - h = GetResource(restype, resid); - if (h != NULL) { - GetResInfo(h, &resid, &restype, resname); - DetachResource(h); - AddResource(h, restype, resid, resname); - if (ResError() == noErr) - WriteResource(h); - } - return ResError(); -} - -struct write_settings { - int fd; - FSSpec tmpfile; - FSSpec dstfile; -}; - -void *open_settings_w(char const *sessionname, char **errmsg) { - short sessVRefNum; - long sessDirID; - OSErr error; - Str255 psessionname; - FSSpec dstfile; - - *errmsg = NULL; - - error = get_session_dir(kCreateFolder, &sessVRefNum, &sessDirID); - if (error != noErr) return NULL; - - if (!sessionname || !*sessionname) - sessionname = "Default Settings"; - c2pstrcpy(psessionname, sessionname); - error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &dstfile); - if (error == fnfErr) { - FSpCreateResFile(&dstfile, PUTTY_CREATOR, SESS_TYPE, smSystemScript); - if ((error = ResError()) != noErr) return NULL; - } else if (error != noErr) return NULL; - - return open_settings_w_fsp(&dstfile); -} - -/* - * NB: Destination file must exist. - */ -void *open_settings_w_fsp(FSSpec *dstfile) -{ - short tmpVRefNum; - long tmpDirID; - struct write_settings *ws; - OSErr error; - Str255 tmpname; - - ws = snew(struct write_settings); - ws->dstfile = *dstfile; - - /* Create a temporary file to save to first. */ - error = FindFolder(ws->dstfile.vRefNum, kTemporaryFolderType, - kCreateFolder, &tmpVRefNum, &tmpDirID); - if (error != noErr) goto out; - c2pstrcpy(tmpname, tmpnam(NULL)); - error = FSMakeFSSpec(tmpVRefNum, tmpDirID, tmpname, &ws->tmpfile); - if (error != noErr && error != fnfErr) goto out; - if (error == noErr) { - error = FSpDelete(&ws->tmpfile); - if (error != noErr) goto out; - } - FSpCreateResFile(&ws->tmpfile, PUTTY_CREATOR, SESS_TYPE, smSystemScript); - if ((error = ResError()) != noErr) goto out; - - ws->fd = FSpOpenResFile(&ws->tmpfile, fsWrPerm); - if (ws->fd == -1) {error = ResError(); goto out;} - - /* Set up standard resources. Doesn't matter if these fail. */ - copy_resource('STR ', -16396); - copy_resource('TMPL', TMPL_Int); - - return ws; - - out: - safefree(ws); - fatalbox("Failed to open session for write (%d)", error); -} - -void write_setting_s(void *handle, char const *key, char const *value) { - int fd = *(int *)handle; - Handle h; - int id; - OSErr error; - Str255 pkey; - - UseResFile(fd); - if (ResError() != noErr) - fatalbox("Failed to open saved session (%d)", ResError()); - - error = PtrToHand(value, &h, strlen(value)); - if (error != noErr) - fatalbox("Failed to allocate memory"); - /* Put the data in a resource. */ - id = Unique1ID(FOUR_CHAR_CODE('TEXT')); - if (ResError() != noErr) - fatalbox("Failed to get ID for resource %s (%d)", key, ResError()); - c2pstrcpy(pkey, key); - AddResource(h, FOUR_CHAR_CODE('TEXT'), id, pkey); - if (ResError() != noErr) - fatalbox("Failed to add resource %s (%d)", key, ResError()); -} - -void write_setting_i(void *handle, char const *key, int value) { - int fd = *(int *)handle; - Handle h; - int id; - OSErr error; - Str255 pkey; - - UseResFile(fd); - if (ResError() != noErr) - fatalbox("Failed to open saved session (%d)", ResError()); - - /* XXX assume all systems have the same "int" format */ - error = PtrToHand(&value, &h, sizeof(int)); - if (error != noErr) - fatalbox("Failed to allocate memory (%d)", error); - - /* Put the data in a resource. */ - id = Unique1ID(FOUR_CHAR_CODE('Int ')); - if (ResError() != noErr) - fatalbox("Failed to get ID for resource %s (%d)", key, ResError()); - c2pstrcpy(pkey, key); - AddResource(h, FOUR_CHAR_CODE('Int '), id, pkey); - if (ResError() != noErr) - fatalbox("Failed to add resource %s (%d)", key, ResError()); -} - -void close_settings_w(void *handle) { - struct write_settings *ws = handle; - OSErr error; - - CloseResFile(ws->fd); - if ((error = ResError()) != noErr) - goto out; - error = FSpExchangeFiles(&ws->tmpfile, &ws->dstfile); - if (error != noErr) goto out; - error = FSpDelete(&ws->tmpfile); - if (error != noErr) goto out; - return; - - out: - fatalbox("Close of saved session failed (%d)", error); - safefree(handle); -} - -void *open_settings_r(char const *sessionname) -{ - short sessVRefNum; - long sessDirID; - FSSpec sessfile; - OSErr error; - Str255 psessionname; - - error = get_session_dir(kDontCreateFolder, &sessVRefNum, &sessDirID); - - if (!sessionname || !*sessionname) - sessionname = "Default Settings"; - c2pstrcpy(psessionname, sessionname); - error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &sessfile); - if (error != noErr) goto out; - return open_settings_r_fsp(&sessfile); - - out: - return NULL; -} - -void *open_settings_r_fsp(FSSpec *sessfile) -{ - OSErr error; - int fd; - int *handle; - - fd = FSpOpenResFile(sessfile, fsRdPerm); - if (fd == 0) {error = ResError(); goto out;} - - handle = snew(int); - *handle = fd; - return handle; - - out: - return NULL; -} - -char *read_setting_s(void *handle, char const *key, char *buffer, int buflen) { - int fd; - Handle h; - size_t len; - Str255 pkey; - - if (handle == NULL) goto out; - fd = *(int *)handle; - UseResFile(fd); - if (ResError() != noErr) goto out; - c2pstrcpy(pkey, key); - h = Get1NamedResource(FOUR_CHAR_CODE('TEXT'), pkey); - if (h == NULL) goto out; - - len = GetHandleSize(h); - if (len + 1 > buflen) goto out; - memcpy(buffer, *h, len); - buffer[len] = '\0'; - - ReleaseResource(h); - if (ResError() != noErr) goto out; - return buffer; - - out: - return NULL; -} - -int read_setting_i(void *handle, char const *key, int defvalue) { - int fd; - Handle h; - int value; - Str255 pkey; - - if (handle == NULL) goto out; - fd = *(int *)handle; - UseResFile(fd); - if (ResError() != noErr) goto out; - c2pstrcpy(pkey, key); - h = Get1NamedResource(FOUR_CHAR_CODE('Int '), pkey); - if (h == NULL) goto out; - value = *(int *)*h; - ReleaseResource(h); - if (ResError() != noErr) goto out; - return value; - - out: - return defvalue; -} - -int read_setting_fontspec(void *handle, const char *name, FontSpec *result) -{ - char *settingname; - FontSpec ret; - char tmp[256]; - - if (!read_setting_s(handle, name, tmp, sizeof(tmp))) - return 0; - c2pstrcpy(ret.name, tmp); - settingname = dupcat(name, "Face", NULL); - ret.face = read_setting_i(handle, settingname, 0); - sfree(settingname); - settingname = dupcat(name, "Height", NULL); - ret.size = read_setting_i(handle, settingname, 0); - sfree(settingname); - if (ret.size == 0) return 0; - *result = ret; - return 1; -} - -void write_setting_fontspec(void *handle, const char *name, FontSpec font) -{ - char *settingname; - char tmp[256]; - - p2cstrcpy(tmp, font.name); - write_setting_s(handle, name, tmp); - settingname = dupcat(name, "Face", NULL); - write_setting_i(handle, settingname, font.face); - sfree(settingname); - settingname = dupcat(name, "Size", NULL); - write_setting_i(handle, settingname, font.size); - sfree(settingname); -} - -int read_setting_filename(void *handle, const char *key, Filename *result) -{ - int fd; - AliasHandle h; - Boolean changed; - OSErr err; - Str255 pkey; - - if (handle == NULL) goto out; - fd = *(int *)handle; - UseResFile(fd); - if (ResError() != noErr) goto out; - c2pstrcpy(pkey, key); - h = (AliasHandle)Get1NamedResource(rAliasType, pkey); - if (h == NULL) goto out; - if ((*h)->userType == 'pTTY' && (*h)->aliasSize == sizeof(**h)) - memset(result, 0, sizeof(*result)); - else { - err = ResolveAlias(NULL, h, &result->fss, &changed); - if (err != noErr && err != fnfErr) goto out; - if ((*h)->userType == 'pTTY') { - long dirid; - StrFileName fname; - - /* Tail of record is pascal string contaning leafname */ - if (FSpGetDirID(&result->fss, &dirid, FALSE) != noErr) goto out; - memcpy(fname, (char *)*h + (*h)->aliasSize, - GetHandleSize((Handle)h) - (*h)->aliasSize); - err = FSMakeFSSpec(result->fss.vRefNum, dirid, fname, - &result->fss); - if (err != noErr && err != fnfErr) goto out; - } - } - ReleaseResource((Handle)h); - if (ResError() != noErr) goto out; - return 1; - - out: - return 0; -} - -void write_setting_filename(void *handle, const char *key, Filename fn) -{ - int fd = *(int *)handle; - AliasHandle h; - int id; - OSErr error; - Str255 pkey; - - UseResFile(fd); - if (ResError() != noErr) - fatalbox("Failed to open saved session (%d)", ResError()); - - if (filename_is_null(fn)) { - /* Generate a special "null" alias */ - h = (AliasHandle)NewHandle(sizeof(**h)); - if (h == NULL) - fatalbox("Failed to create fake alias"); - (*h)->userType = 'pTTY'; - (*h)->aliasSize = sizeof(**h); - } else { - error = NewAlias(NULL, &fn.fss, &h); - if (error == fnfErr) { - /* - * NewAlias can't create an alias for a nonexistent file. - * Create an alias for the directory, and record the - * filename as well. - */ - FSSpec tmpfss; - - FSMakeFSSpec(fn.fss.vRefNum, fn.fss.parID, NULL, &tmpfss); - error = NewAlias(NULL, &tmpfss, &h); - if (error != noErr) - fatalbox("Failed to create alias"); - (*h)->userType = 'pTTY'; - SetHandleSize((Handle)h, (*h)->aliasSize + fn.fss.name[0] + 1); - if (MemError() != noErr) - fatalbox("Failed to create alias"); - memcpy((char *)*h + (*h)->aliasSize, fn.fss.name, - fn.fss.name[0] + 1); - } - if (error != noErr) - fatalbox("Failed to create alias"); - } - /* Put the data in a resource. */ - id = Unique1ID(rAliasType); - if (ResError() != noErr) - fatalbox("Failed to get ID for resource %s (%d)", key, ResError()); - c2pstrcpy(pkey, key); - AddResource((Handle)h, rAliasType, id, pkey); - if (ResError() != noErr) - fatalbox("Failed to add resource %s (%d)", key, ResError()); -} - -void close_settings_r(void *handle) { - int fd; - - if (handle == NULL) return; - fd = *(int *)handle; - CloseResFile(fd); - if (ResError() != noErr) - fatalbox("Close of saved session failed (%d)", ResError()); - sfree(handle); -} - -void del_settings(char const *sessionname) { - OSErr error; - FSSpec sessfile; - short sessVRefNum; - long sessDirID; - Str255 psessionname; - - error = get_session_dir(kDontCreateFolder, &sessVRefNum, &sessDirID); - - c2pstrcpy(psessionname, sessionname); - error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &sessfile); - if (error != noErr) goto out; - - error = FSpDelete(&sessfile); - return; - out: - fatalbox("Delete session failed (%d)", error); -} - -struct enum_settings_state { - short vRefNum; - long dirID; - int index; -}; - -void *enum_settings_start(void) { - OSErr error; - struct enum_settings_state *state; - - state = snew(struct enum_settings_state); - error = get_session_dir(kDontCreateFolder, &state->vRefNum, &state->dirID); - if (error != noErr) { - sfree(state); - return NULL; - } - state->index = 1; - return state; -} - -char *enum_settings_next(void *handle, char *buffer, int buflen) { - struct enum_settings_state *e = handle; - CInfoPBRec pb; - OSErr error = noErr; - Str255 name; - - if (e == NULL) return NULL; - do { - pb.hFileInfo.ioNamePtr = name; - pb.hFileInfo.ioVRefNum = e->vRefNum; - pb.hFileInfo.ioDirID = e->dirID; - pb.hFileInfo.ioFDirIndex = e->index++; - error = PBGetCatInfoSync(&pb); - if (error != noErr) return NULL; - } while (!((pb.hFileInfo.ioFlAttrib & ioDirMask) == 0 && - pb.hFileInfo.ioFlFndrInfo.fdCreator == PUTTY_CREATOR && - pb.hFileInfo.ioFlFndrInfo.fdType == SESS_TYPE && - name[0] < buflen)); - - p2cstrcpy(buffer, name); - return buffer; -} - -void enum_settings_finish(void *handle) { - - safefree(handle); -} - -#define SEED_SIZE 512 - -void read_random_seed(noise_consumer_t consumer) -{ - short puttyVRefNum; - long puttyDirID; - OSErr error; - char buf[SEED_SIZE]; - short refnum; - long count = SEED_SIZE; - - if (get_putty_dir(kDontCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) - return; - if (HOpenDF(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", fsRdPerm, - &refnum) != noErr) - return; - error = FSRead(refnum, &count, buf); - if (error != noErr && error != eofErr) - return; - (*consumer)(buf, count); - FSClose(refnum); -} - -/* - * We don't bother with the usual FSpExchangeFiles dance here because - * it doesn't really matter if the old random seed gets lost. - */ -void write_random_seed(void *data, int len) -{ - short puttyVRefNum; - long puttyDirID; - OSErr error; - FSSpec dstfile; - short refnum; - long count = len; - - if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) - return; - - error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", - &dstfile); - if (error == fnfErr) { - /* Set up standard resources */ - FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman); - refnum = FSpOpenResFile(&dstfile, fsWrPerm); - if (ResError() == noErr) { - copy_resource('STR ', -16397); - CloseResFile(refnum); - } - } else if (error != noErr) return; - - if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return; - FSWrite(refnum, &count, data); - FSClose(refnum); - - return; -} - -/* - * This host key cache uses a file in the PuTTY Preferences folder and - * stores keys as individual TEXT resources in the resource fork of - * that file. This has two problems. Firstly, a resource fork can - * contain no more than 2727 resources. Secondly, the Resource - * Manager uses a linear search to find a particular resource, which - * could make having lots of host keys quite slow. - */ - -int verify_host_key(const char *hostname, int port, - const char *keytype, const char *key) -{ - short puttyVRefNum; - long puttyDirID; - OSErr error; - FSSpec keyfile; - short refnum; - char *resname; - Str255 presname; - char *resvalue; - Handle reshandle; - int len, compare; - - if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) - return 1; - - error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pSSH Host Keys", - &keyfile); - if (error == fnfErr) { - /* Keys file doesn't exist yet, so we can't match the key */ - return 1; - } - - refnum = FSpOpenResFile(&keyfile, fsRdPerm); - - if (refnum == -1) { - /* We couldn't open the resource fork, so we can't match the key */ - return 1; - } - - UseResFile(refnum); - - resname = dupprintf("%s@%d:%s", keytype, port, hostname); - c2pstrcpy(presname, resname); - reshandle = Get1NamedResource(FOUR_CHAR_CODE('TEXT'), presname); - if (ResError() != noErr) { - /* Couldn't open the specific resource */ - return 1; - } - - len = GetHandleSize(reshandle); - resvalue = snewn(len+1, char); - memcpy(resvalue, *reshandle, len); - resvalue[len]='\0'; - ReleaseResource(reshandle); - CloseResFile(refnum); - - compare = strncmp(resvalue, key, strlen(resvalue)); - sfree(resname); - sfree(resvalue); - - if (compare) { - /* Key different */ - return 2; - } else { - /* Key matched */ - return 0; - } -} - -void store_host_key(const char *hostname, int port, - const char *keytype, const char *key) -{ - short puttyVRefNum; - long puttyDirID; - OSErr error; - FSSpec keyfile; - short keyrefnum; - char *resname; - Str255 presname; - Handle resvalue; - Handle reshandle; - int id; - - /* Open the host key file */ - - if (get_putty_dir(~kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) - goto out; - - error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pSSH Host Keys", - &keyfile); - if (error == fnfErr) { - /* It doesn't exist, so create it */ - FSpCreateResFile(&keyfile, INTERNAL_CREATOR, HKYS_TYPE, smRoman); - keyrefnum = FSpOpenResFile(&keyfile, fsWrPerm); - if (ResError() == noErr) { - copy_resource('STR', -16397); /* XXX: wtf is this? */ - CloseResFile(keyrefnum); - } - } else if (error != noErr) goto out; - - keyrefnum = FSpOpenResFile(&keyfile, fsWrPerm); - if (keyrefnum == -1) goto out; - - UseResFile(keyrefnum); - resname = dupprintf("%s@%d:%s", keytype, port, hostname); - c2pstrcpy(presname, resname); - - reshandle = Get1NamedResource(FOUR_CHAR_CODE('TEXT'), presname); - if (reshandle != NULL) { - /* The resource exists, we're replacing a host key */ - RemoveResource(reshandle); - } - error = PtrToHand(key, &resvalue, strlen(key)); - if (error != noErr) goto out; - - id = Unique1ID(FOUR_CHAR_CODE('TEXT')); - if (ResError() != noErr) goto out; - AddResource(resvalue, FOUR_CHAR_CODE('TEXT'), id, presname); - if (ResError() != noErr) goto out; - - CloseResFile(keyrefnum); - return; - - out: - fatalbox("Writing host key failed (%d)", error); - sfree(resname); -} - -/* - * Emacs magic: - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/macstuff.h b/mac/macstuff.h deleted file mode 100644 index 796515b4..00000000 --- a/mac/macstuff.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * macstuff.h -- Mac-specific definitions visible to the rest of PuTTY. - */ - -typedef void *Context; /* FIXME */ - -#include -#include - -#include -#include "charset.h" - -struct Filename { - FSSpec fss; -}; - -extern FILE * f_open(struct Filename, char const *, int); - -/* Suspiciously similar to an ICFontRecord */ -struct FontSpec { - short size; - Style face; - char pad; - Str255 name; -}; - -/* - * On the Mac, Unicode text copied to the clipboard has U+2028 line separators. - * Non-Unicode text will have these converted to CR along with the rest of the - * content. - */ -#define SEL_NL { 0x2028 } - -#include -#include /* Timing related goo */ - -#define GETTICKCOUNT TickCount -#define CURSORBLINK GetCaretTime() -#define TICKSPERSEC 60 - -#define DEFAULT_CODEPAGE 0 /* FIXME: no idea how to do this */ - -#define WCHAR wchar_t -#define BYTE UInt8 -#define DWORD UInt32 - -typedef UInt32 uint32; -#define PUTTY_UINT32_DEFINED - -#define OPTIMISE_SCROLL - -/* - * sk_getxdmdata() does not exist under the Mac (SGT: I have no - * idea whatsoever how to write it, and furthermore I'm unconvinced - * it's necessary), so it's a macro which always returns NULL. - */ -#define sk_getxdmdata(socket, lenp) (NULL) - -/* To make it compile */ - -#include -extern int vsnprintf(char *, size_t, char const *, va_list); - -extern int stricmp(char const *, char const *); -extern int strnicmp(char const *, char const *, size_t); - -#define HELPCTX(foo) I(0) - -#define FILTER_KEY_FILES "pAgt.PPK" - -#define CP_UTF8 CS_UTF8 /* from libcharset */ - diff --git a/mac/macterm.c b/mac/macterm.c deleted file mode 100644 index 4a75a0c6..00000000 --- a/mac/macterm.c +++ /dev/null @@ -1,1908 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 1999 Simon Tatham - * Copyright (c) 1999, 2002 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ - -/* - * macterm.c -- Macintosh terminal front-end - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "macresid.h" -#include "putty.h" -#include "charset.h" -#include "mac.h" -#include "terminal.h" - -#define DEFAULT_FG 256 -#define DEFAULT_FG_BOLD 257 -#define DEFAULT_BG 258 -#define DEFAULT_BG_BOLD 259 -#define CURSOR_FG 260 -#define CURSOR_BG 261 - -#define PTOCC(x) ((x) < 0 ? -(-(x - s->font_width - 1) / s->font_width) : \ - (x) / s->font_width) -#define PTOCR(y) ((y) < 0 ? -(-(y - s->font_height - 1) / s->font_height) : \ - (y) / s->font_height) - -static void mac_initfont(Session *); -static pascal OSStatus uni_to_font_fallback(UniChar *, ByteCount, ByteCount *, - TextPtr, ByteCount, ByteCount *, - LogicalAddress, - ConstUnicodeMappingPtr); -static void mac_initpalette(Session *); -static void mac_adjustwinbg(Session *); -static void mac_adjustsize(Session *, int, int); -static void mac_drawgrowicon(Session *s); -static pascal void mac_growtermdraghook(void); -static pascal void mac_scrolltracker(ControlHandle, short); -static pascal void do_text_for_device(short, short, GDHandle, long); -static void do_text_internal(Context, int, int, wchar_t *, int, - unsigned long, int); -static void text_click(Session *, EventRecord *); -static void mac_activateterm(WindowPtr, EventRecord *); -static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); -static void mac_adjusttermmenus(WindowPtr); -static void mac_updateterm(WindowPtr); -static void mac_clickterm(WindowPtr, EventRecord *); -static void mac_growterm(WindowPtr, EventRecord *); -static void mac_keyterm(WindowPtr, EventRecord *); -static void mac_menuterm(WindowPtr, short, short); -static void mac_closeterm(WindowPtr); - -void pre_paint(Session *s); -void post_paint(Session *s); - -void mac_startsession(Session *s) -{ - const char *errmsg; - int i; - WinInfo *wi; - - init_ucs(s); - - /* - * Select protocol. This is farmed out into a table in a - * separate file to enable an ssh-free variant. - */ - s->back = backend_from_proto(s->cfg.protocol); - if (s->back == NULL) - fatalbox("Unsupported protocol number found"); - - /* XXX: Own storage management? */ - if (HAVE_COLOR_QD()) - s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); - else - s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1); - wi = snew(WinInfo); - memset(wi, 0, sizeof(*wi)); - wi->s = s; - wi->wtype = wTerminal; - wi->activate = &mac_activateterm; - wi->adjustcursor = &mac_adjusttermcursor; - wi->adjustmenus = &mac_adjusttermmenus; - wi->update = &mac_updateterm; - wi->click = &mac_clickterm; - wi->grow = &mac_growterm; - wi->key = &mac_keyterm; - wi->menu = &mac_menuterm; - wi->close = &mac_closeterm; - SetWRefCon(s->window, (long)wi); - s->scrollbar = GetNewControl(cVScroll, s->window); - s->term = term_init(&s->cfg, &s->ucsdata, s); - - mac_initfont(s); - mac_initpalette(s); - if (HAVE_COLOR_QD()) { - /* Set to FALSE to not get palette updates in the background. */ - SetPalette(s->window, s->palette, TRUE); - ActivatePalette(s->window); - } - - s->logctx = log_init(s->term, &s->cfg); - term_provide_logctx(s->term, s->logctx); - - errmsg = s->back->init(s, &s->backhandle, &s->cfg, s->cfg.host, - s->cfg.port, &s->realhost, s->cfg.tcp_nodelay, - s->cfg.tcp_keepalives); - if (errmsg != NULL) - fatalbox("%s", errmsg); - s->back->provide_logctx(s->backhandle, s->logctx); - set_title(s, s->realhost); - - term_provide_resize_fn(s->term, s->back->size, s->backhandle); - - mac_adjustsize(s, s->cfg.height, s->cfg.width); - term_size(s->term, s->cfg.height, s->cfg.width, s->cfg.savelines); - - s->ldisc = ldisc_create(&s->cfg, s->term, s->back, s->backhandle, s); - ldisc_send(s->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */ - - ShowWindow(s->window); - s->next = sesslist; - s->prev = &sesslist; - if (s->next != NULL) - s->next->prev = &s->next; - sesslist = s; -} - -/* - * Try to work out a horizontal scaling factor for the current font - * that will give a chracter width of wantwidth. Return it in numer - * and denom (suitable for passing to StdText()). - */ -static void mac_workoutfontscale(Session *s, int wantwidth, - Point *numerp, Point *denomp) -{ - Point numer, denom, tmpnumer, tmpdenom; - int gotwidth, i; - const char text = 'W'; - FontInfo fi; -#if TARGET_API_MAC_CARBON - CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(s->window)); -#else - QDProcsPtr gp = s->window->grafProcs; -#endif - - numer.v = denom.v = 1; /* always */ - numer.h = denom.h = 1; - for (i = 0; i < 3; i++) { - tmpnumer = numer; - tmpdenom = denom; - if (gp != NULL) - gotwidth = InvokeQDTxMeasUPP(1, &text, &tmpnumer, &tmpdenom, &fi, - gp->txMeasProc); - else - gotwidth = StdTxMeas(1, &text, &tmpnumer, &tmpdenom, &fi); - /* The result of StdTxMeas must be scaled by the factors it returns. */ - gotwidth = FixRound(FixMul(gotwidth << 16, - FixRatio(tmpnumer.h, tmpdenom.h))); - if (gotwidth == wantwidth) - break; - numer.h *= wantwidth; - denom.h *= gotwidth; - } - *numerp = numer; - *denomp = denom; -} - -static UnicodeToTextFallbackUPP uni_to_font_fallback_upp; - -static void mac_initfont(Session *s) -{ - FontInfo fi; - TextEncoding enc; - OptionBits fbflags; - - SetPort((GrafPtr)GetWindowPort(s->window)); - GetFNum(s->cfg.font.name, &s->fontnum); - TextFont(s->fontnum); - TextFace(s->cfg.font.face); - TextSize(s->cfg.font.size); - GetFontInfo(&fi); - s->font_width = CharWidth('W'); /* Well, it's what NCSA uses. */ - s->font_ascent = fi.ascent; - s->font_leading = fi.leading; - s->font_height = s->font_ascent + fi.descent + s->font_leading; - mac_workoutfontscale(s, s->font_width, - &s->font_stdnumer, &s->font_stddenom); - mac_workoutfontscale(s, s->font_width * 2, - &s->font_widenumer, &s->font_widedenom); - TextSize(s->cfg.font.size * 2); - mac_workoutfontscale(s, s->font_width * 2, - &s->font_bignumer, &s->font_bigdenom); - TextSize(s->cfg.font.size); - if (!s->cfg.bold_colour) { - TextFace(bold); - s->font_boldadjust = s->font_width - CharWidth('W'); - } else - s->font_boldadjust = 0; - - if (s->uni_to_font != NULL) - DisposeUnicodeToTextInfo(&s->uni_to_font); - if (mac_gestalts.encvvers != 0 && - UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, - kTextLanguageDontCare, - kTextRegionDontCare, s->cfg.font.name, - &enc) == noErr && - CreateUnicodeToTextInfoByEncoding(enc, &s->uni_to_font) == noErr) { - if (uni_to_font_fallback_upp == NULL) - uni_to_font_fallback_upp = - NewUnicodeToTextFallbackUPP(&uni_to_font_fallback); - fbflags = kUnicodeFallbackCustomOnly; - if (mac_gestalts.uncvattr & kTECAddFallbackInterruptMask) - fbflags |= kUnicodeFallbackInterruptSafeMask; - if (SetFallbackUnicodeToText(s->uni_to_font, - uni_to_font_fallback_upp, fbflags, NULL) != noErr) { - DisposeUnicodeToTextInfo(&s->uni_to_font); - goto no_encv; - } - } else { - char cfontname[256]; - - no_encv: - s->uni_to_font = NULL; - p2cstrcpy(cfontname, s->cfg.font.name); - s->font_charset = - charset_from_macenc(FontToScript(s->fontnum), - GetScriptManagerVariable(smRegionCode), - mac_gestalts.sysvers, cfontname); - } - - mac_adjustsize(s, s->term->rows, s->term->cols); -} - -static pascal OSStatus uni_to_font_fallback(UniChar *ucp, - ByteCount ilen, ByteCount *iusedp, TextPtr obuf, ByteCount olen, - ByteCount *ousedp, LogicalAddress cookie, ConstUnicodeMappingPtr mapping) -{ - - if (olen < 1) - return kTECOutputBufferFullStatus; - /* - * What I'd _like_ to do here is to somehow generate the - * missing-character glyph that every font is required to have. - * Unfortunately (and somewhat surprisingly), I can't find any way - * to actually ask for it explicitly. Bah. - */ - *obuf = '.'; - *iusedp = ilen; - *ousedp = 1; - return noErr; -} - -/* - * To be called whenever the window size changes. - * rows and cols should be desired values. - * It's assumed the terminal emulator will be informed, and will set rows - * and cols for us. - */ -static void mac_adjustsize(Session *s, int newrows, int newcols) { - int winwidth, winheight; - int extraforscroll; - - extraforscroll=s->cfg.scrollbar ? 15 : 0; - winwidth = newcols * s->font_width + extraforscroll; - winheight = newrows * s->font_height; - SizeWindow(s->window, winwidth, winheight, true); - if (s->cfg.scrollbar) { - HideControl(s->scrollbar); - MoveControl(s->scrollbar, winwidth - extraforscroll, -1); - SizeControl(s->scrollbar, extraforscroll + 1, winheight - 13); - ShowControl(s->scrollbar); - } - mac_drawgrowicon(s); -} - -static void mac_initpalette(Session *s) -{ - - if (!HAVE_COLOR_QD()) - return; - /* - * Most colours should be inhibited on 2bpp displays. - * Palette manager documentation suggests inhibiting all tolerant colours - * on greyscale displays. - */ -#define PM_NORMAL ( pmTolerant | pmInhibitC2 | \ - pmInhibitG2 | pmInhibitG4 | pmInhibitG8 ) -#define PM_TOLERANCE 0x2000 - s->palette = NewPalette(262, NULL, PM_NORMAL, PM_TOLERANCE); - if (s->palette == NULL) - fatalbox("Unable to create palette"); - /* In 2bpp, these are the colours we want most. */ - SetEntryUsage(s->palette, DEFAULT_BG, - PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE); - SetEntryUsage(s->palette, DEFAULT_FG, - PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE); - SetEntryUsage(s->palette, DEFAULT_FG_BOLD, - PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE); - SetEntryUsage(s->palette, CURSOR_BG, - PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE); - palette_reset(s); -} - -/* - * Set the background colour of the window correctly. Should be - * called whenever the default background changes. - */ -static void mac_adjustwinbg(Session *s) -{ - - if (!HAVE_COLOR_QD()) - return; -#if !TARGET_CPU_68K - if (mac_gestalts.windattr & gestaltWindowMgrPresent) - SetWindowContentColor(s->window, - &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB); - else -#endif - { -#if !TARGET_API_MAC_CARBON - if (s->wctab == NULL) - s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab)); - if (s->wctab == NULL) - return; /* do without */ - (*s->wctab)->wCSeed = 0; - (*s->wctab)->wCReserved = 0; - (*s->wctab)->ctSize = 0; - (*s->wctab)->ctTable[0].value = wContentColor; - (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB; - SetWinColor(s->window, s->wctab); -#endif - } -} - -/* - * Set the cursor shape correctly - */ -static void mac_adjusttermcursor(WindowPtr window, Point mouse, - RgnHandle cursrgn) -{ - Session *s; - ControlHandle control; - short part; - int x, y; -#if TARGET_API_MAC_CARBON - Cursor arrow; - Rect rect; - RgnHandle visrgn; -#endif - - SetPort((GrafPtr)GetWindowPort(window)); - s = mac_windowsession(window); - GlobalToLocal(&mouse); - part = FindControl(mouse, window, &control); - if (control == s->scrollbar) { -#if TARGET_API_MAC_CARBON - SetCursor(GetQDGlobalsArrow(&arrow)); - RectRgn(cursrgn, GetControlBounds(s->scrollbar, &rect)); -#else - SetCursor(&qd.arrow); - RectRgn(cursrgn, &(*s->scrollbar)->contrlRect); -#endif - } else { - x = mouse.h / s->font_width; - y = mouse.v / s->font_height; - if (s->raw_mouse) { -#if TARGET_API_MAC_CARBON - SetCursor(GetQDGlobalsArrow(&arrow)); -#else - SetCursor(&qd.arrow); -#endif - } else - SetCursor(*GetCursor(iBeamCursor)); - /* Ask for shape changes if we leave this character cell. */ - SetRectRgn(cursrgn, x * s->font_width, y * s->font_height, - (x + 1) * s->font_width, (y + 1) * s->font_height); - } -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), visrgn); - SectRgn(cursrgn, visrgn, cursrgn); - DisposeRgn(visrgn); -#else - SectRgn(cursrgn, window->visRgn, cursrgn); -#endif -} - -/* - * Enable/disable menu items based on the active terminal window. - */ -#if TARGET_API_MAC_CARBON -#define DisableItem DisableMenuItem -#define EnableItem EnableMenuItem -#endif -static void mac_adjusttermmenus(WindowPtr window) -{ - Session *s; - MenuHandle menu; -#if !TARGET_API_MAC_CARBON - long offset; -#endif - - s = mac_windowsession(window); - menu = GetMenuHandle(mFile); - DisableItem(menu, iSave); /* XXX enable if modified */ - EnableItem(menu, iSaveAs); - EnableItem(menu, iChange); - EnableItem(menu, iDuplicate); - menu = GetMenuHandle(mEdit); - EnableItem(menu, 0); - DisableItem(menu, iUndo); - DisableItem(menu, iCut); - if (1/*s->term->selstate == SELECTED*/) - EnableItem(menu, iCopy); - else - DisableItem(menu, iCopy); -#if TARGET_API_MAC_CARBON - if (1) -#else - if (GetScrap(NULL, kScrapFlavorTypeText, &offset) == noTypeErr) -#endif - DisableItem(menu, iPaste); - else - EnableItem(menu, iPaste); - DisableItem(menu, iClear); - EnableItem(menu, iSelectAll); - menu = GetMenuHandle(mWindow); - EnableItem(menu, 0); - EnableItem(menu, iShowEventLog); -} - -static void mac_menuterm(WindowPtr window, short menu, short item) -{ - Session *s; - - s = mac_windowsession(window); - switch (menu) { - case mEdit: - switch (item) { - case iCopy: - /* term_copy(s); */ - break; - case iPaste: - term_do_paste(s->term); - break; - } - break; - case mWindow: - switch(item) { - case iShowEventLog: - mac_showeventlog(s); - break; - } - break; - } -} - -static void mac_clickterm(WindowPtr window, EventRecord *event) -{ - Session *s; - Point mouse; - ControlHandle control; - int part; - static ControlActionUPP mac_scrolltracker_upp = NULL; - - s = mac_windowsession(window); - SetPort((GrafPtr)GetWindowPort(window)); - mouse = event->where; - GlobalToLocal(&mouse); - part = FindControl(mouse, window, &control); - if (control == s->scrollbar) { - switch (part) { - case kControlIndicatorPart: - if (TrackControl(control, mouse, NULL) == kControlIndicatorPart) - term_scroll(s->term, +1, GetControlValue(control)); - break; - case kControlUpButtonPart: - case kControlDownButtonPart: - case kControlPageUpPart: - case kControlPageDownPart: - if (mac_scrolltracker_upp == NULL) - mac_scrolltracker_upp = - NewControlActionUPP(&mac_scrolltracker); - TrackControl(control, mouse, mac_scrolltracker_upp); - break; - } - } else { - text_click(s, event); - } -} - -static void text_click(Session *s, EventRecord *event) -{ - Point localwhere; - int row, col; - static UInt32 lastwhen = 0; - static Session *lastsess = NULL; - static int lastrow = -1, lastcol = -1; - static Mouse_Action lastact = MA_NOTHING; - - SetPort((GrafPtr)GetWindowPort(s->window)); - localwhere = event->where; - GlobalToLocal(&localwhere); - - col = PTOCC(localwhere.h); - row = PTOCR(localwhere.v); - if (event->when - lastwhen < GetDblTime() && - row == lastrow && col == lastcol && s == lastsess) - lastact = (lastact == MA_CLICK ? MA_2CLK : - lastact == MA_2CLK ? MA_3CLK : - lastact == MA_3CLK ? MA_CLICK : MA_NOTHING); - else - lastact = MA_CLICK; - term_mouse(s->term, MBT_LEFT, - event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT, - lastact, col, row, event->modifiers & shiftKey, - event->modifiers & controlKey, event->modifiers & optionKey); - lastsess = s; - lastrow = row; - lastcol = col; - while (StillDown()) { - GetMouse(&localwhere); - col = PTOCC(localwhere.h); - row = PTOCR(localwhere.v); - term_mouse(s->term, MBT_LEFT, - event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT, - MA_DRAG, col, row, event->modifiers & shiftKey, - event->modifiers & controlKey, - event->modifiers & optionKey); - if (row > s->term->rows - 1) - term_scroll(s->term, 0, row - (s->term->rows - 1)); - else if (row < 0) - term_scroll(s->term, 0, row); - } - term_mouse(s->term, MBT_LEFT, - event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT, - MA_RELEASE, col, row, event->modifiers & shiftKey, - event->modifiers & controlKey, event->modifiers & optionKey); - lastwhen = TickCount(); -} - -void write_clip(void *cookie, wchar_t *data, int *attr, int len, int must_deselect) -{ -#if !TARGET_API_MAC_CARBON - Session *s = cookie; - char *mactextbuf; - ByteCount iread, olen; - wchar_t *unitextptr; - StScrpRec *stsc; - size_t stsz; - OSErr err; - int i; - - /* - * See "Programming with the Text Encoding Conversion Manager" - * Appendix E for Unicode scrap conventions. - * - * XXX Maybe PICT scrap too. - */ - if (ZeroScrap() != noErr) - return; - PutScrap(len * sizeof(*data), kScrapFlavorTypeUnicode, data); - - /* Replace LINE SEPARATORs with CR for TEXT output. */ - for (i = 0; i < len; i++) - if (data[i] == 0x2028) - data[i] = 0x000d; - - mactextbuf = snewn(len, char); /* XXX DBCS */ - if (s->uni_to_font != NULL) { - err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar), - (UniChar *)data, - kUnicodeUseFallbacksMask, - 0, NULL, NULL, NULL, - len, &iread, &olen, mactextbuf); - if (err != noErr && err != kTECUsedFallbacksStatus) - return; - } else if (s->font_charset != CS_NONE) { - unitextptr = data; - olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024, - s->font_charset, NULL, ".", 1); - } else - return; - PutScrap(olen, kScrapFlavorTypeText, mactextbuf); - sfree(mactextbuf); - - stsz = offsetof(StScrpRec, scrpStyleTab) + sizeof(ScrpSTElement); - stsc = smalloc(stsz); - stsc->scrpNStyles = 1; - stsc->scrpStyleTab[0].scrpStartChar = 0; - stsc->scrpStyleTab[0].scrpHeight = s->font_height; - stsc->scrpStyleTab[0].scrpAscent = s->font_ascent; - stsc->scrpStyleTab[0].scrpFont = s->fontnum; - stsc->scrpStyleTab[0].scrpFace = 0; - stsc->scrpStyleTab[0].scrpSize = s->cfg.font.size; - stsc->scrpStyleTab[0].scrpColor.red = 0; - stsc->scrpStyleTab[0].scrpColor.green = 0; - stsc->scrpStyleTab[0].scrpColor.blue = 0; - PutScrap(stsz, kScrapFlavorTypeTextStyle, stsc); - sfree(stsc); -#endif -} - -void get_clip(void *frontend, wchar_t **p, int *lenp) -{ -#if TARGET_API_MAC_CARBON - *lenp = 0; -#else - Session *s = frontend; - static Handle h = NULL; - static wchar_t *data = NULL; - Handle texth; - long offset; - int textlen; - TextEncoding enc; - TextToUnicodeInfo scrap_to_uni; - ByteCount iread, olen; - int charset; - char *tptr; - OSErr err; - - if (p == NULL) { - /* release memory */ - if (h != NULL) - DisposeHandle(h); - h = NULL; - if (data != NULL) - sfree(data); - data = NULL; - } else { - if (GetScrap(NULL, kScrapFlavorTypeUnicode, &offset) > 0) { - if (h == NULL) - h = NewHandle(0); - *lenp = - GetScrap(h, kScrapFlavorTypeUnicode, &offset) / sizeof(**p); - HLock(h); - *p = (wchar_t *)*h; - } else if (GetScrap(NULL, kScrapFlavorTypeText, &offset) > 0) { - texth = NewHandle(0); - textlen = GetScrap(texth, kScrapFlavorTypeText, &offset); - HLock(texth); - data = snewn(textlen, wchar_t); - /* XXX should use 'styl' scrap if it's there. */ - if (mac_gestalts.encvvers != 0 && - UpgradeScriptInfoToTextEncoding(smSystemScript, - kTextLanguageDontCare, - kTextRegionDontCare, NULL, - &enc) == noErr && - CreateTextToUnicodeInfoByEncoding(enc, &scrap_to_uni) == - noErr) { - err = ConvertFromTextToUnicode(scrap_to_uni, textlen, - *texth, 0, 0, NULL, NULL, NULL, - textlen * 2, - &iread, &olen, data); - DisposeTextToUnicodeInfo(&scrap_to_uni); - if (err == noErr) { - *p = data; - *lenp = olen / sizeof(**p); - } else { - *p = NULL; - *lenp = 0; - } - } else { - charset = - charset_from_macenc(GetScriptManagerVariable(smSysScript), - GetScriptManagerVariable(smRegionCode), - mac_gestalts.sysvers, NULL); - if (charset != CS_NONE) { - tptr = *texth; - *lenp = charset_to_unicode(&tptr, &textlen, data, - textlen * 2, charset, NULL, - NULL, 0); - } - *p = data; - } - DisposeHandle(texth); - } else { - *p = NULL; - *lenp = 0; - } - } -#endif -} - -static pascal void mac_scrolltracker(ControlHandle control, short part) -{ - Session *s; - -#if TARGET_API_MAC_CARBON - s = mac_windowsession(GetControlOwner(control)); -#else - s = mac_windowsession((*control)->contrlOwner); -#endif - switch (part) { - case kControlUpButtonPart: - term_scroll(s->term, 0, -1); - break; - case kControlDownButtonPart: - term_scroll(s->term, 0, +1); - break; - case kControlPageUpPart: - term_scroll(s->term, 0, -(s->term->rows - 1)); - break; - case kControlPageDownPart: - term_scroll(s->term, 0, +(s->term->rows - 1)); - break; - } -} - -static void mac_keyterm(WindowPtr window, EventRecord *event) -{ - Session *s = mac_windowsession(window); - Key_Sym keysym = PK_NULL; - unsigned int mods = 0, flags = PKF_NUMLOCK; - UniChar utxt[1]; - char txt[1]; - size_t len = 0; - ScriptCode key_script; - - ObscureCursor(); - -#if 0 - fprintf(stderr, "Got key event %08x\n", event->message); -#endif - - /* No meta key yet -- that'll be rather fun. */ - - /* Keys that we handle locally */ - if (event->modifiers & shiftKey) { - switch ((event->message & keyCodeMask) >> 8) { - case 0x74: /* shift-pageup */ - term_scroll(s->term, 0, -(s->term->rows - 1)); - return; - case 0x79: /* shift-pagedown */ - term_scroll(s->term, 0, +(s->term->rows - 1)); - return; - } - } - - if (event->modifiers & shiftKey) - mods |= PKM_SHIFT; - if (event->modifiers & controlKey) - mods |= PKM_CONTROL; - if (event->what == autoKey) - flags |= PKF_REPEAT; - - /* Mac key events consist of a virtual key code and a character code. */ - - switch ((event->message & keyCodeMask) >> 8) { - case 0x24: keysym = PK_RETURN; break; - case 0x30: keysym = PK_TAB; break; - case 0x33: keysym = PK_BACKSPACE; break; - case 0x35: keysym = PK_ESCAPE; break; - - case 0x7A: keysym = PK_F1; break; - case 0x78: keysym = PK_F2; break; - case 0x63: keysym = PK_F3; break; - case 0x76: keysym = PK_F4; break; - case 0x60: keysym = PK_F5; break; - case 0x61: keysym = PK_F6; break; - case 0x62: keysym = PK_F7; break; - case 0x64: keysym = PK_F8; break; - case 0x65: keysym = PK_F9; break; - case 0x6D: keysym = PK_F10; break; - case 0x67: keysym = PK_F11; break; - case 0x6F: keysym = PK_F12; break; - case 0x69: keysym = PK_F13; break; - case 0x6B: keysym = PK_F14; break; - case 0x71: keysym = PK_F15; break; - - case 0x72: keysym = PK_INSERT; break; - case 0x73: keysym = PK_HOME; break; - case 0x74: keysym = PK_PAGEUP; break; - case 0x75: keysym = PK_DELETE; break; - case 0x77: keysym = PK_END; break; - case 0x79: keysym = PK_PAGEDOWN; break; - - case 0x47: keysym = PK_PF1; break; - case 0x51: keysym = PK_PF2; break; - case 0x4B: keysym = PK_PF3; break; - case 0x43: keysym = PK_PF4; break; - case 0x4E: keysym = PK_KPMINUS; break; - case 0x45: keysym = PK_KPCOMMA; break; - case 0x41: keysym = PK_KPDECIMAL; break; - case 0x4C: keysym = PK_KPENTER; break; - case 0x52: keysym = PK_KP0; break; - case 0x53: keysym = PK_KP1; break; - case 0x54: keysym = PK_KP2; break; - case 0x55: keysym = PK_KP3; break; - case 0x56: keysym = PK_KP4; break; - case 0x57: keysym = PK_KP5; break; - case 0x58: keysym = PK_KP6; break; - case 0x59: keysym = PK_KP7; break; - case 0x5B: keysym = PK_KP8; break; - case 0x5C: keysym = PK_KP9; break; - - case 0x7B: keysym = PK_LEFT; break; - case 0x7C: keysym = PK_RIGHT; break; - case 0x7D: keysym = PK_DOWN; break; - case 0x7E: keysym = PK_UP; break; - } - - /* Map from key script to Unicode. */ - txt[0] = event->message & charCodeMask; - key_script = GetScriptManagerVariable(smKeyScript); - - if (mac_gestalts.encvvers != 0) { - static TextToUnicodeInfo key_to_uni = NULL; - static ScriptCode key_to_uni_script; - TextEncoding enc; - ByteCount iread, olen; - OSErr err; - - if (key_to_uni != NULL && key_to_uni_script != key_script) - DisposeTextToUnicodeInfo(&key_to_uni); - if (key_to_uni == NULL || key_to_uni_script != key_script) { - if (UpgradeScriptInfoToTextEncoding(key_script, - kTextLanguageDontCare, - kTextRegionDontCare, NULL, - &enc) == noErr && - CreateTextToUnicodeInfoByEncoding(enc, &key_to_uni) == noErr) - key_to_uni_script = key_script; - else - key_to_uni = NULL; - } - if (key_to_uni != NULL) { - err = ConvertFromTextToUnicode(key_to_uni, 1, txt, - (kUnicodeKeepInfoMask | - kUnicodeStringUnterminatedMask), - 0, NULL, NULL, NULL, - sizeof(utxt), &iread, &olen, utxt); - if (err == noErr) - len = olen / sizeof(*utxt); - } - } else { - int charset; - char *tptr = txt; - int tlen = 1; - - charset = charset_from_macenc(key_script, - GetScriptManagerVariable(smRegionCode), - mac_gestalts.sysvers, NULL); - if (charset != CS_NONE) { - len = charset_to_unicode(&tptr, &tlen, utxt, sizeof(utxt), charset, - NULL, NULL, 0); - } - } - term_key(s->term, keysym, utxt, len, mods, flags); -} - -void request_paste(void *frontend) -{ - Session *s = frontend; - - /* - * In the Mac OS, pasting is synchronous: we can read the - * clipboard with no difficulty, so request_paste() can just go - * ahead and paste. - */ - term_do_paste(s->term); -} - -static struct { - Rect msgrect; - Point msgorigin; - Point zeromouse; - Session *s; - char oldmsg[20]; -} growterm_state; - -static void mac_growterm(WindowPtr window, EventRecord *event) -{ - Rect limits; - long grow_result; - int newrows, newcols; - Session *s; -#if !TARGET_API_MAC_CARBON - DragGrayRgnUPP draghooksave; - GrafPtr portsave; - FontInfo fi; -#endif - - s = mac_windowsession(window); - -#if !TARGET_API_MAC_CARBON - draghooksave = LMGetDragHook(); - growterm_state.oldmsg[0] = '\0'; - growterm_state.zeromouse = event->where; - growterm_state.zeromouse.h -= s->term->cols * s->font_width; - growterm_state.zeromouse.v -= s->term->rows * s->font_height; - growterm_state.s = s; - GetPort(&portsave); - SetPort(s->window); - BackColor(whiteColor); - ForeColor(blackColor); - TextFont(systemFont); - TextFace(0); - TextSize(12); - GetFontInfo(&fi); - SetRect(&growterm_state.msgrect, 0, 0, - StringWidth("\p99999x99999") + 4, fi.ascent + fi.descent + 4); - SetPt(&growterm_state.msgorigin, 2, fi.ascent + 2); - LMSetDragHook(NewDragGrayRgnUPP(mac_growtermdraghook)); -#endif - - SetRect(&limits, s->font_width + 15, s->font_height, SHRT_MAX, SHRT_MAX); - grow_result = GrowWindow(window, event->where, &limits); - -#if !TARGET_API_MAC_CARBON - DisposeDragGrayRgnUPP(LMGetDragHook()); - LMSetDragHook(draghooksave); - InvalRect(&growterm_state.msgrect); - - SetPort(portsave); -#endif - - if (grow_result != 0) { - newrows = HiWord(grow_result) / s->font_height; - newcols = (LoWord(grow_result) - 15) / s->font_width; - mac_adjustsize(s, newrows, newcols); - term_size(s->term, newrows, newcols, s->cfg.savelines); - s->cfg.height=s->term->rows; - s->cfg.width=s->term->cols; - } -} - -#if !TARGET_API_MAC_CARBON -static pascal void mac_growtermdraghook(void) -{ - Session *s = growterm_state.s; - GrafPtr portsave; - Point mouse; - char buf[20]; - unsigned char pbuf[20]; - int newrows, newcols; - - GetMouse(&mouse); - newrows = (mouse.v - growterm_state.zeromouse.v) / s->font_height; - if (newrows < 1) newrows = 1; - newcols = (mouse.h - growterm_state.zeromouse.h) / s->font_width; - if (newcols < 1) newcols = 1; - sprintf(buf, "%dx%d", newcols, newrows); - if (strcmp(buf, growterm_state.oldmsg) == 0) - return; - strcpy(growterm_state.oldmsg, buf); - c2pstrcpy(pbuf, buf); - - GetPort(&portsave); - SetPort(growterm_state.s->window); - EraseRect(&growterm_state.msgrect); - MoveTo(growterm_state.msgorigin.h, growterm_state.msgorigin.v); - DrawString(pbuf); - SetPort(portsave); -} -#endif - -void mac_closeterm(WindowPtr window) -{ - int alertret; - Session *s = mac_windowsession(window); - - if (s->cfg.warn_on_close && !s->session_closed) { - ParamText("\pAre you sure you want to close this session?", - NULL, NULL, NULL); - alertret=CautionAlert(wQuestion, NULL); - if (alertret == 2) { - /* Cancel */ - return; - } - } - - HideWindow(s->window); - *s->prev = s->next; - s->next->prev = s->prev; - if (s->ldisc) - ldisc_free(s->ldisc); - if (s->back) - s->back->free(s->backhandle); - log_free(s->logctx); - if (s->uni_to_font != NULL) - DisposeUnicodeToTextInfo(&s->uni_to_font); - term_free(s->term); - mac_freeeventlog(s); - sfree((WinInfo *)GetWRefCon(s->window)); - DisposeWindow(s->window); - DisposePalette(s->palette); - sfree(s); -} - -static void mac_activateterm(WindowPtr window, EventRecord *event) -{ - Session *s; - Boolean active = (event->modifiers & activeFlag) != 0; - - s = mac_windowsession(window); - term_set_focus(s->term, active); - term_update(s->term); - if (active && s->cfg.scrollbar) - ShowControl(s->scrollbar); - else { - if (HAVE_COLOR_QD()) - PmBackColor(DEFAULT_BG);/* HideControl clears behind the control */ - else - BackColor(blackColor); - HideControl(s->scrollbar); - } - mac_drawgrowicon(s); -} - -static void mac_updateterm(WindowPtr window) -{ - Session *s; - Rect bbox; -#if TARGET_API_MAC_CARBON - RgnHandle visrgn; -#endif - - s = mac_windowsession(window); - SetPort((GrafPtr)GetWindowPort(window)); - BeginUpdate(window); - pre_paint(s); -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), visrgn); - GetRegionBounds(visrgn, &bbox); -#else - bbox = (*window->visRgn)->rgnBBox; -#endif - term_paint(s->term, s, PTOCC(bbox.left), PTOCR(bbox.top), - PTOCC(bbox.right), PTOCR(bbox.bottom), 1); - /* Restore default colours in case the Window Manager uses them */ - if (HAVE_COLOR_QD()) { - PmForeColor(DEFAULT_FG); - PmBackColor(DEFAULT_BG); - } else { - ForeColor(whiteColor); - BackColor(blackColor); - } - if (FrontWindow() != window) -#if TARGET_API_MAC_CARBON - EraseRect(GetControlBounds(s->scrollbar, &bbox)); - UpdateControls(window, visrgn); - DisposeRgn(visrgn); -#else - EraseRect(&(*s->scrollbar)->contrlRect); - UpdateControls(window, window->visRgn); -#endif - mac_drawgrowicon(s); - post_paint(s); - EndUpdate(window); -} - -static void mac_drawgrowicon(Session *s) -{ - Rect clip; - RgnHandle savergn; - - SetPort((GrafPtr)GetWindowPort(s->window)); - /* - * Stop DrawGrowIcon giving us space for a horizontal scrollbar - * See Tech Note TB575 for details. - */ -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(s->window), &clip); -#else - clip = s->window->portRect; -#endif - clip.left = clip.right - 15; - savergn = NewRgn(); - GetClip(savergn); - ClipRect(&clip); - DrawGrowIcon(s->window); - SetClip(savergn); - DisposeRgn(savergn); -} - -struct do_text_args { - Session *s; - Rect textrect; - char *text; - int len; - unsigned long attr; - int lattr; - Point numer, denom; -}; - -/* - * Call from the terminal emulator to draw a bit of text - * - * x and y are text row and column (zero-based) - */ -static void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len, - unsigned long attr, int lattr) -{ - Session *s = ctx; - int style; - struct do_text_args a; - RgnHandle textrgn, saveclip; -#if TARGET_API_MAC_CARBON - RgnHandle visrgn; -#endif - char mactextbuf[1024]; - wchar_t *unitextptr; - int fontwidth; - ByteCount iread, olen; - OSStatus err; - static DeviceLoopDrawingUPP do_text_for_device_upp = NULL; - - assert(len <= 1024); - - SetPort((GrafPtr)GetWindowPort(s->window)); - - fontwidth = s->font_width; - if ((lattr & LATTR_MODE) != LATTR_NORM) - fontwidth *= 2; - - /* First check this text is relevant */ - a.textrect.top = y * s->font_height; - a.textrect.bottom = (y + 1) * s->font_height; - a.textrect.left = x * fontwidth; - a.textrect.right = (x + len) * fontwidth; - if (a.textrect.right > s->term->cols * s->font_width) - a.textrect.right = s->term->cols * s->font_width; -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(s->window), visrgn); - if (!RectInRgn(&a.textrect, visrgn)) { - DisposeRgn(visrgn); - return; - } - DisposeRgn(visrgn); -#else - if (!RectInRgn(&a.textrect, s->window->visRgn)) - return; -#endif - - if (s->uni_to_font != NULL) { - err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar), - text, kUnicodeUseFallbacksMask, - 0, NULL, NULL, NULL, - 1024, &iread, &olen, mactextbuf); - if (err != noErr && err != kTECUsedFallbacksStatus) - olen = 0; - } else if (s->font_charset != CS_NONE) { - /* XXX this is bogus if wchar_t and UniChar are different sizes. */ - unitextptr = (wchar_t *)text; - olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024, - s->font_charset, NULL, ".", 1); - } else - olen = 0; - - a.s = s; - a.text = mactextbuf; - a.len = olen; - a.attr = attr; - a.lattr = lattr; - switch (lattr & LATTR_MODE) { - case LATTR_NORM: - TextSize(s->cfg.font.size); - a.numer = s->font_stdnumer; - a.denom = s->font_stddenom; - break; - case LATTR_WIDE: - TextSize(s->cfg.font.size); - a.numer = s->font_widenumer; - a.denom = s->font_widedenom; - break; - case LATTR_TOP: - case LATTR_BOT: - TextSize(s->cfg.font.size * 2); - a.numer = s->font_bignumer; - a.denom = s->font_bigdenom; - break; - } - SetPort((GrafPtr)GetWindowPort(s->window)); - TextFont(s->fontnum); - style = s->cfg.font.face; - if ((attr & ATTR_BOLD) && !s->cfg.bold_colour) - style |= bold; - if (attr & ATTR_UNDER) - style |= underline; - TextFace(style); - TextMode(srcOr); - if (HAVE_COLOR_QD()) - if (style & bold) { - SpaceExtra(s->font_boldadjust << 16); - CharExtra(s->font_boldadjust << 16); - } else { - SpaceExtra(0); - CharExtra(0); - } - saveclip = NewRgn(); - GetClip(saveclip); - ClipRect(&a.textrect); - textrgn = NewRgn(); - RectRgn(textrgn, &a.textrect); - if (HAVE_COLOR_QD()) { - if (do_text_for_device_upp == NULL) - do_text_for_device_upp = - NewDeviceLoopDrawingUPP(&do_text_for_device); - DeviceLoop(textrgn, do_text_for_device_upp, (long)&a, 0); - } else - do_text_for_device(1, 0, NULL, (long)&a); - SetClip(saveclip); - DisposeRgn(saveclip); - DisposeRgn(textrgn); - /* Tell the window manager about it in case this isn't an update */ -#if TARGET_API_MAC_CARBON - ValidWindowRect(s->window, &a.textrect); -#else - ValidRect(&a.textrect); -#endif -} - -/* - * Wrapper that handles combining characters. - */ -void do_text(Context ctx, int x, int y, wchar_t *text, int len, - unsigned long attr, int lattr) -{ - if (attr & TATTR_COMBINING) { - unsigned long a = 0; - attr &= ~TATTR_COMBINING; - while (len--) { - do_text_internal(ctx, x, y, text, 1, attr | a, lattr); - text++; - a = TATTR_COMBINING; - } - } else - do_text_internal(ctx, x, y, text, len, attr, lattr); -} - -static pascal void do_text_for_device(short depth, short devflags, - GDHandle device, long cookie) -{ - struct do_text_args *a = (struct do_text_args *)cookie; - int bgcolour, fgcolour, bright, reverse, tmp; -#if TARGET_API_MAC_CARBON - CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(a->s->window)); -#else - QDProcsPtr gp = a->s->window->grafProcs; -#endif - - bright = (a->attr & ATTR_BOLD) && a->s->cfg.bold_colour; - reverse = a->attr & ATTR_REVERSE; - - if (depth == 1 && (a->attr & TATTR_ACTCURS)) - reverse = !reverse; - - if (HAVE_COLOR_QD()) { - if (depth > 2) { - fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT); - bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT); - } else { - /* - * NB: bold reverse in 2bpp breaks with the usual PuTTY model and - * boldens the background, because that's all we can do. - */ - fgcolour = bright ? DEFAULT_FG_BOLD : DEFAULT_FG; - bgcolour = DEFAULT_BG; - } - if (reverse) { - tmp = fgcolour; - fgcolour = bgcolour; - bgcolour = tmp; - } - if (bright && depth > 2) - if (fgcolour < 16) fgcolour |=8; - else if (fgcolour >= 256) fgcolour |=1; - if ((a->attr & TATTR_ACTCURS) && depth > 1) { - fgcolour = CURSOR_FG; - bgcolour = CURSOR_BG; - } - PmForeColor(fgcolour); - PmBackColor(bgcolour); - } else { /* No Color Quickdraw */ - /* XXX This should be done with a _little_ more configurability */ - if (reverse) { - ForeColor(blackColor); - BackColor(whiteColor); - } else { - ForeColor(whiteColor); - BackColor(blackColor); - } - } - - if (!(a->attr & TATTR_COMBINING)) - EraseRect(&a->textrect); - switch (a->lattr & LATTR_MODE) { - case LATTR_NORM: - case LATTR_WIDE: - MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent); - break; - case LATTR_TOP: - MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent * 2); - break; - case LATTR_BOT: - MoveTo(a->textrect.left, - a->textrect.top - a->s->font_height + a->s->font_ascent * 2); - break; - } - /* FIXME: Sort out bold width adjustments on Original QuickDraw. */ - if (gp != NULL) - InvokeQDTextUPP(a->len, a->text, a->numer, a->denom, gp->textProc); - else - StdText(a->len, a->text, a->numer, a->denom); - - if (a->attr & TATTR_PASCURS) { - PenNormal(); - switch (depth) { - case 1: - PenMode(patXor); - break; - default: - PmForeColor(CURSOR_BG); - break; - } - FrameRect(&a->textrect); - } -} - -void do_cursor(Context ctx, int x, int y, wchar_t *text, int len, - unsigned long attr, int lattr) -{ - - do_text(ctx, x, y, text, len, attr, lattr); -} - -/* - * Call from the terminal emulator to get its graphics context. - * Should probably be called start_redraw or something. - */ -void pre_paint(Session *s) -{ - GDHandle gdh; - Rect myrect, tmprect; -#if TARGET_API_MAC_CARBON - RgnHandle visrgn; -#endif - - if (HAVE_COLOR_QD()) { - s->term->attr_mask = 0; - SetPort((GrafPtr)GetWindowPort(s->window)); -#if TARGET_API_MAC_CARBON - visrgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(s->window), visrgn); - GetRegionBounds(visrgn, &myrect); - DisposeRgn(visrgn); -#else - myrect = (*s->window->visRgn)->rgnBBox; -#endif - LocalToGlobal((Point *)&myrect.top); - LocalToGlobal((Point *)&myrect.bottom); - for (gdh = GetDeviceList(); - gdh != NULL; - gdh = GetNextDevice(gdh)) { - if (TestDeviceAttribute(gdh, screenDevice) && - TestDeviceAttribute(gdh, screenActive) && - SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) { - switch ((*(*gdh)->gdPMap)->pixelSize) { - case 1: - if (s->cfg.bold_colour) - s->term->attr_mask |= ~(ATTR_COLOURS | - (s->cfg.bold_colour ? ATTR_BOLD : 0)); - break; - case 2: - s->term->attr_mask |= ~ATTR_COLOURS; - break; - default: - s->term->attr_mask = ~0; - return; /* No point checking more screens. */ - } - } - } - } else - s->term->attr_mask = ~(ATTR_COLOURS | - (s->cfg.bold_colour ? ATTR_BOLD : 0)); -} - -Context get_ctx(void *frontend) -{ - Session *s = frontend; - - pre_paint(s); - return s; -} - -void free_ctx(Context ctx) -{ - -} - -/* - * Presumably this does something in Windows - */ -void post_paint(Session *s) -{ - -} - -/* - * Set the scroll bar position - * - * total is the line number of the bottom of the working screen - * start is the line number of the top of the display - * page is the length of the displayed page - */ -void set_sbar(void *frontend, int total, int start, int page) -{ - Session *s = frontend; - - /* We don't redraw until we've set everything up, to avoid glitches */ - SetControlMinimum(s->scrollbar, 0); - SetControlMaximum(s->scrollbar, total - page); - SetControlValue(s->scrollbar, start); -#if !TARGET_CPU_68K - if (mac_gestalts.cntlattr & gestaltControlMgrPresent) - SetControlViewSize(s->scrollbar, page); -#endif -} - -void sys_cursor(void *frontend, int x, int y) -{ - /* - * I think his is meaningless under Mac OS. - */ -} - -/* - * This is still called when mode==BELL_VISUAL, even though the - * visual bell is handled entirely within terminal.c, because we - * may want to perform additional actions on any kind of bell (for - * example, taskbar flashing in Windows). - */ -void do_beep(void *frontend, int mode) -{ - if (mode != BELL_VISUAL) - SysBeep(30); - /* - * XXX We should indicate the relevant window and/or use the - * Notification Manager - */ -} - -int char_width(Context ctx, int uc) -{ - /* - * Until we support exciting character-set stuff, assume all chars are - * single-width. - */ - return 1; -} - -/* - * Set icon string -- a no-op here (Windowshade?) - */ -void set_icon(void *frontend, char *icon) { - Session *s = frontend; - -} - -/* - * Set the window title - */ -void set_title(void *frontend, char *title) -{ - Session *s = frontend; - Str255 mactitle; - - c2pstrcpy(mactitle, title); - SetWTitle(s->window, mactitle); -} - -/* - * Used by backend to indicate busy-ness - */ -void set_busy_status(void *frontend, int status) -{ - /* FIXME do something */ -} - -/* - * set or clear the "raw mouse message" mode - */ -void set_raw_mouse_mode(void *frontend, int activate) -{ - Session *s = frontend; - - s->raw_mouse = activate; - /* FIXME: Should call mac_updatetermcursor as appropriate. */ -} - -/* - * Resize the window at the emulator's request - */ -void request_resize(void *frontend, int w, int h) -{ - Session *s = frontend; - RgnHandle grayrgn; - Rect graybox; - int wlim, hlim; - - /* Arbitrarily clip to the size of the desktop. */ - grayrgn = GetGrayRgn(); -#if TARGET_API_MAC_CARBON - GetRegionBounds(grayrgn, &graybox); -#else - graybox = (*grayrgn)->rgnBBox; -#endif - wlim = (graybox.right - graybox.left) / s->font_width; - hlim = (graybox.bottom - graybox.top) / s->font_height; - if (w > wlim) w = wlim; - if (h > hlim) h = hlim; - term_size(s->term, h, w, s->cfg.savelines); - mac_initfont(s); -} - -/* - * Iconify (actually collapse) the window at the emulator's request. - */ -void set_iconic(void *frontend, int iconic) -{ - Session *s = frontend; - UInt32 features; - - if (mac_gestalts.apprvers >= 0x0100 && - GetWindowFeatures(s->window, &features) == noErr && - (features & kWindowCanCollapse)) - CollapseWindow(s->window, iconic); -} - -/* - * Move the window in response to a server-side request. - */ -void move_window(void *frontend, int x, int y) -{ - Session *s = frontend; - - MoveWindow(s->window, x, y, FALSE); -} - -/* - * Move the window to the top or bottom of the z-order in response - * to a server-side request. - */ -void set_zorder(void *frontend, int top) -{ - Session *s = frontend; - - /* - * We also change the input focus to point to the topmost window, - * since that's probably what the Human Interface Guidelines would - * like us to do. - */ - if (top) - SelectWindow(s->window); - else - SendBehind(s->window, NULL); -} - -/* - * Refresh the window in response to a server-side request. - */ -void refresh_window(void *frontend) -{ - Session *s = frontend; - - term_invalidate(s->term); -} - -/* - * Maximise or restore the window in response to a server-side - * request. - */ -void set_zoomed(void *frontend, int zoomed) -{ - Session *s = frontend; - - ZoomWindow(s->window, zoomed ? inZoomOut : inZoomIn, FALSE); -} - -/* - * Report whether the window is iconic, for terminal reports. - */ -int is_iconic(void *frontend) -{ - Session *s = frontend; - UInt32 features; - - if (mac_gestalts.apprvers >= 0x0100 && - GetWindowFeatures(s->window, &features) == noErr && - (features & kWindowCanCollapse)) - return IsWindowCollapsed(s->window); - return FALSE; -} - -/* - * Report the window's position, for terminal reports. - */ -void get_window_pos(void *frontend, int *x, int *y) -{ - Session *s = frontend; - Rect rect; - -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(s->window), &rect); -#else - rect = s->window->portRect; -#endif - *x = rect.left; - *y = rect.top; -} - -/* - * Report the window's pixel size, for terminal reports. - */ -void get_window_pixels(void *frontend, int *x, int *y) -{ - Session *s = frontend; - Rect rect; - -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(s->window), &rect); -#else - rect = s->window->portRect; -#endif - *x = rect.right - rect.left; - *y = rect.bottom - rect.top; -} - -/* - * Return the window or icon title. - */ -char *get_window_title(void *frontend, int icon) -{ - Session *s = frontend; - Str255 ptitle; - static char title[256]; - - GetWTitle(s->window, ptitle); - p2cstrcpy(title, ptitle); - return title; -} - -/* - * real_palette_set(): This does the actual palette-changing work on behalf - * of palette_set(). Does _not_ call ActivatePalette() in case the caller - * is doing a batch of updates. - */ -static void real_palette_set(Session *s, int n, int r, int g, int b) -{ - RGBColor col; - - if (!HAVE_COLOR_QD()) - return; - col.red = r * 0x0101; - col.green = g * 0x0101; - col.blue = b * 0x0101; - SetEntryColor(s->palette, n, &col); -} - -/* - * Set the logical palette. Called by the terminal emulator. - */ -void palette_set(void *frontend, int n, int r, int g, int b) -{ - Session *s = frontend; - - if (!HAVE_COLOR_QD()) - return; - real_palette_set(s, n, r, g, b); - if (n == DEFAULT_BG) - mac_adjustwinbg(s); - - ActivatePalette(s->window); -} - -/* - * Reset to the default palette - */ -void palette_reset(void *frontend) -{ - Session *s = frontend; - /* This maps colour indices in cfg to those used in our palette. */ - static const int ww[] = { - 256, 257, 258, 259, 260, 261, - 0, 8, 1, 9, 2, 10, 3, 11, - 4, 12, 5, 13, 6, 14, 7, 15 - }; - - int i; - - if (!HAVE_COLOR_QD()) - return; - - for (i = 0; i < 22; i++) { - int w = ww[i]; - real_palette_set(s,w, - s->cfg.colours[i][0], - s->cfg.colours[i][1], - s->cfg.colours[i][2]); - } - for (i = 0; i < 240; i++) { - if (i < 216) { - int r = i / 36, g = (i / 6) % 6, b = i % 6; - real_palette_set(s,i+16, - r * 0x33, - g * 0x33, - b * 0x33); - } else { - int shade = i - 216; - shade = (shade + 1) * 0xFF / (240 - 216 + 1); - real_palette_set(s,i+16,shade,shade,shade); - } - } - - - mac_adjustwinbg(s); - ActivatePalette(s->window); - /* Palette Manager will generate update events as required. */ -} - -/* - * Scroll the screen. (`lines' is +ve for scrolling forward, -ve - * for backward.) - */ -void do_scroll(Context ctx, int topline, int botline, int lines) -{ - Session *s = ctx; - Rect r; - RgnHandle scrollrgn = NewRgn(); - RgnHandle movedupdate = NewRgn(); - RgnHandle update = NewRgn(); - Point g2l = { 0, 0 }; - - SetPort((GrafPtr)GetWindowPort(s->window)); - - /* - * Work out the part of the update region that will scrolled by - * this operation. - */ - if (lines > 0) - SetRectRgn(scrollrgn, 0, (topline + lines) * s->font_height, - s->term->cols * s->font_width, - (botline + 1) * s->font_height); - else - SetRectRgn(scrollrgn, 0, topline * s->font_height, - s->term->cols * s->font_width, - (botline - lines + 1) * s->font_height); -#if TARGET_API_MAC_CARBON - GetWindowRegion(s->window, kWindowUpdateRgn, movedupdate); -#else - GetWindowUpdateRgn(s->window, movedupdate); -#endif - GlobalToLocal(&g2l); - OffsetRgn(movedupdate, g2l.h, g2l.v); /* Convert to local co-ords. */ - SectRgn(scrollrgn, movedupdate, movedupdate); /* Clip scrolled section. */ -#if TARGET_API_MAC_CARBON - ValidWindowRgn(s->window, movedupdate); -#else - ValidRgn(movedupdate); -#endif - OffsetRgn(movedupdate, 0, -lines * s->font_height); /* Scroll it. */ - - PenNormal(); - if (HAVE_COLOR_QD()) - PmBackColor(DEFAULT_BG); - else - BackColor(blackColor); /* XXX make configurable */ - SetRect(&r, 0, topline * s->font_height, - s->term->cols * s->font_width, (botline + 1) * s->font_height); - ScrollRect(&r, 0, - lines * s->font_height, update); - -#if TARGET_API_MAC_CARBON - InvalWindowRgn(s->window, update); - InvalWindowRgn(s->window, movedupdate); -#else - InvalRgn(update); - InvalRgn(movedupdate); -#endif - - DisposeRgn(scrollrgn); - DisposeRgn(movedupdate); - DisposeRgn(update); -} - -/* Dummy routine, only required in plink. */ -void ldisc_update(void *frontend, int echo, int edit) -{ -} - -char *get_ttymode(void *frontend, const char *mode) -{ - Session *s = frontend; - return term_get_ttymode(s->term, mode); -} - -/* - * Mac PuTTY doesn't support printing yet. - */ -printer_job *printer_start_job(char *printer) -{ - - return NULL; -} - -void printer_job_data(printer_job *pj, void *data, int len) -{ -} - -void printer_finish_job(printer_job *pj) -{ -} - -void frontend_keypress(void *handle) -{ - /* - * Keypress termination in non-Close-On-Exit mode is not - * currently supported in PuTTY proper, because the window - * always has a perfectly good Close button anyway. So we do - * nothing here. - */ - return; -} - -/* - * Ask whether to wipe a session log file before writing to it. - * Returns 2 for wipe, 1 for append, 0 for cancel (don't log). - */ -int askappend(void *frontend, Filename filename, - void (*callback)(void *ctx, int result), void *ctx) -{ - - /* FIXME: not implemented yet. */ - return 2; -} - -int from_backend(void *frontend, int is_stderr, const char *data, int len) -{ - Session *s = frontend; - - return term_data(s->term, is_stderr, data, len); -} - -int get_userpass_input(prompts_t *p, unsigned char *in, int inlen) -{ - Session *s = p->frontend; - return term_get_userpass_input(s->term, p, in, inlen); -} - -/* - * Emacs magic: - * Local Variables: - * c-file-style: "simon" - * End: - */ - diff --git a/mac/macucs.c b/mac/macucs.c deleted file mode 100644 index f2c850bb..00000000 --- a/mac/macucs.c +++ /dev/null @@ -1,139 +0,0 @@ -/* $Id$ */ - -#include -#include -#include - -#include -#include "putty.h" -#include "charset.h" -#include "terminal.h" -#include "misc.h" -#include "mac.h" - -/* - * Mac Unicode-handling routines. - * - * BJH: - * What we _should_ do is to use the Text Encoding Conversion Manager - * when it's available, and have our own routines for converting to - * standard Mac OS scripts when it's not. Support for ATSUI might be - * nice, too. - * - * I (OSD) am unsure any of the above is necessary if we just use - * libcharset */ - -/* - * Determine whether a byte is the first byte of a double-byte - * character in a system character set. Only MI use is by clipme() - * when copying direct-to-font text to the clipboard. - */ -int is_dbcs_leadbyte(int codepage, char byte) -{ - return 0; /* we don't do DBCS */ -} - -/* - * Convert from Unicode to a system character set. MI uses are: - * (1) by lpage_send(), whose only MI use is to convert the answerback - * string to Unicode, and - * (2) by clipme() when copying direct-to-font text to the clipboard. - */ -int mb_to_wc(int codepage, int flags, char *mbstr, int mblen, - wchar_t *wcstr, int wclen) -{ - int ret = 0; - while (mblen > 0 && wclen > 0) { - *wcstr++ = (unsigned char) *mbstr++; - mblen--, wclen--, ret++; - } - return ret; /* FIXME: check error codes! */ -} - -/* - * Convert from a system character set to Unicode. Used by luni_send - * to convert Unicode into the line character set. - */ -int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen, - char *mbstr, int mblen, char *defchr, int *defused, - struct unicode_data *ucsdata) -{ - int ret = 0; - if (defused) - *defused = 0; - while (mblen > 0 && wclen > 0) { - if (*wcstr >= 0x100) { - if (defchr) - *mbstr++ = *defchr; - else - *mbstr++ = '.'; - if (defused) - *defused = 1; - } else - *mbstr++ = (unsigned char) *wcstr; - wcstr++; - mblen--, wclen--, ret++; - } - return ret; /* FIXME: check error codes! */ -} - -/* Character conversion array, - * the xterm one has the four scanlines that have no unicode 2.0 - * equivalents mapped to their unicode 3.0 locations. - */ -static const wchar_t unitab_xterm_std[32] = { - 0x2666, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, - 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, - 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, - 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, 0x0020 -}; - -void init_ucs(Session *s) -{ - int i; - - s->ucsdata.line_codepage = decode_codepage(s->cfg.line_codepage); - - /* Find the line control characters. FIXME: this is not right. */ - for (i = 0; i < 256; i++) - if (i < ' ' || (i >= 0x7F && i < 0xA0)) - s->ucsdata.unitab_ctrl[i] = i; - else - s->ucsdata.unitab_ctrl[i] = 0xFF; - - for (i = 0; i < 256; i++) - s->ucsdata.unitab_line[i] = s->ucsdata.unitab_scoacs[i] = i; - - /* VT100 graphics - NB: Broken for non-ascii CP's */ - memcpy(s->ucsdata.unitab_xterm, s->ucsdata.unitab_line, - sizeof(s->ucsdata.unitab_xterm)); - memcpy(s->ucsdata.unitab_xterm + '`', unitab_xterm_std, - sizeof(unitab_xterm_std)); - s->ucsdata.unitab_xterm['_'] = ' '; - -} - -int decode_codepage(char *cp_name) -{ - if (!*cp_name) - return CS_NONE; /* use font encoding */ - return charset_from_localenc(cp_name); -} - -char const *cp_enumerate (int index) -{ - int charset; - if (index == 0) - return "Use font encoding"; - charset = charset_localenc_nth(index-1); - if (charset == CS_NONE) - return NULL; - return charset_to_localenc(charset); -} - -char const *cp_name(int codepage) -{ - if (codepage == CS_NONE) - return "Use font encoding"; - return charset_to_localenc(codepage); -} diff --git a/mac/mkputty.mpw b/mac/mkputty.mpw deleted file mode 100644 index 92156c7b..00000000 --- a/mac/mkputty.mpw +++ /dev/null @@ -1,15 +0,0 @@ -# $Id$ - -Set makefile Makefile.mpw - -# Run Make, then execute its output. - -Echo "# `Date -t` ----- Analyzing dependencies." -Begin - Echo "Set Echo 1" - Make {"Parameters"} -f "{makefile}" -End > make.out -Echo "# `Date -t` ----- Executing build commands." -make.out -Delete make.out -Echo "# `Date -t` ----- Done." diff --git a/mac/mtcpnet.c b/mac/mtcpnet.c deleted file mode 100644 index c1c1fb80..00000000 --- a/mac/mtcpnet.c +++ /dev/null @@ -1,842 +0,0 @@ -/* - * Copyright (c) 2003 Ben Harris - * All rights reserved. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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 THE AUTHORS 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. - */ -/* - * mtcpnet.c - MacTCP interface - */ - -#if !TARGET_API_MAC_CARBON - -#include -#include -#include -#include -#include -#include -#include - -#include - -#define DEFINE_PLUG_METHOD_MACROS -#include "putty.h" -#include "network.h" -#include "mac.h" - -/* - * The following structures are documented as being in - * , but that isn't shipped with Universal - * Interfaces, and it's easier to define them here than to require - * people to download yet another SDK. - */ - -static OSErr OpenResolver(char *); -static OSErr CloseResolver(void); - -enum { - OPENRESOLVER = 1, - CLOSERESOLVER, - STRTOADDR, - ADDRTOSTR, - ENUMCACHE, - ADDRTONAME, - HXINFO, - MXINFO -}; - -#define NUM_ALT_ADDRS 4 - -typedef struct hostInfo { - int rtnCode; - char cname[255]; - unsigned long addr[NUM_ALT_ADDRS]; -}; - -typedef CALLBACK_API(void, ResultProcPtr)(struct hostInfo *, char *); -typedef STACK_UPP_TYPE(ResultProcPtr) ResultUPP; -enum { uppResultProcInfo = kPascalStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct hostInfo*))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *))) -}; -#define NewResultUPP(userRoutine) \ - (ResultUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), \ - uppResultProcInfo, \ - GetCurrentArchitecture()) -#define DisposeResultUPP(userUPP) DisposeRoutineDescriptor(userUPP) - -static OSErr StrToAddr(char *, struct hostInfo *, ResultUPP *, char *); - -typedef CALLBACK_API_C(OSErr, OpenResolverProcPtr)(UInt32, char *); -typedef STACK_UPP_TYPE(OpenResolverProcPtr) OpenResolverUPP; -enum { uppOpenResolverProcInfo = kCStackBased - | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*))) -}; -#define InvokeOpenResolverUPP(selector, fileName, userUPP) \ - CALL_TWO_PARAMETER_UPP((userUPP), uppOpenResolverProcInfo, \ - (selector), (fileName)) - -typedef CALLBACK_API_C(OSErr, CloseResolverProcPtr)(UInt32); -typedef STACK_UPP_TYPE(CloseResolverProcPtr) CloseResolverUPP; -enum { uppCloseResolverProcInfo = kCStackBased - | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32))) -}; -#define InvokeCloseResolverUPP(selector, userUPP) \ - CALL_ONE_PARAMETER_UPP((userUPP), uppCloseResolverProcInfo, (selector)) - -typedef CALLBACK_API_C(OSErr, StrToAddrProcPtr)(UInt32, char *, - struct hostInfo *, ResultUPP, - char *); -typedef STACK_UPP_TYPE(StrToAddrProcPtr) StrToAddrUPP; -enum { uppStrToAddrProcInfo = kCStackBased - | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *))) - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct hostInfo *))) - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(ResultUPP))) - | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char *))) -}; -#define InvokeStrToAddrUPP(selector, hostName, hostInfoPtr, ResultProc, \ - userDataPtr, userUPP) \ - CALL_FIVE_PARAMETER_UPP((userUPP), uppStrToAddrProcInfo, (selector),\ - (hostName), (hostInfoPtr), (ResultProc), \ - (userDataPtr)) -#define StrToAddr(hostName, hostInfoPtr, ResultProc, userDataPtr) \ - InvokeStrToAddrUPP(STRTOADDR, hostName, hostInfoPtr, ResultProc, \ - userDataPtr, (StrToAddrUPP)*mactcp.dnr_handle) - -typedef CALLBACK_API_C(OSErr, AddrToStrProcPtr)(UInt32, unsigned long, char *); -typedef STACK_UPP_TYPE(AddrToStrProcPtr) AddrToStrUPP; -enum { uppAddrToStrProcInfo = kCStackBased - | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned long))) - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(char *))) -}; -#define InvokeAddrToStrUPP(selector, addr, addrStr, userUPP) \ - CALL_THREE_PARAMETER_UPP((userUPP), uppAddrToStrProcInfo, (selector),\ - (addr), (addrStr)) -#define AddrToStr(addr, addrStr) \ - InvokeAddrToStrUPP(ADDRTOSTR, addr, addrStr, \ - (AddrToStrUPP)*mactcp.dnr_handle) - -/* End of AddressXlation.h bits */ - -/* TCP connection states, mysteriously missing from */ -#define TCPS_CLOSED 0 -#define TCPS_LISTEN 2 -#define TCPS_SYN_RECEIVED 4 -#define TCPS_SYN_SENT 6 -#define TCPS_ESTABLISHED 8 -#define TCPS_FIN_WAIT_1 10 -#define TCPS_FIN_WAIT_2 12 -#define TCPS_CLOSE_WAIT 14 -#define TCPS_CLOSING 16 -#define TCPS_LAST_ACK 18 -#define TCPS_TIME_WAIT 20 - -struct Socket_tag { - struct socket_function_table *fn; - /* the above variable absolutely *must* be the first in this structure */ - StreamPtr s; - OSErr err; - Plug plug; - void *private_ptr; - bufchain output_data; - int connected; - int writable; - int frozen; /* this causes readability notifications to be ignored */ - int frozen_readable; /* this means we missed at least one readability - * notification while we were frozen */ - int localhost_only; /* for listening sockets */ - char oobdata[1]; - int sending_oob; - int oobpending; /* is there OOB data available to read? */ - int oobinline; - int pending_error; /* in case send() returns error */ - int listener; - struct Socket_tag *next; - struct Socket_tag **prev; -}; - -/* - * We used to typedef struct Socket_tag *Socket. - * - * Since we have made the networking abstraction slightly more - * abstract, Socket no longer means a tcp socket (it could mean - * an ssl socket). So now we must use Actual_Socket when we know - * we are talking about a tcp socket. - */ -typedef struct Socket_tag *Actual_Socket; - -struct SockAddr_tag { - int resolved; - struct hostInfo hostinfo; - char hostname[512]; -}; - -/* Global variables */ -static struct { - Handle dnr_handle; - int initialised; - short refnum; - ProcessSerialNumber self; - Actual_Socket socklist; -} mactcp; - -static pascal void mactcp_lookupdone(struct hostInfo *hi, char *cookie); -static pascal void mactcp_asr(StreamPtr, unsigned short, Ptr, unsigned short, - struct ICMPReport *); -static Plug mactcp_plug(Socket, Plug); -static void mactcp_flush(Socket); -static void mactcp_close(Socket); -static int mactcp_write(Socket, char const *, int); -static int mactcp_write_oob(Socket, char const*, int); -static void mactcp_set_private_ptr(Socket, void *); -static void *mactcp_get_private_ptr(Socket); -static const char *mactcp_socket_error(Socket); -static void mactcp_set_frozen(Socket, int); - -static void mactcp_recv(Actual_Socket s, size_t len); - -/* - * Initialise MacTCP. - * This should be called once before any TCP connection is opened. - */ - -OSErr mactcp_init(void) -{ - OSErr err; - - /* - * IM:Devices describes a convoluted way of finding a spare unit - * number to open a driver on before calling OpenDriver. Happily, - * the MacTCP INIT ensures that .IPP is already open (and hence - * has a valid unit number already) so we don't need to go through - * all that. (MacTCP Programmer's Guide p6) - */ - err = OpenDriver("\p.IPP", &mactcp.refnum); - if (err != noErr) return err; - err = OpenResolver(NULL); - if (err != noErr) return err; - - mactcp.initialised = TRUE; - return noErr; -} - -void mactcp_cleanup(void) -{ - Actual_Socket s, next; - - /* - * Eventually, PuTTY should close down each session as it exits, - * so there should be no sockets left when we get here. Still, - * better safe than sorry. - * - * XXX What about in-flight aync I/O (when we support that)? - */ - for (s = mactcp.socklist; s != NULL; s = next) { - next = s->next; /* s is about to vanish */ - mactcp_close(&s->fn); - } - - /* - * When we get async DNS, we have to wait for any outstanding - * requests to complete here before exiting. - */ - CloseResolver(); - mactcp.initialised = FALSE; -} - -static ResultUPP mactcp_lookupdone_upp; - -SockAddr mactcp_namelookup(char const *host, char **canonicalname) -{ - SockAddr ret = snew(struct SockAddr_tag); - OSErr err; - volatile int done = FALSE; - char *realhost; - int realhostlen; - - /* Clear the structure. */ - memset(ret, 0, sizeof(struct SockAddr_tag)); - if (mactcp_lookupdone_upp == NULL) - mactcp_lookupdone_upp = NewResultUPP(&mactcp_lookupdone); - /* Casting away const -- hope StrToAddr is sensible */ - err = StrToAddr((char *)host, &ret->hostinfo, mactcp_lookupdone_upp, - (char *)&done); - /* - * PuTTY expects DNS lookups to be synchronous (see bug - * "async-dns"), so we pretend they are. - */ - if (err == cacheFault) - while (!done) - continue; - ret->resolved = TRUE; - - if (ret->hostinfo.rtnCode == noErr) { - realhost = ret->hostinfo.cname; - /* MacTCP puts trailing dots on canonical names. */ - realhostlen = strlen(realhost); - if (realhost[realhostlen - 1] == '.') - realhost[realhostlen - 1] = '\0'; - } else - realhost = ""; - *canonicalname = snewn(1 + strlen(realhost), char); - strcpy(*canonicalname, realhost); - return ret; -} - -static pascal void mactcp_lookupdone(struct hostInfo *hi, char *cookie) -{ - volatile int *donep = (int *)cookie; - - *donep = TRUE; -} - -SockAddr mactcp_nonamelookup(char const *host) -{ - SockAddr ret = snew(struct SockAddr_tag); - - ret->resolved = FALSE; - ret->hostinfo.rtnCode = noErr; - ret->hostname[0] = '\0'; - strncat(ret->hostname, host, lenof(ret->hostname) - 1); - return ret; -} - -void mactcp_getaddr(SockAddr addr, char *buf, int buflen) -{ - char mybuf[16]; - OSErr err; - - if (addr->resolved) { - /* XXX only return first address */ - err = AddrToStr(addr->hostinfo.addr[0], mybuf); - buf[0] = '\0'; - if (err != noErr) - strncat(buf, mybuf, buflen - 1); - } else { - buf[0] = '\0'; - strncat(buf, addr->hostname, buflen - 1); - } -} - -/* I think "local" here really means "loopback" */ - -int mactcp_hostname_is_local(char *name) -{ - - return !strcmp(name, "localhost"); -} - -int mactcp_address_is_local(SockAddr addr) -{ - int i; - - if (addr->resolved) - for (i = 0; i < NUM_ALT_ADDRS; i++) - if (addr->hostinfo.addr[i] & 0xff000000 == 0x7f000000) - return TRUE; - return FALSE; -} - -int mactcp_addrtype(SockAddr addr) -{ - - if (addr->resolved) - return ADDRTYPE_IPV4; - return ADDRTYPE_NAME; -} - -void mactcp_addrcopy(SockAddr addr, char *buf) -{ - - /* XXX only return first address */ - memcpy(buf, &addr->hostinfo.addr[0], 4); -} - -void mactcp_addr_free(SockAddr addr) -{ - - sfree(addr); -} - -static Plug mactcp_plug(Socket sock, Plug p) -{ - Actual_Socket s = (Actual_Socket) sock; - Plug ret = s->plug; - - if (p) - s->plug = p; - return ret; -} - -static void mactcp_flush(Socket s) -{ - - fatalbox("mactcp_flush"); -} - -Socket mactcp_register(void *sock, Plug plug) -{ - - fatalbox("mactcp_register"); -} - -static TCPNotifyUPP mactcp_asr_upp; - -Socket mactcp_new(SockAddr addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug plug) -{ - static struct socket_function_table fn_table = { - mactcp_plug, - mactcp_close, - mactcp_write, - mactcp_write_oob, - mactcp_flush, - mactcp_set_private_ptr, - mactcp_get_private_ptr, - mactcp_set_frozen, - mactcp_socket_error - }; - TCPiopb pb; - UDPiopb upb; - Actual_Socket ret; - ip_addr dstaddr; - size_t buflen; - - /* - * Create Socket structure. - */ - ret = snew(struct Socket_tag); - ret->s = 0; - ret->fn = &fn_table; - ret->err = noErr; - ret->plug = plug; - bufchain_init(&ret->output_data); - ret->connected = 0; /* to start with */ - ret->writable = 0; /* to start with */ - ret->sending_oob = 0; - ret->frozen = 0; - ret->frozen_readable = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ - ret->pending_error = 0; - ret->oobinline = oobinline; - ret->oobpending = FALSE; - ret->listener = 0; - - dstaddr = addr->hostinfo.addr[0]; /* XXX should try all of them */ - /* - * Create a TCP stream. - * - * MacTCP requires us to provide it with some buffer memory. Page - * 31 of the Programmer's Guide says it should be a minimum of - * 4*MTU+1024. Page 36 says a minimum of 4096 bytes. Assume - * they're both correct. - */ - assert(addr->resolved); - upb.ioCRefNum = mactcp.refnum; - upb.csCode = UDPMaxMTUSize; - upb.csParam.mtu.remoteHost = dstaddr; - upb.csParam.mtu.userDataPtr = NULL; - ret->err = PBControlSync((ParmBlkPtr)&upb); - if (ret->err != noErr) return (Socket)ret; - - buflen = upb.csParam.mtu.mtuSize * 4 + 1024; - if (buflen < 4096) buflen = 4096; - if (mactcp_asr_upp == NULL) - mactcp_asr_upp = NewTCPNotifyUPP(&mactcp_asr); - GetCurrentProcess(&mactcp.self); - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPCreate; - pb.csParam.create.rcvBuff = snewn(buflen, char); - pb.csParam.create.rcvBuffLen = buflen; - pb.csParam.create.notifyProc = mactcp_asr_upp; - pb.csParam.create.userDataPtr = (Ptr)ret; - ret->err = PBControlSync((ParmBlkPtr)&pb); - if (ret->err != noErr) return (Socket)ret; - ret->s = pb.tcpStream; - - /* - * Open the connection. - */ - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPActiveOpen; - pb.tcpStream = ret->s; - pb.csParam.open.validityFlags = 0; - pb.csParam.open.remoteHost = dstaddr; - pb.csParam.open.remotePort = port; - pb.csParam.open.localPort = privport ? 1023 : 0; - pb.csParam.open.dontFrag = FALSE; - pb.csParam.open.timeToLive = 0; - pb.csParam.open.security = 0; - pb.csParam.open.optionCnt = 0; - pb.csParam.open.userDataPtr = (Ptr)ret; - while (1) { - ret->err = PBControlSync((ParmBlkPtr)&pb); - if (!privport || ret->err != duplicateSocket) - break; - pb.csParam.open.localPort--; - if (pb.csParam.open.localPort == 0) - break; - } - - if (ret->err != noErr) return (Socket)ret; - - ret->connected = TRUE; - ret->writable = TRUE; - - /* Add this to the list of all sockets */ - ret->next = mactcp.socklist; - ret->prev = &mactcp.socklist; - if (ret->next != NULL) - ret->next->prev = &ret->next; - mactcp.socklist = ret; - - sk_addr_free(addr); /* don't need this anymore */ - - return (Socket)ret; -} - -Socket mactcp_newlistener(char *srcaddr, int port, Plug plug, - int local_host_only, int address_family) -{ - - fatalbox("mactcp_newlistener"); -} - -static void mactcp_close(Socket sock) -{ - Actual_Socket s = (Actual_Socket)sock; - TCPiopb pb; - - /* - * TCPClose is equivalent to shutdown(fd, SHUT_WR), and hence - * leaves the Rx side open, while TCPAbort seems rather vicious, - * throwing away Tx data that haven't been ACKed yet. We do both - * in succession. - */ - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPClose; - pb.tcpStream = s->s; - pb.csParam.close.validityFlags = 0; - pb.csParam.close.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - /* Not much we can do about an error anyway. */ - - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPAbort; - pb.tcpStream = s->s; - pb.csParam.abort.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - /* Even less we can do about an error here. */ - - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPRelease; - pb.tcpStream = s->s; - pb.csParam.create.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - if (s->err == noErr) - sfree(pb.csParam.create.rcvBuff); - - /* Unhitch from list of sockets */ - *s->prev = s->next; - if (s->next != NULL) - s->next->prev = s->prev; - - sfree(s); -} - -static int mactcp_write(Socket sock, char const *buf, int len) -{ - Actual_Socket s = (Actual_Socket) sock; - wdsEntry wds[2]; - TCPiopb pb; - - /* - * Casting away const from buf should be safe -- MacTCP won't - * write to it. - */ - wds[0].length = len; - wds[0].ptr = (char *)buf; - wds[1].length = 0; - - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPSend; - pb.tcpStream = s->s; - pb.csParam.send.validityFlags = 0; - pb.csParam.send.pushFlag = TRUE; /* XXX we want it to return. */ - pb.csParam.send.urgentFlag = 0; - pb.csParam.send.wdsPtr = (Ptr)wds; - pb.csParam.send.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - return 0; -} - -static int mactcp_write_oob(Socket sock, char const *buf, int len) -{ - - fatalbox("mactcp_write_oob"); -} - -static pascal void mactcp_asr(StreamPtr str, unsigned short event, Ptr cookie, - unsigned short termin_reason, - struct ICMPReport *icmp) -{ - - WakeUpProcess(&mactcp.self); -} - -/* - * Called from our event loop if there's work to do. - */ -void mactcp_poll(void) -{ - Actual_Socket s, next; - TCPiopb pb; - - for (s = mactcp.socklist; s != NULL; s = next) { - next = s->next; - do { - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPStatus; - pb.tcpStream = s->s; - pb.csParam.status.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - if (s->err != noErr) - goto next_socket; - if (pb.csParam.status.amtUnreadData == 0) - break; - mactcp_recv(s, pb.csParam.status.amtUnreadData); - } while (TRUE); - switch (pb.csParam.status.connectionState) { - case TCPS_CLOSE_WAIT: - /* Remote end has sent us a FIN */ - plug_closing(s->plug, NULL, 0, 0); - } - next_socket: - ; - } -} - -static void mactcp_recv(Actual_Socket s, size_t len) -{ - rdsEntry rds[2]; - TCPiopb pb; - - if (s->frozen) return; - - while (len > 0) { - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPNoCopyRcv; - pb.tcpStream = s->s; - pb.csParam.receive.commandTimeoutValue = 0; - pb.csParam.receive.rdsPtr = (Ptr)rds; - pb.csParam.receive.rdsLength = lenof(rds) - 1; - pb.csParam.receive.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - if (s->err != noErr) - return; - plug_receive(s->plug, 0, rds[0].ptr, rds[0].length); - len -= rds[0].length; - pb.csCode = TCPRcvBfrReturn; - s->err = PBControlSync((ParmBlkPtr)&pb); - if (s->err != noErr) - return; - } -} - -/* - * Each socket abstraction contains a `void *' private field in - * which the client can keep state. - */ -static void mactcp_set_private_ptr(Socket sock, void *ptr) -{ - Actual_Socket s = (Actual_Socket) sock; - s->private_ptr = ptr; -} - -static void *mactcp_get_private_ptr(Socket sock) -{ - Actual_Socket s = (Actual_Socket) sock; - return s->private_ptr; -} - -/* - * Special error values are returned from mactcp_namelookup and - * mactcp_new if there's a problem. These functions extract an error - * message, or return NULL if there's no problem. - */ -char *mactcp_addr_error(SockAddr addr) -{ - static char buf[64]; - - switch (addr->hostinfo.rtnCode) { - case noErr: - return NULL; - case nameSyntaxErr: - return "Name syntax error"; - case noNameServer: - return "No name server found"; - case authNameErr: - return "Domain name does not exist"; - case noAnsErr: - return "No answer from domain name server"; - case dnrErr: - return "Domain name server returned an error"; - case outOfMemory: - return "Out of memory"; - default: - sprintf(buf, "Unknown DNR error %d", addr->hostinfo.rtnCode); - return buf; - } -} - -static const char *mactcp_socket_error(Socket sock) -{ - static char buf[64]; - Actual_Socket s = (Actual_Socket) sock; - - switch (s->err) { - case noErr: - return NULL; - case insufficientResources: - return "Insufficient resources to open TCP stream"; - case duplicateSocket: - return "Duplicate socket"; - case openFailed: - return "Connection failed while opening"; - default: - sprintf(buf, "Unknown MacTCP error %d", s->err); - return buf; - } -} - -static void mactcp_set_frozen(Socket sock, int is_frozen) -{ - Actual_Socket s = (Actual_Socket) sock; - - if (s->frozen == is_frozen) - return; - s->frozen = is_frozen; -} - -/* - * Bits below here would usually be in dnr.c, shipped with the MacTCP - * SDK, but its convenient not to require that, and since we assume - * System 7 we can actually simplify things a lot. - */ - -static OSErr OpenResolver(char *hosts_file) -{ - short vrefnum; - long dirid; - HParamBlockRec pb; - Str255 filename; - OSErr err; - int fd; - Handle dnr_handle; - - if (mactcp.dnr_handle != NULL) - return noErr; - - err = FindFolder(kOnSystemDisk, kControlPanelFolderType, FALSE, &vrefnum, - &dirid); - if (err != noErr) return err; - - /* - * Might be better to use PBCatSearch here, but it's not always - * available. - */ - pb.fileParam.ioCompletion = NULL; - pb.fileParam.ioNamePtr = filename; - pb.fileParam.ioVRefNum = vrefnum; - pb.fileParam.ioFDirIndex = 1; - pb.fileParam.ioDirID = dirid; - fd = -1; - - while (PBHGetFInfoSync(&pb) == noErr) { - if (pb.fileParam.ioFlFndrInfo.fdType == 'cdev' && - pb.fileParam.ioFlFndrInfo.fdCreator == 'ztcp') { - fd = HOpenResFile(vrefnum, dirid, filename, fsRdPerm); - if (fd == -1) continue; - dnr_handle = Get1IndResource('dnrp', 1); - if (dnr_handle != NULL) - break; - CloseResFile(fd); - fd = -1; - } - pb.fileParam.ioDirID = dirid; - pb.fileParam.ioFDirIndex++; - } - if (fd == -1) - return fnfErr; - - DetachResource(dnr_handle); - CloseResFile(fd); - - MoveHHi(dnr_handle); - HLock(dnr_handle); - - err = InvokeOpenResolverUPP(OPENRESOLVER, hosts_file, - (OpenResolverUPP)*dnr_handle); - if (err != noErr) { - HUnlock(dnr_handle); - DisposeHandle(dnr_handle); - return err; - } - - mactcp.dnr_handle = dnr_handle; - return noErr; -} - -OSErr CloseResolver(void) -{ - Handle dnr_handle = mactcp.dnr_handle; - OSErr err; - - if (mactcp.dnr_handle == NULL) - return notOpenErr; - - err = InvokeCloseResolverUPP(CLOSERESOLVER, - (CloseResolverUPP)*mactcp.dnr_handle); - if (err != noErr) - return err; - - mactcp.dnr_handle = NULL; - HUnlock(dnr_handle); - DisposeHandle(dnr_handle); - return noErr; -} - -#endif - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/otnet.c b/mac/otnet.c deleted file mode 100644 index d5271e70..00000000 --- a/mac/otnet.c +++ /dev/null @@ -1,638 +0,0 @@ -/* - * Macintosh OpenTransport networking abstraction - */ - -#if TARGET_API_MAC_CARBON -#define OTCARBONAPPLICATION 1 -#endif - -#include /* Needed by OpenTransportInternet.h */ -#include -#include - -#include - -#define DEFINE_PLUG_METHOD_MACROS -#include "putty.h" -#include "network.h" -#include "mac.h" - -struct Socket_tag { - struct socket_function_table *fn; - /* other stuff... */ - OSStatus error; - EndpointRef ep; - Plug plug; - void *private_ptr; - bufchain output_data; - int connected; - int writable; - int frozen; /* this causes readability notifications to be ignored */ - int frozen_readable; /* this means we missed at least one readability - * notification while we were frozen */ - int localhost_only; /* for listening sockets */ - char oobdata[1]; - int sending_oob; - int oobpending; /* is there OOB data available to read?*/ - int oobinline; - int pending_error; /* in case send() returns error */ - int listener; - int nodelay, keepalive; - int privport, port; - struct Socket_tag *next; - struct Socket_tag **prev; -}; - -typedef struct Socket_tag *Actual_Socket; - -struct SockAddr_tag { - int resolved; - OSStatus error; - InetHostInfo hostinfo; - char hostname[512]; -}; - -/* Globals */ - -static struct { - Actual_Socket socklist; - InetSvcRef inetsvc; -} ot; - -OSErr ot_init(void) -{ - OSStatus err; - - err = InitOpenTransport(); - if (err != kOTNoError) return err; - ot.inetsvc = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err); - return err; -} - -void ot_cleanup(void) -{ - Actual_Socket s; - - for (s = ot.socklist; s !=NULL; s = s->next) { - OTUnbind(s->ep); - OTCloseProvider(s->ep); - } - - CloseOpenTransport(); -} - -SockAddr ot_namelookup(char const *host, char **canonicalname) -{ - SockAddr ret = snew(struct SockAddr_tag); - char *realhost; - - /* Casting away const -- hope OTInetStringToAddress is sensible */ - ret->error = OTInetStringToAddress(ot.inetsvc, (char *)host, - &ret->hostinfo); - ret->resolved = TRUE; - - if (ret->error == kOTNoError) - realhost = ret->hostinfo.name; - else - realhost = ""; - *canonicalname = snewn(1+strlen(realhost), char); - strcpy(*canonicalname, realhost); - return ret; -} - -SockAddr ot_nonamelookup(char const *host) -{ - SockAddr ret = snew(struct SockAddr_tag); - - ret->resolved = FALSE; - ret->error = kOTNoError; - ret->hostname[0] = '\0'; - strncat(ret->hostname, host, lenof(ret->hostname) - 1); - return ret; -} - -void ot_getaddr(SockAddr addr, char *buf, int buflen) -{ - char mybuf[16]; - - buf[0] = '\0'; - if (addr->resolved) { - /* XXX only return first address */ - OTInetHostToString(addr->hostinfo.addrs[0], mybuf); - strncat(buf, mybuf, buflen - 1); - } else - strncat(buf, addr->hostname, buflen - 1); -} - -/* I think "local" here really means "loopback" */ - -int ot_hostname_is_local(char *name) -{ - - return !strcmp(name, "localhost"); -} - -int ot_address_is_local(SockAddr addr) -{ - int i; - - if (addr->resolved) - for (i = 0; i < kMaxHostAddrs; i++) - if (addr->hostinfo.addrs[i] & 0xff000000 == 0x7f000000) - return TRUE; - return FALSE; -} - -int ot_addrtype(SockAddr addr) -{ - - if (addr->resolved) - return ADDRTYPE_IPV4; - return ADDRTYPE_NAME; -} - -void ot_addrcopy(SockAddr addr, char *buf) -{ - - /* XXX only return first address */ - memcpy(buf, &addr->hostinfo.addrs[0], 4); -} - -void ot_addr_free(SockAddr addr) -{ - sfree(addr); -} - - -static Plug ot_tcp_plug(Socket sock, Plug p) -{ - Actual_Socket s = (Actual_Socket) sock; - Plug ret = s->plug; - if (p) - s->plug = p; - return ret; -} - -static void ot_tcp_flush(Socket s) -{ - /* - * We send data to the socket as soon as we can anyway, - * so we don't need to do anything here. :-) - */ -} - -static void ot_tcp_close(Socket s); -static int ot_tcp_write(Socket s, char const *data, int len); -static int ot_tcp_write_oob(Socket s, char const *data, int len); -static void ot_tcp_set_private_ptr(Socket s, void *ptr); -static void *ot_tcp_get_private_ptr(Socket s); -static void ot_tcp_set_frozen(Socket s, int is_frozen); -static const char *ot_tcp_socket_error(Socket s); -static void ot_recv(Actual_Socket s); -static void ot_listenaccept(Actual_Socket s); -static void ot_setoption(EndpointRef, OTXTILevel, OTXTIName, UInt32); -void ot_poll(void); - - -Socket ot_register(void *sock, Plug plug) -{ - static struct socket_function_table fn_table = { - ot_tcp_plug, - ot_tcp_close, - ot_tcp_write, - ot_tcp_write_oob, - ot_tcp_flush, - ot_tcp_set_private_ptr, - ot_tcp_get_private_ptr, - ot_tcp_set_frozen, - ot_tcp_socket_error - }; - - Actual_Socket ret; - - ret = snew(struct Socket_tag); - ret->fn = &fn_table; - ret->error = kOTNoError; - ret->plug = plug; - bufchain_init(&ret->output_data); - ret->writable = 1; /* to start with */ - ret->sending_oob = 0; - ret->frozen = 1; - ret->frozen_readable = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ - ret->pending_error = 0; - ret->oobpending = FALSE; - ret->listener = 0; - - ret->ep = (EndpointRef)sock; - - /* some sort of error checking */ - - ret->oobinline = 0; - - /* Add this to the list of all sockets */ - ret->next = ot.socklist; - ret->prev = &ot.socklist; - ot.socklist = ret; - - return (Socket) ret; -} - -Socket ot_new(SockAddr addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug plug) -{ - static struct socket_function_table fn_table = { - ot_tcp_plug, - ot_tcp_close, - ot_tcp_write, - ot_tcp_write_oob, - ot_tcp_flush, - ot_tcp_set_private_ptr, - ot_tcp_get_private_ptr, - ot_tcp_set_frozen, - ot_tcp_socket_error - }; - - Actual_Socket ret; - EndpointRef ep; - OSStatus err; - InetAddress dest; - TCall connectCall; - - ret = snew(struct Socket_tag); - ret->fn = &fn_table; - ret->error = kOTNoError; - ret->plug = plug; - bufchain_init(&ret->output_data); - ret->connected = 0; /* to start with */ - ret->writable = 0; /* to start with */ - ret->sending_oob = 0; - ret->frozen = 0; - ret->frozen_readable = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ - ret->pending_error = 0; - ret->oobinline = oobinline; - ret->nodelay = nodelay; - ret->keepalive = keepalive; - ret->oobpending = FALSE; - ret->listener = 0; - - /* Open Endpoint, configure it for TCP over anything */ - - ep = OTOpenEndpoint(OTCreateConfiguration("tcp"), 0, NULL, &err); - - ret->ep = ep; - - if (err) { - ret->error = err; - return (Socket) ret; - } - - if (ret->oobinline) - ot_setoption(ep, INET_TCP, TCP_OOBINLINE, T_YES); - - if (ret->nodelay) - ot_setoption(ep, INET_TCP, TCP_NODELAY, T_YES); - - if (ret->keepalive) { - ot_setoption(ep, INET_TCP, TCP_KEEPALIVE, T_YES); - } - - /* - * Bind to local address. - */ - - /* FIXME: pay attention to privport */ - - err = OTBind(ep, NULL, NULL); /* OpenTransport always picks our address */ - - if (err) { - ret->error = err; - return (Socket) ret; - } - - /* - * Connect to remote address. - */ - - /* XXX Try non-primary addresses */ - OTInitInetAddress(&dest, port, addr->hostinfo.addrs[0]); - - memset(&connectCall, 0, sizeof(TCall)); - connectCall.addr.buf = (UInt8 *) &dest; - connectCall.addr.len = sizeof(dest); - - err = OTConnect(ep, &connectCall, nil); - - if (err) { - ret->error = err; - return (Socket) ret; - } else { - ret->connected = 1; - ret->writable = 1; - } - - /* Add this to the list of all sockets */ - ret->next = ot.socklist; - ret->prev = &ot.socklist; - if (ret->next != NULL) - ret->next->prev = &ret->next; - ot.socklist = ret; - - /* XXX: don't know whether we can sk_addr_free(addr); */ - - return (Socket) ret; -} - -Socket ot_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, - int address_family) -{ - static struct socket_function_table fn_table = { - ot_tcp_plug, - ot_tcp_close, - ot_tcp_write, - ot_tcp_write_oob, - ot_tcp_flush, - ot_tcp_set_private_ptr, - ot_tcp_get_private_ptr, - ot_tcp_set_frozen, - ot_tcp_socket_error - }; - - Actual_Socket ret; - EndpointRef ep; - OSStatus err; - InetAddress addr; - TBind tbind; - - ret = snew(struct Socket_tag); - ret->fn = &fn_table; - ret->error = kOTNoError; - ret->plug = plug; - bufchain_init(&ret->output_data); - ret->writable = 0; /* to start with */ - ret->sending_oob = 0; - ret->frozen = 0; - ret->frozen_readable = 0; - ret->localhost_only = local_host_only; - ret->pending_error = 0; - ret->oobinline = 0; - ret->oobpending = FALSE; - ret->listener = 1; - - /* Open Endpoint, configure it for TCP over anything, and load the - * tilisten module to serialize multiple simultaneous - * connections. */ - - ep = OTOpenEndpoint(OTCreateConfiguration("tilisten,tcp"), 0, NULL, &err); - - ret->ep = ep; - - if (err) { - ret->error = err; - return (Socket) ret; - } - - ot_setoption(ep, INET_IP, IP_REUSEADDR, T_YES); - - OTInitInetAddress(&addr, port, kOTAnyInetAddress); - /* XXX: pay attention to local_host_only */ - - tbind.addr.buf = (UInt8 *) &addr; - tbind.addr.len = sizeof(addr); - tbind.qlen = 10; - - err = OTBind(ep, &tbind, NULL); /* XXX: check qlen we got */ - - if (err) { - ret->error = err; - return (Socket) ret; - } - - /* Add this to the list of all sockets */ - ret->next = ot.socklist; - ret->prev = &ot.socklist; - if (ret->next != NULL) - ret->next->prev = &ret->next; - ot.socklist = ret; - - return (Socket) ret; -} - -static void ot_tcp_close(Socket sock) -{ - Actual_Socket s = (Actual_Socket) sock; - - OTCloseProvider(s->ep); - - /* Unhitch from list of sockets */ - *s->prev = s->next; - if (s->next != NULL) - s->next->prev = s->prev; - - sfree(s); -} - -static void try_send(Actual_Socket s) -{ - while (bufchain_size(&s->output_data) > 0) { - int nsent; - void *data; - int len; - - /* Don't care about oob right now */ - - bufchain_prefix(&s->output_data, &data, &len); - - nsent = OTSnd(s->ep, data, len, 0); - noise_ultralight(nsent); - - if (nsent <= 0) { - /* something bad happened, hey ho */ - } else { - /* still don't care about oob */ - bufchain_consume(&s->output_data, nsent); - } - } -} - -static int ot_tcp_write(Socket sock, char const *buf, int len) -{ - Actual_Socket s = (Actual_Socket) sock; - - bufchain_add(&s->output_data, buf, len); - - if (s->writable) - try_send(s); - return bufchain_size(&s->output_data); -} - -static int ot_tcp_write_oob(Socket sock, char const *buf, int len) -{ - /* Don't care about oob */ - return 0; -} - - -/* - * Each socket abstraction contains a `void *' private field in - * which the client can keep state. - */ -static void ot_tcp_set_private_ptr(Socket sock, void *ptr) -{ - Actual_Socket s = (Actual_Socket) sock; - s->private_ptr = ptr; -} - -static void *ot_tcp_get_private_ptr(Socket sock) -{ - Actual_Socket s = (Actual_Socket) sock; - return s->private_ptr; -} - - -/* - * Special error values are returned from ot_namelookup and ot_new - * if there's a problem. These functions extract an error message, - * or return NULL if there's no problem. - */ -char *ot_addr_error(SockAddr addr) -{ - static char buf[128]; - - if (addr->error == kOTNoError) - return NULL; - sprintf(buf, "error %d", addr->error); - return buf; -} -static const char *ot_tcp_socket_error(Socket sock) -{ - Actual_Socket s = (Actual_Socket) sock; - static char buf[128]; - - if (s->error == kOTNoError) - return NULL; - sprintf(buf, "error %d", s->error); - return buf; -} - -static void ot_tcp_set_frozen(Socket sock, int is_frozen) -{ - Actual_Socket s = (Actual_Socket) sock; - - if (s->frozen == is_frozen) - return; - s->frozen = is_frozen; -} - -/* - * Poll all our sockets from an event loop - */ - -void ot_poll(void) -{ - Actual_Socket s; - OTResult o; - - for (s = ot.socklist; s != NULL; s = s->next) { - o = OTLook(s->ep); - - switch(o) { - case T_DATA: /* Normal Data */ - ot_recv(s); - break; - case T_EXDATA: /* Expedited Data (urgent?) */ - ot_recv(s); - break; - case T_LISTEN: /* Connection attempt */ - ot_listenaccept(s); - break; - case T_ORDREL: /* Orderly disconnect */ - plug_closing(s->plug, NULL, 0, 0); - break; - case T_DISCONNECT: /* Abortive disconnect*/ - plug_closing(s->plug, NULL, 0, 0); - break; - } - } -} - -void ot_recv(Actual_Socket s) -{ - OTResult o; - char buf[2048]; - OTFlags flags; - - if (s->frozen) return; - - o = OTRcv(s->ep, buf, sizeof(buf), &flags); - if (o > 0) - plug_receive(s->plug, 0, buf, o); - if (o < 0 && o != kOTNoDataErr) - plug_closing(s->plug, NULL, 0, 0); /* XXX Error msg */ -} - -void ot_listenaccept(Actual_Socket s) -{ - OTResult o; - OSStatus err; - InetAddress remoteaddr; - TCall tcall; - EndpointRef ep; - - tcall.addr.maxlen = sizeof(InetAddress); - tcall.addr.buf = (unsigned char *)&remoteaddr; - tcall.opt.maxlen = 0; - tcall.opt.buf = NULL; - tcall.udata.maxlen = 0; - tcall.udata.buf = NULL; - - o = OTListen(s->ep, &tcall); - - if (o != kOTNoError) - return; - - /* We've found an incoming connection, accept it */ - - ep = OTOpenEndpoint(OTCreateConfiguration("tcp"), 0, NULL, &err); - o = OTAccept(s->ep, ep, &tcall); - if (plug_accepting(s->plug, ep)) { - OTUnbind(ep); - OTCloseProvider(ep); - } -} - -static void ot_setoption(EndpointRef ep, - OTXTILevel level, - OTXTIName name, - UInt32 value) -{ - TOption option; - TOptMgmt request; - TOptMgmt result; - - if (name == TCP_KEEPALIVE) { - option.len = sizeof(struct t_kpalive); - option.value[1] = T_UNSPEC; - } else - option.len = kOTFourByteOptionSize; - option.level = level; - option.name = name; - option.status = 0; - option.value[0] = value; - - request.opt.buf = (unsigned char *) &option; - request.opt.len = sizeof(option); - request.flags = T_NEGOTIATE; - - result.opt.buf = (unsigned char *) &option; - result.opt.maxlen = sizeof(option); - - OTOptionManagement(ep, &request, &result); -} - -/* - * Local Variables: - * c-file-style: "simon" - * End: - */ diff --git a/mac/setfile.sh b/mac/setfile.sh deleted file mode 100755 index 2407a496..00000000 --- a/mac/setfile.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -# Shell script to be run on Mac OS X, which uses `SetFile' to set -# up the appropriate file metadata so that you can run MPW and have -# it build classic-Mac PuTTY. - -SETFILE=/Developer/Tools/SetFile - -# I want to be able to run this either from the `mac' subdirectory -# or from the main `putty' source directory. -if test -f mac_res.r -a -f ../putty.h; then - cd .. -fi -if test ! -f putty.h; then - echo 'putty.h not found.' >&2 - echo 'This script should be run in the PuTTY source directory.' >&2 - exit 1 -fi - -# Now we can assume we're in the main PuTTY source dir. -find . -name .svn -prune -o -name '*.[chr]' -exec $SETFILE -t TEXT {} \; - -# CR-ise mkputty.mpw and set the new version to TEXT. -tr '\n' '\r' < mac/mkputty.mpw > mac/mk.mpw -$SETFILE -t TEXT mac/mk.mpw diff --git a/mac/stricmp.c b/mac/stricmp.c deleted file mode 100644 index affecb09..00000000 --- a/mac/stricmp.c +++ /dev/null @@ -1,82 +0,0 @@ - -#include "putty.h" - -#define strcasecmp stricmp -#define strncasecmp strnicmp -#define _DIAGASSERT(e) /* nothing */ - -/* - * Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * From NetBSD: strcasecmp.c,v 1.12 2000/01/22 22:19:20 mycroft Exp - */ - -#include - -typedef unsigned char u_char; - -int -strcasecmp(s1, s2) - const char *s1, *s2; -{ - const u_char *us1 = (const u_char *)s1, - *us2 = (const u_char *)s2; - - _DIAGASSERT(s1 != NULL); - _DIAGASSERT(s2 != NULL); - - while (tolower(*us1) == tolower(*us2++)) - if (*us1++ == '\0') - return (0); - return (tolower(*us1) - tolower(*--us2)); -} - -int -strncasecmp(s1, s2, n) - const char *s1, *s2; - size_t n; -{ - - _DIAGASSERT(s1 != NULL); - _DIAGASSERT(s2 != NULL); - if (s1 == NULL || s2 == NULL) - return (0); - - if (n != 0) { - const u_char *us1 = (const u_char *)s1, - *us2 = (const u_char *)s2; - - do { - if (tolower(*us1) != tolower(*us2++)) - return (tolower(*us1) - tolower(*--us2)); - if (*us1++ == '\0') - break; - } while (--n != 0); - } - return (0); -} diff --git a/mac/version.r b/mac/version.r deleted file mode 100644 index 8770d1f6..00000000 --- a/mac/version.r +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Current PuTTY version number. Minor is in BCD - */ -#define VERSION_MAJOR 0x00 -#define VERSION_MINOR 0x60 - -resource 'vers' (1, purgeable) { -#ifdef RELEASE - VERSION_MAJOR, VERSION_MINOR, - beta, -#else - VERSION_MAJOR, VERSION_MINOR + 1, - development, -#endif - 0, /* No prerelease version */ - verBritain, -#ifdef RELEASESTR - RELEASESTR, - "Release " RELEASESTR, -#else -#ifdef SNAPSHOTSTR - SNAPSHOTSTR, - "Development snapshot " SNAPSHOTSTR, -#else - "unknown", - "Unidentified build, " $$Date " " $$Time, -#endif -#endif -}; - -resource 'vers' (2, purgeable) { -#ifdef RELEASE - VERSION_MAJOR, VERSION_MINOR, - beta, -#else - VERSION_MAJOR, VERSION_MINOR + 1, - development, -#endif - 0, /* No prerelease version */ - verBritain, -#ifdef RELEASESTR - RELEASESTR, - "PuTTY " RELEASESTR, -#else -#ifdef SNAPSHOTSTR - SNAPSHOTSTR, - "PuTTY snapshot " SNAPSHOTSTR, -#else - "unknown", - "PuTTY", -#endif -#endif -}; - diff --git a/mac/vsnprint.c b/mac/vsnprint.c deleted file mode 100644 index 0d63a732..00000000 --- a/mac/vsnprint.c +++ /dev/null @@ -1,539 +0,0 @@ - -#include -#include - -#include "putty.h" - -#define __P(decl) decl - -/* XXX */ -typedef unsigned long u_quad_t; -typedef long quad_t; - -typedef unsigned long u_long; -typedef unsigned int u_int; -typedef unsigned short u_short; -typedef long intmax_t; -typedef unsigned long uintmax_t; -typedef long intptr_t; -typedef unsigned long uintptr_t; -typedef int ssize_t; - -#define NBBY CHAR_BIT - -/*- - * Copyright (c) 1986, 1988, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * From NetBSD: subr_prf.c,v 1.86 2002/11/02 07:25:22 perry Exp - * @(#)subr_prf.c 8.4 (Berkeley) 5/4/95 - */ - -/* flags for kprintf */ -#define TOCONS 0x01 /* to the console */ -#define TOTTY 0x02 /* to the process' tty */ -#define TOLOG 0x04 /* to the kernel message buffer */ -#define TOBUFONLY 0x08 /* to the buffer (only) [for snprintf] */ -#define TODDB 0x10 /* to ddb console */ - -/* max size buffer kprintf needs to print quad_t [size in base 8 + \0] */ -#define KPRINTF_BUFSIZE (sizeof(quad_t) * NBBY / 3 + 2) - - -/* - * local prototypes - */ - -static int kprintf __P((const char *, int, void *, - char *, va_list)); - -/* - * vsnprintf: print a message to a buffer [already have va_alist] - */ -int -vsnprintf(buf, size, fmt, ap) - char *buf; - size_t size; - const char *fmt; - va_list ap; -{ - int retval; - char *p; - - if (size < 1) - return (-1); - p = buf + size - 1; - retval = kprintf(fmt, TOBUFONLY, &p, buf, ap); - *(p) = 0; /* null terminate */ - return(retval); -} - - -/* - * kprintf: scaled down version of printf(3). - * - * this version based on vfprintf() from libc which was derived from - * software contributed to Berkeley by Chris Torek. - * - * NOTE: The kprintf mutex must be held if we're going TOBUF or TOCONS! - */ - -/* - * macros for converting digits to letters and vice versa - */ -#define to_digit(c) ((c) - '0') -#define is_digit(c) ((unsigned)to_digit(c) <= 9) -#define to_char(n) ((n) + '0') - -/* - * flags used during conversion. - */ -#define ALT 0x001 /* alternate form */ -#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ -#define LADJUST 0x004 /* left adjustment */ -#define LONGDBL 0x008 /* long double; unimplemented */ -#define LONGINT 0x010 /* long integer */ -#define QUADINT 0x020 /* quad integer */ -#define SHORTINT 0x040 /* short integer */ -#define MAXINT 0x080 /* intmax_t */ -#define PTRINT 0x100 /* intptr_t */ -#define SIZEINT 0x200 /* size_t */ -#define ZEROPAD 0x400 /* zero (as opposed to blank) pad */ -#define FPT 0x800 /* Floating point number */ - - /* - * To extend shorts properly, we need both signed and unsigned - * argument extraction methods. - */ -#define SARG() \ - (flags&MAXINT ? va_arg(ap, intmax_t) : \ - flags&PTRINT ? va_arg(ap, intptr_t) : \ - flags&SIZEINT ? va_arg(ap, ssize_t) : /* XXX */ \ - flags&QUADINT ? va_arg(ap, quad_t) : \ - flags&LONGINT ? va_arg(ap, long) : \ - flags&SHORTINT ? (long)(short)va_arg(ap, int) : \ - (long)va_arg(ap, int)) -#define UARG() \ - (flags&MAXINT ? va_arg(ap, uintmax_t) : \ - flags&PTRINT ? va_arg(ap, uintptr_t) : \ - flags&SIZEINT ? va_arg(ap, size_t) : \ - flags&QUADINT ? va_arg(ap, u_quad_t) : \ - flags&LONGINT ? va_arg(ap, u_long) : \ - flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \ - (u_long)va_arg(ap, u_int)) - -#define KPRINTF_PUTCHAR(C) { \ - if (oflags == TOBUFONLY) { \ - if ((vp != NULL) && (sbuf == tailp)) { \ - ret += 1; /* indicate error */ \ - goto overflow; \ - } \ - *sbuf++ = (C); \ - } \ -} - -/* - * Guts of kernel printf. Note, we already expect to be in a mutex! - */ -static int -kprintf(fmt0, oflags, vp, sbuf, ap) - const char *fmt0; - int oflags; - void *vp; - char *sbuf; - va_list ap; -{ - char *fmt; /* format string */ - int ch; /* character from fmt */ - int n; /* handy integer (short term usage) */ - char *cp; /* handy char pointer (short term usage) */ - int flags; /* flags as above */ - int ret; /* return value accumulator */ - int width; /* width from format (%8d), or 0 */ - int prec; /* precision from format (%.3d), or -1 */ - char sign; /* sign prefix (' ', '+', '-', or \0) */ - - u_quad_t _uquad; /* integer arguments %[diouxX] */ - enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */ - int dprec; /* a copy of prec if [diouxX], 0 otherwise */ - int realsz; /* field size expanded by dprec */ - int size; /* size of converted field or string */ - char *xdigs; /* digits for [xX] conversion */ - char buf[KPRINTF_BUFSIZE]; /* space for %c, %[diouxX] */ - char *tailp; /* tail pointer for snprintf */ - - tailp = NULL; /* XXX: shutup gcc */ - if (oflags == TOBUFONLY && (vp != NULL)) - tailp = *(char **)vp; - - cp = NULL; /* XXX: shutup gcc */ - size = 0; /* XXX: shutup gcc */ - - fmt = (char *)fmt0; - ret = 0; - - xdigs = NULL; /* XXX: shut up gcc warning */ - - /* - * Scan the format for conversions (`%' character). - */ - for (;;) { - while (*fmt != '%' && *fmt) { - ret++; - KPRINTF_PUTCHAR(*fmt++); - } - if (*fmt == 0) - goto done; - - fmt++; /* skip over '%' */ - - flags = 0; - dprec = 0; - width = 0; - prec = -1; - sign = '\0'; - -rflag: ch = *fmt++; -reswitch: switch (ch) { - case ' ': - /* - * ``If the space and + flags both appear, the space - * flag will be ignored.'' - * -- ANSI X3J11 - */ - if (!sign) - sign = ' '; - goto rflag; - case '#': - flags |= ALT; - goto rflag; - case '*': - /* - * ``A negative field width argument is taken as a - * - flag followed by a positive field width.'' - * -- ANSI X3J11 - * They don't exclude field widths read from args. - */ - if ((width = va_arg(ap, int)) >= 0) - goto rflag; - width = -width; - /* FALLTHROUGH */ - case '-': - flags |= LADJUST; - goto rflag; - case '+': - sign = '+'; - goto rflag; - case '.': - if ((ch = *fmt++) == '*') { - n = va_arg(ap, int); - prec = n < 0 ? -1 : n; - goto rflag; - } - n = 0; - while (is_digit(ch)) { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } - prec = n < 0 ? -1 : n; - goto reswitch; - case '0': - /* - * ``Note that 0 is taken as a flag, not as the - * beginning of a field width.'' - * -- ANSI X3J11 - */ - flags |= ZEROPAD; - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } while (is_digit(ch)); - width = n; - goto reswitch; - case 'h': - flags |= SHORTINT; - goto rflag; - case 'j': - flags |= MAXINT; - goto rflag; - case 'l': - if (*fmt == 'l') { - fmt++; - flags |= QUADINT; - } else { - flags |= LONGINT; - } - goto rflag; - case 'q': - flags |= QUADINT; - goto rflag; - case 't': - flags |= PTRINT; - goto rflag; - case 'z': - flags |= SIZEINT; - goto rflag; - case 'c': - *(cp = buf) = va_arg(ap, int); - size = 1; - sign = '\0'; - break; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - _uquad = SARG(); - if ((quad_t)_uquad < 0) { - _uquad = -_uquad; - sign = '-'; - } - base = DEC; - goto number; - case 'n': - if (flags & MAXINT) - *va_arg(ap, intmax_t *) = ret; - else if (flags & PTRINT) - *va_arg(ap, intptr_t *) = ret; - else if (flags & SIZEINT) - *va_arg(ap, ssize_t *) = ret; - else if (flags & QUADINT) - *va_arg(ap, quad_t *) = ret; - else if (flags & LONGINT) - *va_arg(ap, long *) = ret; - else if (flags & SHORTINT) - *va_arg(ap, short *) = ret; - else - *va_arg(ap, int *) = ret; - continue; /* no output */ - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - _uquad = UARG(); - base = OCT; - goto nosign; - case 'p': - /* - * ``The argument shall be a pointer to void. The - * value of the pointer is converted to a sequence - * of printable characters, in an implementation- - * defined manner.'' - * -- ANSI X3J11 - */ - /* NOSTRICT */ - _uquad = (u_long)va_arg(ap, void *); - base = HEX; - xdigs = "0123456789abcdef"; - flags |= HEXPREFIX; - ch = 'x'; - goto nosign; - case 's': - if ((cp = va_arg(ap, char *)) == NULL) - cp = "(null)"; - if (prec >= 0) { - /* - * can't use strlen; can only look for the - * NUL in the first `prec' characters, and - * strlen() will go further. - */ - char *p = memchr(cp, 0, prec); - - if (p != NULL) { - size = p - cp; - if (size > prec) - size = prec; - } else - size = prec; - } else - size = strlen(cp); - sign = '\0'; - break; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - _uquad = UARG(); - base = DEC; - goto nosign; - case 'X': - xdigs = "0123456789ABCDEF"; - goto hex; - case 'x': - xdigs = "0123456789abcdef"; -hex: _uquad = UARG(); - base = HEX; - /* leading 0x/X only if non-zero */ - if (flags & ALT && _uquad != 0) - flags |= HEXPREFIX; - - /* unsigned conversions */ -nosign: sign = '\0'; - /* - * ``... diouXx conversions ... if a precision is - * specified, the 0 flag will be ignored.'' - * -- ANSI X3J11 - */ -number: if ((dprec = prec) >= 0) - flags &= ~ZEROPAD; - - /* - * ``The result of converting a zero value with an - * explicit precision of zero is no characters.'' - * -- ANSI X3J11 - */ - cp = buf + KPRINTF_BUFSIZE; - if (_uquad != 0 || prec != 0) { - /* - * Unsigned mod is hard, and unsigned mod - * by a constant is easier than that by - * a variable; hence this switch. - */ - switch (base) { - case OCT: - do { - *--cp = to_char(_uquad & 7); - _uquad >>= 3; - } while (_uquad); - /* handle octal leading 0 */ - if (flags & ALT && *cp != '0') - *--cp = '0'; - break; - - case DEC: - /* many numbers are 1 digit */ - while (_uquad >= 10) { - *--cp = to_char(_uquad % 10); - _uquad /= 10; - } - *--cp = to_char(_uquad); - break; - - case HEX: - do { - *--cp = xdigs[_uquad & 15]; - _uquad >>= 4; - } while (_uquad); - break; - - default: - cp = "bug in kprintf: bad base"; - size = strlen(cp); - goto skipsize; - } - } - size = buf + KPRINTF_BUFSIZE - cp; - skipsize: - break; - default: /* "%?" prints ?, unless ? is NUL */ - if (ch == '\0') - goto done; - /* pretend it was %c with argument ch */ - cp = buf; - *cp = ch; - size = 1; - sign = '\0'; - break; - } - - /* - * All reasonable formats wind up here. At this point, `cp' - * points to a string which (if not flags&LADJUST) should be - * padded out to `width' places. If flags&ZEROPAD, it should - * first be prefixed by any sign or other prefix; otherwise, - * it should be blank padded before the prefix is emitted. - * After any left-hand padding and prefixing, emit zeroes - * required by a decimal [diouxX] precision, then print the - * string proper, then emit zeroes required by any leftover - * floating precision; finally, if LADJUST, pad with blanks. - * - * Compute actual size, so we know how much to pad. - * size excludes decimal prec; realsz includes it. - */ - realsz = dprec > size ? dprec : size; - if (sign) - realsz++; - else if (flags & HEXPREFIX) - realsz+= 2; - - /* adjust ret */ - ret += width > realsz ? width : realsz; - - /* right-adjusting blank padding */ - if ((flags & (LADJUST|ZEROPAD)) == 0) { - n = width - realsz; - while (n-- > 0) - KPRINTF_PUTCHAR(' '); - } - - /* prefix */ - if (sign) { - KPRINTF_PUTCHAR(sign); - } else if (flags & HEXPREFIX) { - KPRINTF_PUTCHAR('0'); - KPRINTF_PUTCHAR(ch); - } - - /* right-adjusting zero padding */ - if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) { - n = width - realsz; - while (n-- > 0) - KPRINTF_PUTCHAR('0'); - } - - /* leading zeroes from decimal precision */ - n = dprec - size; - while (n-- > 0) - KPRINTF_PUTCHAR('0'); - - /* the string or number proper */ - while (size--) - KPRINTF_PUTCHAR(*cp++); - /* left-adjusting padding (always blank) */ - if (flags & LADJUST) { - n = width - realsz; - while (n-- > 0) - KPRINTF_PUTCHAR(' '); - } - } - -done: - if ((oflags == TOBUFONLY) && (vp != NULL)) - *(char **)vp = sbuf; -overflow: - return (ret); - /* NOTREACHED */ -}