예제 #1
0
void touphScript::kernel2::encode(std::string const& kernel2,
  std::string const& textPath)
{

  std::ifstream xml_file{(fs::path{textPath}/"kernel2.bin.xml").string(), xml_file.binary};
  std::string xml{
    std::istreambuf_iterator<char>{xml_file}, 
    std::istreambuf_iterator<char>{}
  };

  rxml::xml_document<> doc;
  doc.parse<rxml::parse_default>(&xml[0]);

  auto root = doc.first_node("kernel2");
  if (!root)
    throw error{"Root node kernel2 not found"};

  auto section = root->first_node("section");

  ff7::kernel2::Strings sections;

  for (auto i = 0u; i < sections.size();
    section = section->next_sibling("section"), ++i) {
    if (!section)
      throw error{"Insufficient section tags in kernel2"};

    for (auto string = section->first_node("string"); string;
      string = string->next_sibling("string"))
      sections[i].push_back(from_xml(string->first_node()));
  }

  auto data = ff7::kernel2::join(sections);

  std::ofstream{kernel2, std::ios::binary}.write(data.data(), data.size());
}
예제 #2
0
static void	send_privmsg(t_message *msg, char *dest,
			     t_client *client, t_chan *chans)
{
  t_client	*tmpclient;

  if (strcmp(dest, "#*") == 0)
    send_all_chan(msg, client, first_node(&chans->node));
  else if (strcmp(dest, "*") == 0)
    send_all(msg, client, first_node(&client->node));
  else
    {
      if (strncmp(dest, "#", 1) == 0)
	send_chan(msg, client, find_chan(chans, dest));
      else
	{
	  tmpclient = first_node(&client->node);
	  while (tmpclient != NULL && strcmp(tmpclient->nick, dest) != 0)
	    tmpclient = tmpclient->node.next;
	  if (tmpclient == NULL)
	    dprintf(client->client, ERR_NOSUCHNICK, S_NAME, S_ADDR,
		    client->nick, dest);
	  else
	    dprintf(tmpclient->client, ":%s!%s PRIVMSG %s :%s\r\n",
		    client->nick, client->user, tmpclient->nick,
		    msg->params[1]);
	}
    }
}
예제 #3
0
void Dict::DebugWordChoices() {
  LIST Choices;
  int i;
  char LabelString[80];
  VIABLE_CHOICE VChoice = (VIABLE_CHOICE)first_node(best_choices_);
  bool force_debug =
    fragments_debug && VChoice != NULL && VChoice->ComposedFromCharFragments;

  if (stopper_debug_level >= 1 || force_debug ||
  (((STRING)word_to_debug).length() > 0 && best_choices_ &&
       StringSameAs(word_to_debug.string(), word_to_debug_lengths.string(),
                    (VIABLE_CHOICE)first_node(best_choices_)))) {
    if (best_raw_choice_)
      PrintViableChoice(stderr, "\nBest Raw Choice:   ", best_raw_choice_);

    i = 1;
    Choices = best_choices_;
    if (Choices)
      cprintf("\nBest Cooked Choices:\n");
    iterate(Choices) {
      sprintf(LabelString, "Cooked Choice #%d:  ", i);
      PrintViableChoice(stderr, LabelString,
                        (VIABLE_CHOICE)first_node(Choices));
      i++;
    }
  }
}
예제 #4
0
void FrameNetBuilder::read_relations(FrameNet &fn){

    rapidxml::file<> fdoc(this->relation_file_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());

    rapidxml::xml_node<>* root = doc.first_node();
    for(auto fr_type = root->first_node("frameRelationType");fr_type!= nullptr;fr_type = fr_type->next_sibling("frameRelationType")){
        std::string fr_type_name = fr_type->first_attribute("name")->value();
        for(auto fr = fr_type->first_node("frameRelation");fr!= nullptr;fr = fr->next_sibling("frameRelation")){
            std::string subFrame = fr->first_attribute("subFrameName")->value();
            std::string superFrame = fr->first_attribute("superFrameName")->value();
            Frame *current_frame = fn.get_frame(subFrame);
            if(fr_type_name == "Causative_of"||fr_type_name == "Inchoative_of"||fr_type_name == "Precedes"){
                current_frame = fn.get_frame(superFrame);
            }

            for(auto fe_r =fr->first_node("FERelation");fe_r!= nullptr;fe_r = fe_r->next_sibling("FERelation")){
                std::string parent = fe_r->first_attribute("superFEName")->value();
                std::string child = fe_r->first_attribute("subFEName")->value();
                FrameElementRelation *fr = new FrameElementRelation(parent,child,fr_type_name,superFrame,subFrame);
                current_frame->add_fe_relation(fr);

            }

        }
    }
}
예제 #5
0
파일: oldlist.cpp 프로젝트: CDOcr/tesseract
/**********************************************************************
 *  d e s t r o y   n o d e s
 *
 *  Return the space taken by the LISTs of a list to the heap.
 **********************************************************************/
