apk_applet.h 1.46 KB
Newer Older
1 2 3
/* apk_applet.h - Alpine Package Keeper (APK)
 *
 * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
4
 * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
5 6
 * All rights reserved.
 *
7
 * SPDX-License-Identifier: GPL-2.0-only
8 9 10 11 12
 */

#ifndef APK_APPLET_H
#define APK_APPLET_H

13
#include <errno.h>
Timo Teräs's avatar
Timo Teräs committed
14
#include <getopt.h>
15
#include "apk_defines.h"
16
#include "apk_database.h"
17

18 19 20 21 22 23
#define APK_OPTAPPLET		"\x00"
#define APK_OPTGROUP(_name)	_name "\x00"
#define APK_OPT1n(_opt)		       "\xf0" _opt "\x00"
#define APK_OPT1R(_opt)		"\xaf" "\xf0" _opt "\x00"
#define APK_OPT2n(_opt, _short)	       _short _opt "\x00"
#define APK_OPT2R(_opt, _short)	"\xaf" _short _opt "\x00"
Timo Teräs's avatar
Timo Teräs committed
24

25
struct apk_option_group {
26
	const char *desc;
27
	int (*parse)(void *ctx, struct apk_db_options *dbopts,
28
		     int opt, const char *optarg);
29 30
};

31
struct apk_applet {
32 33
	struct list_head node;

34
	const char *name;
35
	const struct apk_option_group *optgroups[4];
Timo Teräs's avatar
Timo Teräs committed
36

37
	unsigned int open_flags, forced_flags, forced_force;
Timo Teräs's avatar
Timo Teräs committed
38 39
	int context_size;

40
	int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);
41 42
};

43 44
extern const struct apk_option_group optgroup_global, optgroup_commit;

45
void apk_help(struct apk_applet *applet);
46 47
void apk_applet_register(struct apk_applet *);
typedef void (*apk_init_func_t)(void);
48 49

#define APK_DEFINE_APPLET(x) \
50 51
static void __register_##x(void) { apk_applet_register(&x); } \
static apk_init_func_t __regfunc_##x __attribute__((__section__("initapplets"))) __attribute((used)) = __register_##x;
52 53

#endif