18 #include <sys/types.h> 24 static int list_element(FILE *,
const char *,
const char *,
const char *,
25 int (*)(
const char *,
const char *,
const char *));
53 int (*lister) (
const char *,
const char *,
const char *))
61 if (desc == 0 || *desc == 0)
68 fprintf(more,
"----------------------------------------------\n");
75 if (mapset == 0 || *mapset == 0)
77 count += list_element(more, element, desc, mapset, lister);
79 count += list_element(more, element, desc, mapset, lister);
82 if (mapset == 0 || *mapset == 0)
83 fprintf(more,
_(
"no %s files available in current mapset\n"),
86 fprintf(more,
_(
"no %s files available in mapset <%s>\n"),
89 fprintf(more,
"----------------------------------------------\n");
97 static int list_element(FILE *out,
const char *element,
const char *desc,
const char *mapset,
98 int (*lister)(
const char *,
const char *,
const char *))
108 if (strcmp(mapset,
".") == 0)
119 if (access(path, 0) != 0) {
129 list =
G_ls2(path, &count);
132 fprintf(out,
_(
"%s files available in mapset <%s>:\n"), desc, mapset);
138 lister(name, mapset, title);
140 fprintf(out,
"\n%-18s %-.60s\n", name, title);
145 for (i = 0; i <
count; i++) {
148 lister(list[i], mapset, title);
149 fprintf(out,
"%-18s %-.60s\n", list[i], title);
157 for (i = 0; i <
count; i++)
176 char **
G_list(
int element,
const char *gisbase,
const char *location,
207 buf = (
char *)
G_malloc(strlen(gisbase) + strlen(location)
208 + strlen(mapset) + strlen(el) + 4);
210 sprintf(buf,
"%s/%s/%s/%s", gisbase, location, mapset, el);
216 list = (
char **)
G_calloc(1,
sizeof(
char *));
222 if (dp->d_name[0] ==
'.')
228 list = (
char **)
G_calloc(count + 1,
sizeof(
char *));
232 if (dp->d_name[0] ==
'.')
236 strcpy(list[count], dp->d_name);
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_free(void *)
Free allocated memory.
char ** G_ls2(const char *, int *)
Stores a sorted directory listing in an array.
FILE * G_open_pager(struct Popen *)
void G_list_element(const char *element, const char *desc, const char *mapset, int(*lister)(const char *, const char *, const char *))
General purpose list function.
void G_close_pager(struct Popen *)
const char * G_mapset(void)
Get current mapset name.
void G_ls_format(char **, int, int, FILE *)
Prints a listing of items to a stream, in prettified column format.
const char * G_get_mapset_name(int)
Get name of the n'th mapset from the current mapset search path.
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.