20 #include <sys/types.h>
23 #include <grass/gis.h>
24 #include <grass/glocale.h>
26 static int broken_pipe;
27 static int hit_return = 0;
28 static int list_element(FILE *,
const char *,
const char *,
const char *,
29 int (*)(
const char *,
const char *,
const char *));
30 static RETSIGTYPE sigpipe_catch(
int);
63 int (*lister) (
const char *,
const char *,
const char *))
70 RETSIGTYPE (*sigpipe)(
int);
76 sigpipe =
signal(SIGPIPE, sigpipe_catch);
80 if (desc == 0 || *desc == 0)
88 more = popen(
"%GRASS_PAGER%",
"w");
90 more = popen(
"$GRASS_PAGER",
"w");
98 fprintf(more,
"----------------------------------------------\n");
105 if (mapset == 0 || *mapset == 0)
107 count += list_element(more, element, desc, mapset, lister);
109 count += list_element(more, element, desc, mapset, lister);
113 if (mapset == 0 || *mapset == 0)
114 fprintf(more, _(
"no %s files available in current mapset\n"),
117 fprintf(more, _(
"no %s files available in mapset <%s>\n"),
121 fprintf(more,
"----------------------------------------------\n");
131 if (hit_return && isatty(1)) {
132 fprintf(stderr, _(
"hit RETURN to continue -->"));
133 while (getchar() !=
'\n') ;
139 static RETSIGTYPE sigpipe_catch(
int n)
145 static int list_element(FILE * out,
146 const char *element,
const char *desc,
147 const char *mapset,
int (*lister) (
const char *,
151 char path[GPATH_MAX];
159 if (strcmp(mapset,
".") == 0)
170 if (access(path, 0) != 0) {
180 list =
G__ls(path, &count);
183 fprintf(out, _(
"%s files available in mapset <%s>:\n"), desc, mapset);
186 char name[GNAME_MAX];
189 lister(name, mapset, title);
191 fprintf(out,
"\n%-18s %-.60s\n", name, title);
196 for (i = 0; i <
count; i++) {
199 lister(list[i], mapset, title);
200 fprintf(out,
"%-18s %-.60s\n", list[i], title);
208 for (i = 0; i <
count; i++)
237 case G_ELEMENT_RASTER:
241 case G_ELEMENT_GROUP:
245 case G_ELEMENT_VECTOR:
249 case G_ELEMENT_REGION:
257 buf = (
char *)G_malloc(strlen(gisbase) + strlen(location)
258 + strlen(mapset) + strlen(el) + 4);
260 sprintf(buf,
"%s/%s/%s/%s", gisbase, location, mapset, el);
266 list = (
char **)G_calloc(1,
sizeof(
char *));
272 if (dp->d_name[0] ==
'.')
278 list = (
char **)G_calloc(count + 1,
sizeof(
char *));
282 if (dp->d_name[0] ==
'.')
285 list[
count] = (
char *)G_malloc(strlen(dp->d_name) + 1);
286 strcpy(list[count], dp->d_name);
char * G_mapset(void)
current mapset name
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
void G_ls_format(char **list, int num_items, int perline, FILE *stream)
Prints a listing of items to a stream, in prettified column format.
char ** G__ls(const char *dir, int *num_files)
Stores a sorted directory listing in an array.
int G_set_list_hit_return(int flag)
int G_list_element(const char *element, const char *desc, const char *mapset, int(*lister)(const char *, const char *, const char *))
General purpose list function.
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
char * G__mapset_name(int n)
Get name of the n'th mapset from the mapset_name[] list.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
char ** G_list(int element, const char *gisbase, const char *location, const char *mapset)
List specified type of elements. Application must release the allocated memory.
void G_free_list(char **list)
Free list.