r1607 - dev/concept/moongoo

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Tue Nov 30 14:07:35 PST 2004


Author: neocool
Date: 2004-11-30 15:07:35 -0700 (Tue, 30 Nov 2004)
New Revision: 1607

Added:
   dev/concept/moongoo/moo.xml
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/alfs.c
   dev/concept/moongoo/alfs.h
   dev/concept/moongoo/book.c
   dev/concept/moongoo/book.h
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/repl.c
   dev/concept/moongoo/repl.h
Log:
* Replaceables are configurable in an XML file now
* Some cleanups
* Parsing of 'cat > moo << EOF' done


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/Makefile	2004-11-30 22:07:35 UTC (rev 1607)
@@ -11,7 +11,7 @@
 
 BOOK=~/projects/alfs/book/index.xml
 
-.PHONY: all clean compile run memcheck debug todo upload
+.PHONY: all clean compile run memcheck debug todo upload bug
 
 all: run
 
@@ -38,6 +38,9 @@
 	@scp moongoo-*.tar.bz2 l14h.org:~/public_html/nALFS2/snap/
 	@rm -f moongoo-*.tar.bz2
 
+bug: 
+	@grep "BUG:" *.c *.h|cut -d" " -f3-|sort
+
 $(BIN): $(OBJS)
 alfs.o: alfs.h
 util.o: util.h

