File: mke_mapset.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (49 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
extern int errno;

#include "gis.h"

#ifdef __MINGW32__
# define mkdir(name, mode) ((mkdir) (name))
#endif

int make_mapset (char *location, char *mapset)
{
	char buffer[2048] ;
	char *buffer2;
	FILE *fd ;

/* create the mapset directory */
	sprintf(buffer,"mkdir '%s'/'%s'",location, mapset) ;
	system(buffer) ;

/* give the mapset a default window for the entire location */
	sprintf(buffer,"cat '%s'/PERMANENT/DEFAULT_WIND  > '%s'/'%s'/WIND",
		location, location, mapset) ;
	system(buffer) ;

/* generate DB settings file in new mapset */
	G_asprintf(&buffer2,"%s/%s/VAR", location, mapset);
	if((fd=fopen(buffer2,"w"))==NULL){
		perror("fopen");
		G_fatal_error("Cannot create <%s> file in new mapset", buffer2);
	}
	fprintf (fd, "DB_DRIVER: dbf\n");
	fprintf (fd, "DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n");
	fclose (fd);
	G_free(buffer2);
	
/* Make the dbf/ subdirectory */
	sprintf( buffer, "%s/%s/dbf", location, mapset );
	if( mkdir( buffer, 0775 ) != 0 )
		return -1;

	return(0) ;
}