-
Notifications
You must be signed in to change notification settings - Fork 0
/
lerest.c
86 lines (72 loc) · 1.96 KB
/
lerest.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
/******************************************************************************
* File Name: lerest.c
* Author: João Rodrigues, Sara Vieira
* Revision: v1.0
* NAME
* Projeto-Gestor de Parque
* SYNOPSIS
* #include <stdlib.h>
* #include <stdio.h>
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "parque.h"
/******************************************************************************
* lefilerest()
*
* Arguments: name of file
* Returns: Lista de restrições
*
* Description: Leitura do ficheiro de restrições e inicialização da lista de restrições
*
*****************************************************************************/
LinkedList * lefilerest(char *file_r)
{
int x, y, z, p;
int ta, tb;
char r;
rest *new_rest;
FILE *fr;
LinkedList *l_rest = initLinkedList();
fr = fopen(file_r, "r");
while(fscanf(fr, "%c", &r) == 1)
{
if(fscanf(fr, "%d %d", &ta, &tb) != 2)
exit(0);
if(fscanf(fr, "%d %d %d\n", &x, &y, &z) == 3)
p = -1; /*esta interdito um LUGAR*/
else{
p = x; /*esta interdito um PISO*/
x = -1;
y = -1;
z = -1;
}
new_rest = (rest *) malloc(sizeof(rest));
new_rest->ta = ta;
new_rest->tb = tb;
new_rest->piso = p;
new_rest->x = x;
new_rest->y = y;
new_rest->z = z;
l_rest = insertSortedLinkedList(l_rest, (Item *)new_rest, &(acontece_depois));
}
fclose(fr);
return l_rest;
}
/******************************************************************************
* acontece_depois()
*
* Arguments: Item 1, Item 2
* Returns: 1 se a retrição c1 começar depois da restrição c2
*
* Description: Função de comparação para a lista de restrições
*
*****************************************************************************/
int acontece_depois(Item c1, Item c2)
{
if(((rest*)c1)->ta > ((rest*)c2)->ta)
return 1;
else
return 0;
}