Exemplo n.º 1
0
void vtkDCMParser::ReadElement(DCMDataElementStruct *des)
{
  if(this->file_in)
    {
      PrevFilePos = ftell(file_in);
      PrevFileIOMessage = FileIOMessage;

      switch(TransferSyntax)
      {
      case TFS_IVRLE:
      case TFS_IVRBE:
        
        des->GroupCode = ReadUINT16();
        des->ElementCode = ReadUINT16();
        des->Length = ReadUINT32();

        des->NextBlock = ftell(file_in);
        if(des->Length != 0xffffffff)
          des->NextBlock += des->Length;

        sprintf(des->VR, "??");
        
        break;
        
      case TFS_EVRLE:
      case TFS_EVRBE:
        
        des->GroupCode = ReadUINT16();
        des->ElementCode = ReadUINT16();
        
        if((des->GroupCode) == 0xfffe)
          {
            if((des->ElementCode == 0xe000) ||
             (des->ElementCode == 0xe00d) ||
             (des->ElementCode == 0xe0dd))
            { // must be implicit VR always
              des->Length = ReadUINT32();

              des->NextBlock = ftell(file_in);
              if(des->Length != 0xffffffff)
                des->NextBlock += des->Length;

              sprintf(des->VR, "??");

              return;
            }
          }
        
        ReadText(des->VR, 2); // getting VR
        
        if((strcmp(des->VR, "OB") == 0) ||
           (strcmp(des->VR, "OW") == 0) ||
           (strcmp(des->VR, "SQ") == 0) ||
           (strcmp(des->VR, "UN") == 0) ||
           (strcmp(des->VR, "UT") == 0)
           )
          {
            des->Length = ReadUINT16(); // reserved field
            des->Length = ReadUINT32();
            des->NextBlock = ftell(file_in);
            if(des->Length != 0xffffffff)
              des->NextBlock += des->Length;
          } else
          {
            des->Length = ReadUINT16();
            des->NextBlock = ftell(file_in);
            if(des->Length != 0xffffffff)
              des->NextBlock += des->Length;
          }
        
        break;
      }
    }
}
Exemplo n.º 2
0
void vtkDCMParser::ReadDICOMMetaHeaderInfo()
{
  long file_pos;
  //UINT16 GroupCode;
  //UINT16 ElementCode;
  //UINT32 Length;
  //char vr[4];
  int tfs;

  short check;
  unsigned char *ptr;

  int implicit = -1; // sp 2002-08-08 
                     // implicit headers are rare, but occur
                     // -1 means don't know yet
                     // 0 means 2 char VR (value rep) code exists
                     // 1 means gotta guess the VR from context (dictionary)

  DCMDataElementStruct des;

  if(this->file_in == NULL)
    return;

  check = 1;
  ptr = (unsigned char *)✓
  MachineLittleEndian = (ptr[0] == 0x01);
  tfs = TFS_IVRLE;
  TransferSyntax = TFS_EVRLE;  // explicit to start with

  PrevFileIOMessage = FileIOMessage = 0;

  PrevFilePos = file_pos = ftell(file_in);

  fread(buff, 132, 1, file_in);
  if((buff[128] == 'D') && (buff[129] == 'I')
     && (buff[130] == 'C') && (buff[131] == 'M'))
  {  
    do
    {
      //file_pos = ftell(file_in);
      ReadElement(&des);

      // check to see if this is implicit header - done first time through
      if (implicit == -1)
        { 
        if ( (des.GroupCode != 0x0002) || (des.ElementCode != 0x0) )
          {
          // bad case - metaheader should start with length
          // guess that it's implicit
          implicit = 0;
          TransferSyntax = TFS_EVRLE; // class flag used in reading
          }
        else
          {
          if (strcmp(des.VR, "UL") == 0) // it has a VR field
            {
            implicit = 0;
            TransferSyntax = TFS_EVRLE; // class flag used in reading
            }
          else
            {
            implicit = 1;
            UnreadLastElement();
            TransferSyntax = TFS_IVRLE; // class flag used in reading
            ReadElement(&des); // re-read without the 2 VR bytes
            }
          }
        }


      if(des.GroupCode != 0x0002)
        {
          UnreadLastElement();
          HeaderStartPos = ftell(file_in);
          break;
        }

      switch(des.ElementCode)
        {
        case 0x0002:
          ReadText(buff, des.Length);
          //printf("Media Storage SOP Class UID (%04x,%04x):\n\t%s\n",
          //     GroupCode, ElementCode, buff);
          stringncopy(MediaStorageSOPClassUID, buff, 64);

          break;

        case 0x0003:
          ReadText(buff, des.Length);
          //printf("Media Storage SOP Instance UID (%04x,%04x):\n\t%s\n",
          //     GroupCode, ElementCode, buff);          
          stringncopy(MediaStorageSOPInstanceUID, buff, 64);

          break;

        case 0x0010:
          ReadText(buff, des.Length);
          //printf("Transfer Syntax UID (%04x,%04x):\n\t%s\n",
          //     GroupCode, ElementCode, buff);
          stringncopy(TransferSyntaxUID, buff, 64);

          if(strcmp(buff, "1.2.840.10008.1.2") == 0)
          {
            //printf("\tImplicit VR Little Endian\n");
            tfs = TFS_IVRLE; 
          }
          else
          if(strcmp(buff, "1.2.840.10008.1.2.1") == 0)
          {
            //printf("\tExplicit VR Little Endian\n");
            tfs = TFS_EVRLE;
          }
          else
          if(strcmp(buff, "1.2.840.10008.1.2.2") == 0)
          {
            //printf("\tExplicit VR Big Endian\n");
            tfs = TFS_EVRBE;
          }
          else
          if(strcmp(buff, "1.2.840.113619.5.2") == 0)
          {
            //printf("\tImplicit VR Big Endian\n");
            
            //
            // claims to be BE but header info is LE
            // and data is BE
            //
            tfs = TFS_IVRBE;  
          }
          else
          {
            //printf("\tNot found: assuming explicit VR Little Endian\n");
            tfs = TFS_EVRLE;
          }

          break;

        case 0x0012:
          ReadText(buff, des.Length);
          //printf("Implementation Class UID (%04x,%04x):\n\t%s\n",
          //     GroupCode, ElementCode, buff);
          stringncopy(ImplementationClassUID, buff, 64);
          
          break;
          
        default:
          //printf("skipping (%04x,%04x) %s (%lu bytes)\n",
          //     GroupCode, ElementCode, vr, Length);
          Skip(des.Length);
        }
    }
    while(1);
  } else
  {
    tfs = TFS_IVRLE; // not necessary to set here
    //printf("No MetaHeader Info!\n");
    //printf("Assuming Implicit VR Little Endian Transfer Syntax.\n");
    HeaderStartPos = file_pos;
    fseek(file_in, file_pos, SEEK_SET);
  }

  TransferSyntax = tfs;

  // note special handling of GE broken Implicit BE
  if( (MachineLittleEndian && ((tfs == TFS_EVRBE))) ||
     ( !MachineLittleEndian && 
        ((tfs == TFS_EVRLE) || (tfs == TFS_IVRLE) || (tfs == TFS_IVRBE)) ))
    MustSwap = 1;
  else
    MustSwap = 0;
}
				void PowerPointSlidePersistTextBytesState::Handle(PptReaderImpl* pPowerPointImpl, EshObject& eshObject) const
				{
					if (pPowerPointImpl->GetReader()->IsFlagCleanHiddenSlides())
					{
						HandleClean(pPowerPointImpl, eshObject);
						return;
					}
					try
					{
						EshAtom* pAtom = ChDOWNCAST<EshObject, EshAtom>(&eshObject);
						if(0 == pAtom)
							throw std::logic_error("Invalid PowerPoint Binary Document EshAtom, the object does not contain a valid EshAtom object");

						pPowerPointImpl->GetReader()->read(*pAtom);

						std::wcstring text = ReadText(pAtom);
						if (!text.empty())
						{
							SlideInfo* pSlideInfo = pPowerPointImpl->GetSlideByReferenceId(pPowerPointImpl->GetCurrentSlideReference());
							if(0 == pSlideInfo)
								pSlideInfo = pPowerPointImpl->AddSlide(pPowerPointImpl->GetCurrentSlideReference(), text);

							pSlideInfo->SetCurrentTextNumber(pSlideInfo->GetCurrentTextNumber() + 1);
							DocumentText::ptr_type docText = pPowerPointImpl->GetVisitor();
							
							//pPowerPointImpl->GetReader()->read(*pTextHeaderAtom);
							if (pPowerPointImpl->GetCurrentTextIsTitle())
							{
								pSlideInfo->SetTitle(text);
														
							}

							std::wcstring prefix = _LL("TEXTBOX");
							prefix += ReaderHelpers::MakeNumberString((pSlideInfo->GetCurrentTextNumber()));
							AbstractTextNode::id_type id = ReaderHelpers::CreateIdForPowerPointNode(prefix, pSlideInfo->GetSlideNumber());
							AbstractTextNode::ptr_type textNode = docText->GetTextNode(id);
							if(textNode == 0)
							{
								textNode = new TextNode(id);
							}
							textNode->AddAdditionalInfo(docText, _LL("SlideId"), ReaderHelpers::MakeNumberString((pSlideInfo->GetSlideNumber())), AbstractTextNode::Long);
							textNode->AddAdditionalInfo(docText, _LL("Title"), pSlideInfo->GetTitle(), AbstractTextNode::String);
							textNode->AddAdditionalInfo(docText, _LL("Content"), text, AbstractTextNode::String);
							docText->AddTextNode(AbstractTextType::TextBox, textNode);

							pSlideInfo->AddContent(text);
							ChWriter* pInfo = pAtom->DetachOverwriteInfo();
							if (pInfo)
								pSlideInfo->AddOverwriteInfo(pInfo);
						}

						if(PptTextHeaderAtom::ID == eshObject.getType())
						{
							pPowerPointImpl->ChangeState<PowerPointSlidePersistTextHeaderState>();
							pPowerPointImpl->GetCurrentState()->Handle(pPowerPointImpl, eshObject);
							return;
						}

						if(PptSlidePersistAtom::ID == eshObject.getType())
						{
							pPowerPointImpl->ChangeState<PowerPointSlidePersistState>();
							// Handle the current state to retrieve the slide reference id.
							pPowerPointImpl->GetCurrentState()->Handle(pPowerPointImpl, eshObject);
						}

						pPowerPointImpl->ChangeState<PowerPointAtomState>();
					}
					catch (CsException& ex)
					{
						throw std::logic_error(ReaderHelpers::ConstructErrorText(ex));
					}
				}
