r1632 - in dev/concept/moongoo: . libalfs syntax

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Sun Dec 5 17:17:52 PST 2004


Author: neocool
Date: 2004-12-05 18:17:51 -0700 (Sun, 05 Dec 2004)
New Revision: 1632

Added:
   dev/concept/moongoo/libalfs/gen.c
   dev/concept/moongoo/libalfs/gen.h
   dev/concept/moongoo/libalfs/net.c
   dev/concept/moongoo/libalfs/net.h
   dev/concept/moongoo/moongoo.h
   dev/concept/moongoo/packages.xml
   dev/concept/moongoo/url.c
   dev/concept/moongoo/url.h
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/inc.mak
   dev/concept/moongoo/libalfs/Makefile
   dev/concept/moongoo/libalfs/alfs.c
   dev/concept/moongoo/libalfs/alfs.h
   dev/concept/moongoo/libalfs/devel.c
   dev/concept/moongoo/libalfs/libalfs.h
   dev/concept/moongoo/libalfs/repl.c
   dev/concept/moongoo/libalfs/util.c
   dev/concept/moongoo/libalfs/util.h
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/syntax/book.c
Log:
* Bugfixes
* Added networking code to libalfs (using libcurl)
* Package URLs can now be automatically generated and checked from
	a packages.xml file w/ download directories


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/Makefile	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,10 +1,10 @@
 CFLAGS=-I. -Ilibalfs
 
 BIN=moongoo
-OBJS=moongoo.o build.o plugin.o
+OBJS=build.o moongoo.o plugin.o url.o
 
 ifeq ($(OPTS),)
-OPTS=
+OPTS=-q
 OPTS+=~/projects/alfs/book/index.xml
 #OPTS+=~/projects/alfs/lfs-profile/LFS.xml
 #OPTS+=~/projects/alfs/ass/index.xml
@@ -25,4 +25,6 @@
 	./$(BIN) $(OPTS)
 
 build.o: build.h
+moongoo.o: moongoo.h
 plugin.o: plugin.h
+url.o: url.h

Modified: dev/concept/moongoo/inc.mak
===================================================================
--- dev/concept/moongoo/inc.mak	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/inc.mak	2004-12-06 01:17:51 UTC (rev 1632)
@@ -2,10 +2,10 @@
 CFLAGS+=-std=c99 -D_BSD_SOURCE -D_GNU_SOURCE
 CFLAGS+=-Wall -Werror -g3
 
-CFLAGS+=`xml2-config --cflags`
-LDLIBS+=`xml2-config --libs` -ldl
+CFLAGS+=`xml2-config --cflags` `curl-config --cflags`
+LDLIBS+=`xml2-config --libs` `curl-config --libs` -ldl
 
-.PHONY: clean todo all-subdirs clean-subdirs
+.PHONY: clean todo all-subdirs clean-subdirs sloccount
 
 all-subdirs:
 	@for dir in $(SUBDIRS) ; do \
@@ -23,5 +23,8 @@
 todo:
 	@find -name '*.c'|xargs grep "TODO:"|cut -d" " -f3-|sort
 
+sloccount:
+	@find -name '*.c'|xargs wc -l|tail -n 1|awk '{print $$1}'
+
 %.so: %.o
 	$(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

Modified: dev/concept/moongoo/libalfs/Makefile
===================================================================
--- dev/concept/moongoo/libalfs/Makefile	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/Makefile	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,7 +1,7 @@
 CFLAGS=-I.
 
 LIB=libalfs.a
-OBJS=alfs.o devel.o repl.o util.o
+OBJS=alfs.o devel.o gen.o net.o repl.o util.o
 
 all: $(LIB)
 
@@ -13,5 +13,7 @@
 
 alfs.o: alfs.h
 devel.o: devel.h
+gen.o: gen.h
+net.o: net.h
 repl.o: repl.h
 util.o: util.h

Modified: dev/concept/moongoo/libalfs/alfs.c
===================================================================
--- dev/concept/moongoo/libalfs/alfs.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/alfs.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -333,11 +333,12 @@
 
 	for (i=0;i<prof->n;i++)
 	{
-		if (strcmp(ch, prof->ch[i].ref))
+		if ((ch) && (strcmp(lower_case(ch), lower_case(prof->ch[i].ref))))
 			continue;
 		
 		for (j=0;j<prof->ch[i].n;j++)
-			if (!strcmp(name, prof->ch[i].pkg[j].name))
+			if (!strcmp(lower_case(name), 
+				lower_case(prof->ch[i].pkg[j].name)))
 				return &prof->ch[i].pkg[j];
 	}
 
@@ -373,3 +374,23 @@
 			return "unknown";
 	}
 }
