|
Packit |
209cc3 |
#include <stdio.h>
|
|
Packit |
209cc3 |
#include <stdlib.h>
|
|
Packit |
209cc3 |
#include <stdarg.h>
|
|
Packit |
209cc3 |
#include <time.h>
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
static void Abort (const char *fmt,...)
|
|
Packit |
209cc3 |
{
|
|
Packit |
209cc3 |
va_list args;
|
|
Packit |
209cc3 |
va_start (args, fmt);
|
|
Packit |
209cc3 |
vfprintf (stderr, fmt, args);
|
|
Packit |
209cc3 |
va_end (args);
|
|
Packit |
209cc3 |
exit (1);
|
|
Packit |
209cc3 |
}
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
int main (int argc, char **argv)
|
|
Packit |
209cc3 |
{
|
|
Packit |
209cc3 |
FILE *inFile;
|
|
Packit |
209cc3 |
FILE *outFile = stdout;
|
|
Packit |
209cc3 |
time_t now = time (NULL);
|
|
Packit |
209cc3 |
int ch, i;
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
if (argc != 2)
|
|
Packit |
209cc3 |
Abort ("Usage: %s bin-file [> result]", argv[0]);
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
if ((inFile = fopen(argv[1],"rb")) == NULL)
|
|
Packit |
209cc3 |
Abort ("Cannot open %s\n", argv[1]);
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
fprintf (outFile,
|
|
Packit |
209cc3 |
"/* data statements for file %s at %.24s */\n"
|
|
Packit |
209cc3 |
"/* Generated by BIN2C, G. Vanem 1995 */\n",
|
|
Packit |
209cc3 |
argv[1], ctime(&now));
|
|
Packit |
209cc3 |
|
|
Packit |
209cc3 |
i = 0;
|
|
Packit |
209cc3 |
while ((ch = fgetc(inFile)) != EOF)
|
|
Packit |
209cc3 |
{
|
|
Packit |
209cc3 |
if (i++ % 12 == 0)
|
|
Packit |
209cc3 |
fputs ("\n ", outFile);
|
|
Packit |
209cc3 |
fprintf (outFile, "0x%02X,", ch);
|
|
Packit |
209cc3 |
}
|
|
Packit |
209cc3 |
fputc ('\n', outFile);
|
|
Packit |
209cc3 |
fclose (inFile);
|
|
Packit |
209cc3 |
return (0);
|
|
Packit |
209cc3 |
}
|