source: trunk/src/core/scew/xparser.c @ 5673

Last change on this file since 5673 was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/**
2 *
3 * @file     xparser.c
4 * @author   Aleix Conchillo Flaque <aleix@member.fsf.org>
5 * @date     Tue Dec 03, 2002 00:21
6 * @brief    SCEW private parser type declaration
7 *
8 * $Id: xparser.c,v 1.2 2004/05/25 20:23:05 aleix Exp $
9 *
10 * @if copyright
11 *
12 * Copyright (C) 2002, 2003, 2004 Aleix Conchillo Flaque
13 *
14 * SCEW is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SCEW is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
27 *
28 * @endif
29 */
30
31#include "xparser.h"
32
33#include "xerror.h"
34#include "xhandler.h"
35
36#include <assert.h>
37
38unsigned int
39init_expat_parser(scew_parser* parser)
40{
41    assert(parser != NULL);
42
43    parser->parser = XML_ParserCreate(NULL);
44    if (parser->parser == NULL)
45    {
46        set_last_error(scew_error_no_memory);
47        return 0;
48    }
49
50    /* initialize Expat handlers */
51    XML_SetXmlDeclHandler(parser->parser, xmldecl_handler);
52    XML_SetElementHandler(parser->parser, start_handler, end_handler);
53    //
54    // commented out the line below because when using the
55    // CharacterData Handler, expat replaces all entity references like,
56    // &lt; and &gt;, with their equivalent translation. in this case,
57    // actual '<' and '>' are placed in the xml file. to get around this,
58    // XML_SetCharacterDataHandler was replaced with XML_SetDefaultHandler
59    // the translation will be done when by the end user of this library.
60    // dsk 20060402
61    //
62    // XML_SetCharacterDataHandler(parser->parser, char_handler);
63    XML_SetDefaultHandler(parser->parser, char_handler);
64    XML_SetUserData(parser->parser, parser);
65
66    return 1;
67}
68
69stack_element*
70stack_push(stack_element** stack, scew_element* element)
71{
72    stack_element* new_elem = (stack_element*) calloc(1, sizeof(stack_element));
73
74    if (new_elem != NULL)
75    {
76        new_elem->element = element;
77        if (stack != NULL)
78        {
79            new_elem->prev = *stack;
80        }
81        *stack = new_elem;
82    }
83
84    return new_elem;
85}
86
87scew_element*
88stack_pop(stack_element** stack)
89{
90    scew_element* element = NULL;
91    stack_element* sk_elem = NULL;
92
93    if (stack != NULL)
94    {
95        sk_elem = *stack;
96        if (sk_elem != NULL)
97        {
98            *stack = sk_elem->prev;
99            element = sk_elem->element;
100            free(sk_elem);
101        }
102    }
103
104    return element;
105}
Note: See TracBrowser for help on using the repository browser.