home *** CD-ROM | disk | FTP | other *** search
- /*
- * Test writing an external function for ProIcon
- *
- * This code resource will appear under the resource type 'TEST', ID 1002,
- * name "Cset Test". Invoke with:
- *
- * callout("TEST", "Cset Test", int1, int2)
- *
- * It accepts two integer arguments and returns the cset spanning those character codes.
- */
-
-
- #include "ProIcon.h"
-
- /*
- * Code resource called as:
- * callout("type", "resource name", ...)
- * where:
- * "type" is a Macintosh 4-character resource type code
- * "resource name" is a string used to specify resource by name.
- * ... are additional arguments whose dptrs are pushed on the stack.
- *
- * dargv[0] - Arg0 - descriptor to place result
- * dargv[1] - Arg1 - first user argument
- * dargv[argc] - Argn - last user argument
- * ip - pointer to integer used to signal error. *ip is initialized
- * to -1, signifying no error.
- *
- * Possible returns:
- * Success - Leave *ip unaltered, return descriptor pointer.
- * Failure - Leave *ip unaltered, return NULL.
- * Error - Set *ip to error code >= 0. Return descriptor pointer or NULL
- * to have value displayed or not displayed in error message.
- */
-
- pascal dptr main(dargv, argc, ip, callback)
- struct descrip dargv[];
- short int argc;
- short int *ip;
- pointer (*callback)();
- {
- register struct b_cset *bp;
- word i1, i2;
- short int j;
-
- if (argc != 2) /* fail if wrong number of arguments */
- Fail;
-
- if (Type(Arg1) != T_Integer)
- RunErr(Err101, &Arg1); /* integer expected for first user arg */
-
- if (Type(Arg2) != T_Integer)
- RunErr(Err101, &Arg2); /* integer expected for second user arg */
-
- if ((i1 = IntVal(Arg1)) < 0 || i1 >= 256)
- RunErr(Err205, &Arg1); /* first argument out of range */
-
- if ((i2 = IntVal(Arg2)) < 0 || i2 >= 256 || i2 < i1)
- RunErr(Err205, &Arg2); /* second argument out of range */
-
- if (blkreq((word)sizeof(struct b_cset)) == Error) /* notify ProIcon of memory needs */
- RunErr(0, NULL);
-
- bp = alccset(); /* allocate block for cset */
- ArgType(0) = D_Cset; /* set cset result code */
- BlkLoc(Arg0) = (union block *) bp; /* point to block containing cset */
- bp->size = i2 - i1 + 1; /* number of bits on */
- while (i1 <= i2) {
- if (CsetOff(i1) == 0 && i1 + IntBits <= i2) {
- *CsetPtr(i1,bp->bits) = MaxUnsigned; /* word at a time */
- i1 += IntBits;
- }
- else {
- Setb(i1, bp->bits); /* bit by bit */
- i1++;
- }
- }
-
- Return;
- }
-