Starting up

This commit is contained in:
Tristan Roux
2019-12-05 19:53:11 +01:00
parent 8aaeea8ee4
commit 76b81478e5
61 changed files with 1826 additions and 59 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.o
*.gc*
xmlparser.a

42
Makefile Normal file
View File

@@ -0,0 +1,42 @@
##
## EPITECH PROJECT, 2019
## xmlparser
## File description:
## Makefile
##
SRC = src/xmlparser.c \
src/parsenode.c \
src/list_utility.c
OBJ = $(SRC:%.c=%.o)
INCLUDE = -I ./include
CFLAGS = $(INCLUDE) -Wall -Wextra -Wshadow
LDFLAGS =
CC = gcc
AR = ar rc
NAME = xmlparser.a
all: build
build: $(OBJ)
$(AR) $(NAME) $(NAME)
clean:
$(RM) $(OBJ)
fclean: clean
$(RM) $(NAME)
re: fclean all
dbg: CFLAGS += -g
dbg: re
.PHONY: all build clean fclean

121
include/my.h Normal file
View File

@@ -0,0 +1,121 @@
/*
** EPITECH PROJECT, 2019
** My lib
** File description:
** Header file
*/
#pragma once
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_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(const char *str);
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_strchr(char *str, char c);
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 *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);

View File

@@ -5,17 +5,27 @@
** xml ** xml
*/ */
typedef struct node node;
typedef struct dictionary dictionary;
#pragma once #pragma once
typedef struct dictionary struct dictionary
{ {
char *property; char *key;
char *value; char *value;
} dictionary;
typedef struct node dictionary *next;
};
struct node
{ {
char *name; char *name;
dictionary *properties; dictionary *properties;
node *child; node *child;
} node;
node *next;
};
dictionary *property_add(dictionary *list, dictionary *property);
node *xml_parsenode(char **nodestr);

View File

@@ -1,16 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** xmlstate
*/
#pragma once
#include "xml.h"
typedef struct xmlstate
{
node valid;
node *current;
} xmlstate;

33
lib/my/Makefile Normal file
View File

@@ -0,0 +1,33 @@
##
## EPITECH PROJECT, 2019
## Makefile
## File description:
## Lib makefile
##
SRC = *.c
OBJ = *.o \
*.gc*
LIBOBJ = lib/my/*.o \
lib/my/libmy.a \
include/my.h
all: buildlib
buildlib:
cp ./my.h ../../include/my.h
gcc -c ./*.c
ar rc ./libmy.a ./*.o
ar rc ../libmy.a ./*.o
clean:
rm -f $(OBJ)
fclean:
rm -f $(LIBOBJ)
rm -f libmy.a
rm -f ../libmy.a
re: fclean all

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

@@ -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);
}

15
lib/my/index_of.c Normal file
View File

@@ -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);
}

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

@@ -0,0 +1,119 @@
/*
** EPITECH PROJECT, 2019
** My lib
** File description:
** Header file
*/
#pragma once
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_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(const char *str);
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(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);

View File

@@ -0,0 +1,29 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day05_2019
** File description:
** Power calculator
*/
int my_compute_power_it(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);
}

View File

@@ -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;
}

View File

@@ -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));
}

View File

@@ -0,0 +1,29 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day05_2019
** File description:
** Power calculator
*/
int my_compute_power_it(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);
}

View File

@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day05_2019
** File description:
** Power calculator but in recursive mode
*/
static int calculate(int nb, int p, int ret)
{
if (ret < 0)
return 0;
if (p == 0)
return ret;
return calculate(nb, p - 1, ret * nb);
}
int my_compute_power_rec(int nb, int p)
{
int mult = 1;
if (p < 0)
return (0);
if (nb < 0) {
nb *= -1;
if (p % 2 == 1)
mult = -1;
}
return (calculate(nb, p, 1) * mult);
}

View File

@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day05_2019
** File description:
** Square root calculator
*/
int my_compute_square_root(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;
}

