GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
overwrite.c
Go to the documentation of this file.
1 
14 #include <stdlib.h>
15 #include <string.h>
16 #include <grass/gis.h>
17 
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 }
const char * G_getenv_nofatal(const char *name)
Get environment variable.
Definition: env.c:381
void G_setenv_nogisrc(const char *name, const char *value)
Set environment name to value (doesn&#39;t update .gisrc)
Definition: env.c:448
int G_check_overwrite(int argc, char **argv)
Check for overwrite mode.
Definition: overwrite.c:34