objects.pl 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!/usr/local/bin/perl
  2. open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
  3. $max_nid=0;
  4. $o=0;
  5. while(<NUMIN>)
  6. {
  7. chop;
  8. $o++;
  9. s/#.*$//;
  10. next if /^\s*$/;
  11. $_ = 'X'.$_;
  12. ($Cname,$mynum) = split;
  13. $Cname =~ s/^X//;
  14. if (defined($nidn{$mynum}))
  15. { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
  16. $nid{$Cname} = $mynum;
  17. $nidn{$mynum} = $Cname;
  18. $order{$mynum} = $o;
  19. $max_nid = $mynum if $mynum > $max_nid;
  20. }
  21. close NUMIN;
  22. open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
  23. $Cname="";
  24. $o=0;
  25. while (<IN>)
  26. {
  27. chop;
  28. $o++;
  29. if (/^!module\s+(.*)$/)
  30. {
  31. $module = $1."-";
  32. $module =~ s/\./_/g;
  33. $module =~ s/-/_/g;
  34. }
  35. if (/^!global$/)
  36. { $module = ""; }
  37. if (/^!Cname\s+(.*)$/)
  38. { $Cname = $1; }
  39. if (/^!Alias\s+(.+?)\s+(.*)$/)
  40. {
  41. $Cname = $module.$1;
  42. $myoid = $2;
  43. $myoid = &process_oid($myoid);
  44. $Cname =~ s/-/_/g;
  45. $ordern{$o} = $Cname;
  46. $order{$Cname} = $o;
  47. $obj{$Cname} = $myoid;
  48. $_ = "";
  49. $Cname = "";
  50. }
  51. s/!.*$//;
  52. s/#.*$//;
  53. next if /^\s*$/;
  54. ($myoid,$mysn,$myln) = split ':';
  55. $mysn =~ s/^\s*//;
  56. $mysn =~ s/\s*$//;
  57. $myln =~ s/^\s*//;
  58. $myln =~ s/\s*$//;
  59. $myoid =~ s/^\s*//;
  60. $myoid =~ s/\s*$//;
  61. if ($myoid ne "")
  62. {
  63. $myoid = &process_oid($myoid);
  64. }
  65. if ($Cname eq "" && !($myln =~ / /))
  66. {
  67. $Cname = $myln;
  68. $Cname =~ s/\./_/g;
  69. $Cname =~ s/-/_/g;
  70. if ($Cname ne "" && defined($ln{$module.$Cname}))
  71. { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  72. }
  73. if ($Cname eq "")
  74. {
  75. $Cname = $mysn;
  76. $Cname =~ s/-/_/g;
  77. if ($Cname ne "" && defined($sn{$module.$Cname}))
  78. { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  79. }
  80. if ($Cname eq "")
  81. {
  82. $Cname = $myln;
  83. $Cname =~ s/-/_/g;
  84. $Cname =~ s/\./_/g;
  85. $Cname =~ s/ /_/g;
  86. if ($Cname ne "" && defined($ln{$module.$Cname}))
  87. { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  88. }
  89. $Cname =~ s/\./_/g;
  90. $Cname =~ s/-/_/g;
  91. $Cname = $module.$Cname;
  92. $ordern{$o} = $Cname;
  93. $order{$Cname} = $o;
  94. $sn{$Cname} = $mysn;
  95. $ln{$Cname} = $myln;
  96. $obj{$Cname} = $myoid;
  97. if (!defined($nid{$Cname}))
  98. {
  99. $max_nid++;
  100. $nid{$Cname} = $max_nid;
  101. $nidn{$max_nid} = $Cname;
  102. }
  103. $Cname="";
  104. }
  105. close IN;
  106. open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
  107. foreach (sort { $a <=> $b } keys %nidn)
  108. {
  109. print NUMOUT $nidn{$_},"\t\t",$_,"\n";
  110. }
  111. close NUMOUT;
  112. open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
  113. print OUT <<'EOF';
  114. /* crypto/objects/obj_mac.h */
  115. /*
  116. * THIS FILE IS GENERATED FROM objects.txt by objects.pl via the following
  117. * command: perl objects.pl objects.txt obj_mac.num obj_mac.h
  118. */
  119. /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  120. * All rights reserved.
  121. *
  122. * This package is an SSL implementation written
  123. * by Eric Young (eay@cryptsoft.com).
  124. * The implementation was written so as to conform with Netscapes SSL.
  125. *
  126. * This library is free for commercial and non-commercial use as long as
  127. * the following conditions are aheared to. The following conditions
  128. * apply to all code found in this distribution, be it the RC4, RSA,
  129. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  130. * included with this distribution is covered by the same copyright terms
  131. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  132. *
  133. * Copyright remains Eric Young's, and as such any Copyright notices in
  134. * the code are not to be removed.
  135. * If this package is used in a product, Eric Young should be given attribution
  136. * as the author of the parts of the library used.
  137. * This can be in the form of a textual message at program startup or
  138. * in documentation (online or textual) provided with the package.
  139. *
  140. * Redistribution and use in source and binary forms, with or without
  141. * modification, are permitted provided that the following conditions
  142. * are met:
  143. * 1. Redistributions of source code must retain the copyright
  144. * notice, this list of conditions and the following disclaimer.
  145. * 2. Redistributions in binary form must reproduce the above copyright
  146. * notice, this list of conditions and the following disclaimer in the
  147. * documentation and/or other materials provided with the distribution.
  148. * 3. All advertising materials mentioning features or use of this software
  149. * must display the following acknowledgement:
  150. * "This product includes cryptographic software written by
  151. * Eric Young (eay@cryptsoft.com)"
  152. * The word 'cryptographic' can be left out if the rouines from the library
  153. * being used are not cryptographic related :-).
  154. * 4. If you include any Windows specific code (or a derivative thereof) from
  155. * the apps directory (application code) you must include an acknowledgement:
  156. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  157. *
  158. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  159. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  160. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  161. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  162. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  163. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  164. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  165. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  166. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  167. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  168. * SUCH DAMAGE.
  169. *
  170. * The licence and distribution terms for any publically available version or
  171. * derivative of this code cannot be changed. i.e. this code cannot simply be
  172. * copied and put under another distribution licence
  173. * [including the GNU Public Licence.]
  174. */
  175. #define SN_undef "UNDEF"
  176. #define LN_undef "undefined"
  177. #define NID_undef 0
  178. #define OBJ_undef 0L
  179. EOF
  180. sub expand
  181. {
  182. my $string = shift;
  183. 1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
  184. return $string;
  185. }
  186. foreach (sort { $a <=> $b } keys %ordern)
  187. {
  188. $Cname=$ordern{$_};
  189. print OUT "\n";
  190. print OUT expand("#define SN_$Cname\t\t\"$sn{$Cname}\"\n") if $sn{$Cname} ne "";
  191. print OUT expand("#define LN_$Cname\t\t\"$ln{$Cname}\"\n") if $ln{$Cname} ne "";
  192. print OUT expand("#define NID_$Cname\t\t$nid{$Cname}\n") if $nid{$Cname} ne "";
  193. print OUT expand("#define OBJ_$Cname\t\t$obj{$Cname}\n") if $obj{$Cname} ne "";
  194. }
  195. close OUT;
  196. sub process_oid
  197. {
  198. local($oid)=@_;
  199. local(@a,$oid_pref);
  200. @a = split(/\s+/,$myoid);
  201. $pref_oid = "";
  202. $pref_sep = "";
  203. if (!($a[0] =~ /^[0-9]+$/))
  204. {
  205. $a[0] =~ s/-/_/g;
  206. if (!defined($obj{$a[0]}))
  207. { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
  208. $pref_oid = "OBJ_" . $a[0];
  209. $pref_sep = ",";
  210. shift @a;
  211. }
  212. $oids = join('L,',@a) . "L";
  213. if ($oids ne "L")
  214. {
  215. $oids = $pref_oid . $pref_sep . $oids;
  216. }
  217. else
  218. {
  219. $oids = $pref_oid;
  220. }
  221. return($oids);
  222. }