Support for /sbin/netconfig under OpenSuse 11.1
[vpnc.git] / enum2debug.pl
blobcb8f02903dde6b441653b6d086762c2d65e35428
1 #!/usr/bin/env perl
3 # Usage: ./enum2debug.pl isakmp.h >vpnc-debug.c 2>vpnc-debug.h
5 use strict;
6 use warnings;
8 my $in_enum = 0;
9 my $element;
10 my $arrayname;
12 print STDERR << 'EOF';
13 /* Automatically generated with enum2debug.pl: Don't edit! */
15 struct debug_strings {
16 unsigned int id;
17 const char *string;
20 extern const char *val_to_string(unsigned int, const struct debug_strings *);
22 EOF
24 print << 'EOF';
25 /* Automatically generated with enum2debug.pl: Don't edit! */
27 #include <stdio.h>
29 #include "vpnc-debug.h"
30 #include "isakmp.h"
32 const char *val_to_string(unsigned int val, const struct debug_strings *dstrings)
34 static const char *unknown = " (unknown)";
35 static const char *na = "";
36 unsigned int i;
38 if (dstrings == NULL)
39 return na;
41 for (i = 0; dstrings[i].id != 0 || dstrings[i].string != NULL; i++)
42 if (dstrings[i].id == val)
43 return dstrings[i].string;
44 return unknown;
47 EOF
49 while (<>) {
50 if (/^enum\W+(\w+)\W*/) {
51 print STDERR "extern const struct debug_strings $1_array[];\n";
52 print "const struct debug_strings $1_array[] = {\n";
53 $in_enum = 1;
54 } elsif ($in_enum && /^}/) {
55 print "\t{ 0,\t(const char *) 0 }\n};\n\n";
56 $in_enum = 0;
57 } elsif (/^\s*\/\*.*\*\/\s*$/) {
58 next;
59 } elsif ($in_enum && /^\W*(\w+)\W*/) {
60 print "\t{ $1,\t\" ($1)\" },\n";
64 exit 0;
66 __END__