Pristine Ack-5.5
[Ack-5.5.git] / modules / src / string / bts2str.c
1 /* $Id: bts2str.c,v 1.9 1994/06/24 11:22:22 ceriel Exp $ */
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
11 #include "ack_string.h"
12
13 #define is_print(c)     ((unsigned)((c) - ' ') <= '~' - ' ')
14
15 char *
16 bts2str(b, n, s)
17         char *b, *s;
18         register int n;
19 {
20         register char *f = b, *t = s;
21
22         while (n-- > 0) {
23                 if (is_print(*f)) {
24                         if (*f == '\\' || *f == '"') *t++ = '\\';
25                         *t++ = *f++;
26                 } else {
27                         *t++ = '\\';
28                         *t++ = ((*f >> 6) & 03) + '0';
29                         *t++ = ((*f >> 3) & 07) + '0';
30                         *t++ = (*f++ & 07) + '0';
31                 }
32         }
33         *t = '\000';
34         return s;
35 }