;; sw2re (Shell Wildcards To Regular Expressions)
;;AUTOLOAD: wildcard-to-regexp
;;AUTODOC: wildcard-to-regexp "transforms a shell wildcard pattern into a regexp"
;; (wildcard-to-regexp shell-pattern)
;;
;; Returns a regular expression from a shell pattern
;; example: Klone*.c is transformed into the regexp: ^Klone.*\.c$
;; understands * and ? for now, lets [] expressions unchanged
;; The result is a regcomp-ed regexp.

(defun wildcard-to-regexp (wild &aux
    (re (copy "^"))
    c
  )
  (dolist (c wild)
    (if
      (seek ".\\$" c)
      (progn
	(put re -1 #\\)
	(put re -1 c)
      )

      (= #\* c)
      (nconc re ".*")

      (= #\? c)
      (put re -1 #\.)

      (put re -1 c)
  ))
  (put re -1 #\$)
  (regcomp re)
)
