;;;; doc.scm -*- Scheme -*- (use eggdoc) (define license "Copyright (c) 2006 Alex Shinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.") (define doc `((eggdoc:begin (name "pty") (description (p "Easy Pseudo-Terminal Interface")) (author "Alex Shinn") (history (version "1.3" "setup script fixes (felix)") (version "1.1" "MacOS X compile [Kon Lovett]") (version "1.0" "Initial release")) (usage) (documentation (p "PTY allows you to run sub-processes in pseudo-terminals" " and access their input and output from the controlling" " program as regular Chicken ports. This is useful for" " a variety of purposes, such as:" (ul (li "Run a remote session via ssh or rlogin using a user-supplied password.") (li "Automate some or all of a terminal game or program (such as nethack or vi).") (li "Run fsck, answering \"yes\" or \"no\" based on pre-determined criteria.") (li "Implement an xterm program.")) "In general these cannot be done with regular sub-process ports.")) (section "High-Level Interface" (group (procedure "(call-with-pty-process-io command proc [name [width [height]]])" (p "Call and return the result of " (code "proc") " which should " " be a procedure of three arguments:" " the input, output and PID of the sub-process " (code "command") " running in a new PTY. Ensures the sub-process is terminated on " " completion. " (code "name") ", " (code "width") " and " (code "height") " are optional settings for the new PTY. " " " (code "command") " may optionally be a list specifying the" " arglist to the sub-process, or a single string which is" " split on whitespace." ) (p "The ports generated only block the current thread, and " (code "char-ready?") " only returns #t if some input is" " already available. The eof-object is returned only" " when the sub-process terminates.") (p (b "NOTE:") " Prior to login of, and after completion of" " the sub-process, anything written to the output port" " will pass directly through to the input port, which" " is almost certainly not what you want. To avoid premature" " writes, you should read once first. To avoid writing" " after the process has completed, don't write after you've" " read a single eof-object, or alternately you can check" " manually with " (code "process-alive?") ".")) (procedure "(with-pty-process-io command proc [name [width [height]]])" (p "As above, except current input and output ports are" " bound to the output and input of " (code "command") " respectively, and " (code "proc") " only takes one" " argument, the PID.")))) (section "Low-Level Interface" (group (procedure "(open-pty-process command [name [width [height]]])") (procedure "(open-pty [name [width [height]]])") (procedure "(login-tty fd)") (procedure "(process-alive? pid)") (procedure "(fcntl-ref fd)") (procedure "(fcntl-set! fd arg)") (procedure "(file-select-one fd)") (procedure "(file-read/maybe fd buf len)") (procedure "(open-file-io/non-blocking fd [process-alive? (-> boolean)])"))) (section "Example" (pre (code " (call-with-pty-process-io \"ssh myfirewall\" (lambda (in out pid) (peek-char in) (display (gui-get-password) out) (newline out) (read-line in) (display \"dhclient 2>/dev/null && echo OK || echo FAIL\\n\" out) (unless (equal? \"OK\" (read-line in)) (error \"couldn't launch dhclient\"))) " ))) (section "License" (pre ,license))))) (eggdoc->html doc)