2011-07-25 02:03:17 +00:00
|
|
|
/*
|
|
|
|
* pkg.h
|
|
|
|
* Global include file for everything.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 William Pitcock <nenolod@dereferenced.org>.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PKG_H
|
|
|
|
#define __PKG_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
2012-04-30 03:58:50 +00:00
|
|
|
#include <ctype.h>
|
2011-07-25 02:03:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-07-25 06:48:40 +00:00
|
|
|
#include <stdbool.h>
|
2011-07-25 02:03:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifndef BUFSIZ
|
|
|
|
#define BUFSIZ 65535
|
|
|
|
#endif
|
|
|
|
|
2012-05-06 02:51:25 +00:00
|
|
|
/* we are compatible with 0.26 of pkg-config */
|
|
|
|
#define PKG_PKGCONFIG_VERSION_EQUIV "0.26"
|
|
|
|
|
2011-07-25 02:03:17 +00:00
|
|
|
typedef enum {
|
|
|
|
PKG_ANY = 0,
|
|
|
|
PKG_LESS_THAN,
|
|
|
|
PKG_GREATER_THAN,
|
|
|
|
PKG_LESS_THAN_EQUAL,
|
|
|
|
PKG_GREATER_THAN_EQUAL,
|
|
|
|
PKG_EQUAL,
|
|
|
|
PKG_NOT_EQUAL,
|
|
|
|
PKG_ALWAYS_MATCH
|
|
|
|
} pkg_comparator_t;
|
|
|
|
|
|
|
|
typedef struct pkg_ pkg_t;
|
|
|
|
typedef struct dependency_ pkg_dependency_t;
|
|
|
|
typedef struct tuple_ pkg_tuple_t;
|
2012-05-03 19:25:33 +00:00
|
|
|
typedef struct fragment_ pkg_fragment_t;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
|
|
|
#define foreach_list_entry(head, value) \
|
|
|
|
for ((value) = (head); (value) != NULL; (value) = (value)->next)
|
|
|
|
|
2012-05-07 01:15:45 +00:00
|
|
|
#define foreach_list_entry_safe(head, nextiter, value) \
|
2012-05-07 01:36:59 +00:00
|
|
|
for ((value) = (head), (nextiter) = (head) != NULL ? (head)->next : NULL; (value) != NULL; (value) = (nextiter), (nextiter) = (nextiter) != NULL ? (nextiter)->next : NULL)
|
2012-05-07 01:15:45 +00:00
|
|
|
|
2011-07-26 16:56:59 +00:00
|
|
|
#define LOCAL_COPY(a) \
|
|
|
|
strcpy(alloca(strlen(a) + 1), a)
|
|
|
|
|
2012-04-30 18:07:51 +00:00
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2012-05-03 19:25:33 +00:00
|
|
|
struct fragment_ {
|
|
|
|
struct fragment_ *prev, *next;
|
|
|
|
|
|
|
|
char type;
|
|
|
|
char *data;
|
|
|
|
};
|
|
|
|
|
2011-07-25 02:03:17 +00:00
|
|
|
struct dependency_ {
|
|
|
|
struct dependency_ *prev, *next;
|
|
|
|
|
2011-07-25 04:20:22 +00:00
|
|
|
char *package;
|
2011-07-25 02:03:17 +00:00
|
|
|
pkg_comparator_t compare;
|
|
|
|
char *version;
|
|
|
|
pkg_t *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tuple_ {
|
|
|
|
struct tuple_ *prev, *next;
|
|
|
|
|
|
|
|
char *key;
|
|
|
|
char *value;
|
|
|
|
};
|
|
|
|
|
2012-05-07 01:38:48 +00:00
|
|
|
#define PKG_PROPF_NONE 0x0
|
|
|
|
#define PKG_PROPF_VIRTUAL 0x1
|
|
|
|
|
2011-07-25 02:03:17 +00:00
|
|
|
struct pkg_ {
|
2011-07-27 01:37:01 +00:00
|
|
|
char *id;
|
2011-07-25 02:03:17 +00:00
|
|
|
char *filename;
|
|
|
|
char *realname;
|
|
|
|
char *version;
|
|
|
|
char *description;
|
|
|
|
char *url;
|
|
|
|
char *pc_filedir;
|
2012-05-03 19:25:59 +00:00
|
|
|
|
|
|
|
pkg_fragment_t *libs;
|
|
|
|
pkg_fragment_t *libs_private;
|
|
|
|
pkg_fragment_t *cflags;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
|
|
|
pkg_dependency_t *requires;
|
2012-05-02 21:37:32 +00:00
|
|
|
pkg_dependency_t *requires_private;
|
2011-07-25 02:03:17 +00:00
|
|
|
pkg_dependency_t *conflicts;
|
|
|
|
pkg_tuple_t *vars;
|
2012-05-06 04:00:20 +00:00
|
|
|
|
|
|
|
bool uninstalled;
|
2012-05-07 01:38:48 +00:00
|
|
|
|
|
|
|
unsigned int flags;
|
2011-07-25 02:03:17 +00:00
|
|
|
};
|
|
|
|
|
2012-05-06 02:26:15 +00:00
|
|
|
#define PKG_MODULE_SEPARATOR(c) ((c) == ',' || isspace ((c)))
|
|
|
|
#define PKG_OPERATOR_CHAR(c) ((c) == '<' || (c) == '>' || (c) == '!' || (c) == '=')
|
|
|
|
|
2012-05-02 21:44:58 +00:00
|
|
|
#define PKGF_NONE 0x0
|
|
|
|
#define PKGF_SEARCH_PRIVATE 0x1
|
2012-05-02 23:16:32 +00:00
|
|
|
#define PKGF_ENV_ONLY 0x2
|
2012-05-07 00:49:15 +00:00
|
|
|
#define PKGF_NO_UNINSTALLED 0x4
|
2012-05-02 21:44:58 +00:00
|
|
|
|
2012-05-03 17:42:04 +00:00
|
|
|
#define PKG_ERRF_OK 0x0
|
|
|
|
#define PKG_ERRF_PACKAGE_NOT_FOUND 0x1
|
|
|
|
#define PKG_ERRF_PACKAGE_VER_MISMATCH 0x2
|
|
|
|
|
2012-05-07 01:30:50 +00:00
|
|
|
/* pkg.c */
|
|
|
|
void pkg_free(pkg_t *pkg);
|
2012-05-02 23:14:53 +00:00
|
|
|
pkg_t *pkg_find(const char *name, unsigned int flags);
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags);
|
|
|
|
unsigned int pkg_verify_graph(pkg_t *root, int depth, unsigned int flags);
|
2011-07-26 16:56:59 +00:00
|
|
|
int pkg_compare_version(const char *a, const char *b);
|
2012-05-03 17:42:04 +00:00
|
|
|
pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags);
|
2011-07-27 00:59:46 +00:00
|
|
|
const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
|
2011-07-25 02:03:17 +00:00
|
|
|
|
|
|
|
/* parse.c */
|
2012-05-07 03:24:36 +00:00
|
|
|
pkg_t *pkg_new_from_file(const char *path, FILE *f);
|
2012-05-07 03:23:05 +00:00
|
|
|
pkg_dependency_t *pkg_dependency_parse(pkg_t *pkg, const char *depends);
|
2011-07-25 21:53:12 +00:00
|
|
|
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);
|
2012-05-07 01:26:24 +00:00
|
|
|
void pkg_dependency_free(pkg_dependency_t *head);
|
2011-07-25 02:03:17 +00:00
|
|
|
|
2012-05-03 18:59:14 +00:00
|
|
|
/* argvsplit.c */
|
2012-05-07 03:21:11 +00:00
|
|
|
int pkg_argv_split(const char *src, int *argc, char ***argv);
|
|
|
|
void pkg_argv_free(char **argv);
|
2012-05-03 18:59:14 +00:00
|
|
|
|
2012-05-03 20:22:19 +00:00
|
|
|
/* fragment.c */
|
2012-05-07 03:29:59 +00:00
|
|
|
pkg_fragment_t *pkg_fragment_parse(pkg_fragment_t *head, pkg_tuple_t *vars, const char *value);
|
2012-05-03 20:22:19 +00:00
|
|
|
pkg_fragment_t *pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail);
|
|
|
|
pkg_fragment_t *pkg_fragment_add(pkg_fragment_t *head, const char *string);
|
2012-05-03 20:31:33 +00:00
|
|
|
pkg_fragment_t *pkg_fragment_copy(pkg_fragment_t *head, pkg_fragment_t *base);
|
2012-05-03 20:27:19 +00:00
|
|
|
void pkg_fragment_delete(pkg_fragment_t *node);
|
2012-05-03 20:43:09 +00:00
|
|
|
bool pkg_fragment_exists(pkg_fragment_t *head, pkg_fragment_t *base);
|
2012-05-07 01:26:09 +00:00
|
|
|
void pkg_fragment_free(pkg_fragment_t *head);
|
2012-05-03 20:22:19 +00:00
|
|
|
|
2012-05-04 03:21:51 +00:00
|
|
|
/* fileio.c */
|
|
|
|
char *pkg_fgetline(char *line, size_t size, FILE *stream);
|
|
|
|
|
2012-05-07 01:06:48 +00:00
|
|
|
/* tuple.c */
|
|
|
|
pkg_tuple_t *pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *value);
|
|
|
|
char *pkg_tuple_find(pkg_tuple_t *head, const char *key);
|
2012-05-07 01:12:11 +00:00
|
|
|
char *pkg_tuple_parse(pkg_tuple_t *vars, const char *value);
|
2012-05-07 01:18:21 +00:00
|
|
|
void pkg_tuple_free(pkg_tuple_t *head);
|
2012-05-07 01:06:48 +00:00
|
|
|
|
2011-07-25 02:03:17 +00:00
|
|
|
#endif
|