-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.txt
More file actions
executable file
·57 lines (57 loc) · 1.54 KB
/
test.txt
File metadata and controls
executable file
·57 lines (57 loc) · 1.54 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
void echo(char cmd[]){
char Print[MAX];
int pos=0;
int quotes[2]={0,0}; // DOES not contain actual number of "" or '' . Used for even odd. odd within even cases also. CONTAINS " & ' outside each of other.
int new_line=0;
for(int i=0;cmd[i];i++){
if(cmd[i]==' ' && quotes[0]%2==0 && quotes[1]%2==0){
Print[pos++]=cmd[i];
cmd=rem_leading_spaces(cmd+i);
i=-1; // i++ will make it 0 next step.
}
else if(cmd[i]=='\''){
if(quotes[1]%2==0){ // if not within the " " , then
quotes[0]++; //dont print
}
else{
Print[pos++]=cmd[i];
}
}
else if(cmd[i]=='"'){
if(quotes[0]%2==0){
quotes[1]++;
}
else{
Print[pos++]=cmd[i];
}
}
else if(cmd[i]=='\n'){
new_line=1;
Print[pos++]='\n';
}
else{
Print[pos++]=cmd[i];
}
}
Print[pos++]='\0';
if(quotes[0]%2 || quotes[1]%2){
printf("Multiline echo not supported yet. Missing ' or \".\n");
}
else{
if(new_line){
printf("%s",Print);
}
else{
printf("%s\n",Print);
}
}
}#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<errno.h>
#include<unistd.h>
#include<string.h>
#include <sys/utsname.h>
#include<signal.h>
#define MAX 1001
#define SHELL_ADDR "/home/pstalwalkar7/2-1/OperatingSystems/Shell/1"