From 64844b69597ef284590c5f51bc8c62c729d4daa5 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 5 Nov 2005 20:04:16 +0000 Subject: [PATCH] reorder functions git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3095 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/browser.c | 150 +++++++++++++++++++++++++------------------------- src/proto.h | 4 +- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/browser.c b/src/browser.c index 32cffa54..0fce1a59 100644 --- a/src/browser.c +++ b/src/browser.c @@ -32,81 +32,6 @@ #ifndef DISABLE_BROWSER -/* Strip one directory from the end of path. */ -void striponedir(char *path) -{ - char *tmp; - - assert(path != NULL); - - tmp = strrchr(path, '/'); - - if (tmp != NULL) - *tmp = '\0'; -} - -/* Return a list of files contained in the directory path. *longest is - * the maximum display length of a file, up to COLS - 1 (but at least - * 7). *numents is the number of files. We assume path exists and is a - * directory. If neither is true, we return NULL. */ -char **browser_init(const char *path, int *longest, size_t *numents, DIR - *dir) -{ - const struct dirent *nextdir; - char **filelist; - size_t i = 0, path_len; - - assert(dir != NULL); - - *longest = 0; - - while ((nextdir = readdir(dir)) != NULL) { - size_t dlen; - - /* Don't show the "." entry. */ - if (strcmp(nextdir->d_name, ".") == 0) - continue; - i++; - - dlen = strlenpt(nextdir->d_name); - if (dlen > *longest) - *longest = (dlen > COLS - 1) ? COLS - 1 : dlen; - } - - *numents = i; - rewinddir(dir); - *longest += 10; - - filelist = (char **)nmalloc(*numents * sizeof(char *)); - - path_len = strlen(path); - - i = 0; - - while ((nextdir = readdir(dir)) != NULL && i < *numents) { - /* Don't show the "." entry. */ - if (strcmp(nextdir->d_name, ".") == 0) - continue; - - filelist[i] = charalloc(path_len + strlen(nextdir->d_name) + 1); - sprintf(filelist[i], "%s%s", path, nextdir->d_name); - i++; - } - - /* Maybe the number of files in the directory changed between the - * first time we scanned and the second. i is the actual length of - * filelist, so record it. */ - *numents = i; - closedir(dir); - - if (*longest > COLS - 1) - *longest = COLS - 1; - if (*longest < 7) - *longest = 7; - - return filelist; -} - /* Our browser function. path is the path to start browsing from. * Assume path has already been tilde-expanded. */ char *do_browser(char *path, DIR *dir) @@ -482,6 +407,68 @@ char *do_browser(char *path, DIR *dir) return retval; } +/* Return a list of files contained in the directory path. *longest is + * the maximum display length of a file, up to COLS - 1 (but at least + * 7). *numents is the number of files. We assume path exists and is a + * directory. If neither is true, we return NULL. */ +char **browser_init(const char *path, int *longest, size_t *numents, DIR + *dir) +{ + const struct dirent *nextdir; + char **filelist; + size_t i = 0, path_len; + + assert(dir != NULL); + + *longest = 0; + + while ((nextdir = readdir(dir)) != NULL) { + size_t dlen; + + /* Don't show the "." entry. */ + if (strcmp(nextdir->d_name, ".") == 0) + continue; + i++; + + dlen = strlenpt(nextdir->d_name); + if (dlen > *longest) + *longest = (dlen > COLS - 1) ? COLS - 1 : dlen; + } + + *numents = i; + rewinddir(dir); + *longest += 10; + + filelist = (char **)nmalloc(*numents * sizeof(char *)); + + path_len = strlen(path); + + i = 0; + + while ((nextdir = readdir(dir)) != NULL && i < *numents) { + /* Don't show the "." entry. */ + if (strcmp(nextdir->d_name, ".") == 0) + continue; + + filelist[i] = charalloc(path_len + strlen(nextdir->d_name) + 1); + sprintf(filelist[i], "%s%s", path, nextdir->d_name); + i++; + } + + /* Maybe the number of files in the directory changed between the + * first time we scanned and the second. i is the actual length of + * filelist, so record it. */ + *numents = i; + closedir(dir); + + if (*longest > COLS - 1) + *longest = COLS - 1; + if (*longest < 7) + *longest = 7; + + return filelist; +} + /* The file browser front end. We check to see if inpath has a dir in * it. If it does, we start do_browser() from there. Otherwise, we * start do_browser() from the current directory. */ @@ -537,4 +524,17 @@ char *do_browse_from(const char *inpath) return do_browser(path, dir); } +/* Strip one directory from the end of path. */ +void striponedir(char *path) +{ + char *tmp; + + assert(path != NULL); + + tmp = strrchr(path, '/'); + + if (tmp != NULL) + *tmp = '\0'; +} + #endif /* !DISABLE_BROWSER */ diff --git a/src/proto.h b/src/proto.h index 40484564..dcd75af3 100644 --- a/src/proto.h +++ b/src/proto.h @@ -203,11 +203,11 @@ bool is_valid_mbstring(const char *s); /* Public functions in browser.c. */ #ifndef DISABLE_BROWSER -void striponedir(char *path); +char *do_browser(char *path, DIR *dir); char **browser_init(const char *path, int *longest, size_t *numents, DIR *dir); -char *do_browser(char *path, DIR *dir); char *do_browse_from(const char *inpath); +void striponedir(char *path); #endif /* Public functions in color.c. */ -- 2.39.5