summaryrefslogtreecommitdiffstats
path: root/cescape.c
blob: 3fd5ac270a16e759c65debaf74f00415f24c5186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// SPDX-FileCopyrightText: 2024 Tomasz Kramkowski <tomasz@kramkow.ski>
// SPDX-LicenseIdentifier: GPL-3.0-or-later

// A tool to produce escaped C strings.
// Only escapes tabs, newlines, double quotes and backslashes.

#include <stdio.h>

int main(void)
{
	int c;
	while (c = getchar(), c != EOF) {
		switch (c) {
		case '\t': fputs("\\t", stdout); break;
		case '\n': fputs("\\n", stdout); break;
		case '"': fputs("\\\"", stdout); break;
		case '\\': fputs("\\\\", stdout); break;
		default: putchar(c); break;
		}
	}
}