static void monitor_find_completion(const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    const mon_cmd_t *cmd;

    const KeyDef *key;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        monitor_printf(cur_mon, "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 && 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(cur_mon->rs, strlen(cmdname));

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

            cmd_completion(cmdname, cmd->name);

        }

    } else {

        /* find the command */

        for (cmd = mon_cmds; 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(cur_mon->rs, strlen(str));

            file_completion(str);

            break;

        case 'B':

            /* block device name completion */

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

            bdrv_iterate(block_completion_it, (void *)str);

            break;

        case 's':

            /* XXX: more generic ? */

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

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

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

                    cmd_completion(str, cmd->name);

                }

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

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

                if (sep)

                    str = sep + 1;

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

                for(key = key_defs; key->name != NULL; key++) {

                    cmd_completion(str, key->name);

                }

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

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

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

                    cmd_completion(str, cmd->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

        g_free(args[i]);

    }

}

static void monitor_find_completion(const char *cmdline)

{

    const char *cmdname;

    char *args[MAX_ARGS];

    int nb_args, i, len;

    const char *ptype, *str;

    const mon_cmd_t *cmd;

    const KeyDef *key;



    parse_cmdline(cmdline, &nb_args, args);

#ifdef DEBUG_COMPLETION

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

        monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)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(cur_mon->rs, strlen(cmdname));

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

            cmd_completion(cmdname, cmd->name);

        }

    } else {

        

        for (cmd = mon_cmds; 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(cur_mon->rs, strlen(str));

            file_completion(str);

            break;

        case 'B':

            

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

            bdrv_iterate(block_completion_it, (void *)str);

            break;

        case 's':

            

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

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

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

                    cmd_completion(str, cmd->name);

                }

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

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

                if (sep)

                    str = sep + 1;

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

                for(key = key_defs; key->name != NULL; key++) {

                    cmd_completion(str, key->name);

                }

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

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

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

                    cmd_completion(str, cmd->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

        g_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;

    const mon_cmd_t *VAR_8;

    const KeyDef *VAR_9;



    parse_cmdline(VAR_0, &VAR_3, VAR_2);

#ifdef DEBUG_COMPLETION

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

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

    }

#endif



    



    VAR_5 = strlen(VAR_0);

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

        if (VAR_3 >= MAX_ARGS) {

            goto cleanup;

        }

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

    }

    if (VAR_3 <= 1) {

        

        if (VAR_3 == 0)

            VAR_1 = "";

        else

            VAR_1 = VAR_2[0];

        readline_set_completion_index(cur_mon->rs, strlen(VAR_1));

        for(VAR_8 = mon_cmds; VAR_8->name != NULL; VAR_8++) {

            cmd_completion(VAR_1, VAR_8->name);

        }

    } else {

        

        for (VAR_8 = mon_cmds; VAR_8->name != NULL; VAR_8++) {

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

                break;

            }

        }

        if (!VAR_8->name) {

            goto cleanup;

        }



        VAR_6 = next_arg_type(VAR_8->args_type);

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

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

                VAR_6 = next_arg_type(VAR_6);

                while (*VAR_6 == '?')

                    VAR_6 = next_arg_type(VAR_6);

            }

        }

        VAR_7 = VAR_2[VAR_3 - 1];

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

            VAR_6 = next_arg_type(VAR_6);

        }

        switch(*VAR_6) {

        case 'F':

            

            readline_set_completion_index(cur_mon->rs, strlen(VAR_7));

            file_completion(VAR_7);

            break;

        case 'B':

            

            readline_set_completion_index(cur_mon->rs, strlen(VAR_7));

            bdrv_iterate(block_completion_it, (void *)VAR_7);

            break;

        case 's':

            

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

                readline_set_completion_index(cur_mon->rs, strlen(VAR_7));

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

                    cmd_completion(VAR_7, VAR_8->name);

                }

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

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

                if (VAR_10)

                    VAR_7 = VAR_10 + 1;

                readline_set_completion_index(cur_mon->rs, strlen(VAR_7));

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

                    cmd_completion(VAR_7, VAR_9->name);

                }

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

                readline_set_completion_index(cur_mon->rs, strlen(VAR_7));

                for (VAR_8 = mon_cmds; VAR_8->name != NULL; VAR_8++) {

                    cmd_completion(VAR_7, VAR_8->name);

                }

            }

            break;

        default:

            break;

        }

    }



cleanup:

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

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