static void find_completion(const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    term_cmd_t *cmd;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        term_printf("arg%d = '%s'\n", i, (char *)args[i]);

    }

#endif



    /* if the line ends with a space, it means we want to complete the

       next arg */

    len = strlen(cmdline);

    if (len > 0 && isspace(cmdline[len - 1])) {

        if (nb_args >= MAX_ARGS)

            return;

        args[nb_args++] = qemu_strdup("");

    }

    if (nb_args <= 1) {

        /* command completion */

        if (nb_args == 0)

            cmdname = "";

        else

            cmdname = args[0];

        completion_index = strlen(cmdname);

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            cmd_completion(cmdname, cmd->name);

        }

    } else {

        /* find the command */

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            if (compare_cmd(args[0], cmd->name))

                goto found;

        }

        return;

    found:

        ptype = cmd->args_type;

        for(i = 0; i < nb_args - 2; i++) {

            if (*ptype != '\0') {

                ptype++;

                while (*ptype == '?')

                    ptype++;

            }

        }

        str = args[nb_args - 1];

        switch(*ptype) {

        case 'F':

            /* file completion */

            completion_index = strlen(str);

            file_completion(str);

            break;

        case 'B':

            /* block device name completion */

            completion_index = strlen(str);

            bdrv_iterate(block_completion_it, (void *)str);

            break;

        default:

            break;

        }

    }

    for(i = 0; i < nb_args; i++)

        qemu_free(args[i]);

}

static void find_completion(const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    term_cmd_t *cmd;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        term_printf("arg%d = '%s'\n", i, (char *)args[i]);

    }

#endif



    



    len = strlen(cmdline);

    if (len > 0 && isspace(cmdline[len - 1])) {

        if (nb_args >= MAX_ARGS)

            return;

        args[nb_args++] = qemu_strdup("");

    }

    if (nb_args <= 1) {

        

        if (nb_args == 0)

            cmdname = "";

        else

            cmdname = args[0];

        completion_index = strlen(cmdname);

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            cmd_completion(cmdname, cmd->name);

        }

    } else {

        

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            if (compare_cmd(args[0], cmd->name))

                goto found;

        }

        return;

    found:

        ptype = cmd->args_type;

        for(i = 0; i < nb_args - 2; i++) {

            if (*ptype != '\0') {

                ptype++;

                while (*ptype == '?')

                    ptype++;

            }

        }

        str = args[nb_args - 1];

        switch(*ptype) {

        case 'F':

            

            completion_index = strlen(str);

            file_completion(str);

            break;

        case 'B':

            

            completion_index = strlen(str);

            bdrv_iterate(block_completion_it, (void *)str);

            break;

        default:

            break;

        }

    }

    for(i = 0; i < nb_args; i++)

        qemu_free(args[i]);

}

static void FUNC_0(const char *VAR_0)

{

    const char *VAR_1;

    char *VAR_2[MAX_ARGS];

    int VAR_3, VAR_4, VAR_5;

    const char *VAR_6, *VAR_7;

    term_cmd_t *cmd;



    parse_cmdline(VAR_0, &VAR_3, VAR_2);

#ifdef DEBUG_COMPLETION

    for(VAR_4 = 0; VAR_4 < VAR_3; VAR_4++) {

        term_printf("arg%d = '%s'\n", VAR_4, (char *)VAR_2[VAR_4]);

    }

#endif



    



    VAR_5 = strlen(VAR_0);

    if (VAR_5 > 0 && isspace(VAR_0[VAR_5 - 1])) {

        if (VAR_3 >= MAX_ARGS)

            return;

        VAR_2[VAR_3++] = qemu_strdup("");

    }

    if (VAR_3 <= 1) {

        

        if (VAR_3 == 0)

            VAR_1 = "";

        else

            VAR_1 = VAR_2[0];

        completion_index = strlen(VAR_1);

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            cmd_completion(VAR_1, cmd->name);

        }

    } else {

        

        for(cmd = term_cmds; cmd->name != NULL; cmd++) {

            if (compare_cmd(VAR_2[0], cmd->name))

                goto found;

        }

        return;

    found:

        VAR_6 = cmd->args_type;

        for(VAR_4 = 0; VAR_4 < VAR_3 - 2; VAR_4++) {

            if (*VAR_6 != '\0') {

                VAR_6++;

                while (*VAR_6 == '?')

                    VAR_6++;

            }

        }

        VAR_7 = VAR_2[VAR_3 - 1];

        switch(*VAR_6) {

        case 'F':

            

            completion_index = strlen(VAR_7);

            file_completion(VAR_7);

            break;

        case 'B':

            

            completion_index = strlen(VAR_7);

            bdrv_iterate(block_completion_it, (void *)VAR_7);

            break;

        default:

            break;

        }

    }

    for(VAR_4 = 0; VAR_4 < VAR_3; VAR_4++)

        qemu_free(VAR_2[VAR_4]);

}

static void FUNC_0(const char *VAR_0)
{ const char *VAR_1; char *VAR_2[MAX_ARGS]; int VAR_3, VAR_4, VAR_5; const char *VAR_6, *VAR_7; term_cmd_t *cmd; parse_cmdline(VAR_0, &VAR_3, VAR_2); #ifdef DEBUG_COMPLETION
for(VAR_4 = 0; VAR_4 < VAR_3; VAR_4++) { term_printf("arg%d = '%s'\n", VAR_4, (char *)VAR_2[VAR_4]); } #endif
VAR_5 = strlen(VAR_0); if (VAR_5 > 0 && isspace(VAR_0[VAR_5 - 1])) { if (VAR_3 >= MAX_ARGS)
return; VAR_2[VAR_3++] = qemu_strdup(""); } if (VAR_3 <= 1) { if (VAR_3 == 0)
VAR_1 = ""; else
VAR_1 = VAR_2[0]; completion_index = strlen(VAR_1); for(cmd = term_cmds; cmd->name != NULL; cmd++) { cmd_completion(VAR_1, cmd->name); } } else { for(cmd = term_cmds; cmd->name != NULL; cmd++) { if (compare_cmd(VAR_2[0], cmd->name))
goto found; } return; found:
VAR_6 = cmd->args_type; for(VAR_4 = 0; VAR_4 < VAR_3 - 2; VAR_4++) { if (*VAR_6 != '\0') { VAR_6++; while (*VAR_6 == '?')
VAR_6++; } } VAR_7 = VAR_2[VAR_3 - 1]; switch(*VAR_6) { case 'F':
completion_index = strlen(VAR_7); file_completion(VAR_7); break; case 'B':
completion_index = strlen(VAR_7); bdrv_iterate(block_completion_it, (void *)VAR_7); break; default:
break; } } for(VAR_4 = 0; VAR_4 < VAR_3; VAR_4++) qemu_free(VAR_2[VAR_4]); }