15c57c3a9Sriastradh#!/usr/bin/awk -f 25c57c3a9Sriastradh 3*d1fdad48Sginsbach# $NetBSD: tables.awk,v 1.2 2014/02/27 01:17:13 ginsbach Exp $ 45c57c3a9Sriastradh 55c57c3a9Sriastradh# Copyright (c) 2013 The NetBSD Foundation, Inc. 65c57c3a9Sriastradh# All rights reserved. 75c57c3a9Sriastradh# 85c57c3a9Sriastradh# This code is derived from software contributed to The NetBSD Foundation 95c57c3a9Sriastradh# by Taylor R. Campbell. 105c57c3a9Sriastradh# 115c57c3a9Sriastradh# Redistribution and use in source and binary forms, with or without 125c57c3a9Sriastradh# modification, are permitted provided that the following conditions 135c57c3a9Sriastradh# are met: 145c57c3a9Sriastradh# 1. Redistributions of source code must retain the above copyright 155c57c3a9Sriastradh# notice, this list of conditions and the following disclaimer. 165c57c3a9Sriastradh# 2. Redistributions in binary form must reproduce the above copyright 175c57c3a9Sriastradh# notice, this list of conditions and the following disclaimer in the 185c57c3a9Sriastradh# documentation and/or other materials provided with the distribution. 195c57c3a9Sriastradh# 205c57c3a9Sriastradh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 215c57c3a9Sriastradh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 225c57c3a9Sriastradh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 235c57c3a9Sriastradh# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 245c57c3a9Sriastradh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 255c57c3a9Sriastradh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 265c57c3a9Sriastradh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 275c57c3a9Sriastradh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 285c57c3a9Sriastradh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 295c57c3a9Sriastradh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 305c57c3a9Sriastradh# POSSIBILITY OF SUCH DAMAGE. 315c57c3a9Sriastradh 325c57c3a9SriastradhBEGIN { 335c57c3a9Sriastradh n_afs = 0 345c57c3a9Sriastradh n_socktypes = 0 355c57c3a9Sriastradh} 365c57c3a9Sriastradh 375c57c3a9Sriastradh!(($1 == "#define") && ($3 ~ /^[0-9]*$/)) { 385c57c3a9Sriastradh next 395c57c3a9Sriastradh} 405c57c3a9Sriastradh 41*d1fdad48Sginsbach($2 ~ /^AF_[A-Z0-9_]*$/) && ($2 != "AF_MAX") { 425c57c3a9Sriastradh afs[n_afs++] = substr($2, 4) 435c57c3a9Sriastradh} 445c57c3a9Sriastradh 455c57c3a9Sriastradh$2 ~ /^SOCK_[A-Z0-9_]*$/ { 465c57c3a9Sriastradh socktypes[n_socktypes++] = substr($2, 6) 475c57c3a9Sriastradh} 485c57c3a9Sriastradh 495c57c3a9SriastradhEND { 505c57c3a9Sriastradh printf("/* Do not edit! This file was generated automagically! */\n"); 515c57c3a9Sriastradh 525c57c3a9Sriastradh printf("\nstatic const char *const address_families[] = {\n"); 535c57c3a9Sriastradh for (i = 0; i < n_afs; i++) 545c57c3a9Sriastradh printf("\t[AF_%s] = \"%s\",\n", afs[i], tolower(afs[i])); 555c57c3a9Sriastradh printf("};\n"); 565c57c3a9Sriastradh 575c57c3a9Sriastradh printf("\nstatic const char *const socket_types[] = {\n"); 585c57c3a9Sriastradh for (i = 0; i < n_socktypes; i++) 595c57c3a9Sriastradh printf("\t[SOCK_%s] = \"%s\",\n", socktypes[i], 605c57c3a9Sriastradh tolower(socktypes[i])); 615c57c3a9Sriastradh printf("};\n"); 625c57c3a9Sriastradh} 63