Fixed fatal linker error (global symbol conflict of "writephonebook")
[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.1.2.1  2001/11/27 04:37:59  short
17   Update: orig2001_11_25_22_56 -> orig2001_11_27_05_17
18
19   Revision 1.1.1.2  2001/11/27 04:19:40  short
20   :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
21
22   Revision 1.27  2001/11/26 18:06:08  pkot
23   Checking for *printf functions, N_(x) for localization, generic ARRAY_LEN, SAFE_STRNCPY, G_GNUC_PRINTF (Jan Kratochvil)
24
25   Revision 1.26  2001/11/14 10:46:12  pkot
26   Small cleanup with __unices__
27
28   Revision 1.25  2001/07/03 15:27:14  pkot
29   AT commands for SMS handling support (Tamas Bondar)
30   Small at-emulator code cleanup (me)
31
32   Revision 1.24  2001/06/28 00:28:46  pkot
33   Small docs updates (Pawel Kot)
34
35
36 */
37
38 #ifndef __misc_h
39 #define __misc_h    
40
41 #include "config.h"
42
43 /* Some general defines. */
44
45 #ifndef false
46 #  define false (0)
47 #endif
48
49 #ifndef true
50 #  define true (!false)
51 #endif
52
53 #ifndef bool    
54 #  define bool int
55 #endif
56
57 #define ARRAY_LEN(x) (sizeof((x)) / sizeof((x)[0]))
58
59 #define SAFE_STRNCPY(dest, src, n) do { \
60         strncpy((dest), (src), (n)); \
61         if ((n) > 0) \
62                 (dest)[(n)-1] = '\0'; \
63         } while (0)
64
65 #define SAFE_STRNCPY_SIZEOF(dest,src) \
66         SAFE_STRNCPY((dest), (src), sizeof((dest)))
67
68 /* Stolen from <glib.h>: */
69 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
70 #  define G_GNUC_PRINTF( format_idx, arg_idx )  \
71     __attribute__((format (printf, format_idx, arg_idx)))
72 #else   /* !__GNUC__ */
73 #  define G_GNUC_PRINTF( format_idx, arg_idx )
74 #endif  /* !__GNUC__ */
75
76 #define GNOKII_MAX(a, b)  (((a) > (b)) ? (a) : (b))
77 #define GNOKII_MIN(a, b)  (((a) < (b)) ? (a) : (b))
78
79 /* A define to make debug printfs neat */
80 #ifndef DEBUG
81 #  define dprintf(a...) do { } while (0)
82 #else
83 #  define dprintf(a...) do { fprintf(stderr, a); fflush(stderr); } while (0) 
84 #endif
85
86 /* Use gsprintf instead of sprintf and sprintf */
87 #ifdef HAVE_SNPRINTF
88 #  define gsprintf(a, b, c...) snprintf(a, b, c)
89 #else
90 #  define gsprintf(a, b, c...) sprintf(a, c)
91 #endif
92 #ifdef HAVE_VSNPRINTF
93 #  define gvsprintf(a, b, c...) vsnprintf(a, b, c)
94 #else
95 #  define gvsprintf(a, b, c...) vsprintf(a, c)
96 #endif
97 #ifdef HAVE_ASPRINTF
98 #  define gasprintf(a...) asprintf(a)
99 #else
100 #include <stdarg.h>
101 extern int gasprintf(char **destp, const char *fmt,...);
102 #endif
103 #ifdef HAVE_VASPRINTF
104 #  define gvasprintf(a...) vasprintf(a)
105 #else
106 #include <stdarg.h>
107 extern int gvasprintf(char **destp, const char *fmt, va_list ap);
108 #endif
109
110 /* Get rid of long defines. Use #if __unices__ */
111 #define __unices__ defined(__svr4__) || defined(__FreeBSD__) || defined(__bsdi__)
112 #if __unices__
113 #  include <strings.h>
114 #  include <sys/file.h>
115 #endif
116
117 /* This one is for NLS. */
118 #ifdef USE_NLS
119 #  include <libintl.h>
120 #  define _(x) gettext(x)
121 #  define N_(x) gettext_noop(x)
122 #else
123 #  define _(x) (x)
124 #  define N_(x) (x)
125 #endif /* USE_NLS */
126
127 /* Definitions for u8, u16, u32 and u64, borrowed from
128    /usr/src/linux/include/asm-i38/types.h */
129
130 #ifndef u8
131         typedef unsigned char u8;
132 #endif
133
134 #ifndef u16
135         typedef unsigned short u16;
136 #endif
137
138 #ifndef u32
139         typedef unsigned int u32;
140 #endif
141
142 #ifndef s32
143         typedef int s32;
144 #endif
145
146 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
147 #  ifndef u64
148         typedef unsigned long long u64;
149 #  endif
150
151 #  ifndef s64
152         typedef signed long long s64;
153 #  endif
154 #endif 
155
156 /* This one is for FreeBSD and similar systems without __ptr_t_ */
157 /* FIXME: autoconf should take care of this. */
158 #ifndef __ptr_t
159         typedef void * __ptr_t;
160 #endif /* __ptr_t */
161
162
163 /* Add here any timer operations which are not supported by libc5 */
164
165 #ifndef HAVE_TIMEOPS
166 #  ifdef WIN32
167
168 #    include <windows.h>
169 #    include <sys/timeb.h>
170 #    define timersub(a, b, result)
171         do {
172                 (result)->tv_sec = (a)->time - (b)->time;
173                 (result)->tv_usec = ((a)->millitm - (b)->millitm) * 1000;
174                 if ((result)->tv_usec < 0) {
175                         --(result)->tv_sec;
176                         (result)->tv_usec += 1000000;
177                 }
178         } while (0)
179 #    define gettimeofday(a, b) _ftime(a)
180
181 #  else /* !WIN32 */
182 #    include <sys/time.h>
183
184 #    ifndef timersub
185 #      define timersub(a, b, result)                               \
186         do {                                                       \
187                 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;      \
188                 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;   \
189                 if ((result)->tv_usec < 0) {                       \
190                         --(result)->tv_sec;                        \
191                         (result)->tv_usec += 1000000;              \
192                 }                                                  \
193         } while (0)
194 #    endif /* timersub */
195
196 #  endif /* WIN32 */
197 #endif /* HAVE_TIMEOPS */
198
199
200 #include <stdio.h>
201 extern int GetLine(FILE *File, char *Line, int count);
202
203 /* For models table */
204 typedef struct {
205         char *model;
206         char *number;
207         int flags;
208 } PhoneModel;
209
210 #define PM_CALLERGROUP    0x0001
211 #define PM_NETMONITOR     0x0002
212 #define PM_KEYBOARD       0x0004
213 #define PM_SMS            0x0008
214 #define PM_CALENDAR       0x0010
215 #define PM_DTMF           0x0020
216 #define PM_DATA           0x0040
217 #define PM_SPEEDDIAL      0x0080
218 #define PM_EXTPBK         0x0100
219 #define PM_AUTHENTICATION 0x0200
220
221 extern char *GetModel (const char *);
222 extern PhoneModel *GetPhoneModel (const char *);
223
224 #endif /* __misc_h */
225