ALAN@NCSUVM.BITNET (01/31/86)
--- da (shell script for aztec C) --
#
# Aztec Shell script to compile, link and install the C Declare
# desk accessory.
#
set -x
cc -bu cdcl.c
ln -an "C Declare" cdcl.o -lc
cprsrc -f DRVR 31 cdcl sys:system
--- SNIP HERE FOR CDCL.C ---
/*
* C Declare -- a desk accessory written in Aztec C
*
* This DA assists you in declaring C variables and functions.
*
* Written by Michael P. Hecht, 10jan86
*/
#asm
main
dc.w $0400 ;ctl-enable
dc.w 0 ;no update
dc.w $014a ;detect mouse and key down events
dc.w 0 ;menu ID number (none)
dc.w open_-main ;open routine
dc.w nop_-main ;prime routine
dc.w control_-main ;control routine
dc.w nop_-main ;status routine
dc.w close_-main ;close routine
title_
dc.b 9
dc.b "C Declare"
ds 0 ;for alignment
public _Uend_,_Dorg_,_Cend_
save_
lea main+(_Uend_-_Dorg_)+(_Cend_-main),a4 ;set up globals
move.l a0,Pbp_ ;save pb pointer
move.l a1,Dp_ ;save DCE pointer
rts
restore_
move.l Pbp_,a0
rts
#endasm
#define _DRIVER
#include <quickdraw.h>
#include <event.h>
#include <window.h>
#include <control.h>
#include <textedit.h>
#include <dialog.h>
#include <desk.h>
#include <scrap.h>
#include <toolutil.h>
#include <memory.h>
#include <pb.h>
#include <osutil.h>
#define SP (*(struct storage **)Dp->dCtlStorage)
/* Dialog item numbers */
#define FUNC_RET 1
#define ARRAY_OF 2
#define PTR_TO 3
#define TEXT 4
/* Owned resource id equates */
#define OWNED 0xc000
#define BY_DRVR 0x0000
#define BY_WDEF 0x0800
#define BY_MDEF 0x1000
#define BY_CDEF 0x1800
#define BY_PDEF 0x2000
#define BY_PACK 0x2800
#define BY_ID_SHIFT 5
DCEPtr Dp;
ParmBlkPtr Pbp;
/* Private storage */
struct storage :
int first;
ControlHandle func_button;
ControlHandle array_button;
Handle text;
StringHandle init;
:;
open()
:
register struct DCE *dp;
register struct storage *sp;
register WindowPtr wp;
register StringHandle s;
register int dlog_id;
int junk;
Rect box;
save();
dp = Dp;
wp = dp->dCtlWindow;
/* First open? Allocate private storage if so. */
if( !wp ) :
dp->dCtlStorage = NewHandle(( long )sizeof( struct storage ));
:
/* Lock it down and dereference it */
HLock( dp->dCtlStorage );
sp = SP;
/* First open? Allocate DLOG and init other stuff if so. */
if( !wp ) :
/* Compute resource id of DLOG at runtime */
dlog_id = -( dp->dCtlRefNum + 1 );
dlog_id <<= BY_ID_SHIFT;
dlog_id |= OWNED | BY_DRVR | 0;
/* Bring up the window */
dp->dCtlWindow = wp = GetNewDialog( dlog_id, 0L, -1L );
/* Grab control handles for the buttons we want to hilite */
GetDItem( wp, FUNC_RET, &junk, &sp->func_button, &box );
GetDItem( wp, ARRAY_OF, &junk, &sp->array_button, &box );
/* Grab TE handle so we can modify the text quickly */
GetDItem( wp, TEXT, &junk, &sp->text, &box );
/* Grab the initial text in a resizable handle */
s = NewHandle(( long )sizeof( Str255 ));
HLock( s );
GetIText( sp->text, *s );
HUnlock( s );
SetHandleSize( s, ( long )(( *s )->length + 1 ));
sp->init = s;
sp->first = TRUE;
:
/* Otherwise, reset if reopened from the front, reset */
else if( wp == FrontWindow()) :
(( WindowPeek )wp )->windowKind = dialogKind;
HiliteControl( sp->func_button, 0 );
HiliteControl( sp->array_button, 0 );
s = sp->init;
HLock( s );
SetIText( sp->text, *s );
HUnlock( s );
sp->first = TRUE;
:
(( WindowPeek )wp )->windowKind = dp->dCtlRefNum;
HUnlock( dp->dCtlStorage );
restore();
return 0;
:
close()
:
register struct DCE *dp;
register WindowPtr wp;
save();
dp = Dp;
wp = dp->dCtlWindow;
(( WindowPeek )wp )->windowKind = dialogKind;
DisposDialog( wp );
dp->dCtlWindow = 0;
DisposHandle( SP->init );
DisposHandle( dp->dCtlStorage );
restore();
return 0;
:
nop()
:
return 0;
:
control()
:
register struct DCE *dp;
register struct storage *sp;
register WindowPtr wp;
register int what;
EventRecord fakenull;
save();
dp = Dp;
HLock( dp->dCtlStorage );
sp = SP;
wp = dp->dCtlWindow;
/* Change windowKind so the dialog mgr will recognize it */
(( WindowPeek )wp )->windowKind = dialogKind;
what = Pbp->u.cp.csCode;
switch( what ) :
case accEvent:
event( sp, *( EventRecord ** )&Pbp->u.cp.csParam,
wp );
break;
case accCursor:
/* This blinks the caret */
fakenull.what = nullEvent;
DialogSelect( &fakenull, 0L, 0L );
break;
default:
/* Assume it's an edit something */
edit( what, sp, wp );
break;
:
HUnlock( dp->dCtlStorage );
(( WindowPeek )wp )->windowKind = dp->dCtlRefNum;
restore();
return 0;
:
event( sp, ep, wp )
register struct storage *sp;
register EventRecord *ep;
WindowPtr wp;
:
register StringHandle s;
register int eventcode;
int item;
/* Keydown with command modifier? */
if( ep->what == keyDown ) :
switch(( char )( ep->message & charCodeMask )) :
case 'Z':
case 'z':
eventcode = accUndo;
break;
case 'X':
case 'x':
eventcode = accCut;
break;
case 'C':
case 'c':
eventcode = accCopy;
break;
case 'V':
case 'v':
eventcode = accPaste;
break;
case '\t':
SelIText( wp, TEXT, 0, 0x7fff );
return;
default:
eventcode = -1;
break;
:
if( eventcode >= 0 && ep->modifiers & cmdKey ) :
edit( eventcode, sp, wp );
return;
:
:
if( !DialogSelect( ep, &wp, &item ))
return;
/* Grab the current text in a resizable handle */
s = NewHandle(( long )sizeof( Str255 ));
HLock( s );
GetIText( sp->text, *s );
HUnlock( s );
SetHandleSize( s, ( long )(( *s )->length + 1 ));
switch( item ) :
case FUNC_RET:
HiliteControl( sp->func_button, 255 );
HiliteControl( sp->array_button, 255 );
if( !sp->first )
paren( s );
else
sp->first = FALSE;
PtrAndHand( "()", s, 2L );
( *s )->length += 2;
break;
case ARRAY_OF:
HiliteControl( sp->func_button, 255 );
if( !sp->first )
paren( s );
else
sp->first = FALSE;
PtrAndHand( "[]", s, 2L );
( *s )->length += 2;
break;
case PTR_TO:
HiliteControl( sp->func_button, 0 );
HiliteControl( sp->array_button, 0 );
sp->first = FALSE;
Munger( s, 1L, 0L, 0L, "*", 1L );
( *s )->length++;
break;
:
HLock( s );
SetIText( sp->text, *s );
DisposHandle( s );
:
paren( s )
register StringHandle s;
:
Munger( s, 1L, 0L, 0L, "(", 1L );
PtrAndHand( ")", s, 1L );
( *s )->length += 2;
:
edit( code, sp, wp )
int code;
register struct storage *sp;
register WindowPtr wp;
:
switch( code ) :
case accUndo:
/* Not supported */
break;
case accCut:
DlgCut( wp );
break;
case accCopy:
DlgCopy( wp );
break;
case accPaste:
DlgPaste( wp );
break;
case accClear:
DlgDelete( wp );
break;
default:
return;
:
ZeroScrap();
TEToScrap();
: