keysets.pl 3.8 KB

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