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

/fth/filefind.fth

https://github.com/cataska/pforth
Forth | 119 lines | 111 code | 8 blank | 0 comment | 3 complexity | 1eeba426983fe63250869b3e614426a5 MD5 | raw file
  1. \ @(#) filefind.fth 98/01/26 1.2
  2. \ FILE? ( <name> -- , report which file this Forth word was defined in )
  3. \
  4. \ FILE? looks for ::::Filename and ;;;; in the dictionary
  5. \ that have been left by INCLUDE. It figures out nested
  6. \ includes and reports each file that defines the word.
  7. \
  8. \ Author: Phil Burk
  9. \ Copyright 1992 Phil Burk
  10. \
  11. \ 00001 PLB 2/21/92 Handle words from kernel or keyboard.
  12. \ Support EACH.FILE?
  13. \ 961213 PLB Port to pForth.
  14. ANEW TASK-FILEFIND.FTH
  15. : BE@ { addr | val -- val , fetch from unaligned address in BigEndian order }
  16. 4 0
  17. DO
  18. addr i + c@
  19. val 8 lshift or -> val
  20. LOOP
  21. val
  22. ;
  23. : BE! { val addr -- , store to unaligned address in BigEndian order }
  24. 4 0
  25. DO
  26. val 3 i - 8 * rshift
  27. addr i + c!
  28. LOOP
  29. ;
  30. : BEW@ { addr -- , fetch word from unaligned address in BigEndian order }
  31. addr c@ 8 lshift
  32. addr 1+ c@ OR
  33. ;
  34. : BEW! { val addr -- , store word to unaligned address in BigEndian order }
  35. val 8 rshift addr c!
  36. val addr 1+ c!
  37. ;
  38. \ scan dictionary from NFA for filename
  39. : F?.SEARCH.NFA { nfa | dpth stoploop keyb nfa0 -- addr count }
  40. 0 -> dpth
  41. 0 -> stoploop
  42. 0 -> keyb
  43. nfa -> nfa0
  44. BEGIN
  45. nfa prevname -> nfa
  46. nfa 0>
  47. IF
  48. nfa 1+ be@
  49. CASE
  50. $ 3a3a3a3a ( :::: )
  51. OF
  52. dpth 0=
  53. IF
  54. nfa count 31 and
  55. 4 - swap 4 + swap
  56. true -> stoploop
  57. ELSE
  58. -1 dpth + -> dpth
  59. THEN
  60. ENDOF
  61. $ 3b3b3b3b ( ;;;; )
  62. OF
  63. 1 dpth + -> dpth
  64. true -> keyb \ maybe from keyboard
  65. ENDOF
  66. ENDCASE
  67. ELSE
  68. true -> stoploop
  69. keyb
  70. IF
  71. " keyboard"
  72. ELSE
  73. " 'C' kernel"
  74. THEN
  75. count
  76. THEN
  77. stoploop
  78. UNTIL
  79. ;
  80. : FINDNFA.FROM { $name start_nfa -- nfa true | $word false }
  81. context @ >r
  82. start_nfa context !
  83. $name findnfa
  84. r> context !
  85. ;
  86. \ Search entire dictionary for all occurences of named word.
  87. : FILE? { | $word nfa done? -- , take name from input }
  88. 0 -> done?
  89. bl word -> $word
  90. $word findnfa
  91. IF ( -- nfa )
  92. $word count type ." from:" cr
  93. -> nfa
  94. BEGIN
  95. nfa f?.search.nfa ( addr cnt )
  96. nfa name> 12 .r \ print xt
  97. 4 spaces type cr
  98. nfa prevname dup -> nfa
  99. 0>
  100. IF
  101. $word nfa findnfa.from \ search from one behind found nfa
  102. swap -> nfa
  103. not
  104. ELSE
  105. true
  106. THEN
  107. UNTIL
  108. ELSE ( -- $word )
  109. count type ." not found!" cr
  110. THEN
  111. ;