2003-06-30 12:44:03 +00:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-03-02 18:02:41 +00:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2004-07-05 20:19:52 +00:00
|
|
|
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
|
2002-04-22 09:24:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-02-09 12:58:15 +00:00
|
|
|
#ifndef _NETSURF_UTILS_UTILS_H_
|
|
|
|
#define _NETSURF_UTILS_UTILS_H_
|
2002-08-11 23:04:02 +00:00
|
|
|
|
2003-11-07 23:47:55 +00:00
|
|
|
#include <stdbool.h>
|
2004-07-05 20:19:52 +00:00
|
|
|
#include <stddef.h>
|
2002-08-11 23:04:02 +00:00
|
|
|
#include <stdlib.h>
|
2003-12-27 20:15:23 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <regex.h>
|
2002-08-11 23:04:02 +00:00
|
|
|
|
2005-04-15 05:52:04 +00:00
|
|
|
#ifndef NOF_ELEMENTS
|
|
|
|
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
|
|
|
|
#endif
|
2005-04-21 21:36:23 +00: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 05:52:04 +00:00
|
|
|
|
2005-04-23 02:58:27 +00: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);
|
|
|
|
void (*escape)(query_id, enum query_response res, void *pw);
|
|
|
|
} query_callback;
|
|
|
|
|
|
|
|
|
2002-04-22 09:24:35 +00:00
|
|
|
char * strip(char * const s);
|
|
|
|
int whitespace(const char * str);
|
2002-05-21 21:27:29 +00:00
|
|
|
char * squash_whitespace(const char * s);
|
2004-07-05 20:19:52 +00:00
|
|
|
char *cnv_space2nbsp(const char *s);
|
2003-11-07 23:47:55 +00:00
|
|
|
bool is_dir(const char *path);
|
2003-12-27 20:15:23 +00:00
|
|
|
void regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
|
2003-12-29 00:38:59 +00:00
|
|
|
void unicode_transliterate(unsigned int c, char **r);
|
2004-04-25 11:40:05 +00:00
|
|
|
char *human_friendly_bytesize(unsigned long bytesize);
|
2006-02-06 00:10:09 +00:00
|
|
|
const char *rfc1123_date(time_t t);
|
2006-07-02 10:26:51 +00:00
|
|
|
char *strcasestr(const char *haystack, const char *needle);
|
2005-04-16 05:09:33 +00:00
|
|
|
|
|
|
|
/* Platform specific functions */
|
|
|
|
void die(const char * const error);
|
2004-06-10 20:41:26 +00:00
|
|
|
void warn_user(const char *warning, const char *detail);
|
2006-02-07 16:16:23 +00: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 02:58:27 +00:00
|
|
|
void query_close(query_id);
|
2002-05-21 21:27:29 +00:00
|
|
|
|
2002-08-11 23:04:02 +00:00
|
|
|
#endif
|