-
Notifications
You must be signed in to change notification settings - Fork 2
/
kpathsea.lisp
80 lines (74 loc) · 2.54 KB
/
kpathsea.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;; An interface to Kpathsea (TeX's file search library)
;; Copyright 2001, 2002, 2007, 2018 Matthias Koeppe <[email protected]>
;;
;; This code is free software; you can redistribute it and/or
;; modify it under the terms of version 2.1 of the GNU Lesser
;; General Public License as published by the Free Software
;; Foundation or any later version, as clarified by the preamble
;; found in COPYING-preamble.txt. This preamble is in the style
;; of the Franz Inc. preamble at http://opensource.franz.com/preamble.html
;; with names and copyright holders altered accordingly.
(in-package :kpathsea)
;; We use CLOCC PORT to run programs if we are not running in CMUCL or SBCL.
;;#+clisp
;;(eval-when (:compile-toplevel :load-toplevel :execute)
;; (cl:require :PORT))
;; #-(or cmu sbcl clisp)
;; (cl:require :PORT)
(defun find-file (name)
#+cmu
(let ((process
(extensions:run-program "kpsewhich" (list (namestring name))
:output :stream)))
(let ((line (read-line (extensions:process-output process) nil nil)))
(prog1
(and line
(parse-namestring line))
(extensions:process-close process))))
#+sbcl
(let ((process
(sb-ext:run-program "/usr/bin/env"
(list "kpsewhich" (namestring name))
:output :stream)))
(let ((line (read-line (sb-ext:process-output process) nil nil)))
(prog1
(and line
(parse-namestring line))
(sb-ext:process-close process))))
#+abcl
(let ((process
(sys:run-program "/usr/bin/env"
(list "kpsewhich" (namestring name)))))
(let ((line (read-line (sys:process-output process) nil nil)))
(and line
(parse-namestring line))))
#+allegro
(let ((stream (excl:run-shell-command (vector "/bin/sh"
"/bin/sh"
"-c"
(format nil "~A ~A" "kpsewhich" (namestring name)))
:output :stream :wait nil)
;; Using run-shell-command with a vector is much faster
;; than with a list (tries to run $SHELL! -- this is what PORT does)
))
(let ((line (read-line stream nil nil)))
(prog1
(and line (parse-namestring line))
(port:close-pipe stream))))
#+ecl
(let ((stream
(ext:run-program "/usr/bin/env"
(list "kpsewhich" (namestring name))
:output :stream)))
(let ((line (read-line stream nil nil)))
(and line
(parse-namestring line))))
#-(or cmu sbcl abcl allegro ecl)
(let ((stream (port:pipe-input "kpsewhich" (namestring name))))
(let ((line (read-line stream nil nil)))
(prog1
(and line (parse-namestring line))
(port:close-pipe stream)))))
#|
(find-file "amsalpha.bst")
|#