Exemple #1
0
unsigned long vtkDCMParser::ReadElementLength()
{
  DCMDataElementStruct des;

  if(file_in == NULL)
    return 0l;

  ReadElement(&des);

  return des.Length;
}
      /// <summary>Reads the language tag and parses the ID</summary>
      /// <param name="element">The language element</param>
      /// <returns>Language ID</returns>
      /// <exception cref="Logic::FileFormatException">Missing language element</exception>
      /// <exception cref="Logic::InvalidValueException">Invalid language ID</exception>
      /// <exception cref="Logic::ComException">COM Error</exception>
      GameLanguage  LanguageFileReader::ReadLanguageTag(XmlNodePtr&  element)
      {
         // Ensure present: "Missing '%s' element"
         if (element == nullptr)
            throw FileFormatException(HERE, VString(ERR_XML_MISSING_ELEMENT, L"language"));

         // Verify tag
         ReadElement(element, L"language");

         // Convert language ID
         return LanguageFilenameReader::ParseLanguageID(ReadAttribute(element, L"id"));
      }
      /// <summary>Reads a string tag</summary>
      /// <param name="element">String 't' element</param>
      /// <param name="page">Containing page</param>
      /// <param name="v">Version of page</param>
      /// <returns>New language string</returns>
      /// <exception cref="Logic::FileFormatException">Missing element or attributes</exception>
      /// <exception cref="Logic::ComException">COM Error</exception>
      LanguageString  LanguageFileReader::ReadString(XmlNodePtr&  element, LanguagePage& page, GameVersion v)
      {
         // Verify string tag
         ReadElement(element, L"t");

         // Get text
         wstring txt((WCHAR*)element->text);

         // Convert octal addition entities
         for (auto pos = txt.find(L"\\053"); pos != wstring::npos; pos = txt.find(L"\\053"))
            txt.replace(pos, 4, L"+");

         // Read ID+text
         return LanguageString(_wtoi(ReadAttribute(element, L"id").c_str()), page.ID, txt, v);
      }