Exemplo n.º 4
0
int KTgaBlockLoader::LoadUITex(LPCTSTR pcszUITex, int nLoadStyle, 
							   int nReadKind, int nFindKind, int TgaInd, 
                               int nFrameNum, HWND hWnd)
{
	int nResult = false;
	int nRetCode = false; 

	size_t uReadIn;
	FILE *fpUiTex = NULL;
	UITEXFILEHEADER UiTexFileHeader;

	LPTSTR pszClip = NULL;
	LPTSTR pszTemp = NULL;
	LPTSTR pszText = NULL;

	TCHAR szTgaName[MAX_PATH];
	TCHAR szSTexName[MAX_PATH];
	TCHAR szTextName[MAX_PATH];

	szTgaName[0] = _T('\0');
	szSTexName[0] = _T('\0');
	szTextName[0] = _T('\0');

	KG_PROCESS_ERROR(pcszUITex);

	fpUiTex = fopen(pcszUITex, "rb");
	KG_PROCESS_ERROR(fpUiTex);

	uReadIn = fread(&UiTexFileHeader, sizeof(UiTexFileHeader), 1, fpUiTex);
	KG_PROCESS_ERROR(uReadIn == 1);
	fclose(fpUiTex);
	fpUiTex = NULL;
	_tcsncpy(szTgaName, pcszUITex, sizeof(szTgaName) / sizeof(TCHAR));
	szTgaName[sizeof(szTgaName) / sizeof(TCHAR) - 1] = _T('\0');
	pszClip = _tcsrchr(szTgaName, '\\');
	if (pszClip)
		++pszClip;
	else
		pszClip = szTgaName;
	pszTemp = _tcsrchr(pszClip, '/');
	if (pszTemp)
		pszClip = pszTemp + 1;
	_tcsncpy(pszClip, UiTexFileHeader.szTgaFileName, sizeof(szTgaName) / sizeof(TCHAR)- (pszClip - szTgaName));
	szTgaName[sizeof(szTgaName) / sizeof(TCHAR) - 1] = _T('\0');

	_tcsncpy(szTextName,pcszUITex,sizeof(szTextName)/sizeof(TCHAR));
	pszText = _tcsrchr(szTextName, _T('.'));
	*pszText = _T('\0');
	_tcsncat(pszText, ".txt", sizeof(pszText) / sizeof(TCHAR));

	if (nLoadStyle == LOAD_AS_REPLACE)
	{
		nRetCode = KSaveManager::GetSelf().SetCurrentEditFile(pcszUITex, szTgaName, szSTexName, szTextName);
		KG_PROCESS_ERROR(nRetCode);        
	}

	nRetCode = SetUITexName(pcszUITex);
	KG_PROCESS_ERROR(nRetCode);
	nRetCode = SetTgaName(szTgaName);
	KG_PROCESS_ERROR(nRetCode);
	nRetCode = SetSTexName(szSTexName);
	KG_PROCESS_ERROR(nRetCode);
	nRetCode = SetTextName(szTextName);
	KG_PROCESS_ERROR(nRetCode);

//	if (nReadKind)
//	{
		nRetCode = ReadText(szTextName, nLoadStyle);
		KG_PROCESS_ERROR(nRetCode);
//	}
	nRetCode = ReadUITex(pcszUITex, nLoadStyle, nFindKind, TgaInd, nFrameNum);
	KG_PROCESS_ERROR(nRetCode);

	nResult = true;
Exit0:
	if (fpUiTex)
	{
		fclose(fpUiTex);
		fpUiTex = NULL;
	}
	return nResult;
}
Exemplo n.º 5
0
BOOL C4Playback::Open(C4Group &rGrp) {
  // clean up
  Clear();
  fLoadSequential = false;
  iLastSequentialFrame = 0;
  bool fStrip = false;
  // get text record file
  StdStrBuf TextBuf;
  if (rGrp.LoadEntryString(C4CFN_CtrlRecText, TextBuf)) {
    if (!ReadText(TextBuf)) return FALSE;
  } else {
    // open group? Then do some sequential reading for large files
    // Can't do this when a dump is forced, because the dump needs all data
    // Also can't do this when stripping is desired
    if (!rGrp.IsPacked())
      if (!Game.RecordDumpFile.getLength())
        if (!fStrip) fLoadSequential = true;
    // get record file
    if (fLoadSequential) {
      if (!rGrp.FindEntry(C4CFN_CtrlRec)) return FALSE;
      if (!playbackFile.Open(
              FormatString("%s%c%s", rGrp.GetFullName().getData(),
                           (char)DirectorySeparator,
                           (const char *)C4CFN_CtrlRec).getData()))
        return FALSE;
      // forcing first chunk to be read; will call ReadBinary
      currChunk = chunks.end();
      if (!NextSequentialChunk()) {
        // empty replay??!
        LogFatal("Record: Binary read error.");
        return FALSE;
      }
    } else {
      // non-sequential reading: Just read as a whole
      StdBuf BinaryBuf;
      if (rGrp.LoadEntry(C4CFN_CtrlRec, BinaryBuf)) {
        if (!ReadBinary(BinaryBuf)) return FALSE;
      } else {
        // file too large? Try sequential loading and parsing
        /*				size_t iSize;
                                        if (rGrp.AccessEntry(C4CFN_CtrlRec,
           &iSize))
                                                {
                                                CStdFile fOut;
           fOut.Create(Game.RecordDumpFile.getData());
                                                fLoadSequential = true;
                                                const size_t iChunkSize =
           1024*1024*16; // 16M
                                                while (iSize)
                                                        {
                                                        size_t iLoadSize =
           Min<size_t>(iChunkSize, iSize);
                                                        BinaryBuf.SetSize(iLoadSize);
                                                        if
           (!rGrp.Read(BinaryBuf.getMData(), iLoadSize))
                                                                {
                                                                LogFatal("Record:
           Binary load error!");
                                                                return FALSE;
                                                                }
                                                        iSize -= iLoadSize;
                                                        if
           (!ReadBinary(BinaryBuf)) return FALSE;
                                                        LogF("%d binary
           remaining", iSize);
                                                        currChunk =
           chunks.begin();
                                                        if (fStrip) Strip();
                                                        StdStrBuf
           s(ReWriteText());
                                                        fOut.WriteString(s.getData());
                                                        LogF("Wrote %d text
           bytes (%d binary remaining)", s.getLength(), iSize);
                                                        chunks.clear();
                                                        }
                                                fOut.Close();
                                                fLoadSequential = false;
                                                }
                                        else*/
        {
          // no control data?
          LogFatal("Record: No control data found!");
          return FALSE;
        }
      }
    }
  }
  // rewrite record
  if (fStrip) Strip();
  if (Game.RecordDumpFile.getLength()) {
    if (SEqualNoCase(GetExtension(Game.RecordDumpFile.getData()), "txt"))
      ReWriteText().SaveToFile(Game.RecordDumpFile.getData());
    else
      ReWriteBinary().SaveToFile(Game.RecordDumpFile.getData());
  }
  // reset status
  currChunk = chunks.begin();
  Finished = false;
// external debugrec file
#if defined(DEBUGREC_EXTFILE) && defined(DEBUGREC)
#ifdef DEBUGREC_EXTFILE_WRITE
  if (!DbgRecFile.Create(DEBUGREC_EXTFILE)) {
    LogFatal("DbgRec: Creation of external file \"" DEBUGREC_EXTFILE
             "\" failed!");
    return FALSE;
  } else
    Log("DbgRec: Writing to \"" DEBUGREC_EXTFILE "\"...");
#else
  if (!DbgRecFile.Open(DEBUGREC_EXTFILE)) {
    LogFatal("DbgRec: Opening of external file \"" DEBUGREC_EXTFILE
             "\" failed!");
    return FALSE;
  } else
    Log("DbgRec: Checking against \"" DEBUGREC_EXTFILE "\"...");
#endif
#endif
  // ok
  return TRUE;
}
Exemplo n.º 6
0
static unsigned _stdcall RequestProc( void *arg )
{
	int *pBuffer;
	DWORD dwRet;
	HANDLE heventWait[2];
	int iBeginLine, iEndLine;

	heventWait[0] = heventParentSend;
	heventWait[1] = heventDone;

	for(;; )
	{
		dwRet = WaitForMultipleObjects( 2, heventWait, FALSE, INFINITE );

		// heventDone fired, so we're exiting.
		if( dwRet == WAIT_OBJECT_0 + 1 )
			break;

		pBuffer = (int *) GetMappedBuffer( hfileBuffer );

		// hfileBuffer is invalid.  Just leave.
		if( !pBuffer )
		{
			printf( "Invalid hfileBuffer\n" );
			break;
		}

		switch( pBuffer[0] )
		{
		case CCOM_WRITE_TEXT:
			// Param1 : Text
			pBuffer[0] = WriteText( (LPCTSTR) ( pBuffer + 1 ) );
			break;

		case CCOM_GET_TEXT:
			// Param1 : Begin line
			// Param2 : End line
			iBeginLine = pBuffer[1];
			iEndLine = pBuffer[2];
			pBuffer[0] = ReadText( (LPTSTR) ( pBuffer + 1 ), iBeginLine,
			                      iEndLine );
			break;

		case CCOM_GET_SCR_LINES:
			// No params
			pBuffer[0] = GetScreenBufferLines( &pBuffer[1] );
			break;

		case CCOM_SET_SCR_LINES:
			// Param1 : Number of lines
			pBuffer[0] = SetScreenBufferLines( pBuffer[1] );
			break;
		}

		ReleaseMappedBuffer( pBuffer );
		SetEvent( heventChildSend );
	}

	_endthreadex( 0 );
	arg = NULL; // wsw : aiwa : shut up compiler
	return 0;
}
Exemplo n.º 7
0
float XmlParser::ReadFloat(char* nodePath)
{
	char output[256];
	ReadText(nodePath, output, sizeof(output));
	return static_cast<float>(atof(output));
}
Exemplo n.º 8
0
ByteBufferPtr File::ReadText()
{
	uint32_t length = GetLength();
	return ReadText(length);
}
Exemplo n.º 9
0
void appCopyPaste::PastePages()
{
    bool fileReadOK = false;
    MenuPageArray pagesRead(16);
    int nObjects;
    try
        {
            appConfigFile::OpenAsClipboard(true);

            //  header
            ReadPageHeader();

            int nPages   = ReadInt();
            int ntotalPages = ReadInt();
            nObjects = ReadInt();

            if (nPages == 0)
                InputError("No pages ??");

            // check that all page types are supported
            char tempStr[160];
            for (int i = 0; i < ntotalPages; i++)
                {
                    ReadText(tempStr, 160);
                    if (!AllocPageC::MenuPageExists(tempStr))
                        InputError("Page type not supported by application");
                }

            // and all object types
            for (int i = 0; i < nObjects; i++)
                {
                    ReadText(tempStr, 160);
                    if (!AllocObjC::MenuObjectExists(tempStr))
                        InputError("Object type not supported by application");
                }

            AppMenuC::GetApp().PrePasteSetup();

            // read app globals
            ReadAppGlobals();

            // read pages
            pagesRead.Alloc(nPages);

            for (int i = 0; i < nPages; i++)
                {
                    ReadText(tempStr, 160);

                    //  convert to page type
                    if (!AllocPageC::MenuPageExists(tempStr))
                        InputError("Page type conversion error ??");

                    //  create new page
                    MenuPageC* newPage = AllocPageC::CreateMenuPage(tempStr);

                    bool childOK = (MenuPageC::currPageObj == 0) ||
                        MenuPageC::currPageObj->AcceptAsChild(*newPage);

                    // test to see if it can be added as child of current page
                    if (childOK && newPage->AcceptAsParent(MenuPageC::currPageObj))
                        {
                            // parent OK -- finish up
                            newPage->ParentChanging(MenuPageC::currPageObj);
                            if (MenuPageC::currPageObj != 0)
                                {
                                    MenuPageC::currPageObj->childPages += newPage;
                                    MenuPageC::currPageObj->ResetChildren();
                                }
                        }
                    else if (!newPage->AcceptAsParent(NULL))
                        {
                            delete newPage;
                            InputError("Page type cannot be pasted");
                        }

                    // add it to list
                    pagesRead.AddTo(newPage);

                    // read it
                    newPage->ReadFromFile();
                }

            AppMenuC::GetApp().PostPasteFixup();

            fileReadOK = true;
        }
    catch (TextC::TextError re) {
        GenAppErrorMsg("PastePages", re.errMsg);
    }

    appConfigFile::Close();

    if (!pagesRead.IsEmpty())
        {
            UpdateAppObjects();

            // update all pointers
            for (int i = 0; i < pagesRead.Size(); i++)
                UpdatePagePointers(pagesRead.GetRef(i));

            // set all FO status && update ui
            for (int i = 0; i < pagesRead.Size(); i++)
                UpdatePageStatus(pagesRead.GetRef(i));

            if (fileReadOK)
                {
                    GenAppClearMsgs();

                    FuncObjArray objsToCalc(nObjects);
                    objsToCalc.SetEmpty();
                    for (int i = 0; i < pagesRead.Size(); i++)
                        GetCalcObjects(pagesRead.GetRef(i), objsToCalc);

                    FuncObjC::CalcSelectedObjects(foc_Full, objsToCalc);
                    PlotDefC::ReplotAfterCalc();
                    ExposedObjC::UpdateAllExposed();
                }

        }

    DeallocFuncObjList();
}
Exemplo n.º 10
0
void appCopyPaste::PasteObjects()
{
    bool fileReadOK = false;
    MenuObjArray objectsRead;
    try
        {
            appConfigFile::OpenAsClipboard(true);

            //  header
            ReadObjHeader();

            int nObjects = ReadInt();
            if (nObjects == 0)
                InputError("No objects ??");

            // check that page type is supported
            char pageStr[160];
            ReadText(pageStr, 160);
            if (!AllocPageC::MenuPageExists(pageStr))
                InputError("Page type not supported by application");

            // and all object types
            for (int i = 0; i < nObjects; i++)
                {
                    char objStr[160];
                    ReadText(objStr, 160);
                    if (!AllocObjC::MenuObjectExists(objStr))
                        InputError("Object type not supported by application");
                    if (!MenuPageC::currPageObj->ObjectOKForPage(objStr))
                        InputError("Object not supported on current page");
                }

            // read app globals
            ReadAppGlobals();
            AppMenuC::GetApp().PrePasteSetup();


            //  read objects
            objectsRead.Alloc(nObjects);
            for (int i = 0; i < nObjects; i++)
                {
                    char objStr[160];
                    ReadText(objStr, 160);
                    MenuObjC* currObj = AllocObjC::CreateMenuObject(objStr, MenuPageC::currPageObj->GetActualParent());
                    currObj->ReadFromFile();

                    objectsRead += currObj;
                    MenuPageC::currPageObj->AddObject(currObj);
                    MenuRootC::currTreeObj->AddObjectLeafToRoot(MenuPageC::currPageObj, currObj);
                }

            AppMenuC::GetApp().PrePasteSetup();

            fileReadOK = true;
        }
    catch (TextC::TextError re) {
        GenAppErrorMsg("PasteObjects", re.errMsg);
    }

    appConfigFile::Close();

    if (!objectsRead.IsEmpty())
        {

            UpdateAppObjects();


            MenuObjC* currObj;

            // update all pointers
            int i;
            for (i = 0; i < objectsRead.Size(); i++)
                {
                    currObj = objectsRead[i];

                    // update refs
                    currObj->objFunction->UpdateFuncObjRefs();
                    currObj->objDeleteable = true;
                    currObj->objSelected = false;
                }

            // set all FO status and UI
            for (i = 0; i < objectsRead.Size(); i++)
                {

                    currObj = objectsRead[i];
                    currObj->objFunction->DoStatusChk();
                    currObj->UpdateTreeData();
                }

            if (fileReadOK)
                {
                    GenAppClearMsgs();

                    FuncObjArray objsToCalc(objectsRead.Size());
                    objsToCalc.SetEmpty();
                    for (i = 0; i < objectsRead.Size(); i++)
                        objsToCalc += objectsRead[i]->objFunction;

                    FuncObjC::CalcSelectedObjects(foc_Full, objsToCalc);

                    PlotDefC::ReplotAfterCalc();
                    ExposedObjC::UpdateAllExposed();

                    objectsRead.LastIndex()->SelectNode();
                }

        }

    DeallocFuncObjList();

}
Exemplo n.º 11
0
/*-------------------------------------------------------------------------*/
APIRET ReadMsgFile( CHAR *netfile )
{
    APIRET           rc;
    CHAR            *string;
    INDEXPKT        *top;

    if(( rc = OpenFile( netfile )) != 0 )
        return( rc );
    
    if( fread( &msg, sizeof( msg ), 1, PktFile ) != 1 )
    {
        CloseFile();
        ShowError( "Error read file '%s'", ShowPath( netfile, 50 ));
        return( ERROR_READ_FAULT );
    }

    filename = netfile;

    string = malloc( MAX_BUFFER );

    if( string == NULL )
        return( ERROR_NOT_ENOUGH_MEMORY );

    pktcount = 1;

    AddNextStruct( pktIndex, top );

    if( top == NULL )
    {
        free( string );
        return( ERROR_NOT_ENOUGH_MEMORY );
    }

    Current = top;

    top -> AddrFrom.Zone      = 0;
    top -> AddrFrom.Net       = msg.orig_net;
    top -> AddrFrom.Node      = msg.orig_node;
    top -> AddrFrom.Point     = 0;
    top -> AddrFrom.Domain[0] = 0;

    top -> AddrTo.Zone        = 0;
    top -> AddrTo.Net         = msg.dest_net;
    top -> AddrTo.Node        = msg.dest_node;
    top -> AddrTo.Point       = 0;
    top -> AddrTo.Domain[0]   = 0;

    top -> attr               = msg.attrib;

    strcpy( string, msg.to   ); string[ MAX_TO ]   = 0; top -> to   = strdup( string );
    strcpy( string, msg.from ); string[ MAX_FROM ] = 0; top -> from = strdup( string );
    strcpy( string, msg.subj ); string[ MAX_SUBJ ] = 0; top -> subj = strdup( string );
    strcpy( string, msg.date ); string[ MAX_DATE ] = 0; top -> date = strdup( string );

    free( string );

    top -> area    = NULL;
    top -> sel     = ' ';
    top -> change  = 0;
    top -> size    = filelength( fileno( PktFile ));
    top -> name    = strdup( netfile );
    
    CloseFile();

    rc = ReadText( 1 );

    return( rc  );
}
Exemplo n.º 12
0
CFSVar CJSONReader::ReadVal(const CFSAString &szKeyPath)
{
	OnValReadStart(szKeyPath);
	CFSVar Data;

	if (m_cCh=='[') {
		Data.Cast(CFSVar::VAR_ARRAY);
		GetChar(true);
		INTPTR ipPos=0;
		for (;;) {
			if (m_cCh==0) {
				throw CJSONException(FSTSTR("Unexpetcted EOF"));
			} else if (m_cCh==']') {
				GetChar(true);
				break;
			} else if (ipPos>0) {
				if (m_cCh==',') {
					GetChar(true);
				} else {
					throw CJSONException(FSTSTR("Missing ',' in array"));
				}
			}

			CFSAString szKey;
			szKey.Format("%zd", ipPos);
			CFSVar Data1=ReadVal(szKeyPath+"/"+szKey);
			if (m_iCollectData>0) {
				Data[ipPos]=Data1;
			}
			ipPos++;
		}
	} else if (m_cCh=='{') {
		Data.Cast(CFSVar::VAR_MAP);
		GetChar(true);
		INTPTR ipPos=0;
		for (;;) {
			if (m_cCh==0) {
				throw CJSONException(FSTSTR("Unexpetcted EOF"));
			} else if (m_cCh=='}') {
				GetChar(true);
				break;
			} else if (ipPos>0) {
				if (m_cCh==',') {
					GetChar(true);
				} else {
					throw CJSONException(FSTSTR("Missing ',' in map"));
				}
			}

			CFSAString szKey;
			if (m_cCh=='\"' || m_cCh=='\'') {
				szKey=ReadString();
			} else if (FSIsLetter(m_cCh)) {
				szKey=ReadText();
			} else {
				throw CJSONException(FSTSTR("Expected key"));
			}
			if (m_cCh==':') {
				GetChar(true);
			} else {
				throw CJSONException(FSTSTR("Expected ':'"));
			}
			CFSVar Data1=ReadVal(szKeyPath+"/"+szKey);
			if (m_iCollectData>0) {
				Data[szKey]=Data1;
			}
			ipPos++;
		}
	} else if (m_cCh=='\"' || m_cCh=='\'') {
		Data=ReadString();
	} else if ((m_cCh>='0' && m_cCh<='9') || FSStrChr("-+.", m_cCh)) {
		Data=ReadNumber();
	} else if (FSIsLetter(m_cCh)) {
		Data=ReadConst();
	} else if (!m_cCh) {
	} else {
		throw CJSONException(FSTSTR("Unknown value type"));
	}

	OnValReadEnd(szKeyPath, Data);
	return Data;
}
Exemplo n.º 13
0
// 显示文件中的设置
void CSettingDlg::ShowOptionsInFile(LPCTSTR path)
{
	CString strBuf;

	gzFile f = gzopen_w(path, "rb");
	if (f == NULL)
		goto UseDefaultOptions;

	// 头部
	char header[2];
	gzread(f, header, sizeof(header));
	if (header[0] != 'T' || header[1] != 'B')
	{
		gzclose(f);
		goto UseDefaultOptions;
	}

	// 违规内容
	ReadRegexTexts(f, m_keywordsPage.m_list);

	// 屏蔽用户
	ReadRegexTexts(f, m_blackListPage.m_list);

	// 信任用户
	int size;
	gzread(f, &size, sizeof(int)); // 长度
	m_whiteListPage.m_list.ResetContent();
	int intBuf;
	for (int i = 0; i < size; i++)
	{
		ReadText(f, strBuf);
		m_whiteListPage.m_list.AddString(strBuf);
	}

	// 信任内容
	ReadRegexTexts(f, m_whiteContentPage.m_list);

	// 违规图片
	m_imagePage.m_updateImage = TRUE;

	BOOL boolBuf;
	float floatBuf;
	double doubleBuf;
	gzread(f, &intBuf, sizeof(int));						// 扫描间隔
	strBuf.Format(_T("%d"), intBuf);
	m_prefPage.m_scanIntervalEdit.SetWindowText(strBuf);
	gzread(f, &boolBuf, sizeof(BOOL));						// 封ID
	m_prefPage.m_banIDCheck.SetCheck(boolBuf);
	gzread(f, &intBuf, sizeof(int));						// 封禁时长
	m_prefPage.m_banDurationCombo.SetCurSel(intBuf == 1 ? 0 : (intBuf == 3 ? 1 : 2));
	gzread(f, &boolBuf, sizeof(BOOL));						// 封IP
	gzread(f, &intBuf, sizeof(int));						// 封禁违规次数
	strBuf.Format(_T("%d"), intBuf);
	m_prefPage.m_trigCountEdit.SetWindowText(strBuf);
	gzread(f, &boolBuf, sizeof(BOOL));						// 只扫描标题
	m_prefPage.m_onlyScanTitleCheck.SetCheck(boolBuf);
	gzread(f, &floatBuf, sizeof(float));					// 删帖间隔
	strBuf.Format(_T("%g"), floatBuf);
	m_prefPage.m_deleteIntervalEdit.SetWindowText(strBuf);
	gzread(f, &boolBuf, sizeof(BOOL));						// 操作前提示
	m_prefPage.m_confirmCheck.SetCheck(boolBuf);
	gzread(f, &intBuf, sizeof(int));						// 扫描最后页数
	strBuf.Format(_T("%d"), intBuf);
	m_prefPage.m_scanPageCountEdit.SetWindowText(strBuf);
	gzread(f, &boolBuf, sizeof(BOOL));						// 只输出删帖封号
	m_prefPage.m_briefLogCheck.SetCheck(boolBuf);
	if (gzread(f, &boolBuf, sizeof(BOOL)) == sizeof(BOOL))	// 删帖
		m_prefPage.m_deleteCheck.SetCheck(boolBuf);
	else
		m_prefPage.m_deleteCheck.SetCheck(TRUE);
	if (gzread(f, &intBuf, sizeof(int)) == sizeof(int))		// 线程数
	{
		strBuf.Format(_T("%d"), intBuf);
		m_prefPage.m_threadCountEdit.SetWindowText(strBuf);
	}
	else
		m_prefPage.m_threadCountEdit.SetWindowText(_T("2"));
	ReadText(f, strBuf);									// 封禁原因
	m_prefPage.m_banReasonEdit.SetWindowText(strBuf);
	ReadText(f, strBuf);									// 违规图片目录
	m_imagePage.m_dirEdit.SetWindowText(strBuf);
	if (gzread(f, &doubleBuf, sizeof(double)) == sizeof(double))	// 阈值
	{
		strBuf.Format(_T("%lf"), doubleBuf);
		m_imagePage.m_thresholdEdit.SetWindowText(strBuf);
	}
	else
		m_imagePage.m_thresholdEdit.SetWindowText(_T("2.43"));

	gzclose(f);
	return;

UseDefaultOptions:
	m_keywordsPage.m_list.ResetContent();					// 违规内容
	m_blackListPage.m_list.ResetContent();					// 屏蔽用户
	m_whiteListPage.m_list.ResetContent();					// 信任用户
	m_whiteContentPage.m_list.ResetContent();				// 信任内容
	m_imagePage.m_updateImage = TRUE;						// 违规图片
	m_prefPage.m_scanIntervalEdit.SetWindowText(_T("5"));	// 扫描间隔
	m_prefPage.m_banIDCheck.SetCheck(FALSE);				// 封ID
	m_prefPage.m_banDurationCombo.SetCurSel(0);				// 封禁时长
	m_prefPage.m_trigCountEdit.SetWindowText(_T("1"));		// 封禁违规次数
	m_prefPage.m_onlyScanTitleCheck.SetCheck(FALSE);		// 只扫描标题
	m_prefPage.m_deleteIntervalEdit.SetWindowText(_T("2"));	// 删帖间隔
	m_prefPage.m_confirmCheck.SetCheck(TRUE);				// 操作前提示
	m_prefPage.m_scanPageCountEdit.SetWindowText(_T("1"));	// 扫描最后页数
	m_prefPage.m_briefLogCheck.SetCheck(FALSE);				// 只输出删帖封号
	m_prefPage.m_deleteCheck.SetCheck(TRUE);				// 删帖
	m_prefPage.m_threadCountEdit.SetWindowText(_T("2"));	// 线程数
	m_prefPage.m_banReasonEdit.SetWindowText(_T(""));		// 封禁原因
	m_imagePage.m_dirEdit.SetWindowText(_T(""));			// 违规图片目录
	m_imagePage.m_thresholdEdit.SetWindowText(_T("2.43"));	// 阈值
}
Exemplo n.º 14
0
const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p ) return 0;

	int tabsize = 4;
	if ( document )
		tabsize = document->TabSize();

	if ( data )
	{
		data->Stamp( p, encoding );
		location = data->Cursor();
	}
	// Read the name, the '=' and the value.
	const char* pErr = p;
	p = ReadName( p, &name, encoding );
	if ( !p || !*p )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
		return 0;
	}
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p || *p != '=' )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
		return 0;
	}

	++p;	// skip '='
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
		return 0;
	}
	
	const char* end;

	if ( *p == '\'' )
	{
		++p;
		end = "\'";
		p = ReadText( p, &value, false, end, false, encoding );
	}
	else if ( *p == '"' )
	{
		++p;
		end = "\"";
		p = ReadText( p, &value, false, end, false, encoding );
	}
	else
	{
		// All attribute values should be in single or double quotes.
		// But this is such a common error that the parser will try
		// its best, even without them.
		value = "";
		while (    p && *p										// existence
				&& !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'	// whitespace
				&& *p != '/' && *p != '>' )						// tag end
		{
			value += *p;
			++p;
		}
	}
	return p;
}
Exemplo n.º 15
0
int XmlParser::ReadInt(char* nodePath)
{
	char output[256];
	ReadText(nodePath, output, sizeof(output));
	return atoi(output);
}
Exemplo n.º 16
0
const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p ) return 0;

