Skip to content

Shell emulator, written by me in December 2023 for a university project

Notifications You must be signed in to change notification settings

Anenokil/AnBash

Repository files navigation

Shell emulator

Description

The program accepts shell commands from the standard input stream and executes them, handling errors.
Algorithm:
  1. The program reads commands of any length in parts using a buffer.
  2. Parses the input data and forms an array of tokens from them.
  3. Performs syntax validation. If the syntax is correct, go to step 4. Otherwise, it reports an error and returns to step 1.
  4. Builds a command tree based on the array.
  5. Executes commands from the tree, handling errors.
  6. Goes to step 1 while waiting for the next command.

The program processes the following special sequences: < > >> | || && & ; ( ) " ' \ # $SHELL $HOME $USER $EUID

Modules

It consists of 3 main modules:
  • shellexec (see below)
  • parse (see below)
  • main

It also uses following auxiliary modules:

  • colors (to learn more about it, see the module README.md)
  • strarr (to learn more about it, see the module README.md)
  • strarr_iter (to learn more about it, see the module README.md)
  • shelltree (to learn more about it, see the module README.md)

shellexec

`int shell_exec(ShTree *tree, int bg_pp, void (*emerg)(void));`
The function executes shell commands of tree and returns exit status; 'bg_pp' is a pipe for background process to remove zombies; 'emerg' is a function that is called in son after fork if execution is failed.

parse

`char ** parse(char **strarr);`
The function parses strarr for shell.
`ShTree * st_build(char **arr);`
The function creates and returns ShTree by parsed array.

About

Shell emulator, written by me in December 2023 for a university project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published