forked from Martell0x1/PosPosShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.c
More file actions
52 lines (39 loc) · 811 Bytes
/
Copy pathhistory.c
File metadata and controls
52 lines (39 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "shell.h"
char history[MAX_HISTORY][MAX_INPUT];
int history_count = 0;
void load_history()
{
FILE *file = fopen(HISTORY_FILE, "r");
if (!file)
return;
while (fgets(history[history_count], MAX_INPUT, file))
{
history_count++;
if (history_count >= MAX_HISTORY)
break;
}
fclose(file);
}
void save_history(char *command)
{
FILE *file = fopen(HISTORY_FILE, "a");
if (!file)
return;
fprintf(file, "%s", command);
fclose(file);
}
void add_history(char *input)
{
if (history_count < MAX_HISTORY)
{
strcpy(history[history_count++], input);
}
save_history(input);
}
void print_history()
{
for (int i = 0; i < history_count; i++)
{
printf("%d %s", i + 1, history[i]);
}
}