~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/driver/parse_ftcap.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file lib/driver/parse_ftcap.c
 
3
 
 
4
  \brief Display Driver - fontcaps
 
5
 
 
6
  (C) 2006-2011 by the GRASS Development Team
 
7
 
 
8
  This program is free software under the GNU General Public License
 
9
  (>=v2). Read the file COPYING that comes with GRASS for details.
 
10
 
 
11
  \author Glynn Clements <glynn gclements.plus.com> (original contributor)
 
12
  \author Huidae Cho <grass4u gmail.com>
 
13
*/
 
14
 
1
15
#include <stdio.h>
2
16
#include <stdlib.h>
3
17
#include <string.h>
 
18
#include <unistd.h>
4
19
#include <grass/gis.h>
5
20
#include <grass/glocale.h>
6
 
#include <grass/freetypecap.h>
 
21
#include <grass/fontcap.h>
7
22
#include "driverlib.h"
8
23
 
 
24
/*!
 
25
  \brief Check if font exists
 
26
*/
9
27
int font_exists(const char *name)
10
28
{
11
 
    FILE *fp;
12
 
 
13
 
    fp = fopen(name, "r");
14
 
    if (!fp)
 
29
    return access(name, R_OK) >= 0;
 
30
}
 
31
 
 
32
/*!
 
33
  \brief Parse fontcap entry
 
34
 
 
35
  \param e pointer to GFONT_CAP struct
 
36
  \param str ?
 
37
 
 
38
  \return 1 on success
 
39
  \return 0 on failure
 
40
*/
 
41
int parse_fontcap_entry(struct GFONT_CAP *e, const char *str)
 
42
{
 
43
    char name[GNAME_MAX], longname[GNAME_MAX], path[GPATH_MAX], encoding[128];
 
44
    int type, index;
 
45
 
 
46
    if (sscanf(str, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
 
47
               name, longname, &type, path, &index, encoding) == 6) {
 
48
        if (!font_exists(path))
 
49
            return 0;
 
50
    }
 
51
    /* GFONT_DRIVER type fonts do not have path. */
 
52
    else if (sscanf(str, "%[^|]|%[^|]|%d||%d|%[^|]|",
 
53
               name, longname, &type, &index, encoding) == 5)
 
54
        path[0] = '\0';
 
55
    else
15
56
        return 0;
16
57
 
17
 
    fclose(fp);
 
58
    e->name = G_store(name);
 
59
    e->longname = G_store(longname);
 
60
    e->type = type;
 
61
    e->path = G_store(path);
 
62
    e->index = index;
 
63
    e->encoding = G_store(encoding);
 
64
 
18
65
    return 1;
19
66
}
20
67
 
21
 
struct GFONT_CAP *parse_freetypecap(void)
 
68
/*!
 
69
  \brief Parse fontcaps
 
70
 
 
71
  \return pointer to GFONT_CAP structure
 
72
*/
 
73
struct GFONT_CAP *parse_fontcap(void)
22
74
{
23
75
    char *capfile, file[GPATH_MAX];
24
76
    char buf[GPATH_MAX];
40
92
 
41
93
    if (fp != NULL) {
42
94
        while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
43
 
            char name[GNAME_MAX], longname[GNAME_MAX],
44
 
                path[GPATH_MAX], encoding[128];
45
 
            int type, index;
 
95
            struct GFONT_CAP cap;
46
96
            char *p;
47
97
 
48
98
            p = strchr(buf, '#');
49
99
            if (p)
50
100
                *p = 0;
51
101
 
52
 
            if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
53
 
                       name, longname, &type, path, &index, encoding)
54
 
                != 6)
55
 
                continue;
56
 
 
57
 
            if (!font_exists(path))
58
 
                continue;
59
 
 
60
 
            fonts = (struct GFONT_CAP *)G_realloc(fonts,
61
 
                                                  (fonts_count +
62
 
                                                   1) *
63
 
                                                  sizeof(struct GFONT_CAP));
64
 
 
65
 
            fonts[fonts_count].name = G_store(name);
66
 
            fonts[fonts_count].longname = G_store(longname);
67
 
            fonts[fonts_count].type = type;
68
 
            fonts[fonts_count].path = G_store(path);
69
 
            fonts[fonts_count].index = index;
70
 
            fonts[fonts_count].encoding = G_store(encoding);
71
 
 
72
 
            fonts_count++;
 
102
            if (!parse_fontcap_entry(&cap, buf))
 
103
                continue;
 
104
 
 
105
            fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
 
106
            fonts[fonts_count++] = cap;
73
107
        }
 
108
 
74
109
        fclose(fp);
75
110
    }
76
111
 
77
 
    fonts = (struct GFONT_CAP *)G_realloc(fonts, (fonts_count + 1) *
78
 
                                          sizeof(struct GFONT_CAP));
 
112
    fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
79
113
    fonts[fonts_count].name = NULL;
80
114
    fonts[fonts_count].path = NULL;
81
115
 
82
116
    return fonts;
83
117
}
84
118
 
85
 
void free_freetypecap(struct GFONT_CAP *ftcap)
 
119
/*!
 
120
  \brief Free allocated GFONT_CAP structure
 
121
 
 
122
  \param ftcap pointer to GFONT_CAP to be freed
 
123
*/
 
124
void free_fontcap(struct GFONT_CAP *ftcap)
86
125
{
87
126
    int i;
88
127
 
97
136
    }
98
137
 
99
138
    G_free(ftcap);
100
 
 
101
 
    return;
102
139
}