Commit | Line | Data |
---|---|---|
8e9db35f PB |
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 | ||
15 | ANEW TASK-FILEFIND.FTH | |
16 | ||
17 | : BE@ { addr | val -- val , fetch from unaligned address in BigEndian order } | |
18 | 4 0 | |
19 | DO | |
20 | addr i + c@ | |
21 | val 8 lshift or -> val | |
22 | LOOP | |
23 | val | |
24 | ; | |
25 | ||
26 | : BE! { val addr -- , store to unaligned address in BigEndian order } | |
27 | 4 0 | |
28 | DO | |
29 | val 3 i - 8 * rshift | |
30 | addr i + c! | |
31 | LOOP | |
32 | ; | |
33 | : BEW@ { addr -- , fetch word from unaligned address in BigEndian order } | |
34 | addr c@ 8 lshift | |
35 | addr 1+ c@ OR | |
36 | ; | |
37 | ||
38 | : BEW! { val addr -- , store word to unaligned address in BigEndian order } | |
39 | val 8 rshift addr c! | |
40 | val addr 1+ c! | |
41 | ; | |
42 | ||
43 | \ scan dictionary from NFA for filename | |
44 | : F?.SEARCH.NFA { nfa | dpth stoploop keyb nfa0 -- addr count } | |
45 | 0 -> dpth | |
46 | 0 -> stoploop | |
47 | 0 -> keyb | |
48 | nfa -> nfa0 | |
49 | BEGIN | |
50 | nfa prevname -> nfa | |
51 | nfa 0> | |
52 | IF | |
53 | nfa 1+ be@ | |
54 | CASE | |
55 | $ 3a3a3a3a ( :::: ) | |
56 | OF | |
57 | dpth 0= | |
58 | IF | |
59 | nfa count 31 and | |
60 | 4 - swap 4 + swap | |
61 | true -> stoploop | |
62 | ELSE | |
63 | -1 dpth + -> dpth | |
64 | THEN | |
65 | ENDOF | |
66 | $ 3b3b3b3b ( ;;;; ) | |
67 | OF | |
68 | 1 dpth + -> dpth | |
69 | true -> keyb \ maybe from keyboard | |
70 | ENDOF | |
71 | ENDCASE | |
72 | ELSE | |
73 | true -> stoploop | |
74 | keyb | |
75 | IF | |
76 | " keyboard" | |
77 | ELSE | |
78 | " 'C' kernel" | |
79 | THEN | |
80 | count | |
81 | THEN | |
82 | stoploop | |
83 | UNTIL | |
84 | ; | |
85 | ||
86 | : FINDNFA.FROM { $name start_nfa -- nfa true | $word false } | |
87 | context @ >r | |
88 | start_nfa context ! | |
89 | $name findnfa | |
90 | r> context ! | |
91 | ; | |
92 | ||
93 | \ Search entire dictionary for all occurences of named word. | |
94 | : FILE? { | $word nfa done? -- , take name from input } | |
95 | 0 -> done? | |
96 | bl word -> $word | |
97 | $word findnfa | |
98 | IF ( -- nfa ) | |
99 | $word count type ." from:" cr | |
100 | -> nfa | |
101 | BEGIN | |
102 | nfa f?.search.nfa ( addr cnt ) | |
103 | nfa name> 12 .r \ print xt | |
104 | 4 spaces type cr | |
105 | nfa prevname dup -> nfa | |
106 | 0> | |
107 | IF | |
108 | $word nfa findnfa.from \ search from one behind found nfa | |
109 | swap -> nfa | |
110 | not | |
111 | ELSE | |
112 | true | |
113 | THEN | |
114 | UNTIL | |
115 | ELSE ( -- $word ) | |
116 | count type ." not found!" cr | |
117 | THEN | |
118 | ; | |
119 |