Esempio n. 1
0
int parse(xmlDocPtr xml_doc, const xmlChar* xpathExpr) {
    xmlXPathContextPtr xpathCtx; 
    xmlXPathObjectPtr xpathObj; 
    
    assert(xml_doc);
    assert(xpathExpr);

    /* Create xpath evaluation context */
    if (! (xpathCtx = xmlXPathNewContext(xml_doc))) {
        printf("Failed to create new XPath context\n"); 
        return -1;
    }
    
    /* Evaluate xpath expression */
    if (! (xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx))) {
        printf("Failed to evaluate xpath expression \"%s\"\n", xpathExpr);
        xmlXPathFreeContext(xpathCtx); 
        return -1;
    }
    
    /* update selected nodes */
    parse_nodes(xpathObj->nodesetval);

    /* Cleanup of XPath data */
    xmlXPathFreeObject(xpathObj);
    xmlXPathFreeContext(xpathCtx); 
    
    return(0);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	char *node_names[argc - 1];
	int opt, count = 0;

	progname = argv[0];
	while ((opt = getopt_long(argc, argv, "-n:P:p:vd", long_options, NULL)) != -1) {
		switch(opt) {
		case 1:  /* node */
			node_names[count++] = optarg;
			break;

		case 2:  /* --sctp */
			dlm_protocol = PROTO_SCTP;
			break;

		case 'd':  /* --debug */
			debug = true;
			break;

		case 'n':  /* --cluster-name */
			cluster_name = optarg;
			break;

		case 'P': /* --fakedlm-port */
			fakedlm_port = atol(optarg);
			break;

		case 'p':  /* --dlm-port */
			dlm_port = atol(optarg);
			break;

		case 'v':  /* --verbose */
			verbose = true;
			break;

		case '?':  /*  bad option */
			usage(2);
		}
	}
	if (count == 0)
		usage(0);

	parse_nodes(node_names, count);
	setup_signals();
	if (all_nodes & (all_nodes - 1)) {
		/* More than one bit set in all_nodes. */
		listen_to_peers();
		connect_to_peers();
	}
	monitor_kernel();
	listen_to_uvents();
	configure_dlm();
	event_loop();
	remove_dlm();
	return 0;
}
Esempio n. 3
0
bool
VskBase::parse_line(
    VskString& text,
    VskLineNo *lineno,
    shared_ptr<VskStmtsNode>& stmts,
    VskTokenNodes& nodes)
{
    assert(lineno != NULL);

    // delete blank at the beginning and the ending of line
    katahiromz::trim(text, " \t");

    // do nothing if empty
    if (text.empty()) {
        return true;
    }

    // lexical analyse
    lex_line(text, nodes);
    text = vsk_text_from_nodes(nodes);

    // pick up the line number if necessary
    if ((*lineno == 0) && vsk_isdigit(text[0])) {
        *lineno = VskLineNo(atoi(text.c_str()));
        nodes.erase(nodes.begin());
        text = vsk_text_from_nodes(nodes);
        if (nodes.size()) {
            auto& str = nodes.front()->m_text;
            if (str[0] == ' ') {
                str.erase(str.begin());
            }
        }
        if (text.size()) {
            if (text[0] == ' ') {
                text.erase(text.begin());
            }
        }
    }

    VskTokenNodes new_nodes;
    trim_nodes(new_nodes, nodes);
    new_nodes.emplace_back(make_shared<VskTokenNode>(TK_eof));

    // parse nodes
    if (!parse_nodes(new_nodes, stmts)) {
        // Syntax error
        do_error(2, *lineno);
#ifndef NDEBUG
        auto text = vsk_debug_text_from_nodes(new_nodes);
        std::cout << text << std::endl;
#endif
        return false;
    }

    return true;
} // VskBase::parse_line
/**
 * topo: An array of strings, the maximum length is 5000
 * edge_num: The number of elements in topo
 * demand: The demand
 */
