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