File: filefind.fth

package info (click to toggle)
pforth 21-11
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 820 kB
  • ctags: 873
  • sloc: ansic: 5,050; makefile: 102
file content (102 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
\ @(#) filefind.fth 98/01/26 1.2
\ FILE?  ( <name> -- , report which file this Forth word was defined in )
\
\ FILE? looks for ::::Filename and ;;;; in the dictionary
\ that have been left by INCLUDE.  It figures out nested
\ includes and reports each file that defines the word.
\
\ Author: Phil Burk
\ Copyright 1992 Phil Burk
\
\ 00001 PLB 2/21/92 Handle words from kernel or keyboard.
\		Support EACH.FILE?
\ 961213 PLB Port to pForth.

ANEW TASK-FILEFIND.FTH

: ODD@ { addr | val -- val , fetch from odd aligned address, IBM PCs??? }
	4 0
	DO
		addr i + c@
		val 8 lshift or -> val
	LOOP
	val
;

\ scan dictionary from NFA for filename
: F?.SEARCH.NFA { nfa | dpth stoploop keyb nfa0 -- addr count }
	0 -> dpth
	0 -> stoploop
	0 -> keyb
	nfa -> nfa0
	BEGIN
		nfa prevname -> nfa
		nfa 0>
		IF
			nfa 1+ odd@
			CASE
				$ 3a3a3a3a ( :::: )
				OF
					dpth 0=
					IF
						nfa count 31 and
						4 - swap 4 + swap
						true -> stoploop
					ELSE
						-1 dpth + -> dpth
					THEN
				ENDOF
				$ 3b3b3b3b ( ;;;; )
				OF
						1 dpth + -> dpth
						true -> keyb     \ maybe from keyboard
				ENDOF
			ENDCASE
		ELSE
			true -> stoploop
			keyb
			IF
				" keyboard"
			ELSE
				" 'C' kernel"
			THEN
			count
		THEN
		stoploop
	UNTIL
;

: FINDNFA.FROM { $name start_nfa -- nfa true | $word false }
	context @ >r
	start_nfa context !
	$name findnfa
	r> context !
;

\ Search entire dictionary for all occurences of named word.
: FILE? {  | $word nfa done? -- , take name from input }
	0 -> done?
	bl word -> $word
	$word findnfa
	IF  ( -- nfa )
		$word count type ."  from:" cr
		-> nfa
		BEGIN
			nfa f?.search.nfa ( addr cnt )
			nfa name> 12 .r   \ print xt
			4 spaces type cr
			nfa prevname dup -> nfa
			0>
			IF
				$word nfa findnfa.from  \ search from one behind found nfa
				swap -> nfa
				not
			ELSE
				true
			THEN
		UNTIL
	ELSE ( -- $word )
		count type ."  not found!" cr
	THEN
;