2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2004 Blender Foundation
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
26 * .blend file reading entry point
29 /** \file blender/blenloader/intern/undofile.c
39 #include "MEM_guardedalloc.h"
41 #include "DNA_listBase.h"
44 #include "BLO_undofile.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_linklist.h"
51 /* **************** support for memory-write, for undo buffers *************** */
53 /* not memfile itself */
54 void BLO_free_memfile(MemFile *memfile)
58 while ( (chunk = (memfile->chunks.first) ) ) {
59 if (chunk->ident == 0) MEM_freeN(chunk->buf);
60 BLI_remlink(&memfile->chunks, chunk);
66 /* to keep list of memfiles consistent, 'first' is always first in list */
67 /* result is that 'first' is being freed */
68 void BLO_merge_memfile(MemFile *first, MemFile *second)
70 MemFileChunk *fc, *sc;
72 fc = first->chunks.first;
73 sc = second->chunks.first;
81 if (fc) fc = fc->next;
82 if (sc) sc = sc->next;
85 BLO_free_memfile(first);
88 static int my_memcmp(const int *mem1, const int *mem2, const int len)
91 register const int *mema = mem1;
92 register const int *memb = mem2;
95 if (*mema != *memb) return 1;
102 void add_memfilechunk(MemFile *compare, MemFile *current, const char *buf, unsigned int size)
104 static MemFileChunk *compchunk = NULL;
105 MemFileChunk *curchunk;
107 /* this function inits when compare != NULL or when current == NULL */
109 compchunk = compare->chunks.first;
112 if (current == NULL) {
117 curchunk = MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk");
118 curchunk->size = size;
119 curchunk->buf = NULL;
121 BLI_addtail(¤t->chunks, curchunk);
123 /* we compare compchunk with buf */
125 if (compchunk->size == curchunk->size) {
126 if (my_memcmp((int *)compchunk->buf, (const int *)buf, size / 4) == 0) {
127 curchunk->buf = compchunk->buf;
131 compchunk = compchunk->next;
135 if (curchunk->buf == NULL) {
136 curchunk->buf = MEM_mallocN(size, "Chunk buffer");
137 memcpy(curchunk->buf, buf, size);
138 current->size += size;