diff --git a/tutorial/.cvsignore b/tutorial/.cvsignore index f13913f1fb7c6cee8fbdfb2d1954293b416ab64e..b68dc9afd0ab50a28a51e03d7e66fcd5de04561d 100644 --- a/tutorial/.cvsignore +++ b/tutorial/.cvsignore @@ -1,7 +1,3 @@ -lenna-mirrorx.gif -lenna-mirrory.gif -lenna-rotate.gif -lenna-skewx.gif -lenna-skewy.gif -lenna.gif tutorial.html +illustration*.gif +___tmp.* diff --git a/tutorial/.gitignore b/tutorial/.gitignore index 81025c1afc7b63aa725b0422f37dcc137f05e0b9..6e7c17b67aad224a3fe6e6bd853156cebd26a9e3 100644 --- a/tutorial/.gitignore +++ b/tutorial/.gitignore @@ -1,7 +1,3 @@ -/lenna-mirrorx.gif -/lenna-mirrory.gif -/lenna-rotate.gif -/lenna-skewx.gif -/lenna-skewy.gif -/lenna.gif /tutorial.html +/illustration*.gif +/___tmp.* diff --git a/tutorial/Makefile b/tutorial/Makefile index 8729d2041e1d25cb209c23e500bd343c099664f9..ac3ecb7e0088a941c3b0eac90f677cab9b55c9f3 100644 --- a/tutorial/Makefile +++ b/tutorial/Makefile @@ -1,4 +1,5 @@ -all: tutorial.html lenna.gif lenna-mirrorx.gif lenna-mirrory.gif lenna-rotate.gif lenna-skewx.gif lenna-skewy.gif +all: tutorial.html +# lenna.gif lenna-mirrorx.gif lenna-mirrory.gif lenna-rotate.gif lenna-skewx.gif lenna-skewy.gif tutorial.html: tutorial.wmml wmml_to_html ./wmml_to_html <tutorial.wmml >tutorial.html diff --git a/tutorial/array.gif b/tutorial/array.gif deleted file mode 100644 index d21670f8f8b78dc9e41d08604791b2443df431bd..0000000000000000000000000000000000000000 Binary files a/tutorial/array.gif and /dev/null differ diff --git a/tutorial/function.gif b/tutorial/function.gif deleted file mode 100644 index 7acf06ec2d92873e0171a54a303b5b6053ce4e5a..0000000000000000000000000000000000000000 Binary files a/tutorial/function.gif and /dev/null differ diff --git a/tutorial/inherit.gif b/tutorial/inherit.gif deleted file mode 100644 index c0d8bf7d440f9716e3c3dc7fe4eba7903eb3ec2e..0000000000000000000000000000000000000000 Binary files a/tutorial/inherit.gif and /dev/null differ diff --git a/tutorial/mapping.gif b/tutorial/mapping.gif deleted file mode 100644 index 3d246fef085cc635fdf9f332177a70dcf2ed2fa1..0000000000000000000000000000000000000000 Binary files a/tutorial/mapping.gif and /dev/null differ diff --git a/tutorial/multiset.gif b/tutorial/multiset.gif deleted file mode 100644 index fe6b0477c7d4ddcde86d03b1d3686ce1b9e372cd..0000000000000000000000000000000000000000 Binary files a/tutorial/multiset.gif and /dev/null differ diff --git a/tutorial/object.gif b/tutorial/object.gif deleted file mode 100644 index 0b461d5938b9a068832eb43e2cd9e3d3267278b7..0000000000000000000000000000000000000000 Binary files a/tutorial/object.gif and /dev/null differ diff --git a/tutorial/program.gif b/tutorial/program.gif deleted file mode 100644 index e111ef462f7b7ae9688e072ee5fafa2c04df1a9e..0000000000000000000000000000000000000000 Binary files a/tutorial/program.gif and /dev/null differ diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml index e691993a47dcf35b322fa528c73ff33e0cd79567..b06379f0eb3d0c0d183787724adec38c77c617b5 100644 --- a/tutorial/tutorial.wmml +++ b/tutorial/tutorial.wmml @@ -63,7 +63,7 @@ examples and explanations about some of the basics. <p> <h2> The history of Pike </h2> -<a name=uLPC> <!-- FIXME replace uLPC with (micro)LPC --> +<a name=uLPC> In the beginning, there was Zork. Then a bunch of people decided to make multiplayer adventure games. One of those people was Lars Pensj� at the Chalmers university in Gothenburg, Sweden. For his game he needed a simple, @@ -75,15 +75,15 @@ dialect called LPC4. LPC4 was still geared towards writing adventure games, but was quite useful for writing other things with as well. A major problem with LPC4 was the copyright. Since it was based on Lars Pensj�'s code, it came with a license that did not allow it to be used for commercial gain. -So, in 1994 I started writing uLPC, which was a new but similar LPC interpreter. -I got financial backing from Signum Support AB for writing uLPC. Signum +So, in 1994 I started writing �LPC, which was a new but similar LPC interpreter. +I got financial backing from Signum Support AB for writing �LPC. Signum is a company dedicated to supporting GNU and GPL software and they wanted to create more GPL software. <p> -When uLPC became usable, Informationsv�varna AB started using it for +When �LPC became usable, Informationsv�varna AB started using it for their webserver. Before then, Roxen (then called Spinner) was non-commercial and written in LPC4. Then in 1996 I started working for Informationsv�varna -developing uLPC for them. We also changed the name of uLPC to Pike to +developing �LPC for them. We also changed the name of �LPC to Pike to get a more commercially viable name. <p> </a> @@ -1029,7 +1029,7 @@ it could look something like this: <pre> do { modem->write("ATDT441-9109\n"); // Dial 441-9109 - } while(modem->gets()[..6]] == "CONNECT"); + } while(modem->gets()[..6]] != "CONNECT"); </pre> This example assumes you have written something that can communicate with the modem by using the functions <tt>write</tt> and <tt>gets</tt>. @@ -1262,7 +1262,7 @@ Also, these functions operates on floats: <dt><tt>float floor(float <i>x</i>)</tt> <dd>This function computes the highest integer value lower or equal to <i>x</i>. -<dt><tt>float ciel(float <i>x</i>)</tt>, +<dt><tt>float ceil(float <i>x</i>)</tt>, <dd>This function computes the lowest integer value higher or equal to <i>x</i>. </dl> </section> @@ -1401,7 +1401,7 @@ which creates a new array. Figure 4.1 shows how the schematics of an array. As you can see, it is a very simple memory structure. <p> <center> -<img src=array.gif><br> +<image xfig=array><br> fig 4.1 </center> <p> @@ -1521,7 +1521,7 @@ What makes mappings special is that they can be indexed on other things than integers. We can imagine that a mapping looks like this: <p> <center> -<img src=mapping.gif><br> +<image xfig=mapping><br> fig 4.2 </center> <p> @@ -1613,7 +1613,7 @@ A multiset is almost the same thing as a mapping. The differance is that there are no values: <p> <center> -<img src=multiset.gif><br> +<image xfig=multiset><br> fig 4.3 </center> <p> @@ -1648,7 +1648,7 @@ space needed to execute the code in the program is stored in an <tt>object</tt> which is the next data type we will discuss. <p> <center> - <img src=program.gif><br> + <image xfig=program><br> fig 4.4 </center> Writing a <tt>program</tt> is easy, in fact, every example we have tried so @@ -1767,7 +1767,7 @@ with a reference to the program from which it was cloned. Many objects can be made from one program. The <tt>program</tt> outlines where in the object different variables are stored. <center> - <img src=object.gif><br> + <image xfig=object><br> fig 4.5 </center> Each object has its own set of variables, and when calling a function in that @@ -1861,7 +1861,7 @@ When indexing an object on a string, and that string is the name of a function in the object a <tt>function</tt> is returned. Despite is name, a <tt>function</tt> is really a <b>function pointer</b>. <center> - <img src=function.gif><br> + <image xfig=function><br> fig 4.6 </center> @@ -2745,7 +2745,9 @@ in front of the function name. The argument to inherit can be one of the followi Let's look at an example. We'll split up an eariler example into three parts and let each inherit the previous part. It would look something like this: -<img src=inherit.gif> +<center> +<image xfig=inherit><br> +</center> Note that the actual code is not copied, only the list of references. Also note that the list of inherits is copied when you inherit a program this does not mean you can access those copied inherit with the <tt>::</tt> @@ -9228,7 +9230,7 @@ prints. </chapter> -<a name=#Image> +<a name=Image> <chapter title="The Image module"> The Image module is used to manipulate bit-mapped color images. It can read PPM images and do various manipulations, or it can be @@ -10562,7 +10564,7 @@ the new image object <dt><encaps>DESCRIPTION</encaps><dd> mirrors an image: <center> -<img align=center src=lenna.gif> -> <img align=center src=lenna-mirrorx.gif><br> +<image src=lenna.rs dpi=225 align=center> -> <illustration align=center src=lenna.rs dpi=225>return src->mirrorx();</illustration><br> </center> </p> <dt><encaps>RETURNS</encaps><dd> @@ -10582,7 +10584,7 @@ the new image object <dt><encaps>DESCRIPTION</encaps><dd> mirrors an image: <center> -<img align=center src=lenna.gif> -> <img align=center src=lenna-mirrory.gif><br> +<image src=lenna.rs dpi=225 align=center> -> ;<illustration align=center src=lenna.rs dpi=225>return src->mirrory();</illustration><br> </center> </p> </dl> @@ -10818,7 +10820,7 @@ object rotate_expand(int|float angle, int r, int g, int b)</ Rotates an image a certain amount of degrees (360� is a complete rotation) counter-clockwise: <center> -<img align=center src=lenna.gif> -> <img align=center src=lenna-rotate.gif><br> +<image src=lenna.rs dpi=225 align=center> -> <illustration align=center src=lenna.rs dpi=225>return src->rotate(45)</illustration><br> </center> The "expand" variant of functions stretches the image border pixels rather then filling with @@ -11011,7 +11013,7 @@ object skewx_expand(int yfactor, int r, int g, int b)</tt> Skews an image an amount of pixels or a factor; a skew-x is a transformation: <center> -<img align=center src=lenna.gif> -> <img align=center src=lenna-skewx.gif><br> +<image src=lenna.rs dpi=225 align=center> -> <illustration align=center src=lenna.rs dpi=225>return src->skewx(0.3)</illustration><br> </center> </p> <dt><encaps>ARGUMENTS</encaps><dd><dl> @@ -11055,7 +11057,7 @@ object skewy_expand(int xfactor, int r, int g, int b)</tt> Skews an image an amount of pixels or a factor; a skew-y is a transformation: <center> -<img align=center src=lenna.gif> -> <img align=center src=lenna-skewy.gif><br> +<image src=lenna.rs dpi=225 align=center> -> <illustration align=center src=lenna.rs dpi=225>return src->skewy(0.3)</illustration><br> </center> The "expand" variant of functions stretches the image border pixels rather then filling with diff --git a/tutorial/wmml_to_html b/tutorial/wmml_to_html index 31bdc6ebcab93651bf52656b1a16a731537c4cdd..eb5717c171de3ce60b2402ea669888a46022b790 100755 --- a/tutorial/wmml_to_html +++ b/tutorial/wmml_to_html @@ -15,11 +15,30 @@ string *srt(string *foo) return foo; } +string quote_param(string s) +{ + string ret=""; + while(sscanf(s,"%[-a-zA-Z0-9/()*,.]%c%s",string a, int c,s)==3) + ret+=sprintf("%s%%02x",a,c); + + return ret+s; +} + +string unquote_param(string s) +{ + string *tmp=s/"%"; + for(int e=1;e<sizeof(tmp);e++) + if(sscanf(tmp[e],"%2x%s",int x, string rest)) + tmp[e]=sprintf("%c%s",x,rest); + + return tmp*""; +} + string code_params(mapping s) { string ret=""; foreach(indices(s), string data) - ret+=" "+data+"=\""+s[data]+"\""; + ret+=" "+data+"="+quote_param(s[data]); return ret; } @@ -45,7 +64,7 @@ void _add_to(mapping foo, string bar, string full) void add_to(string bar, string full) { - sscanf(lower_case(bar),"%*[_ ]%c",int c); + sscanf(lower_case(unquote_param(bar)),"%*[_ ]%c",int c); mapping m; if(!(m=links[c])) m=links[c]=([]); _add_to(m, bar, full); @@ -68,7 +87,7 @@ string anchor(mixed a, mixed b, mixed c) return 0; } -string mklink(string lnk) { return "<a href=#"+lnk+">"+lnk+"</a>"; } +string mklink(string lnk) { return "<a href=#"+lnk+">"+unquote_param(lnk)+"</a>"; } string genindex(mapping m, string prefix) { @@ -81,13 +100,15 @@ string genindex(mapping m, string prefix) m_delete(m,0); foreach(srt(indices(m)), string ind) { - if(m[ind][0] && sizeof(m[ind])==1 && sizeof(m[ind][0])==1 && + if(m[ind][0] && + sizeof(m[ind])==1 && + sizeof(m[ind][0])==1 && m[ind][0][0]==prefix+ind) { foreach(srt(m[ind][0]), string lnk) ret+="<dt>"+mklink(lnk)+"\n"; }else{ - ret+="<dt>"+prefix+ind+"\n"+ + ret+="<dt>"+unquote_param(prefix+ind)+"\n"+ "<dd>\n"+ genindex(m[ind], prefix+ind+"."); } @@ -269,23 +290,113 @@ string box(string tag, mapping params, string data) "</table></center>\n"; } +string do_include(string tag, mapping params, string data) +{ + return Stdio.read_file(params->file); +} + +string end_img_tag(string ret, mapping params) +{ + if(params->align) ret+=" align="+quote_param(params->align); + if(params->alt) ret+=" alt="+quote_param(params->align); + + return ret+">"; +} + +int gifnum; +mapping gifcache=([]); + +string mkgif(object o) +{ + string g=o->togif(); + if(gifcache[g]) return gifcache[g]; + + gifnum++; + string gifname="illustration"+gifnum+".gif"; + rm(gifname); + write_file(gifname,g); + + gifcache[g]=gifname; + return gifname; +} + +mapping gifcache2=([]); + +string illustration(string tag, mapping params, string data) +{ + string src=params->src; + object img=Image.image(); + + float dpi=75.0; + if(params->dpi) dpi=(float)params->dpi; + if(params->scale) dpi/=(float)params->scale; + float scale=75.0/dpi; + + string key=encode_value(({src,scale,data})); + + string file; + if(!(file=gifcache2[key])) + { + if(params->src) img=img->fromppm(Process.popen("anytopnm "+src)); + if(scale!=1.0) img=img->scale(scale); + img=compile_string("object `()(object src){ "+data+" ; }")()(img); + file=mkgif(img); + gifcache2[key]=file; + } + + return end_img_tag("<img src="+file,params); +} + +string image(string tag, mapping params, string data) +{ + string ret; + if(params->xfig) + { + Process.system("fig2dev -L ps "+params->xfig+".fig ___tmp.ps;echo showpage >>___tmp.ps"); + object o=Image.image()->fromppm( + Process.popen("gs -q -sDEVICE=pbmraw -r225 -g2500x2500 -sOutputFile=- ___tmp.ps")); + + o=o->autocrop()->scale(1.0/3)->rotate(-90); + o=Image.image(o->xsize()+40, o->ysize()+40, 255,255,255)->paste(o,20,20); + string gifname=mkgif(o); + rm("___tmp.ps"); + ret="<img src="+quote_param(gifname); + } + else if(params->src) + { + return illustration(tag,params,"return src"); + } + else + { + return ""; + werror("Unknown image type\n"); + } + + return end_img_tag(ret,params); +} + int main() { - string data=stdin->read(0x7fffffff); + string data=Stdio.stdin.read(0x7fffffff); data+="\n<!--END-->"; + /* Preprocess */ + data=parse_html(data,(["include":do_include]),([])); + /* Pass 1, find links for the index */ - string data=parse_html(data, ([]) , (["a":anchor])); + data=parse_html(data, ([]) , (["a":anchor])); /* Pass 2, parse chapters and sections */ - string data=parse_html(data, ([]) , TAGS); + data=parse_html(data, ([]) , TAGS); /* Build index */ string index="<dl>\n"; foreach(sort(indices(links)), int letter) { - index+="<dt><font size=+2>"+upper_case(sprintf("%c",letter))+"</font>\n"+ + index+="<dt><font size=+2>"+ + (letter=='`'?"Operators": upper_case(sprintf("%c",letter)))+ + "</font>\n"+ "<dd>\n"+ genindex(links[letter],""); } @@ -303,10 +414,12 @@ int main() "index":do_replace, "table-of-contents":do_replace, "link":link, + "image":image, ]), ([ "box":box, "encaps":encaps, + "illustration":illustration, ]))); }