Ejemplo n.º 1
0
int
GetFieldOrdering(FieldList  list,
		 int	    *order)
{
    FieldSpec	*field;
    long	ord;

    field = FindField(list, "fieldOrder");

    if (field == NULL)
	ord = TYPE_ORDER;
    else if (field->occurrence != GLOBAL
	     || field->rank != 0
	     || field->data == NULL
	     || !LongVal(field->data, field->type, &ord)
	     || ord != FIELD_ORDER && ord != TYPE_ORDER)
    {
	DebugMsg(1, "Bad field \"fieldOrder\".");
	return FALSE;
    }

    if (order != NULL)
	*order = ord;

    return TRUE;
}
Ejemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////
//
// FromString
//
///////////////////////////////////////////////////////////////////////////////
int TMarcRecord::FromString(char* MarcString)
{
    unsigned long       lngchamp,
                        debutdata,
                        pos,
                        dd,
                        posdata;
    char                cdebutdata[6],
                        temp[6];
    TMarcField          *champ;

    // Delete existing tree
    DelTree();

    *m_recordId = '\0';

    // Leader
    memcpy(itsLeader, MarcString, 24);
    itsLeader[24]=0;

    // On isole l'adresse de d‰but des donn‰es
    memcpy(cdebutdata,&itsLeader[12],5);
    cdebutdata[5]=0;
    if (Val(cdebutdata,&debutdata))
        return mStateManager->SetErrorD(1007,FATAL,cdebutdata);
    pos=24;

    // On va maintenant renseigner les differents champs
    if ((itsFirstField = new TMarcField()) == NULL)
        return mStateManager->SetError(9041,FATAL);
    champ=itsFirstField;

    // Lecture du tag du champs
    memcpy(temp,&MarcString[pos],3);
    temp[3]=0;
    if (champ->SetTag(temp))
        return mStateManager->SetErrorD(1101,ERROR,temp);
    pos+=3;

    // Lecture de sa longueur
    memcpy(temp,&MarcString[pos],4);
    temp[4]=0;
    if (Val(temp,&lngchamp))
        return mStateManager->SetErrorD(1004,ERROR,temp);
    pos += 4;

    // Lecture de sa position
    memcpy(temp,&MarcString[pos],5);
    temp[5]=0;
    if (LongVal(temp,&posdata))
        return mStateManager->SetErrorD(1007,ERROR,temp);
    pos += 5;

    // on remplit le premier champ
    // on alloue de la memoire pour le libelle
    dd=(long)debutdata+posdata;
    if (IsFieldWithIndicators(INPUT,champ->GetTag(),&MarcString[dd],lngchamp))
    {
        champ->SetI1(MarcString[dd++]);
        champ->SetI2(MarcString[dd++]);
        lngchamp-=2;
    }

    champ->SetLib1(&MarcString[dd],(unsigned int)lngchamp-1);

    if (strcmp(champ->GetTag(), "001") == 0)
    {
        strncpy(m_recordId, champ->GetLib1(), 50);
        m_recordId[50] = '\0';
    }

    while (MarcString[pos] != '\x1E')  // end of directory
    {
        champ->SetNextField(new TMarcField());
        if (champ->GetNextField()==NULL)
            return mStateManager->SetError(9041,ERROR);
        champ = champ->GetNextField();

        // Lecture du tag du champs
        memcpy(temp,&MarcString[pos],3);
        temp[3]=0;
        if (champ->SetTag(temp))
            return mStateManager->SetErrorD(1101,ERROR,temp);
        pos+=3;

        // Lecture de sa longueur
        memcpy(temp,&MarcString[pos],4);
        temp[4]=0;
        if (Val(temp,&lngchamp))
            return mStateManager->SetErrorD(1004,ERROR,temp);
        pos += 4;

        // Lecture de sa position
        memcpy(temp,&MarcString[pos],5);
        temp[5]=0;
        if (LongVal(temp,&posdata))
            return mStateManager->SetErrorD(1007,ERROR,temp);
        pos += 5;

        // on remplit le champ
        // on alloue de la memoire pour le libelle
        dd=(long)debutdata+posdata;
        if (IsFieldWithIndicators(INPUT,champ->GetTag(),&MarcString[dd],lngchamp))
        {
            champ->SetI1(MarcString[dd++]);
            champ->SetI2(MarcString[dd++]);
            lngchamp-=2;
        }
        if (lngchamp < 1)
        {
            // A broken record
            lngchamp = 1;
        }

        champ->SetLib1(&MarcString[dd],(unsigned int)lngchamp-1);

        if (strcmp(champ->GetTag(), "001") == 0)
        {
            strncpy(m_recordId, champ->GetLib1(), 50);
            m_recordId[50] = '\0';
        }
    }

    champ->SetNextField(NULL);
    return 0;
}