⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 216.html

📁 Tcl 语言的入门级图书
💻 HTML
字号:
<HTML><TITLE>The Browser Plugin and Safe-Tcl: Solutions to Exercises</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Solutions to Exercises</H1></A>


<P> <A> <A NAME="Sol21.1a">
<STRONG> Solution To Exercise 21.1a</STRONG> </A> <P>


There is no correct answer here.  The point is to do the exercise.

<P> <A> <A NAME="Sol21.1b">
<STRONG> Solution To Exercise 21.1b</STRONG> </A> <P>


Only

<PRE>
http://www.MapFree.com/sbf/tcl/book/canvas.tcl
</PRE>

<P> <A> <A NAME="Sol21.1c">
<STRONG> Solution To Exercise 21.1c</STRONG> </A> <P>


Only

<PRE>
sunscript.sun.com 3
</PRE>

<P> <A> <A NAME="Sol21.1d">
<STRONG> Solution To Exercise 21.1d</STRONG> </A> <P>


Change 

<PRE>
disallow trusted
</PRE>

to

<PRE>
allow trusted ifallowed trustedURLs $originURL
</PRE>

and add this section

<PRE>
section trustedURLs
  allow file:*
</PRE>

<P> <A> <A NAME="Sol21.1e">
<STRONG> Solution To Exercise 21.1e</STRONG> </A> <P>

<P> The basic idea is to change the <TT>allow</TT> statement to

<PRE>
allow trusted ifallowed trustedHomeURLs $originURL
</PRE>

and add a section something like

<PRE>
section trustedHomeURLs
  allow *
  disallow http://www.mapfree.com*
  disallow http:/206.244.69.58*
</PRE>

but there are substantial difficulties in the last step.  The reason is that
you must write a <TT>disallow</TT> statement for <CITE>any</CITE> identifier this server
may have on the Internet.  Since one server can serve multiple domain names
and have multiple IP addresses, it will be difficult for you to be sure you
have really excluded it from your set of acceptable servers.

<P> When trust is needed, it is safer to list the servers you trust than to try
to avoid problematical servers with <TT>disallow</TT>.  "Safer" does not mean
"safe."  See the remark after this exercise.

<P> <A> <A NAME="Sol21.4a">
<STRONG> Solution To Exercise 21.4a</STRONG> </A> <P>


<PRE>
set F [CI invokehidden open sample]
CI eval "set Contents \[read $F]; close $F"
</PRE>

<P> <A> <A NAME="Sol21.4b">
<STRONG> Solution To Exercise 21.4b</STRONG> </A> <P>


<P>  This solution is available as script ES21.4b.

<PRE>
proc nonet_open {Intrp args} {
  if {"[string index [lindex $args 0]  0]"=="|"} {
     error "cannot open a pipeline"
  } elseif {[llength $args]==0} {
    $Intrp invokehidden open
  } else {
    eval {$Intrp invokehidden} open $args
  }
}

proc create_nonet_interp Name {
   interp create $Name
   $Name hide socket
   $Name hide interp
   $Name hide open
   $Name hide exec
   $Name hide unknown
   $Name alias open nonet_open $Name
   return $Name
}
</PRE>

<P> <A> <A NAME="Sol21.4c">
<STRONG> Solution To Exercise 21.4c</STRONG> </A> <P>


<PRE>
#! /usr/local/bin/wish8.0

## A network-inhibited interpreter that operates interactively through a 
## text widget


## source procedures for the network-inhibited interpreter

   source ES21.4b

## source scrollable

   source ES18.1c

## source copy_paste

   source ES20.3b

##  create a scrollable widget object in its own toplevel window
   set txt [scrollable . text 1]
   bind $txt &#60;Control-c&#62; exit
   wm title . "Network Free Command Window"
   wm iconname . "Tk"

## prohibit editing before command line (but permit keyboard movement)
   bind $txt &#60;Key&#62; {
     if {"%K"=="BackSpace"} {
         if [%W compare insert &#60;= boundary] break
     } elseif { "%K"=="Right" || "%K"=="Left" || "%K"=="Up" || "%K"=="Down" \
                || "%K"=="Prior" || "%K"=="Next"
              } {
         continue
     } elseif [%W compare insert &#60; boundary] { 
         %W mark set insert {end -1char}
     }
     %W see {insert linestart}
     %W see insert
   }

## create a network-inhibited interpreter
   create_nonet_interp noNet
   load {} Tk noNet
   noNet eval wm title . .

## arrange for command execution
   proc doCommand txt { 
     set CommandLine [$txt get boundary end]
     if {[info complete  $CommandLine]} {
        catch {noNet eval $CommandLine} CatchBak
        if {"$CatchBak"!=""} {
            $txt insert insert \n$CatchBak
        }
        $txt insert insert \n
        startNewCommandLine $txt 
        $txt see {insert linestart}
        $txt see insert
     } else {
        $txt insert insert \n
        $txt see insert  
     }
   }

   bind $txt &#60;Key-Return&#62; { 
     if {[%W compare insert &#60; boundary]} {
        %W mark set insert {end -1char}
     }
     doCommand %W
     break
  }

## start command line with prompt and mark
   proc startNewCommandLine txt {
       global PROMPT
       $txt insert insert  $PROMPT
       $txt mark set boundary insert
   }

   set PROMPT "&#62; "
   startNewCommandLine $txt
   $txt mark gravity boundary left

## setup standardized cut and paste
   copy_paste $txt
</PRE>








<!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="21.5.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.5.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="21.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
 </NOBR></FONT></CENTER></BODY></HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -