Пример #1
0
Task* LoadTask(char* name) { // modif quand CMD.wd
	FILE* t;
	CMD command;
	char task[1024];
	char* ptr_on_wd;
	Task* tsk = NotUsed();
	
	if (tsk!=NULL) {
		sprintf(task, "%s/%s", PATH_TO_TASKS, name);
		t = fopen(task, "r");
		if (t!=NULL) {
			strncpy(tsk->id, name, 64);
			setEmpty(&(tsk->q));
			tsk->inuse=1;
			tsk->exec=0;
			tsk->demand=0;
			while (fgets(command.cmd, 1024, t)!=NULL) {
				CleanLineFeed(command.cmd);
				if ((ptr_on_wd=strchr(command.cmd, '#'))!=NULL) {
					*ptr_on_wd='\0';
					sprintf(command.wd, "%s", ptr_on_wd+1);
				}
				else command.wd[0]='\0';
				if (!filled(&(tsk->q)))
					addTail(&(tsk->q), command);
			}
			fclose(t);
			sha->loaded++;
			return tsk;
		}
	}
	return NULL;
}
Пример #2
0
static void *_list_insert_item(QSP_ARG_DECL  Container *cnt_p, Item *ip)
{
	Node *np;
	np = mk_node(ip);
	addTail( cnt_p->cnt_lp, np );
	return np;
}
Пример #3
0
static COMMAND_FUNC( new_obj_list )
{
	int n;
	const char *s;
	List *lp;
	Node *np;

	s=NAMEOF("object name");

	n=how_many("number of objects in this list");
	lp=new_list();
	while(n--){
		Data_Obj *dp;

		dp = pick_obj("");
		if( dp != NULL ){
			np=mk_node(dp);
			addTail(lp,np);
		}
	}

	if( make_obj_list(s,lp) == NULL ){
		sprintf(ERROR_STRING,"error making object list %s");
		warn(ERROR_STRING);
	}
}
Пример #4
0
void get_camera_features( PGR_Cam *pgcp )
{
	Node *np;
	int i;

	if ( /*dc1394_get_camera_feature_set*/
		dc1394_feature_get_all( pgcp->pc_cam_p, &pgcp->pc_features ) != DC1394_SUCCESS ) {
		NERROR1("get_camera_features:  unable to get camera feature set");
	}

	/* Now can the table and build the linked list */
	/* We may call this again after we have diddled the controls... */
	/* releasing and rebuilding the list is wasteful, but should work... */
	if( pgcp->pc_feat_lp != NULL ){
		while( (np=remHead(pgcp->pc_feat_lp)) != NULL )
			rls_node(np);
	} else {
		pgcp->pc_feat_lp = new_list();
	}


	for(i=0;i<DC1394_FEATURE_NUM;i++){
		dc1394feature_info_t * f;

		f = &pgcp->pc_features.feature[i];

		assert( f->id >= DC1394_FEATURE_MIN && f->id <= DC1394_FEATURE_MAX );

		if(f->available){
			np = mk_node(f);
			addTail(pgcp->pc_feat_lp,np);
		}
	}
}
Пример #5
0
// hàm đọc file dữ liệu 
int readBook (LIST &l)
{
	FILE *fn = fopen("Data.txt", "rt"); // mở file
	if(fn == NULL) 
		return 0;

	char a[10];
	BOOK s;
	int n = 0; // số lượng sách
	
	for(int i = 0; fgets(a, 10, fn) ; i++) // điều kiện đọc là có dấu xuống dòng
	{
		n++; // cập nhật số lượng sách
		// đọc từng dòng và gán lần lượt vào các thành phần ID, Name, Author, Year, PH của BOOK s
		fgets(s.ID, 50, fn);   
		fgets(s.Name, 50, fn); 
		fgets(s.Author, 50, fn);
		fgets(s.Year, 10, fn);
		fgets(s.PH, 50, fn);

		NODE *p = getNode(s); // tạo node mới với thành phần info là BOOK s
		if(p == NULL)
			return 0;
		else
			addTail(l,p); // thêm node vừa tạo vào đuôi danh sách
	}

	printf("\n\n So luong sach hien co trong thu vien la: %d quyen\n", n);
	// đóng file
	fclose (fn);
	Output(l); // in ra màn hình danh sách mới đọc được
	return n;
}
Пример #6
0
// add x at position k
// 0 <= k (< getQSize(q))
// !filled(q)
void addElem(Queue q, SQueue x, int k){
	int i;
	if (k >= getLength(q)) addTail(q, x);
	else if (k==0) addHead(q, x);
	else {
		if (k >= getLength(q)/2) {
			for (i=getLength(q)-1; i>=k; i--) {
				setElem(q, getElem(q, i), i+1);
			}
			setElem(q, x, i+1);
			setQTail(q, getQTail(q)+1);
		}
		else {
			for (i=0; i<k; i++) {
				setElem(q, getElem(q, i), i-1);
			}
			setElem(q, x, i-1);
			setQHead(q, getQHead(q)-1);
			if (getQHead(q)<0) {
				setQHead(q, getQSize(q)+getQHead(q));
				setQTail(q, getQTail(q)+getQSize(q));
			}
		}
	}
}
Пример #7
0
//------------------------------------------------------------------------------
// addTail(Object*) -- Adds an item to the tail of the list.
//------------------------------------------------------------------------------
void List::addTail(Object* const obj)
{
    if (obj == nullptr) return;
    Item* d = new Item;
    d->value = obj;
    obj->ref();
    addTail(d);
}
Пример #8
0
List *list_add_over(List *h1,List *h2,List *p){
  int n=h1->num+h2->num+p->num;
  p->num=n%1000;
  if(h1->next != NULL || h2->next != NULL || n/1000!=0){
    p=addTail(p,n/1000);
    p=list_add_over(h1->next,h2->next,p->next);
  }
  return p->before;
}
Пример #9
0
List *list_multi_int(List *head, int num){
  List *p=head;
  int n=p->num;
  n*=num;
  p->num=n%1000;
  if(n/1000!=0 && p->next==NULL)p=addTail(p,0);
  if(p->next!=NULL)p=list_multi_int_over(p->next,num,n/1000);
  return head;
}
Пример #10
0
Файл: rbtree.c Проект: nasa/QuIP
static void _add_rb_node_to_list(QSP_ARG_DECL  qrb_node *rbn_p, qrb_tree *tree_p)
{
	Node *np;
	Item *ip;

	ip = RB_NODE_ITEM(rbn_p);
	np = mk_node(ip);
	addTail( RB_TREE_ITEM_LIST(tree_p), np );
}
Пример #11
0
List *list_add(List *h1,List *h2){
  List *p;
  int n=h1->num+h2->num;
  p=list_create(n%1000);
  if(h1->next != NULL || h2->next != NULL || n/1000!=0){
    p=addTail(p,n/1000);
    p=list_add_over(h1->next,h2->next,p->next);
  }
  return p;
}
Пример #12
0
List *list_create(int num){
  List *p;
  if((p=(List *)malloc(sizeof(List))) == NULL){
    printf("malloc error\n");
    exit(1);
  }
  p->num=num%1000;
  if(num/1000!=0)p=addTail(p,num/1000);
  return p;
}
Пример #13
0
Файл: z_list.c Проект: ZwS/qudos
void copyList(list_t *src, list_t *dest)
{
	// get and put the data
	int i = 0;

	// empty the destination
	emptyList(dest);
	for (i = 0; i < src->numNodes; i++)
	{
		void *item = getItem(src, i);
		addTail(dest, item);
	}
}
Пример #14
0
Файл: list.c Проект: HAVRM/work
List *sortedaddNode(List *head, char *ss){
  char s=ss[0];
  List *p=head,*f=head;
  while(p->next != NULL && strcmp(p->str,ss)<0){
    f=p;
    p=p->next;
  }
  if(f==p && p->next!=NULL)return addHead(p,ss);
  f->next=NULL;
  f=addTail(f,ss);
  f->next->next=p;
  return head;
}
Пример #15
0
Файл: list.c Проект: HAVRM/work
int main(void){
  List *p=NULL;
  p=addHead(p,"def");
  p=addHead(p,"abc");
  p=addTail(p,"xyz");
  p=sortedaddNode(p,"opq");
  p=sortedaddNode(p,"lmn");
  p=sortedaddNode(p,"uvm");
  disp(p);
  printf("\n");
  p=delNode(p,"opq");
  dispReverse(p);
  return 0;
}
Пример #16
0
void BigInteger::setBigInteger(string str)
{
	int i = 0;
	if(str[0] == '-') {
		sign = '-';
		digit = str.length() - 1;
		i = i + 1;
	}
	else digit = str.length();
	for(i; i < str.length(); i++)
	{
		Node *N = Node::getNode(str[i]);
		addTail(N);
	}
}
Пример #17
0
void SingleLinkedList<T>::SListAppend(SingleLinkedList l){
	if (l.pHead == NULL) return;
	if (pHead == NULL){
		Node* temp;
		temp = l.pHead;
		while (temp != NULL)
		{
			addTail(temp->data);
			temp = temp->pNext;
		}
	}
	else{
		pTail->pNext = l.pHead;
		pTail = l.pTail;
	}
}
Пример #18
0
void List::copyData(const List& org, const bool)
{
    BaseClass::copyData(org);

    // Clear the old list (if any)
    clear();

    // Copy the new list
    const Item* d = org.getFirstItem();
    for ( ; d != nullptr; d = d->getNext() ) {
        Object* p = d->getValue()->clone();
        if (p != nullptr) {
            addTail(p);
            p->unref();     // p is ref() by addTail(), so we can unref();
        }
    }
}
Пример #19
0
static void addStrToList(struct Node **listHead, struct Node **listTail, const char *string)
{
	struct Node *node;

	if(node=malloc(sizeof(struct Node)))
	{
		if(node->string = strdup(string))
		{
			node->line = lineNumber;
			addTail(listHead,listTail,node);
			return;
		}
		free(node);
	}

	puts("NO MEM");
}
Пример #20
0
void addToHash(HashTable* t, char* name, double value) {
	int hash = Hash(name);

	if (t->table[hash] == NULL) {
		t->table[hash] = (List*) malloc(sizeof(List));
	}

	List* l = t->table[hash];

	Node* result = searchList(l, name);

	if (result != NULL) {
		// replace original variable's value with new value
		result->variable.value = value;
	} else {
		addTail(l, name, value);
	}
}
int main()
{
	int i;
	LIST list_a;
	struct IntNode *m;
	struct IntNode *o;

	list_a = newList();

	printf("Created new list structure, size: %d\n", sizeof(list_a));

	if (list_a != NULL)
	{
		for (i = 0; i < 5; i++)
		{
			m = malloc(sizeof(struct IntNode));
			o = malloc(sizeof(struct IntNode));

			printf("Created new IntNodes m, size: %d\n", sizeof(m));
			printf("Created new IntNode o, size: %d\n", sizeof(o));

			if (m != NULL && o != NULL)
			{
				m->data = rand() % 64;
				o->data = rand() % 64;
				addTail(list_a, (NODE)m);
				insertAfter(list_a, (NODE)m, (NODE)o);
			}
		}

		while (!isEmpty(list_a))
		{
			m = (struct IntNode *)remTail(list_a);

			printf("Node data: %d\n", m->data);

			free(m);
		}

		free(list_a);

		printf("De-allocated list structure, size: %d\n", sizeof(list_a));
	}
}
Пример #22
0
int internalSoundIndex(char *name)
{
	int idx = 0;
	int numSounds = listLength(soundList);
	modelsound *sound;
	int i = 0;

	// convert name to lowercase
	for (i = 0; i < strlen(name); i++) 
		name[i] = tolower(name[i]);
	
	// do we already have this sound?
	for (i = 0; i < numSounds; i++)
	{
		sound = (modelsound *)getItem(soundList, i);
		if(strcmp(sound->name, name) == 0)
		{
			return (*actual_soundindex)(name);
		}
	}

	// ok, do we have too many sounds?
	if (numSounds >= MAX_SOUNDS-1)
	{
		soundNumRejected++;
		// ok, we cannot precache anymore
		if (printSoundRejects->value)
			gi.dprintf("%s precache rejected\n", name);
		return 0;
	}
	
	idx = (*actual_soundindex)(name);
	if (idx == 0)
		return 0;

	sound = gi.TagMalloc (sizeof(modelsound), TAG_LEVEL);
	sound->name = gi.TagMalloc (strlen(name) + 1, TAG_LEVEL);
	strcpy(sound->name, name);
	
	addTail(soundList, sound);
	//gi.dprintf("numSounds = %i\n", listLength(&soundList));

	return idx;
}
Пример #23
0
// hàm tạo một danh sách liên kết
void Input (LIST &l)
{
	int n;
	printf("\n Nhap so luong sach muon them vao:");
	scanf("%d", &n);

	for(int i = 1; i <= n; i++) // thêm bao nhiêu quyển sách mới sẽ chạy bấy nhiêu vòng lặp
	{
		BOOK x;
		imBook(x); // nhập thông tin sách muốn thêm vào
		NODE *p = getNode(x); // khởi tạo node mới với phần info là thông tin vừa nhập
		if(p != NULL) // cấp phát thành công
			addTail(l,p); // thêm node mới vào cuối danh sách.
		
	}
	// in ra màn hình danh sách sau khi thêm
	printf("\n  Danh sach sach hien co trong thu vien la:\n"); 
    Output(l);
}
Пример #24
0
//------------------------------------------------------------------------------
// insert(Item*) -- insert a new item before 'refItem'.  If 'refItem' is
//                  null(0), the new item is added to the tail of the list.
//------------------------------------------------------------------------------
bool List::insert(List::Item* newItem, List::Item* refItem)
{
    bool ok = true;
    if (refItem != nullptr) {
        if (refItem == headP) {
            addHead(newItem);
        }
        else {
            newItem->previous = refItem->previous;
            refItem->previous = newItem;
            newItem->previous->next = newItem;
            newItem->next = refItem;
            num++;
        }
    }
    else {
        addTail(newItem);
    }
    return ok;
}
Пример #25
0
void ReloadTask(char* name) { // modif quand CMD.wd
	Task* taskptr;
	FILE* t;
	CMD command;
	char task[1024];
	
	sprintf(task, "%s/%s", PATH_TO_TASKS, name);
	t = fopen(task, "r");
	if (t!=NULL) {
		if ((taskptr = GetTask(name))!=NULL) {
			setEmpty(&(taskptr->q));
			while (fgets(command.cmd, 1024, t)!=NULL) {
				CleanLineFeed(command.cmd);
				if (!filled(&(taskptr->q)))
					addTail(&(taskptr->q), command);
			}
			fclose(t);
		}
	}
	else fprintf(stderr, "*** impossible to load %s task\n", name);
}
Пример #26
0
void _cat_container_items(QSP_ARG_DECL  List *lp, Container *cnt_p)
{
	Node *np;
	Item *ip;
	Enumerator *ep, *orig;

	ep = (*(cnt_p->cnt_typ_p->new_enumerator))(DEFAULT_QSP_ARG  cnt_p);

	if( ep == NULL ) return;	// enumerator is null if the container is empty

	orig = ep;

	while( ep != NULL ){
		ip = (*(ep->e_typ_p->current_enum_item))(ep);
		if( ip != NULL ){
			np = mk_node(ip);
			addTail(lp,np);
		}
		ep = ep->e_typ_p->advance_enum(ep);
	}
	orig->e_typ_p->release_enum(orig);
}
Пример #27
0
Файл: motif.c Проект: E-LLP/QuIP
void make_picker(QSP_ARG_DECL  Screen_Obj *sop)
{
#ifdef HAVE_MOTIF
	int	j;
	Arg	al[20];
	int	ac = 0;
	Screen_Obj *b_sop;	/* button ptr */
	char buf[6];
	int n;
	const char **stringlist;

	if( SOB_N_CYLINDERS(sop) != 1 ){
		sprintf(ERROR_STRING,"picker %s needs %d components, but we're only implementing 1!?",
			SOB_NAME(sop),SOB_N_CYLINDERS(sop));
		WARN(ERROR_STRING);
	}
	n= SOB_N_SELECTORS_AT_IDX(sop,/*component*/ 0 );

	sop->so_frame = generic_frame(curr_panel->po_panel_obj,
		sop, XmSHADOW_IN);

	XtSetArg(al[ac], XmNentryClass, xmToggleButtonWidgetClass); ac++;
	strcpy(buf,"name");
	sop->so_obj = XmCreateRadioBox(sop->so_frame,
		buf, al, ac);

	XtManageChild(sop->so_obj);

#ifdef CAUTIOUS
	if( sop->so_children != NO_LIST ){
		sprintf(ERROR_STRING,"CAUTIOUS:  Picker %s already has a child list!?",SOB_NAME(sop));
		ERROR1(ERROR_STRING);
	}
#endif /* CAUTIOUS */

	SET_SOB_CHILDREN(sop,new_list());

	stringlist = SOB_SELECTORS_AT_IDX(sop,0);

	// The choices are created as screen_objs, we
	// need to create a special context for them so that we
	// can have the same choices in multiple pickers and choosers
	// The context name should be the concatenation of the current
	// scrnobj context, and the name of this widget...

	push_widget_context(QSP_ARG  sop);

	for(j=0; j<n; j++) {
		b_sop = simple_object(QSP_ARG  stringlist[j]);
		if( b_sop==NO_SCREEN_OBJ ) return;
		b_sop->so_action_text = savestr(stringlist[j]);
		b_sop->so_parent = sop;
		b_sop->so_flags |= SOT_MENU_ITEM;

		/* The choices need to be part of the panel list (so we can find them
		 * with find_object), but also on the parent list, so we can find them
		 * through it...
		 */

		addHead(curr_panel->po_children,mk_node(b_sop));
		addTail(sop->so_children,mk_node(b_sop));

		b_sop->so_obj = XtCreateManagedWidget(
			b_sop->so_name,			/* widget name */
			xmToggleButtonWidgetClass,	/* widget class */
			sop->so_obj,			/* parent widget */
			NULL, 0);
		fix_names(QSP_ARG  b_sop,sop);
										/* client data */
		XtAddCallback(b_sop->so_obj, XmNvalueChangedCallback, chooser_func, NULL);
		XtManageChild(b_sop->so_obj);
	}

	pop_scrnobj_context(SINGLE_QSP_ARG);

	SET_SOB_HEIGHT(sop, CHOOSER_HEIGHT + CHOOSER_ITEM_HEIGHT*n );
#endif /* HAVE_MOTIF */
}
Пример #28
0
void HelpState::addPlankton(PlanktonController::Type type)
{
    auto entity = std::make_unique<Entity>(m_messageBus);
    entity->setWorldPosition({ static_cast<float>(Util::Random::value(0, 1920)), static_cast<float>(Util::Random::value(0, 1080)) });

    auto physComponent = m_physWorld.addBody(planktonSize);
    physComponent->setPosition(entity->getWorldPosition());
    physComponent->setTriggerOnly(true);
    physComponent->setName("control");
    entity->addComponent<PhysicsComponent>(physComponent);

    auto& appInstance = getContext().appInstance;
    bool colourblind = appInstance.getGameSettings().colourblindMode;
    AnimatedDrawable::Ptr ad;
    auto ident = ParticleSystem::create(Particle::Type::Ident, m_messageBus);
    ident->setTexture(appInstance.getTexture("assets/images/particles/ident.png"));
    auto text = std::make_unique<TextDrawable>(m_messageBus);
    text->setFont(appInstance.getFont("assets/fonts/Ardeco.ttf"));
    switch (type)
    {
    case PlanktonController::Type::Good:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food01.png"));
        ad->loadAnimationData("assets/images/player/food01.cra");
        (colourblind) ? ident->setColour({ 14u, 160u, 225u }) : ident->setColour({ 84u, 150u, 75u });
        text->setString("+50 HP");
        break;
    case PlanktonController::Type::Bad:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food02.png"));
        ad->loadAnimationData("assets/images/player/food02.cra");
        (colourblind) ? ident->setColour({ 214u, 190u, 25u }) : ident->setColour({ 184u, 67u, 51u });
        text->setString("-35 HP");
        break;
    case PlanktonController::Type::Bonus:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food03.png"));
        ad->loadAnimationData("assets/images/player/food03.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("+100 HP");
        break;
    case PlanktonController::Type::UberLife:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/bonus.png"));
        ad->loadAnimationData("assets/images/player/bonus.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("FULL HEALTH");
        break;
    default:
        break;
    }
    ident->setName("ident");
    entity->addComponent<ParticleSystem>(ident);

    text->setCharacterSize(40u);
    Util::Position::centreOrigin(*text);
    text->setPosition(0.f, 40.f);
    text->setName("text");
    entity->addComponent<TextDrawable>(text);

    ad->setBlendMode(sf::BlendAdd);
    ad->setOrigin(sf::Vector2f(ad->getFrameSize()) / 2.f);
    if (!ad->getAnimations().empty()) ad->play(ad->getAnimations()[0]);
    ad->setName("drawable");
    entity->addComponent<AnimatedDrawable>(ad);

    auto trail = ParticleSystem::create(Particle::Type::Trail, m_messageBus);
    trail->setTexture(appInstance.getTexture("assets/images/particles/circle.png"));
    float particleSize = planktonSize / 12.f;
    trail->setParticleSize({ particleSize, particleSize });
    trail->setName("trail");
    trail->setEmitRate(10.f);
    entity->addComponent<ParticleSystem>(trail);

    if (type == PlanktonController::Type::UberLife)
    {
        auto tails = std::make_unique<TailDrawable>(m_messageBus);
        tails->addTail(sf::Vector2f(-18.f, -15.f));
        tails->addTail(sf::Vector2f(-8.f, -5.f));
        tails->addTail(sf::Vector2f(-8.f, 5.f));
        tails->addTail(sf::Vector2f(-18.f, 15.f));
        tails->setName("tail");
        entity->addComponent<TailDrawable>(tails);
    }

    auto controller = std::make_unique<PlanktonController>(m_messageBus);
    controller->setType(type);
    controller->setDecayRate(0.f);
    controller->setColourblind(colourblind);
    entity->addComponent<PlanktonController>(controller);

    m_rootNode.addChild(entity);
}
Пример #29
0
Файл: param.c Проект: E-LLP/QuIP
static COMMAND_FUNC( do_chng_one )
{
	Param *p;
	const char **pnlist;
	int nlist=0;
	int i=0;
	const char *s;

	p=theptbl;

	/* count the number of parameters */
	while( p->p_type != NULL_P_TYPE ) {
		nlist++;
		p++;
	}

	pnlist = (const char **) getbuf( (nlist+1) * sizeof(char *) );
	if( pnlist == NULL ) mem_err("do_chng_one");

#ifdef HAVE_HISTORY

	if( intractive(SINGLE_QSP_ARG) && IS_TRACKING_HISTORY(THIS_QSP) ){
		List *lp;
		Node *np;

		lp = new_list();
		for(i=0;i<nlist;i++){
			pnlist[i] = theptbl[i].p_name;
			np = mk_node(&theptbl[i]);
			addTail(lp,np);
		}
		pnlist[i]="all";
		np = mk_node(&pnlist[i]);
		addTail(lp,np);

		if( intractive(SINGLE_QSP_ARG) ){
			char pline[LLEN];
			make_prompt(QSP_ARG  pline,PNAME_PMPT);
			new_defs(QSP_ARG  pline);		/* is this needed? */
			init_hist_from_item_list(QSP_ARG  PNAME_PMPT,lp);
		}

		dellist(lp);
	}

#else /* ! HAVE_HISTORY */
	for(i=0;i<nlist;i++)
		pnlist[i] = theptbl[i].p_name;
#endif /* ! HAVE_HISTORY */

	s=NAMEOF(PNAME_PMPT);
	if( !strcmp(s,"all") ){
		p=theptbl;
		while( p->p_type != NULL_P_TYPE ) {
			getparm(QSP_ARG  p);
			showparm(QSP_ARG  p);
			p++;
		}
		return;
	} else if( get_pval(QSP_ARG  s,theptbl) == -1 ){
		sprintf(ERROR_STRING,"Unknown parameter \"%s\"",s);
		WARN(ERROR_STRING);
	}
}
Пример #30
0
void AddToTask(Task* p) {
	p->demand=1;
	if (!filled(&(p->q))) addTail(&(p->q), addedCommand);
	p->demand=0;
}