Example #1
0
string checkReal(double val)
{
    if (strcmp(ifloat(), "float") == 0) {
        return checkFloat(val);
    } else {
        return checkDouble(val);
    }
}
Example #2
0
void DocCompiler::getTypedNames(Type t, const string& prefix, string& ctype, string& vname)
{
    if (t->nature() == kInt) {
        ctype = "int"; vname = subst("$0", getFreshID(prefix));
    } else {
        ctype = ifloat(); vname = subst("$0", getFreshID(prefix));
    }
}
Example #3
0
void
prim_strtof(PRIM_PROTOTYPE)
{
	CHECKOP(1);
	oper1 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument. (1)");
	fresult = 0.0;
	if (!oper1->data.string || !ifloat(oper1->data.string->data)) {
		fresult = 0.0;
		fr->error.error_flags.nan = 1;
	} else {
		sscanf(oper1->data.string->data, "%g", &fresult);
	}
	CLEAR(oper1);
	PushFloat(fresult);
}
Example #4
0
int
db_get_single_prop(FILE * f, dbref obj, int pos)
{
    char getprop_buf[BUFFER_LEN * 3];
    char *name, *flags, *value, *p;
    int tpos = 0;
    bool do_diskbase_propvals;
    PData pdat;

#ifdef DISKBASE
    do_diskbase_propvals = tp_diskbase_propvals;
#else
    do_diskbase_propvals = 0;
#endif

    if (pos) {
        fseek(f, pos, 0);
    } else if (do_diskbase_propvals) {
        tpos = ftell(f);
    }
    name = fgets(getprop_buf, sizeof(getprop_buf), f);
    if (!name) {
        fprintf(stderr, "PANIC: Error reading property in from db file.\n");
        abort();
    }
    if (*name == '*') {
        if (!strcmp(name, "*End*\n")) {
            return 0;
        }
    }

    flags = index(name, PROP_DELIMITER);
    if (!flags) {               /* this usually means the db file has new lines in the
                                 * middle of properties. Something like this can be
                                 * salvaged by editing the props in question.
                                 */
        fprintf(stderr,
                "PANIC: Unable to find prop flags while loading props.\n");
        abort();
    }
    *flags++ = '\0';

    value = index(flags, PROP_DELIMITER);
    if (!value) {
        fprintf(stderr,
                "PANIC: Unable to find prop value while loading props.\n");
        abort();
    }
    *value++ = '\0';

    p = index(value, '\n');
    if (p)
        *p = '\0';

    if (!number(flags)) {
        fprintf(stderr, "PANIC: Prop flag was not a number. DB error.\n");
        abort();
    }

    pdat.flags = atoi(flags);

    switch (pdat.flags & PROP_TYPMASK) {
        case PROP_STRTYP:
            if (!do_diskbase_propvals || pos) {
                pdat.flags &= ~PROP_ISUNLOADED;
#if defined(COMPRESS) && defined(ARCHAIC_DATABASES)
                if (!(pdat.flags & PROP_COMPRESSED))
                    value = (char *) old_uncompress(value);
#endif
                pdat.data.str = value;
            } else {
                pdat.flags |= PROP_ISUNLOADED;
                pdat.data.pos = tpos;
            }
            break;
        case PROP_LOKTYP:
            if (!do_diskbase_propvals || pos) {
                pdat.flags &= ~PROP_ISUNLOADED;
                pdat.data.lok = parse_boolexp(-1, (dbref) 1, value, 32767);
            } else {
                pdat.flags |= PROP_ISUNLOADED;
                pdat.data.pos = tpos;
            }
            break;
        case PROP_INTTYP:
            if (!number(value)) {
                fprintf(stderr, "PANIC: INT prop had non-int value in db.\n");
                abort();
            }
            pdat.data.val = atoi(value);
            break;
        case PROP_FLTTYP:
            if (!number(value) && !ifloat(value)) {
                char *tpnt = value;
                int dtemp = 0;

                if ((*tpnt == '+') || (*tpnt == '-')) {
                    if (*tpnt == '+') {
                        dtemp = 0;
                    } else {
                        dtemp = 1;
                    }
                    tpnt++;
                }
                tpnt[0] = toupper(tpnt[0]);
                tpnt[1] = toupper(tpnt[1]);
                tpnt[2] = toupper(tpnt[2]);
                if (!strncmp(tpnt, "INF", 3)) {
                    if (!dtemp)
                        pdat.data.fval = INF;
                    else
                        pdat.data.fval = NINF;
                } else {
                    if (!strncmp(tpnt, "NAN", 3)) {
                        pdat.data.fval = NAN;
                    } else {
                        fprintf(stderr,
                                "PANIC:Float prop contained invalid value.\n");
                        abort();
                    }
                }
            } else {
                sscanf(value, "%lg", (double *) &pdat.data.fval);
            }
            break;
        case PROP_REFTYP:
            if (!number(value)) {
                fprintf(stderr,
                        "PANIC:Ref prop contained non-numeric value.\n");
                abort();
            }
            pdat.data.ref = atoi(value);
            break;
        case PROP_DIRTYP:
            break;
    }
    set_property_nofetch(obj, name, &pdat, 1);

    return 1;
}
Example #5
0
/**
 * Push something into the stack from the debugger
 *
 * This can be a number, float, string, dbref, or variable.
 *
 * Variables are parsed almost the same as debug_printvar.  In fact, it
 * looks pretty copy-pasty.  For variable formating rules,
 * @see debug_printvar
 *
 * @private
 * @param player the player doing the pushing
 * @param fr the frame pointer
 * @param arg the argument which is a string containing something to push
 */
