generate tommath_class.h with astyle format (refactor with heredoc)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
diff --git a/dep.pl b/dep.pl
index fe9ab59..71a5dd4 100644
--- a/dep.pl
+++ b/dep.pl
@@ -9,7 +9,18 @@ my %deplist;
#open class file and write preamble
open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n";
-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";
+print {$class} << 'EOS';
+#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
+#if defined(LTM2)
+# define LTM3
+#endif
+#if defined(LTM1)
+# define LTM2
+#endif
+#define LTM1
+
+#if defined(LTM_ALL)
+EOS
foreach my $filename (glob 'bn*.c') {
my $define = $filename;
@@ -19,7 +30,9 @@ foreach my $filename (glob 'bn*.c') {
# convert filename to upper case so we can use it as a define
$define =~ tr/[a-z]/[A-Z]/;
$define =~ tr/\./_/;
- print {$class} "#define $define\n";
+ print {$class} << "EOS";
+# define $define
+EOS
# now copy text and apply #ifdef as required
my $apply = 0;
@@ -31,7 +44,11 @@ foreach my $filename (glob 'bn*.c') {
if ($line =~ /include/) {
print {$out} $line;
} else {
- print {$out} "#include <tommath.h>\n#ifdef $define\n$line";
+ print {$out} << "EOS";
+#include <tommath.h>
+#ifdef $define
+$line
+EOS
$apply = 1;
}
while (<$src>) {
@@ -40,7 +57,9 @@ foreach my $filename (glob 'bn*.c') {
}
}
if ($apply == 1) {
- print {$out} "#endif\n";
+ print {$out} << 'EOS';
+#endif
+EOS
}
close $src;
close $out;
@@ -48,7 +67,10 @@ foreach my $filename (glob 'bn*.c') {
unlink $filename;
rename 'tmp', $filename;
}
-print {$class} "#endif\n\n";
+print {$class} << 'EOS';
+#endif
+
+EOS
# now do classes
@@ -59,7 +81,9 @@ foreach my $filename (glob 'bn*.c') {
$filename =~ tr/[a-z]/[A-Z]/;
$filename =~ tr/\./_/;
- print {$class} "#if defined($filename)\n";
+ print {$class} << "EOS";
+#if defined($filename)
+EOS
my $list = $filename;
# scan for mp_* and make classes
@@ -74,7 +98,9 @@ foreach my $filename (glob 'bn*.c') {
$a =~ tr/[a-z]/[A-Z]/;
$a = 'BN_' . $a . '_C';
if (!($list =~ /$a/)) {
- print {$class} " #define $a\n";
+ print {$class} << "EOS";
+# define $a
+EOS
}
$list = $list . ',' . $a;
}
@@ -82,11 +108,24 @@ foreach my $filename (glob 'bn*.c') {
}
$deplist{$filename} = $list;
- print {$class} "#endif\n\n";
+ print {$class} << 'EOS';
+#endif
+
+EOS
close $src;
}
-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";
+print {$class} << 'EOS';
+#ifdef LTM3
+# define LTM_LAST
+#endif
+
+#include <tommath_superclass.h>
+#include <tommath_class.h>
+#else
+# define LTM_LAST
+#endif
+EOS
close $class;
#now let's make a cool call graph...