OSDN Git Service

branch: yandytex with kpathsea.
[putex/putex.git] / src / texsourc / kpathsea / kpathsea / cnf-to-paths.awk
1 # $Id: cnf-to-paths.awk 23442 2011-08-07 22:50:24Z karl $
2 # cnf-to-paths.awk - convert texmf.cnf assignments to paths.h #define's.
3 # Public domain.  Originally written 2011, Karl Berry.
4
5 # We assume comments have been stripped.
6
7 # we only care about definitions with a valid C identifier (e.g.,
8 # TEXINPUTS, not TEXINPUTS.latex), that is, lines that look like this:
9 #   <name> = <value>
10 # (whitespace around the = is optional)
11 #
12 /^[ \t]*[A-Z0-9_]+[ \t]*=/ {
13   # On these lines, we distinguish three cases:
14   # 
15   # 1) definitions referring to SELFAUTO*, which we want to keep.  In
16   # particular, this is how the compile-time TEXMFCNF gets defined and
17   # thus how texmf.cnf gets found.
18   # 
19   # 2) definitions starting with a /, which we also want to keep.  Here
20   # we assume a distro maintainer has changed a variable, e.g.,
21   # TEXMFMAIN=/usr/share/texmf, so keep it.  (This also preserves the
22   # default values for OSFONTDIR and TRFONTS, but that's ok.)
23   # 
24   # 3) anything else, which we want to convert to a constant /nonesuch.
25   # That way, the binaries don't get changed just because we change
26   # definitions in texmf.cnf.
27   # 
28   # The definition of DEFAULT_TEXMF (and other variables)
29   # that winds up in the final paths.h will not be used.
30   
31   # Extract the identifier and the value from the line.  Since
32   # gawk's subexpression matching is an extension, do it with copies.
33   ident = $0;
34   sub(/^[ \t]*/, "", ident);
35   sub(/[ \t]*=.*/, "", ident);
36   
37   val = $0;
38   sub(/^.*=[ \t]*/, "", val);
39   sub(/[ \t]*$/, "", val);
40   #print "got ident", ident, "and val", val >"/dev/stderr"; 
41   
42   if (val ~ /\$SELFAUTO/) {
43     # Replace all semicolons with colons in the SELFAUTO paths we're keeping.
44     # (The path-splitting code should be changed to understand both.)
45     gsub(/;/, ":", val);
46   } else if (val ~ /^\//) {
47     # If the value starts with /, presume we're compiling with changes
48     # made for a distro, and keep it.  Likewise switch to :.
49     gsub(/;/, ":", val);
50   } else {
51     val = "/nonesuch";
52   }
53   
54   print "#ifndef DEFAULT_" ident;
55   print "#define DEFAULT_" ident " \"" val "\"";
56   print "#endif";
57   print "";
58 }