More gracefully handle type mismatch errors when doing playlist things (just ignore...
[ardour.git] / libs / glibmm2 / glib / glibmm / shell.h
1 // -*- c++ -*-
2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GLIBMM_SHELL_H
4 #define _GLIBMM_SHELL_H
5
6
7 /* $Id: shell.hg,v 1.2 2003/01/22 21:38:35 murrayc Exp $ */
8
9 /* Copyright (C) 2002 The gtkmm Development Team
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26
27 #include <glib/gshell.h>
28 #include <string>
29
30 #include <glibmm/arrayhandle.h>
31 #include <glibmm/error.h>
32
33 #include <glibmmconfig.h>
34 GLIBMM_USING_STD(string)
35
36
37 namespace Glib
38 {
39
40 /** @defgroup ShellUtils Shell-related Utilities
41  * Shell-like command line handling.
42  * @{
43  */
44
45 /** Exception class for shell utility errors.
46  */
47 class ShellError : public Glib::Error
48 {
49 public:
50   enum Code
51   {
52     BAD_QUOTING,
53     EMPTY_STRING,
54     FAILED
55   };
56
57   ShellError(Code error_code, const Glib::ustring& error_message);
58   explicit ShellError(GError* gobject);
59   Code code() const;
60
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62 private:
63
64 #ifdef GLIBMM_EXCEPTIONS_ENABLED
65   static void throw_func(GError* gobject);
66 #else
67   //When not using exceptions, we just pass the Exception object around without throwing it:
68   static std::auto_ptr<Glib::Error> throw_func(GError* gobject);
69 #endif //GLIBMM_EXCEPTIONS_ENABLED
70
71   friend void wrap_init(); // uses throw_func()
72 #endif
73 };
74
75
76 /** Parses a command line into an argument vector, in much the same way the
77  * shell would, but without many of the expansions the shell would perform
78  * (variable expansion, globs, operators, filename expansion, etc.\ are not
79  * supported).  The results are defined to be the same as those you would
80  * get from a UNIX98 /bin/sh, as long as the input contains none of the
81  * unsupported shell expansions.  If the input does contain such expansions,
82  * they are passed through literally.
83  * @param command_line Command line to parse.
84  * @return Array of args (The generic ArrayHandle will be implicitly
85  * converted to any STL compatible container type).
86  * @throw Glib::ShellError
87  */
88 Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line);
89
90 /** Quotes a string so that the shell (/bin/sh) will interpret the quoted
91  * string to mean @a unquoted_string.  If you pass a filename to the shell,
92  * for example, you should first quote it with this function.  The quoting
93  * style used is undefined (single or double quotes may be used).
94  * @param unquoted_string A literal string.
95  * @return A quoted string.
96  */
97 std::string shell_quote(const std::string& unquoted_string);
98
99 /** Unquotes a string as the shell (/bin/sh) would.  Only handles quotes; if
100  * a string contains file globs, arithmetic operators, variables, backticks,
101  * redirections, or other special-to-the-shell features, the result will be
102  * different from the result a real shell would produce (the variables,
103  * backticks, etc. will be passed through literally instead of being expanded).
104  * This function is guaranteed to succeed if applied to the result of
105  * shell_quote().  If it fails, it throws a Glib::ShellError exception.  The
106  * @a quoted_string need not actually contain quoted or escaped text;
107  * shell_unquote() simply goes through the string and unquotes/unescapes
108  * anything that the shell would.  Both single and double quotes are handled,
109  * as are escapes including escaped newlines.
110  *
111  * Shell quoting rules are a bit strange.  Single quotes preserve the literal
112  * string exactly.  Escape sequences are not allowed; not even <tt>\\'</tt> --
113  * if you want a <tt>'</tt> in the quoted text, you have to do something like
114  * <tt>'foo'\\''bar'</tt>.  Double quotes allow <tt>$</tt>, <tt>`</tt>,
115  * <tt>"</tt>, <tt>\\</tt>, and newline to be escaped with backslash.
116  * Otherwise double quotes preserve things literally.
117  *
118  * @param quoted_string Shell-quoted string.
119  * @return An unquoted string.
120  * @throw Glib::ShellError
121  */
122 std::string shell_unquote(const std::string& quoted_string);
123
124 /** @} group ShellUtils */
125
126 } // namespace Glib
127
128
129 #endif /* _GLIBMM_SHELL_H */
130