summaryrefslogtreecommitdiffstats
path: root/cescape.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2024-11-12 13:36:10 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2024-11-12 13:36:10 +0000
commit8d51757e02818146b05c805b81e167f118fca7dc (patch)
treeda5d2ae457f7255a403d9665a2777f6c225ba304 /cescape.c
parent1fc39c620f2a9737851ef45ec77b2461ce1b7c30 (diff)
downloadcquine-8d51757e02818146b05c805b81e167f118fca7dc.tar.gz
cquine-8d51757e02818146b05c805b81e167f118fca7dc.tar.xz
cquine-8d51757e02818146b05c805b81e167f118fca7dc.zip
The quineHEADmaster
Diffstat (limited to 'cescape.c')
-rw-r--r--cescape.c21
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;
+ }
+ }
+}