Deleted Added
sdiff udiff text old ( 99800 ) new ( 99802 )
full compact
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.sbin/mtree/misc.c 99802 2002-07-11 18:42:53Z alfred $";
40#endif /*not lint */
41
42#include <sys/types.h>
43#include <sys/stat.h>
44#include <err.h>
45#include <fts.h>
46#include <stdio.h>
47#include <unistd.h>
48#include "mtree.h"
49#include "extern.h"
50
51extern int lineno;
52
53typedef struct _key {
54 const char *name; /* key name */
55 u_int val; /* value */
56
57#define NEEDVALUE 0x01
58 u_int flags;
59} KEY;
60
61/* NB: the following table must be sorted lexically. */
62static KEY keylist[] = {

--- 17 unchanged lines hidden (view full) ---

80#endif
81 {"size", F_SIZE, NEEDVALUE},
82 {"time", F_TIME, NEEDVALUE},
83 {"type", F_TYPE, NEEDVALUE},
84 {"uid", F_UID, NEEDVALUE},
85 {"uname", F_UNAME, NEEDVALUE},
86};
87
88int keycompare(const void *, const void *);
89
90u_int
91parsekey(name, needvaluep)
92 char *name;
93 int *needvaluep;
94{
95 KEY *k, tmp;
96
97 tmp.name = name;
98 k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY),
99 sizeof(KEY), keycompare);
100 if (k == NULL)
101 errx(1, "line %d: unknown keyword %s", lineno, name);
102
103 if (needvaluep)
104 *needvaluep = k->flags & NEEDVALUE ? 1 : 0;
105 return (k->val);
106}
107
108int
109keycompare(a, b)
110 const void *a, *b;
111{
112 return (strcmp(((const KEY *)a)->name, ((const KEY *)b)->name));
113}
114
115char *
116flags_to_string(fflags)
117 u_long fflags;
118{
119 char *string;
120
121 string = fflagstostr(fflags);
122 if (string != NULL && *string == '\0') {
123 free(string);
124 string = strdup("none");
125 }
126 if (string == NULL)
127 err(1, NULL);
128
129 return string;
130}