r1620 - dev/concept/moongoo

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Thu Dec 2 12:43:57 PST 2004


Author: neocool
Date: 2004-12-02 13:43:57 -0700 (Thu, 02 Dec 2004)
New Revision: 1620

Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/nalfs.c
Log:
Getopt support.


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-02 13:44:58 UTC (rev 1619)
+++ dev/concept/moongoo/Makefile	2004-12-02 20:43:57 UTC (rev 1620)
@@ -9,8 +9,8 @@
 BIN=moongoo
 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
+BOOK=~/projects/alfs/book/index.xml
+#BOOK=~/projects/alfs/lfs-profile/LFS.xml
 #BOOK=~/projects/alfs/ass/index.xml
 #BOOK=~/projects/hive/unstable/profile.xml
 

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-12-02 13:44:58 UTC (rev 1619)
+++ dev/concept/moongoo/moongoo.c	2004-12-02 20:43:57 UTC (rev 1620)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <getopt.h>
 
 #include <alfs.h>
 #include <book.h>
@@ -13,32 +14,70 @@
 
 int main (int argc, char **argv)
 {
+	char c, *syn = NULL;
+	bool quiet;
 	xmlNodePtr cur;
 	profile *prof;
-
+	
 	if (argc<2)
 	{
 		fprintf(stderr, "No book to parse.\n");
 		return 1;
 	}
-	
+
+	while ((c = getopt(argc, argv, "s:qVh")) != EOF)
+	{
+		switch (c)
+		{
+			case 's':
+				syn = (char *)malloc(strlen(optarg)+1);
+				strcpy(syn, optarg);
+				break;
+			case 'q':
+				quiet = true;
+				break;
+			case 'V':
+				printf("moongoo 0.0.1\nWritten by Boris Buegling\n");
+				return 0;
+			case 'h':
+				printf("moongoo [OPTIONS] BOOK\n");
+				printf("\t-s SYNTAX\tChoose syntax\n");
+				printf("\t-q\t\tNo output\n");
+				printf("\t-V\t\tVersion information\n");
+				printf("\t-h\t\tPrint this fluff\n");
+				return 0;
+		}
+	}
+
 	xmlSubstituteEntitiesDefault(1);
-	doc=xmlParseFile(argv[1]);
+	doc=xmlParseFile(argv[argc-1]);
 	if (!doc)
 		return 2;
 	xmlXIncludeProcessFlags(doc, XML_PARSE_NOENT);
 	cur=xmlDocGetRootElement(doc);
 	
-	//prof=bookasprofile(cur);
-	//prof=syn_profile(cur);
-	prof=nalfs_profile(cur);
-	//prof=ass_profile(cur);
+	if ((!syn)||(!strcmp(syn, "book")))
+		prof=bookasprofile(cur);
+	else
+	if (!strcmp(syn, "syn"))
+		prof=syn_profile(cur);
+	else
+	if (!strcmp(syn, "nalfs"))
+		prof=nalfs_profile(cur);
+	else
+	if (!strcmp(syn, "ass"))
+		prof=ass_profile(cur);
+	else
+	{
+		fprintf(stderr, "Syntax '%s' is not valid.\n", syn);
+		return 1;
+	}
 	
-	/*if (prof)
+	if ((prof)||(!quiet))
 	{
 		set_filter(default_filter);
 		print_profile(*prof);
-	}*/
+	}
 	
 	xmlFreeDoc(doc);
 	return 0;

Modified: dev/concept/moongoo/nalfs.c
===================================================================
--- dev/concept/moongoo/nalfs.c	2004-12-02 13:44:58 UTC (rev 1619)
+++ dev/concept/moongoo/nalfs.c	2004-12-02 20:43:57 UTC (rev 1620)
@@ -5,46 +5,51 @@
 #include <devel.h>
 
 profile *prof;
+char commando[512];
 
 void parse_unpack (xmlNodePtr node)
 {
-	/*printf("tar -C %s %s\n", find_value(node->children, "destination"),
-		find_value(node->children, "archive"));*/
-	// find_value(node->children, "digest");
+	node=node->children;
+	snprintf(commando, 512, "tar -C %s %s\n", find_value(node, 
+		"destination"), find_value(node, "archive"));
+	
+	// TODO: Handle <digest>
+	// find_value(node, "digest");
 }
 
 void parse_remove (xmlNodePtr node)
 {
-	//printf("rm -rf %s\n", xmlNodeGetContent(node));
+	snprintf(commando, 512, "rm -rf %s\n", xmlNodeGetContent(node));
 }
 
 void parse_make (xmlNodePtr node)
 {
-	/*node = node->children;
-	printf("%s make %s\n", find_value(node, "prefix"), 
-		find_values(node, "param"));*/
+	node=node->children;
+	snprintf(commando, 512, "%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"));*/
+	node = node->children;
+	snprintf(commando, 512, "%s ./configure %s\n", find_value(node, 
+		"prefix"), find_values(node, "param"));
 }
 
 void parse_copy (xmlNodePtr node)
 {
-	/*char *orig[4] = { "force", "archive", "recursive", NULL };
+	char *orig[4] = { "force", "archive", "recursive", NULL };
 	char *repl[4] = { "-f", "-a", "-r", NULL };
 	node = node->children;
-	printf("cp %s %s %s\n", find_values_repl(node, "option", orig, repl),
-			find_value(node, "source"), find_value(node, "destination"));*/
+	snprintf(commando, 512, "cp %s %s %s\n", find_values_repl(node, "option",
+		orig, repl), find_value(node, "source"), find_value(node, 
+		"destination"));
 }
 
 void __parse_env (xmlNodePtr node, void *data)
 {
-	/*printf("export %s=\"%s\"\n", xmlGetProp(node, "name"), 
-			xmlNodeGetContent(node));*/
+	snprintf(commando, 512, "export %s=\"%s\"\n", xmlGetProp(node, "name"), 
+			xmlNodeGetContent(node));
 }
 
 void parse_environment (xmlNodePtr node, void *data)
