and though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here

...
 
Commits (3)
2021-02-05 16:31 Christos Zoulas <christos@zoulas.com>
* PR/234: Add limit to the number of bytes to scan for encoding
* PR/230: Fix /T (trim flag) for regex
2021-02-01 12:31 Christos Zoulas <christos@zoulas.com>
* PR/77: Trim trailing separator.
......
.\" $File: file.man,v 1.143 2021/02/05 21:33:49 christos Exp $
.\" $File: file.man,v 1.144 2021/02/05 22:08:31 christos Exp $
.Dd February 5, 2021
.Dt FILE __CSECTION__
.Os
......@@ -98,7 +98,7 @@ near the beginning of the file that tells the
operating system
that the file is a binary executable, and which of several types thereof.
The concept of a
.Dq magic
.Dq magic number
has been applied by extension to data files.
Any file with some invariant identifier at a small fixed
offset into the file can usually be described in this way.
......
#------------------------------------------------------------------------------
# $File: windows,v 1.35 2021/01/26 18:45:00 christos Exp $
# $File: windows,v 1.36 2021/02/05 22:29:07 christos Exp $
# windows: file(1) magic for Microsoft Windows
#
# This file is mainly reserved for files where programs
......@@ -597,7 +597,7 @@
>>>>>&0 ubyte x
# characters, digits, underscore and white space followed by right bracket
# terminated by CR implies section line to skip BOOTLOG.TXT DETLOG.TXT
>>>>>>&-1 regex \^([A-Za-z0-9_\(\)\ ]+)\]\r Generic INItialization configuration [%-.40s
>>>>>>&-1 regex/T \^([A-Za-z0-9_\(\)\ ]+)\]\r Generic INItialization configuration [%-.40s
# NETDEF.INF multiarc.ini
#!:mime application/x-setupscript
!:mime application/x-wine-extension-ini
......
#------------------------------------------------------------------------------
# $File: zip,v 1.5 2020/07/31 18:25:25 christos Exp $
# $File: zip,v 1.6 2021/02/05 22:55:36 christos Exp $
# zip: file(1) magic for zip files; this is not use
# Note the version of magic in archive is currently stronger, this is
# just an example until negative offsets are supported better
......@@ -7,6 +7,7 @@
# Zip Central Directory record
0 name zipcd
>0 string PK\001\002 Zip archive data
!:mime application/zip
>>4 leshort x \b, made by
>>4 use zipversion
>>4 use ziphost
......
......@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)$File: file.h,v 1.224 2021/02/05 21:33:49 christos Exp $
* @(#)$File: file.h,v 1.225 2021/02/05 22:29:07 christos Exp $
*/
#ifndef __file_h__
......@@ -552,6 +552,7 @@ protected int file_os2_apptype(struct magic_set *, const char *, const void *,
#endif /* __EMX__ */
protected int file_pipe_closexec(int *);
protected int file_clear_closexec(int);
protected char *file_strtrim(char *);
protected void buffer_init(struct buffer *, int, const struct stat *,
const void *, size_t);
......
......@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
FILE_RCSID("@(#)$File: funcs.c,v 1.120 2021/02/03 19:56:26 christos Exp $")
FILE_RCSID("@(#)$File: funcs.c,v 1.121 2021/02/05 22:29:07 christos Exp $")
#endif /* lint */
#include "magic.h"
......@@ -827,3 +827,20 @@ protected int
file_clear_closexec(int fd) {
return fcntl(fd, F_SETFD, 0);
}
protected char *
file_strtrim(char *str)
{
char *last;
while (isspace(CAST(unsigned char, *str)))
str++;
last = str;
while (*last)
last++;
--last;
while (isspace(CAST(unsigned char, *last)))
last--;
*++last = '\0';
return str;
}
......@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
FILE_RCSID("@(#)$File: softmagic.c,v 1.308 2020/12/16 23:41:38 christos Exp $")
FILE_RCSID("@(#)$File: softmagic.c,v 1.309 2021/02/05 22:29:07 christos Exp $")
#endif /* lint */
#include "magic.h"
......@@ -665,19 +665,9 @@ mprint(struct magic_set *ms, struct magic *m)
if (*m->value.s == '\0')
str[strcspn(str, "\r\n")] = '\0';
if (m->str_flags & STRING_TRIM) {
char *last;
while (isspace(CAST(unsigned char, *str)))
str++;
last = str;
while (*last)
last++;
--last;
while (isspace(CAST(unsigned char, *last)))
last--;
*++last = '\0';
}
if (m->str_flags & STRING_TRIM)
str = file_strtrim(str);
if (file_printf(ms, F(ms, desc, "%s"),
file_printable(sbuf, sizeof(sbuf), str,
sizeof(p->s) - (str - p->s))) == -1)
......@@ -782,7 +772,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_SEARCH:
case FILE_REGEX: {
char *cp;
char *cp, *scp;
int rval;
cp = strndup(RCAST(const char *, ms->search.s),
......@@ -791,8 +781,10 @@ mprint(struct magic_set *ms, struct magic *m)
file_oomem(ms, ms->search.rm_len);
return -1;
}
scp = (m->str_flags & STRING_TRIM) ? file_strtrim(cp) : cp;
rval = file_printf(ms, F(ms, desc, "%s"),
file_printable(sbuf, sizeof(sbuf), cp, ms->search.rm_len));
file_printable(sbuf, sizeof(sbuf), scp, ms->search.rm_len));
free(cp);
if (rval == -1)
......