Exemplo n.º 1
0
bool
fw3_parse_device(void *ptr, const char *val, bool is_list)
{
	char *p;
	struct fw3_device dev = { };

	if (*val == '*')
	{
		dev.set = true;
		dev.any = true;
		put_value(ptr, &dev, sizeof(dev), is_list);
		return true;
	}

	if (*val == '!')
	{
		dev.invert = true;
		while (isspace(*++val));
	}

	if ((p = strchr(val, '@')) != NULL)
	{
		*p++ = 0;
		snprintf(dev.network, sizeof(dev.network), "%s", p);
	}

	if (*val)
		snprintf(dev.name, sizeof(dev.name), "%s", val);
	else
		return false;

	dev.set = true;
	put_value(ptr, &dev, sizeof(dev), is_list);
	return true;
}
// ---------------------------------------------------------------------------
// 
// -----------
void bToolJustification::track_draw(){
	bStdToolPres::track_draw();
	if(!get_use_track()){
		return;
	}
	if(!get_use_drag()){
		return;
	}
	if(!_styl){
		return;
	}
CGPoint		cgp;
i2dvertex	vx;
	get_cur(&vx);
	if(vx.h==LONG_MIN){
		return;
	}
	Convert(&cgp,&vx);

double	val;

	if(_umode==kJustificationUserModeStd){
		if(_jkd==kJustificationKindOnPath){
			val=get_justification_on_path(cgp);
			if(val!=_curjust){
				_curjust=val;
				put_value(_fjust,val);
			}
		}
		else if(_jkd==kJustificationKindOnPoint){
			val=get_justification_on_point(cgp);
			if(val!=_curjust){
				_curjust=val;
				put_value(_fjust,val);
			}			
		}
	}
	else if(_umode==kJustificationUserModeSpace){
		if(_jkd==kJustificationKindOnPath){
			val=get_inter_on_path(cgp);
			if(val!=_curspc){
				_curspc=val;
				put_value(_fspc,val);
			}
		}
		else if(_jkd==kJustificationKindOnPoint){
			val=get_inter_on_point(cgp);
			if(val!=_curjust){
				_curspc=val;
				put_value(_fspc,val);
			}		
		}
	}
}
Exemplo n.º 3
0
/*****************************************************************************
 * A S S I G N _ H E L P E R 1 ( node *var, value val )
 *
 * Similare to assign_helper but used by reload_vars_hds.
 * Therefore if the variable is a parameter given as a value, we assume it is
 * not required to be reset.
 ******************************************************************************
 */
value
assign_helper1(node *var, value val)
{
    node *param;

    if ((param = lookup_symbol(string_part(var->val), SYM_PARAMETER))
	    != NODENIL)
	if (param->interpret == parameter_interpret)
	    return (put_value(symboltable_part(param->val),
		    string_part(param->sub[0]->val), SYM_VARIABLE, val));
	else
	    return trueval;
    else
	return (put_value(activesymtab(SYM_VARIABLE), string_part(var->val),
		SYM_VARIABLE, val));
}
Exemplo n.º 4
0
Sophon_Result
sophon_insfile_store (Sophon_VM *vm, Sophon_Module *mod,
			Sophon_IOFunc func, Sophon_Ptr data)
{
	Sophon_U16 i;

	SOPHON_ASSERT(vm && mod && func);

	put_u32(func, data, SOPHON_INSFILE_MAGIC);
	put_u32(func, data, SOPHON_INSFILE_VERSION);

	if (mod->name)
		put_str(vm, func, data, mod->name);
	else
		put_u32(func, data, 0);

	put_u16(func, data, mod->const_count);
	for (i = 0; i < mod->const_count; i++) {
		put_value(vm, func, data, mod->consts[i]);
	}

	put_u16(func, data, mod->func_count);
	for (i = 0; i < mod->func_count; i++) {
		put_func(vm, func, data, mod->funcs[i]);
	}


	return SOPHON_OK;
}
Exemplo n.º 5
0
static int
rs_update_out(struct trace_proc * proc, const message * m_out)
{

    /*
     * FIXME: this is a value from the wrong message union, and that is
     * actually a minix bug.
     */
    put_struct_rs_start(proc, "addr", (vir_bytes)m_out->m_rs_req.addr);

    /* TODO: interpret these fields */
    put_value(proc, "state", "%d", m_out->m_rs_update.state);
    put_value(proc, "maxtime", "%d", m_out->m_rs_update.prepare_maxtime);

    return CT_DONE;
}
Exemplo n.º 6
0
/*
 * Internal helper function used by WPACKET_close() and WPACKET_finish() to
 * close a sub-packet and write out its length if necessary.
 */
