-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_parser.c
More file actions
29 lines (26 loc) · 810 Bytes
/
Copy pathcmd_parser.c
File metadata and controls
29 lines (26 loc) · 810 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
#include "headers/headers.h"
void cmd_parser(int maxCommandLength, int maxCommands, char *input, char **commandsList, int *numCommands, bool *bgArray)
{
input[strcspn(input, "\n")] = '\0';
int len = strlen(input);
char *saveptr;
int start = 0;
for (int i = 0; i <= len; i++)
{
if (input[i] == '&' || input[i] == ';' || input[i] == '\0')
{
int length = i - start;
if (length > 0)
{
strncpy(commandsList[*numCommands], input + start, length);
commandsList[*numCommands][length] = '\0';
if (input[i] == '&')
{
bgArray[*numCommands] = true;
}
(*numCommands)++;
}
start = i + 1;
}
}
}