-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.c
40 lines (37 loc) · 879 Bytes
/
comment.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
/*
** comment.c for comment in /home/arthur/delivery/PSU/PSU_2016_42sh
**
** Made by Arthur Knoepflin
** Login <[email protected]>
**
** Started on Thu May 18 19:11:24 2017 Arthur Knoepflin
** Last update Thu May 18 20:57:35 2017 Arthur Knoepflin
*/
#include <stdlib.h>
#include "shell.h"
#include "my.h"
int clear_comment(t_shell *shell)
{
int i;
int quote;
char *tmp;
i = 0;
quote = 0;
while (shell->line[i])
{
if (shell->line[i] == '\'' && (quote == 0 || quote == 1))
quote = (quote == 0) ? 1 : 0;
if (shell->line[i] == '"' && (quote == 0 || quote == 2))
quote = (quote == 0) ? 2 : 0;
if (shell->line[i] == '#' && quote == 0 &&
(i == 0 || (i != 0 && (shell->line[i - 1] == ' '))))
{
tmp = my_strndup(shell->line, i);
free(shell->line);
shell->line = tmp;
return (0);
}
i += 1;
}
return (0);
}