r1654 - in dev/concept/moongoo: . libalfs output syntax test

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Tue Dec 14 13:16:43 PST 2004


Author: neocool
Date: 2004-12-14 14:16:42 -0700 (Tue, 14 Dec 2004)
New Revision: 1654

Added:
   dev/concept/moongoo/output/
   dev/concept/moongoo/output/Makefile
   dev/concept/moongoo/output/ass_out.c
   dev/concept/moongoo/test/tst_libtar.c
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/inc.mak
   dev/concept/moongoo/libalfs/gen.c
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/moongoo.h
   dev/concept/moongoo/plugin.c
   dev/concept/moongoo/plugin.h
   dev/concept/moongoo/syntax/ass.c
   dev/concept/moongoo/syntax/blfs.c
   dev/concept/moongoo/syntax/book.c
   dev/concept/moongoo/syntax/diyl.c
   dev/concept/moongoo/syntax/nalfs.c
   dev/concept/moongoo/syntax/sample.c
   dev/concept/moongoo/syntax/syn.c
   dev/concept/moongoo/test/
   dev/concept/moongoo/test/Makefile
Log:
Update.


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/Makefile	2004-12-14 21:16:42 UTC (rev 1654)
@@ -4,8 +4,8 @@
 OBJS=build.o moongoo.o plugin.o url.o
 
 ifeq ($(OPTS),)
-OPTS=-q #-s ass
-OPTS+=~/projects/alfs/book/index.xml
+OPTS=-o help
+#OPTS+=~/projects/alfs/book/index.xml
 #OPTS+=~/projects/alfs/lfs-profile/LFS.xml
 #OPTS+=~/projects/alfs/ass/index.xml
 #OPTS+=~/projects/hive/unstable/profile.xml
@@ -15,7 +15,7 @@
 #OPTS+=~/projects/alfs/refbuild/xml/x86-reference-build.xml
 endif
 
-SUBDIRS=libalfs syntax test
+SUBDIRS=libalfs syntax test output
 
 .PHONY: all
 

Modified: dev/concept/moongoo/inc.mak
===================================================================
--- dev/concept/moongoo/inc.mak	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/inc.mak	2004-12-14 21:16:42 UTC (rev 1654)
@@ -2,8 +2,8 @@
 CFLAGS+=-std=c99 -D_BSD_SOURCE -D_GNU_SOURCE
 CFLAGS+=-Wall -Werror -g3
 
-CFLAGS+=`xml2-config --cflags` `curl-config --cflags`
-LDLIBS+=`xml2-config --libs` `curl-config --libs` -ldl -ltar -lcrypto
+CFLAGS+=`xml2-config --cflags` `curl-config --cflags` -fPIC
+LDLIBS+=`xml2-config --libs` `curl-config --libs` -ldl -ltar -lcrypto -lbz2
 
 .PHONY: clean todo all-subdirs clean-subdirs sloccount
 

Modified: dev/concept/moongoo/libalfs/gen.c
===================================================================
--- dev/concept/moongoo/libalfs/gen.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/libalfs/gen.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -1,21 +1,116 @@
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
+#include <bzlib.h>
 #include <libtar.h>
+#include <zlib.h>
 
-#include <gen.h>
+#include <libalfs.h>
 
 const char *compr[NUM_COMPR] = { ".bz2", ".gz" };
 const char *unpck[NUM_COMPR] = { "tar xfj ", "tar xfz " };
 
