pkgtools

morpheus pkg tools
git clone git://git.2f30.org/pkgtools
Log | Files | Refs | README | LICENSE

commit c4378623aaa08fb925173328365131f2a18875e0
parent 4a6fcbb334184a4ecd001c9c374391e9105bcdd5
Author: sin <sin@2f30.org>
Date:   Tue, 24 Jun 2014 15:51:58 +0100

Add common.c

Diffstat:
MMakefile | 1+
Acommon.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdb.c | 63---------------------------------------------------------------
Mpkg.h | 17+++++++++--------
4 files changed, 75 insertions(+), 71 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,6 +4,7 @@ include config.mk .SUFFIXES: .c .o LIB = \ + common.o \ db.o \ ealloc.o \ eprintf.o \ diff --git a/common.c b/common.c @@ -0,0 +1,65 @@ +/* See LICENSE file for copyright and license details. */ +#include "pkg.h" + +/* Extract the package name from a filename. e.g. /tmp/pkg#version.pkg.tgz */ +void +parse_name(const char *path, char **name) +{ + char tmp[PATH_MAX], filename[PATH_MAX], *p; + + estrlcpy(tmp, path, sizeof(tmp)); + estrlcpy(filename, basename(tmp), sizeof(filename)); + /* strip extension */ + p = strrchr(filename, '.'); + if (!p) + goto err; + *p = '\0'; + p = strrchr(filename, '.'); + if (!p) + goto err; + *p = '\0'; + /* extract name */ + p = strchr(filename, '#'); + if (p) + *p = '\0'; + if (filename[0] == '\0') + goto err; + *name = estrdup(filename); + return; +err: + eprintf("%s: invalid package filename\n", + path); +} + +/* Extract the package version from a filename. e.g. /tmp/pkg#version.pkg.tgz */ +void +parse_version(const char *path, char **version) +{ + char tmp[PATH_MAX], filename[PATH_MAX], *p; + + estrlcpy(tmp, path, sizeof(tmp)); + estrlcpy(filename, basename(tmp), sizeof(filename)); + /* strip extension */ + p = strrchr(filename, '.'); + if (!p) + goto err; + *p = '\0'; + p = strrchr(filename, '.'); + if (!p) + goto err; + *p = '\0'; + /* extract version */ + p = strchr(filename, '#'); + if (!p) { + *version = NULL; + return; + } + p++; + if (*p == '\0') + goto err; + *version = estrdup(p); + return ; +err: + eprintf("%s: invalid package filename\n", + path); +} diff --git a/db.c b/db.c @@ -510,66 +510,3 @@ pkg_free(struct pkg *pkg) free(pkg->version); free(pkg); } - -/* Extract the package name from a filename. e.g. /tmp/pkg#version.pkg.tgz */ -void -parse_name(const char *path, char **name) -{ - char tmp[PATH_MAX], filename[PATH_MAX], *p; - - estrlcpy(tmp, path, sizeof(tmp)); - estrlcpy(filename, basename(tmp), sizeof(filename)); - /* strip extension */ - p = strrchr(filename, '.'); - if (!p) - goto err; - *p = '\0'; - p = strrchr(filename, '.'); - if (!p) - goto err; - *p = '\0'; - /* extract name */ - p = strchr(filename, '#'); - if (p) - *p = '\0'; - if (filename[0] == '\0') - goto err; - *name = estrdup(filename); - return; -err: - eprintf("%s: invalid package filename\n", - path); -} - -/* Extract the package version from a filename. e.g. /tmp/pkg#version.pkg.tgz */ -void -parse_version(const char *path, char **version) -{ - char tmp[PATH_MAX], filename[PATH_MAX], *p; - - estrlcpy(tmp, path, sizeof(tmp)); - estrlcpy(filename, basename(tmp), sizeof(filename)); - /* strip extension */ - p = strrchr(filename, '.'); - if (!p) - goto err; - *p = '\0'; - p = strrchr(filename, '.'); - if (!p) - goto err; - *p = '\0'; - /* extract version */ - p = strchr(filename, '#'); - if (!p) { - *version = NULL; - return; - } - p++; - if (*p == '\0') - goto err; - *version = estrdup(p); - return ; -err: - eprintf("%s: invalid package filename\n", - path); -} diff --git a/pkg.h b/pkg.h @@ -57,6 +57,10 @@ extern int vflag; /* eprintf.c */ extern char *argv0; +/* common.c */ +void parse_version(const char *, char **); +void parse_name(const char *, char **); + /* db.c */ struct db *db_new(const char *); int db_free(struct db *); @@ -74,14 +78,6 @@ int pkg_collisions(struct pkg *); struct pkg *pkg_new(const char *, const char *, const char *); void pkg_free(struct pkg *); -void parse_version(const char *, char **); -void parse_name(const char *, char **); - -/* reject.c */ -void rej_free(struct db *); -int rej_load(struct db *); -int rej_match(struct db *, const char *); - /* ealloc.c */ void *ecalloc(size_t, size_t); void *emalloc(size_t size); @@ -93,6 +89,11 @@ void enprintf(int, const char *, ...); void eprintf(const char *, ...); void weprintf(const char *, ...); +/* reject.c */ +void rej_free(struct db *); +int rej_load(struct db *); +int rej_match(struct db *, const char *); + /* strlcat.c */ #undef strlcat size_t strlcat(char *, const char *, size_t);