]>
git.saurik.com Git - apple/file_cmds.git/blob - file/print.c
aff7a55bef858ede6de829faf115562c87f36568
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* $OpenBSD: print.c,v 1.3 1997/02/09 23:58:32 millert Exp $ */
27 * print.c - debugging printout routines
29 * Copyright (c) Ian F. Darwin, 1987.
30 * Written by Ian F. Darwin.
32 * This software is not subject to any license of the American Telephone
33 * and Telegraph Company or of the Regents of the University of California.
35 * Permission is granted to anyone to use this software for any purpose on
36 * any computer system, and to alter it and redistribute it freely, subject
37 * to the following restrictions:
39 * 1. The author is not responsible for the consequences of use of this
40 * software, no matter how awful, even if they arise from flaws in it.
42 * 2. The origin of this software must not be misrepresented, either by
43 * explicit claim or by omission. Since few users ever read sources,
44 * credits must appear in the documentation.
46 * 3. Altered versions must be plainly marked as such, and must not be
47 * misrepresented as being the original software. Since few users
48 * ever read sources, credits must appear in the documentation.
50 * 4. This notice may not be removed or altered.
68 static char *moduleid
= "$OpenBSD: print.c,v 1.3 1997/02/09 23:58:32 millert Exp $";
72 #define SZOF(a) (sizeof(a) / sizeof(a[0]))
78 static char *typ
[] = { "invalid", "byte", "short", "invalid",
79 "long", "string", "date", "beshort",
80 "belong", "bedate", "leshort", "lelong",
82 (void) fputc('[', stderr
);
83 (void) fprintf(stderr
, ">>>>>>>> %d" + 8 - (m
->cont_level
& 7),
87 (void) fprintf(stderr
, "(%s,%d),",
88 (m
->in
.type
>= 0 && m
->in
.type
< SZOF(typ
)) ?
89 typ
[(unsigned char) m
->in
.type
] :
93 (void) fprintf(stderr
, " %s%s", (m
->flag
& UNSIGNED
) ? "u" : "",
94 (m
->type
>= 0 && m
->type
< SZOF(typ
)) ?
95 typ
[(unsigned char) m
->type
] :
98 (void) fprintf(stderr
, " & %.8x", m
->mask
);
100 (void) fprintf(stderr
, ",%c", m
->reln
);
102 if (m
->reln
!= 'x') {
111 (void) fprintf(stderr
, "%d", m
->value
.l
);
114 showstr(stderr
, m
->value
.s
, -1);
120 char *rt
, *pp
= ctime((time_t*) &m
->value
.l
);
121 if ((rt
= strchr(pp
, '\n')) != NULL
)
123 (void) fprintf(stderr
, "%s,", pp
);
129 (void) fputs("*bad*", stderr
);
133 (void) fprintf(stderr
, ",\"%s\"]\n", m
->desc
);
137 * ckfputs - futs, but with error checking
138 * ckfprintf - fprintf, but with error checking
145 if (fputs(str
,fil
) == EOF
)
146 error("write failed.\n");
152 ckfprintf(FILE *f
, const char *fmt
, ...)
165 f
= va_arg(va
, FILE *);
166 fmt
= va_arg(va
, const char *);
168 (void) vfprintf(f
, fmt
, va
);
170 error("write failed.\n");
175 * error - print best error message possible and exit
180 error(const char *f
, ...)
192 f
= va_arg(va
, const char *);
194 /* cuz we use stdout for most, stderr here */
195 (void) fflush(stdout
);
197 if (progname
!= NULL
)
198 (void) fprintf(stderr
, "%s: ", progname
);
199 (void) vfprintf(stderr
, f
, va
);
207 magwarn(const char *f
, ...)
219 f
= va_arg(va
, const char *);
221 /* cuz we use stdout for most, stderr here */
222 (void) fflush(stdout
);
224 if (progname
!= NULL
)
225 (void) fprintf(stderr
, "%s: %s, %d: ",
226 progname
, magicfile
, lineno
);
227 (void) vfprintf(stderr
, f
, va
);