1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
//! Things that belong elsewhere but can't lie there for various silly 
//! reasons. Everything here is considered internal and not part of 
//! the RXML.pmod API. 
//! 
//! E.g. one reason is to avoid circular references in the parser 
//! objects when the callbacks are defined in them. 
//! 
//! Created 2000-01-21 by Martin Stjernholm 
//! 
//! $Id: utils.pmod,v 1.19 2001/03/23 22:49:43 mast Exp $ 
 
 
array return_zero (mixed... ignored) {return 0;} 
array return_empty_array (mixed... ignored) {return ({});} 
 
int(1..1)|string|array free_text_error (Parser.HTML p, string str) 
{ 
  sscanf (str, "%[ \t\n\r]", string ws); 
  if (str != ws) { 
    sscanf (reverse (str), "%*[ \t\n\r]%s", str); 
    sscanf (reverse (str), "%*[ \t\n\r]%s", str); 
    RXML.parse_error ("Free text %O is not allowed in %s context.\n", str, p->type->name); 
  } 
  return ({}); 
} 
 
int(1..1)|string|array unknown_tag_error (Parser.HTML p, string str) 
{ 
  RXML.parse_error ("Unknown tag %O. Unknown tags are not " 
                    "allowed in %s context.\n", p->tag_name(), p->type->name); 
  return ({}); 
} 
 
int(1..1)|string|array output_error_cb (Parser.HTML p, string str) 
{ 
  if (p->errmsgs) str = p->errmsgs + str, p->errmsgs = 0; 
  if (p->type->free_text) p->_set_data_callback (0); 
  else p->_set_data_callback (free_text_error); 
  return ({str}); 
} 
 
 
// PXml and PEnt callbacks. 
 
int(1..1)|string|array p_xml_comment_cb (Parser.HTML p, string str) 
// FIXME: This is a kludge until quote tags are handled like other tags. 
{ 
  string name = p->parse_tag_name (str); 
  if (sizeof (name)) { 
    name = p->tag_name() + name; 
    if (string|array|function tdef = p->tags()[name]) { 
      if (stringp (tdef)) 
        return ({tdef}); 
      else if (arrayp (tdef)) 
        return tdef[0] (p, p->parse_tag_args (str), @tdef[1..]); 
      else 
        return tdef (p, p->parse_tag_args (str)); 
    } 
    else if (p->containers()[name]) 
      RXML.parse_error ("Sorry, can't handle containers beginning with " + 
                        p->tag_name() + ".\n"); 
  } 
  return p->type->free_text ? 0 : ({}); 
} 
 
int(1..1)|string|array p_xml_entity_cb (Parser.HTML p, string str) 
{ 
  string entity = p->tag_name(); 
  if (sizeof (entity)) { 
    if (entity[0] != '#') 
      return p->handle_var (entity, 
                            p->html_context() == "splice_arg" ? 
                            // No quoting of splice args. FIXME: Add 
                            // some sort of safeguard against splicing 
                            // in things like "nice><evil stuff='...'"? 
                            RXML.t_string : 
                            p->type); 
    if (!p->type->entity_syntax) { 
      // Don't decode normal entities if we're outputting xml-like stuff. 
      if (!p->type->free_text) 
        RXML.parse_error ("Unknown entity &%s; not allowed in this context.\n", entity); 
      if (sscanf (entity, 
                  (<"#x", "#X">)[entity[..1]] ? "%*2s%x%*c" : "%*c%d%*c", 
                  int char) == 2) 
        catch {return ({(string) ({char})});}; 
      // Lax error handling: Just let it through if it can't be 
      // converted. Not really good, though. 
    } 
  } 
  if (!p->type->free_text) 
    RXML.parse_error ("Unknown entity &%s; not allowed in this context.\n", entity); 
  return 0; 
} 
 
int(1..1)|string|array p_xml_compat_entity_cb (Parser.HTML p, string str) 
{ 
  string entity = p->tag_name(); 
  if (sizeof (entity) && entity[0] != '#') 
    return p->handle_var (entity, 
                          p->html_context() == "splice_arg" ? 
                          // No quoting of splice args. FIXME: Add 
                          // some sort of safeguard against splicing 
                          // in things like "nice><evil stuff='...'"? 
                          RXML.t_string : 
                          p->type); 
  if (!p->type->free_text) 
    RXML.parse_error ("Unknown entity &%s; not allowed in this context.\n", entity); 
  return 0; 
}