Exemplo n.º 1
0
struct hotkey_t
parse_hotkey (const char *text)
{
    hotkey_t result;
    const char *cp, *p;

    if (text == NULL)
        text = "";

    /* search for '&', that is not on the of text */
    cp = strchr (text, '&');
    if (cp != NULL && cp[1] != '\0')
    {
        result.start = g_strndup (text, cp - text);

        /* skip '&' */
        cp++;
        p = str_cget_next_char (cp);
        result.hotkey = g_strndup (cp, p - cp);

        cp = p;
        result.end = g_strdup (cp);
    }
    else
    {
        result.start = g_strdup (text);
        result.hotkey = NULL;
        result.end = NULL;
    }

    return result;
}
Exemplo n.º 2
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.º 3
0
static void
help_show (WDialog * h, const char *paint_start)
{
    const char *p, *n;
    int col, line, c;
    gboolean painting = TRUE;
    gboolean acs;               /* Flag: Alternate character set active? */
    gboolean repeat_paint;
    int active_col, active_line;        /* Active link position */
    char buff[MB_LEN_MAX + 1];
    GString *word;

    word = g_string_sized_new (32);

    tty_setcolor (HELP_NORMAL_COLOR);
    do
    {
        line = col = active_col = active_line = 0;
        repeat_paint = FALSE;
        acs = FALSE;

        clear_link_areas ();
        if ((int) (selected_item - paint_start) < 0)
            selected_item = NULL;

        p = paint_start;
        n = paint_start;
        while ((n[0] != '\0') && (n[0] != CHAR_NODE_END) && (line < help_lines))
        {
            p = n;
            n = str_cget_next_char (p);
            memcpy (buff, p, n - p);
            buff[n - p] = '\0';

            c = (unsigned char) buff[0];
            switch (c)
            {
            case CHAR_LINK_START:
                if (selected_item == NULL)
                    selected_item = p;
                if (p != selected_item)
                    tty_setcolor (HELP_LINK_COLOR);
                else
                {
                    tty_setcolor (HELP_SLINK_COLOR);

                    /* Store the coordinates of the link */
                    active_col = col + 2;
                    active_line = line + 2;
                }
                start_link_area (col, line, p);
                break;
            case CHAR_LINK_POINTER:
                painting = FALSE;
                break;
            case CHAR_LINK_END:
                painting = TRUE;
                help_print_word (h, word, &col, &line, FALSE);
                end_link_area (col - 1, line);
                tty_setcolor (HELP_NORMAL_COLOR);
                break;
            case CHAR_ALTERNATE:
                acs = TRUE;
                break;
            case CHAR_NORMAL:
                acs = FALSE;
                break;
            case CHAR_VERSION:
                widget_move (h, line + 2, col + 2);
                tty_print_string (VERSION);
                col += str_term_width1 (VERSION);
                break;
            case CHAR_FONT_BOLD:
                tty_setcolor (HELP_BOLD_COLOR);
                break;
            case CHAR_FONT_ITALIC:
                tty_setcolor (HELP_ITALIC_COLOR);
                break;
            case CHAR_FONT_NORMAL:
                help_print_word (h, word, &col, &line, FALSE);
                tty_setcolor (HELP_NORMAL_COLOR);
                break;
            case '\n':
                if (painting)
                    help_print_word (h, word, &col, &line, FALSE);
                line++;
                col = 0;
                break;
            case '\t':
                col = (col / 8 + 1) * 8;
                if (col >= HELP_WINDOW_WIDTH)
                {
                    line++;
                    col = 8;
                }
                break;
            case ' ':
                /* word delimiter */
                if (painting)
                    help_print_word (h, word, &col, &line, TRUE);
                break;
            default:
                if (painting && (line < help_lines))
                {
                    if (!acs)
                        /* accumulate symbols in a word */
                        g_string_append (word, buff);
                    else if (col < HELP_WINDOW_WIDTH)
                    {
                        widget_move (h, line + 2, col + 2);

                        if ((c == ' ') || (c == '.'))
                            tty_print_char (c);
                        else
#ifndef HAVE_SLANG
                            tty_print_char (acs_map[c]);
#else
                            SLsmg_draw_object (WIDGET (h)->y + line + 2, WIDGET (h)->x + col + 2,
                                               c);
#endif
                        col++;
                    }
                }
            }
        }

        /* print last word */
        if (n[0] == CHAR_NODE_END)
            help_print_word (h, word, &col, &line, FALSE);

        last_shown = p;
        end_of_node = line < help_lines;
        tty_setcolor (HELP_NORMAL_COLOR);
        if ((int) (selected_item - last_shown) >= 0)
        {
            if ((link_area == NULL) || (link_area->data == NULL))
                selected_item = NULL;
            else
            {
                selected_item = ((Link_Area *) link_area->data)->link_name;
                repeat_paint = TRUE;
            }
        }
    }
    while (repeat_paint);

    g_string_free (word, TRUE);

    /* Position the cursor over a nice link */
    if (active_col)
        widget_move (h, active_line, active_col);
}