コード例 #1
0
ファイル: plot.c プロジェクト: eliasah/ComplexNetworks
int main(int argc,char** argv) {
    if (argc < 2) {
	printf("USAGE %s file.distribution\n", argv[0]);
	exit(1);
    }

    if (verbose == 1) printf("plot - %s -\n",argv[1]);
    char* arg1 = prepare_output_file(argv[1]);
    char* arg2 = prepare_to_plot(argv[1]);
    char* commandsForGnuplot[] = {"set logscale xy",
				  "set terminal pdf",
				  arg1,
				  arg2 };
    FILE* gnuplotPipe = popen ("gnuplot -persistent", "w");
    int i;    
    for (i=0; i < NUM_COMMANDS; i++) {
	fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
    }
    if (verbose == 1) printf("end plot\n");
    return 0;
}
コード例 #2
0
/**
 * \brief Storage plugin initialization.
 *
 * Initialize IPFIX storage plugin. This function allocates, fills and
 * returns config structure.
 *
 * \param[in] params parameters for this storage plugin
 * \param[out] config the plugin specific configuration structure
 * \return 0 on success, negative value otherwise
 */
int storage_init(char *params, void **config)
{
	struct ipfix_config *conf;

	xmlDocPtr doc;
	xmlNodePtr cur;

	time_t t;
	struct tm tm;

 	/* allocate space for config structure */
	conf = (struct ipfix_config *) malloc(sizeof(*conf));
	if (conf == NULL) {
		MSG_ERROR(msg_module, "Not enough memory (%s:%d)", __FILE__, __LINE__);
		return -1;
	}
	memset(conf, '\0', sizeof(*conf));

	/* try to parse configuration file */
	doc = xmlReadMemory(params, strlen(params), "nobase.xml", NULL, 0);
	if (doc == NULL) {
		MSG_ERROR(msg_module, "Plugin configuration not parsed successfully");
		goto err_init;
	}
	cur = xmlDocGetRootElement(doc);
	if (cur == NULL) {
		MSG_ERROR(msg_module, "Empty configuration");
		goto err_init;
	}
	if (xmlStrcmp(cur->name, (const xmlChar *) "fileWriter")) {
		MSG_ERROR(msg_module, "Root node != fileWriter");
		goto err_init;
	}
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		/* find out where to store output files */
		if ((!xmlStrcmp(cur->name, (const xmlChar *) "file"))) {
			conf->xml_file = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			break;
		}
		cur = cur->next;
	}

	/* check whether we have found "file" element in configuration file */
	if (conf->xml_file == NULL) {
		MSG_ERROR(msg_module, "Configuration file doesn't specify where "
		                        "to store output files (\"file\" element "
								"is missing)");
		goto err_init;
	}

	/* we only support local files */
	if (strncmp((char *) conf->xml_file, "file:", 5)) {
		MSG_ERROR(msg_module, "Element \"file\": invalid URI - "
								"only allowed scheme is \"file:\"");
		goto err_init;
	}

	/* output file path + timestamp */
	uint16_t path_len = strlen((char *) conf->xml_file) + 13;
	conf->file = (char *) malloc(path_len);
	if (conf->file == NULL) {
		MSG_ERROR(msg_module, "Not enough memory (%s:%d)", __FILE__, __LINE__);
		goto err_init;
	}
	memset(conf->file, 0, path_len);

	/* copy file path, skip "file:" at the beginning of the URI */
	strncpy_safe(conf->file, (char *) conf->xml_file + 5, path_len);

	/* add timestamp at the end of the file name */
	memset(&tm, 0, sizeof(tm));
	t = time(NULL);

	localtime_r(&t, &tm);

	strftime(conf->file+strlen((char *) conf->file), 14, ".%y%m%d%H%M%S", &tm);
	/* conf->file now looks like: "/path/to/file.1109131509" */

	prepare_output_file(conf);

	/* we don't need this xml tree anymore */
	xmlFreeDoc(doc);

	*config = conf;

	return 0;


err_init:
	free(conf);
	return -1;
}