r1646 - in dev/concept/moongoo: . libalfs syntax

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Sun Dec 12 14:42:50 PST 2004


Author: neocool
Date: 2004-12-12 15:42:49 -0700 (Sun, 12 Dec 2004)
New Revision: 1646

Added:
   dev/concept/moongoo/libalfs/parse.c
   dev/concept/moongoo/libalfs/parse.h
Removed:
   dev/concept/moongoo/syntax/rng.c
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/libalfs/Makefile
   dev/concept/moongoo/libalfs/alfs.c
   dev/concept/moongoo/libalfs/alfs.h
   dev/concept/moongoo/libalfs/gen.c
   dev/concept/moongoo/libalfs/gen.h
   dev/concept/moongoo/libalfs/libalfs.h
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/packages.xml
   dev/concept/moongoo/syntax/Makefile
   dev/concept/moongoo/syntax/ass.c
   dev/concept/moongoo/syntax/blfs.c
   dev/concept/moongoo/syntax/book.c
   dev/concept/moongoo/syntax/nalfs.c
   dev/concept/moongoo/syntax/sample.c
   dev/concept/moongoo/syntax/syn.c
   dev/concept/moongoo/url.c
Log:
Update.


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/Makefile	2004-12-12 22:42:49 UTC (rev 1646)
@@ -4,12 +4,12 @@
 OBJS=build.o moongoo.o plugin.o url.o
 
 ifeq ($(OPTS),)
-OPTS=-s blfs
+OPTS=-s nalfs
 #OPTS+=~/projects/alfs/book/index.xml
-#OPTS+=~/projects/alfs/lfs-profile/LFS.xml
+OPTS+=~/projects/alfs/lfs-profile/LFS.xml
 #OPTS+=~/projects/alfs/ass/index.xml
 #OPTS+=~/projects/hive/unstable/profile.xml
-OPTS+=~/projects/alfs/blfs/index.xml
+#OPTS+=~/projects/alfs/blfs/index.xml
 #OPTS+=~/projects/alfs/hlfs/index.xml
 #OPTS+=~/projects/alfs/book-rng/index.xml
 endif
@@ -24,6 +24,9 @@
 
 $(BIN): $(OBJS) libalfs/libalfs.a
 
+check: $(BIN)
+	valgrind --tool=memcheck ./$(BIN) $(OPTS)
+
 run: $(BIN)
 	./$(BIN) $(OPTS)
 

Modified: dev/concept/moongoo/libalfs/Makefile
===================================================================
--- dev/concept/moongoo/libalfs/Makefile	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/Makefile	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,7 +1,7 @@
 CFLAGS=-I.
 
 LIB=libalfs.a
-OBJS=alfs.o devel.o gen.o net.o repl.o util.o
+OBJS=alfs.o devel.o gen.o net.o parse.o repl.o util.o
 
 all: $(LIB)
 
@@ -15,5 +15,6 @@
 devel.o: devel.h
 gen.o: gen.h
 net.o: net.h
+parse.o: parse.h
 repl.o: repl.h
 util.o: util.h

Modified: dev/concept/moongoo/libalfs/alfs.c
===================================================================
--- dev/concept/moongoo/libalfs/alfs.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/alfs.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -9,17 +9,24 @@
 
 void print_links (profile prof)
 {
-	int i, j, k;
+	int i, j;
 
 	for (i=0;i<prof.n;i++)
 		for (j=0;j<prof.ch[i].n;j++)
-			for (k=0;k<prof.ch[i].pkg[j].m;k++)
-			{
-				download moo = prof.ch[i].pkg[j].dl[k];
-				printf("%s: %s\n", algo2str(moo.algo), moo.sum);
-				printf("%s://%s\n", proto2str(moo.proto), moo.url);
-			}
+			print_urls(prof.ch[i].pkg[j]);
 }
+
+void print_urls (package pkg)
+{
+	int k;
+	
+	for (k=0;k<pkg.m;k++)
+	{
+		download moo = pkg.dl[k];
+		printf("%s: %s --- ", algo2str(moo.algo), moo.sum);
+		printf("%s://%s\n", proto2str(moo.proto), moo.url);
+	}
+}
 		
 void print_cmd (command cmd)
 {
@@ -156,6 +163,34 @@
 	}
 }
 
+void foreach_multi (xmlNodePtr node, char **str, xml_handler_t func, 
+	void *data)
+{
+	if (!str)
+		return;
+
+	while (node)
+	{
+		bool recurse = true;
+		int i = 0;
+		
+		while (str[i])
+		{
+			if (!strcmp(node->name, str[i]))
+			{
+				func(node, data);
+				recurse = false;
+				break;
+			}
+			i++;
+		}
+		
+		if (recurse)
+			foreach_multi(node->children, str, func, data);
+		node = node->next;
+	}
+}
+
 xmlNodePtr find_node (xmlNodePtr root, char *str)
 {
 	if (!str)
@@ -247,6 +282,14 @@
 	return xmlNodeGetContent(moo);
 }
 
