forked from PyxisSociety/SANDAL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayCode.c
80 lines (69 loc) · 1.38 KB
/
DisplayCode.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
#include "DisplayCode.h"
/* -------------------------------------------------------
* Liste de code d'affichage
*/
ListDisplayCode* initListDisplayCode(){
ListDisplayCode *l=(ListDisplayCode*)malloc(sizeof(*l));
if(l){
l->first=NULL;
l->size=0;
}
return l;
}
void freeListDisplayCode(ListDisplayCode *l){
DisplayCode *d,*tmp;
if(l){
d=l->first;
while (d) {
tmp=d->next;
free(d);
d=tmp;
}
free(l);
}
}
int addDisplayCode(ListDisplayCode* l,int code,int isDisplaied,int plan){
DisplayCode **d, *new;
int error = 1;
if(l){
d=&(l->first);
while(*d && (*d)->code<code){
d=&((*d)->next);
}
if(*d && (*d)->code==code){
(*d)->isDisplaied=isDisplaied;
(*d)->plan=plan;
error = 0;
}else{
new=(DisplayCode*)malloc(sizeof(*new));
if(new){
new->code=code;
new->next=*d;
new->isDisplaied=isDisplaied;
new->plan=plan;
*d=new;
l->size++;
error = 0;
}
}
}
return error;
}
int delDisplayCode(ListDisplayCode * l, int code){
int error = 1;
DisplayCode ** d, * dtmp;
if(l){
d = &(l->first);
while(*d && (*d)->code < code)
d = &((*d)->next);
if(*d && (*d)->code == code){
error = 0;
dtmp = *d;
*d = dtmp->next;
free(dtmp);
--l->size;
}
}
return error;
}
/* ------------------------------------------------------- */