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

  1. /*
  2.  * Test writing an external function for ProIcon
  3.  *
  4.  * This code resource will appear under the resource type 'TEST', ID 1005,
  5.  * name "External Test".  Invoke with:
  6.  *
  7.  *      callout("TEST", "External Test", int)
  8.  *
  9.  * It accepts an integer argument and returns an external block containing
  10.  * that many 32-bit words of junk data.
  11.  */
  12.  
  13.  
  14. #include "ProIcon.h"
  15.  
  16. /*
  17.  * Code resource called as:
  18.  *   callout("type", "resource name", ...)
  19.  * where:
  20.  *  "type" is a Macintosh 4-character resource type code
  21.  *  "resource name" is a string used to specify resource by name.
  22.  *  ... are additional arguments whose dptrs are pushed on the stack.
  23.  *
  24.  * dargv[0]      - Arg0 - descriptor to place result
  25.  * dargv[1]      - Arg1 - first user argument
  26.  * dargv[argc]   - Argn - last user argument
  27.  * ip            - pointer to integer used to signal error.  *ip is initialized
  28.  *                 to -1, signifying no error.
  29.  *
  30.  * Possible returns:
  31.  *   Success     - Leave *ip unaltered, return descriptor pointer.
  32.  *   Failure     - Leave *ip unaltered, return NULL.
  33.  *   Error       - Set *ip to error code >= 0.  Return descriptor pointer or NULL
  34.  *                 to have value displayed or not displayed in error message.
  35.  */
  36.  
  37. pascal dptr main(dargv, argc, ip, callback)
  38. dptr dargv;
  39. short int argc;
  40. short int *ip;
  41. pointer (*callback)();
  42. {
  43.    register struct b_external *bp;
  44.    word i, j;
  45.  
  46.    if (argc != 1)                        /* fail if wrong number of arguments */
  47.       Fail;
  48.  
  49.    if (Type(Arg1) != T_Integer)
  50.       RunErr(Err101, &Arg1);            /* integer expected for first user arg */
  51.  
  52.    if ((i = IntVal(Arg1)) <= 0)
  53.       RunErr(Err205, &Arg1);            /*  argument out of range */
  54.  
  55.    j = i * sizeof(word) + (sizeof(struct b_external) - WordSize);
  56.    
  57.    if (blkreq(j) == Error)                 /* notify ProIcon of memory needs */
  58.       RunErr(0, NULL);
  59.  
  60.    ArgType(0) = D_External;                /* set external result code */
  61.    bp = alcextrnl(i);
  62.    BlkLoc(Arg0) = (union block *)bp;    /* point to block containing external data */
  63.    for (j = 0; j < i; j++)                /* fill block with junk data */
  64.       bp->exdata[j] = j;
  65.  
  66.    Return;
  67. }
  68.