home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MATLIB / TEST.CPP < prev   
C/C++ Source or Header  |  1996-01-06  |  2KB  |  148 lines

  1.  
  2. #include <owl\owlpch.h>
  3. #include <owl\applicat.h>
  4. #include <owl\framewin.h>
  5. #include <owl\dc.h>
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <string.h>
  9. #include <assert.h>
  10.  
  11. extern "C" {
  12.     #include "lib.h"
  13.     #include "matrix.h"
  14.     #include "ml.h"
  15.     #include "matclass.h"
  16.     void    test();
  17.     static    void    StreamInit();
  18.     static    int        StreamOutput( int, int, DataStruct* );
  19. };
  20.  
  21. class    ErrorObject    {
  22.     public:
  23.         char        msg[256] ;
  24. };
  25.  
  26.  
  27. #include "message.h"
  28.  
  29. static    TMessageWindow    *MessageOut ;
  30.  
  31. class TMyApp : public TApplication {
  32.   public:
  33.     TMyApp() : TApplication() {}
  34.  
  35.   protected:
  36.       BOOL    isidle ;
  37.     void    InitMainWindow();
  38.     BOOL    IdleAction( long );
  39. };
  40.  
  41. void TMyApp::InitMainWindow()
  42. {
  43.     isidle = TRUE ;
  44.     MessageOut = new TMessageWindow( "message window", 100 );
  45.     SetMainWindow( MessageOut->GetWindowPtr() );
  46. }
  47.  
  48. ErrorObject    err ;
  49.  
  50. void    error( const char *msg ) throw( ErrorObject& )
  51. {
  52.     static    int        errcnt = 0 ;
  53.  
  54.     wprintf( msg );
  55.     wprintf( "\n" );
  56.     
  57.     strcpy( err.msg, msg );
  58.  
  59.     throw( err );
  60. }
  61.  
  62.  
  63. BOOL    TMyApp::IdleAction( long /* idleCount */ )
  64. {
  65. #if    1
  66.     if ( isidle )
  67.     {
  68.         MessageSet( error, NULL );
  69.         
  70.         try {
  71.             test();
  72.         }
  73.         catch( ErrorObject& err )
  74.         {
  75.             MainWindow->MessageBox( err.msg, "catch" );
  76.             MainWindow->CloseWindow();
  77.         }
  78.  
  79.         isidle = FALSE ;
  80.     }
  81. #endif
  82.     return FALSE ;
  83. }
  84.  
  85.  
  86. int OwlMain(int /*argc*/, char* /*argv*/ [])
  87. {
  88.     if ( LibraryInit() < 0 )
  89.         return -1 ;
  90.     MatrixInit();
  91.  
  92.     return TMyApp().Run();
  93. }
  94.  
  95. void    test()
  96. {
  97.     int        pdebug = FALSE, edebug = FALSE ;
  98.  
  99.     MLInit();
  100.  
  101.     ParseInit();
  102.  
  103.     MatrixClassInit();
  104.     StreamInit();
  105.  
  106.     DebugMode( pdebug, edebug );
  107.  
  108.     wprintf( "open %s\n", "mat.ml" );
  109.     ParseSentenseAll( "mat.ml" );
  110.  
  111. #if    1
  112.     /*    実行    */
  113.     ExecInit();
  114.     ExecSentenseAll();
  115.     ExecExit();
  116. #endif
  117.  
  118.     ParseExit();
  119. }
  120.  
  121. DataStruct    StreamOut ;
  122. int        StreamClassID ;
  123.  
  124. static    void    StreamInit()
  125. {
  126.     StreamClassID = NewClass( "Stream", 0 );
  127.     StreamOut.type = TYPE_OBJECT ;
  128.     StreamOut.od.ptr = ObjectAlloc( 0, StreamClassID );
  129.     NewConst( "cout", &StreamOut );
  130.  
  131.     NewOperator( StreamClassID, OPE_LSFT, StreamOutput );
  132. }
  133.  
  134. static    int        StreamOutput( ident, args, buf )
  135. int        ident ;
  136. int        args ;
  137. DataStruct    *buf ;
  138. {
  139.     assert( args == 2 );
  140.     ident = FunctionName( "print" );
  141.     assert( ident > 0 );
  142.     CallFunction( ident, 1, buf+1 );
  143.  
  144.     StackPush( &buf[0] );
  145.  
  146.     return RETURN_RETURN ;
  147. }
  148.