Commit | Line | Data |
---|---|---|
cbe4b98c | 1 | /*- |
ebe5d13b KB |
2 | * Copyright (c) 1989 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
cbe4b98c | 5 | * %sccs.include.redist.c% |
ebe5d13b KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
cbe4b98c | 10 | "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ |
ebe5d13b KB |
11 | All rights reserved.\n"; |
12 | #endif /* not lint */ | |
13 | ||
14 | #ifndef lint | |
70db696e | 15 | static char sccsid[] = "@(#)mtree.c 5.8 (Berkeley) %G%"; |
ebe5d13b KB |
16 | #endif /* not lint */ |
17 | ||
18 | #include <sys/param.h> | |
014e60d8 | 19 | #include <sys/stat.h> |
cbe4b98c | 20 | #include <errno.h> |
ebe5d13b | 21 | #include <stdio.h> |
014e60d8 | 22 | #include <fts.h> |
ebe5d13b KB |
23 | #include "mtree.h" |
24 | ||
6e4c29b1 | 25 | NODE *root; |
014e60d8 KB |
26 | int exitval; |
27 | int cflag, dflag, eflag, rflag, uflag; | |
ebe5d13b KB |
28 | |
29 | main(argc, argv) | |
30 | int argc; | |
31 | char **argv; | |
32 | { | |
014e60d8 | 33 | extern int ftsoptions, optind; |
ebe5d13b | 34 | extern char *optarg; |
ebe5d13b | 35 | int ch; |
014e60d8 | 36 | char *dir; |
ebe5d13b | 37 | |
014e60d8 | 38 | dir = (char *)NULL; |
ebe5d13b KB |
39 | while ((ch = getopt(argc, argv, "cdef:p:rux")) != EOF) |
40 | switch((char)ch) { | |
41 | case 'c': | |
42 | cflag = 1; | |
43 | break; | |
44 | case 'd': | |
45 | dflag = 1; | |
46 | break; | |
47 | case 'e': | |
48 | eflag = 1; | |
49 | break; | |
50 | case 'f': | |
51 | if (!(freopen(optarg, "r", stdin))) { | |
52 | (void)fprintf(stderr, | |
53 | "mtree: can't read %s.\n", optarg); | |
54 | exit(1); | |
55 | } | |
56 | break; | |
57 | case 'p': | |
014e60d8 | 58 | dir = optarg; |
ebe5d13b KB |
59 | break; |
60 | case 'r': | |
61 | rflag = 1; | |
62 | break; | |
63 | case 'u': | |
64 | uflag = 1; | |
65 | break; | |
66 | case 'x': | |
014e60d8 | 67 | ftsoptions |= FTS_XDEV; |
ebe5d13b KB |
68 | break; |
69 | case '?': | |
70 | default: | |
cbe4b98c | 71 | usage(); |
ebe5d13b | 72 | } |
cbe4b98c KB |
73 | argc -= optind; |
74 | if (argc) | |
75 | usage(); | |
76 | ||
ebe5d13b KB |
77 | if (!cflag) |
78 | spec(); | |
cbe4b98c | 79 | |
014e60d8 | 80 | if (dir && chdir(dir)) { |
ebe5d13b | 81 | (void)fprintf(stderr, |
014e60d8 | 82 | "mtree: %s: %s\n", dir, strerror(errno)); |
ebe5d13b KB |
83 | exit(1); |
84 | } | |
ebe5d13b | 85 | |
014e60d8 KB |
86 | if (cflag) |
87 | cwalk(); | |
88 | else | |
89 | verify(); | |
cbe4b98c | 90 | exit(exitval); |
ebe5d13b | 91 | } |
8e4dc6b0 | 92 | |
cbe4b98c | 93 | usage() |
8e4dc6b0 | 94 | { |
cbe4b98c KB |
95 | (void)fprintf(stderr, |
96 | "usage: mtree [-cderux] [-p path] [-f spec]\n"); | |
97 | exit(1); | |
8e4dc6b0 | 98 | } |