w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fcinit.c
Go to the documentation of this file.
1 /*
2  * fontconfig/src/fcinit.c
3  *
4  * Copyright © 2001 Keith Packard
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the author(s) not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission. The authors make no
13  * representations about the suitability of this software for any purpose. It
14  * is provided "as is" without express or implied warranty.
15  *
16  * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24 
25 #include "fcint.h"
26 #include <stdlib.h>
27 
28 #if defined(FC_ATOMIC_INT_NIL)
29 #pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe.")
30 #endif
31 #if defined(FC_MUTEX_IMPL_NIL)
32 #pragma message("Could not find any system to define mutex macros, library may NOT be thread-safe.")
33 #endif
34 #if defined(FC_ATOMIC_INT_NIL) || defined(FC_MUTEX_IMPL_NIL)
35 #pragma message("To suppress these warnings, define FC_NO_MT.")
36 #endif
37 
38 #ifdef _WIN32
39 extern char * kpse_var_value(char *a);
40 #endif
41 
42 static FcConfig *
43 FcInitFallbackConfig (const FcChar8 *sysroot)
44 {
46 #ifndef _WIN32
47  const FcChar8 *fallback = (const FcChar8 *) "" \
48  "<fontconfig>" \
50  " <dir prefix=\"xdg\">fonts</dir>" \
51  " <cachedir>" FC_CACHEDIR "</cachedir>" \
52  " <cachedir prefix=\"xdg\">fontconfig</cachedir>" \
53  " <include ignore_missing=\"yes\">" CONFIGDIR "</include>" \
54  " <include ignore_missing=\"yes\" prefix=\"xdg\">fontconfig/conf.d</include>" \
55  " <include ignore_missing=\"yes\" prefix=\"xdg\">fontconfig/fonts.conf</include>" \
56  "</fontconfig>";
57 #endif /* !_WIN32 */
58 
60  if (!config)
61  goto bail0;
62  FcConfigSetSysRoot (config, sysroot);
63 #ifndef _WIN32
65  goto bail1;
66 #endif /* !_WIN32 */
67 
68  return config;
69 
70 bail1:
72 bail0:
73  return 0;
74 }
75 
76 int
78 {
79  return FC_VERSION;
80 }
81 
82 #ifdef WIN32
83 static int is_dir (char *buff)
84 {
85  struct stat stats;
86 
87  return stat (buff, &stats) == 0 && S_ISDIR (stats.st_mode);
88 }
89 #endif
90 
91 /*
92  * Load the configuration files
93  */
94 FcConfig *
96 {
97 #ifdef WIN32
98  FcChar8 *kp8 = NULL;
99  char *p;
100 
101  p = kpse_var_value("XE_FC_CACHEDIR");
102  if(p == NULL)
103  p = kpse_var_value("FC_CACHEDIR");
104  if(p == NULL) {
105  fprintf(stderr, "I cannot determine FC_CACHEDIR. ");
106  fprintf(stderr, "Define FC_CACHEDIR in texmf.cnf.\n");
107  exit(1);
108  } else {
109  kp8 = (FcChar8 *)malloc(strlen(p) + 1);
110  strcpy(kp8, p);
111  free(p);
112  }
113 #endif
114 
115  if (!config)
116  {
117  config = FcConfigCreate ();
118  if (!config)
119  return NULL;
120  }
121 
122  FcInitDebug ();
123 
125  {
126  const FcChar8 *sysroot = FcConfigGetSysRoot (config);
128 
129 #ifdef WIN32
130  if (fallback) {
132  if(!kp8 || is_dir(kp8) == 0) {
133  if(kp8)
134  fprintf(stderr, "%s does not exist.\n", kp8);
135  fprintf(stderr, "Kpathsea is not working.\n");
136  exit(5);
137  }
138  free(kp8);
139  }
140  return fallback;
141 #else
143 
144  return fallback;
145 #endif
146  }
147 #ifdef _MSC_VER
148 #define FC_TEMPLATEDIR "."
149 #endif
150 
151  (void) FcConfigParseOnly (config, (const FcChar8 *)FC_TEMPLATEDIR, FcFalse);
152 
153  if (config->cacheDirs && config->cacheDirs->num == 0)
154 #ifdef WIN32
155  {
157  free(kp8);
158  if (config->cacheDirs && config->cacheDirs->num == 0) {
159  fprintf (stderr,
160  "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
161  return 0;
162  }
163  }
164 #else
165  {
166  FcChar8 *prefix, *p;
167  size_t plen;
168  FcBool have_own = FcFalse;
169  char *env_file, *env_path;
170 
171  env_file = getenv ("FONTCONFIG_FILE");
172  env_path = getenv ("FONTCONFIG_PATH");
173  if ((env_file != NULL && env_file[0] != 0) ||
174  (env_path != NULL && env_path[0] != 0))
175  have_own = FcTrue;
176 
177  if (!have_own)
178  {
179  fprintf (stderr,
180  "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
181  fprintf (stderr,
182  "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
183  FC_CACHEDIR);
184  }
186  if (!prefix)
187  goto bail;
188  plen = strlen ((const char *)prefix);
189  p = realloc (prefix, plen + 12);
190  if (!p)
191  goto bail;
192  prefix = p;
193  memcpy (&prefix[plen], FC_DIR_SEPARATOR_S "fontconfig", 11);
194  prefix[plen + 11] = 0;
195  if (!have_own)
196  fprintf (stderr,
197  "Fontconfig warning: adding <cachedir prefix=\"xdg\">fontconfig</cachedir>\n");
198 
199  if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
201  {
203  const FcChar8 *sysroot;
204 
205  bail:
206  sysroot = FcConfigGetSysRoot (config);
207  fprintf (stderr,
208  "Fontconfig error: out of memory");
209  if (prefix)
210  FcStrFree (prefix);
211  fallback = FcInitFallbackConfig (sysroot);
213 
214  return fallback;
215  }
216  FcStrFree (prefix);
217  }
218 
219 #endif
220  return config;
221 }
222 
223 FcConfig *
225 {
226  return FcInitLoadOwnConfig (NULL);
227 }
228 
229 /*
230  * Load the configuration files and scan for available fonts
231  */
232 FcConfig *
234 {
236  if (!config)
237  return 0;
238  if (!FcConfigBuildFonts (config))
239  {
241  return 0;
242  }
243  return config;
244 }
245 
246 FcConfig *
248 {
250 }
251 
252 /*
253  * Initialize the default library configuration
254  */
255 FcBool
256 FcInit (void)
257 {
258  return FcConfigInit ();
259 }
260 
261 /*
262  * Free all library-allocated data structures.
263  */
264 void
265 FcFini (void)
266 {
267  FcConfigFini ();
268  FcConfigPathFini ();
269  FcDefaultFini ();
270  FcObjectFini ();
271  FcCacheFini ();
272 }
273 
274 /*
275  * Reread the configuration and available font lists
276  */
277 FcBool
279 {
280  FcConfig *config;
281  FcBool ret;
282 
284  if (!config)
285  return FcFalse;
287  /* FcConfigSetCurrent() increases the refcount.
288  * decrease it here to avoid the memory leak.
289  */
291 
292  return ret;
293 }
294 
295 FcBool
297 {
299  FcBool ret = FcTrue;
300  time_t now;
301 
302  if (!config)
303  return FcFalse;
304  /*
305  * rescanInterval == 0 disables automatic up to date
306  */
307  if (config->rescanInterval == 0)
308  goto bail;
309  /*
310  * Check no more often than rescanInterval seconds
311  */
312  now = time (0);
313  if (config->rescanTime + config->rescanInterval - now > 0)
314  goto bail;
315  /*
316  * If up to date, don't reload configuration
317  */
318  if (FcConfigUptoDate (0))
319  goto bail;
320  ret = FcInitReinitialize ();
321 bail:
323 
324  return ret;
325 }
326 
327 #define __fcinit__
328 #include "fcaliastail.h"
329 #undef __fcinit__
#define free(a)
Definition: decNumber.cpp:310
int is_dir(char *buff)
Definition: dirutil.c:24
char * strcpy()
#define FcConfigBuildFonts
Definition: fcalias.h:48
#define FcConfigParseAndLoad
Definition: fcalias.h:446
#define FcConfigCreate
Definition: fcalias.h:36
#define FcConfigUptoDate
Definition: fcalias.h:46
#define FcConfigDestroy
Definition: fcalias.h:40
#define FcConfigSetSysRoot
Definition: fcalias.h:80
#define FcConfigGetSysRoot
Definition: fcalias.h:78
#define FcConfigSetCurrent
Definition: fcalias.h:42
#define FcConfigReference
Definition: fcalias.h:38
#define FcStrFree
Definition: fcalias.h:396
#define FcConfigParseAndLoadFromMemory
Definition: fcalias.h:448
void FcCacheFini(void)
Definition: fccache.c:792
FcChar8 * FcConfigXdgCacheHome(void)
Definition: fccfg.c:2564
void FcConfigFini(void)
Definition: fccfg.c:130
FcBool FcConfigInit(void)
Definition: fccfg.c:124
FcBool FcConfigAddCacheDir(FcConfig *config, const FcChar8 *d)
Definition: fccfg.c:768
void FcInitDebug(void)
Definition: fcdbg.c:569
void FcDefaultFini(void)
Definition: fcdefault.c:215
FcConfig * FcInitLoadOwnConfig(FcConfig *config)
Definition: fcinit.c:95
FcBool FcInitBringUptoDate(void)
Definition: fcinit.c:296
int FcGetVersion(void)
Definition: fcinit.c:77
FcConfig * FcInitLoadOwnConfigAndFonts(FcConfig *config)
Definition: fcinit.c:233
static FcConfig * FcInitFallbackConfig(const FcChar8 *sysroot)
Definition: fcinit.c:43
void FcFini(void)
Definition: fcinit.c:265
FcBool FcInitReinitialize(void)
Definition: fcinit.c:278
FcBool FcInit(void)
Definition: fcinit.c:256
FcConfig * FcInitLoadConfig(void)
Definition: fcinit.c:224
FcConfig * FcInitLoadConfigAndFonts(void)
Definition: fcinit.c:247
void FcObjectFini(void)
Definition: fcobjs.c:48
void FcConfigPathFini(void)
Definition: fcxml.c:2408
FcBool FcConfigParseOnly(FcConfig *config, const FcChar8 *name, FcBool complain)
Definition: fcxml.c:3654
#define FC_DIR_SEPARATOR_S
Definition: fcint.h:80
unsigned char FcChar8
Definition: fontconfig.h:43
#define FcFalse
Definition: fontconfig.h:75
#define FcTrue
Definition: fontconfig.h:76
int FcBool
Definition: fontconfig.h:46
#define FC_VERSION
Definition: fontconfig.h:58
static void
Definition: fpif.c:118
static char buff[2 *10240]
Definition: genind.c:46
#define a(n)
Definition: gpos-common.c:148
#define memcpy(d, s, n)
Definition: gsftopk.c:64
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
void exit()
char * getenv()
struct config_s config
#define S_ISDIR(m)
Definition: win32lib.h:203
static int ret
Definition: convert.c:72
#define fprintf
Definition: mendex.h:64
#define prefix
Definition: cwebboot.c:154
#define malloc
Definition: alloca.c:91
long time_t
Definition: types.h:18
int stat(const char *path, struct stat *sbuf)
static struct statistic stats[]
Definition: lstatslib.c:289
#define realloc
Definition: glob.c:206
time_t time()
#define FC_DEFAULT_FONTS
Definition: config.h:34
*job_name strlen((char *) job_name) - 4)
static UBool fallback(char *loc)
Definition: ucurr.cpp:604