[net.sources.mac] C Declare DA and or Brain Dead Mailer NETPOSTer

ALAN@NCSUVM.BITNET (01/31/86)

Our NetPost program killed the first line of the files I posted previously...
Here are all three programs in one.  First, the shell macro to assemble the
second, which is the source for the third... Watch for ---SNIP--- lines.
     
-Alan
---SNIP---
#
#	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---
/*
 *	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();
:
---SNIP---
(This file must be converted with BinHex 4.0)
     
:#8-J4'9ME'&bC3"%4NP-4%e29J#3#!ITGjJ!N!3"!*!$"i3!!!D%!*!$C35#!li
%MJ8!N!3%&dj@rca)j``BpIdKB!!`r5&J!$Ep)@!!8B(p)@!!@i(d%8KYd(!!(kK
ZU2kT%UN`UFa#TkPlU&!63QG)EG!KB!"6JKqTPc!I28$rrN+R2c`!J%KZ(rp',cc
rN!5TI#!I*N![#amr2!!$5'lr4%KZrr4)E[mm(kQ0,`Xr2!!&5'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