Skip blank lines if old copyright comment was removed, and only then
[openssl.git] / crypto / conf / keysets.pl
1 #! /usr/bin/env perl
2 # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 $NUMBER=0x01;
10 $UPPER=0x02;
11 $LOWER=0x04;
12 $UNDER=0x100;
13 $PUNCTUATION=0x200;
14 $WS=0x10;
15 $ESC=0x20;
16 $QUOTE=0x40;
17 $DQUOTE=0x400;
18 $COMMENT=0x80;
19 $FCOMMENT=0x800;
20 $EOF=0x08;
21 $HIGHBIT=0x1000;
22
23 foreach (0 .. 255)
24         {
25         $v=0;
26         $c=sprintf("%c",$_);
27         $v|=$NUMBER     if ($c =~ /[0-9]/);
28         $v|=$UPPER      if ($c =~ /[A-Z]/);
29         $v|=$LOWER      if ($c =~ /[a-z]/);
30         $v|=$UNDER      if ($c =~ /_/);
31         $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
32         $v|=$WS         if ($c =~ /[ \t\r\n]/);
33         $v|=$ESC        if ($c =~ /\\/);
34         $v|=$QUOTE      if ($c =~ /['`"]/); # for emacs: "`'}/)
35         $v|=$COMMENT    if ($c =~ /\#/);
36         $v|=$EOF        if ($c =~ /\0/);
37         $v|=$HIGHBIT    if ($c =~/[\x80-\xff]/);
38
39         push(@V_def,$v);
40         }
41
42 foreach (0 .. 255)
43         {
44         $v=0;
45         $c=sprintf("%c",$_);
46         $v|=$NUMBER     if ($c =~ /[0-9]/);
47         $v|=$UPPER      if ($c =~ /[A-Z]/);
48         $v|=$LOWER      if ($c =~ /[a-z]/);
49         $v|=$UNDER      if ($c =~ /_/);
50         $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
51         $v|=$WS         if ($c =~ /[ \t\r\n]/);
52         $v|=$DQUOTE     if ($c =~ /["]/); # for emacs: "}/)
53         $v|=$FCOMMENT   if ($c =~ /;/);
54         $v|=$EOF        if ($c =~ /\0/);
55         $v|=$HIGHBIT    if ($c =~/[\x80-\xff]/);
56
57         push(@V_w32,$v);
58         }
59
60 print <<"EOF";
61 /*
62  * WARNING: do not edit!
63  * Generated by crypto/conf/keysets.pl
64  *
65  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
66  * Licensed under the OpenSSL license (the "License").  You may not use
67  * this file except in compliance with the License.  You can obtain a copy
68  * in the file LICENSE in the source distribution or at
69  * https://www.openssl.org/source/license.html
70  */
71
72 #define CONF_NUMBER             $NUMBER
73 #define CONF_UPPER              $UPPER
74 #define CONF_LOWER              $LOWER
75 #define CONF_UNDER              $UNDER
76 #define CONF_PUNCTUATION        $PUNCTUATION
77 #define CONF_WS                 $WS
78 #define CONF_ESC                $ESC
79 #define CONF_QUOTE              $QUOTE
80 #define CONF_DQUOTE             $DQUOTE
81 #define CONF_COMMENT            $COMMENT
82 #define CONF_FCOMMENT           $FCOMMENT
83 #define CONF_EOF                $EOF
84 #define CONF_HIGHBIT            $HIGHBIT
85 #define CONF_ALPHA              (CONF_UPPER|CONF_LOWER)
86 #define CONF_ALPHA_NUMERIC      (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
87 #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
88                                         CONF_PUNCTUATION)
89
90 #define KEYTYPES(c)             ((const unsigned short *)((c)->meth_data))
91 #ifndef CHARSET_EBCDIC
92 # define IS_COMMENT(c,a)         (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
93 # define IS_FCOMMENT(c,a)        (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
94 # define IS_EOF(c,a)             (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
95 # define IS_ESC(c,a)             (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
96 # define IS_NUMBER(c,a)          (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
97 # define IS_WS(c,a)              (KEYTYPES(c)[(a)&0xff]&CONF_WS)
98 # define IS_ALPHA_NUMERIC(c,a)   (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
99 # define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
100                                 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
101 # define IS_QUOTE(c,a)           (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
102 # define IS_DQUOTE(c,a)          (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
103 # define IS_HIGHBIT(c,a)         (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
104
105 #else                           /* CHARSET_EBCDIC */
106
107 # define IS_COMMENT(c,a)         (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
108 # define IS_FCOMMENT(c,a)        (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
109 # define IS_EOF(c,a)             (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
110 # define IS_ESC(c,a)             (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
111 # define IS_NUMBER(c,a)          (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
112 # define IS_WS(c,a)              (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
113 # define IS_ALPHA_NUMERIC(c,a)   (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
114 # define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
115                                 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
116 # define IS_QUOTE(c,a)           (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
117 # define IS_DQUOTE(c,a)          (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
118 # define IS_HIGHBIT(c,a)         (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
119 #endif                          /* CHARSET_EBCDIC */
120
121 EOF
122
123 print "static const unsigned short CONF_type_default[256] = {";
124
125 for ($i=0; $i<256; $i++)
126         {
127         print "\n   " if ($i % 8) == 0;
128         printf " 0x%04X,",$V_def[$i];
129         }
130
131 print "\n};\n\n";
132
133 print "static const unsigned short CONF_type_win32[256] = {";
134
135 for ($i=0; $i<256; $i++)
136         {
137         print "\n   " if ($i % 8) == 0;
138         printf " 0x%04X,",$V_w32[$i];
139         }
140
141 print "\n};\n";