tables.awk revision 1.2
11.1Sriastrad#!/usr/bin/awk -f 21.1Sriastrad 31.2Sginsbach# $NetBSD: tables.awk,v 1.2 2014/02/27 01:17:13 ginsbach Exp $ 41.1Sriastrad 51.1Sriastrad# Copyright (c) 2013 The NetBSD Foundation, Inc. 61.1Sriastrad# All rights reserved. 71.1Sriastrad# 81.1Sriastrad# This code is derived from software contributed to The NetBSD Foundation 91.1Sriastrad# by Taylor R. Campbell. 101.1Sriastrad# 111.1Sriastrad# Redistribution and use in source and binary forms, with or without 121.1Sriastrad# modification, are permitted provided that the following conditions 131.1Sriastrad# are met: 141.1Sriastrad# 1. Redistributions of source code must retain the above copyright 151.1Sriastrad# notice, this list of conditions and the following disclaimer. 161.1Sriastrad# 2. Redistributions in binary form must reproduce the above copyright 171.1Sriastrad# notice, this list of conditions and the following disclaimer in the 181.1Sriastrad# documentation and/or other materials provided with the distribution. 191.1Sriastrad# 201.1Sriastrad# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 211.1Sriastrad# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 221.1Sriastrad# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 231.1Sriastrad# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 241.1Sriastrad# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251.1Sriastrad# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 261.1Sriastrad# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 271.1Sriastrad# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 281.1Sriastrad# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 291.1Sriastrad# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.1Sriastrad# POSSIBILITY OF SUCH DAMAGE. 311.1Sriastrad 321.1SriastradBEGIN { 331.1Sriastrad n_afs = 0 341.1Sriastrad n_socktypes = 0 351.1Sriastrad} 361.1Sriastrad 371.1Sriastrad!(($1 == "#define") && ($3 ~ /^[0-9]*$/)) { 381.1Sriastrad next 391.1Sriastrad} 401.1Sriastrad 411.2Sginsbach($2 ~ /^AF_[A-Z0-9_]*$/) && ($2 != "AF_MAX") { 421.1Sriastrad afs[n_afs++] = substr($2, 4) 431.1Sriastrad} 441.1Sriastrad 451.1Sriastrad$2 ~ /^SOCK_[A-Z0-9_]*$/ { 461.1Sriastrad socktypes[n_socktypes++] = substr($2, 6) 471.1Sriastrad} 481.1Sriastrad 491.1SriastradEND { 501.1Sriastrad printf("/* Do not edit! This file was generated automagically! */\n"); 511.1Sriastrad 521.1Sriastrad printf("\nstatic const char *const address_families[] = {\n"); 531.1Sriastrad for (i = 0; i < n_afs; i++) 541.1Sriastrad printf("\t[AF_%s] = \"%s\",\n", afs[i], tolower(afs[i])); 551.1Sriastrad printf("};\n"); 561.1Sriastrad 571.1Sriastrad printf("\nstatic const char *const socket_types[] = {\n"); 581.1Sriastrad for (i = 0; i < n_socktypes; i++) 591.1Sriastrad printf("\t[SOCK_%s] = \"%s\",\n", socktypes[i], 601.1Sriastrad tolower(socktypes[i])); 611.1Sriastrad printf("};\n"); 621.1Sriastrad} 63