home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / READER / FRMREAD.C < prev    next >
C/C++ Source or Header  |  1996-03-12  |  4KB  |  188 lines

  1. /*
  2.  *        形状ファイル入力関数
  3.  *
  4.  *        Copyright T.Kobayashi    1993.1.17
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <math.h>
  9. #include <string.h>
  10. #include <assert.h>
  11.  
  12. #include "_reader.h"
  13. #include "word.h"
  14. #include "matrix.h"
  15.  
  16. #define NOT_FOUND            11
  17. #define BAD_EXIST            12
  18. #define NOT_FRM_FILE        13
  19. #define NOT_IMPLIMENTED     14
  20. #define LESS_POINT            15
  21. #define MAT_STACK_OVERFLOW    17
  22.  
  23. #define UNEXPECTED_EOF        21
  24. #define NOT_OBJ_FILE        22
  25.  
  26. #define    MAT_STACK_MAX        20
  27.  
  28. static    Matrix    MatStack[MAT_STACK_MAX+1] ;
  29. static    int        MatSP ;
  30. static    Matrix    CurMat ;
  31. static    int        UnitFlag;
  32.  
  33. static    void    frmerror( int, char* );
  34. extern    int        lasterror;
  35.  
  36. int        FrmReadOpen( filename )
  37. const    char    *filename ;
  38. {
  39.     lasterror = 0;
  40.     /*    ファイルのオープン    */
  41.     if ( fileopen( filename ) == 0 )
  42.         return FALSE ;
  43.  
  44.     if (wordid != WORD_FRAM) {
  45.         frmerror(NOT_FRM_FILE,"");
  46.         return FALSE;
  47.     }
  48.     get();
  49.     if (wordid != WORD_OPEN2) {
  50.         frmerror(NOT_FRM_FILE,"");
  51.         return FALSE;
  52.     }
  53.  
  54.     MatSP = 0 ;
  55.     MatUnit( MatStack[MatSP] );
  56.     MatCopy( CurMat, MatStack[MatSP] );
  57.     UnitFlag = TRUE;
  58.  
  59.     return TRUE ;
  60. }
  61.  
  62. int        FrmReadClose()
  63. {
  64.     fileclose() ;
  65.     return TRUE ;
  66. }
  67.  
  68. int        FrmReadObj( char *objname, Matrix Conv)
  69. {
  70.     if ( end_of_file )
  71.         return FALSE ;
  72.  
  73.     while( wordid != WORD_OBJ && MatSP > -1 )
  74.     {
  75.         if (end_of_file) return FALSE;
  76.         switch( wordid )
  77.         {
  78.             case WORD_OPEN2 :
  79.                 get() ;
  80.                 MatCopy( MatStack[MatSP+1], MatStack[MatSP] );
  81.                 if ( MatSP >= MAT_STACK_MAX ) {
  82.                     frmerror( MAT_STACK_OVERFLOW, "" );
  83.                     return FALSE;
  84.                 }
  85.                 else
  86.                 {
  87.                     MatSP ++ ;
  88.                     MatCopy( CurMat, MatStack[MatSP] );
  89.                 }
  90.                 break ;
  91.             case WORD_CLOSE2 :
  92.                 get() ;
  93.                 MatSP -- ;
  94.                 if ( MatSP > 0 )
  95.                     MatCopy( CurMat, MatStack[MatSP] );
  96.                 break ;
  97.             case WORD_LIGHT :
  98.                 get();
  99.                 if (wordid != WORD_PAL) {
  100.                     frmerror(NOT_IMPLIMENTED, nextword);
  101.                 } else {
  102.                     Color tmp;
  103.                     isopen1();
  104.                     getcolor(&tmp);
  105.                     getfloat();
  106.                     getfloat();
  107.                     getfloat();
  108.                     isclose1();
  109.                 }
  110.                 break;
  111.             case WORD_EYE :
  112.                 get();
  113.                 if (wordid != WORD_DEG) {
  114.                     frmerror(BAD_EXIST, nextword);
  115.                 } else {
  116.                     isopen1();
  117.                     getfloat();
  118.                     isclose1();
  119.                 }
  120.                 break;
  121.             case WORD_TARGET :
  122.                 get();
  123.                 break;
  124.             default :
  125.                 getmat( MatStack[MatSP] );
  126.                 MatCopy( CurMat, MatStack[MatSP] );
  127.                 UnitFlag = FALSE;
  128.                 break ;
  129.         }
  130.         if (lasterror) return FALSE;
  131.     }
  132.     if (lasterror) return FALSE;
  133.     if ( MatSP == -1 )
  134.         return FALSE ;
  135.  
  136.     get() ;
  137.  
  138.     MatCopy( Conv, CurMat );
  139.     strcpy( objname, nextword ) ;
  140.     get() ;
  141.  
  142.     return TRUE ;
  143. }
  144.  
  145. static    void    frmerror( n, arg )
  146. int        n ;
  147. char    *arg ;
  148. {
  149.     char    *msg ;
  150.     int        level ;
  151.  
  152.     switch( n )
  153.     {
  154.         case NOT_FOUND :
  155.             msg = " %s がありません。" ;
  156.             level = 10 ;
  157.             break ;
  158.         case BAD_EXIST :
  159.             msg = " %s が存在します。" ;
  160.             level = 10 ;
  161.             break ;
  162.         case NOT_IMPLIMENTED :
  163.             msg = " %s はサポートしていません。" ;
  164.             level = 10 ;
  165.             break ;
  166.         case NOT_FRM_FILE :
  167.             msg = "メカデザインファイルではありません。" ;
  168.             level = 10 ;
  169.         case LESS_POINT :
  170.             msg = "多角形の頂点が2つ以下しかありません。" ;
  171.             level = 10 ;
  172.             break ;
  173.         case MAT_STACK_OVERFLOW :
  174.             msg = "構\造定義が複雑すぎます。" ;
  175.             level = 10 ;
  176.             break ;
  177.         case UNEXPECTED_EOF :
  178.             msg = "エンドオブファイルになりました" ;
  179.             level = 20 ;
  180.             break ;
  181.         default :
  182.             msg = "エラーコードの誤り。( objread.c )" ;
  183.             level = 20 ;
  184.             break ;
  185.     }
  186.     errormessage( level, msg, arg );
  187. }
  188.