wdvi

network DVI viewer
Log | Files | Refs

filefind.h (7087B)


      1 /*========================================================================*\
      2 
      3 Copyright (c) 1996-1999  Paul Vojta
      4 
      5 Permission is hereby granted, free of charge, to any person obtaining a copy
      6 of this software and associated documentation files (the "Software"), to
      7 deal in the Software without restriction, including without limitation the
      8 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
      9 sell copies of the Software, and to permit persons to whom the Software is
     10 furnished to do so, subject to the following conditions:
     11 
     12 The above copyright notice and this permission notice shall be included in
     13 all copies or substantial portions of the Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18 PAUL VOJTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
     19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     21 
     22 \*========================================================================*/
     23 
     24 /*
     25  *	filefind.h - Define the data structures that specify how to search
     26  *		for various types of files.
     27  */
     28 
     29 
     30 /*
     31  *	First, some macro definitions.
     32  *	Optionally, filf-app.h may define these.
     33  */
     34 
     35 #ifndef	True
     36 typedef	char		Boolean;
     37 #define	True	1
     38 #define	False	0
     39 #endif
     40 
     41 
     42 /*
     43  *	Record describing how to search for this type of file.  Fields are
     44  *	described further below.
     45  */
     46 
     47 struct	findrec {
     48 	const	char		*path1;
     49 	const	char		*path2;
     50 	const	char		*type;
     51 	const	char		*fF_etc;
     52 	char			x_var_char;
     53 	int			n_var_opts;
     54 	const	char		*no_f_str;
     55 	const	char		*no_f_str_end;
     56 	const	char		*abs_str;
     57 	const	char		*pct_s_str;
     58 
     59 	struct {
     60 		struct steprec		*stephead;
     61 		struct steprec		*pct_s_head;
     62 		int			pct_s_count;
     63 		const	struct atomrec	**pct_s_atom;
     64 		struct rootrec		*rootp;
     65 	} v;
     66 };
     67 
     68 /*
     69  *	And now, the star of our show.
     70  */
     71 
     72 extern	FILE	*filefind(const char *, struct findrec *, const char **);
     73 
     74 /*
     75  *	Here are the meanings of the various fields in struct findrec:
     76  *
     77  *	const char *path1
     78  *		Colon-separated list of path components to use in the search.
     79  *		This can be obtained, for example, from the environment
     80  *		variable 'XDVIFONTS.'
     81  *
     82  *	const char *path2
     83  *		Secondary list of path components to use in the search.
     84  *		Normally, this is the compiled-in default, and is used at the
     85  *		point (if any) where an extra colon appears in path1.
     86  *
     87  *	const char *type
     88  *		The type of the search (font, vf, etc.).
     89  *
     90  *	const char *fF_etc
     91  *		Certain of the characters following '%' that are to be
     92  *		substituted with strings.  This should begin with 'f' and 'F'.
     93  *		It should not include 'q', 'Q', 't', 's', or 'S'.
     94  *
     95  *	char x_var_char
     96  *		If there is another character besides 'f' and 'F' whose
     97  *		corresponding string may change for different files of this
     98  *		type, then it should be third in fF_etc, and x_var_char
     99  *		should contain its value.  Otherwise, x_var_char should be 'f'.
    100  *
    101  *	int n_var_opts
    102  *		x_var_char == 'f' ? 2 : 3
    103  *
    104  *	const char *no_f_str
    105  *		The address of the string to be implicitly added to the path
    106  *		component if %f was not used.
    107  *
    108  *	const char *no_f_str_end
    109  *		The address of '\0' terminating the above string.
    110  *
    111  *	int no_f_str_flags
    112  *		Flags to be set if no_f_str is used.
    113  *
    114  *	const char *abs_str
    115  *		String to use for the path in case the font/file name begins
    116  *		with a '/' (indicating an absolute path).
    117  *
    118  *	int abs_str_flags
    119  *		Flags to be set if abs_str is used.
    120  *
    121  *	char pk_opt_char
    122  *		'p' for pk/gf file searching (signifying that %p is to be
    123  *		replaced alternately with "pk" and "gf"; 'f' otherwise
    124  *		(signifying that there is no such character).
    125  *
    126  *	const char **pk_gf_addr
    127  *		The address of a pointer that is to be alternately changed
    128  *		to point to "pk" or "gf", as above.
    129  *
    130  *	const char *pct_s_str
    131  *		The string to be substituted for %s occurring at the end of
    132  *		a path component.  This may not contain braces ({}), but it
    133  *		may consist of several strings, separated by colons.
    134  *
    135  *	The remaining fields store information about past searches.  They
    136  *	should be initialized to NULL or 0, as appropriate.
    137  *
    138  *	struct steprec		*stephead;
    139  *		Head of the first linked list of steprecs.
    140  *
    141  *	struct steprec		*pct_s_head;
    142  *		Head of the linked list of steprecs for %s.
    143  *
    144  *	int			pct_s_count;
    145  *		Length of the above linked list.
    146  *
    147  *	const	struct atomrec	**pct_s_atom;
    148  *		An array containing linked list of atomrecs for %s.
    149  *
    150  *	struct rootrec		*rootp;
    151  *		Head of the linked list of rootrecs.
    152  */
    153 
    154 /*
    155  *	Values for flags.
    156  */
    157 
    158 #define	F_FILE_USED	1		/* if %f was used */
    159 #define	F_VARIABLE	2		/* if the string may change next time */
    160 #define	F_PK_USED	4		/* if %p was used */
    161 #define	F_PCT_T		8		/* component began with %t */
    162 #define	F_PCT_S		16		/* put %s after this string of atoms */
    163 #define	F_SLASH_SLASH	32		/* (atomrec) if this began with // */
    164 #define	F_WILD		64		/* (atomrec) if wild cards present */
    165 #define	F_QUICKFIND	128		/* (atomrec, rootrec) if %q or %Q */
    166 #define	F_QUICKONLY	256		/* if %Q */
    167 
    168 /*
    169  *	Values to put in for %x specifiers.
    170  */
    171 
    172 #ifndef	MAX_N_OPTS
    173 #define	MAX_N_OPTS	6
    174 #endif
    175 
    176 extern	const	char		*fF_values[MAX_N_OPTS];
    177 
    178 /*
    179  *	Additional data structures.  These are included because they are
    180  *	referenced in the above structure, but really they are internal
    181  *	to filefind.c.
    182  */
    183 
    184 /*
    185  *	This is the main workhorse data structure.  It is used (1) in a linked
    186  *	list, one for each component of the path; (2) in linked lists of
    187  *	{} alternatives; and (3) in linked lists of alternatives for %s.
    188  *	It contains precomputed (via lazy evaluation) information about how
    189  *	to lay down the candidate file name.
    190  */
    191 
    192 struct	steprec	{
    193 	struct steprec	*next;		/* link to next record in chain */
    194 	const	char	*str;		/* the string we're now looking at */
    195 	const	char	*strend;
    196 	int		flags;		/* not cumulative */
    197 	struct atomrec	*atom;
    198 	struct steprec	*nextstep;
    199 	const	char	*nextpart;	/* only for the main linked list */
    200 	const	char	*home;		/* ~ expansion result (main list only)*/
    201 };
    202 
    203 /*
    204  *	Components of a path following a // or wild card.
    205  */
    206 
    207 struct	atomrec {
    208 	struct atomrec	*next;
    209 	const	char	*p;		/* first char. of dir. name */
    210 	const	char	*p_end;		/* last + 1 char. */
    211 	int		flags;		/* F_PCT_S or F_SLASH_SLASH (so far) */
    212 };
    213 
    214 /*
    215  *	Roots of tree structures containing information on subdirectories.
    216  */
    217 
    218 struct	rootrec {
    219 	struct rootrec	*next;		/* link to next in list */
    220 	struct treerec	*tree;		/* the tree */
    221 	int		flags;		/* F_QUICKFIND and F_QUICKONLY */
    222 	const	char	*fullpat;	/* xlat pattern for use with ls-R */
    223 	const	char	*fullpat_end;
    224 	const	char	*keypat;	/* key for ls-R database search */
    225 	const	char	*keypat_end;
    226 };
    227 
    228 /*
    229  *	Nodes in the above-mentioned tree structure.
    230  */
    231 
    232 struct	treerec {
    233 	const	char	*dirname;
    234 	struct treerec	*next;		/* link to next sibling */
    235 	struct treerec	*child;		/* link to subdirectories */
    236 	Boolean		tried_already;
    237 	Boolean		isdir;
    238 };