summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/pathsearch.h
blob: c79718269994dc872f8bf318a536ecd058fe2df7 (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
/* pathsearch.h: mostly-generic path searching.

   Copyright 1993, 1994, 1996, 1997, 2007, 2008 Karl Berry.
   Copyright 1999-2005 Olaf Weber.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this library; if not, see <http://www.gnu.org/licenses/>.  */

#ifndef KPATHSEA_PATHSEARCH_H
#define KPATHSEA_PATHSEARCH_H

#include <kpathsea/c-proto.h>
#include <kpathsea/str-llist.h>
#include <kpathsea/types.h>

/* If PATH is non-null, return its first element (as defined by
   IS_ENV_SEP).  If it's NULL, return the next element in the previous
   path, a la strtok.  Leading, trailing, or doubled colons result in
   the empty string.  When at the end of PATH, return NULL.  In any
   case, return a pointer to an area that may be overwritten on
   subsequent calls.  */
extern KPSEDLL string kpse_path_element P1H(const_string path);

/* Like `kpse_path_element', but for filename components (using
   IS_DIR_SEP).  Uses same area as `kpse_path_element'.  */
extern string kpse_filename_component P1H(const_string path);

/*
  This function may rewrite its argument to avoid bugs when calling
  stat() or equivalent under Win32.  Also, it returns the index after
  which the program should start to look for expandable constructs. */
extern unsigned kpse_normalize_path P1H(string elt);

/* Given a path element ELT, return a pointer to a NULL-terminated list
   of the corresponding (existing) directory or directories, with
   trailing slashes, or NULL.  If ELT is the empty string, check the
   current working directory.
   
   It's up to the caller to expand ELT.  This is because this routine is
   most likely only useful to be called from `kpse_path_search', which
   has already assumed expansion has been done.  */
extern KPSEDLL str_llist_type *kpse_element_dirs P1H(string elt);


/* Call `kpse_expand' on NAME.  If the result is an absolute or
   explicitly relative filename, check whether it is a readable
   (regular) file.
   
   Otherwise, look in each of the directories specified in PATH (also do
   tilde and variable expansion on elements in PATH), using a prebuilt
   db (see db.h) if it's relevant for a given path element.
   
   If the prebuilt db doesn't exist, or if MUST_EXIST is true and NAME
   isn't found in the prebuilt db, look on the filesystem.  (I.e., if
   MUST_EXIST is false, and NAME isn't found in the db, do *not* look on
   the filesystem.)
   
   The caller must expand PATH. This is because it makes more sense to
   do this once, in advance, instead of for every search.
   
   In any case, return a matching filename if found, otherwise NULL.
   If more than one file matches, which one gets returned is
   unspecified.  */
extern KPSEDLL string kpse_path_search
  P3H(const_string path, const_string name, boolean must_exist);

/* Like `kpse_path_search', except look for a list of NAMES.  */
extern KPSEDLL string kpse_path_search_list
  P3H(const_string path, const_string* names, boolean must_exist);

/* Like `kpse_path_search' with MUST_EXIST true, but always return all
   matches in a NULL-terminated list.  */
extern KPSEDLL string *kpse_all_path_search
  P2H(const_string path, const_string name);

/* Search for any of the NAMES in PATH, and allow specifying both
   MUST_EXIST and ALL.  */
extern KPSEDLL string *kpse_path_search_list_generic
  P4H(const_string path, const_string* names, boolean must_exist, boolean all);

/* Search for any of NAMES, with MUST_EXIST and ALL true.  */
extern KPSEDLL string *kpse_all_path_search_list
  P2H(const_string path, const_string* names);

/* The naming of all these functions is rather scattered and
   inconsistent, but they grew over time, and we don't want to change
   the meaning of existing names.  */
#endif /* not KPATHSEA_PATHSEARCH_H */