Modified: dev/concept/moongoo/alfs.c
===================================================================
--- dev/concept/moongoo/alfs.c	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/alfs.c	2004-11-30 22:07:35 UTC (rev 1607)
@@ -198,7 +198,7 @@
 	{
 		if (node->type==XML_ENTITY_REF_NODE)
 		{
-			// TODO: Resolve entities which are outside text nodes
+			// BUG: Does not resolve entities which are outside text nodes
 			if ((node->prev) && (node->prev->type==XML_TEXT_NODE) &&
 				(strcmp(node->prev->parent->name, "title")))
 			{

Modified: dev/concept/moongoo/alfs.h
===================================================================
--- dev/concept/moongoo/alfs.h	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/alfs.h	2004-11-30 22:07:35 UTC (rev 1607)
@@ -19,14 +19,6 @@
 
 typedef struct
 {
-	char *name;
-	mode_t mode;
-	bool append;
-	char *content;
-} file;
-
-typedef struct
-{
 	char *cmd;
 	char **arg;
 	int n;

Modified: dev/concept/moongoo/book.c
===================================================================
--- dev/concept/moongoo/book.c	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/book.c	2004-11-30 22:07:35 UTC (rev 1607)
@@ -7,6 +7,7 @@
 
 command *cmd;
 profile *prof;
+replaceable *__r;
 int num;
 
 void t_sect1 (xmlNodePtr node, void *data);
@@ -14,14 +15,6 @@
 void __t_userinput (xmlNodePtr node, void *data);
 command *t_userinput (xmlNodePtr node, int *n);
 
-// TODO: Parse 'cat > foo' commands
-file *parse_cat (char *str)
-{
-	//file *f = (file *)malloc(sizeof(file));
-	//printf("%s\n\n", str);
-	return NULL;
-}
-
 void t_sect1 (xmlNodePtr node, void *data)
 {
 	int i;
@@ -73,7 +66,7 @@
 {
 	char *line;
 
-	foreach(node->children, "replaceable", (xml_handler_t)t_repl, NULL);
+	foreach(node->children, "replaceable", (xml_handler_t)t_repl, __r);
 	line = squeeze(xmlNodeGetContent(node));
 	line = strkill(line, "\\\n");
 
@@ -86,7 +79,7 @@
 			if (!strncmp(line, "cat >", 5))
 			{
 				char *t = strnstr(line, "EOF", 2);
-				parse_cat(strcut(line, 0, t-line+3));
+				process_cmd(strcut(line, 0, t-line+3), node);
 				t+=2;
 				line=t;
 				continue;
@@ -111,7 +104,7 @@
 
 profile *bookasprofile (xmlNodePtr node)
 {
-	init_repl();
+	__r = init_repl(MOO_XML);
 	prof = (profile *)malloc(sizeof(profile));
 	prof->pkg = NULL;
 	prof->n = 0;

Modified: dev/concept/moongoo/book.h
===================================================================
--- dev/concept/moongoo/book.h	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/book.h	2004-11-30 22:07:35 UTC (rev 1607)
@@ -6,6 +6,5 @@
 void t_sect1 (xmlNodePtr node, void *data);
 command *t_userinput (xmlNodePtr node, int *n);
 profile *bookasprofile (xmlNodePtr node);
-file *parse_cat (char *str);
 
 #endif

Added: dev/concept/moongoo/moo.xml
===================================================================
--- dev/concept/moongoo/moo.xml	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/moo.xml	2004-11-30 22:07:35 UTC (rev 1607)
@@ -0,0 +1,25 @@
+<answers>
+<!-- Install partition -->
+<answer name="[xxx]">discs/disc0/part5</answer>
+<answer name="[fff]">ext3</answer>
+<!-- /usr partition -->
+<answer name="[zzz]"></answer>
+<!-- Swap partition -->
+<answer name="[yyy]">discs/disc0/part10</answer>
+<!-- Paper size -->
+<answer name="[paper_size]">A4</answer>
+<!-- Network settings -->
+<answer name="[FQDN]">Lenin.Ass</answer>
+<answer name="[HOSTNAME]">Lenin</answer>
+<answer name="[192.168.1.1]">192.168.1.23</answer>
+<answer name="[Your Domain Name]">Ass</answer>
+<answer name="[IP address of your nameserver]">217.237.149.161</answer>
+<!-- Locales -->
+<answer name="[ll]">de</answer>
+<answer name="[CC]">DE at euro</answer>
+<answer name="[arguments for loadkeys]">de-latin1-nodeadkeys</answer>
+<answer name="[arguments for setfont]">lat9u-16</answer>
+<answer name="[/path/to/your/keymap]"></answer>
+<!-- Paths -->
+<answer name="[unpacked sources dir]">/usr/src</answer>
+</answers>

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/moongoo.c	2004-11-30 22:07:35 UTC (rev 1607)
@@ -32,7 +32,8 @@
 		
 		//if (!strcmp(pkg.name, "Module-Init-Tools"))
 		//if (!strcmp(pkg.name, "Creating a file system"))
-		if (!strcmp(pkg.name, "Linux"))
+		//if (!strcmp(pkg.name, "Linux"))
+		if (!strcmp(pkg.name, "Creating the /etc/fstab file"))
 			print_pkg(pkg);
 	}
 	

Modified: dev/concept/moongoo/repl.c
===================================================================
--- dev/concept/moongoo/repl.c	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/repl.c	2004-11-30 22:07:35 UTC (rev 1607)
@@ -3,64 +3,54 @@
 #include <repl.h>
 #include <alfs.h>
 
-replaceable r[REPLC];
-
 void t_repl (xmlNodePtr node, void *data)
 {
-	int i;
 	xmlNodePtr text = find_node(node->children, "text");
+	int i=0;
 	char *repl = xmlNodeGetContent(text);
+	replaceable *r = (replaceable *)data;
 	
-	for (i=0;i<REPLC;i++)
+	if (!r)
+		return;
+	
+	while (r[i].orig)
+	{
 		if (!strcmp(repl, r[i].orig))
 		{
 			xmlNodeSetContent(node, r[i].repl);
 			return;
 		}
+		i++;
+	}
 	
 	fprintf(stderr, "Unknown replaceable: %s\n", repl);
 }
 
-// TODO: Make <replaceable> actually configurable
-void init_repl ()
+replaceable *init_repl (char *fname)
 {
-	// LFS install partition
-	r[0].orig="[xxx]";
-	r[0].repl="/dev/discs/disc0/part5";
-	r[14].orig="[fff]";
-	r[14].repl="ext3";
-	// LFS user partition
-	r[12].orig="[zzz]";
-	r[12].repl="";
-	// Swap partition
-	r[1].orig="[yyy]";
-	r[1].repl="/dev/discs/disc0/part10";
-	// Paper size
-	r[2].orig="[paper_size]";
-	r[2].repl="A4";
-	// Network settings
-	r[3].orig="[FQDN]";
-	r[3].repl="Lenin.Ass";
-	r[4].orig="[HOSTNAME]";
-	r[4].repl="Lenin";
-	r[5].orig="[192.168.1.1]";
-	r[5].repl="192.168.1.23";
-	r[10].orig="[Your Domain Name]";
-	r[10].repl="Ass";
-	r[11].orig="[IP address of your nameserver]";
-	r[11].repl="217.237.149.161";
-	// Locales
-	r[6].orig="[ll]";
-	r[6].repl="de";
-	r[7].orig="[CC]";
-	r[7].repl="DE at euro";
-	r[8].orig="[arguments for loadkeys]";
-	r[8].repl="de-latin1-nodeadkeys";
-	r[9].orig="[arguments for setfont]";
-	r[9].repl="lat9u-16";
-	r[13].orig="[/path/to/your/keymap]";
-	r[13].repl="";
-	// Pathes
-	r[15].orig="[unpacked sources dir]";
-	r[15].repl="/usr/src";
+	replaceable *r = NULL;
+	xmlDocPtr doc;
+	xmlNodePtr node;
+	int count=0;
+
+	doc=xmlParseFile(fname);
+	if (!doc)
+		return NULL;
+	node=xmlDocGetRootElement(doc)->children;
+
+	while (node)
+	{
+		if (!strcmp(node->name, "answer"))
+		{
+			r = realloc(r, (++count)*sizeof(replaceable));
+			r[count-1].orig = xmlGetProp(node, "name");
+			r[count-1].repl = xmlNodeGetContent(node);
+		}
+		node=node->next;
+	}
+
+	r = realloc(r, (++count)*sizeof(replaceable));
+	r[count-1].orig = NULL;
+	r[count-1].repl = NULL;
+	return r;
 }	

Modified: dev/concept/moongoo/repl.h
===================================================================
--- dev/concept/moongoo/repl.h	2004-11-30 21:35:14 UTC (rev 1606)
+++ dev/concept/moongoo/repl.h	2004-11-30 22:07:35 UTC (rev 1607)
@@ -3,11 +3,10 @@
 
 #include <alfs.h>
 
-#define REPLC	16
+// TODO: Make moo.xml location configurable
+#define MOO_XML		"moo.xml"
 
-extern replaceable r[REPLC];
-
 void t_repl (xmlNodePtr node, void *data);
-void init_repl ();
+replaceable *init_repl (char *fname);
 
 #endif




More information about the alfs-log mailing list