diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-04-13 07:26:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-04-13 07:26:16 +0000 |
commit | 804080ef9e088be8ce3d4a9e5e5cdd2636b17fcd (patch) | |
tree | 008cf03f0b3a06a30f20198ec810f536b9f147fb /src/plugins/s3m_extractor.c | |
parent | e19e624671c12726b511e092ea01f977722624d7 (diff) | |
download | libextractor-804080ef9e088be8ce3d4a9e5e5cdd2636b17fcd.tar.gz libextractor-804080ef9e088be8ce3d4a9e5e5cdd2636b17fcd.zip |
-LRN: misc patches:
/home/grothoff/0001-Rewrite-the-template-more-like-documentation-now.patch /home/grothoff/0003-Minimally-ported-s3m-extractor.patch
/home/grothoff/0002-New-header-for-arch-definitions.patch /home/grothoff/0004-Fixed-template-doc-added-architecture-header.patch
Diffstat (limited to 'src/plugins/s3m_extractor.c')
-rw-r--r-- | src/plugins/s3m_extractor.c | 132 |
1 files changed, 79 insertions, 53 deletions
diff --git a/src/plugins/s3m_extractor.c b/src/plugins/s3m_extractor.c index 7e8ae40..9146042 100644 --- a/src/plugins/s3m_extractor.c +++ b/src/plugins/s3m_extractor.c | |||
@@ -1,68 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | * (C) 2008 Toni Ruottu | 3 | (C) 2002, 2003, 2004, 2009 Vidyut Samanta and Christian Grothoff |
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 2, 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 |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * General Public License for more details. | 13 | General Public License for more details. |
14 | * | 14 | |
15 | * You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | * along with libextractor; see the file COPYING. If not, write to the | 16 | along with libextractor; see the file COPYING. If not, write to the |
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | * Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | * | ||
20 | */ | 19 | */ |
21 | 20 | ||
22 | #include "platform.h" | 21 | #include "platform.h" |
23 | #include "extractor.h" | 22 | #include "extractor.h" |
24 | #include "convert.h" | ||
25 | 23 | ||
26 | #define HEADER_SIZE 0x70 | 24 | #include "extractor_plugins.h" |
25 | #include "le_architecture.h" | ||
26 | |||
27 | /* Based upon ST 3.20 spec at http://16-bits.org/s3m/ */ | ||
28 | /* Looks like the format was defined by the software implementation, | ||
29 | * and that implementation was for little-endian platform, which means | ||
30 | * that the format is little-endian. | ||
31 | */ | ||
27 | 32 | ||
28 | struct header | 33 | LE_NETWORK_STRUCT_BEGIN |
34 | struct S3MHeader | ||
29 | { | 35 | { |
30 | char title[28]; | 36 | char song_name[28]; |
31 | char something[16]; | 37 | uint8_t byte_1A; |
32 | char magicid[4]; | 38 | uint8_t file_type; /* 0x10 == ST3 module */ |
39 | uint8_t unknown1[2]; | ||
40 | uint16_t number_of_orders; /* should be even */ | ||
41 | uint16_t number_of_instruments; | ||
42 | uint16_t number_of_patterns; | ||
43 | uint16_t flags; | ||
44 | uint16_t created_with_version; | ||
45 | uint16_t file_format_info; | ||
46 | char SCRM[4]; | ||
47 | uint8_t global_volume; | ||
48 | uint8_t initial_speed; | ||
49 | uint8_t initial_tempo; | ||
50 | uint8_t master_volume; | ||
51 | uint8_t ultra_click_removal; | ||
52 | uint8_t default_channel_positions; | ||
53 | uint8_t unknown2[8]; | ||
54 | uint16_t special; | ||
55 | uint8_t channel_settings[32]; | ||
33 | }; | 56 | }; |
57 | LE_NETWORK_STRUCT_END | ||
34 | 58 | ||
35 | #define ADD(s,t) do { if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | 59 | #define ADD(s,t) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s) + 1)) return 1 |
36 | 60 | #define ADDL(s,t,l) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, l)) return 1 | |
37 | 61 | ||
38 | /* "extract" keyword from a Scream Tracker 3 Module | 62 | int |
39 | * | 63 | EXTRACTOR_s3m_extract_method (struct EXTRACTOR_PluginList *plugin, |
40 | * "Scream Tracker 3.01 BETA File Formats And Mixing Info" | 64 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) |
41 | * was used, while this piece of software was originally | ||
42 | * written. | ||
43 | * | ||
44 | */ | ||
45 | int | ||
46 | EXTRACTOR_s3m_extract (const unsigned char *data, | ||
47 | size_t size, | ||
48 | EXTRACTOR_MetaDataProcessor proc, | ||
49 | void *proc_cls, | ||
50 | const char *options) | ||
51 | { | 65 | { |
52 | char title[29]; | 66 | int64_t offset; |
53 | const struct header *head; | 67 | unsigned char *data; |
54 | 68 | struct S3MHeader header; | |
55 | /* Check header size */ | 69 | char song_name_NT[29]; |
56 | 70 | ||
57 | if (size < HEADER_SIZE) | 71 | if (plugin == NULL) |
58 | return 0; | 72 | return 1; |
59 | head = (const struct header *) data; | 73 | if (sizeof (header) != pl_read (plugin, &data, sizeof (header))) |
60 | if (memcmp (head->magicid, "SCRM", 4)) | 74 | return 1; |
61 | return 0; | 75 | memcpy (&header, data, sizeof (header)); |
62 | ADD ("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE); | 76 | if (header.byte_1A != 0x1A || memcmp (header.SCRM, "SCRM", 4) != 0) |
77 | return 1; | ||
78 | header.number_of_orders = LE_le16toh (header.number_of_orders); | ||
79 | header.number_of_instruments = LE_le16toh (header.number_of_instruments); | ||
80 | header.number_of_patterns = LE_le16toh (header.number_of_patterns); | ||
81 | header.flags = LE_le16toh (header.flags); | ||
82 | header.created_with_version = LE_le16toh (header.created_with_version); | ||
83 | header.file_format_info = LE_le16toh (header.file_format_info); | ||
84 | header.special = LE_le16toh (header.special); | ||
85 | memcpy (song_name_NT, header.song_name, 28); | ||
86 | song_name_NT[28] = '\0'; | ||
63 | 87 | ||
64 | memcpy (&title, head->title, 28); | 88 | ADD("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE); |
65 | title[28] = '\0'; | 89 | ADD(song_name_NT, EXTRACTOR_METATYPE_TITLE); |
66 | ADD (title, EXTRACTOR_METATYPE_TITLE); | 90 | /* TODO: turn other header data into useful metadata (i.e. RESOURCE_TYPE). |
67 | return 0; | 91 | * Also, disabled instruments can be (and are) used to carry user-defined text. |
92 | */ | ||
93 | return 1; | ||
68 | } | 94 | } |