]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/fprint.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / fprint.c
1 /*
2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include <ctype.h>
35 #include <time.h>
36 #include "type.h"
37 #include "faddr.h"
38 #include "fprint.h"
39 #include "field.h"
40 #include "inode.h"
41 #include "inobt.h"
42 #include "bit.h"
43 #include "print.h"
44 #include "output.h"
45 #include "sig.h"
46 #include "malloc.h"
47
48 int
49 fp_charns(
50 void *obj,
51 int bit,
52 int count,
53 char *fmtstr,
54 int size,
55 int arg,
56 int base,
57 int array)
58 {
59 int i;
60 char *p;
61
62 ASSERT(bitoffs(bit) == 0);
63 ASSERT(size == bitsz(char));
64 dbprintf("\"");
65 for (i = 0, p = (char *)obj + byteize(bit);
66 i < count && !seenint();
67 i++, p++) {
68 if (*p == '\\' || *p == '\'' || *p == '"' || *p == '\?')
69 dbprintf("\\%c", *p);
70 else if (isgraph((int)*p) || *p == ' ')
71 dbprintf("%c", *p);
72 else if (*p == '\a' || *p == '\b' || *p == '\f' || *p == '\n' ||
73 *p == '\r' || *p == '\t' || *p == '\v')
74 dbprintf("\\%c", *p + ('a' - '\a'));
75 else
76 dbprintf("\\%03o", *p & 0xff);
77 }
78 dbprintf("\"");
79 return 1;
80 }
81
82 int
83 fp_num(
84 void *obj,
85 int bit,
86 int count,
87 char *fmtstr,
88 int size,
89 int arg,
90 int base,
91 int array)
92 {
93 int bitpos;
94 int i;
95 int isnull;
96 __int64_t val;
97
98 for (i = 0, bitpos = bit;
99 i < count && !seenint();
100 i++, bitpos += size) {
101 val = getbitval(obj, bitpos, size,
102 (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED);
103 if ((arg & FTARG_SKIPZERO) && val == 0)
104 continue;
105 isnull = (arg & FTARG_SIGNED) || size == 64 ?
106 val == -1LL : val == ((1LL << size) - 1LL);
107 if ((arg & FTARG_SKIPNULL) && isnull)
108 continue;
109 if (array)
110 dbprintf("%d:", i + base);
111 if ((arg & FTARG_DONULL) && isnull)
112 dbprintf("null");
113 else if (size > 32)
114 dbprintf(fmtstr, val);
115 else
116 dbprintf(fmtstr, (__int32_t)val);
117 if (i < count - 1)
118 dbprintf(" ");
119 }
120 return 1;
121 }
122
123 /*ARGSUSED*/
124 int
125 fp_sarray(
126 void *obj,
127 int bit,
128 int count,
129 char *fmtstr,
130 int size,
131 int arg,
132 int base,
133 int array)
134 {
135 print_sarray(obj, bit, count, size, base, array,
136 (const field_t *)fmtstr, (arg & FTARG_SKIPNMS) != 0);
137 return 1;
138 }
139
140 /*ARGSUSED*/
141 int
142 fp_time(
143 void *obj,
144 int bit,
145 int count,
146 char *fmtstr,
147 int size,
148 int arg,
149 int base,
150 int array)
151 {
152 int bitpos;
153 char *c;
154 int i;
155 time_t t;
156
157 ASSERT(bitoffs(bit) == 0);
158 for (i = 0, bitpos = bit;
159 i < count && !seenint();
160 i++, bitpos += size) {
161 if (array)
162 dbprintf("%d:", i + base);
163 t=(time_t)getbitval((char *)obj + byteize(bitpos), 0, sizeof(int32_t)*8, 0);
164 c = ctime(&t);
165 dbprintf("%24.24s", c);
166 if (i < count - 1)
167 dbprintf(" ");
168 }
169 return 1;
170 }
171
172 /*ARGSUSED*/
173 int
174 fp_uuid(
175 void *obj,
176 int bit,
177 int count,
178 char *fmtstr,
179 int size,
180 int arg,
181 int base,
182 int array)
183 {
184 char bp[40]; /* UUID string is 36 chars + trailing '\0' */
185 int i;
186 uuid_t *p;
187
188 ASSERT(bitoffs(bit) == 0);
189 for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0;
190 i < count && !seenint();
191 i++, p++) {
192 if (array)
193 dbprintf("%d:", i + base);
194 uuid_unparse(*p, bp);
195 dbprintf("%s", bp);
196 if (i < count - 1)
197 dbprintf(" ");
198 }
199 return 1;
200 }