diff --git a/tutorial/Wmml.pmod b/tutorial/Wmml.pmod index dc3d508015d1928716943d857c7ffd2dde728666..b43883d74fa14aa221a53d24648a7627effcef99 100644 --- a/tutorial/Wmml.pmod +++ b/tutorial/Wmml.pmod @@ -68,6 +68,9 @@ static private int verify_any(SGML data, string in) case "man_bugs": case "man_example": case "man_title": + case "man_arguments": + case "man_returns": + case "man_note": case "ex_identifier": case "ex_keyword": @@ -75,6 +78,10 @@ static private int verify_any(SGML data, string in) case "ex_comment": case "ex_meta": case "example": + + case "aargdesc": + case "aarg": + case "adesc": if(!x->data) { werror("Tag "+x->tag+" not closed near "+x->location()+".\n"); @@ -353,11 +360,6 @@ object(Tag) parse_pike_code(string x, return Tag("example",([]),pos,ret); } -string name_to_link(string x) -{ - return replace(x,({"->","->"}),({".","."})); -} - class Wmml { SGML metadata; @@ -444,6 +446,19 @@ object(Enumerator) chapterE; object(Stacker) classbase; object(TocBuilder) toker; +string name_to_link(string x) +{ + return replace(x,({"->","->"}),({".","."})); +} + +string name_to_link_exp(string x) +{ + x=name_to_link(x); + if (search(x,".")==-1) + x=classbase->query()+"."+x; + return x; +} + SGML fix_anchors(TAG t) { TAG ret=t; @@ -517,10 +532,10 @@ SGML low_make_concrete_wmml(SGML data) foreach(data, TAG tag) { - if(stringp(tag)) + if (stringp(tag)) { ret+=({tag}); - }else{ + }else if (objectp(tag)) { switch(tag->tag) { case "index": @@ -602,8 +617,12 @@ SGML low_make_concrete_wmml(SGML data) case "class": case "module": - ret+=fix_class(tag, tag->params->name); - continue; + { + string name=tag->params->name; + sscanf(name,classbase->query()+"%*[.->]%s",name); + ret+=fix_class(tag, name); + continue; + } case "man_syntax": case "man_example": @@ -611,6 +630,10 @@ SGML low_make_concrete_wmml(SGML data) case "man_bugs": case "man_description": case "man_see": + + case "man_arguments": + case "man_returns": + case "man_note": { string title=tag->tag; SGML args=tag->data; @@ -630,7 +653,11 @@ SGML low_make_concrete_wmml(SGML data) foreach(replace(get_text(args),({" ","\n"}),({"",""}))/",",string name) { tmp+=({ - Tag("link",(["to":name_to_link(name)]),tag->pos, + Tag("link",(["to": + (tag->params->exp + ?name_to_link_exp + :name_to_link)(name)]), + tag->pos, ({ Tag("tt",([]),tag->pos,({name})), })), @@ -644,6 +671,17 @@ SGML low_make_concrete_wmml(SGML data) args=tmp; break; } + case "arguments": + // insert argument parsing here + // format: + // <aargdesc><aarg>int foo</aarg><aarg>int bar</aarg>... + // ...<adesc>description</adesc></aargdesc> + // 'desc' is formatted description text. + // 'arg' may contain <alink to...> tags + + args=({Tag("arguments",([]),tag->pos,tag->data)}); + + break; } title=upper_case(title); ret+=low_make_concrete_wmml( @@ -656,38 +694,50 @@ SGML low_make_concrete_wmml(SGML data) case "method": case "function": { - string fullname; - switch(tag->tag) - { - case "method": - fullname=classbase->query()+"->"+tag->params->name; - break; - case "function": - fullname=classbase->query()+"."+tag->params->name; - break; - } - ret+=low_make_concrete_wmml(({ - Tag("anchor",(["name":name_to_link(fullname), - "type":"method",]),tag->pos, - ({ - Tag("dl",([]),tag->pos, - ({ - Tag("man_title",(["title":upper_case(tag->tag)]),tag->pos, - ({ - Tag("tt",([]),tag->pos,({fullname})), - " - ", - tag->params->title, - }) - ) - }) - + - tag->data - ) - })), - "\n", - Tag("hr"), - })); - continue; + array anchors=({}),fullnames=({}); + + foreach (replace(tag->params->name,">",">")/",", + string name) + { + string fullname; + if (name[0..strlen(classbase->query())-1]== + classbase->query()) + fullname=name; + else switch(tag->tag) + { + case "method": + fullname=classbase->query()+"->"+name; + break; + case "function": + fullname=classbase->query()+"."+name; + break; + } + anchors+=({name_to_link(fullname)}); + fullnames+=({fullname}); + } + array res= + ({Tag("dl",([]),tag->pos, + ({Tag("man_title",(["title":upper_case(tag->tag)]), + tag->pos, + Array.map( + fullnames, + lambda(string name,int pos) + { return ({Tag("tt",([]),pos,({name}))}); }, + tag->pos) + *({ ",", Tag("br") }) + +({ (tag->params->title + ?" - "+tag->params->title + :"")})) + }) + tag->data ) }); + + foreach (anchors,string anchor) + res=({Tag("anchor",(["name":anchor]), + tag->pos,res)}); + + ret+= + ({Tag(tag->tag,(["name":fullnames*","]),tag->pos, + low_make_concrete_wmml(res))}); + continue; } case "example": @@ -725,6 +775,9 @@ SGML low_make_concrete_wmml(SGML data) low_make_concrete_wmml(tag->data), tag->file)}); } + else + throw(({"Tag or contents has illegal type: "+sprintf("%O\n",tag), + backtrace()})); } return ret; } diff --git a/tutorial/html.pike b/tutorial/html.pike index f0a208e776f2852c353ab5d096ecd2982197455e..c4261510f9ef7e4718a36e591dde00107d2cbab4 100644 --- a/tutorial/html.pike +++ b/tutorial/html.pike @@ -299,22 +299,22 @@ SGML convert(SGML data) cpos=data->pos; switch(data->tag) { - case "hr": - data->params->noshade=1; - data->params->size="1"; - break; + case "hr": + data->params->noshade=1; + data->params->size="1"; + break; - case "man_title": - ret+=convert(({ - Sgml.Tag("p"), - "\n", - Sgml.Tag("dt"), - Sgml.Tag("encaps",([]),data->pos, ({data->params->title})), - "\n", - Sgml.Tag("dd"), - })+data->data+ ({ "\n" })); - continue; + case "man_title": + ret+=convert(({ + Sgml.Tag("p"), + "\n", + Sgml.Tag("dt"), + Sgml.Tag("encaps",([]),data->pos, ({data->params->title})), + "\n", + Sgml.Tag("dd"), + })+data->data+ ({ "\n" })); + continue; case "link": { @@ -331,197 +331,255 @@ SGML convert(SGML data) break; } } + + case "arguments": + ret+=convert(({ + Sgml.Tag( + "table",(["border":"1","cellspacing":"0"]),data->pos, + ({Sgml.Tag( + "tr",([]),data->pos, + ({Sgml.Tag("td",(["align":"left"]),data->pos, + ({Sgml.Tag("font",(["size":"-2"]), + data->pos,({"argument(s)"}))})), + Sgml.Tag("td",(["align":"left"]),data->pos, + ({Sgml.Tag("font",(["size":"-2"]), + data->pos,({"description"}))}))}))})+ + data->data) + })); + continue; + + case "aargdesc": + ret+=convert(({Sgml.Tag("tr",([]),data->pos, + ({Sgml.Tag("td")})+data->data)})); + continue; + case "adesc": + ret+=convert(({Sgml.Tag("td",([]),data->pos,data->data)})); + continue; + case "aarg": + ret+=convert(({Sgml.Tag("tt",([]),data->pos,data->data), + Sgml.Tag("br")})); + continue; + + case "link": + { + data->tag="a"; + string to=data->params->to; + m_delete(data->params,"to"); + if(!link_to_page[to]) + { + string s=(to/".")[-1]; + if (link_to_page[s]) + to=s; + else + { + werror("Warning: Cannot find link "+to + +" (near "+data->location()+")\n"); + data->tag="anchor"; + break; + } + } + data->params->href=mklinkname(link_to_page[to])+"#"+to; + break; + } - case "ref": - { - string to=data->params->to; - TAG t2=link_to_data[to]; - if(!t2) - { - werror("Warning: Cannot find ref "+to+" (near "+data->location()+")\n"); - } - if(t2) - data->data=({t2->tag+" "+t2->params->number+" \""+t2->params->title+"\""}); - else - data->data=({"unknown"}); - data->tag="a"; - data->params->href=mklinkname(link_to_page[to])+"#"+to; - break; - } + case "ref": + { + string to=data->params->to; + TAG t2=link_to_data[to]; + if(!t2) + { + werror("Warning: Cannot find ref "+to+" (near "+data->location()+")\n"); + } + if(t2) + data->data=({t2->tag+" "+t2->params->number+" \""+t2->params->title+"\""}); + else + data->data=({"unknown"}); + data->tag="a"; + data->params->href=mklinkname(link_to_page[to])+"#"+to; + break; + } - case "anchor": - data->tag="a"; - break; + case "anchor": + data->tag="a"; + break; - case "ex_identifier": - case "ex_string": - case "ex_commend": - ret+=convert(data->data); - continue; + case "ex_identifier": + case "ex_string": + case "ex_commend": + ret+=convert(data->data); + continue; - case "example": data->tag="blockquote";break; - case "ex_keyword": data->tag="b";break; - case "ex_meta": data->tag="i";break; - case "ex_br": data->tag="br"; break; + case "example": data->tag="blockquote";break; + case "ex_keyword": data->tag="b";break; + case "ex_meta": data->tag="i";break; + case "ex_br": data->tag="br"; break; - case "ex_indent": - ret+=({" "}); - continue; + case "ex_indent": + ret+=({" "}); + continue; - case "table-of-contents": - { - SGML tmp=html_toc; - if(data->params->target) - { - werror("(targeting)"); - tmp=Sgml.copy(tmp); - add_target_to_links(tmp,data->params->target); - } - ret+=({ - Sgml.Tag("h1",([]),data->pos, - ({ - data->title || "Table of contents", - })) + case "table-of-contents": + { + SGML tmp=html_toc; + if(data->params->target) + { + werror("(targeting)"); + tmp=Sgml.copy(tmp); + add_target_to_links(tmp,data->params->target); + } + ret+=({ + Sgml.Tag("h1",([]),data->pos, + ({ + data->title || "Table of contents", + })) })+convert(tmp); - continue; - } + continue; + } - case "index": - ret+=({ - Sgml.Tag("h1",([]),data->pos, - ({ - data->title || "Index", - })) + case "index": + ret+=({ + Sgml.Tag("h1",([]),data->pos, + ({ + data->title || "Index", + })) })+convert(html_index); - continue; - - case "preface": - case "introduction": - ret+= - ({ - Sgml.Tag("h1",([]),data->pos, - ({ - data->params->title, - })), - "\n", - })+ - convert(data->data); - continue; + continue; - case "chapter": - ret+= - ({ - Sgml.Tag("h1",([]),data->pos, - ({ - "Chapter ", - data->params->number, - ", ", - data->params->title, - })), - "\n", - })+ - convert(data->data); - continue; + case "preface": + case "introduction": + ret+= + ({ + Sgml.Tag("h1",([]),data->pos, + ({ + data->params->title, + })), + "\n", + })+ + convert(data->data); + continue; + + case "chapter": + ret+= + ({ + Sgml.Tag("h1",([]),data->pos, + ({ + "Chapter ", + data->params->number, + ", ", + data->params->title, + })), + "\n", + })+ + convert(data->data); + continue; - case "appendix": - ret+=({ - Sgml.Tag("h1",([]),data->pos, - ({ - "Appendix ", - data->params->number, - ", ", - data->params->title, - })), - "\n" + case "appendix": + ret+=({ + Sgml.Tag("h1",([]),data->pos, + ({ + "Appendix ", + data->params->number, + ", ", + data->params->title, + })), + "\n" })+ - convert(data->data) - ; - continue; - - case "section": - { - string *tmp=data->params->number/"."; - int level=sizeof(tmp); - switch(tmp[0]) - { - case "introduction": - case "preface": - ret+=({ - Sgml.Tag("h"+level,([]),data->pos, - ({ - data->params->title, - })), - "\n" - })+ - convert(data->data) - ; - continue; + convert(data->data) + ; + continue; + + case "section": + { + string *tmp=data->params->number/"."; + int level=sizeof(tmp); + switch(tmp[0]) + { + case "introduction": + case "preface": + ret+=({ + Sgml.Tag("h"+level,([]),data->pos, + ({ + data->params->title, + })), + "\n" + })+ + convert(data->data) + ; + continue; - default: - ret+=({ - Sgml.Tag("h"+level,([]),data->pos, - ({ - data->params->number, - " ", - data->params->title, - })), - "\n" - })+ - convert(data->data) - ; - continue; - } - } + default: + ret+=({ + Sgml.Tag("h"+level,([]),data->pos, + ({ + data->params->number, + " ", + data->params->title, + })), + "\n" + })+ + convert(data->data) + ; + continue; + } + } - case "encaps": - { - SGML t=({}); + case "encaps": + { + SGML t=({}); - foreach(data->data[0]/" "-({""}),string tmp) - { - t+=({ - Sgml.Tag("font",(["size":"+1"]),data->pos,({tmp[0..0]})), - Sgml.Tag("font",(["size":"-1"]),data->pos,({tmp[1..]})), - " " - }); - } + foreach(data->data[0]/" "-({""}),string tmp) + { + t+=({ + Sgml.Tag("font",(["size":"+1"]),data->pos,({tmp[0..0]})), + Sgml.Tag("font",(["size":"-1"]),data->pos,({tmp[1..]})), + " " + }); + } - ret+=({ Sgml.Tag("b",([]),data->pos,t) }); - continue; - } + ret+=({ Sgml.Tag("b",([]),data->pos,t) }); + continue; + } - case "img": - add_file_to_export_list(data->params->src); - break; + case "img": + add_file_to_export_list(data->params->src); + break; - case "illustration": - ret+=({ mkimgtag(Wmml.illustration_to_gif(data,75.0),data->params) }); - continue; + case "illustration": + ret+=({ mkimgtag(Wmml.illustration_to_gif(data,75.0),data->params) }); + continue; - case "image": - ret+=({ mkimgtag(Wmml.image_to_gif(data,75.0),data->params) }); - continue; + case "image": + ret+=({ mkimgtag(Wmml.image_to_gif(data,75.0),data->params) }); + continue; - case "box": - ret+=({ - Sgml.Tag("table", - (["cellpadding":"10", - "width":"100%", - "border":"1", - "cellspacing":"0"]),data->pos, - ({ - "\n", - Sgml.Tag("tr",([]),data->pos, - ({ - Sgml.Tag("td",([]),data->pos, - convert(data->data)) - })) - })), - "\n", + case "box": + ret+=({ + Sgml.Tag("table", + (["cellpadding":"10", + "width":"100%", + "border":"1", + "cellspacing":"0"]),data->pos, + ({ + "\n", + Sgml.Tag("tr",([]),data->pos, + ({ + Sgml.Tag("td",([]),data->pos, + convert(data->data)) + })) + })), + "\n", }); - continue; + continue; + + case "method": + case "function": + case "class": + case "module": + // strip this metainformation + ret+=convert(data->data); + continue; } data->data=convert(data->data); ret+=({data}); diff --git a/tutorial/man.pike b/tutorial/man.pike new file mode 100644 index 0000000000000000000000000000000000000000..8e9cc7d20fbf20fadd1f4e94942edbfc537e7143 --- /dev/null +++ b/tutorial/man.pike @@ -0,0 +1,27 @@ +#include "types.h" +inherit Stdio.File : out; + +void make_pages(string base, SGML data, string ind); + +void make_page(string base, TAG tag, string ind, string fbase) +{ + ind=""; + werror(ind+tag->tag+" "+tag->params->name+"\n"); + make_pages(base,tag->data,ind+" "); +} + +void make_pages(string base, SGML data, string ind, string fbase) +{ + if (arrayp(data)) + foreach (data, TAG tag) + if (objectp(tag)) + if ((<"method","function","class","module">)[tag->tag]) + make_page(base,tag,ind); + else + make_pages(base,tag->data,ind+" "); +} + +void output(string base, WMML data) +{ + make_pages(base,data->data,"",""); +} diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml index bc40baad665ea7bf3adb8cc1a08d3de57b5277d8..3556bf8c77b63f49424078594ba8d43640c9fd51 100644 --- a/tutorial/tutorial.wmml +++ b/tutorial/tutorial.wmml @@ -5407,7 +5407,7 @@ Let's look at an example of how this can be used: object font=Image.font(); font->load("testfont"); object image=font->write(ctime(time)); - write(image->togif()); + write(Image.GIF.encode(image)); } </example> This very simple example can be used as a CGI script to produce a gif image