aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/s3m_extractor.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-08-09 21:35:13 +0000
committerChristian Grothoff <christian@grothoff.org>2012-08-09 21:35:13 +0000
commitd9a5c0645b80b3d1760f758282ca987898aed54c (patch)
tree618bf432acef81f8bdc2224f648544a4ee996532 /src/plugins/s3m_extractor.c
parent62a8d56eec03037fce17c5ced51a4f9052e8310a (diff)
downloadlibextractor-d9a5c0645b80b3d1760f758282ca987898aed54c.tar.gz
libextractor-d9a5c0645b80b3d1760f758282ca987898aed54c.zip
it testcase
Diffstat (limited to 'src/plugins/s3m_extractor.c')
-rw-r--r--src/plugins/s3m_extractor.c81
1 files changed, 48 insertions, 33 deletions
diff --git a/src/plugins/s3m_extractor.c b/src/plugins/s3m_extractor.c
index 3ce1a13..6a50636 100644
--- a/src/plugins/s3m_extractor.c
+++ b/src/plugins/s3m_extractor.c
@@ -1,10 +1,10 @@
1/* 1/*
2 This file is part of libextractor. 2 This file is part of libextractor.
3 (C) 2002, 2003, 2004, 2009 Vidyut Samanta and Christian Grothoff 3 (C) 2002, 2003, 2004, 2009, 2012 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 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
@@ -17,18 +17,16 @@
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 */ 19 */
20 20/**
21 * @file plugins/s3m_extractor.c
22 * @brief plugin to support Scream Tracker (S3M) files
23 * @author Toni Ruottu
24 * @author Christian Grothoff
25 */
21#include "platform.h" 26#include "platform.h"
22#include "extractor.h" 27#include "extractor.h"
23
24#include "extractor_plugins.h"
25#include "le_architecture.h" 28#include "le_architecture.h"
26 29
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 */
32 30
33LE_NETWORK_STRUCT_BEGIN 31LE_NETWORK_STRUCT_BEGIN
34struct S3MHeader 32struct S3MHeader
@@ -37,12 +35,12 @@ struct S3MHeader
37 uint8_t byte_1A; 35 uint8_t byte_1A;
38 uint8_t file_type; /* 0x10 == ST3 module */ 36 uint8_t file_type; /* 0x10 == ST3 module */
39 uint8_t unknown1[2]; 37 uint8_t unknown1[2];
40 uint16_t number_of_orders; /* should be even */ 38 uint16_t number_of_orders LE_PACKED; /* should be even */
41 uint16_t number_of_instruments; 39 uint16_t number_of_instruments LE_PACKED;
42 uint16_t number_of_patterns; 40 uint16_t number_of_patterns LE_PACKED;
43 uint16_t flags; 41 uint16_t flags LE_PACKED;
44 uint16_t created_with_version; 42 uint16_t created_with_version LE_PACKED;
45 uint16_t file_format_info; 43 uint16_t file_format_info LE_PACKED;
46 char SCRM[4]; 44 char SCRM[4];
47 uint8_t global_volume; 45 uint8_t global_volume;
48 uint8_t initial_speed; 46 uint8_t initial_speed;
@@ -51,29 +49,46 @@ struct S3MHeader
51 uint8_t ultra_click_removal; 49 uint8_t ultra_click_removal;
52 uint8_t default_channel_positions; 50 uint8_t default_channel_positions;
53 uint8_t unknown2[8]; 51 uint8_t unknown2[8];
54 uint16_t special; 52 uint16_t special LE_PACKED;
55 uint8_t channel_settings[32]; 53 uint8_t channel_settings[32];
56}; 54};
57LE_NETWORK_STRUCT_END 55LE_NETWORK_STRUCT_END
58 56
59#define ADD(s,t) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s) + 1)) return 1
60#define ADDL(s,t,l) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, l)) return 1
61 57
62int 58/**
63EXTRACTOR_s3m_extract_method (struct EXTRACTOR_PluginList *plugin, 59 * Give meta data to LE 'proc' callback using the given LE type and value.
64 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 60 *
61 * @param t LE meta data type
62 * @param s meta data to add
63 */
64#define ADD(s, t) do { if (0 != ec->proc (ec->cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0)
65
66
67/**
68 * Extractor based upon Scream Tracker 3.20 spec at http://16-bits.org/s3m/
69 *
70 * Looks like the format was defined by the software implementation,
71 * and that implementation was for little-endian platform, which means
72 * that the format is little-endian.
73 *
74 * @param ec extraction context
75 */
76void
77EXTRACTOR_s3m_extract_method (struct EXTRACTOR_ExtractContext *ec)
65{ 78{
66 unsigned char *data; 79 void *data;
67 struct S3MHeader header; 80 struct S3MHeader header;
68 char song_name_NT[29]; 81 char song_name_NT[29];
69 82
70 if (plugin == NULL) 83 if (sizeof (header) >
71 return 1; 84 ec->read (ec->cls,
72 if (sizeof (header) != pl_read (plugin, &data, sizeof (header))) 85 &data,
73 return 1; 86 sizeof (header)))
87 return;
74 memcpy (&header, data, sizeof (header)); 88 memcpy (&header, data, sizeof (header));
75 if (header.byte_1A != 0x1A || memcmp (header.SCRM, "SCRM", 4) != 0) 89 if ( (0x1A != header.byte_1A) ||
76 return 1; 90 (0 != memcmp (header.SCRM, "SCRM", 4)) )
91 return;
77 header.number_of_orders = LE_le16toh (header.number_of_orders); 92 header.number_of_orders = LE_le16toh (header.number_of_orders);
78 header.number_of_instruments = LE_le16toh (header.number_of_instruments); 93 header.number_of_instruments = LE_le16toh (header.number_of_instruments);
79 header.number_of_patterns = LE_le16toh (header.number_of_patterns); 94 header.number_of_patterns = LE_le16toh (header.number_of_patterns);
@@ -83,11 +98,11 @@ EXTRACTOR_s3m_extract_method (struct EXTRACTOR_PluginList *plugin,
83 header.special = LE_le16toh (header.special); 98 header.special = LE_le16toh (header.special);
84 memcpy (song_name_NT, header.song_name, 28); 99 memcpy (song_name_NT, header.song_name, 28);
85 song_name_NT[28] = '\0'; 100 song_name_NT[28] = '\0';
86 101 ADD ("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE);
87 ADD("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE); 102 ADD (song_name_NT, EXTRACTOR_METATYPE_TITLE);
88 ADD(song_name_NT, EXTRACTOR_METATYPE_TITLE);
89 /* TODO: turn other header data into useful metadata (i.e. RESOURCE_TYPE). 103 /* TODO: turn other header data into useful metadata (i.e. RESOURCE_TYPE).
90 * Also, disabled instruments can be (and are) used to carry user-defined text. 104 * Also, disabled instruments can be (and are) used to carry user-defined text.
91 */ 105 */
92 return 1;
93} 106}
107
108/* end of s3m_extractor.c */