1*b00ab754SHans Petter Selasky #include <stdio.h>
2*b00ab754SHans Petter Selasky #include <stdlib.h>
3*b00ab754SHans Petter Selasky #include <stdarg.h>
4*b00ab754SHans Petter Selasky #include <time.h>
5*b00ab754SHans Petter Selasky
Abort(const char * fmt,...)6*b00ab754SHans Petter Selasky static void Abort (const char *fmt,...)
7*b00ab754SHans Petter Selasky {
8*b00ab754SHans Petter Selasky va_list args;
9*b00ab754SHans Petter Selasky va_start (args, fmt);
10*b00ab754SHans Petter Selasky vfprintf (stderr, fmt, args);
11*b00ab754SHans Petter Selasky va_end (args);
12*b00ab754SHans Petter Selasky exit (1);
13*b00ab754SHans Petter Selasky }
14*b00ab754SHans Petter Selasky
main(int argc,char ** argv)15*b00ab754SHans Petter Selasky int main (int argc, char **argv)
16*b00ab754SHans Petter Selasky {
17*b00ab754SHans Petter Selasky FILE *inFile;
18*b00ab754SHans Petter Selasky FILE *outFile = stdout;
19*b00ab754SHans Petter Selasky time_t now = time (NULL);
20*b00ab754SHans Petter Selasky int ch, i;
21*b00ab754SHans Petter Selasky
22*b00ab754SHans Petter Selasky if (argc != 2)
23*b00ab754SHans Petter Selasky Abort ("Usage: %s bin-file [> result]", argv[0]);
24*b00ab754SHans Petter Selasky
25*b00ab754SHans Petter Selasky if ((inFile = fopen(argv[1],"rb")) == NULL)
26*b00ab754SHans Petter Selasky Abort ("Cannot open %s\n", argv[1]);
27*b00ab754SHans Petter Selasky
28*b00ab754SHans Petter Selasky fprintf (outFile,
29*b00ab754SHans Petter Selasky "/* data statements for file %s at %.24s */\n"
30*b00ab754SHans Petter Selasky "/* Generated by BIN2C, G. Vanem 1995 */\n",
31*b00ab754SHans Petter Selasky argv[1], ctime(&now));
32*b00ab754SHans Petter Selasky
33*b00ab754SHans Petter Selasky i = 0;
34*b00ab754SHans Petter Selasky while ((ch = fgetc(inFile)) != EOF)
35*b00ab754SHans Petter Selasky {
36*b00ab754SHans Petter Selasky if (i++ % 12 == 0)
37*b00ab754SHans Petter Selasky fputs ("\n ", outFile);
38*b00ab754SHans Petter Selasky fprintf (outFile, "0x%02X,", ch);
39*b00ab754SHans Petter Selasky }
40*b00ab754SHans Petter Selasky fputc ('\n', outFile);
41*b00ab754SHans Petter Selasky fclose (inFile);
42*b00ab754SHans Petter Selasky return (0);
43*b00ab754SHans Petter Selasky }
44