TweetFollow Us on Twitter

Inside Mac XCMD
Volume Number:6
Issue Number:3
Column Tag:XCMD Corner

Related Info: Control Manager Event Manager Resource Manager

Inside Macintosh

By Donald Koscheka, Ernst & Young, MacTutor Contributing Editor

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

“Inside Macintosh” poses a paradox for the Hypercard developer. Hypertalk greatly reduces the stresses and strains of developing a Macintosh application but a quick flip through the pages of Inside Macintosh reveals a wealth of features and capabilities that aren’t available to the script writer. This column attempts to remedy this situation but has focussed in on I/O routines, in part because I/O is where Hypercard is weakest.

The paradox of XCMD programming is that some of the easiest problems are the most difficult to solve. We’ll take as one example, adding a custom control to Hypercard. Before I go into too much detail, I need to warn you. Much of what this column discusses is stuff that ought to be in Hypercard in the first place. I have to believe that some future release will address these issues. Even so, bear with me; there’s still a lot to learn and sometimes going back to the basics can be quite illuminating.

Here is the problem: You want to add a custom control to a Hypercard window, perhaps a horizontal scroll bar. Sounds simple enough so you whip up a little xcmd that calls the toolbox utility “NewControl”. To your bemusement, the control draws correctly but it doesn’t work! Worse yet, the button erases on updates. You dump Hypercard’s window record to discover something even more horrifying - your control is the only object in the control list; Hypercard doesn’t trifle with the control manager.

It turns out that adding a control to the Hypercard window isn’t enough. You need to add a mechanism to track control events by intercepting the event trap (currently GetNextEvent). Although the accompanying code focuses on the control manager, you can modify this technique to manage windows, lists and key events (some of these will be featured in future columns).

By patching GetNextEvent, you can peek at events before Hypercard sees them. You decide whether to pass an event on to Hypercard or to “consume the event”.

Listing 1, Control XFCN.c, creates a control and installs the event patch (if it isn’t already installed). Listing 2 contains the patch which is stored as resource type “EXEC”. Control XFCN installs this patch into the system heap so that we can begin handling events that are germane to the control manager.

In keeping with the tradition of Hypercard, parameters are passed to the XCMD using nomenclature that is as close to human language as possible. For instance, the control type is passed as “Button”, “Check Box”, etc. You can use any names that you like as long as you remember to add them to the STR# resource that represents the “symbol table”.

Listing 3 contains the parsing routines for this symbol table. Entries in this table have two fields, the first is the pattern that needs to be matched, the second is the value that this pattern codes for. If the pattern is “BUTTON”, the corresponding value is 0 since that is the procID of a control button. The value is separated from the pattern by a comma, thus “,” cannot appear in the pattern. To simplify editing, the symbol table is stored as a string, the parser converts the value from a string to a number for you.

Control XFCN takes the following parameters: the control type, the control rect and the control’s title. The header states that the xcmd also accepts the control’s setting, min and max. The “paramtoNum” routine is a simple interface to “StrToNum”. If you want to use my code, I’ve provided two additional files, “HyperUtils.c” and “HyperUtils.h” on this month’s disk.

To code for the standard mac control types, this STR# resource should look like:

BUTTON, 0 \n
CHECKBOX, 1 \n
RADIOBUTTON, 2 \n
SCROLLBAR, 16 \n

The strings are stored in capital letters so that the parse can be case insensitive, we shift any lowercase characters in the pattern. This simple parsing scheme is suitable only for small collections of patterns, it won’t scale very well to very large symbol tables or to more generalized input streams.

Here is an example of how you might add a horizontal scroll bar to Hypercard positioning the thumb at the midway point:

Put NewControl( “SCROLLBAR”, “100, 40, 116, 300”,¬

“MY SCROLL”, 128, 0, 256 ) into theControl

The parse done, we create the control assigning it to the front window. Since our little system requires that the user click on a button in Hypercard to activate the XCMD, we are reasonably assured that Hypercard is the front window. This scheme is not foolproof so you might want to explore ways of making this scheme more robust (I’ll drop a hint later).

I use the concept of appending a resource to the system file for two reasons: it provides a handy place to store information about the patch and such a resource is “globally available”; code in the host stack can communicate with the event patch via this resource. There is a chink in this approach - the system resource gets written out to the file if the stack unexpectedly quits while under multifinder (even if it’s marked as “unchanged”). When the stack runs next, it finds the resource already exists and crashes if the information in that previous invocation isn’t valid. You can make everything whole again by deleting this resource. Better yet, check to see if the resource is in the system file but not loaded into memory, if so, delete the resource, it doesn’t belong there. If the patch installs ok, we save off the old address and the new address in our control information resource .

The patch is now live. The next activation of GetNextEvent will be dispatched to our handler.

Disposing the control requires that we somehow get access to it. Control XFCN returns the control handle as its return value, although it’s better form to store this type of information in the resource that represents our global pool and have Hypercard refer to controls by name (e.g. RemoveControl “OK” ).

Our event handler implements a fairly standard event loop in a fairly non-standard way (see listing 2). The handler starts by setting up A4 as a pointer to our globals. The A4 globals are referenced off the address of the code resource that they were built in, unlike A5 globals which are installed above the application heap by the application launcher. We use a little trick here: register A0 points to the entry point of the EXEC. This implies that the code resource was invoked with the instruction, Jsr (A0). This is nice to know, and I hope Apple doesn’t change this in future manifestations of the toolbox.

A4 is not a free register; we must save off the old contents before moving A0 into A4. We can’t push A4 onto the stack since GetNextEvent is a stack-based routine and we want to keep the stack as clean as possible as we’ll be calling GetNextEvent in just a few brief cycles of the CPU’s clock. So we move the old A4 into a safe place (static oldA4) in our global pool. The static storage class assigns variables to the A4 pool as opposed to the stack. Some programmers prefer to save the oldA4 in some lowmem global like Scratch8 or Scratch20. I’ve never acquired a taste for fiddling with the lowmem globals in this way, I prefer to make room in my own memory pool for my data.

GetNextEvent, like most toolbox routines, unbiases the stack. We need to save the pointer to the event record so that we can look at it AFTER the call to getnextevent. For completeness, we also save off the event mask although EventPatch itself doesn’t use this information.

We saved the address of the actual GetNextEvent in the oldtrap field of resource. We gain access to that resource and then put old trap into A0 for our JSR(A0) call. Now the real (or more accurately, the previous) trap handler will be invoked, cleaning the stack up to the return value which will be pointed to by A7 on return. If the function result of getNextEvent is true, we have an event, otherwise do nothing.

I’ve implemented an update and mousedown method to redraw the controls and to invoke TrackControl . This event loop assumes that the Hypercard window is the front window which may or may not be valid ( here’s the hint: store the windowPtr of your window in your globals. Once in Event patch, compare the front window to our window, if the same,handle the event, if not ignore it).

For the sake of space, I’ve omitted the code for such calls as AddToSystemResource. Such routines are straightforward: Before adding the resource, call useresfile to switch to the system fork. You should also save the oldresource file id and restore it in such calls. If you need this code, it’s on this month’s disk.

When done with a control, you should delete it, when done with all controls, you should remove the patch to getnextevent. Listing 5, RemoveControl, does this. Once we’ve unloaded all controls (controllist goes empty), we remove our patch and then deallocate all memory. TrashHandle unlocks and sets a handle purgeable before disposing it.

