1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1985-2011 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) 2010-09-14 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 <stdio.h> 1109#include <sys/types.h> 1110#include <limits.h> 1111#include <unistd.h>$systeminfo$headers 1112${tail} 1113${script} 1114! 1115 ;; 1116 esac 1117 case $args in 1118 '') set "" ;; 1119 *) eval set '""' '"'$args'"'; shift ;; 1120 esac 1121 for a 1122 do case $script in 1123 '#'*) ./$tmp.sh $a > $tmp.x 2>/dev/null 1124 x=$? 1125 ;; 1126 *) $cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null 1127 x=$? 1128 ;; 1129 esac 1130 case $x in 1131 0) x=`cat $tmp.x` 1132 case $x in 1133 "-") x=$a ;; 1134 esac 1135 break 1136 ;; 1137 *) x= 1138 ;; 1139 esac 1140 done 1141 ;; 1142 esac 1143 case $x in 1144 '') x=$d ;; 1145 esac 1146 ;; 1147 esac 1148 case ${x:+1}:$flags:$conf_op in 1149 1:*:-1|1:*X*:*) 1150 conf_limit=$x 1151 case $flags in 1152 *L*) ;; 1153 *) conf_flags="${conf_flags}|CONF_LIMIT" ;; 1154 esac 1155 conf_flags="${conf_flags}|CONF_LIMIT_DEF" 1156 case $string:$x in 1157 1:*) cat >> $tmp.l <<! 1158printf("#ifndef ${conf_name}\n"); 1159printf("#define ${conf_name} \"${x}\"\n"); 1160printf("#endif\n"); 1161! 1162 ;; 1163 *:U*) cat >> $tmp.l <<! 1164printf("#ifndef ${conf_name}\n"); 1165printf("#ifndef ${x}\n"); 1166printf("#define ${x} %lu\n", ${x}); 1167printf("#endif\n"); 1168printf("#define ${conf_name} ${x}\n"); 1169printf("#endif\n"); 1170! 1171 ;; 1172 *:$sym) cat >> $tmp.l <<! 1173printf("#ifndef ${conf_name}\n"); 1174printf("#ifndef ${x}\n"); 1175printf("#define ${x} %ld\n", ${x}); 1176printf("#endif\n"); 1177printf("#define ${conf_name} ${x}\n"); 1178printf("#endif\n"); 1179! 1180 ;; 1181 *) cat >> $tmp.l <<! 1182printf("#ifndef ${conf_name}\n"); 1183printf("#define ${conf_name} ${x}\n"); 1184printf("#endif\n"); 1185! 1186 ;; 1187 esac 1188 ;; 1189 esac 1190 ;; 1191 esac 1192 ;; 1193 esac 1194 case $section in 1195 [01]) ;; 1196 *) case $flags in 1197 *N*) ;; 1198 *) name=${section}_${name} ;; 1199 esac 1200 standard=${standard}${section} 1201 ;; 1202 esac 1203 conf_minmax=0 1204 case $call:$standard:$flags in 1205 *:C:*M*)for s in _${standard}_${conf_name} ${values} 1206 do case $s in 1207 $sym) ;; 1208 *) conf_minmax=$s 1209 conf_flags="${conf_flags}|CONF_MINMAX_DEF" 1210 break 1211 ;; 1212 esac 1213 done 1214 ;; 1215 *:C:*) ;; 1216 [CPSX][CSX]:*:*[FM]*) 1217 x= 1218 for s in _${standard}_${conf_name} ${values} 1219 do case $s in 1220 $sym) eval x='$'CONF_const_${s} ;; 1221 *) x=1 ;; 1222 esac 1223 case $x in 1224 1) conf_minmax=$s 1225 case $flags in 1226 *M*) conf_flags="${conf_flags}|CONF_MINMAX_DEF" ;; 1227 esac 1228 case $conf_minmax in 1229 [-+0123456789]*) x= ;; 1230 esac 1231 break 1232 ;; 1233 esac 1234 done 1235 case ${x:+1}:${script:+1} in 1236 :1) case $verbose in 1237 1) echo "$command: probe for _${standard}_${conf_name} minmax value" >&2 ;; 1238 esac 1239 case $CONF_getconf in 1240 ?*) if $CONF_getconf _${standard}_${conf_name} > $tmp.x 2>/dev/null 1241 then x=`cat $tmp.x` 1242 case $x in 1243 undefined) x= ;; 1244 esac 1245 fi 1246 ;; 1247 esac 1248 case $x in 1249 '') case $script in 1250 '#'*) echo "$script" > $tmp.sh 1251 chmod +x $tmp.sh 1252 x=`./$tmp.sh 2>/dev/null` 1253 ;; 1254 *) cat > $tmp.c <<! 1255${head} 1256#include <sys/types.h> 1257#include <limits.h> 1258#include <unistd.h>$systeminfo$headers 1259${tail} 1260${script} 1261! 1262 ;; 1263 esac 1264 case $args in 1265 '') set "" ;; 1266 *) eval set '""' "$args"; shift ;; 1267 esac 1268 for a 1269 do case $script in 1270 '#'*) ./$tmp.sh $a > $tmp.x 2>/dev/null 1271 x=$? 1272 ;; 1273 *) $cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null 1274 x=$? 1275 ;; 1276 esac 1277 case $x in 1278 0) x=`cat $tmp.x` 1279 case $x in 1280 "-") x=$a ;; 1281 esac 1282 break 1283 ;; 1284 *) x= 1285 ;; 1286 esac 1287 done 1288 ;; 1289 esac 1290 case $x in 1291 ?*) conf_minmax=$x 1292 case $flags in 1293 *M*) case "|$conf_flags|" in 1294 *'|CONF_MINMAX_DEF|'*) 1295 ;; 1296 *) conf_flags="${conf_flags}|CONF_MINMAX_DEF" 1297 ;; 1298 esac 1299 ;; 1300 esac 1301 ;; 1302 esac 1303 ;; 1304 esac 1305 ;; 1306 esac 1307 case $string in 1308 1) conf_limit="{ 0, $conf_limit }" conf_minmax="{ 0, $conf_minmax }" 1309 ;; 1310 *) case $conf_limit in 1311 0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*) 1312 ;; 1313 *[!0123456789abcdefABCDEF]*) 1314 conf_limit=0 1315 ;; 1316 *[!0123456789]*) 1317 conf_limit=0x$conf_limit 1318 ;; 1319 esac 1320 case $conf_minmax in 1321 0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*) 1322 ;; 1323 *[!0123456789abcdefABCDEF]*) 1324 conf_minmax=0 1325 ;; 1326 *[!0123456789]*) 1327 conf_minmax=0x$conf_minmax 1328 ;; 1329 esac 1330 case $conf_limit in 1331 ?*[-+]*|*['()']*) 1332 ;; 1333 *[lLuU]) 1334 case $LL_suffix in 1335 ??) case $conf_limit in 1336 *[!lL][lL]|*[!lL][lL][uU]) 1337 conf_limit=${conf_limit}L 1338 ;; 1339 esac 1340 ;; 1341 esac 1342 ;; 1343 -*[2468]) 1344 case $shell in 1345 ksh) p=${conf_limit%?} 1346 s=${conf_limit#$p} 1347 ((s=s-1)) 1348 ;; 1349 *) eval `echo '' $conf_limit | sed 's/ *\(.*\)\(.\) */p=\1 s=\2/'` 1350 s=`expr $s - 1` 1351 ;; 1352 esac 1353 conf_limit=${p}${s}${LL_suffix}-1${LL_suffix} 1354 ;; 1355 0[xX]*[abcdefABCDEF]) 1356 conf_limit=${conf_limit}${LL_suffix} 1357 ;; 1358 -*[0123456789]) 1359 conf_limit=${conf_limit}${LL_suffix} 1360 ;; 1361 *[0123456789]) 1362 conf_limit=${conf_limit}U${LL_suffix} 1363 ;; 1364 esac 1365 case $conf_minmax in 1366 ?*[-+]*|*['()']*) 1367 ;; 1368 *[lLuU]) 1369 case $LL_suffix in 1370 ??) case $conf_minmax in 1371 *[!lL][lL]|*[!lL][lL][uU]) 1372 conf_minmax=${conf_minmax}L 1373 ;; 1374 esac 1375 ;; 1376 esac 1377 ;; 1378 -*[2468]) 1379 case $shell in 1380 ksh) p=${conf_minmax%?} 1381 s=${conf_minmax#$p} 1382 ((s=s-1)) 1383 ;; 1384 *) eval `echo '' $conf_minmax | sed 's/ *\(.*\)\(.\) */p=\1 s=\2/'` 1385 s=`expr $s - 1` 1386 ;; 1387 esac 1388 conf_minmax=${p}${s}${LL_suffix}-1${LL_suffix} 1389 ;; 1390 0[xX]*[abcdefABCDEF]) 1391 conf_minmax=${conf_minmax}${LL_suffix} 1392 ;; 1393 -*[0123456789]) 1394 conf_minmax=${conf_minmax}${LL_suffix} 1395 ;; 1396 *[0123456789]) 1397 conf_minmax=${conf_minmax}U${LL_suffix} 1398 ;; 1399 esac 1400 conf_limit="{ $conf_limit, 0 }" conf_minmax="{ $conf_minmax, 0 }" 1401 ;; 1402 esac 1403 case $conf_flags in 1404 '0|'*) case $shell in 1405 ksh) conf_flags=${conf_flags#0?} ;; 1406 *) conf_flags=`echo "$conf_flags" | sed 's/^0.//'` ;; 1407 esac 1408 ;; 1409 esac 1410 echo "{ \"$conf_name\", $conf_limit, $conf_minmax, $conf_flags, $conf_standard, $conf_section, $conf_call, $conf_op }," 1411 case $shell in 1412 ksh) len=${#conf_name} 1413 if ((len>=name_max)) 1414 then ((name_max=len+1)) 1415 fi 1416 ;; 1417 *) len=`echo ${conf_name} | wc -c` 1418 if expr \( $len - 1 \) \>= ${name_max} >/dev/null 1419 then name_max=$len 1420 fi 1421 ;; 1422 esac 1423done 1424exec > /dev/null 1425case $debug in 1426-d6) exit ;; 1427esac 1428 1429# conf string table 1430 1431base=conftab 1432case $verbose in 14331) echo "$command: generate ${base}.h string table header" >&2 ;; 1434esac 1435case $shell in 1436ksh) ((name_max=name_max+3)); ((name_max=name_max/4*4)) ;; # bsd /bin/sh ! 1437*) name_max=`expr \( $name_max + 3 \) / 4 \* 4` ;; 1438esac 1439{ 1440cat <<! 1441#ifndef _CONFTAB_H 1442#define _CONFTAB_H 1443$systeminfo 1444 1445${generated} 1446 1447#if !defined(const) && !defined(__STDC__) && !defined(__cplusplus) && !defined(c_plusplus) 1448#define const 1449#endif 1450 1451#define conf _ast_conf_data 1452#define conf_elements _ast_conf_ndata 1453 1454#define prefix _ast_conf_prefix 1455#define prefix_elements _ast_conf_nprefix 1456 1457#define CONF_nop 0 1458#define CONF_confstr 1 1459#define CONF_pathconf 2 1460#define CONF_sysconf 3 1461#define CONF_sysinfo 4 1462 1463! 1464index=0 1465for standard in $standards 1466do echo "#define CONF_${standard} ${index}" 1467 case $shell in 1468 ksh) ((index=index+1)) ;; 1469 *) index=`expr ${index} + 1` ;; 1470 esac 1471done 1472echo "#define CONF_call ${index}" 1473case $CONF_getconf in 1474?*) echo 1475 echo "#define _pth_getconf \"$CONF_getconf\"" 1476 case $CONF_getconf_a in 1477 ?*) echo "#define _pth_getconf_a \"$CONF_getconf_a\"" ;; 1478 esac 1479 ;; 1480esac 1481cat <<! 1482 1483#define CONF_DEFER_CALL 0x0001 1484#define CONF_DEFER_MM 0x0002 1485#define CONF_FEATURE 0x0004 1486#define CONF_LIMIT 0x0008 1487#define CONF_LIMIT_DEF 0x0010 1488#define CONF_MINMAX 0x0020 1489#define CONF_MINMAX_DEF 0x0040 1490#define CONF_NOSECTION 0x0080 1491#define CONF_NOUNDERSCORE 0x0100 1492#define CONF_PREFIX_ONLY 0x0200 1493#define CONF_PREFIXED 0x0400 1494#define CONF_STANDARD 0x0800 1495#define CONF_STRING 0x1000 1496#define CONF_UNDERSCORE 0x2000 1497#define CONF_USER 0x4000 1498 1499struct Conf_s; typedef struct Conf_s Conf_t; 1500 1501typedef struct Value_s 1502{ 1503 intmax_t number; 1504 const char* string; 1505} Value_t; 1506 1507struct Conf_s 1508{ 1509 const char name[${name_max}]; 1510 Value_t limit; 1511 Value_t minmax; 1512 unsigned int flags; 1513 short standard; 1514 short section; 1515 short call; 1516 short op; 1517}; 1518 1519typedef struct Prefix_s 1520{ 1521 const char name[16]; 1522 short length; 1523 short standard; 1524 short call; 1525} Prefix_t; 1526 1527extern const Conf_t conf[]; 1528extern const int conf_elements; 1529 1530extern const Prefix_t prefix[]; 1531extern const int prefix_elements; 1532 1533#endif 1534! 1535} > $tmp.2 1536case $debug in 1537-d7) echo $command: $tmp.2 ${base}.h ;; 1538*) cmp -s $tmp.2 ${base}.h 2>/dev/null || mv $tmp.2 ${base}.h ;; 1539esac 1540 1541case $verbose in 15421) echo "$command: generate ${base}.c string table" >&2 ;; 1543esac 1544{ 1545cat <<! 1546${head} 1547#include <sys/types.h> 1548#include <limits.h> 1549#include <unistd.h>$systeminfo$headers 1550${tail} 1551#include "${base}.h" 1552 1553${generated} 1554 1555/* 1556 * prefix strings -- the first few are indexed by Conf_t.standard 1557 */ 1558 1559const Prefix_t prefix[] = 1560{ 1561! 1562for standard in $standards 1563do case $shell in 1564 ksh) len=${#standard} ;; 1565 *) len=`echo ${standard} | wc -c`; len=`expr $len - 1` ;; 1566 esac 1567 echo " \"${standard}\", ${len}, CONF_${standard}, -1," 1568done 1569cat <<! 1570 "XX", 2, CONF_POSIX, CONF_nop, 1571 "CS", 2, CONF_POSIX, CONF_confstr, 1572 "PC", 2, CONF_POSIX, CONF_pathconf, 1573 "SC", 2, CONF_POSIX, CONF_sysconf, 1574 "SI", 2, CONF_SVID, CONF_sysinfo, 1575}; 1576 1577const int prefix_elements = (int)sizeof(prefix) / (int)sizeof(prefix[0]); 1578 1579/* 1580 * conf strings sorted in ascending order 1581 */ 1582 1583const Conf_t conf[] = 1584{ 1585! 1586cat $tmp.t 1587cat <<! 1588}; 1589 1590const int conf_elements = (int)sizeof(conf) / (int)sizeof(conf[0]); 1591! 1592} > $tmp.4 1593case $debug in 1594-d7) echo $command: $tmp.4 ${base}.c ;; 1595*) cmp -s $tmp.4 ${base}.c 2>/dev/null || mv $tmp.4 ${base}.c ;; 1596esac 1597 1598# limits.h generation code 1599 1600base=conflim 1601case $verbose in 16021) echo "$command: generate ${base}.h supplemental <limits.h> values" >&2 ;; 1603esac 1604{ 1605cat <<! 1606${generated} 1607 1608/* 1609 * supplemental <limits.h> values 1610 */ 1611 1612! 1613test -f $tmp.l && cat $tmp.l 1614} > $tmp.5 1615case $debug in 1616-d7) echo $command: $tmp.5 ${base}.h ;; 1617*) cmp -s $tmp.5 ${base}.h 2>/dev/null || mv $tmp.5 ${base}.h ;; 1618esac 1619exit 0 1620