Revision 55f81d96

b/monitor.c
2590 2590

  
2591 2591
#define MAX_ARGS 16
2592 2592

  
2593
static void monitor_handle_command(Monitor *mon, const char *cmdline)
2593
static const mon_cmd_t *monitor_parse_command(Monitor *mon,
2594
                                              const char *cmdline,
2595
                                              void *str_allocated[],
2596
                                              QDict *qdict)
2594 2597
{
2595 2598
    const char *p, *typestr;
2596
    int c, nb_args, i, has_arg;
2599
    int c, nb_args, has_arg;
2597 2600
    const mon_cmd_t *cmd;
2598 2601
    char cmdname[256];
2599 2602
    char buf[1024];
2600 2603
    char *key;
2601
    QDict *qdict;
2602
    void *str_allocated[MAX_ARGS];
2603 2604
    void *args[MAX_ARGS];
2604
    void (*handler_d)(Monitor *mon, const QDict *qdict);
2605 2605

  
2606 2606
#ifdef DEBUG
2607 2607
    monitor_printf(mon, "command='%s'\n", cmdline);
......
2610 2610
    /* extract the command name */
2611 2611
    p = get_command_name(cmdline, cmdname, sizeof(cmdname));
2612 2612
    if (!p)
2613
        return;
2613
        return NULL;
2614 2614

  
2615 2615
    /* find the command */
2616 2616
    for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
......
2620 2620

  
2621 2621
    if (cmd->name == NULL) {
2622 2622
        monitor_printf(mon, "unknown command: '%s'\n", cmdname);
2623
        return;
2623
        return NULL;
2624 2624
    }
2625 2625

  
2626
    qdict = qdict_new();
2627

  
2628
    for(i = 0; i < MAX_ARGS; i++)
2629
        str_allocated[i] = NULL;
2630

  
2631 2626
    /* parse the parameters */
2632 2627
    typestr = cmd->args_type;
2633 2628
    nb_args = 0;
......
2872 2867
        goto fail;
2873 2868
    }
2874 2869

  
2875
    qemu_errors_to_mon(mon);
2876
    switch(nb_args) {
2877
    case 0:
2878
    case 1:
2879
    case 2:
2880
    case 3:
2881
    case 4:
2882
    case 5:
2883
    case 6:
2884
    case 7:
2885
    case 10:
2886
        handler_d = cmd->handler;
2887
        handler_d(mon, qdict);
2888
        break;
2889
    default:
2890
        monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
2891
        break;
2892
    }
2893
    qemu_errors_to_previous();
2870
    return cmd;
2894 2871

  
2895
 fail:
2872
fail:
2896 2873
    qemu_free(key);
2897
    for(i = 0; i < MAX_ARGS; i++)
2898
        qemu_free(str_allocated[i]);
2874
    return NULL;
2875
}
2876

  
2877
static void monitor_handle_command(Monitor *mon, const char *cmdline)
2878
{
2879
    int i;
2880
    QDict *qdict;
2881
    const mon_cmd_t *cmd;
2882
    void *str_allocated[MAX_ARGS];
2883

  
2884
    qdict = qdict_new();
2885

  
2886
    for (i = 0; i < MAX_ARGS; i++)
2887
        str_allocated[i] = NULL;
2888

  
2889
    cmd = monitor_parse_command(mon, cmdline, str_allocated, qdict);
2890
    if (cmd) {
2891
        void (*handler)(Monitor *mon, const QDict *qdict);
2892

  
2893
        qemu_errors_to_mon(mon);
2894

  
2895
        handler = cmd->handler;
2896
        handler(mon, qdict);
2897

  
2898
        qemu_errors_to_previous();
2899
    }
2900

  
2899 2901
    QDECREF(qdict);
2902

  
2903
    for (i = 0; i < MAX_ARGS; i++)
2904
        qemu_free(str_allocated[i]);
2900 2905
}
2901 2906

  
2902 2907
static void cmd_completion(const char *name, const char *list)

Also available in: Unified diff