~noskcaj/ubuntu/trusty/libextractor/merge

« back to all changes in this revision

Viewing changes to src/plugins/xmextractor.c

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-11-10 22:21:49 UTC
  • mfrom: (1.10.3 upstream) (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081110222149-pr35f3nmqy5cf52i
Tags: 0.5.21+dfsg-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - (Build-)depend on libltdl7-dev (Ubuntu-specific change).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of libextractor.
 
3
 * (C) 2008 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 2, 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
 
 
22
#include "platform.h"
 
23
#include "extractor.h"
 
24
#include "convert.h"
 
25
 
 
26
#define HEADER_SIZE  64
 
27
 
 
28
struct header
 
29
{
 
30
  char magicid[17];
 
31
  char title[20];
 
32
  char something[1];
 
33
  char tracker[20];
 
34
  char version[2];
 
35
};
 
36
 
 
37
 
 
38
static struct EXTRACTOR_Keywords *addkword
 
39
  (EXTRACTOR_KeywordList * oldhead,
 
40
   const char *phrase, EXTRACTOR_KeywordType type)
 
41
{
 
42
  EXTRACTOR_KeywordList *keyword;
 
43
 
 
44
  keyword = malloc (sizeof (EXTRACTOR_KeywordList));
 
45
  keyword->next = oldhead;
 
46
  keyword->keyword = strdup (phrase);
 
47
  keyword->keywordType = type;
 
48
  return (keyword);
 
49
}
 
50
 
 
51
 
 
52
/* "extract" keyword from an Extended Module
 
53
 *
 
54
 * The XM module format description for XM files
 
55
 * version $0104 that was written by Mr.H of Triton
 
56
 * in 1994 was used, while this piece of software
 
57
 * was originally written.
 
58
 *
 
59
 */
 
60
struct EXTRACTOR_Keywords *libextractor_xm_extract
 
61
  (const char *filename,
 
62
   char *data, size_t size, struct EXTRACTOR_Keywords *prev)
 
63
{
 
64
  char title[21];
 
65
  char tracker[21];
 
66
  char xmversion[8];
 
67
  struct header *head;
 
68
 
 
69
  /* Check header size */
 
70
 
 
71
  if (size < HEADER_SIZE)
 
72
    {
 
73
      return (prev);
 
74
    }
 
75
 
 
76
  head = (struct header *) data;
 
77
 
 
78
  /* Check "magic" id bytes */
 
79
 
 
80
  if (memcmp (head->magicid, "Extended Module: ", 17))
 
81
    {
 
82
      return (prev);
 
83
    }
 
84
 
 
85
  /* Mime-type */
 
86
 
 
87
  prev = addkword (prev, "audio/x-xm", EXTRACTOR_MIMETYPE);
 
88
 
 
89
  /* Version of Tracker */
 
90
 
 
91
  sprintf (xmversion, "%d.%d", head->version[1],head->version[0]);
 
92
  prev = addkword (prev, xmversion, EXTRACTOR_FORMAT_VERSION);
 
93
 
 
94
  /* Song title */
 
95
 
 
96
  memcpy (&title, head->title, 20);
 
97
  title[20] = '\0';
 
98
  prev = addkword (prev, title, EXTRACTOR_TITLE);
 
99
 
 
100
  /* software used for creating the data */
 
101
 
 
102
  memcpy (&tracker, head->tracker, 20);
 
103
  tracker[20] = '\0';
 
104
  prev = addkword (prev, tracker, EXTRACTOR_SOFTWARE);
 
105
 
 
106
  return (prev);
 
107
 
 
108
}