[comp.sys.mac.hypercard] XCMD's in LSC?

mesard@bbn.com (Wayne Mesard) (03/15/89)

In article <1725@quanta.eng.ohio-state.edu> czei@neutron.eng.ohio-state.edu (Michael S. Czeiszperger) writes:
>
>Has anyone programmed XCMD's in LSC? 

Yes.

>In fact,
>with just the shell implemented it bombs the whole operating
>system every time.

You're not doing any obvious XCMD no-nos such as calling any toolbox
Init*() functions, or using global/static variables are you?

>An example would come in handy, assuming that it is supposed to
>work....

Here's some stripped down code.  I'm sure that it won't compile as is.
But it was taken directly from working code compiled with LSC 3.0.  No
apologies for its form or quality.  No responsiblity for its use or the
consequences thereof is implied to BBN or to myself.

---------------------------------
#include <MacTypes.h>
#include <QuickDraw.h>
#include <EventMgr.h>
#include <HyperXCmd.h>
#include "wsm_types.h"
#include "wsm_macros.h"

#define FIELD_PARAM 0
#define SCALE_PARAM 1
#define RESOL_PARAM 2

pascal void main(XCmdBlockPtr);
void WriteNumToField(XCmdBlockPtr, char *, long);


pascal void main(pParm)
XCmdBlockPtr pParm;
{
  GrafPtr ourPort;
  PenState oldPenState;
  Pattern local_gray, local_black;  /* No globals in XCMDS :-( */
  
  EventRecord event;
  int scale;

  /**** Deal with parameters ****/
  if (pParm->paramCount < 3) {
    SysBeep(10);
    return;
  }

  CtoPstr(*(pParm->params[FIELD_PARAM]));
  
  CtoPstr(*(pParm->params[SCALE_PARAM]));
  scale = StrToLong(pParm, (Str31 *) *(pParm->params[SCALE_PARAM]));

  CtoPstr(*(pParm->params[RESOL_PARAM]));
  ssize = StrToLong(pParm, (Str31 *) *(pParm->params[RESOL_PARAM]));

  GetPort(&ourPort);  

  /**** Initialize local vars/read resources ****/
  GetIndPattern(&local_gray, sysPatListID, 4);
  GetIndPattern(&local_black, sysPatListID, 1);
  
  GetPenState(&oldPenState);
  
  /**** Set up screen ****/

[[etc...]]  
  WriteNumToField(pParm, *(pParm->params[FIELD_PARAM]), 0L);


  /**** Main loop ****/  
  FlushEvents(everyEvent, 0);
  while(in_progress) {
    if (GetNextEvent(mUpMask | mDownMask | keyDownMask, &event))
      switch (event.what) {
        case mouseDown:
[[etc...]]
          break;
        case mouseUp:
[[etc...]]
          break;
        case keyDown:
[[etc...]]
          break;
      }
  }
  
  /**** Clean Up ****/
  SetPenState(&oldPenState);
  InvalRect(&ourPort->portRect);
}



void  WriteNumToField (theParamPtr, theFieldName, theValue)
XCmdBlockPtr theParamPtr;
char *theFieldName;
long theValue;
{
  Handle aStringHandle;

  aStringHandle = NewHandle(100);
  NumToString(theValue, *aStringHandle);
  PtoCstr(*aStringHandle);
  SetFieldByName(theParamPtr, 0, (StringPtr)theFieldName, aStringHandle);
  DisposHandle(aStringHandle);
}

-- 
unsigned *Wayne_Mesard();     "I just can't grow parsley, and that's
MESARD@BBN.COM                 all there is to it!"
BBN, Cambridge, MA                                     -AN