C-Shell
A simple shell written in C.
|
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "history.h"
Functions | |
void | add_to_history (char *line) |
Adds a line to the history. | |
void | clear_history () |
Clears the history. | |
const struct history_list * | get_history () |
Gets the history list. | |
void | print_history (int n) |
Prints the last n commands in the history. | |
int | read_history_from_file () |
int | write_history_to_file () |
int | history (int nargs, char **args) |
Print the history of commands. | |
Variables | |
const char *const | history_file = ".chistory" |
struct history_list | h_list |
int | opterr |
int | optind |
int | optopt |
char * | optarg |
void add_to_history | ( | char * | line | ) |
Adds a line to the history.
line | The command to add. |
allocate memory and deep copy
free the memory
allocate memory and deep copy
void clear_history | ( | ) |
Clears the history.
free the memory
const struct history_list * get_history | ( | ) |
Gets the history list.
int history | ( | int | nargs, |
char ** | args ) |
Print the history of commands.
If no option is specified, prints the last 5 commands.
Options:
-c
- clear the history-r
- read the history file and write to the history list-w
- write the history list to the history file void print_history | ( | int | n | ) |
Prints the last n
commands in the history.
n | The number of commands to print. |
int read_history_from_file | ( | ) |
int write_history_to_file | ( | ) |
struct history_list h_list |
const char* const history_file = ".chistory" |
|
extern |
|
extern |
int optind |
int optopt |