Skip to content

Commit

Permalink
Ext. dependency iconv for meta-data with USE_ICONV.
Browse files Browse the repository at this point in the history
  • Loading branch information
gzaffin committed Oct 19, 2024
1 parent 42fbdd1 commit 7f506f2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 31 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ endif()
if(UNIX OR MINGW)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(ICONV REQUIRED iconv)
add_definitions("-D USE_ICONV")
endif()
if(APPLE)
find_package(PkgConfig REQUIRED)
Expand All @@ -41,9 +43,9 @@ if(MSVC)
endif()

if(UNIX OR MINGW OR APPLE)
target_link_libraries(mdxplay PRIVATE mdxmini m ${SDL2_LIBRARIES})
target_include_directories(mdxplay PUBLIC ${SDL2_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_options(mdxplay PUBLIC ${SDL2_FLAGS} ${SDL2_FLAGS_OTHERS})
target_link_options(mdxplay PUBLIC ${SDL2_LDFLAGS} ${SDL2_LDFLAGS_OTHERS})
target_link_libraries(mdxplay PRIVATE mdxmini m ${SDL2_LIBRARIES} ${ICONV_LIBRARIES})
target_include_directories(mdxplay PUBLIC ${SDL2_INCLUDE_DIRS} ${ICONV_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_options(mdxplay PUBLIC ${SDL2_FLAGS} ${SDL2_FLAGS_OTHER} ${ICONV_CFLAGS} ${ICONV_FLAGS_OTHER})
target_link_options(mdxplay PUBLIC ${SDL2_LDFLAGS} ${SDL2_LDFLAGS_OTHER} ${ICONV_LDFLAGS} ${ICONV_LDFLAGS_OTHER})
install(TARGETS mdxplay DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ TARGET = mdxplay$(MODE)$(EXE_SFX)

CFLAGS += -idiraftersrc

LIBS += $(SDL_LIBS)
SLIBS += $(SDL_SLIBS)
CFLAGS += $(SDL_CFLAGS)
LIBS += $(SDL_LIBS) $(ICONV_LIBS)
CFLAGS += $(SDL_CFLAGS) $(ICONV_CFLAGS)


#
Expand Down
15 changes: 12 additions & 3 deletions mak/general.mak
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ endif
# iconv
# Jj commented libiconv usage
#ifneq ($(OS),Windows_NT)
#CFLAGS += -DUSE_ICONV
CFLAGS += -D USE_ICONV
#LIBS += -liconv
#endif

#
# SDL stuff
# SDL2 stuff
#

SDL_CONFIG = sdl2-config

SDL_SLIBS := `$(SDL_CONFIG) --static-libs`
SDL_LIBS := `$(SDL_CONFIG) --libs`
SDL_CFLAGS := `$(SDL_CONFIG) --cflags`

#
# iconv stuff
#

PKG_CONFIG = pkg-config

ICONV_LIBS := `$(PKG_CONFIG) --libs iconv`
ICONV_CFLAGS := `$(PKG_CONFIG) --cflags iconv`

2 changes: 1 addition & 1 deletion nlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ NLGCTX *OpenNLG(const char *file)
return NULL;
}

fread(hdr, 0x60, 1, ctx->file);
(void)fread(hdr, 0x60, 1, ctx->file);

if (memcmp(hdr, "NLG1", 4) != 0)
{
Expand Down
75 changes: 55 additions & 20 deletions sdlplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

NLGCTX *nlgctx;

#define MDXMINI_VERSION "2022-01-30"
#define MDXMINI_VERSION __DATE__

int g_viewnote = 0;
int g_verbose = 0;
Expand Down Expand Up @@ -66,6 +66,10 @@ static void audio_free(void);
static void audio_sig_handle(int sig);
static void audio_info(t_mdxmini *data, int sec, int len);
static int audio_poll_event(void);
#ifdef USE_ICONV
static int conv_with_iconv(char *title_orig, char *title_locale, const char *tocode);

#endif
static void audio_disp_title(t_mdxmini *data);
//static int split_dir(const char *file , char *dir);
static void audio_loop(t_mdxmini *data, int freq, int len, int nloops);
Expand Down Expand Up @@ -210,25 +214,14 @@ static int audio_poll_event(void)
return resVal;
}

#ifdef USE_ICONV
/*
// audio_disp_title
// conv_with_iconv
*/

static void audio_disp_title(t_mdxmini *data)
static int conv_with_iconv(char *title_orig, char *title_locale, const char *tocode)
{
char *title;

char title_orig[1024] = { 0, };

title = title_orig;

mdx_get_title(data, title_orig);

#ifdef USE_ICONV

char title_locale[1024] = { 0, };

iconv_t icd = iconv_open("UTF-8", "SHIFT-JIS");
iconv_t icd = iconv_open("UTF-8", tocode);

if (icd != (iconv_t)(-1))
{
Expand All @@ -239,17 +232,57 @@ static void audio_disp_title(t_mdxmini *data)
size_t destlen = 1024;
size_t wrtBytes = 0;

iconv(icd, NULL, NULL, NULL, NULL); // reset conversion state
(void)iconv(icd, NULL, NULL, NULL, NULL); // reset conversion state

wrtBytes = iconv(icd, &srcstr, &srclen, &deststr, &destlen);
if (wrtBytes != (size_t)-1)
if (wrtBytes == (size_t)-1)
{
title = title_locale;
/*printf("error iconv\n");*/
return -1;
}

iconv_close(icd);
}
else
{
/*printf("error iconv_open\n");*/
return -1;
}

return 0;
}

#endif

/*
// audio_disp_title
*/

static void audio_disp_title(t_mdxmini *data)
{
char *title;

char title_orig[1024] = { 0, };

title = title_orig;

mdx_get_title(data, title_orig);

#ifdef USE_ICONV
char title_locale[1024] = { 0, };

if (0 == conv_with_iconv(title_orig, title_locale, "SHIFT-JIS"))
{
title = title_locale;
}
else if (0 == conv_with_iconv(title_orig, title_locale, "CP932"))
{
title = title_locale;
}
else
{
;
}
#endif

if (!g_viewnote)
Expand All @@ -265,11 +298,13 @@ static void audio_disp_title(t_mdxmini *data)
printf("\n");

SetConsoleOutputCP(oldCodePage);

#else // _MSC_VER
printf("Title:%s\n", title);

#endif // _MSC_VER
}

}
}

/*
Expand Down

0 comments on commit 7f506f2

Please sign in to comment.