<commit_before>#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>

#include "config.h"

#include "objects.h"
#include "macros.h"
#include "convert.h"
#include "zsfunctions.h"

#include "../conf/zsconfig.h"
#include "../include/zsconfig.defaults.h"

struct userdata {
	int		allup_bytes;
	int		monthup_bytes;
	int		wkup_bytes;
	int		dayup_bytes;
	short		name;
};

/*
 * Modified   : 01.27.2002 Author     : Dark0n3
 * 
 * Description: Updates existing entries in userI and groupI or creates new, if
 * old doesnt exist
 */
void 
updatestats(struct VARS *raceI, struct USERINFO **userI, struct GROUPINFO **groupI, char *usern, char *group, off_t filesize, unsigned int speed, unsigned int start_time)
{
	int		u_no = -1;
	int		g_no = -1;
	int		n;
	double		speedD = filesize * 1024. / speed;

	for (n = 0; n < raceI->total.users; n++) {
		if (strncmp(userI[n]->name, usern, 24) == 0) {
			u_no = n;
			g_no = userI[n]->group;
			break;
		}
	}

	if (u_no == -1) {
		if (!raceI->total.users) {
			raceI->total.start_time = start_time;
			/*
			 * to prevent a possible floating point exception in
			 * convert,
			 */
			/* if first entry in racefile is not the oldest one           */
			if ((int)(raceI->total.stop_time - raceI->total.start_time) < 1)
				raceI->total.stop_time = raceI->total.start_time + 1;
		}
		u_no = raceI->total.users++;
		if (userI[u_no])
			free(userI[u_no]);
		userI[u_no] = malloc(sizeof(struct USERINFO));
		memset(userI[u_no], 0, sizeof(struct USERINFO));
		memcpy(userI[u_no]->name, usern, 24);

		for (n = 0; n < raceI->total.groups; n++) {
			if (strncmp(groupI[n]->name, group, 24) == 0) {
				g_no = n;
				break;
			}
		}

		if (g_no == -1) {
			g_no = raceI->total.groups++;
			if (groupI[g_no])
				free(groupI[g_no]);

			groupI[g_no] = malloc(sizeof(struct GROUPINFO));
			memset(groupI[g_no], 0, sizeof(struct GROUPINFO));
			memcpy(groupI[g_no]->name, group, 24);
		}
		userI[u_no]->group = g_no;
	}
	userI[u_no]->bytes += filesize;
	groupI[g_no]->bytes += filesize;
	raceI->total.size += filesize;

	userI[u_no]->speed += speedD;
	groupI[g_no]->speed += speedD;
	raceI->total.speed += speedD;

	userI[u_no]->files++;
	groupI[g_no]->files++;
	raceI->total.files_missing--;

	speed >>= 10;

	if (speed > (unsigned int)raceI->misc.fastest_user[0]) {
		raceI->misc.fastest_user[1] = u_no;
		raceI->misc.fastest_user[0] = speed;
	}
	if (speed < (unsigned int)raceI->misc.slowest_user[0]) {
		raceI->misc.slowest_user[1] = u_no;
		raceI->misc.slowest_user[0] = speed;
	}
}

/*
 * Modified   : 01.17.2002 Author     : Dark0n3
 * 
 * Description: Sorts userI and groupI Modified by psxc 09.25.2004 - nasty bug
 */
