-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.c
70 lines (57 loc) · 1.53 KB
/
echo.c
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
#include "headers.h"
void echo(char *command)
{
long long int s = strlen(command);
long long int quotesflag=0;
long long int afterechoflag=0;
long long int spaceflag=0;
int quotestype=0;
for(long long int a =0; a<s; a++)
{
if(afterechoflag==1 && quotesflag==0)
{
if((int)command[a]==39)
{
quotestype=39;
quotesflag=1;
spaceflag=0;
}
else if((int)command[a]==34)
{
quotestype=34;
quotesflag=1;
spaceflag=0;
}
else if((int)command[a]!=13 && (int)command[a]!=32 && (int)command[a]!=9)
{
printf("%c", command[a]);
spaceflag=0;
}
else if((int)command[a]==13 || (int)command[a]==32 || (int)command[a]==9)
{
if(spaceflag == 0)
{
printf(" ");
spaceflag=1;
}
}
}
else if(afterechoflag==1 && quotesflag==1)
{
if((int)command[a] == quotestype)
{
quotesflag=0;
spaceflag=0;
}
else
{
printf("%c", command[a]);
}
}
if((int)command[a-4]==101 && (int)command[a-3]==99 && (int)command[a-2] ==104 && (int)command[a-1] == 111)
{
afterechoflag=1;
}
}
printf("\n");
}