Exemple #4
0
void vtkDCMParser::ReadDICOMHeaderInfo(dcm_callback dcm_funct)
{
  //UINT16 GroupCode;
  //UINT16 ElementCode;
  //UINT32 Length;
  //char vr[4];
  int stop;
  //UINT32 NextBlock;
  DCMDataElementStruct des;

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

  stop = 0;
  while(!stop)
    {
      ReadElement(&des);
      
      if(feof(file_in) || (FileIOMessage != 0))
    {
      stop = 1;
      break;
    }
    
      if(des.Length != 0xffffffff)
    des.NextBlock = ftell(file_in) + des.Length;
      else
    des.NextBlock = ftell(file_in);

      (*dcm_funct)(des, &stop, this);

      fseek(file_in, des.NextBlock, SEEK_SET);
      if(feof(file_in) || (FileIOMessage != 0))
    {
      stop = 1;
      break;
    }
    }
}
bool
InlineTranslator::TranslateRecording(char *aData, size_t aLen)
{
  // an istream like class for reading from memory
  struct MemReader {
    MemReader(char *aData, size_t aLen) : mData(aData), mEnd(aData + aLen) {}
    void read(char* s, std::streamsize n) {
      if (n <= (mEnd - mData)) {
        memcpy(s, mData, n);
        mData += n;
      } else {
        // We've requested more data than is available
        // set the Reader into an eof state
        mData = mEnd + 1;
      }
    }
    bool eof() {
      return mData > mEnd;
    }
    bool good() {
      return !eof();
    }

    char *mData;
    char *mEnd;
  };
  MemReader reader(aData, aLen);

  uint32_t magicInt;
  ReadElement(reader, magicInt);
  if (magicInt != mozilla::gfx::kMagicInt) {
    return false;
  }

  uint16_t majorRevision;
  ReadElement(reader, majorRevision);
  if (majorRevision != kMajorRevision) {
    return false;
  }

  uint16_t minorRevision;
  ReadElement(reader, minorRevision);
  if (minorRevision > kMinorRevision) {
    return false;
  }

  int32_t eventType;
  ReadElement(reader, eventType);
  while (reader.good()) {
    bool success = RecordedEvent::DoWithEvent(reader, static_cast<RecordedEvent::EventType>(eventType),
                               [&] (RecordedEvent *recordedEvent) {
                                 // Make sure that the whole event was read from the stream successfully.
                                 if (!reader.good()) {
                                     return false;
                                 }

                                 if (!recordedEvent->PlayEvent(this)) {
                                     return false;
                                 }

                                 return true;
                              });
    if (!success) {
      return false;
    }

    ReadElement(reader, eventType);
  }

  return true;
}
Exemple #6
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 *)&check;
  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;
}
Exemple #7
0
static int Demux( demux_t *p_demux )
{
    const char *psz_node = NULL;
    char *psz_txt = NULL;
    char *psz_base = FindPrefix( p_demux );
    char *psz_title_asx = NULL;
    char *psz_entryref = NULL;

    xml_reader_t *p_xml_reader = NULL;
    input_item_t *p_current_input = GetCurrentItem( p_demux );
    input_item_node_t *p_subitems = NULL;

    bool b_first_node = false;
    int i_type;
    int i_n_entry = 0;

    p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
    if( !p_xml_reader )
    {
        msg_Err( p_demux, "Cannot parse ASX input file as XML");
        goto error;
    }

    p_subitems = input_item_node_Create( p_current_input );

    do
    {
        i_type = xml_ReaderNextNode( p_xml_reader, &psz_node );
        if( i_type == XML_READER_STARTELEM )
        {
            if( !b_first_node )
            {
                if(!strncasecmp( psz_node, "ASX", 3 ) )
                    b_first_node = true;
                else
                {
                    msg_Err( p_demux, "invalid root node" );
                    goto error;
                }
            }

            /* Metadata Node Handler */
            if( !strncasecmp( psz_node, "TITLE", 5 ) )
            {
                ReadElement( p_xml_reader, &psz_title_asx );
                input_item_SetTitle( p_current_input, psz_title_asx );
            }
            else if( !strncasecmp( psz_node, "AUTHOR", 6 ) )
            {
                ReadElement( p_xml_reader, &psz_txt );
                input_item_SetArtist( p_current_input, psz_txt );
            }
            else if( !strncasecmp( psz_node, "COPYRIGHT", 9 ) )
            {
                ReadElement( p_xml_reader, &psz_txt );
                input_item_SetCopyright( p_current_input, psz_txt );
            }
            else if( !strncasecmp( psz_node, "MOREINFO", 8 ) )
            {
                const char *psz_tmp;
                do
                {
                    psz_tmp = xml_ReaderNextAttr( p_xml_reader, &psz_node );
                }
                while( psz_tmp && strncasecmp( psz_tmp, "HREF", 4 ) );

                if( !psz_tmp )  // If HREF attribute doesn't exist
                    ReadElement( p_xml_reader, &psz_txt );
                else
                    psz_txt = strdup( psz_node );

                resolve_xml_special_chars( psz_txt );
                input_item_SetURL( p_current_input, psz_txt );
            }
            else if( !strncasecmp( psz_node, "ABSTRACT", 8 ) )
            {
                ReadElement( p_xml_reader, &psz_txt );
                input_item_SetDescription( p_current_input, psz_txt );
            }
            else
            /* Base Node handler */
            if( !strncasecmp( psz_node, "BASE", 4 ) )
                ReadElement( p_xml_reader, &psz_base );
            else
            /* Entry Ref Handler */
            if( !strncasecmp( psz_node, "ENTRYREF", 7 ) )
            {
                const char *psz_tmp;
                do
                {
                    psz_tmp = xml_ReaderNextAttr( p_xml_reader, &psz_node );
                }
                while( psz_tmp && !strncasecmp( psz_tmp, "HREF", 4 ) );

                /* Create new input item */
                input_item_t *p_input;
                psz_txt = strdup( psz_node );
                resolve_xml_special_chars( psz_txt );
                p_input = input_item_New( psz_txt, psz_title_asx );
                input_item_CopyOptions( p_current_input, p_input );
                input_item_node_AppendItem( p_subitems, p_input );

                vlc_gc_decref( p_input );
            }
            else
            /* Entry Handler */
            if( !strncasecmp( psz_node, "ENTRY", 5 ) )
            {
                ProcessEntry( &i_n_entry, p_xml_reader, p_subitems,
                              p_current_input, psz_base);
            }
        /* FIXME Unsupported elements
            PARAM
            EVENT
            REPEAT
            ENDMARK
            STARTMARK
        */
        }
    }
    while( i_type != XML_READER_ENDELEM || strncasecmp( psz_node, "ASX", 3 ) );

    input_item_node_PostAndDelete( p_subitems );
    p_subitems = NULL;


error:
    free( psz_base );
    free( psz_title_asx );
    free( psz_entryref );
    free( psz_txt );

    if( p_xml_reader)
        xml_ReaderDelete( p_xml_reader );
    if( p_subitems )
        input_item_node_Delete( p_subitems );

    vlc_gc_decref( p_current_input );

    return 0;
}
Exemple #8
0
static void ProcessEntry( int *pi_n_entry, xml_reader_t *p_xml_reader,
                         input_item_node_t *p_subitems,
                         input_item_t *p_current_input, char *psz_prefix )
{
    const char *psz_node = NULL;
    const char *psz_txt = NULL;
    int i_type;

    char *psz_title = NULL;
    char *psz_artist = NULL;
    char *psz_copyright = NULL;
    char *psz_moreinfo = NULL;
    char *psz_description = NULL;
    char *psz_name = NULL;
    char *psz_mrl = NULL;
    char *psz_href = NULL;

    input_item_t *p_entry = NULL;

    int i_options;
    mtime_t i_start = 0;
    mtime_t i_duration = 0;
    char *ppsz_options[2];

    do
    {
        i_type = xml_ReaderNextNode( p_xml_reader, &psz_node );

        if( i_type == XML_READER_STARTELEM )
        {
            /* Metadata Node */
            if( !strncasecmp( psz_node, "TITLE", 5 ) )
                ReadElement( p_xml_reader, &psz_title );
            else if( !strncasecmp( psz_node, "AUTHOR", 6 ) )
                ReadElement( p_xml_reader, &psz_artist );
            else if( !strncasecmp( psz_node, "COPYRIGHT", 9 ) )
                ReadElement( p_xml_reader, &psz_copyright );
            else if( !strncasecmp( psz_node,"MOREINFO", 8 ) )
            {
                do
                {
                    psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node );
                }
                while(psz_txt && strncasecmp( psz_txt, "HREF", 4 ) );

                if( !psz_txt )
                    ReadElement( p_xml_reader, &psz_moreinfo );
                else
                    psz_moreinfo = strdup( psz_node );
                resolve_xml_special_chars( psz_moreinfo );
            }
            else if( !strncasecmp( psz_node, "ABSTRACT", 8 ) )
                ReadElement( p_xml_reader, &psz_description );
            else if( !strncasecmp( psz_node, "DURATION", 8 ) )
                i_duration = ParseTime( p_xml_reader );
            else if( !strncasecmp( psz_node, "STARTTIME", 9 ) )
                i_start = ParseTime( p_xml_reader );
            else
            /* Reference Node */
            /* All ref node will be converted into an entry */
            if( !strncasecmp( psz_node, "REF", 3 ) )
            {
                *pi_n_entry = *pi_n_entry + 1;

                if( !psz_title )
                    psz_title = input_item_GetTitle( p_current_input );
                if( !psz_artist )
                    psz_artist = input_item_GetArtist( p_current_input );
                if( !psz_copyright )
                    psz_copyright = input_item_GetCopyright( p_current_input );
                if( !psz_description )
                    psz_description = input_item_GetDescription( p_current_input );

                do
                {
                    psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node );
                }
                while( strncasecmp( psz_txt, "HREF", 4) );
                psz_href = strdup( psz_node );

                if( asprintf( &psz_name, "%d. %s", *pi_n_entry, psz_title ) == -1)
                    psz_name = strdup( psz_title );
                resolve_xml_special_chars( psz_href );
                psz_mrl = ProcessMRL( psz_href, psz_prefix );

                /* Add Time information */
                i_options = 0;
                if( i_start )
                {
                    if( asprintf( ppsz_options, ":start-time=%d" ,(int) i_start/1000000 ) != -1)
                        i_options++;
                }
                if( i_duration)
                {
                    if( asprintf( ppsz_options + i_options, ":stop-time=%d",
                                (int) (i_start+i_duration)/1000000 ) != -1)
                        i_options++;
                }

                /* Create the input item */
                p_entry = input_item_NewExt( psz_mrl, psz_name, i_options,
                        (const char* const*) ppsz_options, VLC_INPUT_OPTION_TRUSTED, i_duration );
                input_item_CopyOptions( p_current_input, p_entry );

                /* Add the metadata */
                if( psz_name )
                    input_item_SetTitle( p_entry, psz_name );
                if( psz_artist )
                    input_item_SetArtist( p_entry, psz_artist );
                if( psz_copyright )
                    input_item_SetCopyright( p_entry, psz_copyright );
                if( psz_moreinfo )
                    input_item_SetURL( p_entry, psz_moreinfo );
                if( psz_description )
                    input_item_SetDescription( p_entry, psz_description );
                if( i_duration > 0)
                    input_item_SetDuration( p_entry, i_duration );

                input_item_node_AppendItem( p_subitems, p_entry );

                while( i_options )
                    free( ppsz_options[--i_options] );
                free( psz_name );
                free( psz_mrl );
            }
        }
    }
    while( i_type != XML_READER_ENDELEM || strncasecmp( psz_node, "ENTRY", 5 ) );

    free( psz_href );
    free( psz_title );
    free( psz_artist );
    free( psz_copyright );
    free( psz_moreinfo );
    free( psz_description );
}