Exemple #1
0
int TiffIfd::LoadImageData(FILE *pFile, bool loadall)
{
  TiffTag *tagdataoffs = FindTag(TiffTag::tag_stripoffset);
  TiffTag *tagdatabytes = FindTag(TiffTag::tag_stripbytes);
  if (tagdataoffs == NULL) {
    if (tagdatabytes !=NULL) throw("offs but no length in data");
    tagdataoffs = FindTag(TiffTag::tag_thumbnailoffset);
    tagdatabytes = FindTag(TiffTag::tag_thumbnaillength);
  }
  delete [] data_;
  data_ = NULL;
  if (tagdataoffs && tagdatabytes) {
    const unsigned int dataoffs = tagdataoffs->GetUIntValue(0);
    const unsigned int databytes = tagdatabytes->GetUIntValue(0);
    printf("Loading internal image data at %d,%d\n", dataoffs, databytes);
    int iRV = fseek(pFile, dataoffs + subfileoffset_, SEEK_SET);
    if (iRV != 0)
      throw("Can't seek to data");
    jpeg_ = new Jpeg();
    jpeg_->LoadFromFile(pFile, false, dataoffs + subfileoffset_);
    if (loadall) {
      printf("Loading all\n");
      iRV = fseek(pFile, dataoffs + subfileoffset_, SEEK_SET);
      data_ = new unsigned char [databytes];
      iRV = fread(data_, sizeof(unsigned char), databytes, pFile);
      if (iRV != databytes)
        throw("Couldn't read ImageData");
    }

    return databytes;
  }
  return 0;
}
size_t psXMLString::FindMatchingEndTag( int start, const char* tagName )
{
    char termTag[100];
    int end=-1, next;
    int nest = 1;

    strcpy(termTag,"/");
    strcat(termTag,tagName);

    while ( nest )
    {
        end = FindTag( termTag, start );
        if ( end == -1 )
            break;

        next = FindTag(tagName, start+1);
        if ( next == -1 || next > end )
        {
            nest--;
            start = end+1;
        }
        else
        {
            nest++;
            start=next+1;
        }
    }
    return end;
}
static int ReadHdr(FILE* fp, int* pSampleRate, int* pChannels, int* pDataStart)
{
    int rtn = 0;
    struct {
        int16_t FormatTag;
        int16_t Channels;
        int32_t SamplesPerSec;
        int32_t AvgBytesPerSec;
        int16_t BlockAlign;
        int16_t BitsPerSample;
    } wavHdr;

    if (fp && pSampleRate && pChannels && pDataStart) {
        int mSamples = FindTag(fp, "fmt ");
        int nread = fread(&wavHdr, sizeof(wavHdr), (size_t)1, fp);
        if (nread <= 0) {
            cli_print("ReadHdr: error in reading wavHdr");
            return -1;
        }

        *pSampleRate = ENDIAN_LE32 (wavHdr.SamplesPerSec);
        *pChannels = ENDIAN_LE16 (wavHdr.Channels);

        fseek(fp, (long)((unsigned int)mSamples - sizeof(wavHdr)), SEEK_CUR);
        rtn = FindTag(fp, "data");
        *pDataStart = ftell(fp);
    }
    return rtn;
}
Exemple #4
0
size_w InsertTypeGV(HWND hwndGridView, HGRIDITEM hRoot, TypeDecl *typeDecl, size_w dwOffset)
{
	GVITEM		gvitem = { 0 };
	size_w		dwLength = 0;
	ExprNode *	offsetExpr;

	// typedef statements are never displayed
	if(typeDecl->typeAlias == true)
		return dwOffset;

	if(typeDecl->declList.size() == 0 && typeDecl->nested)
	{
		if(FindTag(typeDecl->tagList, TOK_OFFSET, &offsetExpr))
		{
			UINT64 r;
			HWND hwndHV = GetActiveHexView(g_hwndMain);
			//dwOffset += Evaluate(offsetExpr);

			r = sizeof(IMAGE_DOS_HEADER);
			Evaluate(hRoot,	offsetExpr, &r, dwOffset, hwndHV, hwndGridView);
			dwOffset = r & 0xffff;
		}

		// embedded struct/union that has no variables (i.e. just a plain unnamed struct decl)
		// don't insert a gridview item for the struct/union name, this means that
		// the embedded struct members get added at the same level as the parent's members
		dwLength += RecurseType(hwndGridView, hRoot, typeDecl->baseType, dwOffset, typeDecl);
		return dwLength;
	}
	else
	{
		// display each variable-decl
		size_t i;

		for(i = 0; i < typeDecl->declList.size(); i++)
		{
			Type *type = typeDecl->declList[i];

			if(FindTag(typeDecl->tagList, TOK_OFFSET, &offsetExpr))
			{
				UINT64 r;
				HWND hwndHV = GetActiveHexView(g_hwndMain);
				Evaluate(hRoot,//typeDecl->parent->sptr, 
					offsetExpr, &r, dwOffset, hwndHV, hwndGridView);
			}
			
			// always an IDENTIFER at this point
			//HGRIDITEM hChild = GridView_InsertChild(hwndGridView, hRoot, &gvitem);
			//TRACEA("*** %d: %s\n", type->ty, type->sym->name);
			//dwLength += RecurseType(hwndGridView, hChild, type, dwOffset + dwLength, typeDecl);

			//TRACEA("*** %d: %s\n", type->ty, type->sym->name);
			dwLength += RecurseType(hwndGridView, hRoot, type, dwOffset + dwLength, typeDecl);
		}
	}

	return dwLength;
}
bool CXMLUtils::FindElement(const char *szXML, const string& strElementName,
                            const char *& szStartOuter, const char *& szEndOuter,
                            const char *& szStartInner, const char *& szEndInner)
{
  string strElementStarter = strElementName;
  string strElementEnder   = string("/") + strElementName;

  return FindTag(szXML, strElementStarter, szStartOuter, szStartInner) &&
         FindTag(szStartInner, strElementEnder, szEndInner, szEndOuter);
}
Exemple #6
0
void Level::OnLoaded() {
	Parent::OnLoaded();

	const tbc::ChunkyClass::Tag* speed_tag = FindTag("driver", 1, 0);
	if (speed_tag) {
		level_speed_ = speed_tag->float_value_list_[0];
	}
	const tbc::ChunkyClass::Tag* gravity_tag = FindTag("behavior", 3, 0);
	if (gravity_tag) {
		vec3 gravity(gravity_tag->float_value_list_[0], gravity_tag->float_value_list_[1], gravity_tag->float_value_list_[2]);
		manager_->GetGameManager()->GetPhysicsManager()->SetGravity(gravity);
	} else {
		deb_assert(false);
	}
}
Exemple #7
0
int FSearch( unsigned handle, char *str, char *buff_start,
             unsigned buff_size, unsigned prefix_len )
{
    unsigned long       size;
    unsigned long       offset;
    unsigned long       match_pos;
    unsigned            str_len;
    status              stat;
    buffer              buff;


    buff.size  = buff_size;
    buff.start = buff_start;
    str_len = strlen( str );
    match_pos = -1;
    offset = 0;
    for( size = SeekStream( handle, 0L, DIO_SEEK_END ) >> 1; size > 0; size >>= 1 ) {
        FilePos = offset + size;
        SeekStream( handle, FilePos, DIO_SEEK_ORG );
        buff.end = buff.start;
        buff.ptr = buff.end;
        stat = FindTag( handle, &buff, str, str_len, prefix_len );
        if( stat == EXACT ) {
            match_pos = FilePos;
            break; /* from for loop */
        } else if( stat == MATCH ) {
            match_pos = FilePos;
        } else if( stat == LOW ) {
            offset += size;
        }
    }
    if( match_pos == -1 ) return( 0 );
    SeekStream( handle, match_pos, DIO_SEEK_ORG );
    return( 1 );
}
void CXMLUtils::WrapWithRoot(const char *szXML,
                             size_t      xmlSize,
                             string    & strWrapped)
{
  const char szVersionTag[] = "?xml";
  const char szRootOpen[]   = "<Root>";
  const char szRootClose[]  = "</Root>";

  // Let's see if XML contains an XML Declaration (e.g. <?xml version="1.0"
  // encoding="UTF-8" ?>)
  const char *szStart = NULL, *szEnd = NULL;

  if (FindTag(szXML, szVersionTag, szStart, szEnd))
  {
    // skip the declaration before wrapping with root (otherwise the XML will
    // not be well formed)
    szXML = szEnd;
  }

  strWrapped.clear();
  strWrapped.reserve(xmlSize + sizeof(szRootOpen) + sizeof(szRootClose));

  strWrapped += szRootOpen;
  strWrapped += szXML;
  strWrapped += szRootClose;
}
Exemple #9
0
void TiffIfd::ListTags() const {
  TiffTag *width_tag = FindTag(TiffTag::tag_width);
  TiffTag *height_tag = FindTag(TiffTag::tag_height);
  if (width_tag && height_tag) {
    printf("Image: %dx%d ", width_tag->GetUIntValue(0), height_tag->GetUIntValue(0));
    TiffTag *compression_tag = FindTag(TiffTag::tag_compression);
    if(compression_tag)
      printf("(%d) ", compression_tag->GetUIntValue(0));
  }

  for(int tagindex=0 ; tagindex < tags_.size(); ++tagindex) {
    tags_[tagindex]->Print();
  printf("\n");
  }
  printf("\n");
}
Exemple #10
0
void Projectile::OnLoaded() {
	Parent::OnLoaded();

	const tbc::ChunkyClass::Tag* tag = FindTag("ammo", 4, -1);
	deb_assert(tag);
	explosive_energy_ = tag->float_value_list_[3];

	str launch_sound_name;
	str shreek_sound_name;
	const float pitch = ProjectileUtil::GetShotSounds(GetManager(), tag->string_value_list_, launch_sound_name, shreek_sound_name);
	if (!launch_sound_name.empty()) {
		xform parent_transform;
		vec3 parent_velocity;
		if (!ProjectileUtil::GetBarrel(this, parent_transform, parent_velocity)) {
			parent_transform.SetPosition(GetPosition());
			parent_velocity = GetVelocity();
		}
		UiCure::UserSound3dResource* launch_sound = new UiCure::UserSound3dResource(GetUiManager(), uilepra::SoundManager::kLoopNone);
		new UiCure::SoundReleaser(GetResourceManager(), ui_manager_, GetManager(), launch_sound_name, launch_sound, parent_transform.GetPosition(), parent_velocity, 5.0f, pitch);
	}
	if (!shreek_sound_name.empty()) {
		shreek_sound_ = new UiCure::UserSound3dResource(GetUiManager(), uilepra::SoundManager::kLoopForward);
		shreek_sound_->Load(GetResourceManager(), shreek_sound_name,
			UiCure::UserSound3dResource::TypeLoadCallback(this, &Projectile::LoadPlaySound3d));
	}
}
Exemple #11
0
void EditorInfo::UnregisterInfo (const char* info) {
    UMapElem* elem = FindTag((void*) info);

    if (elem != nil) {
        UMap::Unregister(elem);
        delete elem;
    }
}
Exemple #12
0
void Parser::ExportStructs()
{
	bool foundExport = false;

	// go through every struct that we parsed in THIS file
	for(size_t i = 0; i < globalTypeDeclList.size(); i++)
	{
		TypeDecl *typeDecl = globalTypeDeclList[i];

		if(typeDecl->baseType->ty == typeSTRUCT && typeDecl->fileRef.fileDesc == curFile)
		{
			if(FindTag(typeDecl->tagList, TOK_EXPORT, 0))
				foundExport = true;
		}
	}

	if(foundExport)
	{
		// clear the export flag on all structs
		for(size_t i = 0; i < globalTypeDeclList.size(); i++)
		{
			TypeDecl *typeDecl = globalTypeDeclList[i];

			if(typeDecl->baseType->ty == typeSTRUCT && typeDecl->fileRef.fileDesc == curFile)
			{
				typeDecl->exported = false;
				typeDecl->baseType->sptr->exported = false;
			}
		}

		// set the export flag on explicity defined structs (with the "export" attribute)
		for(size_t i = 0; i < globalTypeDeclList.size(); i++)
		{
			TypeDecl *typeDecl = globalTypeDeclList[i];

			if(typeDecl->baseType->ty == typeSTRUCT && typeDecl->fileRef.fileDesc == curFile)
			{
				if(FindTag(typeDecl->tagList, TOK_EXPORT, 0))
				{
					typeDecl->exported = true;
					typeDecl->baseType->sptr->exported = true;
				}
			}
		}
	}
}
Exemple #13
0
void ExecuteTagMultiBuf1(U32 u32Deviceid, char *tagname, U8 *buf, U8 rwtype, U8 *u8State)
{
	Tag *pcmnd = (Tag*)FindTag(u32Deviceid, tagname);
	if(pcmnd == 0)
	{
		return;
	}
	//ExecuteCommandM((U32*)buf, 0, pcmnd,rwtype,u8State);////buflen 底層有用
}
Exemple #14
0
void ExecuteTagMultiBuf2(U32 u32Deviceid, char *tagname, U8 *buf, U8 *u8State)
{
	Tag *pcmnd = (Tag*)FindTag(u32Deviceid, tagname);
	if(pcmnd == 0)
	{
		return;
	}
	ExecuteCommandM1((U32*)buf, 0, pcmnd,u8State);//buflen 已經沒用
}
// ---------------------------------------------------------------------------
// SwitchLayoutL
// ---------------------------------------------------------------------------
//
void CAlfExAnalogDialerControl::SwitchLayoutL()
    {
    // Get access to first leafs (visuals) of grid layout
    CAlfVisual* displayDeck = FindTag(_L8( KTagArray[ETagAnalogDialerDisplayDeck]));
    CAlfVisual* dialerDeck = FindTag(_L8( KTagArray[ETagAnalogDialerPlateDeck]));
    
    if (displayDeck && dialerDeck)
        {
        // remove visuals from grid layout
        iRootLayout->Remove(displayDeck);
        iRootLayout->Remove(dialerDeck);
 
        // resolve new layout
        iLayoutMode = ResolveLayout(iSquareSide,
                                    iLongerSide);
        
        // modify grid layout
        AddGridLayoutL();
        
        // put visuals back to layout
        if (iLayoutMode == ELayoutAnalogDialerPortrait)
            {
            User::LeaveIfError(iRootLayout->Append(displayDeck));
            User::LeaveIfError(iRootLayout->Append(dialerDeck));
            }
        else
            {
            User::LeaveIfError(iRootLayout->Append(dialerDeck));
            User::LeaveIfError(iRootLayout->Append(displayDeck));
            }
            
        // Notify Alf about layout change
        Env().NotifyLayoutChangedL();
        }
    // else - better not to do anything

    iFeedback->Start();

    // expose new root layout
    /*TAlfTimedValue opacity(0.0f);
    opacity.SetTarget(255, 500);
    iRootLayout->SetOpacity(opacity);   */

    }
Exemple #16
0
int SetTag(U32 deviceid, char *tagname, U8 *buf)
{
	U8 u8State=0;
	Tag *pcmnd = (Tag*)FindTag(deviceid, tagname);
	if(pcmnd == 0)
	{
		return -1;
	}
	ExecuteTag((U32*)buf, pcmnd, 1,&u8State);

	return u8State;
}
Exemple #17
0
//return: -1 for fail, 其他值為自底層設備正確回傳的值
//deviceid: 平台系統定義的deviceid
//tagname:平台系統定義的指令名稱, 對應於command.txt的第二個參數
//此函數不做multithread的控管
float GetValue(int deviceid, char *tagname,U8 *u8State)
{// -1 means error operation, and the other value is the correct

	Tag *pcmnd = (Tag*)FindTag(deviceid, tagname);
	if(pcmnd == 0)
	{
		return -1;
	}
	float value;
	ExecuteTag((U32*)&value, pcmnd,0,u8State); 
	return value;
}
Exemple #18
0
//return: 0 for success, -1 for fail
//deviceid: 平台系統定義的deviceid
//tagname:平台系統定義的指令名稱, 對應於command.txt的第二個參數
//value:平台系統定義所要寫入的值
//此函數不做multithread的控管
int SetValue(int deviceid, char *tagname, float value)
{//0 for success op, -1 for error op

	U8 u8State=0;
	Tag *pcmnd = (Tag*)FindTag(deviceid, tagname);
	if(pcmnd == 0)
	{
		return -1;
	}
	ExecuteTag((U32*)&value, pcmnd, 1,&u8State);

	return u8State;

}
Exemple #19
0
int Pak::findEntry(uint32_t tag) const
{
  const Header *header = reinterpret_cast<const Header*>(m_pakData);
  const Entry *begin = reinterpret_cast<const Entry*>(header + 1);
  const Entry *end = begin + header->count;

  const Entry *i = std::lower_bound(begin, end, tag, FindTag());
  if(i==end || htonl(i->tag)!=tag)
  {
    ERROR("Pak::findEntry: unknown tag 0x%08x", tag);
    return -1;
  }

  return i-begin;
}
Exemple #20
0
float* GetTag(U32 deviceid, char *tagname, U8 *buf, U8 *u8State)
{
	Tag *pcmnd = (Tag*)FindTag(deviceid, tagname);
	float value;
	if(pcmnd == 0)
	{
		*u8State=2;
		value=-1;
		memcpy(buf, &value, sizeof(float));
		return (float*)buf;
	}
	
	ExecuteTag((U32*)&value, pcmnd,0,u8State);
	memcpy(buf, &value, sizeof(float));
	return (float*)buf;
}
void CMonitorControl::UpdateFrameRateTextL( TReal32 aFrameRate )
    {
    CHuiTextVisual* textVisual = static_cast<CHuiTextVisual*>(FindTag( KFrameRateTag ) );
        
    TBuf<32> buffer;
    buffer.AppendNum(aFrameRate,  TRealFormat( 4, 1 ) );
    buffer.Append( _L(" fps") );
    textVisual->SetTextL( buffer );
    
    // make sure we are on top
    if ( Env().DisplayCount() )
        {
        CHuiDisplay& display = Env().PrimaryDisplay();
        display.Roster().ShowL( *ControlGroup() );
        }
    }
Exemple #22
0
void Level::OnLoaded() {
	Parent::OnLoaded();

	const tbc::ChunkyClass::Tag* tag = FindTag("mass_objects", -1, -1);
	if (tag) {
		deb_assert(tag->string_value_list_.size() == tag->float_value_list_.size());
		deb_assert(tag->string_value_list_.size() == tag->body_index_list_.size());
		const size_t count = tag->body_index_list_.size();
		for (size_t x = 0; x < count; ++x) {
			MassObjectInfo info;
			info.class_id_ = tag->string_value_list_[x];
			info.ground_body_index_ = tag->body_index_list_[x];
			info.count_ = (int)tag->float_value_list_[x];
			mass_objects_.push_back(info);
		}
	}
}
Exemple #23
0
bool CMarkdown::Pull()
{
	if (lower < ahead && (*lower != '<' || ++lower < ahead))
	{
		if (first[1] == '!')
		{
			if (first[2] != '[' && first[2] != '-')
			{
				// neither CDATA nor comment: assume DTD tag
				unsigned quoting = 0;
				while (lower < ahead && (quoting || *lower != '[' && *lower != '>'))
				{
					switch (*lower)
					{
					case '"':
						if (!(quoting & 1))
							quoting ^= 2;
						break;
					case '\'': 
						if (!(quoting & 2))
							quoting ^= 1;
						break;
					}
					++lower;
				}
				if (*lower == '[')
				{
					upper = lower;
					return true;
				}
			}
			return false;
		}
		while (lower < ahead && *lower != '>')
		{
			++lower;
		}
		if (lower[-1] != '/' && lower[-1] != '?' && !(utags && FindTag(utags, first + 1)))
		{
			upper = lower;
			return true;
		}
	}
	return false;
}
Exemple #24
0
size_w SetTypeGV(HWND hwndGridView, HGRIDITEM hItem, TypeDecl *typeDecl, size_w dwOffset)
{
	if(typeDecl->typeAlias == true)
		return dwOffset;

	if(typeDecl->declList.size() > 0)
	{
		Type *type = typeDecl->declList[0];
		ExprNode *offsetExpr;

		if(FindTag(typeDecl->tagList, TOK_OFFSET, &offsetExpr))
			dwOffset = Evaluate(offsetExpr);
			
		dwOffset += RecurseType(hwndGridView, hItem, type, dwOffset, typeDecl);
	}
	
	return dwOffset;
}
TBool CMonitorControl::OfferEventL(const THuiEvent& aEvent)
    {
    TBool handled = EFalse;
    if (aEvent.IsCustomEvent() && aEvent.iParam == EUpdateFrameRate )
        {
        UpdateFrameRateTextL( CHuiStatic::FrameRate() );
        
        THuiCustomEventCommand command( EUpdateFrameRate, static_cast<MHuiEventHandler*>(this) );
        Env().Send( command, iServerSession.iFpsUpdatePeriod );        
        
        handled = ETrue;
        }
    else if ( aEvent.IsCustomEvent() && aEvent.iParam == EUpdateServerHeap )
        {
        CHuiTextVisual* textVisual = static_cast<CHuiTextVisual*>(FindTag( KHeapTag ) );
        
        User::Heap().Compress();
        
        TInt totalSize = 0;
        TInt usedSize = User::AllocSize( totalSize );
        TBuf<32> buffer;
        buffer.AppendNum( usedSize );
        buffer.Append( _L(" cells\n") );
        buffer.AppendNum( totalSize );
        buffer.Append( _L("B") );

        textVisual->SetTextL( buffer );
        
        THuiCustomEventCommand command( EUpdateServerHeap, static_cast<MHuiEventHandler*>(this) );
        Env().Send( command, iServerSession.iServerHeapUpdatePeriod );
        
        // make sure we are on top
        if ( Env().DisplayCount() )
            {
            CHuiDisplay& display = Env().PrimaryDisplay();
            display.Roster().ShowL( *ControlGroup() );
            }
            
        handled = ETrue;
        }
        
    return handled;
    }
