r1612 - dev/concept/moongoo

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Wed Dec 1 08:33:05 PST 2004


Author: neocool
Date: 2004-12-01 09:33:04 -0700 (Wed, 01 Dec 2004)
New Revision: 1612

Added:
   dev/concept/moongoo/devel.c
   dev/concept/moongoo/devel.h
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/alfs.c
   dev/concept/moongoo/alfs.h
   dev/concept/moongoo/nalfs.c
   dev/concept/moongoo/util.c
   dev/concept/moongoo/util.h
Log:
* Added devel functions for rapid parser development
* nALFS parser progressing...


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/Makefile	2004-12-01 16:33:04 UTC (rev 1612)
@@ -7,7 +7,7 @@
 CFLAGS+=-Wall -Werror -g3
 
 BIN=moongoo
-OBJS=alfs.o book.o util.o repl.o syn.o nalfs.o ass.o
+OBJS=alfs.o book.o util.o repl.o syn.o nalfs.o ass.o devel.o
 
 #BOOK=~/projects/alfs/book/index.xml
 BOOK=~/projects/alfs/lfs-profile/LFS.xml
@@ -51,3 +51,4 @@
 repl.o: repl.h
 nalfs.o: nalfs.h
 ass.o: ass.h
+devel.o: devel.h

Modified: dev/concept/moongoo/alfs.c
===================================================================
--- dev/concept/moongoo/alfs.c	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/alfs.c	2004-12-01 16:33:04 UTC (rev 1612)
@@ -109,11 +109,31 @@
 	return NULL;
 }
 
+char *find_values (xmlNodePtr node, char *str)
+{
+	char *ret;
+
+	if ((!node)||(!str))
+		return "";
+
+	ret = (char *)malloc(1);
+	strcpy(ret, "");
+
+	while (node)
+	{
+		if (!strcmp(node->name, str))
+			ret = strdog2(ret, xmlNodeGetContent(node));
+		node = node->next;
+	}
+
+	return ret;
+}			
+
 char *find_value (xmlNodePtr node, char *str)
 {
 	xmlNodePtr moo = find_node(node, str);
 	if (!moo)
-		return NULL;
+		return "";
 	return xmlNodeGetContent(moo);
 }
 

Modified: dev/concept/moongoo/alfs.h
===================================================================
--- dev/concept/moongoo/alfs.h	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/alfs.h	2004-12-01 16:33:04 UTC (rev 1612)
@@ -88,6 +88,7 @@
 void foreach (xmlNodePtr node, char *str, xml_handler_t func, void *data);
 xmlNodePtr find_node (xmlNodePtr root, char *str);
 char *find_value (xmlNodePtr node, char *str);
+char *find_values (xmlNodePtr node, char *str);
 char *entity_val (char *name);
 
 char *role2str (role role);

Added: dev/concept/moongoo/devel.c
===================================================================
--- dev/concept/moongoo/devel.c	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/devel.c	2004-12-01 16:33:04 UTC (rev 1612)
@@ -0,0 +1,43 @@
+#include <string.h>
+#include <stdbool.h>
+
+#include <devel.h>
+
+void dbg_print (xmlNodePtr node, char **known)
+{
+	node = node->children;
+	while (node)
+	{
+		if ((node->type!=XML_TEXT_NODE) && (node->type!=XML_COMMENT_NODE) &&
+			(node->type!=XML_XINCLUDE_START) && 
+			(node->type!=XML_XINCLUDE_END))
+		{
+			bool k = false;
+			if (known)
+			{
+				int i=0;
+				while (known[i])
+				{
+					if (!strcmp(node->name, known[i]))
+						k = true;
+					i++;
+				}
+			}
+			
+			if (!k)
+				printf("%s\n", node->name);
+		}
+		node=node->next;
+	}
+}
+
+void dbg_print2 (xmlNodePtr node, char *name)
+{
+	node = node->children;
+	while (node)
+	{
+		if (!strcmp(node->name, name))
+			printf("%s\n", xmlNodeGetContent(node));
+		node = node->next;
+	}
+}

