1 /* $Id: indep.h,v 1.16 2003/09/22 21:02:19 ukai Exp $ */ 2 #ifndef INDEP_H 3 #define INDEP_H 4 #include "alloc.h" 5 #include "Str.h" 6 #include "config.h" 7 8 #ifndef TRUE 9 #define TRUE 1 10 #endif /* TRUE */ 11 #ifndef FALSE 12 #define FALSE 0 13 #endif /* FALSE */ 14 15 struct growbuf { 16 char *ptr; 17 int length; 18 int area_size; 19 void *(*realloc_proc) (void *, size_t); 20 void (*free_proc) (void *); 21 }; 22 23 #define RAW_MODE 0 24 #define PAGER_MODE 1 25 #define HTML_MODE 2 26 #define HEADER_MODE 3 27 28 extern unsigned char QUOTE_MAP[]; 29 extern char *HTML_QUOTE_MAP[]; 30 #define HTML_QUOTE_MASK 0x07 /* &, <, >, ", ' */ 31 #define SHELL_UNSAFE_MASK 0x08 /* [^A-Za-z0-9_./:\200-\377] */ 32 #define URL_QUOTE_MASK 0x10 /* [\0- \177-\377] */ 33 #define FILE_QUOTE_MASK 0x30 /* [\0- #%&+:?\177-\377] */ 34 #define URL_UNSAFE_MASK 0x70 /* [^A-Za-z0-9_$\-.] */ 35 #define GET_QUOTE_TYPE(c) QUOTE_MAP[(int)(unsigned char)(c)] 36 #define is_html_quote(c) (GET_QUOTE_TYPE(c) & HTML_QUOTE_MASK) 37 #define is_shell_unsafe(c) (GET_QUOTE_TYPE(c) & SHELL_UNSAFE_MASK) 38 #define is_url_quote(c) (GET_QUOTE_TYPE(c) & URL_QUOTE_MASK) 39 #define is_file_quote(c) (GET_QUOTE_TYPE(c) & FILE_QUOTE_MASK) 40 #define is_url_unsafe(c) (GET_QUOTE_TYPE(c) & URL_UNSAFE_MASK) 41 #define html_quote_char(c) HTML_QUOTE_MAP[(int)is_html_quote(c)] 42 43 extern clen_t strtoclen(const char *s); 44 extern char *conv_entity(unsigned int ch); 45 extern int getescapechar(char **s); 46 extern char *getescapecmd(char **s); 47 extern char *allocStr(const char *s, int len); 48 extern int strCmp(const void *s1, const void *s2); 49 extern char *currentdir(void); 50 extern char *cleanupName(char *name); 51 extern char *expandPath(char *name); 52 #ifndef HAVE_STRCHR 53 extern char *strchr(const char *s, int c); 54 #endif /* not HAVE_STRCHR */ 55 #ifndef HAVE_STRCASECMP 56 extern int strcasecmp(const char *s1, const char *s2); 57 extern int strncasecmp(const char *s1, const char *s2, size_t n); 58 #endif /* not HAVE_STRCASECMP */ 59 #ifndef HAVE_STRCASESTR 60 extern char *strcasestr(const char *s1, const char *s2); 61 #endif 62 extern int strcasemstr(char *str, char *srch[], char **ret_ptr); 63 int strmatchlen(const char *s1, const char *s2, int maxlen); 64 extern char *remove_space(char *str); 65 extern int non_null(char *s); 66 extern void cleanup_line(Str s, int mode); 67 extern char *html_quote(char *str); 68 extern char *html_unquote(char *str); 69 extern char *file_quote(char *str); 70 extern char *file_unquote(char *str); 71 extern char *url_quote(char *str); 72 extern Str Str_url_unquote(Str x, int is_form, int safe); 73 extern Str Str_form_quote(Str x); 74 #define Str_form_unquote(x) Str_url_unquote((x), TRUE, FALSE) 75 extern char *shell_quote(char *str); 76 #define xmalloc(s) xrealloc(NULL, s) 77 extern void *xrealloc(void *ptr, size_t size); 78 extern void xfree(void *ptr); 79 extern void *w3m_GC_realloc_atomic(void *ptr, size_t size); 80 extern void w3m_GC_free(void *ptr); 81 extern void growbuf_init(struct growbuf *gb); 82 extern void growbuf_init_without_GC(struct growbuf *gb); 83 extern void growbuf_clear(struct growbuf *gb); 84 extern Str growbuf_to_Str(struct growbuf *gb); 85 extern void growbuf_reserve(struct growbuf *gb, int leastarea); 86 extern void growbuf_append(struct growbuf *gb, const char *src, int len); 87 #define GROWBUF_ADD_CHAR(gb,ch) ((((gb)->length>=(gb)->area_size)?growbuf_reserve(gb,(gb)->length+1):(void)0),(void)((gb)->ptr[(gb)->length++] = (ch))) 88 89 extern char *w3m_auxbin_dir(); 90 extern char *w3m_lib_dir(); 91 extern char *w3m_etc_dir(); 92 extern char *w3m_conf_dir(); 93 extern char *w3m_help_dir(); 94 95 #define NewWithoutGC(type) ((type*)xmalloc(sizeof(type))) 96 #define NewWithoutGC_N(type,n) ((type*)xmalloc((n)*sizeof(type))) 97 #define NewWithoutGC_Reuse(type,ptr,n) ((type*)xrealloc(ptr,(n)*sizeof(type))) 98 99 #endif /* INDEP_H */ 100