void destroy_nodes(LIST list, void_dest destructor) {
  ASSERT_HOST(destructor != nullptr);

  while (list != NIL_LIST) {
    if (first_node(list) != nullptr) (*destructor)(first_node(list));
    list = pop(list);
  }
}
예제 #6
0
/**********************************************************************
 *  d e s t r o y   n o d e s
 *
 *  Return the space taken by the LISTs of a list to the heap.
 **********************************************************************/
void destroy_nodes(LIST list, void_dest destructor) {
  if (destructor == NULL)
    destructor = memfree;

  while (list != NIL_LIST) {
    if (first_node(list) != NULL) (*destructor)(first_node(list));
    list = pop(list);
  }
}
예제 #7
0
/**********************************************************************
 *  i n s e r t
 *
 *  Create a list element and rearange the pointers so that the first
 *  element in the list is the second aurgment.
 **********************************************************************/
void insert(LIST list, void *node) {
  LIST element;

  if (list != NIL_LIST) {
    element = push (NIL_LIST, node);
    set_rest (element, list_rest (list));
    set_rest(list, element);
    node = first_node (list);
    list->node = first_node (list_rest (list));
    list->next->node = (LIST) node;
  }
}
예제 #8
0
struct truth_table *
cpp_truth_table(node_t *node)
{
	struct truth_table *left, *right, *ret;
	int i;

	if (!node)
		return NULL;
	assert(node->type == nt_expr);

	switch (node->e.op) {
	case ID:
		if (! (ret = alloc_truth_table(1)) )
			return NULL;
		set_minterm(ret, 1);
		ret->names[0] = node->str->text;
		return ret;

	case '!':
		ret = cpp_truth_table(first_node(&node->child[che_arg1]));
		if (!ret)
			return NULL;
		for (i = 0; i < ret->tblsize; ++i)
			ret->tbl[i] = ~ret->tbl[i];
		if ((1 << ret->n) < 8*sizeof(long))
			ret->tbl[0] &= (1 << (1 << ret->n)) - 1;
		return ret;

	case AND_OP:
	case OR_OP:
	case EQ_OP:
	case NE_OP:
		left = cpp_truth_table(first_node(&node->child[che_arg1]));
		if (!left)
			return NULL;
		right = cpp_truth_table(first_node(&node->child[che_arg2]));
		if (!right) {
			free_truth_table(left);
			return NULL;
		}

		ret = binop_truth_table(left, right, node->e.op);
		free_truth_table(right);
		free_truth_table(left);
		return ret;

	default:
		fprintf(stderr, "%s: Operator %d not supported\n",
			__func__, node->e.op);
		exit(1);
	}
}
예제 #9
0
/*
 * There are unfortunately some poorly designed mainboards around that
 * only connect memory to a single CPU. This breaks the 1:1 cpu->node
 * mapping. To avoid this fill in the mapping for all possible CPUs,
 * as the number of CPUs is not known yet. We round robin the existing
 * nodes.
 */
