summaryrefslogtreecommitdiff
path: root/source3/aparser/util.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-06-09 02:59:50 +0000
committerAndrew Tridgell <tridge@samba.org>2000-06-09 02:59:50 +0000
commiteee003da6aee5ffc00e318fc0390e6b19151a675 (patch)
tree3cdb43304603d5bc38c2b2609fa8696731c898d5 /source3/aparser/util.c
parentc3487b00dd1dde7fa0511211f466acc1c05d8f3d (diff)
downloadsamba-eee003da6aee5ffc00e318fc0390e6b19151a675.tar.gz
samba-eee003da6aee5ffc00e318fc0390e6b19151a675.tar.bz2
samba-eee003da6aee5ffc00e318fc0390e6b19151a675.zip
started adding support for relative, plus options for autoalignment
so the same parser generator can be uses for cifs and rpc (This used to be commit c7829fa0d87081d9b3f33468527583e3b763916b)
Diffstat (limited to 'source3/aparser/util.c')
-rw-r--r--source3/aparser/util.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/source3/aparser/util.c b/source3/aparser/util.c
new file mode 100644
index 0000000000..ffa84dbfab
--- /dev/null
+++ b/source3/aparser/util.c
@@ -0,0 +1,112 @@
+#include "parser.h"
+
+
+/*******************************************************************
+ Count the number of characters (not bytes) in a unicode string.
+********************************************************************/
+size_t strlen_w(void *src)
+{
+ size_t len;
+
+ for (len = 0; SVAL(src, len*2); len++) ;
+
+ return len;
+}
+
+/****************************************************************************
+expand a pointer to be a particular size
+****************************************************************************/
+void *Realloc(void *p,size_t size)
+{
+ void *ret=NULL;
+
+ if (size == 0) {
+ if (p) free(p);
+ DEBUG(5,("Realloc asked for 0 bytes\n"));
+ return NULL;
+ }
+
+ if (!p)
+ ret = (void *)malloc(size);
+ else
+ ret = (void *)realloc(p,size);
+
+ if (!ret)
+ DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
+
+ return(ret);
+}
+
+
+char *tab_depth(int depth)
+{
+ static pstring spaces;
+ memset(spaces, ' ', depth * 4);
+ spaces[depth * 4] = 0;
+ return spaces;
+}
+
+void print_asc(int level, uchar const *buf, int len)
+{
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ DEBUGADD(level, ("%c", isprint(buf[i]) ? buf[i] : '.'));
+ }
+}
+
+void dump_data(int level, char *buf1, int len)
+{
+ uchar const *buf = (uchar const *)buf1;
+ int i = 0;
+ if (buf == NULL)
+ {
+ DEBUG(level, ("dump_data: NULL, len=%d\n", len));
+ return;
+ }
+ if (len < 0)
+ return;
+ if (len == 0)
+ {
+ DEBUG(level, ("\n"));
+ return;
+ }
+
+ DEBUG(level, ("[%03X] ", i));
+ for (i = 0; i < len;)
+ {
+ DEBUGADD(level, ("%02X ", (int)buf[i]));
+ i++;
+ if (i % 8 == 0)
+ DEBUGADD(level, (" "));
+ if (i % 16 == 0)
+ {
+ print_asc(level, &buf[i - 16], 8);
+ DEBUGADD(level, (" "));
+ print_asc(level, &buf[i - 8], 8);
+ DEBUGADD(level, ("\n"));
+ if (i < len)
+ DEBUGADD(level, ("[%03X] ", i));
+ }
+ }
+
+ if (i % 16 != 0) /* finish off a non-16-char-length row */
+ {
+ int n;
+
+ n = 16 - (i % 16);
+ DEBUGADD(level, (" "));
+ if (n > 8)
+ DEBUGADD(level, (" "));
+ while (n--)
+ DEBUGADD(level, (" "));
+
+ n = MIN(8, i % 16);
+ print_asc(level, &buf[i - (i % 16)], n);
+ DEBUGADD(level, (" "));
+ n = (i % 16) - n;
+ if (n > 0)
+ print_asc(level, &buf[i - n], n);
+ DEBUGADD(level, ("\n"));
+ }
+}