home *** CD-ROM | disk | FTP | other *** search
- /* Next available MSG number is 33 */
-
- /***************************************************************************
- Module Name: gpalsym.c
-
- Description: ADS sample program which exercises the ads_getsym and
- ads_putsym functions.
-
- Author :
- Autodesk, Inc.
- 2320 Marinship Way
- Sausalito, CA. 94965
- (415)332-2344
-
- ¬⌐┼v (C) 1992 Autodesk ñ╜Ñq
-
- Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
- ¡∞½h :
-
- 1) ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
- 2) ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
-
- Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
- Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
-
-
- Function Entry Points:
- void
- main(argc, argv)
- int argc; [Number of argument passed in cmd line]
- char *argv[]; [Array of pointers to arguments]
-
- Exported ADS Functions
- TESTGPSYM [Test the ADS_XXXSYM functions]
-
- Modification History:
- Feb 25 1992 - bcm - original creation
-
- Notes and restrictions on use:
-
-
- ***************************************************************************/
-
- /**************************************************************************/
- /* MODULE NAME */
- /**************************************************************************/
- #define GPALSYM
-
- /****************************************************************************/
- /* DEFINES */
- /****************************************************************************/
- #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
- #define SPOINT(p, x, y, z) p[X] = (x); p[Y] = (y); p[Z] = (z)
- #define CPOINT(dst, src) dst[X] = src[X]; dst[Y] = src[Y]; dst[Z] = src[Z]
-
- /**************************************************************************/
- /* TYPEDEFS */
- /**************************************************************************/
- /* ADS Function Table */
- typedef struct {
- char *name;
- int (*fptr)();
- } ftblent;
-
- typedef struct resbuf rbtype;
-
- /**************************************************************************/
- /* INCLUDES */
- /**************************************************************************/
-
- #include <stdio.h>
- #include "adslib.h"
- #include "ol_errno.h"
- /****************************************************************************/
- /* LOCAL FUNCTION FORWARD DECLARATIONS */
- /****************************************************************************/
- int getsym();
- int putsym();
-
- /**************************************************************************/
- /* GLOBAL VARIABLES */
- /**************************************************************************/
- /* Table of ADS functions */
- ftblent exfun[] = {
- {/*MSG0*/"GETSYM", getsym},
- {/*MSG0*/"PUTSYM", putsym},
- };
-
- /**************************************************************************/
- /* EXTERNAL FUNCTION DECLARATIONS */
- /**************************************************************************/
-
- /**************************************************************************/
- /* EXTERNAL VARIABLE DECLARATIONS */
- /**************************************************************************/
-
- /****************************************************************************/
- /* LOCAL FUNCTION DECLARATIONS */
- /****************************************************************************/
-
- /******************************************************************************/
- /*.doc geterrno(internal) */
- /*+
- This function is called to obtain the value of the AutoCAD system
- variable ERRNO and return it as a result.
- -*/
- /******************************************************************************/
- int
- /*FCN*/geterrno()
- {
- rbtype errval;
-
- ads_getvar(/*MSG0*/"ERRNO", &errval);
-
- return errval.resval.rint;
- }
-
- /******************************************************************************/
- /*.doc funcload(internal) */
- /*+
- This function is called to define all function names in the ADS
- function table. Each named function will be callable from lisp or
- invokable from another ADS application.
- -*/
- /******************************************************************************/
- int
- /*FCN*/funcload()
- {
- int i;
- for (i = 0; i < ELEMENTS(exfun); i++) {
- if (ads_defun(exfun[i].name, i) != RTNORM)
- return RTERROR;
- }
-
- return RTNORM;
- }
-
- /******************************************************************************/
- /*.doc funclunoad(internal) */
- /*+
- This function is called to undefine all function names in the ADS
- function table. Each named function will be removed from the
- AutoLISP hash table.
- -*/
- /******************************************************************************/
- int
- /*FCN*/funcunload()
- {
- int i;
-
- /* Undefine each function we defined */
-
- for (i = 0; i < ELEMENTS(exfun); i++) {
- ads_undef(exfun[i].name,i);
- }
-
- return RTNORM;
- }
- /******************************************************************************/
- /*.doc dofun(internal) */
- /*+
- This function is called to invoke the function which has the
- registerd function code that is obtained from ads_getfuncode. The
- function will return RTERROR if the function code is invalid, or
- RSERR if the invoked function fails to return RTNORM. The value
- RSRSLT will be returned if the function code is valid and the
- invoked subroutine returns RTNORM.
- -*/
- /******************************************************************************/
- int
- /*FCN*/dofun()
- {
- int val;
- int rc;
-
- ads_retvoid();
-
- if ((val = ads_getfuncode()) < 0 || val > ELEMENTS(exfun))
- return RTERROR;
-
- rc = (*exfun[val].fptr)();
-
- return ((rc == RTNORM) ? RSRSLT:RSERR);
- }
-
- /******************************************************************************/
- /*.doc main(internal) */
- /*+
- This is the main entry point for the ADS application. All ADS
- requests will be dispatched from this function. This is your
- standard ADS dispatch loop.
- -*/
- /******************************************************************************/
- void
- /*FCN*/main(argc,argv)
- int argc;
- char *argv[];
- {
- short scode = RSRSLT; /* Normal result code (default) */
- int stat;
-
- ads_init(argc, argv); /* Initiate communication with AutoLISP */
-
- for ( ;; ) { /* Request/Result loop */
-
- if ((stat = ads_link(scode)) < 0) {
- printf(/*MSG1*/"GPALSYM: Ñ╤ ads_link() ╢╟ª^¬║ñú¿╬¬¼║A = %d\n", stat);
- fflush(stdout);
- exit(1);
- }
-
- scode = RSRSLT; /* Reset result code */
-
- switch (stat) {
-
- case RQXLOAD: /* Load & define functions */
- scode = funcload() ? -RSRSLT : -RSERR;
- break;
-
- case RQXUNLD: /* Unload functions */
- scode = funcunload() ? -RSRSLT : -RSERR;
- ads_printf(/*MSG2*/"─└⌐±íC\n");
- break;
-
- case RQSUBR: /* Handle request for external function */
- dofun();
- break;
-
- default:
- break;
- }
- }
- }
-
- /******************************************************************************/
- /*.doc getsym(internal) */
- /*+
- This function is called from dofun function as a result of RQSUBR
- request being sent to the main dispatch loop. It requires one
- string argument which specifies the name of an AutoLISP symbol
- whos value should be returned.
-
- This function always returns RTNORM. An error message will be
- displayed in the event of an error, and nil will be returned.
- Otherwise, the value of the AutoLISP symbol will be returned
- to the AutoLISP caller.
- -*/
- /******************************************************************************/
- int
- /*FCN*/getsym()
- {
- rbtype *args;
- int rc;
- rbtype *varval = NULL;
-
- args = ads_getargs();
- if (args == NULL || args->restype != RTSTR) {
- ads_printf(/*MSG3*/"íu%sívññ╗▌¡nñ@╢╡íuAutoLISP ▓┼╕╣ªW║┘ívíC\n");
- return RTNORM;
- }
-
- rc = ads_getsym(args->resval.rstring, &varval);
- if (rc != RTNORM) {
- switch(geterrno()) {
- case OL_ESYMNAM:
- ads_printf(/*MSG4*/"íuAutoLISP ▓┼╕╣ªW║┘ív╡L«─íC\n");
- break;
- case OL_ENULLPTR:
- ads_printf(/*MSG5*/"╢╟╗╝íuNULL ½ⁿ╝╨ívñ⌐ ads_getsym íC\n");
- break;
- case OL_ENEWRB:
- ads_printf(/*MSG6*/"╡L¬k░t╕míu╡▓¬G╜w╜─░╧ívíC\n");
- break;
- case OL_ESYMVAL:
- ads_printf(/*MSG7*/"íu▓┼╕╣¡╚ív╡L«─íC\n");
- break;
- }
- } else {
- if (varval != NULL) {
- if (varval->rbnext == NULL)
- ads_retval(varval);
- else
- ads_retlist(varval);
- }
- }
- if (varval != NULL)
- ads_relrb(varval);
-
- return RTNORM;
- }
-
- /******************************************************************************/
- /*.doc putsym(internal) */
- /*+
- This function is called from dofun function as a result of RQSUBR
- request being sent to the main dispatch loop. It requires two
- arguments. The first argument is a string containing the name of
- an AutoLISP symbol to set. The second argument can be any data
- type or list containing any data type which can be represented
- in an ADS resbuf structure.
-
- This function always returns RTNORM to the C caller. This function
- always return nil if the operation fails. Otherwise, the value of
- the second argument is returned.
-
- A message will be displayed if an error occurs, and the value
- returned to the AutoLISP caller will be nil.
- -*/
- /******************************************************************************/
- int
- /*FCN*/putsym()
- {
- rbtype *args;
- int rc;
-
- args = ads_getargs();
- ads_retnil();
-
- if (args == NULL || args->restype != RTSTR) {
- ads_printf(/*MSG8*/"Requires name of AutoLISP symbol in \"s, and\n");
- ads_printf(/*MSG9*/"value to be assigned to symbol.\n");
- }
-
- rc = ads_putsym(args->resval.rstring, args->rbnext);
- if (rc != RTNORM) {
- switch(geterrno()) {
- case OL_ESYMNAM:
- ads_printf(/*MSG10*/"íuAutoLISP ▓┼╕╣ªW║┘ív╡L«─íC\n");
- break;
- case OL_ESYMVAL:
- ads_printf(/*MSG11*/"íu▓┼╕╣¡╚ív╡L«─íC\n");
- break;
- }
- } else {
- if (args->rbnext != NULL) {
- if (args->rbnext->rbnext == NULL)
- ads_retval(args->rbnext);
- else
- ads_retlist(args->rbnext);
- }
- }
- return RTNORM;
- }
-