4
* ***** BEGIN GPL/BL DUAL 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. The Blender
10
* Foundation also sells licenses for use in proprietary software under
11
* the Blender License. See http://www.blender.org/BL/ for information
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
* The Original Code is Copyright (C) 2004 Blender Foundation
24
* All rights reserved.
26
* The Original Code is: all of this file.
28
* Contributor(s): none yet.
30
* ***** END GPL/BL DUAL LICENSE BLOCK *****
31
* .blend file reading entry point
43
#include "MEM_guardedalloc.h"
45
#include "DNA_listBase.h"
46
#include "DNA_userdef_types.h"
48
#include "BKE_utildefines.h"
49
#include "BKE_global.h"
51
#include "BLO_undofile.h"
53
#include "BLI_blenlib.h"
54
#include "BLI_linklist.h"
58
/* **************** support for memory-write, for undo buffers *************** */
60
/* not memfile itself */
61
void BLO_free_memfile(MemFile *memfile)
65
while( (chunk = (memfile->chunks.first) ) ) {
66
if(chunk->ident==0) MEM_freeN(chunk->buf);
67
BLI_remlink(&memfile->chunks, chunk);
73
/* to keep list of memfiles consistant, 'first' is always first in list */
74
/* result is that 'first' is being freed */
75
void BLO_merge_memfile(MemFile *first, MemFile *second)
77
MemFileChunk *fc, *sc;
79
fc= first->chunks.first;
80
sc= second->chunks.first;
92
BLO_free_memfile(first);
95
static int my_memcmp(int *mem1, int *mem2, int len)
97
register int a= len, *mema= mem1, *memb= mem2;
100
if( *mema != *memb) return 1;
107
void add_memfilechunk(MemFile *compare, MemFile *current, char *buf, unsigned int size)
109
static MemFileChunk *compchunk=NULL;
110
MemFileChunk *curchunk;
112
/* this function inits when compare != NULL or when current==NULL */
114
compchunk= compare->chunks.first;
122
curchunk= MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk");
123
curchunk->size= size;
126
BLI_addtail(¤t->chunks, curchunk);
128
/* we compare compchunk with buf */
130
if(compchunk->size == curchunk->size) {
131
if( my_memcmp((int *)compchunk->buf, (int *)buf, size/4)==0) {
132
curchunk->buf= compchunk->buf;
136
compchunk= compchunk->next;
140
if(curchunk->buf==NULL) {
141
curchunk->buf= MEM_mallocN(size, "Chunk buffer");
142
memcpy(curchunk->buf, buf, size);
143
current->size += size;