-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.c
48 lines (42 loc) · 1.01 KB
/
Record.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
#include <string.h>
#include "Record.h"
static void Record_Init(Record*);
Record *new_Record() {
Record *This = malloc(sizeof(Record));
Record_Init(This);
return This;
}
static void Record_Init(Record *This) {
This->fields = NULL;
This->set_leader = Record_set_leader;
This->add_field = Record_add_field;
This->as_text = Record_as_text;
}
void Record_set_leader(Record *This, char leader[]) {
This->leader = leader;
}
void Record_add_field(Record *This, Field *f) {
if ( This->fields == NULL ) {
This->fields = f;
} else {
Field *temp = This->fields;
while ( temp->nxt != NULL ) {
temp = temp->nxt;
}
temp->nxt = f;
}
}
void Record_as_text(Record *This) {
if ( This->fields == NULL ) {
printf("Empty record\n");
} else {
printf("LDR %s\n", This->leader);
Field *tmp = This->fields;
tmp->as_text(tmp);
while ( tmp->nxt != NULL ) {
tmp = tmp->nxt;
tmp->as_text(tmp);
}
printf("\n");
}
}