File: strings.c

package info (click to toggle)
libast1 0.4-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 972 kB
  • ctags: 426
  • sloc: sh: 8,807; ansic: 2,874; makefile: 81
file content (736 lines) | stat: -rw-r--r-- 18,381 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/*
 * Copyright (C) 1997-2001, Michael Jennings
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies of the Software, its documentation and marketing & publicity
 * materials, and acknowledgment shall be given in the documentation, materials
 * and software packages that this Software was used.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

static const char cvs_ident[] = "$Id: strings.c,v 1.8 2001/06/12 00:03:21 mej Exp $";

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <libast_internal.h>

#ifndef HAVE_MEMMEM
/* Find first occurance of bytestring needle of size needlelen in memory region
   haystack of size haystacklen */
void *
memmem(const void *haystack, register size_t haystacklen, const void *needle, register size_t needlelen)
{
  register char *hs = (char *) haystack;
  register char *n = (char *) needle;
  register unsigned long i;
  register size_t len = haystacklen - needlelen;

  for (i = 0; i < len; i++) {
    if (!memcmp(hs + i, n, needlelen)) {
      return (hs + i);
    }
  }
  return (NULL);
}
#endif

#ifndef HAVE_USLEEP
void
usleep(unsigned long usec)
{
  struct timeval delay;

  delay.tv_sec = 0;
  delay.tv_usec = usec;
  select(0, NULL, NULL, NULL, &delay);

}

#endif

/***** Not needed ******
#ifndef HAVE_NANOSLEEP
__inline__ void
nanosleep(unsigned long nsec) {
    usleep(nsec / 1000);
}
#endif
************************/

/* Return the leftmost cnt characters of str */
char *
left_str(const char *str, unsigned long cnt)
{
  char *tmpstr;

  REQUIRE_RVAL(str != NULL, NULL);
  REQUIRE_RVAL(cnt <= strlen(str), NULL);
  REQUIRE_RVAL(cnt > 0, NULL);

  tmpstr = (char *) MALLOC(cnt + 1);
  strncpy(tmpstr, str, cnt);
  tmpstr[cnt] = 0;
  return (tmpstr);
}

/* Return cnt characters from str, starting at position index (from 0) */
char *
mid_str(const char *str, unsigned long index, unsigned long cnt)
{
  char *tmpstr;
  const char *pstr = str;
  size_t len;

  REQUIRE_RVAL(str != NULL, NULL);
  len = strlen(str);
  REQUIRE_RVAL(index < len, NULL);
  REQUIRE_RVAL(cnt <= len, NULL);
  REQUIRE_RVAL(cnt > 0, NULL);

  tmpstr = (char *) MALLOC(cnt + 1);
  pstr += index;
  strncpy(tmpstr, pstr, cnt);
  tmpstr[cnt] = 0;
  return (tmpstr);
}

/* Return the rightmost characters of str */
char *
right_str(const char *str, unsigned long cnt)
{
  char *tmpstr;
  const char *pstr = str;

  REQUIRE_RVAL(str != NULL, NULL);
  REQUIRE_RVAL(cnt <= strlen(str), NULL);
  REQUIRE_RVAL(cnt > 0, NULL);

  tmpstr = (char *) MALLOC(cnt + 1);
  pstr += strlen(str);
  pstr -= cnt;
  strcpy(tmpstr, pstr);
  return (tmpstr);
}

/* Returns TRUE if str matches regular expression pattern, FALSE otherwise */
#if defined(HAVE_REGEX_H)
unsigned char
regexp_match(register const char *str, register const char *pattern)
{
  static regex_t *rexp = NULL;
  register int result;
  char errbuf[256];

  if (!rexp) {
    rexp = (regex_t *) MALLOC(sizeof(regex_t));
  }

  REQUIRE_RVAL(str != NULL, FALSE);

  if (pattern) {
    if ((result = regcomp(rexp, pattern, REG_EXTENDED)) != 0) {
      regerror(result, rexp, errbuf, 256);
      print_error("Unable to compile regexp %s -- %s.\n", pattern, errbuf);
      return (FALSE);
    }
  }

  if (((result = regexec(rexp, str, (size_t) 0, (regmatch_t *) NULL, 0))
       != 0) && (result != REG_NOMATCH)) {
    regerror(result, rexp, errbuf, 256);
    print_error("Error testing input string %s -- %s.\n", str, errbuf);
    return (FALSE);
  }
  return (!result);
}