28
lib/my/my_evil_str.c Normal file
View File

@@ -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;
}

View File

@@ -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;
}

69
lib/my/my_getnbr.c Normal file
View File

@@ -0,0 +1,69 @@
/*
** 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; 1; 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;
}
return init_print(str, count, start_index);
}

75
lib/my/my_getnbr_base.c Normal file
View File

@@ -0,0 +1,75 @@
/*
** EPITECH PROJECT, 2019
** Get number with any base
** File description:
** Int library
*/
int my_strlen(const char *str);
int my_compute_power_it(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_compute_power_it(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));
}

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

@@ -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);
}

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

@@ -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);
}

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

@@ -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);
}

46
lib/my/my_print_comb.c Normal file
View File

@@ -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;
}
}

36
lib/my/my_print_comb2.c Normal file
View File

@@ -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);
}

62
lib/my/my_print_combn.c Normal file
View File

@@ -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);
}

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

@@ -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);
}

View File

@@ -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);
}

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

@@ -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);
}

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

@@ -0,0 +1,13 @@
/*
** EPITECH PROJECT, 2019
** Putchar
** File description:
** Yes
*/
#include <unistd.h>
void my_putchar(char c)
{
write(1, &c, 1);
}

38
lib/my/my_putlong_base.c Normal file
View File

@@ -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);
}

38
lib/my/my_putnbr_base.c Normal file
View File

@@ -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);
}

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

@@ -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);
}
}

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

@@ -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);
}

View File

@@ -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);
}

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

@@ -0,0 +1,30 @@
/*
** 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);
static void puthex(char c)
{
char zero = '0';
if (c < 16)
write(1, &zero, 1);
my_putnbr_base(c, "0123456789ABCDEF");
}
int my_showstr(const char *str)
{
for (int i = 0; str[i] != '\0'; i++) {
if (is_printable(str[i]))
write(1, &str[i], 1);
else
puthex(str[i]);
}
}

View File

@@ -0,0 +1,23 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day04_2019
** File description:
** Int array sorter
*/
static int 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);
}

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

@@ -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);
}

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

@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2019
** Str is alpha
** File description:
** Duplicate of the string.h (I think)
*/
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);
}

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

@@ -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);
}

View File

@@ -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);
}

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

@@ -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);
}

View File

@@ -0,0 +1,71 @@
/*
** 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;
int word_length = 0;
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);
}

32
lib/my/my_strcapitalize.c Normal file
View File

@@ -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);
}

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

@@ -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);
}

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

@@ -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);
}

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

@@ -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];
}

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

@@ -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);
}

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

@@ -0,0 +1,21 @@
/*
** 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));
for (int i = 0; i < length; i++)
ret[i] = src[i];
ret[length] = '\0';
return (ret);
}

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

@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2019
** CPool_Day04_2019
** File description:
** Strlen
*/
int my_strlen(const char *str)
{
if (str == 0)
return (0);
for (int i = 0; 1; i++) {
if (*(str + i) == '\0')
return i;
}
}

15
lib/my/my_strlowcase.c Normal file
View File

@@ -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);
}

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

@@ -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);
}

25
lib/my/my_strncmp.c Normal file
View File

@@ -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];
}

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

@@ -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);
}

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

@@ -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;
}

15
lib/my/my_strupcase.c Normal file
View File

@@ -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);
}

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

@@ -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;
}

View File

@@ -1,13 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** parseline
*/
#include "xmlstate.h"
void xml_parseline(xmlstate state, char *line)
{
if (line)
}

24
src/list_utility.c Normal file
View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2019
** xmlparser
** File description:
** list_utility
*/
#include "xml.h"
#include <stddef.h>
dictionary *property_add(dictionary *list, dictionary *property)
{
dictionary *listconst = list;
if (!list)
return (property);
else {
while (list->next)
list = list->next;
list->next = property;
property->next = NULL;
}
return (listconst);
}

