2001-09-12 14:53:50 -04:00
|
|
|
;; ecm-utilities.scm -- Utility procedures for ecm-net code
|
|
|
|
;;
|
2001-11-15 06:12:24 -05:00
|
|
|
;; $Id: ecm-utilities.scm,v 1.2 2001/11/15 11:12:23 mainzelm Exp $
|
2001-09-12 14:53:50 -04:00
|
|
|
;;
|
|
|
|
;; Please send suggestions and bug reports to <emarsden@mail.dotcom.fr>
|
|
|
|
|
|
|
|
|
|
|
|
;; please tell me if this doesn't work on your system.
|
|
|
|
(define (system-fqdn)
|
|
|
|
(let ((sysname (system-name)))
|
|
|
|
(if (string-index sysname #\.)
|
|
|
|
sysname
|
|
|
|
(nslookup-fqdn))))
|
|
|
|
|
|
|
|
(define (nslookup-fqdn)
|
|
|
|
(let* ((cmd (format #f "nslookup ~a" (system-name)))
|
|
|
|
(raw (string-join (run/strings (nslookup ,(system-name)))))
|
|
|
|
(match (string-match "Name: +([-a-zA-Z0-9.]+)" raw)))
|
|
|
|
(display raw)
|
|
|
|
(match:substring match 1)))
|
|
|
|
|
|
|
|
|
|
|
|
;; prefer this to :optional
|
|
|
|
(define (safe-first x) (and (not (null? x)) (car x)))
|
|
|
|
(define (safe-second x) (and (not (null? (cdr x))) (cadr x)))
|
|
|
|
|
|
|
|
(define (write-crlf port)
|
|
|
|
(write-string "\r\n" port)
|
|
|
|
(force-output port))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dump fd)
|
|
|
|
(let loop ((c (read-char fd)))
|
|
|
|
(cond ((not (eof-object? c))
|
|
|
|
(write-char c)
|
|
|
|
(loop (read-char fd))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax when
|
|
|
|
(syntax-rules ()
|
|
|
|
((when bool body1 body2 ...)
|
|
|
|
(if bool (begin body1 body2 ...)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax unless
|
|
|
|
(syntax-rules ()
|
|
|
|
((unless bool body1 body2 ...)
|
|
|
|
(if (not bool) (begin body1 body2 ...)))))
|
|
|
|
|
|
|
|
;; EOF
|