#!/usr/bin/guile \ -e main -s !# ;;; Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) ;;; ;;; This work is licensed under the Creative Commons Attribution-NonCommercial- ;;; ShareAlike License. To view a copy of this license, visit ;;; http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to ;;; Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, ;;; 94105, USA. ; read-entries - slurp up a list of strings from an input-port (define (read-entries port) (let ((in-line (read-line port))) (if (eof-object? in-line) '() (append (list in-line) (read-entries port))))) ; display-matching-indices - search the 'entries' list for 'term'. for ; any matches, display the line number (list index+1) of the match. ; also, notify the user if no matches are found (define (display-matching-indices term entries) (let next-match ((entries-length (length entries)) (match-start (member term entries)) (found-one #f)) (if (not match-start) (if (not found-one) (begin (display "Search term not found.\n") (exit -2))) (begin (display "found match on line: ") (display (+ (- entries-length (length match-start)) 1)) (newline) (next-match entries-length (member term (cdr match-start)) #t))))) (define (main args) (if (not (equal? (length args) 3)) (begin (display (string-append "Usage:\n\t" (car args) " (search term) (file with list of terms)\n")) (exit -1)) (display-matching-indices (cadr args) (call-with-input-file (caddr args) read-entries))))