miidevs2h.awk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #! /usr/bin/awk -f
  2. # $NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:06 christos Exp $
  3. #-
  4. # SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-4-Clause
  5. #
  6. # Copyright (c) 1998 The NetBSD Foundation, Inc.
  7. # All rights reserved.
  8. #
  9. # This code is derived from software contributed to The NetBSD Foundation
  10. # by Christos Zoulas.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions
  14. # are met:
  15. # 1. Redistributions of source code must retain the above copyright
  16. # notice, this list of conditions and the following disclaimer.
  17. # 2. Redistributions in binary form must reproduce the above copyright
  18. # notice, this list of conditions and the following disclaimer in the
  19. # documentation and/or other materials provided with the distribution.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  22. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  23. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  25. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. # POSSIBILITY OF SUCH DAMAGE.
  32. #
  33. # Copyright (c) 1995, 1996 Christopher G. Demetriou
  34. # All rights reserved.
  35. #
  36. # Redistribution and use in source and binary forms, with or without
  37. # modification, are permitted provided that the following conditions
  38. # are met:
  39. # 1. Redistributions of source code must retain the above copyright
  40. # notice, this list of conditions and the following disclaimer.
  41. # 2. Redistributions in binary form must reproduce the above copyright
  42. # notice, this list of conditions and the following disclaimer in the
  43. # documentation and/or other materials provided with the distribution.
  44. # 3. All advertising materials mentioning features or use of this software
  45. # must display the following acknowledgement:
  46. # This model includes software developed by Christopher G. Demetriou.
  47. # This model includes software developed by Christos Zoulas
  48. # 4. The name of the author(s) may not be used to endorse or promote models
  49. # derived from this software without specific prior written permission
  50. #
  51. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  52. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  53. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  54. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  55. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  56. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  60. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. #
  62. # $FreeBSD$
  63. #
  64. function collectline(f, line) {
  65. oparen = 0
  66. line = ""
  67. while (f <= NF) {
  68. if ($f == "#") {
  69. line = line "("
  70. oparen = 1
  71. f++
  72. continue
  73. }
  74. if (oparen) {
  75. line = line $f
  76. if (f < NF)
  77. line = line " "
  78. f++
  79. continue
  80. }
  81. line = line $f
  82. if (f < NF)
  83. line = line " "
  84. f++
  85. }
  86. if (oparen)
  87. line = line ")"
  88. return line
  89. }
  90. BEGIN {
  91. nmodels = nouis = 0
  92. hfile="miidevs.h"
  93. }
  94. NR == 1 {
  95. VERSION = $0
  96. gsub("\\$", "", VERSION)
  97. printf("/* \$FreeBSD\$ */\n\n") > hfile
  98. printf("/*\n") > hfile
  99. printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
  100. > hfile
  101. printf(" *\n") > hfile
  102. printf(" * generated from:\n") > hfile
  103. printf(" *\t%s\n", VERSION) > hfile
  104. printf(" */\n") > hfile
  105. next
  106. }
  107. $1 == "oui" {
  108. nuios++
  109. ouiindex[$2] = nouis; # record index for this name, for later.
  110. ouis[nouis, 1] = $2; # name
  111. ouis[nouis, 2] = $3; # id
  112. printf("#define\tMII_OUI_%s\t%s\t", ouis[nouis, 1],
  113. ouis[nouis, 2]) > hfile
  114. ouis[nouis, 3] = collectline(4, line)
  115. printf("/* %s */\n", ouis[nouis, 3]) > hfile
  116. next
  117. }
  118. $1 == "model" {
  119. nmodels++
  120. models[nmodels, 1] = $2; # oui name
  121. models[nmodels, 2] = $3; # model id
  122. models[nmodels, 3] = $4; # id
  123. printf("#define\tMII_MODEL_%s_%s\t%s\n", models[nmodels, 1],
  124. models[nmodels, 2], models[nmodels, 3]) > hfile
  125. models[nmodels, 4] = collectline(5, line)
  126. printf("#define\tMII_STR_%s_%s\t\"%s\"\n",
  127. models[nmodels, 1], models[nmodels, 2],
  128. models[nmodels, 4]) > hfile
  129. next
  130. }
  131. {
  132. print $0 > hfile
  133. }