:pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
authorshort <>
Tue, 27 Nov 2001 04:19:40 +0000 (04:19 +0000)
committershort <>
Tue, 27 Nov 2001 04:19:40 +0000 (04:19 +0000)
common/misc.c
common/phones/atgen.c
configure.in
include/misc.h

index d9c57ad..9ab975f 100644 (file)
   $Id$
   
   $Log$
   $Id$
   
   $Log$
-  Revision 1.1.1.1  2001/11/25 21:59:04  short
-  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+  Revision 1.1.1.2  2001/11/27 04:19:24  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
+
+  Revision 1.20  2001/11/26 18:06:08  pkot
+  Checking for *printf functions, N_(x) for localization, generic ARRAY_LEN, SAFE_STRNCPY, G_GNUC_PRINTF (Jan Kratochvil)
 
   Revision 1.19  2001/11/22 17:56:53  pkot
   smslib update. sms sending
 
   Revision 1.19  2001/11/22 17:56:53  pkot
   smslib update. sms sending
@@ -46,6 +49,7 @@
 */
 
 #include <string.h>
 */
 
 #include <string.h>
+#include <stdlib.h>
 #include "misc.h"
 
 int GetLine(FILE *File, char *Line, int count)
 #include "misc.h"
 
 int GetLine(FILE *File, char *Line, int count)
@@ -55,8 +59,8 @@ int GetLine(FILE *File, char *Line, int count)
        if (fgets(Line, count, File)) {
                ptr = Line + strlen(Line) - 1;
 
        if (fgets(Line, count, File)) {
                ptr = Line + strlen(Line) - 1;
 
-               while ( (*ptr == '\n' || *ptr == '\r') && ptr>=Line)
-                       *ptr--='\0';
+               while ( (*ptr == '\n' || *ptr == '\r') && ptr >= Line)
+                       *ptr-- = '\0';
 
                return strlen(Line);
        }
 
                return strlen(Line);
        }
@@ -126,4 +130,49 @@ inline char *GetModel (const char *num)
        return (GetPhoneModel(num)->model);
 }
 
        return (GetPhoneModel(num)->model);
 }
 
+#ifndef HAVE_VASPRINTF
+/* Adapted from snprintf(3) man page: */
+int gvasprintf(char **destp, const char *fmt, va_list ap)
+{
+       int n, size = 0x100;
+       char *p, *pnew;
 
 
+       if (!(p = malloc(size))) {
+               *destp = NULL;
+               return(-1);
+       }
+       for (;;) {
+               /* Try to print in the allocated space. */
+               n = gvsprintf(p, size, fmt, ap);
+               /* If that worked, return the string. */
+               if (n > -1 && n < size) {
+                       *destp = p;
+                       return(n);
+               }
+               /* Else try again with more space. */
+               if (n > -1)     /* glibc 2.1 */
+                       size = n + 1;   /* precisely what is needed */
+               else            /* glibc 2.0 */
+                       size *= 2;      /* twice the old size */
+               if (!(pnew = realloc(p, size))) {
+                       free(p);
+                       *destp = NULL;
+                       return(-1);
+               }
+               p = pnew;
+       }
+}
+#endif
+
+#ifndef HAVE_ASPRINTF
+int gasprintf(char **destp, const char *fmt,...)
+{
+       va_list ap;
+       int r;
+
+       va_start(ap,fmt);
+       r = gvasprintf(destp, fmt, ap);
+       va_end(ap);
+       return(r);
+}
+#endif
index fb1da2e..ed6c0fe 100644 (file)
   phones. See README for more details on supported mobile phones.
 
   $Log$
   phones. See README for more details on supported mobile phones.
 
   $Log$
-  Revision 1.1.1.1  2001/11/25 21:59:11  short
-  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+  Revision 1.1.1.2  2001/11/27 04:19:30  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
+
+  Revision 1.7  2001/11/26 18:06:08  pkot
+  Checking for *printf functions, N_(x) for localization, generic ARRAY_LEN, SAFE_STRNCPY, G_GNUC_PRINTF (Jan Kratochvil)
 
   Revision 1.6  2001/11/19 13:03:18  pkot
   nk3110.c cleanup
 
   Revision 1.6  2001/11/19 13:03:18  pkot
   nk3110.c cleanup
@@ -54,9 +57,6 @@
 #include "links/cbus.h"
 
 
 #include "links/cbus.h"
 
 
