Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh-3.0.1-test2 compilation problem



Zoltan Hidvegi wrote:
> I know this preprocessor trickery is ugly but the alternatives are not much
> better either.  We can generate limits with an awk script but it took more
> than a year to make the awk script generating signames.h portable.  And for
> that we have to find out where are the RLIMIT_ macros defined (that seems
> to be always in /usr/include/sys/resource.h but on Linux it is under asm).

Certainly true, but

(1) we can start from that other awk script.  I hacked up the
following which worked fine on a random sample of Sgi, HPUX, SunOS 4,
Solaris 2 and OSF/1 workstations with the standard awk.  The worst
problem may be sneaky definitions which define the signal in terms
of some other cpp token instead of an integer directly.  I think we
can only suck it and see.  (Do `awk -f rlimits.awk
/usr/include/sys/resource.h' unless the limits are elsewhere.)

Note I've made the script exit with the status containing the number
of limits it failed to find, so configure can print a warning, but
supplied the bit of the CPP token (e.g. RSS, CORE, ... although those
are of course handled) as the name, so it can compile anyway.

(2) it shouldn't be too hard to make a list of possible locations for
RLIMITS, let configure decide whether they exist (which it may well do
anyway, thought we might have to check for files included from other
files) and awk through the list of those which do exist.  I thought
I'd better see what people made of the script first, though.

# 
# $Id:$
#
# rlimits.awk: {g,n}awk script to generate rlimits.h
# rewritten by Peter Stephenson <pws@xxxxxx> from Geoff Wing
# <mason@xxxxxxxxxxxxxxxxxxx>'s signames.awk
# NB: On SunOS 4.1.3 - user-functions don't work properly, also \" problems
# Without 0 + hacks some nawks compare numbers as strings
#
/^[\t ]*#[\t ]*define[\t _]*RLIMIT_[A-Z]*[\t ]*[0-9][0-9]*/ { 
    limindex = index($0, "RLIMIT_")
    limtail = substr($0, limindex, 80)
    split(limtail, tmp)
    limnam = substr(tmp[1], 8, 20)
    limnum = tmp[2]
    limrev[limnam] = limnum
    if (lim[limnum] == "") {
	lim[limnum] = limnam
	if (limnum ~ /^[0-9]*$/) {
	    if (limnam == "MEMLOCK") { msg[limnum] = "memorylocked" }
	    if (limnam == "RSS")     { msg[limnum] = "resident" }
	    if (limnam == "VMEM")    { msg[limnum] = "vmemorysize" }
	    if (limnam == "NOFILE")  { msg[limnum] = "descriptors" }
	    if (limnam == "CORE")    { msg[limnum] = "coredumpsize" }
	    if (limnam == "STACK")   { msg[limnum] = "stacksize" }
	    if (limnam == "DATA")    { msg[limnum] = "datasize" }
	    if (limnam == "FSIZE")   { msg[limnum] = "filesize" }
	    if (limnam == "CPU")     { msg[limnum] = "cputime" }
	    if (limnam == "NPROC")   { msg[limnum] = "maxproc" }
	    if (limnam == "AS")      { msg[limnum] = "addressspace" }
	    if (limnam == "TCACHE")  { msg[limnum] = "cachethreads" }
        }
    }
}
/^[\t ]*#[\t ]*define[\t _]*RLIM_NLIMITS[\t ]*[0-9][0-9]*/ {
    limindex = index($0, "RLIM_")
    limtail = substr($0, limindex, 80)
    split(limtail, tmp)
    nlimits = tmp[2]
}

END {
    if (limrev["MEMLOCK"] != "") {
        irss = limrev["RSS"]
        msg[irss] = "memoryuse"
    }
    ps = "%s"

    printf("%s\n%s\n\n%s\n", "/** rlimits.h                                 **/", "/** architecture-customized rlimits.h for zsh **/", "static char *recs[RLIM_NLIMITS+1] = {")

    for (i = 0; i < 0 + nlimits; i++)
	if (msg[i] == "") {
            badlimit = badlimit + 1
            printf("\t%c%s%c,\n", 034, lim[i], 034)
	} else
	    printf("\t%c%s%c,\n", 034, msg[i], 034)
    print "\tNULL"
    print "};"
    print ""
    exit(badlimit)
}

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author