#ifndef _OCP_CONFIG_H
#define _OCP_CONFIG_H 1

#define _GNU_SOURCE 1
#define _XOPEN_SOURCE_EXTENDED 1 // needed for ncurses wide
#define _FILE_OFFSET_BITS 64

#undef WORDS_BIGENDIAN

#if __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
#  define __func__ __FUNCTION__
# else
#  define __func__ "<unknown>"
# endif
#endif

#undef HAVE_CURSES
#undef HAVE_CURSES_ENHANCED
#undef HAVE_CURSES_COLOR
#undef HAVE_CURSES_OBSOLETE
#undef HAVE_NCURSESW
#undef HAVE_NCURSES
#undef HAVE_CURSES_H
#undef HAVE_NCURSESW_H
#undef HAVE_NCURSES_H
#undef HAVE_NCURSESW_CURSES_H
#undef HAVE_NCURSES_CURSES_H
#ifndef NO_CURSES /* some source files have symbols that crashes with ncurses macros etc. */
#  if defined HAVE_NCURSESW_CURSES_H
#    include <ncursesw/curses.h>
#  elif defined HAVE_NCURSESW_H
#    include <ncursesw.h>
#  elif defined HAVE_NCURSES_CURSES_H
#    include <ncurses/curses.h>
#  elif defined HAVE_NCURSES_H
#    include <ncurses.h>
#  elif defined HAVE_CURSES_H
#    include <curses.h>
#  else
#    include "no-curses.h"
#  endif
#endif

#define MAXDLLLIST 150

#define KEY_TAB 9
#define KEY_CTRL_P 0x10
#define KEY_SHIFT_TAB KEY_BTAB /*353*/ /* 0x0f00 curses.h gives us that SHIFT_TAB is BTAB*/

#define _KEY_ENTER 13    /* 13 linux console and curses defines a KEY_ENTER that is something else */
#define KEY_ESC 27
#define KEY_CTRL_D  4  /*      4 linux console */
#define KEY_CTRL_H  8  /*      8 linux console, maps to KEY_BACKSPACE */
#define KEY_CTRL_J 10  /*     10 linux console */
#define KEY_CTRL_K 11  /*     11 linux console */
#define KEY_CTRL_L 12  /*     12 linux console */
#define KEY_CTRL_Q  17 /*     17 linux console */
#define KEY_CTRL_S  19 /*     19 linux console */
#define KEY_CTRL_Z  26 /*     26 linux console */
#define KEY_CTRL_BS 31 /* 0x007f linux console */

#if 0
#define KEY_DOWN 258   /* 0x5000 curses.h */
#define KEY_UP 259     /* 0x4800 curses.h */
#define KEY_LEFT 260   /* 0x4b00 curses.h */
#define KEY_RIGHT 261  /* 0x4d00 curses.h */
#endif

#define KEY_ALT_A 0x1e00 /* 0x1e00 */
#define KEY_ALT_B 0x3000 /* 0x3000 */
#define KEY_ALT_C 0x2e00 /* 0x2e00 */
/*#define KEY_ALT_D 0*/ /* TODO */
#define KEY_ALT_E 0x1200 /* 0x1200 */
/*#define KEY_ALT_F 0*/ /* TODO */
#define KEY_ALT_G 0x2200 /* 0x2200 */
/*#define KEY_ALT_H 0*/ /* TODO */
#define KEY_ALT_I 0x1700 /* 0x1700 */
/*#define KEY_ALT_J 0*/ /* TODO */
#define KEY_ALT_K 0x2500 /* 0x2500 */
#define KEY_ALT_L 0x2600 /* 0x2600 */
#define KEY_ALT_M 0x3200 /* 0x3200 */
/*#define KEY_ALT_N 0*/ /* TODO */
#define KEY_ALT_O 0x1800 /* 0x1800 */
#define KEY_ALT_P 0x1900 /* 0x1900 */
/*#define KEY_ALT_Q 0*/ /* TODO */
#define KEY_ALT_R 0x1300
#define KEY_ALT_S 0x1f00 /* 0x1f00 */
/*#define KEY_ALT_T 0*/ /* TODO */
/*#define KEY_ALT_U 0*/ /* TODO */
/*#define KEY_ALT_V 0*/ /* TODO */
/*#define KEY_ALT_W 0*/ /* 0x1100 TODO */
#define KEY_ALT_X 0x2d00 /* 0x2d00 */
/*#define KEY_ALT_Y 0*/ /* TODO */
#define KEY_ALT_Z 0x2c00 /* 0x2c00 */