-#define ARRAY_LEN(x) (sizeof((x))/sizeof((x)[0]))
-
-
 static GSM_Error Initialise(GSM_Data *setupdata, GSM_Statemachine *state);
 static GSM_Error Functions(GSM_Operation op, GSM_Data *data, GSM_Statemachine *state);
 static GSM_Error Reply(int messagetype, unsigned char *buffer, int length, GSM_Data *data);
 static GSM_Error Initialise(GSM_Data *setupdata, GSM_Statemachine *state);
 static GSM_Error Functions(GSM_Operation op, GSM_Data *data, GSM_Statemachine *state);
 static GSM_Error Reply(int messagetype, unsigned char *buffer, int length, GSM_Data *data);
index 3670353..0a30589 100644 (file)
@@ -32,7 +32,9 @@ test x"$prefix" = xNONE && prefix="$ac_default_prefix"
 
 AC_ARG_ENABLE(debug, 
        [  --enable-debug          compile with debug code],
 
 AC_ARG_ENABLE(debug, 
        [  --enable-debug          compile with debug code],
-       [ CFLAGS="-g -Wall"
+       [ if test "x$GCC" = "xyes"; then
+               CFLAGS="-ggdb3 -Wall"
+         fi
          AC_DEFINE(DEBUG)
          debug="yes" ],
        [ debug="no"  ]
          AC_DEFINE(DEBUG)
          debug="yes" ],
        [ debug="no"  ]
@@ -437,7 +439,7 @@ AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MEMCMP
 AC_TYPE_SIGNAL
 AC_FUNC_STRFTIME
 AC_FUNC_MEMCMP
 AC_TYPE_SIGNAL
 AC_FUNC_STRFTIME
-AC_CHECK_FUNCS(mktime select strdup strstr strtol strtok strsep snprintf)
+AC_CHECK_FUNCS(mktime select strdup strstr strtol strtok strsep snprintf vsnprintf asprintf vasprintf)
 
 CFLAGS="$CFLAGS $NLS_CFLAGS"
 LIBS="$LIBS $NLS_LIBS"
 
 CFLAGS="$CFLAGS $NLS_CFLAGS"
 LIBS="$LIBS $NLS_LIBS"
index 3e91ff0..2110b15 100644 (file)
   Header file for miscellaneous defines, typedefs etc.
 
   $Log$
   Header file for miscellaneous defines, typedefs etc.
 
   $Log$
-  Revision 1.1.1.1  2001/11/25 21:59:21  short
-  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+  Revision 1.1.1.2  2001/11/27 04:19:40  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
+
+  Revision 1.27  2001/11/26 18:06:08  pkot
+  Checking for *printf functions, N_(x) for localization, generic ARRAY_LEN, SAFE_STRNCPY, G_GNUC_PRINTF (Jan Kratochvil)
 
   Revision 1.26  2001/11/14 10:46:12  pkot
   Small cleanup with __unices__
 
   Revision 1.26  2001/11/14 10:46:12  pkot
   Small cleanup with __unices__
 /* Some general defines. */
 
 #ifndef false
 /* Some general defines. */
 
 #ifndef false
-  #define false (0)
+#  define false (0)
 #endif
 
 #ifndef true
 #endif
 
 #ifndef true
-  #define true (!false)
+#  define true (!false)
 #endif
 
 #ifndef bool    
 #endif
 
 #ifndef bool    
-  #define bool int
+#  define bool int
 #endif
 
 #endif
 
+#define ARRAY_LEN(x) (sizeof((x)) / sizeof((x)[0]))
+
+#define SAFE_STRNCPY(dest, src, n) do { \
+       strncpy((dest), (src), (n)); \
+       if ((n) > 0) \
+               (dest)[(n)-1] = '\0'; \
+       } while (0)
+
+#define SAFE_STRNCPY_SIZEOF(dest,src) \
+       SAFE_STRNCPY((dest), (src), sizeof((dest)))
+
+/* Stolen from <glib.h>: */
+#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
 /* A define to make debug printfs neat */
 #ifndef DEBUG
-#define dprintf(a...) do { } while (0)
+#  define dprintf(a...) do { } while (0)
 #else
 #else
-#define dprintf(a...) do { fprintf(stderr, a); fflush(stderr); } while (0) 
+#  define dprintf(a...) do { fprintf(stderr, a); fflush(stderr); } while (0) 
 #endif
 
 /* Use gsprintf instead of sprintf and sprintf */
 #ifdef HAVE_SNPRINTF
 #endif
 
 /* Use gsprintf instead of sprintf and sprintf */
 #ifdef HAVE_SNPRINTF
-# define gsprintf(a, b, c...) snprintf(a, b, c)
+#  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
 #else
-# define gsprintf(a, b, c...) sprintf(a, c)
+#  define gvsprintf(a, b, c...) vsprintf(a, c)
+#endif
+#ifdef HAVE_ASPRINTF
+#  define gasprintf(a...) asprintf(a)
+#else
+#include <stdarg.h>
+extern int gasprintf(char **destp, const char *fmt,...);
+#endif
+#ifdef HAVE_VASPRINTF
+#  define gvasprintf(a...) vasprintf(a)
+#else
+#include <stdarg.h>
+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__)
 #if __unices__
 #endif
 
 /* Get rid of long defines. Use #if __unices__ */
 #define __unices__ defined(__svr4__) || defined(__FreeBSD__) || defined(__bsdi__)
 #if __unices__
