コード例 #1
0
ファイル: task_scheduler.cpp プロジェクト: dimaleks/uDeviceX
void TaskScheduler::saveDependencyGraph_GraphML(std::string fname) const
{
    pugi::xml_document doc;
    auto root = doc.append_child("graphml");

    root.append_attribute("xmlns")              = "http://graphml.graphdrawing.org/xmlns";
    root.append_attribute("xmlns:xsi")          = "http://www.w3.org/2001/XMLSchema-instance";
    root.append_attribute("xsi:schemaLocation") = "http://graphml.graphdrawing.org/xmlns "
                                                  "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd";

    auto key = root.append_child("key");
    key.append_attribute("id")        = "label";
    key.append_attribute("for")       = "node";
    key.append_attribute("attr.name") = "label";
    key.append_attribute("attr.type") = "string";

    auto graph = root.append_child("graph");
    graph.append_attribute("id")          = "Task graph";
    graph.append_attribute("edgedefault") = "directed";

    // Nodes
    for (const auto& t : tasks)
        add_node(graph, t.id, t.label);

    // Edges
    for (const auto& n : nodes) {
        for (auto dep : n->to)
            add_edge(graph, n->id, dep->id);

        for (auto dep : n->from_backup)
            add_edge(graph, dep->id, n->id);
    }

    auto filename = fname + ".graphml";    
    doc.save_file(filename.c_str());
}
コード例 #2
0
ファイル: minc2.c プロジェクト: AhmedAMohamed/graphviz
/*
  creates temporary nodes to the graph , 
  if hasLabels is true (1) all ranks are doubled and every edge is splitted to 2
*/
static void addNodes(Agraph_t * g, int hasLabels)
{
    Agnode_t *v;
    Agedge_t *e;
    Agedge_t *ee = NULL;
    Agedge_t **eList = NULL;		/*for technical reasons i add dummy edges after the loop */
    int tempEdgeCnt = 0;
    int id = 0;

    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
	int type = MND_type(v);
	if (type != STDNODE)
	    continue;
	for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
	    if (MED_type(e) == VIRTUAL)
		continue;
	    eList = RALLOC(tempEdgeCnt + 1, eList, Agedge_t *);
	    eList[tempEdgeCnt] = e;
	    tempEdgeCnt++;
	}
    }
    for (id = 0; id < tempEdgeCnt; id++)
	add_node(g, eList[id], hasLabels);

    /*delete long edges */
    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
	for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
	    if (ee)
		agdelete(g, ee);
	    if (MED_deleteFlag(e) == 1)
		ee = e;
	    else
		ee = NULL;
	}
    }
}
コード例 #3
0
ファイル: network.cpp プロジェクト: gandalfvn/EOH
void NETWORK::generate_random_graph( int _order, int _size, std::vector<double> &_weights )
{
  for(int i=0; i<Order; i++)
    delete Nodes[i];
  Nodes.clear();
  Order = 0;
  Size = 0;

  for(int i=0; i<_order; i++)
    add_node();
  int source, target;
  int edges_left = _size;
  while( edges_left > 0 )
  {
    source = Ran.IRandom( 0, _order-1 );
    target = Ran.IRandom( 0, _order-1 );
    if( !is_there_edge(source, target) && source != target )
    {
      add_edge( source, target, _weights.back() );
      edges_left--;
      _weights.pop_back();
    }
  }
}
コード例 #4
0
ファイル: profiler_vm.cpp プロジェクト: BRIMIL01/rubinius
  void Profiler::results(Env* env, rtable profile, rtable nodes, rtable methods,
                         KeyMap& keys, uint64_t runtime)
  {

    current_me_->stop_all(this, env);

    WorkList work;

    // If we haven't even gone for a total of longer than 10x the threshold,
    // just disable the threshold.
    if(runtime < 10 * threshold_) threshold_ = 0;

    env->table_store(profile, env->symbol("total_nodes"), env->integer_new(nodes_));

    rarray roots = env->array_new(root_->count_sub_nodes());
    env->table_store(profile, env->symbol("roots"), roots);

    int idx = 0;
    Node* sub = root_->sub_nodes();

    while(sub) {
      if(sub->total() >= threshold_) {
        env->array_set(roots, idx++, env->integer_new(sub->id()));
        work.push_back(sub);
      }

      sub = sub->sibling();
    }

    while(work.size() > 0) {
      Node* node = work.back();
      work.pop_back();

      add_node(env, nodes, methods, node, work, keys, threshold_);
    }
  }
コード例 #5
0
int main(int argc, char *argv[])
{
    int count = atoi(argv[1]);
    link temp = NULL;
    link new_node = NULL;
    link head = (node*)malloc(sizeof(node));

    head->next = NULL;
    head->item = -1;

    temp = head;

    for (int loop = 0; loop < count; ++loop)
    {
        new_node = add_node(loop);
        temp->next = new_node;
        temp = temp->next;
    }

    link reversed_link = reverse_link(head);
    release_link(reversed_link);

    return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: ktneale/binary_search_trees
int main()
{
    //Definition of BST starts here!
    node_t * root = create_node(5);

    //Add subsequent nodes here.
    node_t * new_node;

	new_node = create_node(6);
	add_node(root,new_node);

	new_node = create_node(4);
	add_node(root,new_node);

	new_node = create_node(1);
	add_node(root,new_node);

	new_node = create_node(8);
	add_node(root,new_node);

	new_node = create_node(2);
	add_node(root,new_node);

	new_node = create_node(17);
	add_node(root,new_node);

    //Transverse the BST using 3 'Depth First' approaches.
    printf("\npre-order [START]\n");
    pre_order(root);
    printf("pre-order [END]\n");

    printf("\nin-order [START]\n");
    in_order(root);
    printf("in-order [END]\n");

    printf("\npost-order [START]\n");
    post_order(root);
    printf("post-order [END]\n\n");

    return 0;
}
コード例 #7
0
ファイル: list_tests.c プロジェクト: Ataginsky/datalgo
bool test_remove_dups2() {
  
  node_t *head = NULL;
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 2);
  add_node(&head, 2);
  add_node(&head, 1);

  
  
  
  remove_list_dups2(head);
  
  assert(list_len(head) == 2);
  
  //traverse_node(head, print_node);
  
  return list_len(head) == 2;
  
  
}
コード例 #8
0
ファイル: lib_multifeed.c プロジェクト: alkap007/ali3606
/*
 * get one feed's detail information and fill to feed node
 * some info such as tp info, can't find in database, we have to retreive from nit
 */