void search_route(char* topo[5000], int edge_num, char* demand) {
    struct path* paths;
    struct node nodes[MAX_NODE_NUMBERS] = {};
    unsigned int start_index, end_index, via_nodes_count;

    paths = (struct path*) malloc(edge_num * sizeof(struct path));
    parse_paths(topo, (unsigned int) edge_num, paths, nodes);
    parse_nodes((unsigned int) edge_num, paths);
    parse_demand(demand, nodes, &start_index, &end_index, &via_nodes_count);

    perform_actual_search((unsigned int) edge_num, &nodes[start_index], &nodes[end_index], via_nodes_count);

    free(paths);
}
pvm_config_env *pvm_parser_open(char *p_hostfile, int verbose, int full)
{
    int i = 0;
    /* setup defaults */
    s_pvm_conf.p_pvm_hosts = NULL;
    /* XXX: add more defaults? */
    /* get user data */
    parse_config(p_hostfile, full);
    /* get node data */
    i = parse_nodes(p_hostfile, nodes_num);
    /* get lists */
    if (full) {
        parse_filelist(p_hostfile);
    }
    /* then validate it */
    return validate(i, verbose);
}
Esempio n. 6
0
struct Fiber * dataset_list (char * file,const char sep,int numline){
    struct Fiber * dl= malloc(sizeof(struct Fiber));

