-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
56 lines (44 loc) · 1.13 KB
/
main.c
File metadata and controls
56 lines (44 loc) · 1.13 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <dirent.h>
#include <string.h>
#include "args.h"
#include "dir.h"
#include "bufio.h"
#include "misc.h"
#define _POSIX_OPTION_ORDER
#define CUR_DIR "./"
extern char *optarg;
extern int optopt;
extern int opterr;
int main(int argc, char **argv) {
if (argc < 3) {
usage(basename(argv[0]));
return EXIT_FAILURE;
}
char *pattern = (char *) malloc(strlen(argv[1]) + 1);
strcpy(pattern, argv[1]);
filenames_t *filenames = NULL;
int opt;
while ((opt = getopt(argc, argv, OPTIONS)) != EOI) {
switch (opt) {
case 'f':
filenames = addFilename(filenames, optarg);
break;
case '.':
if (filenames == NULL) {
filenames = getFilenames(CUR_DIR);
}
else if (filenames->count > 0) {
filenames = addFilenames(filenames, CUR_DIR);
}
break;
}
}
openfiles(filenames, pattern);
free(pattern);
freeEntries(filenames);
return 0;
}