static void readVertices(spSkeletonBinary *self, spVertexAttachment *attachment, int vertexCount)
{
    if (!readBoolean(self)) {
        attachment->vertices = readFloats(self, self->scale, vertexCount << 1);
        attachment->verticesCount = vertexCount << 1;
        attachment->bones = NULL;
        attachment->bonesCount = 0;
    } else {
        float *weights;
        int *bones;
        int weightCount = 0, boneCount = 0;
        int position = self->data->position;
        
        for (int i = 0; i < vertexCount; i++) {
            int nn = readVarint(self, true);
            boneCount++;
            for (int ii = 0; ii < nn; ii++) {
                readVarint(self, true);
                self->data->position += sizeof(float) * 3;
                weightCount += 3;
                boneCount++;
            }
        }
        
        self->data->position = position;
        
        attachment->bones = MALLOC(int, boneCount);
        attachment->bonesCount = boneCount;
        attachment->vertices = MALLOC(float, weightCount);
        attachment->verticesCount = weightCount;
        weights = attachment->vertices;
        bones = attachment->bones;
        
        for (int i = 0; i < vertexCount; i++) {
            int nn = readVarint(self, true);
            *bones++ = nn;
            for (int ii = 0; ii < nn; ii++) {
                *bones++ = readVarint(self, true);
                *weights++ = readFloat(self) * self->scale;
                *weights++ = readFloat(self) * self->scale;
                *weights++ = readFloat(self);
            }
        }
    }
}
示例#2
0
    uint32_t Node::decode(const std::vector<uint8_t>& buffer, uint32_t offset)
    {
        uint32_t originalOffset = offset;

        if (buffer.size() - offset < 1)
        {
            return 0;
        }

        marker = *reinterpret_cast<const Marker*>(buffer.data() + offset);
        offset += 1;

        uint32_t ret = 0;

        switch (marker)
        {
            case Marker::Number: ret = readNumber(buffer, offset, doubleValue); break;
            case Marker::Boolean: ret = readBoolean(buffer, offset, boolValue); break;
            case Marker::String: ret = readString(buffer, offset, stringValue); break;
            case Marker::Object: ret = readObject(buffer, offset, mapValue); break;
            case Marker::Null: /* Null */; break;
            case Marker::Undefined: /* Undefined */; break;
            case Marker::ECMAArray: ret = readECMAArray(buffer, offset, mapValue); break;
            case Marker::ObjectEnd: break; // should not happen
            case Marker::StrictArray: ret = readStrictArray(buffer, offset, vectorValue); break;
            case Marker::Date: ret = readDate(buffer, offset, dateValue); break;
            case Marker::LongString: ret = readLongString(buffer, offset, stringValue); break;
            case Marker::XMLDocument: ret = readXMLDocument(buffer, offset, stringValue); break;
            case Marker::TypedObject: ret = readTypedObject(buffer, offset); break;
            case Marker::SwitchToAMF3: ret = readSwitchToAMF3(buffer, offset); break;
            default: return 0;
        }

        offset += ret;

        return offset - originalOffset;
    }
