From 8ec44da271f0d34c7a80837f4d6528dae7026c26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 17 Sep 1997 19:18:49 -0700
Subject: [PATCH] did some remodeling

Rev: tutorial/Sgml.pmod:1.2
Rev: tutorial/Wmml.pmod:1.4
Rev: tutorial/html.pike:1.5
Rev: tutorial/tutorial.wmml:1.29
---
 tutorial/Sgml.pmod     |  43 ++++++++--
 tutorial/Wmml.pmod     | 181 +++++++++++++++++++++++++++++++++++------
 tutorial/html.pike     | 113 ++-----------------------
 tutorial/tutorial.wmml |   8 +-
 4 files changed, 204 insertions(+), 141 deletions(-)

diff --git a/tutorial/Sgml.pmod b/tutorial/Sgml.pmod
index 4694c9df56..d3e1a51b33 100644
--- a/tutorial/Sgml.pmod
+++ b/tutorial/Sgml.pmod
@@ -11,17 +11,22 @@ class Tag
   mapping(string:mixed) params=([]);
 //  array(Tag) data;
   array(object) data;
+  string file;
 
-  varargs void create(string t, mapping p, int po, array(object) d)
+  varargs void create(string t, mapping p, int po, array(object) d, string f)
   {
-    tag=t; pos=po; params=p||([]); data=d;
+    tag=t;
+    pos=po;
+    params=p||([]);
+    data=d;
+    file=f;
   }
 };
 
 #define TAG object(Tag)|string
 #define SGML array(TAG)
 
-SGML lex(string data)
+SGML lex(string data, string file)
 {
   mixed foo=data/"<";
   SGML ret=({ unquote(foo[0]) });
@@ -46,7 +51,7 @@ SGML lex(string data)
     }
     
     if(sscanf(s,"%[^ \t\n\r>]%s",tag,s)!=2)
-      werror(sprintf("Missing end > (around pos %d)\n",pos));
+      werror(sprintf("Missing end > (around pos %d in %s)\n",pos,file));
 
     tag=lower_case(tag);
     mapping params=([]);
@@ -56,7 +61,7 @@ SGML lex(string data)
       sscanf(s,"%*[ \t\r\n]%s",s);
       if(!strlen(s))
       {
-	write(sprintf("Missing end > (around pos %d)\n",pos));
+	write(sprintf("Missing end > (around pos %d in %s)\n",pos,file));
 	break;
       }
       if(s[0]=='>')
@@ -104,7 +109,7 @@ SGML lex(string data)
       }
     }
 
-    ret+=({ Tag(tag,params,pos), unquote(s) });
+    ret+=({ Tag(tag,params,pos,0,file), unquote(s) });
     pos+=sizeof(foo[e]);
   }
 
@@ -175,7 +180,31 @@ SGML copy(SGML data)
       {
 	ret+=({t});
       }else{
-	ret+=({Tag(t->tag,t->params+([]),t->pos,copy(t->data))});
+	ret+=({Tag(t->tag,t->params+([]),t->pos,copy(t->data),t->file)});
+      }
+    }
+  return ret;
+}
+
+string get_text(SGML data)
+{
+  string ret="";
+  foreach(data,TAG t)
+    {
+      if(stringp(t))
+      {
+	ret+=t;
+      }else{
+	ret+="<"+t->tag;
+	foreach(indices(t->params), string name)
+	  ret+=" "+name+"="+t->params[name];
+
+	ret+=">";
+	if(t->data)
+	{
+	  ret+=get_text(t->data);
+	  ret+="</"+t->tag+">";
+	}
       }
     }
   return ret;
diff --git a/tutorial/Wmml.pmod b/tutorial/Wmml.pmod
index e416a8754a..598ace9eeb 100644
--- a/tutorial/Wmml.pmod
+++ b/tutorial/Wmml.pmod
@@ -61,6 +61,7 @@ static private int verify_any(SGML data, string in)
 	case "man_syntax":
 	case "man_bugs":
 	case "man_example":
+	case "man_title":
 
       case "ex_identifier":
       case "ex_keyword":
@@ -361,43 +362,173 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
   return Sgml.Tag("example",([]),pos,ret);
 }
 
