Ejemplo n.º 1
0
void
close_out_pipes(void)
{
    FILE_NODE *p = file_list;
    FILE_NODE *q = 0;

    while (p) {

	if (IS_OUTPUT(p->type)) {
	    if (fclose((FILE *) p->ptr) != 0) {
		/* if another error occurs we do not want to be called
		   for the same file again */

		if (q != 0)
		    q->link = p->link;
		else
		    file_list = p->link;
		close_error(p);
	    } else if (p->type == PIPE_OUT) {
		wait_for(p->pid);
	    }
	}

	q = p;
	p = p->link;
    }
}
Ejemplo n.º 2
0
int
file_flush(STRING * sval)
{
    int ret = 0;
    FILE_NODE *p = file_list;
    size_t len = sval->len;
    char *str = sval->str;

    if (len == 0) {
	/* for consistency with gawk */
	ret = flush_all_output();
    } else {
	int found = 0;
	while (p) {
	    if (IS_OUTPUT(p->type) &&
		len == p->name->len &&
		strcmp(str, p->name->str) == 0) {
		found = 1;
		if (efflush((FILE *) p->ptr) != 0)
		    ret = -1;
		/* it's possible for a command and a file to have the same
		   name -- so keep looking */
	    }
	    p = p->link;
	}
	if (!found)
	    ret = -1;
    }
    return ret;
}
Ejemplo n.º 3
0
	Encoder (const Interleaver<Rnd_It> &symbols, const uint8_t SBN)
		:precode (Parameters (symbols.source_symbols(SBN))), _symbols(symbols),
		  _SBN(SBN)
	{
		IS_RANDOM(Rnd_It, "RaptorQ::Impl::Encoder");
		IS_OUTPUT(Out_It, "RaptorQ::Impl::Encoder");
		precode.gen(0);
	}
Ejemplo n.º 4
0
int
flush_all_output(void)
{
    int ret = 0;
    FILE_NODE *p;

    for (p = file_list; p; p = p->link) {
	if (IS_OUTPUT(p->type)) {
	    if (efflush((FILE *) p->ptr) != 0)
		ret = -1;
	}
    }
    return ret;
}
Ejemplo n.º 5
0
void gpio_configure(port_t *port) {
    /* set GPIO function */
    if (port->port_no >= GPIO12_NO && port->port_no <= GPIO15_NO) {
        PIN_FUNC_SELECT(ports_get_gpio_mux(port->port_no), 3 /* function number 3 is the GPIO */);
    }
    
    if (IS_OUTPUT(port)) {
        if (IS_PULL_UP(port)) {
            PIN_PULLUP_EN(ports_get_gpio_mux(port->port_no));
        }
        else {
            PIN_PULLUP_DIS(ports_get_gpio_mux(port->port_no));
        }
    }
    else {
        GPIO_DIS_OUTPUT(port->port_no);
    }
}
Ejemplo n.º 6
0
void port_load(port_t *port, char *data) {
    char *base_ptr = data + CONFIG_OFFS_PORT_BASE + CONFIG_PORT_SIZE * port->port_no;
    char *expr_ptr = data + CONFIG_OFFS_STR_BASE;

    /* description */
    memcpy(port->description, base_ptr + CONFIG_OFFS_PORT_DESC, PORT_MAX_DESC_LEN);
    port->description[PORT_MAX_DESC_LEN - 1] = 0;

    /* unit */
    memcpy(port->unit, base_ptr + CONFIG_OFFS_PORT_UNIT, PORT_MAX_UNIT_LEN);
    port->unit[PORT_MAX_UNIT_LEN - 1] = 0;

    /* flags */
    memcpy(&port->flags, base_ptr + CONFIG_OFFS_PORT_FLAGS, 4);

    /* value */
    memcpy(&port->value, base_ptr + CONFIG_OFFS_PORT_VALUE, 4);

    /* filter */
    port->filter_values = NULL;
    port->filter_width = 0;
    if (!IS_OUTPUT(port)) {
        memcpy(&port->filter_width, base_ptr + CONFIG_OFFS_PORT_FWIDTH, 4);
        if (!port->filter_width) {
            port->filter_width = 2;
        }
        port_filter_set(port, FILTER_TYPE(port), port->filter_width);
    }

    /* custom data */
    memcpy(port->data, base_ptr + CONFIG_OFFS_PORT_DATA, PORT_CUSTOM_DATA_LEN);

    int expr_offs;
    int len;

    port->sexpr = NULL;
    port->expr = NULL;
    port->stransform_write = NULL;
    port->transform_write = NULL;
    port->stransform_read = NULL;
    port->transform_read = NULL;

    if (IS_OUTPUT(port)) {
        /* value expression */
        memcpy(&expr_offs, base_ptr + CONFIG_OFFS_PORT_EXPR, 4);
        if (expr_offs) {
            len = strlen(expr_ptr + expr_offs);
            port->sexpr = malloc(len + 1);
            strcpy(port->sexpr, expr_ptr + expr_offs);
            /* the expression will be parsed later,
             * after all ports will have been loaded */
        }

        /* write transform */
        memcpy(&expr_offs, base_ptr + CONFIG_OFFS_PORT_TRANS_W, 4);
        if (expr_offs) {
            len = strlen(expr_ptr + expr_offs);
            port->stransform_write = malloc(len + 1);
            strcpy(port->stransform_write, expr_ptr + expr_offs);
            /* the expression will be parsed later,
             * after all ports will have been loaded */
        }
    }

    /* read transform */
    memcpy(&expr_offs, base_ptr + CONFIG_OFFS_PORT_TRANS_R, 4);
    if (expr_offs) {
        len = strlen(expr_ptr + expr_offs);
        port->stransform_read = malloc(len + 1);
        strcpy(port->stransform_read, expr_ptr + expr_offs);
        /* the expression will be parsed later,
         * after all ports will have been loaded */
    }

    DEBUG("port %s loaded: description=\"%s\", unit=\"%s\", expression=\"%s\", transform_w=\"%s\", transform_r=\"%s\", flags=0x%08X",
            port->id, port->description, port->unit, port->sexpr ? port->sexpr : "",
            port->stransform_write ? port->stransform_write : "", port->stransform_read ? port->stransform_read : "",
            port->flags);

    /* sequence */
    port->sequence_pos = -1;

    if (port->configure) {
        DEBUG("configuring port %s", port->id);
        port->configure(port);
    }

    if (IS_OUTPUT(port)) {
        if (IS_PERSISTED(port)) {
            port->value = port->value && 1;
            DEBUG("setting port %s to persisted value %d", port->id, port->value);
        }
        else {
            port->value = IS_PULL_UP(port) && 1;
            DEBUG("setting port %s to pull value %d", port->id, port->value);
        }

        port_set_value(port, port->value);
    }
    else { /* input */
        int value = port->read_value(port);
        if (value != UNDEFINED_VALUE) {
            port->value = value;
            if (port->transform_read) {
                port->value = expr_eval(port->transform_read);
            }
            if (FILTER_TYPE(port) && !IS_OUTPUT(port)) {
                port->value = port_filter_apply(port, port->value);
            }
            DEBUG("initialized port %s with read value %d", port->id, port->value && 1);
        }
        else {
            port->value = 0;
            DEBUG("initialized port %s with value 0", port->id);
        }
    }
}