Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / dropbear / libtommath / dep.pl
blobc39e27ea087323b195b7cbde619929e7ed998752
1 #!/usr/bin/perl
3 # Walk through source, add labels and make classes
5 #use strict;
7 my %deplist;
9 #open class file and write preamble
10 open(CLASS, ">tommath_class.h") or die "Couldn't open tommath_class.h for writing\n";
11 print CLASS "#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))\n#if defined(LTM2)\n#define LTM3\n#endif\n#if defined(LTM1)\n#define LTM2\n#endif\n#define LTM1\n\n#if defined(LTM_ALL)\n";
13 foreach my $filename (glob "bn*.c") {
14 my $define = $filename;
16 print "Processing $filename\n";
18 # convert filename to upper case so we can use it as a define
19 $define =~ tr/[a-z]/[A-Z]/;
20 $define =~ tr/\./_/;
21 print CLASS "#define $define\n";
23 # now copy text and apply #ifdef as required
24 my $apply = 0;
25 open(SRC, "<$filename");
26 open(OUT, ">tmp");
28 # first line will be the #ifdef
29 my $line = <SRC>;
30 if ($line =~ /include/) {
31 print OUT $line;
32 } else {
33 print OUT "#include <tommath.h>\n#ifdef $define\n$line";
34 $apply = 1;
36 while (<SRC>) {
37 if (!($_ =~ /tommath\.h/)) {
38 print OUT $_;
41 if ($apply == 1) {
42 print OUT "#endif\n";
44 close SRC;
45 close OUT;
47 unlink($filename);
48 rename("tmp", $filename);
50 print CLASS "#endif\n\n";
52 # now do classes
54 foreach my $filename (glob "bn*.c") {
55 open(SRC, "<$filename") or die "Can't open source file!\n";
57 # convert filename to upper case so we can use it as a define
58 $filename =~ tr/[a-z]/[A-Z]/;
59 $filename =~ tr/\./_/;
61 print CLASS "#if defined($filename)\n";
62 my $list = $filename;
64 # scan for mp_* and make classes
65 while (<SRC>) {
66 my $line = $_;
67 while ($line =~ m/(fast_)*(s_)*mp\_[a-z_0-9]*/) {
68 $line = $';
69 # now $& is the match, we want to skip over LTM keywords like
70 # mp_int, mp_word, mp_digit
71 if (!($& eq "mp_digit") && !($& eq "mp_word") && !($& eq "mp_int")) {
72 my $a = $&;
73 $a =~ tr/[a-z]/[A-Z]/;
74 $a = "BN_" . $a . "_C";
75 if (!($list =~ /$a/)) {
76 print CLASS " #define $a\n";
78 $list = $list . "," . $a;
82 @deplist{$filename} = $list;
84 print CLASS "#endif\n\n";
85 close SRC;
88 print CLASS "#ifdef LTM3\n#define LTM_LAST\n#endif\n#include <tommath_superclass.h>\n#include <tommath_class.h>\n#else\n#define LTM_LAST\n#endif\n";
89 close CLASS;
91 #now let's make a cool call graph...
93 open(OUT,">callgraph.txt");
94 $indent = 0;
95 foreach (keys %deplist) {
96 $list = "";
97 draw_func(@deplist{$_});
98 print OUT "\n\n";
100 close(OUT);
102 sub draw_func()
104 my @funcs = split(",", $_[0]);
105 if ($list =~ /@funcs[0]/) {
106 return;
107 } else {
108 $list = $list . @funcs[0];
110 if ($indent == 0) { }
111 elsif ($indent >= 1) { print OUT "| " x ($indent - 1) . "+--->"; }
112 print OUT @funcs[0] . "\n";
113 shift @funcs;
114 my $temp = $list;
115 foreach my $i (@funcs) {
116 ++$indent;
117 draw_func(@deplist{$i});
118 --$indent;
120 $list = $temp;