+
+xmlNodePtr find_node_match (xmlNodePtr node, xml_match_t func, void *data)
+{
+	if (!func)
+		return NULL;
+
+	while (node)
+	{
+		xmlNodePtr tmp = NULL;;
+		
+		if (func(node, data))
+			return node;
+		tmp=find_node_match(node->children, func, data);
+		if (tmp)
+			return tmp;
+		node=node->next;
+	}
+	
+	return NULL;
+}

Modified: dev/concept/moongoo/libalfs/alfs.h
===================================================================
--- dev/concept/moongoo/libalfs/alfs.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/alfs.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -4,9 +4,11 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
-#include <libxml/xinclude.h>
 #include <libxml/tree.h>
+#include <libxml/xinclude.h>
 
+#include <net.h>
+
 typedef enum
 {
 	ROLE_NONE = 1,
@@ -24,13 +26,6 @@
 	SHA1
 } hash_algo;
 
-typedef enum
-{
-	PROTO_NONE = 1,
-	HTTP,
-	FTP
-} protocol;
-
 typedef struct
 {
 	hash_algo algo;
@@ -74,6 +69,7 @@
 } replaceable;
 
 typedef void (*xml_handler_t) (xmlNodePtr node, void *data);
+typedef bool (*xml_match_t) (xmlNodePtr node, void *data);
 
 void print_subtree (xmlNodePtr node);
 void print_pkg (package pkg);
@@ -88,6 +84,7 @@
 
 void foreach (xmlNodePtr node, char *str, xml_handler_t func, void *data);
 xmlNodePtr find_node (xmlNodePtr root, char *str);
+xmlNodePtr find_node_match (xmlNodePtr node, xml_match_t func, void *data);
 char *find_value (xmlNodePtr node, char *str);
 char *find_values (xmlNodePtr node, char *str);
 char *find_values_repl (xmlNodePtr node, char *str, char **orig, char **repl);

Modified: dev/concept/moongoo/libalfs/devel.c
===================================================================
--- dev/concept/moongoo/libalfs/devel.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/devel.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,5 +1,5 @@
+#include <stdbool.h>
 #include <string.h>
-#include <stdbool.h>
 
 #include <devel.h>
 

Added: dev/concept/moongoo/libalfs/gen.c
===================================================================
--- dev/concept/moongoo/libalfs/gen.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/gen.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,3 @@
+#include <gen.h>
+
+const char *compr[NUM_COMPR] = { ".bz2", ".gz" };

Added: dev/concept/moongoo/libalfs/gen.h
===================================================================
--- dev/concept/moongoo/libalfs/gen.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/gen.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,8 @@
+#ifndef __GEN_H__
+#define __GEN_H__
+
+#define NUM_COMPR	2
+
+extern const char *compr[NUM_COMPR];
+
+#endif

Modified: dev/concept/moongoo/libalfs/libalfs.h
===================================================================
--- dev/concept/moongoo/libalfs/libalfs.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/libalfs.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -3,6 +3,8 @@
 
 #include <alfs.h>
 #include <devel.h>
+#include <gen.h>
+#include <net.h>
 #include <repl.h>
 #include <util.h>
 

