"Fossies" - the Fresh Open Source Software Archive

Member "vpnc-0.5.3/enum2debug.pl" (19 Nov 2008, 1258 Bytes) of package /linux/privat/old/vpnc-0.5.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "enum2debug.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl -w
    2 
    3 # Usage: ./enum2debug.pl isakmp.h  >vpnc-debug.c 2>vpnc-debug.h
    4 
    5 use strict;
    6 
    7 my $in_enum = 0;
    8 my $element;
    9 my $arrayname;
   10 
   11 print STDERR << 'EOF';
   12 /* Automatically generated with enum2debug.pl: Don't edit! */
   13 
   14 struct debug_strings {
   15     unsigned int id;
   16     const char *string;
   17 };
   18 
   19 extern const char *val_to_string(unsigned int, const struct debug_strings *);
   20 
   21 EOF
   22 
   23 print << 'EOF';
   24 /* Automatically generated with enum2debug.pl: Don't edit! */
   25 
   26 #include <stdio.h>
   27 
   28 #include "vpnc-debug.h"
   29 #include "isakmp.h"
   30 
   31 const char *val_to_string(unsigned int val, const struct debug_strings *dstrings)
   32 {
   33     static const char *unknown = " (unknown)";
   34     static const char *na = "";
   35     unsigned int i;
   36     
   37     if (dstrings == NULL)
   38         return na;
   39     
   40     for (i = 0; dstrings[i].id != 0 || dstrings[i].string != NULL; i++)
   41         if (dstrings[i].id == val)
   42             return dstrings[i].string;
   43     return unknown;
   44 }
   45 
   46 EOF
   47 
   48 while (<>) {
   49     if (/^enum\W+(\w+)\W*/) {
   50         print STDERR "extern const struct debug_strings $1_array[];\n";
   51         print "const struct debug_strings $1_array[] = {\n";
   52         $in_enum = 1;
   53     } elsif ($in_enum && /^}/) {
   54         print "\t{ 0,\t(const char *) 0 }\n};\n\n";
   55         $in_enum = 0;
   56     } elsif ($in_enum && /^\W*(\w+)\W*/) {
   57         print "\t{ $1,\t\" ($1)\" },\n";
   58     }
   59 }
   60 
   61 exit 0;
   62 
   63 __END__