static int wpacket_intern_close(WPACKET *pkt)
{
    WPACKET_SUB *sub = pkt->subs;
    size_t packlen = pkt->written - sub->pwritten;

    if (packlen == 0
            && (sub->flags & WPACKET_FLAGS_NON_ZERO_LENGTH) != 0)
        return 0;

    if (packlen == 0
            && sub->flags & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) {
        /* Deallocate any bytes allocated for the length of the WPACKET */
        if ((pkt->curr - sub->lenbytes) == sub->packet_len) {
            pkt->written -= sub->lenbytes;
            pkt->curr -= sub->lenbytes;
        }

        /* Don't write out the packet length */
        sub->packet_len = 0;
        sub->lenbytes = 0;
    }

    /* Write out the WPACKET length if needed */
    if (sub->lenbytes > 0 
                && !put_value((unsigned char *)&pkt->buf->data[sub->packet_len],
                              packlen, sub->lenbytes))
            return 0;

    pkt->subs = sub->parent;
    OPENSSL_free(sub);

    return 1;
}
Exemplo n.º 7
0
Arquivo: vm.c Projeto: Hooman3/minix
static int
vm_mmap_out(struct trace_proc * proc, const message * m_out)
{

	if (m_out->m_mmap.flags & MAP_THIRDPARTY)
		put_endpoint(proc, "forwhom", m_out->m_mmap.forwhom);
	put_ptr(proc, "addr", (vir_bytes)m_out->m_mmap.addr);
	put_value(proc, "len", "%zu", m_out->m_mmap.len);
	put_flags(proc, "prot", mmap_prot, COUNT(mmap_prot), "0x%x",
	    m_out->m_mmap.prot);
	put_flags(proc, "flags", mmap_flags, COUNT(mmap_flags), "0x%x",
	    m_out->m_mmap.flags);
	put_fd(proc, "fd", m_out->m_mmap.fd);
	put_value(proc, "offset", "%"PRId64, m_out->m_mmap.offset);

	return CT_DONE;
}
Exemplo n.º 8
0
/*
 * Print a pointer.  NULL is treated as a special case.
 */
void
put_ptr(struct trace_proc * proc, const char * name, vir_bytes addr)
{

	if (addr == 0 && !valuesonly)
		put_field(proc, name, "NULL");
	else
		put_value(proc, name, "&0x%lx", addr);
}
Exemplo n.º 9
0
/******************************************************************************
 *
 *	A S S I G N _ H E L P E R (node *var, value val)
 *
 * Assign the value 'val' to the variable 'var'.
 * 'Var' is a name_interpret() node whose string_part member contains the
 * identity of the variable.
 *
 * If the variable is a parameter then, on calling the current procedure we
 * could have passed
 * EITHER
 * an expression, which is evaluated and the formal's value member points to
 * that value
 * OR
 * a variable.  In this latter  case the formal's node value will point to a
 * node whose type is TYPE_SYMTAB, whose interpret member is
 * parameter_interpret(), whose symboltable_part() member points to the symbol
 * table of the corresponding actual variable and whose sub[0] member points
 * to a node that is the corresponding actual variable (ie a name_interpret()
 * whose string_part() member points to the identifier).
 *
 * If the variable is not a parameter then we can use
 * put_value(activesymtab(SYM_VARIABLE), var's name, SYM_VARIABLE,val)....) to
 * achieve the storage otherwise we can use put_value(symboltable from formal
 * entry, actual parameter's name,SYM_VARIABLE,val).
 ******************************************************************************
 */
