45 static int read_env(
int);
46 static int set_env(
const char *,
const char *,
int);
47 static int unset_env(
const char *,
int);
48 static const char *get_env(
const char *,
int);
49 static void write_env(
int);
50 static void parse_env(FILE *,
int);
51 static void force_read_env(
int);
52 static FILE *open_env(
const char *,
int);
117 static void parse_env(FILE *fd,
int loc)
125 while (
G_getl2(buf,
sizeof buf, fd)) {
126 for (name = value = buf; *value; value++)
136 set_env(name, value, loc);
140 static int read_env(
int loc)
151 if ((fd = open_env(
"r", loc))) {
165 static void force_read_env(
int loc)
168 if ((fd = open_env(
"r", loc))) {
175 static int set_env(
const char *
name,
const char *value,
int loc)
182 if (!value || !strlen(value)) {
183 unset_env(
name, loc);
191 unset_env(
name, loc);
201 for (n = 0; n < st->env.count; n++) {
202 struct bind *
b = &st->env.binds[n];
205 else if (strcmp(b->name,
name) == 0 && b->loc == loc) {
213 struct bind *
b = &st->env.binds[empty];
221 if (st->env.count >= st->env.size) {
223 st->env.binds =
G_realloc(st->env.binds, st->env.size *
sizeof(
struct bind));
227 struct bind *
b = &st->env.binds[st->env.count++];
237 static int unset_env(
const char *
name,
int loc)
241 for (n = 0; n < st->env.count; n++) {
242 struct bind *
b = &st->env.binds[n];
243 if (b->name && strcmp(b->name,
name) == 0 && b->loc == loc) {
253 static const char *get_env(
const char *
name,
int loc)
257 for (n = 0; n < st->env.count; n++) {
258 struct bind *
b = &st->env.binds[n];
259 if (b->name && (strcmp(b->name,
name) == 0) &&
267 static void write_env(
int loc)
284 sigint = signal(SIGINT, SIG_IGN);
286 sigquit = signal(SIGQUIT, SIG_IGN);
288 if ((fd = open_env(
"w", loc))) {
289 for (n = 0; n < st->env.count; n++) {
290 struct bind *
b = &st->env.binds[n];
291 if (b->name && b->value && b->loc == loc
292 && (sscanf(b->value,
"%1s", dummy) == 1))
293 fprintf(fd,
"%s: %s\n", b->name, b->value);
298 signal(SIGINT, sigint);
300 signal(SIGQUIT, sigquit);
304 static FILE *open_env(
const char *mode,
int loc)
310 st->gisrc =
getenv(
"GISRC");
316 strcpy(buf, st->gisrc);
326 return fopen(buf, mode);
385 if (strcmp(name,
"GISBASE") == 0)
404 if (strcmp(name,
"GISBASE") == 0)
409 return get_env(name, loc);
440 set_env(name, value, loc);
466 set_env(name, value, loc);
494 unset_env(name, loc);
529 for (i = 0; i < st->env.count; i++)
530 if (st->env.binds[i].name && *st->env.binds[i].name && (n-- == 0))
531 return st->env.binds[i].name;
555 st->env.binds =
NULL;
557 for (i = 0; i < st->env2.count; i++) {
558 struct bind *
b = &st->env2.binds[i];
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_free(void *)
Free allocated memory.
char * G_location_path(void)
Get current location UNIX-like path.
void G_strip(char *)
Removes all leading and trailing white space from string.
void G_create_alt_env(void)
Set up alternative environment variables.
const char * G_get_env_name(int n)
Get variable name for index n.
void G__read_gisrc_env(void)
Force to read the GISRC environment file.
void G_initialize_done(int *)
void G_setenv2(const char *name, const char *value, int loc)
Set environment variable from specific place (updates .gisrc)
int G_get_gisrc_mode(void)
Get info where variables are stored.
void G_unsetenv(const char *name)
Remove name from environment.
void G_set_gisrc_mode(int mode)
Set where to find/store variables.
const char * G_getenv_nofatal(const char *name)
Get environment variable.
void G_setenv_nogisrc(const char *name, const char *value)
Set environment name to value (doesn't update .gisrc)
const char * G_getenv_nofatal2(const char *name, int loc)
Get environment variable from specific place.
void G_setenv(const char *name, const char *value)
Set environment variable (updates .gisrc)
int G_is_initialized(int *)
const char * G_getenv2(const char *name, int loc)
Get variable from specific place.
const char * G_mapset(void)
Get current mapset name.
void G_unsetenv2(const char *name, int loc)
Remove name from environment from specific place.
void G__read_mapset_env(void)
Force to read the mapset environment file VAR.
void G_init_env(void)
Initialize variables.
#define G_GISRC_MODE_MEMORY
void G__write_env(void)
Writes current environment to .gisrc.
char * G_store(const char *)
Copy string to allocated memory.
void G_switch_env(void)
Switch environments.
const char * G_getenv(const char *name)
Get environment variable.
void G__read_env(void)
Initialize init array for G_VAR_GISRC.
void G_setenv_nogisrc2(const char *name, const char *value, int loc)
Set environment name to value from specific place (doesn't update .gisrc)