r1610 - dev/concept/moongoo

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Tue Nov 30 17:32:17 PST 2004


Author: neocool
Date: 2004-11-30 18:32:17 -0700 (Tue, 30 Nov 2004)
New Revision: 1610

Added:
   dev/concept/moongoo/syn.c
   dev/concept/moongoo/syn.h
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/book.c
   dev/concept/moongoo/moongoo.c
Log:
* Added preliminary support for syn to show that multiple syntaxes
	can be easily supported.
* Some fixes.


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-01 00:40:19 UTC (rev 1609)
+++ dev/concept/moongoo/Makefile	2004-12-01 01:32:17 UTC (rev 1610)
@@ -7,9 +7,10 @@
 CFLAGS+=-Wall -Werror -g3
 
 BIN=moongoo
-OBJS=alfs.o book.o util.o repl.o
+OBJS=alfs.o book.o util.o repl.o syn.o
 
 BOOK=~/projects/alfs/book/index.xml
+#BOOK=~/projects/hive/unstable/profile.xml
 
 .PHONY: all clean compile run memcheck debug todo upload bug
 

Modified: dev/concept/moongoo/book.c
===================================================================
--- dev/concept/moongoo/book.c	2004-12-01 00:40:19 UTC (rev 1609)
+++ dev/concept/moongoo/book.c	2004-12-01 01:32:17 UTC (rev 1610)
@@ -119,6 +119,12 @@
 {
 	xmlNodePtr info = find_node(node, "bookinfo");
 	__r = init_repl(MOO_XML);
+
+	if (!info)
+	{
+		fprintf(stderr, "XML document is not a valid LFS book.\n");
+		return NULL;
+	}
 	
 	prof = (profile *)malloc(sizeof(profile));
 	prof->name = find_value(info, "title");

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-12-01 00:40:19 UTC (rev 1609)
+++ dev/concept/moongoo/moongoo.c	2004-12-01 01:32:17 UTC (rev 1610)
@@ -3,6 +3,7 @@
 
 #include <alfs.h>
 #include <book.h>
+#include <syn.h>
 #include <repl.h>
 #include <util.h>
 
@@ -28,9 +29,14 @@
 	resolve_entities(cur);
 	
 	prof=bookasprofile(cur);
-	set_filter(default_filter);
-	print_profile(*prof);
+	//prof=syn_profile(cur);
 	
+	if (prof)
+	{
+		set_filter(default_filter);
+		print_profile(*prof);
+	}
+	
 	xmlFreeDoc(doc);
 	return 0;
 }

Added: dev/concept/moongoo/syn.c
===================================================================
--- dev/concept/moongoo/syn.c	2004-12-01 00:40:19 UTC (rev 1609)
+++ dev/concept/moongoo/syn.c	2004-12-01 01:32:17 UTC (rev 1610)
@@ -0,0 +1,114 @@
+#include <string.h>
+
+#include <util.h>
+#include <syn.h>
+
+profile *prof;
+
+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 = 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);
+}
+
+void t_pkg (xmlNodePtr node, void *data)
+{
+	int i, j;
+	char *tmp;
+
+	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;
+	foreach(node->children, "shell", (xml_handler_t)t_shell, NULL);
+
+	if (!prof->ch[i].pkg[j].n)
+		prof->ch[i].n--;
+}
+
+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;
+	foreach(node->children, "package", (xml_handler_t)t_pkg, NULL);
+}
+
+profile *syn_profile (xmlNodePtr node)
+{
+	node = find_node(node, "hive");
+
+	if (!node)
+	{
+		fprintf(stderr, "XML document is not a valid Hive profile.\n");
+		return NULL;
+	}
+
+	prof = (profile *)malloc(sizeof(profile));
+	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"))
+		{
+			printf("%s\n", xmlGetProp(node, "title"));
+			prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
+			t_section(node);
+		}
+		node = node->next;
+	}
+
+	return prof;
+}

Added: dev/concept/moongoo/syn.h
===================================================================
--- dev/concept/moongoo/syn.h	2004-12-01 00:40:19 UTC (rev 1609)
+++ dev/concept/moongoo/syn.h	2004-12-01 01:32:17 UTC (rev 1610)
@@ -0,0 +1,8 @@
+#ifndef __SYN_H__
+#define __SYN_H__
+
+#include <alfs.h>
+
+profile *syn_profile (xmlNodePtr node);
+
+#endif




More information about the alfs-log mailing list