First push
@@ -0,0 +1,271 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(My3D C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
include_directories(include)
|
||||
include_directories(lib/gamacon/include)
|
||||
include_directories(lib/gamacon/include/components)
|
||||
include_directories(lib/gamacon/include/components/controllers)
|
||||
include_directories(lib/gamacon/include/systems)
|
||||
include_directories(lib/gamacon/include/systems/controllers)
|
||||
include_directories(lib/my/include)
|
||||
include_directories(lib/xmlparser/include)
|
||||
|
||||
add_executable(My3D
|
||||
include/my.h
|
||||
include/setup.h
|
||||
lib/gamacon/include/components/controllers/keyboard_controller.h
|
||||
lib/gamacon/include/components/camerafollow_component.h
|
||||
lib/gamacon/include/components/collision_component.h
|
||||
lib/gamacon/include/components/controllable_component.h
|
||||
lib/gamacon/include/components/fixed_to_cam_component.h
|
||||
lib/gamacon/include/components/friction_component.h
|
||||
lib/gamacon/include/components/friction_giver.h
|
||||
lib/gamacon/include/components/movable_component.h
|
||||
lib/gamacon/include/components/parallax_component.h
|
||||
lib/gamacon/include/components/renderer.h
|
||||
lib/gamacon/include/components/transform_component.h
|
||||
lib/gamacon/include/components/vertex_component.h
|
||||
lib/gamacon/include/systems/controllers/keyboard_controller_system.h
|
||||
lib/gamacon/include/systems/camerafollow_system.h
|
||||
lib/gamacon/include/systems/collision_system.h
|
||||
lib/gamacon/include/systems/friction_system.h
|
||||
lib/gamacon/include/systems/movable_system.h
|
||||
lib/gamacon/include/systems/parallax_system.h
|
||||
lib/gamacon/include/systems/sfml_renderer_system.h
|
||||
lib/gamacon/include/component.h
|
||||
lib/gamacon/include/data.h
|
||||
lib/gamacon/include/engine.h
|
||||
lib/gamacon/include/entity.h
|
||||
lib/gamacon/include/entity_factory.h
|
||||
lib/gamacon/include/list.h
|
||||
lib/gamacon/include/my.h
|
||||
lib/gamacon/include/prefab.h
|
||||
lib/gamacon/include/quadtree.h
|
||||
lib/gamacon/include/read_line.h
|
||||
lib/gamacon/include/scene.h
|
||||
lib/gamacon/include/sfml_renderer.h
|
||||
lib/gamacon/include/sprite.h
|
||||
lib/gamacon/include/system.h
|
||||
lib/gamacon/include/tags.h
|
||||
lib/gamacon/include/text.h
|
||||
lib/gamacon/include/tupple.h
|
||||
lib/gamacon/include/utility.h
|
||||
lib/gamacon/include/vector2.h
|
||||
lib/gamacon/include/xml.h
|
||||
lib/gamacon/src/components/controllers/keyboard_controller.c
|
||||
lib/gamacon/src/components/renderers/anim_renderer.c
|
||||
lib/gamacon/src/components/renderers/map_renderer.c
|
||||
lib/gamacon/src/components/renderers/sprite_renderer.c
|
||||
lib/gamacon/src/components/renderers/text_renderer.c
|
||||
lib/gamacon/src/components/camera_follow.c
|
||||
lib/gamacon/src/components/collision_component.c
|
||||
lib/gamacon/src/components/controllable_component.c
|
||||
lib/gamacon/src/components/fixed_to_cam.c
|
||||
lib/gamacon/src/components/friction_component.c
|
||||
lib/gamacon/src/components/friction_giver.c
|
||||
lib/gamacon/src/components/movable_component.c
|
||||
lib/gamacon/src/components/parallax_component.c
|
||||
lib/gamacon/src/components/renderer.c
|
||||
lib/gamacon/src/components/transform_component.c
|
||||
lib/gamacon/src/components/vertex_component.c
|
||||
lib/gamacon/src/deserializer/deserialize_entity.c
|
||||
lib/gamacon/src/deserializer/prefab.c
|
||||
lib/gamacon/src/engine/discard_player.c
|
||||
lib/gamacon/src/engine/engine.c
|
||||
lib/gamacon/src/engine/engine_component_builder.c
|
||||
lib/gamacon/src/engine/engine_dataloader.c
|
||||
lib/gamacon/src/engine/engine_internal.c
|
||||
lib/gamacon/src/engine/engine_system_builder.c
|
||||
lib/gamacon/src/entity/entity.c
|
||||
lib/gamacon/src/entity/entity_factory.c
|
||||
lib/gamacon/src/scene/scene.c
|
||||
lib/gamacon/src/scene/scene_destroy.c
|
||||
lib/gamacon/src/scene/scene_loader.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_dataloaders.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_drawer.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_functions.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_music_player.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_vertex.c
|
||||
lib/gamacon/src/sfml_renderer/texture_utility.c
|
||||
lib/gamacon/src/systems/controllers/keyboard_controller_system.c
|
||||
lib/gamacon/src/systems/camera_follow_system.c
|
||||
lib/gamacon/src/systems/collision_system.c
|
||||
lib/gamacon/src/systems/fixed_to_cam_pseudosystem.c
|
||||
lib/gamacon/src/systems/friction_system.c
|
||||
lib/gamacon/src/systems/movable_system.c
|
||||
lib/gamacon/src/systems/parallax_system.c
|
||||
lib/gamacon/src/systems/sfml_renderer_system.c
|
||||
lib/gamacon/src/utility/arraylen.c
|
||||
lib/gamacon/src/utility/list.c
|
||||
lib/gamacon/src/utility/my_realloc.c
|
||||
lib/gamacon/src/utility/tupple.c
|
||||
lib/gamacon/src/utility/vector2.c
|
||||
lib/gamacon/src/component.c
|
||||
lib/gamacon/src/system.c
|
||||
lib/my/include/formaters.h
|
||||
lib/my/include/my.h
|
||||
lib/my/my/alphanum_helper.c
|
||||
lib/my/my/index_of.c
|
||||
lib/my/my/my_compute_factorial_it.c
|
||||
lib/my/my/my_compute_factorial_rec.c
|
||||
lib/my/my/my_compute_power_it.c
|
||||
lib/my/my/my_compute_square_root.c
|
||||
lib/my/my/my_evil_str.c
|
||||
lib/my/my/my_find_prime_sup.c
|
||||
lib/my/my/my_getnbr.c
|
||||
lib/my/my/my_getnbr_base.c
|
||||
lib/my/my/my_getnbr_base.c
|
||||
lib/my/my/my_is_prime.c
|
||||
lib/my/my/my_isneg.c
|
||||
lib/my/my/my_print_alpha.c
|
||||
lib/my/my/my_print_comb.c
|
||||
lib/my/my/my_print_comb2.c
|
||||
lib/my/my/my_print_combn.c
|
||||
lib/my/my/my_print_digits.c
|
||||
lib/my/my/my_print_revalpha.c
|
||||
lib/my/my/my_put_nbr.c
|
||||
lib/my/my/my_putchar.c
|
||||
lib/my/my/my_putlong_base.c
|
||||
lib/my/my/my_putnbr_base.c
|
||||
lib/my/my/my_putstr.c
|
||||
lib/my/my/my_revstr.c
|
||||
lib/my/my/my_show_words_array.c
|
||||
lib/my/my/my_showmem.c
|
||||
lib/my/my/my_showstr.c
|
||||
lib/my/my/my_sort_int_array.c
|
||||
lib/my/my/my_str_isalpha.c
|
||||
lib/my/my/my_str_islower.c
|
||||
lib/my/my/my_str_isnum.c
|
||||
lib/my/my/my_str_isprintable.c
|
||||
lib/my/my/my_str_isupper.c
|
||||
lib/my/my/my_str_to_word_array.c
|
||||
lib/my/my/my_strcapitalize.c
|
||||
lib/my/my/my_strcat.c
|
||||
lib/my/my/my_strchr.c
|
||||
lib/my/my/my_strcmp.c
|
||||
lib/my/my/my_strcpy.c
|
||||
lib/my/my/my_strdup.c
|
||||
lib/my/my/my_strlen.c
|
||||
lib/my/my/my_strlowcase.c
|
||||
lib/my/my/my_strncat.c
|
||||
lib/my/my/my_strncmp.c
|
||||
lib/my/my/my_strncpy.c
|
||||
lib/my/my/my_strstr.c
|
||||
lib/my/my/my_strupcase.c
|
||||
lib/my/my/my_swap.c
|
||||
lib/my/my/tostr.c
|
||||
lib/my/my/utility.c
|
||||
lib/my/src/formaters/big_hexa_formater.c
|
||||
lib/my/src/formaters/char_formater.c
|
||||
lib/my/src/formaters/float_formater.c
|
||||
lib/my/src/formaters/hexa_formater.c
|
||||
lib/my/src/formaters/int_formater.c
|
||||
lib/my/src/formaters/no_format.c
|
||||
lib/my/src/formaters/octal_formater.c
|
||||
lib/my/src/formaters/ptr_formater.c
|
||||
lib/my/src/formaters/string_formater.c
|
||||
lib/my/src/formaters/string_nonprintable_formater.c
|
||||
lib/my/src/formaters/ubinary_formater.c
|
||||
lib/my/src/formaters/uint_formater.c
|
||||
lib/my/src/get_nbr_size.c
|
||||
lib/my/src/my_putlonglong_base.c
|
||||
lib/my/src/printf.c
|
||||
lib/my/src/printf_utility.c
|
||||
lib/quadtree/include/array.h
|
||||
lib/quadtree/include/quadtree_internal.h
|
||||
lib/quadtree/src/utility/calloc.c
|
||||
lib/quadtree/src/array.c
|
||||
lib/quadtree/src/qt_collide.c
|
||||
lib/quadtree/src/qt_destroy.c
|
||||
lib/quadtree/src/qt_layer.c
|
||||
lib/quadtree/src/qt_position_overlap.c
|
||||
lib/quadtree/src/qt_split.c
|
||||
lib/quadtree/src/quadtree.c
|
||||
lib/xmlparser/include/my.h
|
||||
lib/xmlparser/include/xml.h
|
||||
lib/xmlparser/include/xml_internal.h
|
||||
lib/xmlparser/src/child.c
|
||||
lib/xmlparser/src/floatutils.c
|
||||
lib/xmlparser/src/helper.c
|
||||
lib/xmlparser/src/list_utility.c
|
||||
lib/xmlparser/src/parsenode.c
|
||||
lib/xmlparser/src/rawnode.c
|
||||
lib/xmlparser/src/strangeget.c
|
||||
lib/xmlparser/src/xml_destroy.c
|
||||
lib/xmlparser/src/xmlget.c
|
||||
lib/xmlparser/src/xmlparser.c
|
||||
lib/xmlparser/src/xmlproperties.c
|
||||
src/game_loader.c
|
||||
src/main.c
|
||||
lib/gamacon/include/errors.h
|
||||
lib/gamacon/src/ui/button.c
|
||||
lib/gamacon/src/ui/setup_ui.c
|
||||
lib/gamacon/include/ui.h
|
||||
src/main_menu.c
|
||||
lib/gamacon/src/components/clickable_component.c
|
||||
lib/gamacon/include/components/clickable_component.h
|
||||
lib/gamacon/src/systems/clickable_system.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_events.c
|
||||
lib/my/my/my_str_replace.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_init.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_events.c
|
||||
lib/gamacon/src/isometry/map_utils.c
|
||||
lib/gamacon/include/map_utils.h
|
||||
lib/xmlparser/src/otherget.c
|
||||
src/options.c
|
||||
lib/gamacon/src/components/input_component.c
|
||||
lib/gamacon/include/components/input_component.h
|
||||
lib/xmlparser/src/otherget.c
|
||||
src/options.c
|
||||
lib/gamacon/src/components/input_component.c
|
||||
lib/gamacon/include/components/input_component.h
|
||||
src/systems/teams_system.c
|
||||
include/systems/teams_system.h
|
||||
include/components/teams_component.h
|
||||
src/components/teams_component.c
|
||||
lib/gamacon/src/components/tag_component.c
|
||||
lib/gamacon/include/components/tag_component.h
|
||||
src/components/game_manager.c
|
||||
include/components/game_manager.h
|
||||
include/dpr_errors.h
|
||||
include/components/game_display.h
|
||||
src/components/game_display.c
|
||||
src/systems/game_display_system.c
|
||||
src/isometry/tile_collision_manager.c
|
||||
lib/gamacon/include/tile_collision_manager.h
|
||||
lib/gamacon/src/engine/event_manager.c
|
||||
lib/gamacon/include/event_manager.h
|
||||
src/teams/absent.c
|
||||
src/teams/forgot.c include/teams.h
|
||||
src/systems/game_manager_system.c
|
||||
include/systems/game_manager_system.h
|
||||
lib/gamacon/include/keybindings.h
|
||||
src/isometry/map_interactions.c
|
||||
include/map_interactions.h
|
||||
lib/gamacon/include/keybindings.h
|
||||
lib/gamacon/src/ui/tooltip.c
|
||||
lib/gamacon/src/components/tooltip_component.c
|
||||
lib/gamacon/include/components/tooltip_component.h
|
||||
lib/gamacon/src/systems/tooltip_system.c
|
||||
src/components/map_manager_component.c
|
||||
include/components/isometry/map_manager_component.h
|
||||
lib/gamacon/src/isometry/vertex_data_loader.c
|
||||
lib/gamacon/include/vertex_data_loader.h
|
||||
src/toolbar.c
|
||||
lib/gamacon/include/callbacks.h src/selectors.c
|
||||
src/framerate.c
|
||||
lib/gamacon/src/isometry/isometry.c
|
||||
lib/gamacon/include/isometry.h
|
||||
)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
target_link_libraries(My3D
|
||||
csfml-system
|
||||
csfml-graphics
|
||||
csfml-audio
|
||||
csfml-window
|
||||
m
|
||||
)
|
||||
@@ -0,0 +1,75 @@
|
||||
##
|
||||
## EPITECH PROJECT, 2019
|
||||
## MUL_my_runner_2019
|
||||
## File description:
|
||||
## Makefile
|
||||
##
|
||||
|
||||
SRC = src/main.c \
|
||||
src/game_loader.c \
|
||||
src/framerate.c \
|
||||
src/main_menu.c \
|
||||
src/options.c \
|
||||
src/selectors.c \
|
||||
src/toolbar.c \
|
||||
src/teams/absent.c \
|
||||
src/teams/forgot.c \
|
||||
src/systems/game_display_system.c \
|
||||
src/systems/game_manager_system.c \
|
||||
src/systems/teams_system.c \
|
||||
src/isometry/map_interactions.c \
|
||||
src/isometry/tile_collision_manager.c \
|
||||
src/components/map_manager_component.c \
|
||||
src/components/game_display.c \
|
||||
src/components/game_manager.c \
|
||||
src/components/teams_component.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
INCLUDE = -I ./include -I lib/gamacon/include -I lib/gamacon/lib/xmlparser/include
|
||||
|
||||
CFLAGS = $(INCLUDE) -Wall -Wshadow -Wextra -Wno-unused-parameter
|
||||
|
||||
LDFLAGS = -L lib/gamacon -L lib/my -L lib/xmlparser -L lib/quadtree\
|
||||
-lgamacon -lxmlparser -lquadtree -lmy -lcsfml-system -lcsfml-graphics -lcsfml-audio -lcsfml-window -lm
|
||||
|
||||
NAME = my_world
|
||||
|
||||
CC = gcc
|
||||
|
||||
all: build
|
||||
|
||||
build: $(OBJ)
|
||||
$(MAKE) -C lib/gamacon
|
||||
$(MAKE) -C lib/my
|
||||
$(MAKE) -C lib/xmlparser
|
||||
$(MAKE) -C lib/quadtree
|
||||
$(CC) -o $(NAME) $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(MAKE) -C lib/gamacon clean
|
||||
$(MAKE) -C lib/my clean
|
||||
$(MAKE) -C lib/xmlparser clean
|
||||
$(MAKE) -C lib/quadtree clean
|
||||
$(RM) $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
ffclean: fclean
|
||||
$(MAKE) -C lib/my fclean
|
||||
$(MAKE) -C lib/gamacon fclean
|
||||
$(MAKE) -C lib/xmlparser fclean
|
||||
$(MAKE) -C lib/quadtree fclean
|
||||
|
||||
re: fclean all
|
||||
|
||||
dbg: CFLAGS += -g
|
||||
dbg: clean $(OBJ)
|
||||
$(MAKE) -C lib/gamacon dbg
|
||||
$(MAKE) -C lib/my
|
||||
$(MAKE) -C lib/xmlparser dbg
|
||||
$(MAKE) -C lib/quadtree dbg
|
||||
$(CC) -o $(NAME) $(OBJ) $(LDFLAGS)
|
||||
|
||||
.PHONY: all build clean fclean ffclean
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 243 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 510 B |
|
After Width: | Height: | Size: 768 B |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 717 B |
|
After Width: | Height: | Size: 595 B |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 625 B |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 449 B |
|
After Width: | Height: | Size: 262 B |
|
After Width: | Height: | Size: 216 B |
|
After Width: | Height: | Size: 179 B |
|
After Width: | Height: | Size: 468 B |
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Twac
|
||||
** File description:
|
||||
** array
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void arr_add(int *arr, int n);
|
||||
int arr_len(int *arr);
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/3/20.
|
||||
//
|
||||
|
||||
#ifndef _TEAMS_COMPONENT_C_
|
||||
#define _TEAMS_COMPONENT_H_
|
||||
|
||||
#include "component.h"
|
||||
|
||||
typedef enum display_type
|
||||
{
|
||||
HAPPINESS_DISPLAY,
|
||||
STUPIDITY_DISPLAY,
|
||||
SELECT_TILE_DISPLAY
|
||||
} display_type_enum;
|
||||
|
||||
struct game_display
|
||||
{
|
||||
gc_component base;
|
||||
display_type_enum type;
|
||||
};
|
||||
|
||||
const struct game_display game_display;
|
||||
const struct gc_system game_display_system;
|
||||
|
||||
#endif //_TEAMS_COMPONENT_C_
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/3/20.
|
||||
//
|
||||
|
||||
#ifndef _TEAMS_COMPONENT_C_
|
||||
#define _TEAMS_COMPONENT_H_
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct game_manager
|
||||
{
|
||||
gc_component base;
|
||||
int happiness;
|
||||
int stupidity;
|
||||
};
|
||||
|
||||
const struct game_manager game_manager;
|
||||
|
||||
#endif //_TEAMS_COMPONENT_C_
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/10/20.
|
||||
//
|
||||
|
||||
#ifndef _MAP_MANAGER_COMPONENT_H_
|
||||
#define _MAP_MANAGER_COMPONENT_H_
|
||||
|
||||
#include "component.h"
|
||||
|
||||
enum brush
|
||||
{
|
||||
MOVE,
|
||||
RESET,
|
||||
ROTATE,
|
||||
TEXTURE
|
||||
};
|
||||
|
||||
struct map_manager_component
|
||||
{
|
||||
gc_component base;
|
||||
bool tile_mode;
|
||||
enum brush brush;
|
||||
void *selected_texture;
|
||||
};
|
||||
|
||||
const struct map_manager_component map_manager_component;
|
||||
|
||||
#endif //_MAP_MANAGER_COMPONENT_H_
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/3/20.
|
||||
//
|
||||
|
||||
#ifndef _TEAMS_COMPONENT_C_
|
||||
#define _TEAMS_COMPONENT_H_
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct teams_component
|
||||
{
|
||||
gc_component base;
|
||||
float next_teams;
|
||||
float delay;
|
||||
char **prefabs;
|
||||
int *prefabs_size;
|
||||
int prefab_count;
|
||||
};
|
||||
|
||||
const struct teams_component teams_component;
|
||||
|
||||
bool teams_move_up(gc_scene *scene, float amount, float y_level);
|
||||
void pm_clicked(gc_engine *engine, gc_entity *entity);
|
||||
|
||||
#endif //_TEAMS_COMPONENT_C_
|
||||
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/6/20.
|
||||
//
|
||||
|
||||
#ifndef _DPR_ERRORS_H_
|
||||
#define _DPR_ERRORS_H_
|
||||
|
||||
#define MULTIPLE_GAME_MGR_ERROR "Warning: two game manager exists, \
|
||||
behaviors are undefined.\n"
|
||||
|
||||
#endif //_DPR_ERRORS_H_
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Gamacon
|
||||
** File description:
|
||||
** map_interactions
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MY3D_MAP_INTERACTIONS_H
|
||||
#define MY3D_MAP_INTERACTIONS_H
|
||||
|
||||
#include "engine.h"
|
||||
#include "components/vertex_component.h"
|
||||
#include "keybindings.h"
|
||||
|
||||
enum modes_on_tile {
|
||||
VERTEX_0 = 2,
|
||||
VERTEX_1 = 4,
|
||||
VERTEX_2 = 8,
|
||||
VERTEX_3 = 16,
|
||||
ALL_VERTICES = 30,
|
||||
INVERT_ADD_VALUE = 1
|
||||
};
|
||||
|
||||
bool map_onclick(gc_engine *engine, gc_entity *entity, gc_vector2 pos, \
|
||||
enum gc_mousekeys key);
|
||||
|
||||
#endif //MY3D_MAP_INTERACTIONS_H
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** My lib
|
||||
** File description:
|
||||
** Header file
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
char *my_str_replace(char *str, const char *to_replace, char c);
|
||||
|
||||
int my_str_islower_or_num(const char *str);
|
||||
|
||||
int my_printf(const char *str, ...);
|
||||
|
||||
int count_valid_queens_placements(int n);
|
||||
|
||||
char *my_strchr(const char *str, char c);
|
||||
|
||||
int my_compute_power_it(int n, int p);
|
||||
|
||||
int my_compute_power_rec(int n, int p);
|
||||
|
||||
int my_compute_factorial_it(int n);
|
||||
|
||||
int my_compute_factorial_rec(int n);
|
||||
|
||||
int my_compute_square_root(int n);
|
||||
|
||||
char *my_evil_str(char *str);
|
||||
|
||||
int my_find_prime_sup(int n);
|
||||
|
||||
int my_getnbr_base(const char *str, const char *base);
|
||||
|
||||
int my_getnbr(const char *str);
|
||||
|
||||
int my_isneg(int n);
|
||||
|
||||
int my_is_prime(int n);
|
||||
|
||||
void my_print_alpha(void);
|
||||
|
||||
void my_print_comb2(void);
|
||||
|
||||
void my_print_combn(int n);
|
||||
|
||||
void my_print_comb(void);
|
||||
|
||||
void my_print_digits(void);
|
||||
|
||||
void my_print_revalpha(void);
|
||||
|
||||
void my_putchar(char c);
|
||||
|
||||
void my_putlong_base(long n, const char *base);
|
||||
|
||||
void my_putnbr_base(int n, const char *base);
|
||||
|
||||
void my_put_nbr(int n);
|
||||
|
||||
void my_putstr(const char *str);
|
||||
|
||||
void my_revstr(char *str);
|
||||
|
||||
void my_showmem(char *str, int);
|
||||
|
||||
void my_showstr(const char *str);
|
||||
|
||||
void my_sort_int_array(int *array);
|
||||
|
||||
int is_letter(char c);
|
||||
|
||||
int is_alpha(char c);
|
||||
|
||||
int is_num(char c);
|
||||
|
||||
int is_digit(char c);
|
||||
|
||||
char *my_strcapitalize(char *str);
|
||||
|
||||
char *my_strcat(char *dest, const char *src);
|
||||
|
||||
int my_strcmp(const char *s1, const char *s2);
|
||||
|
||||
char *my_strcpy(char *dest, const char *str);
|
||||
|
||||
int my_str_isalpha(const char *str);
|
||||
|
||||
int is_lowercase(char c);
|
||||
|
||||
int my_str_islower(const char *str);
|
||||
|
||||
int my_str_isnum(const char *str);
|
||||
|
||||
int is_printable(char c);
|
||||
int my_str_isprintable(const char *str);
|
||||
|
||||
int is_upper(char c);
|
||||
int my_str_isupper(const char *str);
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
int my_strlowcase(const char *str);
|
||||
|
||||
char *my_strncat(char *dest, const char *src, int n);
|
||||
|
||||
int my_strncmp(const char *s1, const char *s2, int n);
|
||||
|
||||
char *my_strncpy(char *dest, const char *src, int n);
|
||||
|
||||
char *my_strstr(const char *str, const char *to_find);
|
||||
|
||||
int my_strupcase(const char *str);
|
||||
|
||||
void my_swap(int *a, int *b);
|
||||
|
||||
char *my_strdup(const char *str);
|
||||
|
||||
char **my_str_to_word_array(const char *str);
|
||||
|
||||
int my_show_word_array(const char **words);
|
||||
|
||||
int is_alphanum(char c);
|
||||
|
||||
int first_alphanum(const char *str);
|
||||
|
||||
int index_of(const char *str, char c);
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** quadtree
|
||||
** File description:
|
||||
** quadtree_internal
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quadtree.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void *my_calloc(int capacity, int size);
|
||||
|
||||
quadtree *qt_split(quadtree *tree);
|
||||
|
||||
bool collision_overlapx(qt_intrect r1, qt_intrect r2);
|
||||
bool collision_overlapy(qt_intrect r1, qt_intrect r2);
|
||||
|
||||
bool collision_can_see(int l1, int l2);
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define MAX(x, y) ((x) < (y) ? (y) : (x))
|
||||
|
||||
#define CAN_BE_SEEN 0b10
|
||||
#define CAN_SEE 0b01
|
||||
|
||||
#define TREEOBJ_AT(x) (&((qt_object *)tree->objects)[i])
|
||||
|
||||
#define COLLISION_MAX ((qt_collision){MAXCOL, MAXCOL, MAXCOL, MAXCOL, NULL})
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** runner
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ERROR 84
|
||||
#include "scene.h"
|
||||
|
||||
int start_game();
|
||||
|
||||
bool start_button(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool options(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool goto_main_menu(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool quit(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool catch(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool toggle_pause(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
|
||||
int checkbox_update(gc_scene *s, gc_entity *entity, bool checked);
|
||||
void resolution_set_text(gc_entity *entity, gc_engine *engine);
|
||||
void framerate_set_text(gc_entity *entity, gc_engine *engine);
|
||||
|
||||
bool fullscreen(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool resolution_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool resolution_up(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool framerate_up(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool framerate_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
|
||||
bool tile_select(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool vertex_select(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool up_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool reset(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool rotate(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
bool switch_texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/9/20.
|
||||
//
|
||||
|
||||
#ifndef _GAME_MANAGER_SYSTEM_H_
|
||||
#define _GAME_MANAGER_SYSTEM_H_
|
||||
|
||||
#include "system.h"
|
||||
|
||||
const gc_system game_manager_system;
|
||||
|
||||
#endif //_GAME_MANAGER_SYSTEM_H_
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/3/20.
|
||||
//
|
||||
|
||||
#ifndef _TEAMS_SYSTEM_H_
|
||||
#define _TEAMS_SYSTEM_H_
|
||||
|
||||
#include "system.h"
|
||||
|
||||
const gc_system teams_system;
|
||||
|
||||
#endif //_TEAMS_SYSTEM_H_
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/9/20.
|
||||
//
|
||||
|
||||
#ifndef _TEAMS_H_
|
||||
#define _TEAMS_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "engine.h"
|
||||
|
||||
bool absent_check(gc_engine *engine, int entity_id, gc_vector2 _);
|
||||
bool absent_cross(gc_engine *engine, int entity_id, gc_vector2 _);
|
||||
|
||||
bool forgot_lmfao(gc_engine *engine, int entity_id, gc_vector2 _);
|
||||
bool forgot_ok(gc_engine *engine, int entity_id, gc_vector2 _);
|
||||
|
||||
#endif //_TEAMS_H_
|
||||
@@ -0,0 +1,62 @@
|
||||
##
|
||||
## EPITECH PROJECT, 2019
|
||||
## PSU_my_printf_bootstrap_2019
|
||||
## File description:
|
||||
## Makefile
|
||||
##
|
||||
|
||||
SRC = src/printf.c \
|
||||
src/printf_utility.c \
|
||||
src/my_putlonglong_base.c \
|
||||
src/formaters/string_formater.c \
|
||||
src/formaters/string_nonprintable_formater.c \
|
||||
src/formaters/char_formater.c \
|
||||
src/formaters/int_formater.c \
|
||||
src/formaters/uint_formater.c \
|
||||
src/formaters/ptr_formater.c \
|
||||
src/formaters/ubinary_formater.c \
|
||||
src/formaters/octal_formater.c \
|
||||
src/formaters/hexa_formater.c \
|
||||
src/formaters/big_hexa_formater.c \
|
||||
src/formaters/float_formater.c \
|
||||
src/formaters/no_format.c \
|
||||
src/get_nbr_size.c \
|
||||
my/*.c
|
||||
|
||||
OBJ = *.o
|
||||
|
||||
TESTS = tests/test_printf.c
|
||||
|
||||
INCLUDE = -I ./include
|
||||
|
||||
COVERAGE = --coverage -lcriterion
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -Wshadow -Wextra -Wno-unused-parameter
|
||||
|
||||
NAME = libmy.a
|
||||
|
||||
UT = ut
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME):
|
||||
$(CC) -c $(SRC) $(INCLUDE) $(CFLAGS)
|
||||
ar rc $(NAME) $(OBJ)
|
||||
|
||||
tests_run:
|
||||
$(CC) -o $(UT) $(SRC) $(TESTS) $(INCLUDE) $(COVERAGE) $(CFLAGS)
|
||||
./$(UT)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
rm -rf *.gc*
|
||||
|
||||
fclean: clean
|
||||
rm -rf $(NAME)
|
||||
rm -rf $(UT)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY = all build clean fclean
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Formater struct
|
||||
** File description:
|
||||
** formaters
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdarg.h>
|
||||
|
||||
#define MODIFIERS_SIZE 50
|
||||
|
||||
typedef struct formater
|
||||
{
|
||||
int (*func)(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
char flag;
|
||||
} formater_t;
|
||||
|
||||
int string_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int string_nonprintable_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int char_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int int_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int uint_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int ptr_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int ubinary_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int octal_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int hexa_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int big_hexa_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int float_formater(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
int no_format(va_list ap, char modifiers[MODIFIERS_SIZE]);
|
||||
|
||||
int count(char c, char *str);
|
||||
int contains(char c, char *str);
|
||||
int get_nbr_len(long long int n, const char *base);
|
||||
int is_modifier(char c);
|
||||
int last_mod(char *modifiers);
|
||||
int my_putlonglong_base(long long int nbr, const char *base, int length);
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** My lib
|
||||
** File description:
|
||||
** Header file
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
char *my_str_replace(char *str, const char *to_replace, char c);
|
||||
|
||||
int my_str_islower_or_num(const char *str);
|
||||
|
||||
int my_printf(const char *str, ...);
|
||||
|
||||
void print_ptr(void *ptr);
|
||||
|
||||
void print_str_to(char *ptr, int max);
|
||||
|
||||
int count_valid_queens_placements(int n);
|
||||
|
||||
int my_compute_power_it(int n, int p);
|
||||
|
||||
int my_compute_power_rec(int n, int p);
|
||||
|
||||
int my_compute_factorial_it(int n);
|
||||
|
||||
int my_compute_factorial_rec(int n);
|
||||
|
||||
int my_sqrt(int nb);
|
||||
|
||||
char *my_evil_str(char *str);
|
||||
|
||||
int my_find_prime_sup(int n);
|
||||
|
||||
int my_getnbr_base(const char *str, const char *base);
|
||||
|
||||
int my_getnbr(const char *str);
|
||||
|
||||
int my_isneg(int n);
|
||||
|
||||
int my_is_prime(int n);
|
||||
|
||||
void my_print_alpha(void);
|
||||
|
||||
void my_print_comb2(void);
|
||||
|
||||
void my_print_combn(int n);
|
||||
|
||||
void my_print_comb(void);
|
||||
|
||||
void my_print_digits(void);
|
||||
|
||||
void my_print_revalpha(void);
|
||||
|
||||
void my_putchar(char c);
|
||||
|
||||
int my_putlong_base(long long nbr, const char *base);
|
||||
|
||||
void my_putnbr_base(int n, const char *base);
|
||||
|
||||
void my_put_nbr(int n);
|
||||
|
||||
void my_putstr(const char *str);
|
||||
|
||||
void my_revstr(char *str);
|
||||
|
||||
void my_showmem(char *str, int size);
|
||||
|
||||
void my_showstr(const char *str);
|
||||
|
||||
void my_sort_int_array(int *array);
|
||||
|
||||
int is_letter(char c);
|
||||
|
||||
int is_alpha(char c);
|
||||
|
||||
int is_num(char c);
|
||||
|
||||
int is_digit(char c);
|
||||
|
||||
char *my_strcapitalize(char *str);
|
||||
|
||||
char *my_strcat(char *dest, const char *str);
|
||||
|
||||
int my_strcmp(const char *s1, const char *s2);
|
||||
|
||||
char *my_strcpy(char *dest, const char *src);
|
||||
|
||||
int my_str_isalpha(const char *str);
|
||||
|
||||
int is_lowercase(char c);
|
||||
|
||||
int my_str_islower(const char *str);
|
||||
|
||||
int my_str_isnum(const char *str);
|
||||
|
||||
int is_printable(char c);
|
||||
int my_str_isprintable(const char *str);
|
||||
|
||||
int is_upper(char c);
|
||||
int my_str_isupper(const char *str);
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
int my_strlowcase(const char *str);
|
||||
|
||||
char *my_strncat(char *dest, const char *str, int n);
|
||||
|
||||
int my_strncmp(const char *s1, const char *s2, int n);
|
||||
|
||||
char *my_strncpy(char *dest, const char *src, int n);
|
||||
|
||||
char *my_strstr(const char *str, const char *to_find);
|
||||
|
||||
int my_strupcase(const char *str);
|
||||
|
||||
void my_swap(int *a, int *b);
|
||||
|
||||
char *my_strdup(const char *str);
|
||||
|
||||
char **my_str_to_word_array(const char *str);
|
||||
|
||||
int my_show_word_array(const char **words);
|
||||
|
||||
int is_alphanum(char c);
|
||||
|
||||
int first_alphanum(const char *str);
|
||||
|
||||
int index_of(const char *str, char c);
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Helper for the task 4
|
||||
** File description:
|
||||
** alphanum_helper
|
||||
*/
|
||||
|
||||
int is_alpha(char c);
|
||||
|
||||
int is_digit(char c);
|
||||
|
||||
int is_alphanum(char c)
|
||||
{
|
||||
return (is_alpha(c) || is_digit(c));
|
||||
}
|
||||
|
||||
int first_alphanum(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (is_alphanum(str[i]))
|
||||
return i;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** String helper
|
||||
** File description:
|
||||
** Index of char in a string
|
||||
*/
|
||||
|
||||
int index_of(const char *str, const char c)
|
||||
{
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (str[i] == c)
|
||||
return (i);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Factorials
|
||||
*/
|
||||
|
||||
int my_compute_factorial_it(int nb)
|
||||
{
|
||||
if (nb < 0)
|
||||
return 0;
|
||||
|
||||
int ret = 1;
|
||||
while (nb > 0) {
|
||||
ret *= nb;
|
||||
nb--;
|
||||
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Factorials but in recursive mode
|
||||
*/
|
||||
|
||||
int compute(int nb, int ret)
|
||||
{
|
||||
if (ret < 0)
|
||||
return (0);
|
||||
|
||||
if (nb == 0)
|
||||
return (ret);
|
||||
|
||||
return (compute(nb - 1, ret * nb));
|
||||
}
|
||||
|
||||
int my_compute_factorial_rec(int nb)
|
||||
{
|
||||
if (nb == 0)
|
||||
return (1);
|
||||
|
||||
return (compute(nb, 1));
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Power calculator
|
||||
*/
|
||||
|
||||
int my_pow(int nb, int p)
|
||||
{
|
||||
int ret = 1;
|
||||
int mult = 1;
|
||||
|
||||
if (p < 0)
|
||||
return 0;
|
||||
if (nb < 0) {
|
||||
nb *= -1;
|
||||
if (p % 2 == 1)
|
||||
mult = -1;
|
||||
}
|
||||
while (p > 0) {
|
||||
ret *= nb;
|
||||
p--;
|
||||
|
||||
if (ret < 0)
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (ret * mult);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Square root calculator
|
||||
*/
|
||||
|
||||
int my_sqrt(int nb)
|
||||
{
|
||||
if (nb < 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; 1; i++) {
|
||||
int power = i * i;
|
||||
if (power == nb)
|
||||
return i;
|
||||
else if (power > nb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Reverse string
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
char *my_evil_str(char *str)
|
||||
{
|
||||
int count = 0;
|
||||
char buf[1598246];
|
||||
|
||||
while (1) {
|
||||
buf[count] = str[count];
|
||||
if (*(str + count) != '\0')
|
||||
count++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
str[i] = buf[count - i - 1];
|
||||
|
||||
str[count + 1] = '\0';
|
||||
return str;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Find a prime number greater than the given number
|
||||
*/
|
||||
|
||||
int my_is_prime(int n);
|
||||
|
||||
int my_find_prime_sup(int n)
|
||||
{
|
||||
if (n <= 2)
|
||||
return (2);
|
||||
while (!my_is_prime(n))
|
||||
n++;
|
||||
|
||||
return n;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Int parser
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
static int parse(const char *str, int digit_count, int neg)
|
||||
{
|
||||
int n = 0;
|
||||
int add;
|
||||
for (int power = 0; power < digit_count; power++) {
|
||||
add = str[digit_count - power - 1] - '0';
|
||||
if (power == 10 && add > 2)
|
||||
return 0;
|
||||
|
||||
add *= neg;
|
||||
for (int i = 0; i < power; i++) {
|
||||
add *= 10;
|
||||
if (add * neg < 0)
|
||||
return 0;
|
||||
}
|
||||
n += add;
|
||||
|
||||
if ((neg == -1 && n > 0) || (neg == 1 && n < 0))
|
||||
return 0;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static int init_print(const char *str, int count, int s_index)
|
||||
{
|
||||
int neg = 1;
|
||||
|
||||
for (char c = str[s_index]; c == '-' || c == '+'; c = str[s_index]) {
|
||||
if (c == '-')
|
||||
neg *= -1;
|
||||
s_index++;
|
||||
count--;
|
||||
}
|
||||
|
||||
char buf[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
buf[i] = str[s_index + i];
|
||||
|
||||
|
||||
return parse(buf, count, neg);
|
||||
}
|
||||
|
||||
int my_getnbr(const char *str)
|
||||
{
|
||||
int count = 0;
|
||||
int start_index = -1;
|
||||
char c;
|
||||
|
||||
for (int i = 0; str[i]; i++) {
|
||||
c = str[i];
|
||||
if ((c >= '0' && c <= '9') || c == '-' || c == '+') {
|
||||
if (start_index == -1)
|
||||
start_index = i;
|
||||
count++;
|
||||
}
|
||||
else if (count > 0 || c == '\0')
|
||||
break;
|
||||
}
|
||||
if (count <= 0)
|
||||
return (0);
|
||||
return init_print(str, count, start_index);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Get number with any base
|
||||
** File description:
|
||||
** Int library
|
||||
*/
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
int my_pow(int i, int p);
|
||||
|
||||
static int indexof(char c, const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (str[i] == c)
|
||||
return (i);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static int parse(char *str, const char *base, long n, int i)
|
||||
{
|
||||
int str_length = my_strlen(str);
|
||||
int base_length = my_strlen(base);
|
||||
int power;
|
||||
int neg = 1;
|
||||
|
||||
if (i < 0) {
|
||||
neg = -1;
|
||||
i *= -1;
|
||||
}
|
||||
power = my_pow(base_length, i - 1);
|
||||
n += indexof(str[str_length - i], base) * power * neg;
|
||||
if ((n > 0 && neg < 0) || (n < 0 && neg > 0))
|
||||
return (0);
|
||||
if (str_length - i > 0)
|
||||
return (parse(str, base, n, (i + 1) * neg));
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int get_digit_count(const char *str, const char *base)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (indexof(str[i], base) != -1)
|
||||
count++;
|
||||
else if (count > 0)
|
||||
return (count);
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
int my_getnbr_base(const char *str, const char *base)
|
||||
{
|
||||
int length = get_digit_count(str, base);
|
||||
char num[length + 1];
|
||||
int start_index = 0;
|
||||
int neg = 1;
|
||||
|
||||
if (length == 0)
|
||||
return 0;
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (indexof(str[i], base) != -1) {
|
||||
num[start_index] = str[i];
|
||||
start_index++;
|
||||
}
|
||||
else if (str[i] == '-')
|
||||
neg *= -1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
num[length] = '\0';
|
||||
return (parse(num, base, 0, neg));
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day05_2019
|
||||
** File description:
|
||||
** Check if a number is a prime number
|
||||
*/
|
||||
|
||||
int my_compute_square_root(int n);
|
||||
|
||||
int my_is_prime(int n)
|
||||
{
|
||||
int square;
|
||||
|
||||
if (n <= 1)
|
||||
return (0);
|
||||
if (n == 2)
|
||||
return (1);
|
||||
for (int i = 0; i * i <= n; i++)
|
||||
square = i;
|
||||
for (int i = 2; i < square + 1; i++) {
|
||||
if (n % i == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 4
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
int my_isneg(int n)
|
||||
{
|
||||
if (n < 0)
|
||||
my_putchar('N');
|
||||
else
|
||||
my_putchar('P');
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** First task
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
int my_print_alpha(void)
|
||||
{
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
my_putchar(i);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 5
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
static void print_c(char x, char y, char z)
|
||||
{
|
||||
my_putchar(x);
|
||||
my_putchar(y);
|
||||
my_putchar(z);
|
||||
}
|
||||
|
||||
static void increment_y(char *x, char *y, char *z)
|
||||
{
|
||||
*x = *x + 1;
|
||||
*y = *x + 1;
|
||||
*z = *y + 1;
|
||||
}
|
||||
|
||||
int my_print_comb(void)
|
||||
{
|
||||
char x = '0';
|
||||
char y = '1';
|
||||
char z = '2';
|
||||
|
||||
while (1) {
|
||||
print_c(x, y, z);
|
||||
z++;
|
||||
if (z > '9') {
|
||||
y++;
|
||||
z = y + 1;
|
||||
}
|
||||
if (y > '8')
|
||||
increment_y(&x, &y, &z);
|
||||
if (x <= '7') {
|
||||
my_putchar(',');
|
||||
my_putchar(' ');
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 6
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
static void print_c2(int i, int j)
|
||||
{
|
||||
my_putchar('0' + i / 10);
|
||||
my_putchar('0' + i % 10);
|
||||
my_putchar(' ');
|
||||
my_putchar('0' + j / 10);
|
||||
my_putchar('0' + j % 10);
|
||||
|
||||
if (i != 98) {
|
||||
my_putchar(',');
|
||||
my_putchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
static void get_group2(int i)
|
||||
{
|
||||
for (int j = i + 1; j <= 99; j++)
|
||||
print_c2(i, j);
|
||||
}
|
||||
|
||||
int my_print_comb2(void)
|
||||
{
|
||||
for (int i = 0; i <= 98; i++)
|
||||
get_group2(i);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 9
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
static int is_nbr_valid(int n, int i)
|
||||
{
|
||||
if (n < 9) {
|
||||
if (n >= i)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
int j = n % 10;
|
||||
|
||||
if (j >= i)
|
||||
return (0);
|
||||
return is_nbr_valid(n / 10, j);
|
||||
}
|
||||
|
||||
static void print_cn(int n)
|
||||
{
|
||||
if (n > 9)
|
||||
print_cn(n / 10);
|
||||
|
||||
my_putchar('0' + n % 10);
|
||||
}
|
||||
|
||||
static void process_valid_number(int n, int starting, int last_valid)
|
||||
{
|
||||
if (last_valid) {
|
||||
my_putchar(',');
|
||||
my_putchar(' ');
|
||||
}
|
||||
if (n < starting && starting != 1)
|
||||
my_putchar('0');
|
||||
print_cn(n);
|
||||
}
|
||||
|
||||
int my_print_combn(int n)
|
||||
{
|
||||
if (n > 10)
|
||||
return 0;
|
||||
|
||||
int starting = 1;
|
||||
int last_valid = 0;
|
||||
|
||||
for (int i = 0; i < n - 1; i++)
|
||||
starting *= 10;
|
||||
|
||||
for (int i = starting / 10; i < starting * 10; i++) {
|
||||
if (is_nbr_valid(i, 10)) {
|
||||
process_valid_number(i, starting, last_valid);
|
||||
last_valid = 1;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 3
|
||||
*/
|
||||
|
||||
int my_putchar(char n);
|
||||
|
||||
int my_print_digits(void)
|
||||
{
|
||||
for (char i = '0'; i <= '9'; i++) {
|
||||
my_putchar(i);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** The second task
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
int my_print_revalpha(void)
|
||||
{
|
||||
for (char i = 'z'; i >= 'a'; i--) {
|
||||
my_putchar(i);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day03_2019
|
||||
** File description:
|
||||
** Task 07
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
static void get_digit(long digit)
|
||||
{
|
||||
long n = digit;
|
||||
char c = '0' + n % 10;
|
||||
if (n > 9) {
|
||||
n /= 10;
|
||||
get_digit(n);
|
||||
}
|
||||
my_putchar(c);
|
||||
}
|
||||
|
||||
int my_put_nbr(int n)
|
||||
{
|
||||
long digit = n;
|
||||
if (n < 0) {
|
||||
my_putchar('-');
|
||||
digit *= -1;
|
||||
}
|
||||
get_digit(digit);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Putchar
|
||||
** File description:
|
||||
** Yes
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void my_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Put nbr in a custom base
|
||||
** File description:
|
||||
** Might be useful later
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
static void display_a_digit(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
static void put_digit(long n, int base_length, const char *base)
|
||||
{
|
||||
if (n > base_length - 1)
|
||||
put_digit(n / base_length, base_length, base);
|
||||
display_a_digit(base[n % base_length]);
|
||||
}
|
||||
|
||||
int my_putlong_base(long nbr, const char *base)
|
||||
{
|
||||
int base_length = my_strlen(base);
|
||||
|
||||
if (base_length < 2) {
|
||||
display_a_digit('0');
|
||||
return (0);
|
||||
}
|
||||
if (nbr < 0) {
|
||||
nbr *= -1;
|
||||
display_a_digit('-');
|
||||
}
|
||||
put_digit(nbr, base_length, base);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Put nbr in a custom base
|
||||
** File description:
|
||||
** Might be useful later
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
static void display_a_digit(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
static void put_digit(int n, int base_length, const char *base)
|
||||
{
|
||||
if (n > base_length - 1)
|
||||
put_digit(n / base_length, base_length, base);
|
||||
display_a_digit(base[n % base_length]);
|
||||
}
|
||||
|
||||
int my_putnbr_base(int nbr, const char *base)
|
||||
{
|
||||
int base_length = my_strlen(base);
|
||||
|
||||
if (base_length < 2) {
|
||||
display_a_digit('0');
|
||||
return (0);
|
||||
}
|
||||
if (nbr < 0) {
|
||||
nbr *= -1;
|
||||
display_a_digit('-');
|
||||
}
|
||||
put_digit(nbr, base_length, base);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Put string
|
||||
*/
|
||||
|
||||
int my_putchar(char c);
|
||||
|
||||
int my_putstr(const char *str)
|
||||
{
|
||||
for (int i = 0; 1; i++) {
|
||||
char c = *(str + i);
|
||||
if (c == '\0')
|
||||
return (0);
|
||||
my_putchar(c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Reverse string
|
||||
*/
|
||||
|
||||
int my_strlen(char *str);
|
||||
|
||||
char *my_revstr(char *str)
|
||||
{
|
||||
int length = my_strlen(str);
|
||||
char dup[length + 1];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
dup[i] = str[i];
|
||||
for (int i = 0; i < length; i++)
|
||||
str[i] = dup[length - 1 - i];
|
||||
str[length] = '\0';
|
||||
return (str);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Show an array of words on the screen
|
||||
** File description:
|
||||
** Nothing to say
|
||||
*/
|
||||
|
||||
void my_putstr(const char *str);
|
||||
|
||||
void my_putchar(char c);
|
||||
|
||||
int my_show_word_array(const char *words[])
|
||||
{
|
||||
for (int i = 0; words[i]; i++) {
|
||||
my_putstr(words[i]);
|
||||
my_putchar('\n');
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Memory dump
|
||||
** File description:
|
||||
** Debug Library
|
||||
*/
|
||||
|
||||
const char *hex = "0123456789abcdef";
|
||||
|
||||
#include "my.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int get_size(long n, const char *base);
|
||||
|
||||
void my_putchar(char c);
|
||||
|
||||
int is_printable(char c);
|
||||
|
||||
void display_x_char(char c, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void print_ptr(void *ptr)
|
||||
{
|
||||
write(1, "0x", 2);
|
||||
my_putlong_base((long)ptr, hex);
|
||||
}
|
||||
|
||||
void print_hexa(char *ptr, int size)
|
||||
{
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (i >= size) {
|
||||
display_x_char(' ', 40 - (i * 2 + i / 2));
|
||||
return;
|
||||
}
|
||||
if (ptr[i] < 16)
|
||||
my_putchar('0');
|
||||
my_putlong_base((long)ptr[i], hex);
|
||||
if (i % 2 == 1)
|
||||
my_putchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void print_str_to(char *ptr, int max)
|
||||
{
|
||||
int overflow = 0;
|
||||
|
||||
for (int i = 0; i < max; i++) {
|
||||
if (overflow || !is_printable(ptr[i]))
|
||||
my_putchar('.');
|
||||
else
|
||||
my_putchar(ptr[i]);
|
||||
if (!overflow)
|
||||
overflow = ptr[i] == '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void my_showmem(char *str, int size)
|
||||
{
|
||||
int padding = size % 16;
|
||||
int line_count = padding == 0 ? size / 16 : size / 16 + 1;
|
||||
char *ptr;
|
||||
|
||||
for (int i = 0; i < line_count; i++) {
|
||||
ptr = (str + i * 16);
|
||||
print_ptr((void *)(ptr - str));
|
||||
print_hexa(ptr, size - i * 16);
|
||||
print_str_to(ptr, 16);
|
||||
my_putchar('\n');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Show Str With non printable values in hexa
|
||||
** File description:
|
||||
** Debugger Library
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int is_printable(char c);
|
||||
|
||||
int my_putnbr_base(int i, const char *base);
|
||||
|
||||
void puthex(char c)
|
||||
{
|
||||
write(1, "\\", 1);
|
||||
if (c < 8)
|
||||
write(1, "0", 1);
|
||||
if (c < 16)
|
||||
write(1, "0", 1);
|
||||
my_putnbr_base(c, "01234567");
|
||||
}
|
||||
|
||||
int my_showstr(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (is_printable(str[i]))
|
||||
write(1, &(str[i]), 1);
|
||||
else
|
||||
puthex(str[i]);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Int array sorter
|
||||
*/
|
||||
|
||||
static void sort_linear(int *array, int size)
|
||||
{
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
if (array[i] > array[i + 1]) {
|
||||
int buf = array[i];
|
||||
array[i] = array[i + 1];
|
||||
array[i + 1] = buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int my_sort_int_array(int *array, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
sort_linear(array, size);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str is alpha
|
||||
** File description:
|
||||
** Duplicate of the string.h (I think)
|
||||
*/
|
||||
|
||||
int is_alpha(char c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (1);
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int my_str_isalpha(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_alpha(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str is alpha
|
||||
** File description:
|
||||
** Duplicate of the string.h (I think)
|
||||
*/
|
||||
|
||||
int is_digit(char c);
|
||||
|
||||
int is_lowercase(char c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int my_str_islower(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_lowercase(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int my_str_islower_or_num(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_lowercase(str[i]) && !is_digit(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str is alpha
|
||||
** File description:
|
||||
** Duplicate of the string.h (I think)
|
||||
*/
|
||||
|
||||
int is_digit(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int my_str_isnum(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_digit(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str is alpha
|
||||
** File description:
|
||||
** Duplicate of the string.h (I think)
|
||||
*/
|
||||
|
||||
int is_printable(char c)
|
||||
{
|
||||
if (c >= ' ' && c < 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int my_str_isprintable(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_printable(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str is alpha
|
||||
** File description:
|
||||
** Duplicate of the string.h (I think)
|
||||
*/
|
||||
|
||||
int is_upper(char c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int my_str_isupper(const char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (!is_upper(str[i]))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** My3D
|
||||
** File description:
|
||||
** my_str_replace
|
||||
*/
|
||||
|
||||
#include "my.h"
|
||||
|
||||
char *my_str_replace(char *str, const char *to_replace, char c)
|
||||
{
|
||||
char *p;
|
||||
int len = my_strlen(to_replace);
|
||||
|
||||
while ((p = my_strstr(str, to_replace))) {
|
||||
*p = c;
|
||||
p++;
|
||||
for (char *ptr = p + len - 1; *ptr; ptr++, p++)
|
||||
*p = *ptr;
|
||||
*p = '\0';
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Convert a string to a char **
|
||||
** File description:
|
||||
** Split with every non alpha-numerical characters
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_alphanum(char c);
|
||||
|
||||
int first_alphanum(const char *str);
|
||||
|
||||
static int count_words(const char *str)
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
if (first_alphanum(str) == -1)
|
||||
return (0);
|
||||
for (int i = first_alphanum(str); str[i + 1]; i++) {
|
||||
if (!is_alphanum(str[i]) && is_alphanum(str[i + 1]))
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static int get_word_length(const char *str, int n)
|
||||
{
|
||||
int count = 0;
|
||||
int word_length = 0;
|
||||
|
||||
for (int i = first_alphanum(str); str[i]; i++) {
|
||||
if (!is_alphanum(str[i]) && is_alphanum(str[i + 1]))
|
||||
count++;
|
||||
else if (count == n && is_alphanum(str[i]))
|
||||
word_length++;
|
||||
}
|
||||
return (word_length);
|
||||
}
|
||||
|
||||
static char *get_word(const char *str, int n)
|
||||
{
|
||||
int length = get_word_length(str, n);
|
||||
char *ret = malloc(sizeof(*ret) * (length + 1));
|
||||
int count = 0;
|
||||
int word_length = 0;
|
||||
|
||||
for (int i = first_alphanum(str); word_length != length; i++) {
|
||||
if (!is_alphanum(str[i]) && is_alphanum(str[i + 1]))
|
||||
count++;
|
||||
else if (count == n) {
|
||||
ret[word_length] = str[i];
|
||||
word_length++;
|
||||
}
|
||||
}
|
||||
ret[length] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char **my_str_to_word_array(const char *str)
|
||||
{
|
||||
int count = count_words(str);
|
||||
char **ret = malloc(sizeof(*ret) * (count + 1));
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret[i] = get_word(str, i);
|
||||
}
|
||||
ret[count] = 0;
|
||||
return (ret);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** ToUpercase
|
||||
** File description:
|
||||
** string.h
|
||||
*/
|
||||
|
||||
int is_num(char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
int is_letter(char c)
|
||||
{
|
||||
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
|
||||
}
|
||||
|
||||
char *my_strcapitalize(char *str)
|
||||
{
|
||||
int capitalize_next = 1;
|
||||
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (capitalize_next && str[i] > 'a' && str[i] < 'z')
|
||||
str[i] += 'A' - 'a';
|
||||
|
||||
if (is_num(str[i]) || is_letter(str[i]))
|
||||
capitalize_next = 1;
|
||||
else
|
||||
capitalize_next = 0;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** String cat
|
||||
** File description:
|
||||
** The end of the string.h lib
|
||||
*/
|
||||
|
||||
int my_strlen(const char *dest);
|
||||
|
||||
char *my_strcat(char *dest, const char *src)
|
||||
{
|
||||
int i;
|
||||
int dest_length = my_strlen(dest);
|
||||
|
||||
for (i = 0; src[i]; i++)
|
||||
dest[dest_length + i] = src[i];
|
||||
dest[dest_length + i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** my_strchr
|
||||
*/
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
char *my_strchr(char *str, char c)
|
||||
{
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (str[i] == c)
|
||||
return (&str[i]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** StrCmp
|
||||
** File description:
|
||||
** String.h duplicate
|
||||
*/
|
||||
|
||||
int my_strcmp(const char *str1, const char *str2)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
for (i = 0; str1[i] != '\0'; i++) {
|
||||
if (str2[i] == '\0')
|
||||
return str1[i];
|
||||
ret = str1[i] - str2[i];
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if (str2[i] == '\0')
|
||||
return (0);
|
||||
else
|
||||
return -str2[i];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** String copy
|
||||
** File description:
|
||||
** Copy an entire string
|
||||
*/
|
||||
|
||||
char *my_strcpy(char *dest, const char *src)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; src[i] != '\0'; i++)
|
||||
dest[i] = src[i];
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Str dup replicate
|
||||
** File description:
|
||||
** MALLOC YES
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int my_strlen(const char *src);
|
||||
|
||||
char *my_strdup(const char *src)
|
||||
{
|
||||
int length = my_strlen(src);
|
||||
char *ret = malloc(sizeof(char) * (length + 1));
|
||||
|
||||
if (!ret)
|
||||
return (NULL);
|
||||
for (int i = 0; i < length; i++)
|
||||
ret[i] = src[i];
|
||||
ret[length] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Strlen
|
||||
*/
|
||||
|
||||
int my_strlen(const char *str)
|
||||
{
|
||||
for (int i = 0; 1; i++) {
|
||||
if (*(str + i) == '\0')
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** ToUpercase
|
||||
** File description:
|
||||
** string.h
|
||||
*/
|
||||
|
||||
char *my_strlowcase(char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (str[i] > 'A' && str[i] < 'Z')
|
||||
str[i] += 'a' - 'A';
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** String N Cat
|
||||
** File description:
|
||||
** End of the string.h lib
|
||||
*/
|
||||
|
||||
int my_strlen(const char *str);
|
||||
|
||||
char *my_strncat(char *dest, const char *src, int n)
|
||||
{
|
||||
int i;
|
||||
int dest_length = my_strlen(dest);
|
||||
|
||||
for (i = 0; i < n && src[i]; i++)
|
||||
dest[dest_length + i] = src[i];
|
||||
dest[dest_length + i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** StrNCmp
|
||||
** File description:
|
||||
** String.h duplicate
|
||||
*/
|
||||
|
||||
int my_strncmp(const char *str1, const char *str2, int n)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
for (i = 0; i < n && str1[i] != '\0'; i++) {
|
||||
if (str2[i] == '\0')
|
||||
return str1[i];
|
||||
ret = str1[i] - str2[i];
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if (i == n || str2[i] == '\0')
|
||||
return (0);
|
||||
else
|
||||
return -str2[i];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** String copy n first chars
|
||||
** File description:
|
||||
** Same but different
|
||||
*/
|
||||
|
||||
char *my_strncpy(char *dest, const char* src, int n)
|
||||
{
|
||||
int overflow = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (overflow)
|
||||
dest[i] = '\0';
|
||||
else {
|
||||
dest[i] = src[i];
|
||||
overflow = (src[i] == '\0');
|
||||
}
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** StrStr duplicate
|
||||
** File description:
|
||||
** A search in string function
|
||||
*/
|
||||
|
||||
char *my_strstr(char *str, const char *to_find)
|
||||
{
|
||||
int i;
|
||||
int search_index = 0;
|
||||
|
||||
for (i = 0; str[i] != '\0'; i++) {
|
||||
if (to_find[search_index] == '\0')
|
||||
return (str + i - search_index);
|
||||
if (str[i] == to_find[search_index])
|
||||
search_index++;
|
||||
else if (str[i] == to_find[0])
|
||||
search_index = 1;
|
||||
else
|
||||
search_index = 0;
|
||||
}
|
||||
if (to_find[search_index] == '\0')
|
||||
return (str + i - search_index);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** ToUpercase
|
||||
** File description:
|
||||
** string.h
|
||||
*/
|
||||
|
||||
char *my_strupcase(char *str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
if (str[i] > 'a' && str[i] < 'z')
|
||||
str[i] += 'A' - 'a';
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** CPool_Day04_2019
|
||||
** File description:
|
||||
** Swap int
|
||||
*/
|
||||
|
||||
void my_swap(int *a, int *b)
|
||||
{
|
||||
int n = *a;
|
||||
*a = *b;
|
||||
*b = n;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Convering Between bases
|
||||
** File description:
|
||||
** Moldavie-Land
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void put_digit(int n, const char *base, char *ret, int i)
|
||||
{
|
||||
int base_length = 10;
|
||||
|
||||
if (n > base_length - 1)
|
||||
put_digit(n / base_length, base, ret, i - 1);
|
||||
ret[i] = base[n % base_length];
|
||||
}
|
||||
|
||||
char *putnbr_in(int nbr, const char *base, char *ret, int ret_length)
|
||||
{
|
||||
int base_length = 10;
|
||||
int i = ret_length;
|
||||
|
||||
if (base_length < 2) {
|
||||
ret = "0";
|
||||
return (ret);
|
||||
}
|
||||
if (nbr < 0) {
|
||||
nbr *= -1;
|
||||
ret[0] = '-';
|
||||
} else {
|
||||
i--;
|
||||
ret[i] = '\0';
|
||||
}
|
||||
put_digit(nbr, base, ret, i);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int get_new_size(int n)
|
||||
{
|
||||
int base_size = 10;
|
||||
int i = 1;
|
||||
|
||||
while (n >= base_size) {
|
||||
n /= base_size;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *tostr(int n)
|
||||
{
|
||||
const char *base = "0123456789";
|
||||
int count = get_new_size(n);
|
||||
char *ret = malloc(sizeof(char) * (count + 1));
|
||||
|
||||
if (!ret)
|
||||
return (NULL);
|
||||
|
||||
putnbr_in(n, base, ret, count);
|
||||
ret[count] = '\0';
|
||||
return (ret);
|
||||
}
|
||||