home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 412.lha / crabs / intergerize.c < prev    next >
C/C++ Source or Header  |  1990-08-29  |  963b  |  43 lines

  1. /*
  2. ** This program filters a small file such that the output
  3. ** is the set of short ints required to describe the input
  4. **  NOTE the file must be a rectangle to work and no tabs
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. char            file[100][100];
  10. int             linelen, numlines;
  11.  
  12. main()
  13. {
  14.   int             i;
  15.  
  16.   linelen = 0;
  17.   numlines = 0;
  18.   while (gets(&file[numlines][0]) != NULL && numlines < 99) {
  19.     if ((i = strlen(&file[numlines][0])) > linelen)
  20.       linelen = i;
  21.     numlines++;
  22.   }
  23.   for(i=0; i<numlines; i++) {
  24.     printf("%s0x%c%c%c%c",
  25.        !i ? "{ " : i%8 != 7 ? ", " : ",\n  ",
  26.        conv(i,0), conv(i,4), conv(i,8), conv(i,12) );
  27.   }
  28.   printf("  };\n");
  29.   return 0;
  30. }
  31.  
  32. conv(line, pos)
  33. {
  34.   int             i;
  35.   static char     hex[] = "0123456789abcdef";
  36.  
  37.   i = (file[line][pos] == '*') ? 8 : 0;
  38.   i += (file[line][pos + 1] == '*') ? 4 : 0;
  39.   i += (file[line][pos + 2] == '*') ? 2 : 0;
  40.   i += (file[line][pos + 3] == '*') ? 1 : 0;
  41.   return (hex[i]);
  42. }
  43.