summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 14:07:58 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 14:07:58 (EDT)
commit557ff9418ff811829c5f7f410c56cd552b605d10 (patch)
tree47cdcdde2cfdef00d9fdb7107685b32ce97352d0 /src
parentc5da456687d8b51d8d2360cabc1966387ebc72b9 (diff)
font_default(): New function
And make font_find() return NULL if a font can't be found.
Diffstat (limited to 'src')
-rw-r--r--src/font.c22
-rw-r--r--src/font.h3
2 files changed, 23 insertions, 2 deletions
diff --git a/src/font.c b/src/font.c
index fb54604..30d51c9 100644
--- a/src/font.c
+++ b/src/font.c
@@ -48,12 +48,30 @@ static const struct font_desc *fonts[] = {
};
struct font *
+font_default(void)
+{
+ struct font *font;
+ int pref;
+ size_t i;
+
+ font = NULL;
+ pref = -10000;
+ for (i = 0; i < *(&fonts + 1) - fonts; ++i) {
+ if (fonts[i]->pref > pref) {
+ font = (struct font *) fonts[i];
+ pref = fonts[i]->pref;
+ }
+ }
+ return font;
+}
+
+struct font *
font_find(const char *name)
{
size_t i;
if (!name) {
- return (struct font *) fonts[0];
+ return NULL;
}
for (i = 0; i < *(&fonts + 1) - fonts; ++i) {
@@ -61,7 +79,7 @@ font_find(const char *name)
return (struct font *) fonts[i];
}
}
- return (struct font *) fonts[0];
+ return NULL;
}
int
diff --git a/src/font.h b/src/font.h
index 27cc08e..c1abe26 100644
--- a/src/font.h
+++ b/src/font.h
@@ -27,6 +27,9 @@
#include <linux/font.h>
struct font *
+font_default(void) __attribute__((pure));
+
+struct font *
font_find(const char *name) __attribute__((pure));
int