xref: /dragonfly/bin/cpdup/misc.c (revision 1bf4b486)
1 /*
2  * MISC.C
3  *
4  * $DragonFly: src/bin/cpdup/misc.c,v 1.5 2004/08/25 01:38:50 dillon Exp $
5  */
6 
7 #include "cpdup.h"
8 
9 void
10 logstd(const char *ctl, ...)
11 {
12     va_list va;
13 
14     va_start(va, ctl);
15     vprintf(ctl, va);
16     va_end(va);
17 }
18 
19 void
20 logerr(const char *ctl, ...)
21 {
22     va_list va;
23 
24     va_start(va, ctl);
25     vfprintf(stderr, ctl, va);
26     va_end(va);
27 }
28 
29 char *
30 mprintf(const char *ctl, ...)
31 {
32     char *ptr;
33     va_list va;
34 
35     ptr = NULL;
36 
37     va_start(va, ctl);
38     if (vasprintf(&ptr, ctl, va) < 0)
39 	fatal("malloc failed");
40     va_end(va);
41     assert(ptr != NULL);
42     return(ptr);
43 }
44 
45 void
46 fatal(const char *ctl, ...)
47 {
48     va_list va;
49 
50     if (ctl == NULL) {
51 	puts("cpdup [<options>] src [dest]");
52 	puts("    -v[vv]      verbose level (-vv is typical)\n"
53 	     "    -u          use unbuffered output for -v[vv]\n"
54 	     "    -I          display performance summary\n"
55 	     "    -f          force update even if files look the same\n"
56 	     "    -i0         do NOT confirm when removing something\n"
57 	     "    -s0         disable safeties - allow files to overwrite directories\n"
58 	     "    -q          quiet operation\n"
59 	     "    -o          do not remove any files, just overwrite/add\n"
60 	);
61 	puts("    -m          maintain/generate MD5 checkfile on source,\n"
62 	     "                and compare with (optional) destination,\n"
63 	     "                copying if the compare fails\n"
64 	     "    -M file     -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
65 	     "                copy if md5 check fails\n"
66 	     "    -x          use .cpignore as exclusion file\n"
67 	     "    -X file     specify exclusion file\n"
68 	     " Version 1.06 by Matt Dillon and Dima Ruban\n"
69 	);
70 	exit(0);
71     } else {
72 	va_start(va, ctl);
73 	vprintf(ctl, va);
74 	va_end(va);
75 	puts("");
76 	exit(1);
77     }
78 }
79