-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper_funcs.c
54 lines (43 loc) · 902 Bytes
/
helper_funcs.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
#include "shell.h"
/**
* sigint_handler - doesn't exit in case of Ctrl-C
* @sig: required for signal function to run properly
*
* Description: ignore sig, print newline, print the prompt
* Call to fflush discards the Ctrl-C
*/
void sigint_handler(int sig)
{
(void)sig;
_putchar('\n');
print_prompt();
fflush(stdout);
}
/**
* free_everything - frees arrays of strings
* @args: array of strings to free
*/
void free_everything(char **args)
{
int i;
if (!args)
return;
for (i = 0; args[i]; i++)
free(args[i]);
free(args);
}
/**
* parse_line - handle newline character if found, and parses the input line
* @line: line read from stdin
* @get: size of line returned from getline
*
* Return: parsed line
*/
char **parse_line(char *line, int get)
{
char **input = NULL;
if (line[get - 1] == '\n')
line[get - 1] = '\0';
input = _strtok(line, ' ');
return (input);
}