gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20305 - in monkey/branches/MonkeyBacktracking/monkey: . sr


From: gnunet
Subject: [GNUnet-SVN] r20305 - in monkey/branches/MonkeyBacktracking/monkey: . src src/include src/monkey src/util
Date: Tue, 6 Mar 2012 12:42:54 +0100

Author: safey
Date: 2012-03-06 12:42:54 +0100 (Tue, 06 Mar 2012)
New Revision: 20305

Added:
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.sh
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_data.conf
   monkey/branches/MonkeyBacktracking/monkey/src/util/
   monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am
   monkey/branches/MonkeyBacktracking/monkey/src/util/common_allocation.c
Removed:
   monkey/branches/MonkeyBacktracking/monkey/src/include/gettext.h
   monkey/branches/MonkeyBacktracking/monkey/src/include/platform.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-service-monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.sh
   
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey_data.conf
Modified:
   monkey/branches/MonkeyBacktracking/monkey/configure.ac
   monkey/branches/MonkeyBacktracking/monkey/src/Makefile.am
   monkey/branches/MonkeyBacktracking/monkey/src/include/Makefile.am
   monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/Makefile.am
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/edb_api.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_connect.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_edb.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c
Log:
Refactoring Fest.
Fixing Expression ordering in xml report.
monkey.c disconnected from GNUnet.


Modified: monkey/branches/MonkeyBacktracking/monkey/configure.ac
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/configure.ac      2012-03-06 
11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/configure.ac      2012-03-06 
11:42:54 UTC (rev 20305)
@@ -215,5 +215,6 @@
 Makefile
 src/Makefile
 src/include/Makefile
+src/util/Makefile
 src/monkey/Makefile
 ])

Modified: monkey/branches/MonkeyBacktracking/monkey/src/Makefile.am
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/Makefile.am   2012-03-06 
11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/Makefile.am   2012-03-06 
11:42:54 UTC (rev 20305)
@@ -1,2 +1,2 @@
-SUBDIRS = include monkey .
+SUBDIRS = include util monkey .
 

Modified: monkey/branches/MonkeyBacktracking/monkey/src/include/Makefile.am
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/include/Makefile.am   
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/include/Makefile.am   
2012-03-06 11:42:54 UTC (rev 20305)
@@ -3,6 +3,5 @@
 monkeyincludedir = $(includedir)/monkey
 
 monkeyinclude_HEADERS = \
-  gettext.h \
-  plibc.h \
-  platform.h
+  monkey_common.h \
+  plibc.h

Deleted: monkey/branches/MonkeyBacktracking/monkey/src/include/gettext.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/include/gettext.h     
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/include/gettext.h     
2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,71 +0,0 @@
-/* Convenience header for conditional use of GNU <libintl.h>.
-   Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Library General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-   USA.  */
-
-#ifndef _LIBGETTEXT_H
-#define _LIBGETTEXT_H 1
-
-/* NLS can be disabled through the configure --disable-nls option.  */
-#if ENABLE_NLS
-
-/* Get declarations of GNU message catalog functions.  */
-#include <libintl.h>
-
-#else
-
-/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
-   chokes if dcgettext is defined as a macro.  So include it now, to make
-   later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
-   as well because people using "gettext.h" will not include <libintl.h>,
-   and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
-   is GNUNET_OK.  */
-#if defined(__sun)
-#include <locale.h>
-#endif
-
-/* Disabled NLS.
-   The casts to 'const char *' serve the purpose of producing warnings
-   for invalid uses of the value returned from these functions.
-   On pre-ANSI systems without 'const', the config.h file is supposed to
-   contain "#define const".  */
-#define gettext(Msgid) ((const char *) (Msgid))
-#define dgettext(Domainname, Msgid) ((const char *) (Msgid))
-#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
-#define ngettext(Msgid1, Msgid2, N) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-#define dngettext(Domainname, Msgid1, Msgid2, N) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-/* slight modification here to avoid warnings: generate GNUNET_NO code,
-   not even the cast... */
-#define textdomain(Domainname)
-#define bindtextdomain(Domainname, Dirname)
-#define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
-
-#endif
-
-/* A pseudo function call that serves as a marker for the automated
-   extraction of messages, but does not call gettext().  The run-time
-   translation is done at a different place in the code.
-   The argument, String, should be a literal string.  Concatenated strings
-   and other string expressions won't work.
-   The macro's expansion is not parenthesized, so that it is suitable as
-   initializer for static 'char[]' or 'const char[]' variables.  */
-#define gettext_noop(String) String
-
-#endif /* _LIBGETTEXT_H */

Modified: monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h       
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h       
2012-03-06 11:42:54 UTC (rev 20305)
@@ -162,4 +162,273 @@
 
 #define MONKEY_MAX(a,b) (((a) > (b)) ? (a) : (b))
 
+/* ************************* allocation functions ****************** */
+
+/**
+ * Maximum allocation with MONKEY_malloc macro.
+ */
+#define MONKEY_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
+
+/**
+ * Wrapper around malloc. Allocates size bytes of memory.
+ * The memory will be zero'ed out.
+ *
+ * @param size the number of bytes to allocate, must be
+ *        smaller than 40 MB.
+ * @return pointer to size bytes of memory, never NULL (!)
+ */
+#define MONKEY_malloc(size) MONKEY_xmalloc_(size, __FILE__, __LINE__)
+
+/**
+ * Allocate and initialize a block of memory.
+ *
+ * @param buf data to initalize the block with
+ * @param size the number of bytes in buf (and size of the allocation)
+ * @return pointer to size bytes of memory, never NULL (!)
+ */
+#define MONKEY_memdup(buf,size) MONKEY_xmemdup_(buf, size, __FILE__, __LINE__)
+
+/**
+ * Wrapper around malloc. Allocates size bytes of memory.
+ * The memory will be zero'ed out.
+ *
+ * @param size the number of bytes to allocate
+ * @return pointer to size bytes of memory, NULL if we do not have enough 
memory
+ */
+#define MONKEY_malloc_large(size) MONKEY_xmalloc_unchecked_(size, __FILE__, 
__LINE__)
+
+/**
+ * Wrapper around realloc. Rellocates size bytes of memory.
+ *
+ * @param ptr the pointer to reallocate
+ * @param size the number of bytes to reallocate
+ * @return pointer to size bytes of memory
+ */
+#define MONKEY_realloc(ptr, size) MONKEY_xrealloc_(ptr, size, __FILE__, 
__LINE__)
+
+/**
+ * Wrapper around free. Frees the memory referred to by ptr.
+ * Note that is is generally better to free memory that was
+ * allocated with MONKEY_array_grow using MONKEY_array_grow(mem, size, 0) 
instead of MONKEY_free.
+ *
+ * @param ptr location where to free the memory. ptr must have
+ *     been returned by MONKEY_strdup, MONKEY_strndup, MONKEY_malloc or 
MONKEY_array_grow earlier.
+ */
+#define MONKEY_free(ptr) MONKEY_xfree_(ptr, __FILE__, __LINE__)
+
+/**
+ * Free the memory pointed to by ptr if ptr is not NULL.
+ * Equivalent to if (ptr!=null)MONKEY_free(ptr).
+ *
+ * @param ptr the location in memory to free
+ */
+#define MONKEY_free_non_null(ptr) do { void * __x__ = ptr; if (__x__ != NULL) 
{ MONKEY_free(__x__); } } while(0)
+
+/**
+ * Wrapper around MONKEY_strdup.  Makes a copy of the zero-terminated string
+ * pointed to by a.
+ *
+ * @param a pointer to a zero-terminated string
+ * @return a copy of the string including zero-termination
+ */
+#define MONKEY_strdup(a) MONKEY_xstrdup_(a,__FILE__,__LINE__)
+
+/**
+ * Wrapper around MONKEY_strndup.  Makes a partial copy of the string
+ * pointed to by a.
+ *
+ * @param a pointer to a string
+ * @param length of the string to duplicate
+ * @return a partial copy of the string including zero-termination
+ */
+#define MONKEY_strndup(a,length) MONKEY_xstrndup_(a,length,__FILE__,__LINE__)
+
+/**
+ * Grow a well-typed (!) array.  This is a convenience
+ * method to grow a vector <tt>arr</tt> of size <tt>size</tt>
+ * to the new (target) size <tt>tsize</tt>.
+ * <p>
+ *
+ * Example (simple, well-typed stack):
+ *
+ * <pre>
+ * static struct foo * myVector = NULL;
+ * static int myVecLen = 0;
+ *
+ * static void push(struct foo * elem) {
+ *   MONKEY_array_grow(myVector, myVecLen, myVecLen+1);
+ *   memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo));
+ * }
+ *
+ * static void pop(struct foo * elem) {
+ *   if (myVecLen == 0) die();
+ *   memcpy(elem, myVector[myVecLen-1], sizeof(struct foo));
+ *   MONKEY_array_grow(myVector, myVecLen, myVecLen-1);
+ * }
+ * </pre>
+ *
+ * @param arr base-pointer of the vector, may be NULL if size is 0;
+ *        will be updated to reflect the new address. The TYPE of
+ *        arr is important since size is the number of elements and
+ *        not the size in bytes
+ * @param size the number of elements in the existing vector (number
+ *        of elements to copy over)
+ * @param tsize the target size for the resulting vector, use 0 to
+ *        free the vector (then, arr will be NULL afterwards).
+ */
+#define MONKEY_array_grow(arr,size,tsize) MONKEY_xgrow_((void**)&arr, 
sizeof(arr[0]), &size, tsize, __FILE__, __LINE__)
+
+/**
+ * Append an element to a list (growing the
+ * list by one).
+ */
+#define MONKEY_array_append(arr,size,element) do { 
MONKEY_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
+
+/**
+ * Like snprintf, just aborts if the buffer is of insufficient size.
+ *
+ * @param buf pointer to buffer that is written to
+ * @param size number of bytes in buf
+ * @param format format strings
+ * @param ... data for format string
+ * @return number of bytes written to buf or negative value on error
+ */
+int
+MONKEY_snprintf (char *buf, size_t size, const char *format, ...);
+
+
+/**
+ * Like asprintf, just portable.
+ *
+ * @param buf set to a buffer of sufficient size (allocated, caller must free)
+ * @param format format string (see printf, fprintf, etc.)
+ * @param ... data for format string
+ * @return number of bytes in "*buf" excluding 0-termination
+ */
+int
+MONKEY_asprintf (char **buf, const char *format, ...);
+
+
+/* ************** internal implementations, use macros above! ************** */
+
+/**
+ * Allocate memory. Checks the return value, aborts if no more
+ * memory is available.  Don't use MONKEY_xmalloc_ directly. Use the
+ * MONKEY_malloc macro.
+ * The memory will be zero'ed out.
+ *
+ * @param size number of bytes to allocate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return allocated memory, never NULL
+ */
+void *
+MONKEY_xmalloc_ (size_t size, const char *filename, int linenumber);
+
+
+
+/**
+ * Allocate and initialize memory. Checks the return value, aborts if no more
+ * memory is available.  Don't use MONKEY_xmemdup_ directly. Use the
+ * MONKEY_memdup macro.
+ *
+ * @param buf buffer to initialize from (must contain size bytes)
+ * @param size number of bytes to allocate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return allocated memory, never NULL
+ */
+void *
+MONKEY_xmemdup_ (const void *buf, size_t size, const char *filename,
+                 int linenumber);
+
+
+/**
+ * Allocate memory.  This function does not check if the allocation
+ * request is within reasonable bounds, allowing allocations larger
+ * than 40 MB.  If you don't expect the possibility of very large
+ * allocations, use MONKEY_malloc instead.  The memory will be zero'ed
+ * out.
+ *
+ * @param size number of bytes to allocate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return pointer to size bytes of memory, NULL if we do not have enough 
memory
+ */
+void *
+MONKEY_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
+
+/**
+ * Reallocate memory. Checks the return value, aborts if no more
+ * memory is available.
+ */
+void *
+MONKEY_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
+
+/**
+ * Free memory. Merely a wrapper for the case that we
+ * want to keep track of allocations.  Don't use MONKEY_xfree_
+ * directly. Use the MONKEY_free macro.
+ *
+ * @param ptr pointer to memory to free
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ */
+void
+MONKEY_xfree_ (void *ptr, const char *filename, int linenumber);
+
+
+/**
+ * Dup a string. Don't call MONKEY_xstrdup_ directly. Use the MONKEY_strdup 
macro.
+ * @param str string to duplicate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return the duplicated string
+ */
+char *
+MONKEY_xstrdup_ (const char *str, const char *filename, int linenumber);
+
+/**
+ * Dup partially a string. Don't call MONKEY_xstrndup_ directly. Use the 
MONKEY_strndup macro.
+ *
+ * @param str string to duplicate
+ * @param len length of the string to duplicate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return the duplicated string
+ */
+char *
+MONKEY_xstrndup_ (const char *str, size_t len, const char *filename,
+                  int linenumber);
+
+/**
+ * Grow an array, the new elements are zeroed out.
+ * Grows old by (*oldCount-newCount)*elementSize
+ * bytes and sets *oldCount to newCount.
+ *
+ * Don't call MONKEY_xgrow_ directly. Use the MONKEY_array_grow macro.
+ *
+ * @param old address of the pointer to the array
+ *        *old may be NULL
+ * @param elementSize the size of the elements of the array
+ * @param oldCount address of the number of elements in the *old array
+ * @param newCount number of elements in the new array, may be 0 (then *old 
will be NULL afterwards)
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ */
+void
+MONKEY_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
+               unsigned int newCount, const char *filename, int linenumber);
+
+
+
+
+#if __STDC_VERSION__ < 199901L
+#if __GNUC__ >= 2
+#define __func__ __FUNCTION__
+#else
+#define __func__ "<unknown>"
+#endif
+#endif
+
 #endif /* MONKEY_COMMON_H */