+char *find_attr (xmlNodePtr node, char *str, char *attr)
+{
+	xmlNodePtr moo = find_node(node, str);
+	if (!moo)
+		return "";
+	return xmlGetProp(moo, attr);
+}
+
 char *role2str (role role)
 {
 	switch (role)

Modified: dev/concept/moongoo/libalfs/alfs.h
===================================================================
--- dev/concept/moongoo/libalfs/alfs.h	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/alfs.h	2004-12-12 22:42:49 UTC (rev 1646)
@@ -97,17 +97,20 @@
 void print_chapter (chapter ch);
 void print_profile (profile prof);
 void print_links (profile prof);
+void print_urls (package pkg);
 
 void set_filter (role *role);
 void unset_filter ();
 bool filtered (role role);
 
 void foreach (xmlNodePtr node, char *str, xml_handler_t func, void *data);
+void foreach_multi (xmlNodePtr node, char **str, xml_handler_t func, void *data);
 xmlNodePtr find_node (xmlNodePtr root, char *str);
 xmlNodePtr find_node_match (xmlNodePtr node, xml_match_t func, void *data);
 char *find_value (xmlNodePtr node, char *str);
 char *find_values (xmlNodePtr node, char *str);
 char *find_values_repl (xmlNodePtr node, char *str, char **orig, char **repl);
+char *find_attr (xmlNodePtr node, char *str, char *attr);
 
 package *search_pkg (profile *prof, char *name, char *ch);
 char *role2str (role role);

Modified: dev/concept/moongoo/libalfs/gen.c
===================================================================
--- dev/concept/moongoo/libalfs/gen.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/gen.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,3 +1,4 @@
 #include <gen.h>
 
 const char *compr[NUM_COMPR] = { ".bz2", ".gz" };
+const char *unpck[NUM_COMPR] = { "tar xfz ", "tar xfj " };

Modified: dev/concept/moongoo/libalfs/gen.h
===================================================================
--- dev/concept/moongoo/libalfs/gen.h	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/gen.h	2004-12-12 22:42:49 UTC (rev 1646)
@@ -3,6 +3,6 @@
 
 #define NUM_COMPR	2
 
-extern const char *compr[NUM_COMPR];
+extern const char *compr[NUM_COMPR], *unpck[NUM_COMPR];
 
 #endif

Modified: dev/concept/moongoo/libalfs/libalfs.h
===================================================================
--- dev/concept/moongoo/libalfs/libalfs.h	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/libalfs.h	2004-12-12 22:42:49 UTC (rev 1646)
@@ -5,6 +5,7 @@
 #include <devel.h>
 #include <gen.h>
 #include <net.h>
+#include <parse.h>
 #include <repl.h>
 #include <util.h>
 

Added: dev/concept/moongoo/libalfs/parse.c
===================================================================
--- dev/concept/moongoo/libalfs/parse.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/parse.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -0,0 +1,223 @@
+#include <ctype.h>
+#include <string.h>
+
+#include <gen.h>
+#include <parse.h>
+#include <util.h>
+
+chapter *next_chpt (profile *prof)
+{
+	chapter *ch;
+
+	prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
+	ch = &prof->ch[prof->n-1];
+	
+	ch->name = NULL;
+	ch->ref = NULL;
+	ch->pkg = NULL;
+	ch->n = 0;
+	
+	return ch;
+}
+
+command *next_cmd (profile *prof)
+{
+	command *cmd;
+	int i, j, k;
+
+	i = prof->n-1;
+	j = prof->ch[i].n-1;
+	prof->ch[i].pkg[j].build = realloc(prof->ch[i].pkg[j].build,
+			(++prof->ch[i].pkg[j].n)*sizeof(command));
+	k = prof->ch[i].pkg[j].n-1;
+
+	cmd = &prof->ch[i].pkg[j].build[k];
+	cmd->cmd = NULL;
+	cmd->arg = NULL;
+	cmd->n = 0;
+	cmd->role = ROLE_NONE;
+
+	return cmd;
+}
+
+dep *next_dep (profile *prof)
+{
+	dep *dep;
+	int i, j, k;
+	
+	i = prof->n-1;
+	j = prof->ch[i].n-1;
+	prof->ch[i].pkg[j].dep = realloc(prof->ch[i].pkg[j].dep,
+			(++prof->ch[i].pkg[j].o)*sizeof(dep));
+	k = prof->ch[i].pkg[j].o-1;
+
+	dep = &prof->ch[i].pkg[j].dep[k];
+	dep->type = DEP_NONE;
+	dep->name = NULL;
+
+	return dep;
+}
+
+download *next_dl (profile *prof)
+{
+	download *dl;
+	int i, j, k;
+	
+	i = prof->n-1;
+	j = prof->ch[i].n-1;
+	prof->ch[i].pkg[j].dl = realloc(prof->ch[i].pkg[j].dl,
+		(++prof->ch[i].pkg[j].m)*sizeof(download));
+	k = prof->ch[i].pkg[j].m-1;
+	
+	dl = &prof->ch[i].pkg[j].dl[k];
+	dl->algo = ALGO_NONE;
+	dl->sum = NULL;
+	dl->proto = PROTO_NONE;
+	dl->url = NULL;
+	
+	return dl;
+}
+
+package *next_pkg (profile *prof)
+{
+	package *pkg;
+	int i, j;
+	
+	i = prof->n-1;
+	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
+			(++prof->ch[i].n)*sizeof(package));
+	j = prof->ch[i].n-1;
+	
+	pkg = &prof->ch[i].pkg[j];
+	pkg->name = NULL;
+	pkg->vers = NULL;
+	pkg->build = NULL;
+	pkg->n = 0;
+	pkg->dl = NULL;
+	pkg->m = 0;
+	pkg->dep = NULL;
+	pkg->o = 0;
+
+	return pkg;
+}
+
+package *next_pkg_title (profile *prof, xmlNodePtr node)
+{
+	char *title = find_value(node->children, "title"), 
+		*tmp = strrchr(title, '-');
+	package *pkg = next_pkg(prof);
+
+	if (tmp)
+	{
+		char *t = strnrchr(title, '-', 2);
+		if ((t) && (isdigit(t[1])))
+			tmp = strdog(t, tmp); 
+	}
+	tmp = chrep(tmp, ' ', '\0');
+	
+	pkg->name = tmp ? strcut(title, 0, strlen(title)-strlen(tmp)) : title;
+	pkg->vers = tmp ? strcut(tmp, 1, strlen(tmp)) : NULL;
+
+	return pkg;
+}
+
+profile *new_prof ()
+{
+	profile *prof = (profile *)malloc(sizeof(profile));
+	
+	prof->name = NULL;
+	prof->vers = NULL;
+	prof->ch = NULL;
+	prof->n = 0;
+
+	return prof;
+}
+
+void parse_cmd (profile *prof, char *line, xmlNodePtr node)
+{
+	command *cmd = next_cmd(prof);
+	if (node)
+		cmd->role = parse_role(node);
+
+	if (strcnt(line, " "))
+	{
+		cmd->cmd = strcut(line, 0, whereis(line, ' '));
+		cmd->arg = tokenize(notrail(strstr(line, " "), " "), " ", &cmd->n);
+	}
+	else
+		cmd->cmd = line;
+}
+
+static void __parse_cmdblock (profile *prof, xmlNodePtr node, char *str)
+{
+	char *line = squeeze(str);
+	line = strkill(line, "\\\n");
+	line = strkill(line, "&&");
+
+	if (strcnt(line, "\n"))
+	{
+		char *tmp;
+
+		while ((line) && (strlen(line)))
+		{
+			if (!strncmp(line, "cat >", 5))
+			{
+				char *t = strnstr(line, "EOF", 2);
+				
+				if (!t)
+				{
+					fprintf(stderr, "Unterminated cat command.\n");
+					parse_cmd(prof, line, node);
+				}
+				else
+				{
+					parse_cmd(prof, strcut(line, 0, t-line+3), node);
+					t+=2;
+				}
+				
+				line=t;
+				continue;
+			}
+
+			tmp = strsep(&line, "\n");
+			parse_cmd(prof, tmp, node);
+		}
+	}
+	else
+		parse_cmd(prof, line, node);
+}
+
+void parse_cmdblock (profile *prof, xmlNodePtr node)
+{
+	__parse_cmdblock(prof, node, xmlNodeGetContent(node));
+}
+
+void parse_cmdblock_str (profile *prof, char *str)
+{
+	__parse_cmdblock(prof, NULL, str);
+}
+
+void parse_unpck (profile *prof, char *url, xmlNodePtr node)
+{
+	int i;
+	char *ext = extonly(url), *ret = NULL;
+
+	for (i=0;i<NUM_COMPR;i++)
+	{
+		char *tst = strdog(".tar", (char *)compr[i]);
+		if (!strcmp(ext, tst))
+			ret = (char *)unpck[i];
+		free(tst);
+	}
+	
+	if (!ret)
+	{
+		// TODO: Add support for missing archive types
+		//fprintf(stderr, "Archive extension '%s' is unknown.\n", ext);
+		return;
+	}
+
+	ret = strdog(ret, basename(url));
+	parse_cmd(prof, ret, node);
+	free(ret);
+}

