static void monitor_find_completion(Monitor *mon,

                                    const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    const mon_cmd_t *cmd;

    MonitorBlockComplete mbs;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        monitor_printf(mon, "arg%d = '%s'\n", i, 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 && qemu_isspace(cmdline[len - 1])) {

        if (nb_args >= MAX_ARGS) {

            goto cleanup;

        }

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

    }

    if (nb_args <= 1) {

        /* command completion */

        if (nb_args == 0)

            cmdname = "";

        else

            cmdname = args[0];

        readline_set_completion_index(mon->rs, strlen(cmdname));

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

            cmd_completion(mon, cmdname, cmd->name);

        }

    } else {

        /* find the command */

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

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

                break;

            }

        }

        if (!cmd->name) {

            goto cleanup;

        }



        ptype = next_arg_type(cmd->args_type);

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

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

                ptype = next_arg_type(ptype);

                while (*ptype == '?')

                    ptype = next_arg_type(ptype);

            }

        }

        str = args[nb_args - 1];

        if (*ptype == '-' && ptype[1] != '\0') {

            ptype = next_arg_type(ptype);

        }

        switch(*ptype) {

        case 'F':

            /* file completion */

            readline_set_completion_index(mon->rs, strlen(str));

            file_completion(mon, str);

            break;

        case 'B':

            /* block device name completion */

            mbs.mon = mon;

            mbs.input = str;

            readline_set_completion_index(mon->rs, strlen(str));

            bdrv_iterate(block_completion_it, &mbs);

            break;

        case 's':

            /* XXX: more generic ? */

            if (!strcmp(cmd->name, "info")) {

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, cmd->name);

                }

            } else if (!strcmp(cmd->name, "sendkey")) {

                char *sep = strrchr(str, '-');

                if (sep)

                    str = sep + 1;

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, QKeyCode_lookup[i]);

                }

            } else if (!strcmp(cmd->name, "help|?")) {

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, cmd->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

        g_free(args[i]);

    }

}

static void monitor_find_completion(Monitor *mon,

                                    const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    const mon_cmd_t *cmd;

    MonitorBlockComplete mbs;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        monitor_printf(mon, "arg%d = '%s'\n", i, args[i]);

    }

