示例#1
0
rstat op_dereference( dict *d, void *key ) {
    location *loc = NULL;
    rstat err = locate_key( d, key, &loc );

    if ( !err.num && loc->sref != NULL ) err = do_deref( d, key, loc, NULL );

    if ( loc != NULL ) free_location( d, loc );
    return err;
}
示例#2
0
文件: io.c 项目: npe9/sprite
static IOBUF *
nextfile()
{
	static int i = 1;
	static int files = 0;
	static IOBUF *curfile = NULL;
	char *arg;
	char *cp;
	int fd = -1;

	if (curfile != NULL && curfile->cnt != EOF)
		return curfile;
	for (; i < (int) (ARGC_node->lnode->numbr); i++) {
		arg = (*assoc_lookup(ARGV_node, tmp_number((AWKNUM) i)))->stptr;
		if (*arg == '\0')
			continue;
		cp = strchr(arg, '=');
		if (cp != NULL) {
			*cp++ = '\0';
			variable(arg)->var_value = make_string(cp, strlen(cp));
			*--cp = '=';	/* restore original text of ARGV */
		} else {
			files++;
			if (STREQ(arg, "-"))
				fd = 0;
			else
				fd = devopen(arg, "r");
			if (fd == -1)
				fatal("cannot open file `%s' for reading (%s)",
					arg, strerror(errno));
				/* NOTREACHED */
			/* This is a kludge.  */
			deref = FILENAME_node->var_value;
			do_deref();
			FILENAME_node->var_value =
				make_string(arg, strlen(arg));
			FNR_node->var_value->numbr = 0.0;
			i++;
			break;
		}
	}
	if (files == 0) {
		files++;
		/* no args. -- use stdin */
		/* FILENAME is init'ed to "-" */
		/* FNR is init'ed to 0 */
		fd = 0;
	}
	if (fd == -1)
		return NULL;
	return curfile = iop_alloc(fd);
}
示例#3
0
rstat op_reference( dict *orig, void *okey, set_spec *osp, dict *dest, void *dkey, set_spec *dsp ) {
    rstat out = rstat_ok;
    dev_assert( dsp->swap_from == NULL );
    location *oloc = NULL;
    location *dloc = NULL;

    // Find existing pairs
    out = locate_key( orig, okey, &oloc );
    if ( out.bit.error ) goto OP_REFERENCE_CLEANUP;
    out = locate_key( dest, dkey, &dloc );
    if ( out.bit.error ) goto OP_REFERENCE_CLEANUP;

    if ( oloc->set->immutable || dloc->set->immutable ) {
        out = rstat_imute;
        goto OP_REFERENCE_CLEANUP;
    }

    // No current value, and cannot insert
    if (( !oloc->sref || !oloc->xtrn ) && !osp->insert ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }
    if (( !dloc->sref || !dloc->xtrn ) && !dsp->insert ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }

    // Current value, but cannot update
    if ( dloc->xtrn && !dsp->update ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }

    if ( !oloc->sref ) {
        out = do_set( orig, &oloc, okey, NULL, osp );

        // Error on all but rebalance issues.
        if ( out.bit.error && !out.bit.rebal )
            goto OP_REFERENCE_CLEANUP;
    }

    if ( !dloc->usref ) {
        out = do_set( dest, &dloc, dkey, NULL, dsp );

        // Error on all but rebalance issues.
        if ( out.bit.error && !out.bit.rebal )
            goto OP_REFERENCE_CLEANUP;
    }

    dev_assert( oloc->sref );
    dev_assert( dloc->usref );

    dev_assert( !blocked_null( oloc->sref ));
    dev_assert( !blocked_null( dloc->usref ));

    out = do_deref( dest, dkey, dloc, oloc->usref->sref );

    OP_REFERENCE_CLEANUP:

    if ( oloc != NULL ) free_location( orig, oloc );
    if ( dloc != NULL ) free_location( dest, dloc );

    return out;
}