Пример #1
0
static PSBOOK *ReadAllOldAtoms(char *bok_filename,int *NumOfWav)
 {      /* Wczytanie wszystkich zestawow ksiazek (usredniona mapa Wignera) */
   extern unsigned long NumberOfAllWaveForms;
   int i,k,NumberOfBloks,j,num_of_wav;
   PSBOOK *book=NULL;
   FILE *plik=NULL;
   HEADER head;			/* Funkcja zwraca globalna liczbe atomow */
   ATOM atom;
   float df;

   if((NumberOfBloks=LicznikKsiazek(bok_filename))==-1)
     ERROR("Problemy z odczytem struktury ksiazki !");

   num_of_wav=(int)NumberOfAllWaveForms;
   if((book=(PSBOOK *)malloc((unsigned)num_of_wav*sizeof(PSBOOK)))==NULL)
     ERROR("Brak pamieci (ReadAllAtoms) !");

   if((plik=fopen(bok_filename,"rb"))==NULL)
     ERROR("Problemy przy otwarciu zbioru !\n");

    if(ReadHeader(&head,plik)==-1)
     ERROR("Blad czytania naglowka (ReadAllAtoms) !");

    fseek(plik,0L,SEEK_SET);
    df=2.0F*M_PI/(float)(head.signal_size);

    Ec=E0=0.0F;
    for(i=0,k=0 ; i<NumberOfBloks ; i++)
     {
       if(ReadHeader(&head,plik)==-1)
	 ERROR("Blad czytania naglowka (ReadAllAtoms) !");

       if(head.signal_size!=DimBase)                /* W przypadku niezgodnosci */
	 if(prn==ON)
	   fprintf(stderr,"UWAGA ! Niezgodnosc rozmiaru bazy (%d)"
		   " i analizowanego naglowka (%d)\n",
		   DimBase,head.signal_size);

       E0+=head.signal_energy;
       for(j=0 ; j<head.book_size ; j++)
	{
	  if(ReadAtom(&atom,plik)==-1)
	    ERROR("Blad czytania atomu (ReadAllAtoms) !");

	  book[k].s=(float)(1<<(atom.octave));
	  book[k].t=(float)atom.position;
	  book[k].w=atom.modulus;
	  book[k].f=df*(float)atom.frequency;
	  book[k].amplitude=atom.amplitude;
	  Ec+=SQR(atom.modulus);
	  k++;
	}
     }
   fclose(plik);
   *NumOfWav=num_of_wav;
   return book;
 }
Пример #2
0
bool Datum::Reader::ReadNext() {
    Red.reset(nullptr);
    Deblank();
    if(Cursor == End || *Cursor == 0)
        return false;

    char c = *Cursor;
    if(c == '(')
        ReadList();
    else 
        Red.reset(ReadAtom().release());

    return Errors.size() == 0 && Red != nullptr; }
