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

This header file contains almost everything needed for this project. More...

Go to the source code of this file.

Macros

#define cls   printf("\033[2J\033[1;1H");
 
#define LINE_BUFFER_SIZE   1024
 
#define MAXHOSTNAMELEN   32
 
#define C_SHELL_TOK_DELIM   " \t\r\n"
 

Functions

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

This header file contains almost everything needed for this project.

Author
Swastik Pal
Version
0.1
Date
2022-11-03

Macro Definition Documentation

◆ C_SHELL_TOK_DELIM

#define C_SHELL_TOK_DELIM   " \t\r\n"

◆ cls

#define cls   printf("\033[2J\033[1;1H");

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   1024

◆ MAXHOSTNAMELEN

#define MAXHOSTNAMELEN   32

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.

◆ 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.