//	int tabsize = 4;
//	if ( document )
//		tabsize = document->TabSize();

	if ( data )
	{
		data->Stamp( p, encoding );
		location = data->Cursor();
	}
	// Read the name, the '=' and the value.
	const char* pErr = p;
	p = ReadName( p, &name, encoding );
	if ( !p || !*p )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
		return 0;
	}
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p || *p != '=' )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
		return 0;
	}

	++p;	// skip '='
	p = SkipWhiteSpace( p, encoding );
	if ( !p || !*p )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
		return 0;
	}
	
	const char* end;
	const char SINGLE_QUOTE = '\'';
	const char DOUBLE_QUOTE = '\"';

	if ( *p == SINGLE_QUOTE )
	{
		++p;
		end = "\'";		// single quote in string
		p = ReadText( p, &value, false, end, false, encoding );
	}
	else if ( *p == DOUBLE_QUOTE )
	{
		++p;
		end = "\"";		// double quote in string
		p = ReadText( p, &value, false, end, false, encoding );
	}
	else
	{
		// All attribute values should be in single or double quotes.
		// But this is such a common error that the parser will try
		// its best, even without them.
		value = "";
		while (    p && *p											// existence
				&& !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'	// whitespace
				&& *p != '/' && *p != '>' )							// tag end
		{
			if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
				// [ 1451649 ] Attribute values with trailing quotes not handled correctly
				// We did not have an opening quote but seem to have a 
				// closing one. Give up and throw an error.
				if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
				return 0;
			}
			value += *p;
			++p;
		}
	}
	return p;
}
Exemplo n.º 17
0
void  MenuObjC::ReadDefaultObjectHeader()
{
    char tempStr[40];
    ReadText(tempStr, 40);
    ReadObjectHeader();
}