Home | History | Annotate | Download | only in asn1
      1 #!/usr/local/bin/perl -w
      2 
      3 use strict;
      4 
      5 my ($i, @arr);
      6 
      7 # Set up an array with the type of ASCII characters
      8 # Each set bit represents a character property.
      9 
     10 # RFC2253 character properties
     11 my $RFC2253_ESC = 1;	# Character escaped with \
     12 my $ESC_CTRL	= 2;	# Escaped control character
     13 # These are used with RFC1779 quoting using "
     14 my $NOESC_QUOTE	= 8;	# Not escaped if quoted
     15 my $PSTRING_CHAR = 0x10;	# Valid PrintableString character
     16 my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
     17 my $RFC2253_LAST_ESC = 0x40;  # Escaped with \ if last character
     18 
     19 for($i = 0; $i < 128; $i++) {
     20 	# Set the RFC2253 escape characters (control)
     21 	$arr[$i] = 0;
     22 	if(($i < 32) || ($i > 126)) {
     23 		$arr[$i] |= $ESC_CTRL;
     24 	}
     25 
     26 	# Some PrintableString characters
     27 	if(		   ( ( $i >= ord("a")) && ( $i <= ord("z")) )
     28 			|| (  ( $i >= ord("A")) && ( $i <= ord("Z")) )
     29 			|| (  ( $i >= ord("0")) && ( $i <= ord("9")) )  ) {
     30 		$arr[$i] |= $PSTRING_CHAR;
     31 	}
     32 }
     33 
     34 # Now setup the rest
     35 
     36 # Remaining RFC2253 escaped characters
     37 
     38 $arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
     39 $arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
     40 
     41 $arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
     42 $arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
     43 $arr[ord("\"")] |= $RFC2253_ESC;
     44 $arr[ord("\\")] |= $RFC2253_ESC;
     45 $arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
     46 $arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
     47 $arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
     48 
     49 # Remaining PrintableString characters
     50 
     51 $arr[ord(" ")] |= $PSTRING_CHAR;
     52 $arr[ord("'")] |= $PSTRING_CHAR;
     53 $arr[ord("(")] |= $PSTRING_CHAR;
     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 
     64 # Now generate the C code
     65 
     66 print <<EOF;
     67 /* Auto generated with chartype.pl script.
     68  * Mask of various character properties
     69  */
     70 
     71 static unsigned char char_type[] = {
     72 EOF
     73 
     74 for($i = 0; $i < 128; $i++) {
     75 	print("\n") if($i && (($i % 16) == 0));
     76 	printf("%2d", $arr[$i]);
     77 	print(",") if ($i != 127);
     78 }
     79 print("\n};\n\n");
     80 
     81