1 /* setupvar.c: Look up a value in texmf.cnf or use default.
2 
3    Adapted in 2010 by Peter Breitenlohner.  Public domain.
4    Written in 1995 by Karl Berry.  Public domain.  */
5 
6 #include <w2c/config.h>
7 #include "lib.h"
8 #include <kpathsea/variable.h>
9 
10 /* Look up VAR_NAME in texmf.cnf; assign either the value found there or
11    DFLT to *VAR.  */
12 
13 void
setupboundvariable(integer * var,const_string var_name,integer dflt)14 setupboundvariable (integer *var, const_string var_name, integer dflt)
15 {
16   string expansion = kpse_var_value (var_name);
17   *var = dflt;
18 
19   if (expansion) {
20     integer conf_val = atoi (expansion);
21     /* It's ok if the cnf file specifies 0 for extra_mem_{top,bot}, etc.
22        But negative numbers are always wrong.  */
23     if (conf_val < 0 || (conf_val == 0 && dflt > 0)) {
24       fprintf (stderr,
25                "%s: Bad value (%ld) in environment or texmf.cnf for %s, keeping %ld.\n",
26                kpse_invocation_name,
27                (long) conf_val, var_name, (long) dflt);
28     } else {
29       *var = conf_val; /* We'll make further checks later.  */
30     }
31     free (expansion);
32   }
33 }
34