That’s the starting point. Play around with the event loop to meet your needs. This example doesn’t provide full support for custom controls in Hypercard. It does provide a mechanism for unlocking the toolbox for anyone who needs access to the event loop.

The following is an apology:

My November column inadvertently identified a MacTutor reader as Joe Palooka. This was not intended in any way as a negative reaction to the letter that this reader sent to the editor. The misidentification was purely mechanical. I write this article while on my daily train ride and I did not have this letter with me when I wrote the article. I used a comic character’s name to remind myself to look up the letter in a back copy of MacTutor (which I’ve misplaced so I still can’t identify the letter’s author). I was up against deadline and the article went out without my properly editing it. I apologize to all readers for this inexcusable error, which was solely my mistake.

I will answer all letters that are sent to me via US mail or via America on line (AFC Donald). My phone manners are terrible. If you call, don’t be offended if I’m somewhat less polite than an AT&T operator. Send your letters to the editor. For faster response, copy me at the following address. Please let the magazine know that you’ve sent me a copy so that they don’t forward a second copy (I hate answering the same question twice).

Donald Koscheka

c/o Ernst & Young

787 Seventh Avenue, 20th Floor

New York, NY 10019

Listing 1:  Control XFCN.c

/************************************/
/* File: Control XFCN.c   */
/* */
/* Parameters:   */
/* params[0] == control type*/
/* params[1] == control Rect*/
/* params[2] == control title */
/* params[3] == control setting    */
/* params[4] == control min */
/* params[5] == control max */
/* */
/* --------------------------------*/
/* © 1989 Donald Koscheka */
/* All Rights Reserved    */
/************************************/

#define UsingHypercard

#include<MacTypes.h>
#include<OSUtil.h>
#include<ControlMgr.h>
#include  <HyperXCmd.h>
#include<HyperUtils.h>
#include“Control XFCN.h”

#define ScrollSize 15
#define CONTROL_TYPES6000
#include“miniParser.c”

pascal void main( paramPtr )
 XCmdBlockPtr  paramPtr;
{
 short  procID   = pushButProc;
 WindowPtrtheWindow= FrontWindow();
 Rect   boundsRect;
 short  min = 0;
 short  max = 1;
 short  value    = 0;
 char   title[256];
 ControlHandle theControl = NIL;
 
 if( paramPtr->params[0] )
 procID = (short)matchToken( paramPtr->params[0], CONTROL_TYPES);
 
 parseRect( paramPtr->params[1], &boundsRect );
 
 paramtoPString( paramPtr, 2, title );
 
 value = (short)paramtoNum( paramPtr, 3 );
 min = (short)paramtoNum( paramPtr, 4 );
 max = (short)paramtoNum( paramPtr, 5 );
 if( !max )
 max = 1;
 
 theControl = NewControl( theWindow, &boundsRect,
 title, TRUE, value, min, max, procID, NIL);

 if( validHandle( theControl ) ){  /* install event patch */
 wdGlobalsHand windH;
 Handle event_handler;    
 Handle sysPlace;
 void   *oldTrap;
 long   hSiz;

 SetCtlValue( theControl, value );
 
 if( !(windH = (wdGlobalsHand)GetSystemResource(CONTROL_INFO, CONTROL_PATCH))){
 windH = (wdGlobalsHand)NewSysHandle((long)sizeof( wdGlobals));
 if( validHandle( (Handle)windH ) ){
 
 /*** 11.26.89   ***/
 AddSystemResource((Handle)windH, CONTROL_INFO, CONTROL_PATCH,”\p control 
record” );
 event_handler = GetResource( ‘EXEC’, CONTROL_PATCH );
 
 if( validHandle( event_handler  ) ){
 /* copy our handler into system heap*/
 hSiz = GetHandleSize( event_handler );
 
 sysPlace = NewHandle( hSiz );
 /* would like this in system heap */
 
 if( validHandle( sysPlace ) ){
 MoveHHi( sysPlace );
 HLock( sysPlace );/* our code can’t move*/
 HNoPurge( sysPlace );  /*must stay put in heap*/
 
 BlockMove( *event_handler, *sysPlace, hSiz );
 
 oldTrap = (void *)NGetTrapAddress( EVENT_TRAP, ToolTrap);
 
 NSetTrapAddress(*sysPlace, EVENT_TRAP, ToolTrap);
 
 /* need to save off oldTrap where */
 /* everyone can find it  */
 (*windH)->evtProc = sysPlace;
 (*windH)->oldTrap = oldTrap;
 (*windH)->userData= NIL; 
 /* initialize this for the user */
 }
 }/*** if validHandle( event_handler ) ***/
 }
 }
 }
 
 paramPtr->returnValue = NumToParam( paramPtr, (long)theControl );
}
Listing 2:  EventPatch.c

/************************************/
/* File: EventPatch.c*/
/* */
/* Patch to get next event*/
/* to allow us to intercept events */
/* from Hypercard. */
/* */
/* check to see if we get the event*/
/* if not, pass it back on, */
/* otherwise, handle the event and */
/* return a null event to Hypercard*/
/* */
/* The real getnextevent will unbias*/
/* the stack parameters so we need */
/* to save them off before we call */
/* the real trap */
/* */
/* The Boolean result of GetNextEvt*/
/* will be at 0(A7) immediately  */
/* after calling the real trap*/
/* */
/* If we took the event, then all we*/
/* need do is set the result of  */
/* GetNextEvent to false. */
/* --------------------------------*/
/* ©1989 Donald Koscheka  */
/* All Rights Reserved    */
/************************************/
#include<SetUpA4.h>
#include<MacTypes.h>
#include<OSUtil.h>
#include<ControlMgr.h>
#include  <HyperXCmd.h>
#include<HyperUtils.h>
#include“Control XFCN.h”

/* NOTE: you can have no stack frames in the */
/* intercept since this is a stack based trap */
/* That is to say, the stack is already biased */
/* correctly for trap -- any local variables */
/* must be declared as statics below, no locals */
/* are allowed in main. */

static  void*returnAddress;
static  EventRecord*theEvent;
static  short    evtMask;
static  short    haveEvt;
static  WindowPtrwhichWindow;
static  short    windoPart;
static  void*oldA4;
static  ProcPtr  oldTrap;
static  Point    thePoint;
static  short    controlPart;
static  ControlHandlewhichControl;
static  wdGlobalsHandwindH;

void main(){
 asm{
 Move.l A4, D0   ; we need to save the old A4
 Move.l A0, A4   ; pointer to our globals.
 Move.l D0, oldA4; note that oldA4 is referenced off A4
 Move.l (A7)+, returnAddress; save real return address...
 Move.l (A7), theEvent  ; save the event record pointer
 Move.w 4(A7), evtMask  ; and the event mask
 }

 windH = (wdGlobalsHand)GetSystemResource( CONTROL_INFO, CONTROL_PATCH 
);
 oldTrap = (*windH)->oldTrap;
 
 asm{   ; left the stack intact for the call
 Move.l oldTrap, A0
 Jsr    (A0)
 Move.b (A7), haveEvt; did we get an event?
 }
 
 whichWindow = FrontWindow();
 
 if(windH && haveEvt && (((WindowPeek)whichWindow)->windowKind != dialogKind) 
 ){
 switch( theEvent->what ){
 case mouseDown:
 
 windoPart = FindWindow(theEvent->where, &whichWindow);
 
 if( windoPart == inContent ){
 thePoint = theEvent->where;
 GlobalToLocal( &thePoint );
 
 if( controlPart = FindControl( thePoint, whichWindow, &whichControl 
)){
 
 /* need to temp unpatch GetNextEvent */
 /* for mouse tracking stuff because some */
 /* tracking calls also call getNextEvent! */
 
 NSetTrapAddress( (*windH)->oldTrap, EVENT_TRAP, ToolTrap);
 
 controlPart = TrackControl(whichControl, thePoint, NIL);
 
 /*** now re-install the patch***/
 NSetTrapAddress( *((*windH)->evtProc), EVENT_TRAP, ToolTrap);
 }

 } /*** if mouse down in our window ***/
 break;
 
 case updateEvt: 
 whichWindow = (WindowPtr)theEvent->message;
 DrawControls( whichWindow );
 break;
 
 default: 
 break;
 } /* switch theEvent->what */
 } /* if haveEvt */
 
 asm{ 
 Move.b haveEvt, (A7)
 Move.l returnAddress, A0
 Move.l oldA4, A4
 Jmp    (A0)
 }
}
Listing 3: MiniParser.c

