-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer.c
67 lines (67 loc) · 1.87 KB
/
buffer.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "buffer.h"
idata *ptr1;
idata *ptr2;
void oinit(ilist *l) {
l -> head = l -> tail = l -> tr = NULL;
}
void opinit(ilist *l) {
l -> tr = l -> tr -> next;
}
void oinsert(ilist *l, idata d) {
inode *tmp;
int i = 0;
tmp = (inode *)malloc(sizeof(inode));
tmp -> d.line = (char *)malloc(sizeof(char)*(d.len + 1));
strcpy(tmp -> d.line, d.line);
tmp -> d.len = d.len;
tmp -> d.b_off = d.b_off;
tmp -> d.f_name = (char *)malloc(strlen(d.f_name) + 1);
strcpy(tmp -> d.f_name, d.f_name);
if(l -> head == NULL) {
l -> head = l -> tail = tmp;
l -> head -> next = NULL;
l -> tr = l -> head;
l -> tr -> next = NULL;
return;
}
l -> tail -> next = tmp;
l -> tail = tmp;
l -> tail -> next = NULL;
}
idata *oprovide(ilist *l) {
int i;
if(l -> tr == NULL) {
ptr2 = NULL;
return ptr2;
}
ptr1 = (idata *)malloc(sizeof(idata));
ptr1 -> line = (char *)malloc(sizeof(char)*(l -> tr -> d.len + 1));
strcpy(ptr1 -> line, l -> tr -> d.line);
ptr1 -> f_name = (char *)malloc(strlen(l -> tr -> d.f_name));
strcpy(ptr1 -> f_name, l -> tr -> d.f_name);
ptr1 -> b_off = l -> tr -> d.b_off;
ptr1 -> len = l -> tr -> d.len;
return ptr1;
}
void odestroy(ilist *l) {
while( l -> head != NULL) {
inode *q;
q = l -> head;
l -> head = l -> head -> next;
free(q -> d.line);
free(q -> d.f_name);
free(q);
q = NULL;
}
}
void oprintlist(ilist *l) {
inode *tmp;
tmp = l -> head;
while(tmp != NULL) {
printf("%s:%d:len = %d:%s:", tmp -> d.f_name, tmp -> d.b_off, tmp -> d.len, tmp -> d.line);
tmp = tmp -> next;
}
}