-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnutshell.c
More file actions
52 lines (45 loc) · 1.21 KB
/
nutshell.c
File metadata and controls
52 lines (45 loc) · 1.21 KB
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include <unistd.h>
#include <limits.h>
char *getcwd(char *buf, size_t size);
int main()
{
useAlias = true;
aliasIndex = 0;
varIndex = 0;
char cwd[PATH_MAX];
getcwd(cwd, sizeof(cwd));
strcpy(varTable.var[varIndex], "PWD");
strcpy(varTable.word[varIndex], cwd);
varIndex++;
strcpy(varTable.var[varIndex], "HOME");
strcpy(varTable.word[varIndex], cwd);
varIndex++;
strcpy(varTable.var[varIndex], "PROMPT");
strcpy(varTable.word[varIndex], "nutshell");
varIndex++;
strcpy(varTable.var[varIndex], "PATH");
strcpy(varTable.word[varIndex], ".:/bin");
varIndex++;
strcpy(aliasTable.name[aliasIndex], ".");
strcpy(aliasTable.word[aliasIndex], cwd);
aliasIndex++;
char *pointer = strrchr(cwd, '/');
while(*pointer != '\0') {
*pointer ='\0';
pointer++;
}
strcpy(aliasTable.name[aliasIndex], "..");
strcpy(aliasTable.word[aliasIndex], cwd);
aliasIndex++;
system("clear");
printf("Welcome to the Nutshell by Marcus Elosegui and Eric Ho\n");
while(1){
printf("[%s]>> ", varTable.word[0]);
yyparse();
}
return 0;
}