1 /* XMLPPM: an XML compressor
2 Copyright (C) 2003 James Cheney
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 Contacting the author:
19 James Cheney
20 Computer Science Department
21 Cornell University
22 Ithaca, NY 14850
23
24 jcheney@cs.cornell.edu
25 */
26
27 /* xmlmodel.c: maintains compression state of XML compressor */
28
29 #include <stdio.h>
30 #include <expat.h>
31 #include <string.h>
32 #include "XmlModel.h"
33
34
35
xml_state()36 xml_state::xml_state()
37 {
38 /* I think this should work without the -1, but apparently there was an off by one bug here. */
39 elts = new StringArray (MAXELTS-1);
40 atts = new StringArray (MAXATTS-1);
41 nots = new StringArray (MAXNOTS-1);
42 ents = new StringArray (MAXENTS-1);
43
44 elTop = NULL;
45 char_state = cs_none;
46 depth = 0;
47 hasDtd = 0;
48 hasDecl = 0;
49 lastAttlistElt = NULL;
50 standalone = 1;
51 }
52
53 void
pushElStack(xml_state * state,int elt)54 pushElStack (xml_state * state, int elt)
55 {
56 elStackNode *newtop = (elStackNode *) malloc (sizeof (elStackNode));
57 newtop->next = state->elTop;
58 state->elTop = newtop;
59 state->elTop->elem = elt;
60 }
61
62 void
popElStack(xml_state * state)63 popElStack (xml_state * state)
64 {
65 elStackNode *oldtop = state->elTop;
66 state->elTop = oldtop->next;
67 free (oldtop);
68 }
69
70 int
getTopEl(xml_state * state)71 getTopEl (xml_state * state)
72 {
73 return (state->elTop->elem);
74 }
75