/********************************/
/* File: ParseCommands.c  */
/* */
/* Parse commands coming in from*/
/* Hypercard.    */
/* */
/* Once the object is parsed, it*/
/* is added to the draw list for*/
/* the window.   */
/* */
/* Eventually need to match */
/* multiple tokens so that we */
/* can have parameters such as:  */
/* BOLD&ITALIC&OUTLINE    */
/* ----------------------------  */
/* © 1989 Donald Koscheka */
/* All Rights Reserved    */
/********************************/
#define CR0x0D
#define NEWLINE  0x0D
#define LF0x0A
#define TAB 0x09
#define ETX 0x03 /* the enter key */

long matchToken( buf, tabl )
 Handle buf;
 short  tabl;
/*******************************
* given an input buffer and the resource 
* id of the parse table, return 
* the token that represents the input
* string.
* A token of 0 is returned if no
* match is found.  This way, you
* can use the first item in the list
* as the default item!
*
* The symbol table should have the 
* format:
*<string>, <token>
* where string mathces to the input
* string and token is that value for 
* a given match.
*******************************/
{
 char *bp;/* pointer to input strings */
 Handle strH;/* handle to parse strings resource */
 long token = 0; /* return default if no match */
 short  indx= 0;
 short  theID;
 ResTypetheType; 
 short  done = 0;
 long len;
 char theNum[31];
 char *np;
 char theName[256];
 char theString[256];
 
 bp = *buf;
 
 while( *bp ){
 toUpper( *bp );
 bp++;
 }
 
 strH   = GetResource( ‘STR#’, tabl );
 
 if( strH ){
 
 GetResInfo( strH, &theID, &theType, &theName );
 
 /*** compare the string to the allowable tokens ***/
 indx = 1 ;
 
 while( !done ){
 theString[0] = ‘\0’;
 GetIndString( &theString, tabl, indx );
 
 if( theString[0] == ‘\0’ ){
 /* no strings matched the input   */
 done = 1;
 }
 else{  /* attempt to match to current str */
 
 PtoCstr( (char *)&theString );
 
 len = 0;
 
 bp = theString;
 while ( *bp != ‘,’ ){
 bp++;
 len++;
 }
 
 if( strncmp( *buf, (char *)theString, len ) == 0){
 /* have a match so extract the token */                       
 
 /* move past any garbage in the string */
 while( (*bp < ‘0’ || *bp > ‘9’) && *bp != ‘-’)
 bp++;
 
 /* now copy what bp points to into a */
 /* a pascal style string */
 
 theNum[0] = ‘\0’;
 np = &theNum[1];
 
 while( *bp >= ‘0’ && *bp <= ‘9’ ){
 theNum[0]++;
 *np++ = *bp++;
 }
 
 /* np is a valid p-string */
 StringToNum( theNum, &token );
 done = 1;
 }
 else
 indx++;
 }
 }
 }
 
 return( token );
}

long  parseNum( bp )
char  *bp;
/***********************
* parse the data stream 
* and return a numeric 
* value.  The stream is null
* terminated.
***********************/
{
 long num = 0;
 
 char theString[256];
 short  done = 0;
 char *ps;
 
 /* move input pointer until we’re looking at a number */
 while( *bp && ( *bp < ‘0’ || *bp > ‘9’ ) && *bp != ‘-’ )
 bp++;
 
 /*** copy the data into a pascal string     ***/
 ps= theString;
 ps++;
 
 while( *bp >= ‘0’ && *bp <= ‘9’ )
 *ps++ = *bp++;
 
 /*** moved one past the output so try this  ***/
 theString[0] = (char)( ps - theString -1  );      
 StringToNum( theString, &num );
 
 return( num );  
}

char  *nextToken( bp )
 char *bp;
/***********************
* given a pointer to an
* input stream, move to the 
* next token in the stream. 
* 
* Token’s are delineated by
* ‘,’ or whitespace
* Assumes we are pointing to the current token
* Move past the current token and the white
* space that follows it.
***********************/
{
 /*** move past the current token  ***/
 while( *bp &&(*bp != ‘,’ && *bp != SPACE && *bp != CR && *bp != LF && 
*bp != TAB) )
 bp++;

 /*** move past the white space to the next token  ***/
 while( *bp == ‘,’ || *bp == SPACE || *bp == CR || *bp == LF || *bp == 
TAB )
 bp++;
 
 return( bp );
}

void  parseRect( buf, theRect )
 Handle buf;
 Rect *theRect;
/***********************
* parse the data stream 
* into a rectangle
*
* default is the NULL rect
***********************/
{
 char *bp;
 
 theRect->top = theRect->left = theRect->bottom = theRect->right = 0;
 
 if( validHandle( buf ) ){
 HLock( buf );
 
 bp = *buf;
 theRect->top = parseNum( bp );
 bp= nextToken( bp );
 
 theRect->left = parseNum( bp );
 bp= nextToken( bp );
 
 theRect->bottom = parseNum( bp );
 bp= nextToken( bp );
 
 theRect->right = parseNum( bp );
 bp= nextToken( bp );
 
 HUnlock( buf );
 }
}
Listing 4:  Control XFCN.h

/************************************/
/* Needed for communication between*/
/* Hypercard and the event loop    */
/************************************/
#define CONTROL_PATCH1001
#define CONTROL_INFO ‘cinf’
#define EVENT_TRAP 0xA970


typedef struct{
 Handle evtProc; /* Points to our event handler */
 ProcPtroldTrap; /* previous address of event trap */
 Handle userData;/* for use by the application */
} wdGlobals, *wdGlobalsPtr, **wdGlobalsHand;
Listing 5:  RemoveControl XFCN.c

/************************************/
/* File: RemoveControl XFCN.c */
/* */
/* Parameters:   */
/* params[0] == control handle*/
/* */
/* If no more control in the list  */
/* go ahead and dispose the patch  */
/* */
/* returns NIL to indicate the     */
/* control was removed    */
/* --------------------------------*/
/* © 1989 Donald Koscheka */
/* All Rights Reserved    */
/************************************/
#define UsingHypercard

#include<MacTypes.h>
#include<OSUtil.h>
#include<ControlMgr.h>
#include  <HyperXCmd.h>
#include<HyperUtils.h>
#include“Control XFCN.h”

#define ScrollSize 15
#define CONTROL_TYPES6000

#include“miniParser.c”

pascal void main( paramPtr )
 XCmdBlockPtr  paramPtr;
{
 ControlHandle theControl = NIL;
 WindowPtrtheWindow= FrontWindow();
 WindowPeek wPeek= (WindowPeek)theWindow;
 wdGlobalsHand windH;
 
 if( paramPtr->params[0] ){
 theControl = (ControlHandle)paramtoNum( paramPtr, 0 );
 
 if( validHandle( theControl ) )
 DisposeControl( theControl );

 }/*** if paramPtr[0] ***/

 /*** if no more control in the list ***/
 /*** remove the patch since it isn’t***/
 /*** needed any longer   ***/
 if( !wPeek->controlList ){
 if( windH = (wdGlobalsHand)GetSystemResource( CONTROL_INFO, CONTROL_PATCH 
) ){
 wdGlobalsPtr  wp  = *windH;
 Handle patch  = (Handle)(wp->evtProc);
 
 /*** unload the patch  ***/
 NSetTrapAddress( wp->oldTrap, EVENT_TRAP, ToolTrap);
 TrashHandle( patch );
 RemoveSystemResource( (Handle)windH );
 } 
 }

 paramPtr->returnValue = NIL;
}
Listing: 6:  HyperUtils.c

/********************************************************/
/* HyperUtils.c    */
/*      */
/* A collection of useful   */
/* routines...     */
/* --------------------------------------------------*/
/* 10/23/89 Added Routines to Support HyperAppleTalk */
/********************************************************/
#include<MacTypes.h>
#include<OSUtil.h>
#include<MemoryMgr.h>
#include<FileMgr.h>
#include<ResourceMgr.h>
#include<StdFilePkg.h>
#include  <HyperXCmd.h>
#include  <HyperUtils.h>


#define UsingHypercard

#ifdef  UsingHypercard

/****************************************************/
/* -- HyperCard UTILITIES --*/
/****************************************************/

void  paramtoPString( paramPtr, i, str )
 XCmdBlockPtr  paramPtr;
 short  i;
 char   *str;
/************************
* Given an index into the 
* parameter list, convert the data
* in the handle into a pstring
*
* 10.25.89 DK if handle empty, return empty.
************************/
{
 HLock( paramPtr->params[i] );
 ZeroToPas( paramPtr, (char *)*(paramPtr->params[i]), (char *)str );
 HUnlock( paramPtr->params[i] );
}

long  paramtoNum( paramPtr, i )
 XCmdBlockPtr  paramPtr;
 short  i;
/************************
* Given a handle to an input
* argument in the paramBlk
* return an integer representation
* of the data.
*
* 10.25.89 DK if handle empty, return empty.
************************/
{
 Str31  theStr;
 
 theStr.data[0] = ‘\0’;
 
 if( paramPtr->params[i] ){
 HLock( paramPtr->params[ i ] );
 ZeroToPas( paramPtr, (char *)*(paramPtr->params[ i ]), (char *)&theStr 
);
 HUnlock( paramPtr->params[ i ] );
 }
 return( StrToLong( paramPtr, (char *)&theStr ) );
}

Handle  NumToParam( paramPtr, num )
 XCmdBlockPtr  paramPtr;
 long   num;
/************************
* Given a long,  return a
* Handle to a string
* representation of the data.
************************/
{
 Str31  theStr;
 
 NumToStr( paramPtr, num, (char *)&theStr );
 
 return( PasToZero( paramPtr, (char *)&theStr ) );
}

#endif

/****************************************************/
/* -- Generic UTILITIES --*/
/* */
/* Routines that do generic things like allocate*/
/* memory in the system heap*/
/****************************************************/

void  *sys_alloc( len )
 long len;
/***************************
* Return a chunk of system heap
* requested (len bytes)
***************************/
{
 asm{
        move.l  len, D0
        NewPtr SYS
        move.l  A0, D0
      }
}

Handle  NewSysHandle( len )
 long len;
/***************************
* allocate a handle in the 
* system heap.  
*
* requested (len bytes)
*
* 10.31.89 added this routine to file
***************************/
{
 asm{
        move.l  len, D0
        NewHandleSYS
        move.l  A0, D0
      }
}

short validHandle( h )
 void *h;
/***************************
* This will be my handle checker
* in the future.  Right now, all 
* it does is check to see if the
* handle is nil.
* 
* In the future, I will use
* the information in the header
* to determine if the handle is
* a valid reference in the heap.
*
* (need to make sure this works
* across heap zones).
***************************/
{
 if( h )  
 return( TRUE );
 else
 return( FALSE );
}

void  TrashHandle( h )
 Handle h;
/***************************
* if the handle passed in is not
* NIL, unlock the handle and 
* dispose its contents
*
* ADD A TEST FOR VALID HANDLE!!!
*
* 10.31.89 sets it purgeable first
***************************/
{
 if( validHandle( h ) ){
 HPurge( h );
 HUnlock( h );
 DisposHandle( h );
 }
}

Handle  GetSystemResource( typ, id )
 ResTypetyp;
 short  id;
/***************************
* Load a resource from the system
* resources. Returns nil if handle
* not available.
*
* DEBUG: Return nil if the resource
* is unallocated (size == 0).
*
* 10.31.89 sets it purgeable first
***************************/
{
 short  oldRes = CurResFile();
 Handle h = NIL;

 UseResFile( SYS_RES );
 h = GetResource( typ, id );
 
 if( GetHandleSize( h ) == 0 )
 h = NIL;
 
 UseResFile( oldRes );
 
 return( h );
}

void  RemoveSystemResource( h )
 Handle h;
/***************************
* Remove the specified resource
* from the system resource file
*
* the handle is deleted from 
* memory and its reference in the
* resource map is removed.
***************************/
{
 short  oldRes = CurResFile();

 if( validHandle( h ) ){
 HPurge( h );
 HUnlock( h );

 UseResFile( SYS_RES );
 RmveResource( h );
 UpdateResFile( SYS_RES );
 
 UseResFile( oldRes );
 TrashHandle( h );
 }
}

void  AddSystemResource( h, typ, id, name )
 Handle h;
 ResTypetyp;
 short  id;
 char *name;
/***************************
* Given a handle to something,
* allocate the something as a 
* resource in the system file.
*
* Note that the resource gets
* locked down (this is a special
* routine that is used to allocate
* pseudo-global data.
*
* EVENTUALLY: WANT TO RETURN THE 
* ID SO THAT YOU CAN MAKE SURE YOU
* ALLOCATE A UNIQUE ID EACH TIME!!!
* THEN THE ID CAN BECOME A TASK
* REFERENCE NUMBER!!!
***************************/
{
 short  oldRes = CurResFile();
 short  attributes;
 
 if( validHandle( h ) ){
 MoveHHi( h );
 HLock( h );
 HNoPurge( h );

 UseResFile( SYS_RES );
 AddResource( h, typ, id, name );

 /*** test ***/
 /*** don’t want this resource written out ***/
 attributes = GetResAttrs( h );
 SetResAttrs( h, attributes & 0xfffe );

 UseResFile( oldRes );
 }
}

void  AppendCharToHandle( theHand, theChar )
 Handle theHand;
 char theChar;
/****************************
* Given a valid handle, append
* the character passed in to 
* the end of the handle
* 
* This is a useful way to embed
* \r, \t or \0 into a container
* for use by hypercard.
****************************/
{
 long   hsiz = GetHandleSize( theHand );

 SetHandleSize( theHand, hsiz + 1 );
 *(*theHand + hsiz) = theChar;
}

void  appendChar( theStr, theChar )
 char *theStr;
 char theChar;
/************************
* append the character passed
* to the end of the string 
************************/
{
 long len = strlen( theStr );
 char *theEnd;

 theEnd = theStr + len;
 *theEnd++  = theChar;
 *theEnd  = ‘\0’;
}

char  *CopyAscii( outStr, theChar )
 char *outStr;
 char theChar;
/************************
* if the character passed  
* in the input stream is a 
* printing character, append
* it to the output string,
* otherwise, append the ‘.’
* return the update output 
* string.
************************/
{
 if ( theChar >= SPACE  &&  theChar <= 0x0D8  ) 
 *outStr++ = theChar;
 else
 *outStr++ = ‘.’;
 
 return( outStr );
}
 
void CopyStrToHandle( theStr, hand )
 char *theStr;
 Handle hand;
/************************
* Copy the input data to the
* output handle.
*
* The input string is a “C”
* string.
************************/
{
 long cnt = strlen( theStr );
 long oldSize  = GetHandleSize( hand );

 SetHandleSize( hand, oldSize + cnt );
 BlockMove( theStr, *hand + oldSize, cnt );
}

void CopyDataToHandle( theStr, theLen, theHand, delim )
 char *theStr;
 long theLen;
 Handle theHand;
 char delim;
/************************
* Copy the input data to the
* output handle and append
* the requested character to
* the data.
************************/
{
 long oldSize  = GetHandleSize( theHand );

 SetHandleSize( theHand, oldSize + theLen );
 BlockMove( theStr, *theHand + oldSize, theLen );
 AppendCharToHandle( theHand, delim );
}

short pstrcmp( s1, s2 )
 char *s1;
 char *s2;
/************************
* Compare the two pascal strings
* passed in regardless of case.
*
* returning:
*FALSE  == don’t match
*  TRUE == do match
* 
* We first check to see if 
* both strings are the same
* length.  If not, no sense
* in proceeding.
************************/
{
 short  i;
 short  test= TRUE;
 short  len = (short)*s1;
 register char *str1 = s1;
 register char *str2 = s2;
 
 for( i = 0; i <= len; i++ )
 if( toUpper( *str1 ) == toUpper( *str2 ) ){
 str1++;
 str2++;
 }
 else{
 test = FALSE;
 break;
 }
 
 return( test );
}

short pStrToField( str, delim, list )
 char *str; 
 char delim;
 Handle list;
/*********************************
* Given a pascal string, append it to
* the end of the handle passed in list
* which is assumed to be a valid handle
* of length >= 0.
*
* delim is some character to stick on the
* end of the string to delimit it.
* if you want to build a list for presentation
* in a field, pass ‘\r’ as the delimiter
*
* If you are building items pass a comma
* 
* A value of 0 for delim is ignored.  Pass
* 0 when you don’t want a delimiter.
*********************************/
{
 long   strlen;  /* length of input string   */
 long   oldHSize;/* size of input handle     */
 char   *end;  /* pointer to end of data           */
 
 if( validHandle( list ) ){
 strlen = (long)str[0];   
 oldHSize = GetHandleSize( list );
 
 SetHandleSize( list, oldHSize + strlen );
 end = *list + oldHSize;
 
 BlockMove( (char *)&str[1] , end, strlen );
 AppendCharToHandle( list, delim );
 }
}

void  DataToField( str, len, delim, list )
 char *str; 
 short  len;
 char delim;
 Handle list;
/*********************************
* copy <len> bytes from the input
* stream to the output handle and
* append char <delim> to the end of 
* output handle.
*
* delim is some character to stick on the
* end of the string to delimit it.
* if you want to build a list for presentation
* in a field, pass ‘\r’ as the delimiter
*
* If you are building items pass a comma
* 
* A value of 0 for delim is ignored.  Pass
* 0 when you don’t want a delimiter.
*********************************/
{
 long   oldHSize;/* size of input handle */
 char   *end;  /* pointer to end of data     */
 
 if( validHandle( list ) ){
 oldHSize = GetHandleSize( list );
 
 SetHandleSize( list, oldHSize + len );
 end = *list + oldHSize;
 
 BlockMove( str, end, len );
 AppendCharToHandle( list, delim );
 }
}

void ClimbTree( child, cpb, fullName )
 long   child;
 CInfoPBPtr cpb;
 char   *fullName;
/*************************
* Climb the directory tree
* until we reach the root
*
* Allocate the records in the
* heap to keep the stack frame
* as small as necessary.  Too
* large a stack frame can 
* lead to a case of terminal
* terminal.
*
* child is the working directory
* id of the “current folder”, vol
* is the volume reference number and
* fullName points to the 
* output string
*************************/
{
 StringPtrfolder_name= (StringPtr)NewPtr( 256 );
 char   colon[2];
 
 colon[0] = ‘\1’;
 colon[1] = ‘:’;
 
 /* setting the file directory index to -1 */
 /* lets us get information about the */
 /* directory whose id is specified in the */
 /* ioDrDIrID field of the parameter block */
 folder_name[0] = ‘\0’; 
 
 cpb->dirInfo.ioNamePtr   = (StringPtr)folder_name;
 cpb->dirInfo.ioDrDirID   = child; 

 if( PBGetCatInfo( cpb, 0) == noErr ){
 ClimbTree(cpb->dirInfo.ioDrParID,cpb,fullName);

 Concat( (char *)fullName, (char *)folder_name );
 Concat( (char *)fullName, (char *)&colon );
 }
 DisposPtr( folder_name   );
}

void  CenterWindow( wptr )
 WindowPtrwptr;
/***************************
* Center a window in the current
* screen port.  Note: Does not
* attempt to work with multi-screen
* systems.
*
* This code is inspired by a
* similar routine written by Steve
* Maller in MPW Pascal.  Thanks Steve.
***************************/
{
 short  hWindSize = wptr->portRect.right - wptr->portRect.left;
 short  vWindSize = wptr->portRect.bottom - wptr->portRect.top;
 short  hSize = wptr->portBits.bounds.right - wptr->portBits.bounds.left;
 short  vSize = wptr->portBits.bounds.bottom - wptr->portBits.bounds.top;
 
 MoveWindow( wptr, ( hSize - hWindSize ) / 2, 
 ( vSize - vWindSize + 20) / 2, false);
}

void Concat( str1, str2 )
 char *str1;
 char *str2;
/*****************************
* Append string 2 to the end of
* string 1.  Both strings are 
* pascal-format strings.
*
* str1 must be large enough to hold
* the new string and is assumed to 
* be of Type Str255 (a pascal string)
*****************************/
{
 short len1 = *str1; /* number of chars in string 1 */
 short len2 = *str2++; /* number of chars in string 2 */
 char  *temp;  /* string pointer   */
 
 if( len1 +len2  > 255 )
 len2 = 255 - len1;
 
 *str1++ += len2 ; /* add sizes together to get new size */
 
 temp = str1 + len1; /* move to the end of string 1 */
 while( len2 ){
 *temp++ = *str2++;/* add a char to temp and move along */
 --len2; /* until all characters are added */
 }
}

void  CopyPStr( pStr1, pStr2 )
 char *pStr1;
 char *pStr2;
/****************************
* Copy the contents of pstr1 into
* pstr2.  The strings are assumed 
* to be of type STR255 (length byte
* precedes data 
****************************/
{short  i;
 char *tstr;
 
 tstr = pStr2;
 
 for( i = 0; i <= *pStr1; i++ )
 *tstr++ = *pStr1++;
}

short GetFileNameToOpen( typs, typCnt,theName, theWDID )
 SFTypeList typs;
 short  typCnt;
 char   *theName;
 short  *theWDID;
/*****************************
* Invokes SFOpenFile to query the 
* user for the name of a file to 
* open. 
*
* In:   List of types of files to
*filter for (up to 4)
*
* Out:  fileName if picked in theName
*working directory in theWDID
*nil otherwise
*the file’s volum ref num.
*
* ( Note that the space for the 
* string must be allocated by the
* caller).
*****************************/
{
 Point  where;
 char   prompt[1];
 SFReplyreply;
 GrafPort *oldPort;
 WindowPtrdlogID;
 
 prompt[0]  = ‘\0’;
 
 /*** Get and put up the standard file ***/
 /*** dialog.  You will only see the file***/
 /*** types that you filtered for.  If ***/
 /*** you filtered for no files, then  ***/
 /*** all files will display***/
 
 GetPort( &oldPort );
 dlogID = GetNewDialog( (short)getDlgID, (Ptr)NIL, (Ptr)UPFRONT );
 
 SetPort( dlogID );
 CenterWindow( dlogID );
 where.h = dlogID->portRect.left;
 where.v = dlogID->portRect.top;
 LocalToGlobal( &where );
 
 SFGetFile( where, prompt, (Ptr)NIL, typCnt, typs, (Ptr)NIL, &reply );
 
 DisposDialog( dlogID );
 SetPort( oldPort );
 
 /*** If the user selected a file, let’s ***/
 /*** get the information about it ***/
 
 if (reply.good){
 *theWDID = reply.vRefNum;
 PtoCstr( (char *)&reply.fName );
 strcpy( theName, &reply.fName  );
 }
 return( reply.good );
}

OSErr CopyFork( inref, outref, siz )
 short  inref;
 short  outref;
 long siz;
/*****************************
* Given that the caller has opened
* a fork and passed you the names of 
* the input, copy the number of bytes
* from the input fork to the output 
* fork.
*
* The input mark should be set to 
* start of fork.
* We use a “semi-smart” algorithm
* to do the copy.  If the entire
* fork can be copied, we try doing 
* that, otherwise, we keep dividing
* the size by two until we get enough
* room to read some data in.
*
******************************/
{
 OSErr  rd_err   = noErr;
 OSErr  wrt_err  = noErr;
 long rd_len;    /*** actual bytes read in   ***/
 Ptr    inbuf;
 
 /*** make sure that the size is even  ***/
 if( siz % 2 )
 ++siz;
 
 if( siz > 0 ){
 do{
 inbuf = NewPtr( siz );
 if( !inbuf )
 siz = ( siz >> 1 );
 
 }while( !inbuf );
 
 /* inbuf is the buffer that we read into    ***/
 /*** it ***/
 if( inbuf ){
 do{
 rd_len = siz;
 rd_err = FSRead( inref, &rd_len, inbuf );
 wrt_err= FSWrite( outref, &rd_len, inbuf );
 }while( !rd_err && !wrt_err );
 
 DisposPtr( inbuf );
 }
 }
 return( wrt_err );
}

OSErr CopyFile( inFile, inWD, outFile, outWD )
 char *inFile;
 short  inWD;
 char *outFile;
 short  outWD;
/*****************************
* (1) Determine the size of the input 
* file. 
*
* (2) Attempt to allocate that 
* much space for the output file.
*
* (3) If allocation successful,
* create the output file.
*
* (4) Once the file is created,
* copy the data fork, the resource
* fork and the finder information
* from the input file.
* 
* The file will be called “copy of...”
* Each time we create the file, first
* see if that name exists, if so, keep
* sticking “copy of” onto the name.
******************************/
{
 OSErr  err;
 OSErr  err2;
 short  inref;
 short  outref;
 long   data_eof = 0L;
 long   rsrc_eof = 0L;
 FInfo  fndrinfo;
 short  vref;  /** volume the file is on     ***/
 
 /* (2) Determine how big the input file is */
 if( (err = FSOpen( inFile, inWD, &inref )) == noErr){
 err = GetEOF( inref, &data_eof );
 err = FSClose( inref );
 } 
 
 if( (err = OpenRF( inFile, inWD, &inref )) == noErr ){
 err = GetEOF( inref, &rsrc_eof );
 err = FSClose( inref );  
 }
 
 /* (2) Create  output file and allocate space */
 if( ( err = GetFInfo( inFile, inWD, &fndrinfo ) ) != noErr )
 return( err );
 
 if( ( err = Create( outFile, inWD, fndrinfo.fdCreator, fndrinfo.fdType 
)) != noErr )
 return( err );
 
 /* (3) Try to allocate enough space for both */
 /* forks. Note that if we get enough space. */
 
 if( (err = FSOpen( outFile, outWD, &outref )) != noErr)
 return( err );
 
 if( (err = SetEOF( outref, data_eof  )) != noErr ){
 err2 = FSClose( outref );
 err2 = FSDelete( outFile, outWD );
 return( err );
 }

 err2   = FSClose( outref );
 err  = OpenRF( outFile, outWD, &outref );
 
 if( (err = SetEOF( outref, rsrc_eof  )) != noErr ){
 err2 = FSClose( outref );
 err2 = FSDelete( outFile, outWD );
 return( err );
 }
 err2 = FSClose( outref );
 
 /*** (4) Copy the Data fork***/
 err  = FSOpen( inFile, inWD, &inref );
 
 if( !err ){
 err2   = SetFPos( inref, fsFromStart, 0L );
 err    = CopyFork( inref, outref, data_eof );
 err2   = FSClose( inref );
 err2   = FSClose( outref );
 }
 
 if( err ){
 err2 = FSDelete( outFile, outWD );
 return( err );
 }
 
 /*** (5) Now copy the resource fork ***/
 err  = OpenRF( inFile, inWD, &inref );
 
 if( !err ){
 err2   = SetFPos( inref, fsFromStart, 0L );
 err  = OpenRF( outFile, outWD, &outref );
 err    = CopyFork( inref, outref, rsrc_eof );
 err2   = FSClose( inref );
 err2   = FSClose( outref );
 }
 
 if( err ){
 err2 = FSDelete( outFile, outWD );
 return( err );
 }
 
 return( noErr );
}

/*** 10/23/89 ***/
#ifdef  UsingHypercard

void SaveHandle(paramPtr, containerName, theData)
 XCmdBlockPtr  paramPtr;
 Handle containerName;
 long   theData;
/**********************************
* Saves a long integer (handle) away 
* in the Hypercard global container 
* whose name is passed as a parameter. 
* containerName is a Handle containing
* a null terminated string.
*
* IN: 
* containerName  =the name of
*a Hypercard container
* theData = the handle to store
*in this container.
**********************************/
{
 Handle theDataHand;
 char pasStr[256];
 char   buffHandle[256];

 buffHandle[0] = ‘\0’;
 
 /*** convert the data into a string since   ***/
 /*** that is the friendliest form for HC    ***/
 LongToStr( paramPtr, theData, (char *)&buffHandle );
 theDataHand = PasToZero( paramPtr, (char *)buffHandle );
 
 /*** convert the name to a string ***/
 HLock( containerName );
 ZeroToPas( paramPtr, *containerName, (char *)&pasStr);

 SetGlobal( paramPtr, pasStr, theDataHand );
 HUnlock( containerName );
}

void PutEmptyIntoGlobal(paramPtr, containerName)
 XCmdBlockPtr  paramPtr;
 Handle containerName;
/**********************************
* Sets the given global to the empty
* container.
*
* IN: 
* containerName  =the name of
*a Hypercard container
**********************************/
{
 Handle theDataHand;
 char pasStr[256];
 char   buffHandle[256];

 buffHandle[0] = ‘\0’;
 
 /*** convert the data into a string since   ***/
 /*** that is the friendliest form for HC    ***/
 theDataHand = PasToZero( paramPtr, (char *)buffHandle );
 
 /*** convert the name to a string ***/
 HLock( containerName );
 ZeroToPas( paramPtr, (char *)*containerName, (char *)&pasStr);

 SetGlobal( paramPtr, pasStr, theDataHand );
 HUnlock( containerName );
}

long RetrieveHandle(paramPtr, containerName )
 XCmdBlockPtr  paramPtr;
 Handle containerName;
/**********************************
* Retrieve a handle from the Hypercard
* global pool.  The name of the global 
* container is passed as a parameter
*
* If no data could be extracted from the
* container, we return empty.
**********************************/
{
 Handle theData; /* handle to the data as string */
 char   localString[256];
 long   returnHandle = 0L;
 
 if( containerName ){
 HLock( containerName );  
 ZeroToPas( paramPtr, (char *)*containerName, (char *)&localString );
 theData = GetGlobal( paramPtr, (char *)&localString ); 
 HUnlock( containerName );
 
 if ( theData ){
 MoveHHi( theData );
 HLock( theData );
 ZeroToPas( paramPtr, *theData, (char *)&localString );
 returnHandle = StrToLong( paramPtr, (char *)&localString);
 TrashHandle( theData );
 return( (long)returnHandle );
 }
 }
 
 return( 0L );
}

Handle ErrorReturn( theErr )
 short theErr;
/**********************************
* Given a system error number in theErr
* extract its string from the resource
* fork and returns it to HyperCard
*
* If we can’t work out the error string,
* build one using the error number.
**********************************/
{
 Handle strhand = NIL;
 char s[256];
 char num[256];
 long len = 0;
 
 if(theErr == noErr)
 return( NIL );

 *s = ‘\0’;
 
 strhand = GetResource( ‘STR ‘, theErr );
 if( strhand ){
 /* copy the string to another handle and save it off */
 len = GetHandleSize( strhand );
 BlockMove( *strhand, s, len );
 PtoCstr( (char *)&s );
 }
 else{
 s[0]=’E’; s[1]=’R’; s[2]=’R’; s[3]=’O’; s[4]=’R’; s[5]=’ ‘; s[6]=’\0';
 NumToString( (long)theErr, num );
 sappend( s, num );
 len = (long)slength( s );
 }
 
 if( *s ){
 strhand = NewHandle( len );
 BlockMove( s, *strhand, len );
 }
 return( strhand );
}

/*    Miscellaneous Support Routines */

void pStrCopy( inStr,outStr )
 char *inStr, *outStr;
/*********************************
* copy the pascal-style string from
* the input string to the output 
* string.
*********************************/
{
 short i;
 
 for (i = 0; i <= inStr[0]; i++)
 outStr[i] = inStr[i];
}

short slength( str )
 char *str;
/*********************************
* return the length of a c string
* including the ‘\0’ byte. 
*********************************/
{
 short i = 0;
 
 while( *str++ )
 i++;
 
 return( (i+1) );
}

short strcopy( dst, src )
 char *dst, *src;
/*********************************
* Copy a “C” string to another
* “C” string. 
*********************************/
{
 while( *dst++ = *src++ );
}

short sappend( dst, src )
 char  *dst, *src;
/*********************************
* NOTE: the destination
* string must be large enough to hold
* both strings going in!
*
* tacks source onto destination.
*********************************/
{
 while( *dst )
 dst++;
 while( *dst++ = *src++ );
}

short strCMP( s1, s2 )
 char *s1, *s2;
/*********************************
* compare two c strings regardless
* of case returning:
*
* <0 if s1 < s2
* 0  if s1 == s2
* >0 if s1 > s2
*********************************/
{
 for( ; toUpper( *s1 ) == toUpper( *s2 ); s1++, s2++ )
 if( *s1 == ‘\0’ )
 return( 0 );
 
 return( *s1 - *s2 );
}

#endif

Listing 7:  HyperUtils.H

/********************************/
/* HyperUtils.H  */
/* */
/* Header file for HyperUtils.c  */
/* routines...   */
/* */
/********************************/
#define UPFRONT  -1L
#define SPACE    32
#define SYS_RES  0 /* resource id of the system */

#ifndef NIL  /* standard definition of NIL   */
 #define NIL ( (void *)0 )
#endif

#ifndef empty   /* an alias for nil */
 #define empty ( (void *)0 )
#endif

#define isUpper( c ) ( (c >= ‘A’ && c <= ‘Z’) ? 1 : 0 )
#define isLower( c ) ( (c >= ‘a’ && c <= ‘z’) ? 1 : 0 )
#define toUpper( c ) ( (isLower( c )) ? c - ‘a’ + ‘A’: c )
#define toLower( c ) ( (isUpper( c )) ? c + ‘a’ - ‘A’: c )
#define isAlpha( c ) ( ((c >= ‘A’ && c <= ‘Z’) || (c >= ‘a’ && c <= ‘z’)) 
? 1 : 0 )