/*#define KEY_F(2) 266*/  /* 0x3c00 curses.h */
/*#define KEY_F(3) 267*/  /* 0x3d00 curses.h */
/*#define KEY_F(4) 268*/  /* 0x3e00 curses.h */
/*#define KEY_F(5) 269*/  /* 0x3f00 curses.h */
/*#define KEY_F(6) 270*/  /* 0x4000 curses.h */
/*#define KEY_F(7) 271*/  /* 0x4100 curses.h */
/*#define KEY_F(8) 272*/  /* 0x4200 curses.h */
/*#define KEY_F(9) 273*/  /* 0x4300 curses.h */
/*#define KEY_F(10) 274*/ /* 0x4400 curses.h */
/*#define KEY_F(11) 275*/ /* 0x8500 curses.h */
/*#define KEY_F(12) 276*/ /* 0x8600 curses.h */

#if 0
#define KEY_END   360  /* 0x4f00 curses.h */
#define KEY_HOME  262  /* 0x4700 curses.h */
#endif

#define KEY_CTRL_UP     0x0237 /* 0x8d00 */
#define KEY_CTRL_DOWN   0x020e /* 0x9100 */
#define KEY_CTRL_LEFT   0x0222 /* 0x7300 */
#define KEY_CTRL_RIGHT  0x0231 /* 0x7400 */
#define KEY_CTRL_PGUP   0x8400 /* 0x8400 x11 only */
#define KEY_CTRL_PGDN   0x7600 /* 0x7600 x11 only */
#define KEY_CTRL_HOME   0x0218 /* 0x7700 x11 only */
#define KEY_CTRL_END    0x0213 /* 0x7500 x11 only */
#define KEY_CTRL_DELETE 0x0208 /* 0x9300 x11 only */
#define KEY_CTRL_INSERT 0x9200 /* 0x9200 x11 only */


#define KEY_DELETE KEY_DC/*330*/ /* 0x5300 curses.h delete-key is mapped to delete-character */
#define KEY_INSERT KEY_IC/*331*/ /* 0x5200 curses.h insert-key is mapped to insert-character */

#if 0
#define KEY_NPAGE 338  /* 0x5100 curses.h */
#define KEY_PPAGE 339  /* 0x4900 curses.h */
#endif

#define KEY_CTRL_ENTER 0xff00 /* SDL/SDL2/X11 only */
#define KEY_ALT_ENTER  0xff01 /* used to be 10, collides with ctrl+j */
#define VIRT_KEY_RESIZE     0xff02 /* dummy key */

#define KEY_SHIFT_F(n)      KEY_F(n+12) /* ncurses-hack */
#define KEY_CTRL_F(n)       KEY_F(n+24) /* ncurses-hack */
#define KEY_CTRL_SHIFT_F(n) KEY_F(n+36) /* ncurses-hack */

/* keys we can't do
 KEY_CTRL_ENTER  10
 KEY_ALT_F1      0x6800
 KEY_ALT_F2      0x6900
 KEY_ALT_F3      0x6a00
 KEY_ALT_F4      0x6b00
 KEY_ALT_F8      0x6f00
 KEY_ALT_F9      0x7000

 KEY_ALT_TAB     0xa500   pfilesel.c cpitrack.c cpigraph.c

 keys we don't know
 0x2000  cdapplay.c
*/

#define CONSOLE_MIN_X 80
#define CONSOLE_MIN_Y 20
#define CONSOLE_MAX_X 1024

#undef HAVE_RESIZE_TERM

