This source file includes following definitions.
- init_sh_quoting_options
- shell_quote_length
- shell_quote_copy
- shell_quote
- shell_quote_argv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20
21 #include "sh-quote.h"
22
23 #include <string.h>
24
25 #include "quotearg.h"
26 #include "xalloc.h"
27
28
29 static struct quoting_options *sh_quoting_options;
30
31
32 static void
33 init_sh_quoting_options ()
34 {
35 sh_quoting_options = clone_quoting_options (NULL);
36 set_quoting_style (sh_quoting_options, shell_quoting_style);
37 }
38
39
40 size_t
41 shell_quote_length (const char *string)
42 {
43 if (sh_quoting_options == NULL)
44 init_sh_quoting_options ();
45 return quotearg_buffer (NULL, 0, string, strlen (string),
46 sh_quoting_options);
47 }
48
49
50
51 char *
52 shell_quote_copy (char *p, const char *string)
53 {
54 if (sh_quoting_options == NULL)
55 init_sh_quoting_options ();
56 return p + quotearg_buffer (p, (size_t)(-1), string, strlen (string),
57 sh_quoting_options);
58 }
59
60
61 char *
62 shell_quote (const char *string)
63 {
64 if (sh_quoting_options == NULL)
65 init_sh_quoting_options ();
66 return quotearg_alloc (string, strlen (string), sh_quoting_options);
67 }
68
69
70
71 char *
72 shell_quote_argv (const char * const *argv)
73 {
74 if (*argv != NULL)
75 {
76 const char * const *argp;
77 size_t length;
78 char *command;
79 char *p;
80
81 length = 0;
82 for (argp = argv; ; )
83 {
84 length += shell_quote_length (*argp) + 1;
85 argp++;
86 if (*argp == NULL)
87 break;
88 }
89
90 command = XNMALLOC (length, char);
91
92 p = command;
93 for (argp = argv; ; )
94 {
95 p = shell_quote_copy (p, *argp);
96 argp++;
97 if (*argp == NULL)
98 break;
99 *p++ = ' ';
100 }
101 *p = '\0';
102
103 return command;
104 }
105 else
106 return xstrdup ("");
107 }