GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
overwrite.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/overwrite.c
3
*
4
* \brief GIS Library - Check for overwrite.
5
*
6
* (C) 2001-2008, 2010 by the GRASS Development Team
7
*
8
* This program is free software under the GNU General Public License
9
* (>=v2). Read the file COPYING that comes with GRASS for details.
10
*
11
* \author GRASS GIS Development Team, Martin Landa <landa.martin gmail.com>
12
*/
13
14
#include <stdlib.h>
15
#include <string.h>
16
#include <grass/gis.h>
17
18
/*!
19
* \brief Check for overwrite mode
20
*
21
* Check variables OVERWRITE, GRASS_OVERWRITE and '--o' flag.
22
*
23
* The parser G_parser() checks if the map already exists in current mapset,
24
* we can switch out the check and do it
25
* in the module after the parser.
26
*
27
* \param argc number of arguments
28
* \param argv array of arguments
29
*
30
* \return 1 if overwrite
31
* \return 0 if not overwrite
32
*/
33
34
int
G_check_overwrite
(
int
argc,
char
**argv)
35
{
36
const
char
*overstr;
37
int
overwrite;
38
39
overwrite = 0;
40
if
((overstr =
G_getenv_nofatal
(
"OVERWRITE"
))) {
41
overwrite = atoi(overstr);
42
}
43
44
/* check if inherited GRASS_OVERWRITE is 1 */
45
if
(!overwrite && (overstr = getenv(
"GRASS_OVERWRITE"
))) {
46
overwrite = atoi(overstr);
47
}
48
49
/* check for --o or --overwrite option */
50
if
(!overwrite) {
51
int
i;
52
53
for
(i = 0; i < argc; i++) {
54
if
(strcmp(argv[i],
"--o"
) == 0 ||
55
strcmp(argv[i],
"--overwrite"
) == 0) {
56
overwrite = 1;
57
break
;
58
}
59
}
60
}
61
62
G_setenv_nogisrc
(
"OVERWRITE"
,
"1"
);
63
64
return
overwrite;
65
}
G_check_overwrite
int G_check_overwrite(int argc, char **argv)
Check for overwrite mode.
Definition:
overwrite.c:34
G_setenv_nogisrc
void G_setenv_nogisrc(const char *name, const char *value)
Set environment name to value (doesn't update .gisrc)
Definition:
env.c:448
G_getenv_nofatal
const char * G_getenv_nofatal(const char *name)
Get environment variable.
Definition:
env.c:381
gis
overwrite.c
Generated on Sat Jan 25 2020 17:06:53 for GRASS GIS 7 Programmer's Manual by
1.8.16