static void stats_fillState(stats_state *my_state, char *query, int query_len) {
	char* arg = 0;

	while (1) {
		arg = strtok_r(query, "&", &query);
		if (!arg)
			break;
		if (strstr(arg, "application=")) {
			arg = arg + strlen("application=");
			my_state->globals = parseGlobals(arg, &my_state->globals_cnt);
		} else if (strstr(arg, "inf.name=")) {
			my_state->interfaceName = arg + strlen("inf.name=");
		} else if(strstr(arg, "record.types=")) {
			my_state->recordTypes = strtol(arg + strlen("record.types="), NULL, 16);
		}
	}
}
Beispiel #2
0
void Opa::update()
{
    if (port < 0) return;
    int size = OPA_RXBUFFER_LEN - rxLen;
    rxLen += comRead(port, &rxBuffer[rxLen], size);

// Check for reception
    if (programParamReturn && rxLen >= 4)
        parseProgramParameter();
    if (kitParamReturn && rxLen >= 4)
        parseKitParameter();
    if (programReturn && rxLen >= 4 + sizeof(OpaProgram))
        parseProgram();
    if (kitReturn && rxLen >= 3 + sizeof(OpaKit))
        parseKit();
    if (globalsReturn && rxLen >= 3 + sizeof(OpaGlobals))
        parseGlobals();

// Expected nothing
    if (!isWaiting())
        rxLen = 0;
}
XMLScene::XMLScene(char *filename, GlobalData &globals, Graph &graphScene)
{

	// Read XML from file

	doc=new TiXmlDocument( filename );
	bool loadOkay = doc->LoadFile();

	if ( !loadOkay )
	{
		printf( "Could not load file '%s'. Error='%s'. Exiting.\n", filename, doc->ErrorDesc() );
		exit( 1 );
	}

	TiXmlElement* anfElement= doc->FirstChildElement( "anf" );

	if (anfElement == NULL)
	{
		printf("Main anf block element not found! Exiting!\n");
		exit(1);
	}

	globalsElement = anfElement->FirstChildElement( "globals" );
	cameraElement = anfElement->FirstChildElement("cameras");
	lightElement = anfElement->FirstChildElement("lights");
	textureElement = anfElement->FirstChildElement("textures");
	appearanceElement = anfElement->FirstChildElement("appearances");
	graphElement = anfElement->FirstChildElement("graph");
	animsElement = anfElement->FirstChildElement("animations");

	parseGlobals(globals);
	parseCameras(graphScene);
	parseLights(graphScene);
	parseTextures(graphScene);
	parseAppearances(graphScene);
	parseAnimations(graphScene);
	parseGraph(graphScene);
}
Beispiel #4
0
void MDAL::LoaderGdal::parseRasterBands( const MDAL::GdalDataset *cfGDALDataset )
{
  for ( unsigned int i = 1; i <= cfGDALDataset->mNBands; ++i ) // starts with 1 .... ehm....
  {
    // Get Band
    GDALRasterBandH gdalBand = GDALGetRasterBand( cfGDALDataset->mHDataset, static_cast<int>( i ) );
    if ( !gdalBand )
    {
      throw MDAL_Status::Err_InvalidData;
    }

    // Reference time
    metadata_hash global_metadata = parseMetadata( cfGDALDataset->mHDataset );
    parseGlobals( global_metadata );

    // Get metadata
    metadata_hash metadata = parseMetadata( gdalBand );

    std::string band_name;
    double time = std::numeric_limits<double>::min();
    bool is_vector;
    bool is_x;
    if ( parseBandInfo( cfGDALDataset, metadata, band_name, &time, &is_vector, &is_x ) )
    {
      continue;
    }

    // Add to data structures
    std::vector<GDALRasterBandH>::size_type data_count = is_vector ? 2 : 1;
    std::vector<GDALRasterBandH>::size_type data_index = is_x ? 0 : 1;
    if ( mBands.find( band_name ) == mBands.end() )
    {
      // this Face is not yet added at all
      // => create new map
      timestep_map qMap;
      std::vector<GDALRasterBandH> raster_bands( data_count );

      raster_bands[data_index] = gdalBand;
      qMap[time] = raster_bands;
      mBands[band_name] = qMap;

    }
    else
    {
      timestep_map::iterator timestep = mBands[band_name].find( time );
      if ( timestep == mBands[band_name].end() )
      {
        // Face is there, but new timestep
        // => create just new map entry
        std::vector<GDALRasterBandH> raster_bands( data_count );
        raster_bands[data_index] = gdalBand;
        mBands[band_name][time] = raster_bands;

      }
      else
      {
        // Face is there, and timestep too, this must be other part
        // of the existing vector
        timestep->second[data_index] = gdalBand;
      }
    }
  }
}
Beispiel #5
0
extern int parseFile (FILE *fp, Font_Info **fi, FLAGS flags)
{
    
    int code = AFM_ok; 	/* return code from each of the parsing routines */
    int error = AFM_ok;	/* used as the return code from this function */
    
    register char *keyword; /* used to store a token */	 
    
   			      
    /* storage data for the global variable ident */			      
    if (!ident)
	 ident = (char *) calloc(MAX_NAME, sizeof(char)); 
    if (ident == NULL) {error = AFM_storageProblem; return(error);}      
  
    (*fi) = (Font_Info *) calloc(1, sizeof(Font_Info));
    if ((*fi) == NULL) {error = AFM_storageProblem; return(error);}      
  
    if (flags & P_G) 
    {
        (*fi)->gfi = (GlobalFontInfo *) calloc(1, sizeof(GlobalFontInfo));
        if ((*fi)->gfi == NULL) {error = AFM_storageProblem; return(error);}      
    }
    
    /* The AFM File begins with Global Font Information. This section */
    /* will be parsed whether or not information should be saved. */     
    code = parseGlobals(fp, (*fi)->gfi); 
    
    if (code < 0) error = code;
    
    /* The Global Font Information is followed by the Character Metrics */
    /* section. Which procedure is used to parse this section depends on */
    /* how much information should be saved. If all of the metrics info */
    /* is wanted, parseCharMetrics is called. If only the character widths */
    /* is wanted, parseCharWidths is called. parseCharWidths will also */
    /* be called in the case that no character data is to be saved, just */
    /* to parse through the section. */
  
    if ((code != normalEOF) && (code != AFM_earlyEOF))
    {
        (*fi)->numOfChars = atoi(token(fp));
	    if (flags & (P_M ^ P_W))
        {
            (*fi)->cmi = (CharMetricInfo *) 
                      calloc((*fi)->numOfChars, sizeof(CharMetricInfo));
           if ((*fi)->cmi == NULL) {error = AFM_storageProblem; return(error);}
            code = parseCharMetrics(fp, *fi);             
        }
        else
        {
            if (flags & P_W)
            { 
                (*fi)->cwi = (int *) calloc(256, sizeof(int)); 
                if ((*fi)->cwi == NULL) 
                {
                	error = AFM_storageProblem; 
                	return(error);
                }
            }
            /* parse section regardless */
            code = parseCharWidths(fp, (*fi)->cwi);
        } /* else */
    } /* if */
    
    if ((error != AFM_earlyEOF) && (code < 0)) error = code;
    
    /* The remaining sections of the AFM are optional. This code will */
    /* look at the next keyword in the file to determine what section */
    /* is next, and then allocate the appropriate amount of storage */
    /* for the data (if the data is to be saved) and call the */
    /* appropriate parsing routine to parse the section. */
    
    while ((code != normalEOF) && (code != AFM_earlyEOF))
    {
        keyword = token(fp);
        if (keyword == NULL)
          /* Have reached an early and unexpected EOF. */
          /* Set flag and stop parsing */
        {
            code = AFM_earlyEOF;
            break; /* get out of loop */
        }
        switch(recognize(keyword))
        {
            case STARTKERNDATA:
                break;
            case ENDKERNDATA:
                break;
            case STARTTRACKKERN:
                keyword = token(fp);
                if (flags & P_T)
                {
                    (*fi)->numOfTracks = atoi(keyword);
                    (*fi)->tkd = (TrackKernData *) 
                        calloc((*fi)->numOfTracks, sizeof(TrackKernData));
                    if ((*fi)->tkd == NULL) 
                    {
                    	error = AFM_storageProblem; 
                    	return(error);
                    }
                } /* if */
                code = parseTrackKernData(fp, *fi);
                break;
            case STARTKERNPAIRS:
                keyword = token(fp);
                if (flags & P_P)
                {
                    (*fi)->numOfPairs = atoi(keyword);
                    (*fi)->pkd = (PairKernData *) 
                        calloc((*fi)->numOfPairs, sizeof(PairKernData));
                    if ((*fi)->pkd == NULL) 
                    {
                    	error = AFM_storageProblem; 
                    	return(error);
                    }
                } /* if */
                code = parsePairKernData(fp, *fi);
                break;
            case STARTCOMPOSITES:
                keyword = token(fp);
                if (flags & P_C)
                { 
                    (*fi)->numOfComps = atoi(keyword);
                    (*fi)->ccd = (CompCharData *) 
                        calloc((*fi)->numOfComps, sizeof(CompCharData));
                    if ((*fi)->ccd == NULL) 
                    {
                    	error = AFM_storageProblem; 
                    	return(error);
                    }
                } /* if */
                code = parseCompCharData(fp, *fi); 
                break;    
            case ENDFONTMETRICS:
                code = normalEOF;
                break;
            case NOPE:
            default:
                code = AFM_parseError;
                break;
        } /* switch */
        
        if ((error != AFM_earlyEOF) && (code < 0)) error = code;
        
    } /* while */
  
    if ((error != AFM_earlyEOF) && (code < 0)) error = code;
    
    if (ident != NULL) { free(ident); ident = NULL; }
        
    return(error);
  
} /* parseFile */
bool ANFparser::parse(Scene * scene,const char* filename){
	this->scene = scene;

	try{
		TiXmlDocument * doc = new TiXmlDocument(filename);

		//First things first, reading the XML/ANF file
		if (!doc->LoadFile()){
			issue("Could not load file '%"+str(filename)+"'. Error='" + str(doc->ErrorDesc()) + "'.", ERROR);
		}

		//Must exist anf root block
		TiXmlElement* anfRoot = doc->FirstChildElement("anf");
		if (!anfRoot){
			issue("Main block 'anf' block not found!",ERROR);
		}

		//Lets process the global variables
		TiXmlElement* anfGlobals = anfRoot->FirstChildElement("globals");
		if(!anfGlobals){
			issue("Block 'globals' not found!",WARNING);
		}else{
			parseGlobals(anfGlobals);
		}
		
		//Lets process the cameras
		TiXmlElement* anfCameras = anfRoot->FirstChildElement("cameras");
		if(!anfCameras){
			issue("Block 'cameras' not found!",ERROR);
		}else{
			std::string firstCameraId = str(anfCameras->Attribute("initial"));
			if(firstCameraId == "" ){
				issue("Cameras block must declare the first camera.. ", WARNING);
			}
			parseCameras(anfCameras,firstCameraId);
		}

		//Lets process the lights
		TiXmlElement* anfLights = anfRoot->FirstChildElement("lights");
		if(!anfLights){
			issue("Block 'lights' not found!",WARNING);
		}else{
			parseLights(anfLights);
		}

		//If textures extist, we process it
		TiXmlElement* anfTextures = anfRoot->FirstChildElement("textures");
		map<std::string,Texture *> textures;
		if(!anfTextures){
			issue("Block 'textures' not found!",WARNING);
		}else{
			parseTextures(anfTextures,textures);
		}


		//If appearances block exist, we call its parser
		TiXmlElement* anfAppearances = anfRoot->FirstChildElement("appearances");
		map<std::string,Appearance *> appearances;
		if(!anfAppearances){
			issue("Block 'appearances' not found!",WARNING);
		}else{
			parseAppearances(anfAppearances,appearances,textures);
		}
		
		//If animations extist, we process it
		TiXmlElement* anfAnimations = anfRoot->FirstChildElement("animations");
		map<std::string,Animation *> animations;
		if(!anfAnimations){
			issue("Block 'animations' not found!",WARNING);
		}else{
			parseAnimations(anfAnimations,animations);
		}


		//If graph block exist, we call its parser
		TiXmlElement* anfGraph = anfRoot->FirstChildElement("graph");
		if(!anfGraph){
			issue("Block 'graph' not found!",ERROR);
		}else{
			this->scene->setRoot(parseGraph(anfGraph,appearances,animations));
		}

		return true; 
	}catch(...){
		return false;
	}
}