Added: dev/concept/moongoo/libalfs/parse.h
===================================================================
--- dev/concept/moongoo/libalfs/parse.h	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/libalfs/parse.h	2004-12-12 22:42:49 UTC (rev 1646)
@@ -0,0 +1,19 @@
+#ifndef __PARSE_H__
+#define __PARSE_H__
+
+#include <alfs.h>
+
+chapter *next_chpt (profile *prof);
+command *next_cmd (profile *prof);
+dep *next_dep (profile *prof);
+download *next_dl (profile *prof);
+package *next_pkg (profile *prof);
+package *next_pkg_title (profile *prof, xmlNodePtr node);
+profile *new_prof ();
+
+void parse_cmd (profile *prof, char *line, xmlNodePtr node);
+void parse_cmdblock (profile *prof, xmlNodePtr node);
+void parse_cmdblock_str (profile *prof, char *str);
+void parse_unpck (profile *prof, char *url, xmlNodePtr node);
+	
+#endif

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/moongoo.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -131,21 +131,22 @@
 	{
 		/*package *glibc = search_pkg(prof, "glibc", 
 			"chapter-building-system");*/
-		package *gtk2 = search_pkg(prof, "gtk+",
-			"x-lib");
+		//package *gtk = search_pkg(prof, "gtk+", "x-lib");
+		//package *glib = search_pkg(prof, "glib", "general-genlib");
 		
 		sed_paralell (prof, paralell_filter, popt_pkg, popt_cmd);
 		set_filter(default_filter);
-		
-		if (gtk2)
-		{
-			//print_pkg(*gtk2);
-			print_deptree(*prof, *gtk2);
-		}
+	
+		/*if (glib)
+			//print_pkg(*glib);
+			print_urls(*glib);*/
+		/*if (gtk)
+			//print_pkg(*gtk);
+			print_deptree(*prof, *gtk);*/
 		/*if (glibc)
 			print_pkg(*glibc);*/
 		
-		//print_profile(*prof);
+		print_profile(*prof);
 		//print_links(*prof);
 	}
 

Modified: dev/concept/moongoo/packages.xml
===================================================================
--- dev/concept/moongoo/packages.xml	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/packages.xml	2004-12-12 22:42:49 UTC (rev 1646)
@@ -4,7 +4,7 @@
 <url name="automake">http://ftp.gnu.org/gnu/automake/</url>
 <url name="bash">http://ftp.gnu.org/gnu/bash/</url>
 <url name="binutils">http://www.kernel.org/pub/linux/devel/binutils/</url>
-<url name="bison">http://ftp.gnu.org/gnu/bison/</url>
+<url name="bison">http://ftp.tuniv.szczecin.pl/pub/Linux/alpha-gnu/bison/</url>
 <url name="bzip2" vurl="nodots">ftp://sources.redhat.com/pub/bzip2/v</url>
 <url name="coreutils">http://ftp.gnu.org/gnu/coreutils/</url>
 <url name="dejagnu">http://ftp.gnu.org/gnu/dejagnu/</url>
@@ -22,6 +22,7 @@
 <url name="groff">http://ftp.gnu.org/gnu/groff/</url>
 <url name="grub">ftp://alpha.gnu.org/gnu/grub/</url>
 <url name="gzip">ftp://alpha.gnu.org/gnu/gzip/</url>
+<url name="hotplug">http://www.kernel.org/pub/linux/utils/kernel/hotplug/</url>
 <url name="iana-etc">http://www.sethwklein.net/projects/iana-etc/downloads/</url>
 <url name="inetutils">http://ftp.gnu.org/gnu/inetutils/</url>
 <url name="iproute2">http://developer.osdl.org/dev/iproute2/download/</url>

Modified: dev/concept/moongoo/syntax/Makefile
===================================================================
--- dev/concept/moongoo/syntax/Makefile	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/Makefile	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,6 +1,6 @@
 CFLAGS=-I../libalfs -I..
 
-LIBS=ass.so blfs.so book.so nalfs.so rng.so syn.so
+LIBS=ass.so blfs.so book.so nalfs.so syn.so
 #LIBS+=sample.so
 
 all: $(LIBS)
@@ -11,5 +11,4 @@
 blfs.so: ../libalfs/libalfs.a
 book.so: ../libalfs/libalfs.a
 nalfs.so: ../libalfs/libalfs.a
-rng.so: ../libalfs/libalfs.a
 syn.so: ../libalfs/libalfs.a

Modified: dev/concept/moongoo/syntax/ass.c
===================================================================
--- dev/concept/moongoo/syntax/ass.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/ass.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,6 +1,3 @@
-#include <libgen.h>
-#include <string.h>
-
 #include <libalfs.h>
 #include <plugin.h>
 
@@ -20,64 +17,15 @@
 	return &ass_plugin;
 }
 
-
-static void process_cmd (char *line)
+static void t_shell (xmlNodePtr node, void *data)
 {
-	int i, j, k;
-
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-	prof->ch[i].pkg[j].build = realloc(prof->ch[i].pkg[j].build,
-			(++prof->ch[i].pkg[j].n)*sizeof(command));
-	k = prof->ch[i].pkg[j].n-1;
-	
-	prof->ch[i].pkg[j].build[k].role = ROLE_NONE;
-
-	if (strcnt(line, " "))
-	{
-		prof->ch[i].pkg[j].build[k].cmd = strcut(line, 0, whereis(line, ' '));
-		prof->ch[i].pkg[j].build[k].arg = tokenize(notrail(strstr(line, " "), 
-				" "), " ", &prof->ch[i].pkg[j].build[k].n);
-	}
-	else
-	{
-		prof->ch[i].pkg[j].build[k].cmd = line;
-		prof->ch[i].pkg[j].build[k].arg = NULL;
-		prof->ch[i].pkg[j].build[k].n = 0;
-	}
+	parse_cmdblock(prof, node);
 }
 
-static  void t_shell (xmlNodePtr node, void *data)
+static void t_item (xmlNodePtr node, void *data)
 {
-	char *line = squeeze(xmlNodeGetContent(node));
-	line = strkill(line, "\\\n");
+	download *moo = next_dl(prof);
 
-	if (strcnt(line, "\n"))
-	{
-		char *tmp;
-
-		while ((line) && (strlen(line)))
-		{
-			tmp = strsep(&line, "\n");
-			process_cmd(tmp);
-		}
-	}
-	else
-		process_cmd(line);
-}
-
-static  void t_item (xmlNodePtr node, void *data)
-{
-	int i, j, k;
-	download *moo;
-
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-	prof->ch[i].pkg[j].dl = realloc(prof->ch[i].pkg[j].dl,
-		(++prof->ch[i].pkg[j].m)*sizeof(download));
-	k = prof->ch[i].pkg[j].m-1;
-	moo = &prof->ch[i].pkg[j].dl[k];
-
 	if (xmlGetProp(node, "sha1"))
 	{
 		moo->algo = SHA1;
@@ -89,73 +37,35 @@
 		moo->algo = MD5;
 		moo->sum = xmlGetProp(node, "md5");
 	}
-	else
-	{
-		moo->algo = ALGO_NONE;
-		moo->sum = NULL;
-	}
 	
 	moo->proto = parse_proto(node);
 	moo->url = xmlNodeGetContent(node);
 }
 
-static  void t_down (xmlNodePtr node, void *data)
+static void t_down (xmlNodePtr node, void *data)
 {
 	foreach(node->children, "item", (xml_handler_t)t_item, NULL);
 }
 