/* #define KICKSTART_DEBUG */
/* #define ADBMETA_DEBUG */
/* #define CDFS_DEBUG */
/* #define ZIP_DEBUG */
/* #define ZIP_VERBOSE */
/* #define DIRDB_DEBUG */
/* #define BZIP2_DEBUG */
/* #define BZIP2_VERBOSE */
/* #define GZIP_DEBUG */
/* #define GZIP_VERBOSE */
/* #define Z_DEBUG */
/* #define Z_VERBOSE */
/* #define TAR_DEBUG */
/* #define TAR_VERBOSE */
/* #define PAK_DEBUG */
/* #define PAK_VERBOSE */
/* #define RPG_DEBUG */
/* #define RPG_VERBOSE */
/* #define FILEHANDLE_CACHE_DEBUG */
/* #define FILEHANDLE_CACHE_DISABLE */
/* #define INITCLOSE_DEBUG 1*/
/* #define LD_DEBUG 1 */
/* #define OSS_DEBUG 1 */
/* #define ALSA_DEBUG 1 */
/* #define OSS_LOCK_DEBUG 1 */
/* #define STM_LOAD_DEBUG 1 */
/* #define S3M_LOAD_DEBUG 1 */
/* #define MIXER_DEBUG 1 */
/* #define KEYBOARD_DEBUG 1 */
/* #define KEYBOARDTEXT_DEBUG 1 */
/* #define VCSA_DEBUG 1*/
/* #define DEBUG_FRAMEBUFFER 1 */
/* #define MDB_DEBUG 1 */
/* #define PLAYAY_DEBUG 1 */
/* #define PLAYMP2_DEBUG 1 */
/* #define PLAYQOA_DEBUG 1 */
/* #define PLAYSID_DEBUG 1 */
/* #define PLAYSNDH_DEBUG 1 */
/* #define PLAYTIMIDITY_DEBUG */
/* #define PLAYWAVE_DEBUG 1 */
/* #define PLAYWAVPACK_DEBUG 1 */
/* #define PSETTING_DEBUG 1 */
/* #define XM_LOAD_DEBUG 1 */
/* #define IT_LOAD_DEBUG 1 */
/* #define OKT_LOAD_DEBUG 1 */
/* #define MCP_DEBUG 1 */
/* #define COREAUDIO_DEBUG 1 */
/* #define SDL_DEBUG 1 */
/* #define SDL2_DEBUG 1 */
/* #define SDL3_DEBUG 1 */
/* #define CPIFACE_DEBUG 1 */
/* #define PNG_DEBUG 1 */
/* #define JPEG_DEBUG 1 */
/* #define AMS_DEBUG 1 */
/* #define ANCIENT_DEBUG 1 */

#define VERBOSE_FRAMEBUFFER 1
#define VCSA_VERBOSE 1
/* #define CDROM_VERBOSE 1 */

#define FIX_BACKSPACE 1 /* lot of linux distroes has a broken backspace key in consoles. See stuff-vsca.c */

/* Multibyte support, don't think so.. VGA hardware is hardwired to one byte, so fuck the stupid new standards, since they SUCK */
#define VCSA_FONT "ISO-8859-1"
/*#define VCSA_FONT "LATIN1"*/
#define OCP_FONT "CP437"
#define VCSA_PATH "/dev/vcsa"


/* Stuff below here will be updated by ./configure */

#undef TIMIDITY_DEFAULT_PATH
#undef TIMIDITYPKGDATADIR

#undef HAVE_OV_PCM_SEEK_LAP

#undef HAVE_OV_PCM_SEEK

/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

#undef HAVE_GETOPT

#undef HAVE_GETPWUID

#undef HAVE_MEMMEM

#undef HAVE_MEMRCHR

#undef HAVE_QSORT

#undef HAVE_STRUPR

#undef HAVE_POPEN

#undef HAVE_STRDUP

#undef HAVE_GETCWD

#undef HAVE_STRSTR

#undef HAVE_STRERROR

#undef HAVE_SNPRINTF

#undef HAVE_VSNPRINTF

#undef HAVE_STRNCASECMP

#undef HAVE_SLEEP

#undef HAVE_USLEEP

#undef HAVE_MKSTEMP

#undef HAVE_STRLCPY

#undef HAVE_STRLCAT

#undef HAVE_STRVERSCMP
#ifndef HAVE_STRVERSCMP
int strverscmp(const char *s1, const char *s2);
#endif

#undef HAVE_GETTIMEOFDAY

#undef HAVE_EFENCE

#undef HAVE_DUMA

#undef HAVE_X11

#undef HAVE_X11_SHM

#undef HAVE_SDL