value
assign_helper(node *var, value val)
{
    node *param;

    if ((param = lookup_symbol(string_part(var->val), SYM_PARAMETER))
	    != NODENIL) {
	if (param->interpret == parameter_interpret)
	    return (put_value(symboltable_part(param->val),
		    string_part(param->sub[0]->val), SYM_VARIABLE, val));
	else if( param->interpret == undefined_interpret)
	    put_value(symbols, string_part(var->val), SYM_PARAMETER, val);
	else
	    return exception(
		"ASSNOTVAR Assignment to parameter not passed as a variable");
    } else
	return (put_value(activesymtab(SYM_VARIABLE), string_part(var->val),
		SYM_VARIABLE, val));
}
Exemplo n.º 10
0
/*
 * Print a tail field at the end of an array.  The given 'count' value is the
 * total number of elements in the array, or 0 to indicate that an error
 * occurred.  The given 'printed' value is the number of fields printed so far.
 * If some fields have been printed already, the number of fields not printed
 * will be shown as "..(+N)".  If no fields have been printed already, the
 * (total) number of fields not printed will be shown as "..(N)".  An error
 * will print "..(?)".
 *
 * The rules for printing an array are as follows.  In principle, arrays should
 * be enclosed in "[]".  However, if a copy error occurs immediately, a pointer
 * to the array should be printed instead.  An empty array should be printed as
 * "[]" (not "[..(0)]").  If a copy error occurs in the middle of the array,
 * put_tail should be used with count == 0.  Only if not all fields in the
 * array are printed, put_tail should be used with count > 0.  The value of
 * 'printed' is typically the result of an arbitrary limit set based on the
 * verbosity level.
 */
