aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/winpty/misc/FormatChar.h
blob: aade488f9e26b23ea15e9d3730ba818f8aab1c7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <ctype.h>
#include <stdio.h>
#include <string.h>

static inline void formatChar(char *str, char ch)
{
    // Print some common control codes.
    switch (ch) {
    case '\r': strcpy(str, "CR "); break;
    case '\n': strcpy(str, "LF "); break;
    case ' ':  strcpy(str, "SP "); break;
    case 27:   strcpy(str, "^[ "); break;
    case 3:    strcpy(str, "^C "); break;
    default:
        if (isgraph(ch))
            sprintf(str, "%c ", ch);
        else
            sprintf(str, "%02x ", ch);
        break;
    }
}