Added: dev/concept/moongoo/libalfs/net.c
===================================================================
--- dev/concept/moongoo/libalfs/net.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/net.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,135 @@
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <net.h>
+#include <util.h>
+
+/* This code is based on the libcurl examples */
+
+size_t writemem_cb (void *ptr, size_t size, size_t nmemb, void *data)
+{
+	register int realsize = size * nmemb;
+	memchunk *mem = (memchunk *)data;
+
+	mem->mem = (char *)realloc(mem->mem, mem->size + realsize + 1);
+	if (mem->mem)
+	{
+		memcpy(&(mem->mem[mem->size]), ptr, realsize);
+		mem->size += realsize;
+		mem->mem[mem->size] = 0;
+	}
+
+	return realsize;
+}
+
+static memchunk *__url_get (char *url, bool header, protocol proto)
+{
+	CURL *handle;
+	memchunk *chunk = (memchunk *)malloc(sizeof(memchunk));
+
+	chunk->mem = NULL;
+	chunk->size = 0;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	handle = curl_easy_init();
+
+	if (header)
+	{
+		if (proto==HTTP)
+			curl_easy_setopt(handle, CURLOPT_HEADER, 1);
+		curl_easy_setopt(handle, CURLOPT_NOBODY, 1);
+	}
+	
+	curl_easy_setopt(handle, CURLOPT_URL, url);
+	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writemem_cb);
+	curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)chunk);
+	curl_easy_setopt(handle, CURLOPT_USERAGENT, "moongoo-agent/1.0");
+	//curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
+	
+	chunk->res = curl_easy_perform(handle);
+	curl_easy_cleanup(handle);
+
+	if ((header) && (proto==HTTP))
+	{
+		char *head = chrep(chunk->mem, '\n', '\0'), *tmp;
+		tmp = strstr(head, " ");
+		chunk->res = atoi(++tmp);
+		free(head);
+	}
+
+	return chunk;
+}
+
+memchunk *http_get (char *url)
+{
+	// TODO: Make HTTP get usable
+	return __url_get(url, false, HTTP);
+}
+
+memchunk *http_header (char *url)
+{
+	return __url_get(url, true, HTTP);
+}
+
+memchunk *ftp_get (char *url)
+{
+	// TODO: Implement FTP get
+	return NULL;
+}
+
+URL *parse_url (char *url)
+{
+	URL *ret = (URL *)malloc(sizeof(URL));
+	ret->proto = chrep(url, ':', '\0');
+	ret->host = chrep(strnstr(url, "/", 2), '/', '\0');
+	ret->fname = strnstr(url, "/", 3);
+	return ret;
+}
+
+static CURLcode __ftp_list (char *url, char *command)
+{
+	CURL *handle;
+	URL *moo = parse_url(url);
+	CURLcode res;
+	struct curl_slist *cmd = NULL;
+	
+	cmd = curl_slist_append(cmd, strdog(command, moo->fname));
+	
+	curl_global_init(CURL_GLOBAL_DEFAULT);
+	handle = curl_easy_init();
+
+	curl_easy_setopt(handle, CURLOPT_URL, url);
+	curl_easy_setopt(handle, CURLOPT_QUOTE, cmd);
+	curl_easy_setopt(handle, CURLOPT_NOBODY, 1);
+	//curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
+
+	res = curl_easy_perform(handle);
+	if (res!=CURLE_OK)
+		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &res);
+
+	curl_slist_free_all(cmd);
+	curl_easy_cleanup(handle);
+	curl_global_cleanup();
+	return res;
+}
+
+CURLcode ftp_list (char *url)
+{
+	CURLcode ret = __ftp_list(url, "SIZE ");
+	if ((ret>500) && (ret!=550))
+		ret = __ftp_list(url, "STAT ");
+	return ret;
+}
+
+protocol check_proto (char *url)
+{
+	if (!strncmp(url, "http", 4))
+		return HTTP;
+	else
+	if (!strncmp(url, "ftp", 3))
+		return FTP;
+	
+	return PROTO_NONE;
+}

Added: dev/concept/moongoo/libalfs/net.h
===================================================================
--- dev/concept/moongoo/libalfs/net.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/net.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,38 @@
+#ifndef __NET_H__
+#define __NET_H__
+
+#include <curl/curl.h>
+#include <curl/easy.h>
+#include <curl/types.h>
+
+#define HTTP_OK			200
+
+typedef enum
+{
+	PROTO_NONE = 1,
+	HTTP,
+	FTP
+} protocol;
+
+typedef struct
+{
+	char *mem;
+	size_t size;
+	CURLcode res;
+} memchunk;
+
+typedef struct
+{
+	char *proto;
+	char *host;
+	char *fname;
+} URL;
+
+memchunk *http_get (char *url);
+memchunk *http_header (char *url);
+memchunk *ftp_get (char *url);
+CURLcode ftp_list (char *url);
+protocol check_proto (char *url);
+URL *parse_url (char *url);
+
+#endif

