// -*- C++ -*-

// System-dependent configuration
#ifndef CONFIG_H
#define CONFIG_H

/* What OS do we compile for? Exactly one of these must be 1.
   Assumes a native Windows environment like mingw32, not Cygwin. */
#define WINDOWS 0
#define UNIX 0

// An unsigned integer type with at least 64, possibly more bits
#undef TYPE_UINT64

// Define to 1 if the type "unsigned long long" is supported
#define HAVE_UNSIGNED_LONG_LONG 1

// Define to 1 if "uint64 x; cout << x;" works
#define HAVE_OUTUINT64 1

// Define to 1 if header <stddef.h> is available on the system
#define HAVE_STDDEF_H 0
#if HAVE_STDDEF_H
#  include <stddef.h> /* to get size_t */
#endif

// Define to 1 if header <unistd.h> is available on the system
#define HAVE_UNISTD_H 0

// Define to 1 if header <limits.h> is available on the system
#define HAVE_LIMITS_H 0

// Define to 1 if header <string.h> is available on the system
#define HAVE_STRING_H 1

// Define to `unsigned' if <sys/types.h> doesn't define.
#undef size_t

// Define if you have the ANSI C header files.
#define STDC_HEADERS 1

/* Define to 1 if gettext is installed, if you want support for
  translation of program messages. PACKAGE_LOCALE_DIR is a string like
  "/usr/local/share/locale" under Unix - gettext will load e.g.
  "/usr/local/share/locale/de/LC_MESSAGES/jigdo.mo" for German
  translations */
#define ENABLE_NLS 0

/* Define if your system provides getopt_long (will compile in own
   version if not) */
#undef HAVE_GETOPT_H

/* Define to 1 if libdb is present on the system. If set to 0, some
   functionality (jigdo-file's --cache option) will not be
   available. */
#define HAVE_LIBDB 0

/* Define to 1 if "int lstat(const char *file_name, struct stat *buf)"
   is available, i.e. symbolic links are supported. If defined to 0,
   stat() is used instead. */
#define HAVE_LSTAT 0

/* Preferably, we want to use "int truncate(const char *path, off_t
   length)" to truncate a file to a given length. Alternatively, if
   "int ftruncate(int fd, off_t length)" is available, compat.cc
   truncates using that. */
#define HAVE_TRUNCATE 0
#define HAVE_FTRUNCATE 0

/* Define to 1 if "void * mmap(void *start, size_t length, int prot,
   int flags, int fd, off_t offset)" and "int munmap(void *start,
   size_t length)" are present. Only used in torture. */
#define HAVE_MMAP 0

/* Define to 1 if "int fileno( FILE *stream)" for getting the Unix
   file descriptor for an ANSI C FILE* is present. */
#define HAVE_FILENO 0

/* Define to 1 if "ioctl(fileno(stdout), TIOCGWINSZ, &winsize)" can be
   used to read the width in characters of the TTY, for formatting of
   progress reports. This probably only works on Linux. */
#define HAVE_IOCTL_WINSZ 0

/* Both MinGW32 and glib declare 'struct dirent' and 'struct DIR'. If
   there are problems using the relevant headers together, define to 1
   to do some really dirty things with the preprocessor to disable the
   glib declaration. */
#define DIRENT_HACK 0

// On native MinGW32, redefine snprintf to _snprintf
#undef snprintf

// Define to 1 to compile in lots of additional run-time checks
#ifndef DEBUG
#define DEBUG 0
#endif

// Program version
#undef JIGDO_VERSION

#endif /* CONFIG_H */
//______________________________________________________________________

#ifndef CONFIG_CONSTANTS
#ifdef  __cplusplus
#define CONFIG_CONSTANTS

// Do not change this
#define PACKAGE "jigdo"

/* By removing this you give up portability to early versions of GCC
   2.95, which did not come with any <sstream>, only a <strstream>,
   and even that was so broken it was completely unusable. */
#if DEBUG
#  define stringstream Do_not_use_stringstream__See_config_h
#  define istringstream Do_not_use_istringstream__See_config_h
#  define ostringstream Do_not_use_ostringstream__See_config_h
#endif

#if DEBUG
#  define NOINLINE /* to reduce amount of recompilation */
#else /* !DEBUG */
// Disable runtime checks of glib - if you #include config.h before glib.h!-)
#  define G_DISABLE_CHECKS
#  define G_DISABLE_ASSERT
#endif

/** Character (as char and string constant) for directory separator
    First character of SPLITSEP must be same as DIRSEP */
#if WINDOWS
#  define DIRSEP '\\'
#  define DIRSEPS "\\"
#  define SPLITSEP "\\.\\"
#else
#  define DIRSEP '/'
#  define DIRSEPS "/"
#  define SPLITSEP "//"
#endif
/// Character for filename extensions
#define EXTSEP '.'
#define EXTSEPS "."

#if DIRENT_HACK
#  include <dirent.hh>
#endif

// libwww.hh also contains some of these #defines
#if ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif

#include <cstddef>
namespace std { }
using namespace std;

namespace {

  /** This may seem to be defined the wrong way around, but it allows
      you to write 'if (someFunction()) { handleError(); }' */
  const bool SUCCESS = false; ///
  const bool FAILURE = true;

  /// Version of file format
  const unsigned FILEFORMAT_MAJOR = 1;
  const unsigned FILEFORMAT_MINOR = 1;
  /// String at start of .template files
  const char TEMPLATE_HDR[] = "JigsawDownload template ";

  /// Info URL written in .template/.jigdo file header
  const char* const URL = "http://atterer.net/jigdo";

  /** Approximate size of chunks into which unmatched data is chopped
      up when included in template file. Measured in bytes of
      *uncompressed* data. */
  const size_t ZIPCHUNK_SIZE = 256*1024;

  /** Number of bytes to write at a time before outputting a progress
      report */
  const size_t REPORT_INTERVAL = 256U*1024;
}

/** unsigned int with at least 64, but possibly more bits */
typedef TYPE_UINT64 uint64;
/** unsigned int with at least 32, but possibly more bits */
typedef unsigned int uint32;
/** exactly 8 bits, unsigned */
typedef unsigned char byte;

/// Bjarne's implicit cast - useful at times
template<class T, class U> inline T implicit_cast(U u) { return u; }

#endif
#endif
