remove ?resource-path and resource-exists?

db4
erg 2008-03-26 23:47:51 -05:00
parent 5bab5de16d
commit 15c68a23f8
14 changed files with 36 additions and 38 deletions

View File

@ -39,7 +39,7 @@ vocabs.loader system debugger continuations ;
[ [
"resource:core/bootstrap/stage2.factor" "resource:core/bootstrap/stage2.factor"
dup resource-exists? [ dup exists? [
[ run-file ] [ run-file ]
[ [
:c :c

View File

@ -20,9 +20,6 @@ ARTICLE: "pathnames" "Pathname manipulation"
{ $subsection file-name } { $subsection file-name }
{ $subsection last-path-separator } { $subsection last-path-separator }
{ $subsection append-path } { $subsection append-path }
"Pathnames relative to Factor's install directory:"
{ $subsection resource-path }
{ $subsection ?resource-path }
"Pathnames relative to Factor's temporary files directory:" "Pathnames relative to Factor's temporary files directory:"
{ $subsection temp-directory } { $subsection temp-directory }
{ $subsection temp-file } { $subsection temp-file }
@ -248,12 +245,6 @@ HELP: resource-path
{ $values { "path" "a pathname string" } { "newpath" "a pathname string" } } { $values { "path" "a pathname string" } { "newpath" "a pathname string" } }
{ $description "Resolve a path relative to the Factor source code location. This first checks if the " { $link resource-path } " variable is set to a path, and if not, uses the parent directory of the current image." } ; { $description "Resolve a path relative to the Factor source code location. This first checks if the " { $link resource-path } " variable is set to a path, and if not, uses the parent directory of the current image." } ;
HELP: ?resource-path
{ $values { "path" "a pathname string" } { "newpath" "a string" } }
{ $description "If the path is prefixed with " { $snippet "\"resource:\"" } ", prepends the resource path." } ;
{ resource-path ?resource-path } related-words
HELP: pathname HELP: pathname
{ $class-description "Class of pathname presentations. Path name presentations can be created by calling " { $link <pathname> } ". Instances can be passed to " { $link write-object } " to output a clickable pathname." } ; { $class-description "Class of pathname presentations. Path name presentations can be created by calling " { $link <pathname> } ". Instances can be passed to " { $link write-object } " to output a clickable pathname." } ;

View File

@ -205,3 +205,7 @@ io.encodings.utf8 ;
[ "bar/baz/foo" ] [ "bar/baz" ".///foo" append-path ] unit-test [ "bar/baz/foo" ] [ "bar/baz" ".///foo" append-path ] unit-test
[ "bar/foo" ] [ "bar/baz" "./..//foo" append-path ] unit-test [ "bar/foo" ] [ "bar/baz" "./..//foo" append-path ] unit-test
[ "bar/foo" ] [ "bar/baz" "./../././././././///foo" append-path ] unit-test [ "bar/foo" ] [ "bar/baz" "./../././././././///foo" append-path ] unit-test
[ t ] [ "resource:core" absolute-path? ] unit-test
[ t ] [ "/foo" absolute-path? ] unit-test
[ f ] [ "" absolute-path? ] unit-test

View File

@ -99,7 +99,12 @@ ERROR: no-parent-directory path ;
PRIVATE> PRIVATE>
: absolute-path? ( path -- ? ) : absolute-path? ( path -- ? )
dup empty? [ drop f ] [ first path-separator? ] if ; {
{ [ dup empty? ] [ f ] }
{ [ dup "resource:" head? ] [ t ] }
{ [ dup first path-separator? ] [ t ] }
{ [ t ] [ f ] }
} cond nip ;
: append-path ( str1 str2 -- str ) : append-path ( str1 str2 -- str )
{ {
@ -258,12 +263,6 @@ DEFER: copy-tree-into
"resource-path" get [ image parent-directory ] unless* "resource-path" get [ image parent-directory ] unless*
prepend-path ; prepend-path ;
: ?resource-path ( path -- newpath )
"resource:" ?head [ left-trim-separators resource-path ] when ;
: resource-exists? ( path -- ? )
?resource-path exists? ;
: temp-directory ( -- path ) : temp-directory ( -- path )
"temp" resource-path "temp" resource-path
dup exists? not dup exists? not
@ -273,7 +272,12 @@ DEFER: copy-tree-into
: temp-file ( name -- path ) temp-directory prepend-path ; : temp-file ( name -- path ) temp-directory prepend-path ;
M: object normalize-pathname ( path -- path' ) M: object normalize-pathname ( path -- path' )
current-directory get prepend-path ; "resource:" ?head [
left-trim-separators resource-path
normalize-pathname
] [
current-directory get prepend-path
] if ;
! Pathname presentations ! Pathname presentations
TUPLE: pathname string ; TUPLE: pathname string ;

View File

@ -520,7 +520,7 @@ SYMBOL: interactive-vocabs
[ [
[ [
[ parsing-file ] keep [ parsing-file ] keep
[ ?resource-path utf8 <file-reader> ] keep [ utf8 <file-reader> ] keep
parse-stream parse-stream
] with-compiler-errors ] with-compiler-errors
] [ ] [
@ -532,7 +532,7 @@ SYMBOL: interactive-vocabs
[ dup parse-file call ] assert-depth drop ; [ dup parse-file call ] assert-depth drop ;
: ?run-file ( path -- ) : ?run-file ( path -- )
dup resource-exists? [ run-file ] [ drop ] if ; dup exists? [ run-file ] [ drop ] if ;
: bootstrap-file ( path -- ) : bootstrap-file ( path -- )
[ parse-file % ] [ run-file ] if-bootstrapping ; [ parse-file % ] [ run-file ] if-bootstrapping ;

View File

@ -48,7 +48,7 @@ uses definitions ;
: reset-checksums ( -- ) : reset-checksums ( -- )
source-files get [ source-files get [
swap ?resource-path dup exists? [ swap dup exists? [
utf8 file-lines swap record-checksum utf8 file-lines swap record-checksum
] [ 2drop ] if ] [ 2drop ] if
] assoc-each ; ] assoc-each ;

View File

@ -25,7 +25,7 @@ V{
: vocab-dir? ( root name -- ? ) : vocab-dir? ( root name -- ? )
over [ over [
".factor" vocab-dir+ append-path resource-exists? ".factor" vocab-dir+ append-path exists?
] [ ] [
2drop f 2drop f
] if ; ] if ;

View File

@ -26,7 +26,7 @@ SYMBOL: edit-hook
: edit-location ( file line -- ) : edit-location ( file line -- )
edit-hook get [ edit-hook get [
>r >r ?resource-path r> r> call call
] [ ] [
no-edit-hook edit-location no-edit-hook edit-location
] if* ; ] if* ;
@ -39,7 +39,7 @@ SYMBOL: edit-hook
: :edit ( -- ) : :edit ( -- )
error get delegates [ parse-error? ] find-last nip [ error get delegates [ parse-error? ] find-last nip [
dup parse-error-file source-file-path ?resource-path dup parse-error-file source-file-path
swap parse-error-line edit-location swap parse-error-line edit-location
] when* ; ] when* ;

View File

@ -9,7 +9,7 @@ IN: http.server.templating.fhtml.tests
[ [
".fhtml" append [ run-template ] with-string-writer ".fhtml" append [ run-template ] with-string-writer
] keep ] keep
".html" append ?resource-path utf8 file-contents = ; ".html" append utf8 file-contents = ;
[ t ] [ "example" test-template ] unit-test [ t ] [ "example" test-template ] unit-test
[ t ] [ "bug" test-template ] unit-test [ t ] [ "bug" test-template ] unit-test

View File

@ -83,7 +83,7 @@ DEFER: <% delimiter
templating-vocab use+ templating-vocab use+
! so that reload works properly ! so that reload works properly
dup source-file file set dup source-file file set
?resource-path utf8 file-contents utf8 file-contents
[ eval-template ] [ html-error. drop ] recover [ eval-template ] [ html-error. drop ] recover
] with-file-vocabs ] with-file-vocabs
] assert-depth ; ] assert-depth ;

View File

@ -31,7 +31,7 @@ IN: project-euler
: solution-path ( n -- str/f ) : solution-path ( n -- str/f )
number>euler "project-euler." prepend number>euler "project-euler." prepend
vocab where dup [ first ?resource-path ] when ; vocab where dup [ first ] when ;
PRIVATE> PRIVATE>

View File

@ -3,6 +3,6 @@ USING: io.encodings.ascii io.files kernel ;
: deploy-test-3 : deploy-test-3
"resource:extra/tools/deploy/test/3/3.factor" "resource:extra/tools/deploy/test/3/3.factor"
?resource-path ascii file-contents drop ; ascii file-contents drop ;
MAIN: deploy-test-3 MAIN: deploy-test-3

View File

@ -8,12 +8,12 @@ IN: tools.vocabs
: vocab-tests-file ( vocab -- path ) : vocab-tests-file ( vocab -- path )
dup "-tests.factor" vocab-dir+ vocab-append-path dup dup "-tests.factor" vocab-dir+ vocab-append-path dup
[ dup resource-exists? [ drop f ] unless ] [ drop f ] if ; [ dup exists? [ drop f ] unless ] [ drop f ] if ;
: vocab-tests-dir ( vocab -- paths ) : vocab-tests-dir ( vocab -- paths )
dup vocab-dir "tests" append-path vocab-append-path dup [ dup vocab-dir "tests" append-path vocab-append-path dup [
dup resource-exists? [ dup exists? [
dup ?resource-path directory keys dup directory keys
[ ".factor" tail? ] subset [ ".factor" tail? ] subset
[ append-path ] with map [ append-path ] with map
] [ drop f ] if ] [ drop f ] if
@ -34,7 +34,7 @@ IN: tools.vocabs
: source-modified? ( path -- ? ) : source-modified? ( path -- ? )
dup source-files get at [ dup source-files get at [
dup source-file-path ?resource-path dup source-file-path
dup exists? [ dup exists? [
utf8 file-lines lines-crc32 utf8 file-lines lines-crc32
swap source-file-checksum = not swap source-file-checksum = not
@ -42,7 +42,7 @@ IN: tools.vocabs
2drop f 2drop f
] if ] if
] [ ] [
resource-exists? exists?
] ?if ; ] ?if ;
: modified ( seq quot -- seq ) : modified ( seq quot -- seq )
@ -104,15 +104,14 @@ SYMBOL: sources-changed?
"" refresh f sources-changed? set-global ; "" refresh f sources-changed? set-global ;
MEMO: (vocab-file-contents) ( path -- lines ) MEMO: (vocab-file-contents) ( path -- lines )
?resource-path dup exists? dup exists? [ utf8 file-lines ] [ drop f ] if ;
[ utf8 file-lines ] [ drop f ] if ;
: vocab-file-contents ( vocab name -- seq ) : vocab-file-contents ( vocab name -- seq )
vocab-append-path dup [ (vocab-file-contents) ] when ; vocab-append-path dup [ (vocab-file-contents) ] when ;
: set-vocab-file-contents ( seq vocab name -- ) : set-vocab-file-contents ( seq vocab name -- )
dupd vocab-append-path [ dupd vocab-append-path [
?resource-path utf8 set-file-lines utf8 set-file-lines
\ (vocab-file-contents) reset-memoized \ (vocab-file-contents) reset-memoized
] [ ] [
"The " swap vocab-name "The " swap vocab-name
@ -171,7 +170,7 @@ M: vocab-link summary vocab-summary ;
directory [ second ] subset keys natural-sort ; directory [ second ] subset keys natural-sort ;
: (all-child-vocabs) ( root name -- vocabs ) : (all-child-vocabs) ( root name -- vocabs )
[ vocab-dir append-path ?resource-path subdirs ] keep [ vocab-dir append-path subdirs ] keep
dup empty? [ dup empty? [
drop drop
] [ ] [

View File

@ -62,7 +62,7 @@ M: freetype-renderer free-fonts ( world -- )
} at ; } at ;
: ttf-path ( name -- string ) : ttf-path ( name -- string )
"resource:fonts/" swap ".ttf" 3append ?resource-path ; "resource:fonts/" swap ".ttf" 3append ;
: (open-face) ( path length -- face ) : (open-face) ( path length -- face )
#! We use FT_New_Memory_Face, not FT_New_Face, since #! We use FT_New_Memory_Face, not FT_New_Face, since