Skip to content

Commit

Permalink
Merge pull request #10 from SizzleUnrlsd/Hotfix/null_command
Browse files Browse the repository at this point in the history
Hotfix/null command
  • Loading branch information
SizzleUnrlsd committed Sep 26, 2023
2 parents e806f7a + bff82ad commit 3b882db
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 13 deletions.
7 changes: 6 additions & 1 deletion flag_makefile/cflags.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
-W -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wduplicated-cond -Wswitch-enum -Wfloat-equal -Wtautological-compare -Wcast-qual -Wdeclaration-after-statement -Walloc-zero -Warray-bounds -Wstrict-overflow -Wformat-security -Wuninitialized -Winit-self -Wno-frame-address -Wno-unknown-pragmas -pedantic -g3 -Os -I./include/
-W -Wall -Wextra -Werror -Wshadow -Wpointer-arith
-Wduplicated-cond -Wswitch-enum -Wfloat-equal
-Wtautological-compare -Wcast-qual -Wdeclaration-after-statement
-Wrestrict -Walloc-zero -Warray-bounds -Wstrict-overflow -Wformat-security
-Wuninitialized -Winit-self -Wno-frame-address -Wno-unknown-pragmas
-pedantic -g3 -Os -I./include/
1 change: 1 addition & 0 deletions include/basic_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@

/* PROMPT_TOOLS_ */

__attribute__((warn_unused_result)) int check_shell_line(char *line);
void del_space_end_str(char *command);
void delete_semicolon_end(char *command);
void remove_backslash_n(char *command);
Expand Down
4 changes: 4 additions & 0 deletions include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
_THREAD_ALLOCA_ERROR = 8,
_PIPE_ERROR = 9,
_OVERLAPPING_ERROR = 10,
_OPEN_ERROR = 11,
};

#endif
Expand Down Expand Up @@ -222,6 +223,9 @@
case _OVERLAPPING_ERROR: \
_str = "Overlapping Error"; \
break; \
case _OPEN_ERROR: \
_str = "Open error"; \
break; \
default: \
_str = "Unknown Error"; \
break; \
Expand Down
4 changes: 2 additions & 2 deletions src/builtin/alias/modify_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ parse_aliases(call_alias_t *call_alias, char *cmd, char *cmp, char *new)
char *
format_alias_getline(shell_t *shell, char *cmd)
{
uint32_t cpt = 0;
char *new_line = NULL;
uint32_t cpt = DEFAULT(cpt);
char *new_line = DEFAULT(new_line);
char **arr_line = _str_to_word_array_custom(cmd, ' ');

set_alias(shell->call_alias);
Expand Down
30 changes: 30 additions & 0 deletions src/parse_arg/check_shell_line.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2023 hugo
*
* This file is part of TekSH.
*
* TekSH is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TekSH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TekSH. If not, see <http://www.gnu.org/licenses/>.
*/

#include "shell.h"

__attribute__((warn_unused_result))
inline int check_shell_line(char *line)
{
if (!line || line == 0) {
return 1;
}

return 0;
}
2 changes: 0 additions & 2 deletions src/parse_arg/parse_arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,5 @@ parse_arg(int32_t ac, char **av)
}
}



