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