void
put_tail(struct trace_proc * proc, unsigned int count, unsigned int printed)
{

	if (count == 0)
		put_field(proc, NULL, "..(?)");
	else
		put_value(proc, NULL, "..(%s%u)",
		    (printed > 0) ? "+" : "", count - printed);
}
static void
put_sound_state(struct trace_proc * proc, const char * name, int state)
{

	if (!valuesonly && state == ON)
		put_field(proc, name, "ON");
	else if (!valuesonly && state == OFF)
		put_field(proc, name, "OFF");
	else
		put_value(proc, name, "%d", state);
}
Exemplo n.º 12
0
int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
{
    unsigned char *data;

    /* Internal API, so should not fail */
    if (!ossl_assert(size <= sizeof(unsigned int))
            || !WPACKET_allocate_bytes(pkt, size, &data)
            || !put_value(data, val, size))
        return 0;

    return 1;
}
Exemplo n.º 13
0
int mdhim_mysql_batch_put(void *dbh, void **keys, int32_t *key_lens, 
			    void **data, int32_t *data_lens, int num_records) {
	struct MDI *x = (struct MDI *)(dbh);
	MYSQL *db = (MYSQL *) x->msqdb;
	 if (db == NULL) 
	  {
	      fprintf(stderr, "%s\n", mysql_error(db));
	      return MDHIM_DB_ERROR;
	  }
	int i;
	struct timeval start, end;
		gettimeofday(&start, NULL);	
	char *table_name = x->table;
	char *query=NULL;
	//Insert X amount of Keys and Values
	printf("Number records: %d\n", num_records);
	for (i = 0; i < num_records; i++) {
		query = put_value(db, keys[i], key_lens[i], data[i], data_lens[i], table_name, x->msqkt);
	printf("\nThis is the query: \n%s\n", query);

	    if  (mysql_real_query(db, query, sizeof(char)*strlen(query)))  {
			int check_er = mysql_errno(db);
		    //printf("\nThis is the error number: %d\n", check_er);
			if (check_er == 1062){
				memset(query, 0, sizeof(char)*strlen(query));
				query = update_value(db, keys[i], key_lens[i], data[i], data_lens[i], table_name, x->msqkt);
				//printf("\nThis is the query: \n%s\n", query);

			if  (mysql_real_query(db, query, sizeof(char)*strlen(query)))  {
				//printf("This is the query: %s\n", query);
		   		mlog(MDHIM_SERVER_CRIT, "Error updating key/value in mysql\n");
		    		fprintf(stderr, "%s\n", mysql_error(db));
			return MDHIM_DB_ERROR;
					}
			//else printf("Sucessfully updated key/value in mdhim\n");
			}
		else {
		mlog(MDHIM_SERVER_CRIT, "Error putting key/value in mysql\n");
		    fprintf(stderr, "%s\n", mysql_error(db));
			return MDHIM_DB_ERROR;
			}
	    }

		memset(query, 0, sizeof(query));
	}

	//Report timing
	gettimeofday(&end, NULL);
	mlog(MDHIM_SERVER_DBG, "Took: %d seconds to put %d records", 
	     (int) (end.tv_sec - start.tv_sec), num_records);
	return MDHIM_SUCCESS; 
} 
Exemplo n.º 14
0
int main() 
{
	unsigned char* ptr = Program;

	/* так можно размещать перемнные до запуска ВМ */
	add_var("pi");
	set_var("pi", 3.14159265);

	/* так создаются пермеменные в программе ВМ */
	put_commd(&ptr, CNVAR); put_strng(&ptr, "x1");
	put_commd(&ptr, CPUSH); put_value(&ptr, 2.0);
	put_commd(&ptr, CSVAR); put_strng(&ptr, "x1");

	/* вычисление выражения (2.3+4.7)*2.1 */
	put_commd(&ptr, CPUSH);	put_value(&ptr, 2.3);
	put_commd(&ptr, CPUSH);	put_value(&ptr, 4.7);
	put_commd(&ptr, CADD);
	put_commd(&ptr, CPUSH);	put_value(&ptr, 2.1);
	put_commd(&ptr, CMULT);

	/* делим результат на Pi */
	put_commd(&ptr, CGVAR); put_strng(&ptr, "pi");
	put_commd(&ptr, CDIV);

	/* умножаем на x1 */
	put_commd(&ptr, CGVAR); put_strng(&ptr, "x1");
	put_commd(&ptr, CMULT);

	/* выводим результат, останавливаем машину */
 	put_commd(&ptr, COUT);
	put_commd(&ptr, CHALT);

	vmin = stdin;
	vmout = stdout;

	run();

	return 1;
}
Exemplo n.º 15
0
/**
 * mdhim_mysql_put
 * Stores a single key in the data store
 *
 * @param dbh         in   pointer to the mysql struct which points to the handle
 * @param key         in   void * to the key to store
 * @param key_len     in   length of the key
 * @param data        in   void * to the value of the key
 * @param data_len    in   length of the value data 
 * @param mstore_opts in   additional options for the data store layer 
 * 
 * @return MDHIM_SUCCESS on success or MDHIM_DB_ERROR on failure
 */
