bts2str.c 727 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* bts2str() turns a row of bytes b with length n into string s
  7. The ASCII set of characters is used.
  8. 86/03/17 EHB
  9. */
  10. #include "ack_string.h"
  11. #define is_print(c) ((unsigned)((c) - ' ') <= '~' - ' ')
  12. char *
  13. bts2str(b, n, s)
  14. char *b, *s;
  15. register int n;
  16. {
  17. register char *f = b, *t = s;
  18. while (n-- > 0) {
  19. if (is_print(*f)) {
  20. if (*f == '\\' || *f == '"') *t++ = '\\';
  21. *t++ = *f++;
  22. } else {
  23. *t++ = '\\';
  24. *t++ = ((*f >> 6) & 03) + '0';
  25. *t++ = ((*f >> 3) & 07) + '0';
  26. *t++ = (*f++ & 07) + '0';
  27. }
  28. }
  29. *t = '\000';
  30. return s;
  31. }