1 #!/usr/local/bin/perl -w
3 # Written by Dr Stephen N Henson (steve@openssl.org).
4 # Licensed under the terms of the OpenSSL license.
10 # Set up an array with the type of ASCII characters
11 # Each set bit represents a character property.
13 # RFC2253 character properties
14 my $RFC2253_ESC = 1; # Character escaped with \
15 my $ESC_CTRL = 2; # Escaped control character
16 # These are used with RFC1779 quoting using "
17 my $NOESC_QUOTE = 8; # Not escaped if quoted
18 my $PSTRING_CHAR = 0x10; # Valid PrintableString character
19 my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
20 my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character
22 for($i = 0; $i < 128; $i++) {
23 # Set the RFC2253 escape characters (control)
25 if(($i < 32) || ($i > 126)) {
26 $arr[$i] |= $ESC_CTRL;
29 # Some PrintableString characters
30 if( ( ( $i >= ord("a")) && ( $i <= ord("z")) )
31 || ( ( $i >= ord("A")) && ( $i <= ord("Z")) )
32 || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) {
33 $arr[$i] |= $PSTRING_CHAR;
39 # Remaining RFC2253 escaped characters
41 $arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
42 $arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
44 $arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
45 $arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
46 $arr[ord("\"")] |= $RFC2253_ESC;
47 $arr[ord("\\")] |= $RFC2253_ESC;
48 $arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
49 $arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
50 $arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
52 # Remaining PrintableString characters
54 $arr[ord(" ")] |= $PSTRING_CHAR;
55 $arr[ord("'")] |= $PSTRING_CHAR;
56 $arr[ord("(")] |= $PSTRING_CHAR;
57 $arr[ord(")")] |= $PSTRING_CHAR;
58 $arr[ord("+")] |= $PSTRING_CHAR;
59 $arr[ord(",")] |= $PSTRING_CHAR;
60 $arr[ord("-")] |= $PSTRING_CHAR;
61 $arr[ord(".")] |= $PSTRING_CHAR;
62 $arr[ord("/")] |= $PSTRING_CHAR;
63 $arr[ord(":")] |= $PSTRING_CHAR;
64 $arr[ord("=")] |= $PSTRING_CHAR;
65 $arr[ord("?")] |= $PSTRING_CHAR;
67 # Now generate the C code
70 /* Auto generated with chartype.pl script.
71 * Mask of various character properties
74 static unsigned char char_type[] = {
77 for($i = 0; $i < 128; $i++) {
78 print("\n") if($i && (($i % 16) == 0));
79 printf("%2d", $arr[$i]);
80 print(",") if ($i != 127);