Exemplo n.º 1
0
static GString *
subshell_name_quote (const char *s)
{
    GString *ret;
    const char *su, *n;
    const char *quote_cmd_start, *quote_cmd_end;

    if (mc_global.shell->type == SHELL_FISH)
    {
        quote_cmd_start = "(printf \"%b\" '";
        quote_cmd_end = "')";
    }
    /* TODO: When BusyBox printf is fixed, get rid of this "else if", see
       http://lists.busybox.net/pipermail/busybox/2012-March/077460.html */
    /* else if (subshell_type == ASH_BUSYBOX)
       {
       quote_cmd_start = "\"`echo -en '";
       quote_cmd_end = "'`\"";
       } */
    else
    {
        quote_cmd_start = "\"`printf \"%b\" '";
        quote_cmd_end = "'`\"";
    }

    ret = g_string_sized_new (64);

    /* Prevent interpreting leading '-' as a switch for 'cd' */
    if (s[0] == '-')
        g_string_append (ret, "./");

    /* Copy the beginning of the command to the buffer */
    g_string_append (ret, quote_cmd_start);

    /*
     * Print every character except digits and letters as a backslash-escape
     * sequence of the form \0nnn, where "nnn" is the numeric value of the
     * character converted to octal number.
     */
    for (su = s; su[0] != '\0'; su = n)
    {
        n = str_cget_next_char_safe (su);

        if (str_isalnum (su))
            g_string_append_len (ret, su, n - su);
        else
        {
            int c;

            for (c = 0; c < n - su; c++)
                g_string_append_printf (ret, "\\0%03o", (unsigned char) su[c]);
        }
    }

    g_string_append (ret, quote_cmd_end);

    return ret;
}
Exemplo n.º 2
0
static GString *
subshell_name_quote (const char *s)
{
    GString *ret;
    const char *su, *n;
    const char *quote_cmd_start, *quote_cmd_end;

    if (subshell_type == FISH)
    {
        quote_cmd_start = "(printf \"%b\" '";
        quote_cmd_end = "')";
    }
    else
    {
        quote_cmd_start = "\"`printf \"%b\" '";
        quote_cmd_end = "'`\"";
    }

    ret = g_string_sized_new (64);

    /* Prevent interpreting leading '-' as a switch for 'cd' */
    if (s[0] == '-')
        g_string_append (ret, "./");

    /* Copy the beginning of the command to the buffer */
    g_string_append (ret, quote_cmd_start);

    /*
     * Print every character except digits and letters as a backslash-escape
     * sequence of the form \0nnn, where "nnn" is the numeric value of the
     * character converted to octal number.
     */
    for (su = s; su[0] != '\0'; su = n)
    {
        n = str_cget_next_char_safe (su);

        if (str_isalnum (su))
            g_string_append_len (ret, su, n - su);
        else
        {
            int c;

            for (c = 0; c < n - su; c++)
                g_string_append_printf (ret, "\\0%03o", (unsigned char) su[c]);
        }
    }

    g_string_append (ret, quote_cmd_end);

    return ret;
}
Exemplo n.º 3
0
Arquivo: lib.c Projeto: idispatch/mc
gchar *
mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
                           gboolean * just_letters)
{
    gchar *converted_str;
    const gchar *next_char;

    gsize tmp_len;
#ifdef HAVE_CHARSET
    gsize converted_str_len;
    gchar *converted_str2;

    if (charset == NULL)
        charset = cp_source;

    converted_str = mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
#else
    (void) charset;

    converted_str = g_strndup (str, str_len);
#endif

    next_char = str_cget_next_char (converted_str);

    tmp_len = next_char - converted_str;

    converted_str[tmp_len] = '\0';

#ifdef HAVE_CHARSET
    converted_str2 =
        mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len);
#endif
    if (just_letters)
    {
        if (str_isalnum (converted_str) && !str_isdigit (converted_str))
            *just_letters = TRUE;
        else
            *just_letters = FALSE;
    }
#ifdef HAVE_CHARSET
    g_free (converted_str);
    return converted_str2;
#else
    return converted_str;
#endif
}
Exemplo n.º 4
0
static char *
subshell_name_quote (const char *s)
{
    char *ret, *d;
    const char *su, *n;
    const char *quote_cmd_start, *quote_cmd_end;
    int c;

    if (subshell_type == FISH)
    {
        quote_cmd_start = "(printf \"%b\" '";
        quote_cmd_end = "')";
    }
    else
    {
        quote_cmd_start = "\"`printf \"%b\" '";
        quote_cmd_end = "'`\"";
    }

    /* Factor 5 because we need \, 0 and 3 other digits per character. */
    d = ret = g_try_malloc (1 + (5 * strlen (s)) + (strlen (quote_cmd_start))
                            + (strlen (quote_cmd_end)));
    if (d == NULL)
        return NULL;

    /* Prevent interpreting leading `-' as a switch for `cd' */
    if (*s == '-')
    {
        *d++ = '.';
        *d++ = '/';
    }

    /* Copy the beginning of the command to the buffer */
    strcpy (d, quote_cmd_start);
    d += strlen (quote_cmd_start);

    /*
     * Print every character except digits and letters as a backslash-escape
     * sequence of the form \0nnn, where "nnn" is the numeric value of the
     * character converted to octal number.
     */
    su = s;
    for (; su[0] != '\0';)
    {
        n = str_cget_next_char_safe (su);
        if (str_isalnum (su))
        {
            memcpy (d, su, n - su);
            d += n - su;
        }
        else
        {
            for (c = 0; c < n - su; c++)
            {
                sprintf (d, "\\0%03o", (unsigned char) su[c]);
                d += 5;
            }
        }
        su = n;
    }

    strcpy (d, quote_cmd_end);

    return ret;
}