#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;
int has_escapes = 0;
int has_backspace = 0;
+ int seen_cr = 0;
int n_crlf = 0;
int n_lf = 0;
* 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)
#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.
*