mirror of
https://github.com/zoriya/ash.git
synced 2026-05-30 09:38:51 +00:00
@@ -39,6 +39,7 @@ SRC = src/shell.c \
|
||||
src/utility/fusion.c \
|
||||
src/utility/split_commands.c \
|
||||
src/utility/get_return.c \
|
||||
src/utility/eof.c \
|
||||
src/key_bindings/basic_typing_functions.c \
|
||||
src/key_bindings/default_bindings.c \
|
||||
src/key_bindings/control_commands.c \
|
||||
|
||||
+5
-1
@@ -8,11 +8,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "shell.h"
|
||||
|
||||
char *catpath(char *p1, char *p2);
|
||||
char **to_array(char *str);
|
||||
char *tostr(int n);
|
||||
bool is_alpha(char c);
|
||||
bool is_num(char c);
|
||||
bool envvar_is_valid(const char *str);
|
||||
int count_str(char *str, char *delim);
|
||||
char **split_str(char *str, char delim);
|
||||
@@ -23,4 +25,6 @@ char **split_commands(char *cmd);
|
||||
int *get_return_separator(char *cmd);
|
||||
int split_is_invalid(char **cmds, int *return_values, int i);
|
||||
int count_char(const char *str, char c);
|
||||
int ncount_char(const char *str, int end, char c);
|
||||
int ncount_char(const char *str, int end, char c);
|
||||
int get_max_eof(char *ignoreeof);
|
||||
int skip_eof(buffer_t *buffer, env_t *env);
|
||||
@@ -73,7 +73,7 @@ char **my_unsetenv(char **env, char *name)
|
||||
{
|
||||
int max = env_get_length(env);
|
||||
|
||||
for (int i = 0; env[i]; i++) {
|
||||
for (int i = 0; env && env[i]; i++) {
|
||||
if (same_var(env[i], name) == env[i]) {
|
||||
free(env[i]);
|
||||
env[i] = env[max - 1];
|
||||
|
||||
@@ -60,6 +60,7 @@ int newline_command(int key, buffer_t *buffer, env_t *env)
|
||||
{
|
||||
int ret;
|
||||
|
||||
env->vars = my_unsetenv(env->vars, "eof");
|
||||
if (env->window)
|
||||
my_addstr(env->window, "\n");
|
||||
if (buffer->buffer) {
|
||||
|
||||
@@ -5,14 +5,33 @@
|
||||
** control_commands
|
||||
*/
|
||||
|
||||
#include "shell.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include "shell.h"
|
||||
#include "utility.h"
|
||||
|
||||
int eof_command(int key, buffer_t *buffer, env_t *env)
|
||||
{
|
||||
return (-1);
|
||||
char *ignoreeof = my_getenv(env->vars, "ignoreeof");
|
||||
char *eof = my_getenv(env->vars, "eof");
|
||||
char new[20];
|
||||
unsigned count = eof ? strtol(eof, NULL, 10) : 1;
|
||||
unsigned max = 26;
|
||||
|
||||
if (env->window && buffer->buffer && *buffer->buffer)
|
||||
return (skip_eof(buffer, env));
|
||||
if (!ignoreeof || !env->window)
|
||||
return (-1);
|
||||
max = get_max_eof(ignoreeof);
|
||||
sprintf(new, "%u", ++count);
|
||||
env->vars = my_setenv(env->vars, "eof", new);
|
||||
if (count >= max)
|
||||
return (-1);
|
||||
my_addstr(env->window, "\nUse \"exit\" to leave " SHELL_NAME ".\n");
|
||||
clearerr(stdin);
|
||||
prompt_prepare(buffer, env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
bool set_buffer_to_history(buffer_t *buffer, env_t *env)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** ash
|
||||
** File description:
|
||||
** eof
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "shell.h"
|
||||
#include "utility.h"
|
||||
|
||||
int get_max_eof(char *ignoreeof)
|
||||
{
|
||||
bool correct = true;
|
||||
|
||||
for (int i = 0; ignoreeof[i] && correct; i++)
|
||||
if(!is_num(ignoreeof[i]))
|
||||
correct = false;
|
||||
if (correct && strcmp(ignoreeof, "0") && strcmp(ignoreeof, ""))
|
||||
return(strtol(ignoreeof, NULL, 10));
|
||||
return (26);
|
||||
}
|
||||
|
||||
int skip_eof(buffer_t *buffer, env_t *env)
|
||||
{
|
||||
my_addstr(env->window, "\n");
|
||||
prompt_prepare(buffer, env);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user