C-Shell
A simple shell written in C.
Loading...
Searching...
No Matches
main.c File Reference

The entrypoint to the program. More...

#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "internal_commands.h"
#include "main.h"

Functions

int main ()
 Execution starts here.
 
int execute (int nargs, char *command, char **args)
 Executes the command.
 
int load_settings ()
 Will load configuration file(s).
 
int loop ()
 I keep looping, looping till the user exits.
 
char ** parse_line (char *line, size_t line_size, int *nargs)
 Tokenizes the line.
 
int print_prompt ()
 Prints username@machinename.
 
int read_line (char *buffer, int buffer_size)
 Reads a line from stdin.
 

Detailed Description

The entrypoint to the program.

Author
Swastik Pal
Version
0.1
Date
2022-11-03

Comments can be written in Markdown.

Function Documentation

◆ execute()

int execute ( int nargs,
char * command,
char ** args )

Executes the command.

Parameters
nargsNumber of arguments to the command.
commandThe command to execute.
argsThe list of arguments to the command.
Returns
int

Available commands:

  • cls - clears the screen
  • exit - terminates the terminal

◆ load_settings()

int load_settings ( )

Will load configuration file(s).

Not yet implemented.

◆ loop()

int loop ( )

I keep looping, looping till the user exits.

◆ main()

int main ( )

Execution starts here.

◆ parse_line()

char ** parse_line ( char * line,
size_t line_size,
int * nargs )

Tokenizes the line.

Parameters
lineA string.
line_sizeLength of the string.
Returns
char** An array of tokens.

◆ print_prompt()

int print_prompt ( )

Prints username@machinename.

◆ read_line()

int read_line ( char * buffer,
int buffer_size )

Reads a line from stdin.

Parameters
bufferThe buffer to write into.
buffer_sizeThe size of the provided buffer.
Returns
int The number of characters read.