Index: raster/r.colors/main.c =================================================================== RCS file: /grassrepository/grass6/raster/r.colors/main.c,v retrieving revision 2.11 diff -u -r2.11 main.c --- raster/r.colors/main.c 17 Oct 2006 11:43:08 -0000 2.11 +++ raster/r.colors/main.c 29 Jan 2007 12:31:32 -0000 @@ -24,8 +24,8 @@ #include #include -#include -#include +#include +#include #include #include "local_proto.h" #include @@ -34,29 +34,25 @@ static char *rules_files(void) { char path[4096]; + char **files; + int i, num_files; + char *list = NULL; int size = 0; int len = 0; - DIR *dir; sprintf(path, "%s/etc/colors", G_gisbase()); - dir = opendir(path); - if (!dir) + if (access(path, R_OK)) return NULL; + + files = G__ls(path, &num_files); - for (;;) + for (i = 0; i < num_files; i++) { - struct dirent *d = readdir(dir); int n; - if (!d) - break; - - if (d->d_name[0] == '.') - continue; - - n = strlen(d->d_name); + n = strlen(files[i]); if (size < len + n + 2) { @@ -64,63 +60,30 @@ list = G_realloc(list, size); } - if (len > 0) + if (i > 0) list[len++] = ','; - memcpy(&list[len], d->d_name, n + 1); + memcpy(&list[len], files[i], n + 1); len += n; } - closedir(dir); - return list; } -static int cmp_names(const void *aa, const void *bb) -{ - char * const *a = aa; - char * const *b = bb; - - return strcmp(*a, *b); -} - static void list_rules_files(void) { - static char **names; - static int names_size; + char **names; char path[4096]; - DIR *dir; - int names_len = 0; + int names_len; int i; sprintf(path, "%s/etc/colors", G_gisbase()); - dir = opendir(path); - if (!dir) - G_fatal_error("Rules directory doesn't exist"); - - for (;;) - { - struct dirent *d = readdir(dir); - - if (!d) - break; - - if (d->d_name[0] == '.') - continue; - - if (names_len >= names_size) - { - names_size = names_len + 20; - names = G_realloc(names, names_size * sizeof(char *)); - } - - names[names_len++] = G_store(d->d_name); - } - - closedir(dir); - - qsort(names, names_len, sizeof(char *), cmp_names); + if (access(path, R_OK)) + G_fatal_error("Problem accessing rules directory: %s", + strerror(errno)); + + names = G__ls(path, &names_len); for (i = 0; i < names_len; i++) {