#ifdef UsingHypercard
void  paramtoPString( XCmdBlockPtr paramPtr, short i, char *n);
long  paramtoNum();
Handle  NumToParam( XCmdBlockPtr paramPtr, long num );
#endif

void  *sys_alloc( long len );
short validHandle( void *h );
void  TrashHandle( Handle h );
Handle  NewSysHandle( long len );
Handle  GetSystemResource( ResType typ, short id );
void  RemoveSystemResource( Handle h );
void  AddSystemResource( Handle h, ResType typ, short id, char *name 
);

void  appendChar( char *theStr, char theChar );
void  CopyStrToHandle( char *theStr, Handle hand );
void  CopyDataToHandle( char *theData, long theLen, Handle theHand, char 
delim );
char  *CopyAscii( char *outStr, char theChar );
void  AppendCharToHandle( Handle theHand, char theChar );

short pStrToField( char *str, char delim, Handle list );
void  DataToField( char *str, short len, char delim, Handle list );

void  ClimbTree( long child, CInfoPBPtr cpb, char *fullName );
void  CenterWindow( WindowPtr wptr );
void  Concat( char * str1, char * str2 );
void  CopyPStr( char * pStr1, char * pStr2 );
short GetFileNameToOpen(SFTypeList typs,short typcnt, char *theName, 
short *theWDID);
OSErr CopyFile( char *inFile, short inWD, char *outFile, short outWD 
);

