aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gladkov <gladkov.alexey@gmail.com>2020-04-14 11:28:06 +0200
committerAlexey Gladkov <gladkov.alexey@gmail.com>2020-04-14 11:28:06 +0200
commit7e2fb5fa37906ac20fd1071cbd4af0737cf679c0 (patch)
tree7d104285135ccf2e18efaa611ca362dabf3607d8
parent6ffc91cdd9398ac7078accc56aeef89effdc979e (diff)
downloadkbd-7e2fb5fa37906ac20fd1071cbd4af0737cf679c0.tar.gz
Add options for kfont
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
-rw-r--r--src/context.c12
-rw-r--r--src/context.h16
-rw-r--r--src/loadunimap.c5
-rw-r--r--src/setfont.c14
4 files changed, 34 insertions, 13 deletions
diff --git a/src/context.c b/src/context.c
index 808de5a5..af07825f 100644
--- a/src/context.c
+++ b/src/context.c
@@ -59,6 +59,18 @@ char const *const partfontsuffixes[] = {
};
void
+kfont_set_option(struct kfont_context *ctx, enum kfont_option opt)
+{
+ ctx->options |= 1U << opt;
+}
+
+void
+kfont_unset_option(struct kfont_context *ctx, enum kfont_option opt)
+{
+ ctx->options &= ~(1U << opt);
+}
+
+void
kfont_logger(struct kfont_context *ctx, int priority, const char *file,
int line, const char *fn,
const char *fmt, ...)
diff --git a/src/context.h b/src/context.h
index 9347070b..448777e4 100644
--- a/src/context.h
+++ b/src/context.h
@@ -15,11 +15,18 @@ typedef void (*kfont_logger_t)(struct kfont_context *, int, const char *, int,
__attribute__((nonnull(1)))
__attribute__((format(printf, 6, 0)));
+enum kfont_option {
+ kfont_force,
+ kfont_double_size,
+};
+
struct kfont_context {
const char *progname;
int verbose;
kfont_logger_t log_fn;
+ unsigned int options;
+
const char *const *mapdirpath;
const char *const *mapsuffixes;
@@ -33,6 +40,12 @@ struct kfont_context {
const char *const *unisuffixes;
};
+void kfont_set_option(struct kfont_context *ctx, enum kfont_option opt)
+ __attribute__((nonnull(1)));
+
+void kfont_unset_option(struct kfont_context *ctx, enum kfont_option opt)
+ __attribute__((nonnull(1)));
+
void kfont_logger(struct kfont_context *ctx, int priority, const char *file,
int line, const char *fn, const char *fmt, ...)
__attribute__((format(printf, 6, 7)))
@@ -49,6 +62,7 @@ void kfont_logger(struct kfont_context *ctx, int priority, const char *file,
void kfont_log_stderr(struct kfont_context *ctx, int priority, const char *file,
const int line, const char *fn, const char *format, va_list args)
- __attribute__((format(printf, 6, 0)));
+ __attribute__((format(printf, 6, 0)))
+ __attribute__((nonnull(1)));
#endif /* _KFONT_CONTEXT_H_ */
diff --git a/src/loadunimap.c b/src/loadunimap.c
index 8fe76ec7..6e023bb3 100644
--- a/src/loadunimap.c
+++ b/src/loadunimap.c
@@ -27,11 +27,8 @@
#include "kfont.h"
extern char *progname;
-extern int force;
#ifdef MAIN
-int force = 0;
-
static void __attribute__((noreturn))
usage(void)
{
@@ -342,7 +339,7 @@ loadunicodemap(struct kfont_context *ctx, int fd, const char *tblname)
goto err;
}
- if (listct == 0 && !force) {
+ if (listct == 0 && !(ctx->options & (1 << kfont_force))) {
KFONT_ERR(ctx,
_("not loading empty unimap\n"
"(if you insist: use option -f to override)"));
diff --git a/src/setfont.c b/src/setfont.c
index 9a2f7c47..db74cccf 100644
--- a/src/setfont.c
+++ b/src/setfont.c
@@ -45,9 +45,6 @@ static int loadnewfonts(struct kfont_context *ctx,
static void activatemap(int fd);
static void disactivatemap(int fd);
-int force = 0;
-int double_size = 0;
-
static inline int
findfont(struct kfont_context *ctx, const char *fnam, struct kbdfile *fp)
{
@@ -159,14 +156,14 @@ int main(int argc, char *argv[])
else
ufil = argv[i];
} else if (!strcmp(argv[i], "-f")) {
- force = 1;
+ kfont_set_option(&ctx, kfont_force);
} else if (!strncmp(argv[i], "-h", 2)) {
int tmp = atoi(argv[i] + 2);
if (tmp <= 0 || tmp > 32)
usage();
hwunit = (unsigned int)tmp;
} else if (!strcmp(argv[i], "-d")) {
- double_size = 1;
+ kfont_set_option(&ctx, kfont_double_size);
} else if (argv[i][0] == '-') {
int tmp = atoi(argv[i] + 1);
if (tmp <= 0 || tmp > 32)
@@ -269,12 +266,13 @@ do_loadfont(struct kfont_context *ctx, int fd, const unsigned char *inbuf,
if (!hwunit)
hwunit = height;
- if (double_size && (height > 16 || width > 16)) {
+ if ((ctx->options & (1 << kfont_double_size)) &&
+ (height > 16 || width > 16)) {
KFONT_ERR(ctx, _("Cannot double %dx%d font (limit is 16x16)"), width, height);
- double_size = 0;
+ kfont_unset_option(ctx, kfont_double_size);
}
- if (double_size) {
+ if (ctx->options & (1 << kfont_double_size)) {
unsigned int bytewidth = (width + 7) / 8;
unsigned int kbytewidth = (2 * width + 7) / 8;
unsigned int charsize = height * bytewidth;