int mdhim_mysql_put(void *dbh, void *key, int key_len, void *data, int32_t data_len) {
	
	struct timeval start, end;
	//printf("In put function\n");
	struct MDI *x = (struct MDI *)(dbh);
	MYSQL *db = x->msqdb;
	 if (db == NULL) 
	  {
	      fprintf(stderr, "%s\n", mysql_error(db));
	      return MDHIM_DB_ERROR;
	  }
	char *table_name;
		table_name = x->table;

	gettimeofday(&start, NULL);
	char *query;    
	//Insert key and value into table
	query = put_value(db, key, key_len, data, data_len, table_name, x->msqkt);
	//printf("\nThis is the query: \n%s\n", query);

    if  (mysql_real_query(db, query, sizeof(char)*strlen(query)))  {
		int check_er = mysql_errno(db);
	    //printf("\nThis is the error number: %d\n", check_er);
		if (check_er == 1062){
			memset(query, 0, sizeof(char)*strlen(query));
			query = update_value(db, key, key_len, data, data_len, table_name, x->msqkt);
		//printf("\nThis is the query: \n%s\n", query);


		if  (mysql_real_query(db, query, sizeof(char)*strlen(query)))  {
			//printf("This is the query: %s\n", query);
	   		mlog(MDHIM_SERVER_CRIT, "Error updating key/value in mysql\n");
	    		fprintf(stderr, "%s\n", mysql_error(db));
		return MDHIM_DB_ERROR;
				}
		//else printf("Sucessfully updated key/value in mdhim\n");
		}
	else {
		mlog(MDHIM_SERVER_CRIT, "Error putting key/value in mysql\nHere is the command:%s\n",query);
		    fprintf(stderr, "%s\n", mysql_error(db));
			return MDHIM_DB_ERROR;
			}
    }
	//Report timing
   	gettimeofday(&end, NULL);
    	mlog(MDHIM_SERVER_DBG, "Took: %d seconds to put the record", 
	(int) (end.tv_sec - start.tv_sec));
    return MDHIM_SUCCESS;
}
Exemplo n.º 16
0
static long process(compressRecord *prec)
{
    long	status=0;
    long	nelements = 0;
    int		alg = prec->alg;

    prec->pact = TRUE;
    if(!dbIsLinkConnected(&prec->inp)
    || dbGetNelements(&prec->inp,&nelements)
    || nelements<=0) {
	recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
    } else {
	if(!prec->wptr || nelements!=prec->inpn) {
            if(prec->wptr) {
                free(prec->wptr);
                reset(prec);
            }
	    prec->wptr = (double *)dbCalloc(nelements,sizeof(double));
	    prec->inpn = nelements;
	}
	status = dbGetLink(&prec->inp,DBF_DOUBLE,prec->wptr,0,&nelements);
	if(status || nelements<=0) {
            recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
	    status = 0;
	} else {
	    if(alg==compressALG_Average) {
		status = array_average(prec,prec->wptr,nelements);
	    } else if(alg==compressALG_Circular_Buffer) {
		(void)put_value(prec,prec->wptr,nelements);
		status = 0;
	    } else if(nelements>1) {
		status = compress_array(prec,prec->wptr,nelements);
	    }else if(nelements==1){
		status = compress_scalar(prec,prec->wptr);
	    }else status=1;
	}
    }
    /* check event list */
    if(status!=1) {
		prec->udf=FALSE;
		recGblGetTimeStamp(prec);
		monitor(prec);
		/* process the forward scan link record */
		recGblFwdLink(prec);
    }
    prec->pact=FALSE;
    return(0);
}
Exemplo n.º 17
0
static int array_average(compressRecord *prec,
	double *psource,epicsInt32 no_elements)
{
	epicsInt32	i;
	epicsInt32	nnow;
	epicsInt32	nsam=prec->nsam;
	double	*psum;
	double	multiplier;
	epicsInt32	inx=prec->inx;
	epicsInt32	nuse,n;

	nuse = nsam;
	if(nuse>no_elements) nuse = no_elements;
	nnow=nuse;
	if(nnow>no_elements) nnow=no_elements;
	psum = (double *)prec->sptr;

	/* add in the new waveform */
	if (inx == 0){
		for (i = 0; i < nnow; i++)
		    *psum++ = *psource++;
		for(i=nnow; i<nuse; i++) *psum++ = 0;
	}else{
		for (i = 0; i < nnow; i++)
		    *psum++ += *psource++;
	}

	/* do we need to calculate the result */
	inx++;
	if(prec->n<=0)prec->n=1;
	n = prec->n;
	if (inx<n) {
		prec->inx = inx;
		return(1);
	}
	if(n>1) {
		psum = (double *)prec->sptr;
		multiplier = 1.0/((double)n);
		for (i = 0; i < nuse; i++, psum++)
	    		*psum = *psum * multiplier;
	}
	put_value(prec,prec->sptr,nuse);
	prec->inx = 0;
	return(0);
}
Exemplo n.º 18
0
static int test_gencode()
{
    yla_cop_type buf[100];
    yla_cop_type *ptr = buf;
    
    put_commd(&ptr, 0x12);
    put_value(&ptr, 0x3456);
    put_commd(&ptr, 0x78);
    put_commd(&ptr, 0x9a);

    YLATEST_ASSERT_TRUE(buf[0] == 0x12, "put_commd");
    YLATEST_ASSERT_TRUE(buf[1] == 0x34, "put_value");
    YLATEST_ASSERT_TRUE(buf[2] == 0x56, "put_value");
    YLATEST_ASSERT_TRUE(buf[3] == 0x78, "put_value");
    YLATEST_ASSERT_TRUE(buf[4] == 0x9a, "put_value");
    
    return 0;
}
Exemplo n.º 19
0
static int test_push()
{
    yla_cop_type prg[HEADER_SIZE + 4];
    yla_cop_type *ptr = prg;

    put_header(&ptr, 1, 0, 4);
    put_commd(&ptr, CPUSH);
    put_value(&ptr, 0x1234);
    put_commd(&ptr, CHALT);

    yla_vm vm;

    YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 4), "normal");
    YLATEST_ASSERT_TRUE(yla_vm_run(&vm), "normal")
    YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal");

    return 0;
}
Exemplo n.º 20
0
/*
 * Print a flags field, using known flag names.  The name of the whole field is
 * given as 'name' and may be NULL.  The caller must supply an array of known
 * flags as 'fp' (with 'num' entries).  Each entry in the array has a mask, a
 * value, and a name.  If the given flags 'value', bitwise-ANDed with the mask
 * of an entry, yields the value of that entry, then the name is printed.  This
 * means that certain zero bits may also be printed as actual flags, and that
 * by supplying an all-bits-set mask can print a flag name for a zero value,
 * for example F_OK for access().  See the FLAG macros and their usage for
 * examples.  All matching flag names are printed with a "|" separator, and if
 * after evaluating all 'num' entries in 'fp' there are still bits in 'value'
 * for which nothing has been printed, the remaining bits will be printed with
 * the 'fmt' format string for an integer (generally "%d" should be used).
 */
