blob: f6ada4904ecc9b793df144624837db9addcac43d [file] [log] [blame]
Denis Vlasenko27963982007-12-30 20:13:39 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
Denis Vlasenkod18f52b2008-03-02 12:53:15 +00005 * Copyright (C) 2007 Denys Vlasenko
Denis Vlasenko27963982007-12-30 20:13:39 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenko27963982007-12-30 20:13:39 +00008 */
9
10#include "libbb.h"
11
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000012void FAST_FUNC fputc_printable(int ch, FILE *file)
Denis Vlasenko27963982007-12-30 20:13:39 +000013{
14 if ((ch & (0x80 + PRINTABLE_META)) == (0x80 + PRINTABLE_META)) {
15 fputs("M-", file);
16 ch &= 0x7f;
17 }
18 ch = (unsigned char) ch;
19 if (ch == 0x9b) {
20 /* VT100's CSI, aka Meta-ESC, is not printable on vt-100 */
21 ch = '{';
22 goto print_caret;
23 }
24 if (ch < ' ') {
25 ch += '@';
26 goto print_caret;
27 }
28 if (ch == 0x7f) {
29 ch = '?';
30 print_caret:
31 fputc('^', file);
32 }
33 fputc(ch, file);
34}