summaryrefslogtreecommitdiff
path: root/support/util
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/util
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/util')
-rw-r--r--support/util/NewAlloc.c277
-rw-r--r--support/util/dbuf.c334
-rw-r--r--support/util/dbuf.h65
-rw-r--r--support/util/dbuf_string.c330
-rw-r--r--support/util/dbuf_string.h69
-rw-r--r--support/util/findme.c59
-rw-r--r--support/util/findme.h20
-rw-r--r--support/util/newalloc.h99
-rw-r--r--support/util/pstdint.h678
-rw-r--r--support/util/system.h37
10 files changed, 1968 insertions, 0 deletions
diff --git a/support/util/NewAlloc.c b/support/util/NewAlloc.c
new file mode 100644
index 0000000..ef34c4d
--- /dev/null
+++ b/support/util/NewAlloc.c
@@ -0,0 +1,277 @@
+/*-------------------------------------------------------------------------
+ newalloc.c - SDCC Memory allocation functions
+
+ These functions are wrappers for the standard malloc, realloc and free
+ functions.
+
+ This program 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.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include <assert.h>
+#include "newalloc.h"
+
+#if OPT_ENABLE_LIBGC
+#include <gc/gc.h>
+
+#define MALLOC GC_malloc
+#define REALLOC GC_realloc
+/* PENDING: This is a mild hack. If we try to GC_free something
+ allocated with malloc() then the program will segfault. Might as
+ well drop it and let the garbase collector take care of things.
+*/
+#define FREE(_a)
+
+#else
+
+#define MALLOC malloc
+#define REALLOC realloc
+#define FREE free
+
+#endif
+
+#define TRACEMALLOC 0
+
+#if TRACEMALLOC
+enum
+{
+ TRACESIZE = 4096
+};
+
+static int _allocs[TRACESIZE];
+static int _above;
+
+static void
+_dumpTrace (int code, void *parg)
+{
+ int i;
+ for (i = 0; i < TRACESIZE; i++)
+ {
+ if (_allocs[i])
+ {
+ printf ("%u %u\n", _allocs[i], i);
+ }
+ }
+ printf ("%u above\n", _above);
+}
+
+static void
+_log (int size)
+{
+ static int registered;
+
+ if (registered == 0)
+ {
+ on_exit (_dumpTrace, NULL);
+ registered = 1;
+ }
+ if (size == 12)
+ {
+ _above++;
+ }
+
+ if (size >= TRACESIZE)
+ {
+ _above++;
+ }
+ else
+ {
+ _allocs[size]++;
+ }
+}
+#endif
+
+/*
+-------------------------------------------------------------------------------
+Clear_realloc - Reallocate a memory block and clear any memory added with
+out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *
+Clear_realloc (void *OldPtr, size_t OldSize, size_t NewSize)
+{
+ void *NewPtr;
+
+ NewPtr = REALLOC (OldPtr, NewSize);
+
+ if (!NewPtr)
+ {
+ printf ("ERROR - No more memory\n");
+/* werror(E_OUT_OF_MEM,__FILE__,NewSize);*/
+ exit (1);
+ }
+
+ if (NewPtr)
+ if (NewSize > OldSize)
+ memset ((char *) NewPtr + OldSize, 0x00, NewSize - OldSize);
+
+ return NewPtr;
+}
+
+/*
+-------------------------------------------------------------------------------
+Safe_realloc - Reallocate a memory block with out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *
+Safe_realloc (void *OldPtr, size_t NewSize)
+{
+ void *NewPtr;
+
+ NewPtr = REALLOC (OldPtr, NewSize);
+
+ if (!NewPtr)
+ {
+ printf ("ERROR - No more memory\n");
+/* werror(E_OUT_OF_MEM,__FILE__,NewSize);*/
+ exit (1);
+ }
+
+ return NewPtr;
+}
+
+/*
+-------------------------------------------------------------------------------
+Safe_calloc - Allocate a block of memory from the application heap, clearing
+all data to zero and checking for out of memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *
+Safe_calloc (size_t Elements, size_t Size)
+{
+ void *NewPtr;
+
+ NewPtr = MALLOC (Elements * Size);
+#if TRACEMALLOC
+ _log (Elements * Size);
+#endif
+
+ if (!NewPtr)
+ {
+ printf ("ERROR - No more memory\n");
+/* werror(E_OUT_OF_MEM,__FILE__,Size);*/
+ exit (1);
+ }
+
+ memset (NewPtr, 0, Elements * Size);
+
+ return NewPtr;
+}
+
+/*
+-------------------------------------------------------------------------------
+Safe_malloc - Allocate a block of memory from the application heap
+and checking for out of memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *
+Safe_malloc (size_t Size)
+{
+ void *NewPtr;
+
+ NewPtr = MALLOC (Size);
+
+#if TRACEMALLOC
+ _log (Size);
+#endif
+
+ if (!NewPtr)
+ {
+ printf ("ERROR - No more memory\n");
+/* werror(E_OUT_OF_MEM,__FILE__,Size);*/
+ exit (1);
+ }
+
+ return NewPtr;
+}
+
+void *
+Safe_alloc (size_t Size)
+{
+ return Safe_calloc (1, Size);
+}
+
+void
+Safe_free (void *p)
+{
+ FREE (p);
+}
+
+char *
+Safe_strndup (const char *sz, size_t size)
+{
+ char *pret;
+ assert (sz);
+
+ pret = Safe_alloc (size + 1);
+ strncpy (pret, sz, size);
+ pret[size] = '\0';
+
+ return pret;
+}
+
+char *
+Safe_strdup (const char *sz)
+{
+ assert (sz);
+
+ return Safe_strndup (sz, strlen (sz));
+}
+
+void *
+traceAlloc (allocTrace * ptrace, void *p)
+{
+ assert (ptrace);
+ assert (p);
+
+ /* Also handles where max == 0 */
+ if (ptrace->num == ptrace->max)
+ {
+ /* Add an offset to handle max == 0 */
+ ptrace->max = (ptrace->max + 2) * 2;
+ ptrace->palloced = Safe_realloc (ptrace->palloced, ptrace->max * sizeof (*ptrace->palloced));
+ }
+ ptrace->palloced[ptrace->num++] = p;
+
+ return p;
+}
+
+void
+freeTrace (allocTrace * ptrace)
+{
+ int i;
+ assert (ptrace);
+
+ for (i = 0; i < ptrace->num; i++)
+ {
+ Safe_free (ptrace->palloced[i]);
+ }
+ ptrace->num = 0;
+
+ Safe_free (ptrace->palloced);
+ ptrace->palloced = NULL;
+ ptrace->max = 0;
+}
diff --git a/support/util/dbuf.c b/support/util/dbuf.c
new file mode 100644
index 0000000..3ae6560
--- /dev/null
+++ b/support/util/dbuf.c
@@ -0,0 +1,334 @@
+/*
+ dbuf.c - Dynamic buffer implementation
+ version 1.4.0, 2011-03-27
+
+ Copyright (c) 2002-2011 Borut Razem
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Borut Razem
+ borut.razem@siol.net
+*/
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "dbuf.h"
+
+
+/*
+ * Assure that the buffer is large enough to hold
+ * current length + size bytes; enlarge it if necessary.
+ *
+ * Intended for internal use.
+ */
+
+int _dbuf_expand(struct dbuf_s *dbuf, size_t size)
+{
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ if (dbuf->len + size > dbuf->alloc) {
+ /* new_allocated_size = current_allocated_size * 2^n */
+ /* can this be optimized? */
+ do {
+ dbuf->alloc += dbuf->alloc;
+ }
+ while (dbuf->len + size > dbuf->alloc);
+
+ if ((dbuf->buf = realloc(dbuf->buf, dbuf->alloc)) == NULL)
+ return 0;
+ }
+
+ return 1;
+}
+
+
+/*
+ * Initialize the dbuf structure and
+ * allocate buffer to hold size bytes.
+ */
+
+int dbuf_init(struct dbuf_s *dbuf, size_t size)
+{
+ assert(size != 0);
+
+ if (size == 0)
+ size = 1;
+
+ dbuf->len = 0;
+ dbuf->alloc = size;
+ return ((dbuf->buf = malloc(dbuf->alloc)) != NULL);
+}
+
+
+/*
+ * Test if dbuf is initialized.
+ * NOTE: the dbuf structure should be set
+ * to all zeroes at definition:
+ * struct dbuf_s dbuf = { 0 };
+ *
+ * See: dbuf_init()
+ */
+
+int dbuf_is_initialized (struct dbuf_s *dbuf)
+{
+ if (dbuf->buf == NULL) {
+ assert(dbuf->alloc == 0);
+ assert(dbuf->len == 0);
+ return 0;
+ }
+ else {
+ assert(dbuf->alloc != 0);
+ assert(dbuf->len >= 0 && dbuf->len <= dbuf->alloc);
+ return 1;
+ }
+}
+
+/*
+ * Allocate new dbuf structure on the heap
+ * and initialize it.
+ *
+ * See: dbuf_delete()
+ */
+
+struct dbuf_s *dbuf_new(size_t size)
+{
+ struct dbuf_s *dbuf;
+
+ dbuf = (struct dbuf_s *)malloc(sizeof(struct dbuf_s));
+ if (dbuf != NULL) {
+ if (dbuf_init(dbuf, size) == 0) {
+ free(dbuf);
+ return NULL;
+ }
+ }
+ return dbuf;
+}
+
+
+/*
+ * Set the buffer size. Buffer size can be only decreased.
+ */
+
+int dbuf_set_length(struct dbuf_s *dbuf, size_t len)
+{
+ if (!dbuf_is_initialized (dbuf))
+ dbuf_init (dbuf, len ? len : 1);
+
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(len <= dbuf->len);
+
+ if (len <= dbuf->len) {
+ dbuf->len = len;
+ return 1;
+ }
+
+ return 0;
+}
+
+
+/*
+ * Append the buf to the end of the buffer.
+ */
+
+int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len)
+{
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ if (_dbuf_expand(dbuf, len) != 0) {
+ memcpy(&(((char *)dbuf->buf)[dbuf->len]), buf, len);
+ dbuf->len += len;
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Prepend the buf to the beginning of the buffer.
+ */
+
+int dbuf_prepend(struct dbuf_s *dbuf, const void *buf, size_t len)
+{
+ assert(dbuf);
+ assert(dbuf->alloc);
+ assert(dbuf->buf);
+
+ if (_dbuf_expand(dbuf, len) != 0) {
+ memmove(&(((char *)dbuf->buf)[len]), dbuf->buf, dbuf->len);
+ memcpy(dbuf->buf, buf, len);
+ dbuf->len += len;
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Add '\0' character at the end of the buffer without
+ * count it in the dbuf->len.
+ */
+
+const char *dbuf_c_str(struct dbuf_s *dbuf)
+{
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ if (_dbuf_expand(dbuf, 1) != 0) {
+ ((char *)dbuf->buf)[dbuf->len] = '\0';
+ return dbuf->buf;
+ }
+
+ return NULL;
+}
+
+
+/*
+ * Get the buffer pointer.
+ */
+
+const void *dbuf_get_buf(const struct dbuf_s *dbuf)
+{
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ return dbuf->buf;
+}
+
+
+/*
+ * Get the buffer length.
+ */
+
+size_t dbuf_get_length(const struct dbuf_s *dbuf)
+{
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ return dbuf->len;
+}
+
+
+/*
+ * Trim the allocated buffer to required size
+ */
+
+int dbuf_trim(struct dbuf_s *dbuf)
+{
+ void *buf;
+
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ buf = realloc(dbuf->buf, dbuf->len);
+
+ if (buf != NULL) {
+ dbuf->alloc = dbuf->len;
+ dbuf->buf = buf;
+ }
+
+ return buf != NULL;
+}
+
+
+/*
+ * Detach the buffer from dbuf structure.
+ * The dbuf structure can be reused by
+ * reinitializing it.
+ *
+ * See: dbuf_init()
+ */
+
+void *dbuf_detach(struct dbuf_s *dbuf)
+{
+ void *ret;
+
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ ret = dbuf->buf;
+ dbuf->buf = NULL;
+ dbuf->len = 0;
+ dbuf->alloc = 0;
+
+ return ret;
+}
+
+
+/*
+ * Add '\0' character at the end of the buffer without
+ * count it in the dbuf->len and detach the buffer from dbuf structure.
+ * The dbuf structure can be reused by reinitializing it.
+ *
+ * See: dbuf_init()
+ */
+
+char *dbuf_detach_c_str(struct dbuf_s *dbuf)
+{
+ dbuf_c_str(dbuf);
+ return dbuf_detach(dbuf);
+}
+
+
+/*
+ * Destroy the dbuf structure and
+ * free the buffer
+ */
+
+void dbuf_destroy(struct dbuf_s *dbuf)
+{
+ free(dbuf_detach(dbuf));
+}
+
+
+/*
+ * Delete dbuf structure on the heap:
+ * destroy it and free the allocated space.
+ * The user's responsablity is not to use
+ * the pointer any more: the best think to do
+ * is to set the pointer to NULL value.
+ *
+ * See dbuf_new()
+ */
+
+void dbuf_delete(struct dbuf_s *dbuf)
+{
+ dbuf_destroy(dbuf);
+ free(dbuf);
+}
+
+
+/*
+ * Free detached buffer.
+ *
+ * See dbuf_detach()
+ */
+
+void dbuf_free(const void *buf)
+{
+ free((void *)buf);
+}
diff --git a/support/util/dbuf.h b/support/util/dbuf.h
new file mode 100644
index 0000000..3e4ce2d
--- /dev/null
+++ b/support/util/dbuf.h
@@ -0,0 +1,65 @@
+/*
+ dbuf.h - Dynamic buffer interface
+ version 1.4.0, 2011-03-27
+
+ Copyright (c) 2002-2011 Borut Razem
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Borut Razem
+ borut.razem@siol.net
+*/
+
+
+#ifndef __DBUF_H
+#define __DBUF_H
+
+#include <stddef.h>
+
+struct dbuf_s {
+ size_t alloc; /* size of allocated buffer in bytes */
+ size_t len; /* actual length of the buffer in bytes */
+ void *buf; /* pointer to the buffer, allocated on heap */
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _dbuf_expand(struct dbuf_s *dbuf, size_t size);
+struct dbuf_s *dbuf_new(size_t size);
+int dbuf_init(struct dbuf_s *dbuf, size_t size);
+int dbuf_is_initialized (struct dbuf_s *dbuf);
+int dbuf_set_length(struct dbuf_s *dbuf, size_t size);
+int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len);
+int dbuf_prepend(struct dbuf_s *dbuf, const void *buf, size_t len);
+const void *dbuf_get_buf(const struct dbuf_s *dbuf);
+size_t dbuf_get_length(const struct dbuf_s *dbuf);
+const char *dbuf_c_str(struct dbuf_s *dbuf);
+int dbuf_trim(struct dbuf_s *dbuf);
+void *dbuf_detach(struct dbuf_s *dbuf);
+char *dbuf_detach_c_str(struct dbuf_s *dbuf);
+void dbuf_destroy(struct dbuf_s *dbuf);
+void dbuf_delete(struct dbuf_s *dbuf);
+void dbuf_free(const void *buf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DBUF_H */
diff --git a/support/util/dbuf_string.c b/support/util/dbuf_string.c
new file mode 100644
index 0000000..434ab2d
--- /dev/null
+++ b/support/util/dbuf_string.c
@@ -0,0 +1,330 @@
+/*
+ dbuf_string.c - Append formatted string to the dynamic buffer
+ version 1.2.2, March 20th, 2012
+
+ Copyright (c) 2002-2012 Borut Razem
+
+ This program 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.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include "dbuf_string.h"
+
+
+/*
+ * Append string to the end of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_append_str (struct dbuf_s *dbuf, const char *str)
+{
+ size_t len;
+ assert (str != NULL);
+
+ len = strlen (str);
+ if (dbuf_append (dbuf, str, len + 1))
+ {
+ --dbuf->len;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+/*
+ * Prepend string to the beginning of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_prepend_str (struct dbuf_s *dbuf, const char *str)
+{
+ size_t len;
+ assert (str != NULL);
+
+ len = strlen (str);
+ return (dbuf_prepend (dbuf, str, len));
+}
+
+/*
+ * Append single character to the end of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_append_char (struct dbuf_s *dbuf, char chr)
+{
+ char buf[2];
+ buf[0] = chr;
+ buf[1] = '\0';
+ if (dbuf_append (dbuf, buf, 2))
+ {
+ --dbuf->len;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+/*
+ * Prepend single character to the end of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_prepend_char (struct dbuf_s *dbuf, char chr)
+{
+ char buf[2];
+ buf[0] = chr;
+ buf[1] = '\0';
+ return (dbuf_prepend_str (dbuf, buf));
+}
+
+/*
+ * Calculate length of the resulting formatted string.
+ *
+ * Borrowed from vasprintf.c
+ */
+
+static int
+calc_result_length (const char *format, va_list args)
+{
+ const char *p = format;
+ /* Add one to make sure that it is never zero, which might cause malloc
+ to return NULL. */
+ int total_width = strlen (format) + 1;
+ va_list ap;
+
+#ifdef va_copy
+ va_copy (ap, args);
+#else
+ memcpy (&ap, &args, sizeof (va_list));
+#endif
+
+ while (*p != '\0')
+ {
+ if (*p++ == '%')
+ {
+ while (strchr ("-+ #0", *p))
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ total_width += strtoul (p, (char **) &p, 10);
+ if (*p == '.')
+ {
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ total_width += strtoul (p, (char **) &p, 10);
+ }
+ while (strchr ("hlL", *p))
+ ++p;
+ /* Should be big enough for any format specifier except %s and floats. */
+ total_width += 30;
+ switch (*p)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ case 'c':
+ (void) va_arg (ap, int);
+ break;
+ case 'f':
+ case 'e':
+ case 'E':
+ case 'g':
+ case 'G':
+ (void) va_arg (ap, double);
+ /* Since an ieee double can have an exponent of 307, we'll
+ make the buffer wide enough to cover the gross case. */
+ total_width += 307;
+ break;
+ case 's':
+ {
+ const char *p = va_arg (ap, char *);
+ total_width += strlen (p ? p : "(null)");
+ }
+ break;
+ case 'p':
+ case 'n':
+ (void) va_arg (ap, char *);
+ break;
+ }
+ p++;
+ }
+ }
+#ifdef va_copy
+ va_end (ap);
+#endif
+ return total_width;
+}
+
+
+/*
+ * Append the formatted string to the end of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_vprintf (struct dbuf_s *dbuf, const char *format, va_list args)
+{
+ int size = calc_result_length (format, args);
+
+ assert (dbuf != NULL);
+ assert (dbuf->alloc != 0);
+ assert (dbuf->buf != NULL);
+
+ if (0 != _dbuf_expand (dbuf, size))
+ {
+ int len = vsprintf (&(((char *)dbuf->buf)[dbuf->len]), format, args);
+
+ if (len >= 0)
+ {
+ /* if written length is greater then the calculated one,
+ we have a buffer overrun! */
+ assert (len <= size);
+ dbuf->len += len;
+ }
+ return len;
+ }
+
+ return 0;
+}
+
+
+/*
+ * Append the formatted string to the end of the buffer.
+ * The buffer is null terminated.
+ */
+
+int
+dbuf_printf (struct dbuf_s *dbuf, const char *format, ...)
+{
+ va_list arg;
+ int len;
+
+ va_start (arg, format);
+ len = dbuf_vprintf (dbuf, format, arg);
+ va_end (arg);
+
+ return len;
+}
+
+
+/*
+ * Append line from file to the dynamic buffer
+ * The buffer is null terminated.
+ */
+
+size_t
+dbuf_getline (struct dbuf_s *dbuf, FILE *infp)
+{
+ int c;
+ char chr;
+
+ while ((c = getc (infp)) != '\n' && c != EOF)
+ {
+ chr = c;
+
+ dbuf_append (dbuf, &chr, 1);
+ }
+
+ /* add trailing NL */
+ if (c == '\n')
+ {
+ chr = c;
+
+ dbuf_append (dbuf, &chr, 1);
+ }
+
+ /* terminate the line without increasing the length */
+ if (0 != _dbuf_expand (dbuf, 1))
+ ((char *)dbuf->buf)[dbuf->len] = '\0';
+
+ return dbuf_get_length (dbuf);
+}
+
+
+/*
+ * Remove trailing newline from the string.
+ * The buffer is null terminated.
+ * It returns the total number of characters removed.
+ */
+
+size_t
+dbuf_chomp (struct dbuf_s *dbuf)
+{
+ size_t i = dbuf->len;
+ size_t ret;
+
+ if (i != 0 && '\n' == ((char *)dbuf->buf)[i - 1])
+ {
+ --i;
+ if (i != 0 && '\r' == ((char *)dbuf->buf)[i - 1])
+ {
+ --i;
+ }
+ }
+
+ ret = dbuf->len - i;
+ dbuf->len = i;
+
+ /* terminate the line without increasing the length */
+ if (_dbuf_expand(dbuf, 1) != 0)
+ ((char *)dbuf->buf)[dbuf->len] = '\0';
+
+ return ret;
+}
+
+
+/*
+ * Write dynamic buffer to the file.
+ */
+
+void
+dbuf_write (struct dbuf_s *dbuf, FILE *dest)
+{
+ fwrite (dbuf_get_buf (dbuf), 1, dbuf_get_length (dbuf), dest);
+}
+
+
+/*
+ * Write dynamic buffer to the file and destroy it.
+ */
+
+void
+dbuf_write_and_destroy (struct dbuf_s *dbuf, FILE *dest)
+{
+ dbuf_write (dbuf, dest);
+
+ dbuf_destroy (dbuf);
+}
diff --git a/support/util/dbuf_string.h b/support/util/dbuf_string.h
new file mode 100644
index 0000000..70e9562
--- /dev/null
+++ b/support/util/dbuf_string.h
@@ -0,0 +1,69 @@
+/*
+ dbuf_string.h - Append formatted string to the dynamic buffer
+ version 1.2.2, March 20th, 2012
+
+ Copyright (c) 2002-2012 Borut Razem
+
+ This program 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.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#ifndef __DBUF_STRING_H
+#define __DBUF_STRING_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "dbuf.h"
+
+/* Attribute `nonnull' was valid as of gcc 3.3. */
+#ifndef ATTRIBUTE_NONNULL
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
+# else
+# define ATTRIBUTE_NONNULL(m)
+# endif /* GNUC >= 3.3 */
+#endif /* ATTRIBUTE_NONNULL */
+
+/* The __-protected variants of `format' and `printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+#ifndef ATTRIBUTE_PRINTF
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
+#else
+# define ATTRIBUTE_PRINTF(m, n)
+# endif /* GNUC >= 2.7 */
+#endif /* ATTRIBUTE_PRINTF */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int dbuf_append_str(struct dbuf_s *dbuf, const char *str);
+int dbuf_prepend_str(struct dbuf_s *dbuf, const char *str);
+int dbuf_append_char(struct dbuf_s *dbuf, char chr);
+int dbuf_prepend_char(struct dbuf_s *dbuf, char chr);
+int dbuf_vprintf(struct dbuf_s *dbuf, const char *format, va_list args);
+int dbuf_printf (struct dbuf_s *dbuf, const char *format, ...) ATTRIBUTE_PRINTF(2, 3);
+size_t dbuf_getline(struct dbuf_s *dbuf, FILE *infp);
+size_t dbuf_chomp (struct dbuf_s *dbuf);
+void dbuf_write (struct dbuf_s *dbuf, FILE *dest);
+void dbuf_write_and_destroy (struct dbuf_s *dbuf, FILE *dest);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DBUF_STRING_H */
diff --git a/support/util/findme.c b/support/util/findme.c
new file mode 100644
index 0000000..c509214
--- /dev/null
+++ b/support/util/findme.c
@@ -0,0 +1,59 @@
+/** \ingroup popt
+ * \file popt/findme.c
+ */
+
+/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
+ file accompanying popt source distributions, available from
+ ftp://ftp.rpm.org/pub/rpm/dist.
+
+ alloca replaced with malloc()/free() pair */
+
+#include "system.h"
+#include "findme.h"
+
+const char * findProgramPath(const char * argv0) {
+ char * path = getenv("PATH");
+ char * pathbuf;
+ char * start, * chptr;
+ char * buf;
+
+ if (argv0 == NULL) return NULL; /* XXX can't happen */
+ /* If there is a / in the argv[0], it has to be an absolute path */
+ if (strchr(argv0, '/'))
+ return xstrdup(argv0);
+
+ if (path == NULL) return NULL;
+
+ start = pathbuf = malloc(strlen(path) + 1);
+ if (pathbuf == NULL) return NULL;
+ buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
+ if (buf == NULL) { /* XXX can't happen */
+ free(pathbuf);
+ return NULL;
+ }
+ strcpy(pathbuf, path);
+
+ chptr = NULL;
+ /*@-branchstate@*/
+ do {
+ if ((chptr = strchr(start, ':')))
+ *chptr = '\0';
+ sprintf(buf, "%s/%s", start, argv0);
+
+ if (!access(buf, X_OK)) {
+ free(pathbuf);
+ return buf;
+ }
+
+ if (chptr)
+ start = chptr + 1;
+ else
+ start = NULL;
+ } while (start && *start);
+ /*@=branchstate@*/
+
+ free(buf);
+ free(pathbuf);
+
+ return NULL;
+}
diff --git a/support/util/findme.h b/support/util/findme.h
new file mode 100644
index 0000000..a016b86
--- /dev/null
+++ b/support/util/findme.h
@@ -0,0 +1,20 @@
+/** \ingroup popt
+ * \file popt/findme.h
+ */
+
+/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
+ file accompanying popt source distributions, available from
+ ftp://ftp.rpm.org/pub/rpm/dist. */
+
+#ifndef H_FINDME
+#define H_FINDME
+
+/**
+ * Return absolute path to executable by searching PATH.
+ * @param argv0 name of executable
+ * @return (malloc'd) absolute path to executable (or NULL)
+ */
+/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0)
+ /*@*/;
+
+#endif
diff --git a/support/util/newalloc.h b/support/util/newalloc.h
new file mode 100644
index 0000000..4da6932
--- /dev/null
+++ b/support/util/newalloc.h
@@ -0,0 +1,99 @@
+/*-------------------------------------------------------------------------
+ newalloc.h - SDCC Memory allocation functions
+
+ These functions are wrappers for the standard malloc, realloc and free
+ functions.
+
+ This program 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.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-------------------------------------------------------------------------*/
+
+#if !defined(_NewAlloc_H)
+
+#define _NewAlloc_H
+
+#include <memory.h>
+
+typedef struct _allocTrace
+{
+ int num;
+ int max;
+ void **palloced;
+} allocTrace;
+
+/*
+-------------------------------------------------------------------------------
+Clear_realloc - Reallocate a memory block and clear any memory added with
+out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *Clear_realloc (void *OldPtr, size_t OldSize, size_t NewSize);
+
+/*
+-------------------------------------------------------------------------------
+Safe_realloc - Reallocate a memory block with out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_realloc (void *OldPtr, size_t NewSize);
+
+/*
+-------------------------------------------------------------------------------
+Safe_calloc - Allocate a block of memory from the application heap, clearing
+all data to zero and checking for out or memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_calloc (size_t Elements, size_t Size);
+
+/*
+-------------------------------------------------------------------------------
+Safe_malloc - Allocate a block of memory from the application heap
+and checking for out or memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_malloc (size_t Size);
+
+/** Replacement for Safe_malloc that also zeros memory. To make it interchangable.
+ */
+void *Safe_alloc (size_t Size);
+
+/** Function to make the replacements complete.
+ */
+void Safe_free (void *p);
+
+/** Creates a copy of a string with specified length in a safe way.
+ */
+char *Safe_strndup (const char *sz, size_t len);
+
+/** Creates a copy of a string in a safe way.
+ */
+char *Safe_strdup (const char *sz);
+
+/** Logs the allocated memory 'p' in the given trace for batch freeing
+ later using freeTrace.
+*/
+void *traceAlloc (allocTrace * ptrace, void *p);
+
+/** Frees all the memory logged in the trace and resets the trace.
+ */
+void freeTrace (allocTrace * ptrace);
+
+#endif
diff --git a/support/util/pstdint.h b/support/util/pstdint.h
new file mode 100644
index 0000000..3c53b2f
--- /dev/null
+++ b/support/util/pstdint.h
@@ -0,0 +1,678 @@
+/* A portable stdint.h
+ *
+ * Copyright (c) 2005 Paul Hsieh
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must not misrepresent the orignal
+ * source in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * The names of the authors not its contributors may be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************
+ *
+ * Version 0.1.5
+ *
+ * The ANSI C standard committee, for the C99 standard, specified the
+ * inclusion of a new standard include file called stdint.h. This is
+ * a very useful and long desired include file which contains several
+ * very precise definitions for integer scalar types that is
+ * critically important for making portable several classes of
+ * applications including cryptography, hashing, variable length
+ * integer libraries and so on. But for most developers its likely
+ * useful just for programming sanity.
+ *
+ * The problem is that most compiler vendors have decided not to
+ * implement the C99 standard, and the next C++ language standard
+ * (which has a lot more mindshare these days) will be a long time in
+ * coming and its unknown whether or not it will include stdint.h or
+ * how much adoption it will have. Either way, it will be a long time
+ * before all compilers come with a stdint.h and it also does nothing
+ * for the extremely large number of compilers available today which
+ * do not include this file, or anything comparable to it.
+ *
+ * So that's what this file is all about. Its an attempt to build a
+ * single universal include file that works on as many platforms as
+ * possible to deliver what stdint.h is supposed to. A few things
+ * that should be noted about this file:
+ *
+ * 1) It is not guaranteed to be portable and/or present an identical
+ * interface on all platforms. The extreme variability of the
+ * ANSI C standard makes this an impossibility right from the
+ * very get go. Its really only meant to be useful for the vast
+ * majority of platforms that possess the capability of
+ * implementing usefully and precisely defined, standard sized
+ * integer scalars. Systems which are not intrinsically 2s
+ * complement may produce invalid constants.
+ *
+ * 2) There is an unavoidable use of non-reserved symbols.
+ *
+ * 3) Other standard include files are invoked.
+ *
+ * 4) This file may come in conflict with future platforms that do
+ * include stdint.h. The hope is that one or the other can be
+ * used with no real difference.
+ *
+ * 5) In the current verison, if your platform can't represent
+ * int32_t, int16_t and int8_t, it just dumps out with a compiler
+ * error.
+ *
+ * 6) 64 bit integers may or may not be defined. Test for their
+ * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
+ * Note that this is different from the C99 specification which
+ * requires the existence of 64 bit support in the compiler. If
+ * this is not defined for your platform, yet it is capable of
+ * dealing with 64 bits then it is because this file has not yet
+ * been extended to cover all of your system's capabilities.
+ *
+ * 7) (u)intptr_t may or may not be defined. Test for its presence
+ * with the test: #ifdef PTRDIFF_MAX. If this is not defined
+ * for your platform, then it is because this file has not yet
+ * been extended to cover all of your system's capabilities, not
+ * because its optional.
+ *
+ * 8) The following might not been defined even if your platform is
+ * capable of defining it:
+ *
+ * WCHAR_MIN
+ * WCHAR_MAX
+ * (u)int64_t
+ * PTRDIFF_MIN
+ * PTRDIFF_MAX
+ * (u)intptr_t
+ *
+ * 9) The following have not been defined:
+ *
+ * WINT_MIN
+ * WINT_MAX
+ *
+ * 10) The criteria for defining (u)int_least(*)_t isn't clear,
+ * except for systems which don't have a type that precisely
+ * defined 8, 16, or 32 bit types (which this include file does
+ * not support anyways). Default definitions have been given.
+ *
+ * 11) The criteria for defining (u)int_fast(*)_t isn't something I
+ * would trust to any particular compiler vendor or the ANSI C
+ * comittee. It is well known that "compatible systems" are
+ * commonly created that have very different performance
+ * characteristics from the systems they are compatible with,
+ * especially those whose vendors make both the compiler and the
+ * system. Default definitions have been given, but its strongly
+ * recommended that users never use these definitions for any
+ * reason (they do *NOT* deliver any serious guarantee of
+ * improved performance -- not in this file, nor any vendor's
+ * stdint.h).
+ *
+ * 12) The following macros:
+ *
+ * PRINTF_INTMAX_MODIFIER
+ * PRINTF_INT64_MODIFIER
+ * PRINTF_INT32_MODIFIER
+ * PRINTF_INT16_MODIFIER
+ * PRINTF_LEAST64_MODIFIER
+ * PRINTF_LEAST32_MODIFIER
+ * PRINTF_LEAST16_MODIFIER
+ * PRINTF_INTPTR_MODIFIER
+ *
+ * are strings which have been defined as the modifiers required
+ * for the "d", "u" and "x" printf formats to correctly output
+ * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
+ * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
+ * PRINTF_INTPTR_MODIFIER is not defined for some systems which
+ * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
+ * defined if INT64_MAX is not defined. These are an extension
+ * beyond what C99 specifies must be in stdint.h.
+ *
+ * In addition, the following macros are defined:
+ *
+ * PRINTF_INTMAX_HEX_WIDTH
+ * PRINTF_INT64_HEX_WIDTH
+ * PRINTF_INT32_HEX_WIDTH
+ * PRINTF_INT16_HEX_WIDTH
+ * PRINTF_INT8_HEX_WIDTH
+ * PRINTF_INTMAX_DEC_WIDTH
+ * PRINTF_INT64_DEC_WIDTH
+ * PRINTF_INT32_DEC_WIDTH
+ * PRINTF_INT16_DEC_WIDTH
+ * PRINTF_INT8_DEC_WIDTH
+ *
+ * Which specifies the maximum number of characters required to
+ * print the number of that type in either hexadecimal or decimal.
+ * These are an extension beyond what C99 specifies must be in
+ * stdint.h.
+ *
+ * Compilers tested (all with 0 warnings at their highest respective
+ * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
+ * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
+ * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
+ *
+ * This file should be considered a work in progress. Suggestions for
+ * improvements, especially those which increase coverage are strongly
+ * encouraged.
+ *
+ * Acknowledgements
+ *
+ * The following people have made significant contributions to the
+ * development and testing of this file:
+ *
+ * Chris Howie
+ * John Steele Scott
+ *
+ */
+
+#include <stddef.h>
+#include <limits.h>
+#include <signal.h>
+
+/*
+ * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
+ * do nothing else.
+ */
+
+#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && defined(_STDINT_H))) && !defined (_PSTDINT_H_INCLUDED)
+#include <stdint.h>
+#define _PSTDINT_H_INCLUDED
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
+# endif
+# ifndef PRINTF_INT64_HEX_WIDTH
+# define PRINTF_INT64_HEX_WIDTH "16"
+# endif
+# ifndef PRINTF_INT32_HEX_WIDTH
+# define PRINTF_INT32_HEX_WIDTH "8"
+# endif
+# ifndef PRINTF_INT16_HEX_WIDTH
+# define PRINTF_INT16_HEX_WIDTH "4"
+# endif
+# ifndef PRINTF_INT8_HEX_WIDTH
+# define PRINTF_INT8_HEX_WIDTH "2"
+# endif
+# ifndef PRINTF_INT64_DEC_WIDTH
+# define PRINTF_INT64_DEC_WIDTH "20"
+# endif
+# ifndef PRINTF_INT32_DEC_WIDTH
+# define PRINTF_INT32_DEC_WIDTH "10"
+# endif
+# ifndef PRINTF_INT16_DEC_WIDTH
+# define PRINTF_INT16_DEC_WIDTH "5"
+# endif
+# ifndef PRINTF_INT8_DEC_WIDTH
+# define PRINTF_INT8_DEC_WIDTH "3"
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
+# endif
+#endif
+
+#ifndef _PSTDINT_H_INCLUDED
+#define _PSTDINT_H_INCLUDED
+
+#ifndef SIZE_MAX
+# define SIZE_MAX (~(size_t)0)
+#endif
+
+/*
+ * Deduce the type assignments from limits.h under the assumption that
+ * integer sizes in bits are powers of 2, and follow the ANSI
+ * definitions.
+ */
+
+#ifndef UINT8_MAX
+# define UINT8_MAX 0xff
+#endif
+#ifndef uint8_t
+# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
+ typedef unsigned char uint8_t;
+# define UINT8_C(v) ((uint8_t) v)
+# else
+# error "Platform not supported"
+# endif
+#endif
+
+#ifndef INT8_MAX
+# define INT8_MAX 0x7f
+#endif
+#ifndef INT8_MIN
+# define INT8_MIN INT8_C(0x80)
+#endif
+#ifndef int8_t
+# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
+ typedef signed char int8_t;
+# define INT8_C(v) ((int8_t) v)
+# else
+# error "Platform not supported"
+# endif
+#endif
+
+#ifndef UINT16_MAX
+# define UINT16_MAX 0xffff
+#endif
+#ifndef uint16_t
+#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
+ typedef unsigned int uint16_t;
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER ""
+# endif
+# define UINT16_C(v) ((uint16_t) (v))
+#elif (USHRT_MAX == UINT16_MAX)
+ typedef unsigned short uint16_t;
+# define UINT16_C(v) ((uint16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef INT16_MAX
+# define INT16_MAX 0x7fff
+#endif
+#ifndef INT16_MIN
+# define INT16_MIN INT16_C(0x8000)
+#endif
+#ifndef int16_t
+#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
+ typedef signed int int16_t;
+# define INT16_C(v) ((int16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER ""
+# endif
+#elif (SHRT_MAX == INT16_MAX)
+ typedef signed short int16_t;
+# define INT16_C(v) ((int16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef UINT32_MAX
+# define UINT32_MAX (0xffffffffUL)
+#endif
+#ifndef uint32_t
+#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
+ typedef unsigned long uint32_t;
+# define UINT32_C(v) v ## UL
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+#elif (UINT_MAX == UINT32_MAX)
+ typedef unsigned int uint32_t;
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+# define UINT32_C(v) v ## U
+#elif (USHRT_MAX == UINT32_MAX)
+ typedef unsigned short uint32_t;
+# define UINT32_C(v) ((unsigned short) (v))
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef INT32_MAX
+# define INT32_MAX (0x7fffffffL)
+#endif
+#ifndef INT32_MIN
+# define INT32_MIN INT32_C(0x80000000)
+#endif
+#ifndef int32_t
+#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
+ typedef signed long int32_t;
+# define INT32_C(v) v ## L
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+#elif (INT_MAX == INT32_MAX)
+ typedef signed int int32_t;
+# define INT32_C(v) v
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#elif (SHRT_MAX == INT32_MAX)
+ typedef signed short int32_t;
+# define INT32_C(v) ((short) (v))
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+/*
+ * The macro stdint_int64_defined is temporarily used to record
+ * whether or not 64 integer support is available. It must be
+ * defined for any 64 integer extensions for new platforms that are
+ * added.
+ */
+
+#undef stdint_int64_defined
+#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
+# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
+# define stdint_int64_defined
+ typedef long long int64_t;
+ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# endif
+#endif
+
+#if !defined (stdint_int64_defined)
+# if defined(__GNUC__)
+# define stdint_int64_defined
+ __extension__ typedef long long int64_t;
+ __extension__ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
+# define stdint_int64_defined
+ typedef long long int64_t;
+ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
+# define stdint_int64_defined
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+# define UINT64_C(v) v ## UI64
+# define INT64_C(v) v ## I64
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "I64"
+# endif
+# endif
+#endif
+
+#if !defined (LONG_LONG_MAX) && defined (INT64_C)
+# define LONG_LONG_MAX INT64_C (9223372036854775807)
+#endif
+#ifndef ULONG_LONG_MAX
+# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
+#endif
+
+#if !defined (INT64_MAX) && defined (INT64_C)
+# define INT64_MAX INT64_C (9223372036854775807)
+#endif
+#if !defined (INT64_MIN) && defined (INT64_C)
+# define INT64_MIN INT64_C (-9223372036854775808)
+#endif
+#if !defined (UINT64_MAX) && defined (INT64_C)
+# define UINT64_MAX UINT64_C (18446744073709551615)
+#endif
+
+/*
+ * Width of hexadecimal for number field.
+ */
+
+#ifndef PRINTF_INT64_HEX_WIDTH
+# define PRINTF_INT64_HEX_WIDTH "16"
+#endif
+#ifndef PRINTF_INT32_HEX_WIDTH
+# define PRINTF_INT32_HEX_WIDTH "8"
+#endif
+#ifndef PRINTF_INT16_HEX_WIDTH
+# define PRINTF_INT16_HEX_WIDTH "4"
+#endif
+#ifndef PRINTF_INT8_HEX_WIDTH
+# define PRINTF_INT8_HEX_WIDTH "2"
+#endif
+
+#ifndef PRINTF_INT64_DEC_WIDTH
+# define PRINTF_INT64_DEC_WIDTH "20"
+#endif
+#ifndef PRINTF_INT32_DEC_WIDTH
+# define PRINTF_INT32_DEC_WIDTH "10"
+#endif
+#ifndef PRINTF_INT16_DEC_WIDTH
+# define PRINTF_INT16_DEC_WIDTH "5"
+#endif
+#ifndef PRINTF_INT8_DEC_WIDTH
+# define PRINTF_INT8_DEC_WIDTH "3"
+#endif
+
+/*
+ * Ok, lets not worry about 128 bit integers for now. Moore's law says
+ * we don't need to worry about that until about 2040 at which point
+ * we'll have bigger things to worry about.
+ */
+
+#ifdef stdint_int64_defined
+ typedef int64_t intmax_t;
+ typedef uint64_t uintmax_t;
+# define INTMAX_MAX INT64_MAX
+# define INTMAX_MIN INT64_MIN
+# define UINTMAX_MAX UINT64_MAX
+# define UINTMAX_C(v) UINT64_C(v)
+# define INTMAX_C(v) INT64_C(v)
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
+# endif
+#else
+ typedef int32_t intmax_t;
+ typedef uint32_t uintmax_t;
+# define INTMAX_MAX INT32_MAX
+# define UINTMAX_MAX UINT32_MAX
+# define UINTMAX_C(v) UINT32_C(v)
+# define INTMAX_C(v) INT32_C(v)
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
+# endif
+#endif
+
+/*
+ * Because this file currently only supports platforms which have
+ * precise powers of 2 as bit sizes for the default integers, the
+ * least definitions are all trivial. Its possible that a future
+ * version of this file could have different definitions.
+ */
+
+#ifndef stdint_least_defined
+ typedef int8_t int_least8_t;
+ typedef uint8_t uint_least8_t;
+ typedef int16_t int_least16_t;
+ typedef uint16_t uint_least16_t;
+ typedef int32_t int_least32_t;
+ typedef uint32_t uint_least32_t;
+# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
+# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
+# define UINT_LEAST8_MAX UINT8_MAX
+# define INT_LEAST8_MAX INT8_MAX
+# define UINT_LEAST16_MAX UINT16_MAX
+# define INT_LEAST16_MAX INT16_MAX
+# define UINT_LEAST32_MAX UINT32_MAX
+# define INT_LEAST32_MAX INT32_MAX
+# define INT_LEAST8_MIN INT8_MIN
+# define INT_LEAST16_MIN INT16_MIN
+# define INT_LEAST32_MIN INT32_MIN
+# ifdef stdint_int64_defined
+ typedef int64_t int_least64_t;
+ typedef uint64_t uint_least64_t;
+# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
+# define UINT_LEAST64_MAX UINT64_MAX
+# define INT_LEAST64_MAX INT64_MAX
+# define INT_LEAST64_MIN INT64_MIN
+# endif
+#endif
+#undef stdint_least_defined
+
+/*
+ * The ANSI C committee pretending to know or specify anything about
+ * performance is the epitome of misguided arrogance. The mandate of
+ * this file is to *ONLY* ever support that absolute minimum
+ * definition of the fast integer types, for compatibility purposes.
+ * No extensions, and no attempt to suggest what may or may not be a
+ * faster integer type will ever be made in this file. Developers are
+ * warned to stay away from these types when using this or any other
+ * stdint.h.
+ */
+
+typedef int_least8_t int_fast8_t;
+typedef uint_least8_t uint_fast8_t;
+typedef int_least16_t int_fast16_t;
+typedef uint_least16_t uint_fast16_t;
+typedef int_least32_t int_fast32_t;
+typedef uint_least32_t uint_fast32_t;
+#define UINT_FAST8_MAX UINT_LEAST8_MAX
+#define INT_FAST8_MAX INT_LEAST8_MAX
+#define UINT_FAST16_MAX UINT_LEAST16_MAX
+#define INT_FAST16_MAX INT_LEAST16_MAX
+#define UINT_FAST32_MAX UINT_LEAST32_MAX
+#define INT_FAST32_MAX INT_LEAST32_MAX
+#define INT_FAST8_MIN IN_LEASTT8_MIN
+#define INT_FAST16_MIN INT_LEAST16_MIN
+#define INT_FAST32_MIN INT_LEAST32_MIN
+#ifdef stdint_int64_defined
+ typedef int_least64_t int_fast64_t;
+ typedef uint_least64_t uint_fast64_t;
+# define UINT_FAST64_MAX UINT_LEAST64_MAX
+# define INT_FAST64_MAX INT_LEAST64_MAX
+# define INT_FAST64_MIN INT_LEAST64_MIN
+#endif
+
+#undef stdint_int64_defined
+
+/*
+ * Whatever piecemeal, per compiler thing we can do about the wchar_t
+ * type limits.
+ */
+
+#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
+# include <wchar.h>
+# ifndef WCHAR_MIN
+# define WCHAR_MIN 0
+# endif
+# ifndef WCHAR_MAX
+# define WCHAR_MAX ((wchar_t)-1)
+# endif
+#endif
+
+/*
+ * Whatever piecemeal, per compiler/platform thing we can do about the
+ * (u)intptr_t types and limits.
+ */
+
+#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
+# define STDINT_H_UINTPTR_T_DEFINED
+#endif
+
+#ifndef STDINT_H_UINTPTR_T_DEFINED
+# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
+# define stdint_intptr_bits 64
+# elif defined (__WATCOMC__) || defined (__TURBOC__)
+# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
+# define stdint_intptr_bits 16
+# else
+# define stdint_intptr_bits 32
+# endif
+# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
+# define stdint_intptr_bits 32
+# elif defined (__INTEL_COMPILER)
+/* TODO -- what will Intel do about x86-64? */
+# endif
+
+# ifdef stdint_intptr_bits
+# define stdint_intptr_glue3_i(a,b,c) a##b##c
+# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
+# ifndef PRINTF_INTPTR_MODIFIER
+# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
+# endif
+# ifndef PTRDIFF_MAX
+# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef PTRDIFF_MIN
+# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
+# endif
+# ifndef UINTPTR_MAX
+# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef INTPTR_MAX
+# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef INTPTR_MIN
+# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
+# endif
+# ifndef INTPTR_C
+# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
+# endif
+# ifndef UINTPTR_C
+# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
+# endif
+ typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
+ typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
+# else
+/* TODO -- This following is likely wrong for some platforms, and does
+ nothing for the definition of uintptr_t. */
+ typedef ptrdiff_t intptr_t;
+# endif
+# define STDINT_H_UINTPTR_T_DEFINED
+#endif
+
+/*
+ * Assumes sig_atomic_t is signed and we have a 2s complement machine.
+ */
+
+#ifndef SIG_ATOMIC_MAX
+# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
+#endif
+
+#endif
diff --git a/support/util/system.h b/support/util/system.h
new file mode 100644
index 0000000..6bb01cd
--- /dev/null
+++ b/support/util/system.h
@@ -0,0 +1,37 @@
+/*
+ system.h - includes, required by findme.c
+
+ Copyright (c) 2004 Borut Razem
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Borut Razem
+ borut.razem@siol.net
+*/
+
+#ifndef _SYSTEM_H
+#define _SYSTEM_H
+
+/* findme.c is compiled only on *nix, so includes are *nix specific */
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define xstrdup(_str) strdup(_str)
+
+#endif /* _SYSTEM_H */