-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_comments.c
More file actions
42 lines (38 loc) · 817 Bytes
/
Copy pathhandle_comments.c
File metadata and controls
42 lines (38 loc) · 817 Bytes
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
#include "shell.h"
/**
* handle_comments - Handles comments in the given command string.
* @cmd: The command string to process.
* This function modifies the command string by removing any comments
* starting with a '#' symbol. If the '#' symbol is part of a word and
* not a comment, it is preserved.
**/
void handle_comments(char *cmd)
{
char *cs = cmd;
while (*cs != '\0')
{
if (*cs == '#')
{
if (cs != cmd && !is_whitespace(*(cs - 1)))
{
cs++;
continue;
}
else
{
*cs = '\0';
break;
}
}
cs++;
}
}
/**
* is_whitespace - Checks if the given character is a whitespace character.
* @c: The character to check.
* Return: 1 if the character is a whitespace character, 0 otherwise.
**/
int is_whitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n');
}