+/* This code is partially taken from libtar, (C) 1998-2003  Mark D.Roth */
+int bzopen_fe (char *pathname, int oflags, int mode);
+tartype_t bz2type = { (openfunc_t) bzopen_fe, (closefunc_t) BZ2_bzclose, 
+	(readfunc_t) BZ2_bzread, (writefunc_t) BZ2_bzwrite };
+int gzopen_fe (char *pathname, int oflags, int mode);
+tartype_t gztype = { (openfunc_t) gzopen_fe, (closefunc_t) gzclose,
+	(readfunc_t) gzread, (writefunc_t) gzwrite };
+
+int bzopen_fe (char *pathname, int oflags, int mode)
+{
+	char *bzflags;
+	BZFILE *bzf;
+	int fd;
+
+	switch (oflags & O_ACCMODE)
+	{
+		case O_WRONLY:
+			bzflags="wb";
+			break;
+		case O_RDONLY:
+			bzflags="rb";
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+
+	fd = open(pathname, oflags, mode);
+	if (fd==-1)
+		return -1;
+
+	if ((oflags & O_CREAT) && fchmod(fd, mode))
+		return -1;
+
+	bzf = BZ2_bzdopen(fd, bzflags);
+	if (!bzf)
+	{
+		errno = ENOMEM;
+		return -1;
+	}
+
+	return (int)bzf;
+}
+
+int gzopen_fe (char *pathname, int oflags, int mode)
+{
+	char *gzoflags;
+	gzFile gzf;
+	int fd;
+
+	switch (oflags & O_ACCMODE)
+	{
+		case O_WRONLY:
+			gzoflags = "wb";
+			break;
+		case O_RDONLY:
+			gzoflags = "rb";
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+
+	fd = open(pathname, oflags, mode);
+	if (fd == -1)
+		return -1;
+
+	if ((oflags & O_CREAT) && fchmod(fd, mode))
+		return -1;
+
+	gzf = gzdopen(fd, gzoflags);
+	if (!gzf)
+	{
+		errno = ENOMEM;
+		return -1;
+	}
+
+	return (int)gzf;
+}
+
 char *directory (char *tarball)
 {
-	char *ret;
+	char *ret, *ext;
 	TAR *t = NULL;
+	tartype_t *moo = NULL;
 
-	tar_open(&t, tarball, NULL, O_RDONLY, 0, 0);
+	ext = strrchr(extonly(tarball), '.');
+	if (ext)
+	{
+		ext++;
+		if (!strcmp(ext, "gz"))
+			moo = &gztype;
+		if (!strcmp(ext, "bz2"))
+			moo = &bz2type;
+	}
 	
+	tar_open(&t, tarball, moo, O_RDONLY, 0, 0);
+	
 	if (!t)
 		return NULL;
 	

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/moongoo.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -14,46 +14,41 @@
 {
 	char c, *syn = DEF_SYN, *moo_xml = MOO_XML, *plug_dir = PLUG_DIR, *f;
 	bool quiet = false, build = false;
-	int i = 0;
-	xmlDocPtr doc;
+	int i = 0, ret = 0;
+	xmlDocPtr doc = NULL;
 	xmlNodePtr cur;
-	plug_info *plugin;
+	plug_info *parsers, *writers;
 	profile *prof = NULL;
 	
 	if (argc<2)
 	{
 		fprintf(stderr, "No book to parse.\n");
-		return 1;
+		ret=1;
+		goto cleanup;
 	}
 
 	if (getenv("NALFS_PLUGIN_DIR"))
 		plug_dir = getenv("NALFS_PLUGIN_DIR");
-	plugin = plugscan(plug_dir);
+	parsers = plugscan(strdog(plug_dir, "syntax/"));
+	writers = plugscan(strdog(plug_dir, "output/"));
 
-	if (!plugin)
+	if (!parsers)
 	{
 		fprintf(stderr, "No syntax plugins found.\n");
-		return 2;
+		ret=2;
+		goto cleanup;
 	}
 
-	while ((c = getopt(argc, argv, "s:qVhc:bC")) != EOF)
+	while ((c = getopt(argc, argv, "s:qVhc:bCo:")) != EOF)
 	{
 		switch (c)
 		{
 			case 's':
 				if (!strcmp(optarg, "help"))
 				{
-					printf("Available syntaxes:\n");
-					while (plugin[i].path)
-					{
-						char *tmp = plugarg(plugin[i].path);
-						if (strcmp(tmp, "sample"))
-							printf("\t%s\t\t%s%s\n", tmp, 
-								plugin[i].info->name, ((!strcmp(tmp, DEF_SYN)) 
-								? " (default)" : ""));
-						i++;
-					}
-					return 0;
+					printf("Available input syntaxes:\n");
+					print_plugs(parsers, DEF_SYN);
+					goto cleanup;
 				}
 				syn = (char *)malloc(strlen(optarg)+1);
 				strcpy(syn, optarg);
@@ -63,7 +58,7 @@
 				break;
 			case 'V':
 				printf("moongoo %s\nWritten by Boris Buegling\n", VERSION);
-				return 0;
+				goto cleanup;
 			case 'h':
 				printf("moongoo [OPTIONS] BOOK\n");
 				printf("\t-b\t\tBuild\n");
@@ -72,8 +67,10 @@
 				printf("\t-h\t\tPrint this fluff\n");
 				printf("\t-q\t\tNo output\n");
 				printf("\t-s SYNTAX\tChoose syntax (help shows them)\n");
+				printf("\t-o SYNTAX\tOutput the input in another %s",
+						"syntax (help shows them)\n");
 				printf("\t-V\t\tVersion information\n");
-				return 0;
+				goto cleanup;
 			case 'c':
 				moo_xml = (char *)malloc(strlen(optarg)+1);
 				strcpy(moo_xml, optarg);
@@ -85,13 +82,26 @@
 			case 'C':
 				colors = false;
 				break;
+			case 'o':
+				if (!strcmp(optarg, "help"))
+				{
+					printf("Available output syntaxes:\n");
+					print_plugs(writers, NULL);
+					goto cleanup;
+				}
+				/*syn = (char *)malloc(strlen(optarg)+1);
+				strcpy(syn, optarg);*/
+				break;
 		}
 	}
 
 	xmlSubstituteEntitiesDefault(1);
 	doc = xmlParseFile(argv[argc-1]);
 	if (!doc)
-		return 2;
+	{
+		ret=2;
+		goto cleanup;
+	}
 	xmlXIncludeProcessFlags(doc, XML_PARSE_NOENT);
 	cur = xmlDocGetRootElement(doc);
 
@@ -109,19 +119,18 @@
 		r = init_repl(f);
 	free(f);
 
-	while (plugin[i].path)
+	while (parsers[i].path)
 	{
-		if (!strcmp(syn, plugarg(plugin[i].path)))
-			prof = plugin[i].info->parse(cur, r);
+		if (!strcmp(syn, plugarg(parsers[i].path)))
+			prof = parsers[i].info->parse(cur, r);
 		i++;
 	}
 	
 	if (!prof)
 	{
 		fprintf(stderr, "Document was not parsed correctly.\n");
-		plugunload(plugin);
-		xmlFreeDoc(doc);
-		return 1;
+		ret=1;
+		goto cleanup;
 	}
 
 	if (build)
@@ -155,7 +164,13 @@
 	// Package URLs
 	//find_urls(PKG_XML, prof);
 
-	plugunload(plugin);
-	xmlFreeDoc(doc);
-	return 0;
+
+cleanup:
+	if (parsers)
+		plugunload(parsers);
+	if (writers)
+		plugunload(writers);
+	if (doc)
+		xmlFreeDoc(doc);
+	return ret;
 }

Modified: dev/concept/moongoo/moongoo.h
===================================================================
--- dev/concept/moongoo/moongoo.h	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/moongoo.h	2004-12-14 21:16:42 UTC (rev 1654)
@@ -3,7 +3,7 @@
 
 #define DEF_SYN		"book"
 #define MOO_XML		"/.nALFS/answers.xml"
-#define PLUG_DIR	"syntax"
+#define PLUG_DIR	"./"
 #define PKG_XML		"packages.xml"
 #define	VERSION		"0.0.3"
 


Property changes on: dev/concept/moongoo/output
___________________________________________________________________
Name: svn:ignore
   + ass_out.so


Added: dev/concept/moongoo/output/Makefile
===================================================================
--- dev/concept/moongoo/output/Makefile	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/output/Makefile	2004-12-14 21:16:42 UTC (rev 1654)
@@ -0,0 +1,9 @@
+CFLAGS=-I../libalfs -I..
+
+LIBS=ass_out.so
+
+all: $(LIBS)
+
+include ../inc.mak
+
+ass_out.so: ../libalfs/libalfs.a

Added: dev/concept/moongoo/output/ass_out.c
===================================================================
--- dev/concept/moongoo/output/ass_out.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/output/ass_out.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -0,0 +1,41 @@
+#include <plugin.h>
+
+void write_ass (profile *prof, char *fname);
+
+static t_plug ass_plugin =
+{
+	name:	"ALFS simple syntax writer",
+	vers:	PLUG_VER,
+	parse:	NULL,
+	write_prof: write_ass
+};
+
+t_plug *getplug ()
+{
+	return &ass_plugin;
+}
+
+void write_ass (profile *prof, char *fname)
+{
+	FILE *ass = stderr;
+	int i, j;
+	
+	fprintf(ass, "<?xml version=\"1.0\"?>\n\n<ass>\n");
+	fprintf(ass, "\t<title>%s</title>\n\t<version>%s</version>\n\n", 
+		prof->name, prof->vers);
+	for (i=0;i<prof->n;i++)
+	{
+		fprintf(ass, "\t<chapter name=\"%s\" ref=\"%s\">\n",
+			prof->ch[i].name, prof->ch[i].ref);
+		for (j=0;j<prof->ch[i].n;j++)
+		{
+			fprintf(ass, "\t\t<page>\n\t\t\t<title>%s</title>\n", 
+				prof->ch[i].pkg[j].name);
+			fprintf(ass, "\t\t\t<version>%s</version>\n", 
+				prof->ch[i].pkg[j].vers);
+			fprintf(ass, "\t\t</page>\n");
+		}
+		fprintf(ass, "\t</chapter>\n");
+	}
+	fprintf(ass, "</ass>\n");	
+}

Modified: dev/concept/moongoo/plugin.c
===================================================================
--- dev/concept/moongoo/plugin.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/plugin.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -47,6 +47,7 @@
 	}
 
 	ret = realloc(ret, (++num)*sizeof(plug_info));
+	ret[num-1].info = NULL;
 	ret[num-1].path = NULL;
 
 	closedir(d);
@@ -135,3 +136,17 @@
 		i++;
 	}
 }
