Mercurial > hg > octave-shane > gnulib-hg
annotate lib/system-quote.h @ 17282:a4996fb12971
locale: port to Solaris 2.6 and 7 + GNU gettext
* lib/locale.in.h: Just include_next <locale.h> when
being invoked recursively. This prevents problems on Solaris 2.6 and 7
when combining the localename module with GNU gettext 0.18.2.
Problem reported by Tom G. Christensen in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-01/msg00084.html>.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 10 Jan 2013 13:24:13 -0800 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
16841 | 1 /* Quoting for a system command. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16849
diff
changeset
|
2 Copyright (C) 2001-2013 Free Software Foundation, Inc. |
16841 | 3 Written by Bruno Haible <bruno@clisp.org>, 2012. |
4 | |
5 This program is free software: you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 3 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | |
18 #ifndef _SYSTEM_QUOTE_H | |
19 #define _SYSTEM_QUOTE_H | |
20 | |
21 /* When passing a command the system's command interpreter, we must quote the | |
22 program name and arguments, since | |
16848
ae444fc80840
sh-quote, system-quote: Add comments about wildcards.
Bruno Haible <bruno@clisp.org>
parents:
16844
diff
changeset
|
23 - Unix shells interpret characters like " ", "'", "<", ">", "$", '*', '?' |
ae444fc80840
sh-quote, system-quote: Add comments about wildcards.
Bruno Haible <bruno@clisp.org>
parents:
16844
diff
changeset
|
24 etc. in a special way, |
16841 | 25 - Windows CreateProcess() interprets characters like ' ', '\t', '\\', '"' |
26 etc. (but not '<' and '>') in a special way, | |
27 - Windows cmd.exe also interprets characters like '<', '>', '&', '%', etc. | |
28 in a special way. Note that it is impossible to pass arguments that | |
29 contain newlines or carriage return characters to programs through | |
16848
ae444fc80840
sh-quote, system-quote: Add comments about wildcards.
Bruno Haible <bruno@clisp.org>
parents:
16844
diff
changeset
|
30 cmd.exe. |
ae444fc80840
sh-quote, system-quote: Add comments about wildcards.
Bruno Haible <bruno@clisp.org>
parents:
16844
diff
changeset
|
31 - Windows programs usually perform wildcard expansion when they receive |
16849
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
32 arguments that contain unquoted '*', '?' characters. |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
33 |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
34 With this module, you can build a command that will invoke a program with |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
35 specific strings as arguments. |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
36 |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
37 Note: If you want wildcard expansion to happen, you have to first do wildcard |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
38 expansion through the 'glob' module, then quote the resulting strings through |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
39 this module, and then invoke the system's command interpreter. |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
40 |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
41 Limitations: |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
42 - When invoking native Windows programs on Windows Vista or newer, |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
43 wildcard expansion will occur in the invoked program nevertheless. |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
44 - On native Windows, for SCI_SYSTEM and SCI_WINDOWS_CMD, newlines and |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
45 carriage return characters are not supported. Their undesired effect |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
46 is to truncate the entire command line. |
1aa668619908
system-quote: Add more comments.
Bruno Haible <bruno@clisp.org>
parents:
16848
diff
changeset
|
47 */ |
16841 | 48 |
49 #include <stddef.h> | |
50 | |
51 #ifdef __cplusplus | |
52 extern "C" { | |
53 #endif | |
54 | |
55 /* Identifier for the kind of interpreter of the command. */ | |
56 enum system_command_interpreter | |
57 { | |
58 /* The interpreter used by the system() and popen() functions. | |
59 This is equivalent to SCI_POSIX_SH on Unix platforms and | |
60 SCI_WINDOWS_CMD on native Windows platforms. */ | |
61 SCI_SYSTEM = 0 | |
62 /* The POSIX /bin/sh. */ | |
63 , SCI_POSIX_SH = 1 | |
64 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | |
65 /* The native Windows CreateProcess() function. */ | |
66 , SCI_WINDOWS_CREATEPROCESS = 2 | |
67 /* The native Windows cmd.exe interpreter. */ | |
68 , SCI_WINDOWS_CMD = 3 | |
69 #endif | |
70 }; | |
71 | |
72 /* Returns the number of bytes needed for the quoted string. */ | |
73 extern size_t | |
74 system_quote_length (enum system_command_interpreter interpreter, | |
75 const char *string); | |
76 | |
77 /* Copies the quoted string to p and returns the incremented p. | |
16844 | 78 There must be room for system_quote_length (string) + 1 bytes at p. */ |
16841 | 79 extern char * |
80 system_quote_copy (char *p, | |
81 enum system_command_interpreter interpreter, | |
82 const char *string); | |
83 | |
84 /* Returns the freshly allocated quoted string. */ | |
85 extern char * | |
86 system_quote (enum system_command_interpreter interpreter, | |
87 const char *string); | |
88 | |
89 /* Returns a freshly allocated string containing all argument strings, quoted, | |
90 separated through spaces. */ | |
91 extern char * | |
92 system_quote_argv (enum system_command_interpreter interpreter, | |
93 char * const *argv); | |
94 | |
95 #ifdef __cplusplus | |
96 } | |
97 #endif | |
98 | |
99 #endif /* _SYSTEM_QUOTE_H */ |