xref: /titanic_41/usr/src/lib/libast/common/comp/conf.sh (revision eaacacc0c33d7b79a8156d9b3e07dbb4354eb2d6)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#           Copyright (c) 1985-2007 AT&T Knowledge Ventures            #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                      by AT&T Knowledge Ventures                      #
8#                                                                      #
9#                A copy of the License is available at                 #
10#            http://www.opensource.org/licenses/cpl1.0.txt             #
11#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                 Glenn Fowler <gsf@research.att.com>                  #
18#                  David Korn <dgk@research.att.com>                   #
19#                   Phong Vo <kpv@research.att.com>                    #
20#                                                                      #
21########################################################################
22: generate getconf and limits info
23#
24# @(#)conf.sh (AT&T Research) 2007-04-02
25#
26# this script generates these files from the table file in the first arg
27# the remaining args are the C compiler name and flags
28#
29#	conflim.h	supplemental limits.h definitions
30#	conftab.h	readonly string table definitions
31#	conftab.c	readonly string table data
32#
33# you may think it should be simpler
34# but you shall be confused anyway
35#
36
37case $-:$BASH_VERSION in
38*x*:[0123456789]*)	: bash set -x is broken :; set +ex ;;
39esac
40
41LC_ALL=C
42export LC_ALL
43
44command=conf
45
46shell=`eval 'x=123&&integer n=\${#x}\${x#1?}&&((n==330/(10)))&&echo ksh' 2>/dev/null`
47
48append=0
49debug=
50extra=0
51keep_call='*'
52keep_name='*'
53trace=
54verbose=0
55while	:
56do	case $1 in
57	-a)	append=1 ;;
58	-c*)	keep_call=${1#-?} ;;
59	-d*)	debug=$1 ;;
60	-l)	extra=1 ;;
61	-n*)	keep_name=${1#-?} ;;
62	-t)	trace=1 ;;
63	-v)	verbose=1 ;;
64	-*)	echo "Usage: $command [-a] [-ccall-pattern] [-dN] [-l] [-nname_pattern] [-t] [-v] conf.tab" >&2; exit 2 ;;
65	*)	break ;;
66	esac
67	shift
68done
69head='#include "FEATURE/standards"
70#include "FEATURE/common"'
71tail='#include "FEATURE/param"'
72generated="/* : : generated by $command from $1 : : */"
73hdr=
74ifs=${IFS-'
75	 '}
76nl='
77'
78sp=' '
79ob='{'
80cb='}'
81sym=[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*
82tmp=conf.tmp
83case $verbose:$debug$trace in
841:?*)	echo "$command: debug=$debug trace=$trace keep_call=$keep_call keep_name=$keep_name" >&2 ;;
85esac
86case $trace in
871)	PS4='+$LINENO+ '; set -x ;;
88esac
89
90case $# in
910)	case $extra in
92	0)	echo "$command: table argument expected" >&2
93		exit 1
94		;;
95	esac
96	tab=/dev/null
97	;;
98*)	tab=$1
99	shift
100	if	test ! -f $tab
101	then	echo "$command: $tab: cannot read" >&2
102		exit 1
103	fi
104	;;
105esac
106case $# in
1070)	cc=cc ;;
108*)	cc=$* ;;
109esac
110
111rm -f $tmp.*
112case $debug in
113'')	trap "code=\$?; rm -f $tmp.*; exit \$code" 0 1 2 ;;
114esac
115
116# determine the intmax_t printf format
117
118cat > $tmp.c <<!
119${head}
120int
121main()
122{
123#if _ast_intmax_long
124	return 1;
125#else
126	return 0;
127#endif
128}
129!
130if	$cc -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe
131then	LL='ll'
132else	LL='l'
133fi
134
135# set up the names and keys
136
137keys=
138standards=
139
140case $append$extra in
14100)	case $verbose in
142	1)	echo "$command: read $tab" >&2 ;;
143	esac
144	exec < $tab
145	while	:
146	do	IFS=""
147		read line
148		eof=$?
149		IFS=$ifs
150		case $eof in
151		0)	;;
152		*)	break ;;
153		esac
154		case $line in
155		""|\#*)	;;
156		*)	set x $line
157			shift; name=$1
158			shift; standard=$1
159			shift; call=$1
160			shift; section=$1
161			shift; flags=$1
162			alternates=
163			define=
164			values=
165			script=
166			headers=
167			while	:
168			do	shift
169				case $# in
170				0)	break ;;
171				esac
172				case $1 in
173				":")	shift
174					eval script='$'script_$1
175					break
176					;;
177				*"{")	case $1 in
178					"sh{")	script="# $name" ;;
179					*)	script= ;;
180					esac
181					shift
182					args="$*"
183					IFS=""
184					while	read line
185					do	case $line in
186						"}")	break ;;
187						esac
188						script=$script$nl$line
189					done
190					IFS=$ifs
191					break
192					;;
193				*.h)	case $shell in
194					ksh)	f=${1%.h} ;;
195					*)	f=`echo $1 | sed 's,\.h$,,'` ;;
196					esac
197					case " $hdr " in
198					*" $f "*)
199						headers=$headers$nl#include$sp'<'$1'>'
200						;;
201					*" -$f- "*)
202						;;
203					*)	if	iffe -n - hdr $f | grep -q _hdr_$f
204						then	hdr="$hdr $f"
205							headers=$headers$nl#include$sp'<'$1'>'
206						else	hdr="$hdr -$f-"
207						fi
208						;;
209					esac
210					;;
211				*)	values=$values$sp$1
212					case $1 in
213					$sym)	echo "$1" >> $tmp.v ;;
214					esac
215					;;
216				esac
217			done
218			case " $standards " in
219			*" $standard "*)
220				;;
221			*)	standards="$standards $standard"
222				;;
223			esac
224			case $name:$flags in
225			*:*S*)	;;
226			VERSION)flags="${flags}S" ;;
227			esac
228			case $name in
229			*VERSION*)key=${standard}${section} ;;
230			*)	  key= ;;
231			esac
232			case $key in
233			''|*_)	key=${key}${name} ;;
234			*)	key=${key}_${name} ;;
235			esac
236			eval sys='$'CONF_call_${key}
237			case $sys in
238			?*)	call=$sys ;;
239			esac
240			case $call in
241			SI)	sys=CS ;;
242			*)	sys=$call ;;
243			esac
244			key=${sys}_${key}
245			keys="$keys$nl$key"
246			eval CONF_name_${key}='$'name
247			eval CONF_standard_${key}='$'standard
248			eval CONF_call_${key}='$'call
249			eval CONF_section_${key}='$'section
250			eval CONF_flags_${key}='$'flags
251			eval CONF_define_${key}='$'define
252			eval CONF_values_${key}='$'values
253			eval CONF_script_${key}='$'script
254			eval CONF_args_${key}='$'args
255			eval CONF_headers_${key}='$'headers
256			eval CONF_keys_${name}=\"'$'CONF_keys_${name} '$'key\"
257			;;
258		esac
259	done
260	;;
261esac
262case $debug in
263-d1)	for key in $keys
264	do	eval name=\"'$'CONF_name_$key\"
265		case $name in
266		?*)	eval standard=\"'$'CONF_standard_$key\"
267			eval call=\"'$'CONF_call_$key\"
268			eval section=\"'$'CONF_section_$key\"
269			eval flags=\"'$'CONF_flags_$key\"
270			eval define=\"'$'CONF_define_$key\"
271			eval values=\"'$'CONF_values_$key\"
272			eval script=\"'$'CONF_script_$key\"
273			eval args=\"'$'CONF_args_$key\"
274			eval headers=\"'$'CONF_headers_$key\"
275			printf "%29s %35s %8s %2s %1d %5s %s$nl" "$name" "$key" "$standard" "$call" "$section" "$flags" "$define${values:+$sp=$values}${headers:+$sp$headers$nl}${script:+$sp$ob$script$nl$cb}"
276			;;
277		esac
278	done
279	exit
280	;;
281esac
282
283systeminfo='
284#if !defined(SYS_NMLEN)
285#define SYS_NMLEN	9
286#endif
287#include <sys/systeminfo.h>'
288echo "$systeminfo" > $tmp.c
289$cc -E $tmp.c >/dev/null 2>&1 || systeminfo=
290
291# check for native getconf(1)
292
293CONF_getconf=
294CONF_getconf_a=
295for d in /usr/bin /bin /usr/sbin /sbin
296do	if	test -x $d/getconf
297	then	case `$d/getconf --?-version 2>&1` in
298		*"AT&T"*"Research"*)
299			: presumably an implementation also configured from conf.tab
300			;;
301		*)	CONF_getconf=$d/getconf
302			if	$CONF_getconf -a >/dev/null 2>&1
303			then	CONF_getconf_a=-a
304			fi
305			;;
306		esac
307		break
308	fi
309done
310export CONF_getconf CONF_getconf_a
311
312case $verbose in
3131)	echo "$command: check ${CONF_getconf:+$CONF_getconf(1),}confstr(2),pathconf(2),sysconf(2),sysinfo(2) configuration names" >&2 ;;
314esac
315{
316	echo "#include <unistd.h>$systeminfo
317int i = 0;" > $tmp.c
318	$cc -E $tmp.c
319} |
320sed \
321	-e '/^#[^0123456789]*1[ 	]*".*".*/!d' \
322	-e 's/^#[^0123456789]*1[ 	]*"\(.*\)".*/\1/' |
323sort -u > $tmp.f
324{
325sed \
326	-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]/ /g' \
327	-e 's/[ 	][ 	]*/\n/g' \
328	`cat $tmp.f` 2>/dev/null |
329	egrep '^(SI|_(CS|PC|SC|SI))_.'
330	case $CONF_getconf_a in
331	?*)	$CONF_getconf $CONF_getconf_a | sed 's,[=:    ].*,,'
332		;;
333	*)	case $CONF_getconf in
334		?*)	for v in `strings $CONF_getconf | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*$'`
335			do	if	$CONF_getconf $v >/dev/null
336				then	echo $v
337				fi
338			done
339			;;
340		esac
341		;;
342	esac 2>/dev/null
343} |
344egrep -v '^_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+_(COUNT|LAST|N|STR)$' |
345sort -u > $tmp.g
346{
347	grep '^_' $tmp.g
348	grep '^[^_]' $tmp.g
349} > $tmp.t
350mv $tmp.t $tmp.g
351case $debug in
352-d2)	exit ;;
353esac
354
355HOST=`package | sed -e 's,[0123456789.].*,,' | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
356case $HOST in
357'')	HOST=SYSTEM ;;
358esac
359
360exec < $tmp.g
361
362while	read line
363do	flags=F
364	section=
365	underscore=
366	define=$line
367	IFS=_
368	set $line
369	IFS=$ifs
370	case $1 in
371	'')	case $# in
372		0)	continue ;;
373		esac
374		shift
375		;;
376	esac
377	case $1 in
378	CS|PC|SC|SI)
379		call=$1
380		shift
381		standard=$1
382		;;
383	*)	flags=${flags}R
384		standard=$1
385		while	:
386		do	case $# in
387			0)	continue 2 ;;
388			esac
389			shift
390			case $1 in
391			CS|PC|SC|SI)
392				call=$1
393				shift
394				break
395				;;
396			O|o|OLD|old)
397				continue 2
398				;;
399			esac
400			standard=${standard}_$1
401		done
402		;;
403	esac
404	case $1 in
405	SET)	continue ;;
406	esac
407	case $standard in
408	_*)	standard=`echo $standard | sed 's,^_*,,'` ;;
409	esac
410	case " $standards " in
411	*" $standard "*)
412		;;
413	*)	case $standard in
414		[0123456789]*)
415			section=$standard
416			standard=POSIX
417			;;
418		*[0123456789])
419			eval `echo $standard | sed 's,\(.*\)\([0123456789]*\),standard=\1 section=\2,'`
420			;;
421		esac
422		;;
423	esac
424	case $flags in
425	*R*)	case $call in
426		SI)	;;
427		*)	underscore=U ;;
428		esac
429		;;
430	*)	case " $standards " in
431		" C ")	shift
432			;;
433		*" $standard "*)
434			case $call in
435			SI)	;;
436			*)	flags=${flags}P
437				underscore=U
438				;;
439			esac
440			shift
441			;;
442		*)	standard=
443			;;
444		esac
445		;;
446	esac
447	case $standard in
448	'')	standard=$HOST
449		case $call in
450		SI)	;;
451		*)	underscore=U ;;
452		esac
453		case $call in
454		CS|PC|SC)
455			case $define in
456			_${call}_*)
457				standard=POSIX
458				;;
459			esac
460			;;
461		esac
462		;;
463	esac
464	part=$section
465	case $section in
466	'')	section=1
467		case $standard in
468		POSIX|XOPEN) part=$section ;;
469		esac
470		;;
471	esac
472	name=
473	while	:
474	do	case $# in
475		0)	break ;;
476		esac
477		case $name in
478		'')	name=$1 ;;
479		*)	name=${name}_$1 ;;
480		esac
481		shift
482	done
483	case $name in
484	'')	;;
485	CONFORMANCE|FS_3D|HOSTTYPE|LIBPATH|LIBPREFIX|LIBSUFFIX|PATH_ATTRIBUTES|PATH_RESOLVE|UNIVERSE)
486		;;
487	*)	values=
488		script=
489		args=
490		headers=
491		case $name in
492		V[123456789]_*|V[123456789][0123456789]_*)	underscore=VW ;;
493		esac
494		case $call in
495		CS|SI)	key=CS ;;
496		*)	key=$call ;;
497		esac
498		case $name in
499		*VERSION*)key=${key}_${standard}${part} ;;
500		esac
501		key=${key}_${name}
502		eval x='$'CONF_keys_$name
503		case $x in
504		'')	eval x='$'CONF_name_$key
505			case $x in
506			'')	case $call in
507				SI)	flags=O$flags ;;
508				esac
509				case $underscore in
510				?*)	flags=${flags}${underscore} ;;
511				esac
512				old=QQ
513				case $name in
514				*VERSION*)old=${old}_${standard}${part} ;;
515				esac
516				old=${old}_${name}
517				eval x='$'CONF_name_$old
518				case $x in
519				?*)	eval CONF_name_$old=
520					eval flags='$'flags'$'CONF_flags_$old
521					eval values='$'CONF_values_$old
522					eval script='$'CONF_script_$old
523					eval args='$'CONF_args_$old
524					eval headers='$'CONF_headers_$old
525					;;
526				esac
527				keys="$keys$nl$key"
528				eval CONF_name_${key}='$'name
529				eval CONF_standard_${key}='$'standard
530				eval CONF_call_${key}='$'call
531				eval CONF_section_${key}='$'section
532				eval CONF_flags_${key}=d'$'flags
533				eval CONF_define_${key}='$'define
534				eval CONF_values_${key}='$'values
535				eval CONF_script_${key}='$'script
536				eval CONF_args_${key}='$'args
537				eval CONF_headers_${key}='$'headers
538				;;
539			*)	eval x='$'CONF_define_$key
540				case $x in
541				?*)	case $call in
542					CS)	eval x='$'CONF_call_$key
543						case $x in
544						SI)	;;
545						*)	define= ;;
546						esac
547						;;
548					*)	define=
549						;;
550					esac
551					;;
552				esac
553				case $define in
554				?*)	eval CONF_define_${key}='$'define
555					eval CONF_call_${key}='$'call
556					eval x='$'CONF_call_${key}
557					case $x in
558					QQ)	;;
559					*)	case $flags in
560						*R*)	flags=R ;;
561						*)	flags= ;;
562						esac
563						;;
564					esac
565					case $call in
566					SI)	flags=O$flags ;;
567					esac
568					eval CONF_flags_${key}=d'$'flags'$'CONF_flags_${key}
569					;;
570				esac
571				old=QQ
572				case $name in
573				*VERSION*)old=${old}_${standard}${part} ;;
574				esac
575				old=${old}_${name}
576				eval CONF_name_$old=
577			esac
578			;;
579		*)	for key in $x
580			do	eval x='$'CONF_call_${key}
581				case $x in
582				XX)	eval CONF_call_${key}=QQ
583					eval CONF_flags_${key}=S'$'CONF_flags_${key}
584					;;
585				esac
586			done
587		esac
588		;;
589	esac
590done
591
592# sort keys by name
593
594keys=`for key in $keys
595do	eval echo '$'CONF_name_$key '$'key
596done | sort -u | sed 's,.* ,,'`
597case $debug in
598-d3)	for key in $keys
599	do	eval name=\"'$'CONF_name_$key\"
600		case $name in
601		?*)	eval standard=\"'$'CONF_standard_$key\"
602			eval call=\"'$'CONF_call_$key\"
603			eval section=\"'$'CONF_section_$key\"
604			eval flags=\"'$'CONF_flags_$key\"
605			eval define=\"'$'CONF_define_$key\"
606			eval values=\"'$'CONF_values_$key\"
607			eval script=\"'$'CONF_script_$key\"
608			eval headers=\"'$'CONF_headers_$key\"
609			printf "%29s %35s %8s %2s %1d %5s %s$nl" "$name" "$key" "$standard" "$call" "$section" "$flags" "$define${values:+$sp=$values}${headers:+$sp$headers$nl}${script:+$sp$ob$script$nl$cb}"
610			;;
611		esac
612	done
613	exit
614	;;
615esac
616
617# mark the dups CONF_PREFIXED
618
619prev_key=
620prev_name=
621for key in $keys
622do	eval name=\"'$'CONF_name_$key\"
623	case $name in
624	'')	continue
625		;;
626	$prev_name)
627		eval p='$'CONF_flags_${prev_key}
628		eval c='$'CONF_flags_${key}
629		case $p:$c in
630		*L*:*L*);;
631		*L*:*)	c=L${c} ;;
632		*:*L*)	p=L${p} ;;
633		*)	p=P$p c=P$c ;;
634		esac
635		eval CONF_flags_${prev_key}=$p
636		eval CONF_flags_${key}=$c
637		;;
638	esac
639	prev_name=$name
640	prev_key=$key
641done
642
643# collect all the macros/enums
644
645for key in $keys
646do	eval name=\"'$'CONF_name_$key\"
647	case $name in
648	'')		continue ;;
649	$keep_name)	;;
650	*)		continue ;;
651	esac
652	eval call=\"'$'CONF_call_$key\"
653	case $call in
654	$keep_call)	;;
655	*)		continue ;;
656	esac
657	eval standard=\"'$'CONF_standard_$key\"
658	eval section=\"'$'CONF_section_$key\"
659	eval flags=\"'$'CONF_flags_$key\"
660	eval define=\"'$'CONF_define_$key\"
661	eval values=\"'$'CONF_values_$key\"
662	eval script=\"'$'CONF_script_$key\"
663	eval args=\"'$'CONF_args_$key\"
664	eval headers=\"'$'CONF_headers_$key\"
665	conf_name=$name
666	case $call in
667	QQ)	call=XX
668		for c in SC PC CS
669		do	case $flags in
670			*S*)	case $section in
671				1)	eval x='$'CONF_call_${c}_${standard}_${name} ;;
672				*)	eval x='$'CONF_call_${c}_${standard}${section}_${name} ;;
673				esac
674				;;
675			*)	eval x='$'CONF_call_${c}_${name}
676				;;
677			esac
678			case $x in
679			?*)	call=$x
680				break
681				;;
682			esac
683		done
684		case $call in
685		XX)	for c in SC PC CS
686			do	echo "_${c}_${name}"
687				case $flags in
688				*S*)	case $section in
689					1)	echo "_${c}_${standard}_${name}" ;;
690					*)	echo "_${c}_${standard}${section}_${name}" ;;
691					esac
692					;;
693				esac
694			done
695			;;
696		esac
697		;;
698	esac
699	case $call in
700	CS|PC|SC|SI|XX)
701		;;
702	*)	echo "$command: $name: $call: invalid call" >&2
703		exit 1
704		;;
705	esac
706	case $flags in
707	*[ABEGHIJQTYZabcefghijklmnopqrstuvwxyz_123456789]*)
708		echo "$command: $name: $flags: invalid flag(s)" >&2
709		exit 1
710		;;
711	esac
712	case $section in
713	[01])	;;
714	*)	case $flags in
715		*N*)	;;
716		*)	name=${section}_${name} ;;
717		esac
718		standard=${standard}${section}
719		;;
720	esac
721	case $call in
722	XX)	;;
723	*)	case $flags in
724		*d*)	conf_op=${define} ;;
725		*O*)	conf_op=${call}_${name} ;;
726		*R*)	conf_op=_${standard}_${call}_${name} ;;
727		*S*)	conf_op=_${call}_${standard}_${name} ;;
728		*)	conf_op=_${call}_${name} ;;
729		esac
730		echo "${conf_op}"
731		;;
732	esac
733	case $standard:$flags in
734	C:*)	;;
735	*:*L*)	echo "${conf_name}"
736		echo "_${standard}_${conf_name}"
737		;;
738	*:*M*)	case $section in
739		1)	echo "_${standard}_${conf_name}" ;;
740		*)	echo "_${standard}${section}_${conf_name}" ;;
741		esac
742		;;
743	esac
744done > $tmp.q
745sort -u < $tmp.q > $tmp.t
746mv $tmp.t $tmp.q
747sort -u < $tmp.v > $tmp.t
748mv $tmp.t $tmp.v
749case $debug in
750-d4)	exit ;;
751esac
752
753# test all the macros in a few batches (some compilers have an error limit)
754
755defined() # list-file
756{
757	: > $tmp.p
758	while	:
759	do	{
760			cat <<!
761${head}
762#include <sys/types.h>
763#include <limits.h>
764#include <unistd.h>$systeminfo$headers
765${tail}
766#undef conf
767unsigned int conf[] = {
768!
769			sed 's/$/,/' $1
770			echo "};"
771		} > $tmp.c
772		[[ -f $tmp.1.c ]] || cp $tmp.c $tmp.1.c
773		if	$cc -c $tmp.c > $tmp.e 2>&1
774		then	break
775		fi
776		[[ -f $tmp.1.e ]] || cp $tmp.e $tmp.1.e
777		snl='\
778'
779		sed "s/[^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*/${snl}/g" $tmp.e |
780		grep '^[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz][_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*$' |
781		sort -u > $tmp.n
782		cmp -s $tmp.n $tmp.p && break
783		fgrep -x -v -f $tmp.n $1 > $tmp.y
784		mv $tmp.y $1
785		mv $tmp.n $tmp.p
786	done
787	{
788		cat <<!
789${head}
790#include <sys/types.h>
791#include <limits.h>
792#include <unistd.h>$systeminfo$headers
793${tail}
794#undef conf
795!
796		sed 's/.*/conf "&" = &/' $1
797	} > $tmp.c
798	$cc -E $tmp.c 2>/dev/null |
799	sed -e '/conf[ 	]*".*"[ 	]*=[ 	]*/!d' -e '/[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][ 	]*(/!d' -e 's/.*"\(.*\)".*/\1/' > $tmp.n
800	if	test -s $tmp.n
801	then	fgrep -x -v -f $tmp.n $1 > $tmp.y
802		mv $tmp.y $1
803	fi
804}
805
806case $verbose in
8071)	echo "$command: check macros/enums as static initializers" >&2 ;;
808esac
809defined $tmp.q
810defined $tmp.v
811case $debug in
812-d5)	exit ;;
813esac
814
815# mark the constant macros/enums
816
817exec < $tmp.q
818while	read line
819do	eval CONF_const_${line}=1
820done
821exec < $tmp.v
822while	read line
823do	eval CONF_const_${line}=1
824done
825
826# mark the string literal values
827
828{
829	cat <<!
830${head}
831#include <sys/types.h>
832#include <limits.h>
833#include <unistd.h>$systeminfo$headers
834${tail}
835#undef conf
836!
837	sed 's/.*/conf "&" = &/' $tmp.q
838} > $tmp.c
839$cc -E $tmp.c 2>/dev/null |
840sed -e '/conf[ 	]*".*"[ 	]*=[ 	]*"/!d' -e 's/.*"\([^"]*\)".*/\1/' > $tmp.e
841exec < $tmp.e
842while	read line
843do	eval CONF_string_${line}=1
844done
845
846# walk through the table
847
848case $shell in
849ksh)	integer len name_max ;;
850esac
851name_max=1
852export tmp name standard call cc
853
854for key in $keys
855do	eval name=\"'$'CONF_name_$key\"
856	case $name in
857	'')		continue ;;
858	$keep_name)	;;
859	*)		continue ;;
860	esac
861	eval call=\"'$'CONF_call_$key\"
862	case $call in
863	$keep_call)	;;
864	*)		continue ;;
865	esac
866	eval standard=\"'$'CONF_standard_$key\"
867	eval section=\"'$'CONF_section_$key\"
868	eval flags=\"'$'CONF_flags_$key\"
869	eval define=\"'$'CONF_define_$key\"
870	eval values=\"'$'CONF_values_$key\"
871	eval script=\"'$'CONF_script_$key\"
872	eval args=\"'$'CONF_args_$key\"
873	eval headers=\"'$'CONF_headers_$key\"
874	conf_name=$name
875	case $call in
876	QQ)	call=XX
877		for c in SC PC CS
878		do	case $flags in
879			*S*)	case $section in
880				1)	eval x='$'CONF_call_${c}_${standard}_${name} ;;
881				*)	eval x='$'CONF_call_${c}_${standard}${section}_${name} ;;
882				esac
883				;;
884			*)	eval x='$'CONF_call_${c}_${name}
885				;;
886			esac
887			case $x in
888			?*)	call=$x
889				break
890				;;
891			esac
892		done
893		case $call in
894		XX)	for c in SC PC CS
895			do	case $flags in
896				*S*)	case $section in
897					1)	eval x='$'CONF_const__${c}_${standard}_${name} ;;
898					*)	eval x='$'CONF_const__${c}_${standard}${section}_${name} ;;
899					esac
900					;;
901				*)	eval x='$'CONF_const__${c}_${name}
902					;;
903				esac
904				case $x in
905				1)	call=$c
906					break
907					;;
908				esac
909			done
910			;;
911		esac
912		case $call in
913		XX)	case $standard in
914			C)	standard=POSIX ;;
915			esac
916			case $flags in
917			*L*)	flags=lFU ;;
918			*)	flags=FU ;;
919			esac
920			;;
921		esac
922		;;
923	esac
924	case " $standards " in
925	*" $standard "*)
926		;;
927	*)	standards="$standards $standard"
928		;;
929	esac
930	conf_standard=CONF_${standard}
931	case $call in
932	CS)	conf_call=CONF_confstr
933		;;
934	PC)	conf_call=CONF_pathconf
935		;;
936	SC)	conf_call=CONF_sysconf
937		;;
938	SI)	conf_call=CONF_sysinfo
939		;;
940	XX)	conf_call=CONF_nop
941		;;
942	esac
943	conf_op=-1
944	for s in _${call}_${standard}${section}_${name} _${call}_${standard}_${name} _${call}_${section}_${name} _${call}_${name} ${call}_${name}
945	do	eval x='$'CONF_const_${s}
946		case $x in
947		1)	conf_op=${s}
948			break
949			;;
950		esac
951	done
952	conf_section=$section
953	conf_flags=0
954	case $flags in
955	*C*)	conf_flags="${conf_flags}|CONF_DEFER_CALL" ;;
956	esac
957	case $flags in
958	*D*)	conf_flags="${conf_flags}|CONF_DEFER_MM" ;;
959	esac
960	case $flags in
961	*F*)	conf_flags="${conf_flags}|CONF_FEATURE" ;;
962	esac
963	case $flags in
964	*L*)	conf_flags="${conf_flags}|CONF_LIMIT" ;;
965	esac
966	case $flags in
967	*M*)	conf_flags="${conf_flags}|CONF_MINMAX" ;;
968	esac
969	case $flags in
970	*N*)	conf_flags="${conf_flags}|CONF_NOSECTION" ;;
971	esac
972	case $flags in
973	*P*)	conf_flags="${conf_flags}|CONF_PREFIXED" ;;
974	esac
975	case $flags in
976	*S*)	conf_flags="${conf_flags}|CONF_STANDARD" ;;
977	esac
978	case $flags in
979	*U*)	conf_flags="${conf_flags}|CONF_UNDERSCORE" ;;
980	esac
981	case $flags in
982	*V*)	conf_flags="${conf_flags}|CONF_NOUNDERSCORE" ;;
983	esac
984	case $flags in
985	*W*)	conf_flags="${conf_flags}|CONF_PREFIX_ONLY" ;;
986	esac
987	case $shell in
988	ksh)	conf_flags=${conf_flags#0?} ;;
989	esac
990	case $debug in
991	?*)	case $standard in
992		????)	sep=" " ;;
993		???)	sep="  " ;;
994		??)	sep="   " ;;
995		?)	sep="    " ;;
996		*)	sep="" ;;
997		esac
998		echo "$command: test: $sep$standard $call $name" >&2
999		;;
1000	esac
1001	case $call in
1002	CS|SI)	conf_flags="${conf_flags}|CONF_STRING"
1003		string=1
1004		;;
1005	*)	eval string='$'CONF_string_${key}
1006		;;
1007	esac
1008	conf_limit=0
1009	case $flags in
1010	*[Ll]*)	d=
1011		case ${conf_name} in
1012		LONG_MAX|SSIZE_MAX)
1013			x=
1014			;;
1015		*)	eval x='$'CONF_const_${conf_name}
1016			;;
1017		esac
1018		case $x in
1019		'')	for s in ${values}
1020			do	case $s in
1021				$sym)	eval x='$'CONF_const_${s}
1022					case $x in
1023					1)	eval a='$'CONF_const_${standard}_${s}
1024						case $a in
1025						$x)	x= ;;
1026						*)	x=$s ;;
1027						esac
1028						break
1029						;;
1030					esac
1031					;;
1032				[0123456789]*|[-+][0123456789]*)
1033					d=$s
1034					break
1035					;;
1036				esac
1037			done
1038			case ${x:+1}:$flags:$conf_op in
1039			:*:-1|:*X*:*)
1040				case $verbose in
1041				1)	echo "$command: probe for ${conf_name} <limits.h> value" >&2 ;;
1042				esac
1043				x=
1044				case $CONF_getconf in
1045				?*)	if	$CONF_getconf $conf_name > $tmp.x 2>/dev/null
1046					then	x=`cat $tmp.x`
1047						case $x in
1048						undefined)	x= ;;
1049						esac
1050					fi
1051					;;
1052				esac
1053				case ${x:+1} in
1054				'')	case $script in
1055					'#'*)	echo "$script" > $tmp.sh
1056						chmod +x $tmp.sh
1057						x=`./$tmp.sh 2>/dev/null`
1058						;;
1059					'')	case $conf_name in
1060						SIZE_*|U*|*_MAX)
1061							f="%${LL}u"
1062							t="unsigned _ast_intmax_t"
1063							;;
1064						*)	f="%${LL}d"
1065							t="_ast_intmax_t"
1066							;;
1067						esac
1068						cat > $tmp.c <<!
1069${head}
1070#include <stdio.h>
1071#include <sys/types.h>
1072#include <limits.h>
1073#include <unistd.h>$systeminfo$headers
1074${tail}
1075int
1076main()
1077{
1078	printf("$f\n", ($t)$conf_name);
1079	return 0;
1080}
1081!
1082						;;
1083					*)	cat > $tmp.c <<!
1084${head}
1085#include <sys/types.h>
1086#include <limits.h>
1087#include <unistd.h>$systeminfo$headers
1088${tail}
1089${script}
1090!
1091						;;
1092					esac
1093					case $args in
1094					'')	set "" ;;
1095					*)	eval set '""' '"'$args'"'; shift ;;
1096					esac
1097					for a
1098					do	case $script in
1099						'#'*)	./$tmp.sh $a > $tmp.x 2>/dev/null
1100							x=$?
1101							;;
1102						*)	$cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null
1103							x=$?
1104							;;
1105						esac
1106						case $x in
1107						0)	x=`cat $tmp.x`
1108							case $x in
1109							"-")	x=$a ;;
1110							esac
1111							break
1112							;;
1113						*)	x=
1114							;;
1115						esac
1116					done
1117					;;
1118				esac
1119				case $x in
1120				'')	x=$d ;;
1121				esac
1122				;;
1123			esac
1124			case ${x:+1}:$flags:$conf_op in
1125			1:*:-1|1:*X*:*)
1126				conf_limit=$x
1127				case $flags in
1128				*L*)	;;
1129				*)	conf_flags="${conf_flags}|CONF_LIMIT" ;;
1130				esac
1131				conf_flags="${conf_flags}|CONF_LIMIT_DEF"
1132				case $string:$x in
1133				1:*)	cat >> $tmp.l <<!
1134printf("#ifndef ${conf_name}\n");
1135printf("#define ${conf_name} \"${x}\"\n");
1136printf("#endif\n");
1137!
1138					;;
1139				*:U*)	cat >> $tmp.l <<!
1140printf("#ifndef ${conf_name}\n");
1141printf("#ifndef ${x}\n");
1142printf("#define ${x} %lu\n", ${x});
1143printf("#endif\n");
1144printf("#define ${conf_name} ${x}\n");
1145printf("#endif\n");
1146!
1147					;;
1148				*:$sym)	cat >> $tmp.l <<!
1149printf("#ifndef ${conf_name}\n");
1150printf("#ifndef ${x}\n");
1151printf("#define ${x} %ld\n", ${x});
1152printf("#endif\n");
1153printf("#define ${conf_name} ${x}\n");
1154printf("#endif\n");
1155!
1156					;;
1157				*)	cat >> $tmp.l <<!
1158printf("#ifndef ${conf_name}\n");
1159printf("#define ${conf_name} ${x}\n");
1160printf("#endif\n");
1161!
1162					;;
1163				esac
1164				;;
1165			esac
1166			;;
1167		esac
1168		;;
1169	esac
1170	case $section in
1171	[01])	;;
1172	*)	case $flags in
1173		*N*)	;;
1174		*)	name=${section}_${name} ;;
1175		esac
1176		standard=${standard}${section}
1177		;;
1178	esac
1179	conf_minmax=0
1180	case $call:$standard:$flags in
1181	*:C:*M*)for s in _${standard}_${conf_name} ${values}
1182		do	case $s in
1183			$sym)	;;
1184			*)	conf_minmax=$s
1185				conf_flags="${conf_flags}|CONF_MINMAX_DEF"
1186				break
1187				;;
1188			esac
1189		done
1190		;;
1191	*:C:*)	;;
1192	[CPSX][CSX]:*:*[FM]*)
1193		x=
1194		for s in _${standard}_${conf_name} ${values}
1195		do	case $s in
1196			$sym)	eval x='$'CONF_const_${s} ;;
1197			*)	x=1 ;;
1198			esac
1199			case $x in
1200			1)	conf_minmax=$s
1201				case $flags in
1202				*M*)	conf_flags="${conf_flags}|CONF_MINMAX_DEF" ;;
1203				esac
1204				break
1205				;;
1206			esac
1207		done
1208		case ${x:+1}:${script:+1} in
1209		:1)	case $verbose in
1210			1)	echo "$command: probe for _${standard}_${conf_name} minmax value" >&2 ;;
1211			esac
1212			case $CONF_getconf in
1213			?*)	if	$CONF_getconf _${standard}_${conf_name} > $tmp.x 2>/dev/null
1214				then	x=`cat $tmp.x`
1215					case $x in
1216					undefined)	x= ;;
1217					esac
1218				fi
1219				;;
1220			esac
1221			case $x in
1222			'')	case $script in
1223				'#'*)	echo "$script" > $tmp.sh
1224					chmod +x $tmp.sh
1225					x=`./$tmp.sh 2>/dev/null`
1226					;;
1227				*)	cat > $tmp.c <<!
1228${head}
1229#include <sys/types.h>
1230#include <limits.h>
1231#include <unistd.h>$systeminfo$headers
1232${tail}
1233${script}
1234!
1235					;;
1236				esac
1237				case $args in
1238				'')	set "" ;;
1239				*)	eval set '""' "$args"; shift ;;
1240				esac
1241				for a
1242				do	case $script in
1243					'#'*)	./$tmp.sh $a > $tmp.x 2>/dev/null
1244						x=$?
1245						;;
1246					*)	$cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null
1247						x=$?
1248						;;
1249					esac
1250					case $x in
1251					0)	x=`cat $tmp.x`
1252						case $x in
1253						"-")	x=$a ;;
1254						esac
1255						break
1256						;;
1257					*)	x=
1258						;;
1259					esac
1260				done
1261				;;
1262			esac
1263			case $x in
1264			?*)	conf_minmax=$x
1265				case $flags in
1266				*M*)	conf_flags="${conf_flags}|CONF_MINMAX_DEF" ;;
1267				esac
1268				;;
1269			esac
1270			;;
1271		esac
1272		;;
1273	esac
1274	case $string in
1275	1)	conf_limit="{ 0, $conf_limit }" conf_minmax="{ 0, $conf_minmax }"
1276		;;
1277	*)	case $conf_limit in
1278		0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
1279			;;
1280		*[!0123456789abcdefABCDEF]*)
1281			conf_limit=0
1282			;;
1283		*[!0123456789]*)
1284			conf_limit=0x$conf_limit
1285			;;
1286		esac
1287		case $conf_minmax in
1288		0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
1289			;;
1290		*[!0123456789abcdefABCDEF]*)
1291			conf_minmax=0
1292			;;
1293		*[!0123456789]*)
1294			conf_minmax=0x$conf_minmax
1295			;;
1296		esac
1297		conf_limit="{ $conf_limit, 0 }" conf_minmax="{ $conf_minmax, 0 }"
1298		;;
1299	esac
1300	echo "{ \"$conf_name\", $conf_limit, $conf_minmax, $conf_flags, $conf_standard, $conf_section, $conf_call, $conf_op },"
1301	case $shell in
1302	ksh)	len=${#conf_name}
1303		if	((len>=name_max))
1304		then	((name_max=len+1))
1305		fi
1306		;;
1307	*)	len=`echo ${conf_name} | wc -c`
1308		if	expr \( $len - 1 \) \>= ${name_max} >/dev/null
1309		then	name_max=$len
1310		fi
1311		;;
1312	esac
1313done > $tmp.t
1314case $debug in
1315-d6)	exit ;;
1316esac
1317
1318# conf string table
1319
1320base=conftab
1321case $verbose in
13221)	echo "$command: generate ${base}.h string table header" >&2 ;;
1323esac
1324case $shell in
1325ksh)	((name_max=name_max+3)); ((name_max=name_max/4*4)) ;; # bsd /bin/sh !
1326*)	name_max=`expr \( $name_max + 3 \) / 4 \* 4` ;;
1327esac
1328{
1329cat <<!
1330#pragma prototyped
1331
1332#ifndef _CONFTAB_H
1333#define _CONFTAB_H
1334$systeminfo
1335
1336${generated}
1337
1338#define conf		_ast_conf_data
1339#define conf_elements	_ast_conf_ndata
1340
1341#define prefix		_ast_conf_prefix
1342#define prefix_elements	_ast_conf_nprefix
1343
1344#define CONF_nop	0
1345#define	CONF_confstr	1
1346#define CONF_pathconf	2
1347#define CONF_sysconf	3
1348#define CONF_sysinfo	4
1349
1350!
1351index=0
1352for standard in $standards
1353do	echo "#define CONF_${standard}	${index}"
1354	case $shell in
1355	ksh)	((index=index+1)) ;;
1356	*)	index=`expr ${index} + 1` ;;
1357	esac
1358done
1359echo "#define CONF_call	${index}"
1360case $CONF_getconf in
1361?*)	echo
1362	echo "#define _pth_getconf	\"$CONF_getconf\""
1363	case $CONF_getconf_a in
1364	?*)	echo "#define _pth_getconf_a	\"$CONF_getconf_a\"" ;;
1365	esac
1366	;;
1367esac
1368cat <<!
1369
1370#define CONF_DEFER_CALL		0x0001
1371#define CONF_DEFER_MM		0x0002
1372#define CONF_FEATURE		0x0004
1373#define CONF_LIMIT		0x0008
1374#define CONF_LIMIT_DEF		0x0010
1375#define CONF_MINMAX		0x0020
1376#define CONF_MINMAX_DEF		0x0040
1377#define CONF_NOSECTION		0x0080
1378#define CONF_NOUNDERSCORE	0x0100
1379#define CONF_PREFIX_ONLY	0x0200
1380#define CONF_PREFIXED		0x0400
1381#define CONF_STANDARD		0x0800
1382#define CONF_STRING		0x1000
1383#define CONF_UNDERSCORE		0x2000
1384#define CONF_USER		0x4000
1385
1386struct Conf_s; typedef struct Conf_s Conf_t;
1387
1388typedef int (*Conf_f)(Conf_t*, intmax_t*, char**);
1389
1390typedef struct Value_s
1391{
1392	intmax_t	number;
1393	const char*	string;
1394} Value_t;
1395
1396struct Conf_s
1397{
1398	const char	name[${name_max}];
1399	Value_t		limit;
1400	Value_t		minmax;
1401	short		flags;
1402	short		standard;
1403	short		section;
1404	short		call;
1405	short		op;
1406};
1407
1408typedef struct Prefix_s
1409{
1410	const char	name[16];
1411	short		length;
1412	short		standard;
1413	short		call;
1414} Prefix_t;
1415
1416extern const Conf_t	conf[];
1417extern int		conf_elements;
1418
1419extern const Prefix_t	prefix[];
1420extern int		prefix_elements;
1421
1422#endif
1423!
1424} > $tmp.1
1425proto < $tmp.1 > $tmp.2
1426case $debug in
1427-d7)	echo $command: $tmp.2 ${base}.h ;;
1428*)	cmp -s $tmp.2 ${base}.h 2>/dev/null || mv $tmp.2 ${base}.h ;;
1429esac
1430
1431case $verbose in
14321)	echo "$command: generate ${base}.c string table" >&2 ;;
1433esac
1434{
1435cat <<!
1436#pragma prototyped
1437${head}
1438#include <sys/types.h>
1439#include <limits.h>
1440#include <unistd.h>$systeminfo$headers
1441${tail}
1442#include "${base}.h"
1443
1444${generated}
1445
1446/*
1447 * prefix strings -- the first few are indexed by Conf_t.standard
1448 */
1449
1450const Prefix_t prefix[] =
1451{
1452!
1453for standard in $standards
1454do	case $shell in
1455	ksh)	len=${#standard} ;;
1456	*)	len=`echo ${standard} | wc -c`; len=`expr $len - 1` ;;
1457	esac
1458	echo "	\"${standard}\",	${len},	CONF_${standard},	-1,"
1459done
1460cat <<!
1461	"XX",		2,	CONF_POSIX,	CONF_nop,
1462	"CS",		2,	CONF_POSIX,	CONF_confstr,
1463	"PC",		2,	CONF_POSIX,	CONF_pathconf,
1464	"SC",		2,	CONF_POSIX,	CONF_sysconf,
1465	"SI",		2,	CONF_SVID,	CONF_sysinfo,
1466};
1467
1468int	prefix_elements = (int)sizeof(prefix) / (int)sizeof(prefix[0]);
1469
1470/*
1471 * conf strings sorted in ascending order
1472 */
1473
1474const Conf_t conf[] =
1475{
1476!
1477cat $tmp.t
1478cat <<!
1479};
1480
1481int	conf_elements = (int)sizeof(conf) / (int)sizeof(conf[0]);
1482!
1483} > $tmp.3
1484proto < $tmp.3 > $tmp.4
1485case $debug in
1486-d7)	echo $command: $tmp.4 ${base}.c ;;
1487*)	cmp -s $tmp.4 ${base}.c 2>/dev/null || mv $tmp.4 ${base}.c ;;
1488esac
1489
1490# limits.h generation code
1491
1492base=conflim
1493case $verbose in
14941)	echo "$command: generate ${base}.h supplemental <limits.h> values" >&2 ;;
1495esac
1496{
1497cat <<!
1498${generated}
1499
1500/*
1501 * supplemental <limits.h> values
1502 */
1503
1504!
1505test -f $tmp.l && cat $tmp.l
1506} > $tmp.5
1507case $debug in
1508-d7)	echo $command: $tmp.5 ${base}.h ;;
1509*)	cmp -s $tmp.5 ${base}.h 2>/dev/null || mv $tmp.5 ${base}.h ;;
1510esac
1511exit 0
1512