BESM6: Got rid of ftw(); the font file should be provided as a build option.

This commit is contained in:
Leo Broukhis 2015-01-01 15:05:07 -08:00
parent a50bd68ce5
commit 76cdf0fd10
2 changed files with 14 additions and 38 deletions

View file

@ -32,7 +32,6 @@
#include "besm6_defs.h"
#include <stdlib.h>
#include <ftw.h>
/*
* Use a 640x480 window with 32 bit pixels.
@ -44,14 +43,12 @@
#define STEPX 14
#define STEPY 16
#define FONTNAME "LucidaSansRegular.ttf"
#define FONTPATH1 "/usr/share/fonts"
#define FONTPATH2 "/usr/lib/jvm"
#define FONTPATH3 "/System/Library/Frameworks/JavaVM.framework/Versions"
#include <SDL.h>
#include <SDL_ttf.h>
#define _QUOTE(x) #x
#define QUOTE(x) _QUOTE(x)
/* Data and functions that don't depend on SDL version */
static char *font_path;
static TTF_Font *font_big;
@ -337,22 +334,6 @@ static void draw_brz_static (int top)
}
}
/*
* Поиск файла шрифта по имени.
*/
static int probe_font (const char *path, const struct stat *st, int flag)
{
const char *p;
if (flag != FTW_F)
return 0;
p = path + strlen (path) - strlen (FONTNAME);
if (p < path || strcmp (p, FONTNAME) != 0)
return 0;
font_path = strdup (path);
return 1;
}
/*
* Закрываем графическое окно.
*/
@ -409,22 +390,12 @@ static void init_panel ()
exit (1);
}
/* Find font file */
if (ftw (FONTPATH1, probe_font, 255) <= 0 &&
ftw (FONTPATH2, probe_font, 255) <= 0 &&
ftw (FONTPATH3, probe_font, 255) <= 0) {
fprintf(stderr, "SDL: couldn't find font %s in directory %s\n",
FONTNAME, FONTPATH1);
besm6_close_panel();
exit (1);
}
/* Open the font file with the requested point size */
font_big = TTF_OpenFont (font_path, 16);
font_small = TTF_OpenFont (font_path, 9);
font_big = TTF_OpenFont (QUOTE(FONTFILE), 16);
font_small = TTF_OpenFont (QUOTE(FONTFILE), 9);
if (! font_big || ! font_small) {
fprintf(stderr, "SDL: couldn't load font %s: %s\n",
font_path, SDL_GetError());
QUOTE(FONTFILE), SDL_GetError());
besm6_close_panel();
exit (1);
}

View file

@ -1171,14 +1171,19 @@ BESM6 = ${BESM6D}/besm6_cpu.c ${BESM6D}/besm6_sys.c ${BESM6D}/besm6_mmu.c \
${BESM6D}/besm6_tty.c ${BESM6D}/besm6_panel.c ${BESM6D}/besm6_printer.c \
${BESM6D}/besm6_punch.c
ifeq (,${VIDEO_LDFLAGS})
ifeq (,$(and ${VIDEO_LDFLAGS}, ${FONTFILE}))
ifneq (,$(and ${VIDEO_LDFLAGS}, $(findstring besm6,$(MAKECMDGOALS))))
$(info ***)
$(info *** BESM-6 video not used: please specify a font file with FONTFILE=pathname to enable the panel display)
$(info ***)
endif
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
else ifneq (,$(and $(findstring SDL2,${VIDEO_LDFLAGS}),$(call find_include,SDL2/SDL_ttf),$(call find_lib,SDL2_ttf)))
$(info using libSDL2_ttf: $(call find_lib,SDL2_ttf) $(call find_include,SDL2/SDL_ttf))
BESM6_OPT = -I ${BESM6D} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL2_ttf
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL2_ttf
else ifneq (,$(and $(call find_include,SDL/SDL_ttf),$(call find_lib,SDL_ttf)))
$(info using libSDL_ttf: $(call find_lib,SDL_ttf) $(call find_include,SDL/SDL_ttf))
BESM6_OPT = -I ${BESM6D} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL_ttf
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL_ttf
else
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
endif