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