home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / lib / web.scm < prev   
Lisp/Scheme  |  1999-12-23  |  4KB  |  104 lines

  1.  
  2.  
  3.  
  4.  
  5.  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  ;;; DO NOT EDIT THIS FILE ON PAIN OF MORE PAIN.
  7.  ;;; 
  8.  ;;; The master copy of this file is in ../../speech_tools/lib/siod/web.scm
  9.  ;;; and is copied here at build time.
  10.  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. ;;;                                                                       ;;
  25. ;;;                Centre for Speech Technology Research                  ;;
  26. ;;;                     University of Edinburgh, UK                       ;;
  27. ;;;                       Copyright (c) 1996,1997                         ;;
  28. ;;;                        All Rights Reserved.                           ;;
  29. ;;;                                                                       ;;
  30. ;;;  Permission is hereby granted, free of charge, to use and distribute  ;;
  31. ;;;  this software and its documentation without restriction, including   ;;
  32. ;;;  without limitation the rights to use, copy, modify, merge, publish,  ;;
  33. ;;;  distribute, sublicense, and/or sell copies of this work, and to      ;;
  34. ;;;  permit persons to whom this work is furnished to do so, subject to   ;;
  35. ;;;  the following conditions:                                            ;;
  36. ;;;   1. The code must retain the above copyright notice, this list of    ;;
  37. ;;;      conditions and the following disclaimer.                         ;;
  38. ;;;   2. Any modifications must be clearly marked as such.                ;;
  39. ;;;   3. Original authors' names are not deleted.                         ;;
  40. ;;;   4. The authors' names are not used to endorse or promote products   ;;
  41. ;;;      derived from this software without specific prior written        ;;
  42. ;;;      permission.                                                      ;;
  43. ;;;                                                                       ;;
  44. ;;;  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        ;;
  45. ;;;  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ;;
  46. ;;;  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ;;
  47. ;;;  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     ;;
  48. ;;;  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ;;
  49. ;;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ;;
  50. ;;;  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ;;
  51. ;;;  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ;;
  52. ;;;  THIS SOFTWARE.                                                       ;;
  53. ;;;                                                                       ;;
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;;;
  56. ;;;  Some things for dealing with the web.
  57. ;;;
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59.  
  60. (define (get_url url filename)
  61.   "(get_url URL OUTFILE)
  62.   Get URL and put contents in OUTFILE. Currently only http, and file
  63.   type URLs are supported."
  64.  
  65.   (let ((infile (fopen (parse_url url) "rb")))
  66.     (if infile
  67.     (let ((outfile (fopen filename "wb")))
  68.       (if outfile
  69.           (let ((buffer "                                                                                                                               ") n)
  70.         (while (set! n (fread buffer infile))
  71.                (if ( < n (length buffer))
  72.                (setq buffer (substring buffer 0 n)))
  73.                (fwrite buffer outfile))
  74.         (fclose infile)
  75.         (fclose outfile)
  76.         )
  77.           "can't open out"
  78.           )
  79.       )
  80.     "can't open in"
  81.     )
  82.     )
  83.   )
  84.  
  85. (define (socket_open host port how)
  86.   "(socket_open HOST PORT HOW)
  87.    Open a file descriptor to the BSD socket on HOST at PORT.  HOW may
  88.    be \"r\" or \"w\" for a read only or write only filedescriptor.  If
  89.    HOW is unspecified or NIL, \"w\" is assumed.  If HOW is \"rw\" then
  90.    a list of two file descriptors is returned, the first for reading
  91.    the second for writing.  Take care when using the bidiectional socket
  92.    that deadlock doesn't occur."
  93.  
  94.   (let ((file (fopen (list "tcp" host port "") how)))
  95.     (if (or (equal? how "rw") (equal how "r+"))
  96.     (list file file)
  97.     file)
  98.     )
  99.   )
  100.   
  101.     
  102. (provide 'web)
  103.     
  104.