moving TCL/tk on a bit more; interaction between TCL/tk and HTML?

22 views
Skip to first unread message

dr.mt...@gmail.com

unread,
May 15, 2024, 12:23:25 AMMay 15
to Shen
Right thx Chris.  That's the key.  The code is now.

proc url {String} {
  set data [url_help $String]
  set result [concat \" [join $data " "] \"]
  return $result}

proc url_help {String} {
  package require http
  package require tls
  ::http::register https 443 [list ::tls::socket -request 1 -ssl2 0 -ssl3 0 -tls1 1 -cafile VeriSignClass3SecureServerCA-G3.crt]
  set token [::http::geturl $String]
  upvar #0 $token state
  return $state(body)}

I'm trying to return a string (code in red) and this works.

(bin) 3 % url "https://shenlanguage.org/TBoS/Programs/3.3.txt"
" (define factorial X -> (factorialh X 1)) (define factorialh 0 Accum -> Accum X Accum -> (factorialh (- X 1) (* X Accum))) (define plus X 0 -> X X Y -> (+ 1 (plus X (- Y 1)))) (define fib 0 -> 0 1 -> 1 X -> (+ (fib (- X 1)) (fib (- X 2)))) (define even? 1 -> false X -> (odd? (- X 1))) (define odd? 1 -> true X -> (even? (- X 1))) "

However if I try this on the Shen home page.

url "https://shenlanguage.org/"
list element in quotes followed by "#B6D4D1">" instead of space


The #B6D4D1 is an RGB formatting instruction inside the HTML of the home page.  It looks as if TCL/tk is somehow trying to act on it.

Mark

Chris Double

unread,
May 15, 2024, 12:45:10 AMMay 15
to qil...@googlegroups.com
On Wed, May 15, 2024, at 4:23 PM, dr.mt...@gmail.com wrote:
> set result [concat \" [join $data " "] \"]

Change this to: set result [format "\"%s\"" $data]

"join" expects $data to be a tcl list - any white space or special characters like that in HTML will cause issues. The 'format' approach will convert it to a string.

In 'url_help' you should also cleanup the token:

set result $state(body)
::http::cleanup $token
return $result

--
https://bluishcoder.co.nz
Reply all
Reply to author
Forward
0 new messages