Janitorial duties to make autogen.sh portable.
[Samba/gebeck_regimport.git] / source3 / aparser / util.c
blobffa84dbfabcc89e70a16652de2096d971b295913
1 #include "parser.h"
4 /*******************************************************************
5 Count the number of characters (not bytes) in a unicode string.
6 ********************************************************************/
7 size_t strlen_w(void *src)
9 size_t len;
11 for (len = 0; SVAL(src, len*2); len++) ;
13 return len;
16 /****************************************************************************
17 expand a pointer to be a particular size
18 ****************************************************************************/
19 void *Realloc(void *p,size_t size)
21 void *ret=NULL;
23 if (size == 0) {
24 if (p) free(p);
25 DEBUG(5,("Realloc asked for 0 bytes\n"));
26 return NULL;
29 if (!p)
30 ret = (void *)malloc(size);
31 else
32 ret = (void *)realloc(p,size);
34 if (!ret)
35 DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
37 return(ret);
41 char *tab_depth(int depth)
43 static pstring spaces;
44 memset(spaces, ' ', depth * 4);
45 spaces[depth * 4] = 0;
46 return spaces;
49 void print_asc(int level, uchar const *buf, int len)
51 int i;
52 for (i = 0; i < len; i++)
54 DEBUGADD(level, ("%c", isprint(buf[i]) ? buf[i] : '.'));
58 void dump_data(int level, char *buf1, int len)
60 uchar const *buf = (uchar const *)buf1;
61 int i = 0;
62 if (buf == NULL)
64 DEBUG(level, ("dump_data: NULL, len=%d\n", len));
65 return;
67 if (len < 0)
68 return;
69 if (len == 0)
71 DEBUG(level, ("\n"));
72 return;
75 DEBUG(level, ("[%03X] ", i));
76 for (i = 0; i < len;)
78 DEBUGADD(level, ("%02X ", (int)buf[i]));
79 i++;
80 if (i % 8 == 0)
81 DEBUGADD(level, (" "));
82 if (i % 16 == 0)
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));
93 if (i % 16 != 0) /* finish off a non-16-char-length row */
95 int n;
97 n = 16 - (i % 16);
98 DEBUGADD(level, (" "));
99 if (n > 8)
100 DEBUGADD(level, (" "));
101 while (n--)
102 DEBUGADD(level, (" "));
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"));