Modified: dev/concept/moongoo/libalfs/repl.c
===================================================================
--- dev/concept/moongoo/libalfs/repl.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/repl.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,7 +1,7 @@
 #include <string.h>
 
+#include <alfs.h>
 #include <repl.h>
-#include <alfs.h>
 
 void t_repl (xmlNodePtr node, void *data)
 {

Modified: dev/concept/moongoo/libalfs/util.c
===================================================================
--- dev/concept/moongoo/libalfs/util.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/util.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,8 +1,9 @@
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 
+#include <gen.h>
 #include <util.h>
 
 char *lower_case (char *arg)
@@ -323,6 +324,25 @@
 	return ret;
 }	
 
+char *strnrchr (char *haystack, char needle, int n)
+{
+	int i;
+	char *moo = haystack;
+
+	if (!haystack)
+		return NULL;
+
+	for (i=0;i<n-1;i++)
+	{
+		char *tmp = strrchr(moo, needle);
+		if (!tmp)
+			return NULL;
+		moo = strcut(moo, 0, strlen(moo)-strlen(tmp));
+	}
+
+	return strrchr(moo, needle);
+}
+
 void term_set (int attr, int fg, int bg)
 {
 	char cmd[13];
@@ -375,9 +395,6 @@
 	
 char *extonly (char *url)
 {
-#define NUM_COMPR	2
-	
-	const char *compr[NUM_COMPR] = { ".bz2", ".gz" };
 	char *foo=strrchr(url, '.');
 	int i;
 

Modified: dev/concept/moongoo/libalfs/util.h
===================================================================
--- dev/concept/moongoo/libalfs/util.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/libalfs/util.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -40,6 +40,7 @@
 char *squeeze (char *str);
 char *strkill (char *str, char *tokill);
 char *strnstr (char *haystack, char *needle, int n);
+char *strnrchr (char *haystack, char needle, int n);
 char *cut_trail (char *str, char *delim);
 char *strdog_path (char *str1, char *str2);
 char *extonly (char *url);

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/moongoo.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -2,25 +2,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <build.h>
 #include <libalfs.h>
+#include <moongoo.h>
 #include <plugin.h>
+#include <url.h>
 
-#define DEF_SYN		"book"
-#define MOO_XML		"/.nALFS/answers.xml"
-#define PLUG_DIR	"syntax"
-#define	VERSION		"0.0.2"
-
-/* Some default settings, those should be configurable in the final tool */
-role default_filter[4] = { NOEXECUTE, INTERACTIVE, TESTSUITE, 0 };
-char *paralell_filter[4] = { "configure-host", "clean", "mrproper", NULL };
-char *popt_pkg[2] = { "Glibc-20041115", NULL };
-char *popt_cmd[2] = { "PARALLELMFLAGS=-j", NULL };
-
 int main (int argc, char **argv)
 {
-	char c, *syn = DEF_SYN, *moo_xml = MOO_XML, *plug_dir = PLUG_DIR;
+	char c, *syn = DEF_SYN, *moo_xml = MOO_XML, *plug_dir = PLUG_DIR, *f;
 	bool quiet = false, build = false;
 	int i = 0;
 	xmlDocPtr doc;
@@ -93,19 +85,23 @@
 	}
 
 	xmlSubstituteEntitiesDefault(1);
-	doc=xmlParseFile(argv[argc-1]);
+	doc = xmlParseFile(argv[argc-1]);
 	if (!doc)
 		return 2;
 	xmlXIncludeProcessFlags(doc, XML_PARSE_NOENT);
-	cur=xmlDocGetRootElement(doc);
+	cur = xmlDocGetRootElement(doc);
 
-	r = init_repl(strdog(getenv("HOME"), MOO_XML));
-	if (!r)
+	f = strdog(getenv("HOME"), MOO_XML);
+	if (access(f, R_OK))
 	{
-		r = init_repl("moo.xml");
-		if (!r)
+		if (access("moo.xml", R_OK))
 			fprintf(stderr, "Configuration file could not be opened.\n");
+		else
+			r = init_repl("moo.xml");
 	}
+	else
+		r = init_repl(strdog(getenv("HOME"), MOO_XML));
+	free(f);
 	
 	while (plugin[i].path)
 	{
@@ -123,14 +119,11 @@
 	}
 
 	if (build)
-	{
-		//print_profile(*prof);
 		build_pkg(prof->ch[0].pkg[0]);
-	}
 
 	if (!quiet)
 	{
-		package *glibc = search_pkg(prof, "Glibc-20041115", 
+		package *glibc = search_pkg(prof, "glibc", 
 			"chapter-building-system");
 		sed_paralell (prof, paralell_filter, popt_pkg, popt_cmd);
 		set_filter(default_filter);
@@ -140,7 +133,10 @@
 		//print_profile(*prof);
 		//print_links(*prof);
 	}
-	
+
+	// Package URLs
+	//find_urls(PKG_XML, prof);
+
 	plugunload(plugin);
 	xmlFreeDoc(doc);
 	return 0;

Added: dev/concept/moongoo/moongoo.h
===================================================================
--- dev/concept/moongoo/moongoo.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/moongoo.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,16 @@
+#ifndef __MOONGOO_H
+#define __MOONGOO_H
+
+#define DEF_SYN		"book"
+#define MOO_XML		"/.nALFS/answers.xml"
+#define PLUG_DIR	"syntax"
+#define PKG_XML		"packages.xml"
+#define	VERSION		"0.0.3"
+
+/* Some default settings, those should be configurable in the final tool */
+role default_filter[4] = { NOEXECUTE, INTERACTIVE, TESTSUITE, 0 };
+char *paralell_filter[4] = { "configure-host", "clean", "mrproper", NULL };
+char *popt_pkg[2] = { "Glibc", NULL };
+char *popt_cmd[2] = { "PARALLELMFLAGS=-j", NULL };
+
+#endif

Added: dev/concept/moongoo/packages.xml
===================================================================
--- dev/concept/moongoo/packages.xml	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/packages.xml	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,58 @@
+<packages>
+<!-- Stolen from Matt's site -->
+<url name="autoconf">http://ftp.gnu.org/gnu/autoconf/</url>
+<url name="automake">http://ftp.gnu.org/gnu/automake/</url>
+<url name="bash">http://ftp.gnu.org/gnu/bash/</url>
+<url name="binutils">http://www.kernel.org/pub/linux/devel/binutils/</url>
+<url name="bison">http://ftp.gnu.org/gnu/bison/</url>
+<url name="bzip2" vurl="nodots">ftp://sources.redhat.com/pub/bzip2/v</url>
+<url name="coreutils">http://ftp.gnu.org/gnu/coreutils/</url>
+<url name="dejagnu">http://ftp.gnu.org/gnu/dejagnu/</url>
+<url name="diffutils">http://ftp.gnu.org/gnu/diffutils/</url>
+<url name="e2fsprogs">http://prdownloads.sourceforge.net/e2fsprogs/</url>
+<url name="expect">http://expect.nist.gov/src/</url>
+<url name="file">ftp://ftp.gw.com/mirrors/pub/unix/file/</url>
+<url name="findutils">ftp://alpha.gnu.org/gnu/findutils/</url>
+<url name="flex">http://sourceforge.net/projects/lex/</url>
+<url name="gawk">http://ftp.gnu.org/gnu/gawk/</url>
+<url name="gcc" vurl="true">http://ftp.gnu.org/gnu/gcc/gcc-</url>
+<url name="gettext">http://ftp.gnu.org/gnu/gettext/</url>
+<url name="glibc">ftp://sources.redhat.com/pub/glibc/snapshots/</url>
+<url name="grep">http://ftp.gnu.org/gnu/grep/</url>
+<url name="groff">http://ftp.gnu.org/gnu/groff/</url>
+<url name="grub">ftp://alpha.gnu.org/gnu/grub/</url>
+<url name="gzip">ftp://alpha.gnu.org/gnu/gzip/</url>
+<url name="iana-etc">http://www.sethwklein.net/projects/iana-etc/downloads/</url>
+<url name="inetutils">http://ftp.gnu.org/gnu/inetutils/</url>
+<url name="iproute2">http://developer.osdl.org/dev/iproute2/download/</url>
+<url name="kbd">http://ftp.kernel.org/pub/linux/utils/kbd/</url>
+<url name="less">http://ftp.gnu.org/gnu/less/</url>
+<url name="lfs-bootscripts">http://downloads.linuxfromscratch.org/</url>
+<url name="libol" vurl="base">http://www.balabit.com/downloads/syslog-ng/libol/</url>
+<url name="libtool">http://ftp.gnu.org/gnu/libtool/</url>
+<url name="linux" vurl="base">http://www.kernel.org/pub/linux/kernel/v</url>
+<url name="linux-libc-headers">http://ep09.pld-linux.org/~mmazur/linux-libc-headers/</url>
+<url name="m4">http://ftp.gnu.org/gnu/m4/</url>
+<url name="make">http://ftp.gnu.org/gnu/make/</url>
+<url name="man">ftp://ftp.win.tue.nl/pub/linux-local/utils/man/</url>
+<url name="man-pages">http://ftp.kernel.org/pub/linux/docs/manpages/</url>
+<url name="mktemp">ftp://ftp.cs.colorado.edu:/pub/mktemp/</url>
+<url name="module-init-tools">http://www.kernel.org/pub/linux/kernel/people/rusty/modules/</url>
+<url name="ncurses">http://ftp.gnu.org/gnu/ncurses/</url>
+<url name="patch">http://ftp.gnu.org/gnu/patch/</url>
+<url name="perl">http://www.cpan.org/src/</url>
+<url name="procps">http://procps.sourceforge.net/</url>
+<url name="psmisc">http://prdownloads.sourceforge.net/psmisc/</url>
+<url name="readline">http://ftp.gnu.org/gnu/readline/</url>
+<url name="sed">http://ftp.gnu.org/gnu/sed/</url>
+<url name="shadow">ftp://ftp.pld.org.pl/software/shadow/</url>
+<url name="syslog-ng" vurl="base" append="src/">http://www.balabit.com/downloads/syslog-ng/</url>
+<url name="sysvinit">ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/</url>
+<url name="tar">http://ftp.gnu.org/gnu/tar/</url>
+<url name="tcl">http://prdownloads.sourceforge.net/tcl/</url>
+<url name="texinfo">http://ftp.gnu.org/gnu/texinfo/</url>
+<url name="udev">http://www.kernel.org/pub/linux/utils/kernel/hotplug/</url>
+<url name="util-linux">ftp://ftp.win.tue.nl/pub/linux-local/utils/util-linux/</url>
+<url name="vim">ftp://ftp.vim.org/pub/vim/unix/</url>
+<url name="zlib">http://www.zlib.net/</url>
+</packages>

Modified: dev/concept/moongoo/syntax/book.c
===================================================================
--- dev/concept/moongoo/syntax/book.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/syntax/book.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -100,14 +101,19 @@
 			(++prof->ch[i].n)*sizeof(package));
 	j = prof->ch[i].n-1;
 	
-	tmp = strdog(lower_case(title), "version");
-	// TODO: Name and version are not correctly separated
-	prof->ch[i].pkg[j].vers = NULL;
-	prof->ch[i].pkg[j].name = strcut(title, 0, strlen(title)-
-		((prof->ch[i].pkg[j].vers) ? 1 : 0));
+	tmp = strrchr(title, '-');
+	if (tmp)
+	{
+		char *t = strnrchr(title, '-', 2);
+		if ((t) && (isdigit(t[1])))
+			tmp = strdog(t, tmp); 
+	}
+	tmp = chrep(tmp, ' ', '\0');
+	prof->ch[i].pkg[j].vers = tmp ? strcut(tmp, 1, strlen(tmp)) : NULL;
+	prof->ch[i].pkg[j].name = tmp ? strcut(title, 0, 
+		strlen(title)-strlen(tmp)) : title;
 	prof->ch[i].pkg[j].build = t_userinput(node->children, 
 		&prof->ch[i].pkg[j].n);
-	free(tmp);
 
 	if (!prof->ch[i].pkg[j].n)
 		prof->ch[i].n--;

Added: dev/concept/moongoo/url.c
===================================================================
--- dev/concept/moongoo/url.c	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/url.c	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,111 @@
+#include <string.h>
+
+#include <url.h>
+
+// TODO: Bison 1.875a temporary not available
+// TODO: No splitout GCC tarballs
+// TODO: Tcl URL is not yet found (tcl8.4.7-src.tar.gz)
+// TODO: Vim-lang will not be downloaded atm.
+static void t_url (xmlNodePtr cur, void *data)
+{
+	profile *prof = (profile *)data;
+	protocol proto = check_proto(xmlNodeGetContent(cur));
+	
+	if (proto!=PROTO_NONE)
+	{
+		bool found = false;
+		int i;
+		char base[512], url[512], *vurl = "";
+		package *pkg = search_pkg(prof, xmlGetProp(cur, "name"), NULL);
+				
+		if (xmlGetProp(cur, "vurl"))
+		{
+			char *vers = pkg->vers;
+			
+			if (!strcmp(xmlGetProp(cur, "vurl"), "base"))
+				vers = strcut(vers, 0, strlen(vers)-strlen(strrchr(vers, '.')));
+			if (!strcmp(xmlGetProp(cur, "vurl"), "nodots"))
+				vers = strkill(vers, ".");
+			
+			vurl = strdog(vers, "/");
+		}
+
+		if (xmlGetProp(cur, "append"))
+			vurl = strdog(vurl, xmlGetProp(cur, "append"));
+				
+		snprintf(base, 512, "%s%s%s-%s.tar", xmlNodeGetContent(cur), vurl,
+			lower_case(pkg->name), pkg->vers);
+
+		// TODO: Remove this when the shadow-site is more responsive again
+		if (!strcmp(pkg->name, "Shadow"))
+			return;
+
+		for (i=0;i<NUM_COMPR;i++)
+		{
+			snprintf(url, 512, "%s%s", base, compr[i]);
+					
+			if (proto==HTTP)
+			{
+				memchunk *mem = http_header(url);
+				if (mem->res==HTTP_OK)
+				{
+					found = true;
+					break;
+				}
+			}
+			else
+			if (proto==FTP)
+			{
+				CURLcode res = ftp_list(url);
+				if (res==CURLE_OK)
+				{
+					found = true;
+					break;
+				}
+			}	
+			else
+			{
+				fprintf(stderr, "Unknown protocol in URL '%s'.", url);
+				break;
+			}
+		}
+
+		if (!found)
+			printf("%s\n", url);
+	}
+}
+
+void find_urls (char *fname, profile *prof)
+{
+	xmlDocPtr doc;
+	xmlNodePtr cur;
+	
+	doc = xmlParseFile(fname);
+	if (!doc)
+		return;
+	xmlXIncludeProcessFlags(doc, XML_PARSE_NOENT);
+	cur = xmlDocGetRootElement(doc);
+	foreach(cur->children, "url", (xml_handler_t)t_url, prof);
+}
+
+static bool match_pkg (xmlNodePtr node, void *data)
+{
+	char *name = (char *)node->name;
+	char *prop = xmlGetProp(node, "id");
+	if ((!strcmp(name, "sect1")) && (prop) && 
+		(!strcmp(prop, "materials-packages")))
+			return true;
+	return false;
+}
+
+static void t_ulink (xmlNodePtr node, void *data)
+{
+	printf("%s\n", xmlGetProp(node, "url"));
+}
+
+void book_urls (xmlNodePtr bnode)
+{
+	bnode = find_node_match(bnode->children, (xml_match_t)match_pkg, NULL);
+	if (bnode)
+		foreach(bnode->children, "ulink", (xml_handler_t)t_ulink, NULL);
+}

Added: dev/concept/moongoo/url.h
===================================================================
--- dev/concept/moongoo/url.h	2004-12-05 02:54:52 UTC (rev 1631)
+++ dev/concept/moongoo/url.h	2004-12-06 01:17:51 UTC (rev 1632)
@@ -0,0 +1,9 @@
+#ifndef	__URL_H__
+#define __URL_H__
+
+#include <libalfs.h>
+
+void find_urls (char *fname, profile *prof);
+void book_urls (xmlNodePtr bnode);
+
+#endif




More information about the alfs-log mailing list