guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read-xpilot-robots


From: Thien-Thi Nguyen
Subject: read-xpilot-robots
Date: Sat, 28 Sep 2002 18:25:32 -0700

ok, next thing to fiddle w/ (still in the guile-xlib vein) would be some
kind of tank-crawling-over-landscape 3d wire-frame (vector graphics, woo
hoo!).  rather than design vehicles, i thought perhaps we could borrow
xpilot robots and play w/ some depth-addition heuristics.  below is an
executable module (aka script) to read /usr/share/games/xpilot/robots
into memory, which is a start.

i notice systas has fps.  anyone want to tweak that for guile?

thi

____________________________________
#!/bin/sh
# aside from this initial boilerplate, this is actually -*- scheme -*- code
main='(module-ref (resolve-module '\''(read-xpilot-robots)) '\'main')'
exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
!#
;;; read-xpilot-robots --- Read xpilot "robots" file

;;      Copyright (C) 2002 Thien-Thi Nguyen
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;; Boston, MA 02111-1307 USA

;;; Commentary:

;; Usage: read-xpilot-robots FILE
;;
;; Read xpilot robots file FILE into a list, each element of which
;; having the form:
;;
;;     (NAME TYPE SHIP PARA)
;;
;; where NAME and TYPE are strings, SHIP is a list of sublists of
;; integers, and PARA is a list of integers.  When invoked from the
;; shell, display each form to stdout, one per line.

;;; Code:

(debug-enable 'debug 'backtrace)

(define-module (read-xpilot-robots)
  :use-module ((scripts PROGRAM) :select (script-MAIN))
  :use-module (ice-9 rdelim)
  :use-module (ice-9 regex)
  :use-module (srfi srfi-13)
  :export (read-xpilot-robots))

(define trigger-rx (make-regexp "^type:[ \t]*([^ \t]+)"))
(define next-rx    (make-regexp "^[a-z]+:[ \t]*"))

(define (make-next port)
  (lambda ()
    (match:suffix (regexp-exec next-rx (read-line port)))))

(define (read-string string)
  (with-input-from-string string read))

(define (read-xpilot-robots port)
  (define next (make-next port))
  (let loop ((line (read-line port)) (acc '()))
    (if (eof-object? line)
        (reverse acc)
        (cond ((regexp-exec trigger-rx line)
               => (lambda (m)
                    (let ((type (match:substring m 1))
                          (para (read-string (format #f "(~A)" (next))))
                          (ship (read-string
                                 (format #f "(~A)"
                                         (string-map
                                          (lambda (c)
                                            (if (char=? #\, c)
                                                #\space
                                                c))
                                          (next)))))
                          (name (next)))
                      (loop (read-line port)
                            (cons (list name type ship para) acc)))))
              (else (loop (read-line port) acc))))))

(define (read-xpilot-robots/main . args)
  (let ((file (car args)))
    (for-each (lambda (robot)
                (format #t "~S\n" robot))
              (read-xpilot-robots (open-input-file file))))
  #t)

(define (main . args)
  (script-MAIN args
               "read-xpilot-robots" read-xpilot-robots/main
               '(usage . commentary)))

;;; read-xpilot-robots ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]