static void
push_arg(dbref player, struct frame *fr, const char *arg)
{
    int num, lflag = 0;
    int sflag = 0;
    double inum;

    if (fr->argument.top >= STACK_SIZE) {
        notify_nolisten(player, "That would overflow the stack.", 1);
        return;
    }

    if (number(arg)) {
        /* push a number */
        num = atoi(arg);
        push(fr->argument.st, &fr->argument.top, PROG_INTEGER, MIPSCAST & num);
        notify_nolisten(player, "Integer pushed.", 1);
    } else if (ifloat(arg)) {
        /* push a float */
        inum = atof(arg);
        push(fr->argument.st, &fr->argument.top, PROG_FLOAT, MIPSCAST & inum);
        notify_nolisten(player, "Float pushed.", 1);
    } else if (*arg == NUMBER_TOKEN) {
        /* push a dbref */
        if (!number(arg + 1)) {
            notify_nolisten(player, "I don't understand that dbref.", 1);
            return;
        }

        num = atoi(arg + 1);
        push(fr->argument.st, &fr->argument.top, PROG_OBJECT, MIPSCAST & num);
        notify_nolisten(player, "Dbref pushed.", 1);
    } else if (*arg == '"') {
        /* push a string */
        char buf[BUFFER_LEN];
        char *ptr;
        const char *ptr2;

        for (ptr = buf, ptr2 = arg + 1; *ptr2; ptr2++) {
            if (*ptr2 == '\\') {
                if (!*(++ptr2))
                    break;

                *ptr++ = *ptr2;
            } else if (*ptr2 == '"') {
                break;
            } else {
                *ptr++ = *ptr2;
            }
        }

        *ptr = '\0';
        push(fr->argument.st, &fr->argument.top, PROG_STRING, MIPSCAST alloc_prog_string(buf));
        notify_nolisten(player, "String pushed.", 1);
    } else {
        /*
         * @TODO This is basically copy/pasted from debug_printvar.
         *       The variable resolution should probably be a common
         *       function.
         */
        int varnum = scopedvar_getnum(fr, 0, arg);

        if (varnum != -1) {
            sflag = 1;
        } else {
            if (*arg == 'S' || *arg == 's') {
                arg++;

                if (*arg == 'V' || *arg == 'v') {
                    arg++;
                }

                sflag = 1;
                varnum = scopedvar_getnum(fr, 0, arg);
            } else if (*arg == 'L' || *arg == 'l') {
                arg++;

                if (*arg == 'V' || *arg == 'v') {
                    arg++;
                }

                lflag = 1;
            } else if (*arg == 'V' || *arg == 'v') {
                arg++;
            }
        }

        if (varnum > -1) {
            num = varnum;
        } else if (number(arg)) {
            num = atoi(arg);
        } else {
            notify_nolisten(player, "I don't understand what you want to push.", 1);
            return;
        }

        if (lflag) {
            push(fr->argument.st, &fr->argument.top, PROG_LVAR, MIPSCAST & num);
            notify_nolisten(player, "Local variable pushed.", 1);
        } else if (sflag) {
            push(fr->argument.st, &fr->argument.top, PROG_SVAR, MIPSCAST & num);
            notify_nolisten(player, "Scoped variable pushed.", 1);
        } else {
            push(fr->argument.st, &fr->argument.top, PROG_VAR, MIPSCAST & num);
            notify_nolisten(player, "Global variable pushed.", 1);
        }
    }
}
Example #6
0
static void
push_arg(dbref player, struct frame *fr, const char *arg)
{
    int num, lflag, sflag = 0;
    float inum;

    if (fr->argument.top >= STACK_SIZE) {
	anotify_nolisten(player, CFAIL "That would overflow the stack.", 1);
	return;
    }
    if (number(arg)) {
	/* push a number */
	num = atoi(arg);
	push(fr->argument.st, &fr->argument.top, PROG_INTEGER, MIPSCAST &num);
	anotify_nolisten(player, CSUCC "Integer pushed.", 1);
    } else if (ifloat(arg)) {
	/* push a float */
	inum = (float) atof(arg);
	push(fr->argument.st, &fr->argument.top, PROG_FLOAT, MIPSCAST & inum);
	notify_nolisten(player, "Float pushed.", 1);
    } else if (*arg == '#') {
	/* push a dbref */
	if (!number(arg+1)) {
	    anotify_nolisten(player, CINFO "I don't understand that dbref.", 1);
	    return;
	}
	num = atoi(arg+1);
	push(fr->argument.st, &fr->argument.top, PROG_OBJECT, MIPSCAST &num);
	anotify_nolisten(player, CSUCC "Dbref pushed.", 1);
    } else if (*arg == 'L' || *arg == 'V' || *arg == 'l' || *arg == 'v') {
	if (*arg == 'S' || *arg == 's') {
	    arg++;
	    sflag = 1;
	} else if (*arg == 'L' || *arg == 'l') {
	    arg++;
	    lflag = 1;
      }
	if (*arg == 'V' || *arg == 'v')
	    arg++;
	if (!number(arg)) {
	    anotify_nolisten(player, CINFO "I don't understand which variable you mean.", 1);
	    return;
	}
	num = atoi(arg);
	if (lflag) {
	    push(fr->argument.st, &fr->argument.top, PROG_LVAR, MIPSCAST &num);
	    anotify_nolisten(player, CSUCC "Local variable pushed.", 1);
	} else if (sflag) {
	    push(fr->argument.st, &fr->argument.top, PROG_SVAR, MIPSCAST & num);
	    notify_nolisten(player, "Scoped variable pushed.", 1);
	} else {
	    push(fr->argument.st, &fr->argument.top, PROG_VAR, MIPSCAST &num);
	    anotify_nolisten(player, CSUCC "Global variable pushed.", 1);
	}
    } else if (*arg == '"') {
	/* push a string */
	char buf[BUFFER_LEN];
	char *ptr;
	const char *ptr2;

	for (ptr = buf, ptr2 = arg+1; *ptr2; ptr2++) {
	    if (*ptr2 == '\\') {
		if (!*(++ptr2)) break;
		*ptr++ = *ptr2;
	    } else if (*ptr2 == '"') {
		break;
	    } else {
		*ptr++ = *ptr2;
	    }
	}
	*ptr = '\0';
	push(fr->argument.st, &fr->argument.top, PROG_STRING,
		MIPSCAST alloc_prog_string(buf));
	anotify_nolisten(player, CSUCC "String pushed.", 1);
    } else {
	anotify_nolisten(player, CINFO "I don't know that data type.", 1);
    }
}