-SGML handle_include(SGML data)
+string classbase;
+
+string name_to_link(string x)
+{
+  return replace(x,({"->","-&gt;"}),({".","."}));
+}
+
+SGML make_concrete_wmml(SGML data)
 {
   if(!data) return 0;
-  for(int e=0;e<sizeof(data);e++)
+  SGML ret=({});
+
+  foreach(data, TAG tag)
   {
-    if(!stringp(data[e]))
+    if(stringp(tag))
     {
-      switch(data[e]->tag)
+      ret+=({tag});
+    }else{
+      switch(tag->tag)
       {
-      case "include":
-	data=
-	  data[..e-1]+
-	  Sgml.group(Sgml.lex(Stdio.read_file(data[e]->params->file)))+
-	  data[e+1..];
-	e--;
-	continue;
+	case "include":
+	  ret+=make_concrete_wmml(Sgml.group(Sgml.lex(Stdio.read_file(tag->params->file),tag->params->file)));
+	  continue;
+	  
+	case "chapter":
+	case "preface":
+	case "introduction":
+	case "section":
+	case "table":
+	case "appendix":
+	case "image":
+	case "illustration":
+	  if(tag->params->name)
+	  {
+	    TAG t=Sgml.Tag(tag->tag,
+			   tag->params,
+			   tag->pos,
+			   tag->data=make_concrete_wmml(tag->data),
+			   tag->file);
+	    ret+=({
+	      Sgml.Tag("anchor",
+		       (["name":tag->params->name,"type":tag->tag]),
+		       tag->pos,
+		       ({
+			 t
+			   }))
+		});
+	    continue;
+	  }
+	  break;
 
-      case "example":
-	switch(data[e]->params->language)
+	case "class":
 	{
-	case "pike":
-	  data[e]=parse_pike_code(data[e]->data[0],
-				  data[e]->pos,
-				  reserved_pike);
-	  break;
+	  string tmp=classbase;
+	  if(!classbase || classbase=="")
+	  {
+	    classbase=tag->params->name;
+	  }else{
+	    classbase+="."+tag->params->name;
+	  }
+	  ret+=({
+	    Sgml.Tag("anchor",(["name":classbase,"type":"class"]),tag->pos,
+		make_concrete_wmml(tag->data))
+	  });
+	  classbase=tmp;
+	  continue;
+	}
 
-	case "c":
-	  data[e]=parse_pike_code(data[e]->data[0],
-				  data[e]->pos,
-				  reserved_c);
-	  break;
+	case "man_syntax":
+	case "man_example":
+	case "man_nb":
+	case "man_bugs":
+	case "man_description":
+	case "man_see":
+	{
+	  string title=tag->tag;
+	  SGML args=tag->data;
+	  sscanf(title,"man_%s",title);
+	  switch(title)
+	  {
+	    case "nb": title="nota bene"; break;
+	    case "syntax":
+	    case "example":
+	      args=({Sgml.Tag("tt",([]),tag->pos,tag->data)});
+	      break;
+
+	    case "see":
+	    {
+	      title="see also";
+	      SGML tmp=({});
+	      foreach(replace(Sgml.get_text(args),({" ","\n"}),({"",""}))/",",string name)
+		{
+		  tmp+=({
+		    Sgml.Tag("link",(["to":name_to_link(name)]),tag->pos,
+			     ({
+			       Sgml.Tag("tt",([]),tag->pos,({name})),
+				 })),
+		      ", "
+			});
+		}
+	      
+	      tmp[-1]="";
+	      if(sizeof(tmp)>3) tmp[-3]=" and ";
+	      
+	      args=tmp;
+	      break;
+	    }
+	  }
+	  title=upper_case(title);
+	  ret+=make_concrete_wmml(
+	    ({
+	    Sgml.Tag("man_title",(["title":title]),tag->pos,args),
+	      }));
+	  continue;
 	}
+
+	case "method":
+	{
+	  string fullname=classbase+"->"+tag->params->name;
+	  ret+=make_concrete_wmml(({
+	    Sgml.Tag("anchor",(["name":name_to_link(fullname),
+	    "type":"method",]),tag->pos,
+		     ({
+		       Sgml.Tag("dl",([]),tag->pos,
+				  ({
+				    Sgml.Tag("man_title",(["title":"METHOD"]),tag->pos,
+					     ({
+					       Sgml.Tag("tt",([]),tag->pos,({fullname})),
+						 " - ",
+						   tag->params->title,
+						   })
+					     )
+				  })
+				  +
+				  tag->data
+			 )
+		     })),
+	      "\n",
+	      Sgml.Tag("hr"),
+	  }));
+	  continue;
+	}
+	  
+	case "example":
+	  switch(tag->params->language)
+	  {
+	    case "pike":
+	      ret+=({parse_pike_code(tag->data[0],
+				     tag->pos,
+				     reserved_pike)});
+	      continue;
+	      
+	    case "c":
+	      ret+=({parse_pike_code(tag->data[0],
+				      tag->pos,
+				      reserved_c)});
+	      continue;
+	  }
       }
-      data[e]->data=handle_include(data[e]->data);
+      ret+=({Sgml.Tag(tag->tag,
+		      tag->params,
+		      tag->pos,
+		      make_concrete_wmml(tag->data),
+		      tag->file)});
     }
   }
-  return data;
+  return ret;
 }
 
 void save_image_cache();
