Exemplo n.º 1
0
local int unmarkPlayer(kothmark *md, const char *name)
{
	Link *link;

	for (link = LLGetHead(&md->listed); link; link = link->next)
		if (strcasecmp(name,((marklistednode*)link->data)->name) == 0)
		{
			afree(link->data);
			LLRemove(&md->listed, link->data);

			md->listCount--;
			return 1;
		}

	return 0;
}
Exemplo n.º 2
0
local void postReward(Arena *arena, TurfArena *ta)
{
	TurfStats *ts, **p_ts = P_ARENA_DATA(arena, tskey);
	Link *l = NULL;
	TurfStatsData *tsd;

	if (!arena || !*p_ts) return; else ts = *p_ts;

	LOCK_STATUS(arena);

	if (ts->numStats >= ts->maxHistory)
	{
		/* we already have the maximum # of histories
		 * erase oldest history (end of linked list) */
		Link *nextL = NULL;
		TurfStatsData *data;

		for(nextL = LLGetHead(&ts->stats) ; nextL ; nextL=nextL->next)
		{
			l = nextL;
		}

		l = LLGetHead(&ts->stats);  /* l now points to the end of the LinkedList */
		data = l->data;
		LLRemove(&ts->stats, data); /* remove the link */
		ts->numStats--;
	}

	/* create new node for stats data, add it to the linked list, and fill in data */
	tsd = amalloc(sizeof(TurfStatsData));
	LLAddFirst(&ts->stats, tsd);
	ts->numStats++;

	tsd->numFlags       = ta->numFlags;
	tsd->numPlayers     = ta->numPlayers;
	tsd->numTeams       = ta->numTeams;
	tsd->numWeights     = ta->numWeights;
	tsd->numPoints      = ta->numPoints;
	tsd->sumPerCapitaFlags   = ta->sumPerCapitaFlags;
	tsd->sumPerCapitaWeights = ta->sumPerCapitaWeights;

	tsd->tags       = ta->tags;
	tsd->steals     = ta->steals;
	tsd->lost       = ta->lost;
	tsd->recoveries = ta->recoveries;

	/* copy teams data */
	LLInit(&tsd->teams);
	for(l = LLGetHead(&ta->teams) ; l ; l=l->next)
	{
		TurfTeam *src = l->data;
		TurfTeam *dst = amalloc(sizeof(TurfTeam));

		*dst = *src;

		LLAdd(&tsd->teams, dst);
	}

	ts->dingCount++;
	if (ts->dingCount >= ts->statsOnDing)
		ADisplay(arena, 0);  /* output for the history we just copied */

	UNLOCK_STATUS(arena);
}
Exemplo n.º 3
0
Arquivo: cache.c Projeto: nikmash/C
int searchand(linkedListPtr foundlist, linkedListPtr searchlist, data *dataptr){
	int y;
	int w;
	int boolean;
	boolean = 1;
	int on = 0;
	int lru;


	/*THIS FIRST FOR LOOP HAS TO PUT THE FILES OF THE FIRST WORD INTO THE FOUND ARRAY */

	llnode *currsearch = searchlist->head;

	while(on == 0){
		for (y = 0; y < lwsize; y++){
			w = strcmp(currsearch->filename, listwords[y]->string);
			if (w == 0){
				listwords[y]->counter++;
				llnode *curr = listwords[y]->filelist->head;
				llnode *prev = NULL;
				while(curr != NULL){
					LLInsert(foundlist, curr->filename);
					prev = curr;
					curr = curr->next;	
				}
				on = 1;
				break;
			}
		}
		if(w != 0){
			printf("Word was not in cache %s \n", currsearch->filename);
			lru = LRU(currsearch->filename, dataptr, searchlist);

			if(lru == -1){
				printf("Could not find %s in specified text file \n", currsearch->filename);
				return 0;
			}
		}
	}

	currsearch = currsearch->next;
	
	/* THIS SECOND FOR LOOP GETS ALL THE OTHER WORDS AND THEIR FILES AND COMPARES THEM TO WHATEVER IS ALREADY IN THE FOUND ARRAY.
	EACH FILE IN THE FOUND ARRAY IS COMPARED TO THE OTHER WORDS' FILES, AND IF IT DOESNT EXIST THEN THAT FILE IS DELETED 
	FROM THE FOUND ARRAY */
	int found = 0;
	
	while(currsearch != NULL){
		for (y = 0; y < lwsize; y++){
			w = strcmp(currsearch->filename, listwords[y]->string);

			if (w == 0){
				found = 1;
				listwords[y]->counter++;
				llnode *curr = listwords[y]->filelist->head;
				llnode *prev = NULL;
				llnode *currfound = foundlist->head;


				while(currfound != NULL){
						curr = listwords[y]->filelist->head;

					while(curr != NULL){
							boolean = strcmp(currfound->filename, curr->filename);
							if (boolean == 0){
								break;
							}
							prev = curr;
							curr = curr->next;
					}
					
					if(boolean != 0){
						LLRemove(foundlist, currfound->filename);
					}

					currfound = currfound->next;
					boolean = 1;
				}
				
			}
		}
		if(found == 0){
			printf("%s was not in cache \n", currsearch->filename);
			lru = LRU(currsearch->filename, dataptr, searchlist);
				if(lru == -1){
					printf("%s is not in the specified file", currsearch->filename);
					return 0;
				}
			continue;
		}

		currsearch = currsearch->next;
	}

	if(foundlist->head == NULL){
		fprintf(stderr, "There were no files with all input words \n");
		return 0;
	}

	llnode *currfoundit = foundlist->head;
	while(currfoundit != NULL){

		printf("%s \n", currfoundit->filename);
		currfoundit = currfoundit->next;
	}

	
	return 0;
}