Debian lenny version packages
[pkg-perl] / deb-src / libhtml-parser-perl / libhtml-parser-perl-3.56 / hparser.h
1 /* $Id: hparser.h,v 2.34 2006/04/26 07:01:10 gisle Exp $
2  *
3  * Copyright 1999-2005, Gisle Aas
4  * Copyright 1999-2000, Michael A. Chase
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the same terms as Perl itself.
8  */
9
10 /*
11  * Declare various structures and constants.  The main thing
12  * is 'struct p_state' that contains various fields to represent
13  * the state of the parser.
14  */
15
16 #ifdef MARKED_SECTION
17
18 enum marked_section_t {
19     MS_NONE = 0,
20     MS_INCLUDE,
21     MS_RCDATA,
22     MS_CDATA,
23     MS_IGNORE
24 };
25
26 #endif /* MARKED_SECTION */
27
28
29 #define P_SIGNATURE 0x16091964  /* tag struct p_state for safer cast */
30
31 enum event_id {
32     E_DECLARATION = 0,
33     E_COMMENT,
34     E_START,
35     E_END,
36     E_TEXT,
37     E_PROCESS,
38     E_START_DOCUMENT,
39     E_END_DOCUMENT,
40     E_DEFAULT,
41     /**/
42     EVENT_COUNT,
43     E_NONE   /* used for reporting skipped text (non-events) */
44 };
45 typedef enum event_id event_id_t;
46
47 /* must match event_id_t above */
48 static char* event_id_str[] = {
49     "declaration",
50     "comment",
51     "start",
52     "end",
53     "text",
54     "process",
55     "start_document",
56     "end_document",
57     "default",
58 };
59
60 struct p_handler {
61     SV* cb;
62     SV* argspec;
63 };
64
65 struct p_state {
66     U32 signature;
67
68     /* state */
69     SV* buf;
70     STRLEN offset;
71     STRLEN line;
72     STRLEN column;
73     bool start_document;
74     bool parsing;
75     bool eof;
76
77     /* special parsing modes */
78     char* literal_mode;
79     bool  is_cdata;
80     bool  no_dash_dash_comment_end;
81     char *pending_end_tag;
82
83     /* unbroken_text option needs a buffer of pending text */
84     SV*    pend_text;
85     bool   pend_text_is_cdata;
86     STRLEN pend_text_offset;
87     STRLEN pend_text_line;
88     STRLEN pend_text_column;
89
90     /* skipped text is accumulated here */
91     SV* skipped_text;
92
93 #ifdef MARKED_SECTION
94     /* marked section support */
95     enum marked_section_t ms;
96     AV* ms_stack;
97     bool marked_sections;
98 #endif
99
100     /* various boolean configuration attributes */
101     bool strict_comment;
102     bool strict_names;
103     bool strict_end;
104     bool xml_mode;
105     bool unbroken_text;
106     bool attr_encoded;
107     bool case_sensitive;
108     bool closing_plaintext;
109     bool utf8_mode;
110     bool empty_element_tags;
111     bool xml_pic;
112
113     /* other configuration stuff */
114     SV* bool_attr_val;
115     struct p_handler handlers[EVENT_COUNT];
116     bool argspec_entity_decode;
117
118     /* filters */
119     HV* report_tags;
120     HV* ignore_tags;
121     HV* ignore_elements;
122
123     /* these are set when we are currently inside an element we want to ignore */
124     SV* ignoring_element;
125     int ignore_depth;
126
127     /* cache */
128     HV* entity2char;            /* %HTML::Entities::entity2char */
129     SV* tmp;
130 };
131 typedef struct p_state PSTATE;
132