########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1985-2011 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# David Korn <dgk@research.att.com> #
# Phong Vo <kpv@research.att.com> #
# #
########################################################################
#
# @(#)conf.sh (AT&T Research) 2010-09-14
#
# this script generates these files from the table file in the first arg
# the remaining args are the C compiler name and flags
#
# conftab.h readonly string table definitions
# conftab.c readonly string table data
#
# you may think it should be simpler
# but you shall be confused anyway
#
case $-:$BASH_VERSION in
esac
LC_ALL=C
export LC_ALL
command=conf
append=0
extra=0
keep_call='*'
keep_name='*'
verbose=0
while :
do case $1 in
-a) append=1 ;;
-d*) debug=$1 ;;
-l) extra=1 ;;
-t) trace=1 ;;
-v) verbose=1 ;;
-*) echo "Usage: $command [-a] [-ccall-pattern] [-dN] [-l] [-nname_pattern] [-t] [-v] conf.tab" >&2; exit 2 ;;
*) break ;;
esac
shift
done
hdr=
'}
nl='
'
sp=' '
ob='{'
cb='}'
esac
esac
case $# in
exit 1
;;
esac
;;
*) tab=$1
shift
if test ! -f $tab
exit 1
fi
;;
esac
case $# in
*) cc=$* ;;
esac
esac
# determine the intmax_t printf format
${head}
int
{
#if _ast_intmax_long
return 1;
#else
return 0;
#endif
}
!
then LL_format='ll'
else LL_format='l'
fi
# determine the intmax_t constant suffix
${head}
int
{
#if _ast_intmax_long
return 1;
#else
_ast_intmax_t s = 0x7fffffffffffffffLL;
unsigned _ast_intmax_t u = 0xffffffffffffffffLL;
return 0;
#endif
}
!
then LL_suffix='LL'
else LL_suffix='L'
fi
else LL_suffix=''
fi
# set up the names and keys
keys=
esac
exec < $tab
while :
do IFS=""
read line
eof=$?
0) ;;
*) break ;;
esac
""|\#*) ;;
*) set x $line
shift; name=$1
shift; standard=$1
shift; call=$1
shift; section=$1
shift; flags=$1
while :
do shift
case $# in
0) break ;;
esac
case $1 in
":") shift
break
;;
*) script= ;;
esac
shift
args="$*"
IFS=""
while read line
"}") break ;;
esac
done
break
;;
ksh) f=${1%.h} ;;
esac
*" $f "*)
;;
*" -$f- "*)
;;
fi
;;
esac
;;
case $1 in
esac
;;
esac
done
case " $standards " in
*" $standard "*)
;;
*) standards="$standards $standard"
;;
esac
*:*S*) ;;
esac
*) key= ;;
esac
esac
esac
esac
;;
esac
done
;;
esac
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}"
;;
esac
done
exit
;;
esac
#if !defined(SYS_NMLEN)
#define SYS_NMLEN 9
#endif
#include <sys/systeminfo.h>'
echo "$systeminfo" > $tmp.c
# check for native getconf(1)
*"AT&T"*"Research"*)
;;
then CONF_getconf_a=-a
fi
;;
esac
break
fi
done
export CONF_getconf CONF_getconf_a
1) echo "$command: check ${CONF_getconf:+$CONF_getconf(1),}confstr(2),pathconf(2),sysconf(2),sysinfo(2) configuration names" >&2 ;;
esac
{
echo "#include <unistd.h>$systeminfo
int i = 0;" > $tmp.c
} |
sed \
-e '/^#[^0123456789]*1[ ]*".*".*/!d' \
-e 's/^#[^0123456789]*1[ ]*"\(.*\)".*/\1/' |
{
sed \
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]/ /g' \
-e 's/[ ][ ]*/\n/g' \
egrep '^(SI|_(CS|PC|SC|SI))_.'
case $CONF_getconf_a in
?*) $CONF_getconf $CONF_getconf_a | sed 's,[=: ].*,,'
;;
*) case $CONF_getconf in
?*) for v in `strings $CONF_getconf | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*$'`
do if $CONF_getconf $v >/dev/null
then echo $v
fi
done
;;
esac
;;
} |
egrep -v '^_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+_(COUNT|LAST|N|STR)$' |
{
} > $tmp.t
-d2) exit ;;
esac
HOST=`package | sed -e 's,[0123456789.].*,,' | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
esac
exec < $tmp.g
while read line
do flags=F
IFS=_
set $line
case $1 in
'') case $# in
0) continue ;;
esac
shift
;;
esac
case $1 in
call=$1
shift
standard=$1
;;
standard=$1
while :
do case $# in
0) continue 2 ;;
esac
shift
case $1 in
call=$1
shift
break
;;
continue 2
;;
esac
done
;;
esac
case $1 in
SET) continue ;;
esac
esac
case " $standards " in
*" $standard "*)
;;
[0123456789]*)
;;
*[0123456789])
;;
esac
;;
esac
SI) ;;
*) underscore=U ;;
esac
;;
*) case " $standards " in
" C ") shift
;;
*" $standard "*)
SI) ;;
;;
esac
shift
;;
*) standard=
;;
esac
;;
esac
SI) ;;
*) underscore=U ;;
esac
_${call}_*)
;;
esac
;;
esac
;;
esac
esac
;;
esac
name=
while :
do case $# in
0) break ;;
esac
esac
shift
done
'') ;;
;;
*) values=
args=
esac
esac
esac
case $x in
case $x in
esac
case $underscore in
esac
esac
case $x in
?*) eval CONF_name_$old=
;;
esac
;;
case $x in
case $x in
SI) ;;
*) define= ;;
esac
;;
*) define=
;;
esac
;;
esac
case $x in
QQ) ;;
*R*) flags=R ;;
*) flags= ;;
esac
;;
esac
esac
;;
esac
esac
eval CONF_name_$old=
esac
;;
case $x in
;;
esac
done
esac
;;
esac
done
# sort keys by name
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}"
;;
esac
done
exit
;;
esac
# mark the dups CONF_PREFIXED
'') continue
;;
case $p:$c in
*L*:*L*);;
*L*:*) c=L${c} ;;
*:*L*) p=L${p} ;;
*) p=P$p c=P$c ;;
esac
eval CONF_flags_${prev_key}=$p
eval CONF_flags_${key}=$c
;;
esac
done
'') continue ;;
$keep_name) ;;
*) continue ;;
esac
$keep_call) ;;
*) continue ;;
esac
esac
;;
;;
esac
case $x in
?*) call=$x
break
;;
esac
done
do echo "_${c}_${name}"
1) echo "_${c}_${standard}_${name}" ;;
*) echo "_${c}_${standard}${section}_${name}" ;;
esac
;;
esac
done
;;
esac
;;
esac
;;
exit 1
;;
esac
exit 1
;;
esac
[01]) ;;
*N*) ;;
esac
;;
esac
XX) ;;
esac
echo "${conf_op}"
;;
esac
C:*) ;;
*:*L*) echo "${conf_name}"
echo "_${standard}_${conf_name}"
;;
1) echo "_${standard}_${conf_name}" ;;
*) echo "_${standard}${section}_${conf_name}" ;;
esac
;;
esac
done > $tmp.q
-d4) exit ;;
esac
# test all the macros in a few batches (some compilers have an error limit)
{
: > $tmp.p
while :
do {
cat <<!
${head}
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
unsigned int conf[] = {
!
echo "};"
} > $tmp.c
then break
fi
snl='\
'
sed "s/[^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*/${snl}/g" $tmp.e |
grep '^[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz][_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*$' |
done
{
cat <<!
${head}
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
!
} > $tmp.c
sed -e '/conf[ ]*".*"[ ]*=[ ]*/!d' -e '/[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][ ]*(/!d' -e 's/.*"\(.*\)".*/\1/' > $tmp.n
if test -s $tmp.n
fi
}
esac
-d5) exit ;;
esac
exec < $tmp.q
while read line
do eval CONF_const_${line}=1
done
exec < $tmp.v
while read line
do eval CONF_const_${line}=1
done
# mark the string literal values
{
cat <<!
${head}
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
!
} > $tmp.c
exec < $tmp.e
while read line
do eval CONF_string_${line}=1
done
# walk through the table
esac
name_max=1
exec > $tmp.t
'') continue ;;
$keep_name) ;;
*) continue ;;
esac
$keep_call) ;;
*) continue ;;
esac
esac
;;
;;
esac
case $x in
?*) call=$x
break
;;
esac
done
esac
;;
;;
esac
case $x in
1) call=$c
break
;;
esac
done
;;
esac
esac
esac
;;
esac
;;
esac
;;
*) standards="$standards $standard"
;;
esac
;;
;;
;;
;;
;;
esac
conf_op=-1
for s in _${call}_${standard}${section}_${name} _${call}_${standard}_${name} _${call}_${section}_${name} _${call}_${name} ${call}_${name}
case $x in
1) conf_op=${s}
break
;;
esac
done
esac
esac
esac
esac
esac
esac
esac
esac
esac
esac
esac
esac
;;
esac
CS|SI) conf_flags="${conf_flags}|CONF_STRING"
string=1
;;
;;
esac
*[Ll]*) d=
x=
;;
;;
esac
case $x in
do case $s in
case $x in
case $a in
$x) x= ;;
*) x=$s ;;
esac
break
;;
esac
;;
[0123456789]*|[-+][0123456789]*)
d=$s
break
;;
esac
done
:*:-1|:*X*:*)
esac
x=
case $CONF_getconf in
?*) if $CONF_getconf $conf_name > $tmp.x 2>/dev/null
case $x in
undefined) x= ;;
esac
fi
;;
esac
case ${x:+1} in
;;
f="%${LL_format}u"
t="unsigned _ast_intmax_t"
;;
*) f="%${LL_format}d"
t="_ast_intmax_t"
;;
esac
${head}
#include <stdio.h>
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
int
main()
{
return 0;
}
!
;;
${head}
#include <stdio.h>
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
${script}
!
;;
esac
'') set "" ;;
esac
for a
x=$?
;;
x=$?
;;
esac
case $x in
case $x in
"-") x=$a ;;
esac
break
;;
*) x=
;;
esac
done
;;
esac
case $x in
'') x=$d ;;
esac
;;
esac
1:*:-1|1:*X*:*)
conf_limit=$x
*L*) ;;
esac
conf_flags="${conf_flags}|CONF_LIMIT_DEF"
!
;;
!
;;
!
;;
!
;;
esac
;;
esac
;;
esac
;;
esac
[01]) ;;
*N*) ;;
esac
;;
esac
do case $s in
$sym) ;;
*) conf_minmax=$s
conf_flags="${conf_flags}|CONF_MINMAX_DEF"
break
;;
esac
done
;;
*:C:*) ;;
x=
do case $s in
*) x=1 ;;
esac
case $x in
1) conf_minmax=$s
esac
case $conf_minmax in
[-+0123456789]*) x= ;;
esac
break
;;
esac
done
esac
case $CONF_getconf in
case $x in
undefined) x= ;;
esac
fi
;;
esac
case $x in
;;
${head}
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
${script}
!
;;
esac
'') set "" ;;
esac
for a
x=$?
;;
x=$?
;;
esac
case $x in
case $x in
"-") x=$a ;;
esac
break
;;
*) x=
;;
esac
done
;;
esac
case $x in
?*) conf_minmax=$x
*'|CONF_MINMAX_DEF|'*)
;;
*) conf_flags="${conf_flags}|CONF_MINMAX_DEF"
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
*) case $conf_limit in
0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
;;
*[!0123456789abcdefABCDEF]*)
;;
*[!0123456789]*)
;;
esac
case $conf_minmax in
0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
;;
*[!0123456789abcdefABCDEF]*)
;;
*[!0123456789]*)
;;
esac
case $conf_limit in
?*[-+]*|*['()']*)
;;
*[lLuU])
case $LL_suffix in
??) case $conf_limit in
conf_limit=${conf_limit}L
;;
esac
;;
esac
;;
-*[2468])
ksh) p=${conf_limit%?}
s=${conf_limit#$p}
((s=s-1))
;;
s=`expr $s - 1`
;;
esac
conf_limit=${p}${s}${LL_suffix}-1${LL_suffix}
;;
0[xX]*[abcdefABCDEF])
;;
-*[0123456789])
;;
*[0123456789])
conf_limit=${conf_limit}U${LL_suffix}
;;
esac
case $conf_minmax in
?*[-+]*|*['()']*)
;;
*[lLuU])
case $LL_suffix in
??) case $conf_minmax in
;;
esac
;;
esac
;;
-*[2468])
ksh) p=${conf_minmax%?}
s=${conf_minmax#$p}
((s=s-1))
;;
s=`expr $s - 1`
;;
esac
conf_minmax=${p}${s}${LL_suffix}-1${LL_suffix}
;;
0[xX]*[abcdefABCDEF])
;;
-*[0123456789])
;;
*[0123456789])
conf_minmax=${conf_minmax}U${LL_suffix}
;;
esac
;;
esac
case $conf_flags in
ksh) conf_flags=${conf_flags#0?} ;;
esac
;;
esac
echo "{ \"$conf_name\", $conf_limit, $conf_minmax, $conf_flags, $conf_standard, $conf_section, $conf_call, $conf_op },"
fi
;;
fi
;;
esac
done
-d6) exit ;;
esac
# conf string table
esac
esac
{
cat <<!
#ifndef _CONFTAB_H
#define _CONFTAB_H
${generated}
#if !defined(const) && !defined(__STDC__) && !defined(__cplusplus) && !defined(c_plusplus)
#define const
#endif
#define conf _ast_conf_data
#define conf_elements _ast_conf_ndata
#define prefix _ast_conf_prefix
#define prefix_elements _ast_conf_nprefix
#define CONF_nop 0
#define CONF_confstr 1
#define CONF_pathconf 2
#define CONF_sysconf 3
#define CONF_sysinfo 4
!
index=0
for standard in $standards
do echo "#define CONF_${standard} ${index}"
esac
done
echo "#define CONF_call ${index}"
case $CONF_getconf in
?*) echo
echo "#define _pth_getconf \"$CONF_getconf\""
case $CONF_getconf_a in
esac
;;
esac
cat <<!
#define CONF_DEFER_CALL 0x0001
#define CONF_DEFER_MM 0x0002
#define CONF_FEATURE 0x0004
#define CONF_LIMIT 0x0008
#define CONF_LIMIT_DEF 0x0010
#define CONF_MINMAX 0x0020
#define CONF_MINMAX_DEF 0x0040
#define CONF_NOSECTION 0x0080
#define CONF_NOUNDERSCORE 0x0100
#define CONF_PREFIX_ONLY 0x0200
#define CONF_PREFIXED 0x0400
#define CONF_STANDARD 0x0800
#define CONF_STRING 0x1000
#define CONF_UNDERSCORE 0x2000
#define CONF_USER 0x4000
{
const char* string;
} Value_t;
struct Conf_s
{
Value_t limit;
unsigned int flags;
};
{
const char name[16];
} Prefix_t;
extern const int conf_elements;
extern const int prefix_elements;
#endif
!
} > $tmp.2
esac
esac
{
cat <<!
${head}
#include <limits.h>
#include <unistd.h>$systeminfo$headers
${tail}
#include "${base}.h"
${generated}
/*
*/
{
!
for standard in $standards
esac
echo " \"${standard}\", ${len}, CONF_${standard}, -1,"
done
cat <<!
};
/*
*/
{
!
cat <<!
};
!
} > $tmp.4
esac
# limits.h generation code
esac
{
cat <<!
${generated}
/*
*/
!
} > $tmp.5
esac
exit 0