Revision 3350a4dd

b/monitor.c
47 47
#include "kvm.h"
48 48
#include "acl.h"
49 49
#include "qint.h"
50
#include "qfloat.h"
50 51
#include "qlist.h"
51 52
#include "qdict.h"
52 53
#include "qbool.h"
......
70 71
 * 'l'          target long (32 or 64 bit)
71 72
 * 'M'          just like 'l', except in user mode the value is
72 73
 *              multiplied by 2^20 (think Mebibyte)
74
 * 'b'          double
75
 *              user mode accepts an optional G, g, M, m, K, k suffix,
76
 *              which multiplies the value by 2^30 for suffixes G and
77
 *              g, 2^20 for M and m, 2^10 for K and k
73 78
 * '/'          optional gdb-like print format (like "/10x")
74 79
 *
75 80
 * '?'          optional type (for all types, except '/')
......
3299 3304
    return 0;
3300 3305
}
3301 3306

  
3307
static int get_double(Monitor *mon, double *pval, const char **pp)
3308
{
3309
    const char *p = *pp;
3310
    char *tailp;
3311
    double d;
3312

  
3313
    d = strtod(p, &tailp);
3314
    if (tailp == p) {
3315
        monitor_printf(mon, "Number expected\n");
3316
        return -1;
3317
    }
3318
    if (d != d || d - d != 0) {
3319
        /* NaN or infinity */
3320
        monitor_printf(mon, "Bad number\n");
3321
        return -1;
3322
    }
3323
    *pval = d;
3324
    *pp = tailp;
3325
    return 0;
3326
}
3327

  
3302 3328
static int get_str(char *buf, int buf_size, const char **pp)
3303 3329
{
3304 3330
    const char *p;
......
3635 3661
                qdict_put(qdict, key, qint_from_int(val));
3636 3662
            }
3637 3663
            break;
3664
        case 'b':
3665
            {
3666
                double val;
3667

  
3668
                while (qemu_isspace(*p))
3669
                    p++;
3670
                if (*typestr == '?') {
3671
                    typestr++;
3672
                    if (*p == '\0') {
3673
                        break;
3674
                    }
3675
                }
3676
                if (get_double(mon, &val, &p) < 0) {
3677
                    goto fail;
3678
                }
3679
                if (*p) {
3680
                    switch (*p) {
3681
                    case 'K': case 'k':
3682
                        val *= 1 << 10; p++; break;
3683
                    case 'M': case 'm':
3684
                        val *= 1 << 20; p++; break;
3685
                    case 'G': case 'g':
3686
                        val *= 1 << 30; p++; break;
3687
                    }
3688
                }
3689
                if (*p && !qemu_isspace(*p)) {
3690
                    monitor_printf(mon, "Unknown unit suffix\n");
3691
                    goto fail;
3692
                }
3693
                qdict_put(qdict, key, qfloat_from_double(val));
3694
            }
3695
            break;
3638 3696
        case '-':
3639 3697
            {
3640 3698
                const char *tmp = p;
......
4060 4118
                return -1;
4061 4119
            }
4062 4120
            break;
4121
        case 'b':
4122
            if (qobject_type(value) != QTYPE_QINT && qobject_type(value) != QTYPE_QFLOAT) {
4123
                qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "number");
4124
                return -1;
4125
            }
4126
            break;
4063 4127
        case '-':
4064 4128
            if (qobject_type(value) != QTYPE_QINT &&
4065 4129
                qobject_type(value) != QTYPE_QBOOL) {

Also available in: Unified diff