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