/*
    Pirate Bulletin Board System
    Copyright (C) 1990, Edward Luke

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 1, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


    Email address:
    lush@Athena.EE.MsState.EDU
*/
/* This program converts suntool icon bitmaps to rasters */


#include <stdio.h>
#include <fcntl.h>

int
read_hex()
{
	int ch ;
	int retval ;
	int i ;

	retval = 0 ;
	while((ch = getchar())!= EOF)
		if(ch == '0' && getchar() == 'x')
		  break ;
	for(i=3;i>=0;i--) {
		ch = getchar() ;
		retval<<=4 ;
		if(ch >= '0' && ch <= '9')
		  ch = ch - '0' ;
		else
		  ch = ch - 'A' + 10 ;
		retval |= ch ;
	}
	return retval ;
}

unsigned char image[64][64] ;

read_image()
{
	int i,j ;

	for(i=0; i < 64; i++) {
		for(j=0; j< 4; j++) {
			int x,bit ;
			int val ;
			
			val = read_hex() ;
			for(x=0x8000,bit=0;x!=0;x>>=1,bit++)
			  image[i][j*16+bit] = ((x & val) != 0) ;
		}
	}
}

/*char cver[] = " _-o~:~#" ;*/

char cver[] = " .-o\":^#" ;

write_image()
{
	int i,j ;
    printf("#define icon_width 64\n") ;
    printf("#define icon_height 64\n") ;
    printf("static char icon_bits[] = {\n") ;
    for(i=0;i<64;i++) {
        printf("    ") ;
        for(j=0;j<64;j+=8) {
            int val = 0 ;
            int x ;

            for(x=0;x<8;x++) {
                val<<=1 ;
                val |= (image[i][j+(7-x)]?1:0) ;
            }
            printf("0x%x%c",val,((i==63) && (j==56))?' ':',') ;
        }
        printf("\n") ;
    }
    printf("};\n") ;
}

main(ac,av)
char **av ;
{
	if(ac == 2) {
		close(0) ;
		if(open(av[1],O_RDONLY,0) == -1) {
			fprintf(stderr,"can't open '%s'\n",av[1]) ;
			exit(-1) ;
		}
	}
	read_image() ;
	write_image() ;
}

