~noskcaj/ubuntu/trusty/libextractor/merge

« back to all changes in this revision

Viewing changes to src/plugins/s3mextractor.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  0x70
 
27
 
 
28
struct header
 
29
{
 
30
  char title[28];
 
31
  char something[16];
 
32
  char magicid[4];
 
33
};
 
34
 
 
35
 
 
36
static struct EXTRACTOR_Keywords *addkword
 
37
  (EXTRACTOR_KeywordList * oldhead,
 
38
   const char *phrase, EXTRACTOR_KeywordType type)
 
39
{
 
40
  EXTRACTOR_KeywordList *keyword;
 
41
 
 
42
  keyword = malloc (sizeof (EXTRACTOR_KeywordList));
 
43
  keyword->next = oldhead;
 
44
  keyword->keyword = strdup (phrase);
 
45
  keyword->keywordType = type;
 
46
  return (keyword);
 
47
}
 
48
 
 
49
 
 
50
/* "extract" keyword from a Scream Tracker 3 Module
 
51
 *
 
52
 * "Scream Tracker 3.01 BETA File Formats And Mixing Info"
 
53
 * was used, while this piece of software was originally
 
54
 * written.
 
55
 *
 
56
 */
 
57
struct EXTRACTOR_Keywords *libextractor_s3m_extract
 
58
  (const char *filename,
 
59
   char *data, size_t size, struct EXTRACTOR_Keywords *prev)
 
60
{
 
61
  char title[29];
 
62
  struct header *head;
 
63
 
 
64
  /* Check header size */
 
65
 
 
66
  if (size < HEADER_SIZE)
 
67
    {
 
68
      return (prev);
 
69
    }
 
70
 
 
71
  head = (struct header *) data;
 
72
 
 
73
  /* Check "magic" id bytes */
 
74
 
 
75
  if (memcmp (head->magicid, "SCRM", 4))
 
76
    {
 
77
      return (prev);
 
78
    }
 
79
 
 
80
  /* Mime-type */
 
81
 
 
82
  prev = addkword (prev, "audio/x-s3m", EXTRACTOR_MIMETYPE);
 
83
 
 
84
  /* Song title */
 
85
 
 
86
  memcpy (&title, head->title, 28);
 
87
  title[28] = '\0';
 
88
  prev = addkword (prev, title, EXTRACTOR_TITLE);
 
89
 
 
90
  return (prev);
 
91
 
 
92
}