static void fill_feed_detail_info(struct FEED_INFO *info, UINT32 sat_id, UINT32 prog_id)
{
	INT32 ret = MULTIFEED_FAILURE, ret2 = MULTIFEED_FAILURE;
	T_NODE t_node;
	P_NODE p_node, p_node2;
	P_NODE *feed_pnode;
	DB_VIEW *last_view;
	UINT16 last_filter_mode, i;
	UINT32 last_view_param;

	get_prog_by_id(prog_id, &p_node);

	// first check db whether has the infomation
	ret = find_tp_in_db(sat_id, info->original_network_id, info->transport_stream_id, &t_node);

	if(ret != MULTIFEED_SUCCESS)
	{
		// if already got the nit, then search the buffer, and update to db
		ret = search_node( multifeed_table_buff, 1024, info->original_network_id, info->transport_stream_id, &t_node);
		
		if( ret!=MULTIFEED_SUCCESS )
		{
			// not recieve nit data yet, so request nit data
			ret = find_tp_in_nit(info->original_network_id, info->transport_stream_id, &t_node);
		}
		
		if(ret == MULTIFEED_SUCCESS)
		{
			last_view			=	(DB_VIEW *)get_cur_view();
			last_filter_mode	=	last_view->cur_filter_mode;
			last_view_param		=	last_view->view_param;
			if(last_view->cur_type==TYPE_PROG_NODE)
			{
				recreate_tp_view(VIEW_ALL ,0);
				ret = add_node(TYPE_TP_NODE, sat_id, (void*)&t_node);
				if(ret == SUCCESS)
					update_data();
				recreate_prog_view(last_filter_mode, last_view_param);
			}
			else
			{
				ret = add_node(TYPE_TP_NODE, sat_id, (void*)&t_node);
				if(ret == SUCCESS)
					update_data();			
			}
		}
	}

	// maybe the subfeed is one of the channels, and that channel 
	// maybe locked by parent, so we have to get this information
	if( p_node.prog_number != info->service_id )
	{
		i = 0;
		while(SUCCESS == get_prog_at(i, &p_node2))
		{
			if(( p_node2.tp_id == t_node.tp_id ) && ( p_node2.prog_number == info->service_id ))
			{
				mf_debug("feed: (%s, sid: %d) is Channel: %s\n", \
							info->name, info->service_id, p_node2.service_name );
				ret2 = MULTIFEED_SUCCESS;
				break;
			}
			i++;
		}
	}
	if(ret == SUCCESS)
	{
		info->is_known	=	1;
		feed_pnode		=	&(info->p_node);
		
		MEMCPY(feed_pnode, &p_node, sizeof(P_NODE));
		feed_pnode->tp_id			=	t_node.tp_id;
		feed_pnode->prog_number		=	info->service_id;
		if( ret2 != MULTIFEED_SUCCESS)
		{
			feed_pnode->pmt_pid		=	0x1FFF;
			feed_pnode->audio_count	=	1;
			feed_pnode->audio_pid[0]=	feed_pnode->pcr_pid = feed_pnode->video_pid = 0x1FFF;
		}
		else
		{
			feed_pnode->av_flag		=	p_node2.av_flag;
			feed_pnode->ca_mode		=	p_node2.ca_mode;
			feed_pnode->video_pid	=	p_node2.video_pid;
			feed_pnode->pcr_pid		=	p_node2.pcr_pid;
			feed_pnode->h264_flag	=	p_node2.h264_flag;
			feed_pnode->pmt_pid		=	p_node2.pmt_pid;
			feed_pnode->pmt_version	=	p_node2.pmt_version;
			feed_pnode->service_type=	p_node2.service_type;
			feed_pnode->audio_channel=	p_node2.audio_channel;
			feed_pnode->audio_select=	p_node2.audio_select;
			feed_pnode->lock_flag	=	p_node2.lock_flag;// parent lock
			feed_pnode->audio_count	=	p_node2.audio_count;
			MEMCPY( feed_pnode->audio_pid, p_node2.audio_pid, sizeof(UINT16)*MAX_AUDIO_CNT );
			MEMCPY( feed_pnode->audio_lang, p_node2.audio_lang, sizeof(UINT16)*MAX_AUDIO_CNT );
		}
		mf_debug("feed: tp_id: %d, frq: %d\n", feed_pnode->tp_id, t_node.frq );
	}
}
コード例 #9
0
ファイル: arg.c プロジェクト: dsholla/rdp1_6
void arg_numeric(char key, char * description, unsigned long * unsignedvalue)
{
  add_node(ARG_NUMERIC, key, description, 0, unsignedvalue, NULL); 
}
コード例 #10
0
ファイル: arg.c プロジェクト: dsholla/rdp1_6
void arg_message(char * description)
{
  add_node(ARG_BLANK, '\0', description, 0, 0, NULL); 
}
コード例 #11
0
ファイル: ipc.c プロジェクト: Dany3R9/Proj
int
process_hello(int size, olsr_u8_t vtime, union olsr_ip_addr *originator, union hello_message *m)
{
  struct hellinfo *neigh;
  struct hellinfo6 *neigh6;
  int i;
  int nsize;
  int type;
  //int link;

  printf("Processing HELLO from %s size = %d\n", ip_to_string(originator), size);

  if (!update_timer_node(originator, vtime))
    add_node(originator, vtime);

  /* Add neighbors if any */
  size = size - 4 - 8 - ipsize; /* size of neighbors(size - olsrheder- helloheader) */

  if (!size)
    return 0;

  /* Get the neighbortype-blocks start */
  neigh = m->v4.hell_info;
  neigh6 = m->v6.hell_info;

  //printf("HELLO Size: %d\n", size);

  while (size > 0) {

    //printf("\tNEIGH: 0x%x\n", (int)neigh);
    if (ipversion == AF_INET) {
      nsize = ntohs(neigh->size);
      type = EXTRACT_STATUS(ntohs(neigh->link_code));
      //link = EXTRACT_LINK(ntohs(neigh->link_code));
      //printf("TYPE: %d\n", neigh->link_code);
    } else {
      nsize = ntohs(neigh6->size);
      type = EXTRACT_STATUS(ntohs(neigh6->link_code));
      //link = EXTRACT_LINK(ntohs(neigh6->link_code));
    }

    size -= nsize;

    nsize = nsize - 4;          /* - hellinfo header */
    //printf("Size left: %d Current hellinfo: %d\n", size, nsize);
    i = 0;
    while (nsize > 0) {
      //printf("Adding neighbor %s...\n", ip_to_string((union olsr_ip_addr *)&neigh->neigh_addr[i]));
      /*
         if(MPR)
         update_timer_mpr((union olsr_ip_addr *)&mprsinfo->addr, originator);
       */

      if (ipversion == AF_INET) {       /* Update MPRs */
        if (type == MPR_NEIGH) {
          //printf("MPR from HELLO\n");
          update_timer_mpr((union olsr_ip_addr *)&neigh->neigh_addr[i], originator, vtime);
        }
        add_node((union olsr_ip_addr *)&neigh->neigh_addr[i++], vtime);
      } else {
        if (type == MPR_NEIGH) {        /* Update MPRs */
          //printf("MPR from HELLO\n");
          update_timer_mpr((union olsr_ip_addr *)&neigh6->neigh_addr[i], originator, vtime);
        }
        add_node((union olsr_ip_addr *)&neigh6->neigh_addr[i++], vtime);
      }

      nsize = nsize - ipsize;
      //printf("Nsize: %d\n", nsize);
    }

    neigh = (struct hellinfo *)&neigh->neigh_addr[i];
    neigh6 = (struct hellinfo6 *)&neigh6->neigh_addr[i];

  }
  //printf("DONE\n");

  return 0;
}
コード例 #12
0
ファイル: xt_geoip.c プロジェクト: 3sOx/asuswrt-merlin
static int xt_geoip_mt_checkentry(const struct xt_mtchk_param *par)
{
   
   struct xt_geoip_match_info *info = par->matchinfo;
   struct geoip_info *node;
   u_int8_t i;

   /* FIXME:   Call a function to free userspace allocated memory.
    *          As Martin J. said; this match might eat lot of memory
    *          if commited with iptables-restore --noflush
   void (*gfree)(struct geoip_info *oldmem);
   gfree = info->fini;
   */

   /* If info->refcount isn't NULL, then
    * it means that checkentry() already
    * initialized this entry. Increase a
    * refcount to prevent destroy() of
    * this entry. */
   if (info->refcount != NULL) {
      atomic_inc((atomic_t *)info->refcount);
      return 0;
   }
   
   
   for (i = 0; i < info->count; i++) {
     
      if ((node = find_node(info->cc[i])) != NULL)
            atomic_inc((atomic_t *)&node->ref);   //increase the reference
      else
         if ((node = add_node(info->mem[i])) == NULL) {
            printk(KERN_ERR
                  "xt_geoip: unable to load '%c%c' into memory\n",
                  COUNTRY(info->cc[i]));
            return -ENOMEM;
         }

      /* Free userspace allocated memory for that country.
       * FIXME:   It's a bit odd to call this function everytime
       *          we process a country.  Would be nice to call
       *          it once after all countries've been processed.
       *          - SJ
       * *not implemented for now*
      gfree(info->mem[i]);
      */

      /* Overwrite the now-useless pointer info->mem[i] with
       * a pointer to the node's kernelspace structure.
       * This avoids searching for a node in the match() and
       * destroy() functions.
       */
      info->mem[i] = node;
   }

   /* We allocate some memory and give info->refcount a pointer
    * to this memory.  This prevents checkentry() from increasing a refcount
    * different from the one used by destroy().
    * For explanation, see http://www.mail-archive.com/[email protected]/msg00625.html
    */
   info->refcount = kmalloc(sizeof(u_int8_t), GFP_KERNEL);
   if (info->refcount == NULL) {
      printk(KERN_ERR "xt_geoip: failed to allocate `refcount' memory\n");
      return -ENOMEM;
   }
   *(info->refcount) = 1;
   
   return 0;
}
コード例 #13
0
ファイル: sgraph.cpp プロジェクト: JehandadKhan/roccc-2.0
void SGraph::add_nodes_from_sgraph(const SGraph *SGraph) {
  for (SNodeIter iter(SGraph->get_node_iterator());
       !iter.done(); iter.increment()) {
    add_node(iter.get());
  }
}
コード例 #14
0
ファイル: update_history.cpp プロジェクト: sedna/sedna
void update_history::add_insert_node(const xptr node)
{
	add_node(ut_insert, node);
}
コード例 #15
0
ファイル: bulk_adapt_ops.C プロジェクト: davidheryanto/sc14
void BulkAdapt::handle_split_3D(int remotePartID, int pos, int tableID, adaptAdj elem, 
				RegionID lockRegionID, int n1_idxl, int n2_idxl, int n5_idxl)
{
  int n1 = get_node_from_idxl(n1_idxl, remotePartID), 
    n2 = get_node_from_idxl(n2_idxl, remotePartID), 
    n5;

  if (is_node_in_idxl(n5_idxl, remotePartID)) {
    n5 = get_node_from_idxl(n5_idxl, remotePartID);
  }
  else {
    FEM_DataAttribute *coord = meshPtr->node.getCoord(); // all local coords
    double *n0co = (coord->getDouble()).getRow(n1);
    double *n1co = (coord->getDouble()).getRow(n2);
    double nodeCoords[9];
    nodeCoords[0] = n0co[0];
    nodeCoords[1] = n0co[1];
    nodeCoords[2] = n0co[2];
    nodeCoords[3] = n1co[0];
    nodeCoords[4] = n1co[1];
    nodeCoords[5] = n1co[2];
    midpoint(&(nodeCoords[0]), &(nodeCoords[3]), 3, &(nodeCoords[6]));
    n5 = add_node(3, &(nodeCoords[6]));  
    
    // Find the relative nodes on the edge to be bisected
    int relNodes[4]; 
    FEM_Elem &elems = meshPtr->elem[elem.elemType]; // elems is all local elements
    int *conn = elems.connFor(elem.localID); // conn points at elemID's ACTUAL data!
    
    fillNodes(relNodes, n1, n2, conn);
    // find which edgeID is bisected
    int edgeID = getEdgeID(relNodes[0], relNodes[1], 4, 3);
    
    // find elements on edge to be bisected
    int numElemsToLock = 0;
    adaptAdj *elemsToLock;
    get_elemsToLock(elem, &elemsToLock, edgeID, &numElemsToLock);
    
    // find chunks that share the edge to be bisected
    int *chunks = (int *)malloc(numElemsToLock*sizeof(int));
    int numParts=0;
    for (int i=0; i<numElemsToLock; i++) {
      chunks[i] = -1;
      int j;
      for (j=0; j<numParts; j++) {
	if (chunks[j] == elemsToLock[i].partID) {
	  break;
	}
      }
      chunks[j] = elemsToLock[i].partID;
      if (j==numParts) numParts++;
    }
    
    if (numParts > 1)
      make_node_shared(n5, numParts, &chunks[0]);
    
    free(chunks);
    free(elemsToLock);
  }

  adaptAdj *splitElem = local_split_3D(elem, n1, n2, n5);
  shadowProxy[remotePartID].recv_split_3D(pos, tableID, elem, *splitElem);
  delete splitElem;
}
コード例 #16
0
ファイル: dynamic_cfg.cpp プロジェクト: kumarmadhukar/2ls
void dynamic_cfgt::build_cfg(
  const goto_programt &goto_program,
  const ssa_local_unwindert &ssa_unwinder)
{
  std::vector<unsigned> iteration_stack;
  std::vector<node_indext> loop_node_stack;
  std::vector<unsigned> max_iteration_stack;
  std::map<goto_programt::const_targett,
           std::set<node_indext> > incoming_edges;

  forall_goto_program_instructions(it, goto_program)
  {
    node_indext node=add_node();
    nodes[node].id.pc=it;
    nodes[node].id.iteration_stack=iteration_stack;
    nodes[node].is_loop_head=false;
    nodes[node].assumption=nil_exprt();

    // this is the end of a loop
    //   (sink self-loops are translated into assume false in the SSA)
    if(it->is_backwards_goto() &&
       it->get_target()!=it)
    {
#if 0
      // Sanity checks
      const ssa_local_unwindert::loopt *loop=nullptr;
      if(!ssa_unwinder.find_loop(it->get_target()->location_number, loop))
      {
        std::cout << "NON-LOOP BACKEDGE? " << it->location_number
                  << " --> " << it->get_target()->location_number << std::endl;
        assert(false);
      }
      assert(!iteration_stack.empty());
      assert(!max_iteration_stack.empty());
#endif

      // max_unwind reached
      if(iteration_stack.back()==max_iteration_stack.back())
      {
        iteration_stack.pop_back();
        max_iteration_stack.pop_back();

        // add back-edge
        add_edge(node, loop_node_stack.back());

        loop_node_stack.pop_back();
      }
      // max_unwind not reached
      else
      {
        // add edges for end of loop
        const std::set<node_indext> &iedges=incoming_edges[it];
        for(const auto &from : iedges)
          add_edge(from, node);
        incoming_edges.erase(it);

        // jump back to loop head
        it=it->get_target();
        iteration_stack.back()++;
        node_indext new_node=add_node();
        nodes[new_node].id.iteration_stack=iteration_stack;
        nodes[new_node].id.pc=it;
        nodes[new_node].is_loop_head=false;
        nodes[new_node].assumption=nil_exprt();

        // add forward edge to unwound loop head
        add_edge(node, new_node);

        // remember forward gotos
        if(it->is_goto() && !it->is_backwards_goto())
          incoming_edges[it->get_target()].insert(new_node);
        goto_programt::const_targett next=it; ++next;
        if(next!=goto_program.instructions.end() &&
           (!it->is_goto() || !it->guard.is_true()))
          incoming_edges[next].insert(new_node);

        continue;
      }
    }
    // reconstruct sink self-loops
    else if(it->is_backwards_goto() &&
            it->get_target()==it)
    {
      nodes[node].is_loop_head=true;
      add_edge(node, node);
      continue;
    }

    // remember forward gotos
    if(it->is_goto() && !it->is_backwards_goto())
      incoming_edges[it->get_target()].insert(node);
    goto_programt::const_targett next=it; ++next;
    if(next!=goto_program.instructions.end() &&
       (!it->is_goto() || !it->guard.is_true()))
      incoming_edges[next].insert(node);

    // this is a loop head
    const ssa_local_unwindert::loopt *loop=nullptr;
    if(ssa_unwinder.find_loop(it->location_number, loop))
    {
      iteration_stack.push_back(0);
      loop_node_stack.push_back(node);
      assert(loop->current_unwinding>=0);
      max_iteration_stack.push_back(loop->current_unwinding);
      nodes[node].id.iteration_stack=iteration_stack;
      nodes[node].is_loop_head=true;
    }

    const std::set<node_indext> &iedges=incoming_edges[it];
    for(const auto &from : iedges)
      add_edge(from, node);
    incoming_edges.erase(it);
  }
コード例 #17
0
ファイル: sgraph.cpp プロジェクト: JehandadKhan/roccc-2.0
SGraphNode SGraph::create_node () {
  SGraphNode node = max_num_nodes();
  add_node(node); 
  return(node);
}
コード例 #18
0
ファイル: update_history.cpp プロジェクト: sedna/sedna
void update_history::add_delete_node(const xptr node)
{
	add_node(ut_delete, node);
}
コード例 #19
0
ファイル: sgraph.cpp プロジェクト: JehandadKhan/roccc-2.0
void SGraph::add_nodes_from_list(SGraphNodeList *lst) {
  for (SGraphNodeList::iterator iter = lst->begin();
       iter != lst->end(); iter++) {
    add_node(*iter);
  }
}
コード例 #20
0
int odb_add_node(odb_t * odb, odb_key_t key, odb_value_t value)
{
	return add_node(odb->data, key, value);
}
コード例 #21
0
/* Process a single .desc line.
 */
static int
process_line( SymbolTable *st, const char *text )
{
	char line[1024];

#ifdef DEBUG
	printf( "read: %s\n", text );
#endif /*DEBUG*/

	/* We destroy line during the parse.
	 */
	im_strncpy( line, text, 1024 );

	if( im_isprefix( "#LRJOIN ", line ) || 
		im_isprefix( "#TBJOIN ", line ) ) {
		/* Yes: magic join command. Break into tokens. Format is eg.

			#LRJOIN <left> <right> <out> <x> <y> [<mwidth>]

		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinType type;
		JoinNode *arg1, *arg2, *join;
		int dx, dy, mwidth;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 5 && nitems != 6 ) {
			im_error( "global_balance", 
				_( "bad number of args in join line" ) );
			return( -1 );
		}

		if( !(arg1 = add_node( st, item[0] )) ||
			!(arg2 = add_node( st, item[1] )) ||
			!(join = add_node( st, item[2] )) )
			return( -1 );
		dx = atoi( item[3] );
		dy = atoi( item[4] );
		if( nitems == 6 ) 
			mwidth = atoi( item[5] );
		else
			mwidth = -1;
		if( im_isprefix( "#LRJOIN ", line ) )
			type = JOIN_LR;
		else
			type = JOIN_TB;

		if( make_join( st, type, arg1, arg2, 
			join, 1.0, 0.0, dx, dy, mwidth ) )
			return( -1 );
	}
	else if( im_isprefix( "#LRROTSCALE ", line ) ||
		im_isprefix( "#TBROTSCALE ", line ) ) {
		/* Rot + scale. Format is eg.

			#LRROTSCALE <left> <right> <out> \
				<a> <b> <x> <y> [<mwidth>]

		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinType type;
		JoinNode *arg1, *arg2, *join;
		double a, b, dx, dy;
		int mwidth;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 7 && nitems != 8 ) {
			im_error( "global_balance", 
				_( "bad number of args in join1 line" ) );
			return( -1 );
		}

		if( !(arg1 = add_node( st, item[0] )) ||
			!(arg2 = add_node( st, item[1] )) ||
			!(join = add_node( st, item[2] )) )
			return( -1 );
		a = g_ascii_strtod( item[3], NULL );
		b = g_ascii_strtod( item[4], NULL );
		dx = g_ascii_strtod( item[5], NULL );
		dy = g_ascii_strtod( item[6], NULL );
		if( nitems == 8 )
			mwidth = atoi( item[7] );
		else
			mwidth = -1;
		if( im_isprefix( "#LRROTSCALE ", line ) )
			type = JOIN_LRROTSCALE;
		else
			type = JOIN_TBROTSCALE;

		if( make_join( st, type, arg1, arg2, 
			join, a, b, dx, dy, mwidth ) )
			return( -1 );
	}
	else if( im_isprefix( "copy ", line ) ) {
		/* im_copy() call ... make a JOIN_CP node.
		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinNode *before, *after;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 2 ) {
			im_error( "global_balance", 
				_( "bad number of args in copy line" ) );
			return( -1 );
		}

		if( !(before = add_node( st, item[0] )) ||
			!(after = add_node( st, item[1] )) ||
			make_copy( st, before, after ) )
			return( -1 );
	}

	return( 0 );
}
コード例 #22
0
ファイル: win_search.c プロジェクト: Janesak1977/ali3602
static PRESULT win_search_update_progress(UINT8 progress_prec)
{	
	UINT8 result = PROC_LOOP;
	win_popup_choice_t popup_result=WIN_POP_CHOICE_NULL;
	UINT8 back_save;
	PROGRESS_BAR* bar;
	TEXT_FIELD* txt;
	P_NODE node;
	UINT8 str[32];

	DBG_PRINTF("Enter %s....\n",__FUNCTION__);

	BOOL is_flash_full = FALSE;
	bar = &srch_progress_bar;
	txt = &srch_progress_txt;
	if(progress_prec == 150)
	{
		progress_prec = 100;
		is_flash_full = TRUE;
	}

	OSD_SetProgressBarPos(bar, progress_prec);
	if(progress_prec< 3)
		bar->wTickFg = WSTL_NOSHOW_IDX;
	else
		bar->wTickFg = PROGRESSBAR_PROGRESS_SH_IDX;
	OSD_SetTextFieldContent(txt, STRING_NUM_PERCENT,progress_prec);
	if(win_search_param.as_method != AS_METHOD_NIT_TP &&
		win_search_param.as_method != AS_METHOD_NIT&&
		win_search_param.as_method != AS_METHOD_MULTI_NIT)
	{
		OSD_DrawObject( (POBJECT_HEAD)bar, C_UPDATE_ALL);
		OSD_DrawObject( (POBJECT_HEAD)txt, C_UPDATE_ALL);
	}/*If search mode is AS_METHOD_NIT_TP/AS_METHOD_NIT/AS_METHOD_MULTI_NIT, do not show progress bar*/	

	
	if(progress_prec == 100) // is completed ?
	{
		// stop drawave timer, at first
		//osal_timer_activate(win_search_tmr_id, FALSE);
				
		if((srch_ch_cnt[0] != 0x0)  // radio
		|| (srch_ch_cnt[1] != 0x0))// tv
		{
			//win_search_save_data(TRUE);
		}
		else // not find
		{
			if(!is_flash_full)
			{
				INT32 ret = 0;

				if(pid_search_flg)		
				{
#ifdef NEW_DEMO_FRAME
					struct dmx_device *dmx = (struct dmx_device *)dev_get_by_id(HLD_DEV_TYPE_DMX, 0);
					ret = as_prog_pid_search(dmx, 1, pid_search_VPid,pid_search_APid, pid_search_PPid);
#else
					ret = as_prog_pid_search(1,pid_search_VPid,pid_search_APid,pid_search_PPid);
#endif
					if(ret)
					{//add node
						MEMSET(&node,0,sizeof(node));
						node.sat_id = pid_search_tp>>NODE_ID_TP_BIT;
						node.tp_id = pid_search_tp;
						node.video_pid = pid_search_VPid;
						node.audio_count = 1;
						node.audio_pid[0] = pid_search_APid;
						node.pcr_pid = pid_search_PPid;
						node.av_flag =1;
						sprintf(str,"tp%d_%d",node.tp_id,node.video_pid);
						ComAscStr2Uni(str, (UINT16*)node.service_name);
						if(SUCCESS!= lookup_node(TYPE_PROG_NODE, &node, node.tp_id))
						{
							add_node(TYPE_PROG_NODE, node.tp_id, &node);
							update_data();
						}
					}
				}
				if(!ret)
				{
                    win_search_last_tp_ok_failed(srch_tp_cnt);

					win_compopup_init(WIN_POPUP_TYPE_OK);
					win_compopup_set_msg(NULL,NULL,RS_MSG_NO_PROGRAM_FOUND);
					win_compopup_open_ext(&back_save);
				}
			}			
		}
		
		if(is_flash_full==TRUE)
		{
            win_search_last_tp_ok_failed(srch_tp_cnt);

			win_compopup_init(WIN_POPUP_TYPE_OK);
			win_compopup_set_msg(NULL,NULL,RS_MSG_SPACE_FULL);
			win_compopup_open_ext(&back_save);
		}
		
		result = PROC_LEAVE;
	}
コード例 #23
0
ファイル: callbacks.c プロジェクト: biddyweb/libdmclient
static Ret_t prv_do_generic_cmd_cb(InstanceID_t id,
                                   VoidPtr_t userData,
                                   SmlGenericCmdPtr_t cmdP)
{
    internals_t * internP = (internals_t *)userData;
    SmlStatusPtr_t statusP;
    SmlItemListPtr_t itemCell;

    if (internP->sequence
      && internP->seq_code != OMADM_SYNCML_ERROR_NOT_MODIFIED
      && internP->seq_code != OMADM_SYNCML_ERROR_SUCCESS)
    {
        // do not treat this command
        return SML_ERR_OK;
    }

    if (OMADM_SYNCML_ERROR_AUTHENTICATION_ACCEPTED != internP->srv_auth)
    {
        statusP = create_status(internP, internP->srv_auth, cmdP);

        add_element(internP, (basicElement_t *)statusP);
        return SML_ERR_OK;
    }

    itemCell = cmdP->itemList;
    while (itemCell)
    {
        int code;

        if (internP->sequence && internP->seq_code == OMADM_SYNCML_ERROR_NOT_MODIFIED)
        {
            code = OMADM_SYNCML_ERROR_NOT_EXECUTED;
        }
        else
        {
            switch (cmdP->elementType)
            {
            case SML_PE_ADD:
                code = add_node(internP, itemCell->item);
                break;
            case SML_PE_COPY:
                code = copy_node(internP, itemCell->item);
                break;
            case SML_PE_DELETE:
                code = delete_node(internP, itemCell->item);
                break;
            case SML_PE_REPLACE:
                 code = replace_node(internP, itemCell->item);
                 break;
            default:
                code = OMADM_SYNCML_ERROR_COMMAND_NOT_IMPLEMENTED;
            }
        }
        statusP = create_status(internP, code, cmdP);
        add_target_ref(statusP, itemCell->item->target);
        add_element(internP, (basicElement_t *)statusP);

        itemCell = itemCell->next;
    }

    return SML_ERR_OK;
}
コード例 #24
0
/* update the service list */
void recv_service_list_info(int sockfd, struct ServiceList *service_list){
	char *buff = recv_once(sockfd);
	char *saveptr1, *saveptr2;
	char *str, *substr;
	pthread_mutex_lock(&handler_mutex); /* lock */
	/*printf("-----------------\n");
	printf("%s", buff);
	printf("-----------------\n");*/
	
	str = strtok_r(buff, "\n", &saveptr1);
	char server_name[strlen(str)+1];
	strcpy(server_name, str);
	str = strtok_r(NULL, "\n", &saveptr1);
	
	while( strcmp(str, "TABLE") != 0 ){
		substr = strtok_r(str, "&", &saveptr2);
		struct service *service_iter;
		for(service_iter = service_list->head; service_iter != NULL; service_iter = service_iter->next){
			if( strcmp(service_iter->function, substr)==0 ){
				break;			
			}
		}
		if(service_iter == NULL){
			add_empty_service(service_list, substr);
			service_iter = service_list->tail;
		}
		char *s = (char*)malloc(1000*sizeof(char));
		char *port = (char*)malloc(1000*sizeof(char));
		while( (substr=strtok_r(NULL, "&", &saveptr2)) != NULL){
			struct node *server_iter;
			for (server_iter=service_iter->server_list->head; server_iter != NULL; server_iter = server_iter->next){
				strcpy(s, server_iter->serv_name);
				strcat(s, ":");
				sprintf(port, "%d", server_iter->port);
				strcat(s, port); 
				if( strcmp(s, substr)==0 ){
					break;
				}
			}
			if(server_iter == NULL){
				add_node(service_iter->server_list, substr);
			}	
		}
		free(port);
		free(s);
		str = strtok_r(NULL, "\n", &saveptr1);
	}
	char *s = (char*)malloc(1000*sizeof(char));
	char *port = (char*)malloc(1000*sizeof(char));
	while( (str=strtok_r(NULL, "\n", &saveptr1)) != NULL ){
		struct service *service_iter; /*iterator of service_list */
		for(service_iter = service_list->head; service_iter != NULL; service_iter = service_iter->next){
			if( strcmp(service_iter->function, str)==0 ){ /* found the function in service_list */
				struct node *server_iter;
				for(server_iter=service_iter->server_list->head; server_iter != NULL; server_iter=server_iter->next){
					strcpy(s, server_iter->serv_name);
					strcat(s, ":");
					sprintf(port, "%d", server_iter->port);
					strcat(s, port); 
					if(strcmp(s, server_name)==0){
						break;
					}
				}
				if(server_iter == NULL){
					add_node(service_iter->server_list, server_name); /* add the server to the server_list */
				}
				break;
			}
		}
		if(service_iter == NULL){ /* the service is not in service_list */
			add_service(service_list, str, server_name); /* add the service to service_list */
		}
	}
	free(s);
	free(port);
	printf("------ Current Data Structure ------\n");
	struct service *service_iter;
	for(service_iter = service_list->head; service_iter != NULL; service_iter = service_iter->next){
		printf("service: %s", service_iter->function);
		struct node *server_iter; 
		for (server_iter = service_iter->server_list->head; server_iter != NULL; server_iter = server_iter->next){
			printf(" -> %s:%d", server_iter->serv_name, server_iter->port);
		}
		printf("\n");
	}
	printf("------------------------------------\n\n");
	pthread_mutex_unlock(&handler_mutex); /* unlock */
	/* free */
	free(buff);
}
コード例 #25
0
ファイル: arg.c プロジェクト: dsholla/rdp1_6
void arg_boolean(char key, char * description, int * intvalue)
{
  add_node(ARG_BOOLEAN, key, description, intvalue, 0, NULL); 
}
コード例 #26
0
ファイル: parser.c プロジェクト: misaakidis/SuperscaM
static
void splitCommandLine(char* commandLine, int currentLine, dictionary *D)
{
	//ASMinstr cmd;
	static consecutive_labels = 0;

	char * token = xstrtok(commandLine, cmd_delim);
	//if (strIncludedInArray(token, RtypeCommands))
	if (!strcmp(token, "breakpoint"))
	{
        ASMinstr a;
        a.type = BREAKPOINT;
        a.isBreakpoint = true;
        add_node(L1, a);
                    /* ?!?!?! MAYBE add_node(L1, a); is better
                       than add_node_parser(L1, a, D) for breakpoints; */
        //add_node_parser(L1, a, D);
        fprintf(stderr, "Found breakpoint: %s\n", commandLine);
        //When there is a breakpoint in a line, anything following will be considered as comment
        return;
        //token = xstrtok(NULL, cmd_delim);
        //if (!xstrcmp(token, "arloumpes"))
        //    return;
	}
	if (isRFinstr(token))
	{
		//cmd.type = RTYPE;
		//cmd.instr.r = parseRinstr(commandLine);
		parseRinstr(commandLine, D);
	}
	//else if (strIncludedInArray(token, ItypeCommands))
	else if (isIinstr(token))
	{
		//cmd.type = ITYPE;
		//cmd.instr.i = parseIinstr(commandLine);
		parseIinstr(commandLine, D);
	}
	else if (isBinstr(token))
	{
	    parseBinstr(commandLine, D);
	}
	else if (isSDinstr(token))
        parseSDinstr(commandLine, D);
    else if (isLDinstr(token))
        parseLDinstr(commandLine, D);
    else if (isRRinstr(token))
        parseRRinstr(commandLine, D);
	else
	{
		if(token[strlen(token)-1] == ':')
		{
		    //token = strncpy(token, token, strlen(token)-2);
		    //token[strlen(token)+1] = '\0';
			fprintf(stdout, "New Label: %s\n", token); //TODO Put label in dict

            /*
            if (previouslabel != NULL) //|| isFirstLabel
            {
                //isFirstLabel = false;
                add_to_dict(D, hash(token), node_mod);
                consecutive_labels++;
            }
            else
                while(consecutive_labels > 0)
                {
                    D->e[D->entries-consecutive_labels].goto_node = D->e[D->entries].goto_node;
                    consecutive_labels--;
                }
            */

			previouslabel = (char *)malloc(sizeof(char *));
			strcpy(previouslabel, token);
			token = xstrtok(commandLine, cmd_delim);
			char lampel[MAX_LABEL_LEN];
			strcpy(lampel, token);
            if(token[0] == '0' && token[1] == 'x')
            {
                long hexLabel = 0;
                hexLabel = strtol(lampel, NULL, 16);
                if(hexLabel > 0 && hexLabel < 65535)
                    fprintf(stderr, "The label is in hexadecimal format and within the byte addressing range.\n");
            }
            strcpy(lampel, token);
		}
		else
		{
		    fprintf(stderr, "%s: ", commandLine);
			error(E_CMD_INVALID, ACTION_PRINTMSG);
		}
	}

}
コード例 #27
0
ファイル: arg.c プロジェクト: dsholla/rdp1_6
void arg_string(char key, char * description, char * * str)
{
  add_node(ARG_STRING, key, description, 0, 0, str);
}
コード例 #28
0
ファイル: testmylist.c プロジェクト: bradford-smith94/cs392
int main()
{
	t_node *head;
	t_node *n1;
	t_node *n2;
	int *i1;
	int *i2;
	int *i3;
	int i;
	int j;
	int k;
	char *c1;
	char *c2;
	char *c3;
	char a;
	char b;
	char c;

	head = (t_node*)xmalloc(10*sizeof(t_node));
	
	/*new_node*/
	n1 = new_node("one\n", NULL);
	my_str(n1->elem);/*prints one*/
	n1->elem = NULL;
	free(n1);
	n1 = new_node(NULL, NULL);
	if(!n1->elem)
		my_str("create NULL node ok\n");
	else
		my_str("create NULL node FAIL!\n");
	free(n1);
	n1 = new_node("a", NULL);
	n2 = new_node("b", n1);
	my_str(n2->elem);
	my_str((n2->next)->elem);/*prints ba*/
	my_char('\n');
	my_str("---------------------------------------------------------------------\n");

	/*add_node*/
	add_node(n1, &head);
	my_str((*head).elem);/*prints a*/
	my_char('\n');
	add_node(n2, &head);
	my_str((*head).elem);/*prints b*/
	my_char('\n');
	add_node(NULL, &head);
	if(strcmp((*head).elem, n2->elem) == 0)
		my_str("add NULL ok\n");
	else
		my_str("add NULL FAIL!\n");
	add_node(new_node(NULL, NULL), &head);
	if(strcmp((*head).elem, n2->elem) == 0)
		my_str("add NULL node ok\n");
	else
		my_str("add NULL node FAIL!\n");
	add_node(new_node("something", NULL), NULL);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*traversals*/
	empty_list(&head);
	i = 3;
	i1 = &i;
	add_node(new_node(i1, NULL), &head);
	j = 2;
	i2 = &j;
	add_node(new_node(i2, NULL), &head);
	k = 1;
	i3 = &k;
	add_node(new_node(i3, NULL), &head);
	traverse_int(head);/*prints 1 2 3 */
	my_char('\n');
	head->next->elem = NULL;
	traverse_int(head);/*prints 1 NULL 3*/
	my_char('\n');
	traverse_int(NULL);/*prints The list is empty!*/

	empty_list(&head);
	c = 'c';
	c1 = &c;
	add_node(new_node(c1, NULL), &head);
	b = 'b';
	c2 = &b;
	add_node(new_node(c2, NULL), &head);
	a = 'a';
	c3 = &a;
	add_node(new_node(c3, NULL), &head);
	traverse_char(head);/*prints a b c */
	my_char('\n');
	head->elem = NULL;
	traverse_char(head);/*prints NULL b c*/
	my_char('\n');
	traverse_char(NULL);/*prints The list is empty!*/

	empty_list(&head);
	add_node(new_node("third", NULL), &head);
	add_node(new_node("second", NULL), &head);
	add_node(new_node("first", NULL), &head);
	traverse_string(head);/*prints first second third */
	my_char('\n');
	head->next->next->elem = NULL;
	traverse_string(head);/*prints first second NULL*/
	my_char('\n');
	traverse_string(NULL);/*prints The list is empty!*/
	empty_list(&head);
	my_str("---------------------------------------------------------------------\n");

	/*add_elem*/
	add_elem("a", &head);
	add_elem("b", &head);
	add_elem("c", &head);
	my_str(head->elem);/*prints c*/
	my_char('\n');
	add_elem(NULL, &head);
	if(strcmp(head->elem, "c") == 0)
		my_str("add NULL elem ok\n");
	else
		my_str("add NULL elem FAIL!\n");	
	my_str("---------------------------------------------------------------------\n");
	
	/*append*/
	append(new_node("z", NULL), &head);
	traverse_string(head);/*prints c b a z*/
	my_char('\n');
	append(NULL, &head);
	traverse_string(head);/*prints c b a z*/
	my_char('\n');
	append(new_node("stuff", NULL), NULL);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*add_node_at*/
	add_node_at(new_node("d", NULL), &head, 0);
	traverse_string(head);/*prints d c b a z*/
	my_char('\n');
	add_node_at(new_node("y", NULL), &head, 42);
	traverse_string(head);/*prints d c b a z y*/
	my_char('\n');
	add_node_at(new_node("0", NULL), &head, 4);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(NULL, &head, 2);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(new_node(NULL, NULL), &head, 1);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(new_node("something", NULL), NULL, 7);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*remove_node*/
	my_str(remove_node(&head));/*prints d*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_node(NULL))
		my_str("remove node from NULL ok\n");
	else
		my_str("remove node from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*remove_node_at*/
	my_str(remove_node_at(&head, 0));/*prints c*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	my_str(remove_node_at(&head, 42));/*prints y*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	my_str(remove_node_at(&head, 2));/*prints 0*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_node_at(NULL, 100))
		my_str("remove node from NULL ok\n");
	else
		my_str("remove node from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*remove_last*/
	my_str(remove_last(&head));/*prints z*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_last(NULL))
		my_str("remove last from NULL ok\n");
	else
		my_str("remove last from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*count_nodes*/
	my_int(count_nodes(head));/*prints 2*/
	my_char('\n');
	my_int(count_nodes(NULL));/*prints 0*/
	my_char('\n');
	my_str("---------------------------------------------------------------------\n");

	/*node_at*/
	my_str((node_at(head, 1))->elem);/*prints a*/
	my_char('\n');
	my_str((node_at(head, 0))->elem);/*prints b*/
	my_char('\n');
	my_str((node_at(head, 42))->elem);/*prints a*/
	my_char('\n');
	if(!node_at(NULL, 12))
		my_str("node at with NULL ok\n");
	else
		my_str("node at with NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*elem_at*/
	my_str(elem_at(head, 0));/*prints b*/
	my_char('\n');
	my_str(elem_at(head, 1));/*prints a*/
	my_char('\n');
	my_str(elem_at(head, 42));/*prints a*/
	my_char('\n');
	if(!elem_at(NULL, 3))
		my_str("elem at with NULL ok\n");
	else
		my_str("elem at with NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*empty_list*/
	my_int(count_nodes(head));/*prints 2*/
	my_char('\n');
	empty_list(&head);
	my_int(count_nodes(head));/*prints 0*/
	my_char('\n');
	empty_list(NULL);/*if this doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");
	
	free(head);

	return 0;
}
コード例 #29
0
ファイル: graph.cpp プロジェクト: EEDH/morethantechnical
/*
	Converts arcs added by 'add_edge()' calls
	to a forward star graph representation.

	Linear time algorithm.
	No or little additional memory is allocated
	during this process
	(it may be necessary to allocate additional
	arc blocks, since arcs corresponding to the
	same node must be contiguous, i.e. be in one
	arc block.)
*/
void Graph::prepare_graph()
{
	node *i;
	arc_for_block *ab_for, *ab_for_first;
	arc_rev_block *ab_rev, *ab_rev_first, *ab_rev_scan;
	arc_forward *a_for;
	arc_reverse *a_rev, *a_rev_scan, a_rev_tmp;
	node_block *nb;
	bool for_flag = false, rev_flag = false;
	int k;

	if (!arc_rev_block_first)
	{
		node_id from = add_node(), to = add_node();
		add_edge(from, to, 1, 0);
	}

	/* FIRST STAGE */
	a_rev_tmp.sister = NULL;
	for (a_rev=arc_rev_block_first->current; a_rev<&arc_rev_block_first->arcs_rev[ARC_BLOCK_SIZE]; a_rev++)
	{
		a_rev -> sister = NULL;
	}

	ab_for = ab_for_first = arc_for_block_first;
	ab_rev = ab_rev_first = ab_rev_scan = arc_rev_block_first;
	a_for = &ab_for->arcs_for[0];
	a_rev = a_rev_scan = &ab_rev->arcs_rev[0];

	for (nb=node_block_first; nb; nb=nb->next)
	{
		for (i=&nb->nodes[0]; i<nb->current; i++)
		{
			/* outgoing arcs */
			k = (int) i -> first_out;
			if (a_for + k > &ab_for->arcs_for[ARC_BLOCK_SIZE])
			{
				if (k > ARC_BLOCK_SIZE) { if (error_function) (*error_function)("# of arcs per node exceeds block size!"); exit(1); }
				if (for_flag) ab_for = NULL;
				else          { ab_for = ab_for -> next; ab_rev_scan = ab_rev_scan -> next; }
				if (ab_for == NULL)
				{
					arc_for_block *next = arc_for_block_first;
					char *ptr = new char[sizeof(arc_for_block)+1];
					if (!ptr) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
					if ((int)ptr & 1) arc_for_block_first = (arc_for_block *) (ptr + 1);
					else              arc_for_block_first = (arc_for_block *) ptr;
					arc_for_block_first -> start = ptr;
					arc_for_block_first -> current = & ( arc_for_block_first -> arcs_for[0] );
					arc_for_block_first -> next = next;
					ab_for = arc_for_block_first;
					for_flag = true;
				}
				else a_rev_scan = &ab_rev_scan->arcs_rev[0];
				a_for = &ab_for->arcs_for[0];
			}
			if (ab_rev_scan)
			{
				a_rev_scan += k;
				i -> parent = (arc_forward *) a_rev_scan;
			}
			else i -> parent = (arc_forward *) &a_rev_tmp;
			a_for += k;
			i -> first_out = a_for;
			ab_for -> last_node = i;

			/* incoming arcs */
			k = (int) i -> first_in;
			if (a_rev + k > &ab_rev->arcs_rev[ARC_BLOCK_SIZE])
			{
				if (k > ARC_BLOCK_SIZE) { if (error_function) (*error_function)("# of arcs per node exceeds block size!"); exit(1); }
				if (rev_flag) ab_rev = NULL;
				else          ab_rev = ab_rev -> next;
				if (ab_rev == NULL)
				{
					arc_rev_block *next = arc_rev_block_first;
					char *ptr = new char[sizeof(arc_rev_block)+1];
					if (!ptr) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
					if ((int)ptr & 1) arc_rev_block_first = (arc_rev_block *) (ptr + 1);
					else              arc_rev_block_first = (arc_rev_block *) ptr;
					arc_rev_block_first -> start = ptr;
					arc_rev_block_first -> current = & ( arc_rev_block_first -> arcs_rev[0] );
					arc_rev_block_first -> next = next;
					ab_rev = arc_rev_block_first;
					rev_flag = true;
				}
				a_rev = &ab_rev->arcs_rev[0];
			}
			a_rev += k;
			i -> first_in = a_rev;
			ab_rev -> last_node = i;
		}
		/* i is the last node in block */
		i -> first_out = a_for;
		i -> first_in  = a_rev;
	}

	/* SECOND STAGE */
	for (ab_for=arc_for_block_first; ab_for; ab_for=ab_for->next)
	{
		ab_for -> current = ab_for -> last_node -> first_out;
	}

	for ( ab_for=ab_for_first, ab_rev=ab_rev_first;
		  ab_for;
		  ab_for=ab_for->next, ab_rev=ab_rev->next )
	for ( a_for=&ab_for->arcs_for[0], a_rev=&ab_rev->arcs_rev[0];
		  a_for<&ab_for->arcs_for[ARC_BLOCK_SIZE];
		  a_for++, a_rev++ )
	{
		arc_forward *af;
		arc_reverse *ar;
		node *from;
		int shift = 0, shift_new;
		captype r_cap, r_rev_cap, r_cap_new, r_rev_cap_new;

		if (!(from=(node *)(a_rev->sister))) continue;
		af = a_for;
		ar = a_rev;

		do
		{
			ar -> sister = NULL;

			shift_new = ((char *)(af->shift)) - (char *)from;
			r_cap_new = af -> r_cap;
			r_rev_cap_new = af -> r_rev_cap;
			if (shift)
			{
				af -> shift = shift;
				af -> r_cap = r_cap;
				af -> r_rev_cap = r_rev_cap;
			}
			shift = shift_new;
			r_cap = r_cap_new;
			r_rev_cap = r_rev_cap_new;

			af = -- from -> first_out;
			if ((arc_reverse *)(from->parent) != &a_rev_tmp)
			{
				from -> parent = (arc_forward *)(((arc_reverse *)(from -> parent)) - 1);
				ar = (arc_reverse *)(from -> parent);
			}
		} while (from=(node *)(ar->sister));

		af -> shift = shift;
		af -> r_cap = r_cap;
		af -> r_rev_cap = r_rev_cap;
	}

	for (ab_for=arc_for_block_first; ab_for; ab_for=ab_for->next)
	{
		i = ab_for -> last_node;
		a_for = i -> first_out;
		ab_for -> current -> shift     = a_for -> shift;
		ab_for -> current -> r_cap     = a_for -> r_cap;
		ab_for -> current -> r_rev_cap = a_for -> r_rev_cap;
		a_for -> shift = (int) (ab_for -> current + 1);
		i -> first_out = (arc_forward *) (((char *)a_for) - 1);
	}

	/* THIRD STAGE */
	for (ab_rev=arc_rev_block_first; ab_rev; ab_rev=ab_rev->next)
	{
		ab_rev -> current = ab_rev -> last_node -> first_in;
	}

	for (nb=node_block_first; nb; nb=nb->next)
	for (i=&nb->nodes[0]; i<nb->current; i++)
	{
		arc_forward *a_for_first, *a_for_last;

		a_for_first = i -> first_out;
		if (IS_ODD(a_for_first))
		{
			a_for_first = (arc_forward *) (((char *)a_for_first) + 1);
			a_for_last = (arc_forward *) ((a_for_first ++) -> shift);
		}
		else a_for_last = (i + 1) -> first_out;

		for (a_for=a_for_first; a_for<a_for_last; a_for++)
		{
			node *to = NEIGHBOR_NODE(i, a_for -> shift);
			a_rev = -- to -> first_in;
			a_rev -> sister = a_for;
		}
	}

	for (ab_rev=arc_rev_block_first; ab_rev; ab_rev=ab_rev->next)
	{
		i = ab_rev -> last_node;
		a_rev = i -> first_in;
		ab_rev -> current -> sister = a_rev -> sister;
		a_rev -> sister = (arc_forward *) (ab_rev -> current + 1);
		i -> first_in = (arc_reverse *) (((char *)a_rev) - 1);
	}
}
コード例 #30
0
static void add_nodes(Scene *scene, BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree,
                      const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map)
{
	/* add nodes */
	BL::ShaderNodeTree::nodes_iterator b_node;
	PtrInputMap input_map;
	PtrOutputMap output_map;
	
	BL::Node::inputs_iterator b_input;
	BL::Node::outputs_iterator b_output;

	/* find the node to use for output if there are multiple */
	bool found_active_output = false;
	BL::ShaderNode output_node(PointerRNA_NULL);

	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
		if (is_output_node(*b_node)) {
			BL::ShaderNodeOutputMaterial b_output_node(*b_node);

			if(b_output_node.is_active_output()) {
				output_node = b_output_node;
				found_active_output = true;
				break;
			}
			else if(!output_node.ptr.data && !found_active_output) {
				output_node = b_output_node;
			}
		}
	}

	/* add nodes */
	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
		if (b_node->mute() || b_node->is_a(&RNA_NodeReroute)) {
			/* replace muted node with internal links */
			BL::Node::internal_links_iterator b_link;
			for (b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(b_link->to_socket()));
				
				input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
				output_map[b_link->to_socket().ptr.data] = proxy->outputs[0];
				
				graph->add(proxy);
			}
		}
		else if (b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup)) {
			
			BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL);
			if (b_node->is_a(&RNA_ShaderNodeGroup))
				b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(*b_node)).node_tree());
			else
				b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(*b_node)).node_tree());
			ProxyMap group_proxy_input_map, group_proxy_output_map;
			
			/* Add a proxy node for each socket
			 * Do this even if the node group has no internal tree,
			 * so that links have something to connect to and assert won't fail.
			 */
			for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_input));
				graph->add(proxy);
				
				/* register the proxy node for internal binding */
				group_proxy_input_map[b_input->identifier()] = proxy;
				
				input_map[b_input->ptr.data] = proxy->inputs[0];
				
				set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree);
			}
			for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_output));
				graph->add(proxy);
				
				/* register the proxy node for internal binding */
				group_proxy_output_map[b_output->identifier()] = proxy;
				
				output_map[b_output->ptr.data] = proxy->outputs[0];
			}
			
			if (b_group_ntree)
				add_nodes(scene, b_data, b_scene, graph, b_group_ntree, group_proxy_input_map, group_proxy_output_map);
		}
		else if (b_node->is_a(&RNA_NodeGroupInput)) {
			/* map each socket to a proxy node */
			for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
				ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output->identifier());
				if (proxy_it != proxy_input_map.end()) {
					ProxyNode *proxy = proxy_it->second;
					
					output_map[b_output->ptr.data] = proxy->outputs[0];
				}
			}
		}
		else if (b_node->is_a(&RNA_NodeGroupOutput)) {
			BL::NodeGroupOutput b_output_node(*b_node);
			/* only the active group output is used */
			if (b_output_node.is_active_output()) {
				/* map each socket to a proxy node */
				for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
					ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input->identifier());
					if (proxy_it != proxy_output_map.end()) {
						ProxyNode *proxy = proxy_it->second;
						
						input_map[b_input->ptr.data] = proxy->inputs[0];
						
						set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree);
					}
				}
			}
		}
		else {
			ShaderNode *node = NULL;

			if (is_output_node(*b_node)) {
				if (b_node->ptr.data == output_node.ptr.data) {
					node = graph->output();
				}
			}
			else {
				node = add_node(scene, b_data, b_scene, graph, b_ntree, BL::ShaderNode(*b_node));
			}
			
			if(node) {
				/* map node sockets for linking */
				for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
					ShaderInput *input = node_find_input_by_name(node, *b_node, *b_input);
					input_map[b_input->ptr.data] = input;
					
					set_default_value(input, *b_node, *b_input, b_data, b_ntree);
				}
				for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
					ShaderOutput *output = node_find_output_by_name(node, *b_node, *b_output);
					output_map[b_output->ptr.data] = output;
				}
			}
		}
	}

	/* connect nodes */
	BL::NodeTree::links_iterator b_link;

	for(b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) {
		/* get blender link data */
		BL::NodeSocket b_from_sock = b_link->from_socket();
		BL::NodeSocket b_to_sock = b_link->to_socket();

		ShaderOutput *output = 0;
		ShaderInput *input = 0;
		
		PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data);
		if (output_it != output_map.end())
			output = output_it->second;
		PtrInputMap::iterator input_it = input_map.find(b_to_sock.ptr.data);
		if (input_it != input_map.end())
			input = input_it->second;

		/* either node may be NULL when the node was not exported, typically
		 * because the node type is not supported */
		if(output && input)
			graph->connect(output, input);
	}
}