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