devlist2h.awk 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #! /usr/bin/awk -f
  2. # $OpenBSD: devlist2h.awk,v 1.4 2000/02/01 16:54:41 fgsch Exp $
  3. # $NetBSD: devlist2h.awk,v 1.2 1998/07/22 11:47:13 christos Exp $
  4. #
  5. # Copyright (c) 1998, Christos Zoulas
  6. # Copyright (c) 1995, 1996 Christopher G. Demetriou
  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. # 3. All advertising materials mentioning features or use of this software
  18. # must display the following acknowledgement:
  19. # This product includes software developed by Christopher G. Demetriou.
  20. # This product includes software developed by Christos Zoulas
  21. # 4. The name of the author(s) may not be used to endorse or promote products
  22. # derived from this software without specific prior written permission
  23. #
  24. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  25. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  26. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  29. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. #
  35. function collectline(f, line) {
  36. oparen = 0
  37. line = ""
  38. while (f <= NF) {
  39. if ($f == "#") {
  40. line = line "("
  41. oparen = 1
  42. f++
  43. continue
  44. }
  45. if (oparen) {
  46. line = line $f
  47. if (f < NF)
  48. line = line " "
  49. f++
  50. continue
  51. }
  52. line = line $f
  53. if (f < NF)
  54. line = line " "
  55. f++
  56. }
  57. if (oparen)
  58. line = line ")"
  59. return line
  60. }
  61. BEGIN {
  62. nproducts = nvendors = 0
  63. hfile="pcmciadevs.h"
  64. }
  65. NR == 1 {
  66. VERSION = $0
  67. gsub("\\$", "", VERSION)
  68. printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
  69. printf("/*\n") > hfile
  70. printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
  71. > hfile
  72. printf(" *\n") > hfile
  73. printf(" * generated from:\n") > hfile
  74. printf(" *\t%s\n", VERSION) > hfile
  75. printf(" */\n") > hfile
  76. next
  77. }
  78. $1 == "vendor" {
  79. nvendors++
  80. vendorindex[$2] = nvendors; # record index for this name, for later.
  81. vendors[nvendors, 1] = $2; # name
  82. vendors[nvendors, 2] = $3; # id
  83. printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
  84. vendors[nvendors, 2]) > hfile
  85. vendors[nvendors, 3] = collectline(4, line)
  86. printf("/* %s */\n", vendors[nvendors, 3]) > hfile
  87. next
  88. }
  89. $1 == "product" {
  90. nproducts++
  91. products[nproducts, 1] = $2; # vendor name
  92. products[nproducts, 2] = $3; # product id
  93. products[nproducts, 3] = $4; # id
  94. f = 5;
  95. if ($4 == "{") {
  96. products[nproducts, 3] = "PCMCIA_PRODUCT_INVALID"
  97. z = "{ "
  98. for (i = 0; i < 4; i++) {
  99. if (f <= NF) {
  100. gsub("&sp", " ", $f)
  101. gsub("&tab", "\t", $f)
  102. gsub("&nl", "\n", $f)
  103. z = z $f " "
  104. f++
  105. }
  106. else {
  107. if (i == 3)
  108. z = z "NULL "
  109. else
  110. z = z "NULL, "
  111. }
  112. }
  113. products[nproducts, 4] = z $f
  114. f++
  115. }
  116. else {
  117. products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
  118. }
  119. printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
  120. products[nproducts, 1], products[nproducts, 2],
  121. products[nproducts, 4]) > hfile
  122. printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
  123. products[nproducts, 2], products[nproducts, 3]) > hfile
  124. # products[nproducts, 5] = collectline(f, line)
  125. #
  126. # printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n",
  127. # products[nproducts, 1], products[nproducts, 2],
  128. # products[nproducts, 5]) > hfile
  129. next
  130. }
  131. {
  132. if ($0 == "")
  133. blanklines++
  134. print $0 > hfile
  135. }