ARPDAS_QNX6 1.0
|
00001 #include <ctype.h> 00002 #include "nortlib.h" 00003 00004 /** 00005 * @return Pointer to a static buffer containing a NUL-terminated 00006 * rendition of the input string in printable characters. The output 00007 * string is limited to 82 characters, and is truncated if necessary. 00008 */ 00009 #define ESC_BUF_SIZE 80 00010 const char *ascii_escape(const char *ibuf) { 00011 static char ebuf[ESC_BUF_SIZE+3]; 00012 int ix = 0, ox = 0; 00013 while (ibuf[ix] != '\0' && ox < ESC_BUF_SIZE ) { 00014 int c = (unsigned char)ibuf[ix++]; 00015 if ( isprint(c) ) { 00016 ebuf[ox++] = c; 00017 } else { 00018 switch ( c ) { 00019 case '\n': 00020 ebuf[ox++] = '\\'; 00021 ebuf[ox++] = 'n'; 00022 break; 00023 case '\r': 00024 ebuf[ox++] = '\\'; 00025 ebuf[ox++] = 'r'; 00026 break; 00027 case '\t': 00028 ebuf[ox++] = '\\'; 00029 ebuf[ox++] = 't'; 00030 break; 00031 default: 00032 ox += snprintf( ebuf+ox, 4, "\\x%02x", c); 00033 break; 00034 } 00035 } 00036 } 00037 ebuf[ox] = '\0'; 00038 return ebuf; 00039 }