From 0987522073c9026c4ca83b5b900975f110031d07 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Sun, 19 May 2013 11:45:55 -0300 Subject: [PATCH] Fix portability to Visual C++ Signed-off-by: Claudio Matsuoka --- Changelog | 6 ++ configure.ac | 6 +- src/Makefile.am | 2 +- src/common.h | 20 +++- src/getopt.c | 5 +- src/main.c | 2 + src/sound.h | 2 +- src/win32/unistd.h | 8 ++ src/win32/usleep.c | 48 +++++++++ vc/xmp.sln | 20 ++++ vc/xmp.vcproj | 245 +++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 353 insertions(+), 11 deletions(-) create mode 100644 src/win32/unistd.h create mode 100644 src/win32/usleep.c create mode 100644 vc/xmp.sln create mode 100644 vc/xmp.vcproj diff --git a/Changelog b/Changelog index 9fc88ef..af1ed01 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,12 @@ Stable versions --------------- +4.0.6 (20130519): + - Portability fixes to build with Visual C++ + + Changes by Jan Engelhardt: + - Do not error out when g++ is absent on non-BEOS + 4.0.5 (20130512): - Fix loop when skipping to first file and it's not playable diff --git a/configure.ac b/configure.ac index 5e845f3..d67d688 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([xmp], [4.0.5]) +AC_INIT([xmp], [4.0.6]) AC_CONFIG_AUX_DIR([build-aux]) 0>confdefs.h @@ -67,7 +67,7 @@ AC_DEFUN([AC_CHECK_DEFINED],[ AS_VAR_POPDEF([ac_var])dnl ]) -AC_CHECK_HEADERS([getopt.h signal.h termios.h]) +AC_CHECK_HEADERS([getopt.h signal.h termios.h sys/time.h sys/audioio.h]) case "$host_cpu" in powerpc64) @@ -76,8 +76,6 @@ powerpc64) ;; esac -AC_CHECK_HEADERS(sys/audioio.h) - AM_CONDITIONAL([SOUND_AHI], [false]) AM_CONDITIONAL([SOUND_AIX], [false]) AM_CONDITIONAL([SOUND_ALSA05], [false]) diff --git a/src/Makefile.am b/src/Makefile.am index 0bbe6fe..e7f4716 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -89,7 +89,7 @@ man_MANS = xmp.1 pkgsysconfdir = ${sysconfdir}/${PACKAGE_NAME} pkgsysconf_DATA = modules.conf xmp.conf -EXTRA_DIST = ${man_MANS} ${pkgsysconf_DATA} +EXTRA_DIST = ${man_MANS} ${pkgsysconf_DATA} win32/usleep.c win32/unistd.h # unused sources EXTRA_DIST += sound_dart.c diff --git a/src/common.h b/src/common.h index b3ad6ba..79c8632 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,19 @@ -#ifndef __COMMON_H -#define __COMMON_H +#ifndef XMP_COMMON_H +#define XMP_COMMON_H + +#ifdef _MSC_VER +#define PATH_MAX 1024 +#define inline __inline +#define open _open +#define close _close +#define write _write +#define lseek _lseek +#define strdup _strdup +#define strcasecmp _stricmp +#define snprintf _snprintf +#define kbhit _kbhit +#define getch _getch +#endif #define MAX_DRV_PARM 20 @@ -35,7 +49,7 @@ struct options { }; struct control { - long time; /* Replay time in ms */ + double time; /* Replay time in ms */ int skip; /* Skip to next module */ int loop; /* Module is looped */ int pause; /* Replay paused */ diff --git a/src/getopt.c b/src/getopt.c index d8e87a4..3d9bf35 100644 --- a/src/getopt.c +++ b/src/getopt.c @@ -218,7 +218,8 @@ static char *posixly_correct; /* Avoid depending on library functions or files whose names are inconsistent. */ -char *getenv (); +/* char *getenv (); */ +#include static char * my_index (str, chr) @@ -370,7 +371,7 @@ _getopt_initialize (argc, argv, optstring) nextchar = NULL; - posixly_correct = getenv ("POSIXLY_CORRECT"); + posixly_correct getenv ("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ diff --git a/src/main.c b/src/main.c index a75092b..fc6de99 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,9 @@ #ifdef HAVE_SIGNAL_H #include #endif +#ifdef HAVE_SYS_TIME_H #include +#endif #include #include #include diff --git a/src/sound.h b/src/sound.h index 8782c00..dc31b69 100644 --- a/src/sound.h +++ b/src/sound.h @@ -25,7 +25,7 @@ struct sound_driver { #define parm_end() } } #define parm_error() do { \ fprintf(stderr, "xmp: incorrect parameters in -D %s\n", s); \ - exit(-4); } while (0) + exit(4); } while (0) #define chkparm0(x,y) { \ if (!strcmp(s, x)) { \ if (token != NULL) parm_error(); else { y; } } } diff --git a/src/win32/unistd.h b/src/win32/unistd.h new file mode 100644 index 0000000..71942b6 --- /dev/null +++ b/src/win32/unistd.h @@ -0,0 +1,8 @@ +#ifndef _XMP_WIN32_UNISTD_H +#define _XMP_WIN32_UNISTD_H + +#include + +void usleep(long usec); + +#endif diff --git a/src/win32/usleep.c b/src/win32/usleep.c new file mode 100644 index 0000000..0f81774 --- /dev/null +++ b/src/win32/usleep.c @@ -0,0 +1,48 @@ +#ifndef HAVE_USLEEP + +#ifdef HAVE_SELECT + +#ifdef HAVE_SYS_SELECT_H +# include +#else +# include +# include +# include +#endif + +void usleep(long usec) +{ + struct timeval tv; + + tv.tv_sec = usec / 1000000; + tv.tv_usec = usec % 1000000; + select(0, NULL, NULL, NULL, &tv); +} + +#elif defined WIN32 + +/* usleep implementation from FreeSCI */ + +#include + +void usleep (long usec) +{ + LARGE_INTEGER lFrequency; + LARGE_INTEGER lEndTime; + LARGE_INTEGER lCurTime; + + QueryPerformanceFrequency (&lFrequency); + if (lFrequency.QuadPart) { + QueryPerformanceCounter (&lEndTime); + lEndTime.QuadPart += (LONGLONG) usec * + lFrequency.QuadPart / 1000000; + do { + QueryPerformanceCounter (&lCurTime); + Sleep(0); + } while (lCurTime.QuadPart < lEndTime.QuadPart); + } +} + +#endif + +#endif /* !HAVE_USLEEP */ diff --git a/vc/xmp.sln b/vc/xmp.sln new file mode 100644 index 0000000..9b3aade --- /dev/null +++ b/vc/xmp.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xmp", "xmp.vcproj", "{A25F83C3-6C57-4DD7-939E-3F4F44F22345}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A25F83C3-6C57-4DD7-939E-3F4F44F22345}.Debug|Win32.ActiveCfg = Debug|Win32 + {A25F83C3-6C57-4DD7-939E-3F4F44F22345}.Debug|Win32.Build.0 = Debug|Win32 + {A25F83C3-6C57-4DD7-939E-3F4F44F22345}.Release|Win32.ActiveCfg = Release|Win32 + {A25F83C3-6C57-4DD7-939E-3F4F44F22345}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/vc/xmp.vcproj b/vc/xmp.vcproj new file mode 100644 index 0000000..ef4a2b4 --- /dev/null +++ b/vc/xmp.vcproj @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +