Final malloc work for tonight. Note: BeOS code in do_open() is UNTESTED!

This commit is contained in:
William Kendrick 2003-07-26 11:17:49 +00:00
parent 335cd0bf14
commit 23ed4c11e4
2 changed files with 47 additions and 7 deletions

View file

@ -53,6 +53,9 @@ http://www.newbreedsoftware.com/tuxpaint/
* Removed static "MAX_FILES" limit; now mallocs space for file info. * Removed static "MAX_FILES" limit; now mallocs space for file info.
structures. (Should fix large stack crash on OS X, which is good.) structures. (Should fix large stack crash on OS X, which is good.)
* Fixed bug where ".thumbs" dir wouldn't get generated if it wasn't there
and you went to the 'Open' dialog.
2003.Jun.17 (0.9.11) 2003.Jun.17 (0.9.11)
* Windows bugfixes. * Windows bugfixes.

View file

@ -81,6 +81,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
@ -8459,18 +8460,19 @@ int do_open(int want_new_tool)
{ {
SDL_Surface * img, * img1, * img2; SDL_Surface * img, * img1, * img2;
int things_alloced; int things_alloced;
SDL_Surface * * thumbs; SDL_Surface * * thumbs = NULL;
DIR * d; DIR * d;
struct dirent * f; struct dirent * f;
#ifndef __BEOS__ #ifndef __BEOS__
struct dirent * fs; struct dirent * fs;
#endif #endif
char * dirname, * rfname; char * dirname, * rfname;
char * * d_names, * * d_exts; char * * d_names = NULL, * * d_exts = NULL;
FILE * fi; FILE * fi;
char fname[1024]; char fname[1024];
char * tmp_fname;
int num_files, i, done, update_list, want_erase, cur, which, int num_files, i, done, update_list, want_erase, cur, which,
num_files_in_dir, j; num_files_in_dir, j, res;
SDL_Rect dest; SDL_Rect dest;
SDL_Event event; SDL_Event event;
SDLKey key; SDLKey key;
@ -8505,6 +8507,10 @@ int do_open(int want_new_tool)
things_alloced = 32; things_alloced = 32;
#ifndef __BEOS__ #ifndef __BEOS__
fs = (struct dirent *) malloc(sizeof(struct dirent) * things_alloced); fs = (struct dirent *) malloc(sizeof(struct dirent) * things_alloced);
#else
thumbs = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * things_alloced);
d_names = (char * *) malloc(sizeof(char *) * things_alloced);
d_exts = (char * *) malloc(sizeof(char *) * things_alloced);
#endif #endif
@ -8610,6 +8616,21 @@ int do_open(int want_new_tool)
*dot = '.'; *dot = '.';
num_files_in_dir++; num_files_in_dir++;
if (num_files_in_dir > things_alloced)
{
things_alloced = things_alloced + 32;
thumbs = (SDL_Surface * *)
realloc(thumbs, sizeof(SDL_Surface *) * things_alloced);
d_names = (char * *)
realloc(d_names, sizeof(char *) * things_alloced);
d_exts = (char * *)
realloc(d_exts, sizeof(char *) * things_alloced);
}
} }
} }
} }
@ -8640,9 +8661,6 @@ int do_open(int want_new_tool)
while (f != NULL); while (f != NULL);
printf("num_files_in_dir = %d\n", num_files_in_dir);
fflush(stdout);
thumbs = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * num_files_in_dir); thumbs = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * num_files_in_dir);
d_names = (char * *) malloc(sizeof(char *) * num_files_in_dir); d_names = (char * *) malloc(sizeof(char *) * num_files_in_dir);
d_exts = (char * *) malloc(sizeof(char *) * num_files_in_dir); d_exts = (char * *) malloc(sizeof(char *) * num_files_in_dir);
@ -8739,6 +8757,25 @@ int do_open(int want_new_tool)
{ {
/* No thumbnail - load original: */ /* No thumbnail - load original: */
/* (Make sure we have a .../saved/.thumbs/ directory:) */
tmp_fname = get_fname("saved/.thumbs");
res = mkdir(tmp_fname, 0755);
if (res != 0 && errno != EEXIST)
{
fprintf(stderr,
"\nError: Can't create user data thumbnail directory:\n"
"%s\n"
"The error that occurred was:\n"
"%s\n\n", tmp_fname, strerror(errno));
}
free(tmp_fname);
snprintf(fname, sizeof(fname), "%s/%s", snprintf(fname, sizeof(fname), "%s/%s",
dirname, f->d_name); dirname, f->d_name);
debug(fname); debug(fname);