@@ -54,7 +59,7 @@
 
 void parse_base (xmlNodePtr node, void *data)
 {
-	//printf("cd %s\n", xmlNodeGetContent(node));
+	snprintf(commando, 512, "cd %s\n", xmlNodeGetContent(node));
 }
 
 void parse_stageinfo (xmlNodePtr node)
@@ -66,69 +71,98 @@
 
 void parse_textdump (xmlNodePtr node)
 {
-	/*printf("cat >%s << EOF\n%s\nEOF\n", find_value(node->children, "file"),
-		cut_trail(find_value(node->children, "content"), "="));*/
+	node=node->children;
+	snprintf(commando, 512, "cat >%s << EOF\n%s\nEOF\n", find_value(node,
+		"file"), cut_trail(find_value(node, "content"), "="));
 }
 
 void parse_execute (xmlNodePtr node)
 {
-	/*printf("%s %s\n", xmlGetProp(node, "command"), 
-		find_values(node->children, "param"));*/
+	snprintf(commando, 512, "%s %s\n", xmlGetProp(node, "command"), 
+		find_values(node->children, "param"));
 }
 
 void parse_mkdir (xmlNodePtr node)
 {
-	/*char *orig[2] = { "parents", NULL };
+	char *orig[2] = { "parents", NULL };
 	char *repl[2] = { "-p", NULL };
-	printf("mkdir %s %s\n", find_values_repl(node->children, "option", orig,
-		repl), find_value(node->children, "name"));*/
+	node=node->children;
+	snprintf(commando, 512, "mkdir %s %s\n", find_values_repl(node, "option",
+		orig, repl), find_value(node, "name"));
 }
 
 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"));*/
+	node = node->children;
+	snprintf(commando, 512, "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)
 {
-	/*char *orig[2] = { "recursive", NULL };
+	char *orig[2] = { "recursive", NULL };
 	char *repl[2] = { "-R", NULL };
-	printf("chmod %s %s %s\n", find_values_repl(node->children, "option",
-		orig, repl), xmlGetProp(node, "mode"), 
-		find_value(node->children, "name"));*/
+	snprintf(commando, 512, "chmod %s %s %s\n", find_values_repl(node->children,
+		"option", orig, repl), xmlGetProp(node, "mode"), 
+		find_value(node->children, "name"));
 }
 
 void parse_ownership (xmlNodePtr node)
 {
-	/*char *orig[2] = { "recursive", NULL };
+	char *orig[2] = { "recursive", NULL };
 	char *repl[2] = { "-R", NULL };
-	printf("chown %s %s:%s %s\n", find_values_repl(node->children, "option",
-		orig, repl), xmlGetProp(node, "user"), xmlGetProp(node, "group"),
-		find_value(node->children, "name"));*/
+	snprintf(commando, 512, "chown %s %s:%s %s\n", 
+		find_values_repl(node->children, "option", orig, repl), 
+		xmlGetProp(node, "user"), xmlGetProp(node, "group"),
+		find_value(node->children, "name"));
 }
 
 void parse_patch (xmlNodePtr node)
 {
-	//printf("patch %s\n", find_values(node->children, "param"));
+	snprintf(commando, 512, "patch %s\n", find_values(node->children, "param"));
 }
 
 void parse_move (xmlNodePtr node)
 {
-	/*printf("mv %s %s\n", find_value(node->children, "source"), 
-		find_value(node->children, "destination"));*/
+	snprintf(commando, 512, "mv %s %s\n", find_value(node->children, "source"), 
+		find_value(node->children, "destination"));
 }
 
 void parse_link (xmlNodePtr node)
 {
-	/*char *orig[2] = { "force", NULL };
+	char *orig[2] = { "force", NULL };
 	char *repl[2] = { "f", NULL };
-	printf("ln -s%s %s %s\n", find_values_repl(node->children, "option",
-		orig, repl), find_value(node->children, "target"),
-		find_value(node->children, "name"));*/
+	snprintf(commando, 512, "ln -s%s %s %s\n", find_values_repl(node->children,
+		"option", orig, repl), find_value(node->children, "target"),
+		find_value(node->children, "name"));
 }
 
+void process_cmd4 (char *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;
+
+	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"));
@@ -139,6 +173,10 @@
 		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"))
 				parse_unpack(node);
 			else
@@ -190,6 +228,37 @@
 			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;
+						fprintf(stderr, "%s\n", temp);
+						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);
+			
 		}
 		node=node->next;
 	}
@@ -204,11 +273,11 @@
 			(++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");
 	prof->ch[i].pkg[j].vers = xmlGetProp(node, "version");
 	prof->ch[i].pkg[j].build = NULL;
 	prof->ch[i].pkg[j].n = 0;
+	
 	foreach(node->children, "stage", (xml_handler_t)t_stage2, NULL);
 }
 




More information about the alfs-log mailing list