mirror of
https://github.com/zoriya/ash.git
synced 2026-05-31 18:03:54 +00:00
norm compliance made
This commit is contained in:
@@ -40,6 +40,7 @@ SRC = src/shell.c \
|
||||
src/utility/get_return.c \
|
||||
src/parser/parser.c \
|
||||
src/parser/quotes.c \
|
||||
src/parser/parser_utilities.c \
|
||||
src/key_bindings/basic_typing_functions.c \
|
||||
src/key_bindings/default_bindings.c \
|
||||
src/key_bindings/control_commands.c \
|
||||
|
||||
+6
-1
@@ -8,6 +8,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "shell.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct parser_map {
|
||||
char key;
|
||||
@@ -15,4 +17,7 @@ typedef struct parser_map {
|
||||
} parser_map;
|
||||
|
||||
char **parse_input(char *cmd);
|
||||
int parse_quotes(char *ptr, char **data);
|
||||
int parse_quotes(char *ptr, char **data);
|
||||
|
||||
char *strcat_realloc(char *dest, char *src);
|
||||
char *add_to_buffer(char *buffer, char *ptr, int nb);
|
||||
+1
-34
@@ -9,36 +9,18 @@
|
||||
#include "shell.h"
|
||||
#include "redirections.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include "utility.h"
|
||||
#include "parser.h"
|
||||
#include "builtin.h"
|
||||
#include <malloc.h>
|
||||
|
||||
const parser_map parsers[] = {
|
||||
{'\'', &parse_quotes},
|
||||
{'\0', NULL}
|
||||
};
|
||||
|
||||
char *strcat_realloc(char *dest, char *src)
|
||||
{
|
||||
if (dest) {
|
||||
dest = realloc(dest, sizeof(char) * (strlen(dest) + strlen(src) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
} else {
|
||||
dest = malloc(sizeof(char) * (strlen(src) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
dest[0] = '\0';
|
||||
}
|
||||
strcat(dest, src);
|
||||
return (dest);
|
||||
}
|
||||
|
||||
bool is_character_valid(char c)
|
||||
{
|
||||
static bool is_valid = false;
|
||||
@@ -55,21 +37,6 @@ bool is_character_valid(char c)
|
||||
return (false);
|
||||
}
|
||||
|
||||
char *add_to_buffer(char *buffer, char *ptr, int nb)
|
||||
{
|
||||
char *new;
|
||||
|
||||
if (nb <= 0)
|
||||
return (buffer);
|
||||
new = strndup(ptr, nb + 1);
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new[nb] = '\0';
|
||||
buffer = strcat_realloc(buffer, new);
|
||||
free(new);
|
||||
return (buffer);
|
||||
}
|
||||
|
||||
int call_parsers(char *cmd, int index, char **data)
|
||||
{
|
||||
int new_index = 0;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** PSU_minishell2_2019
|
||||
** File description:
|
||||
** parser_utilities
|
||||
*/
|
||||
|
||||
#include <malloc.h>
|
||||
#include "parser.h"
|
||||
|
||||
char *strcat_realloc(char *dest, char *src)
|
||||
{
|
||||
if (dest) {
|
||||
dest = realloc(dest, sizeof(char) * (strlen(dest) + strlen(src) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
} else {
|
||||
dest = malloc(sizeof(char) * (strlen(src) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
dest[0] = '\0';
|
||||
}
|
||||
strcat(dest, src);
|
||||
return (dest);
|
||||
}
|
||||
|
||||
char *add_to_buffer(char *buffer, char *ptr, int nb)
|
||||
{
|
||||
char *new;
|
||||
|
||||
if (nb <= 0)
|
||||
return (buffer);
|
||||
new = strndup(ptr, nb + 1);
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new[nb] = '\0';
|
||||
buffer = strcat_realloc(buffer, new);
|
||||
free(new);
|
||||
return (buffer);
|
||||
}
|
||||
Reference in New Issue
Block a user