aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Pawel Stefaniak <pstef@FreeBSD.org>2021-09-04 23:50:58 +0000
committerPiotr Pawel Stefaniak <pstef@FreeBSD.org>2021-09-15 23:36:41 +0000
commite43df07e3725ef6d14a2ca635598c18295b1b481 (patch)
tree7370edadeabfd8f026c3c90496af10e9c8dea8c8
parentb5541f456d641d23e0c46874daff0b62552bf3cb (diff)
downloadsrc-e43df07e3725ef6d14a2ca635598c18295b1b481.tar.gz
src-e43df07e3725ef6d14a2ca635598c18295b1b481.zip
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.
-rw-r--r--usr.bin/diff/diff.c50
-rw-r--r--usr.bin/diff/diff.h2
-rw-r--r--usr.bin/diff/diffdir.c9
-rw-r--r--usr.bin/diff/diffreg.c17
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;
@@ -466,14 +467,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)
{
if (label[0] != NULL)
@@ -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)
{