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