<commit_before>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifndef HAVE_STRLCPY
# include "strl/strl.h"
#endif

#include "helpfunctions.h"
#include "zsfunctions.h"
#include "race-file.h"
#include "objects.h"
#include "macros.h"

#include "constants.h"

#include "errors.h"
#include "multimedia.h"
#include "convert.h"
#include "dizreader.h"
#include "stats.h"
#include "complete.h"
#include "crc.h"
#include "ng-version.h"
//#include "avi.h"
//#include "audio.h"
//#include "video.h"
//#include "avinfo.h"

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

#ifdef _SunOS_
#include "scandir.h"
#include "strsep.h"
#endif

/* Store various message strings here */
typedef struct _MSG {
	char *complete;
	char *update;
	char *race;
	char *sfv;
	char *newleader;
	char *halfway;
	char *error;
} MSG;

int handle_zip(GLOBAL *, MSG *, DIR *);
int handle_sfv(GLOBAL *, MSG *, DIR *);
int handle_nfo(GLOBAL *, MSG *, DIR *);
int handle_sfv32(GLOBAL *, MSG *, DIR *, char **, char *);
void read_envdata(GLOBAL *, GDATA *, UDATA *, struct stat *);
void check_filesize(GLOBAL *, const char *, struct stat *);
void lock_release(GLOBAL *, DIR *, DIR *);
void set_uid_gid(void);
void group_dir_users(GLOBAL *); /* call this something else */
int match_nocheck_dirs(GLOBAL *);

/* turn these two into one function */
int check_zerosize(GLOBAL *, MSG *);
int check_banned_file(GLOBAL *, MSG *);

int process_file(GLOBAL *, MSG *, DIR *, char **, char *, int *, int *);

