about summary refs log tree commit diff
path: root/Src/Modules/errnames2.awk
blob: 60969b423a4d0ceb9cf30bd928ffdc0379e2a792 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Edited version of Src/signames2.awk.
#
# {g,n}awk script to generate errnames.c
# This version relies on the previous output of the preprocessor
# on sigtmp.c, sigtmp.out, which is in turn generated by errnames1.awk.
#
# NB: On SunOS 4.1.3 - user-functions don\'t work properly, also \" problems
# Without 0 + hacks some nawks compare numbers as strings
#
/^XXNAMES XXE[A-Z0-9]*[\t ][\t ]*[1-9][0-9]*/ {
    eindex = index($0, "E")
    etail = substr($0, 11, 80)
    split(etail, tmp)
    enam = tmp[1]
    enum = tmp[2]
    if (errname[enum] == "") {
	errname[enum] = enam
	if (0 + max < 0 + enum && enum < 1024)
	    max = enum
    }
}

END {
    ps = "%s"
    printf "/** errnames.c                                 **/\n"
    printf "/** architecture-customized errnames.c for zsh **/\n"
    printf "\n"
    printf "#define ERRCOUNT\t%d\n", max
    printf "\n"
    printf "#include %csystem.mdh%c\n", 34, 34
    printf "\n"
    printf "/**/\n"
    printf "const char *sys_errnames[ERRCOUNT+1] = {\n"

    for (i = 1; i <= 0 + max; i++)
	if (errname[i] == "")
	    printf("\t%cE%d%c,\n", 34, i, 34)
	else
	    printf("\t%c%s%c,\n", 34, errname[i], 34)
    print "\tNULL"
    print "};"
}