Bug#420836: Patch for "texdoc -s" to use the ls-R database
Hi all,
with teTeX, I've been using "texdoc -s" a lot. With a full texlive
install, this is hardly usable, because it runs "find" over all
$TEXMF/doc trees, which takes ages. Of course if you use it a second
time, it's much faster as long as the directories are cached, but you
never want to use it the first time, not with utilities like "locate"
present on your system.
I suggest that "texdoc -s" should use the ls-R database, just as usual
texdoc does. It's hard, however, to get the exactly same result as the
current behavior only with shell scripting, because of the format of the
ls-R database. The approach I took was to search for directories that
match first (that makes long listings more readable, anyway), and for
non-directory files afterwards.
The attached patch does that, except that I don't know whether
tree=${database%ls-R}
is portable (would have to use echo | sed instead).
Comments?
Regards, Frank
--- /usr/bin/texdoc 2007-05-25 07:59:23.000000000 +0200
+++ bin/texdoc 2007-05-25 19:10:45.000000000 +0200
@@ -18,6 +18,9 @@
# Support for compressed documentation implemented by adopting changes
# made by debian. Thomas Esser, Dec. 2004.
#
+# Support for ls-R for the -s option added by Frank Küster
+# <frank@debian.org>, 2007-05-25
+#
# Debian specific changes:
# Denis Barbier <barbier@imacs.polytechnique.fr>, Feb 15 2000
# * accept gzipped files on input
@@ -161,8 +164,40 @@
do
case $mode in
search)
- find `kpsewhich --expand-path='$TEXMF/doc' | tr : ' '` -follow -type f -print |
- egrep $name
+ lsR_files=""
+ # this is analogous to kpsewhere, but setting TEXMF does not
+ # help, we need TEXMFDBS
+ OLDIFS=$IFS
+ IFS=':'
+ for path in `kpsewhich --expand-path='$TEXMF'`; do
+ lsR_files=$(eval TEXMFDBS=\$path kpsewhich ls-R)
+ done
+ IFS=$OLDIFS
+
+ # first, list directories
+ echo "Directories that match $name:"
+ echo
+ for database in $lsR_files; do
+ #POSIX?
+ tree=${database%ls-R}
+ grep '^\./doc' $database | egrep $name | sed -e "s@^./@$tree@;s@:\$@@"
+ done
+
+ # now, list files
+ echo
+ echo "Files that match $name"
+ echo
+ foundfiles=""
+ for database in $lsR_files; do
+ # doesn't work with spaces in the filename
+ # is not restricted to the doc hierarchy
+ hit=$(egrep $name $database) && foundfiles="$foundfiles $hit"
+ done
+
+ for file in $foundfiles; do
+ kpsewhich --format='TeX system documentation' $file
+ done
+
continue
;;
esac
--
Dr. Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)
Reply to: