Beispiel #1
0
int mathWrapInt(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, *b, *c;
	int err;

	a = g->sp - 2;
	b = g->sp - 1;
	c = g->sp;

	if (IsSym(b)) {
		*a = *b;
	} else if (IsSym(c)) {
		*a = *c;
	} else if (IsInt(b) && IsInt(c)) {
		SetRaw(a, sc_mod((int)(slotRawInt(a) - slotRawInt(b)), (int)(slotRawInt(c) - slotRawInt(b) + 1)) + slotRawInt(b));
	} else {
		double x, lo, hi;
		x = slotRawInt(a);
		err = slotDoubleVal(b, &lo);
		if (err) return err;
		err = slotDoubleVal(c, &hi);
		if (err) return err;
		SetFloat(a, sc_mod(x - lo, hi - lo) + lo);
	}
	return errNone;
}
Beispiel #2
0
bool CTag::WriteTagToFile(CFileDataIO* file, EUtf8Str eStrEncode) const
{
	ASSERT_VALID(this);

	// don't write tags of unknown types, we wouldn't be able to read them in again 
	// and the met file would be corrupted
	if (IsStr() || IsInt() || IsFloat() || IsBlob() || IsInt64())
	{
		file->WriteUInt8(m_uType);
		
		if (m_pszName)
		{
			UINT taglen = strlen(m_pszName);
			file->WriteUInt16((uint16)taglen);
			file->Write(m_pszName, taglen);
		}
		else
		{
			file->WriteUInt16(1);
			file->WriteUInt8(m_uName);
		}

		if (IsStr())
		{
			file->WriteString(GetStr(), eStrEncode);
		}
		else if (IsInt())
		{
			file->WriteUInt32((uint32)m_uVal);
		}
		else if (IsInt64(false))
		{
			file->WriteUInt64(m_uVal);
		}
		else if (IsFloat())
		{
			file->Write(&m_fVal, 4);
		}
		else if (IsBlob())
		{
			// NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a
			file->WriteUInt32(m_nBlobSize);
			file->Write(m_pData, m_nBlobSize);
		}
		//TODO: Support more tag types
		else
		{
			TRACE("%s; Unknown tag: type=0x%02X\n", __FUNCTION__, m_uType);
			ASSERT(0);
			return false;
		}
		return true;
	}
	else
	{
		TRACE("%s; Ignored tag with unknown type=0x%02X\n", __FUNCTION__, m_uType);
		ASSERT(0);
		return false;
	}
}
Beispiel #3
0
int mathFoldInt(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, *b, *c;
	int err;

	a = g->sp - 2;
	b = g->sp - 1;
	c = g->sp;

	if (IsSym(b)) {
		*a = *b;
	} else if (IsSym(c)) {
		*a = *c;
	} else if (IsInt(b) && IsInt(c)) {
		SetRaw(a, sc_fold(slotRawInt(a), slotRawInt(b), slotRawInt(c)));
	} else {
		double x, lo, hi;
		x = slotRawInt(a);
		err = slotDoubleVal(b, &lo);
		if (err) return err;
		err = slotDoubleVal(c, &hi);
		if (err) return err;
		SetFloat(a, sc_fold(x, lo, hi));
	}
	return errNone;
}
Beispiel #4
0
/* Function: ReadPhylip()
 * Date:     SRE, Fri Jun 18 12:59:37 1999 [Sanger Centre]
 *
 * Purpose:  Parse an alignment from an open Phylip format
 *           alignment file. Phylip is a single-alignment format.
 *           Return the alignment, or NULL if we have no data.
 *
 * Args:     afp - open alignment file
 *
 * Returns:  MSA * - an alignment object
 *                   Caller responsible for an MSAFree()
 *           NULL if no more alignments        
 */
MSA *
ReadPhylip(MSAFILE *afp)
{
  MSA  *msa;
  char *s, *s1, *s2;
  char  name[11];		/* seq name max len = 10 char */
  int   nseq, alen;
  int   idx;			/* index of current sequence */
  int   slen;
  int   nblock;
  
  if (feof(afp->f)) return NULL;

  /* Skip until we see a nonblank line; it's the header,
   * containing nseq/alen
   */
  nseq = 0; alen = 0;
  while ((s = MSAFileGetLine(afp)) != NULL)
    {
      if ((s1 = sre_strtok(&s, WHITESPACE, NULL)) == NULL) continue;
      if ((s2 = sre_strtok(&s, WHITESPACE, NULL)) == NULL)
	Die("Failed to parse nseq/alen from first line of PHYLIP file %s\n", afp->fname);
      if (! IsInt(s1) || ! IsInt(s2))
	Die("nseq and/or alen not an integer in first line of PHYLIP file %s\n", afp->fname);
      nseq = atoi(s1);
      alen = atoi(s2);
      break;
    }

  msa = MSAAlloc(nseq, 0);
  idx    = 0;
  nblock = 0;
  while ((s = MSAFileGetLine(afp)) != NULL) 
    {
      /* ignore blank lines. nonblank lines start w/ nonblank char */
      if (isspace(*s)) continue;
				/* First block has seq names */
      if (nblock == 0) {
	strncpy(name, s, 10);
	name[10] = '\0';
	GKIStoreKey(msa->index, name);
	msa->sqname[idx] = sre_strdup(name, -1);
	s += 10;		
      }
				/* be careful of trailing whitespace on lines */
      if ((s1 = sre_strtok(&s, WHITESPACE, &slen)) == NULL)
	Die("Failed to parse sequence at line %d of PHYLIP file %s\n", 
	    afp->linenumber, afp->fname);
      msa->sqlen[idx] = sre_strcat(&(msa->aseq[idx]), msa->sqlen[idx], s1, slen);

      idx++;
      if (idx == nseq) { idx = 0; nblock++; }
    }
  msa->nseq = nseq;
  MSAVerifyParse(msa);		/* verifies; sets alen, wgt; frees sqlen[] */
  return msa;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetColorFromInts( Rgba& color )
{
    std::string string = "";


    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.r = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }
    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.g = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }

    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.b = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }

    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.a = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
            return true;
        }
        else
            return false;
    }
    return false;
}
Beispiel #6
0
void PriorityQueueAdd(struct VMGlobals *g, PyrObject* queueobj, PyrSlot* item, double time)
{
	PyrObject *schedq, *newschedq;
	int size, maxsize;

	PyrSlot *schedqSlot = queueobj->slots;
	if (!IsObj(schedqSlot)) {
		size = 32;
		schedq = newPyrArray(g->gc, size, 0, true);
		schedq->size = 1;
		SetInt(schedq->slots + 0, 0); // stability count
		SetObject(schedqSlot, schedq);
		g->gc->GCWriteNew(queueobj, schedq); // we know schedq is white so we can use GCWriteNew
	} else {
		schedq = slotRawObject(schedqSlot);
		maxsize = ARRAYMAXINDEXSIZE(schedq);
		size = schedq->size;
		if (size+3 > maxsize) {

			newschedq = newPyrArray(g->gc, maxsize*2, 0, true);
			newschedq->size = size;

			slotCopy(newschedq->slots, schedq->slots, size);
			assert(IsInt(newschedq->slots));

			SetObject(schedqSlot, newschedq);
			g->gc->GCWriteNew(queueobj, newschedq); // we know newschedq is white so we can use GCWriteNew

			schedq = newschedq;
		}
	}

	addheap(g, schedq, time, item);
}
Beispiel #7
0
    void Table::SetValue(const Value &key, const Value &value)
    {
        // Try array part
        if (key.type_ == ValueT_Number && IsInt(key.num_))
        {
            if (SetArrayValue(static_cast<std::size_t>(key.num_), value))
                return ;
        }

        // Hash part
        if (!hash_)
        {
            // If value is nil and hash part is not existed, then do nothing
            if (value.IsNil())
                return ;
            hash_.reset(new Hash);
        }

        auto it = hash_->find(key);
        if (it != hash_->end())
        {
            // If value is nil, then just erase the element
            if (value.IsNil())
                hash_->erase(it);
            else
                it->second = value;
        }
        else
        {
            // If key is not existed and value is not nil, then insert it
            if (!value.IsNil())
                hash_->insert(std::make_pair(key, value));
        }
    }
Beispiel #8
0
int prSetControlBusValues(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	assert(IsObj(a));
	PyrObject * self = slotRawObject(a);
	int ptrIndex       = 0;
	PyrSlot * ptrSlot = self->slots + ptrIndex;
	if (NotPtr(ptrSlot))
		return errFailed;

	if (!IsInt(b))
		return errFailed;

	int busIndex = slotRawInt(b);

	if (!IsObj(c))
		return errFailed;

	PyrObject * values = slotRawObject(c);
	server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot);
	float * control_busses = client->get_control_busses() + busIndex;

	for (int i = 0; i != values->size; ++i) {
		float value;
		int error = slotFloatVal(values->slots + i, &value);
		if (error != errNone)
			return error;

		control_busses[i] = value;
	}
	return errNone;
}
Beispiel #9
0
int prSetControlBusValue(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	assert(IsObj(a));
	PyrObject * self = slotRawObject(a);
	int ptrIndex       = 0;
	PyrSlot * ptrSlot = self->slots + ptrIndex;
	if (NotPtr(ptrSlot))
		return errFailed;

	if (!IsInt(b))
		return errFailed;

	int busIndex = slotRawInt(b);

	if (NotPtr(ptrSlot))
		return errFailed;

	float value;
	int error = slotFloatVal(c, &value);
	if (error != errNone)
		return error;

	server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot);

	client->get_control_busses()[busIndex] = value;
	return errNone;
}
Beispiel #10
0
int prArray_OSCBytes(VMGlobals *g, int numArgsPushed)
{
	PyrSlot* a = g->sp;
	PyrObject *array = a->uo;
	PyrSlot* args = array->slots;
	int numargs = array->size;
	if (numargs < 1) return errFailed;
	big_scpacket packet;

	if (IsFloat(args) || IsNil(args) || IsInt(args)) {
		makeSynthBundle(&packet, args, numargs, false);
	} else if (IsSym(args) || isKindOfSlot(args, class_string)) {
		makeSynthMsgWithTags(&packet, args, numargs);
	} else {
		return errWrongType;
	}

	int size = packet.size();
	PyrInt8Array* obj = newPyrInt8Array(g->gc, size, 0, true);
	obj->size = size;
	memcpy(obj->b, packet.data(), size);
	SetObject(a, (PyrObject*)obj);
	//for (int i=0; i<packet.size()/4; i++) post("%d %08X\n", i, packet.buf[i]);

	return errNone;
}
Beispiel #11
0
void markChildren(word* p, int s[]){
	if(Color(p[0]) == White){
		p[0] = Paint(p[0], Black);
		for(int i = 1; i <= Length(p[0]); i++){
			if(!IsInt(p[i]) && p[i] != 0) markChildren((word*) p[i], s);
		}
	}
}
Beispiel #12
0
		bool BaseParser::ParseInt(const std::string& value, int& ret)
		{
			if(IsInt(value) == false)
			{
				return false;
			}
			ret = strtol(value.c_str(), nullptr, 10);
			return true;
		}
Beispiel #13
0
/////////////////////////////////////////////////
// Prolog-Value
TStr TPlVal::GetStr(TPlBs* PlBs) const {
  TChA ChA;
  if (IsInt()){ChA+=TInt::GetStr(GetInt());}
  else if (IsFlt()){ChA+=TFlt::GetStr(GetFlt());}
  else if (IsAtom()){ChA+=PlBs->GetAtomQStr(GetAtomId());}
  else if (IsTup()){PPlTup Tup=PlBs->GetTup(GetTupId()); ChA+=Tup->GetStr(PlBs);}
  else {Fail;}
  return ChA;
}
Beispiel #14
0
void markPhase(int s[], int sp) {
	printf("marking ...\n");
	while(sp > 0){
		if(!IsInt(s[sp]) && s[sp] != 0)  {
			markChildren((word*) s[sp],s);
		}
		sp--;
	}
}
Beispiel #15
0
//Mark all headers referenced from the stack
void markPhase(int s[], int sp) {
  printf("marking ...\n");
  int i;
  for(i = 0; i<sp; i++){
    if(!IsInt(s[i]) && s[i] != 0){
      mark((word *)s[i]);
    }
  }
}
Beispiel #16
0
//Mark all headers referenced from the stack
void markPhase(int s[], int sp) {
  printf("marking ...\n");
  int i;
  //Mark all references in the stack
  for(i = 0; i<sp; i++){
    if(!IsInt(s[i]) && s[i] != 0){
      mark((word *)s[i]);
    }
  }
}
Beispiel #17
0
void markPhase(int s[], int sp) {
  printf("\nmarking ...\n");
  
  int n;
  for (n = 0; n < sp; n++) {
    if (!IsInt(s[n]) && s[n] != 0) {
      mark(s[n]);
    }
  }
}
Beispiel #18
0
/* Marks heap references in the stack */
void markPhase(int s[], int sp) {
  printf("\nmarking ...\n");
  int i;
  for(i = 0; i < sp; i++) /* Step A */
  {
	if(!IsInt(s[i]) && (s[i]) != 0) // If item on stack is not an integer and is not nil, convert it to a word reference and mark it
	{ 
	  word* block = ((word*) s[i]);
	  block[0] = Paint(block[0], Grey);
	}
  }

  int goAgain = 1;
  word* b;
  int j;
  
  while(goAgain)
  {
    goAgain = 0;
	for(i = 0; i < HEAPSIZE; i += Length(b[0]) + 1) // To iterate over all the blocks in the heap we increment i by length of b + 1.
	{

	  b = (word*) &heap[i]; // Get address of the block in the heap
	  if(Color(b[0]) == Grey)
	  {
	    b[0] = Paint(b[0], Black);
		for(j = 1; j <= Length(b[0]); j++) // Go through all words in the block b
		{
		  if(!IsInt(b[j]) && b[j] != 0)
		  {
		    word* rblock = (word*) b[j]; // We need to get the word pointer to be able to colour the header
		    if(Color(rblock[0]) == White)
		    {
		      rblock[0] = Paint(rblock[0], Grey);
		      goAgain = 1; // Every time we paint a block grey, we need to check recheck heap for grey blocks.
           }
		  }
		}
	  }
	}
  }
}
Beispiel #19
0
void printStackAndPc(int s[], int bp, int sp, int p[], int pc) {
  printf("[ ");
  int i;
  for (i=0; i<=sp; i++)
    if (IsInt(s[i]))
      printf("%d ", Untag(s[i]));
    else
      printf("#%d ", s[i]);      
  printf("]");
  printf("{%d:", pc); printInstruction(p, pc); printf("}\n"); 
}
Beispiel #20
0
void mark(word* block) {
	if (Color(block[0]) == White) {
		block[0] = Paint(block[0], Black);
		int i;
		for (i = 1; i <= Length(block[0]); i++) {
			if (!IsInt(block[i]) && block[i] != 0) {
				mark(block[i]);
			}
		}
	}
}
Beispiel #21
0
/*! \todo there is probably also a shortcut for Max and jMax
    \todo size checking
*/
FLEXT_TEMPIMPL(void FLEXT_CLASSDEF(flext))::GetAString(const t_atom &a,char *buf,size_t szbuf)
{ 
#if FLEXT_SYS == FLEXT_SYS_PD
	atom_string(const_cast<t_atom *>(&a),buf,(int)szbuf);
#else
    if(IsSymbol(a)) STD::strncpy(buf,GetString(a),szbuf);
	else if(IsFloat(a)) STD::snprintf(buf,szbuf,"%f",GetFloat(a));
	else if(IsInt(a)) STD::snprintf(buf,szbuf,"%i",GetInt(a));
    else *buf = 0;
#endif
}  
Beispiel #22
0
//Marks the headers black recursively
void mark(word* block){
  //Paint header black if color is white and not 0
  if(Color(block[0])==White && block[0] != 0){
    block[0] = Paint(block[0], Black);
    //Mark recursively if one of the elements in the block is a reference
    int i;
    for(i=1; i<=Length(block[0]); i++){
      if(!IsInt(block[i]) && block[i] != 0 && Color(block[i]) != Black)
        mark((word *)block[i]);
    }
  }
}
Beispiel #23
0
/* Marks heap references in the stack */
void markPhase(int s[], int sp) {
  printf("\nmarking ...\n");
  /*Step A*/
  int i;
  for(i = 0; i < sp; i++)
  {
  	if(!IsInt(s[i]) && (s[i]) != 0) // If item on stack is not an integer and is not nil, convert it to a word reference and mark it
  	{ 
  	  mark((word*) s[i]);
  	}
  }
}
Beispiel #24
0
	int Value::AsInt() const
	{
		if (IsNull())
			return 0;
		else
		{
			if (IsInt() || IsDouble())
			{
				std::stringstream sstr(valueStr);
				int val;
				sstr >> val;
				return val;
			}
			else
				throw ValueException();
Beispiel #25
0
int prGetControlBusValues(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	assert(IsObj(a));
	PyrObject * self = slotRawObject(a);
	int ptrIndex       = 0;
	PyrSlot * ptrSlot = self->slots + ptrIndex;
	if (NotPtr(ptrSlot))
		return errFailed;

	if (!IsInt(b))
		return errFailed;

	int busIndex = slotRawInt(b);

	if (!IsInt(c))
		return errFailed;

	int numberOfChannels = slotRawInt(c);

	server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot);

	PyrObject * ret = newPyrArray(g->gc, numberOfChannels, 0, 1);
	ret->size = numberOfChannels;

	for (int i = 0; i != numberOfChannels; ++i) {
		float value = client->get_control_busses()[busIndex + i];
		SetFloat(ret->slots+i, value);
	}

	SetObject(a, ret);
	return errNone;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetInt( int& integer )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            integer = strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
            return true;
        }

        return false;
    }
    return false;
}
Beispiel #27
0
bool CTag::WriteTagToFile(CFileDataIO* file, EUtf8Str WXUNUSED(eStrEncode), bool restrictive) const
{
	
	// Don't write tags of unknown types, we wouldn't be able to read them in again 
	// and the met file would be corrupted
	if (!restrictive || (IsStr() || IsInt() || IsFloat() || IsBlob())) {
	
		// If this fails, it'll throw.
		file->WriteTag(*this);
		return true;

	} else {
		printf("%s; Ignored tag with unknown type=0x%02X\n", __FUNCTION__, m_uType);
		return false;
	}
}
Beispiel #28
0
/// Export a number to a string in given base to given base digits
// FIXME API breach: aPrecision is supposed to be in digits, not bits
void BigNumber::ToString(LispString& aResult, int aBasePrecision, int aBase) const
{
  ANumber num(*iNumber);
//  num.CopyFrom(*iNumber);

  //TODO this round-off code is not correct yet, but will work in most cases
  // This is a bit of a messy way to round off numbers. It is probably incorrect,
  // even. When precision drops one digit, it rounds off the last ten digits.
  // So the following code is probably only correct if aPrecision>=num.iPrecision
  // or if aPrecision < num.iPrecision-10
  if (aBasePrecision<num.iPrecision)
  {
    if (num.iExp > 1)
      num.RoundBits();
  }
  num.ChangePrecision(aBasePrecision);

  if (!IsInt())
  {
    for(;;)
    {

      const int ns = num.size();
      bool greaterOne = false;
      if (num.iExp >= int(ns)) break;
      for (int i=num.iExp;i<ns;i++)
      {
        if (num[i] != 0)
        {
          if (!(i==num.iExp && num[i]<10000 && num.iTensExp == 0))
          {
            greaterOne=true;
            break;
          }
        }
      }
      if (!greaterOne) break;
      PlatDoubleWord carry=0;
      BaseDivideInt(num,10, WordBase, carry);
      num.iTensExp++;
    }
  }

  ANumberToString(aResult, num, aBase,(iType == KFloat));
}
Beispiel #29
0
    void Table::SetValue(const Value &key, const Value &value)
    {
        // Try array part
        if (key.type_ == ValueT_Number && IsInt(key.num_))
        {
            if (SetArrayValue(static_cast<std::size_t>(key.num_), value))
                return ;
        }

        // Hash part
        if (!hash_)
            hash_.reset(new Hash);

        auto it = hash_->find(key);
        if (it != hash_->end())
            it->second = value;
        else
            hash_->insert(std::make_pair(key, value));
    }
Beispiel #30
0
    Value Table::GetValue(const Value &key) const
    {
        // Get from array first
        if (key.type_ == ValueT_Number && IsInt(key.num_))
        {
            std::size_t index = static_cast<std::size_t>(key.num_);
            if (index >= 1 && index <= ArraySize())
                return (*array_)[index - 1];
        }

        // Get from hash table
        if (hash_)
        {
            auto it = hash_->find(key);
            if (it != hash_->end())
                return it->second;
        }

        // key not exist
        return Value();
    }