Debian Codegraph @

tools/fix_tommath_h.tcl

raw
1 # fixtommath.tcl --
2 #
3 # Changes to 'tommath.h' to make it conform with Tcl's linking
4 # conventions.
5 #
6 # Copyright (c) 2005 Kevin B. Kenny. All rights reserved.
7 #
8 # See the file "license.terms" for information on usage and redistribution
9 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 #----------------------------------------------------------------------
11
12 set f [open [lindex $argv 0] r]
13 set data [read $f]
14 close $f
15
16 set eat_endif 0
17 set eat_semi 0
18 set def_count 0
19 foreach line [split $data \n] {
20 if {!$eat_semi && !$eat_endif} {
21 switch -regexp -- $line {
22 {#define BN_H_} {
23 puts $line
24 puts {}
25 puts "\#include \"tclInt.h\""
26 puts "\#include \"tclTomMathDecls.h\""
27 puts "\#ifndef MODULE_SCOPE"
28 puts "\#define MODULE_SCOPE extern"
29 puts "\#endif"
30 }
31 {typedef\s+unsigned long\s+mp_digit;} {
32 # change the second 'typedef unsigned long mp
33 incr def_count
34 puts "\#ifndef MP_DIGIT_DECLARED"
35 if {$def_count == 2} {
36 puts [string map {long int} $line]
37 } else {
38 puts $line
39 }
40 puts "\#define MP_DIGIT_DECLARED"
41 puts "\#endif"
42 }
43 {typedef.*mp_digit;} {
44 puts "\#ifndef MP_DIGIT_DECLARED"
45 puts $line
46 puts "\#define MP_DIGIT_DECLARED"
47 puts "\#endif"
48 }
49 {typedef struct} {
50 puts "\#ifndef MP_INT_DECLARED"
51 puts "\#define MP_INT_DECLARED"
52 puts "typedef struct mp_int mp_int;"
53 puts "\#endif"
54 puts "struct mp_int \{"
55 }
56 \}\ mp_int\; {
57 puts "\};"
58 }
59 {^(char|int|void)} {
60 puts "/*"
61 puts $line
62 set eat_semi 1
63 set after_semi "*/"
64 }
65 {^extern (int|const)} {
66 puts "\#if defined(BUILD_tcl) || !defined(_WIN32)"
67 puts [regsub {^extern} $line "MODULE_SCOPE"]
68 set eat_semi 1
69 set after_semi "\#endif"
70 }
71 {define heap macros} {
72 puts $line
73 puts "\#if 0 /* these are macros in tclTomMathDecls.h */"
74 set eat_endif 1
75 }
76 {__x86_64__} {
77 puts "[string map {__x86_64__ NEVER} $line]\
78 /* 128-bit ints fail in too many places */"
79 }
80 {#include} {
81 # remove all includes
82 }
83 default {
84 puts $line
85 }
86 }
87 } else {
88 puts $line
89 }
90 if {$eat_semi} {
91 if {[regexp {; *$} $line]} {
92 puts $after_semi
93 set eat_semi 0
94 }
95 }
96 if {$eat_endif} {
97 if {[regexp {^\#endif} $line]} {
98 puts "\#endif"
99 set eat_endif 0
100 }
101 }
102 }