示例#1
0
int main(int argc, char ** argv)
{
	int nb, len, ram;
	char input[128] = "test-1200K.xml";

	if(argc < 2)	{
		printf("no input file use '%s'\n", input);
	} else	{
		strncpy(input, argv[1], 128);
	}

	FILE * f = fopen(input, "r");
	if(f)	{
		fseek(f, 0, SEEK_END);
		len = ftell(f);
		fclose(f);
	} else	{
		printf("input file doesnt exist\n");
		return 1;
	}

	node_t *root = roxml_load_doc(input);

	int pgsize = 0;
	int size = 0;
	int resident = 0;
	int share = 0;
	int text = 0;
	int lib = 0;
	int data = 0;
	int dt = 0;
	char statfile[512];
	sprintf(statfile, "/proc/%d/statm", getpid());
	FILE * fstatfile = fopen(statfile, "r");
	if(fstatfile)   {
		fscanf(fstatfile, "%d %d %d %d %d %d %d", &size, &resident, &share, &text, &lib, &data, &dt);
		fclose(fstatfile);
	}
	pgsize = getpagesize();
	ram = pgsize*resident;

	node_t ** set = roxml_xpath(root, "//*", &nb);

	roxml_release(set);
	roxml_close(root);

	printf("stats for '%s':\n", input);
	printf("\tload_doc: %d bytes\n", len);
	printf("\txpath processed %d nodes\n", nb);
	printf("\ttotal node:\t\t\t %u\n",_nb_node);
	printf("\ttotal attr:\t\t\t %u\n",_nb_attr);
	printf("\ttotal text:\t\t\t %u\n",_nb_text);
	printf("\tram tree:\t\t\t %lu bytes\n",(long unsigned int)sizeof(node_t)*(_nb_node+_nb_attr+_nb_text));
	printf("\tram total:\t\t\t %d bytes\n",ram);
	printf("\tram ratio:\t\t\t %f\n",(float)(sizeof(node_t)*(_nb_node+_nb_attr+_nb_text))/(float)len);

	return 0;
}
示例#2
0
int XHCP_loadConfig (node_t* argXmlConfig)
{
    node_t **result;
    int nb_result;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    char *xhcp_fileName;
    
    printf ("Loading XHCP server configuration...\n");
    
    if ( (xhcp_fileName = XHCP_getConfigFile ()) != NULL )
        domConfig = roxml_load_doc (xhcp_fileName);
    else if ( argXmlConfig != NULL )
        domConfig = argXmlConfig;
    else
        Error_Quit ("Unable to find XHCP configuration");
    
    
    /* Time Out */
    result = roxml_xpath ( domConfig, "//XHCPserver/ConnectionTimeOut[@delay]", &nb_result);
    if ( nb_result == 1 )
    {
        char *zaza = roxml_get_content ( roxml_get_attr (result[0], "delay", 0), buffer, XHCP_BUFFER_SZ, &sz_buffer );
        XHCP_connexionTimeOut = atoi (zaza);
        
        if ( XHCP_connexionTimeOut <= 0 )
            XHCP_connexionTimeOut=2;
    }
    else if ( nb_result == 0)
    {
        XHCP_connexionTimeOut = 5;
    }
    else
        Error_Quit ("Erroe parsing XHCP config file (ConnectionTimeOut)");
    
    roxml_release (RELEASE_LAST);
    printf ("XHCP_connexionTimeOut = %d\n", XHCP_connexionTimeOut);
    
    
    return 0;
}
示例#3
0
int xcf_creator(int argc, char *project_path) {
	FILE* actor_src;
	int j, k, n,size_of_config, size_of_partitioning, size_of_partition, size_of_papi, len, actor_num, number_of_actions, number_of_events;
	int num = 0;
	node_t *configuration, *partitioning, *partition, *instance, *papi, *actor_instance, *action, *event;
	char *actor_path;

	char *mapping_file_path;

	if ((mapping_file_path = findMappingFile(project_path)) == NULL) {
		printf("Unable to locate a mapping file, make sure you are using the root path to the RVC CAL generated code with the C backend\n");
		exit(1);
	}

	int actors_num = get_actors_num(mapping_file_path);

	configuration = roxml_load_doc(mapping_file_path); //a: LIBROXML node http://www.libroxml.net/public-api.html
	if (configuration == NULL) {
		printf("I/O error when reading mapping file.\n");
		exit(1);
	}
	node_t *papi_root_node = roxml_add_node(configuration, 0, ROXML_ELM_NODE, "Papi", NULL);
	node_t *papi_instance_node, *papi_action_node, *papi_event_node;

	size_of_config = roxml_get_chld_nb(configuration); //a: This function return the number of children for a given node

	if(DEBUG)printf("Found %d configuration\n", size_of_config);


	partitioning = roxml_get_chld(configuration, NULL, 0); //a: This function returns a given child of a node either by name, or the nth child. (node, child name, number of the child to get)
	size_of_partitioning = roxml_get_chld_nb(partitioning); //a: This function return the number of children for a given node
	if(DEBUG)printf("	Found %d partitionings\n", size_of_partitioning);
	for (j = 0; j < size_of_partitioning; j++) {
		partition = roxml_get_chld(partitioning, NULL, j);
		if(DEBUG)printf("		Found partition, id = '%s'\n", roxml_get_content(roxml_get_attr(partition, "id", 0), NULL, 0, &len));
		size_of_partition = roxml_get_chld_nb(partition);
		for (k = 0; k < size_of_partition; k++) {
			instance = roxml_get_chld(partition, NULL, k);
			if(DEBUG)printf("			Found instance, id = '%s'\n", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			papi_instance_node = roxml_add_node(papi_root_node, 0, ROXML_ELM_NODE, "Instance", NULL);
			roxml_add_node(papi_instance_node, 0, ROXML_ATTR_NODE, "id", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));

			//this goes for every action in the actor:
			actor_path = malloc(strlen(project_path)+strlen(roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len))+10);
			strcpy(actor_path,project_path);
			actor_path = strcat(actor_path,"/src/");
			actor_path = strcat(actor_path,roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			actor_path = strcat(actor_path,".c");
			printf("opening %s\n", actor_path);
			actor_src = fopen(actor_path,"r");
			put_actions(actor_src, papi_instance_node, papi_action_node, papi_event_node);
			fclose(actor_src);
		}
	}

	char *mapping_file_cpy = malloc(strlen(mapping_file_path)+strlen(".papi.xcf")+1);

	strcpy(mapping_file_cpy, mapping_file_path);
	strcat(mapping_file_cpy, ".papi.xcf");



	//tmp = roxml_add_node(tmp, 0, ROXML_ELM_NODE, "price", "24");
	roxml_commit_changes(configuration, mapping_file_cpy, NULL, 1);
	//roxml_close(configuration);


	// release the last allocated buffer even if no pointer is maintained by the user
	roxml_release(RELEASE_LAST);
	// here no memory leak can occur.
	roxml_close(configuration);


	return 0;
}
示例#4
0
/*
 * public interface
 */
