X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgshell.c;h=596f081d6f42f481100953c2dfe117aa3b38b4cf;hb=f2ceb74e91e05e9556622bc2cde7ab57cbc30ea3;hp=32cb33479cae81ad365f29294fdca1210203f670;hpb=4b602940e2c46d9f91acf91f67a6cd0b6ea05e13;p=platform%2Fupstream%2Fglib.git diff --git a/glib/gshell.c b/glib/gshell.c index 32cb334..596f081 100644 --- a/glib/gshell.c +++ b/glib/gshell.c @@ -37,7 +37,15 @@ * SECTION:shell * @title: Shell-related Utilities * @short_description: shell-like commandline handling - **/ + * + * GLib provides the functions g_shell_quote() and g_shell_unquote() + * to handle shell-like quoting in strings. The function g_shell_parse_argv() + * parses a string similar to the way a POSIX shell (/bin/sh) would. + * + * Note that string handling in shells has many obscure and historical + * corner-cases which these functions do not necessarily reproduce. They + * are good enough in practice, though. + */ /** * G_SHELL_ERROR: @@ -191,7 +199,7 @@ unquote_string_inplace (gchar* str, gchar** end, GError** err) * quoting style used is undefined (single or double quotes may be * used). * - * Return value: quoted string + * Returns: quoted string **/ gchar* g_shell_quote (const gchar *unquoted_string) @@ -257,7 +265,7 @@ g_shell_quote (const gchar *unquoted_string) * be escaped with backslash. Otherwise double quotes preserve things * literally. * - * Return value: an unquoted string + * Returns: an unquoted string **/ gchar* g_shell_unquote (const gchar *quoted_string, @@ -518,12 +526,30 @@ tokenize_command_line (const gchar *command_line, g_string_append_c (current_token, *p); /* FALL THRU */ - - case '#': case '\\': current_quote = *p; break; + case '#': + if (p == command_line) + { /* '#' was the first char */ + current_quote = *p; + break; + } + switch(*(p-1)) + { + case ' ': + case '\n': + case '\0': + current_quote = *p; + break; + default: + ensure_token (¤t_token); + g_string_append_c (current_token, *p); + break; + } + break; + default: /* Combines rules 4) and 6) - if we have a token, append to it, * otherwise create a new token. @@ -607,7 +633,7 @@ tokenize_command_line (const gchar *command_line, * literally. Possible errors are those from the #G_SHELL_ERROR * domain. Free the returned vector with g_strfreev(). * - * Return value: %TRUE on success, %FALSE if error set + * Returns: %TRUE on success, %FALSE if error set **/ gboolean g_shell_parse_argv (const gchar *command_line,