unsigned char
regexp_match_r(register const char *str, register const char *pattern, register regex_t **rexp)
{
  register int result;
  char errbuf[256];

  ASSERT_RVAL(rexp != NULL, FALSE);
  if (*rexp == NULL) {
    *rexp = (regex_t *) MALLOC(sizeof(regex_t));
  }

  if (pattern) {
    if ((result = regcomp(*rexp, pattern, REG_EXTENDED)) != 0) {
      regerror(result, *rexp, errbuf, 256);
      print_error("Unable to compile regexp %s -- %s.\n", pattern, errbuf);
      FREE(*rexp);
      return (FALSE);
    }
  }

  if (((result = regexec(*rexp, str, (size_t) 0, (regmatch_t *) NULL, 0))
       != 0) && (result != REG_NOMATCH)) {
    regerror(result, *rexp, errbuf, 256);
    print_error("Error testing input string %s -- %s.\n", str, errbuf);
    return (FALSE);
  }
  return (!result);
}
#endif

#define IS_DELIM(c)  ((delim != NULL) ? (strchr(delim, (c)) != NULL) : (isspace(c)))
#define IS_QUOTE(c)  (quote && quote == (c))

char **
split(const char *delim, const char *str)
{
  char **slist;
  register const char *pstr;
  register char *pdest;
  char quote = 0;
  unsigned short cnt = 0;
  unsigned long len;

  REQUIRE_RVAL(str != NULL, (char **) NULL);

  if ((slist = (char **) MALLOC(sizeof(char *))) == NULL) {
    print_error("split():  Unable to allocate memory -- %s\n", strerror(errno));
    return ((char **) NULL);
  }

  /* Before we do anything, skip leading "whitespace." */
  for (pstr = str; *pstr && IS_DELIM(*pstr); pstr++);

  /* The outermost for loop is where we traverse the string.  Each new
     word brings us back to the top where we resize our string list. */
  for (; *pstr; cnt++) {
    /* First, resize the list to two bigger than our count.  Why two?
       One for the string we're about to do, and one for a trailing NULL. */
    if ((slist = (char **) REALLOC(slist, sizeof(char *) * (cnt + 2))) == NULL) {
      print_error("split():  Unable to allocate memory -- %s\n", strerror(errno));
      return ((char **) NULL);
    }

    /* The string we're about to create can't possibly be larger than the remainder
       of the string we have yet to parse, so allocate that much space to start. */
    len = strlen(pstr) + 1;
    if ((slist[cnt] = (char *) MALLOC(len)) == NULL) {
      print_error("split():  Unable to allocate memory -- %s.\n", strerror(errno));
      return ((char **) NULL);
    }
    pdest = slist[cnt];

    /* This for loop is where we process each character. */
    for (; *pstr && (quote || !IS_DELIM(*pstr));) {
      if (*pstr == '\"' || *pstr == '\'') {
        /* It's a quote character, so set or reset the quote variable. */
        if (quote) {
          if (quote == *pstr) {
            quote = 0;
          } else {
            /* It's a single quote inside double quotes, or vice versa.  Leave it alone. */
            *pdest++ = *pstr++;
          }
        } else {
          quote = *pstr;
        }
        pstr++;
      } else {
        /* Handle any backslashes that are escaping delimiters or quotes. */
        if ((*pstr == '\\') && (IS_DELIM(*(pstr + 1)) || IS_QUOTE(*(pstr + 1)))) {
          /* Incrementing pstr here moves us past the backslash so that the line
             below will copy the next character to the new token, no questions asked. */
          pstr++;
        }
        *pdest++ = *pstr++;
      }
    }
    /* Add the trailing \0 to terminate the new string. */
    *pdest = 0;

    /* Reallocate the new string to be just the right size. */
    len = strlen(slist[cnt]) + 1;
    slist[cnt] = (char *) REALLOC(slist[cnt], len);

    /* Move past any trailing "whitespace." */
    for (; *pstr && IS_DELIM(*pstr); pstr++);
  }
  if (cnt == 0) {
    return NULL;
  } else {
    /* The last element of slist[] should be NULL. */
    slist[cnt] = 0;
    return slist;
  }
}

