From 260424f6a60c21485db638393b3f0529cfb4a3f9 Mon Sep 17 00:00:00 2001 From: William Lash Date: Mon, 21 Jan 2019 15:40:46 +0000 Subject: [PATCH] Remove nested functions --- src/sdl/Makefile | 6 ++++-- src/sdl/sf_osfdlg.c | 24 ++++++++++++------------ src/sdl/sf_util.c | 16 ++++++++-------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/sdl/Makefile b/src/sdl/Makefile index 319835e..570005d 100644 --- a/src/sdl/Makefile +++ b/src/sdl/Makefile @@ -2,8 +2,10 @@ SDL_PKGS ?= libpng libjpeg sdl2 SDL2_mixer freetype2 zlib -# Dependency generation requires GCC. +# Dependency generation requires GCC or clang. CC = gcc +#CC = clang + CFLAGS += `pkg-config $(SDL_PKGS) --cflags` SOURCES = sf_fonts.c sf_msg_en.c sf_resource.c sf_util.c \ @@ -33,7 +35,7 @@ clean: %.o: %.c %.o: %.c %.d - $(CC) -MMD -MP $(CFLAGS) -c $< + $(CC) -MMD -MP $(CFLAGS) -fPIC -fpic -c $< $(DEPS):; diff --git a/src/sdl/sf_osfdlg.c b/src/sdl/sf_osfdlg.c index 7c38f82..e4cc82a 100644 --- a/src/sdl/sf_osfdlg.c +++ b/src/sdl/sf_osfdlg.c @@ -501,6 +501,16 @@ STATIC char *resolvedir( char *dir, char *res, int size) return p; } +static void exhaust( ENTRY *e, ENTRY **resp, int *n) + { + if (!e) return; + exhaust(e->left, resp, n); + e->left = *resp; + *resp = e; + (*n)++; + exhaust(e->right, resp, n); + } + STATIC ENTRY * dodir( char *dirname, char *pattern, char *resdir, int size, int *ndirs, int *ntot) { @@ -512,16 +522,6 @@ STATIC ENTRY * dodir( struct stat fst; int n; - void exhaust( ENTRY *e) - { - if (!e) return; - exhaust(e->left); - e->left = res; - res = e; - n++; - exhaust(e->right); - } - //printf("\ndodir\n"); if (!resolvedir(dirname,resdir,size)) return NULL; resdend = resdir+strlen(resdir); @@ -564,9 +564,9 @@ STATIC ENTRY * dodir( *resdend = 0; n = 0; - exhaust(dirs); + exhaust(dirs, &res, &n); *ndirs = n; - exhaust(files); + exhaust(files, &res, &n); *ntot = n; if (res) diff --git a/src/sdl/sf_util.c b/src/sdl/sf_util.c index 17b2a36..89596ab 100644 --- a/src/sdl/sf_util.c +++ b/src/sdl/sf_util.c @@ -883,19 +883,19 @@ char * sf_GetProfileString( const char *sect, const char *id, char * def) #define pshort( b) (((int)((b)[1]) << 8) + (int)((b)[0])) +static unsigned myin( void *d, byte **b){return 0;} +static int myout( void *udata, byte *b, unsigned n) + { + memmove(udata,b,n); udata += n; + return 0; + } + static int myunzip( int csize, byte *cdata, byte *udata) { byte window[32768]; z_stream z; int st; - unsigned myin( void *d, byte **b){return 0;} - int myout( void *d, byte *b, unsigned n) - { - memmove(udata,b,n); udata += n; - return 0; - } - memset(&z,0,sizeof(z)); st = inflateBackInit( &z, 15, window); @@ -905,7 +905,7 @@ static int myunzip( int csize, byte *cdata, byte *udata) z.avail_in = csize; for (;;){ - st = inflateBack( &z, myin, NULL, myout, NULL); + st = inflateBack( &z, myin, NULL, myout, udata); if (st == Z_STREAM_END) break; if (st) return st; } -- 2.34.1