keysets.pl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. $NUMBER=0x01;
  9. $UPPER=0x02;
  10. $LOWER=0x04;
  11. $UNDER=0x100;
  12. $PUNCTUATION=0x200;
  13. $WS=0x10;
  14. $ESC=0x20;
  15. $QUOTE=0x40;
  16. $DQUOTE=0x400;
  17. $COMMENT=0x80;
  18. $FCOMMENT=0x800;
  19. $EOF=0x08;
  20. $HIGHBIT=0x1000;
  21. foreach (0 .. 255)
  22. {
  23. $v=0;
  24. $c=sprintf("%c",$_);
  25. $v|=$NUMBER if ($c =~ /[0-9]/);
  26. $v|=$UPPER if ($c =~ /[A-Z]/);
  27. $v|=$LOWER if ($c =~ /[a-z]/);
  28. $v|=$UNDER if ($c =~ /_/);
  29. $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
  30. $v|=$WS if ($c =~ /[ \t\r\n]/);
  31. $v|=$ESC if ($c =~ /\\/);
  32. $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/)
  33. $v|=$COMMENT if ($c =~ /\#/);
  34. $v|=$EOF if ($c =~ /\0/);
  35. $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
  36. push(@V_def,$v);
  37. }
  38. foreach (0 .. 255)
  39. {
  40. $v=0;
  41. $c=sprintf("%c",$_);
  42. $v|=$NUMBER if ($c =~ /[0-9]/);
  43. $v|=$UPPER if ($c =~ /[A-Z]/);
  44. $v|=$LOWER if ($c =~ /[a-z]/);
  45. $v|=$UNDER if ($c =~ /_/);
  46. $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
  47. $v|=$WS if ($c =~ /[ \t\r\n]/);
  48. $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/)
  49. $v|=$FCOMMENT if ($c =~ /;/);
  50. $v|=$EOF if ($c =~ /\0/);
  51. $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
  52. push(@V_w32,$v);
  53. }
  54. print <<"EOF";
  55. /*
  56. * WARNING: do not edit!
  57. * Generated by crypto/conf/keysets.pl
  58. *
  59. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  60. * Licensed under the OpenSSL license (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_PUNCTUATION $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_HIGHBIT $HIGHBIT
  78. #define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
  79. #define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
  80. #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
  81. CONF_PUNCTUATION)
  82. #define KEYTYPES(c) ((const unsigned short *)((c)->meth_data))
  83. #ifndef CHARSET_EBCDIC
  84. # define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
  85. # define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
  86. # define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
  87. # define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
  88. # define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
  89. # define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
  90. # define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
  91. # define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
  92. (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
  93. # define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
  94. # define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
  95. # define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
  96. #else /* CHARSET_EBCDIC */
  97. # define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_COMMENT)
  98. # define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_FCOMMENT)
  99. # define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_EOF)
  100. # define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_ESC)
  101. # define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_NUMBER)
  102. # define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_WS)
  103. # define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_ALPHA_NUMERIC)
  104. # define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
  105. (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_ALPHA_NUMERIC_PUNCT)
  106. # define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_QUOTE)
  107. # define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_DQUOTE)
  108. # define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a & 0xff]]&CONF_HIGHBIT)
  109. #endif /* CHARSET_EBCDIC */
  110. EOF
  111. print "static const unsigned short CONF_type_default[256] = {";
  112. for ($i=0; $i<256; $i++)
  113. {
  114. print "\n " if ($i % 8) == 0;
  115. printf " 0x%04X,",$V_def[$i];
  116. }
  117. print "\n};\n\n";
  118. print "static const unsigned short CONF_type_win32[256] = {";
  119. for ($i=0; $i<256; $i++)
  120. {
  121. print "\n " if ($i % 8) == 0;
  122. printf " 0x%04X,",$V_w32[$i];
  123. }
  124. print "\n};\n";