Code Monkey home page Code Monkey logo

minishell's Introduction

Minishell

The objective of this project is for you to create a simple shell.

Resources

Tester

Bashversion

42 = bash3.2 Docker Container = bash5.1

make && valgrind --gen-suppressions=all --suppressions=readline.supp -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./minishell

minishell's People

Contributors

reptudn avatar noelsabia avatar

Stargazers

 avatar

Watchers

 avatar

minishell's Issues

command into structs

  • from the line get all the commands and the args for that command
  • link next / prev command
  • if there is an operator put it in the operator field in the sctruct

(no input validation -> when it get to the code which puts it into the structs the input is already valid. Doesnt mean the command exists tho)

  • ich wuerde mir erst den segfault anschauen und probieren zu fixxen (segfault kommt von commands/command_handler erste if condition im while loop, hab ich also erstmal ausgecommented) ✅
  • dann checken ob das erste struct richtig befuellt wird (ja wird es mehr oder minder, wenn wir das Issue mit echo fixxen!!)✅
  • dann die weiteren structs befuellen ❌

ValgrindKatrin

ValgrindKatrin`s work is to valgrind the shit out of minishell.

Reorganize Makefile

Put the object files in separate folders so as not to lose the overall overview

quotes in quotes, remove parens, ...

  • when a quote is in a quote then dont remove those inside
  • when encountering open or close parens just remove them when splitting (only if they are not in quotes ofc)
  • figure out how to correctly handle heredoc because as an example echo << EOF should just print a nl and cat << EOF the content of the heredoc. right now both just print the heredoc output because its saved inside an echo cmd
  • other stuff that were issues before...

Command handler

Handles Commands and Operators like:
echo, ls, cd etc. pp.

Big Problemo with echo

Every command is doing what it is supposed to do except echo.
Problem:
In utils/make_cmds -> allocate cmd everything is read correctly in the 2D Array of char **args but if you try to read the same piece of memory in the function make_cmds the first word(s) are complete bs.

Example1 (works):
minishell ➜ echo "hello there"

allocate_cmds[0]: "hello
allocate_cmds[1]: there"

make_cmds[0]: "hello
make_cmds[1]: there"

OUTPUT: "hello there"

Example2(does not work):
minishell ➜ echo "hello there how are you doing"

allocate_cmds[0]: "hello
allocate_cmds[1]: there
allocate_cmds[2]: how
allocate_cmds[3]: are
allocate_cmds[4]: you
allocate_cmds[5]: doing"

make_cmds[0]: P��įU
make_cmds[1]: there
make_cmds[2]: how
make_cmds[3]: are
make_cmds[4]: you
make_cmds[5]: doing"

OUTPUT: P��įU there how are you doing"

Command_Handler

int in_fd;

in_fd = run_pipe_cmd(cmd1, cmd2, shell, -1); // First command, no input pipe
in_fd = run_pipe_cmd(cmd2, cmd3, shell, in_fd); // Second command, input from first command
run_pipe_cmd(cmd3, NULL, shell, in_fd); // Third command, input from second command

variable parsing

What?

  • detect variables
  • valid input (VARNAME=CONTENT) -> doesnt matter how many = signs there are as long as there is one all the following count towards the COTENT
  • if variable is already in the variable list then just replace the value
  • strdup the value into the struct
  • free all the split or whatever

Structs

typedef struct s_variable
{
	char				*name;
	char				*value;
	struct s_variable	*next;
	struct s_variable	*prev;
}			t_variable;

typedef struct s_shell
{
	bool		run;
	char		*path;
	char		**env;
	char		**envp;
	t_variable	*variables;
}			t_shell;

typedef struct s_command
{
	char				*command;
	char				**args;
	int					*operator_type;
	int					priority;
	struct s_command	*next;
	struct s_command	*prev;
	t_shell				*shell;
}			t_command;

!!!EVERYTHING THAT IS MALLOCED IS REFERENCED IN A STRUCT!!!

shunting yard

apply the shunting yard algo on the shunting yard strucut array

input validation

  • check if input is valid (cmd args operator cmd args ...) -> no operator in the end or beginnging
  • display quote> prompt to let the user finish their input when they forgot a quote and then append it to the line so that split can split it right after

Redirect_outs

Do redirect out.
Take the output from a command copy that in a struct and give that struct into the redirects

command loop

loop which displays the promt with and runs all the time and displays promt again when pressing enter

build ast

instead of using our command structs we build an AST with tokens and priorities

Priorities from high to low

  1. Parentheses ()
  2. Unary operators (e.g., -, !)
  3. Multiplicative operators (*, /, %)
  4. Additive operators (+, -)
  5. Comparison operators (<, <=, >, >=)
  6. Equality operators (==, !=)
  7. Logical AND (&&)
  8. Logical OR (||)
  9. Assignment operators (=, +=, -=)

PutzfrauSimone

Cleaning up the shit we did wrong. Rewriting code to make it compatible with our new code/ideas. Satisfy Norminette and most important test it.

QuotationMark

  • Handle single and double quotes that all that is inside them is one argv
  • Make variables

pipe peter

  • Make Pipes and redirections not stop the parent process aka the actual minishell
  • Env variables (with $ and unset function which removes one of them)
  • cd work with cd - which is the same as cd ..?

maybe

  • wildcards

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.