Code Monkey home page Code Monkey logo

codam-42sh's People

Contributors

jbrinksma avatar marijnvanh avatar oscarmulder avatar robkuijper avatar thijsdejong avatar

codam-42sh's Issues

Future termcap reworks/addons

There are a few things the termcap functionality does not yet process correctly, since the required functionality is not in place yet.

  • input_parse_ctrl_d should incorporate builtin_exit, not a regular exit call.
  • input_parse_ctrl_up should implement command history functionality.
  • input_parse_ctrl_down should implement command history functionality.
  • clear terminal input when encountering ascii/character code 12 as input after status == 0 check int input_read (maybe)

term_reset returns FUNCT_ERROR but we catch FUNCT_FAILURE

term_reset (in the file term_reset_attributes ⚠️ is this wrong function name?) always evaluates to FUNCT_SUCCESS.

	ret = tcsetattr(STDIN_FILENO, TCSANOW, term_p->old_termios_p);
	if (ret == -1)
		return (FUNCT_SUCCESS);
	return (FUNCT_SUCCESS);

history fix

In principe werkt het maar hier is nog wat er gedaan moet worden:

De laatste pointer uit de history array moet current line worden. Om dat te kunnen doen moet **line, ***line worden. Dat is ook de rede dat ie nu segfault als je arrow up en dan arrow down doet. Volgens mij hoeft er verder niet heel veel gedaan te worden.

TO DO:

  • **line veranderen naar ***line.
  • gnl vervangen
  • Tests uncommenten / checken
  • Extra tests

Problems with env_getvalue

1. File isn't in the right directory.

2. It's just inconsistent in general and I've gotten a way better way of doing it now.

1 header file per shell element

At some point we probably have to split up our header file in multiple header files per shell element (parser.h, lexer.h, built-ins etc.)

Rework update_quote_status

