"Fossies" - the Fresh Open Source Software Archive

Member "libextractor-1.11/src/plugins/xm_extractor.c" (30 Jan 2021, 2996 Bytes) of package /linux/privat/libextractor-1.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "xm_extractor.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.7_vs_1.8.

    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
   68 EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec)
   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]);
   93   ADD (xmversion, EXTRACTOR_METATYPE_FORMAT_VERSION);
   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';
  100   ADD (title, EXTRACTOR_METATYPE_TITLE);
  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';
  107   ADD (tracker, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE);
  108   return;
  109 }
  110 
  111 
  112 /* end of xm_extractor.c */