Added: dev/concept/moongoo/devel.h
===================================================================
--- dev/concept/moongoo/devel.h	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/devel.h	2004-12-01 16:33:04 UTC (rev 1612)
@@ -0,0 +1,9 @@
+#ifndef __DEVEL_H__
+#define __DEVEL_H__
+
+#include <alfs.h>
+
+void dbg_print (xmlNodePtr node, char **known);
+void dbg_print2 (xmlNodePtr node, char *name);
+
+#endif

Modified: dev/concept/moongoo/nalfs.c
===================================================================
--- dev/concept/moongoo/nalfs.c	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/nalfs.c	2004-12-01 16:33:04 UTC (rev 1612)
@@ -1,11 +1,194 @@
+#include <string.h>
+
 #include <nalfs.h>
+#include <util.h>
+#include <devel.h>
 
 profile *prof;
 
-// TODO: Parse all nALFS legacy commands to command* structs
+void parse_unpack (xmlNodePtr node)
+{
+	// TODO: Handle <unpack>
+}
+
+void parse_remove (xmlNodePtr node)
+{
+	// TODO: Handle <remove>
+}
+
+void parse_make (xmlNodePtr node)
+{
+	/*node = node->children;
+	printf("%s make %s\n", find_value(node, "prefix"), 
+		find_values(node, "param"));*/
+}
+
+void parse_configure (xmlNodePtr node)
+{
+	/*node = node->children;
+	printf("%s ./configure %s\n", find_value(node, "prefix"),
+		find_values(node, "param"));*/
+}
+
+void parse_copy (xmlNodePtr node)
+{
+	char *known[4] = { "source", "destination", "option", NULL };
+	dbg_print(node, known);
+	dbg_print2(node, "option");
+}
+
+void parse_environment (xmlNodePtr node)
+{
+}
+
+void parse_stageinfo (xmlNodePtr node)
+{
+	node = node->children;
+	while (node)
+	{
+		if (node->type!=XML_TEXT_NODE)
+		{
+			if (!strcmp(node->name, "environment"))
+				parse_environment(node);
+			else
+			if (!strcmp(node->name, "base"))
+				; //xmlNodeGetContent(node);
+			else
+				fprintf(stderr, "Tag '%s' not handled.\n", node->name);
+		}
+		node = node->next;
+	}
+}
+
+void parse_textdump (xmlNodePtr node)
+{
+}
+
+void parse_execute (xmlNodePtr node)
+{
+}
+
+void parse_mkdir (xmlNodePtr node)
+{
+}
+
+void parse_search_replace (xmlNodePtr node)
+{
+	/*node = node->children;
+	printf("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)
+{
+}
+
+void parse_ownership (xmlNodePtr node)
+{
+	xmlNodePtr cur;
+	char *user, *group, *opts, *names;
+	
+	user = xmlGetProp(node, "user");
+	group = xmlGetProp(node, "group");
+
+	opts = (char *)malloc(2);
+	strcpy(opts, "");
+	names = (char *)malloc(2);
+	strcpy(names, "");
+	
+	cur = node->children;
+	while (cur)
+	{
+		if (!strcmp(cur->name, "option"))
+			if (!strcmp(xmlNodeGetContent(cur), "recursive"))
+				opts = strdog2(opts, "-R");	
+		
+		if (!strcmp(cur->name, "name"))
+			names = strdog2(names, xmlNodeGetContent(cur));
+
+		cur = cur->next;
+	}
+
+	/*ret = (char *)malloc(512);
+	snprintf(ret, 512, "chown %s %s:%s %s", opts, user, group, names);*/
+}
+
+void parse_patch (xmlNodePtr node)
+{
+}
+
+void parse_move (xmlNodePtr node)
+{
+}
+
+void parse_link (xmlNodePtr node)
+{
+}
+
 void t_stage2 (xmlNodePtr node, void *data)
 {
-	printf("%s\n", xmlGetProp(node, "name"));
+	//printf("%s\n", xmlGetProp(node, "name"));
+
+	node=node->children;
+	while (node)
+	{
+		if ((node->type!=XML_TEXT_NODE)&&(node->type!=XML_COMMENT_NODE)&&
+			(node->type!=XML_XINCLUDE_START)&&(node->type!=XML_XINCLUDE_END))
+		{
+			if (!strcmp(node->name, "unpack"))
+				parse_unpack(node);
+			else
+			if (!strcmp(node->name, "remove"))
+				parse_remove(node);
+			else
+			if (!strcmp(node->name, "make"))
+				parse_make(node);
+			else
+			if (!strcmp(node->name, "configure"))
+				parse_configure(node);
+			else
+			if (!strcmp(node->name, "copy"))
+				parse_copy(node);
+			else
+			if (!strcmp(node->name, "stageinfo"))
+				parse_stageinfo(node);
+			else
+			if (!strcmp(node->name, "textdump"))
+				parse_textdump(node);
+			else
+			if (!strcmp(node->name, "execute"))
+				parse_textdump(node);
+			else
+			if (!strcmp(node->name, "mkdir"))
+				parse_mkdir(node);
+			else
+			if (!strcmp(node->name, "search_replace"))
+				parse_search_replace(node);
+			else
+			if (!strcmp(node->name, "permissions"))
+				parse_permissions(node);
+			else
+			if (!strcmp(node->name, "ownership"))
+				parse_ownership(node);
+			else
+			if (!strcmp(node->name, "patch"))
+				parse_patch(node);
+			else
+			if (!strcmp(node->name, "move"))
+				parse_move(node);
+			else
+			if (!strcmp(node->name, "link"))
+				parse_link(node);
+			else
+			if (!strcmp(node->name, "alfs"))
+			// TODO: Do recursive parsing
+				;
+			else
+				fprintf(stderr, "The tag '%s' is not handled yet.\n", 
+					node->name);
+		}
+		node=node->next;
+	}
 }
 
 void t_pkg2 (xmlNodePtr node, void *data)
