-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.c
69 lines (64 loc) · 1.79 KB
/
opts.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* opts.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmoureu- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/12 22:43:35 by dmoureu- #+# #+# */
/* Updated: 2016/02/10 20:28:32 by dmoureu- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void readoptsargs(char **av, char *opts, int i)
{
const char args[7] = {'l', 'R', 'a', 'r', 't', 'f', '1'};
while (ft_strchr(args, *av[i]) && *av[i] != 0)
{
opts[(int)(*av[i])] = 1;
(av[i]++);
}
write(1, "", 0);
if (*av[i] != '\0')
error("ls: illegal option -- ", *av[i]);
}
int readopts(int ac, char **av, char *opts, int i)
{
while (++i < ac)
{
if (*av[i] == '-')
{
av[i]++;
if (*av[i] == '\0')
{
write(1, "", 0);
av[i]--;
return (i);
}
if (*av[i] == '-')
{
if (*(++av[i]) == '\0')
return (i + 1);
else
error("ft_ls: illegal option -- ", *(--av[i]));
}
readoptsargs(av, opts, i);
}
else
return (i);
}
return (i);
}
void viewopts(t_ls *ls)
{
if (ls->opts['l'])
puts("l donne");
if (ls->opts['r'])
puts("r donne");
if (ls->opts['R'])
puts("R donne");
if (ls->opts['a'])
puts("a donne");
if (ls->opts['t'])
puts("t donne");
}