Skip to content
Snippets Groups Projects
Commit 5f457702 authored by Mirar (Pontus Hagland)'s avatar Mirar (Pontus Hagland)
Browse files

better error messages

<illustration> Image-module-compatible (import Image)
<wbr> allowed

Rev: tutorial/Sgml.pmod:1.5
Rev: tutorial/Wmml.pmod:1.9
Rev: tutorial/wmml_to_html:1.5
parent 7df5b55c
No related branches found
No related tags found
No related merge requests found
...@@ -128,6 +128,8 @@ SGML group(SGML data) ...@@ -128,6 +128,8 @@ SGML group(SGML data)
if(strlen(foo->tag) && foo->tag[0]=='/') if(strlen(foo->tag) && foo->tag[0]=='/')
{ {
string tag=foo->tag[1..]; string tag=foo->tag[1..];
string t;
if (sscanf(tag,"%[^ \t\r\n>]%*s",t)==2) foo->tag=tag=t;
for(int d=sizeof(ret)-1;d>=0;d--) for(int d=sizeof(ret)-1;d>=0;d--)
{ {
if(objectp(ret[d]) && !ret[d]->data && ret[d]->tag==tag) if(objectp(ret[d]) && !ret[d]->data && ret[d]->tag==tag)
......
...@@ -101,10 +101,11 @@ static private int verify_any(SGML data, string in) ...@@ -101,10 +101,11 @@ static private int verify_any(SGML data, string in)
i=0; i=0;
} }
case "p": case "p":
case "wbr":
} }
if(x->data) if(x->data)
if(!verify_any(x->data," In tag "+x->tag+" near pos "+x->pos+"\n"+in)) if(!verify_any(x->data," In tag "+(x->tag=="anchor"?x->tag+" (name="+x->params->name+")":x->tag)+" near pos "+x->pos+"\n"+in))
i=0; i=0;
} }
} }
...@@ -731,6 +732,7 @@ void save_image_cache(); ...@@ -731,6 +732,7 @@ void save_image_cache();
int gifnum; int gifnum;
mapping gifcache=([]); mapping gifcache=([]);
mapping srccache=([]);
string mkgif(object o) string mkgif(object o)
{ {
...@@ -771,9 +773,13 @@ object render_illustration(string pike_code, mapping params, float dpi) ...@@ -771,9 +773,13 @@ object render_illustration(string pike_code, mapping params, float dpi)
if(params->scale) dpi/=(float)params->scale; if(params->scale) dpi/=(float)params->scale;
float scale=75.0/dpi; float scale=75.0/dpi;
if(params->src) img=img->fromppm(Process.popen("anytopnm 2>/dev/null "+src)); if(params->src)
img=srccache[params->src]||
(srccache[params->src]=
img->fromppm(Process.popen("anytopnm 2>/dev/null "+src)));
if(scale!=1.0) img=img->scale(scale); if(scale!=1.0) img=img->scale(scale);
return compile_string("object `()(object src){ "+pike_code+" ; }")()(img); return compile_string("import Image;\n"
"object `()(object src){ "+pike_code+" ; }")()(img);
} }
private static string mkkey(mapping params, mixed ... other) private static string mkkey(mapping params, mixed ... other)
...@@ -801,9 +807,20 @@ string illustration_to_gif(TAG data, float dpi) ...@@ -801,9 +807,20 @@ string illustration_to_gif(TAG data, float dpi)
string ret=illustration_cache[key]; string ret=illustration_cache[key];
if(!ret) if(!ret)
{ {
ret=mkgif(render_illustration(pike_code,params, dpi)); mixed err=catch
illustration_cache[key]=ret; {
save_image_cache(); ret=mkgif(render_illustration(pike_code,params, dpi));
illustration_cache[key]=ret;
save_image_cache();
};
if (err)
{
werror("error while compiling and running\n"+pike_code+"\n");
if (params->__from__)
werror("from "+params->__from__+":\n");
werror(master()->describe_backtrace(err)+"\n");
return "failed to illustrate...";
}
} }
return ret; return ret;
} }
......
...@@ -84,6 +84,9 @@ string anchor(mixed a, mixed b, mixed c) ...@@ -84,6 +84,9 @@ string anchor(mixed a, mixed b, mixed c)
add_to(foo[e], foo[..e]*"."); add_to(foo[e], foo[..e]*".");
} }
if (a=="anchor")
return "<a name="+b->name+">"+c+"</a name="+b->name+">";
return 0; return 0;
} }
...@@ -276,7 +279,7 @@ string link(string tag, mapping params, string data) ...@@ -276,7 +279,7 @@ string link(string tag, mapping params, string data)
mixed tmp=aliases[params->to]; mixed tmp=aliases[params->to];
if(!tmp) if(!tmp)
{ {
werror("Unlinked <link> :"+params->to+"\n"); werror("Unresolved <link> :"+params->to+"\n");
return 0; return 0;
} }
...@@ -321,6 +324,7 @@ string mkgif(object o) ...@@ -321,6 +324,7 @@ string mkgif(object o)
} }
mapping gifcache2=([]); mapping gifcache2=([]);
mapping srccache=([]);
string illustration(string tag, mapping params, string data) string illustration(string tag, mapping params, string data)
{ {
...@@ -337,11 +341,26 @@ string illustration(string tag, mapping params, string data) ...@@ -337,11 +341,26 @@ string illustration(string tag, mapping params, string data)
string file; string file;
if(!(file=gifcache2[key])) if(!(file=gifcache2[key]))
{ {
if(params->src) img=img->fromppm(Process.popen("anytopnm "+src)); mixed e;
if(params->src)
img=srccache[src] ||
(srccache[src]=img->fromppm(Process.popen("anytopnm "+src)));
if(scale!=1.0) img=img->scale(scale); if(scale!=1.0) img=img->scale(scale);
img=compile_string("object `()(object src){ "+data+" ; }")()(img); if (e=catch
file=mkgif(img); {
gifcache2[key]=file; img=compile_string("import Image;\n"
"object `()(object src){ "+data+" ; }")()(img);
file=mkgif(img);
gifcache2[key]=file;
})
{
werror("error while compiling and running\n"+data+"\n");
if (params->__from__)
werror("from "+params->__from__+":\n");
werror(master()->describe_backtrace(e)+"\n");
return "<!-- failed to illustrate -->";
}
params-=(["__from__":0]);
} }
return end_img_tag("<img src="+file,params); return end_img_tag("<img src="+file,params);
...@@ -385,7 +404,7 @@ int main() ...@@ -385,7 +404,7 @@ int main()
data=parse_html(data,(["include":do_include]),([])); data=parse_html(data,(["include":do_include]),([]));
/* Pass 1, find links for the index */ /* Pass 1, find links for the index */
data=parse_html(data, ([]) , (["a":anchor])); data=parse_html(data, ([]) , (["a":anchor,"anchor":anchor]));
/* Pass 2, parse chapters and sections */ /* Pass 2, parse chapters and sections */
data=parse_html(data, ([]) , TAGS); data=parse_html(data, ([]) , TAGS);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment