Esempio n. 1
0
void InputLabel::closeKeyboard(EventCustom* event)
{
    CCDictionary* infos = (CCDictionary*)event->getUserData();
    if((isKindOfClass(infos->objectForKey("Sender"), CCInteger)
        && TOINT(infos->objectForKey("Sender")) == identifier)
       || (isKindOfClass(infos->objectForKey("Target"), CCInteger)
           && TOINT(infos->objectForKey("Target")) == identifier))
    {
        CCLOG("Close InputLabel keyboard");
        delegate->detachWithIME();
        delegate->closeKeyboard(); //Force close the keyboard
    }
}
Esempio n. 2
0
void InputLabel::openKeyboard(EventCustom* event)
{
    CCDictionary* infos = (CCDictionary*)event->getUserData();
    if(locks.size() == 0
       && ((isKindOfClass(infos->objectForKey("Sender"), CCInteger)
            && TOINT(infos->objectForKey("Sender")) == identifier)
           || (isKindOfClass(infos->objectForKey("Target"), CCInteger)
               && TOINT(infos->objectForKey("Target")) == identifier)))
    {
        CCLOG("Open InputLabel keyboard");
        delegate->touchDownAction(this, cocos2d::ui::Widget::TouchEventType::ENDED);//open keyboard by simulating a touch inside
        isOpened = true;
    }
}
Esempio n. 3
0
    bool generateEquations(std::vector<std::vector<z3::expr*> > &weights,
                           const LinkDescriptor &linkTable)
    {
        size_t i;
        size_t j;
        size_t totalSizeNode = _inputNodes.size() + _hiddenNodes.size() +
            _outputNodes.size();

        /* checking error of array size */
        if (weights.size() != totalSizeNode)
            {
                std::cerr << "Error: weight table not corresponding to number of nodes in Z3Equation" << std::endl;
                return false;
            }
        for (i = 0; i < weights.size(); ++i)
            if (weights[i].size() != totalSizeNode)
                {
                    std::cerr << "Error: weight table not corresponding to number of nodes in Z3Equation" << std::endl;
                    return false;
                }

        for (i = 0 ; i < totalSizeNode; ++i)
            {
                // build equation
                z3::expr tmp(_context.real_const("tmp"));
                bool b = true;
                for (j = 0; j < totalSizeNode; ++j)
                    {
                        if (linkTable.getLink(j, i))
                            {
                                if (b)
                                    {
                                        tmp = *(weights[j][i]) * *(getNode(j));
                                        b = false;
                                    }
                                else
                                    tmp = tmp + (*(weights[j][i]) * *(getNode(j)));
                            }

                    }
                // FIXME : improve activation function
                // sigmoid(&tmp) for instance;
                tmp = ite(tmp > TOINT((_min + (_max - _min) / 2.f), _precision),
			  _context.real_val(TOINT(_max, _precision)),
                          _context.real_val(TOINT(_min, _precision)));
                if (!b)
                    *getNode(i) = tmp;
            }
        return true;
    }
Esempio n. 4
0
/*
** 'fileio_getptr' returns the current value of the file pointer
*/
int32 fileio_getptr(int32 handle) {
  int32 result;
  handle = map_handle(handle);
  result = TOINT(ftell(fileinfo[handle].stream));
  if (result==-1) error(ERR_GETPTRFAIL);	/* File pointer cannot be read */
  return result;
}
Esempio n. 5
0
elem Verify_NestedStructTest(elem str)
{
	elem t, t2;
	int i;

	t=TyObj_GetSlot(str, SYM("2000"));
	t=TyObj_GetSlot(t, SYM("04"));
	t=TyObj_GetSlot(t, SYM("01"));

	i=0;
	i+=TOINT(TyObj_GetSlot(t, SYM("curly")));
	i+=TOINT(TyObj_GetSlot(t, SYM("larry")));
	i+=TOINT(TyObj_GetSlot(t, SYM("moe")));

	return(FIXNUM(i));
}
Esempio n. 6
0
static void nm_imult( DH_NUMBERS *n, uint16_t m, DH_NUMBERS *d )
{

	if (m == 0)
		d->length = 0;
	else if (m == 1)
		nm_assign( d, n );
	else{

		int i;
		register uint64_t mul;

		int l = n->length;
		uint16_t *pvn = n->values, *pvd = d->values;

		for (i = l, mul = 0; i; i--)
		{
			mul += (uint64_t)m * (uint64_t)*pvn++;
			*pvd++ = TOINT(mul);
			mul  = DIVMAX1( mul );
		}

		if (mul)
		{
			 l++;
			*pvd = mul;
		}
		d->length = l;
	}
}
Esempio n. 7
0
elem Verify_EasyStructTest(elem obj)
{
	elem t;
	int i;

	i=0;

	t=TyObj_GetSlot(obj, SYM("moe"));
	i+=TOINT(t);

	t=TyObj_GetSlot(obj, SYM("larry"));
	i+=TOINT(t);

	t=TyObj_GetSlot(obj, SYM("curly"));
	i+=TOINT(t);

	return(FIXNUM(i));
}
Esempio n. 8
0
/*
** 'fileio_bputstr' writes a string to a file
*/
void fileio_bputstr(int32 handle, char *string, int32 length) {
  _kernel_oserror *oserror;
  _kernel_swi_regs regs;
  regs.r[0] = 2;	/* OS_GBPB 2 = write to file at current file pointer position */
  regs.r[1] = handle;
  regs.r[2] = TOINT(string);
  regs.r[3] = length;
  oserror = _kernel_swi(OS_GBPB, &regs, &regs);
  if (oserror!=NIL) error(ERR_CMDFAIL, oserror->errmess);
  if (regs.r[3]!=0) error(ERR_CANTWRITE);	/* Not all the data was written to the file */
}
Esempio n. 9
0
/*
** 'fileio_getext' returns the size of a file
*/
int32 fileio_getext(int32 handle) {
  long int position, length;
  FILE *stream;
  handle = map_handle(handle);
  stream = fileinfo[handle].stream;
  position = ftell(stream);
  if (position==-1) error(ERR_GETEXTFAIL);	/* Cannot find size of file */
  fseek(stream, 0, SEEK_END);	/* Find the end of the file */
  length = ftell(stream);
  fseek(stream, position, SEEK_SET);	/* Restore file to its original file pointer position */
  return TOINT(length);
}
Esempio n. 10
0
/*
** 'get_number' is called to evaluate an expression that returns an
** integer value. It is used by the functions handling the various
** Basic commands in this file
*/
static int32 get_number(void) {
  factor();
  switch (get_topitem()) {
  case STACK_INT:
    return pop_int();
  case STACK_FLOAT:
    return TOINT(pop_float());
  default:
    error(ERR_TYPENUM);
  }
  return 0;
}
Esempio n. 11
0
    bool assignInpoutOutputValues(void)
    {
        std::vector<float>::const_iterator it;
        size_t i;
        
        // FIXME : check for error outside of the loops
        for (it = _trainingData.input.begin(), i = 0;
             it != _trainingData.input.end();
             ++it, ++i)
            {
                if (i >= _inputNodes.size())
                    {
                        std::cerr << "Error : Bad input _trainingData (array too long)" <<
                            std::endl;
                        return false;
                    }
                *(_inputNodes[i]) = (*(_inputNodes[i])) == TOINT(*it, _precision);
            }

        for (it = _trainingData.output.begin(), i = 0;
             it != _trainingData.output.end();
             ++it, ++i)
            {
                if (i >= _outputNodes.size())
                    {
                        std::cerr << "Error : Bad output _trainingData (array too long)" <<
                            std::endl;
                        return false;
                    }
                if (*it == _min)
                    *(_outputNodes[i]) = (*(_outputNodes[i])) <= TOINT(_min  + ((_max - _min) / 2), _precision);
                else
                    *(_outputNodes[i]) = (*(_outputNodes[i])) > TOINT(_min  + ((_max - _min) / 2), _precision);
                    
            }
        _isInitialized = true;
        return true;
    }
Esempio n. 12
0
elem Verify_ArrayOfStructsTest(elem lst)
{
	elem cur, t;
	int i;

	i=0;
	cur=lst;
	while(ELEM_CONSP(cur))
	{
		t=TyObj_GetSlot(CAR(cur), SYM("curly"));
		i+=TOINT(t);
		cur=CDR(cur);
	}
	return(FIXNUM(i));
}
Esempio n. 13
0
elem XmlRpc_EncodeDate(elem obj)
{
	char buf[18];
	int i, a[6];
	elem t;

	for(i=0; i<6; i++)a[i]=TOINT(LIST_REF(obj, i+1));
	sprintf(buf, "%04d%02d%02dT%02d:%02d:%02d",
		a[0], a[1], a[2], a[3], a[4], a[5]);

	t=STRING(buf);
	t=CONS(t, MISC_EOL);
	t=CONS(MISC_EOL, t);
	t=CONS(SYM("dateTime.iso8601"), t);
	return(t);
}
Esempio n. 14
0
static void nm_mult( DH_NUMBERS *m1, DH_NUMBERS *m2, DH_NUMBERS *d )