-static  void t_unpack (char *url)
+static void t_page (xmlNodePtr node, void *data)
 {
-	char *ext = extonly(url), *ret = NULL;
-
-	if (!strcmp(ext, ".tar.gz"))
-		ret = "tar xfz ";
-	if (!strcmp(ext, ".tar.bz2"))
-		ret = "tar xfj ";
-
-	if (!ret)
-	{
-		fprintf(stderr, "Archive extension '%s' is unknown.\n", ext);
-		return;
-	}
-
-	ret = strdog(ret, basename(url));
-	process_cmd(ret);
-	free(ret);
-}
-
-static  void t_page (xmlNodePtr node, void *data)
-{
-	int i, j;
 	xmlNodePtr dir = find_node(node->children, "directory");
+	package *pkg = next_pkg(prof);
 
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg,
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
+	pkg->name = find_value(node, "title");
+	pkg->vers = find_value(node, "version");
 
-	prof->ch[i].pkg[j].name = find_value(node, "title");
-	prof->ch[i].pkg[j].vers = find_value(node, "version");
-	prof->ch[i].pkg[j].build = NULL;
-	prof->ch[i].pkg[j].n = 0;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
-
 	foreach(node->children, "download", (xml_handler_t)t_down, NULL);
-	t_unpack(prof->ch[i].pkg[j].dl[0].url);
-	process_cmd(strdog("__cd ", xmlNodeGetContent(dir)));
+	parse_unpck(prof, pkg->dl[0].url, node);
+	parse_cmd(prof, strdog("__cd ", xmlNodeGetContent(dir)), node);
 	foreach(node->children, "shell", (xml_handler_t)t_shell, NULL);
 }
 
 static  void t_chapter (xmlNodePtr node, void *data)
 {
-	prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-	prof->ch[prof->n-1].name = xmlGetProp(node, "name");
-	prof->ch[prof->n-1].ref = xmlGetProp(node, "ref");
-	prof->ch[prof->n-1].pkg = NULL;
-	prof->ch[prof->n-1].n = 0;
+	chapter *ch = next_chpt(prof);
+	ch->name = xmlGetProp(node, "name");
+	ch->ref = xmlGetProp(node, "ref");
 	foreach(node->children, "page", (xml_handler_t)t_page, NULL);
 }
 
@@ -169,11 +79,9 @@
 		return NULL;
 	}
 	
-	prof = (profile *)malloc(sizeof(profile));
+	prof = new_prof();
 	prof->name = find_value(node, "title");
 	prof->vers = find_value(node, "version");
-	prof->ch = NULL;
-	prof->n = 0;
 	foreach(node->children, "chapter", (xml_handler_t)t_chapter, NULL);
 	return prof;
 }

Modified: dev/concept/moongoo/syntax/blfs.c
===================================================================
--- dev/concept/moongoo/syntax/blfs.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/blfs.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -5,6 +5,7 @@
 
 profile *prof;
 
+// TODO: Removed a <command> block because of parsing problems (postlfs/config/bootdisk.xml)
 profile *parse_blfs (xmlNodePtr node, replaceable *r);
 
 static t_plug sample_plugin =
@@ -19,50 +20,9 @@
 	return &sample_plugin;
 }
 
-static void process_cmd (char *line)
-{
-	int i, j, k;
-
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-	prof->ch[i].pkg[j].build = realloc(prof->ch[i].pkg[j].build,
-			(++prof->ch[i].pkg[j].n)*sizeof(command));
-	k = prof->ch[i].pkg[j].n-1;
-
-	prof->ch[i].pkg[j].build[k].role = ROLE_NONE;
-
-	
-	if (strcnt(line, " "))
-	{
-		prof->ch[i].pkg[j].build[k].cmd = strcut(line, 0, whereis(line, ' '));
-		prof->ch[i].pkg[j].build[k].arg = tokenize(notrail(strstr(line, " "), 
-				" "), " ", &prof->ch[i].pkg[j].build[k].n);
-	}
-	else
-	{
-		prof->ch[i].pkg[j].build[k].cmd = line;
-		prof->ch[i].pkg[j].build[k].arg = NULL;
-		prof->ch[i].pkg[j].build[k].n = 0;
-	}
-}
-
 static void t_command (xmlNodePtr node, void *data)
 {
-	char *line = squeeze(xmlNodeGetContent(node));
-	line = strkill(line, "\\\n");
-
-	if (strcnt(line, "\n"))
-	{
-		char *tmp;
-
-		while ((line) && (strlen(line)))
-		{
-			tmp = strsep(&line, "\n");
-			process_cmd(tmp);
-		}
-	}
-	else
-		process_cmd(line);
+	parse_cmdblock(prof, node);
 }
 
 static void t_userinput (xmlNodePtr node, void *data)
@@ -77,19 +37,14 @@
 {
 	dtype *type = (dtype *)data;
 	char *role = xmlGetProp(node, "role");
-	int i, j, k;
+	dep *dep;
 
 	if ((role)&&(!strcmp(role, "no")))
 		return;
-	
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-	prof->ch[i].pkg[j].dep = realloc(prof->ch[i].pkg[j].dep,
-			(++prof->ch[i].pkg[j].o)*sizeof(dep));
-	k = prof->ch[i].pkg[j].o-1;
 
-	prof->ch[i].pkg[j].dep[k].name = xmlGetProp(node, "linkend");
-	prof->ch[i].pkg[j].dep[k].type = *type;
+	dep = next_dep(prof);
+	dep->name = xmlGetProp(node, "linkend");
+	dep->type = *type;
 }
 
 static void t_sect4 (xmlNodePtr node, void *data)
@@ -118,60 +73,104 @@
 {
 	char *title = strstr(find_value(node->children, "title"), " ");
 	
+	// TODO: Dependency parsing is broken
+	return;
+	
 	if ((title)&&(!strncmp(lower_case(title), " dependencies", 13)))
 		foreach(node->children, "sect4", (xml_handler_t)t_sect4, NULL);
 }
 
-static void t_sect1 (xmlNodePtr node, void *data)
+static void t_add (xmlNodePtr node, void *data)
 {
-	int i, j;
-	char *title, *tmp;
+	download *moo = next_dl(prof);
 
-	title = find_value(node->children, "title");
+	moo->url = find_attr(node->children, "ulink", "url");
+	moo->proto = check_proto(moo->url);
+}
 
-	if (!title)
+static void t_url (xmlNodePtr node, void *data)
+{
+	int n, i;
+	bool isdl = false;
+	char **moo = tokenize(lower_case(xmlNodeGetContent(node)), " ", &n);
+	protocol proto; 
+	
+	for (i=0;i<n;i++)
 	{
-		fprintf(stderr, "%s: No title found.\n", node->name);
-		return;
+		if (!strcmp(moo[i], "download"))
+			isdl = true;
+		
+		if ((!strcmp(moo[i], "size:"))||(!strcmp(moo[i], "md5"))||
+		   (!strcmp(moo[i], "size"))||(!strcmp(moo[i], "md5sum"))||
+		   (!strcmp(moo[i], "mirrors"))||(!strcmp(moo[i], "md5sum:")))
+			isdl = false;
+		
+		if (moo[i][0]=='(')
+		{
+			char *type = strcut(moo[i], 1, strlen(moo[i])-3);
+			proto = check_proto(type);
+		}
 	}
+	
+	if (isdl)
+	{
+		download *moo = next_dl(prof);
 
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
+		moo->proto = proto;
+		moo->url = find_attr(node->children, "ulink", "url");
+	}
+}
 
