Deleted Added
full compact
misc.c (99800) misc.c (99802)
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[] =
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 99800 2002-07-11 18:31:16Z alfred $";
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 {
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 char *name; /* key name */
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
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
88u_int
89parsekey(name, needvaluep)
90 char *name;
91 int *needvaluep;
92{
93 KEY *k, tmp;
90u_int
91parsekey(name, needvaluep)
92 char *name;
93 int *needvaluep;
94{
95 KEY *k, tmp;
94 int keycompare(const void *, const void *);
95
96 tmp.name = name;
97 k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY),
98 sizeof(KEY), keycompare);
99 if (k == NULL)
100 errx(1, "line %d: unknown keyword %s", lineno, name);
101
102 if (needvaluep)
103 *needvaluep = k->flags & NEEDVALUE ? 1 : 0;
104 return (k->val);
105}
106
107int
108keycompare(a, b)
109 const void *a, *b;
110{
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{
111 return (strcmp(((KEY *)a)->name, ((KEY *)b)->name));
112 return (strcmp(((const KEY *)a)->name, ((const KEY *)b)->name));
112}
113
114char *
115flags_to_string(fflags)
116 u_long fflags;
117{
118 char *string;
119
120 string = fflagstostr(fflags);
121 if (string != NULL && *string == '\0') {
122 free(string);
123 string = strdup("none");
124 }
125 if (string == NULL)
126 err(1, NULL);
127
128 return string;
129}
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}