File: enum2debug.pl

package info (click to toggle)
vpnc 0.5.3r550-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 752 kB
  • ctags: 1,229
  • sloc: ansic: 8,189; sh: 662; perl: 169; makefile: 163
file content (64 lines) | stat: -rwxr-xr-x 1,285 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env perl

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

use strict;
use warnings;

my $in_enum = 0;

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 (/^\s*\/\*.*\*\/\s*$/) {
		next;
	} elsif ($in_enum && /^\W*(\w+)\W*/) {
		print "\t{ $1,\t\" ($1)\" },\n";
	}
}

exit 0;

__END__