12#include <grass/config.h>
20#include "gis_local_proto.h"
30static struct state *st = &state;
32static void new_mapset(
const char *);
48 if (n < 0 || n >= st->path.count)
51 return st->path.names[n];
62 if (st->path.count > 0)
67 st->path.names =
NULL;
76 while (fscanf(fp,
"%s",
name) == 1) {
77 if (strcmp(
name, cur) == 0)
85 static const char perm[] =
"PERMANENT";
92void new_mapset(
const char *
name)
94 if (st->path.count >= st->path.size) {
97 G_realloc(st->path.names, st->path.size *
sizeof(
char *));
108 st->path2.count = st->path.count;
109 st->path2.names = st->path.names;
122 count = st->path2.count;
123 names = st->path2.names;
125 st->path2.count = st->path.count;
126 st->path2.names = st->path.names;
128 st->path.count =
count;
129 st->path.names = names;
150 char **mapsets =
NULL;
156 G_debug(3,
"G_get_available_mapsets");
158 mapsets = G_calloc(alloc,
sizeof(
char *));
161 dir = opendir(location);
167 while ((ent = readdir(dir))) {
171 sprintf(buf,
"%s/%s/WIND", location, ent->d_name);
173 if (
G_stat(buf, &st) != 0) {
174 G_debug(4,
"%s is not mapset", ent->d_name);
178 G_debug(4,
"%s is mapset", ent->d_name);
180 if (n + 2 >= alloc) {
182 mapsets = G_realloc(mapsets, alloc *
sizeof(
char *));
185 mapsets[n++] =
G_store(ent->d_name);
221 for (i = 0; i < st->path.count; i++) {
222 if (strcmp(st->path.names[i], mapset) == 0)
void G_free(void *buf)
Free allocated memory.
int G_debug(int level, const char *msg,...)
Print debugging message.
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
char * G_location_path(void)
Get current location UNIX-like path.
const char * G_mapset(void)
Get current mapset name.
int G_mapset_permissions(const char *mapset)
Check for user mapset permission.
void G_add_mapset_to_search_path(const char *mapset)
Add mapset to the list of mapsets in search path.
void G_reset_mapsets(void)
Reset number of mapsets.
const char * G_get_mapset_name(int n)
Get name of the n'th mapset from the current mapset search path.
void G__get_list_of_mapsets(void)
Fill list of mapsets from search path (internal use only)
void G_create_alt_search_path(void)
Define alternative mapset search path.
void G_switch_search_path(void)
Switch mapset search path.
int G_is_mapset_in_search_path(const char *mapset)
Check if given mapset is in search path.
char ** G_get_available_mapsets(void)
Get list of available mapsets for current location.
int G_stat(const char *file_name, struct stat *buf)
Get file status.
char * G_store(const char *s)
Copy string to allocated memory.