Skip to content

Commit

Permalink
FEAT: refine standard port specifications
Browse files Browse the repository at this point in the history
Originally there was `port-spec-head` which was holding also `path` and `host`, which are not needed in not file related schemes and does not looks good when listed.
  • Loading branch information
Oldes committed Feb 6, 2019
1 parent 4a7852a commit f6b2bb0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
13 changes: 10 additions & 3 deletions src/boot/sysobj.r
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,21 @@ standard: context [
title: ; user-friendly title for port
scheme: ; reference to scheme that defines this port
ref: ; reference path or url (for errors)
path: ; used for files
none ; (extended here)
]

port-spec-net: make port-spec-head [
port-spec-file: make port-spec-head [
path: none
]

port-spec-net: make port-spec-file [
host: none
port-id: 80
none
]

port-spec-checksum: make port-spec-head [
scheme: 'checksum
method: none
]

file-info: context [
Expand Down
2 changes: 1 addition & 1 deletion src/core/p-checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

spec = BLK_SKIP(port, STD_PORT_SPEC);
if (!IS_OBJECT(spec)) Trap1(RE_INVALID_SPEC, spec);
method = Obj_Value(spec, STD_PORT_SPEC_HEAD_PATH);
method = Obj_Value(spec, STD_PORT_SPEC_CHECKSUM_METHOD);
if (!method || !IS_WORD(method)) {
Trap1(RE_INVALID_SPEC, spec);
return 0; //just to make xcode analyze happy
Expand Down
2 changes: 1 addition & 1 deletion src/core/p-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
path = Obj_Value(spec, STD_PORT_SPEC_HEAD_REF);
if (!path) Trap1(RE_INVALID_SPEC, spec);

if (IS_URL(path)) path = Obj_Value(spec, STD_PORT_SPEC_HEAD_PATH);
if (IS_URL(path)) path = Obj_Value(spec, STD_PORT_SPEC_FILE_PATH);
else if (!IS_FILE(path)) Trap1(RE_INVALID_SPEC, path);

state = BLK_SKIP(port, STD_PORT_STATE); // if block, then port is open.
Expand Down
2 changes: 1 addition & 1 deletion src/core/p-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ REBINT Mode_Syms[] = {
path = Obj_Value(spec, STD_PORT_SPEC_HEAD_REF);
if (!path) Trap1(RE_INVALID_SPEC, spec);

if (IS_URL(path)) path = Obj_Value(spec, STD_PORT_SPEC_HEAD_PATH);
if (IS_URL(path)) path = Obj_Value(spec, STD_PORT_SPEC_FILE_PATH);
else if (!IS_FILE(path)) Trap1(RE_INVALID_SPEC, path);

// Get or setup internal state data:
Expand Down
33 changes: 12 additions & 21 deletions src/mezz/sys-ports.r
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,26 @@ init-schemes: func [
make-scheme [
title: "Checksum port"
info: "Possible methods: MD5, SHA1, SHA256, SHA384, SHA512"
spec: system/standard/port-spec-checksum
name: 'checksum
init: function [
port [port!]
][
spec: port/spec
meth: any [ ; using short name so I can easily make the new spec bellow
; when it would be: method: method - it would throw binding error
select spec 'meth
method: any [
select spec 'method
select spec 'host ; if scheme was opened using url type
'md5 ; default method
'md5 ; default method
]
meth: to word! meth ; in case it was not
unless find [md5 sha1 sha256 sha384 sha512] meth [
cause-error 'access 'invalid-spec meth
if any [
error? try [spec/method: to word! method] ; in case it was not
not find [md5 sha1 sha256 sha384 sha512] spec/method
][
cause-error 'access 'invalid-spec method
]
; make the spec only with relevant fields
port/spec: object [
title: spec/title
scheme: spec/scheme
ref: spec/ref ;-- help system wants this value!
method: meth
]
protect/words port/spec
; make port/spec to be only with midi related keys
set port/spec: copy system/standard/port-spec-checksum spec
;protect/words port/spec ; protect spec object keys of modification
]

]
Expand All @@ -323,12 +320,6 @@ init-schemes: func [
name: 'clipboard
]

make-scheme [
title: "MIDI"
name: 'midi
awake: func [event] [print event/type true]
]

system/ports/system: open [scheme: 'system]
system/ports/input: open [scheme: 'console]
system/ports/callback: open [scheme: 'callback]
Expand Down

0 comments on commit f6b2bb0

Please sign in to comment.