示例#3
0
static int readConfigOption( INOUT STREAM *stream, 
							 IN_HANDLE CRYPT_USER iCryptUser )
	{
	CRYPT_ATTRIBUTE_TYPE attributeType;
	const BUILTIN_OPTION_INFO *builtinOptionInfoPtr;
	MESSAGE_DATA msgData;
	void *dataPtr DUMMY_INIT_PTR;
	long optionCode;
	int value, tag, length, status;

	/* Read the wrapper and option index and map it to the actual option.  
	   If we find an unknown index or one that shouldn't be writeable to 
	   persistent storage, we skip it and continue.  This is done to handle 
	   new options that may have been added after this version of cryptlib 
	   was built (for unknown indices) and because the stored configuration 
	   options are an untrusted source so we have to check for attempts to 
	   feed in bogus values (for non-writeable options) */
	readSequence( stream, NULL );
	status = readShortInteger( stream, &optionCode );
	if( cryptStatusError( status ) )
		return( status );
	if( optionCode < 0 || optionCode > LAST_OPTION_INDEX )
		{
		/* Unknown option, ignore it */
		return( readUniversal( stream ) );
		}
	builtinOptionInfoPtr = getBuiltinOptionInfoByCode( optionCode );
	if( builtinOptionInfoPtr == NULL || \
		builtinOptionInfoPtr->index < 0 || \
		builtinOptionInfoPtr->index > LAST_OPTION_INDEX || \
		builtinOptionInfoPtr->index == CRYPT_UNUSED )
		{
		/* Unknown option, ignore it */
		return( readUniversal( stream ) );
		}
	attributeType = builtinOptionInfoPtr->option;

	/* Read the option value and set the option.  We don't treat a failure 
	   to set the option as a problem since the user probably doesn't want 
	   the entire system to fail because of a bad configuration option, and 
	   in any case we'll fall back to a safe default value */
	status = tag = peekTag( stream );
	if( cryptStatusError( status ) )
		return( status );
	if( tag == BER_BOOLEAN || tag == BER_INTEGER )
		{
		/* It's a numeric value, read the appropriate type and try and set 
		   the option */
		if( tag == BER_BOOLEAN )
			status = readBoolean( stream, &value );
		else
			{
			long integer;

			status = readShortInteger( stream, &integer );
			if( cryptStatusOK( status ) )
				value = ( int ) integer;
			}
		if( cryptStatusError( status ) )
			return( status );
		( void ) krnlSendMessage( iCryptUser, IMESSAGE_SETATTRIBUTE, 
								  &value, attributeType );
		return( CRYPT_OK );
		}

	/* It's a string value, set the option straight from the encoded data */
	status = readGenericHole( stream, &length, 1, BER_STRING_UTF8 );
	if( cryptStatusOK( status ) )
		status = sMemGetDataBlock( stream, &dataPtr, length );
	if( cryptStatusOK( status ) )
		status = sSkip( stream, length, SSKIP_MAX );
	if( cryptStatusError( status ) )
		return( status );
	setMessageData( &msgData, dataPtr, length );
	( void ) krnlSendMessage( iCryptUser, IMESSAGE_SETATTRIBUTE_S, 
							  &msgData, attributeType );

	return( CRYPT_OK );
	}
 void ObjectDataInput::readInternal(int typeId, bool *object) {
     *object = readBoolean();
 }
