home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / vifs / rdescr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-13  |  3.0 KB  |  133 lines

  1. /*
  2.  *    rdescr.c  --  read an ifs description file.
  3.  *
  4.  *    4 june 1989  Olle Olsson
  5.  */
  6.  
  7. #include <stdlib.h>
  8. #include <ctype.h>
  9. #include "ifs.h"
  10.  
  11. static char *getline( FILE *infile, char *inbuffer, int buffersize,
  12.                          int eof_fail );
  13.  
  14. void rdescr( inf, dp, show )
  15. FILE *inf;            /* input file */
  16. ifsdes *dp;            /* descriptor to be filled */
  17. int show;            /* trace flag */
  18. {
  19. transform *tp;
  20. int i;
  21. char buf[200];
  22.  
  23. /* 1st line: read size, density and im mode */
  24. dp -> size = dp -> density = dp -> im = 0;
  25. (void) getline( inf, buf, sizeof( buf ), 1 );
  26. sscanf( buf, "%d %lf %d", &dp -> size, &dp -> density, &dp -> im );
  27.  
  28. /* copy the im value to the previous value */
  29. dp -> im_prev = dp -> im;
  30.  
  31. /* */
  32. if (show) printf( "Size %d, density %g, imm %d\n",
  33.          dp -> size, dp -> density, dp -> im );
  34. /* */
  35.  
  36. if (dp -> size <= 0)  error( "Size zero  --  no transformations" );
  37. if (dp -> density <= 0) error( "Density zero  --  no calculations" );
  38.  
  39. if (dp -> size > dp -> maxsize)
  40.     {
  41.     warning( "Max number of transformations (%d) exeeded: %d",
  42.              dp -> size, dp -> maxsize );
  43.     }
  44.  
  45. /* 2nd line: read the plot area */
  46. (void) getline( inf, buf, sizeof( buf ), 1 );
  47. sscanf( buf, "%lf %lf %lf %lf",
  48.     &dp -> area.xlow, &dp -> area.xlen,
  49.     &dp -> area.ylow, &dp -> area.ylen );
  50.  
  51. /* 3rd..3+size lines: read the transformations */
  52. for (tp = dp -> tp, i = 0; i < dp -> size; ++tp, ++i)
  53.     {
  54.     (void) getline( inf, buf, sizeof( buf ), 1 );
  55.  
  56.     /* skip the execessive transforms */
  57.     if (i >= dp -> maxsize )
  58.         continue;
  59.  
  60.     sscanf( buf, "%lf %lf %lf %lf %lf %lf %lf %d %d",
  61.         &tp -> a11, &tp -> a12, &tp -> a21, &tp -> a22,
  62.         &tp -> b1, &tp -> b2, &tp -> prob,
  63.         &tp -> color, &tp -> group );
  64.     }
  65. /* */
  66. if (show) printf( "area %lf %lf %lf %lf\n",
  67.     dp -> area.xlow, dp -> area.xlen, dp -> area.ylow, dp -> area.ylen );
  68.  
  69. if (show) for (tp = dp -> tp, i = dp -> size; i; ++tp, --i)
  70.     printf( "%lf %lf %lf %lf %lf %lf %lf\n",
  71.         tp -> a11, tp -> a12, tp -> a21, tp -> a22,
  72.         tp -> b1, tp -> b2, tp -> prob );
  73.  
  74. /* */
  75.  
  76. /* read the palette */
  77. for (i = 0; i < dp -> clrsize; ++i)
  78.     {
  79.     if (!getline( inf, buf, sizeof( buf ), 0 ))
  80.         break;
  81.  
  82.     sscanf( buf, "%d %d %d", &dp -> colors[i].r, &dp -> colors[i].g,
  83.                              &dp -> colors[i].b );
  84.     }
  85.  
  86. if (show)
  87.     {
  88.     printf( "index  r g b\n" );
  89.     for (i = 0; i < dp -> clrsize; ++i)
  90.         {
  91.         printf( " %d: %d %d %d;", i,
  92.             dp -> colors[i].r, dp -> colors[i].g, dp -> colors[i].b );
  93.         if (!((i + 1) % 4)) printf( "\n" );
  94.         }
  95.     printf( "\n" );
  96.     }
  97. }
  98.  
  99. static char *getline( f, bp, blen, failf )
  100. FILE *f;        /* input file */
  101. char *bp;        /* input buffer */
  102. int blen;               /* buffer size */
  103. int failf;        /* fail-at-eof flag */
  104. {
  105. register char *s;
  106.  
  107. /* read a line from f, skip comments and blank lines */
  108. for (*bp = '\0';;)
  109.     {
  110.     if (fgets( bp, blen, f ) == NULL)
  111.         {
  112.         if (failf)
  113.             error( "premature end of input file" );
  114.  
  115.         return (0);
  116.         }
  117.  
  118.     /* comment ? */
  119.     if (bp[0] == COMMENTCH)
  120.         continue;
  121.  
  122.     /* blank ? */
  123.     for (s = bp; *s; ++s)
  124.         if (!isspace( *s )) break;
  125.  
  126.     if (*s) break;
  127.     }
  128.  
  129. /* ok */
  130. return (bp);
  131. }
  132.  
  133.