117
src/parsenode.c Normal file
View File

@@ -0,0 +1,117 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** parseline
*/
#include "xml.h"
#include "my.h"
#include <stdlib.h>
#include <stdbool.h>
char *xml_getname(char **nodestr, bool *has_parameters)
{
char *p = my_strchr(*nodestr, ' ');
char *name;
if ((*nodestr)[0] != '<')
return (NULL);
if (p) {
*has_parameters = true;
} else {
*has_parameters = false;
p = my_strchr(*nodestr, '>');
if (!p)
return (NULL);
}
*p = '\0';
name = my_strdup(*nodestr);
*nodestr = p + 1;
return (name);
}
dictionary *xml_getproperty(char **nodestr)
{
dictionary *property = malloc(sizeof(dictionary));
char *p;
if (!property)
return (NULL);
p = my_strchr(*nodestr, '=');
if (!p)
return (NULL);
*p = '\0';
property->key = my_strdup(*nodestr);
*nodestr = p + 1;
if ((*nodestr)[0] != '"')
return (NULL);
*nodestr += 1;
p = my_strchr(*nodestr, '"');
if (!p)
return (NULL);
*p = '\0';
property->value = my_strdup(*nodestr);
*nodestr = p + 1;
return (property);
}
dictionary *xml_getproperties(char **nodestr, bool *can_have_child)
{
dictionary *properties = NULL;
dictionary *property = NULL;
while ((*nodestr)[0] != '>') {
property = xml_getproperty(nodestr);
if (!property)
return (NULL);
properties = property_add(properties, property);
if ((*nodestr)[0] == ' ')
*nodestr += 1;
if ((*nodestr)[0] == '/') {
*nodestr += 1;
*can_have_child = true;
}
else
*can_have_child = false;
}
return (properties);
}
int xml_checkclosing(node *n, char **nodestr)
{
if ((*nodestr)[0] != '<' || (*nodestr)[1] != '/')
return (-1);
if (my_strstr(*nodestr, n->name) != *nodestr + 2)
return (-1);
*nodestr += 2 + my_strlen(n->name);
if ((*nodestr)[0] != '>')
return (-1);
*nodestr += 1;
return (0);
}
node *xml_parsenode(char **nodestr)
{
node *n = malloc(sizeof(node));
bool has_next_value;
if (!n)
return (NULL);
n->name = xml_getname(nodestr, &has_next_value);
if (has_next_value) {
if (!(n->properties = xml_getproperties(nodestr, &has_next_value)))
return (NULL);
}
else
n->properties = NULL;
if (has_next_value) {
if (!(n->child = xml_parsenode(nodestr)))
return (NULL);
} else
n->child = NULL;
if (!n->name || xml_checkclosing(n, nodestr) < 0)
return (NULL);
n->next = xml_parsenode(nodestr);
return (n);
}

37
src/xmlparser.c Normal file
View File

@@ -0,0 +1,37 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** xmlparser
*/
#include "xml.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
node *xmlparse(char *path)
{
node *n = NULL;
int fd = open(path, O_RDONLY);
struct stat stats;
char *nodestr;
char *strconst;
int count;
if (fd < 0)
return (NULL);
fstat(fd, &stats);
nodestr = malloc(stats.st_size);
if (nodestr) {
count = read(fd, nodestr, stats.st_size);
if (count == stats.st_size) {
strconst = nodestr;
n = xml_parsenode(&nodestr);
}
free(strconst);
}
close(fd);
return (n);
}

View File

@@ -1,25 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** xmlparser
*/
#include "xml.h"
#include "xmlstate.h"
#include <stdio.h>
node *xmlparse(char *path)
{
FILE *file = fopen(path, "r");
char *line = NULL;
xmlstate state;
if (!file)
return (NULL);
while ((line = getline(line, 0, file))) {
xml_parseline(state, line);
}
fclose(file);
return (state.valid);
}