| 1 |
/* dctrl-tools - Debian control file inspection tools |
| 2 |
Copyright © 2004, 2010 Antti-Juhani Kaijanaho |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 16 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "msg.h" |
| 20 |
#include "para_bundle.h" |
| 21 |
|
| 22 |
void bundle_slurp(struct para_bundle * pb, struct ifile ifi, _Bool reg) |
| 23 |
{ |
| 24 |
int fd = open_ifile(ifi); |
| 25 |
if (fd == -1) { |
| 26 |
record_error(); |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
FSAF * f = fsaf_fdopen(fd, ifi.s); |
| 31 |
if (f == 0) fatal_enomem(0); |
| 32 |
|
| 33 |
struct srcfile * sf = malloc(sizeof *sf); |
| 34 |
if (sf == 0) fatal_enomem(0); |
| 35 |
|
| 36 |
sf->ifi = ifi; |
| 37 |
sf->fd = fd; |
| 38 |
sf->fs = f; |
| 39 |
sf->next = pb->files; |
| 40 |
pb->files = sf; |
| 41 |
|
| 42 |
para_parser_init(&sf->pp, f, false, false, reg); |
| 43 |
while (true) { |
| 44 |
if (pb->num_paras == pb->max_num) { |
| 45 |
size_t max_num = pb->max_num == 0 ? 256 : |
| 46 |
2 * pb->max_num; |
| 47 |
para_t ** paras = realloc(pb->paras, |
| 48 |
max_num |
| 49 |
* sizeof *paras); |
| 50 |
if (paras == 0) fatal_enomem(0); |
| 51 |
pb->max_num = max_num; |
| 52 |
pb->paras = paras; |
| 53 |
} |
| 54 |
assert(pb->num_paras < pb->max_num); |
| 55 |
assert(pb->paras != 0); |
| 56 |
para_t * p = new_para(&pb->pool, &sf->pp); |
| 57 |
if (p == 0) fatal_enomem(0); |
| 58 |
para_parse_next(p); |
| 59 |
if (para_eof(&sf->pp)) break; |
| 60 |
debug("pb->num_paras = %zi", pb->num_paras); |
| 61 |
pb->paras[pb->num_paras++] = p; |
| 62 |
} |
| 63 |
|
| 64 |
// DO NOT CLOSE fsaf -- this makes the whole para_bundle useless! |
| 65 |
// fsaf_close(f); |
| 66 |
close_ifile(ifi, fd); |
| 67 |
} |