From 229d2d3ad7cc60b893e272efc9efae37be2ec610 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 9 Feb 2005 19:25:13 +0000 Subject: [PATCH] Welcome to 4.13 --- src/ascmagic.c | 46 ++++++++++++++++++++++++++++------------------ src/patchlevel.h | 7 +++++-- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/ascmagic.c b/src/ascmagic.c index dc3ebd38..663222d9 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -49,7 +49,7 @@ #include "names.h" #ifndef lint -FILE_RCSID("@(#)$Id: ascmagic.c,v 1.41 2004/09/11 19:15:57 christos Exp $") +FILE_RCSID("@(#)$Id: ascmagic.c,v 1.42 2005/02/09 19:25:13 christos Exp $") #endif /* lint */ typedef unsigned long unichar; @@ -84,6 +84,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes) int has_escapes = 0; int has_backspace = 0; + int seen_cr = 0; int n_crlf = 0; int n_lf = 0; @@ -224,32 +225,41 @@ subtype_identified: * Now try to discover other details about the file. */ for (i = 0; i < ulen; i++) { - if (i > last_line_end + MAXLINELEN) - has_long_lines = 1; - - if (ubuf[i] == '\033') - has_escapes = 1; - if (ubuf[i] == '\b') - has_backspace = 1; - - if (ubuf[i] == '\r' && (i + 1 < ulen && ubuf[i + 1] == '\n')) { - n_crlf++; + if (ubuf[i] == '\n') { + if (seen_cr) + n_crlf++; + else + n_lf++; last_line_end = i; - } - if (ubuf[i] == '\r' && (i + 1 >= ulen || ubuf[i + 1] != '\n')) { + } else if (seen_cr) n_cr++; + + seen_cr = (ubuf[i] == '\r'); + if (seen_cr) last_line_end = i; - } - if (ubuf[i] == '\n' && ((int)i - 1 < 0 || ubuf[i - 1] != '\r')){ - n_lf++; - last_line_end = i; - } + if (ubuf[i] == 0x85) { /* X3.64/ECMA-43 "next line" character */ n_nel++; last_line_end = i; } + + /* If this line is _longer_ than MAXLINELEN, remember it. */ + if (i > last_line_end + MAXLINELEN) + has_long_lines = 1; + + if (ubuf[i] == '\033') + has_escapes = 1; + if (ubuf[i] == '\b') + has_backspace = 1; } + /* Beware, if the data has been truncated, the final CR could have + been followed by a LF. If we have HOWMANY bytes, it indicates + that the data might have been truncated, probably even before + this function was called. */ + if (seen_cr && nbytes < HOWMANY) + n_cr++; + if ((ms->flags & MAGIC_MIME)) { if (subtype_mime) { if (file_printf(ms, subtype_mime) == -1) diff --git a/src/patchlevel.h b/src/patchlevel.h index 1f74d480..22129f8f 100644 --- a/src/patchlevel.h +++ b/src/patchlevel.h @@ -1,11 +1,14 @@ #define FILE_VERSION_MAJOR 4 -#define patchlevel 12 +#define patchlevel 13 /* * Patchlevel file for Ian Darwin's MAGIC command. - * $Id: patchlevel.h,v 1.55 2004/11/24 18:57:47 christos Exp $ + * $Id: patchlevel.h,v 1.56 2005/02/09 19:25:13 christos Exp $ * * $Log: patchlevel.h,v $ + * Revision 1.56 2005/02/09 19:25:13 christos + * Welcome to 4.13 + * * Revision 1.55 2004/11/24 18:57:47 christos * Re-do the autoconf stuff once more; passes make dist now. * -- 2.40.0