Skip to content

Commit ecf1d5e

Browse files
author
archie.cobbs
committed
- Added `-I' flag
- Portability fixes
1 parent 53140b1 commit ecf1d5e

11 files changed

+108
-33
lines changed

CHANGES

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
Version 1.0.1
3+
4+
- Added `-I' flag
5+
- Portability fixes
6+
27
Version 1.0 (r4) released 5 Nov 2010
38

49
- Initial release

configure.ac

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ AC_CHECK_HEADERS(dirent.h err.h errno.h fcntl.h fnmatch.h fts.h grp.h limits.h p
3939
# Check for optional header files
4040
AC_CHECK_HEADERS(openssl/md5.h openssl/sha.h openssl/ripemd.h,,)
4141

42+
# Check for optional functions
43+
AC_CHECK_FUNCS(getmode getline,,)
44+
4245
# Optional features
4346
AC_ARG_ENABLE(Werror,
4447
AC_HELP_STRING([--enable-Werror],

create.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ cwalk(void)
105105
while ((p = fts_read(t))) {
106106
if (iflag)
107107
indent = p->fts_level * 4;
108-
if (check_excludes(p->fts_name, p->fts_path)) {
108+
if (!check_includes(p->fts_name, p->fts_path)
109+
|| check_excludes(p->fts_name, p->fts_path)) {
109110
fts_set(t, p, FTS_SKIP);
110111
continue;
111112
}

excludes.c

+56-10
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,63 @@
4848
* We're assuming that there won't be a whole lot of excludes,
4949
* so it's OK to use a stupid algorithm.
5050
*/
51-
struct exclude {
52-
LIST_ENTRY(exclude) link;
51+
struct patlist {
52+
LIST_ENTRY(patlist) link;
5353
const char *glob;
5454
int pathname;
5555
};
56-
static LIST_HEAD(, exclude) excludes;
56+
LIST_HEAD(pathead, patlist);
57+
58+
static struct pathead includes;
59+
static struct pathead excludes;
60+
61+
static int any_includes;
62+
63+
static void read_patlist_file(struct pathead *pathead, const char *name);
64+
static int check_patlist(struct pathead *pathead, const char *fname, const char *path);
5765

5866
void
59-
init_excludes(void)
67+
init_patlists(void)
6068
{
69+
LIST_INIT(&includes);
6170
LIST_INIT(&excludes);
6271
}
6372

73+
void
74+
read_includes_file(const char *name)
75+
{
76+
read_patlist_file(&includes, name);
77+
any_includes = 1;
78+
}
79+
6480
void
6581
read_excludes_file(const char *name)
82+
{
83+
read_patlist_file(&excludes, name);
84+
}
85+
86+
static void
87+
read_patlist_file(struct pathead *pathead, const char *name)
6688
{
6789
FILE *fp;
6890
char *line, *str;
69-
struct exclude *e;
91+
struct patlist *e;
92+
#if HAVE_GETLINE
7093
ssize_t len;
7194
size_t alloc;
95+
#else
96+
size_t len;
97+
#endif
7298

7399
fp = fopen(name, "r");
74100
if (fp == 0)
75101
err(1, "%s", name);
76102

77-
for (line = NULL; (len = getline(&line, &alloc, fp)) != -1; ) {
103+
#if HAVE_GETLINE
104+
for (line = NULL; (len = getline(&line, &alloc, fp)) != -1; ) {
105+
#else
106+
while ((line = fgetln(fp, &len)) != NULL) {
107+
#endif
78108
if (line[len - 1] == '\n')
79109
len--;
80110
if (len == 0)
@@ -91,24 +121,40 @@ read_excludes_file(const char *name)
91121
e->pathname = 1;
92122
else
93123
e->pathname = 0;
94-
LIST_INSERT_HEAD(&excludes, e, link);
124+
LIST_INSERT_HEAD(pathead, e, link);
95125
}
96-
free(line);
126+
#if HAVE_GETLINE
127+
free(line);
128+
#endif
97129
fclose(fp);
98130
}
99131

132+
int
133+
check_includes(const char *fname, const char *path)
134+
{
135+
return !any_includes || check_patlist(&includes, fname, path);
136+
}
137+
100138
int
101139
check_excludes(const char *fname, const char *path)
102140
{
103-
struct exclude *e;
141+
return check_patlist(&excludes, fname, path);
142+
}
143+
144+
static int
145+
check_patlist(struct pathead *pathead, const char *fname, const char *path)
146+
{
147+
struct patlist *e;
104148

105149
/* fnmatch(3) has a funny return value convention... */
106150
#define MATCH(g, n) (fnmatch((g), (n), FNM_PATHNAME) == 0)
107151

108-
LIST_FOREACH(e, &excludes, link) {
152+
LIST_FOREACH(e, pathead, link) {
109153
if ((e->pathname && MATCH(e->glob, path))
110154
|| MATCH(e->glob, fname))
111155
return 1;
112156
}
113157
return 0;
114158
}
159+
160+

extern.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636

3737
extern uint32_t crc_total;
3838

39-
#ifdef _FTS_H_
40-
int compare(char *, NODE *, FTSENT *);
41-
#endif
4239
int crc(int, uint32_t *, off_t *);
4340
void cwalk(void);
4441
char *flags_to_string(u_long);
@@ -49,15 +46,19 @@ char *rlink(char *);
4946
NODE *mtree_readspec(FILE *fi);
5047
int mtree_verifyspec(FILE *fi);
5148
int mtree_specspec(FILE *fi, FILE *fj);
52-
int compare(char *name, NODE *s, FTSENT *p);
49+
int compare(char *name, NODE *s, FTSENT *p);
5350

54-
int check_excludes(const char *, const char *);
55-
void init_excludes(void);
56-
void read_excludes_file(const char *);
51+
int check_includes(const char *, const char *);
52+
int check_excludes(const char *, const char *);
53+
void init_patlists(void);
54+
void read_includes_file(const char *);
55+
void read_excludes_file(const char *);
5756
const char * ftype(u_int type);
5857

58+
#if !HAVE_GETMODE
5959
mode_t getmode(const void *bbox, mode_t omode);
6060
void *setmode(const char *p);
61+
#endif
6162

6263
#ifdef HAVE_OPENSSL_MD5_H
6364
char * MD5_File(const char *filename, char *result);

mtree.8

+25
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
.Op Fl f Ar spec
4242
.Ek
4343
.Bk -words
44+
.Op Fl I Ar include-list
45+
.Ek
46+
.Bk -words
4447
.Op Fl K Ar keywords
4548
.Ek
4649
.Bk -words
@@ -133,6 +136,22 @@ The output format in this case is somewhat remniscent of
133136
having "in first spec only", "in second spec only", and "different"
134137
columns, prefixed by zero, one and two TAB characters respectively.
135138
Each entry in the "different" column occupies two lines, one from each specification.
139+
.It Fl I Ar include-list
140+
The specified file contains
141+
.Xr fnmatch 3
142+
patterns matching files to be included in
143+
the specification, one to a line.
144+
If the pattern contains a
145+
.Ql \&/
146+
character, it will be matched against entire pathnames (relative to
147+
the starting directory); otherwise,
148+
it will be matched against basenames only.
149+
No comments are allowed in
150+
the
151+
.Ar include-list
152+
file.
153+
.Pp
154+
If this flag is not present, all files are included by default.
136155
.It Fl K Ar keywords
137156
Add the specified (whitespace or comma separated)
138157
.Ar keywords
@@ -165,6 +184,12 @@ No comments are allowed in
165184
the
166185
.Ar exclude-list
167186
file.
187+
.Pp
188+
If both
189+
.Fl I
190+
and
191+
.Fl X
192+
are specified, any files matching both lists are excluded.
168193
.El
169194
.Pp
170195
Specifications are mostly composed of ``keywords'', i.e., strings

mtree.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ main(int argc, char *argv[])
7171

7272
dir = NULL;
7373
keys = KEYDEFAULT;
74-
init_excludes();
74+
init_patlists();
7575
spec1 = stdin;
7676
spec2 = NULL;
7777

@@ -98,6 +98,9 @@ main(int argc, char *argv[])
9898
} else
9999
usage();
100100
break;
101+
case 'I':
102+
read_includes_file(optarg);
103+
break;
101104
case 'i':
102105
iflag = 1;
103106
break;

mtree.h

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838

3939
#define MISMATCHEXIT 2
4040

41-
#define st_atimespec st_atim
42-
#define st_ctimespec st_ctim
43-
#define st_mtimespec st_mtim
44-
4541
typedef struct _node {
4642
struct _node *parent, *child; /* up, down */
4743
struct _node *prev, *next; /* left, right */

setmode.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
* SUCH DAMAGE.
3131
*/
3232

33-
#if defined(LIBC_SCCS) && !defined(lint)
34-
static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94";
35-
#endif /* LIBC_SCCS and not lint */
36-
3733
#include "config.h"
3834

35+
#if !HAVE_GETMODE
36+
3937
#include <sys/cdefs.h>
4038
#include <sys/types.h>
4139

@@ -448,3 +446,4 @@ compress_mode(BITCMD *set)
448446
}
449447
}
450448
}
449+
#endif /* !HAVE_GETMODE */

verify.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ vwalk(void)
9090
level = root;
9191
specdepth = rval = 0;
9292
while ((p = fts_read(t))) {
93-
if (check_excludes(p->fts_name, p->fts_path)) {
93+
if (!check_includes(p->fts_name, p->fts_path)
94+
|| check_excludes(p->fts_name, p->fts_path)) {
9495
fts_set(t, p, FTS_SKIP);
9596
continue;
9697
}

vis.h

-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939

4040
#include <sys/types.h>
4141

42-
#ifndef _SIZE_T_DECLARED
43-
typedef __size_t size_t;
44-
#define _SIZE_T_DECLARED
45-
#endif
46-
4742
/*
4843
* to select alternate encoding format
4944
*/

0 commit comments

Comments
 (0)