return;
}
35 changes: 35 additions & 0 deletions src/prompt_function/prompt_engine/char_stream_formatting.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ set_error_message(shell_t *shell, char first_char, char special_char, char *cont
{
uint32_t len_context = _strlen(context);

if (len_context == 0)
return 1;

if (special_char == '|' || first_char == '|') {
EXIT_W_ECHO_ERROR_("Invalid null command.", 1);
}
Expand Down Expand Up @@ -93,6 +96,37 @@ formatting_brackets(char *command)

}

//tmp
void
del_into_line(char **command)
{
char *line = DEFAULT(line);
uint32_t len = _strlen((*command));
uint32_t another_count = DEFAULT(another_count);

line = (char*)_mallocbucket(sizeof(char) * (len + 1));

for (uint32_t i = 0; (*command)[i]; ++i) {
if ((*command)[i + 1] != '\0' && (*command)[i] == ' ' && (*command)[i + 1] == ' ') {
(*command)[i] = '_';
continue;
}
if ((*command)[i + 1] != '\0' && (*command)[i] == '\t' && ((*command)[i + 1] == '\t' || (*command)[i + 1] == ' ')) {
(*command)[i] = '_';
continue;
}
line[another_count] = (*command)[i];
another_count++;
}
line[another_count] = '\0';

_free((*command));

(*command) = line;

return;
}

bool
char_stream_formatting(shell_t *shell, char **command)
{
Expand All @@ -101,6 +135,7 @@ char_stream_formatting(shell_t *shell, char **command)

remove_backslash_n(*command);
delete_spaces_tabulations(*command);
del_into_line(command);
replace_multiple_spaces_tabulations(*command);
del_space_end_str(*command);
(*command) = formatting_brackets(*command);
Expand Down
19 changes: 13 additions & 6 deletions src/prompt_function/prompt_engine/prompt_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ prompt_shell(shell_t *shell)
ssize_t read = DEFAULT(read);

static int32_t screen_height = DEFAULT(screen_height), screen_width = DEFAULT(screen_width);
rl_get_screen_size(&screen_height, &screen_width);
rl_set_screen_size(1000, screen_height);

tcgetattr(STDIN_FILENO, &old_termios);
new_termios = old_termios;
new_termios.c_lflag &= ~ECHOCTL;
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
if (shell->print && (screen_height == 0 || screen_width == 0)) {
rl_get_screen_size(&screen_height, &screen_width);
rl_set_screen_size(1000, screen_height);

tcgetattr(STDIN_FILENO, &old_termios);
new_termios = old_termios;
new_termios.c_lflag &= ~ECHOCTL;
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
}


_tty = shell->print;
_gshell = shell;
Expand Down Expand Up @@ -167,6 +171,9 @@ prompt_shell(shell_t *shell)
if (getline(&line, &len, stdin) == -1) {
exit(shell->status);
}
if (strcmp(line, "\n") == 0)
exit(shell->status);
garbage_backup_ptr((void*)line);
}
/* In the tty */
if (_tty) {
Expand Down
6 changes: 5 additions & 1 deletion src/prompt_function/prompt_error/set_error_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ saving_error_file(shell_t *shell)
{
const char *restrict path = "mini_dump/error_promt_cmd";
const char *restrict mode = "a";
FILE* file = fopen(path, mode);
char log[256] = {0};
FILE* file = fopen(path, mode);
if (!file) {
_p_error(_OPEN_ERROR);
exit(_OPEN_ERROR);
}

sprintf(log, "%s/%s", shell->line, ARCH);
fprintf(file, "%s\n", log);
Expand Down
3 changes: 3 additions & 0 deletions src/prompt_function/prompt_tools/del_spce_tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ delete_spaces_tabulations(char *command)
int32_t i = DEFAULT(i), j = DEFAULT(j);
int32_t len = _strlen(command);

if (check_shell_line(command))
return;

for (i = 0; i < len && (command[i] == ' ' || command[i] == '\t'); i++);

if (i > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/prompt_function/prompt_tools/remove_backslash_n.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ remove_backslash_n(char *command)
{
uint32_t len_command = _strlen(command);

if (check_shell_line(command))
return;

if (len_command == 0)
return;
if (command[len_command - 1] == '\n') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ replace_multiple_spaces_tabulations(char *command)
int32_t i = DEFAULT(i), j = DEFAULT(j);
int32_t len = _strlen(command);

if (len == 0)
return;

for (i = 0, j = 0; i < len; i++) {
if ((command[i] == ' ' || command[i] == '\t')
&& (i == 0 || command[i - 1] == ' ' || command[i - 1] == '\t'))
Expand Down
2 changes: 1 addition & 1 deletion src/sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ shell_conf_t globalConfig;

void shell_engine(shell_t *shell, char **env)
{
char *new_line = DEFAULT(new_line);
char *restrict new_line = DEFAULT(new_line);
call_alias_t *call_alias = DEFAULT(call_alias);
shell_requirement(shell, env, &call_alias);

Expand Down

0 comments on commit 3b882db

Please sign in to comment.