Imported Upstream version 2.5.1
[debian/amanda] / regex-src / mkh
1 #! /bin/sh
2 # mkh - pull headers out of C source
3 PATH=/bin:/usr/bin ; export PATH
4
5 # egrep pattern to pick out marked lines
6 egrep='^ =([    ]|$)'
7
8 # Sed program to process marked lines into lines for the header file.
9 # The markers have already been removed.  Two things are done here:  removal
10 # of backslashed newlines, and some fudging of comments.  The first is done
11 # because -o needs to have prototypes on one line to strip them down.
12 # Getting comments into the output is tricky; we turn C++-style // comments
13 # into /* */ comments, after altering any existing */'s to avoid trouble.
14 peel='  /\\$/N
15         /\\\n[  ]*/s///g
16         /\/\//s;\*/;* /;g
17         /\/\//s;//\(.*\);/*\1 */;'
18
19 for a
20 do
21         case "$a" in
22         -o)     # old (pre-function-prototype) compiler
23                 # add code to comment out argument lists
24                 peel="$peel
25                         "'/^\([^#\/][^\/]*[a-zA-Z0-9_)]\)(\(.*\))/s;;\1(/*\2*/);'
26                 shift
27                 ;;
28         -A)     # funny Amanda P macro
29                 peel="$peel
30                         "'/^\([^#\/][^\/]*[a-zA-Z0-9_)]\)(\(.*\))/s;;\1 P((\2));'
31                 shift
32                 ;;
33         -b)     # funny Berkeley __P macro
34                 peel="$peel
35                         "'/^\([^#\/][^\/]*[a-zA-Z0-9_)]\)(\(.*\))/s;;\1 __P((\2));'
36                 shift
37                 ;;
38         -s)     # compiler doesn't like `static foo();'
39                 # add code to get rid of the `static'
40                 peel="$peel
41                         "'/^static[     ][^\/]*[a-zA-Z0-9_)](.*)/s;static.;;'
42                 shift
43                 ;;
44         -p)     # private declarations
45                 egrep='^ ==([   ]|$)'
46                 shift
47                 ;;
48         -i)     # wrap in #ifndef, argument is name
49                 ifndef="$2"
50                 shift ; shift
51                 ;;
52         *)      break
53                 ;;
54         esac
55 done
56
57 if test " $ifndef" != " "
58 then
59         echo "#ifndef $ifndef"
60         echo "#define   $ifndef /* never again */"
61 fi
62 echo "/* ========= begin header generated by $0 ========= */"
63 echo '#ifdef __cplusplus'
64 echo 'extern "C" {'
65 echo '#endif'
66 for f
67 do
68         echo
69         echo "/* === $f === */"
70         egrep "$egrep" $f | sed 's/^ ==*[       ]//;s/^ ==*$//' | sed "$peel"
71         echo
72 done
73 echo '#ifdef __cplusplus'
74 echo '}'
75 echo '#endif'
76 echo "/* ========= end header generated by $0 ========= */"
77 if test " $ifndef" != " "
78 then
79         echo "#endif"
80 fi
81 exit 0