-
Notifications
You must be signed in to change notification settings - Fork 0
/
filelist.h
94 lines (87 loc) · 1.63 KB
/
filelist.h
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
typedef struct FileList FileList;
struct FileList
{
struct dirent *file;
char *path;
int fileDescriptor;
char *data;
int size;
struct stat sstat;
struct FileList *sig;
};
FileList * createNode(struct dirent *file, char *path)
{
struct stat sstat;
stat(path,&sstat);
FileList * newFile = (FileList*)malloc(sizeof(FileList));
newFile->file = file;
newFile->sig = NULL;
newFile->path=path;
newFile->fileDescriptor=open(path, O_RDONLY);
newFile->data=NULL;
newFile->sstat=sstat;
newFile->size=sstat.st_size;
return newFile;
}
void add(FileList *file, FileList ** list)
{
FileList * p = *list;
if(!p)
{
*list=file;
}
else
{
while (p->sig)
p = p->sig;
p->sig = file;
}
}
void removeNode(FileList ** list)
{
FileList *p= *list;
if(p->sig)
{
FileList *t=p->sig;
p->sig=p->sig->sig;
free(t);
}
else
*list=NULL;
}
void removeByIndex(int index,FileList ** list)
{
FileList *p= *list;
if(!index&&p)
{
*list=p->sig;
remove(p->path);
free(p);
}
while(index>1&&p&&p->sig)
{
p=p->sig;
index--;
}
if(index==1&&p)
{
remove(p->sig->path);
removeNode(&p);
}
}
void show(FileList *list)
{
printf("\n\nArchivos duplicados:\n");
int i=1;
while(list)
{
printf("\t(%i) %s\n", i++,list->path);
list=list->sig;
}
printf("\nPresione ");
for(int j=1;j<i;j++)
{
printf("%i para eliminar (%i), ",j,j);
}
printf("s para siguiente: ");
}