int update_quote_status(char *line, int cur_index, char *quote)
{
char c;
c = line[cur_index];
if (is_char_escaped(line, cur_index) == 0)
{
if (*quote == '\0' && (c == '"' || c == '\''))
*quote = c;
else if (c == *quote)
*quote = '\0';
else
return (FUNCT_FAILURE);
}
else
return (FUNCT_FAILURE);
return (FUNCT_SUCCESS);

To avoid unnecessary function calling and checking too many things:

int	update_quote_status(char *line, int cur_index, char *quote)
{
	char	c;

	c = line[cur_index];
	if ((c == '"' || c == '\'') && is_char_escaped(line, cur_index) == false)
	{
		if (*quote == '\0')
			*quote = c;
		else
			*quote = '\0';
		return (FUNCT_SUCCESS);
	}
	return (FUNCT_FAILURE);
} 

42 checklist

Mandatory part

  • builtin type
  • builtin export
  • builtin set
  • builtin unset
  • builtin jobs, fg, bg, &
  • $ expansion
  • ${?} exit code of previous command

Modular part 6/6

  • Inhibitors ” (double quote), ’ (simple quote) and \
  • Complete management of the history:
    • Expansions:
      • !!
      • !word
      • !number
      • !-number
    • Saving to a file so that it can be used over several sessions
    • Built-in fc (all POSIX options)
    • Incremental search in the history with CTRL-R
  • Pattern matching (globing): *, ?, [], ! and the caracters intervals with \ (backslash)
  • Alias management via built-ins alias and unalias
  • Contextual dynamic completion of commands, built-ins, files, internal and environment variables. What is meant by contextual? re-we use the “ls /” command and your cursor is on the /, then a contextual completion will only propose the content of the root folder and not the commands or built-ins. Same for this case: “echo ${S”, the completion should only propose variable names that start with S, whether internal or environmental.
  • A hash table and built-in hash to interact with it (FIX PROPER HASH FUNC)

Bonus
Prerequisites

  • No ternary every 3 lines.
  • Explicit function names (no ft_parse1, ft_parse2, etc.)
  • This also applies to variable names
  • Use judiciously qualifer const
  • Have a git history and explicit commit messages
  • Have automated tests

Actual Bonus

  • Autocompletion for order/built-ins parameters

builtin_exit functionality not complete.

As the title says, the functionality of builtin_exit is not complete yet and should be revamped (although just a small bit).
It currently only prints a new line when called, but should in fact print "exit\n" (bash exit).

Input from STDIN without terminal is rejected

So if we do:
echo "echo bullshit'hoi" | bash
We get the output:
bash: line 1: unexpected EOF while looking for matching `'' bash: line 2: syntax error: unexpected end of file
So bash processes the command and finds an error, however the same command piped into vsh:
vsh: STDIN does not refer to a terminal

So we know there is no terminal, but what we should do is process the command anyway.
This will also help to make it possible for fc to reexecute the history commands.

History globals

There are some temporary globals and histsize is a fixed number (500)
When the environment is ready this needs to be replaced.

[21sh_fix_pipeline_execution] Resizing the terminal whilst a process is running causes severe errors and segfaults.

  • case 1: Resizing the terminal whilst running ls -laR / causes the output color to turn red (probably because of a shell being printed). If you then ctrl+c the process, it will not print a prompt, but it will accept input, which will stay in red. On around the third command being entered vsh will segfault.

  • case 2: Resizing the terminal whilst doing something with a long (or in this case infinite) waiting time like base64 /dev/urandom | rev, the shell will exit with a few errors: vsh: 0: bad file descriptor, exit, and vsh: could not reset terminal settings

Is our input_read supposed to also put the `\n` in commandline when read?

@rkuijper, kun jij even uitzoeken of het idd zo is dat bij je termcap functies je eigenlijk ook de `\n`'s of ansi escape of wat dan ook moet meenemen in de input? Op dit moment doe je dat namelijk niet En het lijkt me sterk dat we dat in alle functies moeten toevoegen zoals bij de DLESS en de multiple line commands

Do we explicitly set exit_code to EXIT_SUCCESS in builtins

Whenever a builtin is successful, do we have to set the *exit_code = EXIT_SUCCESS when we encounter no problems during execution, or do we only set exit_code whenever something is wrong.

The reason I ask is because exit_code is already set to EXIT_SUCCESS before any command is ran. I can see how we would want to always set it to EXIT_SUCCESS in the builtin function when it is successful though, just to have the code make more sense. Thoughts?

To fix in parser

  • Free ast_nodes recursively when you are in the middle of parsing
  • Fix norm
  • only 1 newline or multiple new lines
  • add tests (remove or use the parser_tests.c file)

ft_strsplit leaks on malloc fail

	res[j] = ft_strsub(s, 0, ft_word_length(s, c));
	if (res[j] == NULL)
		return (NULL);

Stuff like this, leaks the whole array and all strings in it.

param_to_env could be done without using malloc

char *param_to_env(char *parameter, char **vshenviron)
{
int env_index;
int i;
char *name;
char *value;
env_index = 0;
while (vshenviron[env_index] != NULL)
{
i = 0;
name = ft_strcdup(vshenviron[env_index], '=');
if (name == NULL)
return (NULL);
if (ft_strcmp(parameter, name) == 0)
{
while (vshenviron[env_index][i] != '=')
i++;
value = ft_strdup(&(vshenviron[env_index][i + 1]));
ft_strdel(&name);
return (value);
}
ft_strdel(&name);
env_index++;
}
return (NULL);
}

Things to fix with exit codes and builtins

  • Exit with 1 when malloc error occurs in builtins.
  • Exit with EXIT_FATAL when non numeric argument is given to exit
  • Exit with 2 when multiple arguments are given to exit

Alias to do

  • add escape characters in alias print
  • reloading aliasses from file

History TODO

  • Multiline to file (although bash fucks this up as well)
  • Make sure it's safe to always remove the last char from the line that gets passed into history (this should always be a '\n' but is it always?
    ..

:octocat:

Enum e_tokens should be named e_token

We have an enum called e_tokens which is always just 1 of the tokens (it's not used as a flag).
According to the internet: Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.

So, it would make more sense to call it e_token.
Would like your opinions on this.

PS. The reference I found was describing C#

To args++ or not to args++

Is looping trough a string etc. with str++ acceptable or is this something we want to avoid?

while (*str != '\0')
{
    str++;
}

Of alleen

while (str[i] !=  '\0')
{
    i++;
}

About: commenting functions.

What are the guidelines regarding commenting functionality?
Are comments unnecessary or are we going to stick to a certain format?
AKA:

/*
** @brief		Function description.
** @param 1		Parameter 1 description.
** @param 2		Parameter 2 description.
** @return		Return description.
*/

Hash table TO DO

  • init ht at shell start to all NULL
  • del hash table when PATH is changed in builtin-alias
  • add new hash when find binary is succesful in exec_find_binary
  • create builtin_hash
  • create hash functions

Replace GNL

My gnl is messed up so we need to add another one.

21sh checklist

Requirements

  • The ctrl+D et ctrl+C keys combination features for line edition and process execution.
  • The “;” command line separator
  • Pipes “|”
  • The 4 following redirections “<”, “>”, “<<” et “>>”
  • File descriptor aggregation, for example to close the standard error output:
$> ls
riri
$> rm riri; cat riri 2>&-

Here is a representative example of commands your 21sh must be able to execute
correctly:

$> mkdir testdir ; cd testdir ; ls -a ; ls | cat | wc -c > fifi ; cat fifi
. ..
5
$>
  • It executes ✅

  • A line edition feature using the termcaps library. Check the following description below:

Regarding the line edition, you must at least manage the following features. The
keys to be used are used as examples, you’re free to use other ones as long as your shell
remains logical and intuitive. The person evaluating you will decide what’s logical and
intuitive, so be careful not to get carried away with creativity.

  • Edit the line where the cursor is located.
  • Move the cursor left and right to be able to edit the line at a specific location. Obviously new characters have to be inserted between the existing ones similarly to a classic shell.
  • Use up and down arrows to navigate through the command history which we will then be able to edit if we feel like it (the line, not the history)
  • Cut, copy, and/or paste all or part of a line using the key sequence you prefer.
  • Move directly by word towards the left or the right using ctrl+LEFT and ctrl+RIGHT or any other reasonable combination of keys.
  • Go directly to the beginning or the end of a line by pressing home and end.
  • Write AND edit a command over a few lines. In that case, we would love that ctrl+UP and ctrl+DOWN allow to go from one line to another in the command while remaining in the same column or otherwise the most appropriate column.
  • Completely manage quotes and double quotes, even on several lines (expansions excluded).
  • Fix (d)quote ctrl+d interaction.

Allowed functions

  • Check check double check ✅
    ◦ malloc, free
    ◦ access
    ◦ open, close, read, write
    ◦ opendir, readdir, closedir
    ◦ getcwd, chdir
    ◦ stat, lstat, fstat
    ◦ fork, execve
    ◦ wait, waitpid, wait3, wait4
    ◦ signal, kill
    ◦ exit
    ◦ pipe
    ◦ dup, dup2
    ◦ isatty, ttyname, ttyslot
    ◦ ioctl
    ◦ getenv
    ◦ tcsetattr, tcgetattr
    ◦ tgetent
    ◦ tgetflag
    ◦ tgetnum
    ◦ tgetstr
    ◦ tgoto
    ◦ tputs

Resolve norm errors

There are currently 21 norm errors (norminette | grep -E "^Error" | wc -l)

To see them, execute the following command:
norminette | grep -E "^Error" -B 1 && norminette+ | grep -E "^Error" -B 1

Rewrite ft_strarradd

I quickly imported ft_strarradd from my shitty library, it's a bad function but it works. This is issue is to keep a note that it should be rewritten in a more efficient way.

Naming of Lexer states

I was looking at the lexer code, and I feel like the naming (state_1, state_2, state_3, ...) should be done better. Most states only do one thing, so...

void	state_2(t_scanner *scanner)
{
	if (CURRENT_CHAR == '|')
		change_state(scanner, &state_3);
	else
		scanner->tk_type = PIPE;
}

Should in my opinion be changed to:

void	state_pipe(t_scanner *scanner)
{
	if (CURRENT_CHAR == '|')
		change_state(scanner, &state_or_if);
	else
		scanner->tk_type = PIPE;
}

Or something similar.
Would like your opinions on this.
:octocat:

is_char_escaped

if (index < 0 || index > (int)ft_strlen(line))
return (FUNCT_FAILURE);
if (line[index] == '\\')
{
total_escape_chars = 0;
while (line[index] == '\\' && index >= 0)
{
total_escape_chars++;
index--;
}
if (total_escape_chars % 2 == 1)
return (FUNCT_SUCCESS);
else
return (FUNCT_FAILURE);

Calling ft_strlen(line) each call of is_char_escaped to check if index is not out of line seems very inefficient. Can we not make sure that line[index] is never out of bounds when we call is_char_escaped?

And:

		if (total_escape_chars % 2 == 1)
			return (FUNCT_SUCCESS);
		else
			return (FUNCT_FAILURE);

Could be:

return (total_escape_chars % 2 == 1)
or:
return (total_escape_chars % 2 == 1 ? FUNCT_SUCCESS : FUNCT_FAILURE)

Probably we don't want the last one.

21sh things that we fixed

  • achieve consistency with the FUNCT_FAILURE and FUNCT_ERROR, when do we use what? Also, make sure that you only check to terminate something when you have FUNCT_ERROR, so if ... == FUNCT_ERROR, -> return (FUNCT_ERROR) and not if .. != FUNCT_SUCCESS, -> return (FUNCT_ERROR) since FUNCT_FAILURE shouldn't be a bad thing.
  • find out behaviour of directory shell prompt with symlinks
  • Full check of all code to see if any premature returns would cause leaks
  • BUG: cursor doesnt go to the end of a line when you press enter on a command, which makes it so that it could stay within your typed input when displaying a result
  • In terminal we now automatically copy the helping newlines
  • Rename redir_tools2.c to something that makes more sense
  • Check if valid terminal at start of shell
  • cd ../.../ infinite loop
  • Add CD support for inifinite symlink loop
  • add funny error message in cd when newpath cant get alloced
  • sanity check list for probes (Make sure probe is actually used instead of node or somehting else)
  • malloc print in cd_path functions
  • MAKE SURE WE USE THE PROPER SPACE (NOT FT_ISSPACE), because only \t and are valid whitespace in shell
  • tmp env bug when tmp env var already exists: "PATH=iets echo hoi " After exec PATH is gone.
  • reset term caps on exit / ctrl D ?
  • Fix error returns in PIPE functions so that they actually do something xD
  • temp vars are not send to new program, example cmdline: fuck=you env
  • create files when handling redirections before using them
  • In check_dir: when readdir returns a directory and equals filename it is set to binary but it should be skipped because it's not a file
  • shell_init_vshdata doesn't check what kind of error (E.G. Permission error)
  • shell_init_vshdata returned altijd malloc error bij welke error dan ook
  • Local vars containing shell specials are exported as external vars in env_lsttoarr
  • Tilde expansion
  • Alias error management
  • We need a check if '\' is at the end of the line and then ask for more input
  • input '"' goes wrong in lexer or parser
  • history is fucked after 500 commands + leaks
  • Remove newline from alias quote slash expansion
  • executor doesn't save the binary path separately, but instead replaces the args[0]
  • In commandline: '\'' should ask for input but it segfaults
  • make sure that input functions len_max is accurately compared everywhere
  • input '<<<' or more '<' needs to be fixed
  • alias leaks the string that was replaced
  • identifiers can only consist of alphanum and '_'. (fixed in builtin_export branch)
  • newline should not be added in the history
  • single quotes are not allowed to be escaped in single quote
  • Cat doesnt work in VSH, no input is shown on screen
  • Sort environment variables
  • Add support for CTRL+D [End of Input] when inside function like cat
  • Get rid of <has_dollar> flag in lexer
  • set and export print functions: if value contains a single quote it needs to be escaped. Same for export but for all shell special chars.
  • whitespace flag for set needs to be changed to special_char_flag. if value contains any special char it is printed with single quotes.
  • Remove codecoverage in regular vsh make
  • KNOWN BUG: may print extra newlines in the terminal when resizing which causes the content to move upwards
  • BUG: tcsetattr return has wrong error message get instead of set
  • Should we handle exit codes for non-wait pipe-sequence executables?

VSCODE-ONLY ERRORS:

  • input -> on multilines due to small terminal, pressing left arrow never returns you to the line above
  • replace errors with defines

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.