libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xm_extractor.c
Go to the documentation of this file.
1 /*
2  * This file is part of libextractor.
3  * Copyright (C) 2008, 2009 Toni Ruottu
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., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21 /**
22  * @file plugins/xm_extractor.c
23  * @brief plugin to support XM files
24  * @author Toni Ruottu
25  * @author Christian Grothoff
26  */
27 #include "platform.h"
28 #include "extractor.h"
29 
30 
31 /**
32  * Header of an XM file.
33  */
34 struct Header
35 {
36  char magicid[17];
37  char title[20];
38  char something[1];
39  char tracker[20];
40  char version[2];
41 };
42 
43 
44 /**
45  * Give meta data to LE.
46  *
47  * @param s utf-8 string meta data value
48  * @param t type of the meta data
49  */
50 #define ADD(s,t) do { if (0 != ec->proc (ec->cls, "xm", t, \
51  EXTRACTOR_METAFORMAT_UTF8, \
52  "text/plain", s, strlen (s) \
53  + 1)) return; \
54 } while (0)
55 
56 
57 /**
58  * "extract" metadata from an Extended Module
59  *
60  * The XM module format description for XM files
61  * version $0104 that was written by Mr.H of Triton
62  * in 1994 was used, while this piece of software
63  * was originally written.
64  *
65  * @param ec extraction context
66  */
67 void
69 {
70  void *data;
71  const struct Header *head;
72  char title[21];
73  char tracker[21];
74  char xmversion[8];
75  size_t n;
76 
77  if ((ssize_t) sizeof (struct Header) >
78  ec->read (ec->cls,
79  &data,
80  sizeof (struct Header)))
81  return;
82  head = data;
83  /* Check "magic" id bytes */
84  if (memcmp (head->magicid, "Extended Module: ", 17))
85  return;
86  ADD ("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE);
87  /* Version of Tracker */
88  snprintf (xmversion,
89  sizeof (xmversion),
90  "%u.%u",
91  head->version[1],
92  head->version[0]);
94  /* Song title */
95  memcpy (&title, head->title, 20);
96  n = 19;
97  while ( (n > 0) && isspace ((unsigned char) title[n]))
98  n--;
99  title[n + 1] = '\0';
101  /* software used for creating the data */
102  memcpy (&tracker, head->tracker, 20);
103  n = 19;
104  while ( (n > 0) && isspace ((unsigned char) tracker[n]))
105  n--;
106  tracker[n + 1] = '\0';
108  return;
109 }
110 
111 
112 /* end of xm_extractor.c */
@ EXTRACTOR_METATYPE_FORMAT_VERSION
Definition: extractor.h:191
@ EXTRACTOR_METATYPE_TITLE
Definition: extractor.h:134
@ EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE
Definition: extractor.h:194
@ EXTRACTOR_METATYPE_MIMETYPE
Definition: extractor.h:129
plaform specifics
ssize_t(* read)(void *cls, void **data, size_t size)
Definition: extractor.h:494
char tracker[20]
Definition: xm_extractor.c:39
char title[26]
Definition: it_extractor.c:44
char magicid[4]
Definition: it_extractor.c:43
char version[2]
Definition: it_extractor.c:50
char something[1]
Definition: xm_extractor.c:38
void EXTRACTOR_xm_extract_method(struct EXTRACTOR_ExtractContext *ec)
Definition: xm_extractor.c:68
#define ADD(s, t)
Definition: xm_extractor.c:50