home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
-
- int ScanWord();
- int bitvalue[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
-
- /*****************************************************************************/
- main ( argc, argv )
- int argc;
- char *argv[];
- {
- FILE *fin, *fout;
- int width, height;
- char outname[80], inname[80];
- int i;
-
- if( argc < 2 ) {
- printf( "Usage: %s file ...\n", argv[0] );
- exit( 1 );
- }
- for (i=1; i<argc; i++) {
- printf( "Format converter:" );
- strcpy( outname, argv[i] );
- if (strlen(outname)>4 && strcmp(&outname[strlen(outname)-4],".xbm")==0){
- outname[strlen(outname)-4] = 0;
- }
- strcpy( inname, outname );
- strcat( inname, ".xbm" );
- strcat( outname, ".bm" );
- printf( " \"%s\" to \"%s\".\n", inname, outname );
-
- fin = fopen( inname, "r" );
- if( fin == NULL ) {
- printf( "%s: Can't open input file: %s\n", argv[0], inname );
- exit( 1 );
- }
- ScanWord( fin, "_width" );
- fscanf( fin, "%d", &width );
- ScanWord( fin, "_height" );
- fscanf( fin, "%d", &height );
- printf( "Width=%d, Height=%d\n", width, height );
- ScanWord( fin, "static char" );
- ScanWord( fin, "[]" );
- fout = fopen( outname, "w" );
- ConvertFile( fin, fout, width, height );
- fclose( fout );
- fclose( fin );
- }
- printf( "Awll done.\n");
- }
-
- /*****************************************************************************/
- ConvertFile( fin, fout, width, height )
- FILE *fin, *fout;
- int width, height;
- {
- char hexhi, hexlo;
- char binhi, binlo;
- char rv, v;
- int i;
-
- putc( 'B', fout );
- putc( 'M', fout );
- putc( 0xCB, fout );
- putc( 0x02, fout );
- v = width / 256; putc( v, fout );
- v = width % 256; putc( v, fout );
- v = height / 256; putc( v, fout );
- v = height % 256; putc( v, fout );
- while( ScanWord( fin, "0x" ) != EOF ) {
- /* extract non-inverted binary value */
- hexhi = getc( fin );
- hexlo = getc( fin );
- binhi = hexhi<='9' ? hexhi-'0' : (hexhi - 7) & 0x0F;
- binlo = hexlo<='9' ? hexlo-'0' : (hexlo - 7) & 0x0F;
- v = /*0xFF-*/ (binhi * 16 + binlo);
- /* reverse bit positions */
- rv = 0;
- for( i=0; i<8; i++ ) {
- if( v & bitvalue[i] ) {
- rv |= bitvalue[7 - i];
- }
- }
- putc( rv, fout );
- }
- }
-
- /*****************************************************************************/
- int ScanWord( fin, word )
- FILE *fin;
- char word[];
- {
- int i, c;
-
- i = 1;
- while( word[i] != '\0' ) {
- c = getc( fin );
- if( c == EOF ) return( EOF );
- if( c == word[i] ) {
- i++;
- } else {
- i = 1;
- }
- }
- return( 'a' );
- }
-