#undef HAVE_SDL2

#undef HAVE_SDL3

#undef HAVE_MAD

#undef HAVE_ERRNO_H

#undef HAVE_LIMITS_H

#undef HAVE_SYS_CDEFS_H

#undef HAVE_SYS_STAT_H

#undef HAVE_SYS_TIME_H

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME

#undef HAVE_SYS_PARAM_H

#undef HAVE_SYS_TYPES_H

#undef HAVE_DIRENT_H

#undef HAVE_FCNTL_H

#undef HAVE_GRP_H

#undef HAVE_NDIR_H

#undef HAVE_SYS_NDIR_H

#undef HAVE_SYS_DIR_H

#undef HAVE_STDDEF_H

#undef HAVE_STDINT_H

#undef HAVE_INTTYPES_H

#undef HAVE_BYTESWAP_H

#undef HAVE_GETOPT_H

#undef HAVE_UNISTD_H

#undef HAVE_MACHINE_ENDIAN_H

#undef HAVE_PWD_H

#undef HAVE_SYS_SOUNDCARD_H

#undef HAVE_STRING_H

#undef NO_STRING_H

#undef HAVE_AVAILABILITY_H

#undef HAVE_AVAILABILITYMACROS_H

#undef HAVE_AVAILABILITYVERSIONS_H

#undef HAVE_GETPWNAM

#undef HAVE_FRAMEBUFFER

/* Using GNU libiconv */
#undef USE_LIBICONV_GNU

/* Using a native implementation of iconv in a separate library */
#undef USE_LIBICONV_NATIVE

#undef DLLVERSION
#undef PACKAGE_VERSION
#define VERSION PACKAGE_VERSION
#undef OCP_MAJOR_VERSION
#undef OCP_MINOR_VERSION
#undef OCP_PATCH_VERSION

#undef HAVE_LZW

#undef HAVE_LZH

#ifdef HAVE_EFENCE
#include <stdlib.h>
#include <efence.h>
#endif

#ifdef HAVE_DUMA
#include <stdlib.h>
#include <string.h>
#include <duma.h>
#endif

#if defined(HAVE_DUMA)|defined(HAVE_EFENCE)
#define NO_DLCLOSE
#endif

#ifndef _WIN32
#define PREFIX "/usr/local"
#define LIBDIR "/usr/lib"
#define LIBDIROCP "/usr/lib/ocp"
#define DATADIR "/usr/share"
#define DATADIROCP "/usr/share/ocp"
#endif
#undef UNIFONT_RELATIVE
#undef UNIFONT_TTF
#undef UNIFONT_CSUR_TTF
#undef UNIFONT_UPPER_TTF
#undef UNIFONT_OTF
#undef UNIFONT_CSUR_OTF
#undef UNIFONT_UPPER_OTF

#define LIB_SUFFIX ".so"

#ifndef HAVE_MEMMEM
#include <string.h>
# ifdef __cplusplus
extern "C" {
# endif

/* We experienced that some combination of Haiku + nCurses ends up with header
 * files that defines memmem (as non-static), but no memmem implementation in
 * the provided libc (libgnu might provide it) so redirect memmem to ocp_memmem
 */
#undef memmem
#define memmem ocp_memmem

static inline void *memmem(const void *_haystack, size_t haystacklen,
                           const void *needle, size_t needlelen)
{
	const char *haystack = (const char *)_haystack;
	while (haystacklen>=needlelen)
	{
		if (!memcmp(haystack, needle, needlelen))
			return (void *)haystack;
		haystack++;
		haystacklen--;
	}
	return NULL;
}


# ifdef __cplusplus
}
# endif
#endif

#undef HAVE_FNMATCH
#undef HAVE_PATHMATCHSPECA

#include <limits.h>
/* A lot of structures etc. uses PATH_MAX, NAME_MAX and friends, so we
 * still #include <limits.h> here
 */


#undef GCC_411_RUNTIMECHECK

#undef SUPPORT_STATIC_PLUGINS
#undef STATIC_CORE

#undef HAVE_SYSCONF

#undef HAVE_STRUCT_DIRENT_D_TYPE

#undef SNDH_MUSTPROVIDE_ICE

#undef HAVE_FLAC

#undef HAVE_WAVPACK

#endif
