X-Git-Url: http://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=include%2Fmisc.h;h=435314c77317cae457e6290faa21fad8f3f36b4d;hp=2a16e51f28b2a268d92eca2dc742fc5c7ddcc270;hb=49dd905279a8e62936e3713510ab0fd738e20ecb;hpb=2f2703c9133032c12671ca5c77ae626b8fb178d4 diff --git a/include/misc.h b/include/misc.h index 2a16e51..435314c 100644 --- a/include/misc.h +++ b/include/misc.h @@ -1,32 +1,35 @@ /* + $Id$ + G N O K I I A Linux/Unix toolset and driver for Nokia mobile phones. + Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml. + Released under the terms of the GNU GPL, see file COPYING for more details. Header file for miscellaneous defines, typedefs etc. -*/ + $Log$ + Revision 1.1.1.4 2002/04/03 00:08:19 short + Found in "gnokii-working" directory, some November-patches version -#ifndef __misc_h -#define __misc_h + Revision 1.25 2001/07/03 15:27:14 pkot + AT commands for SMS handling support (Tamas Bondar) + Small at-emulator code cleanup (me) -#include -#include + Revision 1.24 2001/06/28 00:28:46 pkot + Small docs updates (Pawel Kot) -#ifndef VC6 - #include "config.h" - /* Use gsprintf instead of sprintf and sprintf */ - #ifdef HAVE_SNPRINTF - # define gsprintf(a, b, c...) snprintf(a, b, c) - #else - # define gsprintf(a, b, c...) sprintf(a, c) - #endif +*/ -#endif +#ifndef __misc_h +#define __misc_h + +#include /* Some general defines. */ @@ -42,20 +45,70 @@ #define bool int #endif -/* This one is for NLS. */ +#define ARRAY_LEN(x) (sizeof((x))/sizeof((x)[0])) -#ifdef USE_NLS +#define SAFE_STRNCPY(dest,src,n) do { \ + strncpy((dest),(src),(n)); \ + if ((n)>0) \ + (dest)[(n)-1]='\0'; \ + } while (0) - #ifndef VC6 - #include - #define _(x) gettext(x) - #else - #define _(x) (x) - #endif +#define SAFE_STRNCPY_SIZEOF(dest,src) \ + SAFE_STRNCPY((dest),(src),sizeof((dest))) + +/* Stolen from : */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((format (printf, format_idx, arg_idx))) +#else /* !__GNUC__ */ +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif /* !__GNUC__ */ + +#define GNOKII_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define GNOKII_MIN(a, b) (((a) < (b)) ? (a) : (b)) + +/* A define to make debug printfs neat */ +#ifndef DEBUG +#define dprintf(a...) do { } while (0) +#else +#define dprintf(a...) do { fprintf(stderr, a); fflush(stderr); } while (0) +#endif +/* Use gsprintf instead of sprintf and sprintf */ +#ifdef HAVE_SNPRINTF +# define gsprintf(a, b, c...) snprintf(a, b, c) +#else +# define gsprintf(a, b, c...) sprintf(a, c) +#endif +#ifdef HAVE_VSNPRINTF +# define gvsprintf(a, b, c...) vsnprintf(a, b, c) +#else +# define gvsprintf(a, b, c...) vsprintf(a, c) +#endif +#ifdef HAVE_ASPRINTF +# define gasprintf(a...) asprintf(a) +#else +#include +extern int gasprintf(char **destp,const char *fmt,...); +#endif +#ifdef HAVE_VASPRINTF +# define gvasprintf(a...) vasprintf(a) +#else +#include +extern int gvasprintf(char **destp,const char *fmt,va_list ap); +#endif + +/* Get rid of long defines. Use #if __unices__ */ +#define __unices__ defined(__svr4__) || defined(__FreeBSD__) || defined(__bsdi__) + +/* This one is for NLS. */ +#ifdef USE_NLS + #include + #define _(x) gettext(x) #else #define _(x) (x) #endif /* USE_NLS */ +#define N_(x) (x) /* Definitions for u8, u16, u32 and u64, borrowed from /usr/src/linux/include/asm-i38/types.h */ @@ -97,6 +150,22 @@ /* Add here any timer operations which are not supported by libc5 */ #ifndef HAVE_TIMEOPS +#ifdef WIN32 + +#include +#include +#define timersub(a, b, result) + do { + (result)->tv_sec = (a)->time - (b)->time; + (result)->tv_usec = ((a)->millitm - (b)->millitm) * 1000; + if ((result)->tv_usec < 0) { + --(result)->tv_sec; + (result)->tv_usec += 1000000; + } + } while (0) +#define gettimeofday(a, b) _ftime(a) + +#else #include #ifndef timersub @@ -111,15 +180,33 @@ } while (0) #endif +#endif /* WIN32 */ #endif /* HAVE_TIMEOPS */ -#include +#include extern int GetLine(FILE *File, char *Line, int count); -int mem_to_int(const char str[], int len); - -void hexdump(u16 MessageLength, u8 *MessageBuffer); -void txhexdump(u16 MessageLength, u8 *MessageBuffer); +/* For models table */ +typedef struct { + char *model; + char *number; + int flags; +} PhoneModel; + +#define PM_CALLERGROUP 0x0001 +#define PM_NETMONITOR 0x0002 +#define PM_KEYBOARD 0x0004 +#define PM_SMS 0x0008 +#define PM_CALENDAR 0x0010 +#define PM_DTMF 0x0020 +#define PM_DATA 0x0040 +#define PM_SPEEDDIAL 0x0080 +#define PM_EXTPBK 0x0100 +#define PM_AUTHENTICATION 0x0200 + +extern char *GetModel (const char *); +extern PhoneModel *GetPhoneModel (const char *); #endif /* __misc_h */ +