clish_xmldoc_t *clish_xmldoc_read(const char *filename)
{
	node_t *doc = roxml_load_doc((char*)filename);
	return node_to_xmldoc(doc);
}
示例#5
0
int main(int ac, char *av[])
{
	node_t 			*doc;
	char			*xmlname = NULL;
	char			*xpquery = NULL;
	node_t 			**xpr = NULL;
	int 			opt = 0;
	int 			longopt = 0;
	int			flags = 0;

	/* getopt_long() should not display any message */
	opterr = 0; 

	while ((opt = getopt_long(ac, av, short_options, long_options, &longopt)) != -1) {
		switch (opt) {
		case 0:
			/*
			long option encountered
			we should not see any of them, because they are supposed to
			map to the corresponding short option. So if we get this, it
			might indicate that something is borked.
			*/
			break;
		case 1:
			/* not an option */
			if (!xmlname) {
				xmlname = strdup(av[optind-1]);
			} else if (!xpquery) {
				xpquery = strdup(av[optind-1]);
			} else {
				fprintf(stderr, "too many non-option - remove '%s'\n", av[optind - 1]);
				return EXIT_FAILURE;
			}
			break;
		case 'h':
			display_usage(av[0]);
			return EXIT_FAILURE;
		case 'q':
			flags |= ROCAT_FLAG_QUIET;
			break;
		case '?':
			fprintf(stderr, "unknown option '%s'\n", av[optind - 1]);
			return EXIT_FAILURE;
		default:
			break;
		}
	}

	if (!xmlname) {
		if ((flags & ROCAT_FLAG_QUIET) == 0) {
			fprintf(stderr, "invalid options: no XML file name\n\n");
			display_usage(av[0]);
		}
		return EXIT_FAILURE;
	}

	doc = roxml_load_doc(xmlname);
	if (!doc) {
		if ((flags & ROCAT_FLAG_QUIET) == 0)
			fprintf(stderr, "failed to load XML file '%s'\n", xmlname);
		goto on_error;
	}

	if (xpquery) {
		int xncount;

		xpr = roxml_xpath(doc, xpquery, &xncount);
		if (!xpr) {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' failed on '%s'\n", 
					xpquery, xmlname);
			goto on_error;
		}

		if (xncount) {
			int npos; 
			
			for (npos = 0; npos < xncount; ++npos) {
				char *buffer = NULL;
				node_t *xn = xpr[npos];;
				/* commit the node to stdout */
				roxml_commit_changes(xn, NULL, &buffer, 1);
				printf("%s\n", buffer);
				free(buffer);
			}
		} else {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' does not yield to any result\n", 
					xpquery);
			goto on_error;
		}

		roxml_release(xpr);

		free(xpquery);
	} else {
		char *buffer = NULL;
		/* commit everything to stdout */
		roxml_commit_changes(doc, NULL, &buffer, 1);
		printf("%s\n", buffer);
		free(buffer);
	}

	roxml_close(doc);

	free(xmlname);

	return EXIT_SUCCESS;

on_error:
	if (xpr) {
		roxml_release(xpr);
	}
	if (doc) roxml_close(doc);
	if (xmlname) free(xmlname);
	if (xpquery) free(xpquery);

	return EXIT_FAILURE;
}