fix for sconsfiles
[supertux.git] / lib / app / setup.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //
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.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include <cassert>
23 #include <cstdio>
24 #include <iostream>
25 #include <cstdio>
26 #include <cstdlib>
27 #include <cstring>
28 #include <cerrno>
29 #include <unistd.h>
30
31 #include "SDL.h"
32 #include "SDL_image.h"
33 #ifndef NOOPENGL
34 #include "SDL_opengl.h"
35 #endif
36
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <dirent.h>
40 #ifndef WIN32
41 #include <libgen.h>
42 #endif
43
44 #include <cctype>
45
46 #include "globals.h"
47 #include "setup.h"
48 #include "video/screen.h"
49 #include "video/surface.h"
50 #include "gui/menu.h"
51 #include "utils/configfile.h"
52 #include "audio/sound_manager.h"
53 #include "gettext.h"
54
55 using namespace SuperTux;
56
57 #ifdef WIN32
58 #define mkdir(dir, mode)    mkdir(dir)
59 // on win32 we typically don't want LFS paths
60 #undef DATA_PREFIX
61 #define DATA_PREFIX "./data/"
62 #endif
63
64 /* Local function prototypes: */
65
66 void seticon(void);
67 void usage(char * prog, int ret);
68
69 /* Does the given file exist and is it accessible? */
70 int FileSystem::faccessible(const std::string& filename)
71 {
72   struct stat filestat;
73   if (stat(filename.c_str(), &filestat) == -1)
74     {
75       return false;
76     }
77   else
78     {
79       if(S_ISREG(filestat.st_mode))
80         return true;
81       else
82         return false;
83     }
84 }
85
86 /* Can we write to this location? */
87 int FileSystem::fwriteable(const std::string& filename)
88 {
89   FILE* fi;
90   fi = fopen(filename.c_str(), "wa");
91   if (fi == NULL)
92     {
93       return false;
94     }
95   fclose(fi);
96   return true;
97 }
98
99 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
100 int FileSystem::fcreatedir(const std::string& relative_dir)
101 {
102   std::string path = st_dir + "/" + relative_dir + "/";
103   if(mkdir(path.c_str(),0755) != 0)
104     {
105       path = datadir + "/" + relative_dir + "/";
106       if(mkdir(path.c_str(),0755) != 0)
107         {
108           return false;
109         }
110       else
111         {
112           return true;
113         }
114     }
115   else
116     {
117       return true;
118     }
119 }
120
121 /* Get all names of sub-directories in a certain directory. */
122 /* Returns the number of sub-directories found. */
123 /* Note: The user has to free the allocated space. */
124 std::set<std::string> FileSystem::dsubdirs(const std::string &rel_path,const  std::string& expected_file)
125 {
126   DIR *dirStructP;
127   struct dirent *direntp;
128   std::set<std::string> sdirs;
129   std::string filename;
130   std::string path = st_dir + "/" + rel_path;
131
132   if((dirStructP = opendir(path.c_str())) != NULL)
133     {
134       while((direntp = readdir(dirStructP)) != NULL)
135         {
136           std::string absolute_filename;
137           struct stat buf;
138
139           absolute_filename = path + "/" + direntp->d_name;
140
141           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
142             {
143               if(!expected_file.empty())
144                 {
145                   filename = path + "/" + direntp->d_name + "/" + expected_file;
146                   if(!faccessible(filename))
147                     continue;
148                 }
149
150               sdirs.insert(direntp->d_name);
151             }
152         }
153       closedir(dirStructP);
154     }
155
156   path = datadir + "/" + rel_path;
157   if((dirStructP = opendir(path.c_str())) != NULL)
158     {
159       while((direntp = readdir(dirStructP)) != NULL)
160         {
161           std::string absolute_filename;
162           struct stat buf;
163
164           absolute_filename = path + "/" + direntp->d_name;
165
166           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
167             {
168               if(!expected_file.empty())
169                 {
170                   filename = path + "/" + direntp->d_name + "/" + expected_file;
171                   if(!faccessible(filename.c_str()))
172                     {
173                       continue;
174                     }
175                   else
176                     {
177                       filename = st_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file;
178                       if(faccessible(filename.c_str()))
179                         continue;
180                     }
181                 }
182
183               sdirs.insert(direntp->d_name);
184             }
185         }
186       closedir(dirStructP);
187     }
188
189   return sdirs;
190 }
191
192 std::set<std::string> FileSystem::dfiles(const std::string& rel_path, const  std::string& glob, const  std::string& exception_str)
193 {
194   DIR *dirStructP;
195   struct dirent *direntp;
196   std::set<std::string> sdirs;
197   std::string path = st_dir + "/" + rel_path;
198
199   if((dirStructP = opendir(path.c_str())) != NULL)
200     {
201       while((direntp = readdir(dirStructP)) != NULL)
202         {
203           std::string absolute_filename;
204           struct stat buf;
205
206           absolute_filename = path + "/" + direntp->d_name;
207
208           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
209             {
210               if(!exception_str.empty())
211                 {
212                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
213                     continue;
214                 }
215               if(!glob.empty())
216                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
217                   continue;
218
219               sdirs.insert(direntp->d_name);
220             }
221         }
222       closedir(dirStructP);
223     }
224
225   path = datadir + "/" + rel_path;
226   if((dirStructP = opendir(path.c_str())) != NULL)
227     {
228       while((direntp = readdir(dirStructP)) != NULL)
229         {
230           std::string absolute_filename;
231           struct stat buf;
232
233           absolute_filename = path + "/" + direntp->d_name;
234
235           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
236             {
237               if(!exception_str.empty())
238                 {
239                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
240                     continue;
241                 }
242               if(!glob.empty())
243                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
244                   continue;
245
246               sdirs.insert(direntp->d_name);
247             }
248         }
249       closedir(dirStructP);
250     }
251
252   return sdirs;
253 }
254
255 void Setup::init(const std::string& _package_name,
256         const std::string& _package_symbol_name,
257         const std::string& _package_version)
258 {
259   package_name = _package_name;
260   package_symbol_name = _package_symbol_name;    
261   package_version = _package_version;
262     
263   directories();
264   dictionary_manager.add_directory(datadir + "/locale");
265   dictionary_manager.set_charset("iso8859-1");
266 }
267
268 /* --- SETUP --- */
269 /* Set SuperTux configuration and save directories */
270 void Setup::directories()
271 {
272   std::string home;
273   /* Get home directory (from $HOME variable)... if we can't determine it,
274      use the current directory ("."): */
275   if (getenv("HOME") != NULL)
276     home = getenv("HOME");
277   else
278     home = ".";
279
280   st_dir = home + "/." + package_symbol_name;
281
282   /* Remove .supertux config-file from old SuperTux versions */
283   if(FileSystem::faccessible(st_dir)) {
284     remove(st_dir.c_str());
285   }
286
287   st_save_dir = st_dir + "/save";
288
289   /* Create them. In the case they exist they won't destroy anything. */
290   mkdir(st_dir.c_str(), 0755);
291   mkdir(st_save_dir.c_str(), 0755);
292
293   mkdir((st_dir + "/levels").c_str(), 0755);
294
295   // try current directory as datadir
296   if(datadir.empty()) {
297       if(FileSystem::faccessible("./data/intro.txt"))
298           datadir = "./data/";
299   }
300
301   // User has not that a datadir, so we try some magic
302   if (datadir.empty())
303     {
304 #ifndef WIN32
305       // Detect datadir
306       char exe_file[PATH_MAX];
307       if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
308         {
309           puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
310           datadir = DATA_PREFIX;
311         }
312       else
313         {
314           std::string exedir = std::string(dirname(exe_file)) + "/";
315           
316           datadir = exedir + "../data/"; // SuperTux run from source dir
317           if (access(datadir.c_str(), F_OK) != 0)
318             {
319               datadir = exedir + "../../data/";  //SuperTux run from source dir (with libtool script)
320               
321               if (access(datadir.c_str(), F_OK) != 0)
322               {
323               datadir = exedir + "../share/" + package_symbol_name + "/"; // SuperTux run from PATH
324               if (access(datadir.c_str(), F_OK) != 0) 
325                 { // If all fails, fall back to compiled path
326                   datadir = DATA_PREFIX;
327                   datadir += "/"; 
328                 }
329               }
330             }
331         }
332 #else
333       datadir = DATA_PREFIX;
334       datadir += "/";
335 #endif
336     }
337   printf("Datadir: %s\n", datadir.c_str());
338 }
339
340 void Setup::general(void)
341 {
342   /* Seed random number generator: */
343
344   srand(SDL_GetTicks());
345
346   /* Set icon image: */
347
348   seticon();
349
350   /* Unicode needed for input handling: */
351
352   SDL_EnableUNICODE(1);
353
354   /* Load GUI/menu images: */
355   checkbox = new Surface(datadir + "/images/status/checkbox.png", true);
356   checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true);
357   back = new Surface(datadir + "/images/status/back.png", true);
358   arrow_left = new Surface(datadir + "/images/icons/left.png", true);
359   arrow_right = new Surface(datadir + "/images/icons/right.png", true);
360
361   /* Load the mouse-cursor */
362   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
363   MouseCursor::set_current(mouse_cursor);
364   
365 }
366
367 void Setup::general_free(void)
368 {
369
370   /* Free GUI/menu images: */
371   delete checkbox;
372   delete checkbox_checked;
373   delete back;
374   delete arrow_left;
375   delete arrow_right;
376
377   /* Free mouse-cursor */
378   delete mouse_cursor;
379   
380 }
381
382 void Setup::video(unsigned int screen_w, unsigned int screen_h)
383 {
384   /* Init SDL Video: */
385   if (SDL_Init(SDL_INIT_VIDEO) < 0)
386     {
387       fprintf(stderr,
388               "\nError: I could not initialize video!\n"
389               "The Simple DirectMedia error that occured was:\n"
390               "%s\n\n", SDL_GetError());
391       exit(1);
392     }
393
394   /* Open display: */
395   if(use_gl)
396     video_gl(screen_w, screen_h);
397   else
398     video_sdl(screen_w, screen_h);
399
400   Surface::reload_all();
401
402   /* Set window manager stuff: */
403   SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str());
404 }
405
406 void Setup::video_sdl(unsigned int screen_w, unsigned int screen_h)
407 {
408   if (use_fullscreen)
409     {
410       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
411       if (screen == NULL)
412         {
413           fprintf(stderr,
414                   "\nWarning: I could not set up fullscreen video for "
415                   "800x600 mode.\n"
416                   "The Simple DirectMedia error that occured was:\n"
417                   "%s\n\n", SDL_GetError());
418           use_fullscreen = false;
419         }
420     }
421   else
422     {
423       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
424
425       if (screen == NULL)
426         {
427           fprintf(stderr,
428                   "\nError: I could not set up video for 800x600 mode.\n"
429                   "The Simple DirectMedia error that occured was:\n"
430                   "%s\n\n", SDL_GetError());
431           exit(1);
432         }
433     }
434 }
435
436 void Setup::video_gl(unsigned int screen_w, unsigned int screen_h)
437 {
438 #ifndef NOOPENGL
439
440   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
441   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
442   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
443   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
444   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
445
446   if (use_fullscreen)
447     {
448       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
449       if (screen == NULL)
450         {
451           fprintf(stderr,
452                   "\nWarning: I could not set up fullscreen video for "
453                   "640x480 mode.\n"
454                   "The Simple DirectMedia error that occured was:\n"
455                   "%s\n\n", SDL_GetError());
456           use_fullscreen = false;
457         }
458     }
459   else
460     {
461       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL);
462
463       if (screen == NULL)
464         {
465           fprintf(stderr,
466                   "\nError: I could not set up video for 640x480 mode.\n"
467                   "The Simple DirectMedia error that occured was:\n"
468                   "%s\n\n", SDL_GetError());
469           exit(1);
470         }
471     }
472
473   /*
474    * Set up OpenGL for 2D rendering.
475    */
476   glDisable(GL_DEPTH_TEST);
477   glDisable(GL_CULL_FACE);
478
479   glViewport(0, 0, screen->w, screen->h);
480   glMatrixMode(GL_PROJECTION);
481   glLoadIdentity();
482   glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
483
484   glMatrixMode(GL_MODELVIEW);
485   glLoadIdentity();
486   glTranslatef(0.0f, 0.0f, 0.0f);
487
488 #endif
489
490 }
491
492 void Setup::joystick(void)
493 {
494
495   /* Init Joystick: */
496
497   use_joystick = true;
498
499   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
500     {
501       fprintf(stderr, "Warning: I could not initialize joystick!\n"
502               "The Simple DirectMedia error that occured was:\n"
503               "%s\n\n", SDL_GetError());
504
505       use_joystick = false;
506     }
507   else
508     {
509       /* Open joystick: */
510       if (SDL_NumJoysticks() <= 0)
511         {
512           fprintf(stderr, "Info: No joysticks were found.\n");
513
514           use_joystick = false;
515         }
516       else
517         {
518           js = SDL_JoystickOpen(joystick_num);
519
520           if (js == NULL)
521             {
522               fprintf(stderr, "Warning: Could not open joystick %d.\n"
523                       "The Simple DirectMedia error that occured was:\n"
524                       "%s\n\n", joystick_num, SDL_GetError());
525
526               use_joystick = false;
527             }
528           else
529             {
530               if (SDL_JoystickNumAxes(js) < 2)
531                 {
532                   fprintf(stderr,
533                           "Warning: Joystick does not have enough axes!\n");
534
535                   use_joystick = false;
536                 }
537               else
538                 {
539                   if (SDL_JoystickNumButtons(js) < 2)
540                     {
541                       fprintf(stderr,
542                               "Warning: "
543                               "Joystick does not have enough buttons!\n");
544
545                       use_joystick = false;
546                     }
547                 }
548             }
549         }
550     }
551 }
552
553 void Setup::audio(void)
554 {
555
556   /* Init SDL Audio silently even if --disable-sound : */
557
558   if (SoundManager::get()->audio_device_available())
559     {
560       if (SDL_Init(SDL_INIT_AUDIO) < 0)
561         {
562           /* only print out message if sound or music
563              was not disabled at command-line
564            */
565           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
566             {
567               fprintf(stderr,
568                       "\nWarning: I could not initialize audio!\n"
569                       "The Simple DirectMedia error that occured was:\n"
570                       "%s\n\n", SDL_GetError());
571             }
572           /* keep the programming logic the same :-)
573              because in this case, use_sound & use_music' values are ignored
574              when there's no available audio device
575           */
576           SoundManager::get()->enable_sound(false);
577           SoundManager::get()->enable_music(false);
578           SoundManager::get()->set_audio_device_available(false);
579         }
580     }
581
582
583   /* Open sound silently regarless the value of "use_sound": */
584
585   if (SoundManager::get()->audio_device_available())
586     {
587       if (SoundManager::get()->open_audio(44100, AUDIO_S16, 2, 2048) < 0)
588         {
589           /* only print out message if sound or music
590              was not disabled at command-line
591            */
592           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
593             {
594               fprintf(stderr,
595                       "\nWarning: I could not set up audio for 44100 Hz "
596                       "16-bit stereo.\n"
597                       "The Simple DirectMedia error that occured was:\n"
598                       "%s\n\n", SDL_GetError());
599             }
600           SoundManager::get()->enable_sound(false);
601           SoundManager::get()->enable_music(false);
602           SoundManager::get()->set_audio_device_available(false);
603         }
604     }
605
606 }
607
608
609 /* --- SHUTDOWN --- */
610
611 void Termination::shutdown(void)
612 {
613   config->save();
614   SoundManager::get()->close_audio();
615   SDL_Quit();
616 }
617
618 /* --- ABORT! --- */
619
620 void Termination::abort(const std::string& reason, const std::string& details)
621 {
622   fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
623   shutdown();
624   ::abort();
625 }
626
627 /* Set Icon (private) */
628
629 void seticon(void)
630 {
631 //  int masklen;
632 //  Uint8 * mask;
633   SDL_Surface * icon;
634
635
636   /* Load icon into a surface: */
637
638   icon = IMG_Load((datadir + "/images/" + package_symbol_name + ".xpm").c_str());
639   if (icon == NULL)
640     {
641       fprintf(stderr,
642               "\nError: I could not load the icon image: %s%s\n"
643               "The Simple DirectMedia error that occured was:\n"
644               "%s\n\n", datadir.c_str(), ("/images/" + package_symbol_name + ".xpm").c_str(), SDL_GetError());
645       exit(1);
646     }
647
648
649   /* Create mask: */
650 /*
651   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
652   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
653   memset(mask, 0xFF, masklen);
654 */
655
656   /* Set icon: */
657
658   SDL_WM_SetIcon(icon, NULL);//mask);
659
660
661   /* Free icon surface & mask: */
662
663 //  free(mask);
664   SDL_FreeSurface(icon);
665 }
666
667
668 /* Parse command-line arguments: */
669
670 void Setup::parseargs(int argc, char * argv[])
671 {
672   int i;
673
674   config->load();
675
676   /* Parse arguments: */
677
678   for (i = 1; i < argc; i++)
679     {
680       if (strcmp(argv[i], "--fullscreen") == 0 ||
681           strcmp(argv[i], "-f") == 0)
682         {
683           use_fullscreen = true;
684         }
685       else if (strcmp(argv[i], "--window") == 0 ||
686                strcmp(argv[i], "-w") == 0)
687         {
688           use_fullscreen = false;
689         }
690       else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
691         {
692           assert(i+1 < argc);
693           joystick_num = atoi(argv[++i]);
694         }
695       else if (strcmp(argv[i], "--joymap") == 0)
696         {
697           assert(i+1 < argc);
698           if (sscanf(argv[++i],
699                      "%d:%d:%d:%d:%d", 
700                      &joystick_keymap.x_axis, 
701                      &joystick_keymap.y_axis, 
702                      &joystick_keymap.a_button, 
703                      &joystick_keymap.b_button, 
704                      &joystick_keymap.start_button) != 5)
705             {
706               puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
707             }
708           else
709             {
710               std::cout << "Using new joymap:\n"
711                         << "  X-Axis:       " << joystick_keymap.x_axis << "\n"
712                         << "  Y-Axis:       " << joystick_keymap.y_axis << "\n"
713                         << "  A-Button:     " << joystick_keymap.a_button << "\n"
714                         << "  B-Button:     " << joystick_keymap.b_button << "\n"
715                         << "  Start-Button: " << joystick_keymap.start_button << std::endl;
716             }
717         }
718       else if (strcmp(argv[i], "--leveleditor") == 0)
719         {
720           launch_leveleditor_mode = true;
721         }
722       else if (strcmp(argv[i], "--worldmap") == 0)
723         {
724           launch_worldmap_mode = true;
725         }
726       else if (strcmp(argv[i], "--flip-levels") == 0)
727         {
728           flip_levels_mode = true;
729         }
730       else if (strcmp(argv[i], "--datadir") == 0 
731                || strcmp(argv[i], "-d") == 0 )
732         {
733           assert(i+1 < argc);
734           datadir = argv[++i];
735         }
736       else if (strcmp(argv[i], "--show-fps") == 0)
737         {
738           /* Use full screen: */
739
740           show_fps = true;
741         }
742       else if (strcmp(argv[i], "--opengl") == 0 ||
743                strcmp(argv[i], "-gl") == 0)
744         {
745 #ifndef NOOPENGL
746           /* Use OpengGL: */
747
748           use_gl = true;
749 #endif
750         }
751       else if (strcmp(argv[i], "--sdl") == 0)
752           {
753             use_gl = false;
754           }
755       else if (strcmp(argv[i], "--usage") == 0)
756         {
757           /* Show usage: */
758
759           usage(argv[0], 0);
760         }
761       else if (strcmp(argv[i], "--version") == 0)
762         {
763           /* Show version: */
764           printf((package_name + " " + package_version + "\n").c_str() );
765           exit(0);
766         }
767       else if (strcmp(argv[i], "--disable-sound") == 0)
768         {
769           /* Disable the compiled in sound feature */
770           printf("Sounds disabled \n");
771           SoundManager::get()->enable_sound(false); 
772         }
773       else if (strcmp(argv[i], "--disable-music") == 0)
774         {
775           /* Disable the compiled in sound feature */
776           printf("Music disabled \n");
777           SoundManager::get()->enable_music(false); 
778         }
779       else if (strcmp(argv[i], "--debug") == 0)
780         {
781           /* Enable the debug-mode */
782           debug_mode = true;
783
784         }
785       else if (strcmp(argv[i], "--help") == 0)
786         {     /* Show help: */
787           puts(_(("  SuperTux  " + package_version + "\n"
788                "  Please see the file \"README.txt\" for more details.\n").c_str()));
789           printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
790           puts(_("Display Options:\n"
791                "  -f, --fullscreen    Run in fullscreen mode.\n"
792                "  -w, --window        Run in window mode.\n"
793                "  --opengl            If OpenGL support was compiled in, this will tell\n"
794                "                      SuperTux to make use of it.\n"
795                "  --sdl               Use the SDL software graphical renderer\n"
796                "\n"
797                "Sound Options:\n"
798                "  --disable-sound     If sound support was compiled in,  this will\n"
799                "                      disable sound for this session of the game.\n"
800                "  --disable-music     Like above, but this will disable music.\n"
801                "\n"
802                "Misc Options:\n"
803                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
804                "  --joymap XAXIS:YAXIS:A:B:START\n"
805                "                      Define how joystick buttons and axis should be mapped\n"
806                "  --leveleditor       Opens the leveleditor in a file.\n"
807                "  --worldmap          Opens the specified worldmap file.\n"
808                "  --flip-levels       Flip levels upside-down.\n"
809                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
810                "  --debug             Enables the debug mode, which is useful for developers.\n"
811                "  --help              Display a help message summarizing command-line\n"
812                "                      options, license and game controls.\n"
813                "  --usage             Display a brief message summarizing command-line options.\n"
814                "  --version           Display the version of SuperTux you're running.\n\n"
815                ));
816           exit(0);
817         }
818       else if (argv[i][0] != '-')
819         {
820           level_startup_file = argv[i];
821         }
822       else
823         {
824           /* Unknown - complain! */
825
826           usage(argv[0], 1);
827         }
828     }
829 }
830
831
832 /* Display usage: */
833
834 void usage(char * prog, int ret)
835 {
836   FILE * fi;
837
838
839   /* Determine which stream to write to: */
840
841   if (ret == 0)
842     fi = stdout;
843   else
844     fi = stderr;
845
846
847   /* Display the usage message: */
848
849   fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] [--flip-levels] FILENAME\n"),
850           prog);
851
852
853   /* Quit! */
854
855   exit(ret);
856 }
857
858 std::set<std::string> FileSystem::read_directory(const std::string& pathname)
859 {
860   std::set<std::string> dirnames;
861   
862   DIR* dir = opendir(pathname.c_str());
863   if (dir)
864     {
865       struct dirent *direntp;
866       
867       while((direntp = readdir(dir)))
868         {
869           dirnames.insert(direntp->d_name);
870         }
871       
872       closedir(dir);
873     }
874
875   return dirnames;
876 }
877
878 /* EOF */