blob: 9c9a00dea8d7a7978b3afa2e85d1aa36af80a1e9 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#! /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
9use strict;
10use warnings;
11use FindBin;
12use lib "$FindBin::Bin/../../util/perl";
13use OpenSSL::copyright;
14
15my $NUMBER = 0x0001;
16my $UPPER = 0x0002;
17my $LOWER = 0x0004;
18my $UNDER = 0x0100;
19my $PUNCTUATION = 0x0200;
20my $WS = 0x0010;
21my $ESC = 0x0020;
22my $QUOTE = 0x0040;
23my $DQUOTE = 0x0400;
24my $COMMENT = 0x0080;
25my $FCOMMENT = 0x0800;
26my $EOF = 0x0008;
27my @V_def;
28my @V_w32;
29
30my $v;
31my $c;
32foreach (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.
61my $YEAR = OpenSSL::copyright::year_of($0);
62print <<"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
102EOF
103
104my $i;
105
106print "static const unsigned short CONF_type_default[128] = {";
107for ($i = 0; $i < 128; $i++) {
108 print "\n " if ($i % 8) == 0;
109 printf " 0x%04X,", $V_def[$i];
110}
111print "\n};\n\n";
112
113print "static const unsigned short CONF_type_win32[128] = {";
114for ($i = 0; $i < 128; $i++) {
115 print "\n " if ($i % 8) == 0;
116 printf " 0x%04X,", $V_w32[$i];
117}
118print "\n};\n";