summaryrefslogtreecommitdiffstats
path: root/cquine.in.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 /cquine.in.c
parent1fc39c620f2a9737851ef45ec77b2461ce1b7c30 (diff)
downloadcquine-master.tar.gz
cquine-master.tar.xz
cquine-master.zip
The quineHEADmaster
Diffstat (limited to 'cquine.in.c')
-rw-r--r--cquine.in.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/cquine.in.c b/cquine.in.c
new file mode 100644
index 0000000..42860c8
--- /dev/null
+++ b/cquine.in.c
@@ -0,0 +1,27 @@
+// SPDX-FileCopyrightText: 2024 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-LicenseIdentifier: GPL-3.0-or-later
+
+#include <stdio.h>
+#include <string.h>
+
+void escape(char *dest, const char *src)
+{
+ for (size_t i = 0; src[i] != '\0'; i++) {
+ switch (src[i]) {
+ case '\t': *dest++ = '\\'; *dest++ = 't'; break;
+ case '\n': *dest++ = '\\'; *dest++ = 'n'; break;
+ case '"': *dest++ = '\\'; *dest++ = '"'; break;
+ case '\\': *dest++ = '\\'; *dest++ = '\\'; break;
+ default: *dest++ = src[i]; break;
+ }
+ }
+ *dest = '\0';
+}
+
+int main(void)
+{
+ const char *program = "%s";
+ char escaped[strlen(program) * 2 + 1];
+ escape(escaped, program);
+ printf(program, escaped);
+}