static void term_completion(void)

{

    int len, i, j, max_width, nb_cols;

    char *cmdline;



    nb_completions = 0;

    

    cmdline = qemu_malloc(term_cmd_buf_index + 1);

    if (!cmdline)

        return;

    memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);

    cmdline[term_cmd_buf_index] = '\0';

    find_completion(cmdline);

    qemu_free(cmdline);



    /* no completion found */

    if (nb_completions <= 0)

        return;

    if (nb_completions == 1) {

        len = strlen(completions[0]);

        for(i = completion_index; i < len; i++) {

            term_insert_char(completions[0][i]);

        }

        /* extra space for next argument. XXX: make it more generic */

        if (len > 0 && completions[0][len - 1] != '/')

            term_insert_char(' ');

    } else {

        term_printf("\n");

        max_width = 0;

        for(i = 0; i < nb_completions; i++) {

            len = strlen(completions[i]);

            if (len > max_width)

                max_width = len;

        }

        max_width += 2;

        if (max_width < 10)

            max_width = 10;

        else if (max_width > 80)

            max_width = 80;

        nb_cols = 80 / max_width;

        j = 0;

        for(i = 0; i < nb_completions; i++) {

            term_printf("%-*s", max_width, completions[i]);

            if (++j == nb_cols || i == (nb_completions - 1)) {

                term_printf("\n");

                j = 0;

            }

        }

        term_show_prompt2();

    }

}

static void term_completion(void)

{

    int len, i, j, max_width, nb_cols;

    char *cmdline;



    nb_completions = 0;

    

    cmdline = qemu_malloc(term_cmd_buf_index + 1);

    if (!cmdline)

        return;

    memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);

    cmdline[term_cmd_buf_index] = '\0';

    find_completion(cmdline);

    qemu_free(cmdline);



    

    if (nb_completions <= 0)

        return;

    if (nb_completions == 1) {

        len = strlen(completions[0]);

        for(i = completion_index; i < len; i++) {

            term_insert_char(completions[0][i]);

        }

        

        if (len > 0 && completions[0][len - 1] != '/')

            term_insert_char(' ');

    } else {

        term_printf("\n");

        max_width = 0;

        for(i = 0; i < nb_completions; i++) {

            len = strlen(completions[i]);

            if (len > max_width)

                max_width = len;

        }

        max_width += 2;

        if (max_width < 10)

            max_width = 10;

        else if (max_width > 80)

            max_width = 80;

        nb_cols = 80 / max_width;

        j = 0;

        for(i = 0; i < nb_completions; i++) {

            term_printf("%-*s", max_width, completions[i]);

            if (++j == nb_cols || i == (nb_completions - 1)) {

                term_printf("\n");

                j = 0;

            }

        }

        term_show_prompt2();

    }

}

static void FUNC_0(void)

{

    int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4;

    char *VAR_5;



    nb_completions = 0;

    

    VAR_5 = qemu_malloc(term_cmd_buf_index + 1);

    if (!VAR_5)

        return;

    memcpy(VAR_5, term_cmd_buf, term_cmd_buf_index);

    VAR_5[term_cmd_buf_index] = '\0';

    find_completion(VAR_5);

    qemu_free(VAR_5);



    

    if (nb_completions <= 0)

        return;

    if (nb_completions == 1) {

        VAR_0 = strlen(completions[0]);

        for(VAR_1 = completion_index; VAR_1 < VAR_0; VAR_1++) {

            term_insert_char(completions[0][VAR_1]);

        }

        

        if (VAR_0 > 0 && completions[0][VAR_0 - 1] != '/')

            term_insert_char(' ');

    } else {

        term_printf("\n");

        VAR_3 = 0;

        for(VAR_1 = 0; VAR_1 < nb_completions; VAR_1++) {

            VAR_0 = strlen(completions[VAR_1]);

            if (VAR_0 > VAR_3)

                VAR_3 = VAR_0;

        }

        VAR_3 += 2;

        if (VAR_3 < 10)

            VAR_3 = 10;

        else if (VAR_3 > 80)

            VAR_3 = 80;

        VAR_4 = 80 / VAR_3;

        VAR_2 = 0;

        for(VAR_1 = 0; VAR_1 < nb_completions; VAR_1++) {

            term_printf("%-*s", VAR_3, completions[VAR_1]);

            if (++VAR_2 == VAR_4 || VAR_1 == (nb_completions - 1)) {

                term_printf("\n");

                VAR_2 = 0;

            }

        }

        term_show_prompt2();

    }

}

static void FUNC_0(void)
{ int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4; char *VAR_5; nb_completions = 0; VAR_5 = qemu_malloc(term_cmd_buf_index + 1); if (!VAR_5)
return; memcpy(VAR_5, term_cmd_buf, term_cmd_buf_index); VAR_5[term_cmd_buf_index] = '\0'; find_completion(VAR_5); qemu_free(VAR_5); if (nb_completions <= 0)
return; if (nb_completions == 1) { VAR_0 = strlen(completions[0]); for(VAR_1 = completion_index; VAR_1 < VAR_0; VAR_1++) { term_insert_char(completions[0][VAR_1]); } if (VAR_0 > 0 && completions[0][VAR_0 - 1] != '/')
term_insert_char(' '); } else { term_printf("\n"); VAR_3 = 0; for(VAR_1 = 0; VAR_1 < nb_completions; VAR_1++) { VAR_0 = strlen(completions[VAR_1]); if (VAR_0 > VAR_3)
VAR_3 = VAR_0; } VAR_3 += 2; if (VAR_3 < 10)
VAR_3 = 10; else if (VAR_3 > 80)
VAR_3 = 80; VAR_4 = 80 / VAR_3; VAR_2 = 0; for(VAR_1 = 0; VAR_1 < nb_completions; VAR_1++) { term_printf("%-*s", VAR_3, completions[VAR_1]); if (++VAR_2 == VAR_4 || VAR_1 == (nb_completions - 1)) { term_printf("\n"); VAR_2 = 0; } } term_show_prompt2(); } }