This commit is contained in:
SavaletDev
2023-12-12 14:12:17 +01:00
commit 936fa139c0
35 changed files with 879 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
my_radar
.idea
.vscode

34
Makefile Normal file
View File

@@ -0,0 +1,34 @@
##
## EPITECH PROJECT, 2023
## Makefile
## File description:
## Makefile to build project
##
NAME = my_radar
SRCS = src/main.c
CC = gcc
CFLAGS = -Iinclude -Llib/my -lmy -l csfml-graphics -l csfml-system -l csfml-window
all: $(NAME)
$(NAME):
cd lib/my && make
$(CC) $(SRCS) -o $(NAME) $(CFLAGS)
clean:
$(RM) *.o
$(RM) $(OBJS)
fclean: clean
cd lib/my && make fclean
$(RM) $(NAME)
re: fclean all
asan: fclean
cd lib/my && make
$(CC) $(SRCS) -o $(NAME) -lasan -g3 $(CFLAGS)

16
include/radar.h Normal file
View File

@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2023
** B-MUL-100-REN-1-1-myradar-savinien.petitjean
** File description:
** radar.h
*/
#ifndef RADAR_H
#define RADAR_H
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdlib.h>
#include "../lib/my/lib.h"
#endif /* RADAR_H */

1
lib/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
libmy.a

2
lib/my/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
libmy.a
*.o

58
lib/my/Makefile Normal file
View File