int 
main(int argc, char **argv)
{
	GLOBAL		g; /* this motherfucker owns */
	MSG		msg;
	GDATA		gdata;
	UDATA		udata;

	DIR		*dir, *parent;
	
	char           *fileext = NULL, *name_p, *temp_p = NULL;
	char           *target = 0;
	char           *update_type = 0;
	char           *complete_bar = 0;
	int				exit_value = EXIT_SUCCESS;
	int				no_check = FALSE;
	char	       *race_type = 0;
	char	       *newleader_type = 0;
	char	       *race_halfway_type = 0;
	char	       *norace_halfway_type = 0;
	char	       *inc_point[2];
	char           *complete_announce = 0;
	int		cnt, n = 0;
	char	*nfofound = 0;
#if ( del_banned_release || enable_banned_script )
	int		deldir = 0;
#endif
	struct stat	fileinfo;

#if ( benchmark_mode == TRUE )
	struct timeval	bstart, bstop;
	d_log("zipscript-c: Reading time for benchmark\n");
	gettimeofday(&bstart, (struct timezone *)0);
#endif

#if ( debug_mode == TRUE && debug_announce == TRUE)
	printf("PZS-NG: Running in debug mode.\n");
#endif

	/*
	 * Adding version-number to head if .debug message 15.09.2004 - psxc
	 */
	d_log("zipscript-c: Project-ZS Next Generation (pzs-ng) v%s debug log.\n", ng_version());

#ifdef _ALT_MAX
	d_log("zipscript-c: PATH_MAX not found - using predefined settings! Please report to the devs!\n");
#endif

	umask(0666 & 000);

	set_uid_gid();

	if (argc != 4) {
		printf(" - - PZS-NG ZipScript-C v%s - -\n\nUsage: %s <filename> <path> <crc>\n\n", ng_version(), argv[0]);
		exit(1);
	}
	
	bzero(&g, sizeof(GLOBAL));
	//d_log("zipscript-c: Clearing arrays\n");
	//bzero(&g.v.total, sizeof(struct race_total));
	//g.v.misc.slowest_user[0] = 30000;
	//g.v.misc.fastest_user[0] = g.v.misc.release_type = RTYPE_NULL;

	/* gettimeofday(&g.v.transfer_stop, (struct timezone *)0 ); */

	g.v.misc.write_log = TRUE;
	g.v.misc.in_sfvfile = FALSE;

	strlcpy(g.v.file.name, argv[1], NAME_MAX);
	strlcpy(g.l.path, argv[2], PATH_MAX);
	strlcpy(g.v.misc.current_path, g.l.path, PATH_MAX);
	d_log("zipscript-c: Changing directory to %s\n", g.l.path);
	chdir(g.l.path);

	d_log("zipscript-c: Reading data from environment variables\n");
	read_envdata(&g, &gdata, &udata, &fileinfo);
	g.v.file.speed *= 1024;

	d_log("zipscript-c: Checking the file size of %s\n", g.v.file.name);
	check_filesize(&g, g.v.file.name, &fileinfo);

	d_log("zipscript-c: Setting race times\n");
	if (g.v.file.size != 0)
		g.v.total.start_time = g.v.total.stop_time - ((unsigned int)(g.v.file.size) / g.v.file.speed);
	else
		g.v.total.start_time = g.v.total.stop_time > (g.v.total.stop_time - 1) ? g.v.total.stop_time : (g.v.total.stop_time -1);<commit_msg>moved the check for arguments further up<commit_after>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifndef HAVE_STRLCPY
# include "strl/strl.h"
#endif

#include "helpfunctions.h"
#include "zsfunctions.h"
#include "race-file.h"
#include "objects.h"
#include "macros.h"

#include "constants.h"

#include "errors.h"
#include "multimedia.h"
#include "convert.h"
#include "dizreader.h"
#include "stats.h"
#include "complete.h"
#include "crc.h"
#include "ng-version.h"
//#include "avi.h"
//#include "audio.h"
//#include "video.h"
//#include "avinfo.h"

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

#ifdef _SunOS_
#include "scandir.h"
#include "strsep.h"
#endif

/* Store various message strings here */
typedef struct _MSG {
	char *complete;
	char *update;
	char *race;
	char *sfv;
	char *newleader;
	char *halfway;
	char *error;
} MSG;

int handle_zip(GLOBAL *, MSG *, DIR *);
int handle_sfv(GLOBAL *, MSG *, DIR *);
int handle_nfo(GLOBAL *, MSG *, DIR *);
int handle_sfv32(GLOBAL *, MSG *, DIR *, char **, char *);
void read_envdata(GLOBAL *, GDATA *, UDATA *, struct stat *);
void check_filesize(GLOBAL *, const char *, struct stat *);
void lock_release(GLOBAL *, DIR *, DIR *);
void set_uid_gid(void);
void group_dir_users(GLOBAL *); /* call this something else */
int match_nocheck_dirs(GLOBAL *);

/* turn these two into one function */
int check_zerosize(GLOBAL *, MSG *);
int check_banned_file(GLOBAL *, MSG *);

int process_file(GLOBAL *, MSG *, DIR *, char **, char *, int *, int *);

int 
main(int argc, char **argv)
{
	GLOBAL		g; /* this motherfucker owns */
	MSG		msg;
	GDATA		gdata;
	UDATA		udata;

	DIR		*dir, *parent;
	
	char           *fileext = NULL, *name_p, *temp_p = NULL;
	char           *target = 0;
	char           *update_type = 0;
	char           *complete_bar = 0;
	int				exit_value = EXIT_SUCCESS;
	int				no_check = FALSE;
	char	       *race_type = 0;
	char	       *newleader_type = 0;
	char	       *race_halfway_type = 0;
	char	       *norace_halfway_type = 0;
	char	       *inc_point[2];
	char           *complete_announce = 0;
	int		cnt, n = 0;
	char	*nfofound = 0;
#if ( del_banned_release || enable_banned_script )
	int		deldir = 0;
#endif
	struct stat	fileinfo;

#if ( benchmark_mode == TRUE )
	struct timeval	bstart, bstop;
	d_log("zipscript-c: Reading time for benchmark\n");
	gettimeofday(&bstart, (struct timezone *)0);
#endif

	if (argc != 4) {
		printf(" - - PZS-NG ZipScript-C v%s - -\n\nUsage: %s <filename> <path> <crc>\n\n", ng_version(), argv[0]);
		return EXIT_FAILURE;
	}

#if ( debug_mode == TRUE && debug_announce == TRUE)
	printf("PZS-NG: Running in debug mode.\n");
#endif

	/*
	 * Adding version-number to head if .debug message 15.09.2004 - psxc
	 */
	d_log("zipscript-c: Project-ZS Next Generation (pzs-ng) v%s debug log.\n", ng_version());

#ifdef _ALT_MAX
	d_log("zipscript-c: PATH_MAX not found - using predefined settings! Please report to the devs!\n");
#endif

	umask(0666 & 000);

	set_uid_gid();

	bzero(&g, sizeof(GLOBAL));
	//d_log("zipscript-c: Clearing arrays\n");
	//bzero(&g.v.total, sizeof(struct race_total));
	//g.v.misc.slowest_user[0] = 30000;
	//g.v.misc.fastest_user[0] = g.v.misc.release_type = RTYPE_NULL;

	/* gettimeofday(&g.v.transfer_stop, (struct timezone *)0 ); */

	g.v.misc.write_log = TRUE;
	g.v.misc.in_sfvfile = FALSE;

	strlcpy(g.v.file.name, argv[1], NAME_MAX);
	strlcpy(g.l.path, argv[2], PATH_MAX);
	strlcpy(g.v.misc.current_path, g.l.path, PATH_MAX);
	d_log("zipscript-c: Changing directory to %s\n", g.l.path);
	chdir(g.l.path);

	d_log("zipscript-c: Reading data from environment variables\n");
	read_envdata(&g, &gdata, &udata, &fileinfo);
	g.v.file.speed *= 1024;

	d_log("zipscript-c: Checking the file size of %s\n", g.v.file.name);
	check_filesize(&g, g.v.file.name, &fileinfo);

	d_log("zipscript-c: Setting race times\n");
	if (g.v.file.size != 0)
		g.v.total.start_time = g.v.total.stop_time - ((unsigned int)(g.v.file.size) / g.v.file.speed);
	else
		g.v.total.start_time = g.v.total.stop_time > (g.v.total.stop_time - 1) ? g.v.total.stop_time : (g.v.total.stop_time -1);
{'fraction_non_alphanumeric': 0.17091836734693877, 'fraction_numerical': 0.011479591836734694, 'mean_word_length': 3.78369384359401, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '896835', 'n_tokens_mistral': 3645, 'n_tokens_neox': 3486, 'n_words': 804}