lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env perl |
| 2 | # Copyright 1995-2022 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 | use strict; |
| 10 | use warnings; |
| 11 | use FindBin; |
| 12 | use lib "$FindBin::Bin/../../util/perl"; |
| 13 | use OpenSSL::copyright; |
| 14 | |
| 15 | my $NUMBER = 0x0001; |
| 16 | my $UPPER = 0x0002; |
| 17 | my $LOWER = 0x0004; |
| 18 | my $UNDER = 0x0100; |
| 19 | my $PUNCTUATION = 0x0200; |
| 20 | my $WS = 0x0010; |
| 21 | my $ESC = 0x0020; |
| 22 | my $QUOTE = 0x0040; |
| 23 | my $DQUOTE = 0x0400; |
| 24 | my $COMMENT = 0x0080; |
| 25 | my $FCOMMENT = 0x0800; |
| 26 | my $EOF = 0x0008; |
| 27 | my @V_def; |
| 28 | my @V_w32; |
| 29 | |
| 30 | my $v; |
| 31 | my $c; |
| 32 | foreach (0 .. 127) { |
| 33 | $c = sprintf("%c", $_); |
| 34 | $v = 0; |
| 35 | $v |= $NUMBER if $c =~ /[0-9]/; |
| 36 | $v |= $UPPER if $c =~ /[A-Z]/; |
| 37 | $v |= $LOWER if $c =~ /[a-z]/; |
| 38 | $v |= $UNDER if $c =~ /_/; |
| 39 | $v |= $PUNCTUATION if $c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/; |
| 40 | $v |= $WS if $c =~ /[ \t\r\n]/; |
| 41 | $v |= $ESC if $c =~ /\\/; |
| 42 | $v |= $QUOTE if $c =~ /['`"]/; # for emacs: "`' |
| 43 | $v |= $COMMENT if $c =~ /\#/; |
| 44 | $v |= $EOF if $c =~ /\0/; |
| 45 | push(@V_def, $v); |
| 46 | |
| 47 | $v = 0; |
| 48 | $v |= $NUMBER if $c =~ /[0-9]/; |
| 49 | $v |= $UPPER if $c =~ /[A-Z]/; |
| 50 | $v |= $LOWER if $c =~ /[a-z]/; |
| 51 | $v |= $UNDER if $c =~ /_/; |
| 52 | $v |= $PUNCTUATION if $c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/; |
| 53 | $v |= $WS if $c =~ /[ \t\r\n]/; |
| 54 | $v |= $DQUOTE if $c =~ /["]/; # for emacs: " |
| 55 | $v |= $FCOMMENT if $c =~ /;/; |
| 56 | $v |= $EOF if $c =~ /\0/; |
| 57 | push(@V_w32, $v); |
| 58 | } |
| 59 | |
| 60 | # The year the output file is generated. |
| 61 | my $YEAR = OpenSSL::copyright::year_of($0); |
| 62 | print <<"EOF"; |
| 63 | /* |
| 64 | * WARNING: do not edit! |
| 65 | * Generated by crypto/conf/keysets.pl |
| 66 | * |
| 67 | * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved. |
| 68 | * Licensed under the OpenSSL license (the "License"). You may not use |
| 69 | * this file except in compliance with the License. You can obtain a copy |
| 70 | * in the file LICENSE in the source distribution or at |
| 71 | * https://www.openssl.org/source/license.html |
| 72 | */ |
| 73 | |
| 74 | #define CONF_NUMBER $NUMBER |
| 75 | #define CONF_UPPER $UPPER |
| 76 | #define CONF_LOWER $LOWER |
| 77 | #define CONF_UNDER $UNDER |
| 78 | #define CONF_PUNCT $PUNCTUATION |
| 79 | #define CONF_WS $WS |
| 80 | #define CONF_ESC $ESC |
| 81 | #define CONF_QUOTE $QUOTE |
| 82 | #define CONF_DQUOTE $DQUOTE |
| 83 | #define CONF_COMMENT $COMMENT |
| 84 | #define CONF_FCOMMENT $FCOMMENT |
| 85 | #define CONF_EOF $EOF |
| 86 | #define CONF_ALPHA (CONF_UPPER|CONF_LOWER) |
| 87 | #define CONF_ALNUM (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) |
| 88 | #define CONF_ALNUM_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER|CONF_PUNCT) |
| 89 | |
| 90 | |
| 91 | #define IS_COMMENT(conf,c) is_keytype(conf, c, CONF_COMMENT) |
| 92 | #define IS_FCOMMENT(conf,c) is_keytype(conf, c, CONF_FCOMMENT) |
| 93 | #define IS_EOF(conf,c) is_keytype(conf, c, CONF_EOF) |
| 94 | #define IS_ESC(conf,c) is_keytype(conf, c, CONF_ESC) |
| 95 | #define IS_NUMBER(conf,c) is_keytype(conf, c, CONF_NUMBER) |
| 96 | #define IS_WS(conf,c) is_keytype(conf, c, CONF_WS) |
| 97 | #define IS_ALNUM(conf,c) is_keytype(conf, c, CONF_ALNUM) |
| 98 | #define IS_ALNUM_PUNCT(conf,c) is_keytype(conf, c, CONF_ALNUM_PUNCT) |
| 99 | #define IS_QUOTE(conf,c) is_keytype(conf, c, CONF_QUOTE) |
| 100 | #define IS_DQUOTE(conf,c) is_keytype(conf, c, CONF_DQUOTE) |
| 101 | |
| 102 | EOF |
| 103 | |
| 104 | my $i; |
| 105 | |
| 106 | print "static const unsigned short CONF_type_default[128] = {"; |
| 107 | for ($i = 0; $i < 128; $i++) { |
| 108 | print "\n " if ($i % 8) == 0; |
| 109 | printf " 0x%04X,", $V_def[$i]; |
| 110 | } |
| 111 | print "\n};\n\n"; |
| 112 | |
| 113 | print "static const unsigned short CONF_type_win32[128] = {"; |
| 114 | for ($i = 0; $i < 128; $i++) { |
| 115 | print "\n " if ($i % 8) == 0; |
| 116 | printf " 0x%04X,", $V_w32[$i]; |
| 117 | } |
| 118 | print "\n};\n"; |