VOID dobranch_Correlation(ADDRINT des, ADDRINT ins, BOOL judge) { 

        //Achar Indices
        int indice7  = TestarMask(Bits, 127);
        int indice8  = TestarMask(Bits, 255);
        int indice9  = TestarMask(Bits, 511);
        int indice10 = TestarMask(Bits, 1023);
        int indice11 = TestarMask(Bits, 2047);
        int indice12 = TestarMask(Bits, 4095);
        int indice13 = TestarMask(Bits, 8191);
        int indice14 = TestarMask(Bits, 16383);

        UINT64 i, tag;
        i = TestarMask(ins, 4095);
        tag = FindTag(ins, 12);


        //7 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_7bits, Erros_correlation_7bits, correlation_btb_7bit, indice7, correlation_7bits);   
        //8 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_8bits, Erros_correlation_8bits, correlation_btb_8bit, indice8, correlation_8bits);
        //9 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_9bits, Erros_correlation_9bits, correlation_btb_9bit, indice9, correlation_9bits);
        //10 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_10bits, Erros_correlation_10bits, correlation_btb_10bit, indice10, correlation_10bits);
        //11 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_11bits, Erros_correlation_11bits, correlation_btb_11bit, indice11, correlation_11bits);
        //12 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_12bits, Erros_correlation_12bits, correlation_btb_12bit, indice12, correlation_12bits);
        //13 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_13bits, Erros_correlation_13bits, correlation_btb_13bit, indice13, correlation_13bits);
        //14 bits
        Analisar(des, ins, judge, i, tag, Acertos_correlation_14bits, Erros_correlation_14bits, correlation_btb_14bit, indice14, correlation_14bits);


        //Feito no final o deslocamento.
        Bits = MoveBit(Bits, judge);

        if(judge) takenBranch++;
        else nTakenBranch++;
}
Exemple #27
0
CMarkdown &CMarkdown::Move()
{
	Scan();
	for (;;)
	{
		while (*this && *upper != '<')
		{
			++upper;
		}
		if (utags && upper < ahead && *upper == '<')
		{
			if (int utlen = FindTag(utags, upper + 2))
			{
				upper += 2 + utlen;
				continue;
			}
		}
		break;
	}
	first = lower = upper;
	return *this;
}
Exemple #28
0
/*
 * TagHunt - hunt for a specified tag
 */
