From a848231ae0f346dc7cc000973fbeb65b0894ee92 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 21:59:03 +0200 Subject: Adding upstream version 3.8.5. Signed-off-by: Daniel Baumann --- mantools/comment.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 mantools/comment.c (limited to 'mantools/comment.c') diff --git a/mantools/comment.c b/mantools/comment.c new file mode 100644 index 0000000..4372d44 --- /dev/null +++ b/mantools/comment.c @@ -0,0 +1,66 @@ +#include + +void copy_comment() +{ + int c; + + while ((c = getchar()) != EOF) { + if (c == '*') { + if ((c = getchar()) == '/') { + putchar('\n'); + return; + } + if (c != EOF) + ungetc(c, stdin); + putchar('*'); + } else { + putchar(c); + } + } +} + +void skip_string(int quote) +{ + int c; + + while ((c = getchar()) != EOF) { + if (c == quote) { + return; + } else if (c == '\\') { + getchar(); + } + } +} + +int main() +{ + int c; + + while ((c = getchar()) != EOF) { + switch (c) { + case '/': + if ((c = getchar()) == '*') { + copy_comment(); + } else if (c == '/') { + while ((c = getchar()) != EOF) { + putchar(c); + if (c == '\n') + break; + } + } else { + if (c != EOF) + ungetc(c, stdin); + } + break; + case '"': + case '\'': + skip_string(c); + break; + case '\\': + (void) getchar(); + break; + default: + break; + } + } +} -- cgit v1.2.3