<commit_before>/*
  TODO:
       - Handle exceptional conditions throughout the code
       - Improve options processing (using getopt?)
 */

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "include/list.h"
#include "include/uar.h"


/* Main operations */
static int extract(char *ar_name, char *file_name);
static void print_table(char *arch_name, char *fname);
static int replace_or_add(char *ar_name, char *file_name);
static int delete_file(char *ar_name, char *file_name);

/* Helper functions*/
static void print_usage (void);
static char get_op (int, char**);
static void check_archive (char*);
static int parse_archive(char*);
static uint32_t get_acc_size (uint32_t);
static void dispatch(int, char*[]);

enum {
	OP_DEL = 0x01,
	OP_ADD = 0x02,
	OP_EXT = 0x04,
	OP_TAB = 0x08,
	OP_CHK = 0x10
};

static int flag = 0;

int
main(int argc, char **argv)
{
	int ch = 0;

	setprogname(argv[0]);

	while((ch = getopt(argc, argv, "drxtc")) != -1) {
		switch (ch) {
			case 'd':
				flag |= OP_DEL;
				break;
			case 'r':
				flag |= OP_ADD;
				break;
			case 'x':
				flag |= OP_EXT;
				break;
			case 't':
				flag |= OP_TAB;
				break;
			case 'c':
				flag |= OP_CHK;
				break;
			case '?':
				print_usage();
		}
	}

	argc -= optind;
	argv += optind;

	dispatch(argc, argv);

	return 0;
}

static void
dispatch(int argc, char *argv[]) {
	if (flag & OP_DEL) {
		if (argc < 2)
			print_usage();
		return;
	}
	if (flag & OP_ADD) {
		if (argc < 2)
			print_usage();
	}
	if (flag & OP_EXT) {
		if (argc < 1)
			print_usage();
		if (argc > 1)
			for (int i = 1; i < argc; i++)
				extract(argv[0], argv[i]);
			else
				extract(argv[0], NULL);
		return;
	}
	if (flag & OP_TAB) {
		if (argc < 1)
			print_usage();
		if (argc > 1)
			for (int i = 1; i < argc; i++)
				print_table(argv[0], argv[i]);
		else
			print_table(argv[0], NULL);<commit_msg>uar: -d and -r working again :)<commit_after>/*
  TODO:
       - Handle exceptional conditions throughout the code
       - Improve options processing (using getopt?)
 */

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "include/list.h"
#include "include/uar.h"


/* Main operations */
static int extract(char *ar_name, char *file_name);
static void print_table(char *arch_name, char *fname);
static int replace_or_add(char *ar_name, char *file_name);
static int delete_file(char *ar_name, char *file_name);

/* Helper functions*/
static void print_usage (void);
static char get_op (int, char**);
static void check_archive (char*);
static int parse_archive(char*);
static uint32_t get_acc_size (uint32_t);
static void dispatch(int, char*[]);

enum {
	OP_DEL = 0x01,
	OP_ADD = 0x02,
	OP_EXT = 0x04,
	OP_TAB = 0x08,
	OP_CHK = 0x10
};

static int flag = 0;

int
main(int argc, char **argv)
{
	int ch = 0;

	setprogname(argv[0]);

	while((ch = getopt(argc, argv, "drxtc")) != -1) {
		switch (ch) {
			case 'd':
				flag |= OP_DEL;
				break;
			case 'r':
				flag |= OP_ADD;
				break;
			case 'x':
				flag |= OP_EXT;
				break;
			case 't':
				flag |= OP_TAB;
				break;
			case 'c':
				flag |= OP_CHK;
				break;
			case '?':
				print_usage();
		}
	}

	argc -= optind;
	argv += optind;

	dispatch(argc, argv);

	return 0;
}

static void
dispatch(int argc, char *argv[]) {
	if (flag & OP_DEL) {
		if (argc < 2)
			print_usage();
		for (int i = 1; i < argc; i++)
			delete_file(argv[0], argv[i]);
		return;
	}
	if (flag & OP_ADD) {
		if (argc < 2)
			print_usage();
		for (int i = 1; i < argc; i++)
			replace_or_add(argv[0], argv[i]);
		return;
	}
	if (flag & OP_EXT) {
		if (argc < 1)
			print_usage();
		if (argc > 1)
			for (int i = 1; i < argc; i++)
				extract(argv[0], argv[i]);
			else
				extract(argv[0], NULL);
		return;
	}
	if (flag & OP_TAB) {
		if (argc < 1)
			print_usage();
		if (argc > 1)
			for (int i = 1; i < argc; i++)
				print_table(argv[0], argv[i]);
		else
			print_table(argv[0], NULL);
{'fraction_non_alphanumeric': 0.16685872320811246, 'fraction_numerical': 0.01751555657985711, 'mean_word_length': 3.3055555555555554, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 35, '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': '7500055', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1763, 'n_words': 482}