void __init numa_init_array(void)
{
	int rr, i;

	rr = first_node(node_online_map);
	for (i = 0; i < nr_cpu_ids; i++) {
		if (early_cpu_to_node(i) != NUMA_NO_NODE)
			continue;
		numa_set_node(i, rr);
		rr = next_node(rr, node_online_map);
		if (rr == MAX_NUMNODES)
			rr = first_node(node_online_map);
	}
}
예제 #10
0
파일: propdirs.c 프로젝트: hyena/fuzzball
/* path is the name of the propdir to find the first node of */
PropPtr
propdir_first_elem(PropPtr root, char *path)
{
	PropPtr p;

	while (*path && *path == PROPDIR_DELIMITER)
		path++;
	if (!*path)
		return (first_node(root));
	p = propdir_get_elem(root, path);
	if (p && PropDir(p)) {
		return (first_node(PropDir(p)));	/* found the property! */
	}
	return (NULL);				/* nope, doesn't exist */
}
예제 #11
0
/*---------------------------------------------------------------------------*/
CHAR_FEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM& denorm) {
/*
 **      Parameters:
 **              Blob            blob to extract micro-features from
 **              denorm          control parameter to feature extractor
 **      Operation:
 **              This routine extracts micro-features from the specified
 **              blob and returns a list of the micro-features.  All
 **              micro-features are normalized according to the specified
 **              line statistics.
 **      Return: List of micro-features extracted from the blob.
 **      Exceptions: none
 **      History: 7/21/89, DSJ, Created.
 */
  MICROFEATURES MicroFeatures = NIL_LIST;
  FLOAT32 XScale, YScale;
  LIST Outlines;
  LIST RemainingOutlines;
  MFOUTLINE Outline;
  INT_FEATURE_ARRAY blfeatures;
  INT_FEATURE_ARRAY cnfeatures;
  INT_FX_RESULT_STRUCT results;

  if (Blob != NULL) {
    Outlines = ConvertBlob (Blob);
    if (!ExtractIntFeat(Blob, denorm, blfeatures, cnfeatures, &results))
      return NULL;
    XScale = 0.2f / results.Ry;
    YScale = 0.2f / results.Rx;

    RemainingOutlines = Outlines;
    iterate(RemainingOutlines) {
      Outline = (MFOUTLINE) first_node (RemainingOutlines);
      CharNormalizeOutline (Outline,
        results.Xmean, results.Ymean,
        XScale, YScale);
    }

    RemainingOutlines = Outlines;
    iterate(RemainingOutlines) {
      Outline = (MFOUTLINE) first_node (RemainingOutlines);
      FindDirectionChanges(Outline, classify_min_slope, classify_max_slope);
      MarkDirectionChanges(Outline);
      SmearExtremities(Outline, XScale, YScale);
      MicroFeatures = ConvertToMicroFeatures (Outline, MicroFeatures);
    }
    FreeOutlines(Outlines);
  }
예제 #12
0
t_chan		*find_chan(t_chan *chan, char const *name)
{
  if (name == NULL)
    return (NULL);
  else
    return (rec_find_chan(first_node(&chan->node), name));
}
/*--------------------------------------------------------------------------*/
void WriteMicrofeat(
    char	*Directory,
	LIST	ClassList)

{
	FILE		*File;
	char		Filename[MAXNAMESIZE];
	MERGE_CLASS MergeClass;

	strcpy (Filename, "");
	if (Directory != NULL)
	{
		strcat (Filename, Directory);
		strcat (Filename, "/");
	}
	strcat (Filename, "Microfeat");
	File = Efopen (Filename, "w");
	printf ("\nWriting Merged %s ...", Filename);
	iterate(ClassList)
	{
		MergeClass = (MERGE_CLASS) first_node (ClassList);
		WriteProtos(File, MergeClass);
		WriteConfigs(File, MergeClass->Class);
	}
	fclose (File);
} // WriteMicrofeat
/*----------------------------------------------------------------------------
						Public Code
-----------------------------------------------------------------------------*/
void DisplayProtoList(const char* ch, LIST protolist) {
  void* window = c_create_window("Char samples", 50, 200,
                                 520, 520, -130.0, 130.0, -130.0, 130.0);
  LIST proto = protolist;
  iterate(proto) {
    PROTOTYPE* prototype = reinterpret_cast<PROTOTYPE *>(first_node(proto));
    if (prototype->Significant)
      c_line_color_index(window, Green);
    else if (prototype->NumSamples == 0)
      c_line_color_index(window, Blue);
    else if (prototype->Merged)
      c_line_color_index(window, Magenta);
    else
      c_line_color_index(window, Red);
    float x = CenterX(prototype->Mean);
    float y = CenterY(prototype->Mean);
    double angle = OrientationOf(prototype->Mean) * 2 * M_PI;
    float dx = static_cast<float>(LengthOf(prototype->Mean) * cos(angle) / 2);
    float dy = static_cast<float>(LengthOf(prototype->Mean) * sin(angle) / 2);
    c_move(window, (x - dx) * 256, (y - dy) * 256);
    c_draw(window, (x + dx) * 256, (y + dy) * 256);
    if (prototype->Significant)
      tprintf("Green proto at (%g,%g)+(%g,%g) %d samples\n",
              x, y, dx, dy, prototype->NumSamples);
    else if (prototype->NumSamples > 0 && !prototype->Merged)
      tprintf("Red proto at (%g,%g)+(%g,%g) %d samples\n",
              x, y, dx, dy, prototype->NumSamples);
  }
  c_make_current(window);
}
예제 #15
0
/**
 * This routine writes a binary representation of Class
 * to File.
 *
 * @param File    open file to write Class to
 * @param Class   adapted class to write to File
 * @param NumConfigs  number of configs in Class
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 13:33:51 1991, DSJ, Created.
 */
void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs) {
  int NumTempProtos;
  LIST TempProtos;
  int i;

  /* first write high level adapted class structure */
  fwrite ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File);

  /* then write out the definitions of the permanent protos and configs */
  fwrite ((char *) Class->PermProtos, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_PROTOS), File);
  fwrite ((char *) Class->PermConfigs, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_CONFIGS), File);

  /* then write out the list of temporary protos */
  NumTempProtos = count (Class->TempProtos);
  fwrite ((char *) &NumTempProtos, sizeof (int), 1, File);
  TempProtos = Class->TempProtos;
  iterate (TempProtos) {
    void* proto = first_node(TempProtos);
    fwrite ((char *) proto, sizeof (TEMP_PROTO_STRUCT), 1, File);
  }

  /* then write out the adapted configs */
  fwrite ((char *) &NumConfigs, sizeof (int), 1, File);
  for (i = 0; i < NumConfigs; i++)
    if (test_bit (Class->PermConfigs, i))
      WritePermConfig (File, Class->Config[i].Perm);
    else
      WriteTempConfig (File, Class->Config[i].Temp);

}                                /* WriteAdaptedClass */
/*-----------------------------------------------------------------------------*/
void FreeLabeledClassList (
    LIST	ClassList)

/*
 **	Parameters:
 **		FontList	list of all fonts in document
 **	Globals: none
 **	Operation:
 **		This routine deallocates all of the space allocated to
 **		the specified list of training samples.
 **	Return: none
 **	Exceptions: none
 **	History: Fri Aug 18 17:44:27 1989, DSJ, Created.
 */

{
  MERGE_CLASS	MergeClass;

  iterate (ClassList) 		/* iterate thru all of the fonts */
  {
    MergeClass = (MERGE_CLASS) first_node (ClassList);
    free (MergeClass->Label);
    FreeClass(MergeClass->Class);
    delete MergeClass;
  }
  destroy (ClassList);

}	/* FreeLabeledClassList */
예제 #17
0
   //!Allocates a singly linked list of n nodes ending in null pointer. 
   multiallocation_chain allocate_nodes(const size_type n)
   {
      //Preallocate all needed blocks to fulfill the request
      size_type cur_nodes = m_freelist.size();
      if(cur_nodes < n){
         priv_alloc_block(((n - cur_nodes) - 1)/m_nodes_per_block + 1);
      }

      //We just iterate the needed nodes to get the last we'll erase
      typedef typename free_nodes_t::iterator free_iterator;
      free_iterator before_last_new_it = m_freelist.before_begin();
      for(size_type j = 0; j != n; ++j){
         ++before_last_new_it;
      }

      //Cache the first node of the allocated range before erasing
      free_iterator first_node(m_freelist.begin());
      free_iterator last_node (before_last_new_it);

      //Erase the range. Since we already have the distance, this is O(1)
      m_freelist.erase_after( m_freelist.before_begin()
                            , ++free_iterator(before_last_new_it)
                            , n);

      //Now take the last erased node and just splice it in the end
      //of the intrusive list that will be traversed by the multialloc iterator.
      multiallocation_chain chain;
      chain.incorporate_after(chain.before_begin(), &*first_node, &*last_node, n);
      m_allocated += n;
      return boost::move(chain);
   }
