-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
62 lines (42 loc) · 1.08 KB
/
shell.c
File metadata and controls
62 lines (42 loc) · 1.08 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
53
54
55
56
57
58
59
60
61
62
/*
============================================================================
Name : shell.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "interpreter.h"
int parse ( char array[]){
char temp[200];
char *words[100];
int a,b;
int w =0;
const char delim[10] = { 10 };
char * token;
token = strtok(array, delim);
// eliminate white spaces at the beggining
for (a=0; array[a]==' ' && a < 1000; a++);
while (array[a] != '\0' && a <1000){
for (b=0; array[a] != '\0' && array[a] != ' ' && a<1000 ; a++,b++){
temp[b] = array[a];
}
temp[b]= '\0';
const char delim[10] = { 10 };
char * token;
token = strtok(temp, delim);
words[w]= strdup(token);
a++;
w++;
}
words[w]=NULL;
if (words[0]==NULL){
printf("empty user input\n");
return 0;
}
return interpreter(words,w);
}