home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 12.img / ADS1.LIB / APPMNGR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-12  |  11.9 KB  |  352 lines

  1. /* Next available MSG number is  33 */
  2.  
  3. /***************************************************************************
  4.    Module Name:  appmngr.c
  5.  
  6.    Description:  App loads and unloads a series of ADS apps, and displays
  7.                  The currently loaded ADS applications.
  8.  
  9.    Author     :
  10.                  Autodesk, Inc.
  11.                  2320 Marinship Way
  12.                  Sausalito, CA. 94965
  13.                  (415)332-2344
  14.  
  15.       ¬⌐┼v (C) 1992  Autodesk ñ╜Ñq
  16.  
  17.       Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
  18.       ¡∞½h :
  19.  
  20.       1)  ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
  21.       2)  ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
  22.  
  23.       Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
  24.       Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
  25.  
  26.  
  27.     Function Entry Points:
  28.         void
  29.         main(argc, argv)
  30.         int    argc;              [Number of argument passed in cmd line]
  31.         char   *argv[];           [Array of pointers to arguments]
  32.  
  33.     Exported ADS Functions
  34.         TESTXLOAD                 [Test ADS_ XLOAD/XUNLOAD/LOADED functions]
  35.  
  36.     Modification History:
  37.         Feb 26 1992 - bcm - original creation
  38.  
  39.     Notes and restrictions on use:
  40.  
  41.  
  42. ***************************************************************************/
  43.  
  44. /**************************************************************************/
  45. /*  MODULE NAME  */
  46. /**************************************************************************/
  47. #define    APPMNGR
  48.  
  49. /****************************************************************************/
  50. /*  DEFINES  */
  51. /****************************************************************************/
  52. #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  53.  
  54. /**************************************************************************/
  55. /*  TYPEDEFS  */
  56. /**************************************************************************/
  57. /* ADS Function Table */
  58. typedef struct {
  59.     char    *name;
  60.     int     (*fptr)();
  61. } ftblent;
  62.  
  63. typedef struct resbuf rbtype;
  64.  
  65. /**************************************************************************/
  66. /*  INCLUDES  */
  67. /**************************************************************************/
  68.  
  69. #include <stdio.h>
  70. #include "adslib.h"
  71. #include "ol_errno.h"
  72. /****************************************************************************/
  73. /*  LOCAL FUNCTION FORWARD DECLARATIONS  */
  74. /****************************************************************************/
  75. int     testappmngr();
  76.  
  77. /**************************************************************************/
  78. /*  GLOBAL VARIABLES  */
  79. /**************************************************************************/
  80. /* Table of ADS functions */
  81. ftblent exfun[] = {
  82.             {/*MSG0*/"C:TESTAPPMNGR", testappmngr},
  83.         };
  84.  
  85. /* Table of ADS applications */
  86. char    *AppTable[] = {
  87.             /*MSG0*/"ads_perr",
  88.             /*MSG0*/"appmngr",
  89.             /*MSG0*/"arbmat",
  90.             /*MSG0*/"asctext",
  91.             /*MSG0*/"colext",
  92.             /*MSG0*/"dlgtest",
  93.             /*MSG0*/"dragger",
  94.             /*MSG0*/"fact",
  95.             /*MSG0*/"gpalsym",
  96.             /*MSG0*/"gravity",
  97.             /*MSG0*/"magnets",
  98.             /*MSG0*/"project",
  99.             /*MSG0*/"ptext",
  100.             /*MSG0*/"sld2ps",
  101.             /*MSG0*/"sqr",
  102.             /*MSG0*/"tower",
  103.         };
  104.  
  105. /**************************************************************************/
  106. /*  EXTERNAL FUNCTION DECLARATIONS  */
  107. /**************************************************************************/
  108.  
  109. /**************************************************************************/
  110. /*  EXTERNAL VARIABLE DECLARATIONS  */
  111. /**************************************************************************/
  112.  
  113. /****************************************************************************/
  114. /*  LOCAL FUNCTION DECLARATIONS  */
  115. /****************************************************************************/
  116.  
  117. /******************************************************************************/
  118. /*.doc geterrno(internal) */
  119. /*+
  120.     This function is called to obtain the value of the AutoCAD system
  121.     variable ERRNO and return it as a result.
  122. -*/
  123. /******************************************************************************/
  124. int
  125. /*FCN*/geterrno()
  126. {
  127.     rbtype errval;
  128.  
  129.     ads_getvar(/*MSG0*/"ERRNO", &errval);
  130.  
  131.     return errval.resval.rint;
  132. }
  133.  
  134. /******************************************************************************/
  135. /*.doc funcload(internal) */
  136. /*+
  137.     This function is called to define all function names in the ADS
  138.     function table.  Each named function will be callable from lisp or
  139.     invokable from another ADS application.
  140. -*/
  141. /******************************************************************************/
  142. int
  143. /*FCN*/funcload()
  144. {
  145.     int i;
  146.  
  147.     for (i = 0; i < ELEMENTS(exfun); i++) {
  148.         if (!ads_defun(exfun[i].name, i))
  149.             return RTERROR;
  150.     }
  151.  
  152.     return RTNORM;
  153. }
  154.  
  155. /******************************************************************************/
  156. /*.doc funclunoad(internal) */
  157. /*+
  158.     This function is called to undefine all function names in the ADS
  159.     function table.  Each named function will be removed from the
  160.     AutoLISP hash table.
  161. -*/
  162. /******************************************************************************/
  163. int
  164. /*FCN*/funcunload()
  165. {
  166.     int i;
  167.  
  168.     /* Undefine each function we defined */
  169.  
  170.     for (i = 0; i < ELEMENTS(exfun); i++) {
  171.         ads_undef(exfun[i].name,i);
  172.     }
  173.  
  174.     return RTNORM;
  175. }
  176. /******************************************************************************/
  177. /*.doc dofun(internal) */
  178. /*+
  179.     This function is called to invoke the function which has the
  180.     registerd function code that is obtained from  ads_getfuncode.  The
  181.     function will return RTERROR if the function code is invalid, or
  182.     RSERR if the invoked function fails to return RTNORM.  The value
  183.     RSRSLT will be returned if the function code is valid and the
  184.     invoked subroutine returns RTNORM.
  185. -*/
  186. /******************************************************************************/
  187. int
  188. /*FCN*/dofun()
  189. {
  190.     int    val;
  191.     int    rc;
  192.  
  193.     ads_retvoid();
  194.  
  195.     if ((val = ads_getfuncode()) < 0 || val > ELEMENTS(exfun))
  196.         return RTERROR;
  197.  
  198.     rc = (*exfun[val].fptr)();
  199.  
  200.     return ((rc == RTNORM) ? RSRSLT:RSERR);
  201. }
  202.  
  203. /******************************************************************************/
  204. /*.doc main(internal) */
  205. /*+
  206.     This is the main entry point for the ADS application.  All ADS
  207.     requests will be dispatched from this function.  This is your
  208.     standard ADS dispatch loop.
  209. -*/
  210. /******************************************************************************/
  211. void
  212. /*FCN*/main(argc,argv)
  213. int argc;
  214. char *argv[];
  215. {
  216.     short scode = RSRSLT;          /* Normal result code (default) */
  217.     int   stat;
  218.  
  219.     ads_init(argc, argv);          /* Initiate communication with AutoLISP */
  220.  
  221.     for ( ;; ) {                   /* Request/Result loop */
  222.  
  223.         if ((stat = ads_link(scode)) < 0) {
  224.             printf(/*MSG1*/"APPMNGR: Ñ╤ ads_link() ╢╟ª^¬║ñú¿╬¬¼║A = %d\n", stat);
  225.             fflush(stdout);
  226.             exit(1);
  227.         }
  228.  
  229.         scode = RSRSLT;           /* Reset result code */
  230.  
  231.         switch (stat) {
  232.  
  233.         case RQXLOAD:             /* Load & define functions */
  234.             scode = funcload() ? -RSRSLT : -RSERR;
  235.             break;
  236.  
  237.         case RQXUNLD:             /* Unload functions */
  238.             scode = funcunload() ? -RSRSLT : -RSERR;
  239.             ads_printf(/*MSG2*/"─└⌐±íC\n");
  240.             break;
  241.  
  242.         case RQSUBR:             /* Handle request for external function */
  243.             dofun();
  244.             break;
  245.  
  246.         default:
  247.             break;
  248.         }
  249.     }
  250. }
  251.  
  252. /******************************************************************************/
  253. /*.doc testappmngr(internal) */
  254. /*+
  255.     This function is called from dofun function as a result of RQSUBR
  256.     request being sent to the main dispatch loop.
  257.  
  258.     The function will walk thru the AppTable and perform an ADS_XLOAD
  259.     on each application.  The message Loading apname... will be printed
  260.     before each application is attempted to be loaded.  If the load
  261.     fails, then the message will be followed by the messaged FAILED..
  262.  
  263.     The next phase of the test will make a call to the function
  264.     ADS_LOADED to obtain the list of currently loaded applications.  It
  265.     will then walk thu the list and perform an ADS_XUNLOAD on each
  266.     application.  The message Unloading appname... will be printed
  267.     before each application is attempted to be unloaded.  Note, that
  268.     some applications may generate messages of their own, so the output
  269.     may not be exactly as described.  If an application fails to be
  270.     unloaded, then the message FAILED will follow the unloading
  271.     message.
  272.  
  273.     This function always returns RTNORM.
  274. -*/
  275. /******************************************************************************/
  276. int
  277. /*FCN*/testappmngr()
  278. {
  279.     rbtype      *args;
  280.     rbtype      *tapl;
  281.     rbtype      *applist;
  282.     int         x;
  283.     int         i;
  284.     int         pcount;
  285.  
  286.     args = ads_getargs();
  287.     ads_printf(/*MSG3*/"\n░⌡ªµ ads_xload, ads_xunload, and ads_loaded ┤·╕╒\n");
  288.     pcount = 5;
  289.     if (args != NULL) {
  290.         if (args->restype == RTSHORT)
  291.             pcount = args->resval.rint;
  292.     }
  293.  
  294.     for (i = 1; i <= pcount; i++) {
  295.         ads_printf(/*MSG4*/"\n\n\n│B▓z %d íC\n\n\n", i);
  296.         for (x = 0; x < ELEMENTS(AppTable); x++) {
  297.             ads_printf(/*MSG5*/"╕ⁿñJíu%sív...\n", AppTable[x]);
  298.             if (ads_xload(AppTable[x]) != RTNORM)
  299.                 switch(geterrno()) {
  300.                 case OL_ENULLPTR:
  301.                     ads_printf(/*MSG6*/"íu└╔ªWñ▐╝╞ív¼░íuNULL ½ⁿ╝╨ívíC\n");
  302.                     break;
  303.                 case OL_EOPEN:
  304.                     ads_printf(/*MSG7*/"½ⁿ⌐w¬║íu└╔«╫ív╡L¬k╢}▒╥íC\n");
  305.                     break;
  306.                 case OL_ELOADED:
  307.                     ads_printf(/*MSG8*/"½ⁿ⌐w¬║íu└╔«╫ívñw╕ⁿñJíC\n");
  308.                     break;
  309.                 case OL_ENOMEM:
  310.                     ads_printf(/*MSG9*/"¿Sª│¬┼╢íñ⌐íu└│Ñ╬╡{ªíív▒▒¿ε░╧╢⌠ (block)íC\n");
  311.                     break;
  312.                 case OL_EMAXAPP:
  313.                     ads_printf(/*MSG10*/"╕ⁿñJñºíuADS └│Ñ╬╡{ªíívñw╣FñW¡¡íC\n");
  314.                     break;
  315.                 case OL_EEXEC:
  316.                     ads_printf(/*MSG11*/"íu└│Ñ╬╡{ªíív╡L¬k░⌡ªµíC\n");
  317.                     break;
  318.                 case OL_EVERSION:
  319.                     ads_printf(/*MSG12*/"íu└│Ñ╬╡{ªíívª│┐∙╗~¬║íuADS ¬⌐Ñ╗ #ívíC\n");
  320.                     break;
  321.                 }
  322.         }
  323.  
  324.         for (tapl = applist = ads_loaded(); tapl != NULL; tapl = tapl->rbnext) {
  325.             if (tapl->restype == RTSTR && tapl->resval.rstring != NULL) {
  326.                 ads_printf(/*MSG13*/"─└⌐±íu%sív...\n", tapl->resval.rstring);
  327.                 if (ads_xunload(tapl->resval.rstring) != RTNORM)
  328.                     switch(geterrno()) {
  329.                     case OL_ENULLPTR:
  330.                         ads_printf(/*MSG14*/"íu└╔ªWñ▐╝╞ív¼░íuNULL ½ⁿ╝╨ívíC\n");
  331.                         break;
  332.                     case OL_EDENIED:
  333.                         ads_printf(/*MSG15*/"íu└│Ñ╬╡{ªíív╡L¬kÑHª╣║╪ñΦªí¿╙íu─└⌐±ívª█ñv;\n");
  334.                         ads_printf(/*MSG16*/"ªP«╔, ▒_▓╒¬║íu└│Ñ╬╡{ªíív╡L¬kíu─└⌐±ívíC\n");
  335.                         break;
  336.                     case OL_EREFUSE:
  337.                         ads_printf(/*MSG17*/"íu└│Ñ╬╡{ªíív⌐┌ªµíu─└⌐± (unload)ívíC\n");
  338.                         break;
  339.                     case OL_ENOTLOADED:
  340.                         ads_printf(/*MSG18*/"íu└│Ñ╬╡{ªíív«┌Ñ╗Ñ╝╕ⁿñJ, ª]ª╣\n");
  341.                         ads_printf(/*MSG19*/"╡{ªí╡L¬k│Qíu─└⌐±ívíC\n");
  342.                         break;
  343.                     }
  344.             }
  345.         }
  346.  
  347.         if (applist != NULL)
  348.             ads_relrb(applist);
  349.     }
  350.     return RTNORM;
  351. }
  352.