GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <fcntl.h> 00002 #include <sys/stat.h> 00003 #include <sys/types.h> 00004 #include <stdio.h> 00005 #include <unistd.h> 00006 #include <grass/gis.h> 00007 #include "local_proto.h" 00008 00009 static char *filename(const char *name, const char *mapset) 00010 { 00011 static char path[GPATH_MAX]; 00012 00013 G__file_name(path, "", name, mapset); 00014 return path; 00015 } 00016 00017 int mapset_permissions(const char *mapset) 00018 { 00019 int stat; 00020 00021 stat = G__mapset_permissions(mapset); 00022 if (stat == 1) { 00023 if (access(filename(".lock", mapset), 0) == 0) 00024 stat = 0; 00025 } 00026 return stat; 00027 } 00028 00029 int mapset_message(const char *mapset) 00030 { 00031 if (printfile(filename(".message", mapset))) 00032 hit_return(); 00033 00034 return 0; 00035 } 00036 00037 int mapset_question(const char *mapset) 00038 { 00039 if (printfile(filename(".question", mapset))) 00040 return G_yes("Select this mapset? ", -1); 00041 return 1; 00042 } 00043 00044 int printfile(const char *name) 00045 { 00046 int fd; 00047 int n; 00048 char buf[1024]; 00049 00050 fd = open(name, 0); 00051 if (fd < 0) 00052 return 0; 00053 while ((n = read(fd, buf, sizeof buf)) > 0) 00054 write(STDOUT_FILENO, buf, n); 00055 close(fd); 00056 return 1; 00057 }