-
Notifications
You must be signed in to change notification settings - Fork 0
/
poset_manage.h
96 lines (75 loc) · 2.54 KB
/
poset_manage.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
95
96
// this also modified with tailRef
/***
* ** functions used are makenode addnode_poset makeposet lengthposet printposet
*/
void addNode_poset(struct sysCPS **tmpRef, struct sysCPS **headRef, struct sysCPS **tailRef) {
if(!(*headRef)) {
*headRef = *tmpRef;
*tailRef = *tmpRef;
}
(*tailRef)->next = (*tmpRef);
(*tailRef) = (*tmpRef);
}
struct sysCPS *makeNode(char *call, int t, struct sysCPS *tmpN) {
struct sysCPS *tmp;
if(t == 1) {
tmp = (struct sysCPS *)malloc(sizeof(struct sysCPS));
tmp->call1 = strdup(call);
tmp->next = NULL;
return tmp;
}
else {
tmpN->call2 = strdup(call);
return tmpN;
}
}
void makePoset(char *fileName) {
char *tmp = "";
char call[5];
FILE *file = fopen(fileName, "r");
int k=1;
head = NULL;
while(!feof(file)) {
memset(call, 0, sizeof(call));
fscanf(file, "%s\n", call);
countPS++; // length of the poset members
if(strcmp(tmp, "") == 0) {
tmp = strdup(call);
k = 2;
continue;
}
if(k == 1) {
random_var = (struct sysCPS*)malloc(sizeof(struct sysCPS));
random_var->call1 = tmp;
random_var->call2 = strdup(call);
random_var->next = NULL;
tmp = strdup(call);
addNode_poset(&random_var, &head, &tail);
k++;
}
else if(k == 2) {
random_var = (struct sysCPS*)malloc(sizeof(struct sysCPS));
random_var->call1 = tmp;
random_var->call2 = strdup(call);
random_var->next = NULL;
tmp = strdup(call);
addNode_poset(&random_var, &head, &tail);
k = 1;
}
}
fclose(file);
}
int lengthPoset(struct sysCPS *headRef) {
int l=0;
while(headRef) {
l++;
headRef = headRef->next;
}
return l;
}
void printPoset(struct sysCPS *headRef) {
while(headRef) {
printf("%s\t%s\n", headRef->call1, headRef->call2);
headRef = headRef->next;
}
}