char **
split_regexp(const char *regexp, const char *str)
{
  USE_VAR(regexp);
  USE_VAR(str);
  return (NULL);
}

char *
join(const char *sep, char **slist)
{
  register unsigned long i;
  size_t len, slen;
  char *new_str;

  if (sep == NULL) {
    sep = "";
  }
  slen = strlen(sep);
  for (i = len = 0; slist[i]; i++) {
    len += strlen(slist[i]);
  }
  len += slen * (i - 1);
  new_str = (char *) MALLOC(len);
  strcpy(new_str, slist[0]);
  for (i = 1; slist[i]; i++) {
    if (slen) {
      strcat(new_str, sep);
    }
    strcat(new_str, slist[i]);
  }
  return new_str;
}

/* Return malloc'd pointer to index-th word in str.  "..." counts as 1 word. */
#undef IS_DELIM
#define IS_DELIM(c)  (delim ? ((c) == delim) : isspace(c))

char *
get_word(unsigned long index, const char *str)
{
  char *tmpstr;
  char delim = 0;
  register unsigned long i, j, k;

  k = strlen(str) + 1;
  if ((tmpstr = (char *) MALLOC(k)) == NULL) {
    print_error("get_word(%lu, %s):  Unable to allocate memory -- %s.\n",
	    index, str, strerror(errno));
    return ((char *) NULL);
  }
  *tmpstr = 0;
  for (i = 0, j = 0; j < index && str[i]; j++) {
    for (; isspace(str[i]); i++);
    switch (str[i]) {
      case '\"':
	delim = '\"';
	i++;
	break;
      case '\'':
	delim = '\'';
	i++;
	break;
      default:
	delim = 0;
    }
    for (k = 0; str[i] && !IS_DELIM(str[i]);) {
      if (str[i] == '\\') {
	if (str[i + 1] == '\'' || str[i + 1] == '\"') {
	  i++;
	}
      }
      tmpstr[k++] = str[i++];
    }
    switch (str[i]) {
      case '\"':
      case '\'':
	i++;
	break;
    }
    tmpstr[k] = 0;
  }

  if (j != index) {
    FREE(tmpstr);
    D_STRINGS(("get_word(%lu, %s) returning NULL.\n", index, str));
    return ((char *) NULL);
  } else {
    tmpstr = (char *) REALLOC(tmpstr, strlen(tmpstr) + 1);
    D_STRINGS(("get_word(%lu, %s) returning \"%s\".\n", index, str, tmpstr));
    return (tmpstr);
  }
}

/* Return pointer into str to index-th word in str.  "..." counts as 1 word. */
char *
get_pword(unsigned long index, const char *str)
{
  register const char *tmpstr = str;
  register unsigned long j;

  if (!str)
    return ((char *) NULL);
  for (; isspace(*tmpstr) && *tmpstr; tmpstr++);
  for (j = 1; j < index && *tmpstr; j++) {
    for (; !isspace(*tmpstr) && *tmpstr; tmpstr++);
    for (; isspace(*tmpstr) && *tmpstr; tmpstr++);
  }

  if (*tmpstr == '\"' || *tmpstr == '\'') {
    tmpstr++;
  }
  if (*tmpstr == '\0') {
    D_STRINGS(("get_pword(%lu, %s) returning NULL.\n", index, str));
    return ((char *) NULL);
  } else {
    D_STRINGS(("get_pword(%lu, %s) returning \"%s\"\n", index, str, tmpstr));
    return (char *) tmpstr;
  }
}

/* Returns the number of words in str, for use with get_word() and get_pword().  "..." counts as 1 word. */
unsigned long
num_words(const char *str)
{
  register unsigned long cnt = 0;
  char delim = 0;
  register unsigned long i;

  for (i = 0; str[i] && IS_DELIM(str[i]); i++);
  for (; str[i]; cnt++) {
    switch (str[i]) {
      case '\"':
	delim = '\"';
	i++;
	break;
      case '\'':
	delim = '\'';
	i++;
	break;
      default:
	delim = 0;
    }
    for (; str[i] && !IS_DELIM(str[i]); i++);
    switch (str[i]) {
      case '\"':
      case '\'':
	i++;
	break;
    }
    for (; str[i] && isspace(str[i]); i++);
  }

  D_STRINGS(("num_words() returning %lu\n", cnt));
  return (cnt);
}

