Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
[gnokii.git] / include / misc.h
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml.
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13   Header file for miscellaneous defines, typedefs etc.
14
15   $Log$
16   Revision 1.1.1.4  2002/04/03 00:08:19  short
17   Found in "gnokii-working" directory, some November-patches version
18
19   Revision 1.25  2001/07/03 15:27:14  pkot
20   AT commands for SMS handling support (Tamas Bondar)
21   Small at-emulator code cleanup (me)
22
23   Revision 1.24  2001/06/28 00:28:46  pkot
24   Small docs updates (Pawel Kot)
25
26
27 */
28
29 #ifndef __misc_h
30 #define __misc_h    
31
32 #include <config.h>
33
34 /* Some general defines. */
35
36 #ifndef false
37   #define false (0)
38 #endif
39
40 #ifndef true
41   #define true (!false)
42 #endif
43
44 #ifndef bool    
45   #define bool int
46 #endif
47
48 #define ARRAY_LEN(x) (sizeof((x))/sizeof((x)[0]))
49
50 #define SAFE_STRNCPY(dest,src,n) do { \
51         strncpy((dest),(src),(n)); \
52         if ((n)>0) \
53                 (dest)[(n)-1]='\0'; \
54         } while (0)
55
56 #define SAFE_STRNCPY_SIZEOF(dest,src) \
57         SAFE_STRNCPY((dest),(src),sizeof((dest)))
58
59 /* Stolen from <glib.h>: */
60 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
61 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
62   __attribute__((format (printf, format_idx, arg_idx)))
63 #else   /* !__GNUC__ */
64 #define G_GNUC_PRINTF( format_idx, arg_idx )
65 #endif  /* !__GNUC__ */
66
67 #define GNOKII_MAX(a, b)  (((a) > (b)) ? (a) : (b))
68 #define GNOKII_MIN(a, b)  (((a) < (b)) ? (a) : (b))
69
70 /* A define to make debug printfs neat */
71 #ifndef DEBUG
72 #define dprintf(a...) do { } while (0)
73 #else
74 #define dprintf(a...) do { fprintf(stderr, a); fflush(stderr); } while (0) 
75 #endif
76
77 /* Use gsprintf instead of sprintf and sprintf */
78 #ifdef HAVE_SNPRINTF
79 # define gsprintf(a, b, c...) snprintf(a, b, c)
80 #else
81 # define gsprintf(a, b, c...) sprintf(a, c)
82 #endif
83 #ifdef HAVE_VSNPRINTF
84 # define gvsprintf(a, b, c...) vsnprintf(a, b, c)
85 #else
86 # define gvsprintf(a, b, c...) vsprintf(a, c)
87 #endif
88 #ifdef HAVE_ASPRINTF
89 # define gasprintf(a...) asprintf(a)
90 #else
91 #include <stdarg.h>
92 extern int gasprintf(char **destp,const char *fmt,...);
93 #endif
94 #ifdef HAVE_VASPRINTF
95 # define gvasprintf(a...) vasprintf(a)
96 #else
97 #include <stdarg.h>
98 extern int gvasprintf(char **destp,const char *fmt,va_list ap);
99 #endif
100
101 /* Get rid of long defines. Use #if __unices__ */
102 #define __unices__ defined(__svr4__) || defined(__FreeBSD__) || defined(__bsdi__)
103
104 /* This one is for NLS. */
105 #ifdef USE_NLS
106   #include <libintl.h>
107   #define _(x) gettext(x)
108 #else
109   #define _(x) (x)
110 #endif /* USE_NLS */
111 #define N_(x) (x)
112
113 /* Definitions for u8, u16, u32 and u64, borrowed from
114    /usr/src/linux/include/asm-i38/types.h */
115
116 #ifndef u8
117   typedef unsigned char u8;
118 #endif
119
120 #ifndef u16
121   typedef unsigned short u16;
122 #endif
123
124 #ifndef u32
125   typedef unsigned int u32;
126 #endif
127
128 #ifndef s32
129   typedef int s32;
130 #endif
131
132 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
133   #ifndef u64
134     typedef unsigned long long u64;
135   #endif
136
137   #ifndef s64
138     typedef signed long long s64;
139   #endif
140 #endif 
141
142 /* This one is for FreeBSD and similar systems without __ptr_t_ */
143 /* FIXME: autoconf should take care of this. */
144
145 #ifndef __ptr_t
146   typedef void * __ptr_t;
147 #endif /* __ptr_t */
148
149
150 /* Add here any timer operations which are not supported by libc5 */
151
152 #ifndef HAVE_TIMEOPS
153 #ifdef WIN32
154
155 #include <windows.h>
156 #include <sys/timeb.h>
157 #define timersub(a, b, result)
158   do {
159     (result)->tv_sec = (a)->time - (b)->time;
160     (result)->tv_usec = ((a)->millitm - (b)->millitm) * 1000;
161     if ((result)->tv_usec < 0) {
162       --(result)->tv_sec;
163       (result)->tv_usec += 1000000;
164     }
165   } while (0)
166 #define gettimeofday(a, b) _ftime(a)
167
168 #else
169 #include <sys/time.h>
170
171 #ifndef timersub
172 #define timersub(a, b, result)                                                \
173   do {                                                                        \
174     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
175     (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
176     if ((result)->tv_usec < 0) {                                              \
177       --(result)->tv_sec;                                                     \
178       (result)->tv_usec += 1000000;                                           \
179     }                                                                         \
180   } while (0)
181 #endif
182
183 #endif /* WIN32 */
184 #endif /* HAVE_TIMEOPS */
185
186
187 #include <stdio.h>
188 extern int GetLine(FILE *File, char *Line, int count);
189
190 /* For models table */
191 typedef struct {
192   char *model;
193   char *number;
194   int flags;
195 } PhoneModel;
196
197 #define PM_CALLERGROUP    0x0001
198 #define PM_NETMONITOR     0x0002
199 #define PM_KEYBOARD       0x0004
200 #define PM_SMS            0x0008
201 #define PM_CALENDAR       0x0010
202 #define PM_DTMF           0x0020
203 #define PM_DATA           0x0040
204 #define PM_SPEEDDIAL      0x0080
205 #define PM_EXTPBK         0x0100
206 #define PM_AUTHENTICATION 0x0200
207
208 extern char *GetModel (const char *);
209 extern PhoneModel *GetPhoneModel (const char *);
210
211 #endif /* __misc_h */
212