{
	static uint16_t id[ MAXLEN ];
	register uint16_t *vp;
	register uint64_t sum;
	register uint64_t tp1;
	register uint16_t *p2;
	uint16_t *p1;
	int l1, l2, ld, lc, l, i, j;

	l1 = m1->length;
	l2 = m2->length;
	l = l1 + l2;
	if (l >= MAXLEN)
		// abort();
		return;

	for (i = l, vp = id; i--;)
		*vp++ = 0;

	for ( p1 = m1->values, i = 0; i < l1 ; i++, p1++ )
	{

		tp1 = (uint64_t) * p1;
		vp = &id[i];
		sum = 0;
		for ( p2 = m2->values, j = l2; j--;)
		{
		    sum += (uint64_t) * vp + (tp1 * (uint64_t) * p2++);
		    *vp++ = TOINT( sum );
		    sum = DIVMAX1(sum);
		}
		*vp++ += (uint16_t)sum;
	}

	ld = 0;
	for (lc = 0, vp = id, p1 = d->values; lc++ < l;)
	{
		if ( *p1++ = *vp++ )
		    ld = lc;
	}

	d->length = ld;

	n_div( d, mod_z2, NUM0P, d );
}
Esempio n. 15
0
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <h/kernel.h>
#include <h/graphics.h>
#include <time.h>

forwards void init_event_tree(void);

extern EventNodeObj getNodeEventTree(EventTreeObj t, Any value);

#define TOINT(x) x

static Int	 last_buttons     = TOINT(ZERO); /* defaults for next event */
static Any	 last_window      = NIL;
static Int	 last_x		  = TOINT(ZERO);
static Int	 last_y		  = TOINT(ZERO);
static unsigned long last_time	  = 0L;

static Int	         last_down_bts    = ZERO;
static int	         last_down_x      = -1000; /* multiclick detection */
static int	         last_down_y	  = -1000;
static unsigned long     last_down_time   = 0;
static unsigned int	 multi_click_time = 400;
static int	         multi_click_diff = 4;
static int	         last_click_type  = CLICK_TYPE_triple;
static int		 loc_still_posted = TRUE;
static unsigned long	 host_last_time   = 0;
static int		 loc_still_time	  = 400;
Esempio n. 16
0
elem XmlRpc_EncodeValue(elem val)
{
	char buf[256];
	int i;
	double x;
	elem t;

	char *s, *s2;

	if(ELEM_STRINGP(val))
	{
		t=val;
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("string"), t);
		return(t);
	}
	if(ELEM_FIXNUMP(val))
	{
		i=TOINT(val);
		sprintf(buf, "%d", i);
		t=STRING(buf);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("i4"), t);
		return(t);
	}
	if(ELEM_FLONUMP(val))
	{
		x=TOFLOAT(val);
		sprintf(buf, "%g", x);
		t=STRING(buf);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("double"), t);
		return(t);
	}

	if(ELEM_CONSP(val))
	{
		if(CAR(val)==SYM("date-time:"))
		{
			t=XmlRpc_EncodeDate(val);
			return(t);
		}

		t=XmlRpc_EncodeArray(val);
		return(t);
	}

	if(ELEM_ENVOBJP(val))
	{
		t=XmlRpc_EncodeStruct(val);
		return(t);
	}

	if(ELEM_BYTEVECTORP(val))
	{
		s=TyFcn_ByteVectorBody(val);
		i=VECTOR_LEN(val);
		s2=kalloc(((i*4)/3)+5);
		HttpNode_EncodeMime(s2, s, i);

		kprint("send mime %d->%d\n", i, (i*4)/3);
		t=STRING(s2);
		kfree(s2);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("base64"), t);
		return(t);
	}

	if(val==MISC_TRUE)
	{
		t=STRING("1");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}
	if(val==MISC_FALSE)
	{
		t=STRING("0");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}

	if(val==MISC_NULL)
	{
		t=STRING("$null");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}

	t=STRING("$undefined");
	t=CONS(t, MISC_EOL);
	t=CONS(MISC_EOL, t);
	t=CONS(SYM("string"), t);
	return(t);
}
Esempio n. 17
0
bool srprs_hive(const char** ptr, const struct hive_info** result)
{
	const char* str = *ptr;
	const struct hive_info* info = NULL;
	bool long_hive = false;

	if ((toupper(str[0]) != 'H') || (toupper(str[1]) != 'K')
	    || (str[2] == '\0') )
	{
		return false;
	}

	switch ( TOINT(toupper(str[2]), toupper(str[3])) ) {
	case TOINT('E', 'Y'):
		if (str[4] == '_') {
			int i;
			for (i=0; (info = HIVE_INFO[i]); i++) {
				if (strncmp(&str[5], &info->long_name[5],
					    info->long_name_len-5) == 0)
				{
					long_hive = true;
					break;
				}
			}
		}
		break;
	case TOINT('L', 'M'):
		info = &HIVE_INFO_HKLM;
		break;
	case TOINT('C', 'U'):
		info = &HIVE_INFO_HKCU;
		break;
	case TOINT('C', 'R'):
		info = &HIVE_INFO_HKCR;
		break;
	case TOINT('C', 'C'):
		info = &HIVE_INFO_HKCC;
		break;
	case TOINT('D', 'D'):
		info = &HIVE_INFO_HKDD;
		break;
	case TOINT('P', 'D'):
		info = &HIVE_INFO_HKPD;
		break;
	case TOINT('P', 'T'):
		info = &HIVE_INFO_HKPT;
		break;
	case TOINT('P', 'N'):
		info = &HIVE_INFO_HKPN;
		break;
	default:
		if (toupper(str[2]) == 'U') {
			info = &HIVE_INFO_HKU;
		}
		break;
	}
	if (info != NULL) {
		if (result != NULL) {
			*result = info;
		}
		*ptr += long_hive ? info->long_name_len : info->short_name_len;
		return true;
	}
	return false;
}
Esempio n. 18
0
/*
** 'restore_retparm' is called when a 'return parameter' block is found on the
** stack. It saves the value currently in the parameter at the address stored as
** the return parameter address and then returns the local variable to its
** correct value
*/
void restore_retparm(int32 parmcount) {
  stack_retparm *p;
  int32 vartype, intvalue;
  float64 floatvalue;
  basicstring stringvalue;
  p = basicvars.stacktop.retparmsp;	/* Not needed, but the code is unreadable otherwise */
#ifdef DEBUG
  if (basicvars.debug_flags.stack) fprintf(stderr, "Restoring RETURN variable at %p from %p, return dest=%p\n",
   p->savedetails.address.intaddr, p, p->retdetails.address.intaddr);
#endif
  basicvars.stacktop.retparmsp++;
  switch (p->savedetails.typeinfo & PARMTYPEMASK) {	/* Fetch value from local variable and restore local var */
  case VAR_INTWORD:	/* Integer variable */
    intvalue = *p->savedetails.address.intaddr;		/* Fetch current value of local variable */
    *p->savedetails.address.intaddr = p->value.savedint;	/* Restore local variable to its old value */
    vartype = VAR_INTWORD;
    break;
  case VAR_FLOAT:	/* Floating point variable */
    floatvalue = *p->savedetails.address.floataddr;
    *p->savedetails.address.floataddr = p->value.savedfloat;
    vartype = VAR_FLOAT;
    break;
  case VAR_STRINGDOL:	/* String variable */
    stringvalue = *p->savedetails.address.straddr;
    *p->savedetails.address.straddr = p->value.savedstring;
    vartype = VAR_STRINGDOL;
    break;
  case VAR_INTBYTEPTR:	/* Indirect byte integer variable */
    intvalue = basicvars.offbase[p->savedetails.address.offset];
    basicvars.offbase[p->savedetails.address.offset] = p->value.savedint;
    vartype = VAR_INTWORD;
    break;
  case VAR_INTWORDPTR:	/* Indirect word integer variable */
    intvalue = get_integer(p->savedetails.address.offset);
    store_integer(p->savedetails.address.offset, p->value.savedint);
    vartype = VAR_INTWORD;
    break;
  case VAR_FLOATPTR:		/* Indirect floating point variable */
    floatvalue = get_float(p->savedetails.address.offset);
    store_float(p->savedetails.address.offset, p->value.savedfloat);
    vartype = VAR_FLOAT;
    break;
  case VAR_DOLSTRPTR:		/* Indirect string variable */
    intvalue = stringvalue.stringlen = get_stringlen(p->savedetails.address.offset);
    stringvalue.stringaddr = alloc_string(intvalue);
    if (intvalue>0) memmove(stringvalue.stringaddr, &basicvars.offbase[p->savedetails.address.offset], intvalue);
    memmove(&basicvars.offbase[p->savedetails.address.offset], p->value.savedstring.stringaddr, p->value.savedstring.stringlen);
    free_string(p->value.savedstring);		/* Discard saved copy of original '$ string' */
    vartype = VAR_DOLSTRPTR;
    break;
  case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY:	/* Array - Do nothing */
    break;
  default:
    error(ERR_BROKEN, __LINE__, "stack");
  }

/* Now restore the next parameter */

  parmcount--;
  if (parmcount>0) {	/* There are still some parameters to do */
    if (basicvars.stacktop.intsp->itemtype==STACK_LOCAL)
      restore(parmcount);
    else {	/* Must be a return parameter */
      restore_retparm(parmcount);
    }
  }

/* Now we can store the returned value in original variable */

  switch (p->retdetails.typeinfo) {
  case VAR_INTWORD:
    *p->retdetails.address.intaddr = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue);
    break;
  case VAR_FLOAT:
    *p->retdetails.address.floataddr = vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue;
    break;
  case VAR_STRINGDOL:
    free_string(*p->retdetails.address.straddr);
    *p->retdetails.address.straddr = stringvalue;
    break;
  case VAR_INTBYTEPTR:
    basicvars.offbase[p->retdetails.address.offset] = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue);
    break;
  case VAR_INTWORDPTR:
    store_integer(p->retdetails.address.offset, vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue));
    break;
  case VAR_FLOATPTR:
    store_float(p->retdetails.address.offset, vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue);
    break;
  case VAR_DOLSTRPTR:
    if (stringvalue.stringlen>0) memmove(&basicvars.offbase[p->retdetails.address.offset], stringvalue.stringaddr, stringvalue.stringlen);
    if (vartype==VAR_STRINGDOL) {	/* Local var was a normal string variable */
      basicvars.offbase[p->retdetails.address.offset+stringvalue.stringlen] = CR;	/* So add a 'CR' at the end of the string */
    }
    free_string(stringvalue);
    break;
  case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY:	/* 'RETURN' dest is array - Do nothing */
    break;
  default:
    error(ERR_BROKEN, __LINE__, "stack");
  }
}
Esempio n. 19
0
int multi_string(char *out, char *sbase, int squarn)
{
	int i,j,k,l, m;
	
	int base_length,tmp_begin;
	int mul,up,leave, imiddle;

	int begin;
	
	char stmp[MAXLENGTH+1];
	char matrix[6][MAXLENGTH+1];
	
	base_length=strlen(sbase);
	memset(stmp, ' ', MAXLENGTH);
	stmp[MAXLENGTH] = '\0';
	
	for(i=base_length-1; i>=0; i--) {
		stmp[MAXLENGTH-(base_length-i)]=sbase[i];
	}
	for(i=1; i<squarn; i++) {
		/* double string  stmpXsbase, result save in stmp */
		for(j=MAXLENGTH; j>=0; j--) {
			if(stmp[j] == ' ') {
				tmp_begin = j+1;
				break;
			}
		}
		
		memset(matrix, ' ', sizeof(matrix));
		for(j=base_length-1; j>=0; j--) {
			up = 0;
			mul = 0;
			leave = 0;
			if( TOINT(sbase[j]) == 0)
				continue;
			
			for(k=MAXLENGTH-1; k>=tmp_begin; k--) {
				mul= TOINT(sbase[j])*TOINT(stmp[k]) +up;
				up=mul/10;
				leave=mul%10;
				matrix[j][k-(base_length-j-1)] = TOCHAR(leave);
			}
			if( up !=0 ) {
				matrix[j][tmp_begin-(base_length-j)] = TOCHAR(up);
			}
		}
		if(up!=0) 
			tmp_begin=tmp_begin-base_length;
		else
			tmp_begin=tmp_begin-base_length+1;
		
		for(l=base_length-1; l>=0; l--){
			for(m=0; m<MAXLENGTH; m++) {
			}
		}
				
		/* count the matrix */

		up = 0;
		for(k=MAXLENGTH-1; k>=tmp_begin; k--) {
			mul = 0;
			leave = 0;
			for(j=base_length-1; j>=0; j--) {
				if(matrix[j][k] == ' ')
					imiddle=0;
				else
					imiddle = TOINT(matrix[j][k]);
				mul += imiddle;
			}
			mul += up;
			up = mul/10;
			leave = mul%10;
			stmp[k] = TOCHAR(leave);
		}
		if( up != 0) {
			stmp[k] = TOCHAR(up);
		}
	}
	
	for(i=0; i<MAXLENGTH; i++) {
		if(stmp[i] != ' ') {
			begin = i;
			break;
		}
	}
	memcpy(out, stmp, MAXLENGTH+1);
	return begin;
}