GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
fopen.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <grass/gis.h>
3#include <grass/imagery.h>
4#include <grass/glocale.h>
5
6/******************************************************
7 * I_fopen_group_file_new()
8 * I_fopen_group_file_append()
9 * I_fopen_group_file_old()
10 *
11 * fopen new group files in the current mapset
12 * fopen old group files anywhere
13 *******************************************************/
14
15FILE *fopen_group_file_old(const char *group, const char *mapset,
16 const char *file)
17{
18 FILE *fd;
19
20 if (mapset == NULL || *mapset == 0)
21 mapset = G_mapset();
22
23 /* find file first */
24 if (!I_find_group_file2(group, mapset, file)) {
25 G_warning(_("Unable to find file [%s] of group [%s in %s]"), file,
26 group, mapset);
27
28 return ((FILE *)NULL);
29 }
30
31 fd = G_fopen_old_misc("group", file, group, mapset);
32 if (!fd)
33 G_warning(_("Unable to open file [%s] of group [%s in %s]"), file,
34 group, mapset);
35
36 return fd;
37}
38
39FILE *fopen_subgroup_file_old(const char *group, const char *subgroup,
40 const char *mapset, const char *file)
41{
42 FILE *fd;
43 char element[GNAME_MAX * 2];
44
45 if (mapset == NULL || *mapset == 0)
46 mapset = G_mapset();
47
48 /* find file first */
49 if (!I_find_subgroup_file2(group, subgroup, mapset, file)) {
51 _("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
52 file, subgroup, group, mapset);
53
54 return ((FILE *)NULL);
55 }
56
57 /* get subgroup element name */
58 snprintf(element, sizeof(element), "subgroup/%s/%s", subgroup, file);
59
60 fd = G_fopen_old_misc("group", element, group, mapset);
61 if (!fd)
63 _("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
64 file, subgroup, group, mapset);
65
66 return fd;
67}
68
69FILE *I_fopen_group_file_new(const char *group, const char *file)
70{
71 FILE *fd;
72
73 fd = G_fopen_new_misc("group", file, group);
74 if (!fd)
75 G_warning(_("Unable to create file [%s] of group [%s in %s]"), file,
76 group, G_mapset());
77
78 return fd;
79}
80
81FILE *I_fopen_group_file_append(const char *group, const char *file)
82{
83 FILE *fd;
84
85 fd = G_fopen_append_misc("group", file, group);
86 if (!fd)
87 G_warning(_("Unable to open file [%s] of group [%s in %s]"), file,
88 group, G_mapset());
89
90 return fd;
91}
92
93/*!
94 * \brief Open group file for reading
95 *
96 * Internally uses G_fopen_old_misc
97 *
98 * \param group
99 * \param file
100 * \return FILE *
101 */
102FILE *I_fopen_group_file_old(const char *group, const char *file)
103{
104 return fopen_group_file_old(group, NULL, file);
105}
106
107/*!
108 * \brief Open group file for reading
109 *
110 * Internally uses G_fopen_old_misc
111 *
112 * \param group
113 * \param mapset
114 * \param file
115 * \return FILE *
116 */
117FILE *I_fopen_group_file_old2(const char *group, const char *mapset,
118 const char *file)
119{
120 return fopen_group_file_old(group, mapset, file);
121}
122
123FILE *I_fopen_subgroup_file_new(const char *group, const char *subgroup,
124 const char *file)
125{
126 FILE *fd;
127 char element[GNAME_MAX * 2];
128
129 /* create subgroup directory */
130 snprintf(element, sizeof(element), "%s/subgroup/%s", group, subgroup);
132
133 /* get subgroup element name */
134 snprintf(element, sizeof(element), "subgroup/%s/%s", subgroup, file);
135
136 fd = G_fopen_new_misc("group", element, group);
137 if (!fd)
138 G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s "
139 "in %s]"),
140 file, subgroup, group, G_mapset());
141
142 return fd;
143}
144
145FILE *I_fopen_subgroup_file_append(const char *group, const char *subgroup,
146 const char *file)
147{
148 FILE *fd;
149 char element[GNAME_MAX * 2];
150
151 /* create subgroup directory */
152 snprintf(element, sizeof(element), "%s/subgroup/%s", group, subgroup);
154
155 /* get subgroup element name */
156 snprintf(element, sizeof(element), "subgroup/%s/%s", subgroup, file);
157
158 fd = G_fopen_append_misc("group", element, group);
159 if (!fd)
160 G_warning(
161 _("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
162 file, subgroup, group, G_mapset());
163
164 return fd;
165}
166
167FILE *I_fopen_subgroup_file_old(const char *group, const char *subgroup,
168 const char *file)
169{
170 return fopen_subgroup_file_old(group, subgroup, NULL, file);
171}
172
173FILE *I_fopen_subgroup_file_old2(const char *group, const char *subgroup,
174 const char *mapset, const char *file)
175{
176 return fopen_subgroup_file_old(group, subgroup, mapset, file);
177}
#define NULL
Definition ccmath.h:32
FILE * G_fopen_append_misc(const char *, const char *, const char *)
Definition open_misc.c:222
int G__make_mapset_element_misc(const char *, const char *)
Create misc element in the current mapset.
Definition mapset_msc.c:261
void G_warning(const char *,...) __attribute__((format(printf
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition open_misc.c:210
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition open_misc.c:183
const char * G_mapset(void)
Get current mapset name.
Definition gis/mapset.c:33
int I_find_group_file2(const char *, const char *, const char *)
Searches for a group file in the specified mapset.
int I_find_subgroup_file2(const char *, const char *, const char *, const char *)
Searches for a subgroup file in the specified mapset.
FILE * I_fopen_group_file_new(const char *group, const char *file)
Definition fopen.c:69
FILE * I_fopen_subgroup_file_append(const char *group, const char *subgroup, const char *file)
Definition fopen.c:145
FILE * I_fopen_subgroup_file_old2(const char *group, const char *subgroup, const char *mapset, const char *file)
Definition fopen.c:173
FILE * I_fopen_subgroup_file_new(const char *group, const char *subgroup, const char *file)
Definition fopen.c:123
FILE * I_fopen_group_file_old(const char *group, const char *file)
Open group file for reading.
Definition fopen.c:102
FILE * I_fopen_subgroup_file_old(const char *group, const char *subgroup, const char *file)
Definition fopen.c:167
FILE * fopen_subgroup_file_old(const char *group, const char *subgroup, const char *mapset, const char *file)
Definition fopen.c:39
FILE * fopen_group_file_old(const char *group, const char *mapset, const char *file)
Definition fopen.c:15
FILE * I_fopen_group_file_append(const char *group, const char *file)
Definition fopen.c:81
FILE * I_fopen_group_file_old2(const char *group, const char *mapset, const char *file)
Open group file for reading.
Definition fopen.c:117
#define GNAME_MAX
Definition gis.h:196
#define _(str)
Definition glocale.h:10
#define file