diff options
Diffstat (limited to 'src/plugins/xm_extractor.c')
-rw-r--r-- | src/plugins/xm_extractor.c | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/src/plugins/xm_extractor.c b/src/plugins/xm_extractor.c index d8e0829..7ac94f4 100644 --- a/src/plugins/xm_extractor.c +++ b/src/plugins/xm_extractor.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * libextractor is free software; you can redistribute it and/or modify | 5 | * libextractor is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published | 6 | * it under the terms of the GNU General Public License as published |
7 | * by the Free Software Foundation; either version 2, or (at your | 7 | * by the Free Software Foundation; either version 3, or (at your |
8 | * option) any later version. | 8 | * option) any later version. |
9 | * | 9 | * |
10 | * libextractor is distributed in the hope that it will be useful, but | 10 | * libextractor is distributed in the hope that it will be useful, but |
@@ -18,13 +18,19 @@ | |||
18 | * Boston, MA 02111-1307, USA. | 18 | * Boston, MA 02111-1307, USA. |
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | /** | |
22 | * @file plugins/xm_extractor.c | ||
23 | * @brief plugin to support XM files | ||
24 | * @author Toni Ruottu | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
22 | #include "platform.h" | 27 | #include "platform.h" |
23 | #include "extractor.h" | 28 | #include "extractor.h" |
24 | #include "convert.h" | ||
25 | 29 | ||
26 | #define HEADER_SIZE 64 | ||
27 | 30 | ||
31 | /** | ||
32 | * Header of an XM file. | ||
33 | */ | ||
28 | struct header | 34 | struct header |
29 | { | 35 | { |
30 | char magicid[17]; | 36 | char magicid[17]; |
@@ -34,40 +40,48 @@ struct header | |||
34 | char version[2]; | 40 | char version[2]; |
35 | }; | 41 | }; |
36 | 42 | ||
37 | #define ADD(s,t) do { if (0 != proc (proc_cls, "xm", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | ||
38 | 43 | ||
44 | /** | ||
45 | * Give meta data to LE. | ||
46 | * | ||
47 | * @param s utf-8 string meta data value | ||
48 | * @param t type of the meta data | ||
49 | */ | ||
50 | #define ADD(s,t) do { if (0 != ec->proc (ec->cls, "xm", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) | ||
39 | 51 | ||
40 | /* "extract" keyword from an Extended Module | 52 | |
53 | /** | ||
54 | * "extract" metadata from an Extended Module | ||
41 | * | 55 | * |
42 | * The XM module format description for XM files | 56 | * The XM module format description for XM files |
43 | * version $0104 that was written by Mr.H of Triton | 57 | * version $0104 that was written by Mr.H of Triton |
44 | * in 1994 was used, while this piece of software | 58 | * in 1994 was used, while this piece of software |
45 | * was originally written. | 59 | * was originally written. |
46 | * | 60 | * |
61 | * @param ec extraction context | ||
47 | */ | 62 | */ |
48 | int | 63 | void |
49 | EXTRACTOR_xm_extract (const unsigned char *data, | 64 | EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec) |
50 | size_t size, | ||
51 | EXTRACTOR_MetaDataProcessor proc, | ||
52 | void *proc_cls, | ||
53 | const char *options) | ||
54 | { | 65 | { |
66 | void *data; | ||
67 | const struct header *head; | ||
55 | char title[21]; | 68 | char title[21]; |
56 | char tracker[21]; | 69 | char tracker[21]; |
57 | char xmversion[8]; | 70 | char xmversion[8]; |
58 | const struct header *head; | ||
59 | 71 | ||
60 | /* Check header size */ | 72 | if (sizeof (struct header) > |
61 | if (size < HEADER_SIZE) | 73 | ec->read (ec->cls, |
62 | return 0; | 74 | &data, |
63 | head = (const struct header *) data; | 75 | sizeof (struct header))) |
76 | return; | ||
77 | head = data; | ||
64 | /* Check "magic" id bytes */ | 78 | /* Check "magic" id bytes */ |
65 | if (memcmp (head->magicid, "Extended Module: ", 17)) | 79 | if (memcmp (head->magicid, "Extended Module: ", 17)) |
66 | return 0; | 80 | return; |
67 | ADD("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE); | 81 | ADD("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE); |
68 | /* Version of Tracker */ | 82 | /* Version of Tracker */ |
69 | snprintf (xmversion, | 83 | snprintf (xmversion, |
70 | sizeof(xmversion), | 84 | sizeof (xmversion), |
71 | "%d.%d", | 85 | "%d.%d", |
72 | head->version[1], | 86 | head->version[1], |
73 | head->version[0]); | 87 | head->version[0]); |
@@ -80,5 +94,7 @@ EXTRACTOR_xm_extract (const unsigned char *data, | |||
80 | memcpy (&tracker, head->tracker, 20); | 94 | memcpy (&tracker, head->tracker, 20); |
81 | tracker[20] = '\0'; | 95 | tracker[20] = '\0'; |
82 | ADD (tracker, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); | 96 | ADD (tracker, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); |
83 | return 0; | 97 | return; |
84 | } | 98 | } |
99 | |||
100 | /* end of xm_extractor.c */ | ||