File: enum2debug.pl

package info (click to toggle)
vpnc 0.5.1r334-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 680 kB
  • ctags: 1,010
  • sloc: ansic: 7,082; sh: 6,166; perl: 167; makefile: 148
file content (63 lines) | stat: -rwxr-xr-x 1,258 bytes parent folder | download
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
#!/usr/bin/perl -w

# Usage: ./enum2debug.pl isakmp.h  >vpnc-debug.c 2>vpnc-debug.h

use strict;

my $in_enum = 0;
my $element;
my $arrayname;

print STDERR << 'EOF';
/* Automatically generated with enum2debug.pl: Don't edit! */

struct debug_strings {
	unsigned int id;
	const char *string;
};

extern const char *val_to_string(unsigned int, const struct debug_strings *);

EOF

print << 'EOF';
/* Automatically generated with enum2debug.pl: Don't edit! */

#include <stdio.h>

#include "vpnc-debug.h"
#include "isakmp.h"

const char *val_to_string(unsigned int val, const struct debug_strings *dstrings)
{
	static const char *unknown = " (unknown)";
	static const char *na = "";
	unsigned int i;
	
	if (dstrings == NULL)
		return na;
	
	for (i = 0; dstrings[i].id != 0 || dstrings[i].string != NULL; i++)
		if (dstrings[i].id == val)
			return dstrings[i].string;
	return unknown;
}

EOF

while (<>) {
	if (/^enum\W+(\w+)\W*/) {
		print STDERR "extern const struct debug_strings $1_array[];\n";
		print "const struct debug_strings $1_array[] = {\n";
		$in_enum = 1;
	} elsif ($in_enum && /^}/) {
		print "\t{ 0,\t(const char *) 0 }\n};\n\n";
		$in_enum = 0;
	} elsif ($in_enum && /^\W*(\w+)\W*/) {
		print "\t{ $1,\t\" ($1)\" },\n";
	}
}

exit 0;

__END__