]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/print.c
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 static void print_allfields(const struct field
*fields
);
35 static int print_f(int argc
, char **argv
);
36 static void print_flist_1(struct flist
*flist
, char **pfx
, int parentoff
);
37 static void print_somefields(const struct field
*fields
, int argc
,
40 static const cmdinfo_t print_cmd
=
41 { "print", "p", print_f
, 0, -1, 0, N_("[value]..."),
42 N_("print field values"), NULL
};
46 const field_t
*fields
)
53 flist
= flist_make("");
56 (void)flist_parse(fields
, flist
, iocur_top
->data
, 0);
58 i
= flist_parse(fields
, flist
, iocur_top
->data
, 0);
73 if (cur_typ
== NULL
) {
74 dbprintf(_("no current type\n"));
79 dbprintf(_("no print function for type %s\n"), cur_typ
->name
);
84 (*pf
)(DB_READ
, cur_typ
->fields
, argc
, argv
);
95 print_flist_1(flist
, pfx
, 0);
114 for (fl
= flist
; fl
&& !seenint(); fl
= fl
->sibling
) {
115 pfx
= copy_strvec(ppfx
);
117 add_strvec(&pfx
, fl
->name
);
118 if (fl
->flags
& FL_OKLOW
) {
119 add_strvec(&pfx
, "[");
120 snprintf(buf
, sizeof(buf
), "%d", fl
->low
);
121 add_strvec(&pfx
, buf
);
122 if (fl
->low
!= fl
->high
) {
123 add_strvec(&pfx
, "-");
124 snprintf(buf
, sizeof(buf
), "%d", fl
->high
);
125 add_strvec(&pfx
, buf
);
127 add_strvec(&pfx
, "]");
131 add_strvec(&pfx
, ".");
132 print_flist_1(fl
->child
, pfx
, fl
->offset
);
135 fa
= &ftattrtab
[f
->ftyp
];
136 ASSERT(fa
->ftyp
== f
->ftyp
);
139 if (fl
->flags
& FL_OKLOW
)
143 count
= fcount(f
, iocur_top
->data
, parentoff
);
144 if (fl
->flags
& FL_OKHIGH
)
145 count
= min(count
, fl
->high
- low
+ 1);
150 /* Don't read an array off the end of the buffer */
151 fsz
= fsize(f
, iocur_top
->data
, parentoff
, 0);
152 bitlen
= iocur_top
->len
* NBBY
;
153 if ((f
->flags
& FLD_ARRAY
) &&
154 fl
->offset
+ (count
* fsz
) > bitlen
) {
155 count
= (bitlen
- fl
->offset
) / fsz
;
158 neednl
= fa
->prfunc(iocur_top
->data
, fl
->offset
,
159 count
, fa
->fmtstr
, fsz
, fa
->arg
, low
,
160 (f
->flags
& FLD_ARRAY
) != 0);
164 ASSERT(fa
->arg
& FTARG_OKEMPTY
);
165 dbprintf(_("(empty)\n"));
175 add_command(&print_cmd
);
195 ASSERT(bitoffs(bit
) == 0);
197 for (f
= flds
, first
= 1; f
->name
; f
++) {
198 if (f
->flags
& FLD_SKIPALL
)
200 dbprintf("%c%s", first
? '[' : ',', f
->name
);
205 for (i
= 0, bitoff
= bit
;
206 i
< count
&& !seenint();
207 i
++, bitoff
+= size
) {
209 dbprintf("\n%d:", i
+ base
);
210 for (f
= flds
, first
= 1; f
->name
; f
++) {
211 if (f
->flags
& FLD_SKIPALL
)
213 fa
= &ftattrtab
[f
->ftyp
];
214 ASSERT(fa
->ftyp
== f
->ftyp
);
215 dbprintf("%c", first
? '[' : ',');
220 bitoffset(f
, obj
, bitoff
, i
+ base
),
221 fcount(f
, obj
, bitoff
), fa
->fmtstr
,
222 fsize(f
, obj
, bitoff
, i
+ base
),
223 fa
->arg
, (f
->flags
& FLD_ABASE1
) != 0,
224 f
->flags
& FLD_ARRAY
);
226 ASSERT(fa
->arg
& FTARG_OKEMPTY
);
227 dbprintf(_("(empty)"));
238 const field_t
*fields
,
249 nfl
= flist_scan(*argv
);
263 if (fields
->name
[0] == '\0') {
264 fa
= &ftattrtab
[fields
->ftyp
];
265 ASSERT(fa
->ftyp
== fields
->ftyp
);
268 if (!flist_parse(fields
, fl
, iocur_top
->data
, 0)) {
280 const field_t
*fields
,
287 dbprintf(_("no arguments allowed\n"));
289 for (cp
= iocur_top
->data
;
290 cp
< (char *)iocur_top
->data
+ iocur_top
->len
&& *cp
&&
299 const field_t
*fields
,
304 print_allfields(fields
);
306 print_somefields(fields
, argc
, argv
);