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