summaryrefslogtreecommitdiff
path: root/support/texfind
blob: 6f2722c8df632f95e2aeb9f194e241a888d1d755 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/local/bin/perl

# Perl program to find a full path to various TeX-interesting files.
# Michal Jaegermann, 1 July 1994
#
# Names with '.' in name are taken literally, otherwise all extensions
# for a given class will be added and tried.  The program does not
# expand any wildcards (beyond what was done by shell).  In particular
# do not use '~' in path names, unless you want it to be interpreted
# literally.  For 'home directory' use instead, in arguments, $HOME.
# The search is stopped after the first hit, unless '-a' option given.
#
# Default path values are used if not specified on a command line
# and environment variables do not give anything.  Modify defaults
# to fit your system.  What is below serves rather as an example.
# Adding other file types and wildcard expansion is left as an exercise
# to a user.

require "getopts.pl";

$sepr    = '/';			# this value for Unix
($myname = $0) =~ s:.*$sepr::;
$use = qq!$myname [-p path] [-r] [-n] [-b] [-f] [-m] [-a] <name> [<name> ...]

Print a full path to a file <name> which will be included by TeX.
If extension not specified explicitely all supported extensions are tried.
Options:
\t-p <path>  search along specified path
\t-r         recursive; include in search subdirectories
\t-n         non-recursive; only directories in path
\t-b         search for bibtex files
\t-f         search for fonts (.tfm files)
\t-m         search for metafont inputs
\t-a         show all files matching search criteria
!;

# defaults - modify to your installation and circumstances

@tex_exts = ('.tex', '.sty', '.cls', '.dtx', '.ltx', '.txi', '.texi');
@bib_exts = ('.bbl', '.bib', '.bst');
@font_exts = ('.tfm');
@mf_exts = ('.mf');

$myown = $ENV{'HOME'} . '/Library/texinputs:';
$default_texpath = '.:' . $myown . '/usr/lib/tex/inputs';
$default_bibpath = '.:' . $myown . '/usr/lib/tex/inputs';
$default_mfpath  = '.:' . $myown . '/usr/lib/mf/inputs';
$default_fontpath= '.:/usr/lib/tex/fonts/tfm:/LocalLibrary/Fonts/TeXFonts/tfm';

$recurse = 1;
$all     = 0;			# if 0 then stop at the first find

# end of defaults

&Getopts('p:rnbfma') || die $use;
if ($opt_p) { $path = $opt_p; }
if ($opt_r) { $recurse = 1; }
if ($opt_n) { $recurse = 0; }
if ($opt_b) {
    $path = $ENV{'BIBINPUTS'} unless $path;
    $path = $default_bibpath  unless $path;
    @exts = @bib_exts;
}
if ($opt_f) {
    $path = $ENV{'TEXFONTS'}  unless $path;
    $path = $default_fontpath unless $path;
    @exts = @font_exts;
}
if ($opt_m) { 
    $path = $ENV{'MFINPUTS'} unless $path;
    $path = $default_mfpath  unless $path;
    @exts = @mf_exts;
}
if ($opt_a) { $all = 1; }
@ARGV || die $use;

$path = $ENV{'TEXINPUTS'} unless $path;
$path = $default_texpath  unless $path;
@exts = @tex_exts unless @exts;

chop($cwd = `pwd`);
@dirs = grep(length > 0, split(':', $path));

while ($_ = shift @ARGV) {
    if (/\./) {
	@files = ($_);
    }
    else {
	@files = ();
	foreach $ext (@exts) {
	    push(@files, $_ . $ext);
	}
    }
    foreach $check (@dirs) {
	$check = $cwd if $check eq '.';
	chdir $check || die "Can't cd to $check; $!";
	&dodir($check);
    }
    chdir $cwd || die "Can't cd to $cwd; $!";
}

sub dodir {
    local($dpath) = @_;

    opendir(DIR, '.') || die "Can't open $dpath; $!";
    local(@dirlist) = readdir(DIR);
    closedir(DIR);
    
    @dirlist = sort @dirlist;

    #check this directory first
    
    foreach $file (@files) {
	for (@dirlist) {
	    if ($file eq $_) {
		print $dpath, $sepr, $_, "\n";
		next if $all; 
		return;
	    }
	}
    }

    if ($recurse) {
	for (@dirlist) {
	    next if $_ eq '.';
	    next if $_ eq '..';
	    if ( -d $_ ) {		# we have subdirectory
		$subdir = $dpath . $sepr . $_;
		chdir $_ || die "Can't cd to $subdir; $!";
		&dodir($subdir);
		chdir $dpath;
	    }
	}
    }
}