diff --git a/tutorial/html.pike b/tutorial/html.pike
index a1eb73e614..4f61cce2f1 100644
--- a/tutorial/html.pike
+++ b/tutorial/html.pike
@@ -230,8 +230,6 @@ string name_to_link(string x)
 
 int cpos;
 
-string classbase;
-
 SGML wmml_to_html(SGML data);
 
 /* Partially destructive! */
@@ -255,115 +253,17 @@ SGML convert(SGML data)
 	data->params->size="1";
 	break;
 
-	case "class":
-	{
-	  string tmp=classbase;
-	  if(!classbase || classbase=="")
-	  {
-	    classbase=data->params->name;
-	  }else{
-	    classbase+="."+data->params->name;
-	  }
-	  ret+=convert(data->data);
-	  classbase=tmp;
-	  continue;
-	}
 
 	case "man_title":
 	  ret+=convert(({
 	    Sgml.Tag("p"),
 	    "\n",
 	    Sgml.Tag("dt"),
-	      Sgml.Tag("encaps",([]),data->pos, data->data),
-	      Sgml.Tag("dd"),
-	      "\n"
-	      }));
-	  continue;
-
-	case "method":
-	{
-	  string fullname=classbase+"->"+data->params->name;
-	  ret+=convert(({
-	    Sgml.Tag("anchor",(["name":name_to_link(fullname)]),data->pos,
-		     ({
-		       Sgml.Tag("dl",([]),data->pos,
-				  ({
-				    Sgml.Tag("man_title",([]),data->pos,({"METHOD"})),
-				    Sgml.Tag("tt",([]),data->pos,({fullname})),
-				    " - ",
-				    data->params->title,
-				    "\n",
-				  })
-				  +
-				  data->data
-			 )
-		     })),
+	      Sgml.Tag("encaps",([]),data->pos, ({data->params->title})),
 	      "\n",
-	      Sgml.Tag("hr"),
-	  }));
-	  continue;
-	}
-	case "man_syntax":
-	  ret+=convert(
-	    ({
-	    Sgml.Tag("man_title",([]),data->pos,({"SYNTAX"})),
-	      Sgml.Tag("tt",([]),data->pos,data->data)
-		}));
-	  continue;
-
-	case "man_example":
-	  ret+=convert(
-	    ({
-	    Sgml.Tag("man_title",([]),data->pos,({"EXAMPLE"})),
-	      Sgml.Tag("tt",([]),data->pos,data->data)
-		}));
-	  continue;
-		    
-	case "man_nb":
-	  ret+=convert(
-	    ({
-	    Sgml.Tag("man_title",([]),data->pos,({"NOTA BENE"})),
-	      })+data->data);
-	  continue;
-
-	case "man_bugs":
-	  ret+=convert(
-	    ({
-	    Sgml.Tag("man_title",([]),data->pos,({"BUGS"})),
-	      })+data->data);
-	  continue;
-	
-	case "man_description":
-	  ret+=convert(
-	    ({
-	    Sgml.Tag("man_title",([]),data->pos,({"DESCRIPTION"})),
-	      })+data->data);
-	  continue;
-
-	case "man_see":
-	{
-	  ret+=convert( ({
-	    Sgml.Tag("man_title",([]),data->pos,({"SEE ALSO"}))
-	      }));
-	  
-	  SGML tmp=({});
-	  foreach(replace(data->data[0],({" ","\n"}),({"",""}))/",",string name)
-	    {
-	      tmp+=({
-		Sgml.Tag("link",(["to":name_to_link(name)]),data->pos,
-			 ({
-			   Sgml.Tag("tt",([]),data->pos,({name})),
-			     })),
-		  ", "
-		    });
-	    }
-
-	  tmp[-1]="";
-	  if(sizeof(tmp)>3) tmp[-3]=" and ";
-
-	  ret+=convert(tmp);
+	      Sgml.Tag("dd"),
+	      })+data->data+ ({ "\n" }));
 	  continue;
