File: bin2data.c

package info (click to toggle)
vmelilo 1.1.1-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 360 kB
  • ctags: 761
  • sloc: ansic: 7,361; makefile: 98
file content (65 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 *	VME Linux/m68k Loader
 *
 *	(c) Copyright 1997 by Nick Holgate
 *
 *	This file is subject to the terms and conditions of the GNU General Public
 *	License.  See the file COPYING for more details.
 */

/*--------------------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>

/*--------------------------------------------------------------------------*/

int
main
(	int		argc,
	char		*argv[]
)
{	FILE		*fp1;
	int		c;
	int		count;

	if (argc != 3)
	{
		printf("Usage : %s <source_file> <label>\n", argv[0]);
		exit(0);
	}

	if ((fp1 = fopen(argv[1], "rb")) == NULL)
	{
		printf("Error opening '%s' for reading!\n", argv[1]);
		exit(1);
	}

	printf("unsigned char %s[] = {", argv[2]);

	count = 0;
	while ((c = getc(fp1)) != EOF)
	{
		if (count)
		{
			putc(',', stdout);
		}
			
		if ((count % 10) == 0)
		{
			printf("\n\t");
		}

		printf("0x%02X", c);

		count++;
	}

	printf("\n};\n");

	fclose(fp1);

	return 0;
}

/*-----------------------------< end of file >------------------------------*/