9 #ifndef D_LOCATION_NAME
10 #define D_LOCATION_NAME "spearfish"
13 #define D_GISDBASE "/data"
15 #ifndef GRASS_VERSION_NUMBER
16 #define GRASS_VERSION_NUMBER ""
21 static char *intro[] = {
22 " PLEASE SET SESSION INFORMATION",
24 "DATABASE: A directory (folder) on disk to contain all GRASS maps and data.",
26 "LOCATION: This is the name of a geographic location. It is defined by a",
27 " co-ordinate system and a rectangular boundary.",
29 "MAPSET: Each GRASS session runs under a particular MAPSET. This consists of",
30 " a rectangular REGION and a set of maps. Every LOCATION contains at",
31 " least a MAPSET called PERMANENT, which is readable by all sessions.",
33 " The REGION defaults to the entire area of the chosen LOCATION.",
34 " You may change it later with the command: g.region",
35 "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",
38 static char *loc_text =
39 "LOCATION: (enter list for a list of locations)";
40 static char *map_text =
41 "MAPSET: (or mapsets within a location)";
44 #include <sys/types.h>
48 #include <grass/gis.h>
49 #include <grass/vask.h>
50 #include <grass/edit.h>
53 int main(
int argc,
char *argv[])
56 char gisdbase[GPATH_MAX];
57 char location_name[GMAPSET_MAX];
58 char location[GPATH_MAX + GMAPSET_MAX];
59 char mapset[GMAPSET_MAX];
62 struct Cell_head window;
82 LOCATION_NAME =
G__getenv(
"LOCATION_NAME");
92 strcpy(mapset, MAPSET);
93 strcpy(location_name, LOCATION_NAME);
94 strcpy(gisdbase, GISDBASE);
103 for (line = 1; intro[line]; line++)
104 V_line(line, intro[line]);
108 V_ques(location_name,
's', line++, 12, 25);
111 V_ques(mapset,
's', line++, 12, 25);
114 V_line(line,
"DATABASE:");
115 V_ques(gisdbase,
's', line++, 10, 70 - 1);
122 if (*gisdbase == 0) {
123 fprintf(stderr,
"No DATABASE specified\n");
128 if (*gisdbase ==
'/') {
129 char tmp[GPATH_MAX], *p;
132 for (p = tmp + strlen(tmp); --p >= tmp && *p ==
'\\';) ;
133 for (; --p >= tmp && *p !=
'\\';) ;
134 for (; --p >= tmp && *p ==
'\\';) ;
136 for (p = tmp; *p; p++)
139 strcat(tmp, gisdbase);
140 strcpy(gisdbase, tmp);
142 if (!gisdbase[1] || gisdbase[1] !=
':')
144 if (*gisdbase !=
'/')
147 char temp[GPATH_MAX];
149 fprintf(stderr,
"DATABASE <%s> - must start with /\n", gisdbase);
150 sprintf(temp,
" '%s'", gisdbase);
151 strcpy(gisdbase, temp);
154 if (access(gisdbase, 0) != 0) {
155 fprintf(stderr,
"DATABASE <%s> - not found\n", gisdbase);
165 fprintf(stderr,
"LOCATION <%s> - illegal name\n", location_name);
169 fprintf(stderr,
"MAPSET <%s> - illegal name\n", mapset);
173 if (*location_name == 0 || strcmp(location_name,
"list") == 0) {
178 sprintf(location,
"%s/%s", gisdbase, location_name);
179 if (access(location, 0) != 0) {
180 fprintf(stderr,
"LOCATION <%s> - doesn't exist\n", location_name);
185 fprintf(stderr,
"\nWould you like to create location <%s> ? ",
190 G__setenv(
"LOCATION_NAME", location_name);
195 if (system(
"g.setproj")) {
199 "WARNING: You did not provide default region for %s!\n",
204 fprintf(stderr,
"LOCATION <%s> created\n",
207 "\nBut the PROJECTION information files were not created!\n");
209 "You must run g.setproj successfully before projection software will work%c%c%c\n",
217 "WARNING: You did not provide default region for %s!\n",
221 fprintf(stderr,
"LOCATION <%s> created!\n",
226 fprintf(stderr,
"LOCATION <%s> NOT created\n", location_name);
230 G__setenv(
"LOCATION_NAME", location_name);
231 if (*mapset == 0 || strcmp(mapset,
"list") == 0) {
242 if (strcmp(mapset,
G_whoami()) == 0) {
247 fprintf(stderr,
"\n\nMapset <<%s>> is not available\n",
251 "\nWould you like to create < %s > as a new mapset? ",
260 fprintf(stderr,
"\n\nSorry, no access to <<%s>>.\n", mapset);
280 fprintf(stderr,
"\nAvailable locations:\n");
281 fprintf(stderr,
"----------------------\n");
282 G_ls(gisdbase, stderr);
283 fprintf(stderr,
"----------------------\n");
294 fprintf(stderr,
"\nMapsets in location <%s>\n", location_name);
295 fprintf(stderr,
"----------------------\n");
296 mapsets =
G__ls(location, &num_mapsets);
300 if (num_mapsets > 0) {
301 for (i = 0; i < num_mapsets; i++) {
303 len = strlen(mapsets[i]) + 1;
305 len = (len + 1) * 20;
308 fprintf(stderr,
"\n");
313 fprintf(stderr,
"%s%-*s", ok ?
"(+)" :
" ", len, mapsets[i]);
316 fprintf(stderr,
"\n");
319 "\nnote: you only have access to mapsets marked with (+)\n");
322 "\nnote: you do not have access to any of these mapsets\n");
324 fprintf(stderr,
"----------------------\n");
331 char temp[GNAME_MAX];
334 sscanf(buf,
"%s", temp);
344 fprintf(stderr,
"\nHit RETURN -->");
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int mapset_message(const char *)
char * G__getenv(const char *name)
Get environment variable.
int mapset_question(const char *)
#define GRASS_VERSION_NUMBER
char ** G__ls(const char *dir, int *num_files)
Stores a sorted directory listing in an array.
void V_clear(void)
Zero out prompt and answer arrays.
int V_line(int linenumber, const char *text)
int make_mapset(const char *, const char *)
int G_yes(const char *question, int dflt)
Ask a yes/no question.
int G_get_default_window(struct Cell_head *window)
read the default region
void G_ls(const char *dir, FILE *stream)
Prints a directory listing to a stream, in prettified column format.
def version
Get GRASS version as dictionary.
int G_unsetenv(const char *name)
Remove name from environment.
int V_call(void)
Interact with the user.
int list_mapsets(const char *, const char *)
char * G_getenv(const char *name)
Get environment variable.
int E_edit_cellhd(struct Cell_head *cellhd, int type)
int can_make_location(char *gisdbase, char *location)
int main(int argc, char *argv[])
int G_strip(char *buf)
Removes all leading and trailing white space from string.
def mapsets
List available mapsets.
int mapset_permissions(const char *)
int G__write_env(void)
Writes current environment to .gisrc.
char * G_whoami(void)
Gets user's name.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G__setenv(const char *name, const char *value)
Set environment name to value.
int G__put_window(const struct Cell_head *window, char *dir, char *name)
int list_locations(const char *)
int G_legal_filename(const char *s)
Check for legal database file name.
int V_ques(void *src, int var_type, int row, int col, int length)
int make_location(const char *, const char *)
void V_intrpt_ok(void)
Allow CTRL-C.