19 #include <grass/gis.h>
20 #include <grass/glocale.h>
21 #include <grass/fontcap.h>
29 return access(name, R_OK) >= 0;
43 char name[GNAME_MAX], longname[GNAME_MAX],
path[GPATH_MAX], encoding[128];
46 if (sscanf(str,
"%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
47 name, longname, &type, path, &index, encoding) == 6) {
52 else if (sscanf(str,
"%[^|]|%[^|]|%d||%d|%[^|]|",
53 name, longname, &type, &index, encoding) == 5)
59 e->longname =
G_store(longname);
63 e->encoding =
G_store(encoding);
75 char *capfile,
file[GPATH_MAX];
79 struct GFONT_CAP *fonts =
NULL;
82 if ((capfile = getenv(
"GRASS_FONT_CAP"))) {
83 if ((fp = fopen(capfile,
"r")) ==
NULL)
84 G_warning(_(
"%s: Unable to read font definition file; use the default"),
88 sprintf(file,
"%s/etc/fontcap",
G_gisbase());
89 if ((fp = fopen(file,
"r")) ==
NULL)
90 G_warning(_(
"%s: No font definition file"), file);
94 while (fgets(buf,
sizeof(buf), fp) && !feof(fp)) {
105 fonts = G_realloc(fonts, (fonts_count + 1) *
sizeof(
struct GFONT_CAP));
106 fonts[fonts_count++] = cap;
112 fonts = G_realloc(fonts, (fonts_count + 1) *
sizeof(
struct GFONT_CAP));
113 fonts[fonts_count].name =
NULL;
114 fonts[fonts_count].path =
NULL;
131 for (i = 0; ftcap[i].name; i++) {
133 G_free(ftcap[i].longname);
135 G_free(ftcap[i].encoding);
struct GFONT_CAP * parse_fontcap(void)
Parse fontcaps.
char * G_store(const char *s)
Copy string to allocated memory.
int parse_fontcap_entry(struct GFONT_CAP *e, const char *str)
Parse fontcap entry.
void free_fontcap(struct GFONT_CAP *ftcap)
Free allocated GFONT_CAP structure.
int font_exists(const char *name)
Check if font exists.
void G_free(void *buf)
Free allocated memory.
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_warning(const char *msg,...)
Print a warning message to stderr.