vi_rc TagHunt( char *str )
{
    char        buff[MAX_STR], file[FILENAME_MAX];
    int         num;
    vi_rc       rc;

    rc = LocateTag( str, file, buff );
    if( rc == ERR_NO_ERR ) {

        PushFileStack();
        rc = EditFile( file, FALSE );
        if( rc == ERR_NO_ERR ) {
            if( buff[0] != '/' ) {
                num = atoi( buff );
                rc = GoToLineNoRelCurs( num );
            } else {
                rc = FindTag( buff );
                if( rc < ERR_NO_ERR ) {
                    strcpy( buff, str );
                    ColorFind( buff, 0 );
                    rc = ERR_TAG_NOT_FOUND;
                }
            }
        } else {
            PopFileStack();
        }

    }

    if( rc == ERR_TAG_NOT_FOUND ) {
        Error( GetErrorMsg( rc ), str );
        rc = DO_NOT_CLEAR_MESSAGE_WINDOW;
    }
    return( rc );

} /* TagHunt */
Exemple #29
0
// Save the ifd out to an open file. Return this ifdlocation
unsigned int TiffIfd::Write(FILE *pFile,
			    unsigned int nextifdoffset,
			    int subfileoffset) const
{
  // Values that need to be filled in later.
  // Record where in the file and then what value will be put there.
  std::vector<unsigned int> pending_pointers_where;
  std::vector<unsigned int> pending_pointers_what;

  int iRV = fseek(pFile, 0, SEEK_END);
  if (iRV != 0 )
    fprintf(stderr, "Failed to fseek in TiffIfd::Write\n");

  // Write the ifd block out.
  const unsigned int ifdstart = ftell(pFile);
  // Write out the IFD with dummies for pointers.
  short nr = tags_.size();
  iRV = fwrite(&nr, sizeof(short), 1, pFile);
  int whereisdata = -1;
  for(int tagindex=0 ; tagindex < tags_.size(); ++tagindex) {
    unsigned int pointer = tags_[tagindex]->Write(pFile);   // 0 if no pointer.
    if (pointer) {
      if (tags_[tagindex]->GetTag() == TiffTag::tag_stripoffset ||
	  tags_[tagindex]->GetTag() == TiffTag::tag_thumbnailoffset)
        whereisdata = pending_pointers_where.size();  // Which entry corresponds to the strips/thumbnail
      pending_pointers_where.push_back(pointer); // "Where":  Where we stored the pointer
    }
  }
  iRV = fwrite(&nextifdoffset, sizeof(unsigned int), 1, pFile);

  unsigned int datastart = 0;
  // Write the image or thumbnail data.
  if (data_) {
    TiffTag *tagdatabytes = FindTag(TiffTag::tag_stripbytes);
    if (tagdatabytes == NULL)
      tagdatabytes = FindTag(TiffTag::tag_thumbnaillength);
    datastart = ftell(pFile);
    iRV = fwrite(data_, sizeof(unsigned char), tagdatabytes->GetUIntValue(0),
		 pFile);
  }

  // Write all the subsidiary data.
  for(int tagindex=0 ; tagindex < tags_.size(); ++tagindex) {
    if (datastart && pending_pointers_what.size() == whereisdata)
      pending_pointers_what.push_back(datastart);  // "Where" we wrote the datablock.
    unsigned int pointer = tags_[tagindex]->WriteDataBlock(pFile, subfileoffset);
    if (pointer) pending_pointers_what.push_back(pointer);  // "What": where we wrote the datablock.
  }
  if (datastart && pending_pointers_what.size() == whereisdata)
    pending_pointers_what.push_back(datastart);  // "Where" we wrote the datablock.

  // If we're keeping track of pending pointers, fill them in now.
  if (pending_pointers_where.size() != pending_pointers_what.size())
    throw("pending pointers don't match");
  for(int i = 0; i < pending_pointers_what.size(); ++i) {
    printf("Write TiffIfd Locs Where: %d What: %d-%d\n",
	   pending_pointers_where[i], pending_pointers_what[i], subfileoffset);
    fseek(pFile, pending_pointers_where[i], SEEK_SET); // Where
    const unsigned int ifdloc = pending_pointers_what[i]-subfileoffset;  // What
    iRV = fwrite(&ifdloc, sizeof(unsigned int), 1, pFile);
  }
  iRV = fseek(pFile, 0, SEEK_END);
  // Return the location of this ifdstart (from which we can calculate
  // where we have to write the nextifdoffset if we hadn't precalculated it)
  return ifdstart;
}
Exemple #30
0
void Traite(CLIENT *client)
{
	char PlcName[30];
	char TagName[50];
	char writevalue[20];
	char requete[MAXBUFFERSIZE];
	memset(PlcName,0,sizeof(PlcName));
	memset(TagName,0,sizeof(TagName));
	memset(writevalue,0,sizeof(writevalue));
	memset(requete,0,sizeof(requete));	
	memcpy(requete,client->InBuffer.data,client->InBuffer.size);
	Log(LOG_DEBUG,"Entering Traite for %p (%s)[%i]\n",client,requete,client->InBuffer.size);
	if (ParseRequest(PlcName,TagName,writevalue,requete)== SUCCESS)
	{
		Log(LOG_DEBUG,"Traite for %s@%s=%s \n", TagName, PlcName, writevalue);
		if(strncasecmp(PlcName,"@",1)==0)
		{
			Affiche(client->FD,TagName);
			client->InBuffer.size=0;
			return;
		}
		PLC *plc=FindPLC(PlcName,&PLCs);
		if (plc!=NULL)
		{
			TAG *tag=FindTag(TagName,PlcName,&TAGs);
			if (tag!=NULL)
			{ /* Tag exist */
				Log(LOG_DEBUG,"\t=Tag %s already exist (%p)\n",TagName,tag);
			} else
			{
				tag=malloc(sizeof(TAG));
				if (tag!=NULL)
				{
					Log(LOG_DEBUG,"\t+Creating Tag %s (%p) on %s\n",TagName,tag,plc->PlcName);
					memset(tag,0,sizeof(TAG));
					strncpy(tag->TagName,TagName,strlen(TagName));
					tag->Plc=plc;
					plc->References++;
					AddChListe(&TAGs,tag);
				} else 
				{
					Log(LOG_CRIT, "Erreur à l'ajout du tag (%s)\n",strerror(errno));
					return;
				}
			}
			if ((time(NULL)-tag->Time_Value)<UPDATE_RATE)
			{
				Log(LOG_DEBUG,"\t=Reading buffered value for Tag %s\n",TagName);
				Reply(client->FD,"[%s]%s=%f\n",plc->PlcName,TagName,tag->Value);
			} else 
			{
				if (ReadTag(tag)>0) Reply(client->FD,"[%s]%s=%f\n",plc->PlcName,TagName,tag->Value);
					else Reply(client->FD,"[%s]%s=Erreur\n",plc->PlcName,TagName);
			}
			//Reply(client->FD,"TuxReader : %s (Path : %s) Tag : %s\n",plc->PlcName,plc->PlcPath,TagName);
		} else
		{
			Reply(client->FD,"[%s]%s=PLC not found in Config file\n",plc->PlcName,TagName);
			/* Test Gardian
			int *a=(int*)(NULL);
			*a=10;*/
		}
	} else
	{
		Reply(client->FD,"%s=Request error\n",client->InBuffer.data);
	}
	client->InBuffer.size=0;
}