summaryrefslogtreecommitdiff
path: root/kconf2h/kconf2h.c
blob: 91ef6c736f394f32d0884e8fb46df1a6e8995851 (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>

#include <sys/stat.h>

#include "kconf2h.h"

int main( int argc, char **argv )
{
	FILE *fin = NULL;
	FILE *fout = NULL;
	struct stat st;

	char *buf=NULL;
	if ( argc == 3 )
	{
		fin = fopen( argv[1], "r+" );
		fout = fopen( argv[2], "w+" );
		fseek( fin, 0, SEEK_SET );
		if ( fin && fout )
		{
			if ( stat( argv[1], &st ) )
			{
				goto error_exit;
			}
			buf = malloc( st.st_size ); memset( buf, 0, st.st_size );
			size_t r_size = fread( buf, 1, st.st_size, fin );
			if ( r_size > 0 )
			{
				int ret = parse_kconf2h( buf, fout );
				printf("Kconfig file parsed %d %d bytes\n", ret, r_size );
			} else
			{
				printf("ERR: while reading file %s [%d]\n", argv[1], r_size);
			}
error_exit:
			if ( buf ) free( buf );
			fclose( fin );
			fclose( fout );
		} else
		{
			printf("ERR: Cannot open file\n");
		}
	} else
	{
		printf("ERR: usage ./kconf2h [conffile] [outputheader]\n");
		return -1;
	}
	return 0;
}