Skip to content

Commit

Permalink
FEAT: allow to use word! as a name of scheme in some port actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 19, 2024
1 parent 5ebb529 commit f4b1a2d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/boot/actions.reb
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ delete: action [

open: action [
{Opens a port; makes a new port from a specification if necessary.}
spec [port! file! url! block!]
spec [port! file! url! block! word!]
/new {Create new file - if it exists, reset it (truncate)}
/read {Open for read access}
/write {Open for write access}
Expand All @@ -413,7 +413,7 @@ close: action [

read: action [
{Read from a file, URL, or other port.}
source [port! file! url! block!]
source [port! file! url! block! word!]
/part {Partial read a given number of units (source relative)}
length [number!]
/seek {Read from a specific position (source relative)}
Expand All @@ -428,7 +428,7 @@ read: action [

write: action [
{Writes to a file, URL, or port - auto-converts text strings.}
destination [port! file! url! block!]
destination [port! file! url! block! word!]
data {Data to write (non-binary converts to UTF-8)}
/part {Partial write a given number of units}
length [number!]
Expand All @@ -451,7 +451,7 @@ open?: action [

query: action [
{Returns information about target if possible.}
target [port! file! url! block! vector! date! handle!]
target [port! file! url! block! vector! date! handle! word!]
field [word! block! none! datatype!] "NONE will return valid modes for target type"
/mode "** DEPRECATED **"
]
Expand Down
8 changes: 8 additions & 0 deletions src/core/t-word.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
}
break;

case A_OPEN:
case A_READ:
case A_WRITE:
case A_QUERY:
// Support for port: OPEN 'console, READ 'clipboard etc..
// The word is used as a name of the scheme
return T_Port(ds, action);

default:
Trap_Action(type, action);
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/units/checksum-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ Rebol [
port: open checksum:md5
--assert 'md5 = port/spec/method

;; using just a name of the scheme...
;@@ https://github.com/Oldes/Rebol-issues/issues/826
--assert all [
port? try [port: open 'checksum]
'md5 = port/spec/method
]

--test-- "checksum-port-sha1"
port: open checksum:sha1
sum1: checksum bin 'sha1
Expand Down
19 changes: 19 additions & 0 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,14 @@ if system/platform = 'Windows [
write clipboard:// append copy "" ch
--assert (to binary! ch) = to binary! read clipboard://
]
--test-- "Using just a name of the scheme"
;@@ https://github.com/Oldes/Rebol-issues/issues/826
txt: "hello"
--assert all [
port? try [write 'clipboard txt]
txt = try [read 'clipboard]
txt = try [read open 'clipboard]
]

===end-group===
]
Expand Down Expand Up @@ -696,6 +704,12 @@ if all [
= m: query system/ports/input none
--assert block? v: query system/ports/input m
--assert 8 = length? v
--test-- "Using just a name of the console scheme"
;@@ https://github.com/Oldes/Rebol-issues/issues/826
--assert all [
port? try [p: open 'console]
close p
]
===end-group===
]

Expand All @@ -706,6 +720,11 @@ if all [
;@@ https://github.com/Oldes/Rebol-issues/issues/1935
--test-- "read dns://"
--assert string? try [probe read dns://] ;- no crash!

--test-- "Using just a name of the dns scheme"
;@@ https://github.com/Oldes/Rebol-issues/issues/826
--assert string? try [read 'dns]

--test-- "read dns://8.8.8.8"
--assert "dns.google" = try [probe read dns://8.8.8.8]
--test-- "read dns://google.com"
Expand Down

0 comments on commit f4b1a2d

Please sign in to comment.