-# include <strings.h>
-# include <sys/file.h>
+#  include <strings.h>
+#  include <sys/file.h>
 #endif
 
 /* This one is for NLS. */
 #ifdef USE_NLS
 #endif
 
 /* This one is for NLS. */
 #ifdef USE_NLS
-  #include <libintl.h>
-  #define _(x) gettext(x)
+#  include <libintl.h>
+#  define _(x) gettext(x)
+#  define N_(x) gettext_noop(x)
 #else
 #else
-  #define _(x) (x)
+#  define _(x) (x)
+#  define N_(x) (x)
 #endif /* USE_NLS */
 
 /* Definitions for u8, u16, u32 and u64, borrowed from
    /usr/src/linux/include/asm-i38/types.h */
 
 #ifndef u8
 #endif /* USE_NLS */
 
 /* Definitions for u8, u16, u32 and u64, borrowed from
    /usr/src/linux/include/asm-i38/types.h */
 
 #ifndef u8
-  typedef unsigned char u8;
+       typedef unsigned char u8;
 #endif
 
 #ifndef u16
 #endif
 
 #ifndef u16
-  typedef unsigned short u16;
+       typedef unsigned short u16;
 #endif
 
 #ifndef u32
 #endif
 
 #ifndef u32
-  typedef unsigned int u32;
+       typedef unsigned int u32;
 #endif
 
 #ifndef s32
 #endif
 
 #ifndef s32
-  typedef int s32;
+       typedef int s32;
 #endif
 
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 #endif
 
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-  #ifndef u64
-    typedef unsigned long long u64;
-  #endif
+#  ifndef u64
+       typedef unsigned long long u64;
+#  endif
 
 
-  #ifndef s64
-    typedef signed long long s64;
-  #endif
+#  ifndef s64
+       typedef signed long long s64;
+#  endif
 #endif 
 
 /* This one is for FreeBSD and similar systems without __ptr_t_ */
 /* FIXME: autoconf should take care of this. */
 #endif 
 
 /* This one is for FreeBSD and similar systems without __ptr_t_ */
 /* FIXME: autoconf should take care of this. */
-
 #ifndef __ptr_t
 #ifndef __ptr_t
-  typedef void * __ptr_t;
+       typedef void * __ptr_t;
 #endif /* __ptr_t */
 
 
 /* Add here any timer operations which are not supported by libc5 */
 
 #ifndef HAVE_TIMEOPS
 #endif /* __ptr_t */
 
 
 /* Add here any timer operations which are not supported by libc5 */
 
 #ifndef HAVE_TIMEOPS
-#ifdef WIN32
-
-#include <windows.h>
-#include <sys/timeb.h>
-#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 <sys/time.h>
-
-#ifndef timersub
-#define timersub(a, b, result)                                                \
-  do {                                                                        \
-    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
-    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
-    if ((result)->tv_usec < 0) {                                              \
-      --(result)->tv_sec;                                                     \
-      (result)->tv_usec += 1000000;                                           \
-    }                                                                         \
-  } while (0)
-#endif
-
-#endif /* WIN32 */
+#  ifdef WIN32
+
+#    include <windows.h>
+#    include <sys/timeb.h>
+#    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 /* !WIN32 */
+#    include <sys/time.h>
+
+#    ifndef timersub
+#      define timersub(a, b, result)                               \
+       do {                                                       \
+               (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;      \
+               (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;   \
+               if ((result)->tv_usec < 0) {                       \
+                       --(result)->tv_sec;                        \
+                       (result)->tv_usec += 1000000;              \
+               }                                                  \
+       } while (0)
+#    endif /* timersub */
+
+#  endif /* WIN32 */
 #endif /* HAVE_TIMEOPS */
 
 
 #endif /* HAVE_TIMEOPS */
 
 
@@ -156,9 +199,9 @@ extern int GetLine(FILE *File, char *Line, int count);
 
 /* For models table */
 typedef struct {
 
 /* For models table */
 typedef struct {
-  char *model;
-  char *number;
-  int flags;
+       char *model;
+       char *number;
+       int flags;
 } PhoneModel;
 
 #define PM_CALLERGROUP   0x0001
 } PhoneModel;
 
 #define PM_CALLERGROUP   0x0001