26ff092000-01-21Martin Stjernholm //! Things that belong elsewhere but can't lie there for various silly reasons. //! //! 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 //!
9f74bb2000-02-15Martin Stjernholm //! $Id: utils.pmod,v 1.7 2000/02/15 06:10:11 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 
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] != '#') return p->handle_var (entity); if (p->type->quoting_scheme != "xml") { // Don't decode any normal entities if we're outputting xml-like stuff.
26ff092000-01-21Martin Stjernholm  if (!p->type->free_text) return ({}); string out; if ((<"#x", "#X">)[entity[..1]]) { if (sscanf (entity, "%*2s%x%*c", int c) == 2) out = (string) ({c}); } else if (sscanf (entity, "%*c%d%*c", int c) == 2) out = (string) ({c}); return out && ({out}); } } return p->type->free_text ? 0 : ({}); }
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(); if (sizeof (entity) && entity[0] != '#') return p->handle_var (entity); return p->type->free_text ? 0 : ({}); }