-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathprovides.fs
78 lines (65 loc) · 2.45 KB
/
provides.fs
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
\ need database generator
\ Authors: Bernd Paysan
\ Copyright (C) 2024 Free Software Foundation, Inc.
\ This file is part of Gforth.
\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.
\ create database for what sources provide
$variable provider-file
10 stack: providers
?: >abspath ( addr u -- addr' u' )
over c@ '/' <> IF
[: {: | pwd[ $1000 ] :} pwd[ $1000 get-dir
type '/' emit type ;] $tmp
compact-filename
THEN ;
: <no-provides ( -- )
\G lines that aren't provided by some upper level
0 provider-file !@ providers >stack ;
: <provides ( -- )
\G lines that are provided by the current file
<no-provides sourcefilename >abspath provider-file $! ;
: provides> ( -- )
\G end of a provides/no-provides block
provider-file $free providers stack> provider-file ! ;
: source-provider ( -- addr u )
\G what's the source provider's file name?
provider-file $@ 2dup d0= IF 2drop sourcefilename >abspath THEN ;
$variable last-provider
0 Value provides.fd
: provides-header ( -- )
provides.fd 0= latest 0= or get-current >voc xt? 0= or ?EXIT
[: source-provider 2dup last-provider $@ str= 0=
IF
2dup last-provider $!
cr type ':' emit
ELSE 2drop
THEN
space
get-current forth-wordlist <> IF
get-current >voc name>string type ':' emit
THEN
latest name>string type
;] provides.fd outfile-execute ;
: provides-file ( -- addr u )
${GFORTH_PROVIDES} dup ?EXIT
${XDG_DATA_HOME} dup 0= IF 2drop "~/.local/share" THEN
[: type ." /gforth/provides" ;] $tmp ;
\ to generate the database, call
\ gforth need.fs -e 'provides' <files>
\ and to add more infos to the data base
\ gforth need.fs -e 'provides+' <more-files>
: provides ( -- )
provides-file w/o create-file throw to provides.fd
['] provides-header IS header-extra ;
: provides+ ( -- )
provides-file w/o open-file throw to provides.fd
['] provides-header IS header-extra ;