From e43df07e3725ef6d14a2ca635598c18295b1b481 Mon Sep 17 00:00:00 2001 From: Piotr Pawel Stefaniak Date: Sun, 5 Sep 2021 01:50:58 +0200 Subject: diff: move functions around and reduce their visibility Most of them become static. There will be more such functions added in upcoming commits, so they would be inconsistent with existing code. Improve the existing code instead of reinforcing the unwanted pattern. --- usr.bin/diff/diff.c | 50 ++++++++++++++++++++++++++++++-------------------- usr.bin/diff/diff.h | 2 -- usr.bin/diff/diffdir.c | 9 +++++++++ usr.bin/diff/diffreg.c | 17 ----------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 03eb16211e86..a5966e74dbcc 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -101,12 +101,13 @@ static struct option longopts[] = { { NULL, 0, 0, '\0'} }; -void usage(void) __dead2; -void conflicting_format(void) __dead2; -void push_excludes(char *); -void push_ignore_pats(char *); -void read_excludes_file(char *file); -void set_argstr(char **, char **); +static void usage(void) __dead2; +static void conflicting_format(void) __dead2; +static void push_excludes(char *); +static void push_ignore_pats(char *); +static void read_excludes_file(char *file); +static void set_argstr(char **, char **); +static char *splice(char *, char *); int main(int argc, char **argv) @@ -393,7 +394,7 @@ main(int argc, char **argv) exit(status); } -void +static void set_argstr(char **av, char **ave) { size_t argsize; @@ -413,7 +414,7 @@ set_argstr(char **av, char **ave) /* * Read in an excludes file and push each line. */ -void +static void read_excludes_file(char *file) { FILE *fp; @@ -438,7 +439,7 @@ read_excludes_file(char *file) /* * Push a pattern onto the excludes list. */ -void +static void push_excludes(char *pattern) { struct excludes *entry; @@ -449,7 +450,7 @@ push_excludes(char *pattern) excludes_list = entry; } -void +static void push_ignore_pats(char *pattern) { size_t len; @@ -465,14 +466,6 @@ push_ignore_pats(char *pattern) } } -void -print_only(const char *path, size_t dirlen, const char *entry) -{ - if (dirlen > 1) - dirlen--; - printf("Only in %.*s: %s\n", (int)dirlen, path, entry); -} - void print_status(int val, char *path1, char *path2, const char *entry) { @@ -517,7 +510,7 @@ print_status(int val, char *path1, char *path2, const char *entry) } } -void +static void usage(void) { (void)fprintf(stderr, @@ -544,10 +537,27 @@ usage(void) exit(2); } -void +static void conflicting_format(void) { fprintf(stderr, "error: conflicting output format options.\n"); usage(); } + +static char * +splice(char *dir, char *path) +{ + char *tail, *buf; + size_t dirlen; + + dirlen = strlen(dir); + while (dirlen != 0 && dir[dirlen - 1] == '/') + dirlen--; + if ((tail = strrchr(path, '/')) == NULL) + tail = path; + else + tail++; + xasprintf(&buf, "%.*s/%s", (int)dirlen, dir, tail); + return (buf); +} diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h index 04e75e631954..7ae700810fc6 100644 --- a/usr.bin/diff/diff.h +++ b/usr.bin/diff/diff.h @@ -102,8 +102,6 @@ extern struct stat stb1, stb2; extern struct excludes *excludes_list; extern regex_t ignore_re; -char *splice(char *, char *); int diffreg(char *, char *, int, int); void diffdir(char *, char *, int); -void print_only(const char *, size_t, const char *); void print_status(int, char *, char *, const char *); diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c index 2b6e5f366454..ecb7c4a6c4ee 100644 --- a/usr.bin/diff/diffdir.c +++ b/usr.bin/diff/diffdir.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); static int selectfile(const struct dirent *); static void diffit(struct dirent *, char *, size_t, char *, size_t, int); +static void print_only(const char *, size_t, const char *); #define d_status d_type /* we need to store status for -l */ @@ -237,3 +238,11 @@ selectfile(const struct dirent *dp) return (1); } + +void +print_only(const char *path, size_t dirlen, const char *entry) +{ + if (dirlen > 1) + dirlen--; + printf("Only in %.*s: %s\n", (int)dirlen, path, entry); +} diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 94026007a1bf..45821ad96e8c 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -486,23 +486,6 @@ opentemp(const char *f) return (fdopen(ofd, "r")); } -char * -splice(char *dir, char *path) -{ - char *tail, *buf; - size_t dirlen; - - dirlen = strlen(dir); - while (dirlen != 0 && dir[dirlen - 1] == '/') - dirlen--; - if ((tail = strrchr(path, '/')) == NULL) - tail = path; - else - tail++; - xasprintf(&buf, "%.*s/%s", (int)dirlen, dir, tail); - return (buf); -} - static bool prepare(int i, FILE *fd, size_t filesize, int flags) { -- cgit v1.2.3