void
put_flags(struct trace_proc * proc, const char * name, const struct flags * fp,
	unsigned int num, const char * fmt, unsigned int value)
{
	unsigned int left;
	int first;

	if (valuesonly) {
		put_value(proc, name, fmt, value);

		return;
	}

	put_field(proc, name, "");

	for (first = TRUE, left = value; num > 0; fp++, num--) {
		if ((value & fp->mask) == fp->value) {
			if (first)
				first = FALSE;
			else
				put_text(proc, "|");
			put_text(proc, fp->name);

			left -= fp->value;
		}
	}

	if (left != 0) {
		if (first)
			first = FALSE;
		else
			put_text(proc, "|");

		put_fmt(proc, fmt, left);
	}

	/*
	 * If nothing has been printed so far, simply print a zero.  Ignoring
	 * the given format in this case is intentional: a simple 0 looks
	 * better than 0x0 or 00 etc.
	 */
	if (first)
		put_text(proc, "0");
}
Exemplo n.º 21
0
int main()
{
	struct indicator *indicators;
	struct strategy *strategies;
	struct coll_ctrl_blk *coll_ctrl_blks;

	indicators = load_indicators("indicators.xml");
	print_indicators(indicators);
	//destroy_indicators(indicators);
	strategies = load_strategies("strategies.xml");
	print_strategies(strategies);
	//destroy_strategies(strategies);
	//printf("name offset in Indicator is: %u\n", offsetof(struct indicator, name));
	//printf("size of int: %u\n", sizeof(int));
	struct data data;
	init_data(&data);
	put_value(&data, "hello", "wold");
	struct pair *pair_ptr = get_pair(&data, "hello");
	printf("%s, %s\n", pair_ptr->name, pair_ptr->value);
	coll_ctrl_blks = generate_coll_ctrl_blks(indicators, strategies);
	print_coll_ctrl_blks(coll_ctrl_blks);
	struct coll_ctrl_blk *coll_ctrl_blk_ptr = find_coll_ctrl_blk(coll_ctrl_blks, 1);
	printf("Indicator NAME: %s\n", coll_ctrl_blk_ptr->indicator_ptr->name);
	generate_coll_commands(coll_ctrl_blk_ptr);
	
	destroy_indicators(indicators);
	destroy_strategies(strategies);

	ssh_init();
	struct ssh_client client;
	struct line *lines;
	init_client(&client);
	login(&client, "127.0.0.1", 22, "tshi", "123456");
	lines = exec_command(&client, "date");
	print_lines(lines);
	destroy_lines(lines);
	lines = exec_command(&client, "top -b -n 1");
	print_lines(lines);
	destroy_lines(lines);
	close_client(&client);
	ssh_exit();
	
	return (0);
}
Exemplo n.º 22
0
static int test_get_stack_full()
{
    yla_cop_type prg[HEADER_SIZE + 4];
    yla_cop_type *ptr = prg;

    put_header(&ptr, 0, 0, 4);
    put_commd(&ptr, CPUSH);
    put_value(&ptr, 0x1234);
    put_commd(&ptr, CHALT);

    yla_vm vm;

    YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 4), "normal");
    YLATEST_ASSERT_FALSE(yla_vm_run(&vm), "normal")
    YLATEST_ASSERT_TRUE(yla_vm_last_error(&vm) == YLA_VM_ERROR_STACK_FULL, "incorrect error code");
    YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal");

    return 0;
}
Exemplo n.º 23
0
static void
put_fbd_action(struct trace_proc * proc, const char * name, int action)
{
	const char *text = NULL;

	if (!valuesonly) {
		switch (action) {
		TEXT(FBD_ACTION_CORRUPT);
		TEXT(FBD_ACTION_ERROR);
		TEXT(FBD_ACTION_MISDIR);
		TEXT(FBD_ACTION_LOSTTORN);
		}
	}

	if (text != NULL)
		put_field(proc, name, text);
	else
		put_value(proc, name, "%d", action);
}
static void
put_tty_disc(struct trace_proc * proc, const char * name, int disc)
{
	const char *text = NULL;

	if (!valuesonly) {
		switch (disc) {
		TEXT(TTYDISC);
		TEXT(TABLDISC);
		TEXT(SLIPDISC);
		TEXT(PPPDISC);
		TEXT(STRIPDISC);
		TEXT(HDLCDISC);
		}
	}

	if (text != NULL)
		put_field(proc, name, text);
	else
		put_value(proc, name, "%d", disc);
}
static void
put_i2c_op(struct trace_proc * proc, const char *name, i2c_op_t op)
{
	const char *text = NULL;

	if (!valuesonly) {
		switch (op) {
		TEXT(I2C_OP_READ);
		TEXT(I2C_OP_READ_WITH_STOP);
		TEXT(I2C_OP_WRITE);
		TEXT(I2C_OP_WRITE_WITH_STOP);
		TEXT(I2C_OP_READ_BLOCK);
		TEXT(I2C_OP_WRITE_BLOCK);
		}
	}

	if (text != NULL)
		put_field(proc, name, text);
	else
		put_value(proc, name, "%d", op);
}
Exemplo n.º 26
0
void uart_hardware_init(void)
{
    //HAS_CRITICAL_SECTION;
    //ENTER_CRITICAL_SECTION();
    //LEAVE_CRITICAL_SECTION();

	if(uart_initialized == false) {
    set_hbit(GPCTL,GPCTL_UART);
    put_hvalue(GPPMB,0);		// disable SIO bits 6 and 7
   	put_hvalue(GPPOB,0);
    put_hvalue(GPPMA,0x0002);	// RX is input (A0), TX is output (A1)
   	put_hvalue(GPPOA,0);

    put_value(UARTIER,0);		// no interrupts
    put_value(UARTLCR,0x80);	// enable access to divisor latch
    put_value(UARTDLM,0);
    put_value(UARTDLL,0x3E);	// 57600 baud
    put_value(UARTLCR,0x03);
    put_value(UARTFCR,0xC7);	// 14 byte trigger, cleared and buffered (auto set to normal FCR mode)
    put_value(UARTMCR,0);
    put_value(UARTIER,0x01);	// RX

    IRQ_HANDLER_TABLE[INT_UART]=uart_interrupt_handler;
	set_wbit(ILC1,ILC1_ILR9 & ILC1_INT_LV3);

	set_hbit(GPPMC, UART_EN); 									// set PIOC6(UART_EN) to output
	set_hbit(GPPMC, UART_FORCEOFF); 									// set PIOC7(FORCEOFF) to output

    set_hbit(GPCTL,GPCTL_UART);
    put_hvalue(GPPMA,0x0002);	// RX is input (A0), TX is output (A1)
   	put_hvalue(GPPOA,0);
	clr_hbit(GPPOC,UART_EN);
	set_hbit(GPPOC,UART_FORCEOFF);	// this also drives FORCEON -- they are tied together

	uart_initialized = true;
	}
}
Exemplo n.º 27
0
/*
 * Internal helper function used by WPACKET_close(), WPACKET_finish() and
 * WPACKET_fill_lengths() to close a sub-packet and write out its length if
 * necessary. If |doclose| is 0 then it goes through the motions of closing
 * (i.e. it fills in all the lengths), but doesn't actually close anything.
 */
