Write a shell with history capabilities

This commit is contained in:
Fabio Scotto di Santolo
2024-09-06 17:46:55 +02:00
parent c85abfa7c3
commit 7f14ff82bf
5 changed files with 305 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#ifndef __HISTORY_H__
#define __HISTORY_H__
#define MAXLEN 80
#define HISTORY_SIZE 10
typedef struct __HISTORY_ENTRY__ {
int line_number;
char command[MAXLEN];
} history_entry_t;
// Create new history file if not exists,
// otherwise read last command count and return it
int allocate_history(void);
// Return last ten command in the history file
history_entry_t *get_history(int);
// Write a record in the history file
int add_history(int, char *);
// Read last command in the history file
int last_command(char *);
// Search nth command in the history file,
// if not found nth command return -1.
int nth_command(char *, int);
#endif // __HISTORY_H__