+
+void print_plugs (plug_info *plugs, char *def)
+{
+	int i=0;
+	
+	while (plugs[i].info)
+	{
+		char *tmp = plugarg(plugs[i].path);
+		if (strcmp(tmp, "sample"))
+			printf("\t%s\t\t%s%s\n", tmp, plugs[i].info->name, 
+				(((def) && !strcmp(tmp, def)) ? " (default)" : ""));
+		i++;
+	}
+}

Modified: dev/concept/moongoo/plugin.h
===================================================================
--- dev/concept/moongoo/plugin.h	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/plugin.h	2004-12-14 21:16:42 UTC (rev 1654)
@@ -11,6 +11,7 @@
 	char *name;
 	int vers;
 	profile *(* parse) (xmlNodePtr node, replaceable *r);
+	void (* write_prof) (profile *prof, char *fname);
 } t_plug;
 
 typedef struct
@@ -33,5 +34,6 @@
 void print_plug (plug_info plug);
 char *plugarg (char *path);
 void plugunload (plug_info *plug);
+void print_plugs (plug_info *plugs, char *def);
 
 #endif

Modified: dev/concept/moongoo/syntax/ass.c
===================================================================
--- dev/concept/moongoo/syntax/ass.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/ass.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -9,7 +9,8 @@
 {
 	name:	"ALFS simple syntax",
 	vers:	PLUG_VER,
-	parse:	ass_profile
+	parse:	ass_profile,
+	write_prof: NULL
 };
 
 t_plug *getplug ()
