-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeaderTable.c
147 lines (120 loc) · 3.4 KB
/
HeaderTable.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
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
/*
*
* Author: Amanzou Amine, Jeremy Paulino
*
* Created on 20 mai 2012
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "HeaderTable.h"
line_header *create_header(unsigned int size) {
line_header * new_line = (line_header *)malloc(sizeof(line_header));
line_header * local_line = new_line;
int local_size = size;
int i;
if (size == 0) {
free(new_line);
perror("Error : No line created (size is NULL)");
}
do
{
local_line->count = (local_size > TAB_SIZE)?TAB_SIZE:local_size;
for (i = 0; i < TAB_SIZE; i++) {
local_line->array[i].t = Vide;
}
local_size = local_size - TAB_SIZE;
if (local_size > 0) {
local_line->next = (line_header *)malloc(sizeof(line_header));
local_line = local_line->next;
}
} while (local_size > 0);
return new_line;
}
int update_header (line_header *l, data_header d, unsigned int place) {
line_header * local_line = l;
int local_place = place;
while ((local_line != NULL) && (local_place > TAB_SIZE)) {
local_line = local_line->next;
local_place = local_place - TAB_SIZE;
}
if (local_line == NULL)
return -1;
if (local_place > local_line->count)
return -1;
local_line->array[local_place-1] = d;
return 0;
}
int delete_line (line_header *l);
void printCell_header (data_header d) {
if (d.t == Caractere)
printf("\tCHAR");
if (d.t == Entier)
printf("\tINT");
if (d.t == Vide)
printf("NULL\t");
}
void print_header (line_header *l) {
line_header *courant = l;
int i;
printf("TYPE:");
while (courant != NULL) {
for (i = 0; i < courant->count; i++) {
printCell_header(courant->array[i]);
}
courant = courant->next;
}
courant=l;
printf("\nNAME:");
while (courant != NULL) {
for (i = 0; i < courant->count; i++) {
printf("\t%s",courant->array[i].name_col);
}
courant = courant->next;
}
}
unsigned int
getPlace (char* nameCol, line_header* lh){
unsigned int place = 0, j;
line_header *courant = lh;
while (courant != NULL){
for (j=0; j<courant->count; j++ )
if(!strcmp(courant->array[j].name_col, nameCol)){ //la bonne colonne
place = place + j + 1;
return place;
}
place = place + j;
courant = courant->next;
}
return 0; // n'existe pas
}
int
getType(char *nameCol, line_header* lh, enum type* t)
{
line_header *courant = lh;
int j = 0;
if (lh == NULL)
return -1;
while (courant != NULL) {
for (j = 0; j < courant->count; j++){
if(!strcmp(courant->array[j].name_col, nameCol)){ //la bonne colonne
*t = courant->array[j].t;
return 0;
}
}
courant = courant->next;
}
return -1;
}
data_header * makeCar_header(char* c) {
data_header *d = (data_header *)malloc(sizeof(data_header));
d->name_col = (char*) malloc ((strlen(c)+1)*sizeof(char));
strcpy(d->name_col,c); d->t = Caractere;
return d;
}
data_header * makeInt_header(char* c) {
data_header *d = malloc(sizeof(data_header));
d->name_col = (char*) malloc ((strlen(c)+1)*sizeof(char));
strcpy(d->name_col,c); d->t = Entier;
return d;
}