+2008-10-18 16:45 Christos Zoulas <christos@astron.com>
+
+ * Added APPLE file creator/type
+
2008-10-12 10:20 Christos Zoulas <christos@astron.com>
* Added CDF parsing
-.\" $File: file.man,v 1.74 2008/10/09 17:19:11 christos Exp $
+.\" $File: file.man,v 1.75 2008/10/09 17:25:01 christos Exp $
.Dd October 9, 2008
.Dt FILE __CSECTION__
.Os
application type (only on EMX).
.It ascii
Check for various types of ascii files.
+.It cdf
+Don't look for Compound Document Files.
.It compress
Don't look for, or inside compressed files.
.It elf
-.\" $File: magic.man,v 1.56 2008/03/01 22:21:48 rrt Exp $
+.\" $File: magic.man,v 1.57 2008/08/30 09:50:20 christos Exp $
.Dd August 30, 2008
.Dt MAGIC __FSECTION__
.Os
space.
.El
.Pp
+An APPLE 4+4 character APPLE creator and type can be specified as:
+.Bd -literal -offset indent
+!:apple CREATYPE
+.Ed
+.Pp
A MIME type is given on a separate line, which must be the next
non-blank or comment line after the magic line that identifies the
file type, and has the following format:
# standard unix compress
0 string \037\235 compress'd data
!:mime application/x-compress
+!:apple LZIVZIVU
>2 byte&0x80 >0 block compressed
>2 byte&0x1f x %d bits
# GIF
0 string GIF8 GIF image data
!:mime image/gif
+!:apple 8BIMGIFf
>4 string 7a \b, version 8%s,
>4 string 9a \b, version 8%s,
>6 leshort >0 %hd x
#
0 beshort 0xffd8 JPEG image data
!:mime image/jpeg
+!:apple 8BIMJPEG
!:strength +1
>6 string JFIF \b, JFIF standard
# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
# Stuffit archives are the de facto standard of compression for Macintosh
# files obtained from most archives. (franklsm@tuns.ca)
0 string SIT! StuffIt Archive (data)
+!:mime application/x-stuffit
+!:apple SIT!SIT!
>2 string x : %s
0 string SITD StuffIt Deluxe (data)
>2 string x : %s
# Newer StuffIt archives (grant@netbsd.org)
0 string StuffIt StuffIt Archive
!:mime application/x-stuffit
+!:apple SIT!SIT!
#>162 string >0 : %s
# Macintosh Applications and Installation binaries (franklsm@tuns.ca)
# PostScript, updated by Daniel Quinlan (quinlan@yggdrasil.com)
0 string %! PostScript document text
!:mime application/postscript
+!:apple ASPSTEXT
>2 string PS-Adobe- conforming
>>11 string >\0 DSC level %.3s
>>>15 string EPS \b, type %s
# Some PCs have the annoying habit of adding a ^D as a document separator
0 string \004%! PostScript document text
!:mime application/postscript
+!:apple ASPSTEXT
>3 string PS-Adobe- conforming
>>12 string >\0 DSC level %.3s
>>>16 string EPS \b, type %s
#include <dirent.h>
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.140 2008/07/20 04:02:15 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.141 2008/08/31 07:58:00 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
private int check_format(struct magic_set *, struct magic *);
private int get_op(char);
private int parse_mime(struct magic_set *, struct magic_entry *, const char *);
-private int parse_strength(struct magic_set *, struct magic_entry *,
- const char *);
+private int parse_strength(struct magic_set *, struct magic_entry *, const char *);
+private int parse_apple(struct magic_set *, struct magic_entry *, const char *);
private size_t maxmagic = 0;
} bang[] = {
#define DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
DECLARE_FIELD(mime),
+ DECLARE_FIELD(apple),
DECLARE_FIELD(strength),
#undef DECLARE_FIELD
{ NULL, 0, NULL }
return -1;
}
+/*
+ * Parse an Apple CREATOR/TYPE annotation from magic file and put it into magic[index - 1]
+ */
+private int
+parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
+{
+ size_t i;
+ const char *l = line;
+ struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
+
+ if (m->apple[0] != '\0') {
+ file_magwarn(ms, "Current entry already has a APPLE type `%.8s',"
+ " new type `%s'", m->mimetype, l);
+ return -1;
+ }
+
+ EATAB;
+ for (i = 0; *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
+ || strchr("-+/.", *l)) && i < sizeof(m->apple); m->apple[i++] = *l++)
+ continue;
+ if (i == sizeof(m->apple) && *l) {
+ if (ms->flags & MAGIC_CHECK)
+ file_magwarn(ms, "APPLE type `%s' truncated %zu",
+ line, i);
+ }
+
+ if (i > 0)
+ return 0;
+ else
+ return -1;
+}
+
/*
* parse a MIME annotation line from magic file, put into magic[index - 1]
* if valid
}
EATAB;
- for (i = 0;
- *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
- || strchr("-+/.", *l)) && i < sizeof(m->mimetype);
- m->mimetype[i++] = *l++)
+ for (i = 0; *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
+ || strchr("-+/.", *l)) && i < sizeof(m->mimetype); m->mimetype[i++] = *l++)
continue;
if (i == sizeof(m->mimetype)) {
m->desc[sizeof(m->mimetype) - 1] = '\0';
#include "names.h"
#ifndef lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.65 2008/08/31 07:58:00 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.66 2008/10/16 16:31:16 christos Exp $")
#endif /* lint */
#define MAXLINELEN 300 /* longest sane line length */
size_t last_line_end = (size_t)-1;
int has_long_lines = 0;
+ if (ms->flags & MAGIC_APPLE)
+ return 0;
+
/*
* Undo the NUL-termination kindly provided by process()
* but leave at least one byte to look at
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.124 2008/10/09 17:24:03 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.125 2008/10/12 15:38:51 christos Exp $")
#endif /* lint */
help();
break;
case 10:
- flags |= MAGIC_MIME_TYPE;
+ flags |= MAGIC_APPLE;
break;
case 11:
+ flags |= MAGIC_MIME_TYPE;
+ break;
+ case 12:
flags |= MAGIC_MIME_ENCODING;
break;
}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.109 2008/09/02 07:11:30 christos Exp $
+ * @(#)$File: file.h,v 1.110 2008/10/12 15:38:52 christos Exp $
*/
#ifndef __file_h__
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 6
-#define FILE_MAGICSIZE (32 * 6)
+#define VERSIONNO 7
+#define FILE_MAGICSIZE 200
#define FILE_LOAD 0
#define FILE_CHECK 1
#define str_flags _u._s._flags
/* Words 9-16 */
union VALUETYPE value; /* either number or string */
- /* Words 17..31 */
+ /* Words 17-25 */
char desc[MAXDESC]; /* description */
- /* Words 32..47 */
+ /* Words 26-34 */
char mimetype[MAXDESC]; /* MIME type */
+ /* Words 35-43 */
+ char apple[8];
};
#define BIT(A) (1 << (A))
OPT('F', "separator", 1, " STRING use string as separator instead of `:'\n")
OPT('i', "mime", 0, " output MIME type strings (--mime-type and\n"
" --mime-encoding)\n")
+OPT_LONGONLY("apple", 0, " output the APPLE CREATOR/TYPE\n")
OPT_LONGONLY("mime-type", 0, " output the MIME type\n")
OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n")
OPT('k', "keep-going", 0, " don't stop at the first match\n")
#undef HAVE_MAJOR
#ifndef lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.52 2008/07/25 23:59:01 rrt Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.53 2008/10/16 16:31:16 christos Exp $")
#endif /* lint */
private int
struct stat tstatbuf;
#endif
+ if (ms->flags & MAGIC_APPLE)
+ return 0;
if (fn == NULL)
return 0;
#include "tar.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.30 2008/01/26 18:45:16 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.31 2008/02/04 20:51:17 christos Exp $")
#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
* Do the tar test first, because if the first file in the tar
* archive starts with a dot, we can confuse it with an nroff file.
*/
- int tar = is_tar(buf, nbytes);
+ int tar;
int mime = ms->flags & MAGIC_MIME;
- if (tar < 1 || tar > 3)
+ if ((ms->flags & MAGIC_APPLE) != 0 || mime == MAGIC_MIME_ENCODING)
return 0;
- if (mime == MAGIC_MIME_ENCODING)
+ tar = is_tar(buf, nbytes);
+ if (tar < 1 || tar > 3)
return 0;
if (file_printf(ms, mime ? "application/x-tar" :
#define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */
#define MAGIC_MIME_ENCODING 0x000400 /* Return only the MIME encoding */
#define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
+#define MAGIC_APPLE 0x000800 /* Return APPLE CREATOR/TYPE */
#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.5 2008/10/13 18:23:47 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.6 2008/10/14 10:38:22 christos Exp $")
#endif
#include <stdio.h>
(void)&nbytes;
(void)&buf;
+ if (ms->flags & MAGIC_APPLE)
+ return 0;
if (cdf_read_header(fd, &h) == -1)
return 0;
#ifdef CDF_DEBUG
#include "magic.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.78 2008/08/31 07:58:00 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.79 2008/10/12 19:06:36 christos Exp $")
#endif
#ifdef ELFCORE
Elf64_Ehdr elf64hdr;
uint16_t type;
- if (ms->flags & MAGIC_MIME)
+ if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))
return 0;
/*
* ELF executables have multiple section headers in arbitrary
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.122 2008/09/23 14:34:25 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.123 2008/10/16 16:31:16 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, uint32_t, size_t, size_t);
private int mconvert(struct magic_set *, struct magic *);
private int print_sep(struct magic_set *, int);
-private int handle_mime(struct magic_set *, struct magic *);
+private int handle_annotation(struct magic_set *, struct magic *);
private void cvt_8(union VALUETYPE *, const struct magic *);
private void cvt_16(union VALUETYPE *, const struct magic *);
private void cvt_32(union VALUETYPE *, const struct magic *);
if (*m->desc) {
need_separator = 1;
printed_something = 1;
- if ((e = handle_mime(ms, m)) != 0)
+ if ((e = handle_annotation(ms, m)) != 0)
return e;
if (print_sep(ms, firstline) == -1)
return -1;
*/
if (*m->desc) {
printed_something = 1;
- if ((e = handle_mime(ms, m)) != 0)
+ if ((e = handle_annotation(ms, m)) != 0)
return e;
if (print_sep(ms, firstline) == -1)
return -1;
default:
matched = 0;
- file_magerror(ms, "cannot happen with float: invalid relation `%c'", m->reln);
+ file_magerror(ms, "cannot happen with float: invalid relation `%c'",
+ m->reln);
return -1;
}
return matched;
}
private int
-handle_mime(struct magic_set *ms, struct magic *m)
+handle_annotation(struct magic_set *ms, struct magic *m)
{
- if (ms->flags & MAGIC_MIME_TYPE)
- return file_printf(ms, "%s", m->mimetype);
+ if (ms->flags & MAGIC_APPLE) {
+ if (file_printf(ms, "%.8s", m->apple) == -1)
+ return -1;
+ return 1;
+ }
+ if (ms->flags & MAGIC_MIME_TYPE) {
+ if (file_printf(ms, "%.8s", m->mimetype) == -1)
+ return 1;
+ }
return 0;
}