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