-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg_parser.c
48 lines (44 loc) · 1.47 KB
/
arg_parser.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* arg_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alischyn <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 14:15:50 by alischyn #+# #+# */
/* Updated: 2017/03/24 15:56:31 by alischyn ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void arg_error(char chr)
{
ft_printf("%s: illegal option -- %c\n", PROGNAME, chr);
ft_printf("usage: %s [-alrRt] [file ...]\n", PROGNAME);
exit(1);
}
void arg_parse(int argc,
char *argv[],
char *(*args[]))
{
int i;
int j;
__builtin_bzero(g_params, sizeof(g_params));
i = 0;
while (++i < argc && argv[i][0] == '-')
{
if (argv[i][1] == '-' && argv[i][2] == '\0')
{
i++;
break ;
}
j = 0;
while (argv[i][++j] != '\0')
{
if (IS_PARAM(argv[i][j]))
g_params[(int)argv[i][j]] = true;
else
arg_error(argv[i][j]);
}
}
*args = &argv[i];
}