GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
env.c File Reference

GIS library - environment routines. More...

#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for env.c:

Go to the source code of this file.

Functions

void G_set_gisrc_mode (int mode)
 Set where to find/store variables. More...
 
int G_get_gisrc_mode (void)
 Get info where variables are stored. More...
 
void G_init_env (void)
 Initialize variables. More...
 
void G__read_mapset_env (void)
 Force to read the mapset environment file VAR. More...
 
void G__read_gisrc_env (void)
 Force to read the GISRC environment file. More...
 
void G__read_gisrc_path ()
 Read or read again the GISRC (session) environment variable. More...
 
const char * G_getenv (const char *name)
 Get environment variable. More...
 
const char * G_getenv2 (const char *name, int loc)
 Get variable from specific place. More...
 
const char * G_getenv_nofatal (const char *name)
 Get environment variable. More...
 
const char * G_getenv_nofatal2 (const char *name, int loc)
 Get environment variable from specific place. More...
 
void G_setenv (const char *name, const char *value)
 Set environment variable (updates .gisrc) More...
 
void G_setenv2 (const char *name, const char *value, int loc)
 Set environment variable from specific place (updates .gisrc) More...
 
void G_setenv_nogisrc (const char *name, const char *value)
 Set environment name to value (doesn't update .gisrc) More...
 
void G_setenv_nogisrc2 (const char *name, const char *value, int loc)
 Set environment name to value from specific place (doesn't update .gisrc) More...
 
void G_unsetenv (const char *name)
 Remove name from environment. More...
 
void G_unsetenv2 (const char *name, int loc)
 Remove name from environment from specific place. More...
 
void G__write_env (void)
 Writes current environment to .gisrc. More...
 
const char * G_get_env_name (int n)
 Get variable name for index n. More...
 
void G__read_env (void)
 Initialize init array for G_VAR_GISRC. More...
 
void G_create_alt_env (void)
 Set up alternative environment variables. More...
 
void G_switch_env (void)
 Switch environments. More...
 

Detailed Description

GIS library - environment routines.

(C) 2001-2023 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL
Updated for GRASS7 by Glynn Clements

Definition in file env.c.

Function Documentation

◆ G__read_env()

void G__read_env ( void  )

Initialize init array for G_VAR_GISRC.

Definition at line 553 of file env.c.

References G_VAR_GISRC.

◆ G__read_gisrc_env()

void G__read_gisrc_env ( void  )

Force to read the GISRC environment file.

The GISRC file will be read into memory, ignoring if it was readed before. Existing values will be overwritten, new values appended.

Returns

Definition at line 112 of file env.c.

◆ G__read_gisrc_path()

void G__read_gisrc_path ( void  )

Read or read again the GISRC (session) environment variable.

The GISRC environment variable will be read and its value stored, ignoring if it was read before.

Calls G_fatal_error when the GISRC variable is not set.

Definition at line 125 of file env.c.

References _, G_fatal_error(), and getenv().

◆ G__read_mapset_env()

void G__read_mapset_env ( void  )

Force to read the mapset environment file VAR.

The mapset specific VAR file of the mapset set with G_setenv() will be read into memory, ignoring if it was readed before. Existing values will be overwritten, new values appended.

Returns

Definition at line 98 of file env.c.

◆ G__write_env()

void G__write_env ( void  )

Writes current environment to .gisrc.

Definition at line 516 of file env.c.

References G_VAR_GISRC.

◆ G_create_alt_env()

void G_create_alt_env ( void  )

Set up alternative environment variables.

Definition at line 561 of file env.c.

References b, and NULL.

Referenced by G_make_mapset().

◆ G_get_env_name()

const char* G_get_env_name ( int  n)

Get variable name for index n.

For example:

for (n = 0; ; n++)
if ((name = G_get_env_name(n)) == NULL)
break;
Parameters
nindex of variable
Returns
pointer to variable name
NULL not found

Definition at line 538 of file env.c.

◆ G_get_gisrc_mode()

int G_get_gisrc_mode ( void  )

Get info where variables are stored.

Returns
mode

Definition at line 73 of file env.c.

◆ G_getenv()

const char* G_getenv ( const char *  name)

Get environment variable.

G_fatal_error() is called when variable is not found.

Parameters
namevariable name
Returns
char pointer to value for name

Definition at line 353 of file env.c.

References _, G_fatal_error(), G_getenv_nofatal(), and NULL.

Referenced by G_gisbase(), G_gisdbase(), and G_location().

◆ G_getenv2()

const char* G_getenv2 ( const char *  name,
int  loc 
)

Get variable from specific place.

Locations:

  • G_VAR_GISRC
  • G_VAR_MAPSET

G_fatal_error() is called when variable is not found.

Parameters
namevariable name
loclocation (G_VAR_GISRC, G_VAR_MAPSET)
Returns
variable value
NULL if not found

Definition at line 379 of file env.c.

References _, G_fatal_error(), G_getenv_nofatal2(), and NULL.

◆ G_getenv_nofatal()

const char* G_getenv_nofatal ( const char *  name)

Get environment variable.

Parameters
namevariable name
Returns
char pointer to value for name
NULL if name not set

Definition at line 398 of file env.c.

References getenv().

Referenced by G__mapset(), G_check_overwrite(), G_define_standard_option(), and G_getenv().

◆ G_getenv_nofatal2()

const char* G_getenv_nofatal2 ( const char *  name,
int  loc 
)

Get environment variable from specific place.

Parameters
namevariable name
loclocation (G_VAR_GISRC, G_VAR_MAPSET)
Returns
char pointer to value for name
NULL if name not set

Definition at line 417 of file env.c.

References getenv().

Referenced by db_get_connection(), db_get_default_database_name(), db_get_default_driver_name(), db_get_default_group_name(), db_get_default_schema_name(), G_getenv2(), tgis_get_connection(), tgis_get_database_name(), and tgis_get_driver_name().

◆ G_init_env()

void G_init_env ( void  )

Initialize variables.

Returns

Definition at line 83 of file env.c.

Referenced by G_init_all().

◆ G_set_gisrc_mode()

void G_set_gisrc_mode ( int  mode)

Set where to find/store variables.

Modes:

  • G_GISRC_MODE_FILE
  • G_GISRC_MODE_MEMORY
Parameters
modemode to find/store variables (G_GISRC_MODE_FILE by default)

Definition at line 63 of file env.c.

◆ G_setenv()

void G_setenv ( const char *  name,
const char *  value 
)

Set environment variable (updates .gisrc)

If value is NULL, becomes an G_unsetenv().

Parameters
namevariable name
valuevariable value

Definition at line 435 of file env.c.

◆ G_setenv2()

void G_setenv2 ( const char *  name,
const char *  value,
int  loc 
)

Set environment variable from specific place (updates .gisrc)

If value is NULL, becomes an G_unsetenv().

Parameters
namevariable name
valuevariable value
loclocation (G_VAR_GISRC, G_VAR_MAPSET)

Definition at line 452 of file env.c.

Referenced by db_set_connection(), and tgis_set_connection().

◆ G_setenv_nogisrc()

void G_setenv_nogisrc ( const char *  name,
const char *  value 
)

Set environment name to value (doesn't update .gisrc)

Parameters
namevariable name
valuevariable value

Definition at line 465 of file env.c.

Referenced by G_check_overwrite(), and G_make_mapset().

◆ G_setenv_nogisrc2()

void G_setenv_nogisrc2 ( const char *  name,
const char *  value,
int  loc 
)

Set environment name to value from specific place (doesn't update .gisrc)

Parameters
namevariable name
valuevariable value
loclocation (G_VAR_GISRC, G_VAR_MAPSET)

Definition at line 478 of file env.c.

◆ G_switch_env()

void G_switch_env ( void  )

Switch environments.

Definition at line 582 of file env.c.

Referenced by G_make_mapset().

◆ G_unsetenv()

void G_unsetenv ( const char *  name)

Remove name from environment.

Updates .gisrc

Parameters
namevariable name

Definition at line 491 of file env.c.

◆ G_unsetenv2()

void G_unsetenv2 ( const char *  name,
int  loc 
)

Remove name from environment from specific place.

Updates .gisrc

Parameters
namevariable name
loclocation (G_VAR_GISRC, G_VAR_MAPSET)

Definition at line 506 of file env.c.

Referenced by db_set_connection().