-	tmp = strrchr(title, '-');
-	if (tmp)
+static void t_info (xmlNodePtr node, void *data)
+{
+	char *title = lower_case(find_value(node->children, "title"));
+
+	if (!title)
+		return;
+	
+	if (!strcmp(title, "package information"))
+		foreach(node->children, "para", (xml_handler_t)t_url, NULL);
+
+	if (!strcmp(title, "additional downloads"))
+		foreach(node->children, "para", (xml_handler_t)t_add, NULL);
+}
+
+static void t_sect1 (xmlNodePtr node, void *data)
+{
+	package *pkg = next_pkg_title(prof, node);
+
+	foreach(node->children, "sect3", (xml_handler_t)t_info, NULL);
+	foreach(node->children, "sect3", (xml_handler_t)t_sect3, data);
+
+	if (pkg->m>0)
 	{
-		char *t = strnrchr(title, '-', 2);
-		if ((t) && (isdigit(t[1])))
-			tmp = strdog(t, tmp); 
+		char *url = pkg->dl[0].url, *tball = basename(url);
+		int i;
+		
+		parse_unpck(prof, url, node);
+		for (i=0;i<NUM_COMPR;i++)
+		{
+			char *dir, *com;
+			com = strdog(".tar", (char *)compr[i]);
+			dir = strkill(tball, com);
+			if (strcmp(dir, tball))
+				parse_cmd(prof, strdog("__cd ", dir), node);
+			free(com);
+			free(dir);
+		}
 	}
-	tmp = chrep(tmp, ' ', '\0');
-	prof->ch[i].pkg[j].vers = tmp ? strcut(tmp, 1, strlen(tmp)) : NULL;
-	prof->ch[i].pkg[j].name = tmp ? strcut(title, 0, 
-		strlen(title)-strlen(tmp)) : title;
-	prof->ch[i].pkg[j].build = NULL;
-	prof->ch[i].pkg[j].n = 0;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
 	
-	foreach(node->children, "sect3", (xml_handler_t)t_sect3, data);
 	foreach(node->children, "userinput", (xml_handler_t)t_userinput, data);
-
-	if (!prof->ch[i].pkg[j].n)
-		prof->ch[i].n--;
+	
+	if (!pkg->n)
+		prof->ch[prof->n-1].n--;
 }
 
 static void t_chapter (xmlNodePtr node, void *data)
 {
-	prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-	prof->ch[prof->n-1].name = find_value(node->children, "title");
-	prof->ch[prof->n-1].ref = xmlGetProp(node, "id");
-	prof->ch[prof->n-1].pkg = NULL;
-	prof->ch[prof->n-1].n = 0;
+	chapter *ch = next_chpt(prof);
+	ch->name = find_value(node->children, "title");
+	ch->ref = xmlGetProp(node, "id");
 	foreach(node->children, "sect1", (xml_handler_t)t_sect1, data);
 }
 
@@ -190,13 +189,11 @@
 		return NULL;
 	}
 
-	prof = (profile *)malloc(sizeof(profile));
+	prof = new_prof();
 	prof->name = find_value(info->children, "title");
 	prof->vers = find_value(info->children, "subtitle");
 	prof->vers = strstr(prof->vers, " ");
 	prof->vers++;
-	prof->ch = NULL;
-	prof->n = 0;
 	foreach(node->children, "part", (xml_handler_t)t_part, r);
 	return prof;
 }

Modified: dev/concept/moongoo/syntax/book.c
===================================================================
--- dev/concept/moongoo/syntax/book.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/book.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -5,10 +5,9 @@
 #include <libalfs.h>
 #include <plugin.h>
 
-command *cmd;
-int num;
 profile *prof;
 replaceable *r;
+bool is_rng = false;
 
 profile *bookasprofile (xmlNodePtr node, replaceable *r);
 
@@ -24,120 +23,44 @@
 	return &book_plugin;
 }
 
-
-static void process_cmd (char *line, xmlNodePtr node)
+static void t_userinput (xmlNodePtr node, void *data)
 {
-	cmd = realloc(cmd, (++num)*sizeof(command));
-	cmd[num-1].role = parse_role(node);
-	
-	if (strcnt(line, " "))
-	{
-		cmd[num-1].cmd = strcut(line, 0, whereis(line, ' '));
-		cmd[num-1].arg = tokenize(notrail(strstr(line, " "), " "), 
-				" ", &cmd[num-1].n);
-	}
-	else
-	{
-		cmd[num-1].cmd = line;
-		cmd[num-1].arg = NULL;
-		cmd[num-1].n = 0;
-	}
+	// TODO: <replaceable> problems w/ the RNG book
+	foreach(node->children, "replaceable", (xml_handler_t)t_repl, r);
+	parse_cmdblock(prof, node); 
 }
 
-static void __t_userinput (xmlNodePtr node, void *data)
+static void t_sect1 (xmlNodePtr node, void *data)
 {
-	char *line;
+	package *pkg = next_pkg_title(prof, node);
+	foreach(node->children, "userinput", (xml_handler_t)t_userinput, NULL);
 
-	foreach(node->children, "replaceable", (xml_handler_t)t_repl, r);
-	line = squeeze(xmlNodeGetContent(node));
-	line = strkill(line, "\\\n");
-
-	if (strcnt(line, "\n"))
-	{
-		char *tmp;
-		
-		while ((line) && (strlen(line)))
-		{
-			if (!strncmp(line, "cat >", 5))
-			{
-				char *t = strnstr(line, "EOF", 2);
-				process_cmd(strcut(line, 0, t-line+3), node);
-				t+=2;
-				line=t;
-				continue;
-			}
-			
-			tmp = strsep(&line, "\n");
-			process_cmd(tmp, node);
-		}
-	}
-	else
-		process_cmd(line, node);
+	if (!pkg->n)
+		prof->ch[prof->n-1].n--;
 }
 
-static command *t_userinput (xmlNodePtr node, int *n)
+static void t_chapter (xmlNodePtr node, void *data)
 {
-	cmd = NULL;
-	num = 0;
-	foreach(node, "userinput", (xml_handler_t)__t_userinput, NULL);
-	*n = num;
-	return cmd;
+	chapter *ch = next_chpt(prof);
+	ch->name = xmlGetProp(node, "xreflabel");
+	ch->ref = xmlGetProp(node, "id");
+	foreach(node->children, is_rng ? "section" : "sect1", 
+		(xml_handler_t)t_sect1, NULL);
 }
 
-static void t_sect1 (xmlNodePtr node, void *data)
+static void t_part (xmlNodePtr node, void *data)
 {
-	int i, j;
-	char *title, *tmp;
-		
-	title = find_value(node->children, "title");
-
-	if (!title)
-	{
-		fprintf(stderr, "%s: No title found.\n", node->name);
-		return;
-	}
-
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
-	
-	tmp = strrchr(title, '-');
-	if (tmp)
-	{
-		char *t = strnrchr(title, '-', 2);
-		if ((t) && (isdigit(t[1])))
-			tmp = strdog(t, tmp); 
-	}
-	tmp = chrep(tmp, ' ', '\0');
-	prof->ch[i].pkg[j].vers = tmp ? strcut(tmp, 1, strlen(tmp)) : NULL;
-	prof->ch[i].pkg[j].name = tmp ? strcut(title, 0, 
-		strlen(title)-strlen(tmp)) : title;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
-	
-	prof->ch[i].pkg[j].build = t_userinput(node->children, 
-		&prof->ch[i].pkg[j].n);
-
-	if (!prof->ch[i].pkg[j].n)
-		prof->ch[i].n--;
+	foreach(node->children, "chapter", (xml_handler_t)t_chapter, NULL);
 }
 
