Loading...
Searching...
No Matches
overwrite.c
Go to the documentation of this file.
/*!
* \file lib/gis/overwrite.c
*
* \brief GIS Library - Check for overwrite.
*
* (C) 2001-2008, 2010 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 GRASS Development Team, Martin Landa <landa.martin gmail.com>
*/
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
/*!
* \brief Check for overwrite mode
*
* Check variables OVERWRITE, GRASS_OVERWRITE and '--o' flag.
*
* The parser G_parser() checks if the map already exists in current mapset,
* we can switch out the check and do it
* in the module after the parser.
*
* \param argc number of arguments
* \param argv array of arguments
*
* \return 1 if overwrite
* \return 0 if not overwrite
*/
int G_check_overwrite(int argc, char **argv)
{
const char *overstr;
int overwrite;
overwrite = 0;
if ((overstr = G_getenv_nofatal("OVERWRITE"))) {
overwrite = atoi(overstr);
}
/* check if inherited GRASS_OVERWRITE is 1 */
if (!overwrite && (overstr = getenv("GRASS_OVERWRITE"))) {
overwrite = atoi(overstr);
}
/* check for --o or --overwrite option */
if (!overwrite) {
int i;
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "--o") == 0 ||
strcmp(argv[i], "--overwrite") == 0) {
overwrite = 1;
break;
}
}
}
G_setenv_nogisrc("OVERWRITE", "1");
return overwrite;
}
G_getenv_nofatal
const char * G_getenv_nofatal(const char *name)
Get environment variable.
Definition env.c:405
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:472
G_check_overwrite
int G_check_overwrite(int argc, char **argv)
Check for overwrite mode.
Definition overwrite.c:33