summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/util.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/util.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/util.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/noncore/games/sfcave-sdl/util.cpp b/noncore/games/sfcave-sdl/util.cpp
index 86738ad..f73e256 100644
--- a/noncore/games/sfcave-sdl/util.cpp
+++ b/noncore/games/sfcave-sdl/util.cpp
@@ -26,39 +26,50 @@ Uint32 getpixel(SDL_Surface *surface, int x, int y)
26 return p[0] << 16 | p[1] << 8 | p[2]; 26 return p[0] << 16 | p[1] << 8 | p[2];
27 else 27 else
28 return p[0] | p[1] << 8 | p[2] << 16; 28 return p[0] | p[1] << 8 | p[2] << 16;
29 29
30 case 4: 30 case 4:
31 return *(Uint32 *)p; 31 return *(Uint32 *)p;
32 32
33 default: 33 default:
34 return 0; /* shouldn't happen, but avoids warnings */ 34 return 0; /* shouldn't happen, but avoids warnings */
35 } 35 }
36} 36}
37 37
38const char *chooseRandomFile( string path, string fileType ) 38string chooseRandomFile( string path, string fileType )
39{ 39{
40 vector<string> files; 40 vector<string> files;
41 DIR *d = opendir( path.c_str() ); 41 DIR *d = opendir( path.c_str() );
42 if ( !d ) 42 if ( !d )
43 return ""; 43 return "";
44 44
45 struct dirent *item = readdir( d ); 45 struct dirent *item = readdir( d );
46 while ( item ) 46 while ( item )
47 { 47 {
48 string file = string( path ) + item->d_name; 48 string file = string( path ) + item->d_name;
49 49
50 // Rip extension from file 50 // Rip extension from file
51 int pos = file.find( ".", 1 ) + 1; 51 int pos = file.find( ".", 1 ) + 1;
52 string tmp = file.substr( pos ); 52 string tmp = file.substr( pos );
53 printf( "pos = %d, tmp =%s\n", pos, tmp.c_str() );
54 if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) 53 if ( tmp.size() > 0 && fileType.find( tmp ) != -1 )
55 { 54 {
56 printf( "Matching <%s> - %s with <%s>\n", file.substr( pos ).c_str(), file.c_str(), fileType.c_str() );
57 files.push_back( file ); 55 files.push_back( file );
58 } 56 }
59 item = readdir( d ); 57 item = readdir( d );
60 } 58 }
61 59
62 closedir( d ); 60 closedir( d );
63 return files[nextInt( files.size() )].c_str(); 61 return files[nextInt( files.size() )];
62}
63
64
65string getHomeDir()
66{
67 string home;
68#ifdef QWS
69 home = getenv( "HOME" );
70#else
71 home = ".";
72#endif
73
74 return home;
64} 75}