time and color

This commit is contained in:
Jack Halford 2016-11-25 18:29:21 +01:00
parent cf8d5f81aa
commit ed26039dd2
11 changed files with 176 additions and 7 deletions

38
libft/includes/color.h Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */
/* Updated: 2016/11/25 18:27:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COLOR_H
# define COLOR_H
# include "libft.h"
# define FG_BLACK "\x1b[30m"
# define FG_RED "\x1b[31m"
# define FG_GREEN "\x1b[32m"
# define FG_YELLOW "\x1b[33m"
# define FG_BLUE "\x1b[34m"
# define FG_MAGENTA "\x1b[35m"
# define FG_CYAN "\x1b[36m"
# define FG_DEFAULT "\x1b[0m"
# define BG_BLACK "\x1b[40m"
# define BG_RED "\x1b[41m"
# define BG_GREEN "\x1b[42m"
# define BG_YELLOW "\x1b[43m"
# define BG_BLUE "\x1b[44m"
# define BG_MAGENTA "\x1b[45m"
# define BG_CYAN "\x1b[46m"
# define BG_DEFAULT "\x1b[49m"
void ft_color_reset(void);
void ft_color_set(char *fg, char *bg);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2016/11/23 13:56:46 by jhalford ### ########.fr */
/* Updated: 2016/11/25 16:02:22 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,15 +14,19 @@
# define LIBFT_H
# include "ft_xattr.h"
# include "mytime.h"
# include "lst.h"
# include "dlst.h"
# include "btree.h"
# include "color.h"
# include <string.h>
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# include <sys/xattr.h>
# include <sys/acl.h>
# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n')
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
@ -125,8 +129,6 @@ char **ft_sstrdup(char **list);
void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr);
int ft_time_isrecent(time_t event);
char *ft_path_notdir(char *path);
int ft_printf(const char *format, ...);

34
libft/includes/mytime.h Normal file
View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mytime.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 11:43:12 by jhalford #+# #+# */
/* Updated: 2016/11/25 18:28:27 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MYTIME_H
# define MYTIME_H
# include "libft.h"
struct s_mytime
{
char *year;
char *month;
char *day;
char *hour;
char *min;
char *sec;
};
typedef struct s_mytime t_mytime;
int ft_time_isrecent(time_t event);
t_mytime *ft_mytime_get(time_t epoch);
void ft_mytime_free(t_mytime **time);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
/* Updated: 2016/11/21 15:13:44 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:28:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_color_reset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 13:48:05 by jhalford #+# #+# */
/* Updated: 2016/11/25 14:06:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_color_reset(void)
{
ft_putstr(FG_DEFAULT);
ft_putstr(BG_DEFAULT);
}

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_color_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 13:53:46 by jhalford #+# #+# */
/* Updated: 2016/11/25 14:05:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_color_set(char *fg, char *bg)
{
ft_putstr(fg);
ft_putstr(bg);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
/* Updated: 2016/11/16 17:52:01 by jhalford ### ########.fr */
/* Updated: 2016/11/25 11:31:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_mytime_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 11:45:29 by jhalford #+# #+# */
/* Updated: 2016/11/25 11:48:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_mytime_free(t_mytime **time)
{
ft_strdel(&(*time)->year);
ft_strdel(&(*time)->month);
ft_strdel(&(*time)->day);
ft_strdel(&(*time)->hour);
ft_strdel(&(*time)->min);
ft_strdel(&(*time)->sec);
ft_memdel((void **)time);
}

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_getstrtime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */
/* Updated: 2016/11/25 11:55:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_mytime *ft_mytime_get(time_t epoch)
{
char *date;
t_mytime *time;
time = (t_mytime*)malloc(sizeof(*time));
date = ctime(&epoch);
date[ft_strlen(date) - 1] = 0;
time->year = ft_isdigit(date[20]) ?
ft_strsub(date, 20, 4) : ft_strsub(date, 24, 5);
time->month = ft_strsub(date, 4, 3);
time->day = ft_strsub(date, 8, 2);
time->hour = ft_strsub(date, 11, 2);
time->min = ft_strsub(date, 14, 2);
time->sec = ft_strsub(date, 17, 2);
return (time);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */
/* Updated: 2016/11/08 16:12:50 by jhalford ### ########.fr */
/* Updated: 2016/11/25 11:43:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:00:52 by jhalford #+# #+# */
/* Updated: 2016/11/03 18:00:56 by jhalford ### ########.fr */
/* Updated: 2016/11/25 17:22:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */