-
Notifications
You must be signed in to change notification settings - Fork 0
/
_comments.c
75 lines (72 loc) · 1.43 KB
/
_comments.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
71
72
73
74
75
#include "sshell.h"
/**
* semicolon - search if in the input there is a ";" or a ";;"
* @line: complete input of user
* @loop: number of actual loop
* @argv: input argument
* Return: 1 if find ";" or ";;" or 0 if not
*/
int semicolon(char *line, int loop, char **argv)
{
int valid = 0, cont = 0;
while (line[cont] != '\0')
{
if (line[0] == ';')
{
valid = 1;
write(STDERR_FILENO, argv[0], _strlen(argv[0]));
write(STDERR_FILENO, ": ", 2);
print_number(loop);
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, "Syntax error: ", 14);
write(STDERR_FILENO, ";", 1);
write(STDERR_FILENO, " unexpected\n", 12);
break;
}
if (line[cont] == ';' && line[cont + 1] == ';')
{
valid = 1;
write(STDERR_FILENO, argv[0], _strlen(argv[0]));
write(STDERR_FILENO, ": ", 2);
print_number(loop);
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, "Syntax error: ", 14);
write(STDERR_FILENO, ";;", 2);
write(STDERR_FILENO, " unexpected\n", 12);
break;
}
cont++;
}
return (valid);
}
/**
*_comments - remove commentaries
*@line: input of user
* Return: the new input
*/
char *_comments(char *line)
{
int a = 0, c = 0, flag = 0;
while (line[c] != '\0')
c++;
while (line[a] != '\0')
{
if (line[0] == '#')
{
flag = 1;
break;
}
if (line[a] == '#' && line[a - 1] == ' ')
{
flag = 1;
break;
}
a++;
}
if (flag == 1)
{
for (; a < c; a++)
line[a] = 0;
}
return (line);
}