    char ** lines=NULL;
    lines=parse_nodes(file,numline);
    if(lines==NULL){
     printf("lines parsing error\n");
     exit(0);
    }
    char ** dl_keys=NULL;
    char ** dl_values=NULL;
    dl_keys=(char **)malloc(sizeof(char *)*numline);
    if (dl_keys==NULL)  {
     printf("dl_keys allocation error\n");
     exit(0);
    }
    dl_values=(char **)malloc(sizeof(char *)*numline);
    if (dl_values==NULL)  {
     printf("dl_values allocation error\n");
     exit(0);
    }
    dl->count=bufi;
    int i;
    for (i=0;i<bufi;i++){
      char ** tokens=NULL;
      tokens=str_split(lines[i],sep);
      if(tokens==NULL) {
       printf("tokens memory error\n");
       exit(0);
      }
      dl_keys[i]=(char *)malloc(strlen(tokens[0])+1);
      dl_values[i]=(char *)malloc(strlen(tokens[1])+1);
      if(dl_keys[i]==NULL || dl_values[i]==NULL){
       printf("dl keys element allocate error\n");
      }
      strcpy(dl_keys[i],tokens[0]);
      strcpy(dl_values[i],tokens[1]);
    }
    dl->keys=dl_keys;
    dl->values=dl_values;
    bufi=0;
    if(lines!=NULL) free(lines);
    return dl;
}
Esempio n. 7
0
void Test::test_sub(const char *nodes_str, const char *qids_str, int count_req, const char *expected_str, int expected_return)
{
	Nodes result_nodes;
	Nodes nodes = parse_nodes(nodes_str);
	Qids qids = parse_qids(qids_str);

	{
		AutoSelect autosel;
		int result = autosel.detect(result_nodes, nodes, qids, count_req);
		ASSERT_EQUAL(expected_return, result);
		ASSERT_EQUAL(expected_return, count_overlap_kid(result_nodes));
	}
	{
		std::vector<int> expected = parse_int_array(expected_str);
		int i = 0;
		for (Qids::const_iterator qi = qids.begin(); qi != qids.end(); ++qi, ++i) {
			Qid qid = *qi;
			ASSERT_EQUAL(expected[i], count_per_qid(result_nodes, qid));
		}
	}
}
Esempio n. 8
0
struct Catalog * catalog_list (char * file,const char sep,int numline){
    struct Catalog * dl= malloc(sizeof(struct Catalog));
    if(dl==NULL){
      printf("catalog dl mem err\n");
      exit(0);
    }
    char ** lines=parse_nodes(file,numline);
    if(lines==NULL){
     printf("lines parsing error\n");
     exit(0);
    }
    char ** dl_plate_mjd=NULL;
    hsize_t * dl_fiber_id=NULL;
    char ** dl_filepath=NULL;
    hsize_t * dl_fiber_offset=NULL;
    hsize_t * dl_fiber_local_length=NULL;
    dl_plate_mjd=(char **)malloc(sizeof(char *)*(numline+1));
    if (dl_plate_mjd==NULL)  {
     printf("dl_platemjd allocation error\n");
     exit(0);
    }
    dl_fiber_id=(hsize_t *)malloc(sizeof(hsize_t)*(numline+1));
    if (dl_fiber_id==NULL)  {
     printf("dl_fiber_id allocation error\n");
     exit(0);
    }
    dl_filepath=(char **)malloc(sizeof(char *)*(numline+1));
    if (dl_filepath==NULL)  {
     printf("dl_filepath allocation error\n");
     exit(0);
    }
    dl_fiber_offset=(hsize_t *)malloc(sizeof(hsize_t)*(numline+1));
    if (dl_fiber_offset==NULL)  {
     printf("dl_fiber_offset allocation error\n");
     exit(0);
    }
    dl_fiber_local_length=(hsize_t *)malloc(sizeof(hsize_t)*(numline+1));
    if (dl_fiber_local_length==NULL)  {
     printf("dl_fiber_local_length allocation error\n");
     exit(0);
    }
    dl->count=bufi;
    int i;
    for (i=0;i<bufi;i++){
      char ** tokens=str_split(lines[i],sep);
      dl_plate_mjd[i]=(char *)malloc(strlen(tokens[0])+1);
      if(dl_plate_mjd[i]==NULL){
        printf("dl_plate_mjd mem err\n");
        exit(0);
       }

     dl_filepath[i]=(char *)malloc(strlen(tokens[2])+1);
      if(dl_filepath[i]==NULL){
        printf("dl_filepath mem err\n");
        exit(0);
       }
     strcpy(dl_plate_mjd[i],tokens[0]);
     dl_fiber_id[i]=atoll(tokens[1]);
     strcpy(dl_filepath[i],tokens[2]);
     dl_fiber_offset[i]=atoll(tokens[3]);
     dl_fiber_local_length[i]=atoll(tokens[4]);
    }
    if(lines!=NULL) free(lines);
    dl->plate_mjd=dl_plate_mjd;
    dl->fiberid=dl_fiber_id;
    dl->filepath=dl_filepath;
    dl->fiber_gstart=dl_fiber_offset;
    dl->fiber_llength=dl_fiber_local_length;
    bufi=0;
    return dl;
}
/* ************************************************** */
int do_configuration(void) {
    xmlSchemaValidCtxtPtr sv_ctxt = NULL;
    xmlSchemaParserCtxtPtr sp_ctxt = NULL;
    xmlSchemaPtr schema = NULL;
    xmlParserCtxtPtr p_ctxt = NULL;
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xp_ctx = NULL; 
    xmlXPathObjectPtr simul_xobj = NULL;
    xmlXPathObjectPtr entity_xobj = NULL; 
    xmlXPathObjectPtr environment_xobj = NULL; 
    xmlXPathObjectPtr bundle_xobj = NULL; 
    xmlXPathObjectPtr node_xobj = NULL; 
    xmlNodeSetPtr nodeset;
    xmlpathobj_t xpathobj[] = {{&simul_xobj, (xmlChar *) XML_X_SIMULATION}, 
                               {&entity_xobj, (xmlChar *) XML_X_ENTITY},
                               {&environment_xobj, (xmlChar *) XML_X_ENVIRONMENT},
                               {&bundle_xobj, (xmlChar *) XML_X_BUNDLE},
                               {&node_xobj, (xmlChar *) XML_X_NODE}};
    int ok = 0, i;

    /* Check XML version */
    LIBXML_TEST_VERSION;
        
    /* Initialise and parse schema */
    sp_ctxt = xmlSchemaNewParserCtxt(schemafile);
    if (sp_ctxt == NULL) {
        fprintf(stderr, "config: XML schema parser initialisation failure (do_configuration())\n");
        ok = -1;
        goto cleanup;
    }
    xmlSchemaSetParserErrors(sp_ctxt,
                             (xmlSchemaValidityErrorFunc)   xml_error,
                             (xmlSchemaValidityWarningFunc) xml_warning,
                             NULL);
    
    schema = xmlSchemaParse(sp_ctxt);
    if (schema == NULL) {
        fprintf(stderr, "config: error in schema %s (do_configuration())\n", schemafile);
        ok = -1;
        goto cleanup;
    }
    xmlSchemaSetValidErrors(sv_ctxt,
                            (xmlSchemaValidityErrorFunc)   xml_error,
                            (xmlSchemaValidityWarningFunc) xml_warning,
                            NULL);
    
    sv_ctxt = xmlSchemaNewValidCtxt(schema);
    if (sv_ctxt == NULL) {
        fprintf(stderr, "config: XML schema validator initialisation failure (do_configuration())\n");
        ok = -1;
        goto cleanup;
    }
    
    /* Initialise and parse document */
    p_ctxt = xmlNewParserCtxt();
    if (p_ctxt == NULL) {
        fprintf(stderr, "config: XML parser initialisation failure (do_configuration())\n");
        ok = -1;
        goto cleanup;
    }
    
    doc = xmlCtxtReadFile(p_ctxt, configfile, NULL, XML_PARSE_NONET | XML_PARSE_NOBLANKS | XML_PARSE_NSCLEAN);
    if (doc == NULL) {
        fprintf(stderr, "config: failed to parse %s (do_configuration())\n", configfile);
        ok = -1;
        goto cleanup;
    }

    /* Validate document */
    if (xmlSchemaValidateDoc(sv_ctxt, doc)) {
        fprintf(stderr, "config: error in configuration file %s (do_configuration())\n", configfile);
        ok = -1;
        goto cleanup;
    }
    
    /* Create xpath context */
    xp_ctx = xmlXPathNewContext(doc);
    if (xp_ctx == NULL) {
        fprintf(stderr, "config: XPath initialisation failure (do_configuration())\n");
        ok = -1;
        goto cleanup;
    }
    xmlXPathRegisterNs(xp_ctx, (xmlChar *) XML_NS_ID, (xmlChar *) XML_NS_URL); 
    
    
    /* Get xpath obj */
    for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) {
        *xpathobj[i].ptr = xmlXPathEvalExpression(xpathobj[i].expr, xp_ctx);
        if (*xpathobj[i].ptr == NULL) {
            fprintf(stderr, "config: unable to evaluate xpath \"%s\" (do_configuration())\n", xpathobj[i].expr);
            ok = -1;
            goto cleanup;
            
        }
    }

    /***************/
    /* Counting... */
    /***************/
    nodeset = entity_xobj->nodesetval;
    if ((entities.size = (nodeset) ? nodeset->nodeNr : 0) == 0) {
        fprintf(stderr, "config: no entity defined (do_configuration())\n");
        ok = -1; 
        goto cleanup;
    }
    fprintf(stderr, "\nFound %d entities...\n", entities.size);
    nodeset = environment_xobj->nodesetval;
    if (((nodeset) ? nodeset->nodeNr : 0) == 0) {
        fprintf(stderr, "config: no environment defined (do_configuration())\n");
        ok = -1; 
        goto cleanup;
    }
    fprintf(stderr, "Found 1 environment...\n");
    nodeset = bundle_xobj->nodesetval;
    if ((bundles.size = (nodeset) ? nodeset->nodeNr : 0) == 0) {
        fprintf(stderr, "config: no bundle defined (do_configuration())\n");
        ok = -1; 
        goto cleanup;
    }
    fprintf(stderr, "Found %d bundles...\n", bundles.size);
    

    if ((dflt_params = das_create()) == NULL) {
        ok = -1; 
        goto cleanup;
    }

    /**************/
    /* Simulation */
    /**************/
    if (parse_simulation(simul_xobj->nodesetval)) {
        ok = -1;
        goto cleanup;
    }
                                                          
    /**********/
    /* Entity */
    /**********/
    /* initialize library paths */
    config_set_usr_modulesdir();
    user_path_list = g_strsplit(user_modulesdir, ":", 0); /* TOCLEAN */
    sys_path_list = g_strsplit(sys_modulesdir, ":", 0); /* TOCLEAN */

    /* parse */
    if (parse_entities(entity_xobj->nodesetval)) {
        ok = -1;
        goto cleanup;
    }

    /**************/
    /* Measure    */
    /**************/
    if (parse_measure()) {
        ok = -1;
        goto cleanup;
    }

    /***************/
    /* Environment */
    /***************/
    if (parse_environment(environment_xobj->nodesetval)) {
        ok = -1;
        goto cleanup;
    }
    
    /***************/
    /* Bundle      */
    /***************/
    if (parse_bundles(bundle_xobj->nodesetval)) {
        ok = -1;
        goto cleanup;
    }

    /***************/
    /* Nodes      */
    /***************/
    if (parse_nodes(node_xobj->nodesetval)) {
        ok = -1;
        goto cleanup;
    }
 
    /* edit by Quentin Lampin <*****@*****.**> */
    gchar **path = NULL;
    for (path = user_path_list ; *path ; path++) {
        g_free(*path);
    }
    path = NULL;
    for (path = sys_path_list  ; *path ; path++) {
        g_free(*path);
    }
    /* end of edition */

 cleanup:
    clean_params();
    
    for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) {
        xmlXPathFreeObject(*xpathobj[i].ptr);
    }

    if (xp_ctx) {
        xmlXPathFreeContext(xp_ctx);
    }

    if (sp_ctxt) {
        xmlSchemaFreeParserCtxt(sp_ctxt);		
    }

    if (schema) {
        xmlSchemaFree(schema);
    }

    if (sv_ctxt) {
        xmlSchemaFreeValidCtxt(sv_ctxt);
    }

    if (doc) {
        xmlFreeDoc(doc);
    }

    if (p_ctxt) {
        xmlFreeParserCtxt(p_ctxt);
    }

    xmlCleanupParser();
    return ok;
}