aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gladkov <gladkov.alexey@gmail.com>2020-04-13 13:41:01 +0200
committerAlexey Gladkov <gladkov.alexey@gmail.com>2020-04-13 18:22:23 +0200
commitfec381b031b8356ad632ea876f9863a3ae31336f (patch)
treedee0b9abf0f02041054e609dd737c47b4fdc242f
parent1a8da09ade6712be3699bdc4a5def7edfd61829e (diff)
downloadkbd-fec381b031b8356ad632ea876f9863a3ae31336f.tar.gz
Move font locations to kfont_context
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
-rw-r--r--src/clrunimap.c7
-rw-r--r--src/context.c71
-rw-r--r--src/context.h14
-rw-r--r--src/getunimap.c7
-rw-r--r--src/loadunimap.c21
-rw-r--r--src/mapscrn.c25
-rw-r--r--src/psfxtable.c7
-rw-r--r--src/readpsfheader.c7
-rw-r--r--src/setfont.c56
-rw-r--r--src/showconsolefont.c7
10 files changed, 116 insertions, 106 deletions
diff --git a/src/clrunimap.c b/src/clrunimap.c
index 2f4b1843..bf09ad53 100644
--- a/src/clrunimap.c
+++ b/src/clrunimap.c
@@ -28,11 +28,8 @@ int main(int argc, char *argv[])
if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
return loadunimap(&ctx, fd, NULL, NULL);
}
diff --git a/src/context.c b/src/context.c
index 357be080..808de5a5 100644
--- a/src/context.c
+++ b/src/context.c
@@ -1,7 +1,62 @@
#include <stdio.h>
#include <syslog.h>
+#include "libcommon.h"
#include "context.h"
+#include "paths.h"
+
+/* search for the map file in these directories (with trailing /) */
+static const char *const mapdirpath[] = {
+ "",
+ DATADIR "/" TRANSDIR "/",
+ NULL
+};
+
+static const char *const mapsuffixes[] = {
+ "",
+ ".trans",
+ "_to_uni.trans",
+ ".acm",
+ NULL
+};
+
+/* search for the font in these directories (with trailing /) */
+static const char *const fontdirpath[] = {
+ "",
+ DATADIR "/" FONTDIR "/",
+ NULL
+};
+static char const *const fontsuffixes[] = {
+ "",
+ ".psfu",
+ ".psf",
+ ".cp",
+ ".fnt",
+ NULL
+};
+
+static const char *const unidirpath[] = {
+ "",
+ DATADIR "/" UNIMAPDIR "/",
+ NULL
+};
+static const char *const unisuffixes[] = {
+ "",
+ ".uni",
+ ".sfm",
+ NULL
+};
+
+/* hide partial fonts a bit - loading a single one is a bad idea */
+const char *const partfontdirpath[] = {
+ "",
+ DATADIR "/" FONTDIR "/" PARTIALDIR "/",
+ NULL
+};
+char const *const partfontsuffixes[] = {
+ "",
+ NULL
+};
void
kfont_logger(struct kfont_context *ctx, int priority, const char *file,
@@ -45,3 +100,19 @@ kfont_log_stderr(struct kfont_context *ctx, int priority, const char *file,
fflush(stderr);
}
+
+void
+kfont_init(struct kfont_context *ctx)
+{
+ ctx->progname = get_progname();
+ ctx->verbose = 0;
+ ctx->log_fn = kfont_log_stderr;
+ ctx->mapdirpath = mapdirpath;
+ ctx->mapsuffixes = mapsuffixes;
+ ctx->fontdirpath = fontdirpath;
+ ctx->fontsuffixes = fontsuffixes;
+ ctx->partfontdirpath = partfontdirpath;
+ ctx->partfontsuffixes = partfontsuffixes;
+ ctx->unidirpath = unidirpath;
+ ctx->unisuffixes = unisuffixes;
+}
diff --git a/src/context.h b/src/context.h
index f1c02307..9347070b 100644
--- a/src/context.h
+++ b/src/context.h
@@ -8,6 +8,8 @@
struct kfont_context;
+void kfont_init(struct kfont_context *ctx);
+
typedef void (*kfont_logger_t)(struct kfont_context *, int, const char *, int,
const char *, const char *, va_list)
__attribute__((nonnull(1)))
@@ -17,6 +19,18 @@ struct kfont_context {
const char *progname;
int verbose;
kfont_logger_t log_fn;
+
+ const char *const *mapdirpath;
+ const char *const *mapsuffixes;
+
+ const char *const *fontdirpath;
+ const char *const *fontsuffixes;
+
+ const char *const *partfontdirpath;
+ const char *const *partfontsuffixes;
+
+ const char *const *unidirpath;
+ const char *const *unisuffixes;
};
void kfont_logger(struct kfont_context *ctx, int priority, const char *file,
diff --git a/src/getunimap.c b/src/getunimap.c
index 1eaeef94..2a72415a 100644
--- a/src/getunimap.c
+++ b/src/getunimap.c
@@ -69,11 +69,8 @@ int main(int argc, char **argv)
if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
if (getunimap(&ctx, fd, &ud))
return EXIT_FAILURE;
diff --git a/src/loadunimap.c b/src/loadunimap.c
index a95c3c6c..54ed43ec 100644
--- a/src/loadunimap.c
+++ b/src/loadunimap.c
@@ -29,18 +29,6 @@
extern char *progname;
extern int force;
-static const char *const unidirpath[] = {
- "",
- DATADIR "/" UNIMAPDIR "/",
- NULL
-};
-static const char *const unisuffixes[] = {
- "",
- ".uni",
- ".sfm",
- NULL
-};
-
#ifdef MAIN
int force = 0;
@@ -85,11 +73,8 @@ int main(int argc, char *argv[])
if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
if (outfnam) {
if ((ret = saveunicodemap(&ctx, fd, outfnam)) < 0)
@@ -305,7 +290,7 @@ loadunicodemap(struct kfont_context *ctx, int fd, const char *tblname)
return -EX_OSERR;
}
- if (kbdfile_find(tblname, unidirpath, unisuffixes, fp)) {
+ if (kbdfile_find(tblname, ctx->unidirpath, ctx->unisuffixes, fp)) {
KFONT_ERR(ctx, "unable to find unimap: %s: %m", tblname);
ret = -EX_NOINPUT;
goto err;
diff --git a/src/mapscrn.c b/src/mapscrn.c
index 4beae5e5..5bedcd71 100644
--- a/src/mapscrn.c
+++ b/src/mapscrn.c
@@ -24,34 +24,17 @@
static int ctoi(const char *);
-/* search for the map file in these directories (with trailing /) */
-static const char *const mapdirpath[] = {
- "",
- DATADIR "/" TRANSDIR "/",
- NULL
-};
-static const char *const mapsuffixes[] = {
- "",
- ".trans",
- "_to_uni.trans",
- ".acm",
- NULL
-};
-
#ifdef MAIN
int main(int argc, char *argv[])
{
int fd, ret;
-
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
set_progname(argv[0]);
setuplocale();
+ kfont_init(&ctx);
+
if (argc == 2 && !strcmp(argv[1], "-V"))
print_version_and_exit();
@@ -151,7 +134,7 @@ readnewmapfromfile(struct kfont_context *ctx, const char *mfil,
return -EX_OSERR;
}
- if (kbdfile_find(mfil, mapdirpath, mapsuffixes, fp)) {
+ if (kbdfile_find(mfil, ctx->mapdirpath, ctx->mapsuffixes, fp)) {
KFONT_ERR(ctx, _("Cannot open map file: %s"), mfil);
ret = -EX_DATAERR;
goto end;
diff --git a/src/psfxtable.c b/src/psfxtable.c
index b46241e1..1b48f0da 100644
--- a/src/psfxtable.c
+++ b/src/psfxtable.c
@@ -244,11 +244,8 @@ int main(int argc, char **argv)
fontbuf = NULL;
notable = 0;
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
if (!strcmp(get_progname(), "psfaddtable")) {
/* Do not send binary data to stdout without explicit "-" */
diff --git a/src/readpsfheader.c b/src/readpsfheader.c
index 858d5085..3e405890 100644
--- a/src/readpsfheader.c
+++ b/src/readpsfheader.c
@@ -33,11 +33,8 @@ int main(int argc, char **argv)
exit(1);
}
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
if (readpsffont(&ctx, f, &inbuf, &inbuflth, &fontbuf, &fontbuflth, &width, &fontlen, 0, &uclistheads) < 0) {
fprintf(stderr, "%s: Bad magic number\n", argv[0]);
diff --git a/src/setfont.c b/src/setfont.c
index 55c95468..9a2f7c47 100644
--- a/src/setfont.c
+++ b/src/setfont.c
@@ -48,41 +48,16 @@ static void disactivatemap(int fd);
int force = 0;
int double_size = 0;
-/* search for the font in these directories (with trailing /) */
-const char *const fontdirpath[] = {
- "",
- DATADIR "/" FONTDIR "/",
- NULL
-};
-char const *const fontsuffixes[] = {
- "",
- ".psfu",
- ".psf",
- ".cp",
- ".fnt",
- NULL
-};
-/* hide partial fonts a bit - loading a single one is a bad idea */
-const char *const partfontdirpath[] = {
- "",
- DATADIR "/" FONTDIR "/" PARTIALDIR "/",
- NULL
-};
-char const *const partfontsuffixes[] = {
- "",
- NULL
-};
-
static inline int
-findfont(const char *fnam, struct kbdfile *fp)
+findfont(struct kfont_context *ctx, const char *fnam, struct kbdfile *fp)
{
- return kbdfile_find(fnam, fontdirpath, fontsuffixes, fp);
+ return kbdfile_find(fnam, ctx->fontdirpath, ctx->fontsuffixes, fp);
}
static inline int
-findpartialfont(const char *fnam, struct kbdfile *fp)
+findpartialfont(struct kfont_context *ctx, const char *fnam, struct kbdfile *fp)
{
- return kbdfile_find(fnam, partfontdirpath, partfontsuffixes, fp);
+ return kbdfile_find(fnam, ctx->partfontdirpath, ctx->partfontsuffixes, fp);
}
static void __attribute__((noreturn))
@@ -131,11 +106,8 @@ int main(int argc, char *argv[])
set_progname(argv[0]);
setuplocale();
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
ifiles[0] = mfil = ufil = Ofil = ofil = omfil = oufil = NULL;
iunit = hwunit = 0;
@@ -526,7 +498,7 @@ loadnewfonts(struct kfont_context *ctx,
ifil = ifiles[i];
- if (findfont(ifil, fp) && findpartialfont(ifil, fp)) {
+ if (findfont(ctx, ifil, fp) && findpartialfont(ctx,ifil, fp)) {
KFONT_ERR(ctx, _("Cannot open font file %s"), ifil);
ret = -EX_NOINPUT;
goto end;
@@ -628,25 +600,25 @@ loadnewfont(struct kfont_context *ctx, int fd, const char *ifil,
if (iunit > 32)
iunit = 0;
if (iunit == 0) {
- if (findfont(ifil = "default", fp) &&
- findfont(ifil = "default8x16", fp) &&
- findfont(ifil = "default8x14", fp) &&
- findfont(ifil = "default8x8", fp)) {
+ if (findfont(ctx, ifil = "default", fp) &&
+ findfont(ctx, ifil = "default8x16", fp) &&
+ findfont(ctx, ifil = "default8x14", fp) &&
+ findfont(ctx, ifil = "default8x8", fp)) {
KFONT_ERR(ctx, _("Cannot find default font"));
ret = -EX_NOINPUT;
goto end;
}
} else {
sprintf(defname, "default8x%u", iunit);
- if (findfont(ifil = defname, fp) &&
- findfont(ifil = "default", fp)) {
+ if (findfont(ctx, ifil = defname, fp) &&
+ findfont(ctx, ifil = "default", fp)) {
KFONT_ERR(ctx, _("Cannot find %s font"), ifil);
ret = -EX_NOINPUT;
goto end;
}
}
} else {
- if (findfont(ifil, fp)) {
+ if (findfont(ctx, ifil, fp)) {
KFONT_ERR(ctx, _("Cannot open font file %s"), ifil);
ret = -EX_NOINPUT;
goto end;
diff --git a/src/showconsolefont.c b/src/showconsolefont.c
index a56fd18a..e2fa4758 100644
--- a/src/showconsolefont.c
+++ b/src/showconsolefont.c
@@ -128,11 +128,8 @@ int main(int argc, char **argv)
set_progname(argv[0]);
setuplocale();
- struct kfont_context ctx = {
- .progname = get_progname(),
- .verbose = 0,
- .log_fn = kfont_log_stderr,
- };
+ struct kfont_context ctx;
+ kfont_init(&ctx);
if (argc == 2 &&
(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))