Created
March 29, 2024 14:10
-
-
Save outlyer/420b5b4b93fa9c3cfa0e9548c6e5f66a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(int argc, char ** argv) { | |
char c = '\0'; | |
int i = 0; | |
int j = 1; | |
/* Do not care if no arguments are passed; escaped nothing is still nothing. */ | |
if (argc < 2) { | |
return 0; | |
} | |
while (j < argc) { | |
while (i < strlen(argv[j])) { | |
c = argv[j][i]; | |
/* This switch has no breaks on purpose. */ | |
switch (c) { | |
case ';': | |
case '\'': | |
case ' ': | |
case '!': | |
case '"': | |
case '#': | |
case '$': | |
case '&': | |
case '(': | |
case ')': | |
case '|': | |
case '*': | |
case ',': | |
case '<': | |
case '>': | |
case '[': | |
case ']': | |
case '\\': | |
case '^': | |
case '`': | |
case '{': | |
case '}': | |
putchar('\\'); | |
default: | |
putchar(c); | |
} | |
i++; | |
} | |
j++; | |
if (j < argc) { | |
putchar(' '); | |
} | |
i = 0; | |
} | |
/* Newline at the end */ | |
putchar('\n'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment