From f4b1a2dd435507860e8461d7d08cb711d7494f22 Mon Sep 17 00:00:00 2001 From: Oldes Huhuman Date: Fri, 19 Jul 2024 16:43:20 +0200 Subject: [PATCH] FEAT: allow to use `word!` as a name of scheme in some port actions resolves: https://github.com/Oldes/Rebol-issues/issues/826 --- src/boot/actions.reb | 8 ++++---- src/core/t-word.c | 8 ++++++++ src/tests/units/checksum-test.r3 | 7 +++++++ src/tests/units/port-test.r3 | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/boot/actions.reb b/src/boot/actions.reb index a1c530f6e0..850c85ee4d 100644 --- a/src/boot/actions.reb +++ b/src/boot/actions.reb @@ -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} @@ -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)} @@ -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!] @@ -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 **" ] diff --git a/src/core/t-word.c b/src/core/t-word.c index 073ac7df02..4772630f4d 100644 --- a/src/core/t-word.c +++ b/src/core/t-word.c @@ -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); } diff --git a/src/tests/units/checksum-test.r3 b/src/tests/units/checksum-test.r3 index 17dbccb082..7072973f0b 100644 --- a/src/tests/units/checksum-test.r3 +++ b/src/tests/units/checksum-test.r3 @@ -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 diff --git a/src/tests/units/port-test.r3 b/src/tests/units/port-test.r3 index 8ebfb2bccf..6c3ad3d2ab 100644 --- a/src/tests/units/port-test.r3 +++ b/src/tests/units/port-test.r3 @@ -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=== ] @@ -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=== ] @@ -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"