GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <string.h> 00004 #include <sys/types.h> 00005 #include <sys/stat.h> 00006 #include <fcntl.h> 00007 #include <unistd.h> 00008 #include <errno.h> 00009 extern int errno; 00010 00011 #include <grass/gis.h> 00012 00013 int make_mapset(const char *location, const char *mapset) 00014 { 00015 char buffer[GPATH_MAX]; 00016 char *buffer2; 00017 FILE *fd; 00018 struct Cell_head window; 00019 00020 /* create the mapset directory */ 00021 sprintf(buffer, "%s/%s", location, mapset); 00022 G_mkdir(buffer); 00023 00024 /* give the mapset a default window for the entire location */ 00025 G_get_default_window(&window); 00026 G_put_window(&window); 00027 00028 /* generate DB settings file in new mapset */ 00029 G_asprintf(&buffer2, "%s/%s/VAR", location, mapset); 00030 if ((fd = fopen(buffer2, "w")) == NULL) { 00031 perror("fopen"); 00032 G_fatal_error("Cannot create <%s> file in new mapset", buffer2); 00033 } 00034 fprintf(fd, "DB_DRIVER: dbf\n"); 00035 fprintf(fd, "DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n"); 00036 fclose(fd); 00037 G_free(buffer2); 00038 00039 /* Make the dbf/ subdirectory */ 00040 sprintf(buffer, "%s/%s/dbf", location, mapset); 00041 if (G_mkdir(buffer) != 0) 00042 return -1; 00043 00044 return (0); 00045 }