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.
This commit is contained in:
Piotr Pawel Stefaniak 2021-09-05 01:50:58 +02:00
parent b5541f456d
commit e43df07e37
4 changed files with 39 additions and 39 deletions

View file

@ -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);
}

View file

@ -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 *);

View file

@ -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);
}

View file

@ -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)
{