Esempio n. 1
0
STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) {
    mp_obj_t self;
    if (update) {
        check_set(args[0]);
        self = args[0];
    } else {
        self = set_copy(args[0]);
    }

    for (size_t i = 1; i < n_args; i++) {
        mp_obj_t other = args[i];
        if (self == other) {
            set_clear(self);
        } else {
            mp_set_t *self_set = &((mp_obj_set_t*)MP_OBJ_TO_PTR(self))->set;
            mp_obj_t iter = mp_getiter(other, NULL);
            mp_obj_t next;
            while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
                mp_set_lookup(self_set, next, MP_MAP_LOOKUP_REMOVE_IF_FOUND);
            }
        }
    }

    return self;
}
Esempio n. 2
0
/**********************************************************************
 *
 *	firstpos
 *
 * Fills firstpos-field in syntax tree. Here we suppose, that all
 * nodes below current node are already visited (depth-first traversal).
 * Firstpos is a set of positions that can match the first symbol of a 
 * string generated by the subexpression rooted by node.
 */
static void firstpos(REG1 int node, REG2 node_t* tnode)
{
	switch (tnode->type) {
		case EMPTY_ID:
		    set_clear(tnode->firstpos, rbuf.setsize);
		    break;
		case CLASS_ID:
		case ID:
		    add_set(tnode->firstpos, node);
		    break;
		case OR:
		    set_union(tnode->firstpos,
		        rbuf.tree[tnode->val.next.left].firstpos,
			rbuf.tree[tnode->val.next.right].firstpos,
			rbuf.setsize);
		    break;
		case CAT:
		    if (rbuf.tree[tnode->val.next.left].nullable)
			set_union(tnode->firstpos,
			    rbuf.tree[tnode->val.next.left].firstpos,
			    rbuf.tree[tnode->val.next.right].firstpos,
			    rbuf.setsize);
		    else
			set_copy(tnode->firstpos,
			    rbuf.tree[tnode->val.next.left].firstpos,
			    rbuf.setsize);
		    break;
		case CLOSURE:
		    set_copy(tnode->firstpos,
		         rbuf.tree[tnode->val.next.left].firstpos,
		         rbuf.setsize);
		    break;
	}
}
Esempio n. 3
0
STATIC mp_obj_t set_diff_int(int n_args, const mp_obj_t *args, bool update) {
    assert(n_args > 0);

    mp_obj_set_t *self;
    if (update) {
        check_set(args[0]);
        self = args[0];
    } else {
        check_set_or_frozenset(args[0]);
        self = set_copy_as_mutable(args[0]);
    }


    for (int i = 1; i < n_args; i++) {
        mp_obj_t other = args[i];
        if (self == other) {
            set_clear(self);
        } else {
            mp_obj_t iter = mp_getiter(other);
            mp_obj_t next;
            while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
                set_discard(self, next);
            }
        }
    }

    self->base.type = ((mp_obj_set_t*)args[0])->base.type;
    return self;
}
Esempio n. 4
0
static void 
commit_done(ipmi_solparm_t *solparm,
	    int            err,
	    void           *cb_data)
{
    ipmi_sol_config_t *solc = cb_data;
    unsigned char     data[1];
    int               rv;

    /* Note that we ignore the error.  The commit done is optional,
       and must return an error if it is optional, so we just ignore
       the error and clear the field here. */

    /* Commit is done.  The IPMI spec says that it goes into the
       set-in-progress state after this, so we need to clear it. */

    data[0] = 0;
    rv = ipmi_solparm_set_parm(solparm, 0, data, 1, set_clear, solc);
    if (rv) {
	ipmi_log(IPMI_LOG_WARNING,
		 "solparm.c(commit_done): Error trying to clear the set in"
		 " progress: %x",
		 rv);
	set_clear(solparm, err, solc);
    }
}
Esempio n. 5
0
STATIC mp_obj_t set_diff_int(int n_args, const mp_obj_t *args, bool update) {
    assert(n_args > 0);
    assert(MP_OBJ_IS_TYPE(args[0], &mp_type_set));
    mp_obj_set_t *self;
    if (update) {
        self = args[0];
    } else {
        self = set_copy(args[0]);
    }


    for (int i = 1; i < n_args; i++) {
        mp_obj_t other = args[i];
        if (self == other) {
            set_clear(self);
        } else {
            mp_obj_t iter = mp_getiter(other);
            mp_obj_t next;
            while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
                set_discard(self, next);
            }
        }
    }

    return self;
}
Esempio n. 6
0
File: set.c Progetto: romalik/rl_cpu
struct set * set_create_static(size_t capacity, size_t el_size, struct set * self, unsigned int * arena) {
  self->capacity = capacity;
  self->el_size = el_size;
  self->data = arena;
  set_clear(self);
  return self;
}
Esempio n. 7
0
void read_cube(register FILE *fp, pPLA PLA)
{
register int var, i;
pset cf = cube.temp[0], cr = cube.temp[1], cd = cube.temp[2];
int savef = 0, saved = 0, saver = 0;
char token[256]; int varx, first, last, offset;	set_clear(cf, cube.size);
for(var = 0; var < cube.num_binary_vars; var++)
switch((--(fp)->_cnt>=0? ((int)*(fp)->_ptr++):_filbuf(fp))) {
case (-1):
goto bad_char;
case '\n':
if (! line_length_error)
fprintf((&_iob[2]), "product term(s) %s\n",
"span more than one line (warning only)");
line_length_error = 1;
lineno++;
var--;
break;
case ' ': case '|': case '\t':
var--;
break;
case '2': case '-':
(cf[((( var*2+1) >> 5) + 1)] |= 1 << (( var*2+1) & (32-1)));
case '0':
(cf[((( var*2) >> 5) + 1)] |= 1 << (( var*2) & (32-1)));
break;
case '1':
(cf[((( var*2+1) >> 5) + 1)] |= 1 << (( var*2+1) & (32-1)));
break;
case '?':
break;
default:
goto bad_char;
}
for(var = cube.num_binary_vars; var < cube.num_vars-1; var++)
if (cube.part_size[var] < 0) {
(void) fscanf(fp, "%s", token);
if ((strcmp(token, "-") == 0) || (strcmp(token, "ANY") == 0)) {
if (kiss && var == cube.num_vars - 2) {
} else {
set_or(cf, cf, cube.var_mask[var]);
}
} else if ((strcmp(token, "~") == 0)) {
;
} else {
if (kiss && var == cube.num_vars - 2)
varx = var - 1, offset = ((cube.part_size[var-1]) < 0 ? -(cube.part_size[var-1]) : (cube.part_size[var-1]));
else
varx = var, offset = 0;
first = cube.first_part[varx];
last = cube.last_part[varx];
for(i = first; i <= last; i++)
if (PLA->label[i] == (char *) 0) {
PLA->label[i] = util_strsav(token);	(cf[((( i+offset) >> 5) + 1)] |= 1 << (( i+offset) & (32-1)));
break;
} else if ((strcmp(PLA->label[i], token) == 0)) {
Esempio n. 8
0
STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) {
    mp_obj_set_t *self;
    bool cleanup_self = false;
    if (is_set_or_frozenset(self_in)) {
        self = MP_OBJ_TO_PTR(self_in);
    } else {
        self = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &self_in));
        cleanup_self = true;
    }

    mp_obj_set_t *other;
    bool cleanup_other = false;
    if (is_set_or_frozenset(other_in)) {
        other = MP_OBJ_TO_PTR(other_in);
    } else {
        other = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &other_in));
        cleanup_other = true;
    }
    mp_obj_t out = mp_const_true;
    if (proper && self->set.used == other->set.used) {
        out = mp_const_false;
    } else {
        mp_obj_iter_buf_t iter_buf;
        mp_obj_t iter = set_getiter(MP_OBJ_FROM_PTR(self), &iter_buf);
        mp_obj_t next;
        while ((next = set_it_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
            if (!mp_set_lookup(&other->set, next, MP_MAP_LOOKUP)) {
                out = mp_const_false;
                break;
            }
        }
    }
    // TODO: Should free objects altogether
    if (cleanup_self) {
        set_clear(MP_OBJ_FROM_PTR(self));
    }
    if (cleanup_other) {
        set_clear(MP_OBJ_FROM_PTR(other));
    }
    return out;
}
Esempio n. 9
0
File: unate.c Progetto: spl/ivy
pcover map_cover_to_unate(pset *T)
{
    register unsigned int word_test, word_set, bit_test, bit_set;
    register pcube p, pA;
    pset_family A;
    pcube *T1;
    int ncol, i;

    A = sf_new(CUBELISTSIZE(T), cdata.vars_unate);
    A->count = CUBELISTSIZE(T);
    foreachi_set(A, i, p) {
	(void) set_clear(p, A->sf_size);
    }
Esempio n. 10
0
STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) {
    mp_obj_set_t *self;
    bool cleanup_self = false;
    if (MP_OBJ_IS_TYPE(self_in, &mp_type_set)) {
        self = self_in;
    } else {
        self = set_make_new((mp_obj_t)&mp_type_set, 1, 0, &self_in);
        cleanup_self = true;
    }

    mp_obj_set_t *other;
    bool cleanup_other = false;
    if (MP_OBJ_IS_TYPE(other_in, &mp_type_set)) {
        other = other_in;
    } else {
        other = set_make_new((mp_obj_t)&mp_type_set, 1, 0, &other_in);
        cleanup_other = true;
    }
    bool out = true;
    if (proper && self->set.used == other->set.used) {
        out = false;
    } else {
        mp_obj_t iter = set_getiter(self);
        mp_obj_t next;
        while ((next = set_it_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
            if (!mp_set_lookup(&other->set, next, MP_MAP_LOOKUP)) {
                out = false;
                break;
            }
        }
    }
    if (cleanup_self) {
        set_clear(self);
    }
    if (cleanup_other) {
        set_clear(other);
    }
    return MP_BOOL(out);
}
Esempio n. 11
0
void
set_test()
{
	printf("SET S: ");
	set* s = set_init();
	set_add(s, (SETDATA*)1);
	set_add(s, (SETDATA*)2);
	set_add(s, (SETDATA*)3);
	set_add(s, (SETDATA*)4);
	set_add(s, (SETDATA*)5);
	set_add(s, (SETDATA*)6);
	set_print(s, set_testcb);

	printf("S \\ 2, 6: ");
	set_remove(s, (SETDATA*)6);
	set_remove(s, (SETDATA*)2);
	set_print(s, set_testcb);
	
	printf("SET T: ");
	set* t = set_init();
	set_add(t, (SETDATA*)1);
	set_add(t, (SETDATA*)2);
	set_add(t, (SETDATA*)9);
	set_add(t, (SETDATA*)4);
	set_print(t, set_testcb);
	
	printf("UNION OF S, T: ");
	set* u = set_init();
	set_union(u, s, t);
	set_print(u, set_testcb);
	
	printf("INTERSECTION OF S, T: ");
	set* i = set_init();
	set_intersection(i, s, t);
	set_print(i, set_testcb);
	
	printf("DIFFERENCE OF S, T: ");
	set* d = set_init();
	set_difference(d, s, t);
	set_print(d, set_testcb);
	
	printf("CLEAR S: ");
	set_clear(s);
	set_print(s, set_testcb);
	
	set_free(s);
	set_free(t);
	set_free(u);
	set_free(i);
	set_free(d);
}
Esempio n. 12
0
static int torisa_chanconfig(struct zt_chan *chan, int sigtype)
{
	int alreadyrunning;
	unsigned long flags;
	alreadyrunning = chan->span->flags & ZT_FLAG_RUNNING;
	if (debug) {
		if (alreadyrunning)
			printk("TorISA: Reconfigured channel %d (%s) sigtype %d\n", chan->channo, chan->name, sigtype);
		else
			printk("TorISA: Configured channel %d (%s) sigtype %d\n", chan->channo, chan->name, sigtype);
	}		
	write_lock_irqsave(&torisa, flags);	
	if (alreadyrunning && (card_type == TYPE_T1))
		set_clear();
	write_unlock_irqrestore(&torisa, flags);	
	return 0;
}
Esempio n. 13
0
void set_delete(struct set *s)
{
	set_clear(s);
	free(s->buckets);
	free(s);
}
Esempio n. 14
0
static void 
set_done(ipmi_solparm_t *solparm,
	 int            err,
	 void           *cb_data)
{
    ipmi_sol_config_t *solc = cb_data;
    unsigned char     data[MAX_IPMI_DATA_SIZE];
    solparms_t        *lp = &(solparms[solc->curr_parm]);

    if (err == IPMI_IPMI_ERR_VAL(0x82)) {
	/* We attempted to write a read-only parameter that is not
	   marked by the spec as read-only.  Just ignore it. */
	err = 0;
    }

    if (err) {
	ipmi_log(IPMI_LOG_ERR_INFO,
		 "solparm.c(set_done): Error setting sol parm %d sel %d: %x",
		 solc->curr_parm, solc->curr_sel, err);
	goto done;
    }

 next_parm:
    switch (solc->curr_parm) {
    case IPMI_SOLPARM_PAYLOAD_PORT_NUMBER:
	goto done;
    default:
	solc->curr_parm++;
    }

    lp = &(solparms[solc->curr_parm]);
    if ((!lp->valid) || (!lp->set_handler)
	|| (lp->optional_offset
	    && !(((unsigned char *) solc)[lp->optional_offset])))
    {
	/* The parameter is read-only or not supported, just go on. */
	goto next_parm;
    }

    lp->set_handler(solc, lp, data);
    err = ipmi_solparm_set_parm(solparm, solc->curr_parm,
				data, lp->length, set_done, solc);
    if (err)
	goto done;

    return;

 done:
    if (!solc->lock_supported) {
	/* No lock support, just finish the operation. */
	set_clear(solparm, err, solc);
	return;
    }
    else if (err) {
	data[0] = 0; /* Don't commit the parameters. */
	solc->err = err;
	err = ipmi_solparm_set_parm(solparm, 0, data, 1, set_clear, solc);
    } else {
	data[0] = 2; /* Commit the parameters. */
	err = ipmi_solparm_set_parm(solparm, 0, data, 1, commit_done, solc);
    }
    if (err) {
	ipmi_log(IPMI_LOG_WARNING,
		 "solparm.c(set_done): Error trying to clear the set in"
		 " progress: %x",
		 err);
	set_clear(solparm, err, solc);
    }
}
Esempio n. 15
0
void test_set(void)
{
  int i;
  void* S = set_create(100, NULL, NULL);
  fprintf(stdout, "call function : %s\n", __func__);
  set_object(S);

  fprintf(stdout, "\ntest function - set_insert ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * rand() % 1000 * 0.456;
      fprintf(stdout, "\tinsert {object=>0x%p, vlaue=>%.3f}\n", d, *d);
      set_insert(S, d);
    }
    set_object(S);

    set_for_each(S, set_member_show_double, NULL);
    set_for_each(S, set_member_destroy, NULL);
    set_object(S);
    set_clear(S);
  }
  set_object(S);

  fprintf(stdout, "\ntest function - set_remove ===>\n");
  {
    double* remove_member = NULL;
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * rand() % 1000 * 0.456;
      fprintf(stdout, "\tinsert {object=>0x%p, vlaue=>%.3f}\n", d, *d);
      set_insert(S, d);

      if (0 == i)
        remove_member = d;
    }
    set_object(S);
    set_for_each(S, set_member_show_double, NULL);

    set_remove(S, remove_member);
    set_object(S);
    set_for_each(S, set_member_show_double, NULL);

    set_for_each(S, set_member_destroy, NULL);
    set_object(S);
    set_clear(S);
  }
  set_object(S);

  fprintf(stdout, "\ntest function - set_release ===>\n");
  set_release(&S);
  set_object(S);


  fprintf(stdout, "\n\ntest function - set operations ===>\n");
  {
    void* s = set_create(100, NULL, NULL);
    void* t = set_create(100, NULL, NULL);
    void* oper_s;

    for (i = 0; i < 7; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * (i + 1) * 0.234;
      fprintf(stdout, "\tinsert s {object=>0x%p, value=>%.3f}\n", d, *d);
      if (i < 5)
        set_insert(s, d);
      set_insert(t, d);        
    }

    fprintf(stdout, "  show 's' set object:\n");
    set_object(s);
    set_for_each(s, set_member_show_double, NULL);
    fprintf(stdout, "  show 't' set object:\n");
    set_object(t);
    set_for_each(t, set_member_show_double, NULL);

    /* set_union */
    fprintf(stdout, "  test function - set_union ===>\n");
    oper_s = set_union(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_union(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_union(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=s,t=t):\n");
    set_object(oper_s);

    /* set_inter */
    fprintf(stdout, "  test function - set_inter ===>\n");
    oper_s = set_inter(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_inter(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_inter(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=s,t=t):\n");
    set_object(oper_s);

    /* set_minus */
    fprintf(stdout, "  test function - set_minus ===>\n");
    oper_s = set_minus(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_minus(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_minus(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=s,t=t):\n");
    set_object(oper_s);

    /* set_diff */
    fprintf(stdout, "  test function - set_diff ===>\n");
    oper_s = set_diff(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_diff(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_diff(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=s,t=t):\n");
    set_object(oper_s);


    fprintf(stdout, "  release 's' and 't' object:\n");
    set_for_each(t, set_member_destroy, NULL);
    set_clear(s);
    set_clear(t);
    set_release(&s);
    set_release(&t);
    fprintf(stdout, "  show 's' set object:\n");
    set_object(s);
    fprintf(stdout, "  show 't' set object:\n");
    set_object(t);
  }
}
Esempio n. 16
0
/*
 *  Yes, I know this routine is a mess
 */
void read_cube(register FILE *fp, pPLA PLA)
{
    register int var, i;
    pcube cf = cube.temp[0], cr = cube.temp[1], cd = cube.temp[2];
    bool savef = FALSE, saved = FALSE, saver = FALSE;
    char token[256]; 			/* for kiss read hack */
    int varx, first, last, offset;	/* for kiss read hack */

    set_clear(cf, cube.size);

    /* Loop and read binary variables */
    for(var = 0; var < cube.num_binary_vars; var++)
	switch(getc(fp)) {
	    case EOF:
		goto bad_char;
	    case '\n':
		if (! line_length_error)
		    fprintf(stderr, "product term(s) %s\n",
			"span more than one line (warning only)");
		line_length_error = TRUE;
		lineno++;
		var--;
		break;
	    case ' ': case '|': case '\t':
		var--;
		break;
	    case '2': case '-':
		set_insert(cf, var*2+1);
	    case '0':
		set_insert(cf, var*2);
		break;
	    case '1':
		set_insert(cf, var*2+1);
		break;
	    case '?':
		break;
	    default:
		goto bad_char;
	}


    /* Loop for the all but one of the multiple-valued variables */	
    for(var = cube.num_binary_vars; var < cube.num_vars-1; var++)

	/* Read a symbolic multiple-valued variable */
	if (cube.part_size[var] < 0) {
	    (void) fscanf(fp, "%s", token);
	    if (equal(token, "-") || equal(token, "ANY")) {
		if (kiss && var == cube.num_vars - 2) {
		    /* leave it empty */
		} else {
		    /* make it full */
		    set_or(cf, cf, cube.var_mask[var]);
		}
	    } else if (equal(token, "~")) {
		;
		/* leave it empty ... (?) */
	    } else {
		if (kiss && var == cube.num_vars - 2)
		    varx = var - 1, offset = ABS(cube.part_size[var-1]);
		else
		    varx = var, offset = 0;
		/* Find the symbolic label in the label table */
		first = cube.first_part[varx];
		last = cube.last_part[varx];
		for(i = first; i <= last; i++)
		    if (PLA->label[i] == (char *) NULL) {
			PLA->label[i] = strdup(token);	/* add new label */
			set_insert(cf, i+offset);
			break;
		    } else if (equal(PLA->label[i], token)) {
			set_insert(cf, i+offset);	/* use column i */
			break;
		    }
		if (i > last) {
		    fprintf(stderr,
"declared size of variable %d (counting from variable 0) is too small\n", var);
		    exit(-1);
		}
	    }
	
	} else for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
	    switch (getc(fp)) {
		case EOF:
		    goto bad_char;
		case '\n':
		    if (! line_length_error)
			fprintf(stderr, "product term(s) %s\n",
			    "span more than one line (warning only)");
		    line_length_error = TRUE;
		    lineno++;
		    i--;
		    break;
		case ' ': case '|': case '\t':
		    i--;
		    break;
		case '1':
		    set_insert(cf, i);
		case '0':
		    break;
		default:
		    goto bad_char;
	    }

    /* Loop for last multiple-valued variable */
    if (kiss) {
	saver = savef = TRUE;
	(void) set_xor(cr, cf, cube.var_mask[cube.num_vars - 2]);
    } else
	set_copy(cr, cf);
    set_copy(cd, cf);
    for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
	switch (getc(fp)) {
	    case EOF:
		goto bad_char;
	    case '\n':
		if (! line_length_error)
		    fprintf(stderr, "product term(s) %s\n",
			"span more than one line (warning only)");
		line_length_error = TRUE;
		lineno++;
		i--;
		break;
	    case ' ': case '|': case '\t':
		i--;
		break;
	    case '4': case '1':
		if (PLA->pla_type & F_type)
		    set_insert(cf, i), savef = TRUE;
		break;
	    case '3': case '0':
		if (PLA->pla_type & R_type)
		    set_insert(cr, i), saver = TRUE;
		break;
	    case '2': case '-':
		if (PLA->pla_type & D_type)
		    set_insert(cd, i), saved = TRUE;
	    case '~':
		break;
	    default:
		goto bad_char;
	}
    if (savef) PLA->F = sf_addset(PLA->F, cf);
    if (saved) PLA->D = sf_addset(PLA->D, cd);
    if (saver) PLA->R = sf_addset(PLA->R, cr);
    return;

bad_char:
    fprintf(stderr, "(warning): input line #%d ignored\n", lineno);
    skip_line(fp, stdout, TRUE);
    return;
}
Esempio n. 17
0
static int torisa_startup(struct zt_span *span)
{
	unsigned long endjif;
	int i;
	int tspan;
	unsigned long flags;
	char *coding;
	char *framing;
	char *crcing;
	int alreadyrunning;

	tspan = getspan(span);
	if (tspan < 0) {
		printk("TorISA: Span '%d' isn't us?\n", span->spanno);
		return -1;
	}


	write_lock_irqsave(&torisa, flags);

	alreadyrunning = span->flags & ZT_FLAG_RUNNING;

	/* initialize the start value for the last ec buffer */
	for(i = 0; i < span->channels; i++)
	{
		last_ecwrite[tspan - 1][i] = ZT_LIN2X(0,&span->chans[i]);
	}
	crcing = "";
	if (card_type == TYPE_T1) { /* if its a T1 card */
		if (!alreadyrunning) {

			setctlreg(MASTERCLOCK);
			/* Zero out all registers */
			for (i = 0x20; i< 0x40; i++)
				t1out(tspan, i, 0);
			for (i = 0x60; i< 0x80; i++)
				t1out(tspan, i, 0);
	
			/* Full-on Sync required (RCR1) */
			t1out(tspan, 0x2b, 8);	
			/* RSYNC is an input (RCR2) */
			t1out(tspan, 0x2c, 8);	
			/* RBS enable (TCR1) */
			t1out(tspan, 0x35, 0x10);
			/* TSYNC to be output (TCR2) */
			t1out(tspan, 0x36, 4);
			/* Tx & Rx Elastic store, sysclk = 2.048 mhz, loopback controls (CCR1) */
			t1out(tspan, 0x37, 0x8c);
		}
		/* Enable F bits pattern */
		i = 0x20;
		if (span->lineconfig & ZT_CONFIG_ESF)
			i = 0x88;
		if (span->lineconfig & ZT_CONFIG_B8ZS)
			i |= 0x44;
		t1out(tspan, 0x38, i);
		if (i & 0x80)
			coding = "ESF";
		else
			coding = "SF";
		if (i & 0x40)
			framing = "B8ZS";
		else {
			framing = "AMI";
			t1out(tspan,0x7e,0x1c); /* F bits pattern (0x1c) into FDL register */
		}
		t1out(tspan, 0x7c, span->txlevel << 5);

		if (!alreadyrunning) {	
			/* LIRST to 1 in CCR3 */
			t1out(tspan, 0x30, 1);
	
			/* Wait 100 ms */
			endjif = jiffies + 10;
			write_unlock_irqrestore(&torisa, flags);
	
			while(jiffies < endjif); /* wait 100 ms */

			write_lock_irqsave(&torisa, flags);
			t1out(tspan,0x30,0x40); /* set CCR3 to 0x40, resetting Elastic Store */

			span->flags |= ZT_FLAG_RUNNING;
			spansstarted++;

#if 0
			printk("Enabling interrupts: %d\n", clockvals[syncsrc] | INTENA);
#endif

			/* output the clock info and enable interrupts */
			setctlreg(clockvals[syncsrc] | INTENA);
		}
	set_clear();  /* this only applies to a T1 */
	} else { /* if its an E1 card */
		u_char ccr1 = 0, tcr1 = 0;

		if (!alreadyrunning) {
			t1out(tspan,0x1a,4); /* CCR2: set LOTCMC */
			for(i = 0; i <= 8; i++) t1out(tspan,i,0);
			for(i = 0x10; i <= 0x4f; i++) if (i != 0x1a) t1out(tspan,i,0);
			t1out(tspan,0x10,0x20); /* RCR1: Rsync as input */
			t1out(tspan,0x11,6); /* RCR2: Sysclk=2.048 Mhz */
			t1out(tspan,0x12,8); /* TCR1: TSiS mode */
		}
		tcr1 = 8; /* base TCR1 value: TSis mode */
		if (span->lineconfig & ZT_CONFIG_CCS) {
			ccr1 |= 8; /* CCR1: Rx Sig mode: CCS */
			coding = "CCS";
		} else {
			tcr1 |= 0x20; 
			coding = "CAS";
		}
		if (span->lineconfig & ZT_CONFIG_HDB3) {
			ccr1 |= 0x44; /* CCR1: TX and RX HDB3 */
			framing = "HDB3";
		} else framing = "AMI";
		if (span->lineconfig & ZT_CONFIG_CRC4) {
			ccr1 |= 0x11; /* CCR1: TX and TX CRC4 */
			crcing = "/CRC4";
		} 
		t1out(tspan,0x12,tcr1);
		t1out(tspan,0x14,ccr1);
		t1out(tspan, 0x18, 0x80);

		if (!alreadyrunning) {
			t1out(tspan,0x1b,0x8a); /* CCR3: LIRST & TSCLKM */
			t1out(tspan,0x20,0x1b); /* TAFR */
			t1out(tspan,0x21,0x5f); /* TNAFR */
			t1out(tspan,0x40,0xb); /* TSR1 */
			for(i = 0x41; i <= 0x4f; i++) t1out(tspan,i,0x55);
			for(i = 0x22; i <= 0x25; i++) t1out(tspan,i,0xff);
			/* Wait 100 ms */
			endjif = jiffies + 10;
			write_unlock_irqrestore(&torisa, flags);
			while(jiffies < endjif); /* wait 100 ms */
			write_lock_irqsave(&torisa, flags);
			t1out(tspan,0x1b,0x9a); /* CCR3: set also ESR */
			t1out(tspan,0x1b,0x82); /* CCR3: TSCLKM only now */
			
			/* output the clock info and enable interrupts */
			setctlreg(clockvals[syncsrc] | INTENA);
		}

	}

	write_unlock_irqrestore(&torisa, flags);	

	if (debug) {
		if (card_type == TYPE_T1) {
			if (alreadyrunning) 
				printk("TorISA: Reconfigured span %d (%s/%s) LBO: %s\n", span->spanno, coding, framing, zt_lboname(span->txlevel));
			else
				printk("TorISA: Startup span %d (%s/%s) LBO: %s\n", span->spanno, coding, framing, zt_lboname(span->txlevel));
		} else {
			if (alreadyrunning) 
				printk("TorISA: Reconfigured span %d (%s/%s%s) 120 ohms\n", span->spanno, coding, framing, crcing);
			else
				printk("TorISA: Startup span %d (%s/%s%s) 120 ohms\n", span->spanno, coding, framing, crcing);
		}
	}
	if (syncs[0] == span->spanno) printk("SPAN %d: Primary Sync Source\n",span->spanno);
	if (syncs[1] == span->spanno) printk("SPAN %d: Secondary Sync Source\n",span->spanno);
	return 0;
}
Esempio n. 18
0
static void automount_enter_waiting(Automount *a) {
        _cleanup_close_ int ioctl_fd = -1;
        int p[2] = { -1, -1 };
        char name[sizeof("systemd-")-1 + DECIMAL_STR_MAX(pid_t) + 1];
        char options[sizeof("fd=,pgrp=,minproto=5,maxproto=5,direct")-1
                     + DECIMAL_STR_MAX(int) + DECIMAL_STR_MAX(gid_t) + 1];
        bool mounted = false;
        int r, dev_autofs_fd;
        struct stat st;

        assert(a);
        assert(a->pipe_fd < 0);
        assert(a->where);

        set_clear(a->tokens);

        r = unit_fail_if_symlink(UNIT(a), a->where);
        if (r < 0)
                goto fail;

        (void) mkdir_p_label(a->where, 0555);

        unit_warn_if_dir_nonempty(UNIT(a), a->where);

        dev_autofs_fd = open_dev_autofs(UNIT(a)->manager);
        if (dev_autofs_fd < 0) {
                r = dev_autofs_fd;
                goto fail;
        }

        if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
                r = -errno;
                goto fail;
        }

        xsprintf(options, "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct", p[1], getpgrp());
        xsprintf(name, "systemd-"PID_FMT, getpid());
        if (mount(name, a->where, "autofs", 0, options) < 0) {
                r = -errno;
                goto fail;
        }

        mounted = true;

        p[1] = safe_close(p[1]);

        if (stat(a->where, &st) < 0) {
                r = -errno;
                goto fail;
        }

        ioctl_fd = open_ioctl_fd(dev_autofs_fd, a->where, st.st_dev);
        if (ioctl_fd < 0) {
                r = ioctl_fd;
                goto fail;
        }

        r = autofs_protocol(dev_autofs_fd, ioctl_fd);
        if (r < 0)
                goto fail;

        r = autofs_set_timeout(dev_autofs_fd, ioctl_fd, a->timeout_idle_usec);
        if (r < 0)
                goto fail;

        /* Autofs fun fact:
         *
         * Unless we close the ioctl fd here, for some weird reason
         * the direct mount will not receive events from the
         * kernel. */

        r = sd_event_add_io(UNIT(a)->manager->event, &a->pipe_event_source, p[0], EPOLLIN, automount_dispatch_io, a);
        if (r < 0)
                goto fail;

        (void) sd_event_source_set_description(a->pipe_event_source, "automount-io");

        a->pipe_fd = p[0];
        a->dev_id = st.st_dev;

        automount_set_state(a, AUTOMOUNT_WAITING);

        return;

fail:
        log_unit_error_errno(UNIT(a), r, "Failed to initialize automounter: %m");

        safe_close_pair(p);

        if (mounted) {
                r = repeat_unmount(a->where, MNT_DETACH);
                if (r < 0)
                        log_error_errno(r, "Failed to unmount, ignoring: %m");
        }

        automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
}
Esempio n. 19
0
static void automount_enter_waiting(Automount *a) {
        int p[2] = { -1, -1 };
        char name[32], options[128];
        bool mounted = false;
        int r, ioctl_fd = -1, dev_autofs_fd;
        struct stat st;

        assert(a);
        assert(a->pipe_fd < 0);
        assert(a->where);

        if (a->tokens)
                set_clear(a->tokens);

        dev_autofs_fd = open_dev_autofs(UNIT(a)->manager);
        if (dev_autofs_fd < 0) {
                r = dev_autofs_fd;
                goto fail;
        }

        /* We knowingly ignore the results of this call */
        mkdir_p_label(a->where, 0555);

        warn_if_dir_nonempty(a->meta.id, a->where);

        if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
                r = -errno;
                goto fail;
        }

        snprintf(options, sizeof(options), "fd=%i,pgrp=%u,minproto=5,maxproto=5,direct", p[1], (unsigned) getpgrp());
        char_array_0(options);

        snprintf(name, sizeof(name), "systemd-%u", (unsigned) getpid());
        char_array_0(name);

        if (mount(name, a->where, "autofs", 0, options) < 0) {
                r = -errno;
                goto fail;
        }

        mounted = true;

        close_nointr_nofail(p[1]);
        p[1] = -1;

        if (stat(a->where, &st) < 0) {
                r = -errno;
                goto fail;
        }

        ioctl_fd = open_ioctl_fd(dev_autofs_fd, a->where, st.st_dev);
        if (ioctl_fd < 0) {
                r = ioctl_fd;
                goto fail;
        }

        r = autofs_protocol(dev_autofs_fd, ioctl_fd);
        if (r < 0)
                goto fail;

        r = autofs_set_timeout(dev_autofs_fd, ioctl_fd, 300);
        if (r < 0)
                goto fail;

        /* Autofs fun fact:
         *
         * Unless we close the ioctl fd here, for some weird reason
         * the direct mount will not receive events from the
         * kernel. */

        close_nointr_nofail(ioctl_fd);
        ioctl_fd = -1;

        r = sd_event_add_io(UNIT(a)->manager->event, p[0], EPOLLIN, automount_dispatch_io, a, &a->pipe_event_source);
        if (r < 0)
                goto fail;

        a->pipe_fd = p[0];
        a->dev_id = st.st_dev;

        automount_set_state(a, AUTOMOUNT_WAITING);

        return;

fail:
        assert_se(close_pipe(p) == 0);

        if (ioctl_fd >= 0)
                close_nointr_nofail(ioctl_fd);

        if (mounted)
                repeat_unmount(a->where);

        log_error_unit(UNIT(a)->id,
                       "Failed to initialize automounter: %s", strerror(-r));
        automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
}