terminate config reading on EOT/Ctl-D instead of just on pipe close
[vpnc.git] / enum2debug.pl
blob318fce3baeb4ef6e62050f7d266549e73e3be3d2
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;
10 print STDERR << 'EOF';
11 /* Automatically generated with enum2debug.pl: Don't edit! */
13 struct debug_strings {
14 unsigned int id;
15 const char *string;
18 extern const char *val_to_string(unsigned int, const struct debug_strings *);
20 EOF
22 print << 'EOF';
23 /* Automatically generated with enum2debug.pl: Don't edit! */
25 #include <stdio.h>
27 #include "vpnc-debug.h"
28 #include "isakmp.h"
30 const char *val_to_string(unsigned int val, const struct debug_strings *dstrings)
32 static const char *unknown = " (unknown)";
33 static const char *na = "";
34 unsigned int i;
36 if (dstrings == NULL)
37 return na;
39 for (i = 0; dstrings[i].id != 0 || dstrings[i].string != NULL; i++)
40 if (dstrings[i].id == val)
41 return dstrings[i].string;
42 return unknown;
45 EOF
47 while (<>) {
48 if (/^enum\W+(\w+)\W*/) {
49 print STDERR "extern const struct debug_strings $1_array[];\n";
50 print "const struct debug_strings $1_array[] = {\n";
51 $in_enum = 1;
52 } elsif ($in_enum && /^}/) {
53 print "\t{ 0,\t(const char *) 0 }\n};\n\n";
54 $in_enum = 0;
55 } elsif (/^\s*\/\*.*\*\/\s*$/) {
56 next;
57 } elsif ($in_enum && /^\W*(\w+)\W*/) {
58 print "\t{ $1,\t\" ($1)\" },\n";
62 exit 0;
64 __END__