Пример #3
0
void ParsedObject::ReadExpression(LispInt depth)
{
    ReadAtom();

    for (;;) {
        //Handle special case: a[b]. a is matched with lowest precedence!!
        if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) {
            // Match opening bracket
            MatchToken(iLookAhead);
            // Read "index" argument
            ReadExpression(KMaxPrecedence);
            // Match closing bracket
            if (iLookAhead != iParser.iEnvironment.iProgClose->String())
                throw LispErrGeneric(std::string("Expecting a ] close bracket for program block, but got ") + *iLookAhead + std::string(" instead"));

            MatchToken(iLookAhead);
            // Build into Ntn(...)
            const LispString* theOperator = iParser.iEnvironment.iNth->String();
            InsertAtom(theOperator);
            Combine(2);
        } else {
            LispOperators::const_iterator opi = iParser.iInfixOperators.find(iLookAhead);
            
            if (opi == iParser.iInfixOperators.end()) {
                if (!IsSymbolic((*iLookAhead)[0]))
                    return;
                
                const std::size_t origlen = iLookAhead->size();
                std::size_t len = origlen;

                while (len > 1) {
                    len -= 1;
                    const LispString* lookUp =
                            iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(0, len));

                    opi = iParser.iInfixOperators.find(lookUp);

                    if (opi != iParser.iInfixOperators.end()) {

                        const LispString* lookUpRight =
                                iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(len, origlen - len));

                        if (iParser.iPrefixOperators.find(lookUpRight) != iParser.iPrefixOperators.end()) {
                            iLookAhead = lookUp;
                            LispInput& input = iParser.iInput;
                            LispInt newPos = input.Position() - (origlen - len);
                            input.SetPosition(newPos);
                            break;
                        }

                        opi = iParser.iInfixOperators.end();
                    }
                }

                if (opi == iParser.iInfixOperators.end())
                    return;
            }

            
            if (depth < opi->second.iPrecedence)
                return;
            LispInt upper = opi->second.iPrecedence;
            if (!opi->second.iRightAssociative)
                upper--;
            GetOtherSide(2, upper);
        }
    }
}
Пример #4
0
M4Err ParseAtom(Atom **outAtom, BitStream *bs, u64 *read)
{
	u32 type;
	u64 size;
	u8 uuid[16];
	M4Err e;
	Atom *newAtom;
	char name[5];
	name[4] = 0;
	e = M4OK;
	if ((bs == NULL) || (outAtom == NULL) ) return M4BadParam;
	*outAtom = NULL;

	//read atom header
	size = (u64) BS_ReadInt(bs, 32);
	*read = 4;
	/*fix for some atoms found in some old hinted files*/
	if ((size >= 2) && (size <= 4)) {
		size = 4;
		type = VoidAtomType;
	} else {
		type = BS_ReadInt(bs, 32);
		*read += 4;
		/*no size means till end of file - EXCEPT FOR some old QuickTime atoms...*/
		if (type == totlAtomType)
			size = 12;
		if (!size) 
			size = BS_Available(bs) + 4;
	}
	/*handle uuid*/
	memset(uuid, 0, 16);
	if (type == ExtendedAtomType ) {
		BS_ReadData(bs, (unsigned char *) uuid, 16);
		*read += 16;
	}
	
	//handle large atom
	if (size == 1) {
		size = BS_ReadInt(bs, 64);
		*read += 8;
	}

	if ( size - *read < 0 ) return M4InvalidMP4File;
	//OK, create the atom based on the type
	newAtom = CreateAtom(type);
	if (! newAtom) return M4OutOfMem;

	//OK, init and read this atom
	newAtom->size = size;
	memcpy(newAtom->uuid, uuid, 16);
	if (!newAtom->type) newAtom->type = type; 

	if (newAtom->size - *read > BS_Available(bs) ) {
		*outAtom = newAtom;
		return M4UncompleteFile;
	}
	//we need a special reading for these atoms...
	if (newAtom->type == DegradationPriorityAtomType) {
		*outAtom = newAtom;
		return M4OK;
	}

#if 0
	/*perf test*/
	switch (type) {
	case SampleTableAtomType:
	case TimeToSampleAtomType:
	case SampleToChunkAtomType:
	case CompactSampleSizeAtomType:
	case SampleSizeAtomType:
	case ChunkOffsetAtomType:
	case ChunkLargeOffsetAtomType:
		now = M4_GetSysClock();
		e = ReadAtom(newAtom, bs);
		M4_MP4TypeToString(newAtom->type, name);
		printf("Read atom %s in %d ms\n", name, M4_GetSysClock() - now);
		break;
	default:
		e = ReadAtom(newAtom, bs, read);
		break;
	}
#else
	e = ReadAtom(newAtom, bs, read);	
#endif

	//DON'T DELETE THE MDAT ATOM IF UNCOMPLETE...
	if (e < 0 && e != M4UncompleteFile) {
		DelAtom(newAtom);
		*outAtom = NULL;
		return e;
	}
	*outAtom = newAtom;
	return e;
}