ack/modules/src/string/bts2str.c
carl 3214ddfa68 Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
2019-02-19 00:54:23 +08:00

35 lines
723 B
C

/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* bts2str() turns a row of bytes b with length n into string s
The ASCII set of characters is used.
86/03/17 EHB
*/
#include "ack_string.h"
#define is_print(c) ((unsigned)((c) - ' ') <= '~' - ' ')
char *bts2str(char *b, register int n, char *s)
{
register char *f = b, *t = s;
while (n-- > 0) {
if (is_print(*f)) {
if (*f == '\\' || *f == '"') *t++ = '\\';
*t++ = *f++;
} else {
*t++ = '\\';
*t++ = ((*f >> 6) & 03) + '0';
*t++ = ((*f >> 3) & 07) + '0';
*t++ = (*f++ & 07) + '0';
}
}
*t = '\000';
return s;
}