Esempio n. 1
0
int main (int argc, char *argv[])
{
    char *filename   = argc > 1 ? argv[1] : "-";
    char *nvtnamestr = argc > 2 ? argv[2] : NULL;

    SdifFileT        *file    = open_file(filename);

    /* get list of all nvts */
    SdifNameValuesLT *nvtlist = SdifFNameValueList(file);

    if (nvtnamestr)
    {   /* query one key */
	SdifNameValueT *nv = SdifNameValuesLGet(nvtlist, nvtnamestr);
	    
	if (nv)
	    printf("Name %s:\n%s\n", 
		   SdifNameValueGetName(nv), SdifNameValueGetValue(nv));
	else
	{
	    printf("Name %s not found!\n", nvtnamestr);
	    SdifFClose(file);
	    exit(1);
	}
    }
    else
    {   /* print nvts */
	SdifListT *nvtl   = SdifNameValueTableList(nvtlist);
	int	   numnvt = SdifListGetNbData(nvtl);
	SdifHashTableIteratorT *nvtiter = SdifCreateHashTableIterator(NULL);
	
	printf("Number of NVTs in file %s: %d\n", filename, numnvt);

	SdifListInitLoop(nvtl);
	while (SdifListIsNext(nvtl))
	{   /* print one NVT */
	    SdifNameValueTableT *currnvt = 
		(SdifNameValueTableT *) SdifListGetNext(nvtl);
	    SdifHashTableT      *nvht = SdifNameValueTableGetHashTable(currnvt);

	    printf("\nNameValueTable Number %d Stream %d Size %d:\n", 
		   SdifNameValueTableGetNumTable(currnvt), 
		   SdifNameValueTableGetStreamID(currnvt),
		   SdifHashTableGetNbData(nvht));

	    SdifHashTableIteratorInitLoop(nvtiter, nvht);
	    while (SdifHashTableIteratorIsNext(nvtiter))
	    {
		SdifNameValueT *nv = (SdifNameValueT *) 
		    SdifHashTableIteratorGetNext(nvtiter);
		printf("%s\t%s;\n", SdifNameValueGetName(nv), 
		                    SdifNameValueGetValue(nv));
	    }
	}

	SdifKillHashTableIterator(nvtiter);
    }
    
    SdifFClose(file);
}
Esempio n. 2
0
/*	query posts frame, matrix, and all ascii info	  */
static void sdiflists_info(t_sdiflists *x)
{

  /* What I want to Post:
     - information about external
     - filename
     - 1NVT
     - streams in file, frame/matrix types
     - selection
     - column info
     - framecount and timerange
  */

  post("\n_-=-_ sdiflists -info _-=-_");
  
  if(x->markers[0].timetag == -1) 
    {
      post("sdiflists: open a file before getting info");
      return;
    }
  post("filename: %s", x->filename->s_name);


  //size_t bytesread = 0; 
  //int eof; 


  SdifFClose (x->file);
  x->file = SdifFOpen ( x->filename->s_name, eReadFile); 
  SdifFReadGeneralHeader  (x->file); 
  SdifFReadAllASCIIChunks (x->file); 
  


  //----send all Names Values Tables out right most list outlet----
  if (SdifNameValuesLIsNotEmpty(x->file->NameValues)) 
  {
      x->string = SdifStringNew();
      SdifListInitLoop(x->file->NameValues->NVTList); 
      while (SdifListIsNext(x->file->NameValues->NVTList)) 
      {
          x->file->NameValues->CurrNVT = (SdifNameValueTableT *)
	      SdifListGetNext(x->file->NameValues->NVTList);
	  
          SdifUInt4       iNV;
          SdifHashNT     *pNV;
          SdifHashTableT *HTable;
          HTable = x->file->NameValues->CurrNVT->NVHT;
	  
          for(iNV=0; iNV<HTable->HashSize; iNV++)
	      for (pNV = HTable->Table[iNV]; pNV; pNV = pNV->Next)
              {
		  SdifNameValueT *NameValue = (SdifNameValueT *) pNV->Data;
		  SETSYMBOL(x->infolist , gensym(NameValue->Name));
		  SETSYMBOL(x->infolist + 1 , gensym(NameValue->Value));
		  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);
              }//end for pNV
      } //end list while NVT
      SdifStringFree(x->string);
  }// end if NVT is not empty

  //---------------------- post 1IDS ---------------------------
  if (   (SdifExistUserMatrixType(x->file->MatrixTypesTable))
         || (SdifExistUserFrameType(x->file->FrameTypesTable)) )
    {
      x->string = SdifStringNew();
      if ((x->file->TypeDefPass == eNotPass) || (x->file->TypeDefPass == eReadPass))
        {   
          SdifFAllMatrixTypeToSdifString(x->file, x->string); 
          SETSYMBOL ( x->infolist , gensym( SdifSignatureToString(e1TYP)) );
          SETSYMBOL ( x->infolist + 1 , gensym(x->string->str) );
          outlet_list(x->infoout, gensym("list"), 2 , x->infolist);

          post("----  %s  ----",SdifSignatureToString(e1TYP));
				
	  SdifFAllFrameTypeToSdifString(x->file, x->string);		//this compiles
	}
      SdifStringFree(x->string);	
    }

  if (SdifStreamIDTableGetNbData  (x->file->StreamIDsTable) > 0)
  {
      x->string = SdifStringNew();
      if ((x->file->StreamIDPass == eNotPass) || (x->file->StreamIDPass == eReadPass))
      {      
	  SdifFAllStreamIDToSdifString(x->file, x->string);	//this also undeclared in sdif.h. x->string?	
	  SETSYMBOL ( x->infolist , gensym(SdifSignatureToString(e1IDS)) );
          SETSYMBOL ( x->infolist + 1 , gensym(x->string->str) );
          outlet_list(x->infoout, gensym("list"), 2 , x->infolist);

      }
      SdifStringFree(x->string);	
  }
			
  //------ output Stream ID's and corresponding Frame types --------
  size_t  bytesread = 0;
  int eof = 0;
  int nStream = 0;
  int streamIDlist[MAX_STREAMS];
  int j, newStream;
  for(j = 0; j < MAX_STREAMS; j++)
      streamIDlist[j] = -1;
  while(!eof)
  {
      bytesread += SdifFReadFrameHeader (x->file);
      SdifUInt4       streamid = SdifFCurrID (x->file);
      SdifSignature   fsig     = SdifFCurrFrameSignature (x->file);
      newStream = 1;
      for(j = 0; j < MAX_STREAMS; j++)
      {
	  if(streamIDlist[j] == (signed) streamid)
	      newStream = 0;
      }
      if(newStream)
      {
	  streamIDlist[nStream++] = streamid;
	  SETSYMBOL(x->infolist , gensym("stream"));
	  SETFLOAT(x->infolist + 1, streamid );
	  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);

	  SETSYMBOL(x->infolist , gensym("frametype"));
	  SETSYMBOL (x->infolist + 1, gensym(SdifSignatureToString(fsig)) );
	  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);
      }

      bytesread += SdifFSkipFrameData (x->file);
      eof = (SdifFGetSignature(x->file, &bytesread)== eEof);
 
  }
  
  //also send other useful info out rightmost list outlet
  SETSYMBOL(x->infolist , gensym("frames"));
  SETFLOAT (x->infolist + 1, (float) x->nframes);
  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);
    
  SETSYMBOL(x->infolist , gensym("seconds"));
  SETFLOAT (x->infolist + 1, x->seconds );
  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);
	 
  SETSYMBOL(x->infolist , gensym("maxlist"));
  SETFLOAT (x->infolist + 1, x->max_vec );
  outlet_list(x->infoout, gensym("list"), 2 , x->infolist);
   
 
}