Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * print.c - debugging printout routines | |
3 | * | |
4 | * Copyright (c) Ian F. Darwin, 1987. | |
5 | * Written by Ian F. Darwin. | |
6 | * | |
7 | * This software is not subject to any license of the American Telephone | |
8 | * and Telegraph Company or of the Regents of the University of California. | |
9 | * | |
10 | * Permission is granted to anyone to use this software for any purpose on | |
11 | * any computer system, and to alter it and redistribute it freely, subject | |
12 | * to the following restrictions: | |
13 | * | |
14 | * 1. The author is not responsible for the consequences of use of this | |
15 | * software, no matter how awful, even if they arise from flaws in it. | |
16 | * | |
17 | * 2. The origin of this software must not be misrepresented, either by | |
18 | * explicit claim or by omission. Since few users ever read sources, | |
19 | * credits must appear in the documentation. | |
20 | * | |
21 | * 3. Altered versions must be plainly marked as such, and must not be | |
22 | * misrepresented as being the original software. Since few users | |
23 | * ever read sources, credits must appear in the documentation. | |
24 | * | |
25 | * 4. This notice may not be removed or altered. | |
26 | */ | |
27 | ||
28 | #include <stdio.h> | |
29 | #include <errno.h> | |
30 | #include "file.h" | |
31 | ||
32 | #ifndef lint | |
33 | static char *moduleid = | |
34 | "@(#)$Header: print.c,v 1.11 88/01/15 12:17:06 ian Exp $"; | |
35 | #endif /* lint */ | |
36 | ||
37 | #define MAXSTR 500 | |
38 | ||
39 | extern char *progname; | |
40 | extern char *magicfile; | |
41 | extern int debug, nmagic; /* number of valid magic[]s */ | |
42 | extern void showstr(); | |
43 | ||
44 | mdump(m) | |
45 | struct magic *m; | |
46 | { | |
47 | (void) printf("%d\t%d\t%d\t%c\t", | |
48 | m->contflag, | |
49 | m->offset, | |
50 | m->type, | |
51 | m->reln, | |
52 | 0); | |
53 | if (m->type == STRING) | |
54 | showstr(m->value.s); | |
55 | else | |
56 | (void) printf("%d",m->value.l); | |
57 | (void) printf("\t%s", m->desc); | |
58 | (void) putchar('\n'); | |
59 | } | |
60 | ||
61 | /* | |
62 | * error - print best error message possible and exit | |
63 | */ | |
64 | /*ARGSUSED1*/ | |
65 | /*VARARGS*/ | |
66 | void | |
67 | error(s1, s2) | |
68 | char *s1, *s2; | |
69 | { | |
70 | warning(s1, s2); | |
71 | exit(1); | |
72 | } | |
73 | ||
74 | /*ARGSUSED1*/ | |
75 | /*VARARGS*/ | |
76 | warning(f, a) | |
77 | char *f, *a; | |
78 | { | |
79 | extern int errno, sys_nerr; | |
80 | extern char *sys_errlist[]; | |
81 | int myerrno; | |
82 | ||
83 | myerrno = errno; | |
84 | ||
85 | /* cuz we use stdout for most, stderr here */ | |
86 | (void) fflush(stdout); | |
87 | ||
88 | if (progname != NULL) { | |
89 | (void) fputs(progname, stderr); | |
90 | (void) putc(':', stderr); | |
91 | (void) putc(' ', stderr); | |
92 | } | |
93 | (void) fprintf(stderr, f, a); | |
94 | if (myerrno > 0 && myerrno < sys_nerr) | |
95 | (void) fprintf(stderr, " (%s)", sys_errlist[myerrno]); | |
96 | putc('\n', stderr); | |
97 | } |