Handle  ErrorReturn( OSErr theErr );

 
AAPL
$467.36
Apple Inc.
+0.00
MSFT
$32.87
Microsoft Corpora
+0.00
GOOG
$885.51
Google Inc.
+0.00

MacTech Search:
Community Search:

Software Updates via MacUpdate

VueScan 9.2.23 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Acorn 4.1 - Bitmap image editor. (Demo)
Acorn is a new image editor built with one goal in mind - simplicity. Fast, easy, and fluid, Acorn provides the options you'll need without any overhead. Acorn feels right, and won't drain your bank... Read more
Mellel 3.2.3 - Powerful word processor w...
Mellel is the leading word processor for OS X, and has been widely considered the industry standard since its inception. Mellel focuses on writers and scholars for technical writing and multilingual... Read more
Iridient Developer 2.2 - Powerful image...
Iridient Developer (was RAW Developer) is a powerful image conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
Delicious Library 3.1.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Epson Printer Drivers for OS X 2.15 - Fo...
Epson Printer Drivers includes the latest printing and scanning software for OS X 10.6, 10.7, and 10.8. Click here for a list of supported Epson printers and scanners.OS X 10.6 or laterDownload Now Read more
Freeway Pro 6.1.0 - Drag-and-drop Web de...
Freeway Pro lets you build websites with speed and precision... without writing a line of code! With it's user-oriented drag-and-drop interface, Freeway Pro helps you piece together the website of... Read more
Transmission 2.82 - Popular BitTorrent c...
Transmission is a fast, easy and free multi-platform BitTorrent client. Transmission sets initial preferences so things "Just Work", while advanced features like watch directories, bad peer blocking... Read more
Google Earth Web Plug-in 7.1.1.1888 - Em...
Google Earth Plug-in and its JavaScript API let you embed Google Earth, a true 3D digital globe, into your Web pages. Using the API you can draw markers and lines, drape images over the terrain, add... Read more
Google Earth 7.1.1.1888 - View and contr...
Google Earth gives you a wealth of imagery and geographic information. Explore destinations like Maui and Paris, or browse content from Wikipedia, National Geographic, and more. Google Earth... Read more