/* chomp() removes leading and trailing whitespace from a string */
char *
chomp(char *s)
{

  register char *front, *back;

  ASSERT_RVAL(s != NULL, NULL);
  for (front = s; *front && isspace(*front); front++);
  for (back = s + strlen(s) - 1; *back && isspace(*back) && back > front; back--);

  *(++back) = 0;
  if (front != s) {
    memmove(s, front, back - front + 1);
  }
  return (s);
}

char *
strip_whitespace(register char *str)
{
  register unsigned long i, j;

  ASSERT_RVAL(str != NULL, NULL);
  if ((j = strlen(str))) {
    for (i = j - 1; isspace(*(str + i)); i--);
    str[j = i + 1] = 0;
    for (i = 0; isspace(*(str + i)); i++);
    j -= i;
    memmove(str, str + i, j + 1);
  }
  return (str);
}

char *
downcase_str(char *str)
{
  register char *tmp;

  for (tmp = str; *tmp; tmp++) {
    *tmp = tolower(*tmp);
  }
  D_STRINGS(("downcase_str() returning %s\n", str));
  return (str);
}

char *
upcase_str(char *str)
{
  register char *tmp;

  for (tmp = str; *tmp; tmp++) {
    *tmp = toupper(*tmp);
  }
  D_STRINGS(("upcase_str() returning %s\n", str));
  return (str);
}

#ifndef HAVE_STRCASESTR
char *
strcasestr(const char *haystack, register const char *needle)
{
  register const char *t;
  register size_t len = strlen(needle);

  for (t = haystack; t && *t; t++) {
    if (!strncasecmp(t, needle, len)) {
      return ((char *) t);
    }
  }
  return (NULL);
}
#endif

#ifndef HAVE_STRCASECHR
char *
strcasechr(const char *haystack, register const char needle)
{
  register const char *t;

  for (t = haystack; t && *t; t++) {
    if (tolower(*t) == tolower(needle)) {
      return ((char *) t);
    }
  }
  return (NULL);
}
#endif

#ifndef HAVE_STRCASEPBRK
char *
strcasepbrk(const char *haystack, register const char *needle)
{
  register const char *t;

  for (t = haystack; t && *t; t++) {
    if (strcasechr(needle, *t)) {
      return ((char *) t);
    }
  }
  return (NULL);
}
#endif

#ifndef HAVE_STRREV
char *
strrev(register char *str)
{
  register int i, j;

  i = strlen(str);
  for (j = 0, i--; i > j; i--, j++) {
    SWAP(str[j], str[i]);
  }
  return (str);

}
#endif

#if !(HAVE_STRSEP)
char *
strsep(char **str, register char *sep)
{

  register char *s = *str;
  char *sptr;

  D_STRINGS(("strsep(%s, %s) called.\n", *str, sep));
  sptr = s;
  for (; *s && !strchr(sep, *s); s++);
  if (!*s) {
    if (s != sptr) {
      *str = s;
      D_STRINGS(("Reached end of string with token \"%s\" in buffer\n", sptr));
      return (sptr);
    } else {
      D_STRINGS(("Reached end of string\n"));
      return ((char *) NULL);
    }
  }
  *s = 0;
  *str = s + 1;
  D_STRINGS(("Got token \"%s\", *str == \"%s\"\n", sptr, *str));
  return (sptr);
}
#endif

char *
garbage_collect(char *buff, size_t len)
{

  register char *tbuff = buff, *pbuff = buff;
  register unsigned long i, j;

  D_STRINGS(("Garbage collecting on %lu bytes at %10.8p\n", len, buff));
  for (i = 0, j = 0; j < len; j++)
    if (pbuff[j])
      tbuff[i++] = pbuff[j];
  tbuff[i++] = '\0';
  D_STRINGS(("Garbage collecting gives: \n%s\n", buff));
  return ((char *) REALLOC(buff, sizeof(char) * i));
}

