aboutsummaryrefslogtreecommitdiff
path: root/src/txtacc.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:21:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:33:34 +0300
commitde3fbe3e8d4dd2a89f7755906d76055784c437cc (patch)
tree65356dd7b5a9010499550c468e960c93515a7e15 /src/txtacc.c
parentf569a6f2628b9ddef4dfb4424aff2dad644a8f19 (diff)
downloadwydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.gz
wydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.bz2
Drop gnulib.
* bootstrap: Rewrite. * bootstrap.conf: Remove. * configure.ac: Remove gl_EARLY/gl_INIT * src/backup.c: New file. * src/txtacc.c (txtacc_finish): Make sure a new entry is appended only once to the list. * (all sources): Use grecs memory allocation functions. * src/wydawca.h" Include fnmatch.h and regex.h (backup_type): New enum. (simple_backup_suffix): New extern. (find_backup_file_name): New proto. * tests/bkupname.c: New file. * tests/backup00.at: New file. * tests/backup01.at: New file. * tests/backup02.at: New file. * tests/backup03.at: New file. * tests/Makefile.am: Add new tests. * tests/testsuite.at: Add new tests. * grecs: Update.
Diffstat (limited to 'src/txtacc.c')
-rw-r--r--src/txtacc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/txtacc.c b/src/txtacc.c
index 91659f6..442e27e 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -25,26 +25,26 @@ struct txtacc_entry
25#define TXTACC_BUFSIZE 1024 25#define TXTACC_BUFSIZE 1024
26#define txtacc_entry_freesize(e) ((e)->size - (e)->len) 26#define txtacc_entry_freesize(e) ((e)->size - (e)->len)
27 27
28struct txtacc 28struct txtacc
29{ 29{
30 struct grecs_list *cur; /* Current build list */ 30 struct grecs_list *cur; /* Current build list */
31 struct grecs_list *mem; /* List of already allocated elements */ 31 struct grecs_list *mem; /* List of already allocated elements */
32}; 32};
33 33
34static struct txtacc_entry * 34static struct txtacc_entry *
35txtacc_alloc_entry (struct grecs_list *list, size_t size) 35txtacc_alloc_entry (struct grecs_list *list, size_t size)
36{ 36{
37 struct txtacc_entry *p = xmalloc (sizeof (*p)); 37 struct txtacc_entry *p = grecs_malloc (sizeof (*p));
38 p->buf = xmalloc (size); 38 p->buf = grecs_malloc (size);
39 p->size = size; 39 p->size = size;
40 p->len = 0; 40 p->len = 0;
41 grecs_list_append (list, p); 41 grecs_list_append (list, p);
42 return p; 42 return p;
43} 43}
44 44
45static struct txtacc_entry * 45static struct txtacc_entry *
46txtacc_cur_entry (struct txtacc *acc) 46txtacc_cur_entry (struct txtacc *acc)
47{ 47{
48 struct txtacc_entry *ent; 48 struct txtacc_entry *ent;
49 49
50 if (grecs_list_size (acc->cur) == 0) 50 if (grecs_list_size (acc->cur) == 0)
@@ -80,25 +80,25 @@ txtacc_entry_free (void *p)
80{ 80{
81 if (p) 81 if (p)
82 { 82 {
83 struct txtacc_entry *ent = p; 83 struct txtacc_entry *ent = p;
84 free (ent->buf); 84 free (ent->buf);
85 free (ent); 85 free (ent);
86 } 86 }
87} 87}
88 88
89struct txtacc * 89struct txtacc *
90txtacc_create () 90txtacc_create ()
91{ 91{
92 struct txtacc *acc = xmalloc (sizeof (*acc)); 92 struct txtacc *acc = grecs_malloc (sizeof (*acc));
93 acc->cur = grecs_list_create (); 93 acc->cur = grecs_list_create ();
94 acc->cur->free_entry = txtacc_entry_free; 94 acc->cur->free_entry = txtacc_entry_free;
95 acc->mem = grecs_list_create (); 95 acc->mem = grecs_list_create ();
96 acc->mem->free_entry = txtacc_entry_free; 96 acc->mem->free_entry = txtacc_entry_free;
97 return acc; 97 return acc;
98} 98}
99 99
100void 100void
101txtacc_free (struct txtacc *acc) 101txtacc_free (struct txtacc *acc)
102{ 102{
103 grecs_list_free (acc->cur); 103 grecs_list_free (acc->cur);
104 grecs_list_free (acc->mem); 104 grecs_list_free (acc->mem);
@@ -128,55 +128,57 @@ txtacc_finish (struct txtacc *acc, int steal)
128 size_t size; 128 size_t size;
129 char *p; 129 char *p;
130 130
131 switch (grecs_list_size (acc->cur)) 131 switch (grecs_list_size (acc->cur))
132 { 132 {
133 case 0: 133 case 0:
134 return NULL; 134 return NULL;
135 135
136 case 1: 136 case 1:
137 txtent = acc->cur->head->data; 137 txtent = acc->cur->head->data;
138 acc->cur->head->data = NULL; 138 acc->cur->head->data = NULL;
139 txtacc_entry_tailor (txtent); 139 txtacc_entry_tailor (txtent);
140 grecs_list_append (acc->mem, txtent);
140 break; 141 break;
141 142
142 default: 143 default:
143 size = 0; 144 size = 0;
144 for (ep = acc->cur->head; ep; ep = ep->next) 145 for (ep = acc->cur->head; ep; ep = ep->next)
145 { 146 {
146 txtent = ep->data; 147 txtent = ep->data;
147 size += txtent->len; 148 size += txtent->len;
148 } 149 }
149 150
150 txtent = txtacc_alloc_entry (acc->mem, size); 151 txtent = txtacc_alloc_entry (acc->mem, size);
151 for (ep = acc->cur->head; ep; ep = ep->next) 152 for (ep = acc->cur->head; ep; ep = ep->next)
152 { 153 {
153 struct txtacc_entry *tp = ep->data; 154 struct txtacc_entry *tp = ep->data;
154 txtacc_entry_append (txtent, tp->buf, tp->len); 155 txtacc_entry_append (txtent, tp->buf, tp->len);
155 } 156 }
156 } 157 }
157 158
158 grecs_list_clear (acc->cur); 159 grecs_list_clear (acc->cur);
159 p = txtent->buf; 160 p = txtent->buf;
160 if (steal) 161 if (steal)
161 free (txtent); 162 {
162 else 163 grecs_list_remove_tail (acc->mem);
163 grecs_list_append (acc->mem, txtent); 164 free (txtent);
165 }
164 return p; 166 return p;
165} 167}
166 168
167void 169void
168txtacc_free_string (struct txtacc *acc, char *str) 170txtacc_free_string (struct txtacc *acc, char *str)
169{ 171{
170 struct grecs_list_entry *ep; 172 struct grecs_list_entry *ep;
171 for (ep = acc->mem->head; ep; ep = ep->next) 173 for (ep = acc->mem->head; ep; ep = ep->next)
172 { 174 {
173 struct txtacc_entry *tp = ep->data; 175 struct txtacc_entry *tp = ep->data;
174 if (tp->buf == str) 176 if (tp->buf == str)
175 { 177 {
176 grecs_list_remove_entry(acc->mem, ep); 178 grecs_list_remove_entry (acc->mem, ep);
177 free (tp->buf); 179 free (tp->buf);
178 return; 180 return;
179 } 181 }
180 } 182 }
181} 183}
182 184

Return to:

Send suggestions and report system problems to the System administrator.