Пример #1
0
void findAllPath(tNode* root, node** nl, int sum)
{
       if(root == NULL)
       {
               printf("node is null\n");
               return ;
       } 
       int* key = (int*)root->item;
       printf("Node of this path:");
       print_list(*nl, printl);
        sleep(1);
       printf("Sum of this path:%d\n", sum + *key);
       if(root->lchild != NULL)
       {
               listAppend(nl, root->lchild);
               findAllPath(root->lchild, nl, sum + *key);
               listPop(nl);
       }
       if(root->rchild != NULL)
       {
               listAppend(nl, root->rchild);
               findAllPath(root->rchild, nl, sum + *key);
               listPop(nl);
       }
             
}
Пример #2
0
const char *raceGetList(bool pc_only) {
  static char buf[MAX_BUFFER];
  LIST       *name_list = newList();
  HASH_ITERATOR *race_i = newHashIterator(race_table);
  const char      *name = NULL;
  RACE_DATA       *data = NULL;

  // collect all of our names
  ITERATE_HASH(name, data, race_i) {
    if(pc_only && data->pc_ok == FALSE) continue;
    listPutWith(name_list, strdup(name), strcmp);
  }
  deleteHashIterator(race_i);

  // print all the names to our buffer
  char *new_name = NULL; // gotta use a new name ptr.. can't free const
  int i = 0;
  while( (new_name = listPop(name_list)) != NULL) {
    i += snprintf(buf+i, MAX_BUFFER-i, "%s%s",
		  new_name, (listSize(name_list) > 0 ? ", " : ""));
    free(new_name);
  }

  // delete our list of names and return the buffer
  deleteListWith(name_list, free);
  return buf;
}
Пример #3
0
void run_code(PyObject *code, PyObject *dict, const char *locale) {
  if(script_loop_depth >= MAX_LOOP_DEPTH) {
    // should we flag some sort of error, here?
    //***********
    // FINISH ME
    //***********

    script_ok = FALSE;
  }
  else {
    listPush(locale_stack, strdupsafe(locale));

    // try executing the code
    script_ok = TRUE;
    script_loop_depth++;
    PyObject *retval = PyEval_EvalCode((PyCodeObject *)code, dict, dict);
    script_loop_depth--;

    // did we throw an error?
    if(retval == NULL && PyErr_Occurred() != PyExc_SystemExit)
      script_ok = FALSE;

    // garbage collection
    free(listPop(locale_stack));
    Py_XDECREF(retval);
  }
}
Пример #4
0
//
// save all of our pending persistent rooms to disc
void flush_persistent_rooms_event(void *owner, void *data, const char *arg) {
  ROOM_DATA *room = NULL;
  while( (room = listPop(p_to_save)) != NULL) {
    worldStorePersistentRoom(gameworld, roomGetClass(room), room);
    roomClearPersistentDirty(room);
  }
}
Пример #5
0
void
tcCheck(TConst tc)
{
	Bool	result;
	AbLogic known;
	extern AbLogic abCondKnown;
	
	listPush(TConst, tc, tcStack);

	switch (tcTag(tc)) {
	case TC_Satisfies:
		known = abCondKnown;
		abCondKnown = tcKnown(tc);
		result = tfSatisfies1(tc->ab0, tcArgv(tc)[0], tcArgv(tc)[1]);
		abCondKnown = known;
		break;
	default:
		bugBadCase(tcTag(tc));
		NotReached(result = false);
	}

	listPop(TConst, tc, tcStack, tcEq);

	if (!result) {
		if (DEBUG(tc)) {
			tcPrint(dbOut, tc);
			fnewline(dbOut);
		}
		tiTopFns()->terrorTypeConstFailed(tc);
	}
}
Пример #6
0
void *popHead(List *l) {
  void *popd = NULL;
  if (l != NULL && l->head != NULL) {
    popd = listPop(&l->head);
    --l->size;
  }

  return popd;
}
Пример #7
0
//
// tries to make a char parse var
PARSE_VAR *use_one_parse_token_char(CHAR_DATA *looker, PARSE_TOKEN *tok,
				    const char *name) {
  int    type = FOUND_NONE;
  void *found = find_specific(looker, name, "", "", FIND_TYPE_CHAR, tok->scope,
			      tok->all_ok, &type);

  // make sure we found something...
  if(found == NULL)
    return NULL;
  else {
    PARSE_VAR *var = newParseVar(PARSE_VAR_CHAR);

    // if multiple vals were possible, flag it
    var->multiple_possible = tok->all_ok;

    // make sure it's not us if that's not allowed
    if(type == FOUND_CHAR) {
      if(tok->self_ok || looker != found)
	var->ptr_val = found;
      else {
	deleteParseVar(var);
	var = NULL;
      }
    }
    // if we got a list, make sure we remove ourself as neccessary
    else if(type == FOUND_LIST) {
      if(!tok->self_ok)
	listRemove(found, looker);
      // make sure we're not empty...
      if(listSize(found) > 1) {
	var->ptr_val  = found;
	var->multiple = TRUE;
      }
      else if(listSize(found) == 1) {
	var->ptr_val = listPop(found);
	deleteList(found);
      }
      else {
	deleteList(found);
	deleteParseVar(var);
	var = NULL;
      }
    }
    // this shouldn't happen...
    else {
      deleteParseVar(var);
      var = NULL;
    }

    // return what we found, if anything
    return var;
  }
}
Пример #8
0
void next_cmd_from_buffer(SOCKET_DATA *dsock) {
  // do we have stuff in our input list? If so, use that instead of inbuf
  dsock->cmd_read = FALSE;
  if(listSize(dsock->input) > 0) {
    char *cmd = listPop(dsock->input);
    bufferClear(dsock->next_command);
    bufferCat(dsock->next_command, cmd);
    dsock->cmd_read    = TRUE;
    dsock->bust_prompt = TRUE;
    free(cmd);
  }
  else {
    int i = 0, cmd_end = -1;

    // are we building an IAC command? Try to continue it
    if(bufferLength(dsock->iac_sequence) > 0)
      i += read_iac_sequence(dsock, 0);

    // copy over characters until we hit a newline, an IAC command, or \0
    for(; dsock->inbuf[i] != '\0' && cmd_end < 0; i++) {
      switch(dsock->inbuf[i]) {
      default:
	// append us to the command
	bufferCatCh(dsock->next_command, dsock->inbuf[i]);
	break;
      case '\n':
	// command end found
	cmd_end = ++i;
      case '\r':
	// ignore \r ... only pay attention to \n
	break;
      case (signed char) IAC:
	i += read_iac_sequence(dsock, i) - 1;
	break;
      }
      if(cmd_end >= 0)
	break;
    }

    // move the context of inbuf down
    int begin = 0;
    while(dsock->inbuf[i] != '\0')
      dsock->inbuf[begin++] = dsock->inbuf[i++];
    dsock->inbuf[begin] = '\0';
    
    // did we find a command?
    if(cmd_end >= 0) {
      dsock->cmd_read    = TRUE;
      dsock->bust_prompt = TRUE;
    }
  }
}
Пример #9
0
PyObject *eval_script(PyObject *dict, const char *statement,const char *locale){
  listPush(locale_stack, strdupsafe(locale));
 
  // run the statement
  PyObject *retval = PyRun_String(statement, Py_eval_input, dict, dict);

  // did we encounter an error?
  if(retval == NULL)
    log_pyerr("eval_script terminated with an error:\r\n%s", statement);

  free(listPop(locale_stack));
  return retval;
}
Пример #10
0
void
tcFree(TConst tc)
{
	int l0 = 0;
	if (DEBUG(tc)) {
		l0 = listLength(TConst)(tcList);
		listPop(TConst, tc, tcList, tcEq);
		assert(l0 - 1 == listLength(TConst)(tcList));
	}

	tcCount -= 1;
	stoFree((Pointer) tc);
}
Пример #11
0
//
// tries to make an exit parse var
PARSE_VAR *use_one_parse_token_exit(CHAR_DATA *looker, PARSE_TOKEN *tok, 
				    const char *name) {
  int    type = FOUND_NONE;
  void *found = find_specific(looker, name, "", "", FIND_TYPE_EXIT, tok->scope,
			      tok->all_ok, &type);

  // make sure we found something
  if(found == NULL)
    return NULL;
  else {
    PARSE_VAR *var = newParseVar(PARSE_VAR_EXIT);

    // if multiple vals were possible, flag it
    var->multiple_possible = tok->all_ok;

    // Is it a single exit?
    if(type == FOUND_EXIT)
      var->ptr_val = found;

    // or is it multiple exits?
    else if(type == FOUND_LIST) {
      if(listSize(found) > 1) {
	var->ptr_val = found;
	var->multiple = TRUE;
      }
      else if(listSize(found) == 1) {
	var->ptr_val = listPop(found);
	deleteList(found);
      }
      else {
	deleteList(found);
	deleteParseVar(var);
	var = NULL;
      }
    }

    // We should never reach this case
    else {
      deleteParseVar(var);
      var = NULL;
    }

    // return whatever we found
    return var;
  }
}
Пример #12
0
int main() {
  int i;
  List *l = NULL;

  List *(* listAddFunc)(List *, void *) = append;
#ifdef DEMO_PREPEND
  listAddFunc = prepend;
#endif

  for (i=0; i < 40; ++i) {
    int *tp = (int *)malloc(sizeof(int));
    *tp = i;
    l = listAddFunc(l, tp);
  }

#ifdef DEMO_CIRCULARITY
  while (l->head != NULL) {
    void *vSav = listPop(&(l->head));
    if (vSav != NULL) {
      printf("vS: %d\n", *(int *)vSav);
      free(vSav);
    }
    break;
  }
#endif

  printList(l);
  printf("\n");

  i = 8;

  printf("Size: %d\n", getListSize(l));
  l = removeElem(l, &i, intPtrComp);

  printf("Size: %d\n", getListSize(l));
  printList(l);
  printf("\n");
  destroyList(l);
  return 0;
}
Пример #13
0
static void *check_thread_run(void *args)
{
    int ret;
    thread_data *cdata = args;
    redis_group *srgroup = cdata->srgroup;
    redis_group *trgroup = cdata->trgroup;
    dict *nodes;
    dictEntry *de;
    dictIterator *di;
    redis_node *rnode;
    struct mbuf *mbuf;

    nodes = srgroup->nodes;
    di = dictGetIterator(nodes);
    while ((de = dictNext(di)) != NULL) {
    	rnode = dictGetVal(de);

        rnode->write_data = cdata;

        /* remove the not used part for source redis node */
        if (rnode->rdb != NULL) {
            redis_rdb_deinit(rnode->rdb);
            rmt_free(rnode->rdb);
            rnode->rdb = NULL;
        }
        
        if (rnode->cmd_data != NULL) {
            while (!mttlist_empty(rnode->cmd_data)) {
                mbuf = mttlist_pop(rnode->cmd_data);
                mbuf_put(mbuf);
            }
            
            mttlist_destroy(rnode->cmd_data);
            rnode->cmd_data = NULL;
        }

        if (rnode->sockpairfds[0] > 0) {
            close(rnode->sockpairfds[0]);
            rnode->sockpairfds[0] = -1;
        }

        if (rnode->sockpairfds[1] > 0) {
            close(rnode->sockpairfds[1]);
            rnode->sockpairfds[1] = -1;
        }

        if (rnode->rr != NULL) {
            redis_replication_deinit(rnode->rr);
            rmt_free(rnode->rr);
            rnode->rr = NULL;
        }

        if (rnode->piece_data != NULL) {
            while ((mbuf = listPop(rnode->piece_data)) != NULL) {
                mbuf_put(mbuf);
            }
            
            listRelease(rnode->piece_data);
            rnode->piece_data = NULL;
        }

        /* add the used part for source redis node */
        if (rnode->send_data == NULL) {
            rnode->send_data = listCreate();
            if (rnode->send_data == NULL) {
                log_error("ERROR: Create msg list failed: out of memory");
                return 0;
            }
        }

        if (rnode->sent_data == NULL) {
            rnode->sent_data = listCreate();
            if (rnode->sent_data == NULL) {
                log_error("ERROR: Create msg list failed: out of memory");
                return 0;
            }
        }

        if (rnode->sk_event < 0) {
            rnode->sk_event = socket(AF_INET, SOCK_STREAM, 0);
            if(rnode->sk_event < 0){
                log_error("ERROR: Create sk_event for node[%s] failed: %s", 
                    rnode->addr, strerror(errno));
                return 0;
            }
        }
        ret = aeCreateFileEvent(cdata->loop, rnode->sk_event, 
            AE_WRITABLE, check_begin, rnode);
        if (ret != AE_OK) {
            log_error("ERROR: send_data event create %ld failed: %s",
                cdata->thread_id, strerror(errno));
            return 0;
        }
    }
    dictReleaseIterator(di);

    nodes = trgroup->nodes;
    di = dictGetIterator(nodes);
    while ((de = dictNext(di)) != NULL) {
    	rnode = dictGetVal(de);

        rnode->write_data = cdata;
    }
    dictReleaseIterator(di);

    aeMain(cdata->loop);
    return 0;
}
Пример #14
0
void
tcPop(TConst tc)
{
	listPop(TConst, tc, tfConsts(tcOwner(tc)), tcEq);
}