1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)misc.c 5.1 (Berkeley) 12/11/91 8 */ 9 10 #include <sys/types.h> 11 #include <sys/stat.h> 12 #include <fts.h> 13 #include <stdio.h> 14 #include "mtree.h" 15 #include "extern.h" 16 17 extern int lineno; 18 19 typedef struct _key { 20 char *name; /* key name */ 21 u_int val; /* value */ 22 } KEY; 23 24 /* NB: the following table must be sorted lexically. */ 25 static KEY keylist[] = { 26 "cksum", F_CKSUM, 27 "gid", F_GID, 28 "gname", F_GNAME, 29 "ignore", F_IGN, 30 "link", F_SLINK, 31 "mode", F_MODE, 32 "nlink", F_NLINK, 33 "size", F_SIZE, 34 "time", F_TIME, 35 "type", F_TYPE, 36 "uid", F_UID, 37 "uname", F_UNAME, 38 }; 39 40 u_int 41 parsekey(name) 42 char *name; 43 { 44 KEY *k, tmp; 45 int keycompare __P((const void *, const void *)); 46 47 tmp.name = name; 48 k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY), 49 sizeof(KEY), keycompare); 50 if (k == NULL) 51 err("unknown keyword %s", name); 52 return (k->val); 53 } 54 55 int 56 keycompare(a, b) 57 const void *a, *b; 58 { 59 return (strcmp(((KEY *)a)->name, ((KEY *)b)->name)); 60 } 61 62 #if __STDC__ 63 #include <stdarg.h> 64 #else 65 #include <varargs.h> 66 #endif 67 68 void 69 #if __STDC__ 70 err(const char *fmt, ...) 71 #else 72 err(fmt, va_alist) 73 char *fmt; 74 va_dcl 75 #endif 76 { 77 va_list ap; 78 #if __STDC__ 79 va_start(ap, fmt); 80 #else 81 va_start(ap); 82 #endif 83 (void)fprintf(stderr, "mtree: "); 84 (void)vfprintf(stderr, fmt, ap); 85 va_end(ap); 86 (void)fprintf(stderr, "\n"); 87 if (lineno) 88 (void)fprintf(stderr, 89 "mtree: failed at line %d of the specification\n", lineno); 90 exit(1); 91 /* NOTREACHED */ 92 } 93