4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2004 Blender Foundation
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
28 * .blend file reading entry point
36 #include "MEM_guardedalloc.h"
38 #include "DNA_listBase.h"
41 #include "BLO_undofile.h"
43 #include "BLI_blenlib.h"
44 #include "BLI_linklist.h"
48 /* **************** support for memory-write, for undo buffers *************** */
50 /* not memfile itself */
51 void BLO_free_memfile(MemFile *memfile)
55 while( (chunk = (memfile->chunks.first) ) ) {
56 if(chunk->ident==0) MEM_freeN(chunk->buf);
57 BLI_remlink(&memfile->chunks, chunk);
63 /* to keep list of memfiles consistent, 'first' is always first in list */
64 /* result is that 'first' is being freed */
65 void BLO_merge_memfile(MemFile *first, MemFile *second)
67 MemFileChunk *fc, *sc;
69 fc= first->chunks.first;
70 sc= second->chunks.first;
82 BLO_free_memfile(first);
85 static int my_memcmp(int *mem1, int *mem2, int len)
87 register int a= len, *mema= mem1, *memb= mem2;
90 if( *mema != *memb) return 1;
97 void add_memfilechunk(MemFile *compare, MemFile *current, char *buf, unsigned int size)
99 static MemFileChunk *compchunk=NULL;
100 MemFileChunk *curchunk;
102 /* this function inits when compare != NULL or when current==NULL */
104 compchunk= compare->chunks.first;
112 curchunk= MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk");
113 curchunk->size= size;
116 BLI_addtail(¤t->chunks, curchunk);
118 /* we compare compchunk with buf */
120 if(compchunk->size == curchunk->size) {
121 if( my_memcmp((int *)compchunk->buf, (int *)buf, size/4)==0) {
122 curchunk->buf= compchunk->buf;
126 compchunk= compchunk->next;
130 if(curchunk->buf==NULL) {
131 curchunk->buf= MEM_mallocN(size, "Chunk buffer");
132 memcpy(curchunk->buf, buf, size);
133 current->size += size;