home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / ADSCPP / ADSCPP.CPP next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  5.9 KB  |  220 lines

  1. /* 
  2.     ADSCPP.CPP -
  3.     
  4.     This file:
  5.  
  6.     Defines general ADS application object, ADS_APP.  This 
  7.     application object is to be used when ads_main() is employed 
  8.     instead of WinMain().
  9.         
  10.  
  11.     (C) Copyright 1988-1994 by Autodesk, Inc.
  12.  
  13.     This program is copyrighted by Autodesk, Inc. and is  licensed
  14.     to you under the following conditions.  You may not distribute
  15.     or  publish the source code of this program in any form.   You
  16.     may  incorporate this code in object form in derivative  works
  17.     provided  such  derivative  works  are  (i.) are  designed and
  18.     intended  to  work  solely  with  Autodesk, Inc. products, and
  19.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  20.     1988-1994 by Autodesk, Inc."
  21.  
  22.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  23.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  24.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  25.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  26.     UNINTERRUPTED OR ERROR FREE.
  27.  
  28. */
  29. #include "adscpp.h"
  30.  
  31. //-----------------------------------------------------------------------------
  32. ADS_APP     *main_app = NULL;
  33.  
  34. //-----------------------------------------------------------------------------
  35. ADS_APP* GetAdsApp()
  36. {
  37.     ASSERT ( main_app != NULL );
  38.     return main_app;
  39. }
  40.  
  41. //-----------------------------------------------------------------------------
  42. ADS_APP::DISPATCHER  ADS_APP::dispatcher[] =
  43. {
  44.     { RQXLOAD,      &ADS_APP::LOADFun }
  45.     , { RQSUBR,     &ADS_APP::SUBRFun }
  46.     , { RQXUNLD,    &ADS_APP::UNLDFun }
  47.     , { RQEND,      &ADS_APP::ENDFun }
  48.     , { RQQUIT,     &ADS_APP::QUITFun }
  49.     , { RQSAVE,     &ADS_APP::SAVEFun }
  50.     , { RQHUP,      &ADS_APP::HUPFun }
  51.     , { RQCFG,      &ADS_APP::CFGFun }
  52. };
  53.  
  54. //-----------------------------------------------------------------------------
  55. ADS_APP::ADS_APP(int argc, char **argv)
  56. {
  57.     ads_init(argc, argv);
  58.  
  59.     LOAD_status = RTNORM;
  60.     UNLD_status = RTERROR;
  61.     SUBR_status = RTNORM;
  62.     num_funs = 0;
  63.     num_run_funs = 0;
  64.     app_state = APP_OK;
  65. }
  66.  
  67. //-----------------------------------------------------------------------------
  68. int ADS_APP::InsertExternFunc(ADS_FUNC_INFO& target)
  69. {
  70.     if (num_funs < MAX_ADS_FUNC)
  71.     {
  72.         target.func_code = num_funs;    // zero based
  73.         exfuns[num_funs++] = target;
  74.         return num_funs;
  75.     }
  76.     else
  77.     {
  78.         return -1;
  79.     }
  80. }
  81.  
  82. //-----------------------------------------------------------------------------
  83. int ADS_APP::LOADFun()
  84. {
  85.     int i;
  86.     for (i = 0; i < num_funs; i++) 
  87.     {
  88.         if ( !ads_defun(exfuns[i].extern_name, i) )
  89.         {
  90.             LOAD_status = RTERROR;
  91.             break;
  92.         }
  93.         else
  94.         {
  95.             ads_printf(exfuns[i].message);
  96.         }
  97.     }
  98.     return ( (LOAD_status == RTNORM) ? -RSRSLT : -RSERR);
  99. }
  100.  
  101.  
  102. //-----------------------------------------------------------------------------
  103. int ADS_APP::UNLDFun()
  104. {
  105.     UNLD_status = RTNORM;
  106.     for (int i = 0; i < num_funs; i++) 
  107.     {
  108.         if (ads_undef(exfuns[i].extern_name,i) == RTERROR)
  109.         {
  110.             UNLD_status = RTERROR;
  111.         }
  112.     }
  113.     app_state = APP_DONE;
  114.     ads_printf( "Unloading.\n" );
  115.     return ( (UNLD_status == RTNORM) ? -RSRSLT : - RSERR);
  116. }
  117.  
  118. //-----------------------------------------------------------------------------
  119. int ADS_APP::Run()
  120. {
  121.     short   scode = RSRSLT;             /* Normal result code (default) */
  122.     int     stat;
  123.  
  124.     while ( app_state != APP_DONE )
  125.     {
  126.         if ( ( stat = ads_link( scode ) ) < 0 )
  127.         {
  128.             return (1);
  129.         }
  130.         //
  131.         // Dispatching the result
  132.         //
  133.         scode = RSRSLT;
  134.         int i;
  135.         for ( i = 0; i < ARRAY_SIZE( dispatcher ); i++ )
  136.         {            
  137.             if ( dispatcher[i].command == stat)
  138.             {
  139.                 scode = ( this->*dispatcher[i].rsp_fun )();
  140.                 break;
  141.             }            
  142.         }
  143.  
  144.         if ( num_run_funs != 0 )
  145.         {
  146.             while ( --num_run_funs )
  147.             {
  148.                 ( this->*run_funs[ num_run_funs ] )();
  149.             }
  150.         }
  151.     }
  152.     ads_link( scode );
  153.     return 1;
  154. }
  155.  
  156. //-----------------------------------------------------------------------------
  157. int ADS_APP::SUBRFun()
  158. {
  159.     struct resbuf *rb=NULL;
  160.     int func_code = ads_getfuncode();
  161.  
  162.     if ( func_code< 0 
  163.         || func_code > num_funs )
  164.         //
  165.         // We should check the arguments here
  166.         //
  167.         // || ((rb = ads_getargs()) == NULL))
  168.     {
  169.         return 0;
  170.     }
  171.  
  172.     switch (exfuns[func_code].func_type)
  173.     {
  174.         case ADS_INT_FUNC:
  175.         {
  176.             ads_retint(exfuns[func_code].extern_func.calling_fun.AdsIntFunc(rb));
  177.         }
  178.         break;
  179.  
  180.         case ADS_VOID_FUNC:
  181.         {
  182.             exfuns[func_code].extern_func.calling_fun.AdsVoidFunc(rb);
  183.             ads_retvoid();
  184.         }
  185.         break;
  186.  
  187.         case ADS_REAL_FUNC:
  188.         {
  189.             ads_retreal(exfuns[func_code].extern_func.calling_fun.AdsRealFunc(rb));
  190.         }
  191.         break;
  192.     }
  193.     return ( (SUBR_status == RTERROR) ? RSERR : RSRSLT);
  194. }
  195.  
  196. /******************************************************************************
  197.  
  198.                 ADS_FUNC_INFO member functions    
  199.     
  200. ******************************************************************************/
  201. //-----------------------------------------------------------------------------
  202. ADS_FUNC_INFO::ADS_FUNC_INFO(ADS_FUNC _extern_func
  203.                             , ADS_FUNC_TYPE _ads_func_type
  204.                             , char *_extern_name
  205.                             , char *_message):extern_func(_extern_func)
  206. {
  207.     func_type = _ads_func_type;
  208.     
  209.     strcpy(extern_name, _extern_name);
  210.     
  211.     if ( _message == NULL)
  212.     {
  213.         message[0] = '\0';
  214.     }
  215.     else
  216.     {
  217.         strcpy(message, _message);
  218.     }
  219. }
  220.