void 
sortstats(struct VARS *raceI, struct USERINFO **userI, struct GROUPINFO **groupI)
{
	int		n;
	int		n2;
	int		t;
	int            *p_array;
	char           *r_list;
	char           *t_list;

	p_array = (int *)m_alloc(raceI->total.users * sizeof(int));
	bzero(p_array, raceI->total.users * sizeof(int));
	r_list = raceI->misc.racer_list;
	t_list = raceI->misc.total_racer_list;

	for (n = 0; n < raceI->total.users; n++) {
		t = p_array[n];
		for (n2 = n + 1; n2 < raceI->total.users; n2++) {
			if (userI[n]->bytes >= userI[n2]->bytes) {
				p_array[n2]++;
			} else {
				t++;
			}
		}
		userI[t]->pos = n;
#if ( get_competitor_list == TRUE )
		if (strcmp(raceI->user.name, userI[n]->name)) {
			r_list += sprintf(r_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
			t_list += sprintf(t_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
		} else {
			t_list += sprintf(t_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
			raceI->user.pos = n;
		}
#else
		if (!strcmp(raceI->user.name, userI[n]->name))
			raceI->user.pos = n;
#endif<commit_msg>ibug 226 and 227 - halfway msg may list wrong racers in the %against cookie.<commit_after>#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>

#include "config.h"

#include "objects.h"
#include "macros.h"
#include "convert.h"
#include "zsfunctions.h"

#include "../conf/zsconfig.h"
#include "../include/zsconfig.defaults.h"

struct userdata {
	int		allup_bytes;
	int		monthup_bytes;
	int		wkup_bytes;
	int		dayup_bytes;
	short		name;
};

/*
 * Modified   : 01.27.2002 Author     : Dark0n3
 * 
 * Description: Updates existing entries in userI and groupI or creates new, if
 * old doesnt exist
 */
void 
updatestats(struct VARS *raceI, struct USERINFO **userI, struct GROUPINFO **groupI, char *usern, char *group, off_t filesize, unsigned int speed, unsigned int start_time)
{
	int		u_no = -1;
	int		g_no = -1;
	int		n;
	double		speedD = filesize * 1024. / speed;

	for (n = 0; n < raceI->total.users; n++) {
		if (strncmp(userI[n]->name, usern, 24) == 0) {
			u_no = n;
			g_no = userI[n]->group;
			break;
		}
	}

	if (u_no == -1) {
		if (!raceI->total.users) {
			raceI->total.start_time = start_time;
			/*
			 * to prevent a possible floating point exception in
			 * convert,
			 */
			/* if first entry in racefile is not the oldest one           */
			if ((int)(raceI->total.stop_time - raceI->total.start_time) < 1)
				raceI->total.stop_time = raceI->total.start_time + 1;
		}
		u_no = raceI->total.users++;
		if (userI[u_no])
			free(userI[u_no]);
		userI[u_no] = malloc(sizeof(struct USERINFO));
		memset(userI[u_no], 0, sizeof(struct USERINFO));
		memcpy(userI[u_no]->name, usern, 24);

		for (n = 0; n < raceI->total.groups; n++) {
			if (strncmp(groupI[n]->name, group, 24) == 0) {
				g_no = n;
				break;
			}
		}

		if (g_no == -1) {
			g_no = raceI->total.groups++;
			if (groupI[g_no])
				free(groupI[g_no]);

			groupI[g_no] = malloc(sizeof(struct GROUPINFO));
			memset(groupI[g_no], 0, sizeof(struct GROUPINFO));
			memcpy(groupI[g_no]->name, group, 24);
		}
		userI[u_no]->group = g_no;
	}
	userI[u_no]->bytes += filesize;
	groupI[g_no]->bytes += filesize;
	raceI->total.size += filesize;

	userI[u_no]->speed += speedD;
	groupI[g_no]->speed += speedD;
	raceI->total.speed += speedD;

	userI[u_no]->files++;
	groupI[g_no]->files++;
	raceI->total.files_missing--;

	speed >>= 10;

	if (speed > (unsigned int)raceI->misc.fastest_user[0]) {
		raceI->misc.fastest_user[1] = u_no;
		raceI->misc.fastest_user[0] = speed;
	}
	if (speed < (unsigned int)raceI->misc.slowest_user[0]) {
		raceI->misc.slowest_user[1] = u_no;
		raceI->misc.slowest_user[0] = speed;
	}
}

/*
 * Modified   : 01.17.2002 Author     : Dark0n3
 * 
 * Description: Sorts userI and groupI
 * Modified by psxc 09.25.2004 - nasty bug
 * Modified by psxc 11.22.2004 - added support for list of ppl against leader.
 */
void 
sortstats(struct VARS *raceI, struct USERINFO **userI, struct GROUPINFO **groupI)
{
	int		n;
	int		n2;
	int		t;
	int            *p_array;
	char           *r_list;
	char           *t_list;

	p_array = (int *)m_alloc(raceI->total.users * sizeof(int));
	bzero(p_array, raceI->total.users * sizeof(int));
	r_list = raceI->misc.racer_list;
	t_list = raceI->misc.total_racer_list;

	for (n = 0; n < raceI->total.users; n++) {
		t = p_array[n];
		for (n2 = n + 1; n2 < raceI->total.users; n2++) {
			if (userI[n]->bytes >= userI[n2]->bytes) {
				p_array[n2]++;
			} else {
				t++;
			}
		}
		userI[t]->pos = n;
#if ( get_competitor_list == TRUE )
		if ((userI[t]->pos) > 0) {
//		if (strcmp(raceI->user.name, userI[n]->name)) {
			r_list += sprintf(r_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
			t_list += sprintf(t_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
		} else {
			t_list += sprintf(t_list, "%s%s", racersplit, convert2(raceI, userI[n], groupI, racersmsg, t));
			raceI->user.pos = n;
		}
#else
		if (!strcmp(raceI->user.name, userI[n]->name))
			raceI->user.pos = n;
#endif
{'fraction_non_alphanumeric': 0.17689212974603974, 'fraction_numerical': 0.019738496354035705, 'mean_word_length': 3.439174107142857, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4515518', 'n_tokens_mistral': 3704, 'n_tokens_neox': 3300, 'n_words': 709}