2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2015-01-11 05:08:30 +00:00
|
|
|
#pragma once
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
2015-07-25 23:10:45 +00:00
|
|
|
#include <cstddef>
|
2015-01-11 05:08:30 +00:00
|
|
|
#include <cstdint>
|
2015-07-25 23:10:45 +00:00
|
|
|
#include <cstring>
|
2013-12-18 21:47:20 +00:00
|
|
|
#include "dxxsconf.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2018-08-28 02:00:00 +00:00
|
|
|
#include "compiler-array.h"
|
2014-09-28 23:28:56 +00:00
|
|
|
#include <vector>
|
2012-11-11 22:12:51 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2008-01-03 10:31:02 +00:00
|
|
|
#if defined(macintosh)
|
2015-01-11 05:08:30 +00:00
|
|
|
#define snprintf macintosh_snprintf
|
2013-06-08 22:24:17 +00:00
|
|
|
extern void snprintf(char *out_string, int size, const char * format, ... );
|
2010-07-19 18:17:08 +00:00
|
|
|
#endif
|
2015-01-12 00:26:03 +00:00
|
|
|
|
|
|
|
#ifdef DXX_HAVE_STRCASECMP
|
|
|
|
#define d_stricmp strcasecmp
|
|
|
|
static inline int d_strnicmp(const char *s1, const char *s2, size_t n)
|
|
|
|
{
|
|
|
|
return strncasecmp(s1, s2, n);
|
|
|
|
}
|
|
|
|
#else
|
2015-01-11 05:08:30 +00:00
|
|
|
__attribute_nonnull()
|
2012-05-18 23:36:41 +00:00
|
|
|
extern int d_stricmp( const char *s1, const char *s2 );
|
2015-01-11 05:08:30 +00:00
|
|
|
__attribute_nonnull()
|
|
|
|
int d_strnicmp(const char *s1, const char *s2, uint_fast32_t n);
|
2015-01-12 00:26:03 +00:00
|
|
|
#endif
|
2012-05-18 23:36:41 +00:00
|
|
|
extern void d_strlwr( char *s1 );
|
|
|
|
extern void d_strupr( char *s1 );
|
|
|
|
extern void d_strrev( char *s1 );
|
2013-12-18 22:33:25 +00:00
|
|
|
#ifdef DEBUG_MEMORY_ALLOCATIONS
|
2015-06-11 03:06:58 +00:00
|
|
|
char *d_strdup(const char *str, const char *, const char *, unsigned) __attribute_malloc();
|
|
|
|
#define d_strdup(str) (d_strdup(str, #str, __FILE__,__LINE__))
|
2013-12-18 22:33:25 +00:00
|
|
|
#else
|
|
|
|
#include <cstring>
|
|
|
|
#define d_strdup strdup
|
|
|
|
#endif
|
2008-01-19 01:13:47 +00:00
|
|
|
|
2015-01-12 00:26:03 +00:00
|
|
|
template <std::size_t N>
|
|
|
|
static inline int d_strnicmp(const char *s1, const char (&s2)[N])
|
|
|
|
{
|
|
|
|
return d_strnicmp(s1, s2, N - 1);
|
|
|
|
}
|
|
|
|
|
2013-06-09 18:10:09 +00:00
|
|
|
struct splitpath_t
|
|
|
|
{
|
|
|
|
const char *drive_start, *drive_end, *path_start, *path_end, *base_start, *base_end, *ext_start;
|
|
|
|
};
|
|
|
|
|
2008-02-11 12:12:57 +00:00
|
|
|
// remove extension from filename, doesn't work with paths.
|
2018-08-26 18:10:36 +00:00
|
|
|
void removeext(const char *filename, array<char, 20> &out);
|
2008-02-11 12:12:57 +00:00
|
|
|
|
2010-09-26 13:15:20 +00:00
|
|
|
//give a filename a new extension, doesn't work with paths with no extension already there
|
2013-06-08 22:24:17 +00:00
|
|
|
extern void change_filename_extension( char *dest, const char *src, const char *new_ext );
|
2008-01-19 01:13:47 +00:00
|
|
|
|
2012-07-24 09:29:43 +00:00
|
|
|
// split an MS-DOS path into drive, directory path, filename without the extension (base) and extension.
|
|
|
|
// if it's just a filename with no directory specified, this function will get 'base' and 'ext'
|
2013-06-09 18:10:09 +00:00
|
|
|
void d_splitpath(const char *name, struct splitpath_t *path);
|
2010-07-19 18:17:08 +00:00
|
|
|
|
2015-01-17 18:31:42 +00:00
|
|
|
class string_array_t
|
2014-09-28 23:28:56 +00:00
|
|
|
{
|
2015-01-17 18:31:42 +00:00
|
|
|
typedef std::vector<const char *> ptr_t;
|
2014-09-28 23:28:56 +00:00
|
|
|
std::vector<char> buffer;
|
2015-01-17 18:31:42 +00:00
|
|
|
ptr_t ptr;
|
|
|
|
public:
|
|
|
|
ptr_t &pointer() { return ptr; }
|
2014-09-28 23:28:56 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
ptr.clear();
|
|
|
|
buffer.clear();
|
|
|
|
}
|
|
|
|
void add(const char *);
|
|
|
|
void tidy(std::size_t offset, int (*comp)( const char *, const char * ));
|
|
|
|
};
|
2010-09-26 13:15:20 +00:00
|
|
|
|
2016-09-04 19:10:42 +00:00
|
|
|
int string_array_sort_func(const void *v0, const void *v1);
|
2010-09-26 13:15:20 +00:00
|
|
|
|
2020-04-19 20:47:07 +00:00
|
|
|
/* Compute the number of digits required to represent MaximumValue in
|
|
|
|
* the given Base. The result does not account for any characters other
|
|
|
|
* than the required digits.
|
|
|
|
*/
|
|
|
|
template <std::size_t MaximumValue, std::size_t Base = 10>
|
|
|
|
constexpr std::size_t number_to_text_length = (MaximumValue < Base) ? 1 : 1 + number_to_text_length<MaximumValue / Base, Base>;
|
|
|
|
static_assert(number_to_text_length<1> == 1, "");
|
|
|
|
static_assert(number_to_text_length<9> == 1, "");
|
|
|
|
static_assert(number_to_text_length<10> == 2, "");
|
|
|
|
static_assert(number_to_text_length<255, 16> == 2, "");
|
|
|
|
static_assert(number_to_text_length<256, 16> == 3, "");
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|