blob: 6cec097c993c5ea689ff256ef97a4b7608a33178 (
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
|
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "builtins.h"
#include "utils/env.h"
int dot(struct string **args)
{
if (args[0] == NULL)
{
fprintf(stderr, ".: filename argument required\n");
fflush(stdout);
return 2;
}
if (args[1] != NULL)
{
fprintf(stderr, ".: too many arguments\n");
fflush(stdout);
return 2;
}
FILE *file = fopen(args[0]->data, "r");
if (file == NULL)
{
fprintf(stderr, ".: filename does not exist\n");
fflush(stdout);
return 1;
}
char line[1024];
while (fgets(line, sizeof(line), file))
{
// TODO : execute file
fputs(line, stdout);
}
fclose(file);
fflush(stdout);
return 0;
}
|