=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/Attic/print.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/file/Attic/print.c 2003/06/13 18:31:14 1.10 --- src/usr.bin/file/Attic/print.c 2004/05/19 02:32:35 1.11 *************** *** 1,8 **** ! /* $OpenBSD: print.c,v 1.10 2003/06/13 18:31:14 deraadt 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. --- 1,5 ---- ! /* $OpenBSD: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; * maintained 1995-present by Christos Zoulas and others. *************** *** 29,146 **** * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include - #include - #include "file.h" #ifndef lint ! static char *moduleid = "$OpenBSD: print.c,v 1.10 2003/06/13 18:31:14 deraadt Exp $"; #endif /* lint */ #define SZOF(a) (sizeof(a) / sizeof(a[0])) ! void ! mdump(m) ! struct magic *m; { ! static char *typ[] = { "invalid", "byte", "short", "invalid", ! "long", "string", "date", "beshort", ! "belong", "bedate", "leshort", "lelong", ! "ledate" }; (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); ! (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); (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; ! } } (void) fprintf(stderr, ",\"%s\"]\n", m->desc); } ! /* ! * 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, ...) { va_list va; ! va_start(va, fmt); ! verr(1, fmt, va); ! } ! /* ! * 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"); } ! /*VARARGS*/ ! void ! ckfprintf(FILE *f, const char *fmt, ...) { ! va_list va; ! va_start(va, fmt); ! (void) vfprintf(f, fmt, va); ! if (ferror(f)) ! err(1, "write failed"); ! va_end(va); } --- 26,187 ---- * 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 #include #include #include #include + #ifdef HAVE_UNISTD_H #include + #endif #include #ifndef lint ! 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])) ! #ifndef COMPILE_ONLY ! protected void ! file_mdump(struct magic *m) { ! 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,", ! /* 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" : "", ! /* 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 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 ! /*VARARGS*/ ! protected void ! file_magwarn(const char *f, ...) { va_list va; ! va_start(va, f); ! /* 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); } ! protected char * ! file_fmttime(uint32_t v, int local) { ! char *pp, *rt; ! time_t t = (time_t)v; ! struct tm *tm; ! 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; }