1#include "parser.h"
2
3
4/*******************************************************************
5 Count the number of characters (not bytes) in a unicode string.
6********************************************************************/
7size_t strlen_w(void *src)
8{
9	size_t len;
10
11	for (len = 0; SVAL(src, len*2); len++) ;
12
13	return len;
14}
15
16/****************************************************************************
17expand a pointer to be a particular size
18****************************************************************************/
19void *Realloc(void *p,size_t size)
20{
21  void *ret=NULL;
22
23  if (size == 0) {
24    if (p) free(p);
25    DEBUG(5,("Realloc asked for 0 bytes\n"));
26    return NULL;
27  }
28
29  if (!p)
30    ret = (void *)malloc(size);
31  else
32    ret = (void *)realloc(p,size);
33
34  if (!ret)
35    DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
36
37  return(ret);
38}
39
40
41char *tab_depth(int depth)
42{
43	static pstring spaces;
44	memset(spaces, ' ', depth * 4);
45	spaces[depth * 4] = 0;
46	return spaces;
47}
48
49void print_asc(int level, uchar const *buf, int len)
50{
51	int i;
52	for (i = 0; i < len; i++)
53	{
54		DEBUGADD(level, ("%c", isprint(buf[i]) ? buf[i] : '.'));
55	}
56}
57
58void dump_data(int level, char *buf1, int len)
59{
60	uchar const *buf = (uchar const *)buf1;
61	int i = 0;
62	if (buf == NULL)
63	{
64		DEBUG(level, ("dump_data: NULL, len=%d\n", len));
65		return;
66	}
67	if (len < 0)
68		return;
69	if (len == 0)
70	{
71		DEBUG(level, ("\n"));
72		return;
73	}
74
75	DEBUG(level, ("[%03X] ", i));
76	for (i = 0; i < len;)
77	{
78		DEBUGADD(level, ("%02X ", (int)buf[i]));
79		i++;
80		if (i % 8 == 0)
81			DEBUGADD(level, (" "));
82		if (i % 16 == 0)
83		{
84			print_asc(level, &buf[i - 16], 8);
85			DEBUGADD(level, (" "));
86			print_asc(level, &buf[i - 8], 8);
87			DEBUGADD(level, ("\n"));
88			if (i < len)
89				DEBUGADD(level, ("[%03X] ", i));
90		}
91	}
92
93	if (i % 16 != 0)	/* finish off a non-16-char-length row */
94	{
95		int n;
96
97		n = 16 - (i % 16);
98		DEBUGADD(level, (" "));
99		if (n > 8)
100			DEBUGADD(level, (" "));
101		while (n--)
102			DEBUGADD(level, ("   "));
103
104		n = MIN(8, i % 16);
105		print_asc(level, &buf[i - (i % 16)], n);
106		DEBUGADD(level, (" "));
107		n = (i % 16) - n;
108		if (n > 0)
109			print_asc(level, &buf[i - n], n);
110		DEBUGADD(level, ("\n"));
111	}
112}
113