Annotation of embedaddon/strongswan/src/libstrongswan/asn1/oid.pl, revision 1.1
1.1 ! misho 1: #!/usr/bin/perl
! 2: # Generates oid.h and oid.c out of oid.txt
! 3: #
! 4: # Copyright (C) 2003-2008 Andreas Steffen
! 5: # HSR Hochschule fuer Technik Rapperswil
! 6: #
! 7: # This program is free software; you can redistribute it and/or modify it
! 8: # under the terms of the GNU General Public License as published by the
! 9: # Free Software Foundation; either version 2 of the License, or (at your
! 10: # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 11: #
! 12: # This program is distributed in the hope that it will be useful, but
! 13: # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 15: # for more details.
! 16: #
! 17:
! 18: $copyright="Copyright (C) 2003-2008 Andreas Steffen, Hochschule fuer Technik Rapperswil";
! 19: $automatic="This file has been automatically generated by the script oid.pl";
! 20: $warning="Do not edit manually!";
! 21:
! 22: # Generate oid.h
! 23:
! 24: open(OID_H, ">oid.h")
! 25: or die "could not open 'oid.h': $!";
! 26:
! 27: print OID_H "/* Object identifiers (OIDs) used by strongSwan\n",
! 28: " * ", $copyright, "\n",
! 29: " * \n",
! 30: " * ", $automatic, "\n",
! 31: " * ", $warning, "\n",
! 32: " */\n\n",
! 33: "#include <utils/utils.h>\n\n",
! 34: "#ifndef OID_H_\n",
! 35: "#define OID_H_\n\n",
! 36: "typedef struct {\n",
! 37: " u_char octet;\n",
! 38: " u_int next;\n",
! 39: " u_int down;\n",
! 40: " u_int level;\n",
! 41: " const u_char *name;\n",
! 42: "} oid_t;\n",
! 43: "\n",
! 44: "extern const oid_t oid_names[];\n",
! 45: "\n",
! 46: "#define OID_UNKNOWN -1\n";
! 47:
! 48: # parse oid.txt
! 49:
! 50: open(SRC, "<oid.txt")
! 51: or die "could not open 'oid.txt': $!";
! 52:
! 53: $counter = 0;
! 54: $max_name = 0;
! 55: $max_order = 0;
! 56:
! 57: while ($line = <SRC>)
! 58: {
! 59: $line =~ m/( *?)(0x\w{2})\s+(".*?")[ \t]*?([\w_]*?)\Z/;
! 60:
! 61: @order[$counter] = length($1);
! 62: @octet[$counter] = $2;
! 63: @name[$counter] = $3;
! 64:
! 65: if (length($1) > $max_order)
! 66: {
! 67: $max_order = length($1);
! 68: }
! 69: if (length($3) > $max_name)
! 70: {
! 71: $max_name = length($3);
! 72: }
! 73: if (length($4) > 0)
! 74: {
! 75: printf OID_H "#define %s%s%d\n", $4, "\t" x ((39-length($4))/4), $counter;
! 76: }
! 77: $counter++;
! 78: }
! 79:
! 80: printf OID_H "\n#define OID_MAX%s%d\n", "\t" x 8, $counter;
! 81:
! 82: print OID_H "\n#endif /* OID_H_ */\n";
! 83:
! 84: close SRC;
! 85: close OID_H;
! 86:
! 87: # Generate oid.c
! 88:
! 89: open(OID_C, ">oid.c")
! 90: or die "could not open 'oid.c': $!";
! 91:
! 92: print OID_C "/* List of some useful object identifiers (OIDs)\n",
! 93: " * ", $copyright, "\n",
! 94: " * \n",
! 95: " * ", $automatic, "\n",
! 96: " * ", $warning, "\n",
! 97: " */\n",
! 98: "\n",
! 99: "#include <stdlib.h>\n",
! 100: "\n",
! 101: "#include \"oid.h\"\n",
! 102: "\n",
! 103: "const oid_t oid_names[] = {\n";
! 104:
! 105: for ($c = 0; $c < $counter; $c++)
! 106: {
! 107: $next = 0;
! 108:
! 109: for ($d = $c+1; $d < $counter && @order[$d] >= @order[$c]; $d++)
! 110: {
! 111: if (@order[$d] == @order[$c])
! 112: {
! 113: @next[$c] = $d;
! 114: last;
! 115: }
! 116: }
! 117:
! 118: printf OID_C " {%s%s,%s%3d, %d, %2d, %s%s}%s /* %3d */\n"
! 119: ,' ' x @order[$c]
! 120: , @octet[$c]
! 121: , ' ' x (1 + $max_order - @order[$c])
! 122: , @next[$c]
! 123: , @order[$c+1] > @order[$c]
! 124: , @order[$c] / 2
! 125: , @name[$c]
! 126: , ' ' x ($max_name - length(@name[$c]))
! 127: , $c != $counter-1 ? "," : " "
! 128: , $c;
! 129: }
! 130:
! 131: print OID_C "};\n" ;
! 132: close OID_C;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>