예제 #18
0
파일: fadv.c 프로젝트: antdvid/FronTier
EXPORT	void print_linked_node_list(
	INTERFACE	*intfc)
{
	NODE		**n, *m;
	int		i, node_count;

	n = intfc->nodes;
	if (! n)
	{
	    (void) printf("NULL node list on intfc\n");
	    return;
	}

	(void) printf("\tnode list - intfc %llu\n",(long long unsigned int)interface_number(intfc));
	for (node_count = 0;  n && *n;  ++n, ++node_count)
		;

	m = first_node(intfc);
	for (i = 0;  i <= node_count + 2;  ++i) 
	{
	    if (m != NULL)
	    {
	    	(void) printf("prev %llu  m %llu  next %llu  ",
	    		      (long long unsigned int)node_number(prev_node(m)),
			      (long long unsigned int)node_number(m),
	    		      (long long unsigned int)node_number(next_node(m)));
	    	print_propagation_status(m);
	    }
	    else
	    	break;
	    m = next_node(m);
	}
}		/*end print_linked_node_list*/
예제 #19
0
FLOAT32 Dict::CurrentBestChoiceAdjustFactor() {
  VIABLE_CHOICE BestChoice;
  if (best_choices_ == NIL_LIST)
    return (MAX_FLOAT32);
  BestChoice = (VIABLE_CHOICE) first_node (best_choices_);
  return (BestChoice->AdjustFactor);
}
예제 #20
0
/* removes property list --- if it's not there then ignore */
void
remove_property_list(dbref player, int all)
{
    PropPtr l;
    PropPtr p;
    PropPtr n;

    /* if( tp_db_readonly ) return; *//* Why did we remove this? */

#ifdef DISKBASE
    fetchprops(player);
#endif

    if ((l = DBFETCH(player)->properties)) {
        p = first_node(l);
        while (p) {
            n = next_node(l, PropName(p));
            remove_proplist_item(player, p, all);
            l = DBFETCH(player)->properties;
            p = n;
        }
    }
#ifdef DISKBASE
    dirtyprops(player);
#endif

    DBDIRTY(player);
}
예제 #21
0
std::vector<char> touphScript::flevel::tutorial::encode(std::string const& file)
{
  std::ifstream str{file, str.binary};
  std::string data{
    std::istreambuf_iterator<char>{str}, 
    std::istreambuf_iterator<char>{}
  };

  if (data.empty())
    return {};

  std::vector<std::vector<char>> out;

  rxml::xml_document<> doc;
  doc.parse<rxml::parse_default>(&data[0]);

  auto root = doc.first_node("field");
  if (!root)
    throw error{"Root node field not found"};

  for (auto n = root->first_node("tutorial"); n;
    n = n->next_sibling("tutorial")) {

    auto id = util::xml::ul(util::xml::att(n, "id"));

    if (out.size() < id + 1)
      out.resize(id + 1);

    out[id] = from_xml(n);
  }

  return ff7::flevel::script::tutorial::join(out);
}
예제 #22
0
int
ReadAll (int sd, c_tree * ct)
{
  int s,i=0;
  Node *curNode;
  curNode = first_node (ct);
fprintf(stderr,"1: ReadAll(%d) nodes=%d\n",sd,ct->numNodes);
  while (curNode)
  {

//fprintf(stderr, "--------------Ident: %d\n", curNode->data.Ident );
//fflush(stderr);

    curNode->data.Reliability =
      GetItemInfo (curNode->data.Ident, &curNode->data.Value,
		   &curNode->data.ELRange, &curNode->data.EHRange);
    curNode->access_time = time (NULL);
    s = send (sd, &(curNode->data), sizeof (GIV), MSG_DONTWAIT);
if(s<1) fprintf(stderr,"-----------------------------s[%d]=%d\n",i,s);
//else	fprintf(stderr,"ident=%d rel=%d\n",curNode->data.Ident,curNode->data.Reliability);
    curNode = next_node (curNode);
    i++;
  }
fprintf(stderr,"2: ReadAll() send %d Items\n",i);  
  return 1;
}
예제 #23
0
LexicalUnit*  FrameNetBuilder::parse_lu_xml(std::string xml_path,LexicalUnit* original){
    rapidxml::file<> fdoc(xml_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());

    rapidxml::xml_node<>* root = doc.first_node();

    std::string name = original->get_name(); //带有词性
    std::string POS = original->get_pos();
    std::string frame_name = original->get_frame_name();
    int ID = original->get_ID();
    std::string status = original->get_status();

    //std::string lexeme = root->first_node("lexeme")->first_attribute("name")->value();
    std::string definition = root->first_node("definition")->value();
    rapidxml::xml_node<>* valence = root->first_node("valences");
    std::vector<FERealization*>fe_realizations;
    for(auto p = valence->first_node("FERealization");p !=  nullptr;p = p->next_sibling("FERealization")){
        fe_realizations.push_back(build_realization(p,frame_name,name));
    }

    std::vector<Annotation*> annotations;
    for(auto subCorpus = root->first_node("subCorpus");subCorpus != nullptr;subCorpus = subCorpus->next_sibling("subCorpus")){
        for(auto senten = subCorpus->first_node("sentence");senten != nullptr; senten = senten->next_sibling("sentence")){
            annotations.push_back(build_annotation(senten));
        }
    }

    original->set_definition(definition);
    original->set_fe_realizations(fe_realizations);
    original->set_annotations(annotations);
    return original;

}
예제 #24
0
FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
/*
 **	Parameters:
 **		Blob		blob to extract pico-features from
 **		LineStats	statistics on text row blob is in
 **	Globals:
 **		classify_norm_method	normalization method currently specified
 **	Operation: Dummy for now.
 **	Return: Pico-features for Blob.
 **	Exceptions: none
 **	History: 9/4/90, DSJ, Created.
 */
  LIST Outlines;
  LIST RemainingOutlines;
  MFOUTLINE Outline;
  FEATURE_SET FeatureSet;
  FLOAT32 XScale, YScale;

  FeatureSet = NewFeatureSet(MAX_PICO_FEATURES);
  Outlines = ConvertBlob(Blob);
  NormalizeOutlines(Outlines, &XScale, &YScale);
  RemainingOutlines = Outlines;
  iterate(RemainingOutlines) {
    Outline = (MFOUTLINE) first_node (RemainingOutlines);
    ConvertToPicoFeatures2(Outline, FeatureSet);
  }
  if (classify_norm_method == baseline)
    NormalizePicoX(FeatureSet);
  FreeOutlines(Outlines);
  return (FeatureSet);

}                                /* ExtractPicoFeatures */
예제 #25
0
파일: draw.c 프로젝트: Stargateur/zappy
void		draw_stone(t_map *map, t_texture *img, t_display *disp)
{
  t_square	*tmp;
  SDL_Rect	DestR;

  tmp = first_node(&map->items->node);
  DestR.w = (int)disp->_shape_size;
  DestR.h = (int)disp->_shape_size2;
  while (tmp != NULL)
    {
      if (tmp->coord.x < disp->_horiz + disp->_nb_case
	   && tmp->coord.x >= disp->_horiz
	   && tmp->coord.y < disp->_verti + disp->_nb_case
	   && tmp->coord.y >= disp->_verti)
	{
	  DestR.x = (int)((tmp->coord.x - disp->_horiz)
			  * (disp->_shape_size + 1));
	  DestR.y = (int)((tmp->coord.y - disp->_verti)
			  * (disp->_shape_size2 + 1));
	  SDL_RenderCopy(disp->renderer, img->mine, NULL, &DestR);
	}
      tmp = tmp->node.next;
    }
  if (disp->_horiz + disp->_nb_case > map->width ||
      disp->_verti + disp->_nb_case > map->height)
    draw_more_stone(map, img, disp, &DestR);
}
예제 #26
0
/**********************************************************************
 *  d e l e t e    d
 *
 *  Delete all the elements out of the current list that match the key.
 *  This operation destroys the original list.  The caller will supply a
 *  routine that will compare each node to the
 *  key, and return a non-zero value when they match.  If the value
 *  NULL is supplied for is_equal, the is_key routine will be used.
 **********************************************************************/
