home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep1 / External Functions / Samples / teststring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-24  |  1.6 KB  |  53 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Test returning a string qualifier from an external function for ProIcon
  3.  *
  4.  * This code resource will appear under the resource type 'TEST', ID 1004,
  5.  * name "Substring Test".  Invoke with:
  6.  *
  7.  *      callout("TEST", "String Test")
  8.  */
  9.  
  10.  
  11. #include "ProIcon.h"
  12.  
  13. /*
  14.  * Code resource called as:
  15.  *   callout("type", "resource name", ...)
  16.  * where:
  17.  *  "type" is a Macintosh 4-character resource type code
  18.  *  "resource name" is a string used to specify resource by name.
  19.  *  ... are additional arguments whose dptrs are pushed on the stack.
  20.  *
  21.  * dargv[0]      - Arg0 - descriptor to place result
  22.  * dargv[1]      - Arg1 - first user argument
  23.  * dargv[argc]   - Argn - last user argument
  24.  * ip            - pointer to integer used to signal error.  *ip is initialized
  25.  *                 to -1, signifying no error.
  26.  *
  27.  * Possible returns:
  28.  *   Success     - Leave *ip unaltered, return descriptor pointer.
  29.  *   Failure     - Leave *ip unaltered, return NULL.
  30.  *   Error       - Set *ip to error code >= 0.  Return descriptor pointer or NULL
  31.  *                 to have value displayed or not displayed in error message.
  32.  */
  33.  
  34. #define resultstr "This is a test string"
  35. #define resultlen (sizeof(resultstr) - 1)
  36.  
  37. pascal dptr main(dargv, argc, ip, callback)                /* string() */
  38. dptr dargv;
  39. short int argc;
  40. short int *ip;
  41. pointer (*callback)();
  42. {
  43.    if (argc != 0)
  44.       Fail;
  45.  
  46.    if (strreq(resultlen) == Error)                    /* make sure space available */
  47.       RunErr(0, NULL);
  48.    StrLoc(Arg0) = alcstr(resultstr, (word)resultlen);    /* allocate and copy string */
  49.    StrLen(Arg0) = resultlen;                            /* set string length in qualifier */
  50.  
  51.    Return;
  52. }
  53.