Repository navigation
Expand file tree
/
Copy pathcontroller.c
More file actions
202 lines (181 loc) · 5.21 KB
/
Copy pathcontroller.c
File metadata and controls
202 lines (181 loc) · 5.21 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "LinkedList.h"
#include "controller.h"
#include "vuelos-piloto.h"
#include "parser.h"
#include "funcionesgnr.h"
int controller_Sellanes_loadVuelos(char* path, LinkedList* pArrayListVuelo)
{
int auxRet=-1;
FILE* pFile= NULL;
ll_clear(pArrayListVuelo);
pFile=fopen(path, "r");
auxRet=parcerVueloFromText(pFile, pArrayListVuelo);
fclose(pFile);
return auxRet;
}
int controller_Sellanes_loadPilotos(char* path, LinkedList* pArrayListPiloto)
{
int auxRet=-1;
FILE* pFile= NULL;
ll_clear(pArrayListPiloto);
pFile=fopen(path, "r");
auxRet=parcerVueloFromText(pFile, pArrayListPiloto);
fclose(pFile);
return auxRet;
}
int controller_Sellanes_listarVuelos(LinkedList* pArrayListVuelo, LinkedList* pListaPiloto)
{
int i;
int len;
int auxRet=-1;
if(pArrayListVuelo != NULL && pListaPiloto != NULL)
{
auxRet=0;
len=ll_len(pArrayListVuelo);
printf("%10s%15s%20s%15s%15s%15s%15s%15s\n", "ID VUELO", "ID AVION",
"PILOTO", "FECHA", "DESTINO", "PASAJEROS", "HORA DESPEGE", "HORA LLEGADA");
for(i=0; i<len; i++)
{
printVuelo((eVuelos*)ll_get(pArrayListVuelo, i), pListaPiloto);
}
}
return auxRet;
}
int controller_Sellanes_contarPasajeros(LinkedList* pArrayListVuelo)
{
int auxRet=-1;
int cant=0;
if(pArrayListVuelo != NULL)
{
cant=ll_count(pArrayListVuelo, contarPasajeros);
printf("\nLa cantidad de pasajeros es: %d\n", cant);
}
return auxRet;
}
int controller_Sellanes_contarPasajerosIrlanda(LinkedList* pArrayListVuelo)
{
int auxRet=-1;
int cant=0;
if(pArrayListVuelo != NULL)
{
auxRet=0;
cant=ll_count(pArrayListVuelo, contarPasajerosIrlanda);
printf("\nLa cantidad de pasajeros con destino Irlanda es: %d\n", cant);
}
return auxRet;
}
int controller_Sellanes_saveVuelos(char* path, LinkedList* pArrayListVuelo)
{
int auxRet=-1;
eVuelos* vueloAux;
FILE* pFile = NULL;
int i;
int len;
int idVuelo, idPiloto, idAvion, cantPsj, hsDespege, hsLlegada;
char fecha[20], destino[50];
if(pArrayListVuelo != NULL)
{
pFile=fopen(path, "w");
if(pFile != NULL)
{
auxRet=0;
len=ll_len(pArrayListVuelo);
fprintf(pFile, "idVuelo,idAvion,idPiloto,fecha,destino,cantPasajeros,horaDespegue,horaLlegada\n");
for(i=0; i<len; i++)
{
vueloAux= (eVuelos*) ll_get(pArrayListVuelo, i);
vuelo_getId(vueloAux, &idVuelo);
vuelo_getIdAvion(vueloAux, &idAvion);
vuelo_getIdPiloto(vueloAux, &idPiloto);
vuelo_getFecha(vueloAux, fecha);
vuelo_getDestino(vueloAux, destino);
vuelo_getCantPasajeros(vueloAux, &cantPsj);
vuelo_getHoraDespeje(vueloAux, &hsDespege);
vuelo_getHoraLlegada(vueloAux, &hsLlegada);
fprintf(pFile, "%d,%d,%d,%s,%s,%d,%d,%d\n", idVuelo, idAvion, idPiloto, fecha, destino, cantPsj, hsDespege, hsLlegada);
}
}
fclose(pFile);
}
return auxRet;
}
int controller_Sellanes_filterAndSaveVuelosCortos(char* path, LinkedList* pArrayListVuelo)
{
LinkedList* filterList=NULL;
int auxRet=0;
if(path != NULL && pArrayListVuelo != NULL)
{
filterList=ll_filter(pArrayListVuelo, filtrarVuelosCortos);
if(filterList != NULL)
{
auxRet=1;
controller_Sellanes_saveVuelos(path, filterList);
}
}
ll_deleteLinkedList(filterList);
return auxRet;
}
int controller_Sellanes_listarVuelosPortugal(LinkedList* pArrayListVuelo, LinkedList* pListPilots)
{
LinkedList* filterList=NULL;
int auxRet=0;
if(pArrayListVuelo != NULL)
{
filterList=ll_filter(pArrayListVuelo, filtrarVuelosAPortugal);
if(filterList != NULL)
{
auxRet=1;
controller_Sellanes_listarVuelos(filterList, pListPilots);
}
}
return auxRet;
}
int controller_Sellanes_listarVuelosSinAlexLifeson(LinkedList* pArrayListVuelo, LinkedList* pListPilots)
{
LinkedList* filterList=NULL;
int auxRet=0;
if(pArrayListVuelo != NULL)
{
filterList=ll_filter(pArrayListVuelo, excludeAlexLifeson);
if(filterList != NULL)
{
auxRet=1;
controller_Sellanes_listarVuelos(filterList, pListPilots);
}
}
return auxRet;
}
int controller_Sellanes_listarPiltos(LinkedList* pListPilots)
{
int len;
int i;
int auxRet=0;
if(pListPilots != NULL)
{
auxRet=1;
len=ll_len(pListPilots);
for(i=0; i<len; i++)
{
printPiloto((ePiloto*) ll_get(pListPilots, i));
}
}
return auxRet;
}
int controller_Sellanes_filtrarPilotosNombre(LinkedList* pListPilots, char* nombre)
{
LinkedList* filterList=NULL;
int auxRet=0;
if(pListPilots != NULL)
{
filterList=ll_filterParametros(pListPilots, filtrarPorNombre, nombre);
if(filterList!= NULL)
{
auxRet=1;
controller_Sellanes_listarPiltos(filterList);
}
}
return auxRet;
}