diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-08-09 21:35:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-08-09 21:35:13 +0000 |
commit | d9a5c0645b80b3d1760f758282ca987898aed54c (patch) | |
tree | 618bf432acef81f8bdc2224f648544a4ee996532 | |
parent | 62a8d56eec03037fce17c5ced51a4f9052e8310a (diff) | |
download | libextractor-d9a5c0645b80b3d1760f758282ca987898aed54c.tar.gz libextractor-d9a5c0645b80b3d1760f758282ca987898aed54c.zip |
it testcase
-rw-r--r-- | src/plugins/Makefile.am | 17 | ||||
-rw-r--r-- | src/plugins/it_extractor.c | 6 | ||||
-rw-r--r-- | src/plugins/s3m_extractor.c | 81 | ||||
-rw-r--r-- | src/plugins/test_it.c | 76 |
4 files changed, 143 insertions, 37 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 4f3fb8c..2acb576 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -23,7 +23,8 @@ EXTRA_DIST = template_extractor.c \ | |||
23 | testdata/mpeg_alien.mpg \ | 23 | testdata/mpeg_alien.mpg \ |
24 | testdata/mpeg_melt.mpg \ | 24 | testdata/mpeg_melt.mpg \ |
25 | testdata/wav_noise.wav \ | 25 | testdata/wav_noise.wav \ |
26 | testdata/wav_alert.wav | 26 | testdata/wav_alert.wav \ |
27 | testdata/it_dawn.it | ||
27 | 28 | ||
28 | if HAVE_VORBISFILE | 29 | if HAVE_VORBISFILE |
29 | PLUGIN_OGG=libextractor_ogg.la | 30 | PLUGIN_OGG=libextractor_ogg.la |
@@ -69,6 +70,7 @@ endif | |||
69 | plugin_LTLIBRARIES = \ | 70 | plugin_LTLIBRARIES = \ |
70 | libextractor_it.la \ | 71 | libextractor_it.la \ |
71 | libextractor_xm.la \ | 72 | libextractor_xm.la \ |
73 | libextractor_s3m.la \ | ||
72 | libextractor_wav.la \ | 74 | libextractor_wav.la \ |
73 | $(PLUGIN_OGG) \ | 75 | $(PLUGIN_OGG) \ |
74 | $(PLUGIN_MIME) \ | 76 | $(PLUGIN_MIME) \ |
@@ -85,6 +87,7 @@ endif | |||
85 | 87 | ||
86 | check_PROGRAMS = \ | 88 | check_PROGRAMS = \ |
87 | test_wav \ | 89 | test_wav \ |
90 | test_it \ | ||
88 | $(TEST_OGG) \ | 91 | $(TEST_OGG) \ |
89 | $(TEST_MIME) \ | 92 | $(TEST_MIME) \ |
90 | $(TEST_GIF) \ | 93 | $(TEST_GIF) \ |
@@ -113,11 +116,23 @@ libextractor_xm_la_SOURCES = \ | |||
113 | libextractor_xm_la_LDFLAGS = \ | 116 | libextractor_xm_la_LDFLAGS = \ |
114 | $(PLUGINFLAGS) | 117 | $(PLUGINFLAGS) |
115 | 118 | ||
119 | |||
116 | libextractor_it_la_SOURCES = \ | 120 | libextractor_it_la_SOURCES = \ |
117 | it_extractor.c | 121 | it_extractor.c |
118 | libextractor_it_la_LDFLAGS = \ | 122 | libextractor_it_la_LDFLAGS = \ |
119 | $(PLUGINFLAGS) | 123 | $(PLUGINFLAGS) |
120 | 124 | ||
125 | test_it_SOURCES = \ | ||
126 | test_it.c | ||
127 | test_it_LDADD = \ | ||
128 | $(top_builddir)/src/plugins/libtest.la | ||
129 | |||
130 | |||
131 | libextractor_s3m_la_SOURCES = \ | ||
132 | s3m_extractor.c | ||
133 | libextractor_s3m_la_LDFLAGS = \ | ||
134 | $(PLUGINFLAGS) | ||
135 | |||
121 | 136 | ||
122 | libextractor_wav_la_SOURCES = \ | 137 | libextractor_wav_la_SOURCES = \ |
123 | wav_extractor.c | 138 | wav_extractor.c |
diff --git a/src/plugins/it_extractor.c b/src/plugins/it_extractor.c index 852e50b..b2b1079 100644 --- a/src/plugins/it_extractor.c +++ b/src/plugins/it_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 |
@@ -85,8 +85,8 @@ EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec) | |||
85 | EXTRACTOR_METATYPE_MIMETYPE, | 85 | EXTRACTOR_METATYPE_MIMETYPE, |
86 | EXTRACTOR_METAFORMAT_UTF8, | 86 | EXTRACTOR_METAFORMAT_UTF8, |
87 | "text/plain", | 87 | "text/plain", |
88 | "audio/x-it", | 88 | "audio/x-mod", |
89 | strlen ("audio/x-it") + 1)) | 89 | strlen ("audio/x-mod") + 1)) |
90 | return; | 90 | return; |
91 | 91 | ||
92 | /* Version of Tracker */ | 92 | /* Version of Tracker */ |
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 | ||
33 | LE_NETWORK_STRUCT_BEGIN | 31 | LE_NETWORK_STRUCT_BEGIN |
34 | struct S3MHeader | 32 | struct 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 | }; |
57 | LE_NETWORK_STRUCT_END | 55 | LE_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 | ||
62 | int | 58 | /** |
63 | EXTRACTOR_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 | */ | ||
76 | void | ||
77 | EXTRACTOR_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 */ | ||
diff --git a/src/plugins/test_it.c b/src/plugins/test_it.c new file mode 100644 index 0000000..2ee5a73 --- /dev/null +++ b/src/plugins/test_it.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2012 Vidyut Samanta and Christian Grothoff | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
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 | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file plugins/test_it.c | ||
22 | * @brief testcase for it plugin | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "test_lib.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Main function for the IT testcase. | ||
31 | * | ||
32 | * @param argc number of arguments (ignored) | ||
33 | * @param argv arguments (ignored) | ||
34 | * @return 0 on success | ||
35 | */ | ||
36 | int | ||
37 | main (int argc, char *argv[]) | ||
38 | { | ||
39 | struct SolutionData it_dawn_sol[] = | ||
40 | { | ||
41 | { | ||
42 | EXTRACTOR_METATYPE_MIMETYPE, | ||
43 | EXTRACTOR_METAFORMAT_UTF8, | ||
44 | "text/plain", | ||
45 | "audio/x-mod", | ||
46 | strlen ("audio/x-mod") + 1, | ||
47 | 0 | ||
48 | }, | ||
49 | { | ||
50 | EXTRACTOR_METATYPE_TITLE, | ||
51 | EXTRACTOR_METAFORMAT_C_STRING, | ||
52 | "text/plain", | ||
53 | "Dawn", | ||
54 | strlen ("Dawn") + 1, | ||
55 | 0 | ||
56 | }, | ||
57 | { | ||
58 | EXTRACTOR_METATYPE_FORMAT_VERSION, | ||
59 | EXTRACTOR_METAFORMAT_C_STRING, | ||
60 | "text/plain", | ||
61 | "1.2", | ||
62 | strlen ("1.2") + 1, | ||
63 | 0 | ||
64 | }, | ||
65 | { 0, 0, NULL, NULL, 0, -1 } | ||
66 | }; | ||
67 | struct ProblemSet ps[] = | ||
68 | { | ||
69 | { "testdata/it_dawn.it", | ||
70 | it_dawn_sol }, | ||
71 | { NULL, NULL } | ||
72 | }; | ||
73 | return ET_main ("it", ps); | ||
74 | } | ||
75 | |||
76 | /* end of test_it.c */ | ||