Skip to content

Commit

Permalink
updated Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mmusic committed Jul 13, 2022
1 parent cefa503 commit 1bb8ee7
Show file tree
Hide file tree
Showing 14 changed files with 1,188 additions and 1,196 deletions.
117 changes: 69 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,69 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jbrown <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/01/31 10:58:52 by jbrown #+# #+# #
# Updated: 2022/03/03 10:15:58 by jbrown ### ########.fr #
# #
# **************************************************************************** #

NAME = libftprintf.a
CC = gcc
CFLAGS = -Wall -Werror -Wextra -Iheaders -I . -c

RM = rm -f

SRCS = srcs/basic_print.c srcs/character_handle.c srcs/formatspec.c \
srcs/formatspec_extra.c srcs/ft_printf.c srcs/string_handle.c \
srcs/nbr_prec_width.c srcs/setnbr.c srcs/radix_print.c

OBJ_DEST = mv *.o srcs

OBJS = $(SRCS:.c=.o)

all: $(NAME)

$(NAME):
$(MAKE) bonus -C ./libft
cp libft/libft.a $(NAME)
$(CC) $(CFLAGS) $(SRCS)
$(OBJ_DEST)
ar rcs $(NAME) $(OBJS)

bonus: $(NAME)

clean:
$(MAKE) clean -C ./libft
$(RM) $(OBJS)

fclean: clean
$(MAKE) fclean -C ./libft
$(RM) $(NAME)

re: fclean all

.PHONY: all clean fclean re
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jbrown <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/01/31 10:58:52 by jbrown #+# #+# #
# Updated: 2022/03/03 10:15:58 by jbrown ### ########.fr #
# #
# **************************************************************************** #

NAME = libftprintf.a
LIBFT = libft.a
CC = gcc
CFLAGS = -Wall -Werror -Wextra -Iheaders -I . -c

RM = rm -f

SRCS = srcs/basic_print.c srcs/character_handle.c srcs/formatspec.c \
srcs/formatspec_extra.c srcs/ft_printf.c srcs/string_handle.c \
srcs/nbr_prec_width.c srcs/setnbr.c srcs/radix_print.c

OBJ_DEST = mv *.o srcs

OBJS = $(SRCS:.c=.o)

LIBFT_MSG = echo "libft archive compiling..."
LIBFT_CLEAN_MSG = echo "removing libft object files"
LIBFT_FCLEAN_MSG = echo "removing libft archive"
PRINTF_CLEAN_MSG = echo "removing printf object files"
PRINTF_FCLEAN_MSG = echo "removing printf archive"
PRINTF_MSG = echo "printf archive compiling..."
COMPLETE_MSG = echo "printf archive ready!"

all: $(NAME)

$(NAME): $(LIBFT)
@$(CC) $(CFLAGS) $(SRCS) >/dev/null
@$(PRINTF_MSG)
@$(OBJ_DEST) >/dev/null
@ar rcs $(NAME) $(OBJS) >/dev/null
@$(COMPLETE_MSG)

bonus: $(NAME)

$(LIBFT):
if [ ! -d "libft/" ]; then\
git clone https://github.com/t0mmusic/libft.git libft; \
fi
@$(LIBFT_MSG)
@$(MAKE) bonus -C ./libft >/dev/null
@cp libft/libft.a $(NAME) >/dev/null

clean:
@$(MAKE) clean -C ./libft >/dev/null
@$(LIBFT_CLEAN_MSG)
@$(RM) $(OBJS) >/dev/null
@$(PRINTF_CLEAN_MSG)

fclean: clean
@$(MAKE) fclean -C ./libft >/dev/null
@$(LIBFT_FCLEAN_MSG)
@$(RM) $(NAME) >/dev/null
@$(PRINTF_FCLEAN_MSG)

re: fclean all

.PHONY: all clean fclean re
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# ft_printf
recreation of the printf function in c

# Purpose
This project aims to recreate some of the functionality of the printf function in C. This must be achieved with minimal use of external functions.

%s - print string <br />
%c - print character <br />
%i - print integer<br />
%d - print decimal<br />
%u - print unsigned integer<br />
%x - print lowercase hexidecimal<br />
%X - print uppercase hexidecimal<br />
%p - print pointer in hexidecimal<br />
%% - print %<br />

# Bonus
In addition to printing, the function must work with flags and other format specifiers used by the original printf function. The output must be identical to the original function.

'0' flag - fills output string with zeroes<br />
'space' flag - fills output string with spaces<br />
'#' flag - preceeds hexidecimal with '0x'<br /> <br />
width specifier - dictates the total length of the output string<br />
precision specifier - limits the total length of the output string<br />

# Details

