[Frugalware-git] pacman-frontend: add initial pacman-frontend initialization

James Buren ryuo at frugalware.org
Mon Sep 26 19:20:36 CEST 2011


Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-frontend.git;a=commitdiff;h=b67217a4ba61942620f2c9c62244ac56ada7dd7c

commit b67217a4ba61942620f2c9c62244ac56ada7dd7c
Author: James Buren <ryuo at frugalware.org>
Date:   Mon Sep 26 07:21:09 2011 -0500

add initial pacman-frontend initialization

diff --git a/pacman-frontend.c b/pacman-frontend.c
index 0f75817..77682ae 100644
--- a/pacman-frontend.c
+++ b/pacman-frontend.c
@@ -1 +1,87 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
#include "pacman-frontend.h"
+
+static struct
+{
+	PM_DB **sync;
+	PM_DB *local;
+} G;
+
+static void *
+xmalloc(size_t n)
+{
+	void *p;
+
+	assert(n);
+
+	p = malloc(n);
+
+	if(!p)
+	{
+		perror("malloc");
+		abort();
+	}
+
+	return p;
+}
+
+static void *
+xrealloc(void *p,size_t n)
+{
+	assert(p && n);
+
+	p = realloc(p,n);
+
+	if(!p)
+	{
+		perror("realloc");
+		abort();
+	}
+
+	return p;
+}
+
+static void
+_cb_db_register(const char *section,PM_DB *db)
+{
+	static size_t len = 0, size = 32;
+
+	if(!section && !db)
+	{
+		G.sync = xrealloc(G.sync,sizeof(void *) * (len + 1));
+		G.sync[len] = 0;
+		return;
+	}
+
+	if(!G.sync)
+		G.sync = xmalloc(sizeof(void *) * size);
+
+	if(len == size)
+	{
+		size *= 2;
+		G.sync = xrealloc(G.sync,sizeof(void *) * size);
+	}
+
+	G.sync[len++] = db;
+}
+
+int
+pacman_frontend_initialize(const char *root,const char *config)
+{
+	if(pacman_initialize(root) == -1)
+		return -1;
+
+	if(pacman_parse_config(config ? config : "/etc/pacman-g2.conf",_cb_db_register,"") == -1)
+		return -1;
+
+	G.local = pacman_db_register("local");
+
+	if(!G.local)
+		return -1;
+
+	_cb_db_register(0,0);
+
+	return 0;
+}
diff --git a/pacman-frontend.h b/pacman-frontend.h
index d090fa6..e9aa521 100644
--- a/pacman-frontend.h
+++ b/pacman-frontend.h
@@ -1,4 +1,6 @@
#ifndef _pacman_frontend_header_
#define _pacman_frontend_header_
#include <pacman.h>
+
+int pacman_frontend_initialize(const char *root,const char *config);
#endif


More information about the Frugalware-git mailing list