#include #include extern const char *__progname; static struct { char ch; const char bits[12]; } codes[] = { { ' ', "100110101101" }, { '$', "100100100101" }, { '%', "101001001001" }, { '*', "100101101101" }, { '+', "100101001001" }, { '-', "100101011011" }, { '.', "110010101101" }, { '/', "100100101001" }, { '0', "101001101101" }, { '1', "110100101011" }, { '2', "101100101011" }, { '3', "110110010101" }, { '4', "101001101011" }, { '5', "110100110101" }, { '6', "101100110101" }, { '7', "101001011011" }, { '8', "110100101101" }, { '9', "101100101101" }, { 'A', "110101001011" }, { 'B', "101101001011" }, { 'C', "110110100101" }, { 'D', "101011001011" }, { 'E', "110101100101" }, { 'F', "101101100101" }, { 'G', "101010011011" }, { 'H', "110101001101" }, { 'I', "101101001101" }, { 'J', "101011001101" }, { 'K', "110101010011" }, { 'L', "101101010011" }, { 'M', "110110101001" }, { 'N', "101011010011" }, { 'O', "110101101001" }, { 'P', "101101101001" }, { 'Q', "101010110011" }, { 'R', "110101011001" }, { 'S', "101101011001" }, { 'T', "101011011001" }, { 'U', "110010101011" }, { 'V', "100110101011" }, { 'W', "110011010101" }, { 'X', "100101101011" }, { 'Y', "110010110101" }, { 'Z', "100101011011" }, { 0 } }; static char bits[128]; static int bx; static void genbits(const char *s, int n) { for (;n>0;s++,n--) { switch (*s) { case '0': bits[bx++] = 0; break; case '1': bits[bx++] = 1; break; default: abort(); break; } } } static void genchar(char c) { int i; for (i=0;codes[i].ch;i++) { if (codes[i].ch == c) { genbits(codes[i].bits,12); return; } } fprintf(stderr,"%s: bad char `%c' in code\n",__progname,c); exit(1); } static void dumppbm(void) { int y; int x; int col; static void bit(char c) { if (col > 68) { putchar('\n'); col = 0; } putchar(c); col ++; } printf("P1\n107 68\n"); col = 0; for (y=0;y<15;y++) for (x=0;x<107;x++) bit('0'); for (y=0;y<38;y++) { for (x=0;x<15;x++) bit('0'); for (x=0;x<77;x++) bit('0'+bits[x]); for (x=0;x<15;x++) bit('0'); } for (y=0;y<15;y++) for (x=0;x<107;x++) bit('0'); putchar('\n'); } int main(int, char **); int main(int ac, char **av) { if ((ac != 2) || (strlen(av[1]) != 4)) { fprintf(stderr,"Usage: %s 4-char-code\n",__progname); exit(1); } bx = 0; genbits("100101101101",12); genbits("0",1); genchar(av[1][0]); genbits("0",1); genchar(av[1][1]); genbits("0",1); genchar(av[1][2]); genbits("0",1); genchar(av[1][3]); genbits("0",1); genbits("100101101101",12); if (bx != 77) abort(); dumppbm(); exit(0); }