1 /* CAVE (Character Animation Viewer for Everyone)
2 Copyright (C) 2001-2002 Ben Kibbey <bjk@arbornet.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 static long framedelim(const char *line
)
36 if (regexec(®ex
, line
, 1, 0, 0) == 0) {
46 SCENE
*readfile(char *filename
)
57 SCENE
*scene
, *snode
, *sprev
;
60 line
= Calloc(1, LINE_MAX
);
63 if ((fp
= gzopen(filename
, "rb")) == NULL
) {
65 if ((fp
= fopen(filename
, "r")) == NULL
) {
72 if ((line
= gzgets(fp
, line
, LINE_MAX
)) == NULL
) {
74 if ((line
= fgets(line
, LINE_MAX
, fp
)) == NULL
) {
80 line
[strlen(line
) - 1] = 0;
81 septop
= (framedelim(line
) != -1) ? 1 : 0;
89 message(NULL
, NULL
, LOADING
, sepfile(filename
));
91 scene
= Calloc(1, sizeof(SCENE
));
93 snode
->frame
= Calloc(1, sizeof(FRAME
));
95 frames
= delaylen
= 0;
98 while ((line
= gzgets(fp
, line
, LINE_MAX
)) != NULL
) {
100 while ((line
= fgets(line
, LINE_MAX
, fp
)) != NULL
) {
102 int len
= strlen(line
) - 1;
105 n
= framedelim(line
);
119 snode
->timepos
= delaylen
;
125 snode
->frameid
= ++frames
;
127 snode
->next
= Calloc(1, sizeof(SCENE
));
131 snode
->frame
= Calloc(1, sizeof(FRAME
));
132 fnode
= snode
->frame
;
137 fnode
->line
= strdup(line
);
138 fnode
->next
= Calloc(1, sizeof(FRAME
));
140 snode
->rows
= ++rows
;
152 snode
->timepos
= delaylen
;
158 snode
->frameid
= ++frames
;
160 snode
->next
= Calloc(1, sizeof(SCENE
));
164 snode
->frame
= Calloc(1, sizeof(FRAME
));
165 fnode
= snode
->frame
;
169 scene
->prev
= snode
->prev
;
179 message(NULL
, NULL
, NULL
);