-static void t_chapter (xmlNodePtr node)
-{
-	int i = prof->n-1;
-	prof->ch[i].name = xmlGetProp(node, "xreflabel");
-	prof->ch[i].ref = xmlGetProp(node, "id");
-	prof->ch[i].pkg = NULL;
-	prof->ch[i].n = 0;
-	foreach(node->children, "sect1", (xml_handler_t)t_sect1, NULL);
-}
-
 profile *bookasprofile (xmlNodePtr node, replaceable *_r)
 {
 	xmlNodePtr info = find_node(node, "bookinfo");
+	if (!info)
+	{
+		info = find_node(node, "info");
+		is_rng = true;
+	}
 
 	if (!info)
 	{
@@ -146,31 +69,11 @@
 	}
 
 	r = _r;
-	prof = (profile *)malloc(sizeof(profile));
+	prof = new_prof();
 	prof->name = find_value(info, "title");
 	prof->vers = find_value(info, "subtitle");
 	prof->vers = strcut(prof->vers, strlen("Version"), strlen(prof->vers));
-	prof->ch = NULL;
-	prof->n = 0;
 	
-	node = node->children;
-	while (node)
-	{
-		if (!strcmp(node->name, "part"))
-		{
-			xmlNodePtr cur = node->children;
-			while (cur)
-			{
-				if (!strcmp(cur->name, "chapter"))
-				{
-					prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-					t_chapter(cur);
-				}
-				cur=cur->next;
-			}
-		}
-		node=node->next;
-	}
-	
+	foreach(node->children, "part", (xml_handler_t)t_part, NULL);
 	return prof;
 }

Modified: dev/concept/moongoo/syntax/nalfs.c
===================================================================
--- dev/concept/moongoo/syntax/nalfs.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/nalfs.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -5,13 +5,13 @@
 #include <util.h>
 #include <plugin.h>
 
-// TODO: Having a big static buffer sucks
-#define BUF_LEN		3000
+#define BUF_LEN		4096	// Needs to be big enough to hold parsed cats
 
 profile *prof;
 char commando[BUF_LEN];
 
 profile *nalfs_profile (xmlNodePtr node, replaceable *r);
+static void t_alfs (xmlNodePtr node, void *data);
 
 static t_plug nalfs_plugin =
 {
@@ -25,36 +25,36 @@
 	return &nalfs_plugin;
 }
 
-void parse_unpack (xmlNodePtr node)
+static void parse_unpack (xmlNodePtr node)
 {
+	char *archive = find_value(node->children, "archive");
 	node=node->children;
-	snprintf(commando, BUF_LEN, "tar -C %s %s\n", find_value(node, 
-		"destination"), find_value(node, "archive"));
-	
-	// TODO: Handle <digest>
-	// find_value(node, "digest");
+	// TODO: squeeze() squeezes too much
+	snprintf(commando, BUF_LEN, "tar -C %s %s\necho \"%s  %s\"|md5sum -c -\n", 
+		find_value(node, "destination"), archive, find_value(node, "digest"),
+		archive);
 }
 
-void parse_remove (xmlNodePtr node)
+static void parse_remove (xmlNodePtr node)
 {
 	snprintf(commando, BUF_LEN, "rm -rf %s\n", xmlNodeGetContent(node));
 }
 
-void parse_make (xmlNodePtr node)
+static void parse_make (xmlNodePtr node)
 {
 	node=node->children;
 	snprintf(commando, BUF_LEN, "%s make %s\n", find_value(node, "prefix"), 
 		find_values(node, "param"));
 }
 
-void parse_configure (xmlNodePtr node)
+static void parse_configure (xmlNodePtr node)
 {
 	node = node->children;
 	snprintf(commando, BUF_LEN, "%s ./configure %s\n", find_value(node, 
 		"prefix"), find_values(node, "param"));
 }
 
-void parse_copy (xmlNodePtr node)
+static void parse_copy (xmlNodePtr node)
 {
 	char *orig[4] = { "force", "archive", "recursive", NULL };
 	char *repl[4] = { "-f", "-a", "-r", NULL };
@@ -64,43 +64,43 @@
 		"destination"));
 }
 
-void __parse_env (xmlNodePtr node, void *data)
+static void __parse_env (xmlNodePtr node, void *data)
 {
 	snprintf(commando, BUF_LEN, "export %s=\"%s\"\n", xmlGetProp(node, "name"), 
 			xmlNodeGetContent(node));
 }
 
-void parse_environment (xmlNodePtr node, void *data)
+static void parse_environment (xmlNodePtr node, void *data)
 {
 	foreach(node->children, "variable", (xml_handler_t)__parse_env, NULL);
 }
 
-void parse_base (xmlNodePtr node, void *data)
+static void parse_base (xmlNodePtr node, void *data)
 {
 	snprintf(commando, BUF_LEN, "cd %s\n", xmlNodeGetContent(node));
 }
 
-void parse_stageinfo (xmlNodePtr node)
+static void parse_stageinfo (xmlNodePtr node)
 {
 	foreach(node->children, "environment", (xml_handler_t)parse_environment, 
 		NULL);
 	foreach(node->children, "base", (xml_handler_t)parse_base, NULL);
 }
 
-void parse_textdump (xmlNodePtr node)
+static void parse_textdump (xmlNodePtr node)
 {
 	node=node->children;
 	snprintf(commando, BUF_LEN, "cat >%s << EOF\n%s\nEOF\n", find_value(node,
 		"file"), cut_trail(find_value(node, "content"), "="));
 }
 
-void parse_execute (xmlNodePtr node)
+static void parse_execute (xmlNodePtr node)
 {
 	snprintf(commando, BUF_LEN, "%s %s\n", xmlGetProp(node, "command"), 
 		find_values(node->children, "param"));
 }
 
-void parse_mkdir (xmlNodePtr node)
+static void parse_mkdir (xmlNodePtr node)
 {
 	char *orig[2] = { "parents", NULL };
 	char *repl[2] = { "-p", NULL };
@@ -109,14 +109,14 @@
 		orig, repl), find_value(node, "name"));
 }
 
-void parse_search_replace (xmlNodePtr node)
+static void parse_search_replace (xmlNodePtr node)
 {
 	node = node->children;
 	snprintf(commando, BUF_LEN, "sed -i 's%%%s%%%s%%g' %s\n", find_value(node,
 		"find"), find_value(node, "replace"), find_value(node, "file"));
 }
 
-void parse_permissions (xmlNodePtr node)
+static void parse_permissions (xmlNodePtr node)
 {
 	char *orig[2] = { "recursive", NULL };
 	char *repl[2] = { "-R", NULL };
@@ -125,7 +125,7 @@
 		find_value(node->children, "name"));
 }
 
-void parse_ownership (xmlNodePtr node)
+static void parse_ownership (xmlNodePtr node)
 {
 	char *orig[2] = { "recursive", NULL };
 	char *repl[2] = { "-R", NULL };
@@ -135,18 +135,18 @@
 		find_value(node->children, "name"));
 }
 
-void parse_patch (xmlNodePtr node)
+static void parse_patch (xmlNodePtr node)
 {
 	snprintf(commando, BUF_LEN, "patch %s\n", find_values(node->children, "param"));
 }
 
-void parse_move (xmlNodePtr node)
+static void parse_move (xmlNodePtr node)
 {
 	snprintf(commando, BUF_LEN, "mv %s %s\n", find_value(node->children, "source"), 
 		find_value(node->children, "destination"));
 }
 
-void parse_link (xmlNodePtr node)
+static void parse_link (xmlNodePtr node)
 {
 	char *orig[2] = { "force", NULL };
 	char *repl[2] = { "f", NULL };
@@ -155,34 +155,8 @@
 		find_value(node->children, "name"));
 }
 
