1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY! 2 #ifndef _GLIBMM_SHELL_H 3 #define _GLIBMM_SHELL_H 4 5 6 /* Copyright (C) 2002 The gtkmm Development Team 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 23 #include <glibmm/arrayhandle.h> 24 #include <glibmm/error.h> 25 #include <glib.h> 26 #include <string> 27 28 namespace Glib 29 { 30 31 /** @defgroup ShellUtils Shell-related Utilities 32 * Shell-like command line handling. 33 * @{ 34 */ 35 36 /** %Exception class for shell utility errors. 37 */ 38 class GLIBMM_API ShellError : public Glib::Error 39 { 40 public: 41 /** @var Code BAD_QUOTING 42 * Mismatched or otherwise mangled quoting. 43 * 44 * @var Code EMPTY_STRING 45 * String to be parsed was empty. 46 * 47 * @var Code FAILED 48 * Some other error. 49 * 50 * @enum Code 51 * 52 * %Error codes returned by shell functions. 53 */ 54 enum Code 55 { 56 BAD_QUOTING, 57 EMPTY_STRING, 58 FAILED 59 }; 60 61 ShellError(Code error_code, const Glib::ustring& error_message); 62 explicit ShellError(GError* gobject); 63 Code code() const; 64 65 #ifndef DOXYGEN_SHOULD_SKIP_THIS 66 private: 67 68 static void throw_func(GError* gobject); 69 70 friend GLIBMM_API void wrap_init(); // uses throw_func() 71 72 #endif //DOXYGEN_SHOULD_SKIP_THIS 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 GLIBMM_API 89 Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line); 90 91 /** Quotes a string so that the shell (/bin/sh) will interpret the quoted 92 * string to mean @a unquoted_string. If you pass a filename to the shell, 93 * for example, you should first quote it with this function. The quoting 94 * style used is undefined (single or double quotes may be used). 95 * @param unquoted_string A literal string. 96 * @return A quoted string. 97 */ 98 GLIBMM_API 99 std::string shell_quote(const std::string& unquoted_string); 100 101 /** Unquotes a string as the shell (/bin/sh) would. Only handles quotes; if 102 * a string contains file globs, arithmetic operators, variables, backticks, 103 * redirections, or other special-to-the-shell features, the result will be 104 * different from the result a real shell would produce (the variables, 105 * backticks, etc. will be passed through literally instead of being expanded). 106 * This function is guaranteed to succeed if applied to the result of 107 * shell_quote(). If it fails, it throws a Glib::ShellError exception. The 108 * @a quoted_string need not actually contain quoted or escaped text; 109 * shell_unquote() simply goes through the string and unquotes/unescapes 110 * anything that the shell would. Both single and double quotes are handled, 111 * as are escapes including escaped newlines. 112 * 113 * Shell quoting rules are a bit strange. Single quotes preserve the literal 114 * string exactly. Escape sequences are not allowed; not even <tt>\\'</tt> -- 115 * if you want a <tt>'</tt> in the quoted text, you have to do something like 116 * <tt>'foo'\\''bar'</tt>. Double quotes allow <tt>$</tt>, <tt>`</tt>, 117 * <tt>"</tt>, <tt>\\</tt>, and newline to be escaped with backslash. 118 * Otherwise double quotes preserve things literally. 119 * 120 * @param quoted_string Shell-quoted string. 121 * @return An unquoted string. 122 * @throw Glib::ShellError 123 */ 124 GLIBMM_API 125 std::string shell_unquote(const std::string& quoted_string); 126 127 /** @} group ShellUtils */ 128 129 } // namespace Glib 130 131 132 #endif /* _GLIBMM_SHELL_H */ 133 134