コード例 #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;
}
コード例 #2
0
ファイル: subshell.c プロジェクト: GalaxyTab4/workbench
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;
}
コード例 #3
0
ファイル: strutil.c プロジェクト: novacej/School_OSP
int
str_length_char (const char *text)
{
    return str_cget_next_char_safe (text) - text;
}
コード例 #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;
}