-
Notifications
You must be signed in to change notification settings - Fork 1
/
stmtlist.c
57 lines (51 loc) · 1.25 KB
/
stmtlist.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
#include "stmtlist.h"
struct StmtList_ {
char *stmt;
StmtList next;
};
StmtList CreateStmtList() {
StmtList temp = malloc(sizeof(struct StmtList_));
temp->next = NULL;
temp->stmt = NULL;
return temp;
}
void AddStmt(char *str, StmtList stmtlist) {
StmtList temp = malloc(sizeof(struct StmtList_));
temp->stmt = str;
temp->next = stmtlist->next;
stmtlist->next = temp;
}
void ClearList(StmtList stmtlist) {
StmtList current = stmtlist->next;
StmtList temp;
while (current != NULL) {
temp = current->next;
free(current);
current = temp;
}
stmtlist->next = NULL;
}
void MergeList(StmtList stmtlist1, StmtList stmtlist2) {
StmtList temp = stmtlist2->next;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = stmtlist1->next;
stmtlist1->next = stmtlist2->next;
}
void WriteList(StmtList stmtlist, char *filename) {
FILE *fp;
fp = fopen(filename, "w");
StmtList Reverse = CreateStmtList();
StmtList temp = stmtlist->next;
while (temp != NULL) {
AddStmt(temp->stmt, Reverse);
temp = temp->next;
}
temp = Reverse->next;
while (temp != NULL) {
printf("%s\n", temp->stmt);
fprintf(fp, "%s\n", temp->stmt);
temp = temp->next;
}
}