Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / common.h
1 #ifndef __COMMON_H
2 #define __COMMON_H
3
4 #define IRSSI_DIR_FULL "%s/.silc" /* %s == g_get_home_dir() */
5
6 #define IRSSI_GLOBAL_CONFIG "silc.conf" /* config file name in /etc/ */
7 #define IRSSI_HOME_CONFIG "silc.conf" /* config file name in ~/.irssi/ */
8
9 #define DEFAULT_SERVER_ADD_PORT 706
10
11 #ifdef HAVE_CONFIG_H
12 #include "irssi-config.h"
13 #endif
14
15 #ifndef PACKAGE
16 #define PACKAGE "SILC Client"
17 #endif /* PACKAGE */
18
19 #include <stdio.h>
20 #include <stddef.h>
21 #include <stdarg.h>
22 #include <ctype.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <time.h>
27
28 #include <sys/types.h>
29 #ifdef HAVE_SYS_TIME_H
30 #  include <sys/time.h>
31 #endif
32 #include <sys/stat.h>
33
34 #ifdef HAVE_UNISTD_H
35 #  include <unistd.h>
36 #endif
37 #ifdef HAVE_DIRENT_H
38 #  include <dirent.h>
39 #endif
40 #include <fcntl.h>
41 #ifdef WIN32
42 #  include <win32-compat.h>
43 #endif
44
45 #include <glib.h>
46 #ifdef HAVE_GMODULE
47 #  include <gmodule.h>
48 #endif
49
50 #if !GLIB_CHECK_VERSION(2,10,0)
51 #define g_slice_alloc(size)      g_malloc(size)
52 #define g_slice_alloc0(size)     g_malloc0(size)
53 #define g_slice_free1(size, mem) g_free(mem)
54 #define g_slice_new(type)        g_new(type, 1)
55 #define g_slice_new0(type)       g_new0(type, 1)
56 #define g_slice_free(type, mem)  g_free(mem)
57 #endif
58
59 #ifdef USE_GC
60 #  define g_free(x) G_STMT_START { (x) = NULL; } G_STMT_END
61 #endif
62
63 #if defined (UOFF_T_INT)
64 typedef unsigned int uoff_t;
65 #elif defined (UOFF_T_LONG)
66 typedef unsigned long uoff_t;
67 #elif defined (UOFF_T_LONG_LONG)
68 typedef unsigned long long uoff_t;
69 #else
70 #  error uoff_t size not set
71 #endif
72
73 /* input functions */
74 #define G_INPUT_READ    (1 << 0)
75 #define G_INPUT_WRITE   (1 << 1)
76
77 typedef void (*GInputFunction) (void *data, GIOChannel *source, int condition);
78
79 int g_input_add(GIOChannel *source, int condition,
80                 GInputFunction function, void *data);
81 int g_input_add_full(GIOChannel *source, int priority, int condition,
82                      GInputFunction function, void *data);
83
84 /* return full path for ~/.irssi */
85 const char *get_irssi_dir(void);
86 /* return full path for ~/.irssi/config */
87 const char *get_irssi_config(void);
88
89 /* max. size for %d */
90 #define MAX_INT_STRLEN ((sizeof(int) * CHAR_BIT + 2) / 3 + 1)
91
92 #define g_free_not_null(a) g_free(a)
93
94 #define g_free_and_null(a) \
95         G_STMT_START { \
96           if (a) { g_free(a); (a) = NULL; } \
97         } G_STMT_END
98
99 /* ctype.h isn't safe with chars, use our own instead */
100 #define i_toupper(x) toupper((int) (unsigned char) (x))
101 #define i_tolower(x) tolower((int) (unsigned char) (x))
102 #define i_isalnum(x) isalnum((int) (unsigned char) (x))
103 #define i_isalpha(x) isalpha((int) (unsigned char) (x))
104 #define i_isascii(x) isascii((int) (unsigned char) (x))
105 #define i_isblank(x) isblank((int) (unsigned char) (x))
106 #define i_iscntrl(x) iscntrl((int) (unsigned char) (x))
107 #define i_isdigit(x) isdigit((int) (unsigned char) (x))
108 #define i_isgraph(x) isgraph((int) (unsigned char) (x))
109 #define i_islower(x) islower((int) (unsigned char) (x))
110 #define i_isprint(x) isprint((int) (unsigned char) (x))
111 #define i_ispunct(x) ispunct((int) (unsigned char) (x))
112 #define i_isspace(x) isspace((int) (unsigned char) (x))
113 #define i_isupper(x) isupper((int) (unsigned char) (x))
114 #define i_isxdigit(x) isxdigit((int) (unsigned char) (x))
115
116 typedef struct _IPADDR IPADDR;
117
118 typedef struct _LINEBUF_REC LINEBUF_REC;
119 typedef struct _NET_SENDBUF_REC NET_SENDBUF_REC;
120 typedef struct _RAWLOG_REC RAWLOG_REC;
121
122 typedef struct _CHAT_PROTOCOL_REC CHAT_PROTOCOL_REC;
123 typedef struct _CHATNET_REC CHATNET_REC;
124 typedef struct _SERVER_REC SERVER_REC;
125 typedef struct _WI_ITEM_REC WI_ITEM_REC;
126 typedef struct _CHANNEL_REC CHANNEL_REC;
127 typedef struct _QUERY_REC QUERY_REC;
128 typedef struct _NICK_REC NICK_REC;
129
130 typedef struct _SERVER_CONNECT_REC SERVER_CONNECT_REC;
131 typedef struct _SERVER_SETUP_REC SERVER_SETUP_REC;
132 typedef struct _CHANNEL_SETUP_REC CHANNEL_SETUP_REC;
133
134 typedef struct _WINDOW_REC WINDOW_REC;
135
136 #endif