libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit d9a5c0645b80b3d1760f758282ca987898aed54c
parent 62a8d56eec03037fce17c5ced51a4f9052e8310a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  9 Aug 2012 21:35:13 +0000

it testcase

Diffstat:
Msrc/plugins/Makefile.am | 17++++++++++++++++-
Msrc/plugins/it_extractor.c | 6+++---
Msrc/plugins/s3m_extractor.c | 81+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Asrc/plugins/test_it.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 143 insertions(+), 37 deletions(-)

diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -23,7 +23,8 @@ EXTRA_DIST = template_extractor.c \ testdata/mpeg_alien.mpg \ testdata/mpeg_melt.mpg \ testdata/wav_noise.wav \ - testdata/wav_alert.wav + testdata/wav_alert.wav \ + testdata/it_dawn.it if HAVE_VORBISFILE PLUGIN_OGG=libextractor_ogg.la @@ -69,6 +70,7 @@ endif plugin_LTLIBRARIES = \ libextractor_it.la \ libextractor_xm.la \ + libextractor_s3m.la \ libextractor_wav.la \ $(PLUGIN_OGG) \ $(PLUGIN_MIME) \ @@ -85,6 +87,7 @@ endif check_PROGRAMS = \ test_wav \ + test_it \ $(TEST_OGG) \ $(TEST_MIME) \ $(TEST_GIF) \ @@ -113,11 +116,23 @@ libextractor_xm_la_SOURCES = \ libextractor_xm_la_LDFLAGS = \ $(PLUGINFLAGS) + libextractor_it_la_SOURCES = \ it_extractor.c libextractor_it_la_LDFLAGS = \ $(PLUGINFLAGS) +test_it_SOURCES = \ + test_it.c +test_it_LDADD = \ + $(top_builddir)/src/plugins/libtest.la + + +libextractor_s3m_la_SOURCES = \ + s3m_extractor.c +libextractor_s3m_la_LDFLAGS = \ + $(PLUGINFLAGS) + libextractor_wav_la_SOURCES = \ wav_extractor.c diff --git a/src/plugins/it_extractor.c b/src/plugins/it_extractor.c @@ -4,7 +4,7 @@ * * 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 @@ -85,8 +85,8 @@ EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec) EXTRACTOR_METATYPE_MIMETYPE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", - "audio/x-it", - strlen ("audio/x-it") + 1)) + "audio/x-mod", + strlen ("audio/x-mod") + 1)) return; /* Version of Tracker */ diff --git 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 */ diff --git a/src/plugins/test_it.c b/src/plugins/test_it.c @@ -0,0 +1,76 @@ +/* + This file is part of libextractor. + (C) 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 3, or (at your + option) any later version. + + libextractor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file plugins/test_it.c + * @brief testcase for it plugin + * @author Christian Grothoff + */ +#include "platform.h" +#include "test_lib.h" + + +/** + * Main function for the IT testcase. + * + * @param argc number of arguments (ignored) + * @param argv arguments (ignored) + * @return 0 on success + */ +int +main (int argc, char *argv[]) +{ + struct SolutionData it_dawn_sol[] = + { + { + EXTRACTOR_METATYPE_MIMETYPE, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + "audio/x-mod", + strlen ("audio/x-mod") + 1, + 0 + }, + { + EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METAFORMAT_C_STRING, + "text/plain", + "Dawn", + strlen ("Dawn") + 1, + 0 + }, + { + EXTRACTOR_METATYPE_FORMAT_VERSION, + EXTRACTOR_METAFORMAT_C_STRING, + "text/plain", + "1.2", + strlen ("1.2") + 1, + 0 + }, + { 0, 0, NULL, NULL, 0, -1 } + }; + struct ProblemSet ps[] = + { + { "testdata/it_dawn.it", + it_dawn_sol }, + { NULL, NULL } + }; + return ET_main ("it", ps); +} + +/* end of test_it.c */