aboutsummaryrefslogtreecommitdiffstats
path: root/structs/struct2desc
blob: 7ca7386b57e96fa6f344b2abc1208c1db04190f7 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl
use strict;

my %mapit = (
	"int"	 => "SINT32",
	"__s32"	 => "SINT32",
	"__u32"	 => "UINT32",
	"__s16"	 => "SINT16",
	"__u16"	 => "UINT16",
	"__s8"	 => "SINT8",
	"__u8"	 => "UINT8",
);

my $struct = 0;
my $enum = 0;

while (my $line = <>) {

	# start of struct
	if ($line =~ m/^struct\s+(\w+)/) {
		die "--\n$line\nstruct is 1" if $struct == 1;
		$struct = 1;
		print "\n";
		print "struct struct_desc desc_$1\[\] = {{\n";
		next;
	}
	next if ($struct == 1 && $line =~ /^\{/);

	# end of struct
	if ($struct == 1 && $line =~ m/^\};/) {
		$struct = 0;
		print "  .type   = END_OF_LIST,\n";
		print "}};\n";
		next;
	}

	# struct elements
	if ($struct == 1 && $line =~ m/^\s+(int|__u32|__s32|__u16|__s16|__u8|__s8)\s+(\w+);/) {
		print "  .type   = $mapit{$1},\n";
		print "  .name   = \"$2\",\n";
		print "},{\n";
		next;
	}
	if ($struct == 1 && $line =~ m/^\s+(char|__u8)\s+(\w+)\[(\d+)\];/) {
		print "  .type   = STRING,\n";
		print "  .name   = \"$2\",\n";
		print "  .length = $3,\n";
		print "},{\n";
		next;
	}
	if ($struct == 1 && $line =~ m/^\s+enum\s+(\w+)\s+(\w+);/) {
		print "  .type   = ENUM,\n";
		print "  .name   = \"$2\",\n";
		print "  .enums  = desc_$1,\n";
		print "},{\n";
		next;
	}


	# start of enum
	if ($line =~ m/^enum\s+(\w+)/) {
		die "--\n$line\nenum is 1" if $enum == 1;
		$enum = 1;
		print "\n";
		print "char desc_$1\[\] = {\n";
		next;
	}

	# end of enum
	if ($enum == 1 && $line =~ m/^\};/) {
		$enum = 0;
		print "};\n";
		next;
	}

	# enum elements
	if ($enum == 1 && $line =~ m/^\s+(\w+)/) {
		print "  [$1] = \"$1\",\n";
		next;
	}

	next if $line =~ m/#define/;
	next if $struct == 0;

	chomp $line;
	print "/* FIXME $line */\n";
}

Privacy Policy