Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / glib / src / shell.hg
1 /* $Id: shell.hg,v 1.2 2003/01/22 21:38:35 murrayc Exp $ */
2
3 /* Copyright (C) 2002 The gtkmm Development Team
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 _DEFS(glibmm,glib)
21
22 #include <glib.h>
23 #include <string>
24
25 #include <glibmm/arrayhandle.h>
26 #include <glibmm/error.h>
27
28 #include <glibmmconfig.h>
29 GLIBMM_USING_STD(string)
30
31
32 namespace Glib
33 {
34
35 /** @defgroup ShellUtils Shell-related Utilities
36  * Shell-like command line handling.
37  * @{
38  */
39
40 /** Exception class for shell utility errors.
41  */
42 _WRAP_GERROR(ShellError, GShellError, G_SHELL_ERROR, NO_GTYPE)
43
44
45 /** Parses a command line into an argument vector, in much the same way the
46  * shell would, but without many of the expansions the shell would perform
47  * (variable expansion, globs, operators, filename expansion, etc.\ are not
48  * supported).  The results are defined to be the same as those you would
49  * get from a UNIX98 /bin/sh, as long as the input contains none of the
50  * unsupported shell expansions.  If the input does contain such expansions,
51  * they are passed through literally.
52  * @param command_line Command line to parse.
53  * @return Array of args (The generic ArrayHandle will be implicitly
54  * converted to any STL compatible container type).
55  * @throw Glib::ShellError
56  */
57 Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line);
58
59 /** Quotes a string so that the shell (/bin/sh) will interpret the quoted
60  * string to mean @a unquoted_string.  If you pass a filename to the shell,
61  * for example, you should first quote it with this function.  The quoting
62  * style used is undefined (single or double quotes may be used).
63  * @param unquoted_string A literal string.
64  * @return A quoted string.
65  */
66 std::string shell_quote(const std::string& unquoted_string);
67
68 /** Unquotes a string as the shell (/bin/sh) would.  Only handles quotes; if
69  * a string contains file globs, arithmetic operators, variables, backticks,
70  * redirections, or other special-to-the-shell features, the result will be
71  * different from the result a real shell would produce (the variables,
72  * backticks, etc. will be passed through literally instead of being expanded).
73  * This function is guaranteed to succeed if applied to the result of
74  * shell_quote().  If it fails, it throws a Glib::ShellError exception.  The
75  * @a quoted_string need not actually contain quoted or escaped text;
76  * shell_unquote() simply goes through the string and unquotes/unescapes
77  * anything that the shell would.  Both single and double quotes are handled,
78  * as are escapes including escaped newlines.
79  *
80  * Shell quoting rules are a bit strange.  Single quotes preserve the literal
81  * string exactly.  Escape sequences are not allowed; not even <tt>\\'</tt> --
82  * if you want a <tt>'</tt> in the quoted text, you have to do something like
83  * <tt>'foo'\\''bar'</tt>.  Double quotes allow <tt>$</tt>, <tt>`</tt>,
84  * <tt>"</tt>, <tt>\\</tt>, and newline to be escaped with backslash.
85  * Otherwise double quotes preserve things literally.
86  *
87  * @param quoted_string Shell-quoted string.
88  * @return An unquoted string.
89  * @throw Glib::ShellError
90  */
91 std::string shell_unquote(const std::string& quoted_string);
92
93 /** @} group ShellUtils */
94
95 } // namespace Glib
96