#endif



    



    len = strlen(cmdline);

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

        if (nb_args >= MAX_ARGS) {

            goto cleanup;

        }

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

    }

    if (nb_args <= 1) {

        

        if (nb_args == 0)

            cmdname = "";

        else

            cmdname = args[0];

        readline_set_completion_index(mon->rs, strlen(cmdname));

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

            cmd_completion(mon, cmdname, cmd->name);

        }

    } else {

        

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

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

                break;

            }

        }

        if (!cmd->name) {

            goto cleanup;

        }



        ptype = next_arg_type(cmd->args_type);

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

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

                ptype = next_arg_type(ptype);

                while (*ptype == '?')

                    ptype = next_arg_type(ptype);

            }

        }

        str = args[nb_args - 1];

        if (*ptype == '-' && ptype[1] != '\0') {

            ptype = next_arg_type(ptype);

        }

        switch(*ptype) {

        case 'F':

            

            readline_set_completion_index(mon->rs, strlen(str));

            file_completion(mon, str);

            break;

        case 'B':

            

            mbs.mon = mon;

            mbs.input = str;

            readline_set_completion_index(mon->rs, strlen(str));

            bdrv_iterate(block_completion_it, &mbs);

            break;

        case 's':

            

            if (!strcmp(cmd->name, "info")) {

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, cmd->name);

                }

            } else if (!strcmp(cmd->name, "sendkey")) {

                char *sep = strrchr(str, '-');

                if (sep)

                    str = sep + 1;

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, QKeyCode_lookup[i]);

                }

            } else if (!strcmp(cmd->name, "help|?")) {

                readline_set_completion_index(mon->rs, strlen(str));

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

                    cmd_completion(mon, str, cmd->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

        g_free(args[i]);

    }

}

            break;             break;     parse_cmdline(cmdline, &nb_args, args);     for (i = 0; i < nb_args; i++) {         g_free(args[i]);
static void FUNC_0(Monitor *VAR_0,

                                    const char *VAR_1)

{

    const char *VAR_2;

    char *VAR_3[MAX_ARGS];

    int VAR_4, VAR_5, VAR_6;

    const char *VAR_7, *VAR_8;

    const mon_cmd_t *VAR_9;

    MonitorBlockComplete mbs;



    parse_cmdline(VAR_1, &VAR_4, VAR_3);

#ifdef DEBUG_COMPLETION

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

        monitor_printf(VAR_0, "arg%d = '%s'\n", VAR_5, VAR_3[VAR_5]);

    }

#endif



    



    VAR_6 = strlen(VAR_1);

    if (VAR_6 > 0 && qemu_isspace(VAR_1[VAR_6 - 1])) {

        if (VAR_4 >= MAX_ARGS) {

            goto cleanup;

        }

        VAR_3[VAR_4++] = g_strdup("");

    }

    if (VAR_4 <= 1) {

        

        if (VAR_4 == 0)

            VAR_2 = "";

        else

            VAR_2 = VAR_3[0];

        readline_set_completion_index(VAR_0->rs, strlen(VAR_2));

        for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) {

            cmd_completion(VAR_0, VAR_2, VAR_9->name);

        }

    } else {

        

        for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) {

            if (compare_cmd(VAR_3[0], VAR_9->name)) {

                break;

            }

        }

        if (!VAR_9->name) {

            goto cleanup;

        }



        VAR_7 = next_arg_type(VAR_9->args_type);

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

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

                VAR_7 = next_arg_type(VAR_7);

                while (*VAR_7 == '?')

                    VAR_7 = next_arg_type(VAR_7);

            }

        }

        VAR_8 = VAR_3[VAR_4 - 1];

        if (*VAR_7 == '-' && VAR_7[1] != '\0') {

            VAR_7 = next_arg_type(VAR_7);

        }

        switch(*VAR_7) {

        case 'F':

            

            readline_set_completion_index(VAR_0->rs, strlen(VAR_8));

            file_completion(VAR_0, VAR_8);

            break;

        case 'B':

            

            mbs.VAR_0 = VAR_0;

            mbs.input = VAR_8;

            readline_set_completion_index(VAR_0->rs, strlen(VAR_8));

            bdrv_iterate(block_completion_it, &mbs);

            break;

        case 's':

            

            if (!strcmp(VAR_9->name, "info")) {

                readline_set_completion_index(VAR_0->rs, strlen(VAR_8));

                for(VAR_9 = info_cmds; VAR_9->name != NULL; VAR_9++) {

                    cmd_completion(VAR_0, VAR_8, VAR_9->name);

                }

            } else if (!strcmp(VAR_9->name, "sendkey")) {

                char *VAR_10 = strrchr(VAR_8, '-');

                if (VAR_10)

                    VAR_8 = VAR_10 + 1;

                readline_set_completion_index(VAR_0->rs, strlen(VAR_8));

                for (VAR_5 = 0; VAR_5 < Q_KEY_CODE_MAX; VAR_5++) {

                    cmd_completion(VAR_0, VAR_8, QKeyCode_lookup[VAR_5]);

                }

            } else if (!strcmp(VAR_9->name, "help|?")) {

                readline_set_completion_index(VAR_0->rs, strlen(VAR_8));

                for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) {

                    cmd_completion(VAR_0, VAR_8, VAR_9->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

        g_free(VAR_3[VAR_5]);

    }

}

static void FUNC_0(Monitor *VAR_0,
const char *VAR_1)
{ const char *VAR_2; char *VAR_3[MAX_ARGS]; int VAR_4, VAR_5, VAR_6; const char *VAR_7, *VAR_8; const mon_cmd_t *VAR_9; MonitorBlockComplete mbs; parse_cmdline(VAR_1, &VAR_4, VAR_3); #ifdef DEBUG_COMPLETION
for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { monitor_printf(VAR_0, "arg%d = '%s'\n", VAR_5, VAR_3[VAR_5]); } #endif
VAR_6 = strlen(VAR_1); if (VAR_6 > 0 && qemu_isspace(VAR_1[VAR_6 - 1])) { if (VAR_4 >= MAX_ARGS) { goto cleanup; } VAR_3[VAR_4++] = g_strdup(""); } if (VAR_4 <= 1) { if (VAR_4 == 0)
VAR_2 = ""; else
VAR_2 = VAR_3[0]; readline_set_completion_index(VAR_0->rs, strlen(VAR_2)); for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) { cmd_completion(VAR_0, VAR_2, VAR_9->name); } } else { for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) { if (compare_cmd(VAR_3[0], VAR_9->name)) { break; } } if (!VAR_9->name) { goto cleanup; } VAR_7 = next_arg_type(VAR_9->args_type); for(VAR_5 = 0; VAR_5 < VAR_4 - 2; VAR_5++) { if (*VAR_7 != '\0') { VAR_7 = next_arg_type(VAR_7); while (*VAR_7 == '?')
VAR_7 = next_arg_type(VAR_7); } } VAR_8 = VAR_3[VAR_4 - 1]; if (*VAR_7 == '-' && VAR_7[1] != '\0') { VAR_7 = next_arg_type(VAR_7); } switch(*VAR_7) { case 'F':
readline_set_completion_index(VAR_0->rs, strlen(VAR_8)); file_completion(VAR_0, VAR_8); break; case 'B':
mbs.VAR_0 = VAR_0; mbs.input = VAR_8; readline_set_completion_index(VAR_0->rs, strlen(VAR_8)); bdrv_iterate(block_completion_it, &mbs); break; case 's':
if (!strcmp(VAR_9->name, "info")) { readline_set_completion_index(VAR_0->rs, strlen(VAR_8)); for(VAR_9 = info_cmds; VAR_9->name != NULL; VAR_9++) { cmd_completion(VAR_0, VAR_8, VAR_9->name); } } else if (!strcmp(VAR_9->name, "sendkey")) { char *VAR_10 = strrchr(VAR_8, '-'); if (VAR_10)
VAR_8 = VAR_10 + 1; readline_set_completion_index(VAR_0->rs, strlen(VAR_8)); for (VAR_5 = 0; VAR_5 < Q_KEY_CODE_MAX; VAR_5++) { cmd_completion(VAR_0, VAR_8, QKeyCode_lookup[VAR_5]); } } else if (!strcmp(VAR_9->name, "help|?")) { readline_set_completion_index(VAR_0->rs, strlen(VAR_8)); for (VAR_9 = VAR_0->cmd_table; VAR_9->name != NULL; VAR_9++) { cmd_completion(VAR_0, VAR_8, VAR_9->name); } } break; default:
break; } } cleanup:
for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { g_free(VAR_3[VAR_5]); } }