diff options
| author | jtc <jtc@NetBSD.org> | 1993-09-16 17:39:00 +0000 |
|---|---|---|
| committer | jtc <jtc@NetBSD.org> | 1993-09-16 17:39:00 +0000 |
| commit | 69a25a6a71efcadf0db55504379e7a74cecf54ca (patch) | |
| tree | 70d25a47e8da160d611afa43ef8986aa2bbe62fa /gnu/usr.bin/diff/dir.c | |
| parent | 941b6d7b199d8c66a499f0baea38c26e5882e3c6 (diff) | |
Updated to GNU Diffutils 2.4.
Diffstat (limited to 'gnu/usr.bin/diff/dir.c')
| -rw-r--r-- | gnu/usr.bin/diff/dir.c | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/gnu/usr.bin/diff/dir.c b/gnu/usr.bin/diff/dir.c index f10488737a0..b31eb633ff2 100644 --- a/gnu/usr.bin/diff/dir.c +++ b/gnu/usr.bin/diff/dir.c @@ -1,5 +1,5 @@ /* Read, sort and compare two directories. Used for GNU DIFF. - Copyright (C) 1988, 1989, 1992 Free Software Foundation, Inc. + Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -18,13 +18,11 @@ along with GNU DIFF; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef lint -static char rcsid[] = "$Id: dir.c,v 1.3 1993/08/02 17:26:12 mycroft Exp $"; -#endif /* not lint */ +static char *rcsid = "$Id: dir.c,v 1.4 1993/09/16 17:39:12 jtc Exp $"; +#endif #include "diff.h" -static int compare_names (); - /* Read the directory named by DIR and store into DIRDATA a sorted vector of filenames for its contents. DIR->desc == -1 means this directory is known to be nonexistent, so set DIRDATA to an empty vector. @@ -32,31 +30,35 @@ static int compare_names (); struct dirdata { - char **files; /* Sorted names of files in dir, terminated by (char *) 0. */ + char const **names; /* Sorted names of files in dir, 0-terminated. */ char *data; /* Allocated storage for file names. */ }; +static int compare_names PARAMS((void const *, void const *)); +static int dir_sort PARAMS((struct file_data const *, struct dirdata *)); + static int dir_sort (dir, dirdata) - struct file_data *dir; + struct file_data const *dir; struct dirdata *dirdata; { - register struct direct *next; + register struct dirent *next; register int i; /* Address of block containing the files that are described. */ - char **files; + char const **names; /* Number of files in directory. */ - int nfiles; + size_t nnames; /* Allocated and used storage for file name data. */ char *data; size_t data_alloc, data_used; - dirdata->files = 0; + dirdata->names = 0; dirdata->data = 0; - nfiles = 0; + nnames = 0; + data = 0; if (dir->desc != -1) { @@ -69,7 +71,7 @@ dir_sort (dir, dirdata) data_alloc = max (1, (size_t) dir->stat.st_size); data_used = 0; - dirdata->data = data = (char *) xmalloc (data_alloc); + dirdata->data = data = xmalloc (data_alloc); /* Read the directory entries, and insert the subfiles into the `data' table. */ @@ -89,10 +91,10 @@ dir_sort (dir, dirdata) d_size = strlen (d_name) + 1; while (data_alloc < data_used + d_size) - dirdata->data = data = (char *) xrealloc (data, data_alloc *= 2); - bcopy (d_name, data + data_used, d_size); + dirdata->data = data = xrealloc (data, data_alloc *= 2); + memcpy (data + data_used, d_name, d_size); data_used += d_size; - nfiles++; + nnames++; } if (errno) { @@ -101,7 +103,7 @@ dir_sort (dir, dirdata) errno = e; return -1; } -#ifdef VOID_CLOSEDIR +#if VOID_CLOSEDIR closedir (reading); #else if (closedir (reading) != 0) @@ -109,17 +111,18 @@ dir_sort (dir, dirdata) #endif } - /* Create the `files' table from the `data' table. */ - dirdata->files = files = (char **) xmalloc (sizeof (char *) * (nfiles + 1)); - for (i = 0; i < nfiles; i++) + /* Create the `names' table from the `data' table. */ + dirdata->names = names = (char const **) xmalloc (sizeof (char *) + * (nnames + 1)); + for (i = 0; i < nnames; i++) { - files[i] = data; + names[i] = data; data += strlen (data) + 1; } - files[nfiles] = 0; + names[nnames] = 0; /* Sort the table. */ - qsort (files, nfiles, sizeof (char *), compare_names); + qsort (names, nnames, sizeof (char *), compare_names); return 0; } @@ -128,9 +131,9 @@ dir_sort (dir, dirdata) static int compare_names (file1, file2) - char **file1, **file2; + void const *file1, *file2; { - return strcmp (*file1, *file2); + return strcmp (* (char const *const *) file1, * (char const *const *) file2); } /* Compare the contents of two directories named in FILEVEC[0] and FILEVEC[1]. @@ -155,8 +158,8 @@ compare_names (file1, file2) int diff_dirs (filevec, handle_file, depth) - struct file_data filevec[]; - int (*handle_file) (); + struct file_data const filevec[]; + int (*handle_file) PARAMS((char const *, char const *, char const *, char const *, int)); int depth; { struct dirdata dirdata[2]; @@ -173,42 +176,42 @@ diff_dirs (filevec, handle_file, depth) if (val == 0) { - register char **files0 = dirdata[0].files; - register char **files1 = dirdata[1].files; - char *name0 = filevec[0].name; - char *name1 = filevec[1].name; + register char const * const *names0 = dirdata[0].names; + register char const * const *names1 = dirdata[1].names; + char const *name0 = filevec[0].name; + char const *name1 = filevec[1].name; /* If `-S name' was given, and this is the topmost level of comparison, ignore all file names less than the specified starting name. */ if (dir_start_file && depth == 0) { - while (*files0 && strcmp (*files0, dir_start_file) < 0) - files0++; - while (*files1 && strcmp (*files1, dir_start_file) < 0) - files1++; + while (*names0 && strcmp (*names0, dir_start_file) < 0) + names0++; + while (*names1 && strcmp (*names1, dir_start_file) < 0) + names1++; } /* Loop while files remain in one or both dirs. */ - while (*files0 || *files1) + while (*names0 || *names1) { /* Compare next name in dir 0 with next name in dir 1. At the end of a dir, pretend the "next name" in that dir is very large. */ - int nameorder = (!*files0 ? 1 : !*files1 ? -1 - : strcmp (*files0, *files1)); - int v1 = (*handle_file) (name0, 0 < nameorder ? 0 : *files0++, - name1, nameorder < 0 ? 0 : *files1++, + int nameorder = (!*names0 ? 1 : !*names1 ? -1 + : strcmp (*names0, *names1)); + int v1 = (*handle_file) (name0, 0 < nameorder ? 0 : *names0++, + name1, nameorder < 0 ? 0 : *names1++, depth + 1); if (v1 > val) val = v1; } } - + for (i = 0; i < 2; i++) { - if (dirdata[i].files) - free (dirdata[i].files); + if (dirdata[i].names) + free (dirdata[i].names); if (dirdata[i].data) free (dirdata[i].data); } |
