home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / REND.C < prev    next >
C/C++ Source or Header  |  1996-07-29  |  36KB  |  1,439 lines

  1. /*
  2.  *        Rendering    Program        Ver 2
  3.  *
  4.  *                1989.12.17
  5.  *                CopyRight    T.Kobayashi
  6.  */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12. #if !defined(DJ) && !defined(UNIX)
  13.     #include <conio.h>
  14. #endif
  15. #if defined(MSC)
  16.     #include <sys/types.h>
  17. #endif
  18.  
  19. #if defined(DJ) || defined(__BORLANDC__) || defined(MSC) || defined(UNIX)
  20.     #include <sys/stat.h>
  21.     #include <time.h>
  22. #else
  23.     #include <stat.h>
  24.     #include <time.h>
  25. #endif
  26.  
  27. #ifdef UNIX
  28. #define tolower(c) (('A' <= (c) && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c))
  29. #endif
  30.  
  31. #define REND
  32. #define    ESC    '\x1B'
  33.  
  34. #include "reader.h"
  35. #include "glib.h"
  36. #include "rend.h"
  37. #ifndef NO_PICLIB
  38. #include "piclib.h"
  39. #endif
  40.  
  41. #ifdef BG
  42.     #include "bg.h"
  43. #endif
  44.  
  45. /* 大域変数  */
  46. int        antiareas = 1 ;                /*    アンチエリアシング            */
  47. int        nflag = FALSE ;                /*    画像ファイル出力オプション    */
  48. int        uflag = FALSE ;                /*  画面出力オプション            */
  49. int        picerrorflag = FALSE ;        /*  画像ファイル出力エラー        */
  50. #ifdef EDGEANTI
  51. int        EdgeAntiFlag = TRUE;
  52. #endif
  53. #ifdef MAPANTI
  54. int        MapAntiFlag = FALSE;
  55. #endif
  56. #ifdef MOB
  57. int        TimeAnti = 1;
  58. #endif
  59. #ifdef WIREVIEW
  60. int        wiresize = 0;
  61. #endif
  62. int        fullcoloroutflag = FALSE;
  63. int        fullcolorditherflag = FALSE;
  64. #ifdef HIVISION
  65. int        XPosition = 0, YPosition = 0;
  66. PixelType        PixelMode = P256x256;
  67. #endif
  68. #ifdef BACKFACE
  69. int        backface = FALSE;
  70. #endif
  71. #ifdef    XC
  72.     int        WindowMode = FALSE ;    /*  ウインドウモード    */
  73. #endif
  74.  
  75. static    Pointer(Atr*)    atr = NULL ;            /*    アトリビュートリスト            */
  76. static    Pointer(Object*)    obj = NULL ;            /*    オブジェクトリスト                */
  77. static    int        startframe = 1 ;        /*    スタートフレーム                */
  78. static    int        endframe = 999 ;        /*    エンドフレーム                    */
  79. #ifdef NO_PICLIB
  80. static    char    picfile[F_NAME_LEN]="" ;    /*    画像ファイル                    */
  81. static    int        picnum=0 ;                /*  画像ファイルの番号                */
  82. #else
  83. static    PicSequence outseq;                /*    画像ファイル名                */
  84. #endif
  85.  
  86. #ifdef NO_PICLIB
  87. static    char    backfile[F_NAME_LEN]="" ;    /*  背景ファイル                    */
  88. static    int        backnum = 0 ;                /*  背景ファイルの番号                */
  89. #else
  90. static    PicSequence backseq;                /*    画像ファイル名                */
  91. #endif
  92.  
  93. #ifdef STAR
  94. static    int        stars = 0;                /*    背景の星の数                    */
  95. static    int        stardir = 0;            /*    背景の星の方向(上=0, 時計回り)    */
  96. static    int        starstep = 0;            /*    背景の星の速さ                    */
  97. #endif
  98. static    int        tflag = FALSE ;            /*    テンポラリファイル使用フラグ    */
  99. static    char    tempfile[F_NAME_LEN] ;    /*    テンポラリファイル                */
  100. static    char    virfile[F_NAME_LEN] ;    /*  仮想記憶ファイル                */
  101. static    char    *ext[4] =
  102.     { ".ATR", ".SUF", ".FRM", ".FSC" };    /*  拡張子                            */
  103.  
  104. #ifdef    BG
  105.     static    int        bgmode = 4 ;        /*  バックグラウンドのモード        */
  106.     static    struct    COMBUF    combuf ;    /*  通信バッファ                    */
  107. #endif
  108. #if defined(X68000)
  109.     static    long    dsize = 0L ;        /*    データ領域のサイズ                */
  110.     static    char    **WindowArgv ;        /*  引数ファイル名                    */
  111.     static    int        WindowArgc ;        /*    引数の数                        */
  112. #elif defined(DJ) || defined(UNIX) || defined(__WIN32__)
  113.     static    long    dsize = 16L*1024L*1024L ;/*    データ領域のサイズ            */
  114. #elif defined(MSC) || defined(__BORLANDC__)
  115.     static    long    dsize = 200L*1024L ;/*    データ領域のサイズ                */
  116. #else
  117.     static    long    dsize = 0L ;/*    データ領域のサイズ                */
  118. #endif
  119. #ifndef WINDOWS
  120.     static    char    precommandline[256] = "";
  121.     static    char    postcommandline[256] = "";
  122. #endif
  123.  
  124.     static    char    logfile[F_NAME_LEN]="REND.LOG";
  125.     static    char    logcommandline[1024]="";
  126.     static    int        logflag=FALSE;
  127.     FILE        *logfp = NULL;
  128.     static    long        peakusedarea=0, peakfreearea = 256L * 1024L * 1024L;
  129.     static    time_t    starttime, laptime1, laptime2;
  130.  
  131. #ifdef RENDXVI
  132.     int _SSP;
  133. #endif
  134.  
  135. /*
  136.     proto -s rend.c > temp
  137. */
  138. #ifdef WINDOWS
  139. extern    void    check_winmessage( void );
  140. #else
  141. static    void    check_esc( void );
  142. #endif
  143. #ifdef BG
  144. static    void    check_kill( void );
  145. #endif
  146. static    void    mainloop( void );
  147. static    void    analizeargs( int, char*[] );
  148. static    void    analizeoption( char* );
  149. static    int        piccheck( char* );
  150. static    void    usage( void );
  151. static    void    error( int, char* );
  152. static    int        isext( char* );
  153.  
  154. #ifndef WINDOWS
  155. void commandexec(char *, int, char *, int, char *, int);
  156. #endif
  157. #ifdef WINDOWS
  158. int        Main(int argc, char *argv[] )
  159. #else
  160. int        main(int argc, char *argv[] )
  161. #endif
  162. {
  163. #ifdef RENDXVI
  164.     _SSP = SUPER( 0 );
  165. #endif
  166.     fprintf(stderr, "%s%s%s", program, version, copyright);
  167.     virtualmode = FALSE ;
  168. #ifdef WINDOWS
  169.     interrupt = check_winmessage ;
  170. #else
  171.     interrupt = check_esc ;
  172. #endif
  173.     (*interrupt)();
  174.     errorexec = (void (*)(int))error ;
  175.  
  176.     analizeargs( argc, argv );
  177.  
  178. #ifdef    BG
  179.     if ( BackGroundJob )
  180.     {
  181.         int        ret ;
  182.         static  char    sspbuf[1000] ;
  183.         extern    char    *_SEND ;
  184.  
  185.         combuf.bufsize = 0 ;
  186.         combuf.address = NULL ;
  187.         combuf.flag = 0xFFFF ;
  188.         interrupt = check_kill ;
  189.  
  190.         ret = bg_set( "REND", bgmode, _SEND, sspbuf+1000,
  191.                         mainloop, &combuf, 2000 );
  192.         if ( ret < 0 )
  193.         {
  194.             fprintf( stderr,
  195.                 "バックグラウンドプロセスを登録できませんでした。\n" );
  196.             exit( 1 );
  197.         }
  198.         freopen( "nul", "w", stdout );
  199.         freopen( "nul", "w", stderr );
  200.         keepexit( 1, 0 );
  201.     }
  202. #endif
  203.     mainloop();
  204. #ifdef RENDXVI
  205.     STACK_ADJUST:
  206.     SUPER( _SSP );
  207. #endif
  208.     return( 0 );
  209. }
  210.  
  211. #ifndef WINDOWS
  212. static    void    check_esc()
  213. {
  214. #if (defined(VGA) || !defined(DJ)) && !defined(UNIX)
  215.     while( kbhit() != 0 )
  216.     {
  217.         if ( getch() == ESC )
  218.         {
  219.             fprintf( stderr, "\nESC キーが押されました。\n" );
  220.             fprintf( stderr, "処理を中断します。\n\n" );
  221.             fcloseall();
  222. #ifdef    VIRTUAL
  223.             if ( virtualmode )
  224.                 unlink( virfile );
  225. #endif
  226.             exit( 1 );
  227.         }
  228.     }
  229. #endif
  230. }
  231. #endif
  232.  
  233. #ifdef    BG
  234. static    void    check_kill()
  235. {
  236.     bg_check_kill( &combuf, "REND を終了します。" );
  237. }
  238. #endif
  239. static    void    mainloop()
  240. {
  241.     long n;
  242.     int        fr ;    /*    フレーム数 */
  243.     char    name[F_NAME_LEN] ;
  244.     long    size ;
  245.     Frame    *frame ;
  246.     Pointer(void*)    mark;
  247.     Pointer(void*) errormark ;
  248.     FILE    *fp ;
  249.  
  250.     size = datasize();
  251.     mark = datamark();
  252.  
  253.     for( fr = 1 ; fr < startframe ; ++fr )
  254.     {
  255. #ifdef STAR
  256.         if (stars > 0) {
  257.             StarStep();
  258.         }
  259. #endif
  260.         if ( frameskip() == 0 )
  261.             error( 1, NULL );
  262.     }
  263.  
  264.     PictureOutput = picout ;
  265.  
  266.     if ( ! uflag )
  267.     {
  268.         LineOutput = piclineout ;
  269. #ifdef HIVISION
  270.         {
  271.             switch (PixelMode) {
  272.                 case P256x256:        crtinit(  256 );    break;
  273.                 case P512x512:        crtinit(  512 );    break;
  274.                 case P640x400:        crtinit(  512 );    break;
  275.                 case P640x480:        crtinit(  512 );    break;
  276.                 case P1024x1024:    crtinit( 1024 );    break;
  277.                 case P1920x1125:    crtinit( 2048 );    break;
  278.                 case P2048x2048:    crtinit( 2048 );    break;
  279.                 case P4096x4096:    crtinit( 4096 );    break;
  280.                 default:
  281.                     ;
  282.             }
  283.         }
  284. #else
  285.         crtinit( YPixel / antiareas );
  286. #endif
  287.     }
  288.  
  289.     if (logflag) {
  290.         laptime1 = time(NULL);
  291.     }
  292. #ifdef NO_PICLIB
  293.     if ( picnum == 0 )
  294.         picnum = fr ;
  295. #else
  296.     if (outseq.number == 0) {
  297.         outseq.number = fr;
  298.     }
  299.     PicSequence_forceAnim(&outseq);
  300. #endif
  301.     while( ! end_of_file && fr <= endframe )
  302.     {
  303. #ifndef WINDOWS
  304.         if (precommandline[0] != '\0') {
  305. #ifdef NO_PICLIB
  306.             commandexec(precommandline, fr, picfile, picnum, backfile, backnum);
  307. #else
  308.             commandexec(precommandline, fr, outseq.body, outseq.number, backseq.body, backseq.number);
  309. #endif
  310.         }
  311. #endif
  312.         frame = frameread( obj );
  313.         if ( frame == NULL )
  314.             error( 1, NULL );
  315.         errormark = datamark();
  316.         do
  317.         {
  318.             if ( ! uflag )
  319.                 crtclr();
  320.             fprintf( stderr, "Frame %d\n", fr );
  321. #ifndef VGA
  322.             fprintf( stderr, "   使用データ領域  : %ld Byte\n", size );
  323. #else
  324.             fprintf( stderr, "   Data  : %ld Byte\n", size );
  325. #endif
  326. #ifdef WINDOWS
  327.             if (logflag && logfp != NULL) {
  328.                 fprintf( logfp, "Frame %d\n", fr );
  329.                 fprintf( logfp, "   使用データ領域  : %ld Byte\n", size );
  330.             }
  331. #endif
  332.             n = ViewConv( frame );
  333.             picerrorflag = FALSE ;
  334.             if (logflag) {
  335.                 laptime2 = time(NULL);
  336.             }
  337. #ifndef VGA
  338.             fprintf( stderr, "   使用ワーク領域  : %ld Byte\n", datasize() - size );
  339.             fprintf( stderr, "   ポリゴン数      : %ld\n", n );
  340. #else
  341.             fprintf( stderr, "   Work  : %ld Byte\n", datasize() - size );
  342.             fprintf( stderr, "   Polys : %ld\n", n );
  343. #endif
  344. #ifdef WINDOWS
  345.             if (logflag && logfp != NULL) {
  346.                 fprintf( logfp, "   使用ワーク領域  : %ld Byte\n",
  347.                                                 datasize() - size );
  348.                 fprintf( logfp, "   ポリゴン数      : %ld\n", n );
  349.             }
  350. #endif
  351. #ifdef NO_PICLIB
  352.             sprintf( name, "%s%03d.PIC", picfile, picnum );
  353. #else
  354.             PicSequence_get(&outseq, name);
  355. #endif
  356.             if ( BackLoad )
  357.             {
  358. #ifdef NO_PICLIB
  359.                 if ( backnum == 0 )
  360.                 {
  361.                     sprintf( BackFile, "%s.PIC", backfile );
  362.                 }
  363.                 else
  364.                 {
  365.                     sprintf( BackFile, "%s%03d.PIC", backfile, backnum );
  366.                 }
  367. #else
  368.                 PicSequence_get(&backseq, BackFile);
  369. #endif
  370.             }
  371.             fp = picinit( name );
  372. #ifdef WIREVIEW
  373.             if (nflag || fp != NULL) {
  374.                 if (wiresize == 0) {
  375.                     Display( frame, n );
  376.                 } else {
  377.                     wiresave();
  378.                 }
  379.             }
  380. #else
  381.             if (nflag || fp != NULL )
  382.             {
  383.                 Display( frame, n );
  384.             }
  385. #endif
  386.             if ( picerrorflag )
  387.             {
  388.                 datarelease( errormark );
  389.                 if ( ! uflag )
  390.                     crtclr();
  391. #ifdef WINDOWS
  392.                 error(0, "ファイル出力に失敗しました" );
  393. #endif
  394.                 fprintf( stderr, "画像ファイル出力でエラーが発生しました。\n" );
  395.                 fprintf( stderr, "ディスクがいっぱいだと思われます。\n" );
  396. #ifndef WINDOWS
  397.                 fprintf( stderr, "ディスクを入れ替えてください。\n" );
  398.                 fprintf( stderr, "準備ができたらどれかキーを押してください。\n" );
  399. #endif
  400. #ifdef DJ
  401.                 fgetc(stdin);
  402. #else
  403. #ifdef UNIX
  404.                 fgetc(stdin);
  405. #else
  406.                 getch() ;
  407. #endif
  408. #endif
  409.             }
  410.         }
  411.         while( picerrorflag );
  412.  
  413.         if (logflag) {
  414.             long freearea, usedarea;
  415.             time_t nowtime;
  416.             nowtime = time(NULL);
  417.             if (logfp  != NULL) {
  418.                 fprintf(logfp, "%24s %6dkB %6dkB %6dkB %8d %5d秒 %5d秒\n",
  419.                 name, size/1024, ((usedarea=datasize())-size-1)/1024+1, (freearea=memgetsize())/1024,
  420.                 n, laptime2 - laptime1, nowtime - laptime2);
  421.                 if (usedarea > peakusedarea) {
  422.                     peakusedarea = usedarea;
  423.                 }
  424.                 if (freearea < peakfreearea) {
  425.                     peakfreearea = freearea;
  426.                 }
  427.                 laptime1 = nowtime;
  428.             }
  429.         }
  430.  
  431.         datarelease( mark );
  432. #ifndef WINDOWS
  433.         if (postcommandline[0] != '\0') {
  434. #ifdef NO_PICLIB
  435.             commandexec(postcommandline, fr, picfile, picnum, backfile, backnum);
  436. #else
  437.             commandexec(postcommandline, fr, outseq.body, outseq.number, backseq.body, backseq.number);
  438. #endif
  439.         }
  440. #endif
  441.         fr ++ ;
  442. #ifdef NO_PICLIB
  443.         picnum ++ ;
  444.         if ( BackLoad && backnum != 0) {
  445.             backnum ++ ;
  446.         }
  447. #else
  448.         PicSequence_next(&outseq);
  449.         if (BackLoad) {
  450.             PicSequence_next(&backseq);
  451.         }
  452. #endif
  453.     }
  454.     if (logflag) {
  455.         time_t nowtime, lap;
  456.         nowtime = time(NULL);
  457.         lap = nowtime - starttime;
  458.         if (logfp != NULL) {
  459.             fprintf(logfp, "総所要時間=%d:%02d:%02d 最大使用メモリ領域=%8dkB 最小空きメモリ領域=%8dkB\n",
  460.                     lap / 3600, (lap / 60) % 60, lap % 60,
  461.                     (peakusedarea-1)/1024+1, peakfreearea/1024);
  462.         }
  463.     }
  464.  
  465. #ifndef DJ
  466. #ifndef UNIX
  467.     fcloseall();
  468. #endif
  469. #endif
  470. #ifdef    VIRTUAL
  471.     if ( virtualmode )
  472.         unlink( virfile );
  473. #endif
  474. #ifdef    BG
  475.     if ( BackGroundJob )
  476.         bg_kill();
  477. #endif
  478. }
  479.  
  480. /*    コマンドラインの評価    */
  481. static    void    analizeargs( argc, argv )
  482. int        argc ;
  483. char    *argv[] ;
  484. {
  485.     int        i, j;
  486.     int        files[4] ;
  487.     char    framefile[F_NAME_LEN], framesource[F_NAME_LEN], *p ;
  488.     char    buf[256] ;
  489.     char    *option ;
  490.     long    fsctime ;
  491.     struct    stat    statbuf, *sbuf = &statbuf ;
  492.  
  493.     option = getenv( "RENDLOG" );
  494.     if ( option == NULL )
  495.         option = getenv( "rendlog" );
  496.     if ( option != NULL ) {
  497.         logflag = TRUE;
  498.         if ( option[0] == '\0' )
  499.             strcpy( logfile, "REND.LOG" );
  500.         else
  501.             strcpy( logfile, option );
  502.         i = strlen( logfile );
  503.         if ( logfile[i-1] == '\\' || logfile[i-1] == ':' )
  504.             strcat( logfile, "REND.LOG" );
  505.     }
  506.     for (i = 1; i < argc; ++i) {
  507. #ifdef NOSLASHOPT
  508.         if ((argv[i][0] == '-') && (argv[i][1] == 'l' || argv[i][1] == 'L')) {
  509. #else
  510.         if ((argv[i][0] == '-' || argv[i][0] == '/') && (argv[i][1] == 'l' || argv[i][1] == 'L')) {
  511. #endif
  512.             logflag = TRUE;
  513.             break;
  514.         }
  515.     }
  516.     if (logflag) {
  517.         for (i = 0; i < argc; ++i) {
  518.             strcat(logcommandline, " ");
  519.             strcat(logcommandline, argv[i]);
  520.         }
  521.     }
  522.  
  523.     extendargs( &argc, &argv, 4, ext );
  524.     if ( argc == 1 )
  525.         usage() ;
  526.  
  527. #ifdef NO_PICLIB
  528.     strcpy( picfile, "" );
  529.     picnum = 0 ;
  530. #else
  531.     outseq.body[0] = '\0';
  532.     outseq.number = 0;
  533.     backseq.body[0] = '\0';
  534. #endif
  535.     for( i = 0 ; i < 4 ; ++i )
  536.         files[i] = 0 ;
  537.  
  538. #ifdef WINDOWS
  539.     XPixel = 320;
  540.     YPixel = 240;
  541.     PixelRatio = 1.0;
  542.     PixelMode = P512x512;
  543. #endif
  544.     for( i = 1 ; i < argc ; ++i )
  545.     {
  546. #ifdef NOSLASHOPT
  547.         if ( argv[i][0] == '-' )
  548. #else
  549.         if ( argv[i][0] == '-' || argv[i][0] == '/' )
  550. #endif
  551.         {
  552.             analizeoption( argv[i] );
  553.             argv[i] = "" ;
  554.         }
  555.     }
  556.  
  557. #ifdef    XC
  558.     if ( WindowMode )
  559.     {
  560.         argv = WindowArgv - 1 ;
  561.         argc = WindowArgc + 1 ;
  562.     }
  563. #endif
  564.     for( i = 1 ; i < argc ; ++i )
  565.     {
  566.         if ( argv[i][0] != '\0' )
  567.         {
  568.             j = isext( argv[i] ) ;
  569.             switch( j )
  570.             {
  571.                 case -1 :
  572.                     usage();
  573.                     break ;
  574.                 case 2 :
  575.                     if ( files[3] == 0 )
  576.                     {
  577.                         strcpy( framefile, argv[i] );
  578.                         files[2] = 1 ;
  579.                     }
  580.                     break ;
  581.                 case 3 :
  582. #ifndef WINDOWS
  583.                     files[2] = 0 ;
  584.                     files[3] = 1 ;
  585.                     strcpy( framefile, argv[i] );
  586. #endif
  587.                     break ;
  588.                 default :
  589.                     files[j] ++ ;
  590.                     break ;
  591.             }
  592.         }
  593.     }
  594. #ifndef MESSAGE
  595.     fprintf( stderr, "\n" );
  596. #endif
  597.  
  598. #ifdef    BG
  599.     if ( BackGroundJob && dsize == 0 )
  600.         error( 0, "データ領域の大きさを指定されていません。" );
  601. #endif
  602. #ifdef WIREVIEW
  603.     if (wiresize > 0) {
  604.         ShadingModel = FLAT_SHADE;
  605.     }
  606. #endif
  607.  
  608.  
  609.     XPixel *= antiareas ;
  610.     YPixel *= antiareas ;
  611.     if ( YPixel > MAXLINE )
  612.         error( 0, "解像度が高すぎます。" );
  613.  
  614.  
  615.     if (logflag) {
  616.         if (logfp != NULL) {
  617.             fputs("コマンドライン =", logfp);
  618.             fputs(logcommandline, logfp);
  619.             fputs("\n          画像ファイル名   データ   ワーク   残メモリ ポリゴン数 透視変換 作画\n", logfp);
  620.         } else {
  621.             logflag = FALSE;
  622.         }
  623.         starttime = time(NULL);
  624.     }
  625.  
  626.     /*    エラーチェック    */
  627.     if ( files[0] == 0 )
  628.         error( 0, "アトリビュートファイルがありません。" );
  629.     if ( files[1] == 0 )
  630.         error( 0, "形状ファイルがありません。" );
  631.     if ( files[2] == 0 && files[3] == 0 )
  632.         error( 0, "フレームファイルがありません。" );
  633. #ifdef NO_PICLIB
  634.     if ( strcmp( picfile, "" ) == 0 )
  635.         strcpy( picfile, framefile );
  636.     picnum = piccheck( picfile );
  637. #else
  638.     if (outseq.body[0] == '\0') {
  639.         PicSequence_set(&outseq, framefile);
  640.         strcpy(outseq.ext, "PIC");
  641.     }
  642. #endif
  643.  
  644.     /*    フレームソースのときの処理    */
  645.     if ( files[3] > 0 )
  646.     {
  647.         strcpy( framesource, framefile );
  648.         p = strrchr( framefile, '.' );
  649.         strcpy( p, ".FRM" );
  650.         if ( stat( framesource, sbuf ) == -1 )
  651. #ifdef JAP
  652.             error( 0, "フレームソ\ースファイルがありません。" );
  653. #else
  654.             error( 0, "フレームソースファイルがありません。" );
  655. #endif
  656.         fsctime = sbuf->st_atime ;
  657.         if ( stat( framefile, sbuf ) == -1 || fsctime > sbuf->st_atime )
  658.         {
  659.             option = getenv( "FFOPTION" );
  660.             if ( option == NULL )
  661.                 option = getenv( "ffoption" );
  662.             if ( option == NULL )
  663.                 option = "" ;
  664.     #ifdef DJ
  665.             sprintf( buf, "ff386 %s %s", option, framesource );
  666.     #else
  667.             sprintf( buf, "ff %s %s", option, framesource );
  668.     #endif
  669.             system( buf );
  670.             fprintf( stderr, "\n" );
  671.         }
  672.     }
  673.  
  674.  
  675.     /*    データバッファの初期化  */
  676.     meminit( dsize );
  677. #ifdef    VIRTUAL
  678.     if ( virtualmode )
  679.         virinit( virfile );
  680. #endif
  681.  
  682.  
  683. #ifdef STAR
  684.     if (stars > 0) {
  685.         StarInit(stars, stardir, starstep);
  686.     }
  687. #endif
  688.  
  689.     /*    アトリビュートファイルのリード    */
  690.     fprintf( stderr, "Reading Attribute File\n" );
  691. #ifdef WINDOWS
  692.     if (logflag && logfp != NULL) {
  693.         fprintf( logfp, "Reading Attribute File\n" );
  694.     }
  695. #endif
  696.     for( i = 1 ; i < argc ; ++i )
  697.     {
  698.         if ( isext( argv[i] ) == 0 )
  699.         {
  700.             fprintf( stderr, "%s\n", argv[i] );
  701. #ifdef WINDOWS
  702.             if (logflag && logfp != NULL) {
  703.                 fprintf( logfp, "%s\n", argv[i] );
  704.             }
  705. #endif
  706.             atr = atrread( argv[i], atr ) ;
  707.             if ( atr == NULL )
  708.                 error( 1, NULL );
  709.             argv[i] = "" ;
  710.         }
  711.     }
  712.     if ( ShadingModel == GOURAUD_SHADE )
  713.         MapInit( atr );
  714.  
  715.     /*    形状ファイルのリード    */
  716.     fprintf( stderr, "Reading Object File\n" );
  717. #ifdef WINDOWS
  718.     if (logflag && logfp != NULL) {
  719.         fprintf( logfp, "Reading Object File\n" );
  720.     }
  721. #endif
  722.  
  723.     if ( tflag )
  724.         tempopen( tempfile );
  725.     for( i = 1 ; i < argc ; ++i )
  726.     {
  727.         if ( isext( argv[i] ) == 1 )
  728.         {
  729.             fprintf( stderr, "%s\n", argv[i] );
  730. #ifdef WINDOWS
  731.             if (logflag && logfp != NULL) {
  732.                 fprintf( logfp, "%s\n", argv[i] );
  733.             }
  734. #endif
  735.             if ( tflag )
  736.                 obj = tempread( argv[i], obj );
  737.             else
  738.                 obj = objread( argv[i], obj );
  739.             if ( obj == NULL )
  740.                 error( 1, NULL );
  741.             argv[i] = "" ;
  742.         }
  743.     }
  744.     if ( tflag )
  745.         tempclose( tempfile );
  746.     if ( objatr( obj, atr ) == FALSE )
  747.         exit( 1 );
  748.  
  749.     /*    フレームファイルのオープン    */
  750.     fprintf( stderr, "Reading Frame File\n" );
  751.     fprintf( stderr, "%s\n", framefile );
  752. #ifdef WINDOWS
  753.     if (logflag && logfp != NULL) {
  754.         fprintf( logfp, "Reading Frame File\n" );
  755.         fprintf( logfp, "%s\n", framefile );
  756.     }
  757. #endif
  758.  
  759.     if ( frameopen( framefile ) == 0 )
  760.         error( 1, NULL );
  761. }
  762.  
  763. /*    オプションの評価、ファイル名のチェック    */
  764. static    void    analizeoption( str )
  765. char    *str ;
  766. {
  767.     int        i, n ;
  768.     char    *p ;
  769. #ifdef    BG
  770.     struct    PROCESS    processbuf ;
  771. #endif
  772.  
  773.     switch( tolower( str[1] ) )
  774.     {
  775.         case 'a' :
  776. #ifdef MAPANTI
  777.             if (tolower(str[2]) == 'm') {
  778.                 MapAntiFlag = TRUE;
  779.                 fprintf(stderr, "マッピングにアンチエイリアシングをかけます。\n");
  780.                 break;
  781.             }
  782. #endif
  783. #ifdef MOB
  784.             if (tolower(str[2]) == 't') {
  785.                 n = atoi(str+3);
  786.                 if (n != 2 && n != 4) {
  787.                     error( 0, "オプション'AT'の指定の誤り" );
  788.                 }
  789.                 fprintf( stderr,
  790.                     "時間方向に %d 倍解像度でアンチエリアシングをかけます。\n", n );
  791.                 TimeAnti = n;
  792.                 break;
  793.             }
  794. #endif
  795.             n = atoi( str+2 );
  796.             if ( n <= 1 || 9 <= n )
  797.             error( 0, "オプション'A'が 2 ~ 9 に収まってません" );
  798.             fprintf( stderr,
  799.                 " %d 倍解像度でアンチエリアシングをかけます。\n", n );
  800.             antiareas = n ;
  801.             break ;
  802.         case 'b' :
  803. #ifdef BGMAKE
  804.             if (str[2] == '\0') {
  805. #endif
  806.             fprintf( stderr, "バックを透明にします。\n" );
  807.             TraBack = 1 ;
  808. #ifdef BGMAKE
  809.             } else {
  810.                 BgMake = 0;
  811.                 p = str+2;
  812.                 i = 0;
  813.                 for (;*p;p++) {
  814.                     if (*p == ',' || (i > 2 && *p == ':')) {
  815.                         BgMakeFile[BgMake][i] = '\0';
  816.                         i = 0;
  817.                         BgMake++;
  818.                         if (BgMake == 12) {
  819.                             error( 0, "オプション'B'画像数が多すぎる" );
  820.                         }
  821.                     } else {
  822.                         BgMakeFile[BgMake][i++] = *p;
  823.                     }
  824.                 }
  825.                 BgMakeFile[BgMake][i] = '\0';
  826.                 BgMake++;
  827.                 if (BgMake == 1) {
  828.                     fprintf( stderr, "背景球を、極座標系: %s で行います。\n",BgMakeFile[0]);
  829.                 } else if (BgMake == 2) {
  830.                     fprintf( stderr, "背景球を、前後: %s、左右: %s で行います。\n",
  831.                             BgMakeFile[0], BgMakeFile[1]);
  832.                 } else if (BgMake == 4) {
  833.                     fprintf( stderr, "背景球を、前: %s、右: %s 後: %s 左: %s で行います。\n",
  834.                             BgMakeFile[0], BgMakeFile[1],
  835.                             BgMakeFile[2], BgMakeFile[3]);
  836.                 } else if (BgMake == 6) {
  837.                     fprintf( stderr, "背景球を、上前後: %s、上左右: %s 中前後: %s 中左右: %s 下前後: %s 下左右: %s で行います。\n",
  838.                             BgMakeFile[0], BgMakeFile[1],
  839.                             BgMakeFile[2], BgMakeFile[3],
  840.                             BgMakeFile[4], BgMakeFile[5]);
  841.                 } else if (BgMake == 12) {
  842.                     fprintf( stderr,
  843.                         "背景球を、\n"
  844.                         "\t上: %s, %s, %s, %s\n"
  845.                         "\t中: %s, %s, %s, %s\n"
  846.                         "\t下: %s, %s, %s, %s\n"
  847.                         "\t\tで行います。\n",
  848.                         BgMakeFile[0], BgMakeFile[1],BgMakeFile[2],BgMakeFile[3],
  849.                         BgMakeFile[4], BgMakeFile[5],BgMakeFile[6],BgMakeFile[7],
  850.                         BgMakeFile[8], BgMakeFile[9],BgMakeFile[10],BgMakeFile[11]);
  851.                 } else {
  852.                     error( 0, "オプション'B' 画像の枚数がおかしい" );
  853.                 }
  854.             }
  855. #endif
  856.             break ;
  857.         case 'c' :
  858. #ifdef HIVISION
  859.             {
  860.                 int nx = 0, ny = 0;
  861.                 int rx = 0, ry = 0;
  862.                 int cc;
  863.                 nx = atoi( str+2 ) ;
  864.                 for (cc = 2; str[cc]; ++cc) {
  865.                     if (str[cc] == 'X' || str[cc] == 'x' || str[cc] == '*'
  866.                      || str[cc] == ',' || str[cc] == ':') {
  867.                         ny = atoi(str+cc+1);
  868.                         break;
  869.                     }
  870.                 }
  871.                 if (ny != 0) {
  872.                     for (cc++; str[cc]; ++cc) {
  873.                         if (str[cc] == ',' || str[cc] == ':') {
  874.                             rx = atoi(str+cc+1);
  875.                             break;
  876.                         }
  877.                     }
  878.                 }
  879.                 if (rx != 0) {
  880.                     for (cc++; str[cc]; ++cc) {
  881.                         if (str[cc] == ',' || str[cc] == ':') {
  882.                             ry = atoi(str+cc+1);
  883.                             break;
  884.                         }
  885.                     }
  886.                 }
  887.                 if (ny == 0) {
  888.                     ny = nx;
  889.                 }
  890.                 XPixel = nx;
  891.                 YPixel = ny;
  892.                 if (nx == 320 && ny == 200) {
  893.                     PixelMode = P320x200;
  894.                     PixelRatio = 1.00;
  895.                 } else if (nx == 320 && ny == 240) {
  896.                     PixelMode = P512x512;
  897.                     PixelRatio = 1.00;
  898.                 } else if (nx == 640 && ny == 400) {
  899.                     PixelMode = P640x400;
  900.                     PixelRatio = 1.00;
  901.                 } else if (nx == 640 && ny == 480) {
  902.                     PixelMode = P640x480;
  903.                     PixelRatio = 1.00;
  904.                 } else if (nx == 1920 && ny == 1125) {
  905.                     PixelMode = P1920x1125;
  906.                     PixelRatio = 1.00;
  907.                 } else if (2 <= nx && nx <= 512 && 2 <= ny && ny <= 512) {
  908.                     if (XPixel >  256 || YPixel > 256) {
  909.                         PixelMode = P512x512;
  910.                     } else {
  911.                         PixelMode = P256x256;
  912.                     }
  913. /*                    PixelRatio = 0.75;*/
  914.                     PixelRatio = (Float)XPixel / (Float)YPixel * 0.75;
  915.                 } else if (nx <= 1024 && ny <= 1024) {
  916.                     PixelMode = P1024x1024;
  917.                     PixelRatio = 0.75;
  918.                 } else if (nx <= 2048 && ny <= 2048) {
  919.                     PixelMode = P2048x2048;
  920.                     PixelRatio = (Float)XPixel / (Float)YPixel * 0.75;
  921.                 } else if (nx <= 4096 && ny <= 4096) {
  922.                     PixelMode = P4096x4096;
  923.                     PixelRatio = (Float)XPixel / (Float)YPixel * 0.75;
  924.                 } else {
  925.                     error( 0, "オプション'C' 解像度が高すぎる" );
  926.                 }
  927.                 if (rx != 0 && ry != 0) {
  928.                     PixelRatio = (Float)XPixel / (Float)YPixel * (Float)ry / (Float)rx;
  929.                 }
  930.             }
  931. #else
  932.             n = atoi( str+2 ) ;
  933.             if ( n == 256 || n == 512 )
  934.                 XPixel = YPixel = n ;
  935.             else
  936.                 error( 0, "オプション'C'の指定の誤り" );
  937. #endif
  938.             fprintf( stderr, "画面サイズは %d * %d です。\n", XPixel, YPixel );
  939.             break ;
  940.         case 'd' :
  941.             n = atoi(str+2);
  942.             if (tolower(str[2]) == 'r') {
  943.                 fprintf( stderr, "ランダムディザをかけて作画します。\n");
  944.                 fullcoloroutflag = FALSE;
  945.                 fullcolorditherflag = RANDOMDITHER;
  946.             } else if (tolower(str[2]) == 'e' && str[3] == '2') {
  947.                 fprintf( stderr, "誤差拡散で256色で作画します。\n");
  948.                 fullcoloroutflag = FALSE;
  949.                 fullcolorditherflag = ERRORDIFUSION2;
  950.             } else if (tolower(str[2]) == 'e') {
  951.                 fprintf( stderr, "誤差拡散で作画します。\n");
  952.                 fullcoloroutflag = FALSE;
  953.                 fullcolorditherflag = ERRORDIFUSION;
  954.             } else if (n==0 || n == 200 || n == 400 || tolower(str[2]) == 'd'|| n == 2) {
  955.                 fprintf( stderr, "ディザをかけて疑似200万色で作画します。\n");
  956.                 fullcoloroutflag = FALSE;
  957.                 fullcolorditherflag = ORDEREDDITHER4;
  958.             } else if (tolower(str[2]) == 'o' || n == 4) {
  959.                 fprintf( stderr, "ディザをかけて疑似1400万色で作画します。\n");
  960.                 fullcoloroutflag = FALSE;
  961.                 fullcolorditherflag = ORDEREDDITHER8;
  962.             } else if (tolower(str[2]) == 'f'
  963.                  || tolower(str[2]) == 't' || n == 1600) {
  964.                 fprintf( stderr, "16,777,216色フルカラーで作画します。\n");
  965.                 fullcoloroutflag = TRUE;
  966.                 fullcolorditherflag = ORDEREDDITHER4;
  967.             } else {
  968.                 error( 0, "オプション'D'は r, e, o, tのどれか" );
  969.             }
  970.             break;
  971. #ifndef WINDOWS
  972.         case 'e' :
  973.                 if (str[2] == '0' || tolower(str[2]) == 's' || tolower(str[2]) == 'b') {
  974.                     strcpy(precommandline, str+3);
  975.                     fprintf( stderr, "各フレーム作画直前にコマンド'%s'を実行します。\n", str+3);
  976.                     if (tolower(precommandline[0]) == 'd' &&
  977.                         tolower(precommandline[1]) == 'e' &&
  978.                         tolower(precommandline[2]) == 'l' &&
  979.                         isspace(precommandline[3])) {
  980.                     } else {
  981.                         dsize = (long)-512*1024;
  982.                     }
  983.                 } else if (str[2] == '1' || tolower(str[2]) == 'e') {
  984.                     strcpy(postcommandline, str+3);
  985.                     fprintf( stderr, "各フレーム作画直後にコマンド'%s'を実行します。\n", str+3);
  986.                     if (tolower(precommandline[0]) == 'd' &&
  987.                         tolower(precommandline[1]) == 'e' &&
  988.                         tolower(precommandline[2]) == 'l' &&
  989.                         isspace(precommandline[3])) {
  990.                     } else {
  991.                         dsize = (long)-512*1024;
  992.                     }
  993.                 }
  994.             break;
  995. #endif
  996.         case 'f' :
  997.             FrontClip = atof( str+2 );
  998.             if ( FrontClip <= 0.0 )
  999.                 error( 0, "前面クリッピング距離がおかしい。" );
  1000.             fprintf( stderr,
  1001.                 "前面クリッピング距離を %g にします。\n", FrontClip );
  1002.             break ;
  1003.         case 'g' :
  1004.             ShadingModel = GOURAUD_SHADE ;
  1005.             fprintf( stderr, "スムーズシェーディングをかけます。\n" );
  1006.             break ;
  1007.         case 'h' :
  1008.                 BackLoad = TRUE ;
  1009. #ifdef NO_PICLIB
  1010.                 strcpy( backfile, str+2 );
  1011.                 fprintf( stderr, "背景をファイル %s から読み込みます。\n", backfile );
  1012.                 backnum = piccheck( backfile );
  1013. #else
  1014.                 PicSequence_set(&backseq, str+2);
  1015.                 fprintf( stderr, "背景をファイル %s から読み込みます。\n", str+2 );
  1016. #endif
  1017.             break ;
  1018. #ifdef STAR
  1019.         case 'i' :
  1020.             {
  1021.                 int cc, dir = 0, step = 0;
  1022.                 n = atoi(str+2);
  1023.                 for (cc = 2; str[cc]; ++cc) {
  1024.                     if (str[cc] == 'X' || str[cc] == 'x' || str[cc] == '*'
  1025.                      || str[cc] == ',' || str[cc] == ':') {
  1026.                         dir = atoi(str+cc+1);
  1027.                         break;
  1028.                     }
  1029.                 }
  1030.                 if (isdigit(str[cc+1]) || str[cc+1] == '-') {
  1031.                     for (cc++; str[cc]; ++cc) {
  1032.                         if (str[cc] == ',' || str[cc] == ':') {
  1033.                             step = atoi(str+cc+1);
  1034.                             break;
  1035.                         }
  1036.                     }
  1037.                 }
  1038.                 if (n == 0) {
  1039.                     n = 1000;
  1040.                 }
  1041.                 if (-180 <= dir && dir <= 360 && 0 < step && step <= 360) {
  1042.                     fprintf( stderr, "背景に %d 度方向に速さ %d 度で進む %d 個の星を描きます。\n", dir, step, n );
  1043.                     stardir = dir;
  1044.                     starstep = step;
  1045.                 } else {
  1046.                     fprintf( stderr, "背景に %d 個の星を描きます。\n", n );
  1047.                 }
  1048.                 stars = n;
  1049.             }
  1050.             break;
  1051. #endif
  1052. #ifdef    BG
  1053.         case 'j' :
  1054.             BackGroundJob = TRUE ;
  1055.             n = atoi( str+2 );
  1056.             if ( 0 < n && n < 256 )
  1057.                 bgmode = n ;
  1058.             fprintf( stderr, "バックグラウンドジョブで実行します。\n" );
  1059.             break ;
  1060. #endif
  1061. #ifdef EDGEANTI
  1062.         case 'k' :
  1063.             EdgeAntiFlag = FALSE;
  1064.             fprintf( stderr, "エッジにアンチエイリアシングをかけません。\n" );
  1065.             break;
  1066. #endif
  1067.         case 'l' :
  1068.             logflag = TRUE;
  1069.             if ( str[2] == '\0' )
  1070.                 strcpy( logfile, "REND.LOG" );
  1071.             else
  1072.                 strcpy( logfile, str+2 );
  1073.             i = strlen( logfile );
  1074.             if ( logfile[i-1] == '\\' || logfile[i-1] == ':' )
  1075.                 strcat( logfile, "REND.LOG" );
  1076.             fprintf( stderr, "作画ログを %s に書き込みます。\n", logfile );
  1077.             logfp = fopen(logfile, "a");
  1078. #ifdef WINDOWS
  1079.             errfp = logfp;
  1080. #endif
  1081.             break ;
  1082.         case 'm' :
  1083.             n = atoi( str+2 );
  1084.             if ( n < -1000 || 16000 < n )
  1085.                 error( 0, "オプション'M' 指定の誤り" );
  1086.             fprintf( stderr, "データ領域を %d Kbyte 確保します。\n", n );
  1087.             dsize = (long)n * 1024L ;
  1088.             break ;
  1089.         case 'n' :
  1090.             fprintf( stderr, "画像ファイルを出力しません。\n" );
  1091.             nflag = 1 ;
  1092.             break ;
  1093.         case 'o' :
  1094. #ifdef NO_PICLIB
  1095.             strcpy( picfile, str+2 );
  1096. #else
  1097.             PicSequence_set(&outseq, str+2);
  1098. #endif
  1099.             fprintf( stderr, "画像ファイル名を %s にします。\n", str+2 );
  1100.             break ;
  1101. #ifdef HIVISION
  1102.         case 'p' :
  1103.             {
  1104.                 int nx, ny = 0;
  1105.                 int cc;
  1106.                 nx = atoi( str+2 ) ;
  1107.                 for (cc = 2; str[cc]; ++cc) {
  1108.                     if (str[cc] == 'X' || str[cc] == 'x' || str[cc] == '*'
  1109.                      || str[cc] == ',' || str[cc] == ':') {
  1110.                         ny = atoi(str+cc+1);
  1111.                         break;
  1112.                     }
  1113.                 }
  1114.                 XPosition = nx;
  1115.                 YPosition = ny;
  1116.                 if (nx < 0 || nx >= 512 || ny < 0 || ny >= 512) {
  1117.                     error( 0, "オプション'P' の指定の誤り" );
  1118.                 }
  1119.             }
  1120.             break;
  1121. #endif
  1122. #ifdef    BACKFACE
  1123.         case 'q':
  1124.             backface = TRUE;
  1125.             fprintf(stderr, "裏面は作画しません。\n");
  1126.             break;
  1127. #endif
  1128. #ifdef    BG
  1129.         case 'r':
  1130.             strcpy( processbuf.name, "REND" );
  1131.             n = bg_get( -1, &processbuf );
  1132.             if ( n > 0 )
  1133.             {
  1134.                 if ( bg_send( 0, n, 0xFFF9, NULL, 0 ) < 0 )
  1135.                     fprintf( stderr, " エラーが発生しました。\n" );
  1136.             }
  1137.             else
  1138.                 fprintf( stderr, " REND が存在しません。\n" );
  1139.             exit( 0 );
  1140. #endif
  1141. #ifdef REFMAP
  1142.         case 'r' :
  1143.             RefMap = 1;
  1144.             strcpy(RefMapFile[0], str+2);
  1145.             while ((p = strchr(RefMapFile[RefMap-1], ',')) != NULL
  1146.                 || (p = strchr(RefMapFile[RefMap-1]+2, ':')) != NULL) {
  1147.                 *p = '\0';
  1148.                 if (RefMap == 6) {
  1149.                     error( 0, "オプション'R' 画像の枚数が多すぎる" );
  1150.                 }
  1151.                 strcpy(RefMapFile[RefMap++], p+1);
  1152.             }
  1153.             if (RefMap == 1) {
  1154.                 fprintf( stderr, "環境マッピングを、極座標系: %s で行います。\n",RefMapFile[0]);
  1155.             } else if (RefMap == 2) {
  1156.                 fprintf( stderr, "環境マッピングを、上半球: %s、下半球: %s で行います。\n",
  1157.                         RefMapFile[0], RefMapFile[1]);
  1158.             } else if (RefMap == 6) {
  1159.                 fprintf( stderr,
  1160.                     "環境マッピングを、前: %s、右: %s 後: %s 左: %s 上: %s 下: %s で行います。\n",
  1161.                     RefMapFile[0], RefMapFile[1],RefMapFile[2],
  1162.                     RefMapFile[3], RefMapFile[4],RefMapFile[5]);
  1163.             } else {
  1164.                 error( 0, "オプション'R' 画像の枚数がおかしい" );
  1165.             }
  1166.             break;
  1167. #endif
  1168.         case 's' :
  1169.             p = strchr( str+2, ':' );
  1170.             if ( p != NULL )
  1171.                 *p = '\0' ;
  1172.             /*    スタートフレームのチェック    */
  1173.             startframe = atoi( str+2 );
  1174.             if ( startframe <= 0 )
  1175.                 startframe = 1 ;
  1176.             else
  1177.             {
  1178.                 fprintf( stderr, " %d フレームから描き始めます。\n",
  1179.                     startframe );
  1180.             }
  1181.             /*    エンドフレームのチェック  */
  1182.             if ( p != NULL )
  1183.             {
  1184.                 /*    エンドフレームがある  */
  1185.                 endframe = atoi( p+1 );
  1186.                 if ( startframe > endframe )
  1187.                     error( 0, "オプション'S' 開始フレームよりも終了フレームの方が小さい" );
  1188.                 fprintf( stderr, " %d フレームで終わります。\n", endframe );
  1189.             }
  1190.             break ;
  1191.         case 't' :
  1192.             tflag = TRUE ;
  1193.             if ( str[2] == '\0' )
  1194.                 strcpy( tempfile, "REND.TMP" );
  1195.             else
  1196.                 strcpy( tempfile, str+2 );
  1197.             i = strlen( tempfile );
  1198.             if ( tempfile[i-1] == '\\' || tempfile[i-1] == ':' )
  1199.                 strcat( tempfile, "REND.TMP" );
  1200.             fprintf( stderr, "テンポラリファイル %s を使用します。\n",
  1201.                     tempfile );
  1202.             break ;
  1203.         case 'u' :
  1204.             uflag = TRUE ;
  1205.             fprintf( stderr, "画面出力しません。\n" );
  1206.             break ;
  1207.         case 'v' :
  1208.             virtualmode = TRUE ;
  1209.             if ( str[2] == '\0' )
  1210.                 strcpy( virfile, "REND.SWP" );
  1211.             else
  1212.                 strcpy( virfile, str+2 );
  1213.             i = strlen( virfile );
  1214.             if ( virfile[i-1] == '\\' || virfile[i-1] == ':' )
  1215.                 strcat( virfile, "REND.SWP" );
  1216.             fprintf( stderr,
  1217.                 "仮想記憶ファイル %s を使用します。\n", virfile );
  1218.             break ;
  1219. #ifdef WIREVIEW
  1220.         case 'w' :
  1221.             n = atoi( str+2 );
  1222.             if ( n <= 1 || 5 <= n ) {
  1223.                 n = 1;
  1224.             }
  1225.             fprintf( stderr,"出力画像をワイヤーフレームにします。\n", n );
  1226.             wiresize = n ;
  1227.             break ;
  1228. #endif
  1229. #ifdef    XC
  1230.         case 'w' :
  1231.             WindowMode = TRUE ;
  1232.             WindowArgv = atoi( str+2 );
  1233.             for( WindowArgc = 0 ; WindowArgv[WindowArgc] != NULL ; ++ WindowArgc );
  1234.             fprintf( stderr, "ウインドウモードで実行します。\n" );
  1235.             break ;
  1236. #endif
  1237.         case '?' :
  1238.             usage() ;
  1239.             break ;
  1240.         default :
  1241.             error( 0, "不明のオプションを指定" );
  1242.     }
  1243. }
  1244.  
  1245. #ifdef NO_PICLIB
  1246. /*    画像ファイル名のチェック  */
  1247. static    int        piccheck( name )
  1248. char    *name ;
  1249. {
  1250.     char    *p, *p2 ;
  1251.     int        i, n, ret ;
  1252. #if 0
  1253.     if ( *name == '.' )
  1254.         p = name + 2 ;    /*    親ディレクトリを示す  */
  1255.     else
  1256.         p = name ;
  1257. #else
  1258.     if (p2 = strrchr(name, ':'), p2++ == NULL) {
  1259.         p2 = name;
  1260.     }
  1261.     if (p = strrchr(p2, '\\'), p++ == NULL) {
  1262.         p = p2;
  1263.     }
  1264. #endif
  1265.     p = strchr( p, '.' ) ;
  1266.     if ( p != NULL )    /*    拡張子を削除する  */
  1267.         *p = '\0' ;
  1268.  
  1269.     ret = 0 ;
  1270.     n = strlen( name );
  1271.     if ( isdigit( name[n-3] ) && isdigit( name[n-2] ) && isdigit( name[n-1] ) )
  1272.     {
  1273.         ret = atoi( name + n - 3 );
  1274.         name[n-3] = '\0' ;
  1275.     }
  1276.  
  1277.     p = name + strlen( name ) - 1 ;
  1278.     for( i = 0 ; *p != '\\' && *p != ':' && p >= name ; ++i )
  1279.         --p ;
  1280.     if ( ret != 0 && i > 5 )
  1281.         error( 0, "画像ファイル名が長すぎます。" );
  1282.  
  1283.     return( ret );
  1284. }
  1285. #endif
  1286.  
  1287. /*    usage の表示    */
  1288. static    void    usage()
  1289. {
  1290.     int        i ;
  1291.  
  1292.     static    char    *msg[] = {
  1293.             "使用法:rend [ -Options ] [#<IndirectFile>] < File... ( .atr .suf .frm ) >",
  1294.             "Option  -a<num>           : <num>倍解像度でアンチエリアシング",
  1295. #ifdef MAPANTI
  1296.             "        -am               : マッピングにアンチエリアシングをかける",
  1297. #endif
  1298. #ifdef MOB
  1299.             "        -at<num>          : 時間方向にアンチエイリアシング(<num>=2,3,4)",
  1300. #endif
  1301.             "        -b                : 背景を透明にする",
  1302. #ifdef BGMAKE
  1303.             "        -b<file1>,<file2>,...",
  1304.             "                          : 背景球を描く",
  1305. #endif
  1306. #ifdef HIVISION
  1307.             "        -c<numx>[:<numy>] : 画面サイズを<numx>×<numy>にする",
  1308. #else
  1309.             "        -c<num>           : 画面サイズ",
  1310. #endif
  1311. /*            "        -d<num>           : <num>万色で作画する(<num>=6,400,1600)",*/
  1312.             "        -d[<mode>]        : ディザリングをかける(<mode>=2,4,r,e)",
  1313. #ifndef WINDOWS
  1314.             "        -e0<command>      : コマンド実行(作画前)",
  1315.             "        -e1<command>      : コマンド実行(作画後)",
  1316. #endif
  1317.             "        -f<num>           : 前面クリッピング距離",
  1318.             "        -g                : スムースシェーディングモード",
  1319.             "        -h<filename>      : 背景をファイルから読み込む",
  1320. #ifdef STAR
  1321. /*            "        -i<num>           : 背景<num>個の星を描く",*/
  1322.             "        -i<num>[:<d>:<s>] : 背景<num>個の星を<d>度の方向で速さ<s>度で描く",
  1323. #endif
  1324. #ifdef    BG
  1325.             "        -j[mode]          : バックグラウンドジョブで実行する",
  1326.             "                          :       ( Human68k ver 2.00 以上 )",
  1327. #endif
  1328. #ifdef EDGEANTI
  1329.             "        -k                : エッジにアンチエイリアシングをかけない",
  1330. #endif
  1331. #if 0
  1332.             "        -l<filename>      : ログを記録する",
  1333. #endif
  1334.             "        -m<num>           : データ領域のサイズを指定する(Kbyte)",
  1335.             "        -n                : 画像ファイルを出力しない",
  1336.             "        -o<name>          : 画像ファイル名",
  1337. #ifdef HIVISION
  1338.             "        -p<numx>:<numy>   : 画像左上の座標を(<numx>,<numy>)にする",
  1339. #endif
  1340. #ifdef BACKFACE
  1341.             "        -q                : 裏面を描きません",
  1342. #endif
  1343. #ifdef    BG
  1344.             "        -r                : バックグラウンドジョブを中断させる。",
  1345. #endif
  1346. #ifdef REFMAP
  1347.             "        -r<file1>,...     : 環境マッピングを行う。",
  1348.             "                            ファイル数1: 極座標系",
  1349.             "                            ファイル数2: 上半球、下半球",
  1350.             "                            ファイル数6: 前、右、後、左、上、下",
  1351. #endif
  1352.             "        -s<num1>[:<num2>] : num1 スタートフレーム",
  1353. #ifdef JAP
  1354.             "                            num2 エンドフレーム(省略可能\)",
  1355. #else
  1356.             "                            num2 エンドフレーム(省略可能)",
  1357. #endif
  1358. #ifndef DJ
  1359.             "        -t[filename]      : テンポラリファイル使用",
  1360. #endif
  1361.             "        -u                : 画面出力しない",
  1362. #ifdef    VIRTUAL
  1363.             "        -v[filename]      : 仮想記憶モード",
  1364. #ifdef    EMS
  1365.             "        -vEMS             : EMSによる仮想記憶モード",
  1366. #endif
  1367. #endif
  1368. #ifdef WIREVIEW
  1369.             "        -w                : ワイヤーフレーム出力",
  1370. #endif
  1371. #ifdef JAP
  1372.             "        -?                : 使用法表\示",
  1373. #else
  1374.             "        -?                : 使用法表示",
  1375. #endif
  1376.             "#<インダイレクトファイル> は、そのファイルの中身を(改行は空白として)そこに書くのと同等です。",
  1377.             "ESC キーで中止",
  1378.             ""
  1379.     } ;
  1380.  
  1381.     for( i = 0 ; strcmp( msg[i], "" ) != 0 ; ++i )
  1382.         fprintf( stdout, "%s\n", msg[i] );
  1383. /*    putc( '\n', stderr );*/
  1384.     exit( 1 );
  1385. }
  1386.  
  1387. /*    エラー    */
  1388. static    void    error( n, msg )
  1389. int        n ;
  1390. char    *msg ;
  1391. {
  1392. #ifdef MESSAGE
  1393.     extern int printwarning(const char *format, ...);
  1394. #endif
  1395.     if ( n == 0 ) {
  1396.         fprintf( stderr, "コマンドラインエラー:%s\n", msg );
  1397. #ifdef MESSAGE
  1398.         printwarning("コマンドラインエラー:%s", msg);
  1399. #endif
  1400.     }
  1401. #ifdef MESSAGE
  1402.     else printwarning("エラーが発生しました。");
  1403. #endif
  1404.     fprintf( stderr, "エラーが発生しました。\n\n" );
  1405.  
  1406. #ifndef DJ
  1407. #ifndef UNIX
  1408.     fcloseall();
  1409. #endif
  1410. #endif
  1411.     exit( 1 );
  1412. }
  1413.  
  1414. /*
  1415.     拡張子の種類を返す。
  1416.         戻り値    -1 : エラー
  1417.                  0 : .atr
  1418.                  1 : .suf
  1419.                  2 : .frm
  1420.                  3 : .fsc
  1421. */
  1422. static    int        isext( file )
  1423. char    *file ;
  1424. {
  1425.     int        i ;
  1426.     char    *p ;
  1427.  
  1428.     p = strrchr( file, '.' );
  1429.     if ( p == NULL )
  1430.         return( -1 );
  1431.  
  1432.     for( i = 0 ; i < 4 ; ++i )
  1433.     {
  1434.         if ( strcmpi( p, ext[i] ) == 0 )
  1435.             return( i );
  1436.     }
  1437.     return( -1 );
  1438. }
  1439.