Esempio n. 1
0
void parse (char* sData, long nDataLen) {
	SimpleXmlParser parser= simpleXmlCreateParser(sData, nDataLen);
	if (parser == NULL) {
		fprintf(stderr, "couldn't create parser");
		return;
	}
	if (simpleXmlParse(parser, handler) != 0) {
		fprintf(stderr, "parse error on line %li:\n%s\n", 
			simpleXmlGetLineNumber(parser), simpleXmlGetErrorDescription(parser));
	}
}
Esempio n. 2
0
/* ---- example xml handler */
void* handler (SimpleXmlParser parser, SimpleXmlEvent event, 
	const char* szName, const char* szAttribute, const char* szValue)
{
	static int nDepth= 0;
	char *tmp;
	char szHandlerName[32];
	char szHandlerAttribute[32];
	char *szHandlerValue;
	//struct socket_data *news;
	//struct core_data *newc;
	//struct thread_data *newt;
	int last_cid=0;

	szHandlerValue=malloc(32);
	memset(szHandlerValue,0,32);

	if (szName != NULL) {
		trim(szName, szHandlerName);
	}
	if (szAttribute != NULL) {
		trim(szAttribute, szHandlerAttribute);
	}
	if (szValue != NULL) {
		trim(szValue, szHandlerValue);
	}

	if (event == ADD_SUBTAG) {
		fprintf(stderr,"depth: %d, val: %s\n",nDepth,szHandlerName);
		fprintf(stderr, "%6li: %s add subtag (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
		nDepth++;
	} else if (event == ADD_ATTRIBUTE) {
//		printf("attribute tag:%s %s=%s\n",szHandlerName, szHandlerAttribute, szHandlerValue);
		fprintf(stderr, "%6li: %s ///add attribute to tag %s ([%s]=[%s])\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName, szHandlerAttribute, szHandlerValue);

		if ( (!strcmp(szHandlerAttribute,"cache-level")) && (!strcmp(szHandlerValue,"3")) ) {
			//attribute cache-level=3 detected: new L3 domain
			fprintf(stderr,"\n* NEW SOCKET *\n");
			new_socket(last_sid,last_sid);
			push_socket_id(last_sid);
			last_sid++;
			level=3;
		}

		if ( (!strcmp(szHandlerAttribute,"name")) && (!strcmp(szHandlerValue,"SMT")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n       * NEW CORE, Sock %d *     \n", last_sid - 1);
			//uncomment for noSMP:
			//level=10;

			//ucomment for SMP:
			last_cid=pop_core_id();
			new_core(0,last_cid,last_sid - 1);
		} else if ( (!strcmp(szHandlerAttribute,"name")) && (!strcmp(szHandlerValue,"THREAD")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n* NEW THREAD, Sock %d *\n", last_sid - 1);
			last_cid=pop_core_id();
			new_thread(0,last_cid,last_sid - 1);
		}

		if ( (!strcmp(szHandlerAttribute,"level")) && (!strcmp(szHandlerValue,"3")) ) {
			//no cpu count="2"/SMT/THREAD Routing!
			level=300;
		} else if ( (!strcmp(szHandlerAttribute,"level")) && (!strcmp(szHandlerValue,"2")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n* !NEW LOGICAL CORE %d!, Sock: %d*\n", last_cid,last_sid - 1);
			//We have "cpu count="2" and SMT/THREAD flag name
			level=200;
		}

	} else if (event == ADD_CONTENT) {
		fprintf(stderr,"depth: %d, LEVEL %d, context for:[%s] [%s]\n",nDepth,level,szHandlerName, szHandlerValue);

		if (level==200) {
			if (!strcmp(szHandlerName,"cpu")) {
				fprintf(stderr,"  !ROUTE LEVEL 10: Cores ID processed: %s, SOCKET: %d\n",szHandlerValue, last_sid - 1 );
				while ((tmp = strsep(&szHandlerValue, ",")) != NULL) {
					if (tmp[0] == '\0')
						break; /* XXX */
					trim_spaces(tmp);
// comment for no SMP?
					push_core_id(atoi(tmp));
					fprintf(stderr,"\n\n\nHA: [%d]\n\n\n",atoi(tmp));
// uncomment for no SMP:
//					last_cid=pop_core_id();
//					new_core(0,atoi(tmp),last_sid - 1);
				}
			// drop level
//			level=9;
			}
		} else if (level==300) {
		//no cpu count="2"/SMT/THREAD Routing!
			if (!strcmp(szHandlerName,"cpu")) {
				fprintf(stderr,"  !ROUTE LEVEL 10: Cores ID processed: %s, SOCKET: %d\n",szHandlerValue, last_sid - 1 );
				while ((tmp = strsep(&szHandlerValue, ",")) != NULL) {
					if (tmp[0] == '\0')
						break; /* XXX */
					trim_spaces(tmp);
// comment for no SMP?
					push_core_id(atoi(tmp));
					fprintf(stderr,"\n\n\nHA: [%d]\n\n\n",atoi(tmp));
// uncomment for no SMP:
					last_cid=pop_core_id();
					new_core(0,atoi(tmp),last_sid - 1);
				}
			// drop level
//			level=9;
			}
		}

		fprintf(stderr, "%6li: %s add content to tag %s (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName, szHandlerValue);
	} else if (event == FINISH_ATTRIBUTES) {
		fprintf(stderr,"finish for:%s\n",szHandlerName);
		fprintf(stderr, "%6li: %s finish attributes (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
	} else if (event == FINISH_TAG) {
		fprintf(stderr,"finish for:%s\n",szHandlerName);
		fprintf(stderr, "%6li: %s finish tag (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
		nDepth--;
		if (level==10) {
			if (!strcmp(szHandlerName,"cpu"))
				level=0;
		}
	}

	//list_sockets();
	return handler;
}
Esempio n. 3
0
/*!
 * \brief
 * Loads a tileset from a Tiled .tsx file
 *
 * \param filename
 * TSX file to load
 *
 * \returns
 * Reference to the newly loaded tileset or NULL if error
 *
 * \remarks
 * An associated palette is also created, it can be obtained calling TLN_GetTilesetPalette()
 */
TLN_Tileset TLN_LoadTileset (char *filename)
{
    SimpleXmlParser parser;
    size_t size;
    BYTE *data;
    TLN_Tileset tileset;
    TLN_Bitmap bitmap;
    int htiles, vtiles;
    int x,y,dx,dy;
    int id;
    int pitch;

    /* load file */
    data = LoadFile (filename, &size);
    if (!data)
        return NULL;

    /* parse */
    memset (&loader, 0, sizeof(loader));
    parser = simpleXmlCreateParser (data, (long)size);
    if (parser != NULL)
    {
        if (simpleXmlParse(parser, handler) != 0)
        {
            printf("parse error on line %li:\n%s\n",
                   simpleXmlGetLineNumber(parser), simpleXmlGetErrorDescription(parser));
            free (data);
            return NULL;
        }
    }
    free (data);

    /* check filename */
    if (!loader.source[0])
        return NULL;

    /* load picture */
    bitmap = TLN_LoadBitmap (loader.source);
    if (!bitmap)
        return NULL;

    /* create tileset */
    dx = loader.tilewidth + loader.spacing;
    dy = loader.tileheight + loader.spacing;
    htiles = (TLN_GetBitmapWidth(bitmap) - loader.margin*2 + loader.spacing) / dx;
    vtiles = (TLN_GetBitmapHeight(bitmap) - loader.margin*2 + loader.spacing) / dy;
    tileset = TLN_CreateTileset (htiles*vtiles, loader.tilewidth, loader.tileheight, TLN_ClonePalette(TLN_GetBitmapPalette(bitmap)));
    pitch = TLN_GetBitmapPitch (bitmap);

    /* load tiles */
    for (id=1, y=0; y<vtiles; y++)
    {
        for (x=0; x<htiles; x++, id++)
        {
            BYTE *srcptr = TLN_GetBitmapPtr (bitmap, loader.margin + x*dx, loader.margin + y*dy);
            TLN_SetTilesetPixels (tileset, id, srcptr, pitch);
        }
    }

    TLN_DeleteBitmap (bitmap);

    return tileset;
}