-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.c
62 lines (53 loc) · 848 Bytes
/
history.c
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
53
54
55
56
57
58
59
60
61
#include <stdlib.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "parse.h"
#include "commands.h"
#include "ls.h"
#include "background.h"
#include "main.h"
#include "history.h"
void history_command(char * input)
{
char *temp = malloc (1 + strlen(input));
strcpy(temp,input);
char * token = strtok(NULL, " \t\r\n");
int i;
int tot;
if(size >= 10)
tot = 10;
else
tot = size;
if(token == NULL)
{
for(i=size-tot;i<size;i++)
{
printf("%s\n",hist[i]);
}
}
else
{
int j = atoi(token);
if(size >= j)
{
for(i=size-j;i<size;i++)
{
printf("%s\n",hist[i]);
}
}
else
{
//printf("%d\n",tot);
for(i=size-tot;i<size;i++)
{
printf("%s\n",hist[i]);
}
}
}
return;
}