2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2006-11-27 18:35:18 +03:00
|
|
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
2003-06-30 16:44:03 +04:00
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2007-01-30 01:27:15 +03:00
|
|
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
2004-07-06 00:19:52 +04:00
|
|
|
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
|
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>
|
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
|
2005-04-15 09:52:04 +04:00
|
|
|
|
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);
|
2006-07-02 14:26:51 +04:00
|
|
|
char *strcasestr(const char *haystack, const char *needle);
|
2007-01-30 01:27:15 +03:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
/* FreeBSD lacks strndup */
|
|
|
|
char *strndup(const char *s, size_t n);
|
|
|
|
#endif
|
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
|