static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
{
    size_t packlen = pkt->written - sub->pwritten;

    if (packlen == 0
            && (sub->flags & WPACKET_FLAGS_NON_ZERO_LENGTH) != 0)
        return 0;

    if (packlen == 0
            && sub->flags & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) {
        /* We can't handle this case. Return an error */
        if (!doclose)
            return 0;

        /* Deallocate any bytes allocated for the length of the WPACKET */
        if ((pkt->curr - sub->lenbytes) == sub->packet_len) {
            pkt->written -= sub->lenbytes;
            pkt->curr -= sub->lenbytes;
        }

        /* Don't write out the packet length */
        sub->packet_len = 0;
        sub->lenbytes = 0;
    }

    /* Write out the WPACKET length if needed */
    if (sub->lenbytes > 0
                && !put_value(&GETBUF(pkt)[sub->packet_len], packlen,
                              sub->lenbytes))
            return 0;

    if (doclose) {
        pkt->subs = sub->parent;
        OPENSSL_free(sub);
    }

    return 1;
}
Exemplo n.º 28
0
static int compress_scalar(struct compressRecord *prec,double *psource)
{
	double	value = *psource;
	double	*pdest=&prec->cvb;
	epicsInt32	inx = prec->inx;

	/* compress according to specified algorithm */
	switch (prec->alg){
	case (compressALG_N_to_1_Low_Value):
	    if ((value < *pdest) || (inx == 0))
		*pdest = value;
	    break;
	case (compressALG_N_to_1_High_Value):
	    if ((value > *pdest) || (inx == 0))
		*pdest = value;
	    break;
	/* for scalars, Median not implemented => use average */
	case (compressALG_N_to_1_Average):
	case (compressALG_N_to_1_Median):
	    if (inx == 0)
		*pdest = value;
	    else {
		*pdest += value;
		if(inx+1>=(prec->n)) *pdest = *pdest/(inx+1);
	    }
	    break;
	}
	inx++;
	if(inx>=prec->n) {
		put_value(prec,pdest,1);
		prec->inx = 0;
		return(0);
	} else {
		prec->inx = inx;
		return(1);
	}
}
Exemplo n.º 29
0
      iter_type put(duration_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill,
          duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end) const
      {

        const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
        for (; pattern != pat_end; ++pattern)
        {
          if (ct.narrow(*pattern, 0) == '%')
          {
            if (++pattern == pat_end)
            {
              *s++ = pattern[-1];
              break;
            }
            char fmt = ct.narrow(*pattern, 0);
            switch (fmt)
            {
            case 'v':
            {
              s = put_value(s, ios, fill, d);
              break;
            }
            case 'u':
            {
              s = put_unit(units_facet, s, ios, fill, d);
              break;
            }
            default:
              BOOST_ASSERT(false && "Boost::Chrono internal error.");
              break;
            }
          }
          else
            *s++ = *pattern;
        }
        return s;
      }
static void
put_sound_device(struct trace_proc * proc, const char * name, int device)
{
	const char *text = NULL;

	if (!valuesonly) {
		switch (device) {
		TEXT(Master);
		TEXT(Dac);
		TEXT(Fm);
		TEXT(Cd);
		TEXT(Line);
		TEXT(Mic);
		TEXT(Speaker);
		TEXT(Treble);
		TEXT(Bass);
		}
	}

	if (text != NULL)
		put_field(proc, name, text);
	else
		put_value(proc, name, "%d", device);
}