From d9a5c0645b80b3d1760f758282ca987898aed54c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Aug 2012 21:35:13 +0000 Subject: it testcase --- src/plugins/s3m_extractor.c | 81 +++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'src/plugins/s3m_extractor.c') 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 @@ /* This file is part of libextractor. - (C) 2002, 2003, 2004, 2009 Vidyut Samanta and Christian Grothoff + (C) 2002, 2003, 2004, 2009, 2012 Vidyut Samanta and Christian Grothoff libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your + by the Free Software Foundation; either version 3, or (at your option) any later version. libextractor is distributed in the hope that it will be useful, but @@ -17,18 +17,16 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +/** + * @file plugins/s3m_extractor.c + * @brief plugin to support Scream Tracker (S3M) files + * @author Toni Ruottu + * @author Christian Grothoff + */ #include "platform.h" #include "extractor.h" - -#include "extractor_plugins.h" #include "le_architecture.h" -/* Based upon ST 3.20 spec at http://16-bits.org/s3m/ */ -/* Looks like the format was defined by the software implementation, - * and that implementation was for little-endian platform, which means - * that the format is little-endian. - */ LE_NETWORK_STRUCT_BEGIN struct S3MHeader @@ -37,12 +35,12 @@ struct S3MHeader uint8_t byte_1A; uint8_t file_type; /* 0x10 == ST3 module */ uint8_t unknown1[2]; - uint16_t number_of_orders; /* should be even */ - uint16_t number_of_instruments; - uint16_t number_of_patterns; - uint16_t flags; - uint16_t created_with_version; - uint16_t file_format_info; + uint16_t number_of_orders LE_PACKED; /* should be even */ + uint16_t number_of_instruments LE_PACKED; + uint16_t number_of_patterns LE_PACKED; + uint16_t flags LE_PACKED; + uint16_t created_with_version LE_PACKED; + uint16_t file_format_info LE_PACKED; char SCRM[4]; uint8_t global_volume; uint8_t initial_speed; @@ -51,29 +49,46 @@ struct S3MHeader uint8_t ultra_click_removal; uint8_t default_channel_positions; uint8_t unknown2[8]; - uint16_t special; + uint16_t special LE_PACKED; uint8_t channel_settings[32]; }; LE_NETWORK_STRUCT_END -#define ADD(s,t) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s) + 1)) return 1 -#define ADDL(s,t,l) if (0 != proc (proc_cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, l)) return 1 -int -EXTRACTOR_s3m_extract_method (struct EXTRACTOR_PluginList *plugin, - EXTRACTOR_MetaDataProcessor proc, void *proc_cls) +/** + * Give meta data to LE 'proc' callback using the given LE type and value. + * + * @param t LE meta data type + * @param s meta data to add + */ +#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) + + +/** + * Extractor based upon Scream Tracker 3.20 spec at http://16-bits.org/s3m/ + * + * Looks like the format was defined by the software implementation, + * and that implementation was for little-endian platform, which means + * that the format is little-endian. + * + * @param ec extraction context + */ +void +EXTRACTOR_s3m_extract_method (struct EXTRACTOR_ExtractContext *ec) { - unsigned char *data; + void *data; struct S3MHeader header; char song_name_NT[29]; - if (plugin == NULL) - return 1; - if (sizeof (header) != pl_read (plugin, &data, sizeof (header))) - return 1; + if (sizeof (header) > + ec->read (ec->cls, + &data, + sizeof (header))) + return; memcpy (&header, data, sizeof (header)); - if (header.byte_1A != 0x1A || memcmp (header.SCRM, "SCRM", 4) != 0) - return 1; + if ( (0x1A != header.byte_1A) || + (0 != memcmp (header.SCRM, "SCRM", 4)) ) + return; header.number_of_orders = LE_le16toh (header.number_of_orders); header.number_of_instruments = LE_le16toh (header.number_of_instruments); header.number_of_patterns = LE_le16toh (header.number_of_patterns); @@ -83,11 +98,11 @@ EXTRACTOR_s3m_extract_method (struct EXTRACTOR_PluginList *plugin, header.special = LE_le16toh (header.special); memcpy (song_name_NT, header.song_name, 28); song_name_NT[28] = '\0'; - - ADD("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE); - ADD(song_name_NT, EXTRACTOR_METATYPE_TITLE); + ADD ("audio/x-s3m", EXTRACTOR_METATYPE_MIMETYPE); + ADD (song_name_NT, EXTRACTOR_METATYPE_TITLE); /* TODO: turn other header data into useful metadata (i.e. RESOURCE_TYPE). * Also, disabled instruments can be (and are) used to carry user-defined text. */ - return 1; } + +/* end of s3m_extractor.c */ -- cgit v1.2.3