Deleted: monkey/branches/MonkeyBacktracking/monkey/src/include/platform.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/include/platform.h    
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/include/platform.h    
2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,250 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff 
(and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file include/platform.h
- * @brief plaform specifics
- *
- * @author Nils Durner
- *
- * This file should never be included by installed
- * header files (thos starting with "gnunet_").
- */
-
-#ifndef PLATFORM_H
-#define PLATFORM_H
-
-#ifndef HAVE_USED_CONFIG_H
-#define HAVE_USED_CONFIG_H
-#if HAVE_CONFIG_H
-#include "monkey_config.h"
-#endif
-#endif
-
-#ifdef WINDOWS
-#define BREAKPOINT asm("int $3;");
-#define GNUNET_SIGCHLD 17
-#else
-#define BREAKPOINT
-#define GNUNET_SIGCHLD SIGCHLD
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#define ALLOW_EXTRA_CHECKS GNUNET_NO
-
-/**
- * For strptime (glibc2 needs this).
- */
-#ifndef _XOPEN_SOURCE
-#define _XOPEN_SOURCE
-#endif
-
-#ifndef _REENTRANT
-#define _REENTRANT
-#endif
-
-/* configuration options */
-
-#define VERBOSE_STATS 0
-
-#ifdef CYGWIN
-#include <sys/reent.h>
-#define _REENT_ONLY
-#endif
-
-#ifdef CYGWIN
-#undef _REENT_ONLY
-#endif
-
-#ifdef _MSC_VER
-#include <Winsock2.h>
-#include <ws2tcpip.h>
-#else
-#ifndef MINGW
-#include <netdb.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-#include <netinet/ip.h> /* superset of previous */
-#include <arpa/inet.h>
-#include <netinet/tcp.h>
-#include <pwd.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <grp.h>
-#else
-#include "winproc.h"
-#endif
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <signal.h>
-#ifdef WINDOWS
-#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
-#endif
-#ifndef _MSC_VER
-#include <unistd.h>             /* KLB_FIX */
-#endif
-#include <sys/stat.h>
-#include <sys/types.h>
-#ifndef _MSC_VER
-#include <dirent.h>             /* KLB_FIX */
-#endif
-#include <fcntl.h>
-#include <math.h>
-#if HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#if TIME_WITH_SYS_TIME
-#include <sys/time.h>
-#include <time.h>
-#else
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-#endif
-
-#ifdef SOMEBSD
-#include <net/if.h>
-#endif
-#ifdef GNUNET_freeBSD
-#include <semaphore.h>
-#endif
-#ifdef DARWIN
-#include <dlfcn.h>
-#include <semaphore.h>
-#include <net/if.h>
-#endif
-#ifdef LINUX
-#include <net/if.h>
-#endif
-#ifdef SOLARIS
-#include <sys/sockio.h>
-#include <sys/filio.h>
-#include <sys/loadavg.h>
-#include <semaphore.h>
-#endif
-#if HAVE_UCRED_H
-#include <ucred.h>
-#endif
-#ifdef CYGWIN
-#include <windows.h>
-#include <cygwin/if.h>
-#endif
-#if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#endif
-#include <errno.h>
-#include <limits.h>
-
-#if HAVE_VFORK_H
-#include <vfork.h>
-#endif
-
-#include <ctype.h>
-#if HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
-#if HAVE_ENDIAN_H
-#include <endian.h>
-#endif
-#if HAVE_SYS_ENDIAN_H
-#include <sys/endian.h>
-#endif
-
-#include "plibc.h"
-
-#include <locale.h>
-#ifndef FRAMEWORK_BUILD
-#include "gettext.h"
-/**
- * GNU gettext support macro.
- */
-#define _(String) dgettext("gnunet",String)
-#define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
-#else
-#include "libintlemu.h"
-#define _(String) dgettext("org.gnunet.gnunet",String)
-#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
-#endif
-
-#ifdef CYGWIN
-#define SIOCGIFCONF     _IOW('s', 100, struct ifconf)   /* get if list */
-#define SIOCGIFFLAGS    _IOW('s', 101, struct ifreq)    /* Get if flags */
-#define SIOCGIFADDR     _IOW('s', 102, struct ifreq)    /* Get if addr */
-#endif
-
-#ifndef MINGW
-#include <sys/mman.h>
-#endif
-
-#ifdef FREEBSD
-#define __BYTE_ORDER BYTE_ORDER
-#define __BIG_ENDIAN BIG_ENDIAN
-#endif
-
-#ifdef DARWIN
-#define __BYTE_ORDER BYTE_ORDER
-#define __BIG_ENDIAN BIG_ENDIAN
- /* not available on darwin, override configure */
-#undef HAVE_STAT64
-#undef HAVE_MREMAP
-#endif
-
-
-#if !HAVE_ATOLL
-long long atoll (const char *nptr);
-#endif
-
-#if ENABLE_NLS
-#include "langinfo.h"
-#endif
-
-#ifndef SIZE_MAX
-#define SIZE_MAX ((size_t)(-1))
-#endif
-
-#ifndef O_LARGEFILE
-#define O_LARGEFILE 0
-#endif
-
-#if defined(__sparc__)
-#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, 
&(val), sizeof((val))); __tmp; })
-#else
-#define MAKE_UNALIGNED(val) val
-#endif
-
-#endif

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/Makefile.am
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/Makefile.am    
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/Makefile.am    
2012-03-06 11:42:54 UTC (rev 20305)
@@ -24,29 +24,28 @@
   monkey_edb.h
 
 libmonkeyedb_la_LIBADD = \