static spAttachment *readAttachment(spSkeletonBinary *self, spSkin *skin, int slotIndex, const char *attachmentName)
{
    spAttachment *attachment = NULL;
    float scale = self->scale;
    
    char *name = readString(self);
    if (name == NULL) name = (char *)attachmentName;
    
    switch ((spAttachmentType)readByte(self)) {
        case SP_ATTACHMENT_REGION: {
            spRegionAttachment *region;
            
            char *path = readString(self);
            if (path == NULL) path = name;
            
            attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_REGION, name, path);
            region = SUB_CAST(spRegionAttachment, attachment);
            if (path) {
                region->path = copyString(path);
            }
            
            region->rotation = readFloat(self);
            region->x = readFloat(self) * scale;
            region->y = readFloat(self) * scale;
            region->scaleX = readFloat(self);
            region->scaleY = readFloat(self);
            region->width = readFloat(self) * scale;
            region->height = readFloat(self) * scale;
            readColor(self, &region->r, &region->g, &region->b, &region->a);
            
            spRegionAttachment_updateOffset(region);
            spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
            break;
        }
        case SP_ATTACHMENT_BOUNDING_BOX: {
            spBoundingBoxAttachment *boundingBox;
            int vertexCount = readVarint(self, true);
            
            attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_BOUNDING_BOX, name, name);
            boundingBox = SUB_CAST(spBoundingBoxAttachment, attachment);
            readVertices(self, SUPER(boundingBox), vertexCount);
            SUPER(boundingBox)->worldVerticesLength = vertexCount << 1;
            
            spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
            
            break;
        }
        case SP_ATTACHMENT_MESH: {
            spMeshAttachment *mesh;
            int vertexCount;
            
            char *path = readString(self);
            if (path == NULL) path = name;
            
            attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_MESH, name, path);
            mesh = SUB_CAST(spMeshAttachment, attachment);
            if (path) {
                mesh->path = copyString(path);
            }
            
            readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a);
            vertexCount = readVarint(self, true);
            mesh->regionUVs = readFloats(self, 1, vertexCount << 1);
            mesh->trianglesCount = readVarint(self, true);
            mesh->triangles = readShorts(self, mesh->trianglesCount);
            readVertices(self, SUPER(mesh), vertexCount);
            SUPER(mesh)->worldVerticesLength = vertexCount << 1;
            mesh->hullLength = readVarint(self, true) << 1;
            
            spMeshAttachment_updateUVs(mesh);
            spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
            break;
        }
        case SP_ATTACHMENT_LINKED_MESH: {
            spMeshAttachment *mesh;
            
            char *parent;
            char *skinName;
            char *path = readString(self);
            if (path == NULL) path = name;
            
            attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_LINKED_MESH, name, path);
            mesh = SUB_CAST(spMeshAttachment, attachment);
            if (path) {
                mesh->path = copyString(path);
            }
            
            readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a);
            skinName = readString(self);
            parent = readString(self);
            mesh->inheritDeform = readBoolean(self);
            
            addLinkedMesh(self, mesh, skinName, slotIndex, parent);
            break;
        }
        case SP_ATTACHMENT_PATH: {
            spPathAttachment *path;
            int vertexCount;
            
            attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_PATH, name, NULL);
            path = SUB_CAST(spPathAttachment, attachment);
            
            path->closed = readBoolean(self);
            path->constantSpeed = readBoolean(self);
            vertexCount = readVarint(self, true);
            readVertices(self, SUPER(path), vertexCount);
            SUPER(path)->worldVerticesLength = vertexCount << 1;
            path->lengthsLength = vertexCount / 3;
            path->lengths = MALLOC(float, path->lengthsLength);
            for (int i = 0; i < path->lengthsLength; i++) {
                path->lengths[i] = readFloat(self) * self->scale;
            }
            
            break;
        }
    }
    
    return attachment;
}
示例#6
0
bool Configurator::readConfiguration (const char *filename)
{
	std::ifstream file(filename == 0 ? Configurator::filename : filename);
	if (!file.good())
		return false;

	int version;
	if (!readInt(file, version) || (version != 1 && version != 2 && version != 3))
		return false;

	int routerCount;
	if (!readInt(file, routerCount) || routerCount < 0)
		return false;
	
	for (int i = 0; i != routerCount; ++i)
	{
		std::string interface;
		int vrid;
		int addressFamily;
		int priority;
		int interval;
		bool accept;
		bool preempt;
		bool enabled;
		int flags;
		IpAddress primaryIp;
		int addressCount;
		IpSubnetSet subnets;
		std::string masterCommand;
		std::string backupCommand;
		int vlanId;

		// Read data
		if (
				!readString(file, interface)
				|| !readInt(file, vrid)
				|| !readInt(file, addressFamily)
				|| !readInt(file, priority)
				|| !readInt(file, interval)
				|| !readBoolean(file, accept)
				|| !readBoolean(file, preempt)
				|| !readBoolean(file, enabled)
				|| !readInt(file, flags))
		{
			return false;
		}

		if (flags & FLAG_HAS_PRIMARY_IP_ADDRESS)
		{
			if (!readIp(file, primaryIp))
				return false;
		}

		if (version > 1)
		{
			if (!readString(file, masterCommand) || !readString(file, backupCommand))
				return false;
		}

		if (version > 2)
		{
			if (!readInt(file, vlanId))
				return false;
		}

		if (!readInt(file, addressCount))
			return false;

		for (int j = 0; j != addressCount; ++j)
		{
			IpSubnet subnet;
			if (!readSubnet(file, subnet))
				return false;

			subnets.insert(subnet);
		}

		// Sanitize

		if (vrid < 1 || vrid > 255)
		{
			// TODO - Add to log
			continue;
		}

		if (priority < 1 || priority > 255)
		{
			// TODO - Add to log
			continue;
		}

		if (addressFamily != AF_INET && addressFamily != AF_INET6)
		{
			// TODO - Add to log
			continue;
		}

		if (interval % 10 != 0 || interval < 10 || interval > 40950)
		{
			// TODO - Add to log
			continue;
		}

		int ifIndex = if_nametoindex(interface.c_str());
		if (ifIndex <= 0)
		{
			// TODO - Add to log
			continue;
		}

		// Create service

		VrrpService *service = VrrpManager::getService(ifIndex, vrid, vlanId, addressFamily, true);
		if (service == 0)
		{
			// TODO - Add to log
			continue;
		}

		service->setPriority(priority);
		service->setAdvertisementInterval(interval / 10);
		service->setAcceptMode(accept);
		service->setPreemptMode(preempt);
		if (flags & FLAG_HAS_PRIMARY_IP_ADDRESS)
			service->setPrimaryIpAddress(primaryIp);
		service->setMasterCommand(masterCommand);
		service->setBackupCommand(backupCommand);
		for (IpSubnetSet::const_iterator subnet = subnets.begin(); subnet != subnets.end(); ++subnet)
		{
			service->addIpAddress(*subnet);
		}
		if (enabled)
			service->enable();
		else
			service->disable();
	}

	return true;
}
示例#7
0
TDefMech read_TDefMech(int numJugador, int numMech){
  TDefMech d;
  char path[32];
  
  sprintf(path, "%s%i-%i%s", "defmechJ", numJugador, numMech, ".sbt");
  
  FILE * sbt = fopen(path, "r");
  
  if(sbt == NULL){
    char aux[128];
    sprintf(aux, "%s%s%s", "Error Apertura: No se puede abrir el fichero defMech ", path, "\n");
    write_LogStatus(aux);
    exit(-1);
  }
  
  if(checkSbt(sbt, "defmechSBT")){
    readNombre (sbt, d.nombre);
    readNombre (sbt, d.modelo);
    d.toneladas = readInteger( sbt );
    d.potencia = readInteger( sbt );
    d.numRadiadoresInt = readInteger( sbt );
    d.numRadiadores = readInteger( sbt );
    d.tieneMASC = readBoolean(sbt);
    d.tieneDACMTD = readBoolean(sbt);
    d.tieneDACMTI = readBoolean(sbt);
    d.tieneDACMTC = readBoolean(sbt);
    d.maxCalorGenerado = readInteger( sbt );
    d.conBrazos = readBoolean(sbt);
    d.conHombroIzq  = readBoolean(sbt);
    d.conBrazoIzq = readBoolean(sbt);
    d.conAnteBrazoIzq = readBoolean(sbt);
    d.conManoIzq = readBoolean(sbt);
    d.conHombroDer = readBoolean(sbt);
    d.conBrazoDer = readBoolean(sbt);
    d.conAnteBrazoDer = readBoolean(sbt);
    d.conManoDer = readBoolean(sbt);
    d.blinBrazoIzq = readInteger( sbt );
    d.blinTorsoIzq = readInteger( sbt );
    d.blinPiernaIzq = readInteger( sbt );
    d.blinPiernaDer = readInteger( sbt );
    d.blinTorsoDer = readInteger( sbt );
    d.blinBrazoDer = readInteger( sbt );
    d.blinTorsoCen = readInteger( sbt );
    d.blinCabeza = readInteger( sbt );
    d.blinAtrasTorsoIzq = readInteger( sbt );
    d.blinAtrasTorsoDer = readInteger( sbt );
    d.blinAtrasTorsoCen = readInteger( sbt );
    d.ptsEstIntBrazoIzq = readInteger( sbt );
    d.ptsEstIntTorsoIzq = readInteger( sbt );
    d.ptsEstIntPiernaIzq = readInteger( sbt );
    d.ptsEstIntPiernaDer = readInteger( sbt );
    d.ptsEstIntTorsoDer = readInteger( sbt );
    d.ptsEstIntBrazoDer = readInteger( sbt );
    d.ptsEstIntTorsoCen = readInteger( sbt );
    d.ptsEstIntCabeza = readInteger( sbt );
    d.numComponentes = readInteger( sbt );

#if defined (_DEBUG)
    int linea = 2;
    printf("--------READ TDEFMECH--------\n");
    printf("%03ic:%s\n", linea++, d.nombre);
    printf("%03ic:%s\n", linea++, d.modelo);
    printf("%03in:%i\n", linea++, d.toneladas);
    printf("%03in:%i\n", linea++, d.potencia);
    printf("%03in:%i\n", linea++, d.numRadiadoresInt);
    printf("%03in:%i\n", linea++, d.numRadiadores);
    printf("%03in:%i\n", linea++, d.tieneMASC);
    printf("%03in:%i\n", linea++, d.tieneDACMTD);
    printf("%03in:%i\n", linea++, d.tieneDACMTI);
    printf("%03in:%i\n", linea++, d.tieneDACMTC);
    printf("%03in:%i\n", linea++, d.maxCalorGenerado);
    printf("%03in:%i\n", linea++, d.conBrazos);
    printf("%03in:%i\n", linea++, d.conHombroIzq);
    printf("%03in:%i\n", linea++, d.conBrazoIzq);
    printf("%03in:%i\n", linea++, d.conAnteBrazoIzq);
    printf("%03in:%i\n", linea++, d.conManoIzq);
    printf("%03in:%i\n", linea++, d.conHombroDer);
    printf("%03in:%i\n", linea++, d.conBrazoDer);
    printf("%03in:%i\n", linea++, d.conAnteBrazoDer);
    printf("%03in:%i\n", linea++, d.conManoDer);
    printf("%03in:%i\n", linea++, d.blinBrazoIzq);
    printf("%03in:%i\n", linea++, d.blinTorsoIzq);
    printf("%03in:%i\n", linea++, d.blinPiernaIzq);
    printf("%03in:%i\n", linea++, d.blinPiernaDer);
    printf("%03in:%i\n", linea++, d.blinTorsoDer);
    printf("%03in:%i\n", linea++, d.blinBrazoDer);
    printf("%03in:%i\n", linea++, d.blinTorsoCen);
    printf("%03in:%i\n", linea++, d.blinCabeza);
    printf("%03in:%i\n", linea++, d.blinAtrasTorsoIzq);
    printf("%03in:%i\n", linea++, d.blinAtrasTorsoDer);
    printf("%03in:%i\n", linea++, d.blinAtrasTorsoCen);
    printf("%03in:%i\n", linea++, d.ptsEstIntBrazoIzq);
    printf("%03in:%i\n", linea++, d.ptsEstIntTorsoIzq);
    printf("%03in:%i\n", linea++, d.ptsEstIntPiernaIzq);
    printf("%03in:%i\n", linea++, d.ptsEstIntPiernaDer);
    printf("%03in:%i\n", linea++, d.ptsEstIntTorsoDer);
    printf("%03in:%i\n", linea++, d.ptsEstIntBrazoDer);
    printf("%03in:%i\n", linea++, d.ptsEstIntTorsoCen);
    printf("%03in:%i\n", linea++, d.ptsEstIntCabeza);
    printf("%03in:%i\n", linea++, d.numComponentes);
#endif

    d.componentes = (TComponente *) malloc(d.numComponentes * sizeof(TComponente));
    
    for(int i = 0; i < d.numComponentes; i++){
      d.componentes[i].codigo = readInteger( sbt );
      readNombre (sbt, d.componentes[i].nombre);
      d.componentes[i].clase = read_TClase(sbt);
      d.componentes[i].estaEnTrasera = readBoolean(sbt);
      d.componentes[i].locPrimaria = read_TLocDF(sbt);
      d.componentes[i].locSecundaria = read_TLocDF(sbt);
      d.componentes[i].tipoArma = read_TArma(sbt);
      d.componentes[i].calor = readInteger( sbt );
      d.componentes[i].danio = readInteger( sbt );
      d.componentes[i].disparosPorTurnos = readInteger( sbt );
      d.componentes[i].distMinima = readInteger( sbt );
      d.componentes[i].distCorta = readInteger( sbt );
      d.componentes[i].distMedia = readInteger( sbt );
      d.componentes[i].distLarga = readInteger( sbt );
      d.componentes[i].estaOperativo = readBoolean(sbt);
      d.componentes[i].codigoArma = readInteger( sbt );
      d.componentes[i].cantidad = readInteger( sbt );
      d.componentes[i].esMunicionEspecial = readBoolean(sbt);
      d.componentes[i].modiDisparo = readInteger( sbt );

#if defined (_DEBUG)
      printf("%03in:%i\n", linea++, d.componentes[i].codigo);
      printf("%03ic:%s\n", linea++, d.componentes[i].nombre);
      printf("%03in:%i\n", linea++, d.componentes[i].clase);
      printf("%03in:%i\n", linea++, d.componentes[i].estaEnTrasera);
      printf("%03in:%i\n", linea++, d.componentes[i].locPrimaria);
      printf("%03in:%i\n", linea++, d.componentes[i].locSecundaria);
      printf("%03in:%i\n", linea++, d.componentes[i].tipoArma);
      printf("%03in:%i\n", linea++, d.componentes[i].calor);
      printf("%03in:%i\n", linea++, d.componentes[i].danio);
      printf("%03in:%i\n", linea++, d.componentes[i].disparosPorTurnos);
      printf("%03in:%i\n", linea++, d.componentes[i].distMinima);
      printf("%03in:%i\n", linea++, d.componentes[i].distCorta);
      printf("%03in:%i\n", linea++, d.componentes[i].distMedia);
      printf("%03in:%i\n", linea++, d.componentes[i].distLarga);
      printf("%03in:%i\n", linea++, d.componentes[i].estaOperativo);
      printf("%03in:%i\n", linea++, d.componentes[i].codigoArma);
      printf("%03in:%i\n", linea++, d.componentes[i].cantidad);
      printf("%03in:%i\n", linea++, d.componentes[i].esMunicionEspecial);
      printf("%03in:%i\n", linea++, d.componentes[i].modiDisparo);
#endif
    }
    
    d.numArmas = readInteger(sbt);
    d.numActuadores = readInteger(sbt);

#if defined (_DEBUG)
    printf("%03in:%i\n", linea++, d.numArmas);
    printf("%03in:%i\n", linea++, d.numActuadores);
#endif

    d.actuadores = (TActuador *) malloc(d.numActuadores * sizeof(TActuador));
    
    for(int i = 0; i < d.numActuadores; i++){
      d.actuadores[i].codigo = readInteger(sbt);
      readNombre(sbt, d.actuadores[i].nombre);
      d.actuadores[i].loc = read_TLocDF(sbt);
      d.actuadores[i].estaOperativo = readBoolean(sbt);
      d.actuadores[i].numImpactos = readInteger(sbt);

#if defined (_DEBUG)
      printf("%03in:%i\n", linea++, d.actuadores[i].codigo);
      printf("%03ic:%s\n", linea++, d.actuadores[i].nombre);
      printf("%03in:%i\n", linea++, d.actuadores[i].loc);
      printf("%03in:%i\n", linea++, d.actuadores[i].estaOperativo);
      printf("%03in:%i\n", linea++, d.actuadores[i].numImpactos);
#endif
    }
    
    for(int i = 0; i <= 7; i++){
      d.loc[i].numSlotOcupados = readInteger(sbt);
#if defined (_DEBUG)
      printf("%03inumSlots:%i\n", linea++, d.loc[i].numSlotOcupados);
#endif      

      d.loc[i].slots = (TSlotOcupado *) malloc(d.loc[i].numSlotOcupados * sizeof(TSlotOcupado));
      
      for(int j = 0; j < d.loc[i].numSlotOcupados; j++){
	d.loc[i].slots[j].clase = read_TClase(sbt);
	d.loc[i].slots[j].cantidad = readInteger(sbt);
	d.loc[i].slots[j].codigo = readInteger(sbt);
	readNombre(sbt, d.loc[i].slots[j].nombre);
	d.loc[i].slots[j].indiceComponente = readInteger(sbt);
	d.loc[i].slots[j].indiceActuador = readInteger(sbt);
	d.loc[i].slots[j].dmgEnCasoCritico = readInteger(sbt);

#if defined (_DEBUG)
	printf("%03iclase:%i\n", linea++, d.loc[i].slots[j].clase);
	printf("%03icant:%i\n", linea++, d.loc[i].slots[j].cantidad);
	printf("%03icod:%i\n", linea++, d.loc[i].slots[j].codigo);
	printf("%03inom:%s\n", linea++, d.loc[i].slots[j].nombre);
	printf("%03iindCom:%i\n", linea++, d.loc[i].slots[j].indiceComponente);
	printf("%03iindAct:%i\n", linea++, d.loc[i].slots[j].indiceActuador);
	printf("%03idmg:%i\n", linea++, d.loc[i].slots[j].dmgEnCasoCritico);
#endif
      }
    }
    
    d.ptsMovAndando = readInteger(sbt);
    d.ptsMovCorriendo = readInteger(sbt);
    d.ptsMovSaltando = readInteger(sbt);
    d.tipoRadiadores = read_TRadiador(sbt);

#if defined (_DEBUG)
    printf("%03in:%i\n", linea++, d.ptsMovAndando);
    printf("%03in:%i\n", linea++, d.ptsMovCorriendo);
    printf("%03in:%i\n", linea++, d.ptsMovSaltando);
    printf("%03in:%i\n", linea++, d.tipoRadiadores);
    printf("------FIN READ TDEFMECH-----------\n");
#endif
  }

  fclose(sbt);
  
  return d;
}
示例#8
0
文件: Config.cpp 项目: luozy/fooking
bool Config::load(const char *filename)
{
	pState = luaL_newstate();
	if(luaL_dofile(pState, filename)){
		printf("parse config file error=%s\n", lua_tostring(pState, -1));
		return false;
	}
	
	//basic option
	sFile = filename;//file
	sHost = readString("HOST");//host
	nPort = readInt("PORT");//port
	bDaemonize = readBoolean("DAEMONIZE");
	sLogFile = readString("LOG_FILE");//log file
	nLogLevel = readInt("LOG_LEVEL");//log level
	bRouter = readBoolean("ROUTER");//router server
	
	//router == 1
	if(bRouter){
		return true;
	}
	
	//worker option
	nServerId = readInt("SERVER_ID");
	bEventConnect = readBoolean("EVENT_CONNECT");
	bEventClose = readBoolean("EVENT_CLOSE");
	nWorkers = readInt("WORKER_NUM");
	if(nWorkers < 1){
		printf("WORKER_NUM Invalid(WORKER_NUM>=1)\n");
		return false;
	}
	
	nMaxClients = readInt("MAX_CLIENT_NUM");
	if(nMaxClients < 1){
		printf("MAX_CLIENT_NUM Invalid(MAX_CLIENT_NUM>=1)\n");
		return false;
	}
	
	nSendBufferSize = readInt("SEND_BUFF_SIZE");
	if(nSendBufferSize < 1){
		printf("SEND_BUFF_SIZE Invalid(SEND_BUFF_SIZE>=1)\n");
		return false;
	}
	
	nRecvBufferSize = readInt("RECV_BUFF_SIZE");
	if(nRecvBufferSize < 1){
		printf("RECV_BUFF_SIZE Invalid(RECV_BUFF_SIZE>=1)\n");
		return false;
	}
	
	//暂时只能fastcgi
	nProtocol = readInt("PROTOCOL");
	
	//backend server list
	nBackendTimeout = readInt("BACKEND_TIMEOUT");
	lua_getglobal(pState, "BACKEND_SERVER");
	if(lua_isstring(pState, -1)){
		const char *val = lua_tostring(pState, -1);
		if(!addBackendServer(val, 1)){
			printf("BACKEND_SERVER Invalid\n");
			return false;
		}
	}else if(lua_istable(pState, -1)){
		lua_pushnil(pState);
		while(lua_next(pState, -2))
		{
			const char *str = NULL;
			int weight = 0;
			if(lua_isstring(pState, -2)){
				str = lua_tostring(pState, -2);
			}
			if(lua_isnumber(pState, -1)){
				weight = lua_tonumber(pState, -1);;
			}
			if(str && weight > 0){
				if(!addBackendServer(str, weight)){
					printf("BACKEND_SERVER Invalid\n");
					return false;
				}
			}
			lua_pop(pState, 1);
		}
		lua_pop(pState, 1);
	}else{
		printf("BACKEND_SERVER invalid\n");
		return false;
	}
	
	//router option
	sScriptFile = readString("SCRIPT_FILE");
	sRouterHost = readString("ROUTER_HOST");
	nRouterPort = readInt("ROUTER_PORT");
	
	//fastcgi
	sFastcgiRoot = readString("FASTCGI_ROOT");
	sFastcgiFile = readString("FASTCGI_FILE");
	
	//fastcgi params
	lua_getglobal(pState, "FASTCGI_PARAMS");
	if(lua_istable(pState, -1)){
		lua_pushnil(pState);
		while(lua_next(pState, -2))
		{
			const char *key = NULL;
			const char *val = NULL;
			if(lua_isstring(pState, -2)){
				key = lua_tostring(pState, -2);
			}
			if(lua_isstring(pState, -1)){
				val = lua_tostring(pState, -1);
			}
			if(key && val){
				arFastcgiParams[key] = val;
			}
			lua_pop(pState, 1);
		}
		lua_pop(pState, 1);
	}else{
		printf("FASTCGI_PARAMS invalid\n");
		return false;
	}
	
	return true;
}