char *
file_garbage_collect(char *buff, size_t len)
{

  register char *tbuff = buff, *pbuff = buff;
  char *tmp1, *tmp2;
  register unsigned long j;

  D_STRINGS(("File garbage collecting on %lu bytes at %10.8p\n", len, buff));
  for (j = 0; j < len;) {
    switch (pbuff[j]) {
      case '#':
	for (; !strchr("\r\n", pbuff[j]) && j < len; j++)
	  pbuff[j] = '\0';	/* First null out the line up to the CR and/or LF */
	for (; strchr("\r\n", pbuff[j]) && j < len; j++)
	  pbuff[j] = '\0';	/* Then null out the CR and/or LF */
	break;
      case '\r':
      case '\n':
      case '\f':
      case ' ':
      case '\t':
      case '\v':
	for (; isspace(pbuff[j]) && j < len; j++)
	  pbuff[j] = '\0';	/* Null out the whitespace */
	break;
      default:
	/* Find the end of this line and the occurence of the
	   next mid-line comment. */
	tmp1 = strpbrk(pbuff + j, "\r\n");
	tmp2 = strstr(pbuff + j, " #");

	/* If either is null, take the non-null one.  Otherwise,
	   take the lesser of the two. */
	if (!tmp1 || !tmp2) {
	  tbuff = ((tmp1) ? (tmp1) : (tmp2));
	} else {
	  tbuff = ((tmp1 < tmp2) ? (tmp1) : (tmp2));
	}

	/* Now let j catch up so that pbuff+j = tbuff; i.e., let
	   pbuff[j] refer to the same character that tbuff does */
	j += tbuff - (pbuff + j);

	/* Finally, change whatever is at pbuff[j] to a newline.
	   This will accomplish several things at once:
	   o It will change a \r to a \n if that's what's there
	   o If it's a \n, it'll stay the same.  No biggie.
	   o If it's a space, it will end the line there and the
	   next line will begin with a comment, which is handled
	   above. */
	if (j < len)
	  pbuff[j++] = '\n';

    }
  }

  /* Change all occurances of a backslash followed by a newline to nulls
     and null out all whitespace up to the next non-whitespace character.
     This handles support for breaking a string across multiple lines. */
  for (j = 0; j < len; j++) {
    if (pbuff[j] == '\\' && pbuff[j + 1] == '\n') {
      pbuff[j++] = '\0';
      for (; isspace(pbuff[j]) && j < len; j++)
	pbuff[j] = '\0';	/* Null out the whitespace */
    }
  }

  /* And the final step, garbage collect the buffer to condense all
     those nulls we just put in. */
  return (garbage_collect(buff, len));
}

char *
condense_whitespace(char *s)
{

  register unsigned char gotspc = 0;
  register char *pbuff = s, *pbuff2 = s;

  D_STRINGS(("condense_whitespace(%s) called.\n", s));
  for (; *pbuff2; pbuff2++) {
    if (isspace(*pbuff2)) {
      if (!gotspc) {
	*pbuff = ' ';
	gotspc = 1;
	pbuff++;
      }
    } else {
      *pbuff = *pbuff2;
      gotspc = 0;
      pbuff++;
    }
  }
  if ((pbuff >= s) && (isspace(*(pbuff - 1))))
    pbuff--;
  *pbuff = 0;
  D_STRINGS(("condense_whitespace() returning \"%s\".\n", s));
  return (REALLOC(s, strlen(s) + 1));
}

char *
safe_str(register char *str, unsigned short len)
{
  register unsigned short i;

  for (i = 0; i < len; i++) {
    if (iscntrl(str[i])) {
      str[i] = '.';
    }
  }

  return (str);
}

void
hex_dump(void *buff, register size_t count)
{

  register unsigned long j, k, l;
  register unsigned char *ptr;
  unsigned char buffr[9];

  print_error(" Address |  Size  | Offset  | 00 01 02 03 04 05 06 07 |  ASCII  \n");
  print_error("---------+--------+---------+-------------------------+---------\n");
  for (ptr = (unsigned char *) buff, j = 0; j < count; j += 8) {
    print_error(" %8p | %06lu | %07x | ", buff, (unsigned long) count, (unsigned int) j);
    l = ((count - j < 8) ? (count - j) : (8));
    memset(buffr, 0, 9);
    memcpy(buffr, ptr + j, l);
    for (k = 0; k < l; k++) {
      print_error("%02x ", buffr[k]);
    }
    for (; k < 8; k++) {
      print_error("   ");
    }
    print_error("| %-8s\n", safe_str((char *) buffr, l));
  }
}