-  -lgnunetutil \
+  -lmonkeyutil \
   -lsqlite3 \
-  $(GN_LIBINTL) $(XLIB)  
+  $(XLIB)  
 
 libmonkeyaction_la_SOURCES = \
   action_api.c \
   monkey_action.h
 
 libmonkeyaction_la_LIBADD = \
-  -lgnunetutil \
-  $(GN_LIBINTL) $(XLIB)  
+  -lmonkeyutil \
+  $(XLIB)
 
 libmonkeyxml_la_LIBADD = \
-  -lgnunetutil \
-   $(GN_LIBINTL) $(XLIB)
+  -lmonkeyutil \
+  $(XLIB)
    
 libmonkeyxml_la_SOURCES = \
   xml_writer.c \
   monkey_xml_writer.h
   
 bin_PROGRAMS = \
- gnunet-monkey \
- gnunet-service-monkey \
+ monkey \
  bug_null_pointer_exception \
  bug_bad_memory_access \
  bug_assertion_failure \
@@ -60,7 +59,7 @@
  bug_crypto_crc \
  bug_division_by_zero_loop
 
-gnunet_monkey_SOURCES = \
+monkey_SOURCES = \
  gdbmi.h \
  gdbmi_alloc.c \
  gdbmi_breakpoint.c \
@@ -77,10 +76,10 @@
  gdbmi_target_man.c \
  gdbmi_thread.c \
  gdbmi_var_obj.c \
- gnunet-monkey.c \
+ monkey.c \
  mail_sender.c
 
-gnunet_monkey_LDADD = \
+monkey_LDADD = \
   -lgnunetutil \
   $(top_builddir)/src/monkey/libmonkeyedb.la \
   $(top_builddir)/src/monkey/libmonkeyaction.la \
@@ -89,13 +88,6 @@
   $(GN_LIBINTL)
 
 
-gnunet_service_monkey_SOURCES = \
- gnunet-service-monkey.c         
-gnunet_service_monkey_LDADD = \
-  -lgnunetutil \
-  $(GN_LIBINTL)
-
-
 bug_null_pointer_exception:
        gcc -g -O0 -o bug_null_pointer_exception bug_null_pointer_exception.c
 
@@ -113,7 +105,7 @@
 
 check_PROGRAMS = \
     test_monkey_edb
-    #test_gnunet_monkey        
+    #test_monkey       
 
 if ENABLE_TEST_RUN
 # TESTS = $(check_SCRIPTS)
@@ -123,22 +115,21 @@
 test_monkey_edb_SOURCES = \
   test_monkey_edb.c
 test_monkey_edb_LDADD = \
-  -lgnunetutil \
+  -lmonkeyutil \
   $(top_builddir)/src/monkey/libmonkeyedb.la
 
-#test_gnunet_monkey_SOURCES = \
- #test_gnunet_monkey.c
-#test_gnunet_monkey_LDADD = \
-  -lgnunetarm \
-  -lgnunetutil
+#test_monkey_SOURCES = \
+ #test_monkey.c
+#test_monkey_LDADD = \
+  -lmonkeyutil
 
 
 check_SCRIPTS = \
-  #test_gnunet_monkey.sh \
+  #test_monkey.sh \
   #test_monkey_npe.sh
 
 EXTRA_DIST = \
-  test_gnunet_monkey_data.conf \
+  test_monkey_data.conf \
   test.db \
   bug_null_pointer_exception.db
   

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-06 11:42:54 UTC (rev 20305)
@@ -176,7 +176,7 @@
                  /* Execution stopped because of hitting a watch point */
            static int watchPointHitNumber = 0;
            struct WatchInfo *watchInfo =
-             malloc (sizeof (struct WatchInfo));
+             MONKEY_malloc (sizeof (struct WatchInfo));
            watchInfo->hitNumber = ++watchPointHitNumber;
            watchInfo->value = cntxt->gdb_stop_reason->wp_val;
            MONKEY_CONTAINER_DLL_insert (watchInfoListHead, watchInfoListTail,
@@ -292,8 +292,8 @@
       printf ("%s\n", ext);
       if (strcmp (ext, ".c") == 0)
        {
-         fileName = malloc (sizeof (struct FileName));
-         fileName->name = strdup (token);
+         fileName = MONKEY_malloc (sizeof (struct FileName));
+         fileName->name = MONKEY_strdup (token);
          fileName->next = NULL;
          fileName->prev = NULL;
          MONKEY_CONTAINER_DLL_insert (fileNameListHead, fileNameListTail,
@@ -318,7 +318,7 @@
        if (NULL == colValues[0])
                return 1; /* Error */
 
-       struct ScopeEnd *scopeEnd = malloc(sizeof(struct ScopeEnd));
+       struct ScopeEnd *scopeEnd = MONKEY_malloc(sizeof(struct ScopeEnd));
        scopeEnd->lineNo = atoi(colValues[0]);
        MONKEY_CONTAINER_DLL_insert (scopeEndListHead, scopeEndListTail,
                                                 scopeEnd);
@@ -351,8 +351,8 @@
   if (NULL == colValues[0] || NULL == colValues[1])
     return 1;                  /* Error */
 
-  expression = malloc (sizeof (struct Expression));
-  expression->expressionSyntax = strdup (colValues[0]);
+  expression = MONKEY_malloc (sizeof (struct Expression));
+  expression->expressionSyntax = MONKEY_strdup (colValues[0]);
   expression->lineNo = atoi (colValues[1]);
   expression->expressionValue = NULL; expression->next = NULL; 
expression->prev = NULL;
 
@@ -490,10 +490,10 @@
                        expressionPtr = functionPtr->expressionListHead;
                        functionPtr->expressionListHead = 
functionPtr->expressionListHead->next;
 
-                       free(expressionPtr->expressionSyntax);
-                       free(expressionPtr);
+                       MONKEY_free((char *)expressionPtr->expressionSyntax);
+                       MONKEY_free(expressionPtr);
                }
-               free(functionPtr);
+               MONKEY_free(functionPtr);
        }
        return MONKEY_OK;
 }
@@ -533,7 +533,7 @@
   static struct MONKEY_EDB_Context *edbCntxt;
 
   if (NULL == trace) {
-         trace = malloc(sizeof(struct Trace));
+         trace = MONKEY_malloc(sizeof(struct Trace));
          trace->functionListHead = NULL;
          trace->functionListTail = NULL;
   }
@@ -583,13 +583,13 @@
 #endif
 
   /* Now we know the end scope of the faulty expression. We can build the 
function struct */
-  function = malloc(sizeof(struct Function));
+  function = MONKEY_malloc(sizeof(struct Function));
   function->depth = stackDepth++;
   function->line = cntxt->gdb_frames->line;
   function->name = cntxt->gdb_frames->func;
   function->file = cntxt->gdb_frames->file;
   function->expressionListHead = NULL; function->expressionListTail = NULL; 
