xref: /netbsd-src/usr.bin/getaddrinfo/tables.awk (revision 28ffd7e64fafff76902ba719324ae71ab116f9be)
188bc4b53Sriastradh#!/usr/bin/awk -f
288bc4b53Sriastradh
3*28ffd7e6Sginsbach#	$NetBSD: tables.awk,v 1.2 2014/02/27 01:17:13 ginsbach Exp $
488bc4b53Sriastradh
588bc4b53Sriastradh# Copyright (c) 2013 The NetBSD Foundation, Inc.
688bc4b53Sriastradh# All rights reserved.
788bc4b53Sriastradh#
888bc4b53Sriastradh# This code is derived from software contributed to The NetBSD Foundation
988bc4b53Sriastradh# by Taylor R. Campbell.
1088bc4b53Sriastradh#
1188bc4b53Sriastradh# Redistribution and use in source and binary forms, with or without
1288bc4b53Sriastradh# modification, are permitted provided that the following conditions
1388bc4b53Sriastradh# are met:
1488bc4b53Sriastradh# 1. Redistributions of source code must retain the above copyright
1588bc4b53Sriastradh#    notice, this list of conditions and the following disclaimer.
1688bc4b53Sriastradh# 2. Redistributions in binary form must reproduce the above copyright
1788bc4b53Sriastradh#    notice, this list of conditions and the following disclaimer in the
1888bc4b53Sriastradh#    documentation and/or other materials provided with the distribution.
1988bc4b53Sriastradh#
2088bc4b53Sriastradh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2188bc4b53Sriastradh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2288bc4b53Sriastradh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2388bc4b53Sriastradh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2488bc4b53Sriastradh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2588bc4b53Sriastradh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2688bc4b53Sriastradh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2788bc4b53Sriastradh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2888bc4b53Sriastradh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2988bc4b53Sriastradh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3088bc4b53Sriastradh# POSSIBILITY OF SUCH DAMAGE.
3188bc4b53Sriastradh
3288bc4b53SriastradhBEGIN {
3388bc4b53Sriastradh	n_afs = 0
3488bc4b53Sriastradh	n_socktypes = 0
3588bc4b53Sriastradh}
3688bc4b53Sriastradh
3788bc4b53Sriastradh!(($1 == "#define") && ($3 ~ /^[0-9]*$/)) {
3888bc4b53Sriastradh	next
3988bc4b53Sriastradh}
4088bc4b53Sriastradh
41*28ffd7e6Sginsbach($2 ~ /^AF_[A-Z0-9_]*$/) && ($2 != "AF_MAX") {
4288bc4b53Sriastradh	afs[n_afs++] = substr($2, 4)
4388bc4b53Sriastradh}
4488bc4b53Sriastradh
4588bc4b53Sriastradh$2 ~ /^SOCK_[A-Z0-9_]*$/ {
4688bc4b53Sriastradh	socktypes[n_socktypes++] = substr($2, 6)
4788bc4b53Sriastradh}
4888bc4b53Sriastradh
4988bc4b53SriastradhEND {
5088bc4b53Sriastradh	printf("/* Do not edit!  This file was generated automagically! */\n");
5188bc4b53Sriastradh
5288bc4b53Sriastradh	printf("\nstatic const char *const address_families[] = {\n");
5388bc4b53Sriastradh	for (i = 0; i < n_afs; i++)
5488bc4b53Sriastradh		printf("\t[AF_%s] = \"%s\",\n", afs[i], tolower(afs[i]));
5588bc4b53Sriastradh	printf("};\n");
5688bc4b53Sriastradh
5788bc4b53Sriastradh	printf("\nstatic const char *const socket_types[] = {\n");
5888bc4b53Sriastradh	for (i = 0; i < n_socktypes; i++)
5988bc4b53Sriastradh		printf("\t[SOCK_%s] = \"%s\",\n", socktypes[i],
6088bc4b53Sriastradh		    tolower(socktypes[i]));
6188bc4b53Sriastradh	printf("};\n");
6288bc4b53Sriastradh}
63