(root)/
gettext-0.22.4/
gnulib-local/
lib/
libxml/
DOCBparser.c
       1  /* libxml2 - Library for parsing XML documents
       2   * Copyright (C) 2006-2019 Free Software Foundation, Inc.
       3   *
       4   * This file is not part of the GNU gettext program, but is used with
       5   * GNU gettext.
       6   *
       7   * The original copyright notice is as follows:
       8   */
       9  
      10  /*
      11   * Copyright (C) 1998-2012 Daniel Veillard.  All Rights Reserved.
      12   *
      13   * Permission is hereby granted, free of charge, to any person obtaining a copy
      14   * of this software and associated documentation files (the "Software"), to deal
      15   * in the Software without restriction, including without limitation the rights
      16   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      17   * copies of the Software, and to permit persons to whom the Software is fur-
      18   * nished to do so, subject to the following conditions:
      19   *
      20   * The above copyright notice and this permission notice shall be included in
      21   * all copies or substantial portions of the Software.
      22   *
      23   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      24   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
      25   * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
      26   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      27   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      28   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      29   * THE SOFTWARE.
      30   *
      31   * daniel@veillard.com
      32   */
      33  
      34  /*
      35   * DOCBparser.c : an attempt to parse SGML Docbook documents
      36   *
      37   * This is deprecated !!!
      38   * Code removed with release 2.6.0 it was broken.
      39   * The doc are expect to be migrated to XML DocBook
      40   */
      41  
      42  #define IN_LIBXML
      43  #include "libxml.h"
      44  #ifdef LIBXML_DOCB_ENABLED
      45  
      46  #include <libxml/xmlerror.h>
      47  #include <libxml/DOCBparser.h>
      48  
      49  /**
      50   * docbEncodeEntities:
      51   * @out:  a pointer to an array of bytes to store the result
      52   * @outlen:  the length of @out
      53   * @in:  a pointer to an array of UTF-8 chars
      54   * @inlen:  the length of @in
      55   * @quoteChar: the quote character to escape (' or ") or zero.
      56   *
      57   * Take a block of UTF-8 chars in and try to convert it to an ASCII
      58   * plus SGML entities block of chars out.
      59   *
      60   * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
      61   * The value of @inlen after return is the number of octets consumed
      62   *     as the return value is positive, else unpredictable.
      63   * The value of @outlen after return is the number of octets consumed.
      64   */
      65  int
      66  docbEncodeEntities(unsigned char *out ATTRIBUTE_UNUSED,
      67                     int *outlen ATTRIBUTE_UNUSED,
      68                     const unsigned char *in ATTRIBUTE_UNUSED,
      69                     int *inlen ATTRIBUTE_UNUSED,
      70                     int quoteChar ATTRIBUTE_UNUSED)
      71  {
      72      static int deprecated = 0;
      73  
      74      if (!deprecated) {
      75          xmlGenericError(xmlGenericErrorContext,
      76                          "docbEncodeEntities() deprecated function reached\n");
      77          deprecated = 1;
      78      }
      79      return(-1);
      80  }
      81  
      82  /**
      83   * docbParseDocument:
      84   * @ctxt:  an SGML parser context
      85   *
      86   * parse an SGML document (and build a tree if using the standard SAX
      87   * interface).
      88   *
      89   * Returns 0, -1 in case of error. the parser context is augmented
      90   *                as a result of the parsing.
      91   */
      92  
      93  int
      94  docbParseDocument(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
      95  {
      96      static int deprecated = 0;
      97  
      98      if (!deprecated) {
      99          xmlGenericError(xmlGenericErrorContext,
     100                          "docbParseDocument() deprecated function reached\n");
     101          deprecated = 1;
     102      }
     103      return (xmlParseDocument(ctxt));
     104  }
     105  
     106  /**
     107   * docbFreeParserCtxt:
     108   * @ctxt:  an SGML parser context
     109   *
     110   * Free all the memory used by a parser context. However the parsed
     111   * document in ctxt->myDoc is not freed.
     112   */
     113  
     114  void
     115  docbFreeParserCtxt(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
     116  {
     117      static int deprecated = 0;
     118  
     119      if (!deprecated) {
     120          xmlGenericError(xmlGenericErrorContext,
     121                          "docbFreeParserCtxt() deprecated function reached\n");
     122          deprecated = 1;
     123      }
     124      xmlFreeParserCtxt(ctxt);
     125  }
     126  
     127  /**
     128   * docbParseChunk:
     129   * @ctxt:  an XML parser context
     130   * @chunk:  an char array
     131   * @size:  the size in byte of the chunk
     132   * @terminate:  last chunk indicator
     133   *
     134   * Parse a Chunk of memory
     135   *
     136   * Returns zero if no error, the xmlParserErrors otherwise.
     137   */
     138  int
     139  docbParseChunk(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
     140                 const char *chunk ATTRIBUTE_UNUSED,
     141  	       int size ATTRIBUTE_UNUSED,
     142                 int terminate ATTRIBUTE_UNUSED)
     143  {
     144      static int deprecated = 0;
     145  
     146      if (!deprecated) {
     147          xmlGenericError(xmlGenericErrorContext,
     148                          "docbParseChunk() deprecated function reached\n");
     149          deprecated = 1;
     150      }
     151  
     152      return (xmlParseChunk(ctxt, chunk, size, terminate));
     153  }
     154  
     155  /**
     156   * docbCreatePushParserCtxt:
     157   * @sax:  a SAX handler
     158   * @user_data:  The user data returned on SAX callbacks
     159   * @chunk:  a pointer to an array of chars
     160   * @size:  number of chars in the array
     161   * @filename:  an optional file name or URI
     162   * @enc:  an optional encoding
     163   *
     164   * Create a parser context for using the DocBook SGML parser in push mode
     165   * To allow content encoding detection, @size should be >= 4
     166   * The value of @filename is used for fetching external entities
     167   * and error/warning reports.
     168   *
     169   * Returns the new parser context or NULL
     170   */
     171  docbParserCtxtPtr
     172  docbCreatePushParserCtxt(docbSAXHandlerPtr sax ATTRIBUTE_UNUSED,
     173                           void *user_data ATTRIBUTE_UNUSED,
     174                           const char *chunk ATTRIBUTE_UNUSED,
     175  			 int size ATTRIBUTE_UNUSED,
     176  			 const char *filename ATTRIBUTE_UNUSED,
     177                           xmlCharEncoding enc ATTRIBUTE_UNUSED)
     178  {
     179      static int deprecated = 0;
     180  
     181      if (!deprecated) {
     182          xmlGenericError(xmlGenericErrorContext,
     183                          "docbParseChunk() deprecated function reached\n");
     184          deprecated = 1;
     185      }
     186  
     187      return(xmlCreatePushParserCtxt(sax, user_data, chunk, size, filename));
     188  }
     189  
     190  /**
     191   * docbSAXParseDoc:
     192   * @cur:  a pointer to an array of xmlChar
     193   * @encoding:  a free form C string describing the SGML document encoding, or NULL
     194   * @sax:  the SAX handler block
     195   * @userData: if using SAX, this pointer will be provided on callbacks.
     196   *
     197   * parse an SGML in-memory document and build a tree.
     198   * It use the given SAX function block to handle the parsing callback.
     199   * If sax is NULL, fallback to the default DOM tree building routines.
     200   *
     201   * Returns the resulting document tree
     202   */
     203  
     204  docbDocPtr
     205  docbSAXParseDoc(xmlChar * cur ATTRIBUTE_UNUSED,
     206                  const char *encoding ATTRIBUTE_UNUSED,
     207  		docbSAXHandlerPtr sax ATTRIBUTE_UNUSED,
     208                  void *userData ATTRIBUTE_UNUSED)
     209  {
     210      static int deprecated = 0;
     211  
     212      if (!deprecated) {
     213          xmlGenericError(xmlGenericErrorContext,
     214                          "docbParseChunk() deprecated function reached\n");
     215          deprecated = 1;
     216      }
     217  
     218      return (xmlSAXParseMemoryWithData(sax, (const char *)cur,
     219  			  xmlStrlen((const xmlChar *) cur), 0,  userData));
     220  }
     221  
     222  /**
     223   * docbParseDoc:
     224   * @cur:  a pointer to an array of xmlChar
     225   * @encoding:  a free form C string describing the SGML document encoding, or NULL
     226   *
     227   * parse an SGML in-memory document and build a tree.
     228   *
     229   * Returns the resulting document tree
     230   */
     231  
     232  docbDocPtr
     233  docbParseDoc(xmlChar * cur ATTRIBUTE_UNUSED,
     234               const char *encoding ATTRIBUTE_UNUSED)
     235  {
     236      static int deprecated = 0;
     237  
     238      if (!deprecated) {
     239          xmlGenericError(xmlGenericErrorContext,
     240                          "docbParseChunk() deprecated function reached\n");
     241          deprecated = 1;
     242      }
     243  
     244      return (xmlParseDoc(cur));
     245  }
     246  
     247  
     248  /**
     249   * docbCreateFileParserCtxt:
     250   * @filename:  the filename
     251   * @encoding:  the SGML document encoding, or NULL
     252   *
     253   * Create a parser context for a file content.
     254   * Automatic support for ZLIB/Compress compressed document is provided
     255   * by default if found at compile-time.
     256   *
     257   * Returns the new parser context or NULL
     258   */
     259  docbParserCtxtPtr
     260  docbCreateFileParserCtxt(const char *filename ATTRIBUTE_UNUSED,
     261                           const char *encoding ATTRIBUTE_UNUSED)
     262  {
     263      static int deprecated = 0;
     264  
     265      if (!deprecated) {
     266          xmlGenericError(xmlGenericErrorContext,
     267                          "docbCreateFileParserCtxt() deprecated function reached\n");
     268          deprecated = 1;
     269      }
     270  
     271      return (xmlCreateFileParserCtxt(filename));
     272  }
     273  
     274  /**
     275   * docbSAXParseFile:
     276   * @filename:  the filename
     277   * @encoding:  a free form C string describing the SGML document encoding, or NULL
     278   * @sax:  the SAX handler block
     279   * @userData: if using SAX, this pointer will be provided on callbacks.
     280   *
     281   * parse an SGML file and build a tree. Automatic support for ZLIB/Compress
     282   * compressed document is provided by default if found at compile-time.
     283   * It use the given SAX function block to handle the parsing callback.
     284   * If sax is NULL, fallback to the default DOM tree building routines.
     285   *
     286   * Returns the resulting document tree
     287   */
     288  
     289  docbDocPtr
     290  docbSAXParseFile(const char *filename ATTRIBUTE_UNUSED,
     291                   const char *encoding ATTRIBUTE_UNUSED,
     292                   docbSAXHandlerPtr sax ATTRIBUTE_UNUSED,
     293  		 void *userData ATTRIBUTE_UNUSED)
     294  {
     295      static int deprecated = 0;
     296  
     297      if (!deprecated) {
     298          xmlGenericError(xmlGenericErrorContext,
     299                          "docbSAXParseFile() deprecated function reached\n");
     300          deprecated = 1;
     301      }
     302  
     303      return (xmlSAXParseFileWithData(sax, filename, 0, userData));
     304  }
     305  
     306  /**
     307   * docbParseFile:
     308   * @filename:  the filename
     309   * @encoding:  a free form C string describing document encoding, or NULL
     310   *
     311   * parse a Docbook SGML file and build a tree. Automatic support for
     312   * ZLIB/Compress compressed document is provided by default if found
     313   * at compile-time.
     314   *
     315   * Returns the resulting document tree
     316   */
     317  
     318  docbDocPtr
     319  docbParseFile(const char *filename ATTRIBUTE_UNUSED,
     320                const char *encoding ATTRIBUTE_UNUSED)
     321  {
     322      static int deprecated = 0;
     323  
     324      if (!deprecated) {
     325          xmlGenericError(xmlGenericErrorContext,
     326                          "docbParseFile() deprecated function reached\n");
     327          deprecated = 1;
     328      }
     329  
     330      return (xmlParseFile(filename));
     331  }
     332  #define bottom_DOCBparser
     333  #include "elfgcchack.h"
     334  #endif /* LIBXML_DOCB_ENABLED */