1 # $NetBSD: gen_errno_tables.awk,v 1.3 2005/12/11 12:19:56 christos Exp $ 2 3 # Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions 7 # are met: 8 # 1. Redistributions of source code must retain the above copyright 9 # notice, this list of conditions and the following disclaimer. 10 # 2. Redistributions in binary form must reproduce the above copyright 11 # notice, this list of conditions and the following disclaimer in the 12 # documentation and/or other materials provided with the distribution. 13 # 3. All advertising materials mentioning features or use of this software 14 # must display the following acknowledgement: 15 # This product includes software developed by Christopher G. Demetriou 16 # for the NetBSD Project. 17 # 4. The name of the author may not be used to endorse or promote products 18 # derived from this software without specific prior written permission 19 # 20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 # Currently this script works with either gawk or nawk. 32 # 33 # Use it like: 34 # 35 # awk -f gen_errno_tables.awk -v PREFIX=OSF1 netbsd_errno_hdr \ 36 # osf1_errno_hdr 37 # 38 # It puts results into 'c' and 'h' in current directory, which can then be 39 # incorporated into emulation header files. 40 # 41 # Note that this script is not meant to generate perfectly pretty output. 42 # Wanna be a formatting weenie, hand-edit the output (or make the script 43 # output perfectly pretty lists). 44 45 BEGIN { 46 nr_offset = 0; 47 idx = 0; 48 49 printf "" > "c" 50 printf "" > "h" 51 } 52 53 NR != (FNR + nr_offset) { 54 printf("file switch\n"); 55 if (idx != 0) { 56 exit 1 57 } 58 nr_offset = (NR - FNR) 59 idx = 1; 60 } 61 62 /^#[ \t]*define[ \t]+E[A-Z0-9]*[ \t]+[0-9]+/ { 63 if ($1 == "#define") { 64 name=$2 65 val=$3 66 } else { 67 name=$3 68 val=$4 69 } 70 71 if (val_max[idx] < val) { 72 val_max[idx] = val; 73 } 74 if (mappings[idx, "val", val] == "") { 75 mappings[idx, "name", name] = val 76 mappings[idx, "val", val] = name 77 } 78 } 79 80 END { 81 if (idx != 1) { 82 exit 1 83 } 84 85 printf(" 0,\n") >> "c" 86 for (i = 1; i <= val_max[0]; i++) { 87 nb_name = mappings[0, "val", i] 88 if (nb_name != "") { 89 otheros_val = mappings[1, "name", nb_name] 90 if (otheros_val != "") { 91 printf(" %s_%s,\t\t/* %s (%d) -> %d */\n", 92 PREFIX, nb_name, nb_name, i, 93 otheros_val) >> "c" 94 } else { 95 printf(" %s_%s,\t\t/* %s (%d) has no equivalent */\n", 96 PREFIX, "ENOSYS", nb_name, i) >> "c" 97 } 98 } 99 } 100 101 for (i = 1; i <= val_max[1]; i++) { 102 if (mappings[1, "val", i] != "") { 103 printf("#define %s_%s\t\t%d\n", 104 PREFIX, mappings[1, "val", i], i) >> "h" 105 } 106 } 107 } 108