2008-07-13 21:07:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
* *
|
|
|
|
* 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 2 of the License, 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., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-07-13 20:20:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-10-30 11:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-13 21:07:14 +00:00
|
|
|
int main(int argc, char **argv)
|
2008-07-13 20:20:58 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
unsigned int n;
|
2010-12-29 21:07:21 +00:00
|
|
|
const char *name;
|
2008-07-13 20:20:58 +00:00
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
fprintf(stderr, "bin2char <varname>\n");
|
|
|
|
fprintf(stderr, "read from standard input and write a char"
|
2008-12-13 12:44:39 +00:00
|
|
|
" array out to standard output\n");
|
2008-07-13 20:20:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-10-30 11:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* for win32 set stdin/stdout to binary mode */
|
|
|
|
_setmode(_fileno(stdin), _O_BINARY);
|
|
|
|
_setmode(_fileno(stdout), _O_BINARY);
|
|
|
|
#endif
|
|
|
|
|
2008-07-13 20:20:58 +00:00
|
|
|
n = 0;
|
|
|
|
name = argv[1];
|
|
|
|
fprintf(stdout, "/* autogenerated from %s */\n", argv[0]);
|
|
|
|
fprintf(stdout, "unsigned const char %s[] = {\n", name);
|
|
|
|
while ((c = getc(stdin)) != EOF) {
|
|
|
|
fprintf(stdout, "0x%02x,", c & 0xff);
|
|
|
|
if ((++n % 16) == 0)
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
}
|
2008-07-13 21:07:14 +00:00
|
|
|
fprintf(stdout, "0 /* terminate with a null */};\n");
|
2008-07-13 20:20:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|