@@ -23,42 +24,16 @@
 	parse_cmdblock(prof, node);
 }
 
-static void t_item (xmlNodePtr node, void *data)
-{
-	download *moo = next_dl(prof);
-
-	if (xmlGetProp(node, "sha1"))
-	{
-		moo->algo = ALGO_SHA1;
-		moo->sum = xmlGetProp(node, "sha1");
-	}
-	else
-	if (xmlGetProp(node, "md5"))
-	{
-		moo->algo = ALGO_MD5;
-		moo->sum = xmlGetProp(node, "md5");
-	}
-	
-	moo->proto = parse_proto(node);
-	moo->url = xmlNodeGetContent(node);
-}
-
-static void t_down (xmlNodePtr node, void *data)
-{
-	foreach(node->children, "item", (xml_handler_t)t_item, NULL);
-}
-
 static void t_page (xmlNodePtr node, void *data)
 {
-	xmlNodePtr dir = find_node(node->children, "directory");
 	package *pkg = next_pkg(prof);
 
 	pkg->name = find_value(node, "title");
 	pkg->vers = find_value(node, "version");
 
-	foreach(node->children, "download", (xml_handler_t)t_down, NULL);
-	parse_unpck(prof, pkg->dl[0].url, node);
-	parse_cmd(prof, strdog("__cd ", xmlNodeGetContent(dir)), node);
+	//foreach(node->children, "download", (xml_handler_t)t_down, NULL);
+	/*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);
 }
 

Modified: dev/concept/moongoo/syntax/blfs.c
===================================================================
--- dev/concept/moongoo/syntax/blfs.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/blfs.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -11,7 +11,8 @@
 {
 	name:	"BLFS book as profile",
 	vers:	PLUG_VER,
-	parse:	parse_blfs
+	parse:	parse_blfs,
+	write_prof: NULL
 };
 
 t_plug *getplug ()

Modified: dev/concept/moongoo/syntax/book.c
===================================================================
--- dev/concept/moongoo/syntax/book.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/book.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -15,7 +15,8 @@
 {
 	name:	"LFS book as profile",
 	vers:	PLUG_VER,
-	parse:	bookasprofile
+	parse:	bookasprofile,
+	write_prof: NULL
 };
 
 t_plug *getplug ()

Modified: dev/concept/moongoo/syntax/diyl.c
===================================================================
--- dev/concept/moongoo/syntax/diyl.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/diyl.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -8,7 +8,8 @@
 {
 	name:	"DIY Linux",
 	vers:	PLUG_VER,
-	parse:	parse_diyl
+	parse:	parse_diyl,
+	write_prof: NULL
 };
 
 t_plug *getplug ()

Modified: dev/concept/moongoo/syntax/nalfs.c
===================================================================
--- dev/concept/moongoo/syntax/nalfs.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/nalfs.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -18,7 +18,8 @@
 {
 	name:	"nALFS legacy syntax",
 	vers:	PLUG_VER,
-	parse:	nalfs_profile
+	parse:	nalfs_profile,
+	write_prof: NULL
 };
 
 t_plug *getplug ()

Modified: dev/concept/moongoo/syntax/sample.c
===================================================================
--- dev/concept/moongoo/syntax/sample.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/sample.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -12,12 +12,14 @@
 #include <plugin.h>
 
 profile *parse_example (xmlNodePtr node, replaceable *r);
+void write_example (profile *prof, char *fname);
 
 static t_plug sample_plugin =
 {
 	name:	"Example plugin",
 	vers:	PLUG_VER,
-	parse:	parse_example
+	parse:	parse_example,
+	write_prof: write_example
 };
 
 t_plug *getplug ()
@@ -29,3 +31,8 @@
 {
 	return NULL;
 }
+
+void write_example (profile *prof, char *fname)
+{
+	printf("Moongoo!\n");
+}

Modified: dev/concept/moongoo/syntax/syn.c
===================================================================
--- dev/concept/moongoo/syntax/syn.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/syntax/syn.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -11,7 +11,8 @@
 {
 	name:	"Hive profile syntax",
 	vers:	PLUG_VER,
-	parse:	syn_profile
+	parse:	syn_profile,
+	write_prof: NULL
 };
 
 t_plug *getplug ()


Property changes on: dev/concept/moongoo/test
___________________________________________________________________
Name: svn:ignore
   - tst_squeeze
tst_sha1
tst_md5

   + tst_squeeze
tst_sha1
tst_md5
tst_libtar


Modified: dev/concept/moongoo/test/Makefile
===================================================================
--- dev/concept/moongoo/test/Makefile	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/test/Makefile	2004-12-14 21:16:42 UTC (rev 1654)
@@ -2,7 +2,7 @@
 
 CFLAGS=-I. -I../libalfs
 
-TESTS=tst_md5 tst_sha1 tst_squeeze
+TESTS=tst_libtar tst_md5 tst_sha1 tst_squeeze
 
 .PHONY: all
 
@@ -15,6 +15,7 @@
 
 include ../inc.mak
 
+tst_libtar: tst.o ../libalfs/libalfs.a
 tst_md5: tst.o ../libalfs/libalfs.a
 tst_sha1: tst.o ../libalfs/libalfs.a
 tst_squeeze: tst.o ../libalfs/libalfs.a

Added: dev/concept/moongoo/test/tst_libtar.c
===================================================================
--- dev/concept/moongoo/test/tst_libtar.c	2004-12-14 02:47:18 UTC (rev 1653)
+++ dev/concept/moongoo/test/tst_libtar.c	2004-12-14 21:16:42 UTC (rev 1654)
@@ -0,0 +1,20 @@
+#include <string.h>
+
+#include <libalfs.h>
+#include <tst.h>
+
+int main (int argc, char **argv)
+{
+	char *host = popen_read("hostname");
+	int ret;
+	
+	host = strcut(host, 0, strlen(host)-1);
+	if (strcmp(host, "Lenin"))
+		return 0;
+	
+	ret = tst_harness(directory("/usr/src/Packages/xvidcore-0.9.0.tar.bz2"), 
+		"xvidcore-0.9.0/");
+	ret += tst_harness(directory("/usr/src/Packages/zip23.tar.gz"),
+		"zip-2.3/");
+	return ret;
+}




More information about the alfs-log mailing list