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