-.\" $File: magic.man,v 1.73 2012/08/26 10:08:29 christos Exp $
-.Dd April 3, 2012
+.\" $File: magic.man,v 1.74 2012/09/06 14:42:39 christos Exp $
+.Dd September 6, 2012
.Dt MAGIC __FSECTION__
.Os
.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
.It Dv string
A string of bytes.
The string type specification can be optionally followed
-by /[WwcCtb]*.
+by /[WwcCtbT]*.
The
.Dq W
flag compacts whitespace in the target, which must
flag forces the test to be done for text files, while the
.Dq b
flag forces the test to be done for binary files.
+The
+.Dq T
+flag causes the string to be trimmed, i.e. leading and trailing whitespace
+is deleted before the string is printed.
.It Dv pstring
A Pascal-style string where the first byte/short/int is interpreted as the
unsigned length.
#------------------------------------------------------------------------------
-# $File: filesystems,v 1.61 2011/01/10 14:01:10 christos Exp $
+# $File: filesystems,v 1.62 2012/09/06 14:42:39 christos Exp $
# filesystems: file(1) magic for different filesystems
#
0 string \366\366\366\366 PC formatted floppy with no filesystem
>>38917 byte >0x33 (unknown version, ID 0x%X)
>>38917 byte <0x31 (unknown version, ID 0x%X)
# "application id" which appears to be used as a volume label
->32808 string >\0 '%s'
+>32808 string/T >\0 '%s'
>34816 string \000CD001\001EL\ TORITO\ SPECIFICATION (bootable)
37633 string CD001 ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)
!:mime application/x-iso9660-image
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.175 2012/04/06 21:14:01 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.176 2012/09/06 14:42:39 christos Exp $")
#endif /* lint */
#include "magic.h"
case CHAR_TEXTTEST:
m->str_flags |= STRING_TEXTTEST;
break;
+ case CHAR_TRIM:
+ m->str_flags |= STRING_TRIM;
+ break;
case CHAR_PSTRING_1_LE:
if (m->type != FILE_PSTRING)
goto bad;
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.138 2012/06/20 22:33:43 christos Exp $
+ * @(#)$File: file.h,v 1.139 2012/09/06 14:42:39 christos Exp $
*/
#ifndef __file_h__
#define PSTRING_LEN \
(PSTRING_1_BE|PSTRING_2_LE|PSTRING_2_BE|PSTRING_4_LE|PSTRING_4_BE)
#define PSTRING_LENGTH_INCLUDES_ITSELF BIT(12)
+#define STRING_TRIM BIT(13)
#define CHAR_COMPACT_WHITESPACE 'W'
#define CHAR_COMPACT_OPTIONAL_WHITESPACE 'w'
#define CHAR_IGNORE_LOWERCASE 'c'
#define CHAR_IGNORE_UPPERCASE 'C'
#define CHAR_REGEX_OFFSET_START 's'
#define CHAR_TEXTTEST 't'
+#define CHAR_TRIM 'T'
#define CHAR_BINTEST 'b'
#define CHAR_PSTRING_1_BE 'B'
#define CHAR_PSTRING_1_LE 'B'
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.150 2012/05/15 17:14:36 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.151 2012/09/06 14:42:39 christos Exp $")
#endif /* lint */
#include "magic.h"
t = ms->offset + m->vallen;
}
else {
+ char *str = p->s;
+
+ /* compute t before we mangle the string? */
+ t = ms->offset + strlen(str);
+
if (*m->value.s == '\0')
- p->s[strcspn(p->s, "\n")] = '\0';
- if (file_printf(ms, m->desc, p->s) == -1)
+ str[strcspn(str, "\n")] = '\0';
+
+ if (m->str_flags & STRING_TRIM) {
+ char *last;
+ while (isspace((unsigned char)*str))
+ str++;
+ last = str;
+ while (*last)
+ last++;
+ --last;
+ while (isspace((unsigned char)*last))
+ last--;
+ *++last = '\0';
+ }
+
+ if (file_printf(ms, m->desc, str) == -1)
return -1;
- t = ms->offset + strlen(p->s);
+
if (m->type == FILE_PSTRING)
t += file_pstring_length_size(m);
}