-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsfind.c
executable file
·104 lines (67 loc) · 1.86 KB
/
rsfind.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "myFunctionalLib.h"
#include "argsHandler.h"
#include "searcher.h"
#include "optionsToApply.h"
#include <string.h>
#include <dirent.h>
#include <time.h>
#include <locale.h>
int main(int argc, char** argv){
//==========Local Settlement==========
setlocale(LC_ALL,"");
//==========Options Checking==========
int returnOferrInArg = errInArg(argc, argv);
if (returnOferrInArg!=0){
if (returnOferrInArg==1){
return 1;
}
else if (returnOferrInArg ==2){
return 1;
}
}
//==========Path Definition==========
char* myPath;
if (argc>1)
if (argv[1][0]=='-')
myPath = ".";
else
myPath = argv[1];
else
myPath = ".";
DIR* initDir;
initDir = opendir(myPath);
if(initDir==NULL)
return 1; // NOT a valid path.
//==========Options Dispatching==========
int nOpt = 0, iOpt = 0, tOpt = 0;
int lOpt = 0, eOpt = 0, pOpt = 0;
char* nArg = malloc(1);
char* tArg = malloc(1);
char* eArg = malloc(1);
if(optDispatcher(argc, argv, &lOpt, &tOpt, &tArg, &iOpt, &nOpt, &nArg, &eOpt, &eArg, &pOpt)){
return 1; // Wrong entry.
}
//==========Recursive Research==========
listOfFiles* myList = malloc(sizeof(listOfFiles));
myList -> myFile = create_File(myPath, "", 0);
myList -> next = NULL;
if(finderRecursive(myList))
return 1; //Impossible to open.
//==========Apply Restrictions==========
if (nOpt){myList = applyNOption(myList, nArg);}
if (iOpt){myList = applyIOption(myList);}
if (tOpt){myList = applyTOption(myList, tArg);}
//==========Datas Complements==========
if (lOpt){ myList = applyLOption(myList); }
//==========Execution on Result==========
if (eOpt){
myList = applyEOption(myList, eArg);/*Apply the -exec with a pipe : JULIEN*/
}
//==========PRINT IT ==========
printerGeneral(myList,pOpt,lOpt,eOpt);
return 0;
}