LIST delete_d(LIST list, void *key, int_compare is_equal) {
  LIST result = NIL_LIST;
  LIST last_one = NIL_LIST;

  if (is_equal == NULL)
    is_equal = is_same;

  while (list != NIL_LIST) {
    if (!(*is_equal) (first_node (list), key)) {
      if (last_one == NIL_LIST) {
        last_one = list;
        list = list_rest (list);
        result = last_one;
        set_rest(last_one, NIL_LIST);
      }
      else {
        set_rest(last_one, list);
        last_one = list;
        list = list_rest (list);
        set_rest(last_one, NIL_LIST);
      }
    }
    else {
      list = pop (list);
    }
  }
  return (result);
}
예제 #27
0
LIST delete_d(LIST list, void *key,
              TessResultCallback2<int, void*, void*>* is_equal) {
  LIST result = NIL_LIST;
  LIST last_one = NIL_LIST;

  while (list != NIL_LIST) {
    if (!(*is_equal).Run (first_node (list), key)) {
      if (last_one == NIL_LIST) {
        last_one = list;
        list = list_rest (list);
        result = last_one;
        set_rest(last_one, NIL_LIST);
      }
      else {
        set_rest(last_one, list);
        last_one = list;
        list = list_rest (list);
        set_rest(last_one, NIL_LIST);
      }
    }
    else {
      list = pop (list);
    }
  }
  return (result);
}
/*---------------------------------------------------------------------------*/
LABELEDLIST FindList (
    LIST	List,
    char	*Label)

