blob: da1bd6c1407624ea8042758b765655bffd8f73fe (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <readline/readline.h>
#include <dirent.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
/* BOOLEANS */
#define true 1
#define false 0
#define _DEFAULT_SOURCE
void exit_program(char *argv)
{
if (strcmp(argv, "exit"))
{
exit(0);
}
}
void get_pid_parent_process()
{
printf("PID %ld\n", (long)getpid());
}
void list_directories()
{
struct dirent **namelist;
int n;
n = scandir(".", &namelist, NULL, alphasort);
if (n == -1)
{
perror("scandir");
exit(EXIT_FAILURE);
}
while (n--)
{
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist[n]);
exit(EXIT_SUCCESS);
}
void echo(char *command, char *argv)
{
if (strcmp(command, "echo") == 0)
{
printf("argv");
}
}
int main(void)
{
char *input;
readline(input);
while(strcmp(input, "exit") != 0)
{
list_directories();
}
exit_program(input);
return 0;
}
|