PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/freebsd5/sys/boot/forth/pnp.4th

https://github.com/kame/kame
Forth | 172 lines | 158 code | 14 blank | 0 comment | 6 complexity | 35e4779dff0e9eb37af60f4d25a4b618 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. \ Copyright (c) 2000 Daniel C. Sobral <dcs@freebsd.org>
  2. \ All rights reserved.
  3. \
  4. \ Redistribution and use in source and binary forms, with or without
  5. \ modification, are permitted provided that the following conditions
  6. \ are met:
  7. \ 1. Redistributions of source code must retain the above copyright
  8. \ notice, this list of conditions and the following disclaimer.
  9. \ 2. Redistributions in binary form must reproduce the above copyright
  10. \ notice, this list of conditions and the following disclaimer in the
  11. \ documentation and/or other materials provided with the distribution.
  12. \
  13. \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. \ SUCH DAMAGE.
  24. \
  25. \ $FreeBSD: src/sys/boot/forth/pnp.4th,v 1.2 2001/12/11 00:49:34 jhb Exp $
  26. pnpdevices drop
  27. : enumerate
  28. pnphandlers begin
  29. dup @
  30. while
  31. ." Probing " dup @ pnph.name @ dup strlen type ." ..." cr
  32. 0 over @ pnph.enumerate @ ccall drop
  33. cell+
  34. repeat
  35. ;
  36. : summary
  37. ." PNP scan summary:" cr
  38. pnpdevices stqh_first @
  39. begin
  40. dup
  41. while
  42. dup pnpi.ident stqh_first @ pnpid.ident @ dup strlen type
  43. dup pnpi.desc @ ?dup if
  44. ." : "
  45. dup strlen type
  46. then
  47. cr
  48. pnpi.link stqe_next @
  49. repeat
  50. drop
  51. ;
  52. : compare-pnpid ( addr addr' -- flag )
  53. begin
  54. over c@ over c@ <> if drop drop false exit then
  55. over c@ over c@ and
  56. while
  57. char+ swap char+ swap
  58. repeat
  59. c@ swap c@ or 0=
  60. ;
  61. : search-pnpid ( id -- flag )
  62. >r
  63. pnpdevices stqh_first @
  64. begin ( pnpinfo )
  65. dup
  66. while
  67. dup pnpi.ident stqh_first @
  68. begin ( pnpinfo pnpident )
  69. dup pnpid.ident @ r@ compare-pnpid
  70. if
  71. r> drop
  72. \ XXX Temporary debugging message
  73. ." Found " pnpid.ident @ dup strlen type
  74. pnpi.desc @ ?dup if
  75. ." : " dup strlen type
  76. then cr
  77. \ drop drop
  78. true
  79. exit
  80. then
  81. pnpid.link stqe_next @
  82. ?dup 0=
  83. until
  84. pnpi.link stqe_next @
  85. repeat
  86. r> drop
  87. drop
  88. false
  89. ;
  90. : skip-space ( addr -- addr' )
  91. begin
  92. dup c@ bl =
  93. over c@ 9 = or
  94. while
  95. char+
  96. repeat
  97. ;
  98. : skip-to-space ( addr -- addr' )
  99. begin
  100. dup c@ bl <>
  101. over c@ 9 <> and
  102. over c@ and
  103. while
  104. char+
  105. repeat
  106. ;
  107. : premature-end? ( addr -- addr flag )
  108. postpone dup postpone c@ postpone 0=
  109. postpone if postpone exit postpone then
  110. ; immediate
  111. 0 value filename
  112. 0 value timestamp
  113. 0 value id
  114. only forth also support-functions
  115. : (load) load ;
  116. : check-pnpid ( -- )
  117. line_buffer .addr @
  118. \ Search for filename
  119. skip-space premature-end?
  120. dup to filename
  121. \ Search for end of filename
  122. skip-to-space premature-end?
  123. 0 over c! char+
  124. \ Search for timestamp
  125. skip-space premature-end?
  126. dup to timestamp
  127. skip-to-space premature-end?
  128. 0 over c! char+
  129. \ Search for ids
  130. begin
  131. skip-space premature-end?
  132. dup to id
  133. skip-to-space dup c@ >r
  134. 0 over c! char+
  135. id search-pnpid if
  136. filename dup strlen 1 ['] (load) catch if
  137. drop drop drop
  138. ." Error loading " filename dup strlen type cr
  139. then
  140. r> drop exit
  141. then
  142. r> 0=
  143. until
  144. ;
  145. : load-pnp
  146. 0 to end_of_file?
  147. reset_line_reading
  148. s" /boot/pnpid.conf" O_RDONLY fopen fd !
  149. fd @ -1 <> if
  150. begin
  151. end_of_file? 0=
  152. while
  153. read_line
  154. check-pnpid
  155. repeat
  156. fd @ fclose
  157. then
  158. ;