예제 #1
0
파일: array.c 프로젝트: kevinwern/libprefix
// Insert node at any point in DynArray
int insert_dyn_array_node(DynArray *a, Node *n, int index)
{
  LIBPREFIX_ASSERT(a->type != UNINITIALIZED, ARR_NOT_INIT);
  LIBPREFIX_ASSERT(a->type == NON_CONTINUOUS, INCORRECT_ARR_TYPE);

  if (a->size <= index || index < 0) {
    libprefix_set_error(INVALID_INDEX);
    return -1; 
  }
  if (a->array[index] != NULL) {
    clear_node(a->array[index]);
  }
  else {
    a->total += 1;
  }
  a->array[index] = n;
  return 0;
}
예제 #2
0
파일: treemap.c 프로젝트: abbrous/Gauche
static Node *delete_node(ScmTreeCore *tc, Node *n)
{
    while (n->left && n->right) {
        /* N has both children.  We swap N and its previous node.
           It would be easier just to swap key and value, but it could
           lead to a hard-to-track bug if a pointer to N is retained
           in somewhere (e.g. iterator).  So we actually swap the node. */
        swap_node(tc, n, prev_node(n));
    }

    /* we have at most one child */
    if (n->left) {
        delete_node1(tc, n, n->left);
    } else {
        delete_node1(tc, n, n->right);  /* this covers no child case */
    }
    clear_node(n);
    return n;
}
예제 #3
0
파일: array.c 프로젝트: kevinwern/libprefix
// Free dynamic array structure
void clear_dyn_array(DynArray *a)
{
  int i;
  if (a->type == CONTINUOUS) {
    for (i = 0; i < a->size; i++) {
      free(a->array[i]);
    }
  }
  else {
    for (i = 0; i < a->size; i++) {
      if (a->array[i] != NULL) {
        clear_node(a->array[i]);
        dealloc_node(a->array[i]);
      }
    }
  }
  free(a->array);
  a->size = 0;
  a->total = 0;
  a->type = UNINITIALIZED;
  a->array = NULL;
}
예제 #4
0
파일: clientlog.c 프로젝트: teto/chrony
static void
create_node(Subnet *parent_subnet, int the_entry)
{
  Node *new_node;
  new_node = MallocNew(Node);
  parent_subnet->entry[the_entry] = (void *) new_node;
  clear_node(new_node);

  alloced += sizeof (Node);

  if (n_nodes == max_nodes) {
    if (nodes) {
      assert(max_nodes > 0);
      max_nodes *= 2;
      nodes = ReallocArray(Node *, max_nodes, nodes);
    } else {
      assert(max_nodes == 0);
      max_nodes = 16;
      nodes = MallocArray(Node *, max_nodes);
    }
    alloced += sizeof (Node *) * (max_nodes - n_nodes);
  }
예제 #5
0
파일: graph.c 프로젝트: kevinwern/libprefix
// Remove a word in the set
// Params: a node, a word
int delete_word (Node *graph, wchar_t *word)
{
  Node *lastwordnode = NULL, *searchPointer = graph;
  while (*word != L'\0' && searchPointer != NULL){
    HashTable *word_table = searchPointer->next;
    if (searchPointer->isword && word_table->array->total == 1){
      lastwordnode = searchPointer;
    }
    else if (word_table->array->total > 1) {
      lastwordnode = NULL;
    }
    searchPointer = lookup_node_hash_table(word_table, *word);
    word++;
  }
  if (searchPointer == NULL)
    return -1;
  searchPointer->isword = 0;
  if (lastwordnode != NULL){
    clear_node(lastwordnode);
    dealloc_node(lastwordnode);
  }
  return 0;
}
예제 #6
0
void Textual::reset() {
  clear_node(htmlDocument().body());
  setMove(0, -1, "Mainline:");
}
예제 #7
0
void Textual::setMove(const Index& index, int turn, const DecoratedMove& move,
                                                          const QString& comment) {
  //kDebug() << "i= " << index;
  DOM::HTMLDocument document = htmlDocument();
  QString istr = (QString)index;

  DOM::Element this_mv = document.getElementById("mv_"+istr);
  DOM::Element this_cm = document.getElementById("cm_"+istr);
  if(!this_mv.isNull() && !this_cm.isNull()) {
    clear_node(this_mv);
    for(int i=0;i<move.size();i++) {
      DOM::Text t = document.createTextNode(move[i].m_string);
      this_mv.appendChild(t);
    }

    clear_node(this_cm);
    if(!comment.isEmpty()) {
      this_cm.appendChild(document.createTextNode(comment));
      this_cm.appendChild(document.createTextNode(QString(" ")));
    }
    return;
  }

  DOM::Element parent;
  DOM::Element prev_mv;
  DOM::Element prev_cm;

  if(index != Index(0)) {
    prev_cm = document.getElementById("cm_"+index.prev());
    prev_mv = document.getElementById("mv_"+index.prev());
    if(prev_cm.isNull() || prev_mv.isNull()) {
      kDebug() << " --> Error in Textual::setMove, no previous move!";
      return;
    }
  }

  int mv_num = 0;
  int sub_mv_num = 0;
  if(!prev_mv.isNull()) {
    int prev_turn = prev_mv.getAttribute("turn").string().toInt();
    int prev_mv_num = prev_mv.getAttribute("mvnum").string().toInt();
    int prev_sub_mv_num = prev_mv.getAttribute("submvnum").string().toInt();
    if(prev_turn != turn)
      mv_num = prev_mv_num+1;
    else {
      mv_num = prev_mv_num;
      sub_mv_num = prev_sub_mv_num+1;
    }
  }

  if(!index.nested.size()) {
    parent = document.body();
    if(parent.isNull()) {
      kDebug() << "QUEEEEEEEEE!!!!!!!";
      return;
    }
  }
  else if(index.atVariationStart()) {
    QString var_id = "vc_" + istr;
    DOM::Element add_before = prev_cm.nextSibling();

    while(!add_before.isNull()) {

      QString id = add_before.getAttribute("id").string();
      if(id.startsWith("vc_") && id < var_id)
        add_before = add_before.nextSibling();
      else
        break;
    }

    DOM::Element var_el = document.createElement("span");
    var_el.setAttribute("id", var_id);
    var_el.setAttribute("class", "variation");
    var_el.appendChild(document.createTextNode("[ "));


    parent = document.createElement("span");
    parent.setAttribute("id", "vr_" + istr);
    DOM::Element vk_el = document.createElement("span");
    vk_el.setAttribute("id", "vk_" + istr);
    vk_el.setAttribute("class", "comment");
    //vk_el.setContentEditable(true);
    parent.appendChild(vk_el);
    var_el.appendChild(parent);

    var_el.appendChild(document.createTextNode("] "));
    prev_cm.parentNode().insertBefore(var_el, add_before);

    if(!add_before.isNull() && add_before.getAttribute("id").string().startsWith("mv_")) {
      int mv_num = add_before.getAttribute("mvnum").string().toInt();
      int sub_mv_num = add_before.getAttribute("submvnum").string().toInt();
      QString num_str;
      if(m_layout_style == 0) {
        if(mv_num%2)
          num_str = QString("%1. ").arg((mv_num+1)/2);
        else
          num_str = QString("%1. ... ").arg((mv_num+2)/2);
      }
      else {
        if(sub_mv_num==0)
          num_str = QString("%1. ").arg(mv_num);
        else
          num_str = QString("%1+%2. ").arg(mv_num).arg(sub_mv_num);
      }
      DOM::Element num_el = document.createElement("a");
      num_el.setAttribute("class", "mvnum");
      num_el.setAttribute("id", "nm_"+istr);
      num_el.appendChild(document.createTextNode(num_str));
      prev_cm.parentNode().insertBefore(num_el, add_before);
    }
  }
  else {
    Index pi = index.prev(index.nested.back().num_moves);
    parent = document.getElementById("vr_"+pi);
    if(parent.isNull()) {
      kDebug() << " --> Error in Textual::setMove, no variation?!?!?";
      return;
    }
  }

  if(mv_num>0 && ((sub_mv_num==0 && (mv_num%2 || m_layout_style)) || parent.lastChild() != prev_cm) ) {
    QString num_str;
    if(m_layout_style == 0) {
      if(mv_num%2)
        num_str = QString("%1. ").arg((mv_num+1)/2);
      else
        num_str = QString("%1. ... ").arg((mv_num+2)/2);
    }
    else {
      if(sub_mv_num==0)
        num_str = QString("%1. ").arg(mv_num);
      else
        num_str = QString("%1+%2. ").arg(mv_num).arg(sub_mv_num);
    }
    DOM::Element num_el = document.createElement("a");
    num_el.setAttribute("class", "mvnum");
    num_el.setAttribute("id", "nm_"+istr);
    num_el.appendChild(document.createTextNode(num_str));
    parent.appendChild(num_el);
  }

  DOM::Element mv_el = document.createElement("a");
  mv_el.setAttribute("id", "mv_"+istr);
  mv_el.setAttribute("href", "index://"+istr);
  mv_el.setAttribute("class", "move");
  mv_el.setAttribute("turn", QString::number(turn));
  mv_el.setAttribute("mvnum", QString::number(mv_num));
  mv_el.setAttribute("submvnum", QString::number(sub_mv_num));
  for(int i=0;i<move.size();i++) {
    if(move[i].m_type == MovePart::Figurine) {
      ::Loader::Glyph g = m_loader.getValue< ::Loader::Glyph>(move[i].m_string);
      DOM::Element el = document.createElement("span");
#if 1
      kDebug() << "size = " << QString("%1%").arg(g.m_font.pointSize()*100/12);
      el.style().setProperty("font-size", QString("%1%").arg(g.m_font.pointSize()*100/12), "important");
      el.style().setProperty("line-height", QString("%1%").arg(g.m_font.pointSize()*100/12), "important");
#endif
      kDebug() << "familiy = " << g.m_font.family();
      el.style().setProperty("font-weight", "normal", "important");
      el.style().setProperty("font-family", g.m_font.family(), "important");
      DOM::Text t = document.createTextNode(QString(g.m_char));
      el.appendChild(t);
      mv_el.appendChild(el);
    }
    else {
      DOM::Text t = document.createTextNode(move[i].m_string);
      mv_el.appendChild(t);
    }
  }
  parent.appendChild(mv_el);

  parent.appendChild(document.createTextNode(QString(" ")));

  DOM::Element cm_el = document.createElement("span");
  cm_el.setAttribute("id", "cm_"+istr);
  cm_el.setAttribute("class", "comment");
  if(!comment.isEmpty()) {
    cm_el.appendChild(document.createTextNode(comment));
    cm_el.appendChild(document.createTextNode(QString(" ")));
  }
  //cm_el.setContentEditable(true);
  parent.appendChild(cm_el);
}
예제 #8
0
 /* 清空 */
 void clear() 
 {
     clear_node(root);
     for (int i = 0; i < Size; ++i)
         root.child[i] = 0;
 }
int
main(int argc, char **argv)
{
	int                 rc = 0;
	int                 ch = 0;
	mysql_connection_t  conn;
	char               *node = NULL;
	char               *mask_str = NULL;
	int                 port = -1;
#if HAVE_LIBGENDERS
	static char const   str_opts[] = "hCc:sr:Rp:eE:Sf";
#else
	static char const   str_opts[] = "hCc:sr:Rp:eE:S";
#endif
	static const struct option long_opts [] = {
	   {"help", 0, 0, 'h'},
	   {"clear-all", 0, 0, 'C'},
	   {"clear", 1, 0, 'c'},
	   {"report", 1, 0, 'r'},
	   {"report-all", 0, 0, 'R'},
	   {"report-error", 0, 0, 'e'},
	   {"report-error-mask", 1, 0, 'E'},
	   {"port", 1, 0, 'p'},
	   {"show-queries", 0, 0, 's'},
	   {"node-name-map", 1, 0, 1},
	   {"line-mode", 0, 0, 'l'},
#if HAVE_LIBGENDERS
	   {"sum-fabric-errors", 0, 0, 'f'},
#endif
	   { }
	};

	argv0 = argv[0];

	while ((ch = getopt_long(argc, argv, str_opts, long_opts, NULL)) != -1) {
		switch (ch) {
		case 1:
			node_name_map_file = strdup(optarg);
			break;
		case 'C':
			printf("clearing all\n");
			mode = CLEAR_ALL;
			break;
		case 'c':
			printf("clearing node %s\n", optarg);
			node = strdup(optarg);
			mode = CLEAR_NODE;
			break;
		case 'r':
			node = strdup(optarg);
			mode = REPORT_NODE;
			break;
		case 'R':
			mode = REPORT_ALL;
			break;
		case 'e':
			mode = REPORT_ERROR;
			break;
		case 'E':
			mode = REPORT_ERROR;
			mask_str = strdup(optarg);
			break;
		case 'p':
			port = atoi(optarg);
			if (port <= 0) {
				fprintf(stderr,
					"Invalid port value specified : \"%d\"\n",
					port);
				usage();
				exit(1);
			}
			if (mode == QUERY_ALL) { mode = REPORT_ALL; }
			break;
		case 's':
			show_queries = 1;
			break;
		case 'S':
			skummee_output = 1;
			break;
#if HAVE_LIBGENDERS
		case 'f':
			sum_fabric_errors = 1;
			break;
#endif
		case 'h':
		default:
			usage();
			exit(0);
		}
	}

	node_name_map = open_node_name_map(node_name_map_file);
	
	/* work */
	construct_mysql_connection(&conn);
	sql_setup_db_conn(&conn);

	switch (mode) {
		case CLEAR_NODE:
			rc = clear_node(&conn, node);
			break;
		case REPORT_NODE:
			rc = report(&conn, node, port);
			break;
		case REPORT_ALL:
			rc = report(&conn, NULL, port);
			break;
		case REPORT_ERROR:
			rc = report_error(&conn, mask_str);
			break;
		case CLEAR_ALL:
			rc = clear_all(&conn);
			break;
		default:
		case QUERY_ALL:
			rc = query_status(&conn);
			break;
	}

	mysql_close(&(conn.mysql));
	close_node_name_map(node_name_map);

	return (rc);
}