From e0a03a7769fef605b0dbf0cec16047d83e4fdd58 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 2 Nov 2005 08:30:38 +0000 Subject: [PATCH] Updated to work with the new vector/hashtable syntax --- contrib/aim/aim.factor | 23 ++++++++++------------- contrib/aim/net-bytes.factor | 18 ++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/contrib/aim/aim.factor b/contrib/aim/aim.factor index 9a00a90892..275a6fb951 100644 --- a/contrib/aim/aim.factor +++ b/contrib/aim/aim.factor @@ -73,11 +73,6 @@ H{ [[ 12 "Translate" ]] [[ 19 "SSI" ]] [[ 21 "ICQ" ]] [[ 34 "Unknown Family" ]] } ; -: ch>lower ( int -- int ) dup LETTER? [ HEX: 20 + ] when ; -: ch>upper ( int -- int ) dup letter? [ HEX: 20 - ] when ; -: >lower ( seq -- seq ) [ ch>lower ] map ; -: >upper ( seq -- seq ) [ ch>upper ] map ; - : sanitize-name ( name -- name ) HEX: 20 swap remove >lower ; : hash-swap ( hash -- hash ) @@ -182,12 +177,14 @@ H{ conn get swap with-unscoped-stream ; : read-aim ( -- bc ) - [ [ - head-byte drop - head-byte drop - head-short drop - head-short head-string - ] with-aim ] catch [ "Socket error" print throw ] when + [ + [ + head-byte drop + head-byte drop + head-short drop + head-short head-string + ] with-aim + ] catch [ "Socket error" print throw ] when "Received: " write dup hexdump ; : make-snac ( fam subtype flags req-id -- ) @@ -729,11 +726,11 @@ SYMBOL: type type get { - { [ dup 0 = ] [ drop name get bid get gid get { } clone f f + { [ dup 0 = ] [ drop name get bid get gid get V{ } clone f f dup name get sanitize-name buddy-hash-name get set-hash bid get buddy-hash-id get set-hash ] } { [ dup 1 = ] [ drop name get dup length 0 = [ drop ] [ gid get dup name get sanitize-name group-hash-name get set-hash gid get group-hash-id get set-hash ] if ] } - { [ dup 3 = ] [ drop name get bid get gid get { } clone f f + { [ dup 3 = ] [ drop name get bid get gid get V{ } clone f f dup name get sanitize-name banned-hash-name get set-hash bid get banned-hash-id get set-hash ] } { [ t ] [ drop "Unknown 19-6 type" print ] } } cond diff --git a/contrib/aim/net-bytes.factor b/contrib/aim/net-bytes.factor index d803eef300..999638a279 100644 --- a/contrib/aim/net-bytes.factor +++ b/contrib/aim/net-bytes.factor @@ -22,14 +22,12 @@ SYMBOL: unscoped-stack HEX: 000000ff bitand unparse % ] "" make ; - - ! doesn't compile ! : >nvector ( elems n -- ) ! { } clone swap [ drop swap add ] each reverse ; : 4vector ( elems -- ) - { } clone 4 [ drop swap add ] each reverse ; + V{ } clone 4 [ drop swap add ] each reverse ; ! TODO: make this work for types other than "" : papply ( seq seq -- seq ) @@ -38,7 +36,6 @@ SYMBOL: unscoped-stack : writeln ( string -- ) write terpri ; -! wrote this months and months ago.. ! NEEDS REFACTORING, GOSH! ! Hexdump : (print-offset) ( lineno -- ) @@ -82,21 +79,15 @@ SYMBOL: unscoped-stack ] "" make write ; : hexdump ( str -- ) -! drop ; dup length (print-length) (print-bytes) ; : save-current-scope - unscoped-stack get [ { } clone unscoped-stack set ] unless + unscoped-stack get [ V{ } clone unscoped-stack set ] unless swap dup unscoped-stream set unscoped-stack get push ; : set-previous-scope - ! unscoped-stream get contents . - ! [ - ! "UNREAD BYTES" writeln - ! hexdump - ! ] when unscoped-stack get dup length 1 > [ [ pop ] keep nip peek unscoped-stream set ] [ pop drop @@ -167,16 +158,19 @@ SYMBOL: unscoped-stack : (head-u128) ( str -- u128 ) 16 swap head endian> ; - +! 8 bits : head-byte ( -- byte ) 1 unscoped-stream get stream-read first ; +! 16 bits : head-short ( -- short ) 2 unscoped-stream get stream-read (head-short) ; +! 32 bits : head-int ( -- int ) 4 unscoped-stream get stream-read (head-int) ; +! 64 bits : head-longlong ( -- longlong ) 8 unscoped-stream get stream-read (head-longlong) ;