home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_07 / 9n07030a < prev    next >
Text File  |  1991-05-10  |  4KB  |  95 lines

  1.  
  2. /*************************************************************
  3. *       phraseXcmd.c v1.0
  4. *       chunk words into phrases
  5. *       needs: ANSI-A4, MacTraps, HyperXCmd.h,
  6. *               XCmdGlue.inc.c, and phrase.c
  7. *       THINK C v4.0
  8. *       Richard Rathe 8/90
  9. */
  10.  
  11. extern int __GetA4(void);       /* prototype for #includes */
  12.  
  13. #include <HyperXCmd.h>          /* for XCmdBlock struct */
  14. #include <MacTypes.h>           /* for Handle, etc. */
  15. #include <SetUpA4.h>            /* for register A4 functions */
  16. #include <string.h>             /* for strlen and strcpy */
  17.  
  18. #include "phrase.h"             /* for #defines and prototypes */
  19.  
  20. #define NO_ERROR        0       /* all is well */
  21. #define PARAM_ERR       1       /* wrong number of params error */
  22. #define SIZE_ERR        2       /* text too big error */
  23.  
  24. #define SEGMENT         30000   /* max size for HyperCard containers */
  25.  
  26.                                 /* prototype */
  27. extern void     phraseXcmd(char *in,char *out,char *stop,XCmdBlockPtr paramPtr);
  28.  
  29. pascal void main(paramPtr)      /* XFCN entry point */
  30.         XCmdBlockPtr paramPtr;
  31. {
  32.         int error;
  33.         char *text,*list,*stoplist;
  34.         
  35.         RememberA0();           /* so we can recover */
  36.         SetUpA4();              /* so we can find literals */
  37.         
  38.         error = NO_ERROR;       /* clear error flag */
  39.         
  40.         if (paramPtr->paramCount != 2)  /* need two parameters */
  41.                 error = PARAM_ERR;
  42.         
  43.         HLock(paramPtr->params[0]);     /* lock handles */
  44.         HLock(paramPtr->params[1]);
  45.         
  46.         text = *(paramPtr->params[0]);          /* get first param */
  47.         stoplist = *(paramPtr->params[1]);      /* get second param */
  48.  
  49.         
  50.         if(strlen(text) > SEGMENT / MAXWORD)    /* check size */
  51.                 error = SIZE_ERR;
  52.  
  53.         paramPtr->returnValue = NewHandle(SEGMENT);     /* get storage */
  54.         HLock(paramPtr->returnValue);
  55.         list = *(paramPtr->returnValue);
  56.         
  57.         if(error == NO_ERROR)                           /* if no error */
  58.                 phraseXcmd(text,list,stoplist,paramPtr);/* call phrase */
  59.         else if(error == PARAM_ERR)                     /* else give message */
  60.                 strcpy(list,"error: syntax is \"put phrase(<source>,<stoplist>)
  61.                         into destination\"");
  62.         else if(error == SIZE_ERR)
  63.                 strcpy(list,"error: source text too large!");
  64.  
  65.         HUnlock(paramPtr->params[0]);           /* unlock handles */
  66.         HUnlock(paramPtr->params[1]);
  67.         HUnlock(paramPtr->returnValue);
  68.  
  69.         RestoreA4();                            /* restore A4 */
  70. }
  71.  
  72. /* replacement for phrase() with wait cursor call added */
  73.  
  74. void phraseXcmd(char *in,char *out,char *stop,XCmdBlockPtr paramPtr)
  75. {
  76.         char flag;
  77.         char buf[MAXCHAR];
  78.         char HCmessage[MAXCHAR / 2];
  79.         
  80.         strcpy(HCmessage,"set cursor to busy"); /* init message */
  81.         CtoPstr(HCmessage);                     /* convert to pascal string */
  82.  
  83.         *out = EOS;                             /* just to be sure */
  84.  
  85.         while(*(in = getword(in,buf,&flag)) != EOS)     /* get a word */
  86.         {
  87.                 addword(out,buf,stop,flag);             /* add it */
  88.                         /* spin the beachball */
  89.                 SendCardMessage(paramPtr,(StringPtr) HCmessage);
  90.         }
  91.  
  92.         addword(out,buf,stop,flag);                     /* last word */
  93. }
  94.  
  95.