1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/**
* \file overwrite.c
*
* \brief GIS Library - Check for overwrite.
*
* (C) 2001-2008 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 GIS Development Team, Martin Landa <landa.martin gmail.com>
*
* \date 2007-2008
*/
#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[in] argc number of arguments
* \param[in] argv array of arguments
*
* \return 1 if overwrite
* \return 0 if not overwrite
*/
int G_check_overwrite(int argc, char **argv)
{
char *overstr;
int overwrite;
overwrite = 0;
if ((overstr = G__getenv("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("OVERWRITE", "1");
return overwrite;
}
|