1
/* tex-file.c: high-level file searching by format.
3
Copyright 1998-2005 Olaf Weber.
4
Copyright 1993, 94, 95, 96, 97 Karl Berry.
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <kpathsea/config.h>
24
#include <kpathsea/c-fopen.h>
25
#include <kpathsea/c-pathch.h>
26
#include <kpathsea/c-vararg.h>
27
#include <kpathsea/cnf.h>
28
#include <kpathsea/concatn.h>
29
#include <kpathsea/default.h>
30
#include <kpathsea/expand.h>
31
#include <kpathsea/fontmap.h>
32
#include <kpathsea/paths.h>
33
#include <kpathsea/pathsearch.h>
34
#include <kpathsea/tex-file.h>
35
#include <kpathsea/tex-make.h>
36
#include <kpathsea/variable.h>
40
const_string kpse_fallback_font = NULL;
41
const_string kpse_fallback_resolutions_string = NULL;
42
unsigned *kpse_fallback_resolutions = NULL;
43
kpse_format_info_type kpse_format_info[kpse_last_format];
45
/* These are not in the structure
46
because it's annoying to initialize lists in C. */
47
#define GF_ENVS "GFFONTS", GLYPH_ENVS
48
#define PK_ENVS "PKFONTS", "TEXPKS", GLYPH_ENVS
49
#define GLYPH_ENVS "GLYPHFONTS", "TEXFONTS"
50
#define TFM_ENVS "TFMFONTS", "TEXFONTS"
51
#define AFM_ENVS "AFMFONTS", "TEXFONTS"
52
#define BASE_ENVS "MFBASES", "TEXMFINI"
53
#define BIB_ENVS "BIBINPUTS", "TEXBIB"
54
#define BST_ENVS "BSTINPUTS"
55
#define CNF_ENVS "TEXMFCNF"
56
#define DB_ENVS "TEXMFDBS"
57
#define FMT_ENVS "TEXFORMATS", "TEXMFINI"
58
#define FONTMAP_ENVS "TEXFONTMAPS", "TEXFONTS"
59
#define MEM_ENVS "MPMEMS", "TEXMFINI"
60
#define MF_ENVS "MFINPUTS"
61
#define MFPOOL_ENVS "MFPOOL", "TEXMFINI"
62
#define MFT_ENVS "MFTINPUTS"
63
#define MP_ENVS "MPINPUTS"
64
#define MPPOOL_ENVS "MPPOOL", "TEXMFINI"
65
#define MPSUPPORT_ENVS "MPSUPPORT"
66
#define OCP_ENVS "OCPINPUTS"
67
#define OFM_ENVS "OFMFONTS", "TEXFONTS"
68
#define OPL_ENVS "OPLFONTS", "TEXFONTS"
69
#define OTP_ENVS "OTPINPUTS"
70
#define OVF_ENVS "OVFFONTS", "TEXFONTS"
71
#define OVP_ENVS "OVPFONTS", "TEXFONTS"
72
#define PICT_ENVS "TEXPICTS", TEX_ENVS
73
#define TEX_ENVS "TEXINPUTS"
74
#define TEXDOC_ENVS "TEXDOCS"
75
#define TEXPOOL_ENVS "TEXPOOL", "TEXMFINI"
76
#define TEXSOURCE_ENVS "TEXSOURCES"
77
#define TEX_PS_HEADER_ENVS "TEXPSHEADERS", "PSHEADERS"
78
#define TROFF_FONT_ENVS "TRFONTS"
79
#define TYPE1_ENVS "T1FONTS", "T1INPUTS", "TEXFONTS", TEX_PS_HEADER_ENVS
80
#define VF_ENVS "VFFONTS", "TEXFONTS"
81
#define DVIPS_CONFIG_ENVS "TEXCONFIG"
82
#define IST_ENVS "TEXINDEXSTYLE", "INDEXSTYLE"
83
#define TRUETYPE_ENVS "TTFONTS", "TEXFONTS"
84
#define TYPE42_ENVS "T42FONTS", "TEXFONTS"
85
#define WEB2C_ENVS "WEB2C"
86
#define MISCFONTS_ENVS "MISCFONTS", "TEXFONTS"
87
#define WEB_ENVS "WEBINPUTS"
88
#define CWEB_ENVS "CWEBINPUTS"
89
#define ENC_ENVS "ENCFONTS", "TEXFONTS"
90
#define CMAP_ENVS "CMAPFONTS", "TEXFONTS"
91
#define SFD_ENVS "SFDFONTS", "TEXFONTS"
92
#define OPENTYPE_ENVS "OPENTYPEFONTS", "TEXFONTS"
93
#define PDFTEXCONFIG_ENVS "PDFTEXCONFIG"
94
#define LIG_ENVS "LIGFONTS", "TEXFONTS"
95
#define TEXMFSCRIPTS_ENVS "TEXMFSCRIPTS"
97
/* The compiled-in default list, DEFAULT_FONT_SIZES, is intended to be
98
set from the command line (presumably via the Makefile). */
100
#ifndef DEFAULT_FONT_SIZES
101
#define DEFAULT_FONT_SIZES ""
105
kpse_init_fallback_resolutions P1C(string, envvar)
108
const_string size_var = ENVVAR (envvar, "TEXSIZES");
109
string size_str = getenv (size_var);
110
unsigned *last_resort_sizes = NULL;
111
unsigned size_count = 0;
112
const_string default_sizes = kpse_fallback_resolutions_string
113
? kpse_fallback_resolutions_string
114
: DEFAULT_FONT_SIZES;
115
string size_list = kpse_expand_default (size_str, default_sizes);
117
/* Initialize the list of last-resort sizes. */
118
for (size = kpse_path_element (size_list); size != NULL;
119
size = kpse_path_element (NULL))
122
if (! *size) /* Skip empty elements. */
126
if (size_count && s < last_resort_sizes[size_count - 1]) {
127
WARNING1 ("kpathsea: last resort size %s not in ascending order, ignored",
131
XRETALLOC (last_resort_sizes, size_count, unsigned);
132
last_resort_sizes[size_count - 1] = atoi (size);
136
/* Add a zero to mark the end of the list. */
138
XRETALLOC (last_resort_sizes, size_count, unsigned);
139
last_resort_sizes[size_count - 1] = 0;
143
kpse_fallback_resolutions = last_resort_sizes;
146
/* We should be able to set the program arguments in the same way. Not
147
to mention the path values themselves. */
150
kpse_set_program_enabled P3C(kpse_file_format_type, fmt, boolean, value,
151
kpse_src_type, level)
153
kpse_format_info_type *f = &kpse_format_info[fmt];
154
if (level >= f->program_enable_level) {
155
f->program_enabled_p = value;
156
f->program_enable_level = level;
161
/* Web2c and kpsewhich have command-line options to set this stuff. May
162
as well have a common place. */
165
kpse_maketex_option P2C(const_string, fmtname, boolean, value)
167
kpse_file_format_type fmt = kpse_last_format;
169
/* Trying to match up with the suffix lists unfortunately doesn't work
170
well, since that would require initializing the formats. */
171
/* FIXME: Currently the function silently ignores unrecognized arguments.*/
172
if (FILESTRCASEEQ (fmtname, "pk")) {
173
fmt = kpse_pk_format;
174
} else if (FILESTRCASEEQ (fmtname, "mf")) {
175
fmt = kpse_mf_format;
176
} else if (FILESTRCASEEQ (fmtname, "tex")) {
177
fmt = kpse_tex_format;
178
} else if (FILESTRCASEEQ (fmtname, "tfm")) {
179
fmt = kpse_tfm_format;
180
} else if (FILESTRCASEEQ (fmtname, "ofm")) {
181
fmt = kpse_ofm_format;
182
} else if (FILESTRCASEEQ (fmtname, "ocp")) {
183
fmt = kpse_ocp_format;
185
if (fmt != kpse_last_format) {
186
kpse_set_program_enabled (fmt, value, kpse_src_cmdline);
190
/* Macro subroutines for `init_path'. TRY_ENV checks if an envvar ENAME
191
is set and non-null, and sets var to ENAME if so. */
192
#define TRY_ENV(ename) do { \
193
string evar = ename; \
196
/* And EXPAND_DEFAULT calls kpse_expand_default on try_path and the
197
present info->path. */
198
#define EXPAND_DEFAULT(try_path, source_string) \
200
info->raw_path = try_path; \
201
info->path = kpse_expand_default (try_path, info->path); \
202
info->path_source = source_string; \
205
/* Find the final search path to use for the format entry INFO, given
206
the compile-time default (DEFAULT_PATH), and the environment
207
variables to check (the remaining arguments, terminated with NULL).
208
We set the `path' and `path_source' members of INFO. The
209
`client_path' member must already be set upon entry. */
212
init_path PVAR2C(kpse_format_info_type *, info, const_string, default_path, ap)
215
string env_value = NULL;
218
info->default_path = default_path;
220
/* First envvar that's set to a nonempty value will exit the loop. If
221
none are set, we want the first cnf entry that matches. Find the
222
cnf entries simultaneously, to avoid having to go through envvar
223
list twice -- because of the PVAR?C macro, that would mean having
224
to create a str_list and then use it twice. Yuck. */
225
while ((env_name = va_arg (ap, string)) != NULL) {
226
/* Since sh doesn't like envvar names with `.', check PATH_prog
227
as well as PATH.prog. */
230
string evar = concat3 (env_name, ".", kpse_program_name);
231
env_value = getenv (evar);
232
if (env_value && *env_value) {
237
evar = concat3 (env_name, "_", kpse_program_name);
238
env_value = getenv (evar);
239
if (env_value && *env_value) {
243
/* Try simply PATH. */
244
env_value = getenv (env_name);
245
if (env_value && *env_value) {
252
/* If we are initializing the cnf path, don't try to get any
253
values from the cnf files; that's infinite loop time. */
254
if (!info->cnf_path && info != &kpse_format_info[kpse_cnf_format])
255
info->cnf_path = kpse_cnf_get (env_name);
257
if (var && info->cnf_path)
262
/* Expand any extra :'s. For each level, we replace an extra : with
263
the path at the next lower level. For example, an extra : in a
264
user-set envvar should be replaced with the path from the cnf file.
265
things are complicated because none of the levels above the very
266
bottom are guaranteed to exist. */
268
/* Assume we can reliably start with the compile-time default. */
269
info->path = info->raw_path = info->default_path;
270
info->path_source = "compile-time paths.h";
272
/* Translate ';' in the envvar into ':' if that's our ENV_SEP. */
273
if (IS_ENV_SEP(':') && env_value) {
275
env_value = xstrdup(env_value); /* Freed below. */
276
for (loc = env_value; *loc; loc++) {
282
EXPAND_DEFAULT (info->cnf_path, "texmf.cnf");
283
EXPAND_DEFAULT (info->client_path, "program config file");
285
EXPAND_DEFAULT (env_value, concat (var, " environment variable"));
286
EXPAND_DEFAULT (info->override_path, "application override variable");
287
info->path = kpse_brace_expand (info->path);
289
/* Free the copied env_value. */
290
if (IS_ENV_SEP(':') && env_value)
295
/* Some file types have more than one suffix. */
296
/* Some times it is convenient to modify the list of searched suffixes.
297
*** Don't complain if this function goes away. ***
300
kpse_set_suffixes PVAR2C(kpse_file_format_type, format,
301
boolean, alternate, ap)
308
list = &kpse_format_info[format].alt_suffix;
311
list = &kpse_format_info[format].suffix;
314
while ((s = va_arg (ap, string)) != NULL) {
316
XRETALLOC (*list, count + 1, const_string);
317
(*list)[count - 1] = s;
320
(*list)[count] = NULL;
324
/* The path spec we are defining, one element of the global array. */
325
#define FMT_INFO kpse_format_info[format]
326
/* Call kpse_set_add_suffixes. */
327
#define SUFFIXES(args) kpse_set_suffixes(format, false, args, NULL)
328
#define ALT_SUFFIXES(args) kpse_set_suffixes(format, true, args, NULL)
330
/* Call `init_path', including appending the trailing NULL to the envvar
331
list. Also initialize the fields not needed in setting the path. */
332
#define INIT_FORMAT(text, default_path, envs) \
333
FMT_INFO.type = text; \
334
init_path (&FMT_INFO, default_path, envs, NULL)
337
/* A few file types allow for runtime generation by an external program.
338
kpse_init_prog may have already initialized it (the `program'
339
member). Here we allow people to turn it off or on in the config
340
file, by setting the variable whose name is the uppercasified program
344
init_maketex PVAR2C(kpse_file_format_type, fmt, const_string, dflt_prog, ap)
346
kpse_format_info_type *f = &kpse_format_info[fmt];
347
const_string prog = f->program ? f->program : dflt_prog; /* mktexpk */
348
string PROG = uppercasify (prog); /* MKTEXPK */
349
string progval = kpse_var_value (PROG); /* ENV/cnf{"MKTEXPK"} */
352
/* Doesn't hurt to always set this info. */
355
/* Set up the argument vector. */
357
f->argv = XTALLOC(2, const_string);
358
f->argv[f->argc++] = dflt_prog;
359
while ((arg = va_arg (ap, string)) != NULL) {
361
XRETALLOC (f->argv, f->argc + 1, const_string);
362
f->argv[f->argc - 1] = arg;
364
f->argv[f->argc] = NULL;
366
if (progval && *progval) {
367
/* This might actually be from an environment variable value, but in
368
that case, we'll have previously set it from kpse_init_prog. */
369
kpse_set_program_enabled (fmt, *progval == '1', kpse_src_client_cnf);
375
/* We need this twice, so ... */
376
#define MKTEXPK_ARGS \
377
"--mfmode","$MAKETEX_MODE",\
378
"--bdpi","$MAKETEX_BASE_DPI",\
379
"--mag","$MAKETEX_MAG",\
380
"--dpi","$KPATHSEA_DPI",\
384
remove_dbonly P1C(const_string, path)
386
string ret = XTALLOC(strlen (path) + 1, char), q=ret;
388
boolean new_elt=true;
391
if (new_elt && *p && *p == '!' && *(p+1) == '!')
394
new_elt = (*p == ENV_SEP);
402
/* Initialize everything for FORMAT. */
405
kpse_init_format P1C(kpse_file_format_type, format)
407
/* If we get called twice, don't redo all the work. */
409
return FMT_INFO.path;
412
{ /* We might be able to avoid repeating `gf' or whatever so many
413
times with token pasting, but it doesn't seem worth it. */
415
INIT_FORMAT ("gf", DEFAULT_GFFONTS, GF_ENVS);
417
FMT_INFO.suffix_search_only = true;
418
FMT_INFO.binmode = true;
421
init_maketex (format, "mktexpk", MKTEXPK_ARGS);
422
INIT_FORMAT ("pk", DEFAULT_PKFONTS, PK_ENVS);
424
FMT_INFO.suffix_search_only = true;
425
FMT_INFO.binmode = true;
427
case kpse_any_glyph_format:
428
init_maketex (format, "mktexpk", MKTEXPK_ARGS);
429
INIT_FORMAT ("bitmap font", DEFAULT_GLYPHFONTS, GLYPH_ENVS);
430
FMT_INFO.suffix_search_only = true;
431
FMT_INFO.binmode = true;
433
case kpse_tfm_format:
434
/* Must come before kpse_ofm_format. */
435
init_maketex (format, "mktextfm", NULL);
436
INIT_FORMAT ("tfm", DEFAULT_TFMFONTS, TFM_ENVS);
438
FMT_INFO.suffix_search_only = true;
439
FMT_INFO.binmode = true;
441
case kpse_afm_format:
442
INIT_FORMAT ("afm", DEFAULT_AFMFONTS, AFM_ENVS);
445
case kpse_base_format:
446
init_maketex (format, "mktexfmt", NULL);
447
INIT_FORMAT ("base", DEFAULT_MFBASES, BASE_ENVS);
449
FMT_INFO.binmode = true;
451
case kpse_bib_format:
452
INIT_FORMAT ("bib", DEFAULT_BIBINPUTS, BIB_ENVS);
454
FMT_INFO.suffix_search_only = true;
456
case kpse_bst_format:
457
INIT_FORMAT ("bst", DEFAULT_BSTINPUTS, BST_ENVS);
460
case kpse_cnf_format:
461
INIT_FORMAT ("cnf", DEFAULT_TEXMFCNF, CNF_ENVS);
465
INIT_FORMAT ("ls-R", DEFAULT_TEXMFDBS, DB_ENVS);
466
#define LSR_SUFFIXES "ls-R", "ls-r"
467
SUFFIXES (LSR_SUFFIXES);
468
FMT_INFO.path = remove_dbonly (FMT_INFO.path);
470
case kpse_fmt_format:
471
init_maketex (format, "mktexfmt", NULL);
472
INIT_FORMAT ("fmt", DEFAULT_TEXFORMATS, FMT_ENVS);
474
#define FMT_SUFFIXES ".efmt",".efm",".ofmt",".ofm",".oft",".eofmt",".eoft",".eof",".pfmt",".pfm",".epfmt",".epf",".xpfmt",".xpf",".afmt",".afm"
475
ALT_SUFFIXES (FMT_SUFFIXES);
476
FMT_INFO.binmode = true;
478
case kpse_fontmap_format:
479
INIT_FORMAT ("map", DEFAULT_TEXFONTMAPS, FONTMAP_ENVS);
482
case kpse_mem_format:
483
init_maketex (format, "mktexfmt", NULL);
484
INIT_FORMAT ("mem", DEFAULT_MPMEMS, MEM_ENVS);
486
FMT_INFO.binmode = true;
489
init_maketex (format, "mktexmf", NULL);
490
INIT_FORMAT ("mf", DEFAULT_MFINPUTS, MF_ENVS);
493
case kpse_mft_format:
494
INIT_FORMAT ("mft", DEFAULT_MFTINPUTS, MFT_ENVS);
497
case kpse_mfpool_format:
498
INIT_FORMAT ("mfpool", DEFAULT_MFPOOL, MFPOOL_ENVS);
502
INIT_FORMAT ("mp", DEFAULT_MPINPUTS, MP_ENVS);
505
case kpse_mppool_format:
506
INIT_FORMAT ("mppool", DEFAULT_MPPOOL, MPPOOL_ENVS);
509
case kpse_mpsupport_format:
510
INIT_FORMAT ("MetaPost support", DEFAULT_MPSUPPORT, MPSUPPORT_ENVS);
512
case kpse_ocp_format:
513
init_maketex (format, "mkocp", NULL);
514
INIT_FORMAT ("ocp", DEFAULT_OCPINPUTS, OCP_ENVS);
516
FMT_INFO.suffix_search_only = true;
517
FMT_INFO.binmode = true;
519
case kpse_ofm_format:
520
init_maketex (format, "mkofm", NULL);
521
INIT_FORMAT ("ofm", DEFAULT_OFMFONTS, OFM_ENVS);
522
#define OFM_SUFFIXES ".ofm", ".tfm"
523
SUFFIXES (OFM_SUFFIXES);
524
FMT_INFO.suffix_search_only = true;
525
FMT_INFO.binmode = true;
527
case kpse_opl_format:
528
INIT_FORMAT ("opl", DEFAULT_OPLFONTS, OPL_ENVS);
530
FMT_INFO.suffix_search_only = true;
532
case kpse_otp_format:
533
INIT_FORMAT ("otp", DEFAULT_OTPINPUTS, OTP_ENVS);
535
FMT_INFO.suffix_search_only = true;
537
case kpse_ovf_format:
538
INIT_FORMAT ("ovf", DEFAULT_OVFFONTS, OVF_ENVS);
540
FMT_INFO.suffix_search_only = true;
541
FMT_INFO.binmode = true;
543
case kpse_ovp_format:
544
INIT_FORMAT ("ovp", DEFAULT_OVPFONTS, OVP_ENVS);
546
FMT_INFO.suffix_search_only = true;
548
case kpse_pict_format:
549
INIT_FORMAT ("graphic/figure", DEFAULT_TEXINPUTS, PICT_ENVS);
550
#define PICT_SUFFIXES ".eps", ".epsi"
551
ALT_SUFFIXES (PICT_SUFFIXES);
552
FMT_INFO.binmode = true;
554
case kpse_tex_format:
555
init_maketex (format, "mktextex", NULL);
556
INIT_FORMAT ("tex", DEFAULT_TEXINPUTS, TEX_ENVS);
558
/* We don't maintain a list of alternate TeX suffixes. Such a list
559
could never be complete. */
561
case kpse_tex_ps_header_format:
562
INIT_FORMAT ("PostScript header", DEFAULT_TEXPSHEADERS,
564
/* Unfortunately, dvipsk uses this format for type1 fonts. */
565
#define TEXPSHEADER_SUFFIXES ".pro"
566
ALT_SUFFIXES (TEXPSHEADER_SUFFIXES);
567
FMT_INFO.binmode = true;
569
case kpse_texdoc_format:
570
INIT_FORMAT ("TeX system documentation", DEFAULT_TEXDOCS, TEXDOC_ENVS);
572
case kpse_texpool_format:
573
INIT_FORMAT ("texpool", DEFAULT_TEXPOOL, TEXPOOL_ENVS);
576
case kpse_texsource_format:
577
INIT_FORMAT ("TeX system sources", DEFAULT_TEXSOURCES, TEXSOURCE_ENVS);
579
case kpse_troff_font_format:
580
INIT_FORMAT ("Troff fonts", DEFAULT_TRFONTS, TROFF_FONT_ENVS);
581
FMT_INFO.binmode = true;
583
case kpse_type1_format:
584
INIT_FORMAT ("type1 fonts", DEFAULT_T1FONTS, TYPE1_ENVS);
585
#define TYPE1_SUFFIXES ".pfa", ".pfb"
586
SUFFIXES (TYPE1_SUFFIXES);
587
FMT_INFO.binmode = true;
590
INIT_FORMAT ("vf", DEFAULT_VFFONTS, VF_ENVS);
592
FMT_INFO.suffix_search_only = true;
593
FMT_INFO.binmode = true;
595
case kpse_dvips_config_format:
596
INIT_FORMAT ("dvips config", DEFAULT_TEXCONFIG, DVIPS_CONFIG_ENVS);
598
case kpse_ist_format:
599
INIT_FORMAT ("ist", DEFAULT_INDEXSTYLE, IST_ENVS);
602
case kpse_truetype_format:
603
INIT_FORMAT ("truetype fonts", DEFAULT_TTFONTS, TRUETYPE_ENVS);
604
#define TRUETYPE_SUFFIXES ".ttf", ".ttc", ".TTF", ".TTC"
605
SUFFIXES (TRUETYPE_SUFFIXES);
606
FMT_INFO.suffix_search_only = false;
607
FMT_INFO.binmode = true;
609
case kpse_type42_format:
610
INIT_FORMAT ("type42 fonts", DEFAULT_T42FONTS, TYPE42_ENVS);
611
FMT_INFO.binmode = true;
613
case kpse_web2c_format:
614
INIT_FORMAT ("web2c files", DEFAULT_WEB2C, WEB2C_ENVS);
616
case kpse_program_text_format:
617
INIT_FORMAT ("other text files",
618
concatn (".", ENV_SEP_STRING, "$TEXMF/",
619
kpse_program_name, "//", NULL),
620
concat (uppercasify (kpse_program_name), "INPUTS"));
622
case kpse_program_binary_format:
623
INIT_FORMAT ("other binary files",
624
concatn (".", ENV_SEP_STRING, "$TEXMF/",
625
kpse_program_name, "//", NULL),
626
concat (uppercasify (kpse_program_name), "INPUTS"));
627
FMT_INFO.binmode = true;
629
case kpse_miscfonts_format:
630
INIT_FORMAT ("misc fonts", DEFAULT_MISCFONTS, MISCFONTS_ENVS);
631
FMT_INFO.binmode = true;
633
case kpse_web_format:
634
INIT_FORMAT ("web", DEFAULT_WEBINPUTS, WEB_ENVS);
636
ALT_SUFFIXES (".ch");
638
case kpse_cweb_format:
639
INIT_FORMAT ("cweb", DEFAULT_CWEBINPUTS, CWEB_ENVS);
640
#define CWEB_SUFFIXES ".w", ".web"
641
SUFFIXES (CWEB_SUFFIXES);
642
ALT_SUFFIXES (".ch");
644
case kpse_enc_format:
645
INIT_FORMAT ("enc files", DEFAULT_ENCFONTS, ENC_ENVS);
648
case kpse_cmap_format:
649
INIT_FORMAT ("cmap files", DEFAULT_CMAPFONTS, CMAP_ENVS);
652
case kpse_sfd_format:
653
INIT_FORMAT ("subfont definition files", DEFAULT_SFDFONTS, SFD_ENVS);
656
case kpse_opentype_format:
657
INIT_FORMAT ("opentype fonts", DEFAULT_OPENTYPEFONTS, OPENTYPE_ENVS);
659
FMT_INFO.binmode = true;
661
case kpse_pdftex_config_format:
662
INIT_FORMAT ("pdftex config", DEFAULT_PDFTEXCONFIG, PDFTEXCONFIG_ENVS);
664
case kpse_lig_format:
665
INIT_FORMAT ("lig files", DEFAULT_LIGFONTS, LIG_ENVS);
668
case kpse_texmfscripts_format:
669
INIT_FORMAT ("texmfscripts", DEFAULT_TEXMFSCRIPTS, TEXMFSCRIPTS_ENVS);
672
FATAL1 ("kpse_init_format: Unknown format %d", format);
676
#define MAYBE(member) (FMT_INFO.member ? FMT_INFO.member : "(none)")
678
/* Describe the monster we've created. */
679
if (KPSE_DEBUG_P (KPSE_DEBUG_PATHS))
681
DEBUGF2 ("Search path for %s files (from %s)\n",
682
FMT_INFO.type, FMT_INFO.path_source);
683
DEBUGF1 (" = %s\n", FMT_INFO.path);
684
DEBUGF1 (" before expansion = %s\n", FMT_INFO.raw_path);
685
DEBUGF1 (" application override path = %s\n", MAYBE (override_path));
686
DEBUGF1 (" application config file path = %s\n", MAYBE (client_path));
687
DEBUGF1 (" texmf.cnf path = %s\n", MAYBE (cnf_path));
688
DEBUGF1 (" compile-time path = %s\n", MAYBE (default_path));
689
DEBUGF (" default suffixes =");
690
if (FMT_INFO.suffix) {
692
for (ext = FMT_INFO.suffix; ext && *ext; ext++) {
693
fprintf (stderr, " %s", *ext);
697
fputs (" (none)\n", stderr);
699
DEBUGF (" other suffixes =");
700
if (FMT_INFO.alt_suffix) {
702
for (alt = FMT_INFO.alt_suffix; alt && *alt; alt++) {
703
fprintf (stderr, " %s", *alt);
707
fputs (" (none)\n", stderr);
709
DEBUGF1 (" search only with suffix = %d\n",FMT_INFO.suffix_search_only);
710
DEBUGF1 (" numeric format value = %d\n", format);
711
DEBUGF1 (" runtime generation program = %s\n", MAYBE (program));
712
DEBUGF (" runtime generation command =");
715
for (arg = FMT_INFO.argv; *arg; arg++) {
716
fprintf (stderr, " %s", *arg);
720
fputs(" (none)\n", stderr);
722
DEBUGF1 (" program enabled = %d\n", FMT_INFO.program_enabled_p);
723
DEBUGF1 (" program enable level = %d\n", FMT_INFO.program_enable_level);
725
#endif /* KPSE_DEBUG */
727
return FMT_INFO.path;
730
/* Look up a file NAME of type FORMAT, and the given MUST_EXIST. This
731
initializes the path spec for FORMAT if it's the first lookup of that
732
type. Return the filename found, or NULL. This is the most likely
733
thing for clients to call. */
736
kpse_find_file P3C(const_string, name, kpse_file_format_type, format,
740
unsigned name_len = 0;
741
boolean name_has_suffix_already = false;
743
string *mapped_names;
744
const_string *target;
746
boolean use_fontmaps = (format == kpse_tfm_format
747
|| format == kpse_gf_format
748
|| format == kpse_pk_format
749
|| format == kpse_ofm_format);
752
/* NAME being NULL is a programming bug somewhere. NAME can be empty,
753
though; this happens with constructs like `\input\relax'. */
756
if (FMT_INFO.path == NULL)
757
kpse_init_format (format);
759
if (KPSE_DEBUG_P(KPSE_DEBUG_SEARCH))
760
DEBUGF3 ("kpse_find_file: searching for %s of type %s (from %s)\n",
761
name, FMT_INFO.type, FMT_INFO.path_source);
763
/* Do variable and tilde expansion. */
764
name = kpse_expand(name);
766
/* Does NAME already end in a possible suffix? */
767
name_len = strlen (name);
768
if (FMT_INFO.suffix) {
769
for (ext = FMT_INFO.suffix; !name_has_suffix_already && *ext; ext++) {
770
unsigned suffix_len = strlen (*ext);
771
name_has_suffix_already = (name_len >= suffix_len
772
&& FILESTRCASEEQ (*ext, name + name_len - suffix_len));
775
if (!name_has_suffix_already && FMT_INFO.alt_suffix) {
776
for (ext = FMT_INFO.alt_suffix; !name_has_suffix_already && *ext; ext++) {
777
unsigned suffix_len = strlen (*ext);
778
name_has_suffix_already = (name_len >= suffix_len
779
&& FILESTRCASEEQ (*ext, name + name_len - suffix_len));
783
/* Set up target list. */
785
target = XTALLOC1 (const_string);
786
/* Case #1: NAME doesn't have a suffix which is equal to a "standard"
787
suffix. For example, foo.bar, but not foo.tex. We look for the
788
name with the standard suffixes appended. */
789
if (!name_has_suffix_already && FMT_INFO.suffix) {
790
for (ext = FMT_INFO.suffix; *ext; ext++) {
791
string name_with_suffix = concat (name, *ext);
792
target[count++] = name_with_suffix;
793
XRETALLOC(target, count+1, const_string);
795
&& (mapped_names = kpse_fontmap_lookup (name_with_suffix)) != NULL)
797
/* FIXME: we leak mapped_names and its elements, some of the time */
798
while ((mapped_name = *mapped_names++) != NULL) {
799
target[count++] = xstrdup (mapped_name);
800
XRETALLOC(target, count+1, const_string);
805
/* Case #2: Just look for the name we've been given, provided non-suffix
806
searches are allowed or the name already includes a suffix. */
807
if (name_has_suffix_already || !FMT_INFO.suffix_search_only) {
808
target[count++] = xstrdup (name);
809
XRETALLOC(target, count+1, const_string);
810
if (use_fontmaps && (mapped_names = kpse_fontmap_lookup (name)) != NULL) {
811
/* FIXME: we leak mapped_names and its elements, some of the time */
812
while ((mapped_name = *mapped_names++) != NULL) {
813
target[count++] = xstrdup (mapped_name);
814
XRETALLOC(target, count+1, const_string);
818
/* Terminate list. */
819
target[count] = NULL;
823
/* Simple version, just do the search for the list, and pound disk
824
* then and there if appropriate.
826
ret = kpse_path_search_list (FMT_INFO.path, target, must_exist);
828
/* Variant where we delay disk-pounding. */
829
ret = kpse_path_search_list (FMT_INFO.path, target, false);
830
if (!ret && must_exist)
831
ret = kpse_path_search_list (FMT_INFO.path, target, true);
833
/* Variant that tries the match the original behaviour more closely.
834
* The distinction is that we pound the disk for a far shorter list
837
* This is the fastest variant, because it does fewer disk accesses
838
* than the two variants above -- for example some 750 calls of
839
* access(2) compared to 1500.
841
ret = kpse_path_search_list (FMT_INFO.path, target, false);
842
/* Do we need to pound the disk? */
843
if (!ret && must_exist) {
844
for (count = 0; target[count]; count++)
845
free((void*)target[count]);
847
/* We look for a subset of the previous set of names, so the
848
* target array is large enough. In particular, we don't pound
849
* the disk for alternate names from the fontmaps. Perhaps we
852
if (!name_has_suffix_already && FMT_INFO.suffix_search_only) {
853
for (ext = FMT_INFO.suffix; !ret && *ext; ext++)
854
target[count++] = concat (name, *ext);
856
if (name_has_suffix_already || !FMT_INFO.suffix_search_only) {
857
target[count++] = xstrdup (name);
859
target[count] = NULL;
860
ret = kpse_path_search_list (FMT_INFO.path, target, true);
864
/* Free the list we created. */
865
for (count = 0; target[count]; count++)
866
free((void*)target[count]);
869
/* If nothing was found, call mktex* to create a missing file. */
870
if (!ret && must_exist) {
871
ret = kpse_make_tex (format, name);
879
/* Open NAME along the search path for TYPE for reading and return the
880
resulting file, or exit with an error message. */
883
kpse_open_file P2C(const_string, name, kpse_file_format_type, type)
885
string fullname = kpse_find_file (name, type, true);
886
const_string mode = kpse_format_info[type].binmode
889
FILE *f = fullname ? fopen (fullname, mode) : NULL;
895
FATAL2 ("%s file `%s' not found", kpse_format_info[type].type, name);
902
/* When using the %&<format> construct, we'd like to use the paths for
903
that format, rather than those for the name we were called with.
904
Of course this happens after various initializations have been
905
performed, so we have this function to force the issue. Note that
906
the paths for kpse_cnf_format and kpse_db_format are not cleared.
908
This function is defined here, and not in progname.c, because it
909
need kpse_format_info, and would cause all of tex-file to be pulled
910
in by programs that do not need it. */
912
kpse_reset_program_name P1C(const_string, progname)
916
/* It is a fatal error for either of these to be NULL. */
917
assert (progname && kpse_program_name);
918
/* Do nothing if the name is unchanged. */
919
if (STREQ(kpse_program_name, progname))
922
free (kpse_program_name);
923
kpse_program_name = xstrdup (progname);
924
xputenv("progname", kpse_program_name);
926
/* Clear paths -- do we want the db path to be cleared? */
927
for (i = 0; i != kpse_last_format; ++i) {
928
/* Do not erase the cnf of db paths. This means that the filename
929
database is not rebuilt, nor are different configuration files
930
searched. The alternative is to tolerate a memory leak of up
931
to 100k if this function is called. */
932
if (i == kpse_cnf_format || i == kpse_db_format)
934
/* Wipe the path (it is tested) and the cnf_path and because their
935
values may differ with the new program name. */
936
if (kpse_format_info[i].path != NULL) {
937
free ((string)kpse_format_info[i].path);
938
kpse_format_info[i].path = NULL;
940
/* We cannot free the cnf_path: it points into the cnf hash, which
941
means all hell will break loose if we did. */
942
if (kpse_format_info[i].cnf_path != NULL) {
943
kpse_format_info[i].cnf_path = NULL;
945
/* We do not wipe the override_path at this point, though arguably
946
we should provide new values. It is not likely to matter for
947
the programs that call this function. */