summaryrefslogtreecommitdiffstats
path: root/usr.bin/file/print.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2004-05-19 02:32:35 +0000
committertedu <tedu@openbsd.org>2004-05-19 02:32:35 +0000
commit0d65fb4d9c70600549cebe929e13e33e76c07ca4 (patch)
treeaf478a5173805673ae044c0aa5b1a6f206805fa1 /usr.bin/file/print.c
parentAdd missing aic79xx_reg.h file. Update aic79xx* files to latest (diff)
downloadwireguard-openbsd-0d65fb4d9c70600549cebe929e13e33e76c07ca4.tar.xz
wireguard-openbsd-0d65fb4d9c70600549cebe929e13e33e76c07ca4.zip
big update to file 4.09. ok ian@
Diffstat (limited to 'usr.bin/file/print.c')
-rw-r--r--usr.bin/file/print.c207
1 files changed, 124 insertions, 83 deletions
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index f68bb1de31c..9b172d37a06 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -1,8 +1,5 @@
-/* $OpenBSD: print.c,v 1.10 2003/06/13 18:31:14 deraadt Exp $ */
-
+/* $OpenBSD: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $ */
/*
- * print.c - debugging printout routines
- *
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
@@ -29,118 +26,162 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+/*
+ * print.c - debugging printout routines
+ */
+#include "file.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <time.h>
-#include <err.h>
-#include "file.h"
#ifndef lint
-static char *moduleid = "$OpenBSD: print.c,v 1.10 2003/06/13 18:31:14 deraadt Exp $";
+FILE_RCSID("@(#)$Id: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
-void
-mdump(m)
-struct magic *m;
+#ifndef COMPILE_ONLY
+protected void
+file_mdump(struct magic *m)
{
- static char *typ[] = { "invalid", "byte", "short", "invalid",
- "long", "string", "date", "beshort",
- "belong", "bedate", "leshort", "lelong",
- "ledate" };
+ private const char *typ[] = { "invalid", "byte", "short", "invalid",
+ "long", "string", "date", "beshort",
+ "belong", "bedate", "leshort", "lelong",
+ "ledate", "pstring", "ldate", "beldate",
+ "leldate", "regex" };
+ private const char optyp[] = { '@', '&', '|', '^', '+', '-',
+ '*', '/', '%' };
(void) fputc('[', stderr);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
- if (m->flag & INDIR)
- (void) fprintf(stderr, "(%s,%d),",
- (m->in.type >= 0 && m->in.type < SZOF(typ)) ?
- typ[(unsigned char) m->in.type] :
- "*bad*",
- m->in.offset);
-
+ if (m->flag & INDIR) {
+ (void) fprintf(stderr, "(%s,",
+ /* Note: type is unsigned */
+ (m->in_type < SZOF(typ)) ?
+ typ[m->in_type] : "*bad*");
+ if (m->in_op & FILE_OPINVERSE)
+ (void) fputc('~', stderr);
+ (void) fprintf(stderr, "%c%d),",
+ ((m->in_op&0x7F) < SZOF(optyp)) ?
+ optyp[m->in_op&0x7F] : '?',
+ m->in_offset);
+ }
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
- (m->type >= 0 && m->type < SZOF(typ)) ?
- typ[(unsigned char) m->type] :
- "*bad*");
- if (m->mask != ~0)
- (void) fprintf(stderr, " & %.8x", m->mask);
+ /* Note: type is unsigned */
+ (m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
+ if (m->mask_op & FILE_OPINVERSE)
+ (void) fputc('~', stderr);
+ if (m->mask) {
+ if ((m->mask_op & 0x7F) < SZOF(optyp))
+ fputc(optyp[m->mask_op&0x7F], stderr);
+ else
+ fputc('?', stderr);
+ if(FILE_STRING != m->type || FILE_PSTRING != m->type)
+ (void) fprintf(stderr, "%.8x", m->mask);
+ else {
+ if (m->mask & STRING_IGNORE_LOWERCASE)
+ (void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
+ if (m->mask & STRING_COMPACT_BLANK)
+ (void) fputc(CHAR_COMPACT_BLANK, stderr);
+ if (m->mask & STRING_COMPACT_OPTIONAL_BLANK)
+ (void) fputc(CHAR_COMPACT_OPTIONAL_BLANK,
+ stderr);
+ }
+ }
(void) fprintf(stderr, ",%c", m->reln);
if (m->reln != 'x') {
- switch (m->type) {
- case BYTE:
- case SHORT:
- case LONG:
- case LESHORT:
- case LELONG:
- case BESHORT:
- case BELONG:
- (void) fprintf(stderr, "%d", m->value.l);
- break;
- case STRING:
- showstr(stderr, m->value.s, -1);
- break;
- case DATE:
- case LEDATE:
- case BEDATE:
- {
- char *rt, *pp = ctime((time_t*) &m->value.l);
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
- (void) fprintf(stderr, "%s,", pp);
- if (rt)
- *rt = '\n';
- }
- break;
- default:
- (void) fputs("*bad*", stderr);
- break;
- }
+ switch (m->type) {
+ case FILE_BYTE:
+ case FILE_SHORT:
+ case FILE_LONG:
+ case FILE_LESHORT:
+ case FILE_LELONG:
+ case FILE_BESHORT:
+ case FILE_BELONG:
+ (void) fprintf(stderr, "%d", m->value.l);
+ break;
+ case FILE_STRING:
+ case FILE_PSTRING:
+ case FILE_REGEX:
+ file_showstr(stderr, m->value.s, ~0U);
+ break;
+ case FILE_DATE:
+ case FILE_LEDATE:
+ case FILE_BEDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime(m->value.l, 1));
+ break;
+ case FILE_LDATE:
+ case FILE_LELDATE:
+ case FILE_BELDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime(m->value.l, 0));
+ break;
+ default:
+ (void) fputs("*bad*", stderr);
+ break;
+ }
}
(void) fprintf(stderr, ",\"%s\"]\n", m->desc);
}
+#endif
-/*
- * This "error" is here so we don't have to change all occurrences of
- * error() to err(1,...) when importing new versions from Christos.
- */
-void error(const char *fmt, ...)
+/*VARARGS*/
+protected void
+file_magwarn(const char *f, ...)
{
va_list va;
- va_start(va, fmt);
- verr(1, fmt, va);
-}
+ va_start(va, f);
-/*
- * ckfputs - futs, but with error checking
- * ckfprintf - fprintf, but with error checking
- */
-void
-ckfputs(str, fil)
- const char *str;
- FILE *fil;
-{
- if (fputs(str,fil) == EOF)
- err(1, "write failed");
+ /* cuz we use stdout for most, stderr here */
+ (void) fflush(stdout);
+
+ (void) fprintf(stderr, "WARNING: ");
+ (void) vfprintf(stderr, f, va);
+ va_end(va);
+ fputc('\n', stderr);
}
-/*VARARGS*/
-void
-ckfprintf(FILE *f, const char *fmt, ...)
+protected char *
+file_fmttime(uint32_t v, int local)
{
- va_list va;
+ char *pp, *rt;
+ time_t t = (time_t)v;
+ struct tm *tm;
- va_start(va, fmt);
- (void) vfprintf(f, fmt, va);
- if (ferror(f))
- err(1, "write failed");
- va_end(va);
+ if (local) {
+ pp = ctime(&t);
+ } else {
+#ifndef HAVE_DAYLIGHT
+ private int daylight = 0;
+#ifdef HAVE_TM_ISDST
+ private time_t now = (time_t)0;
+
+ if (now == (time_t)0) {
+ struct tm *tm1;
+ (void)time(&now);
+ tm1 = localtime(&now);
+ daylight = tm1->tm_isdst;
+ }
+#endif /* HAVE_TM_ISDST */
+#endif /* HAVE_DAYLIGHT */
+ if (daylight)
+ t += 3600;
+ tm = gmtime(&t);
+ pp = asctime(tm);
+ }
+
+ if ((rt = strchr(pp, '\n')) != NULL)
+ *rt = '\0';
+ return pp;
}