<commit_before>#include <command.h>
#include <string.h>
#include <shell.h>
#include <stdio.h>
#include <libc.h>


void help(char *argv[], int argc) 
{
	int cmd_index;
	cmd_entry* table = get_command_table();
	if (argc == 1) {
		cmd_index = get_cmd_index(argv[0]);
		if (cmd_index != -1) {
			printf("\n%s\n", table[cmd_index].help);
		} else {
			help_error_print(table);
		}
	} else if (argc == 0) {
		help_error_print(table);
	}
}


void echo(char** args, int argc)
{
	int i;
	char fmt[]="%s ";
	for(i=0; i <=argc ; i++)
	{
		printf(fmt, args[i]);
	}
	putc('\n');

}

void clear(char** args, int argc)
{
	int i = 0;
	for(i=0; i<25;i++){
		printf("\n");
	}
}


void date(char** args, int argc)
{
	//TODO int date params;
	//TODO get_date(); //implementation pending
	printf("Implement date");
}

void time(char** args, int argc)
{
	//TODO int time params;
	//TODO gettime(); //implementation pending
	struct rtc_time time_struct;
	gettime(&time_struct);
	printf("%d/%d/%d %d:%d:%d\n",
		time_struct.day,
		time_struct.mon,
		time_struct.year,
		time_struct.hour,
		time_struct.min,
		time_struct.sec
	);
}

void set_date(char** args, int argc)
{
	int days, months, years;
	if(argc <1){
		char err[] ="Invalid date inserted, please respect dd/mm/yyyy format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}
	if(!parse_date(args[0], &days, &months, &years)){
		char err[] ="Invalid date inserted, please respect dd/mm/yyyy format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;

	}
	//TODO   set system date
}

void set_time(char** args, int argc)
{
	int seconds, minutes, hours;
	if(argc < 1)
	{
		char err[] ="No arguments were sent to command settime format musut be ss:mm:hh \n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}	
	if(!parse_time(args[0], &seconds, &minutes, &hours))
	{
		char err[] ="Invalid date inserted, please respect ss:mm:hh format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}
	//TODO SET SYSTEM TIME

}

//Receives input string, parses it for a date, returns 1 if valid, 0 if not
int parse_date(char* date_string, int* days, int*months, int*years)
{
	int len =0;
	len = strlen(date_string);
	if(len !=10)
	{
		return 0;<commit_msg>get and set<commit_after>#include <command.h>
#include <string.h>
#include <shell.h>
#include <stdio.h>
#include <libc.h>


void help(char *argv[], int argc) 
{
	int cmd_index;
	cmd_entry* table = get_command_table();
	if (argc == 1) {
		cmd_index = get_cmd_index(argv[0]);
		if (cmd_index != -1) {
			printf("\n%s\n", table[cmd_index].help);
		} else {
			help_error_print(table);
		}
	} else if (argc == 0) {
		help_error_print(table);
	}
}


void echo(char** args, int argc)
{
	int i;
	char fmt[]="%s ";
	for(i=0; i <=argc ; i++)
	{
		printf(fmt, args[i]);
	}
	putc('\n');

}

void clear(char** args, int argc)
{
	int i = 0;
	for(i=0; i<25;i++){
		printf("\n");
	}
}


void date(char** args, int argc)
{
	struct rtc_time time_struct;
	gettime(&time_struct);
	printf("%d/%d/%d\n",
		time_struct.day,
		time_struct.mon,
		time_struct.year
	);

}

void time(char** args, int argc)
{
	struct rtc_time time_struct;
	gettime(&time_struct);
	printf("%d:%d:%d\n",
		time_struct.hour,
		time_struct.min,
		time_struct.sec
	);
}

void set_date(char** args, int argc)
{
	struct rtc_time time_struct;
	int days, months, years;

	gettime(&time_struct);
	if(argc <1){
		char err[] ="Invalid date inserted, please respect dd/mm/yyyy format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}
	if(!parse_date(args[0], &days, &months, &years)){
		char err[] ="Invalid date inserted, please respect dd/mm/yyyy format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;

	}
	time_struct.year = years;
	time_struct.mon = months;
	time_struct.day = days;

	settime(&time_struct);
}

void set_time(char** args, int argc)
{
	struct rtc_time time_struct;
	int seconds, minutes, hours;

	gettime(&time_struct);
	if(argc < 1)
	{
		char err[] ="No arguments were sent to command settime format musut be ss:mm:hh \n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}	
	if(!parse_time(args[0], &seconds, &minutes, &hours))
	{
		char err[] ="Invalid date inserted, please respect ss:mm:hh format & insert a valid date.\n";
		char fmt[]= "%s";
		printf(fmt, err);
		return;
	}


	time_struct.sec = seconds;
	time_struct.min = minutes;
	time_struct.hour = hours;

	settime(&time_struct);

}

//Receives input string, parses it for a date, returns 1 if valid, 0 if not
int parse_date(char* date_string, int* days, int*months, int*years)
{
	int len =0;
	len = strlen(date_string);
	if(len !=10)
	{
		return 0;
{'fraction_non_alphanumeric': 0.1747283187726401, 'fraction_numerical': 0.008097165991902834, 'mean_word_length': 3.9151832460732985, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, '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': '1968879', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1874, 'n_words': 501}