A document detailing some of the choices made [can be found here](https://docs.google.com/document/d/1d9tURqtoB20OnSp-jafY_21bqlDb-ZWNDP2nnaQb504/edit?usp=sharing).

# Status

Complete! Passes with 125%
# ft_printf
recreation of the printf function in c

# Purpose
This project aims to recreate some of the functionality of the printf function in C. This must be achieved with minimal use of external functions.

%s - print string <br />
%c - print character <br />
%i - print integer<br />
%d - print decimal<br />
%u - print unsigned integer<br />
%x - print lowercase hexidecimal<br />
%X - print uppercase hexidecimal<br />
%p - print pointer in hexidecimal<br />
%% - print %<br />

# Bonus
In addition to printing, the function must work with flags and other format specifiers used by the original printf function. The output must be identical to the original function.

'0' flag - fills output string with zeroes<br />
'space' flag - fills output string with spaces<br />
'#' flag - preceeds hexidecimal with '0x'<br /> <br />
width specifier - dictates the total length of the output string<br />
precision specifier - limits the total length of the output string<br />

# Details

A document detailing some of the choices made [can be found here](https://docs.google.com/document/d/1d9tURqtoB20OnSp-jafY_21bqlDb-ZWNDP2nnaQb504/edit?usp=sharing).

# Status

Complete! Passes with 125%
176 changes: 88 additions & 88 deletions headers/ft_printf.h
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbrown <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/31 12:20:57 by jbrown #+# #+# */
/* Updated: 2022/03/03 09:54:14 by jbrown ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef FT_PRINTF_H
# define FT_PRINTF_H

# include <stdarg.h>
# include "libft.h"

typedef struct s_specs
{
int zero;
int pound;
int plus;
int minus;
va_list arg;
char format;
int width;
int precision;
char space;
} t_specs;

/* Basic printf functions */

int ft_printf(const char *str, ...);
char *printtype(char c, va_list v);
void specinit(t_specs *s);
int putnewstr(t_specs *s, va_list v, int *count, int len);
int basic_print(char c, va_list v);

/* Number handling including hexidecimal */

char *ft_neghandle(long long int n);
char *ft_nbrtoa(size_t n, int radix);
int nbrcount(size_t n, int radix);
char *nbrwidth(t_specs *s, char *str);
void strupper(char *str);
char *hexwidth(t_specs *s, char *str);
char *hexprec(t_specs *s, char *str);
char *nbrprec(t_specs *s, char *str);
char *nbrmod(t_specs *s, char *str);

/* String Handling */

char *strhandle(va_list v);
char *strwidth(t_specs *s, char *str);
char *strprec(t_specs *s, char *str);
char *formatstr(t_specs *s, char *s2);
void strfill(char *str, char c, int len);

/* Character Handling */

char *chartostr(char c);
char *charwidth(char *str, t_specs *s);
void charprec(t_specs *s, char *str, int *count);
int charcheck(char *str, char c);
void charmod(char *str, char c);

/* Checking format specifiers and flags */

int formatspec(const char *c, t_specs *s, va_list v, int *count);
void flagfill(t_specs *s, char *str);
void setwidth(t_specs *s, char *str);
void setprecision(t_specs *s, char *str);
int ignoreprec(char *str, int i);
int validitycheck(char *s);
int flagcheck(char c);
int formatcheck(char c);
char *paramaterfill(char *s);
int formatnull(const char *c, t_specs *s, int len, int *count);

/* Memory allocation / freeing */

char *freejoin(char *s1, char *s2);

/* Extra fun functions */
char *radix_print(va_list v);

#endif
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbrown <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/31 12:20:57 by jbrown #+# #+# */
/* Updated: 2022/03/03 09:54:14 by jbrown ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef FT_PRINTF_H
# define FT_PRINTF_H

# include <stdarg.h>
# include "libft.h"

typedef struct s_specs
{
int zero;
int pound;
int plus;
int minus;
va_list arg;
char format;
int width;
int precision;
char space;
} t_specs;

/* Basic printf functions */

int ft_printf(const char *str, ...);
char *printtype(char c, va_list v);
void specinit(t_specs *s);
int putnewstr(t_specs *s, va_list v, int *count, int len);
int basic_print(char c, va_list v);

/* Number handling including hexidecimal */

char *ft_neghandle(long long int n);
char *ft_nbrtoa(size_t n, int radix);
int nbrcount(size_t n, int radix);
char *nbrwidth(t_specs *s, char *str);
void strupper(char *str);
char *hexwidth(t_specs *s, char *str);
char *hexprec(t_specs *s, char *str);
char *nbrprec(t_specs *s, char *str);
char *nbrmod(t_specs *s, char *str);

/* String Handling */

char *strhandle(va_list v);
char *strwidth(t_specs *s, char *str);
char *strprec(t_specs *s, char *str);
char *formatstr(t_specs *s, char *s2);
void strfill(char *str, char c, int len);

/* Character Handling */

char *chartostr(char c);
char *charwidth(char *str, t_specs *s);
void charprec(t_specs *s, char *str, int *count);
int charcheck(char *str, char c);
void charmod(char *str, char c);

/* Checking format specifiers and flags */

int formatspec(const char *c, t_specs *s, va_list v, int *count);
void flagfill(t_specs *s, char *str);
void setwidth(t_specs *s, char *str);
void setprecision(t_specs *s, char *str);
int ignoreprec(char *str, int i);
int validitycheck(char *s);
int flagcheck(char c);
int formatcheck(char c);
char *paramaterfill(char *s);
int formatnull(const char *c, t_specs *s, int len, int *count);

/* Memory allocation / freeing */

char *freejoin(char *s1, char *s2);

/* Extra fun functions */
char *radix_print(va_list v);

#endif
Loading

0 comments on commit 1bb8ee7

Please sign in to comment.