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 | |
275bb093 | 15 | static char sccsid[] = "@(#)mtree.c 5.9 (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> |
275bb093 | 21 | #include <unistd.h> |
ebe5d13b | 22 | #include <stdio.h> |
014e60d8 | 23 | #include <fts.h> |
ebe5d13b | 24 | #include "mtree.h" |
275bb093 | 25 | #include "extern.h" |
ebe5d13b | 26 | |
275bb093 | 27 | extern int crc_total; |
ebe5d13b | 28 | |
275bb093 KB |
29 | int ftsoptions = FTS_PHYSICAL; |
30 | int cflag, dflag, eflag, rflag, sflag, uflag; | |
31 | u_short keys; | |
32 | char fullpath[MAXPATHLEN]; | |
33 | ||
34 | static void usage __P((void)); | |
35 | ||
36 | int | |
ebe5d13b KB |
37 | main(argc, argv) |
38 | int argc; | |
275bb093 | 39 | char *argv[]; |
ebe5d13b | 40 | { |
275bb093 | 41 | extern int optind; |
ebe5d13b | 42 | extern char *optarg; |
ebe5d13b | 43 | int ch; |
275bb093 | 44 | char *dir, *p; |
ebe5d13b | 45 | |
275bb093 KB |
46 | dir = NULL; |
47 | keys = KEYDEFAULT; | |
48 | while ((ch = getopt(argc, argv, "cdef:K:k:p:rs:ux")) != EOF) | |
ebe5d13b KB |
49 | switch((char)ch) { |
50 | case 'c': | |
51 | cflag = 1; | |
52 | break; | |
53 | case 'd': | |
54 | dflag = 1; | |
55 | break; | |
56 | case 'e': | |
57 | eflag = 1; | |
58 | break; | |
59 | case 'f': | |
275bb093 KB |
60 | if (!(freopen(optarg, "r", stdin))) |
61 | err("%s: %s", optarg, strerror(errno)); | |
62 | break; | |
63 | case 'K': | |
64 | while ((p = strsep(&optarg, " \t,")) != NULL) | |
65 | if (*p != '\0') | |
66 | keys |= parsekey(p); | |
67 | break; | |
68 | case 'k': | |
69 | keys = F_TYPE; | |
70 | while ((p = strsep(&optarg, " \t,")) != NULL) | |
71 | if (*p != '\0') | |
72 | keys |= parsekey(p); | |
ebe5d13b KB |
73 | break; |
74 | case 'p': | |
014e60d8 | 75 | dir = optarg; |
ebe5d13b KB |
76 | break; |
77 | case 'r': | |
78 | rflag = 1; | |
79 | break; | |
275bb093 KB |
80 | case 's': |
81 | sflag = 1; | |
82 | crc_total = ~strtol(optarg, &p, 0); | |
83 | if (*p) | |
84 | err("illegal seed value -- %s", optarg); | |
ebe5d13b KB |
85 | case 'u': |
86 | uflag = 1; | |
87 | break; | |
88 | case 'x': | |
014e60d8 | 89 | ftsoptions |= FTS_XDEV; |
ebe5d13b KB |
90 | break; |
91 | case '?': | |
92 | default: | |
cbe4b98c | 93 | usage(); |
ebe5d13b | 94 | } |
cbe4b98c | 95 | argc -= optind; |
275bb093 KB |
96 | argv += optind; |
97 | ||
cbe4b98c KB |
98 | if (argc) |
99 | usage(); | |
100 | ||
275bb093 KB |
101 | if (dir && chdir(dir)) |
102 | err("%s: %s", dir, strerror(errno)); | |
cbe4b98c | 103 | |
275bb093 KB |
104 | if ((cflag || sflag) && !getwd(fullpath)) |
105 | err("%s", fullpath); | |
ebe5d13b | 106 | |
275bb093 | 107 | if (cflag) { |
014e60d8 | 108 | cwalk(); |
275bb093 KB |
109 | exit(0); |
110 | } | |
111 | exit(verify()); | |
ebe5d13b | 112 | } |
8e4dc6b0 | 113 | |
275bb093 | 114 | static void |
cbe4b98c | 115 | usage() |
8e4dc6b0 | 116 | { |
cbe4b98c | 117 | (void)fprintf(stderr, |
275bb093 | 118 | "usage: mtree [-cderux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); |
cbe4b98c | 119 | exit(1); |
8e4dc6b0 | 120 | } |