function->next = NULL; function->prev = NULL;
-  MONKEY_CONTAINER_DLL_insert (trace->functionListHead, 
trace->functionListTail,
+  MONKEY_CONTAINER_DLL_insert_tail (trace->functionListHead, 
trace->functionListTail,
                                         function);
 
   if (strcasecmp (signalMeaning, "Segmentation fault") == 0)
@@ -662,21 +662,21 @@
   char *valgrindCommand;
   FILE *valgrindPipe;
 
-  asprintf (&cntxt->valgrind_output_tmp_file_name, "%d", rand ());
+  MONKEY_asprintf (&cntxt->valgrind_output_tmp_file_name, "%d", rand ());
   cntxt->debug_mode = DEBUG_MODE_VALGRIND;
-  asprintf (&valgrindCommand,
+  MONKEY_asprintf (&valgrindCommand,
                   "valgrind --leak-check=yes --log-file=%s %s",
                   cntxt->valgrind_output_tmp_file_name, cntxt->binary_name);
   valgrindPipe = popen (valgrindCommand, "r");
   if (NULL == valgrindPipe)
     {
       fprintf(stderr, "Error in running Valgrind!\n");
-      free (valgrindCommand);
+      MONKEY_free (valgrindCommand);
       return MONKEY_NO;
     }
 
   pclose (valgrindPipe);
-  free (valgrindCommand);
+  MONKEY_free (valgrindCommand);
   return MONKEY_OK;
 }
 
@@ -782,20 +782,20 @@
 static const char *
 expressionListToString (struct Expression *head)
 {
-  char *string = strdup ("");
+  char *string = MONKEY_strdup ("");
   char *strTmp;
   struct Expression *tmp;
 
   for (tmp = head; NULL != tmp;  tmp = tmp->next)
     {
-      asprintf (&strTmp,
+      MONKEY_asprintf (&strTmp,
                       "%s%s => %s\n",
                       string,
                       tmp->expressionSyntax,
                       NULL ==
                       tmp->expressionValue ? "Not evaluated" : tmp->
                       expressionValue);
-      free (string);
+      MONKEY_free (string);
       string = strTmp;
     }
   return string;
@@ -823,20 +823,20 @@
 static const char *
 watchInfoListToString (struct WatchInfo *head)
 {
-  char *string = malloc (getWatchInfoListSize (head));
+  char *string = MONKEY_malloc (getWatchInfoListSize (head));
   char *strTmp;
   struct WatchInfo *tmp = head;
 
-  asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
+  MONKEY_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
   strcpy (string, strTmp);
-  free (strTmp);
+  MONKEY_free (strTmp);
   tmp = tmp->next;
 
   while (NULL != tmp)
     {
-      asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
+      MONKEY_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
       strcat (string, strTmp);
-      free (strTmp);
+      MONKEY_free (strTmp);
       tmp = tmp->next;
     }
 
@@ -854,7 +854,7 @@
   size = ftell (valgrindFile);
   fseek (valgrindFile, 0L, SEEK_SET);
 
-  valgrindOutput = malloc (size);
+  valgrindOutput = MONKEY_malloc (size);
   fread (valgrindOutput, size - 1, 1, valgrindFile);
   fclose (valgrindFile);
   return valgrindOutput;
@@ -870,9 +870,9 @@
 
 static struct MONKEY_XML_Node * createXmlCrashNode(const char *category, const 
char *function, int line, const char *file) {
        struct MONKEY_XML_Node * node;
-       const char *lineStr;
+       char *lineStr;
 
-       asprintf(&lineStr, "%d", line);
+       MONKEY_asprintf(&lineStr, "%d", line);
        node = MONKEY_XML_WRITER_new_node("crash", NULL);
        MONKEY_XML_WRITER_add_attribute(node, "category", category);
        MONKEY_XML_WRITER_add_attribute(node, "function", function);
@@ -884,8 +884,8 @@
 
 static struct MONKEY_XML_Node * createXmlEpochStep(int step) {
        struct MONKEY_XML_Node * node;
-       const char *stepStr;
-       asprintf(&stepStr, "%d", step);
+       char *stepStr;
+       MONKEY_asprintf(&stepStr, "%d", step);
        node = MONKEY_XML_WRITER_new_node("epoch", NULL);
        MONKEY_XML_WRITER_add_attribute(node, "step", stepStr);
        return node;
@@ -894,11 +894,11 @@
 
 static struct MONKEY_XML_Node * createXmlFunctionNode(const char *name, int 
line, const char *file, int depth) {
        struct MONKEY_XML_Node * node;
-       const char *lineStr;
-       const char *depthStr;
+       char *lineStr;
+       char *depthStr;
 
-       asprintf(&lineStr, "%d", line);
-       asprintf(&depthStr, "%d", depth);
+       MONKEY_asprintf(&lineStr, "%d", line);
+       MONKEY_asprintf(&depthStr, "%d", depth);
        node = MONKEY_XML_WRITER_new_node("function", NULL);
        MONKEY_XML_WRITER_add_attribute(node, "name", name);
        MONKEY_XML_WRITER_add_attribute(node, "line", lineStr);
@@ -970,7 +970,7 @@
     case DEBUG_MODE_GDB:
       if (cntxt->bug_detected == BUG_NULL_POINTER)
        {
-         asprintf (&(cntxt->debug_report),
+         MONKEY_asprintf (&(cntxt->debug_report),
                           "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n Details:\n 
Expression:%s is NULL\n",
                           cntxt->gdb_frames->file, cntxt->gdb_frames->func,
                           cntxt->gdb_frames->line,
@@ -989,7 +989,7 @@
                expressionListToString (expressionListHead);
 
            if (strcasecmp(cntxt->gdb_stop_reason->signal_meaning, "Arithmetic 
exception") == 0) {
-               asprintf (&(cntxt->debug_report),
+               MONKEY_asprintf (&(cntxt->debug_report),
                                                           "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\nDetails:\nArithmetic 
Exception: Division by Zero suspected\nExpression evaluation:\n%s\n",
                                                           
cntxt->gdb_frames->file,
                                                           
cntxt->gdb_frames->func,
@@ -1000,7 +1000,7 @@
            }
            else {
                /* Assertion Failure */
-                       asprintf (&(cntxt->debug_report),
+                       MONKEY_asprintf (&(cntxt->debug_report),
                                           "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\nDetails:\nAssertion 
Failure\nExpression evaluation:\n%s\n",
                                           cntxt->gdb_frames->file,
                                           cntxt->gdb_frames->func,
@@ -1014,7 +1014,7 @@
            {
              /* Inspection of user-defined expression */
              /*
-                asprintf(&(cntxt->debug_report),
+                MONKEY_asprintf(&(cntxt->debug_report),
                 "Inspection of expression: %s in function: %s, file:%s\nHit 
Number: \t \tValue:\n%s",
                 cntxt->inspect_expression, cntxt->inspect_function, 
cntxt->binary_name, watchInfoListToString(watchInfoListHead));
               */
@@ -1022,7 +1022,7 @@
        }
       break;
     case DEBUG_MODE_VALGRIND:
-      asprintf (&(cntxt->debug_report),
+      MONKEY_asprintf (&(cntxt->debug_report),
                       "Bug detected in file:%s\nfunction:%s\nline:%d\nreceived 
signal:%s\n%s\n Details:\n Memory Check from Valgrind:\n%s",
                       cntxt->gdb_frames->file, cntxt->gdb_frames->func,
                       cntxt->gdb_frames->line,
@@ -1044,16 +1044,16 @@
                                     *cntxt)
 {
   if (NULL != cntxt->debug_report)
-    free (cntxt->debug_report);
+    MONKEY_free (cntxt->debug_report);
   if (NULL != cntxt->valgrind_output_tmp_file_name)
     {
       remove (cntxt->valgrind_output_tmp_file_name);
-      free (cntxt->valgrind_output_tmp_file_name);
+      MONKEY_free (cntxt->valgrind_output_tmp_file_name);
     }
   if (NULL != cntxt->xmlReportRootNode)
          MONKEY_XML_WRITER_delete_tree(cntxt->xmlReportRootNode);
 
-  free (cntxt);
+  MONKEY_free (cntxt);
   return MONKEY_OK;
 }
 

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/edb_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/edb_api.c      
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/edb_api.c      
2012-03-06 11:42:54 UTC (rev 20305)
@@ -33,7 +33,7 @@
 {
   int err;
   struct MONKEY_EDB_Context *ctxt =
-    malloc (sizeof (struct MONKEY_EDB_Context));
+    MONKEY_malloc (sizeof (struct MONKEY_EDB_Context));
 
   err = sqlite3_open (db_file_name, &ctxt->db_handle);
   if (err)
@@ -57,7 +57,7 @@
 MONKEY_EDB_disconnect (struct MONKEY_EDB_Context *cntxt)
 {
   sqlite3_close (cntxt->db_handle);
-  free (cntxt);
+  MONKEY_free (cntxt);
   return MONKEY_OK;
 }
 
@@ -72,7 +72,7 @@
   char *errMsg;
   char *query;
 
-  if (asprintf (&query, "select distinct file_name from Expression") == -1)
+  if (MONKEY_asprintf (&query, "select distinct file_name from Expression") == 
-1)
     {
       fprintf(stderr,
                  "Memory allocation problem occurred during creating database 
query!\n");
@@ -105,7 +105,7 @@
          char *errMsg;
          char *query;
 
-         if (asprintf
+         if (MONKEY_asprintf
                  (&query,
                   "select distinct end_lineno from Expression where file_name 
LIKE \'%%/%s\' and start_lineno >= %d and start_lineno < %d and end_lineno > %d 
order by end_lineno",
                   file_name, function_beginning, scope_in_question_start, 
scope_in_question_end) == -1)
@@ -138,7 +138,7 @@
          char *errMsg;
          char *query;
 
-         if (asprintf
+         if (MONKEY_asprintf
              (&query,
               "select MIN(start_lineno) from Expression where file_name LIKE 
\'%%/%s\' and end_lineno >= %d",
               file_name, scope_end) == -1)
@@ -181,7 +181,7 @@
   char *errMsg;
   char *query;
 
-  if (asprintf
+  if (MONKEY_asprintf
       (&query,
        "select end_lineno from Expression where file_name LIKE \'%%/%s\' and 
start_lineno = %d",
        file_name, start_line_no) == -1)
@@ -192,7 +192,7 @@
     }
 
   err = sqlite3_exec (cntxt->db_handle, query, iter, iter_cls, &errMsg);
-  free (query);
+  MONKEY_free (query);
 
   if (err)
     {
@@ -215,7 +215,7 @@
   int err;
   char *errMsg;
   char *query;
-  if (asprintf
+  if (MONKEY_asprintf
          (&query,
           "select expr_syntax, start_lineno from Expression where file_name 
LIKE \'%%/%s\' and start_lineno <= %d and end_lineno <= %d",
           file_name, start_line_no, end_line_no) == -1)
@@ -258,7 +258,7 @@
   int err;
   char *errMsg;
   char *query;
-  if (asprintf
+  if (MONKEY_asprintf
       (&query,
        "select expr_syntax, start_lineno from Expression where file_name LIKE 
\'%%/%s\' and start_lineno <= %d and end_lineno = %d",
        file_name, start_line_no, end_line_no) == -1)
@@ -290,7 +290,7 @@
   int err;
   char *errMsg;
   char *query;
-  if (asprintf
+  if (MONKEY_asprintf
       (&query,
        "select expr_syntax, start_lineno from Expression where file_name LIKE 
\'%%/%s\' and start_lineno = %d and end_lineno = %d",
        file_name, start_line_no, end_line_no) == -1)

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_connect.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_connect.c        
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_connect.c        
2012-03-06 11:42:54 UTC (rev 20305)
@@ -18,7 +18,6 @@
 
 ***************************************************************************/
 
-#include "platform.h"
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -32,6 +31,7 @@
 #include <signal.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include "plibc.h"
 
 #include "gdbmi.h"
 #ifndef _GNU_SOURCE

Deleted: monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-monkey.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-monkey.c        
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-monkey.c        
2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,221 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file monkey/gnunet-monkey.c
- * @brief Monkey: gnunet automated debugging tool
- */
-
-#include <stdio.h>
-#include <sys/stat.h>
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include "monkey_action.h"
-
-static const char *mode;
-static const char *dumpFileName;
-static const char *binaryName;
-static const char *emailAddress;
-static const char *edbFilePath;
-static const char *gdbBinaryPath;
-static const char *inspectExpression;
-static const char *inspectFunction;
-static int ret = 0;
-
-/**
- * Main function that will launch the action api.
- *
- * @param cls closure
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
- * @param c configuration
- */
-static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
-{
-  int result;
-  struct MONKEY_ACTION_Context *cntxt;
-
-  if (NULL == edbFilePath)
-    {
-      /* lookup a file named test.db in the working directory */
-      struct stat buf;
-      if (0 != stat ("test.db", &buf))
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     "Expression Database file was not provided as and 
argument, "
-                     "and there is no file named test.db in monkey's working 
directory!\n");
-         GNUNET_break (0);
-         ret = 1;
-         return;
-       }
-
-    }
-
-  if (NULL == dumpFileName)
-    {
-      /* if no file name provided for the output report, use a default one in 
the current working directory */
-      dumpFileName = "monkey_output";
-    }
-
-  if (strcasecmp (mode, "email") == 0)
-    {
-      if (NULL == emailAddress)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     "Working in email mode requires an email address!\n");
-         GNUNET_break (0);
-         ret = 1;
-         return;
-       }
-    }
-
-  /* Initialize context for the Action API */
-  cntxt = GNUNET_malloc (sizeof (struct MONKEY_ACTION_Context));
-  cntxt->binary_name = binaryName;
-  cntxt->expression_database_path = edbFilePath;
-  cntxt->gdb_binary_path = gdbBinaryPath;
-  cntxt->inspect_expression = inspectExpression;
-  cntxt->inspect_function = inspectFunction;
-  cntxt->function_start_line = 0;
-  cntxt->scope_depth = 0;
-  cntxt->xmlReportRootNode = NULL;
-
-  result = MONKEY_ACTION_rerun_with_gdb (cntxt);
-  switch (result)
-    {
-      int retVal;
-    case GDB_STATE_ERROR:
-      break;
-    case GDB_STATE_EXIT_NORMALLY:
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                 "Debug with gdb, program exited normally!\n");
-      /*FIXME: Valgrind should be launched here */
-      break;
-    case GDB_STATE_STOPPED:
-      /*FIXME: Expression Database should be inspected here (before writing 
the report) */
-      retVal = MONKEY_ACTION_inspect_expression_database (cntxt);
-      if (GNUNET_NO == retVal)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     "Error using Expression Database!\n");
-         ret = 1;
-         break;
-       }
-      else if (GDB_STATE_ERROR == retVal)
-       {
-         /* GDB could not locate a NULL value expression, launch Valgrind */
-         retVal = MONKEY_ACTION_rerun_with_valgrind (cntxt);
-         if (GNUNET_NO == retVal)
-           {
-             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error using Valgrind!\n");
-             ret = 1;
-             break;
-           }
-       }
-      if (GNUNET_OK != MONKEY_ACTION_format_report_xml (cntxt))
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     "Error in generating debug report!\n");
-         ret = 1;
-       }
-      if (strcasecmp (mode, "email") == 0)
-       {
-         if (GNUNET_OK != MONKEY_ACTION_report_email (cntxt))
-           {
-             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error sending email!\n");
-             ret = 1;
-           }
-       }
-      else
-       {
-         /* text mode */
-         if (GNUNET_OK !=
-             MONKEY_ACTION_report_file (cntxt, dumpFileName, GNUNET_YES))
-           {
-             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                         "Error in saving debug file!\n");
-             ret = 1;
-           }
-       }
-      break;
-    default:
-      break;
-    }
-  MONKEY_ACTION_delete_context (cntxt);
-}
-
-
-int
-main (int argc, char *argv[])
-{
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    {'m', "mode", NULL,
-     gettext_noop
-     ("mandatory:monkey's mode of operation: options are \"text\" or 
\"email\""),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &mode},
-    {'b', "binary", NULL,
-     gettext_noop
-     ("mandatory:path to a binary file for a program to debug with monkey"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName},
-    {'o', "output", NULL,
-     gettext_noop
-     ("path to the debug report generated by monkey. If not provided, monkey 
will save the report in file named monkey_output"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName},
-    {'a', "address", NULL,
-     gettext_noop ("email address to which monkey will send debug report"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &emailAddress},
-    {'d', "database", NULL,
-     gettext_noop ("mandatory:path to Expression Database file"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &edbFilePath},
-    {'g', "gdb", NULL,
-     gettext_noop ("path to gdb binary to use. Default is /usr/bin/gdb"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &gdbBinaryPath},
-    {'f', "function", NULL,
-     gettext_noop ("monkey will set a breakpoint on this function"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &inspectFunction},
-    {'i', "inspect", NULL,
-     gettext_noop
-     ("expression to inspect in the function specified after the argument f"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &inspectExpression},
-    GNUNET_GETOPT_OPTION_END
-  };
-
-  if (argc < 2)
-    {
-      printf ("%s",
-             "Monkey should take arguments: Use --help to get a list of 
options.\n");
-      return 1;
-    }
-
-  if (GNUNET_OK == GNUNET_PROGRAM_run (argc,
-                                      argv,
-                                      "gnunet-monkey",
-                                      gettext_noop
-                                      ("Automatically debug a service"),
-                                      options, &run, NULL))
-    {
-      return ret;
-    }
-
-  return 1;
-}

Deleted: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-service-monkey.c
===================================================================
--- 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-service-monkey.c    
    2012-03-06 11:41:44 UTC (rev 20304)
+++ 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-service-monkey.c    
    2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,6 +0,0 @@
-
-
-int main(int argc, char *argv[]) 
-{
-       return 0;
-}

Copied: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c (from rev 
20231, monkey/branches/MonkeyBacktracking/monkey/src/monkey/gnunet-monkey.c)
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c               
                (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c       
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,264 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file monkey/gnunet-monkey.c
+ * @brief Monkey: automatic debugging tool
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "monkey_common.h"
+#include "monkey_action.h"
+
+#define MIN_ARG_REQUIRED 2
+
+static const char *mode = NULL;
+static const char *dumpFileName = NULL;
+static const char *binaryName = NULL;
+static const char *emailAddress = NULL;
+static const char *edbFilePath = NULL;
+static const char *gdbBinaryPath = NULL;
+static const char *inspectExpression = NULL;
+static const char *inspectFunction = NULL;
+static int ret = 0;
+
+/**
+ * Main function that will launch Monkey's action api.
+*/
+static void run()
+{
+  int result;
+  struct MONKEY_ACTION_Context *cntxt;
+
+  if (NULL == edbFilePath)
+    {
+      /* lookup a file named test.db in the working directory */
+      struct stat buf;
+      if (0 != stat ("test.db", &buf))
+       {
+         fprintf( stderr,
+                     "Expression Database file was not provided as and 
argument, "
+                     "and there is no file named test.db in monkey's working 
directory!\n");
+         MONKEY_break (0);
+         ret = 1;
+         return;
+       }
+
+    }
+
+  if (NULL == dumpFileName)
+    {
+      /* if no file name provided for the output report, use a default one in 
the current working directory */
+      dumpFileName = "monkey_output";
+    }
+
+  if (strcasecmp (mode, "email") == 0)
+    {
+      if (NULL == emailAddress)
+       {
+         fprintf( stderr,
+                     "Working in email mode requires an email address!\n");
+         MONKEY_break (0);
+         ret = 1;
+         return;
+       }
+    }
+
+  /* Initialize context for the Action API */
+  cntxt = MONKEY_malloc (sizeof (struct MONKEY_ACTION_Context));
+  cntxt->binary_name = binaryName;
+  cntxt->expression_database_path = edbFilePath;
+  cntxt->gdb_binary_path = gdbBinaryPath;
+  cntxt->inspect_expression = inspectExpression;
+  cntxt->inspect_function = inspectFunction;
+  cntxt->function_start_line = 0;
+  cntxt->scope_depth = 0;
+  cntxt->xmlReportRootNode = NULL;
+
+  result = MONKEY_ACTION_rerun_with_gdb (cntxt);
+  switch (result)
+    {
+      int retVal;
+    case GDB_STATE_ERROR:
+      break;
+    case GDB_STATE_EXIT_NORMALLY:
+      fprintf (stderr,
+                 "Debug with gdb, program exited normally!\n");
+      /*FIXME: Valgrind should be launched here */
+      break;
+    case GDB_STATE_STOPPED:
+      retVal = MONKEY_ACTION_inspect_expression_database (cntxt);
+      if (MONKEY_NO == retVal)
+       {
+         fprintf( stderr,
+                     "Error using Expression Database!\n");
+         ret = 1;
+         break;
+       }
+      else if (GDB_STATE_ERROR == retVal)
+       {
+         /* GDB could not locate a NULL value expression, launch Valgrind */
+         retVal = MONKEY_ACTION_rerun_with_valgrind (cntxt);
+         if (MONKEY_NO == retVal)
+           {
+             fprintf( stderr, "Error using Valgrind!\n");
+             ret = 1;
+             break;
+           }
+       }
+      if (MONKEY_OK != MONKEY_ACTION_format_report_xml (cntxt))
+       {
+         fprintf( stderr,
+                     "Error in generating debug report!\n");
+         ret = 1;
+       }
+      if (strcasecmp (mode, "email") == 0)
+       {
+         if (MONKEY_OK != MONKEY_ACTION_report_email (cntxt))
+           {
+             fprintf( stderr, "Error sending email!\n");
+             ret = 1;
+           }
+       }
+      else
+       {
+         /* text mode */
+         if (MONKEY_OK !=
+             MONKEY_ACTION_report_file (cntxt, dumpFileName, MONKEY_YES))
+           {
+             fprintf( stderr,
+                         "Error in saving debug file!\n");
+             ret = 1;
+           }
+       }
+      break;
+    default:
+      break;
+    }
+  MONKEY_ACTION_delete_context (cntxt);
+}
+
+
+/* display help */
+void showHelp() {
+   printf("Monkey: Automatically debug a service\n");
+   printf ("\t-b: binary: path to a binary file for a program to debug with 
monkey [mandatory]\n");
+   printf ("\t-d: database: path to Expression Database file [mandatory]\n");
+   printf ("\t-m: mode: monkey's mode of operation: options are \"text\" or 
\"email\" [mandatory]\n");
+   printf ("\t-a: address: email address to which monkey will send debug 
report [optional]\n");
+   printf ("\t-f: function: function name at which monkey will set a 
breakpoint [optional]\n");
+   printf ("\t-g: gdb: path to gdb binary to use. If not passed, monkey will 
look for gdb at /usr/bin/gdb [optional]\n");
+   printf ("\t-h: help: print this help [optional]\n");
+   printf ("\t-i: inspect: expression to inspect in the function specified 
after argument f [optional]\n");
+   printf ("\t-o: output: path to the debug report generated by monkey. If not 
provided monkey will save the report in a file named monkey_output in the 
current working directory [optional]\n");
+   printf ("\t-v: version: monkey's version [optional]\n");
+   printf ("Report bugs to address@hidden");
+   printf ("GNUnet home page:  http://www.gnu.org/software/gnunet/\n";);
+   printf ("General help using GNU software: http://www.gnu.org/gethelp/\n";);
+}
+
+int freeMonkeyArgs()
+{
+       if (NULL != mode)
+               MONKEY_free(mode);
+       if (NULL != dumpFileName)
+               MONKEY_free(dumpFileName);
+       if (NULL != binaryName)
+               MONKEY_free(binaryName);
+       if (NULL != emailAddress)
+               MONKEY_free(emailAddress);
+       if (NULL != edbFilePath)
+               MONKEY_free(edbFilePath);
+       if (NULL != gdbBinaryPath)
+               MONKEY_free(gdbBinaryPath);
+       if (NULL != inspectExpression)
+               MONKEY_free(inspectExpression);
+       if (NULL != inspectFunction)
+               MONKEY_free(inspectFunction);
+
+       return MONKEY_OK;
+}
+
+int
+main (int argc, char *argv[])
+{
+       int i;
+       int binaryCheck = MONKEY_NO;
+       int databaseCheck = MONKEY_NO;
+       int modeCheck = MONKEY_NO;
+        if (argc < MIN_ARG_REQUIRED)
+           {
+             printf ("%s",
+                     "Monkey should take arguments: Use -h to get a list of 
options.\n");
+             return 1;
+           }
+        /* Parsing arguments */
+        for (i = 0; i < argc; i++) {
+                if (strcmp("-h", argv[i]) == 0) {
+                        showHelp();
+                        freeMonkeyArgs();
+                        return 1;
+                }
+                if (strcmp("-b", argv[i]) == 0) {
+                        binaryCheck = MONKEY_OK;
+                        binaryName = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-d", argv[i]) == 0) {
+                        databaseCheck = MONKEY_OK;
+                        edbFilePath = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-m", argv[i]) == 0) {
+                        modeCheck = MONKEY_OK;
+                        mode = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-o", argv[i]) == 0) {
+                        dumpFileName = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-a", argv[i]) == 0) {
+                        emailAddress = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-g", argv[i]) == 0) {
+                        gdbBinaryPath = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-f", argv[i]) == 0) {
+                        inspectFunction = MONKEY_strdup(argv[++i]);
+                }
+                else if (strcmp("-i", argv[i]) == 0) {
+                        inspectExpression = MONKEY_strdup(argv[++i]);
+                }
+        }
+        if (MONKEY_NO == binaryCheck)
+                printf("Error: missing argument: path to the binary file.\n");
+        if (MONKEY_NO == databaseCheck)
+                printf("Error: missing argument: path to expression database 
file.\n");
+        if (MONKEY_NO == modeCheck)
+                printf("Error: missing argument: mode of operation.\n");
+        if (MONKEY_NO == binaryCheck || MONKEY_NO == databaseCheck || 
MONKEY_NO == modeCheck) {
+                showHelp();
+                return 1;
+        }
+
+        /* Run Monkey */
+        run();
+
+  return ret;
+}

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-06 11:42:54 UTC (rev 20305)
@@ -7,6 +7,7 @@
 #define MONKEY_ACTION_H
 
 #include "gdbmi.h"
+#include "monkey_xml_writer.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -43,7 +44,7 @@
   int debug_mode;
   int bug_detected;
   char *debug_report;
-  struct MONKEY_XML_node *xmlReportRootNode;
+  struct MONKEY_XML_Node *xmlReportRootNode;
 
   /* gdb debugging attributes */
   int run_reverse;

Deleted: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.c   
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.c   
2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,71 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file monkey/test_gnunet_monkey.c
- * @brief Testcase for Monkey
- * @author Safey A.Halim
- */
-
-/**
- * Test case for Monkey Automatic Debugger.
- * It launches Monkey to run binaries having 
- * known bugs (e.g. Null Pointer Exception)
- * Monkey should be able to detect the problem and send an e-mail
- * containing the problem description.
- */
-
-
-#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_program_lib.h"
-
-
-static int
-check ()
-{
-  GNUNET_OS_process_close (GNUNET_OS_start_process (NULL, NULL,
-                                                   "gnunet-monkey",
-                                                   "gnunet-monkey",
-                                                   
"./bug_null_pointer_exception",
-                                                   NULL));
-
-  return 0;
-}
-
-
-int
-main (int argc, char *argv[])
-{
-  int ret;
-
-  GNUNET_log_setup ("test-gnunet-monkey",
-#if VERBOSE
-                   "DEBUG",
-#else
-                   "WARNING",
-#endif
-                   NULL);
-  ret = check ();
-  return ret;
-}
-
-/* end of test_gnunet_monkey.c */

Deleted: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.sh
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.sh  
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.sh  
2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,199 +0,0 @@
-#!/bin/sh
-
-rm -rf /tmp/test-gnunetd-monkey/
-exe="./gnunet-monkey -c test_monkey_api_data.conf"
-out=`mktemp /tmp/test-gnunet-monkey-logXXXXXXXX`
-arm="gnunet-arm -c test_monkey_api_data.conf $DEBUG"
-#DEBUG="-L DEBUG"
-# -----------------------------------
-echo -n "Preparing: Starting service..."
-
-$arm -s > /dev/null
-sleep 1
-$arm -i monkey > /dev/null
-sleep 1 
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Bad argument checking..."
-
-if $exe -x 2> /dev/null; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set value..."
-
-if ! $exe $DEBUG -n test -s subsystem 42 ; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set another value..."
-
-if ! $exe $DEBUG -n other -s osystem 43 ; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing all stats..."
-
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | wc -l`
-if test $LINES -ne 2; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing stats by name..."
-
-if ! $exe $DEBUG -n other > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 43 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing stats by subsystem..."
-
-if ! $exe $DEBUG -s subsystem > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 42 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set persistent value..."
-
-if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 40 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    cat $out
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# -----------------------------------
-echo -n "Restarting service..."
-$arm -k monkey > /dev/null
-sleep 1
-$arm -i monkey > /dev/null
-sleep 1
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: checking persistence..."
-
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 40 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    cat $out
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Removing persistence..."
-
-if ! $exe  $DEBUG -n lasting -s subsystem 40; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep \! | wc -l`
-if test $LINES -ne 0; then
-    echo "FAIL: unexpected output"
-    cat $out
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-
-# -----------------------------------
-echo -n "Restarting service..."
-$arm -k monkey > /dev/null
-sleep 1
-$arm -i monkey > /dev/null
-sleep 1
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: checking removed persistence..."
-
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 40 | wc -l`
-if test $LINES -ne 0; then
-    echo "FAIL: unexpected output"
-    cat $out
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# -----------------------------------
-echo -n "Stopping service..."
-$arm -e > /dev/null
-sleep 1
-echo "DONE"
-rm -f $out
-rm -rf /tmp/test-gnunetd-monkey/

Deleted: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey_data.conf
===================================================================
--- 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey_data.conf
   2012-03-06 11:41:44 UTC (rev 20304)
+++ 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey_data.conf
   2012-03-06 11:42:54 UTC (rev 20305)
@@ -1,43 +0,0 @@
-[PATHS]
-SERVICEHOME = /tmp/test-gnunetd-arm/
-DEFAULTCONFIG = test_arm_api_data.conf
-
-[arm]
-PORT = 23354
-DEFAULTSERVICES =
-BINARY = gnunet-service-arm
-OPTIONS = -L ERROR
-# DEBUG = YES
-#PREFIX = valgrind --tool=memcheck --leak-check=yes
-
-[gnunet-monkey]
-# DEBUG = YES
-PORT = 23355
-BINARY = gnunet-monkey
-# PREFIX = valgrind
-
-
-[fs]
-AUTOSTART = NO
-
-[datastore]
-AUTOSTART = NO
-
-[core]
-AUTOSTART = NO
-
-[transport]
-AUTOSTART = NO
-
-[peerinfo]
-AUTOSTART = NO
-
-[statistics]
-AUTOSTART = YES
-# DEBUG = NO
-
-
-[dns]
-AUTOSTART = NO
-
-

Copied: monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.c 
(from rev 20231, 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.c)
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.c          
                (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.c  
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,71 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file monkey/test_gnunet_monkey.c
+ * @brief Testcase for Monkey
+ * @author Safey A.Halim
+ */
+
+/**
+ * Test case for Monkey Automatic Debugger.
+ * It launches Monkey to run binaries having 
+ * known bugs (e.g. Null Pointer Exception)
+ * Monkey should be able to detect the problem and send an e-mail
+ * containing the problem description.
+ */
+
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_program_lib.h"
+
+
+static int
+check ()
+{
+  GNUNET_OS_process_close (GNUNET_OS_start_process (NULL, NULL,
+                                                   "gnunet-monkey",
+                                                   "gnunet-monkey",
+                                                   
"./bug_null_pointer_exception",
+                                                   NULL));
+
+  return 0;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  int ret;
+
+  GNUNET_log_setup ("test-gnunet-monkey",
+#if VERBOSE
+                   "DEBUG",
+#else
+                   "WARNING",
+#endif
+                   NULL);
+  ret = check ();
+  return ret;
+}
+
+/* end of test_gnunet_monkey.c */

Copied: monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.sh 
(from rev 20231, 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey.sh)
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.sh         
                (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey.sh 
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,199 @@
+#!/bin/sh
+
+rm -rf /tmp/test-gnunetd-monkey/
+exe="./gnunet-monkey -c test_monkey_api_data.conf"
+out=`mktemp /tmp/test-gnunet-monkey-logXXXXXXXX`
+arm="gnunet-arm -c test_monkey_api_data.conf $DEBUG"
+#DEBUG="-L DEBUG"
+# -----------------------------------
+echo -n "Preparing: Starting service..."
+
+$arm -s > /dev/null
+sleep 1
+$arm -i monkey > /dev/null
+sleep 1 
+echo "DONE"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: Bad argument checking..."
+
+if $exe -x 2> /dev/null; then
+  echo "FAIL: error running $exe"
+  $arm -e
+  exit 1
+fi
+echo "PASS"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: Set value..."
+
+if ! $exe $DEBUG -n test -s subsystem 42 ; then
+  echo "FAIL: error running $exe"
+  $arm -e
+  exit 1
+fi
+echo "PASS"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: Set another value..."
+
+if ! $exe $DEBUG -n other -s osystem 43 ; then
+  echo "FAIL: error running $exe"
+  $arm -e
+  exit 1
+fi
+echo "PASS"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: viewing all stats..."
+
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | wc -l`
+if test $LINES -ne 2; then
+    echo "FAIL: unexpected output"
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: viewing stats by name..."
+
+if ! $exe $DEBUG -n other > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 43 | wc -l`
+if test $LINES -ne 1; then
+    echo "FAIL: unexpected output"
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: viewing stats by subsystem..."
+
+if ! $exe $DEBUG -s subsystem > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 42 | wc -l`
+if test $LINES -ne 1; then
+    echo "FAIL: unexpected output"
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: Set persistent value..."
+
+if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
+  echo "FAIL: error running $exe"
+  $arm -e
+  exit 1
+fi
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 40 | wc -l`
+if test $LINES -ne 1; then
+    echo "FAIL: unexpected output"
+    cat $out
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+# -----------------------------------
+echo -n "Restarting service..."
+$arm -k monkey > /dev/null
+sleep 1
+$arm -i monkey > /dev/null
+sleep 1
+echo "DONE"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: checking persistence..."
+
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 40 | wc -l`
+if test $LINES -ne 1; then
+    echo "FAIL: unexpected output"
+    cat $out
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: Removing persistence..."
+
+if ! $exe  $DEBUG -n lasting -s subsystem 40; then
+  echo "FAIL: error running $exe"
+  $arm -e
+  exit 1
+fi
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep \! | wc -l`
+if test $LINES -ne 0; then
+    echo "FAIL: unexpected output"
+    cat $out
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+
+# -----------------------------------
+echo -n "Restarting service..."
+$arm -k monkey > /dev/null
+sleep 1
+$arm -i monkey > /dev/null
+sleep 1
+echo "DONE"
+
+# 
----------------------------------------------------------------------------------
+echo -n "TEST: checking removed persistence..."
+
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 40 | wc -l`
+if test $LINES -ne 0; then
+    echo "FAIL: unexpected output"
+    cat $out
+    $arm -e
+    exit 1
+fi
+echo "PASS"
+
+# -----------------------------------
+echo -n "Stopping service..."
+$arm -e > /dev/null
+sleep 1
+echo "DONE"
+rm -f $out
+rm -rf /tmp/test-gnunetd-monkey/

Copied: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_data.conf 
(from rev 20231, 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_gnunet_monkey_data.conf)
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_data.conf  
                        (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_data.conf  
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,43 @@
+[PATHS]
+SERVICEHOME = /tmp/test-gnunetd-arm/
+DEFAULTCONFIG = test_arm_api_data.conf
+
+[arm]
+PORT = 23354
+DEFAULTSERVICES =
+BINARY = gnunet-service-arm
+OPTIONS = -L ERROR
+# DEBUG = YES
+#PREFIX = valgrind --tool=memcheck --leak-check=yes
+
+[gnunet-monkey]
+# DEBUG = YES
+PORT = 23355
+BINARY = gnunet-monkey
+# PREFIX = valgrind
+
+
+[fs]
+AUTOSTART = NO
+
+[datastore]
+AUTOSTART = NO
+
+[core]
+AUTOSTART = NO
+
+[transport]
+AUTOSTART = NO
+
+[peerinfo]
+AUTOSTART = NO
+
+[statistics]
+AUTOSTART = YES
+# DEBUG = NO
+
+
+[dns]
+AUTOSTART = NO
+
+

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_edb.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_edb.c      
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/test_monkey_edb.c      
2012-03-06 11:42:54 UTC (rev 20305)
@@ -21,9 +21,8 @@
  * @file monkey/test_monkey_edb.c
  * @brief testcase for edb_api.c
  */
-#include "platform.h"
-#include "gnunet/gnunet_common.h"
-#include "gnunet_monkey_edb.h"
+#include "monkey_common.h"
+#include "monkey_edb.h"
 
 
 static const char *ref[16] =
@@ -53,22 +52,16 @@
 int
 main (int args, const char *argv[])
 {
-  GNUNET_log_setup ("test-monkey-edb",
-#if VERBOSE
-                   "DEBUG",
-#else
-                   "WARNING",
-#endif
-                   NULL);
-  struct GNUNET_MONKEY_EDB_Context *cntxt;
-  cntxt = GNUNET_MONKEY_EDB_connect ("test.db");
+  printf ("test-monkey-edb\n");
+  struct MONKEY_EDB_Context *cntxt;
+  cntxt = MONKEY_EDB_connect ("test.db");
   ret =
-    GNUNET_MONKEY_EDB_get_expressions (cntxt,
+    MONKEY_EDB_get_expressions (cntxt,
                                       "monkey/seaspider/SeaspiderTest.c", 44,
                                       83, &expressionIterator, NULL);
-  GNUNET_MONKEY_EDB_disconnect (cntxt);
+  MONKEY_EDB_disconnect (cntxt);
 
-  if (ret == GNUNET_OK)
+  if (ret == MONKEY_OK)
     {
       return 0;
     }

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c   
2012-03-06 11:41:44 UTC (rev 20304)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c   
2012-03-06 11:42:54 UTC (rev 20305)
@@ -12,7 +12,7 @@
 
 
 struct MONKEY_XML_Node* MONKEY_XML_WRITER_new_node(const char *name, const 
char *innerText) {
-       struct MONKEY_XML_Node *node = malloc(sizeof(struct MONKEY_XML_Node));
+       struct MONKEY_XML_Node *node = MONKEY_malloc(sizeof(struct 
MONKEY_XML_Node));
        node->name = name;
        node->innerText = innerText;
        node->childrenListHead = NULL;
@@ -25,7 +25,7 @@
 
 int MONKEY_XML_WRITER_add_attribute(struct MONKEY_XML_Node* node, const char 
*attrName, const char *attrValue)
 {
-       struct XmlAttribute *attribute = malloc(sizeof(struct XmlAttribute));
+       struct XmlAttribute *attribute = MONKEY_malloc(sizeof(struct 
XmlAttribute));
        attribute->name = attrName;
        attribute->value  = attrValue;
        attribute->next = NULL; attribute->prev = NULL;
@@ -47,22 +47,22 @@
        struct MONKEY_XML_Node *tmp = NULL;
        struct XmlAttribute *tmpAttribute = NULL;
 
-       /* Freeing children list - Depth First */
+       /* MONKEY_freeing children list - Depth First */
        while (NULL != root->childrenListHead) {
                tmp = root->childrenListHead;
                root->childrenListHead = tmp->next;
                MONKEY_XML_WRITER_delete_tree(tmp);
        }
 
-       /* Freeing Attributes List */
+       /* MONKEY_freeing Attributes List */
        while (NULL != root->attributeListHead) {
                tmpAttribute = root->attributeListHead;
                root->attributeListHead = tmpAttribute->next;
-               free(tmpAttribute);
+               MONKEY_free(tmpAttribute);
        }
 
-       /* Freeing Leaf Node */
-       free(root);
+       /* MONKEY_freeing Leaf Node */
+       MONKEY_free(root);
 
        return MONKEY_OK;
 }

Added: monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am              
                (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am      
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,11 @@
+INCLUDES = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include
+
+if USE_COVERAGE
+  AM_CFLAGS = --coverage -O0
+  XLIB = -lgcov
+endif
+
+lib_LTLIBRARIES = libmonkeyutil.la
+
+libmonkeyutil_la_SOURCES = \
+  common_allocation.c
\ No newline at end of file

Added: monkey/branches/MonkeyBacktracking/monkey/src/util/common_allocation.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/util/common_allocation.c      
                        (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/util/common_allocation.c      
2012-03-06 11:42:54 UTC (rev 20305)
@@ -0,0 +1,338 @@
+/*
+     This file is part of MONKEY.
+     (C) 2001, 2002, 2003, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+
+     MONKEY is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     MONKEY is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with MONKEY; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file util/common_allocation.c
+ * @brief wrapper around malloc/free
+ * @author Christian Grothoff
+ * @author Safey A.Halim
+ */
+
+#include "monkey_common.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#ifndef INT_MAX
+#define INT_MAX 0x7FFFFFFF
+#endif
+
+#if 0
+#define W32_MEM_LIMIT 200000000
+#endif
+
+#ifdef W32_MEM_LIMIT
+static LONG mem_used = 0;
+#endif
+
+/**
+ * Allocate memory. Checks the return value, aborts if no more
+ * memory is available.
+ *
+ * @param size how many bytes of memory to allocate, do NOT use
+ *  this function (or MONKEY_malloc) to allocate more than several MB
+ *  of memory, if you are possibly needing a very large chunk use
+ *  MONKEY_xmalloc_unchecked_ instead.
+ * @param filename where in the code was the call to MONKEY_malloc
+ * @param linenumber where in the code was the call to MONKEY_malloc
+ * @return pointer to size bytes of memory
+ */
+void *
+MONKEY_xmalloc_ (size_t size, const char *filename, int linenumber)
+{
+  void *ret;
+
+  /* As a security precaution, we generally do not allow very large
+   * allocations using the default 'MONKEY_malloc' macro */
+  MONKEY_assert_at (size <= MONKEY_MAX_MALLOC_CHECKED, filename, linenumber);
+  ret = MONKEY_xmalloc_unchecked_ (size, filename, linenumber);
+  if (ret == NULL)
+  {
+    fprintf (stderr, "malloc");
+    abort ();
+  }
+  return ret;
+}
+
+
+/**
+ * Allocate and initialize memory. Checks the return value, aborts if no more
+ * memory is available.  Don't use MONKEY_xmemdup_ directly. Use the
+ * MONKEY_memdup macro.
+ *
+ * @param buf buffer to initialize from (must contain size bytes)
+ * @param size number of bytes to allocate
+ * @param filename where is this call being made (for debugging)
+ * @param linenumber line where this call is being made (for debugging)
+ * @return allocated memory, never NULL
+ */
+void *
+MONKEY_xmemdup_ (const void *buf, size_t size, const char *filename,
+                 int linenumber)
+{
+  void *ret;
+
+  /* As a security precaution, we generally do not allow very large
+   * allocations here */
+  MONKEY_assert_at (size <= MONKEY_MAX_MALLOC_CHECKED, filename, linenumber);
+#ifdef W32_MEM_LIMIT
+  size += sizeof (size_t);
+  if (mem_used + size > W32_MEM_LIMIT)
+    return NULL;
+#endif
+  MONKEY_assert_at (size < INT_MAX, filename, linenumber);
+  ret = malloc (size);
+  if (ret == NULL)
+  {
+    fprintf (stderr, "malloc");
+    abort ();
+  }
+#ifdef W32_MEM_LIMIT
+  *((size_t *) ret) = size;
+  ret = &((size_t *) ret)[1];
+  mem_used += size;
+#endif
+  memcpy (ret, buf, size);
+  return ret;
+}
+
+
+
+/**
+ * Wrapper around malloc. Allocates size bytes of memory.
+ * The memory will be zero'ed out.
+ *
+ * @param size the number of bytes to allocate
+ * @param filename where in the code was the call to MONKEY_malloc_large
+ * @param linenumber where in the code was the call to MONKEY_malloc_large
+ * @return pointer to size bytes of memory, NULL if we do not have enough 
memory
+ */
+void *
+MONKEY_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
+{
+  void *result;
+
+#ifdef W32_MEM_LIMIT
+  size += sizeof (size_t);
+  if (mem_used + size > W32_MEM_LIMIT)
+    return NULL;
+#endif
+
+  MONKEY_assert_at (size < INT_MAX, filename, linenumber);
+  result = malloc (size);
+  if (result == NULL)
+    return NULL;
+  memset (result, 0, size);
+
+#ifdef W32_MEM_LIMIT
+  *((size_t *) result) = size;
+  result = &((size_t *) result)[1];
+  mem_used += size;
+#endif
+
+  return result;
+}
+
+
+/**
+ * Reallocate memory. Checks the return value, aborts if no more
+ * memory is available.
+ *
+ * @param ptr the pointer to reallocate
+ * @param n how many bytes of memory to allocate
+ * @param filename where in the code was the call to MONKEY_realloc
+ * @param linenumber where in the code was the call to MONKEY_realloc
+ * @return pointer to size bytes of memory
+ */
+void *
+MONKEY_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
+{
+#ifdef W32_MEM_LIMIT
+  n += sizeof (size_t);
+  ptr = &((size_t *) ptr)[-1];
+  mem_used = mem_used - *((size_t *) ptr) + n;
+#endif
+  ptr = realloc (ptr, n);
+  if ((NULL == ptr) && (n > 0))
+  {
+    fprintf (stderr, "realloc");
+    abort ();
+  }
+#ifdef W32_MEM_LIMIT
+  ptr = &((size_t *) ptr)[1];
+#endif
+  return ptr;
+}
+
+
+/**
+ * Free memory. Merely a wrapper for the case that we
+ * want to keep track of allocations.
+ *
+ * @param ptr the pointer to free
+ * @param filename where in the code was the call to MONKEY_array_grow
+ * @param linenumber where in the code was the call to MONKEY_array_grow
+ */
+void
+MONKEY_xfree_ (void *ptr, const char *filename, int linenumber)
+{
+  MONKEY_assert_at (ptr != NULL, filename, linenumber);
+#ifdef W32_MEM_LIMIT
+  ptr = &((size_t *) ptr)[-1];
+  mem_used -= *((size_t *) ptr);
+#endif
+  free (ptr);
+}
+
+/**
+ * Dup a string (same semantics as strdup).
+ *
+ * @param str the string to dup
+ * @param filename where in the code was the call to MONKEY_strdup
+ * @param linenumber where in the code was the call to MONKEY_strdup
+ * @return strdup(str)
+ */
+char *
+MONKEY_xstrdup_ (const char *str, const char *filename, int linenumber)
+{
+  char *res;
+
+  MONKEY_assert_at (str != NULL, filename, linenumber);
+  res = MONKEY_xmalloc_ (strlen (str) + 1, filename, linenumber);
+  memcpy (res, str, strlen (str) + 1);
+  return res;
+}
+
+
+/**
+ * Dup partially a string (same semantics as strndup).
+ *
+ * @param str the string to dup
+ * @param len the length of the string to dup
+ * @param filename where in the code was the call to MONKEY_strndup
+ * @param linenumber where in the code was the call to MONKEY_strndup
+ * @return strndup(str,len)
+ */
+char *
+MONKEY_xstrndup_ (const char *str, size_t len, const char *filename,
+                  int linenumber)
+{
+  char *res;
+
+  MONKEY_assert_at (str != NULL, filename, linenumber);
+  len = MONKEY_MIN (len, strlen (str));
+  res = MONKEY_xmalloc_ (len + 1, filename, linenumber);
+  memcpy (res, str, len);
+  res[len] = '\0';
+  return res;
+}
+
+
+/**
+ * Grow an array.  Grows old by (*oldCount-newCount)*elementSize bytes
+ * and sets *oldCount to newCount.
+ *
+ * @param old address of the pointer to the array
+ *        *old may be NULL
+ * @param elementSize the size of the elements of the array
+ * @param oldCount address of the number of elements in the *old array
+ * @param newCount number of elements in the new array, may be 0
+ * @param filename where in the code was the call to MONKEY_array_grow
+ * @param linenumber where in the code was the call to MONKEY_array_grow
+ */
+void
+MONKEY_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
+               unsigned int newCount, const char *filename, int linenumber)
+{
+  void *tmp;
+  size_t size;
+
+  MONKEY_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
+  size = newCount * elementSize;
+  if (size == 0)
+  {
+    tmp = NULL;
+  }
+  else
+  {
+    tmp = MONKEY_xmalloc_ (size, filename, linenumber);
+    memset (tmp, 0, size);      /* client code should not rely on this, 
though... */
+    if (*oldCount > newCount)
+      *oldCount = newCount;     /* shrink is also allowed! */
+    memcpy (tmp, *old, elementSize * (*oldCount));
+  }
+
+  if (*old != NULL)
+  {
+    MONKEY_xfree_ (*old, filename, linenumber);
+  }
+  *old = tmp;
+  *oldCount = newCount;
+}
+
+
+/**
+ * Like asprintf, just portable.
+ *
+ * @param buf set to a buffer of sufficient size (allocated, caller must free)
+ * @param format format string (see printf, fprintf, etc.)
+ * @param ... data for format string
+ * @return number of bytes in "*buf" excluding 0-termination
+ */
+int
+MONKEY_asprintf (char **buf, const char *format, ...)
+{
+  int ret;
+  va_list args;
+
+  va_start (args, format);
+  ret = vsnprintf (NULL, 0, format, args);
+  va_end (args);
+  *buf = MONKEY_malloc (ret + 1);
+  va_start (args, format);
+  ret = vsprintf (*buf, format, args);
+  va_end (args);
+  return ret;
+}
+
+
+/**
+ * Like snprintf, just aborts if the buffer is of insufficient size.
+ *
+ * @param buf pointer to buffer that is written to
+ * @param size number of bytes in buf
+ * @param format format strings
+ * @param ... data for format string
+ * @return number of bytes written to buf or negative value on error
+ */
+int
+MONKEY_snprintf (char *buf, size_t size, const char *format, ...)
+{
+  int ret;
+  va_list args;
+
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  MONKEY_assert (ret <= size);
+  return ret;
+}
+
+/* end of common_allocation.c */


Property changes on: 
monkey/branches/MonkeyBacktracking/monkey/src/util/common_allocation.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain




reply via email to

[Prev in Thread] Current Thread [Next in Thread]