5 ;; Copyright (C) 2015 Christopher Allan Webber <cwebber@dustycloud.org>
7 ;; This library is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU Lesser General Public
9 ;; License as published by the Free Software Foundation; either
10 ;; version 3 of the License, or (at your option) any later version.
12 ;; This library is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; Lesser General Public License for more details.
17 ;; You should have received a copy of the GNU Lesser General Public
18 ;; License along with this library; if not, write to the Free Software
19 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 (use-modules (eightsync repl)
32 (define default-irc-port 6665)
34 (define* (irc-socket-setup hostname #:optional (inet-port default-irc-port))
35 (let ((s (socket PF_INET SOCK_STREAM 0))
36 (ip-address (inet-ntoa (car (hostent:addr-list (gethost hostname))))))
38 (inet-pton AF_INET ip-address)
42 (define (install-socket socket handler)
43 (display "Installing socket...\n") ; debugging :)
44 (make-port-request socket #:read handler))
46 (define (handle-line socket line)
50 (define (make-simple-irc-handler handle-line)
52 (define (reset-buffer)
54 (define (should-read-char socket)
55 (and (char-ready? socket) (not (eof-object? (peek-char socket)))))
56 (define (irc-handler socket)
57 (while (should-read-char socket)
58 (set! buffer (cons (read-char socket) buffer))
60 ((#\newline #\return (? char? line-chars) ...)
61 (%sync (%run (handle-line
63 (list->string (reverse line-chars)))))
69 (define* (queue-and-start-irc-agenda! agenda socket #:key
70 (inet-port default-irc-port)
71 (handler (make-simple-irc-handler handle-line)))
75 (enq! (agenda-queue agenda) (wrap (install-socket socket handler)))
76 (start-agenda agenda))
78 (display "Cleaning up...\n")
87 `((server (single-char #\s) (required? #t) (value #t))
88 (port (single-char #\p)
92 (if (string->number s) #t #f))))
93 (username (single-char #\u) (required? #t) (value #t))
97 (let* ((options (getopt-long args option-spec))
98 (server (option-ref options 'server #f))
99 (port (or (option-ref options 'port #f)
101 (username (option-ref options 'username #f))
102 (listen (option-ref options 'listen #f)))
103 (display `((server ,server) (port ,port) (username ,username)