23a0882000-08-12Martin Stjernholm //! 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.
26ff092000-01-21Martin Stjernholm //! //! 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 //!
252e9c2001-03-01Martin Stjernholm //! $Id: utils.pmod,v 1.15 2001/03/01 03:12:57 mast Exp $
26ff092000-01-21Martin Stjernholm  array return_zero (mixed... ignored) {return 0;} array return_empty_array (mixed... ignored) {return ({});}
ea3bfd2000-02-13Martin Stjernholm 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);
5ed0132000-02-13Martin Stjernholm  RXML.parse_error ("Free text %O is not allowed in this context.\n", str);
ea3bfd2000-02-13Martin Stjernholm  } return ({}); }
9265b52000-02-11Martin Stjernholm int(1..1)|string|array unknown_tag_error (Parser.HTML p, string str) {
5ed0132000-02-13Martin Stjernholm  RXML.parse_error ("Unknown tag %O. Unknown tags are not " "allowed in this context.\n", p->tag_name());
9265b52000-02-11Martin Stjernholm  return ({}); }
f9dcf62000-02-13Martin Stjernholm 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}); }
26ff092000-01-21Martin Stjernholm 
9f74bb2000-02-15Martin Stjernholm // PXml and PEnt callbacks.
26ff092000-01-21Martin Stjernholm 
b1c1d32000-03-06Martin Stjernholm 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. {
5eef022000-03-06Martin Stjernholm  string name = p->parse_tag_name (str);
b1c1d32000-03-06Martin Stjernholm  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 : ({}); }
f9dcf62000-02-13Martin Stjernholm int(1..1)|string|array p_xml_entity_cb (Parser.HTML p, string str)
26ff092000-01-21Martin Stjernholm { string entity = p->tag_name(); if (sizeof (entity)) {
d3b7262000-02-12Martin Stjernholm  if (entity[0] != '#')
b8e84a2000-03-04Martin Stjernholm  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_text : p->type);
252e9c2001-03-01Martin Stjernholm  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.
26ff092000-01-21Martin Stjernholm  } }
6efe862000-05-03Martin Stjernholm  if (!p->type->free_text) RXML.parse_error ("Unknown entity &%s; not allowed in this context.\n", entity); return 0;
26ff092000-01-21Martin Stjernholm }
9f74bb2000-02-15Martin Stjernholm int(1..1)|string|array p_xml_compat_entity_cb (Parser.HTML p, string str)
26ff092000-01-21Martin Stjernholm { string entity = p->tag_name();
b8e84a2000-03-04Martin Stjernholm  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_text : p->type);
6efe862000-05-03Martin Stjernholm  if (!p->type->free_text) RXML.parse_error ("Unknown entity &%s; not allowed in this context.\n", entity); return 0;
26ff092000-01-21Martin Stjernholm }