23a088 | 2000-08-12 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
6fae20 | 2001-05-19 | Martin Stjernholm | | constant short_format_length = 40;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final string format_short (mixed val)
|
6fae20 | 2001-05-19 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | {
|
6fae20 | 2001-05-19 | Martin Stjernholm | | string res = "";
void format_val (mixed val)
{
if (arrayp (val) || multisetp (val)) {
string end;
if (multisetp (val)) res += "(<", end = ">)", val = indices (val);
else res += "({", end = "})";
if (sizeof (res) >= short_format_length) throw (0);
for (int i = 0; i < sizeof (val);) {
res += format_val (val[i]);
if (++i < sizeof (val) - 1) res += ", ";
if (sizeof (res) >= short_format_length) throw (0);
}
res += end;
}
else if (mappingp (val)) {
res += "([";
if (sizeof (res) >= short_format_length) throw (0);
array ind = sort (indices (val));
for (int i = 0; i < sizeof (ind);) {
res += format_val (ind[i]) + ": ";
if (sizeof (res) >= short_format_length) throw (0);
res += format_val (val[ind[i]]);
if (++i < sizeof (ind) - 1) res += ", ";
if (sizeof (res) >= short_format_length) throw (0);
}
res += "])";
}
else {
if (stringp (val) && sizeof (val) > short_format_length - sizeof (res)) {
sscanf (val, "%[ \t\n\r]", string lead);
if (sizeof (lead) > sizeof ("/.../") && sizeof (lead) < sizeof (val))
val = val[sizeof (lead)..], res += "/.../";
if (sizeof (val) > short_format_length - sizeof (res)) {
res += sprintf ("%O", val[..short_format_length - sizeof (res) - 1]);
throw (0);
}
}
res += sprintf ("%O", val);
}
};
mixed err = catch {
format_val (val);
return res;
};
if (err) throw (err);
return res + "/.../";
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final array return_zero (mixed... ignored) {return 0;}
final array return_empty_array (mixed... ignored) {return ({});}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | final mapping(string:string) return_empty_mapping (mixed... ignored)
{return ([]);}
final mapping(string:string) return_help_arg (mixed... ignored)
{return (["help": "help"]);}
final mixed get_non_nil (RXML.Type type, mixed... vals)
{
int pos = -1;
do
if (++pos == sizeof (vals)) return RXML.nil;
while (vals[pos] == RXML.nil);
mixed res = vals[pos];
for (pos++; pos < sizeof (vals); pos++)
if (vals[pos] != RXML.nil)
RXML.parse_error (
"Cannot append another value %s to non-sequential value of type %s.\n",
format_short (vals[pos]), type->name);
return res;
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
final int(1..1)|string|array free_text_error (object p, string str)
|
ea3bfd | 2000-02-13 | Martin Stjernholm | | {
sscanf (str, "%[ \t\n\r]", string ws);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (str != ws)
RXML.parse_error ("Free text %s is not allowed in context of type %s.\n",
format_short (String.trim_all_whites (str)), p->type->name);
|
ea3bfd | 2000-02-13 | Martin Stjernholm | | return ({});
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array unknown_tag_error (object p, string str)
|
9265b5 | 2000-02-11 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | RXML.parse_error ("Unknown tag %s is not allowed in context of type %s.\n",
format_short (p->tag_name()), p->type->name);
|
9265b5 | 2000-02-11 | Martin Stjernholm | | return ({});
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array unknown_pi_tag_error (object p, string str)
{
sscanf (str, "%[^ \t\n\r]", str);
RXML.parse_error (
"Unknown processing instruction %s not allowed in context of type %s.\n",
format_short ("<" + p->tag_name() + str), p->type->name);
return ({});
}
final int(1..1)|string|array invalid_cdata_error (object p, string str)
{
RXML.parse_error ("CDATA text %O is not allowed in context of type %s.\n",
format_short (str), p->type->name);
return ({});
}
final int(1..1)|string|array output_error_cb (object p, string str)
|
f9dcf6 | 2000-02-13 | Martin Stjernholm | | {
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});
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
9f74bb | 2000-02-15 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_comment_cb (object p, string str)
|
b1c1d3 | 2000-03-06 | Martin Stjernholm | |
{
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (p->type->handle_literals) p->handle_literal();
|
4c7230 | 2001-05-19 | Martin Stjernholm | | else if (p->p_code) p->p_code_literal();
|
5eef02 | 2000-03-06 | Martin Stjernholm | | string name = p->parse_tag_name (str);
|
b1c1d3 | 2000-03-06 | Martin 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 : ({});
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_cdata_cb (object p, string str)
{
return ({str});
}
final int(1..1)|string|array p_xml_entity_cb (object p, string str)
|
26ff09 | 2000-01-21 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | RXML.Type type = p->type;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string entity = p->tag_name();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (sizeof (entity))
if (entity[0] == '#') {
if (!p->type->entity_syntax) {
if (sscanf (entity,
(<"#x", "#X">)[entity[..1]] ? "%*2s%x%*c" : "%*c%d%*c",
int char) == 2)
catch (str = (string) ({char}));
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | else
if (entity[0] == ':') str = entity[1..];
else if (has_value (entity, ".")) {
if (type->handle_literals) p->handle_literal();
|
4c7230 | 2001-05-19 | Martin Stjernholm | | else if (p->p_code) p->p_code_literal();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed value = p->handle_var (
|
4c7230 | 2001-05-19 | Martin Stjernholm | | p,
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | entity,
p->html_context() == "splice_arg" ? RXML.t_string : type);
if (value != RXML.nil) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (type->free_text && !p->p_code) return ({value});
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p->add_value (value);
}
return ({});
}
if (!type->free_text)
RXML.parse_error ("Unknown entity \"&%s;\" not allowed context of type %s.\n",
entity, type->name);
return ({str});
|
26ff09 | 2000-01-21 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_compat_entity_cb (object p, string str)
|
26ff09 | 2000-01-21 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | RXML.Type type = p->type;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string entity = p->tag_name();
|
b8e84a | 2000-03-04 | Martin Stjernholm | | if (sizeof (entity) && entity[0] != '#')
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (entity[0] == ':') str = entity[1..];
else if (has_value (entity, ".")) {
if (type->handle_literals) p->handle_literal();
|
4c7230 | 2001-05-19 | Martin Stjernholm | | else if (p->p_code) p->p_code_literal();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed value = p->handle_var (
|
4c7230 | 2001-05-19 | Martin Stjernholm | | p,
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | entity,
|
4c7230 | 2001-05-19 | Martin Stjernholm | | p->html_context() == "splice_arg" ? RXML.t_string : type);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (value != RXML.nil) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (type->free_text && !p->p_code) return ({value});
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p->add_value (value);
}
return ({});
}
if (!type->free_text)
RXML.parse_error ("Unknown entity \"&%s;\" not allowed in context of type %s.\n",
entity, type->name);
return ({str});
|
26ff09 | 2000-01-21 | Martin Stjernholm | | }
|