bts2str.c 725 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* $Header$ */
  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. #define is_print(c) ((unsigned)((c) - ' ') <= '~' - ' ')
  11. char *
  12. bts2str(b, n, s)
  13. char *b, *s;
  14. register int n;
  15. {
  16. register char *f = b, *t = s;
  17. while (n-- > 0) {
  18. if (is_print(*f))
  19. *t++ = *f++;
  20. else {
  21. register int n = (*f++ & 0377);
  22. register int i;
  23. register char *p;
  24. *t = '\\';
  25. p = (t += 4);
  26. for (i = 0; i < 3; i++) {
  27. *--p = (n & 07) + '0';
  28. n >>= 3;
  29. }
  30. }
  31. }
  32. *t = '\000';
  33. return s;
  34. }