2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-01-30 01:27:15 +03:00
|
|
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
2008-08-05 05:30:31 +04:00
|
|
|
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-22 13:24:35 +04:00
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#ifndef _NETSURF_UTILS_UTILS_H_
|
|
|
|
#define _NETSURF_UTILS_UTILS_H_
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2003-11-08 02:47:55 +03:00
|
|
|
#include <stdbool.h>
|
2004-07-06 00:19:52 +04:00
|
|
|
#include <stddef.h>
|
2002-08-12 03:04:02 +04:00
|
|
|
#include <stdlib.h>
|
2003-12-27 23:15:23 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <regex.h>
|
2008-05-25 19:04:22 +04:00
|
|
|
#include <assert.h>
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2005-04-15 09:52:04 +04:00
|
|
|
#ifndef NOF_ELEMENTS
|
|
|
|
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
|
|
|
|
#endif
|
2005-04-22 01:36:23 +04:00
|
|
|
#ifndef ABS
|
|
|
|
#define ABS(x) (((x)>0)?(x):(-(x)))
|
|
|
|
#endif
|
|
|
|
#ifndef min
|
|
|
|
#define min(x,y) (((x)<(y))?(x):(y))
|
|
|
|
#endif
|
|
|
|
#ifndef max
|
|
|
|
#define max(x,y) (((x)>(y))?(x):(y))
|
|
|
|
#endif
|
2008-08-13 21:37:59 +04:00
|
|
|
#ifndef PRIxPTR
|
|
|
|
#define PRIxPTR "x"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAIKU__) || defined(__BEOS__)
|
|
|
|
#define strtof(s,p) ((float)(strtod((s),(p))))
|
|
|
|
#endif
|
2005-04-15 09:52:04 +04:00
|
|
|
|
2008-05-25 19:51:30 +04:00
|
|
|
/**
|
|
|
|
* Calculate length of constant C string.
|
|
|
|
*
|
|
|
|
* \param x a constant C string.
|
|
|
|
* \return the length of C string without its terminating NUL accounted.
|
|
|
|
*/
|
|
|
|
#define SLEN(x) (sizeof((x)) - 1)
|
|
|
|
|
2005-04-23 06:58:27 +04:00
|
|
|
enum query_response {
|
|
|
|
QUERY_CONTINUE,
|
|
|
|
QUERY_YES,
|
|
|
|
QUERY_NO,
|
|
|
|
QUERY_ESCAPE
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int query_id;
|
|
|
|
|
|
|
|
#define QUERY_INVALID ((query_id)-1)
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void (*confirm)(query_id id, enum query_response res, void *pw);
|
|
|
|
void (*cancel)(query_id, enum query_response res, void *pw);
|
|
|
|
} query_callback;
|
|
|
|
|
|
|
|
|
2002-04-22 13:24:35 +04:00
|
|
|
char * strip(char * const s);
|
|
|
|
int whitespace(const char * str);
|
2002-05-22 01:27:29 +04:00
|
|
|
char * squash_whitespace(const char * s);
|
2004-07-06 00:19:52 +04:00
|
|
|
char *cnv_space2nbsp(const char *s);
|
2003-11-08 02:47:55 +03:00
|
|
|
bool is_dir(const char *path);
|
2003-12-27 23:15:23 +03:00
|
|
|
void regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
|
2003-12-29 03:38:59 +03:00
|
|
|
void unicode_transliterate(unsigned int c, char **r);
|
2004-04-25 15:40:05 +04:00
|
|
|
char *human_friendly_bytesize(unsigned long bytesize);
|
2006-02-06 03:10:09 +03:00
|
|
|
const char *rfc1123_date(time_t t);
|
2008-08-11 20:44:12 +04:00
|
|
|
#if !(defined(_GNU_SOURCE) || defined(__NetBSD__)) || defined(riscos) || \
|
|
|
|
defined(__APPLE__)
|
2006-07-02 14:26:51 +04:00
|
|
|
char *strcasestr(const char *haystack, const char *needle);
|
2007-02-10 05:21:32 +03:00
|
|
|
#endif
|
2007-01-30 18:32:31 +03:00
|
|
|
unsigned int wallclock(void);
|
2005-04-16 09:09:33 +04:00
|
|
|
|
2008-05-25 19:04:22 +04:00
|
|
|
/**
|
|
|
|
* Return a hex digit for the given numerical value.
|
|
|
|
*
|
|
|
|
* \return character in range 0-9a-f
|
|
|
|
*/
|
|
|
|
inline static char digit2lowcase_hex(unsigned char digit) {
|
|
|
|
assert(digit < 16);
|
|
|
|
return "0123456789abcdef"[digit];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-16 09:09:33 +04:00
|
|
|
/* Platform specific functions */
|
|
|
|
void die(const char * const error);
|
2004-06-11 00:41:26 +04:00
|
|
|
void warn_user(const char *warning, const char *detail);
|
2006-02-07 19:16:23 +03:00
|
|
|
query_id query_user(const char *query, const char *detail,
|
|
|
|
const query_callback *cb, void *pw, const char *yes, const char *no);
|
2005-04-23 06:58:27 +04:00
|
|
|
void query_close(query_id);
|
2002-05-22 01:27:29 +04:00
|
|
|
|
2002-08-12 03:04:02 +04:00
|
|
|
#endif
|