1# $OpenBSD: devlist2h.awk,v 1.6 2004/04/07 18:24:19 mickey Exp $ 2 3# 4# Copyright (c) 1998-2003 Michael Shalayeff 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22# SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26# THE POSSIBILITY OF SUCH DAMAGE. 27# 28 29BEGIN { 30 ncpu = 0; 31 cpuh="cpudevs.h"; 32 cpud="cpudevs_data.h"; 33 SUBSEP = "_"; 34} 35 36/^[ \t]*$/ {next} 37 38/^[ \t]*\/\*/ {busted++} 39 40/^[ \t]*#/ {next} 41 42busted { 43 cp = match($0, /\*\//); 44 if(!cp) { 45 next; 46 } else if (cp + 1 == length($0)) { 47 busted = 0; 48 next; 49 } else { 50 sub(/.*\*\//, ""); 51 busted = 0; 52 } 53} 54 55# first line is rcsid, beware 56NR == 1 { 57 VERSION = $0; 58 gsub("\\$", "", VERSION); 59 60 printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \ 61 " * generated from:\n *\t%s\n */\n\n", VERSION) > cpud; 62 printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \ 63 " * generated from:\n *\t%s\n */\n\n", VERSION) > cpuh; 64} 65 66$1 == "type" { 67 printf("#define\tHPPA_TYPE_%s\t%s\n", toupper($2), $3) > cpuh; 68 types[tolower($2)] = toupper($2); 69 next; 70} 71 72NR > 1 { 73 if (tolower($1) in types) { 74 printf("#define\tHPPA_%s_%s\t%s\n", toupper($1), 75 toupper($2), $3) > cpuh; 76 printf("{HPPA_TYPE_%s,\tHPPA_%s_%s,\t\"", toupper($1), 77 toupper($1), toupper($2), $3) > cpud; 78 f = 4; 79 while (f <= NF) { 80 sub(/[ \t]*/, "", $f); 81 ep = match($f, /\*\//); 82 if (busted && !ep) { 83 f++; 84 continue; 85 } 86 if (match($f, /\/\*/)) { 87 if (ep) { 88 sub(/\/\*/, "", $f); 89 } else { 90 sub(/\/\*.*$/, "", $f); 91 busted++; 92 } 93 } 94 if (ep) { 95 gsub(/^.*\*\//, "", $f); 96 busted = 0; 97 } 98 if (length($f)) { 99 if (f > 4) 100 printf (" ") > cpud; 101 printf ("%s", $f) > cpud; 102 } 103 f++; 104 } 105 printf("\" },\n") > cpud; 106 } else { 107 printf("WHA at line %d\n", NR); 108 exit(1); 109 } 110} 111 112END { 113 if (busted) { 114 print("unterminated comment at the EOF\n"); 115 exit(1); 116 } 117 printf("{ -1 }\n") > cpud; 118} 119 120