]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4f5dd394 LP |
2 | #pragma once |
3 | ||
4f5dd394 | 4 | #include <inttypes.h> |
11c3a366 TA |
5 | #include <stddef.h> |
6 | #include <stdint.h> | |
71d35b6b | 7 | #include <sys/types.h> |
c932fb71 | 8 | #include <uchar.h> |
4f5dd394 | 9 | |
11c3a366 | 10 | #include "string-util.h" |
c932fb71 | 11 | #include "missing.h" |
11c3a366 | 12 | |
4f5dd394 LP |
13 | /* What characters are special in the shell? */ |
14 | /* must be escaped outside and inside double-quotes */ | |
15 | #define SHELL_NEED_ESCAPE "\"\\`$" | |
804ee07c ZJS |
16 | |
17 | /* Those that can be escaped or double-quoted. | |
18 | * | |
19 | * Stricly speaking, ! does not need to be escaped, except in interactive | |
20 | * mode, but let's be extra nice to the user and quote ! in case this | |
21 | * output is ever used in interactive mode. */ | |
22 | #define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!" | |
23 | ||
24 | /* Note that we assume control characters would need to be escaped too in | |
25 | * addition to the "special" characters listed here, if they appear in the | |
26 | * string. Current users disallow control characters. Also '"' shall not | |
27 | * be escaped. | |
28 | */ | |
29 | #define SHELL_NEED_ESCAPE_POSIX "\\\'" | |
4f5dd394 LP |
30 | |
31 | typedef enum UnescapeFlags { | |
32 | UNESCAPE_RELAX = 1, | |
33 | } UnescapeFlags; | |
34 | ||
804ee07c ZJS |
35 | typedef enum EscapeStyle { |
36 | ESCAPE_BACKSLASH = 1, | |
37 | ESCAPE_POSIX = 2, | |
38 | } EscapeStyle; | |
39 | ||
4f5dd394 | 40 | char *cescape(const char *s); |
a5ef3638 | 41 | char *cescape_length(const char *s, size_t n); |
b778252b | 42 | int cescape_char(char c, char *buf); |
4f5dd394 LP |
43 | |
44 | int cunescape(const char *s, UnescapeFlags flags, char **ret); | |
45 | int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret); | |
46 | int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret); | |
c932fb71 | 47 | int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit); |
4f5dd394 LP |
48 | |
49 | char *xescape(const char *s, const char *bad); | |
95052df3 | 50 | char *octescape(const char *s, size_t len); |
4f5dd394 LP |
51 | |
52 | char *shell_escape(const char *s, const char *bad); | |
804ee07c | 53 | char* shell_maybe_quote(const char *s, EscapeStyle style); |