-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_program.c
More file actions
44 lines (42 loc) · 797 Bytes
/
Copy pathfind_program.c
File metadata and controls
44 lines (42 loc) · 797 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
42
43
44
#include "main.h"
/**
* find_program - Split and process a command buffer
* @buf: The command buffer to process
*/
void find_program(char *buf)
{
char *tok, *dup;
char **arr;
int k;
arr = malloc(strlen(buf) + 1);
if (arr == NULL)
{
perror("Malloc arr");
return;
}
dup = _strdup(buf);
if (dup == NULL)
{
perror("strdup dup");
free(arr);
return;
}
tok = _strtok(dup, ";");
if (tok == NULL)
{
free(dup);
free(arr);
perror("strtok tok");
return;
}
arr[0] = tok;
for (k = 1; (tok = _strtok(NULL, ";")) != NULL; k++)
{
arr[k] = tok;
}
for (int n = 0; n < k; n++)
{
_operator(true, arr[n], true, false);
}
free(arr);
}