summaryrefslogtreecommitdiff
path: root/navit/maptool/itembin_buffer.c
blob: 980749539aff115c865e6569971b1fdf466c40a9 (plain)
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
68
69
70
71
72
73
74
75
76
77
/**
 * Navit, a modular navigation system.
 * Copyright (C) 2005-2011 Navit Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */
#include <string.h>
#include <stdlib.h>
#include "maptool.h"
#include "debug.h"


/** Buffer for temporarily storing an item. */
static char misc_item_buffer[20000000];
/** An item_bin for temporary use. */
struct item_bin *tmp_item_bin=(struct item_bin *)(void *)misc_item_buffer;
/** A node_item for temporary use. */
static struct node_item *tmp_node_item=(struct node_item *)(void *)misc_item_buffer;

struct node_item *
read_node_item(FILE *in)
{
	if (fread(tmp_node_item, sizeof(struct node_item), 1, in) != 1)
		return NULL;
	return tmp_node_item;
}

struct item_bin *
read_item(FILE *in)
{
	struct item_bin *ib=(struct item_bin *) misc_item_buffer;
	for (;;) {
		switch (item_bin_read(ib, in)) {
		case 0:
			return NULL;
		case 2:
			dbg_assert((ib->len+1)*4 < sizeof(misc_item_buffer));
			bytes_read+=(ib->len+1)*sizeof(int);
			return ib;
		default:
			continue;
		}
	}
}

struct item_bin *
read_item_range(FILE *in, int *min, int *max)
{
	struct range r;

	if (fread(&r, sizeof(r), 1, in) != 1)
		return NULL;
	*min=r.min;
	*max=r.max;
	return read_item(in);
}

struct item_bin *
init_item(enum item_type type)
{
	struct item_bin *ib=(struct item_bin *) misc_item_buffer;

	item_bin_init(ib, type);
	return ib;
}