-	}
 
 	case "link":
 	{
@@ -384,9 +284,12 @@ SGML convert(SGML data)
 	  TAG t2=link_to_data[to];
 	  if(!t2)
 	  {
-	    werror("Warning: Cannot find link "+to+" (near pos "+data->pos+")\n");
+	    werror("Warning: Cannot find ref "+to+" (near pos "+data->pos+")\n");
 	  }
-	  data->data=({t2->tag+" "+t2->params->number});
+	  if(t2)
+	    data->data=({t2->tag+" "+t2->params->number});
+	  else
+	    data->data=({"unknown"});
 	  data->tag="a";
 	  data->params->href=mkfilename(link_to_page[to])+"#"+to;
 	  break;
diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml
index 293de8cf44..2afcf99c94 100644
--- a/tutorial/tutorial.wmml
+++ b/tutorial/tutorial.wmml
@@ -4952,7 +4952,7 @@ void write(mixed v)
 </example>
 <p>
 <dt><encaps>SEE ALSO</encaps><dd>
-<link to=Tread.Mutex>Thread.Mutex</link>
+<link to=Thread.Mutex>Thread.Mutex</link>
 <p>
 </dl>
 
@@ -5336,7 +5336,7 @@ Result: green, blue or white<br>
 </tt>
 <p>
 <dt><encaps>SEE ALSO</encaps><dd>
-<link to=multiplication>`*</link>
+<link to=%60*>`*</link>
 </dl>
 </anchor>
 
@@ -5467,7 +5467,7 @@ first call that returned true instead or returning an array of the
 returned values. If no call returns true, -1 is returned.
 <p>
 <dt><encaps>SEE ALSO</encaps><dd>
-<link to=Array.sum_arrays.html>Array.sum_arrays</link> and <link to=Array.filter_array>Array.filter_array</link>
+<link to=Array.sum_arrays>Array.sum_arrays</link> and <link to=Array.filter_array>Array.filter_array</link>
 <p>
 </dl>
 </anchor>
@@ -12722,7 +12722,7 @@ pid of the child. Refer to your Unix manual for further details.
 This function cause endless bugs if used without proper care.
 <p>
 <dt><encaps>SEE ALSO</encaps><dd>
-<link to=Simulate.exec>Simulate.exec</link> and <link to=Stdio.File.pipe>Stdio.File-&gt;pipe</link>
+<link to=Process.exec>Process.exec</link> and <link to=Stdio.File.pipe>Stdio.File-&gt;pipe</link>
 <p>
 </dl>
 </anchor>
-- 
GitLab