@@ -16,7 +199,8 @@
 	prof->ch[i].pkg = realloc(prof->ch[i].pkg,
 			(++prof->ch[i].n)*sizeof(package));
 	j = prof->ch[i].n-1;
-	
+
+	//printf("%s\n", xmlGetProp(node, "name"));
 	prof->ch[i].pkg[j].name = xmlGetProp(node, "name");
 	// TODO: <package version="moo"> cannot be parsed yet
 	prof->ch[i].pkg[j].vers = NULL;

Modified: dev/concept/moongoo/util.c
===================================================================
--- dev/concept/moongoo/util.c	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/util.c	2004-12-01 16:33:04 UTC (rev 1612)
@@ -37,6 +37,23 @@
 	return ret;
 }
 
+char *strdog2 (char *str1, char *str2)
+{
+	char *ret;
+
+	if ((!str1)||(!str2))
+		return NULL;
+	
+	ret=(char *)malloc(strlen(str1)+strlen(str2)+2);
+
+	strcpy(ret, str1);
+	if (strlen(str1)>0)
+		strcat(ret, " ");
+	strcat(ret, str2);
+	free(str1);
+	return ret;
+}
+
 char *chrep (char *str, char old, char new)
 {
 	char *ret;

Modified: dev/concept/moongoo/util.h
===================================================================
--- dev/concept/moongoo/util.h	2004-12-01 12:18:53 UTC (rev 1611)
+++ dev/concept/moongoo/util.h	2004-12-01 16:33:04 UTC (rev 1612)
@@ -27,6 +27,7 @@
 
 char *lower_case (char *str);
 char *strdog (char *str1, char *str2);
+char *strdog2 (char *str1, char *str2);
 char *chrep (char *str, char old, char new);
 char **tokenize (char *str, char *token, int *i);
 char *strrep (char *str, char *old, char *new);




More information about the alfs-log mailing list