"Fossies" - the Fresh Open Source Software Archive

Member "libextractor-1.11/src/main/extractor_print.c" (30 Jan 2021, 3331 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 "extractor_print.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2      This file is part of libextractor.
    3      Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 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 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., 51 Franklin Street, Fifth Floor,
   18      Boston, MA 02110-1301, USA.
   19  */
   20 /**
   21  * @file main/extractor_print.c
   22  * @brief convenience functions for printing meta data
   23  * @author Christian Grothoff
   24  */
   25 #include "platform.h"
   26 #include "extractor.h"
   27 #include "extractor_logging.h"
   28 #if HAVE_ICONV
   29 #include "iconv.c"
   30 #endif
   31 
   32 /**
   33  * Simple EXTRACTOR_MetaDataProcessor implementation that simply
   34  * prints the extracted meta data to the given file.  Only prints
   35  * those keywords that are in UTF-8 format.
   36  *
   37  * @param handle the file to write to (stdout, stderr), must NOT be NULL,
   38  *               must be of type "FILE *".
   39  * @param plugin_name name of the plugin that produced this value
   40  * @param type libextractor-type describing the meta data
   41  * @param format basic format information about data
   42  * @param data_mime_type mime-type of data (not of the original file);
   43  *        can be NULL (if mime-type is not known)
   44  * @param data actual meta-data found
   45  * @param data_len number of bytes in data
   46  * @return non-zero if printing failed, otherwise 0.
   47  */
   48 int
   49 EXTRACTOR_meta_data_print (void *handle,
   50                            const char *plugin_name,
   51                            enum EXTRACTOR_MetaType type,
   52                            enum EXTRACTOR_MetaFormat format,
   53                            const char *data_mime_type,
   54                            const char *data,
   55                            size_t data_len)
   56 {
   57 #if HAVE_ICONV
   58   iconv_t cd;
   59 #endif
   60   char *buf;
   61   int ret;
   62   const char *mt;
   63 
   64   if (EXTRACTOR_METAFORMAT_UTF8 != format)
   65     return 0;
   66 #if HAVE_ICONV
   67   cd = iconv_open (nl_langinfo (CODESET),
   68                    "UTF-8");
   69   if (((iconv_t) -1) == cd)
   70   {
   71     LOG_STRERROR ("iconv_open");
   72     return 1;
   73   }
   74   buf = iconv_helper (cd, data, data_len);
   75   if (NULL == buf)
   76   {
   77     LOG_STRERROR ("iconv_helper");
   78     ret = -1;
   79   }
   80   else
   81   {
   82     mt = EXTRACTOR_metatype_to_string (type);
   83     ret = fprintf (handle,
   84                    "%s - %s\n",
   85                    (NULL == mt)
   86                    ? dgettext ("libextractor", gettext_noop ("unknown"))
   87                    : dgettext ("libextractor", mt),
   88                    buf);
   89     free (buf);
   90   }
   91   iconv_close (cd);
   92 #else
   93   ret = fprintf (handle,
   94                  "%s - %.*s\n",
   95                  (NULL == mt)
   96                  ? dgettext ("libextractor", gettext_noop ("unknown"))
   97                  : dgettext ("libextractor", mt),
   98                  (int) data_len,
   99                  data);
  100 #endif
  101   return (ret < 0) ? 1 : 0;
  102 }
  103 
  104 
  105 /* end of extractor_print.c */