-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
executable file
·76 lines (69 loc) · 1.39 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
** parser.c for in /home/locque_d//rendu/proj/my_script/ESSAY
**
** Made by damien locque
** Login <[email protected]>
**
** Started on Sun Feb 27 12:37:30 2011 damien locque
** Last update Sun Feb 27 12:23:45 2011 damien locque
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "my_script.h"
void parse_arg(int argc, char **argv, char *opt)
{
int c;
(*opt) = 0;
while ((c = getopt(argc, argv, "ac:fqt")) != -1)
{
if (c == 'a')
(*opt) |= MASK_A;
else if (c == 'c')
(*opt) |= MASK_C;
else if (c == 'f')
(*opt) |= MASK_F;
else if (c == 'q')
(*opt) |= MASK_Q;
else if (c == 't')
(*opt) |= MASK_T;
else
{
fprintf(stderr,
"usage: script [-a] [-c COMMAND] [-f] [-q] [-t] [file]\n");
exit(EXIT_FAILURE);
}
}
}
static void change_name(char *src, char **dest)
{
(*dest) = src;
}
void check_file(int argc, char **argv, t_fd *fd)
{
int i;
int j;
bool flag;
j = 1;
i = 1;
fd->fname = DEFAULT_NAME;
while (i < argc)
{
flag = false;
if (argv[i] && argv[i][0] != '-')
{
if (argv[i] && argv[i - 1] && argv[i - 1][0] == '-')
{
while (argv[i - 1][j])
if (argv[i - 1][j++] == 'c')
flag = true;
if (!flag)
return (change_name(argv[i], &(fd->fname)));
}
else
return (change_name(argv[i], &(fd->fname)));
}
++i;
}
}