/******************************************************************************
Copyright (c) 2002 by Ben Stern.
This file is a simple Linux kernel logo reading program.

ll2xpm 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 2 of the License, or (at your option) any later
version.

ll2xpm 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
ll2xpm; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
******************************************************************************/

/* Version: 1.1.0 */

#include <stdio.h>

#ifndef LINUXLOGO
#error "You must build this with -DLINUXLOGO=\"name/of/logo-header.h\""
#else
#define INCLUDE_LINUX_LOGO_DATA
#include LINUXLOGO
#endif

char color2char[LINUX_LOGO_COLORS][2];

int main(int argc, char *argv[]) {
    FILE *f;
    int i;

    if (argc != 2) {
        puts("Usage: a.out <xpm filename>");
        return 1;
    }
    f = fopen(argv[1], "w");
    if (f == NULL) {
        perror("fopen");
        return 2;
    }
    fputs("/* XPM */\n", f);
    fprintf(f, "static char * %s_linux_logo[] = {\n", argv[1]);
    fputs("/* width height ncolors cpp */\n", f);
    fprintf(f, "\"80 80 %d 2\",\n", LINUX_LOGO_COLORS);
    fputs("/* colors */\n", f);
    for (i = 0; i < LINUX_LOGO_COLORS; i++) {
        color2char[i][0] = i/92 + '#'; /* there are 92 printable characters, */
        color2char[i][1] = i%92 + '#'; /* after skipping ", which start at # */
        fprintf(f, "\"%c%c c #%2.2X%2.2X%2.2X\",\n", color2char[i][0],
            color2char[i][1], linux_logo_red[i], linux_logo_green[i],
            0xff - linux_logo_blue[i]);
    }
    fputs("/* pixels */\n", f);
    for (i = 0; i < 80*80; i++) {
        if (i && !(i%80)) fputs("\",\n", f);
        if (!(i%80)) fputc('"', f);
        fputc(color2char[linux_logo[i]-0x20][0], f);
        fputc(color2char[linux_logo[i]-0x20][1], f);
    }
    fputs("\"\n};\n", f);
    fclose(f);
}

