Welcome to mirror list, hosted at ThFree Co, Russian Federation.

undofile.c « intern « blenloader « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c191e48a1432c2a1798cc0a0975c660e4a6e23ac (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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.
 *
 * The Original Code is Copyright (C) 2004 Blender Foundation
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL LICENSE BLOCK *****
 * .blend file reading entry point
 */

/** \file blender/blenloader/intern/undofile.c
 *  \ingroup blenloader
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

#include "MEM_guardedalloc.h"

#include "DNA_listBase.h"

#include "BLI_blenlib.h"

#include "BLO_undofile.h"

/* **************** support for memory-write, for undo buffers *************** */

/* not memfile itself */
void BLO_memfile_free(MemFile *memfile)
{
	MemFileChunk *chunk;
	
	while ((chunk = BLI_pophead(&memfile->chunks))) {
		if (chunk->ident == 0)
			MEM_freeN(chunk->buf);
		MEM_freeN(chunk);
	}
	memfile->size = 0;
}

/* to keep list of memfiles consistent, 'first' is always first in list */
/* result is that 'first' is being freed */
void BLO_memfile_merge(MemFile *first, MemFile *second)
{
	MemFileChunk *fc, *sc;
	
	fc = first->chunks.first;
	sc = second->chunks.first;
	while (fc || sc) {
		if (fc && sc) {
			if (sc->ident) {
				sc->ident = 0;
				fc->ident = 1;
			}
		}
		if (fc) fc = fc->next;
		if (sc) sc = sc->next;
	}
	
	BLO_memfile_free(first);
}

void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsigned int size)
{
	static MemFileChunk *compchunk = NULL;
	MemFileChunk *curchunk;
	
	/* this function inits when compare != NULL or when current == NULL  */
	if (compare) {
		compchunk = compare->chunks.first;
		return;
	}
	if (current == NULL) {
		compchunk = NULL;
		return;
	}
	
	curchunk = MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk");
	curchunk->size = size;
	curchunk->buf = NULL;
	curchunk->ident = 0;
	BLI_addtail(&current->chunks, curchunk);
	
	/* we compare compchunk with buf */
	if (compchunk) {
		if (compchunk->size == curchunk->size) {
			if (memcmp(compchunk->buf, buf, size) == 0) {
				curchunk->buf = compchunk->buf;
				curchunk->ident = 1;
			}
		}
		compchunk = compchunk->next;
	}
	
	/* not equal... */
	if (curchunk->buf == NULL) {
		curchunk->buf = MEM_mallocN(size, "Chunk buffer");
		memcpy(curchunk->buf, buf, size);
		current->size += size;
	}
}