Meet Daniel Singer, the Thirteen-Year-Ol...
Ever had the idea for an app, but felt like the lack of programming and design ability was a bit of a non-starter? Well, 13-year-old Daniel Singer has made an app. He’s the designer of Backdoor, a chat app that lets users chat with their friends... | Read more »
Flashout 2 Gets Revealed, Offers Up An E...
Flashout 2 Gets Revealed, Offers Up An Enhanced Career Mode and Exciting New Circuits Posted by Andrew Stevens on August 13th, 2013 [ permalink ] | Read more »
Mickey Mouse Clubhouse Paint and Play HD...
Mickey Mouse Clubhouse Paint and Play HD Review By Amy Solomon on August 13th, 2013 Our Rating: :: 3-D FUNiPad Only App - Designed for the iPad Color in areas of the Mickey Mouse Clubhouse with a variety of art supplies for fun 3-... | Read more »
Strategy & Tactics: World War II Upd...
Strategy & Tactics: World War II Update Adds Two New Scenarios Posted by Andrew Stevens on August 12th, 2013 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Expenses Planner Review
Expenses Planner Review By Angela LaFollette on August 12th, 2013 Our Rating: :: PLAIN AND SIMPLEUniversal App - Designed for iPhone and iPad Expenses Planner keeps track of future bills through due date reminders, and it also... | Read more »
Kinesis: Strategy in Motion Brings An Ad...
Kinesis: Strategy in Motion Brings An Adaptation Of The Classic Strategic Board Game To iOS Posted by Andrew Stevens on August 12th, 2013 [ | Read more »
Z-Man Games Creates New Studio, Will Bri...
Z-Man Games Creates New Studio, Will Bring A Digital Version of Pandemic! | Read more »
Minutely Review
Minutely Review By Jennifer Allen on August 12th, 2013 Our Rating: :: CROWDSOURCING WEATHERiPhone App - Designed for the iPhone, compatible with the iPad Work together to track proper weather conditions no matter what area of the... | Read more »
10tons Discuss Publishing Fantasy Hack n...
Recently announced, Trouserheart looks like quite the quirky, DeathSpank-style fantasy action game. Notably, it’s a game that is being published by established Finnish games studio, 10tons and developed by similarly established and Finnish firm,... | Read more »
Boat Watch Lets You Track Ships From Por...
Boat Watch Lets You Track Ships From Port To Port Posted by Andrew Stevens on August 12th, 2013 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »

Price Scanner via MacPrices.net

15″ 2.3GHz MacBook Pro (refurbished) availabl...
 The Apple Store has Apple Certified Refurbished 15″ 2.3GHz MacBook Pros available for $1449 or $350 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. Read more
13″ 2.5GHz MacBook Pro on sale for $150 off M...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $1049.95 including free shipping. Their price is $150 off MSRP plus NY sales tax only. B&H will include free copies of Parallels Desktop... Read more
iPod touch (refurbished) available for up to...
The Apple Store is now offering a full line of Apple Certified Refurbished 2012 iPod touches for up to $70 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free: -... Read more
27″ Apple Display (refurbished) available for...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $799 including free shipping. That’s $200 off the cost of new models. Read more
Apple TV (refurbished) now available for only...
The Apple Store has Apple Certified Refurbished 2012 Apple TVs now available for $75 including free shipping. That’s $24 off the cost of new models. Apple’s one-year warranty is standard. Read more
AnandTech Reviews 2013 MacBook Air (11-inch)...
AnandTech is never the first out with Apple new product reviews, but I’m always interested in reading their detailed, in-depth analyses of Macs and iDevices. AnandTech’s Vivek Gowri bought and tried... Read more
iPad, Tab, Nexus, Surface, And Kindle Fire: W...
VentureBeat’s John Koetsier says: The iPad may have lost the tablet wars to an army of Android tabs, but its still first in peoples hearts. Second place, however, belongs to a somewhat unlikely... Read more
Should You Buy An iPad mini Or An iPad 4?
Macworld UK’s David Price addresses the conundrum of which iPAd to buy? Apple iPad 4, iPad 2, iPad mini? Or hold out for the iPad mini 2 or the iPad 5? Price notes that potential Apple iPad... Read more
iDraw 2.3 A More Economical Alternative To Ad...
If you’re a working graphics pro, you can probably justify paying the stiff monthly rental fee to use Adobe’s Creative Cloud, including the paradigm-setting vector drawing app. Adobe Illustrator. If... Read more
New Documentary By Director Werner Herzog Sho...
Injuring or even killing someone because you were texting while driving is a life-changing experience. There are countless stories of people who took their eyes off the road for a second and ended up... Read more

Jobs Board

Sales Representative - *Apple* Honda - Appl...
APPLE HONDA AUTOMOTIVE CAREER FAIR! NOW HIRING AUTO SALES REPS, AUTO SERVICE BDC REPS & AUTOMOTIVE BILLER! NO EXPERIENCE NEEDED! Apple Honda is offering YOU a Read more
*Apple* Developer Support Advisor - Portugue...
Changing the world is all in a day's work at Apple . If you love innovation, here's your chance to make a career of it. You'll work hard. But the job comes with more than Read more
RBB - *Apple* OS X Platform Engineer - Barc...
RBB - Apple OS X Platform Engineer Ref 63198 Country USA…protected by law. Main Function | The engineering of Apple OS X based solutions, in line with customer and Read more
RBB - Core Software Engineer - Mac Platform (...
RBB - Core Software Engineer - Mac Platform ( Apple OS X) Ref 63199 Country USA City Dallas Business Area Global Technology Contract Type Permanent Estimated publish end Read more
*Apple* Desktop Analyst - Infinity Consultin...
Job Title: Apple Desktop Analyst Location: Yonkers, NY Job Type: Contract to hire Ref No: 13-02843 Date: 2013-07-30 Find other jobs in Yonkers Desktop Analyst The Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.