-void process_cmd4 (char *cmd)
+static void t_stage2 (xmlNodePtr node, void *data)
 {
-	int i, j, k;
-	
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-	prof->ch[i].pkg[j].build = realloc(prof->ch[i].pkg[j].build, 
-		(++prof->ch[i].pkg[j].n)*sizeof(command));
-	k = prof->ch[i].pkg[j].n-1;
-
-	prof->ch[i].pkg[j].build[k].role = ROLE_NONE;
-	
-	if (strcnt(cmd, " "))
-	{
-		prof->ch[i].pkg[j].build[k].cmd = strcut(cmd, 0, whereis(cmd, ' '));
-		prof->ch[i].pkg[j].build[k].arg = tokenize(notrail(strstr(cmd, " "), 
-			" "),  " ", &prof->ch[i].pkg[j].build[k].n);
-	}
-	else
-	{
-		prof->ch[i].pkg[j].build[k].cmd = cmd;
-		prof->ch[i].pkg[j].build[k].arg = NULL;
-		prof->ch[i].pkg[j].build[k].n = 0;
-	}
-}
-
-void t_stage2 (xmlNodePtr node, void *data)
-{
 	//printf("%s\n", xmlGetProp(node, "name"));
 
 	node=node->children;
@@ -191,8 +165,6 @@
 		if ((node->type!=XML_TEXT_NODE)&&(node->type!=XML_COMMENT_NODE)&&
 			(node->type!=XML_XINCLUDE_START)&&(node->type!=XML_XINCLUDE_END))
 		{
-			char *temp;
-			
 			strcpy(commando, "");
 			
 			if (!strcmp(node->name, "unpack"))
@@ -241,80 +213,36 @@
 				parse_link(node);
 			else
 			if (!strcmp(node->name, "alfs"))
-			// TODO: Do recursive parsing
-				;
+				t_alfs(node, NULL);
 			else
 				fprintf(stderr, "The tag '%s' is not handled yet.\n", 
 					node->name);
 
-			strcpy(commando, squeeze(commando));
-			strcpy(commando, strkill(commando, "\\\n"));
-
-			temp = (char *)malloc(strlen(commando)+1);
-			strcpy(temp, commando);
-			
-			if (strcnt(temp, "\n"))
-			{
-				char *tmp;
-		
-				while ((temp) && (strlen(temp)))
-				{
-					if (!strncmp(temp, "cat >", 5))
-					{
-						char *t;
-						t = strnstr(temp, "EOF", 2);
-						process_cmd4(strcut(temp, 0, t-temp+3));
-						t+=2;
-						strcpy(temp, t);
-						continue;
-					}
-			
-					tmp = strsep(&temp, "\n");
-					process_cmd4(tmp);
-				}
-			}
-			else
-				process_cmd4(temp);
-			
+			parse_cmdblock_str(prof, commando);
 		}
 		node=node->next;
 	}
 }
 
-void t_pkg2 (xmlNodePtr node, void *data)
+static void t_pkg (xmlNodePtr node, void *data)
 {
-	int i, j;
-
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg,
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
-
-	prof->ch[i].pkg[j].name = xmlGetProp(node, "name");
-	prof->ch[i].pkg[j].vers = xmlGetProp(node, "version");
-	prof->ch[i].pkg[j].build = NULL;
-	prof->ch[i].pkg[j].n = 0;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
-	
+	package *pkg = next_pkg(prof);
+	pkg->name = xmlGetProp(node, "name");
+	pkg->vers = xmlGetProp(node, "version");
 	foreach(node->children, "stage", (xml_handler_t)t_stage2, NULL);
 }
 
-void t_alfs (xmlNodePtr node, void *data)
+static void t_alfs (xmlNodePtr node, void *data)
 {
-	// TODO: Handle <stage> node only pages, like chapter07/network.xml 
-	foreach(node->children, "package", (xml_handler_t)t_pkg2, NULL);
+	char *sect[3] = { "package", "stage", NULL };
+	foreach_multi(node->children, sect, (xml_handler_t)t_pkg, NULL);
 }
 
-void t_stage (xmlNodePtr node, void *data)
+static void t_stage (xmlNodePtr node, void *data)
 {
-	prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-	prof->ch[prof->n-1].name = xmlGetProp(node, "name");
-	prof->ch[prof->n-1].name = prof->ch[prof->n-1].name;
-	prof->ch[prof->n-1].pkg = NULL;
-	prof->ch[prof->n-1].n = 0;
+	chapter *ch = next_chpt(prof);
+	ch->name = xmlGetProp(node, "name");
+	ch->name = ch->name;
 	foreach(node->children, "alfs", (xml_handler_t)t_alfs, NULL);
 }
 
@@ -328,11 +256,8 @@
 		return NULL;
 	}
 	
-	prof = (profile *)malloc(sizeof(profile));
+	prof = new_prof();
 	prof->name = "nALFS legacy profile";
-	prof->vers = NULL;
-	prof->ch = NULL;
-	prof->n = 0;
 	foreach(node->children, "stage", (xml_handler_t)t_stage, NULL);
 	return prof;
 }

Deleted: dev/concept/moongoo/syntax/rng.c
===================================================================
--- dev/concept/moongoo/syntax/rng.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/rng.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,166 +0,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <libalfs.h>
-#include <plugin.h>
-
-command *cmd;
-int num;
-profile *prof;
-replaceable *r;
-
-profile *bookasprofile (xmlNodePtr node, replaceable *r);
-
-static t_plug book_plugin =
-{
-	name:	"LFS Relax-NG book as profile",
-	vers:	PLUG_VER,
-	parse:	bookasprofile
-};
-
-t_plug *getplug ()
-{
-	return &book_plugin;
-}
-
-
-static void process_cmd (char *line, xmlNodePtr node)
-{
-	cmd = realloc(cmd, (++num)*sizeof(command));
-	cmd[num-1].role = parse_role(node);
-	
-	if (strcnt(line, " "))
-	{
-		cmd[num-1].cmd = strcut(line, 0, whereis(line, ' '));
-		cmd[num-1].arg = tokenize(notrail(strstr(line, " "), " "), 
-				" ", &cmd[num-1].n);
-	}
-	else
-	{
-		cmd[num-1].cmd = line;
-		cmd[num-1].arg = NULL;
-		cmd[num-1].n = 0;
-	}
-}
-
-static void __t_userinput (xmlNodePtr node, void *data)
-{
-	char *line;
-
-	foreach(node->children, "replaceable", (xml_handler_t)t_repl, r);
-	line = squeeze(xmlNodeGetContent(node));
-	line = strkill(line, "\\\n");
-
-	if (strcnt(line, "\n"))
-	{
-		char *tmp;
-		
-		while ((line) && (strlen(line)))
-		{
-			if (!strncmp(line, "cat >", 5))
-			{
-				char *t = strnstr(line, "EOF", 2);
-				process_cmd(strcut(line, 0, t-line+3), node);
-				t+=2;
-				line=t;
-				continue;
-			}
-			
-			tmp = strsep(&line, "\n");
-			process_cmd(tmp, node);
-		}
-	}
-	else
-		process_cmd(line, node);
-}
-
-static command *t_userinput (xmlNodePtr node, int *n)
-{
-	cmd = NULL;
-	num = 0;
-	foreach(node, "userinput", (xml_handler_t)__t_userinput, NULL);
-	*n = num;
-	return cmd;
-}
-
-static void t_section (xmlNodePtr node, void *data)
-{
-	int i, j;
-	char *title, *tmp;
-		
-	title = find_value(node->children, "title");
-
-	if (!title)
-	{
-		fprintf(stderr, "%s: No title found.\n", node->name);
-		return;
-	}
-
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
-	
-	tmp = strrchr(title, '-');
-	if (tmp)
-	{
-		char *t = strnrchr(title, '-', 2);
-		if ((t) && (isdigit(t[1])))
-			tmp = strdog(t, tmp); 
-	}
-	tmp = chrep(tmp, ' ', '\0');
-	prof->ch[i].pkg[j].vers = tmp ? strcut(tmp, 1, strlen(tmp)) : NULL;
-	prof->ch[i].pkg[j].name = tmp ? strcut(title, 0, 
-		strlen(title)-strlen(tmp)) : title;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
-	
-	prof->ch[i].pkg[j].build = t_userinput(node->children, 
-		&prof->ch[i].pkg[j].n);
-
-	if (!prof->ch[i].pkg[j].n)
-		prof->ch[i].n--;
-}
-
-static void t_chapter (xmlNodePtr node, void *data)
-{
-	int i;
-
-	prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-	i = prof->n-1;
-	prof->ch[i].name = xmlGetProp(node, "xreflabel");
-	prof->ch[i].ref = xmlGetProp(node, "id");
-	prof->ch[i].pkg = NULL;
-	prof->ch[i].n = 0;
-	foreach(node->children, "section", (xml_handler_t)t_section, NULL);
-}
-
-void t_part (xmlNodePtr node, void *data)
-{
-	foreach(node->children, "chapter", (xml_handler_t)t_chapter, NULL);
-}
-
-profile *bookasprofile (xmlNodePtr node, replaceable *_r)
-{
-	xmlNodePtr info = find_node(node, "info");
-
-	if (!info)
-	{
-		fprintf(stderr, "XML document is not a valid LFS RNG book.\n");
-		return NULL;
-	}
-
-	r = _r;
-	prof = (profile *)malloc(sizeof(profile));
-	prof->name = find_value(info, "title");
-	prof->vers = find_value(info, "subtitle");
-	prof->vers = strcut(prof->vers, strlen("Version"), strlen(prof->vers));
-	prof->ch = NULL;
-	prof->n = 0;
-	
-	foreach(node->children, "part", (xml_handler_t)t_part, NULL);
-	return prof;
-}

