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

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