diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-11-12 13:36:10 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-11-12 13:36:10 +0000 |
commit | 8d51757e02818146b05c805b81e167f118fca7dc (patch) | |
tree | da5d2ae457f7255a403d9665a2777f6c225ba304 /cescape.c | |
parent | 1fc39c620f2a9737851ef45ec77b2461ce1b7c30 (diff) | |
download | cquine-master.tar.gz cquine-master.tar.xz cquine-master.zip |
Diffstat (limited to 'cescape.c')
-rw-r--r-- | cescape.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cescape.c b/cescape.c new file mode 100644 index 0000000..3fd5ac2 --- /dev/null +++ b/cescape.c @@ -0,0 +1,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; + } + } +} |