/*
 **	Parameters:
 **		List		list to search
 **		Label		label to search for
 **	Globals: none
 **	Operation:
 **		This routine searches thru a list of labeled lists to find
 **		a list with the specified label.  If a matching labeled list
 **		cannot be found, NULL is returned.
 **	Return: Labeled list with the specified Label or NULL.
 **	Exceptions: none
 **	History: Fri Aug 18 15:57:41 1989, DSJ, Created.
 */

{
  LABELEDLIST	LabeledList;

  iterate (List)
  {
    LabeledList = (LABELEDLIST) first_node (List);
    if (strcmp (LabeledList->Label, Label) == 0)
      return (LabeledList);
  }
  return (NULL);

}	/* FindList */
/*-----------------------------------------------------------------------------*/
void CleanUpUnusedData(
    LIST ProtoList)
{
  PROTOTYPE* Prototype;

  iterate(ProtoList)
  {
    Prototype = (PROTOTYPE *) first_node (ProtoList);
    if(Prototype->Variance.Elliptical != NULL)
    {
      memfree(Prototype->Variance.Elliptical);
      Prototype->Variance.Elliptical = NULL;
    }
    if(Prototype->Magnitude.Elliptical != NULL)
    {
      memfree(Prototype->Magnitude.Elliptical);
      Prototype->Magnitude.Elliptical = NULL;
    }
    if(Prototype->Weight.Elliptical != NULL)
    {
      memfree(Prototype->Weight.Elliptical);
      Prototype->Weight.Elliptical = NULL;
    }
  }
}
예제 #30
0
int ReadNew (int sd, c_tree * ct)
{
  GIV new_data;
  int counter = 0;
  int total_counter = 0;
  Node *curNode;
  int MustSend;
  time_t new_time;
  curNode = first_node (ct);
  
  fprintf(stderr,"ReadNew(%d) nodes=%d\n",sd,ct->numNodes);
  
  while (curNode)
  {
    MustSend = 0;
    new_time = time (NULL);
    new_data.Ident = curNode->data.Ident;
    new_data.Reliability =
      GetItemInfo (new_data.Ident, &new_data.Value, &new_data.ELRange,
		   &new_data.EHRange);
		   
//fprintf(stderr,"In ask new-Ident: %d  Rel: %d\n", new_data.Ident, 
//						    new_data.Reliability );

    if (fabsf (new_data.Value - curNode->data.Value) > curNode->si.DeadZone)
    {
      if (labs (new_time - curNode->access_time) > curNode->si.DeadTime)
      {
	MustSend = 1;
      }
    }
    else
    {
      if (new_data.Reliability != curNode->data.Reliability ||
	  fabsf (new_data.ELRange - curNode->data.ELRange) > PRECISION ||
	  fabsf (new_data.EHRange - curNode->data.EHRange) > PRECISION)
      {
	MustSend = 1;
      }
    }
    if (MustSend)
    {
      curNode->access_time = new_time;
      memcpy (&(curNode->data), &new_data, sizeof (GIV));
      send (sd, &(curNode->data), sizeof (GIV), MSG_DONTWAIT);
// fprintf(stderr,"SEND!!! Rel=%d Ident=%d\n",curNode->data.Reliability,curNode->data.Ident);
      counter++;
    }
    curNode = next_node (curNode);
    total_counter++;
  }
  if (counter == 0 || counter != total_counter)	// not new data or send some of data
  {
    new_data.Ident = -1;
    new_data.Value = 3.1415926;
    send (sd, &new_data, sizeof (GIV), MSG_DONTWAIT);
  }

  return 1;
}