Modified: dev/concept/moongoo/syntax/sample.c
===================================================================
--- dev/concept/moongoo/syntax/sample.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/sample.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -4,7 +4,8 @@
  * parser function, which needs to take one xmlNodePtr as argument and
  * return a pointer to a profile struct (see alfs.h). You now can just
  * put your parser code into the parser function using the libalfs 
- * routines. 
+ * routines. Use the routines from libalfs/parse.h for rapid parser
+ * development.
  * 
  */
 

Modified: dev/concept/moongoo/syntax/syn.c
===================================================================
--- dev/concept/moongoo/syntax/syn.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/syntax/syn.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -1,7 +1,4 @@
-#include <string.h>
-
-#include <alfs.h>
-#include <util.h>
+#include <libalfs.h>
 #include <plugin.h>
 
 profile *prof;
@@ -21,85 +18,29 @@
 }
 
 // TODO: Complete syn support
-void process_cmd2 (char *line, xmlNodePtr node)
-{
-	int i, j, k;
-
-	i = prof->n-1;
-	j = prof->ch[i].n-1;
-
-	prof->ch[i].pkg[j].build = realloc(prof->ch[i].pkg[j].build,
-			(++prof->ch[i].pkg[j].n)*sizeof(command));
-	k = prof->ch[i].pkg[j].n-1;
-
-	prof->ch[i].pkg[j].build[k].role = ROLE_NONE;
-
-	if (strcnt(line, " "))
-	{
-		prof->ch[i].pkg[j].build[k].cmd = strcut(line, 0, whereis(line, ' '));
-		prof->ch[i].pkg[j].build[k].arg = tokenize(notrail(strstr(line, " "), 
-				" "), " ", &prof->ch[i].pkg[j].build[k].n);
-	}
-	else
-	{
-		prof->ch[i].pkg[j].build[k].cmd = line;
-		prof->ch[i].pkg[j].build[k].arg = NULL;
-		prof->ch[i].pkg[j].build[k].n = 0;
-	}
-}
-
 void t_shell (xmlNodePtr node, void *data)
 {
-	char *line = squeeze(xmlNodeGetContent(node));
-	line = strkill(line, "\\\n");
-	
-	if (strcnt(line, "\n"))
-	{
-		char *tmp;
-
-		while ((line) && (strlen(line)))
-		{
-			tmp = strsep(&line, "\n");
-			process_cmd2(tmp, node);
-		}
-	}
-	else
-		process_cmd2(line, node);
+	parse_cmdblock(prof, node);
 }
 
-void t_pkg (xmlNodePtr node, void *data)
+static void t_pkg (xmlNodePtr node, void *data)
 {
-	int i, j;
-	char *tmp;
+	char *tmp = find_value(node, "title");
+	package *pkg = next_pkg(prof);
 
-	i = prof->n-1;
-	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
-			(++prof->ch[i].n)*sizeof(package));
-	j = prof->ch[i].n-1;
-
-	tmp = find_value(node, "title");
-	prof->ch[i].pkg[j].name = strcut(tmp, 0, whereis(tmp, ' '));
-	prof->ch[i].pkg[j].vers = find_value(node, "version");
-	prof->ch[i].pkg[j].build = NULL;
-	prof->ch[i].pkg[j].n = 0;
-	prof->ch[i].pkg[j].dl = NULL;
-	prof->ch[i].pkg[j].m = 0;
-	prof->ch[i].pkg[j].dep = NULL;
-	prof->ch[i].pkg[j].o = 0;
-	
+	pkg->name = strcut(tmp, 0, whereis(tmp, ' '));
+	pkg->vers = find_value(node, "version");
 	foreach(node->children, "shell", (xml_handler_t)t_shell, NULL);
 
-	if (!prof->ch[i].pkg[j].n)
-		prof->ch[i].n--;
+	if (!pkg->n)
+		prof->ch[prof->n-1].n--;
 }
 
-void t_section (xmlNodePtr node)
+static void t_section (xmlNodePtr node)
 {	
-	int i = prof->n-1;
-	prof->ch[i].name = xmlGetProp(node, "title");
-	prof->ch[i].ref = prof->ch[i].name;
-	prof->ch[i].pkg = NULL;
-	prof->ch[i].n = 0;
+	chapter *ch = next_chpt(prof);
+	ch->name = xmlGetProp(node, "title");
+	ch->ref = ch->name;
 	foreach(node->children, "page", (xml_handler_t)t_pkg, NULL);
 }
 
@@ -113,22 +54,9 @@
 		return NULL;
 	}
 
-	prof = (profile *)malloc(sizeof(profile));
+	prof = new_prof();
 	prof->name = find_value(node, "title");
 	prof->vers = find_value(node, "version");
-	prof->ch = NULL;
-	prof->n = 0;
-
-	node = node->children;
-	while (node)
-	{
-		if (!strcmp(node->name, "section"))
-		{
-			prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
-			t_section(node);
-		}
-		node = node->next;
-	}
-
+	foreach(node->children, "section", (xml_handler_t)t_section, NULL);
 	return prof;
 }

Modified: dev/concept/moongoo/url.c
===================================================================
--- dev/concept/moongoo/url.c	2004-12-11 23:49:43 UTC (rev 1645)
+++ dev/concept/moongoo/url.c	2004-12-12 22:42:49 UTC (rev 1646)
@@ -2,7 +2,6 @@
 
 #include <url.h>
 
-// TODO: Bison 1.875a temporary not available
 // TODO: No splitout GCC tarballs
 // TODO: Tcl URL is not yet found (tcl8.4.7-src.tar.gz)
 // TODO: Vim-lang will not be downloaded atm.




More information about the alfs-log mailing list