Skip to content

Svenja's notes

svenja edited this page May 14, 2022 · 16 revisions

so, what all needs to be handled:

  • in main loop: history append thingy

  • lexer: just divide all the tokens -> don't use isalnum, just treat them as normal characters! if you have unclosed quotes, just read them as normal characters!

  • parser_expander: handle " and ' (double and single quotes), $ (in quotes too, unlike the redirections)

  • maybe already pair into pipes (error: nothing to left or right of pipe), and connect to redirections (error: end of line or pipe to the right of redirection). mayyyyybe we can also already open the heredocs? not sure, would be kind of weird.
  • so now we have everything how it should be, and pipe/redirection errors are handled. now, we can start executing, right?
  • i guess, first comes input/output creator. not sure if this is parser stuff. so we create and/or open the proper documents with the proper flags. if one is not needed/overwritten, close it!! we save the file descriptors, pipes too.
  • then, the executor? for every command, check if it's inbuilt or not. if it is, go to the inbuilt function, if not, use execve. for both, we fork before, and then change stdin to its input fd and stdout to its output fd. after execution fd needs to be closed? it's complicated, do in code, have to used dup and dup2. use wait/waitpid to collect exit status?

proposal of structure:

  • lexer: divides tokens.
  • errors: no ID next to redirection, another pipe or nothing next to a pipe
  • parser_expander: expand double and single quotes and $. combine command blocks/use them as new tokens. check for incorrect redirection or pipe use. save those somewhere.
  • input_output_handler: create pipes and redirections, close unused ones, and save the ones that should be used. command block/token structure should be quite simple now.
  • executor: executes the command.

executor detailed

THIS CAN GO IN PARSER? idk for every command block cmd:

  • check if inbuilt
  • check if cmd is at the path that we're given
  • if so don't change cmd pointer
  • if not! search for path.
  • find value of path with collect_varvalue
  • split PATH into its different paths (':' is delimiter)
  • then do strjoin with all those paths and cmd and test if there is access. if so, replace cmd with the strjoin and return. perhaps need to handle with and without backslash, not sure if we should handle
  • for every not found command, give error message
  • if any of these are neither inbuilt, nor can the path be found, give command not found error message and stop process
  • blablabla lol
  • argv converter (is ok with pathname)
  • env pointer converter (free?)
  • after those conversions, can free executor struct lel
  • should free those too after exec

  • code the inbuilt functions
  • save environment variables somewhere, replace them when $ is used. -> what if word after $ is not in the env?
  • $?, but that will be easy.
  • ctrl-c, ctrl-d, ctrl-\ (look into what should happen in shell and in here doc (asked in eval!)
  • global: exit status

cat | cat | ls

Clone this wiki locally