@@ -0,0 +1,58 @@
##
## EPITECH PROJECT, 2023
## Makefile
## File description:
## Makefile to build project
##
NAME = libmy.a
SRCS = my_compute_power_rec.c \
my_compute_square_root.c \
my_put_float.c \
my_put_float_upper.c \
my_put_address.c \
my_isneg.c \
my_put_nbr.c \
my_put_unsigned_nbr.c \
my_put_hexa.c \
my_put_hexa_upper.c \
my_put_octal.c \
my_putchar.c \
my_putstr.c \
my_revstr.c \
my_show_word_array.c \
my_strcat.c \
my_strcmp.c \
my_strcpy.c \
my_strdup.c \
my_strlen.c \
my_strncat.c \
my_strncpy.c \
my_swap.c \
my_printf.c \
my_format.c \
my_error.c \
my_strpop.c
OBJS = $(SRCS:.c=.o)
CC = gcc
CFLAGS = -c -Iinclude -Wall -Wextra -Werror
all: $(NAME)
$(NAME): $(OBJS)
$(CC) $(CFLAGS) $(SRCS)
ar rc $(NAME) $(OBJS)
clean:
$(RM) *.o
$(RM) $(OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean all

60
lib/my/lib.h Normal file
View File

@@ -0,0 +1,60 @@
/*
** EPITECH PROJECT, 2023
** Lib/My
** File description:
** ./lib/my/lib.h
*/
#ifndef LIB_H_
#define LIB_H_
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
int my_printf(const char *, ...);
int my_format(const char *, int, va_list);
int my_format2(const char *, int, va_list);
int my_format3(const char *, int, va_list);
int my_putchar(char);
int my_isneg(int);
int my_put_nbr(int);
int my_put_unsigned_nbr(unsigned int);
int my_put_hexa(int);
int my_put_address(int);
int my_put_hexa_upper(int);
void my_error(char *);
int my_put_octal(int);
int my_swap(int *, int *);
int my_put_float(float);
int my_put_float_upper(float);
void my_put_float2(int *, int, int, int);
void my_put_float2_upper(int *, int, int, int);
int my_putstr(char const *);
int my_strlen(char const *);
int my_getnbr(char const *);
int my_sort_int_array(int *, int);
int my_compute_power_rec(int, int);
int my_compute_square_root(int);
int my_is_prime(int);
int my_find_prime_sup(int);
char *my_strcpy(char *, char const *);
char *my_strncpy(char *, char const *, int);
char *my_revstr(char *);
char my_strstr(char const *, char const *);
int my_strcmp(char const *, char const *);
int my_strncmp(char const *, char const *, int);
char *my_strupcase(char *);
char *my_strlowcase(char *);
char *my_strcapitalize(char *);
int my_str_isalpha(char const *);
int my_str_isnum(char const *);
int my_str_islower(char const *);
int my_str_isupper(char const *);
int my_str_isprintable(char const *);
int my_showstr(char const *);
int my_showmem(char const *, int);
int my_show_word_array(char *const *);
char *my_strcat(char *, char const *);
char *my_strncat(char *, char const *, int);
char *my_strdup(char const *);
char *my_strpop(char *, int);
#endif /* LIB_H_ */

View File

@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_compute_power_rec.c
*/
#include "lib.h"
int my_compute_power_rec(int nb, int p)
{
int result = 1;
if (p == 0)
return 1;
if (p < 0)
return 0;
result = my_compute_power_rec(nb, p - 1) * nb;
return (result);
}

View File

@@ -0,0 +1,19 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_compute_square_root.c
*/
#include "lib.h"
int my_compute_square_root(int nb)
{
if (nb <= 0)
return 0;
for (int i = 1; i <= nb / 2 + 1; i++) {
if (i * i == nb)
return (i);
}
return (0);
}

14
lib/my/my_error.c Normal file
View File

@@ -0,0 +1,14 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_isneg.c
*/
#include "lib.h"
void my_error(char *message)
{
my_printf("%s\n", message);
exit(84);
}

68
lib/my/my_format.c Normal file
View File

@@ -0,0 +1,68 @@
/*
** EPITECH PROJECT, 2023
** miniprintf
** File description:
** ./my_format.c
*/
#include <stdarg.h>
#include "lib.h"
int my_format(const char *format, int i, va_list list)
{
int count = 1;
switch (format[i + 1]) {
case '%':
my_putchar('%');
break;
case 'c':
my_putchar(va_arg(list, int));
break;
case 'i' :
case 'd' :
case 'n' :
count = my_put_nbr(va_arg(list, int));
break;
default:
return (my_format2(format, i, list));
}
return (count);
}
int my_format2(const char *format, int i, va_list list)
{
int count = 1;
switch (format[i + 1]) {
case 'u':
count = my_put_unsigned_nbr(va_arg(list, unsigned int));
break;
case 'o':
count = my_put_octal(va_arg(list, unsigned int));
break;
case 'f':
count = my_put_float(va_arg(list, double));
break;
case 's':
count = my_putstr(va_arg(list, char *));
break;
default:
return -42;
}
return (count);
}
int my_format3(const char *format, int i, va_list list)
{
int count = 1;
switch (format[i + 1]) {
case 'F':
count = my_put_float_upper(va_arg(list, double));
break;
default:
return -42;
}
return (count);
}

17
lib/my/my_isneg.c Normal file
View File

@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_isneg.c
*/
#include "lib.h"
int my_isneg(int n)
{
if (n < 0)
my_putchar('N');
else
my_putchar('P');
return (0);
}

30
lib/my/my_printf.c Normal file
View File

@@ -0,0 +1,30 @@
/*
** EPITECH PROJECT, 2023
** miniprintf
** File description:
** ./mini_printf.c
*/
#include <stdarg.h>
#include "lib.h"
int my_printf(const char *format, ...)
{
va_list list;
int count = 0;
if (format == 0)
return -42;
va_start(list, format);
for (int i = 0; i < my_strlen(format); i++) {
if (format[i] == '%') {
count += my_format(format, i, list);
i++;
} else {
my_putchar(format[i]);
count++;
}
}
va_end(list);
return count;
}

26
lib/my/my_put_address.c Normal file
View File

@@ -0,0 +1,26 @@
/*
** EPITECH PROJECT, 2023
** my_put_adress.c
** File description:
** my_put_adress.c
*/
#include "lib.h"
int my_put_address(int nb)
{
int i = 0;
if (nb < 0) {
my_putchar('-');
nb = nb * (-1);
}
if (nb >= 10) {
i = (nb % 10);
nb = (nb - i) / 10;
my_put_nbr(nb);
my_putchar(i + 48);
} else
my_putchar(nb + 48);
return (0);
}

47
lib/my/my_put_float.c Normal file
View File

@@ -0,0 +1,47 @@
/*
** EPITECH PROJECT, 2023
** my_put_float
** File description:
** my_put_float.c
*/
#include "lib.h"
int my_put_float(float nb)
{
int x = 0;
int entier = nb;
int precision = 6;
int decimal[precision];
int b = 10;
int tt;
for (int i = 0; i < precision; i++) {
tt = (int)(nb * b);
decimal[i] = tt % 10;
b = b * 10;
}
if (nb < 0) {
my_putchar('-');
nb = nb * -1;
entier = nb;
}
my_put_float2(decimal, x, precision, entier);
return (0);
}
void my_put_float2(
int *decimal,
int x,
int precision,
int entier
)
{
x += my_put_nbr(entier);
my_putchar('.');
x++;
for (int i = 0; i < precision; i++) {
if (decimal[i] != 0)
x += my_put_nbr(decimal[i]);
}
}

View File

@@ -0,0 +1,47 @@
/*
** EPITECH PROJECT, 2023
** my_put_float_upper
** File description:
** ./my_put_float_upper.c
*/
#include "lib.h"
int my_put_float_upper(float nb)
{
int x = 0;
int entier = nb;
int precision = 6;
int decimal[precision];
int b = 10;
int tt;
for (int i = 0; i < precision; i++) {
tt = (int)(nb * b);
decimal[i] = tt % 10;
b = b * 10;
}
if (nb < 0) {
my_putchar('-');
nb = nb * -1;
entier = nb;
}
my_put_float2_upper(decimal, x, precision, entier);
return (0);
}
void my_put_float2_upper(
int *decimal,
int x,
int precision,
int entier
)
{
x += my_put_nbr(entier);
my_putchar('.');
x++;
for (int i = 0; i < precision; i++) {
if (decimal[i] != 0)
x += my_put_nbr(decimal[i]);
}
}

24
lib/my/my_put_hexa.c Normal file
View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2023
** my_put_hexa
** File description:
** ./my_put_hexa.c
*/
#include "lib.h"
int my_put_hexa(int nb)
{
int result = nb;
while (nb != 0) {
result = nb % 16;
if (result < 10) {
my_putchar(result + 48);
} else {
my_putchar(result + 87);
}
nb = nb / 16;
}
return (0);
}

View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2023
** my_put_hexa_upper
** File description:
** ./my_put_hexa_upper.c
*/
#include "lib.h"
int my_put_hexa_upper(int nb)
{
int result = nb;
while (nb != 0) {
result = nb % 16;
if (result < 10) {
my_putchar(result + 48);
} else {
my_putchar(result + 5);
}
nb = nb / 16;
}
return (0);
}

35
lib/my/my_put_nbr.c Normal file
View File

@@ -0,0 +1,35 @@
/*
** EPITECH PROJECT, 2023
** SH_PUTNBR
** File description:
** Outputs a given int.
*/
#include "lib.h"
static void my_put_positive(int nb, int *count)
{
if (nb > 9)
my_put_positive(nb / 10, count);
my_putchar(nb % 10 + '0');
count++;
}
int my_put_nbr(int nb)
{
int output = nb;
int count = 0;
if (nb < 0) {
my_putchar('-');
count++;
output = -nb;
}
if (output < 0) {
output = -(output / 10);
my_put_positive(output, &count);
my_put_positive(-(nb % 10), &count);
} else
my_put_positive(output, &count);
return (count);
}

20
lib/my/my_put_octal.c Normal file
View File

@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2023
** my_put_octal
** File description:
** ./my_put_octal.c
*/
#include "lib.h"
int my_put_octal(int nb)
{
int result = nb;
while (nb != 0) {
result = nb % 8;
my_putchar(result + 48);
nb = nb / 8;
}
return (0);
}

View File

@@ -0,0 +1,28 @@
/*
** EPITECH PROJECT, 2023
** MyPrintf
** File description:
** Outputs a given int.
*/
#include "lib.h"
void my_put_positive(int nb)
{
if (nb > 9)
my_put_positive(nb / 10);
my_putchar(nb % 10 + '0');
}
int my_put_unsigned_nbr(unsigned int nb)
{
int output = nb;
if (output < 0) {
output = -(output / 10);
my_put_positive(output);
my_put_positive(-(nb % 10));
} else
my_put_positive(output);
return (0);
}

14
lib/my/my_putchar.c Normal file
View File

@@ -0,0 +1,14 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_putchar.c
*/
#include "lib.h"
int my_putchar(char a)
{
write(1, &a, 1);
return (0);
}

19
lib/my/my_putstr.c Normal file
View File

@@ -0,0 +1,19 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_putstr.c
*/
#include "lib.h"
int my_putstr(char const *str)
{
int count = 0;
for (int i = 0; str[i] != '\0'; i++) {
my_putchar(str[i]);
count++;
}
return (count);
}

22
lib/my/my_revstr.c Normal file
View File

@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_revstr.c
*/
#include "lib.h"
char *my_revstr(char *str)
{
int i;
char swap;
for (i = 0; str[i] != '\0'; i++);
for (int j = 0; j < i / 2; j++) {
swap = str[j];
str[j] = str[i - j - 1];
str[i - j - 1] = swap;
}
return str;
}

View File

@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay08
** File description:
** ./lin/my/my_show_word_array.c
*/
#include "lib.h"
int my_show_word_array(char *const *tab)
{
for (int i = 0; tab[i] != 0; i++) {
my_putstr(tab[i]);
my_putchar('\n');
}
return 0;
}

30
lib/my/my_strcat.c Normal file
View File

@@ -0,0 +1,30 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_strcat.c
*/
#include "lib.h"
#include <stdlib.h>
char *my_strcat(char *dest, char const *src)
{
int i;
int count;
char *res;
i = 0;
count = 0;
res = malloc(sizeof(*res) * (my_strlen(dest) + my_strlen(src) + 1));
while (dest[i]) {
res[i] = dest[i];
i++;
}
while (src[count]) {
res[i + count] = src[count];
count++;
}
res[i + count] = '\0';
return (res);
}

18
lib/my/my_strcmp.c Normal file
View File

@@ -0,0 +1,18 @@
/*
** EPITECH PROJECT, 2023
** B-PSU-100-REN-1-1-bsmyls-savinien.petitjean
** File description:
** ./my_strcmp.c
*/
#include "lib.h"
int my_strcmp(char const *s1, char const *s2)
{
int i = 0;
while (s1[i] == s2[i] && s1[i] != '\0') {
i++;
}
return s1[i] - s2[i];
}

20
lib/my/my_strcpy.c Normal file
View File

@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_strcpy.c
*/
#include "lib.h"
char *my_strcpy(char *dest, char const *src)
{
int i = 0;
while (src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return dest;
}

17
lib/my/my_strdup.c Normal file
View File

@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay08
** File description:
** ./my_strdup.c
*/
#include "lib.h"
char *my_strdup(char const *src)
{
char *dest;
int len = my_strlen(src);
dest = malloc(sizeof(char) * (len + 1));
return my_strcpy(dest, src);
}

16
lib/my/my_strlen.c Normal file
View File

@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_strlen.c
*/
#include "lib.h"
int my_strlen(char const *str)
{
int i;
for (i = 0; str[i] != '\0'; i++);
return (i);
}

21
lib/my/my_strncat.c Normal file
View File

@@ -0,0 +1,21 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_strncat.c
*/
#include "lib.h"
char *my_strncat(char *dest, char const *src, int nb)
{
int i = 0;
int len = my_strlen(dest);
while (src[i] != '\0' && i < nb) {
dest[i + len] = src[i];
i++;
}
dest[i + len] = '\0';
return dest;
}

21
lib/my/my_strncpy.c Normal file
View File

@@ -0,0 +1,21 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_strncpy.c
*/
#include "lib.h"
char *my_strncpy(char *dest, char const *src, int n)
{
int i = 0;
while (i < n && src[i] != '\0') {
dest[i] = src[i];
i++;
}
if (src[i] == '\0' && i < n)
dest[i] = '\0';
return dest;
}

21
lib/my/my_strpop.c Normal file
View File

@@ -0,0 +1,21 @@
/*
** EPITECH PROJECT, 2023
** B-PSU-100-REN-1-1-myls-savinien.petitjean
** File description:
** lib/mu/my_strpop.c
*/
#include <stdlib.h>
#include "lib.h"
char *my_strpop(char *str, int size)
{
int l = my_strlen(str);
char *strr = malloc(l - size);
for (int i = 0; i < l - size; i++) {
strr[i] = str[i];
}
strr[l - size] = '\0';
return strr;
}

18
lib/my/my_swap.c Normal file
View File

@@ -0,0 +1,18 @@
/*
** EPITECH PROJECT, 2023
** CPoolDay07
** File description:
** ./my_swap.c
*/
#include "lib.h"
int my_swap(int *a, int *b)
{
int swap;
swap = *a;
*a = *b;
*b = swap;
return (0);
}

32
src/main.c Normal file
View File

@@ -0,0 +1,32 @@
/*
** EPITECH PROJECT, 2023
** B-CPE-110-REN-1-1-organized-nathan.barbet
** File description:
** main.c
*/
#include "../include/radar.h"
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <stdlib.h>
int main()
{
sfVideoMode mode = {1920, 1080, 32};
sfRenderWindow* window;
sfEvent event;
window = sfRenderWindow_create(mode, "My Radar", sfResize | sfClose, NULL);
if (!window)
return EXIT_FAILURE;
while (sfRenderWindow_isOpen(window))
{
while (sfRenderWindow_pollEvent(window, &event))
{
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
sfRenderWindow_clear(window, sfBlack);
sfRenderWindow_display(window);
}
sfRenderWindow_destroy(window);
return EXIT_SUCCESS;
}