Goodbye gettext, Welcome TinyGetText
[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 "../app/globals.h"
47 #include "../app/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 "../app/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   directories();
260   dictionary_manager.add_directory(datadir + "/locale");
261   
262   package_name = _package_name;
263   package_symbol_name = _package_symbol_name;
264   package_version = _package_version;
265 }
266
267 /* --- SETUP --- */
268 /* Set SuperTux configuration and save directories */
269 void Setup::directories()
270 {
271   std::string home;
272   /* Get home directory (from $HOME variable)... if we can't determine it,
273      use the current directory ("."): */
274   if (getenv("HOME") != NULL)
275     home = getenv("HOME");
276   else
277     home = ".";
278
279   st_dir = home + "/." + package_symbol_name;
280
281   /* Remove .supertux config-file from old SuperTux versions */
282   if(FileSystem::faccessible(st_dir))
283     {
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                 }
328               }
329             }
330         }
331 #else
332   datadir = DATA_PREFIX;
333 #endif
334     }
335   printf("Datadir: %s\n", datadir.c_str());
336 }
337
338 void Setup::general(void)
339 {
340   /* Seed random number generator: */
341
342   srand(SDL_GetTicks());
343
344   /* Set icon image: */
345
346   seticon();
347
348   /* Unicode needed for input handling: */
349
350   SDL_EnableUNICODE(1);
351
352   /* Load GUI/menu images: */
353   checkbox = new Surface(datadir + "/images/status/checkbox.png", true);
354   checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true);
355   back = new Surface(datadir + "/images/status/back.png", true);
356   arrow_left = new Surface(datadir + "/images/icons/left.png", true);
357   arrow_right = new Surface(datadir + "/images/icons/right.png", true);
358
359   /* Load the mouse-cursor */
360   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
361   MouseCursor::set_current(mouse_cursor);
362   
363 }
364
365 void Setup::general_free(void)
366 {
367
368   /* Free GUI/menu images: */
369   delete checkbox;
370   delete checkbox_checked;
371   delete back;
372   delete arrow_left;
373   delete arrow_right;
374
375   /* Free mouse-cursor */
376   delete mouse_cursor;
377   
378 }
379
380 void Setup::video(unsigned int screen_w, unsigned int screen_h)
381 {
382   /* Init SDL Video: */
383   if (SDL_Init(SDL_INIT_VIDEO) < 0)
384     {
385       fprintf(stderr,
386               "\nError: I could not initialize video!\n"
387               "The Simple DirectMedia error that occured was:\n"
388               "%s\n\n", SDL_GetError());
389       exit(1);
390     }
391
392   /* Open display: */
393   if(use_gl)
394     video_gl(screen_w, screen_h);
395   else
396     video_sdl(screen_w, screen_h);
397
398   Surface::reload_all();
399
400   /* Set window manager stuff: */
401   SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str());
402 }
403
404 void Setup::video_sdl(unsigned int screen_w, unsigned int screen_h)
405 {
406   if (use_fullscreen)
407     {
408       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
409       if (screen == NULL)
410         {
411           fprintf(stderr,
412                   "\nWarning: I could not set up fullscreen video for "
413                   "800x600 mode.\n"
414                   "The Simple DirectMedia error that occured was:\n"
415                   "%s\n\n", SDL_GetError());
416           use_fullscreen = false;
417         }
418     }
419   else
420     {
421       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
422
423       if (screen == NULL)
424         {
425           fprintf(stderr,
426                   "\nError: I could not set up video for 800x600 mode.\n"
427                   "The Simple DirectMedia error that occured was:\n"
428                   "%s\n\n", SDL_GetError());
429           exit(1);
430         }
431     }
432 }
433
434 void Setup::video_gl(unsigned int screen_w, unsigned int screen_h)
435 {
436 #ifndef NOOPENGL
437
438   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
439   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
440   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
441   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
442   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
443
444   if (use_fullscreen)
445     {
446       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
447       if (screen == NULL)
448         {
449           fprintf(stderr,
450                   "\nWarning: I could not set up fullscreen video for "
451                   "640x480 mode.\n"
452                   "The Simple DirectMedia error that occured was:\n"
453                   "%s\n\n", SDL_GetError());
454           use_fullscreen = false;
455         }
456     }
457   else
458     {
459       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL);
460
461       if (screen == NULL)
462         {
463           fprintf(stderr,
464                   "\nError: I could not set up video for 640x480 mode.\n"
465                   "The Simple DirectMedia error that occured was:\n"
466                   "%s\n\n", SDL_GetError());
467           exit(1);
468         }
469     }
470
471   /*
472    * Set up OpenGL for 2D rendering.
473    */
474   glDisable(GL_DEPTH_TEST);
475   glDisable(GL_CULL_FACE);
476
477   glViewport(0, 0, screen->w, screen->h);
478   glMatrixMode(GL_PROJECTION);
479   glLoadIdentity();
480   glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
481
482   glMatrixMode(GL_MODELVIEW);
483   glLoadIdentity();
484   glTranslatef(0.0f, 0.0f, 0.0f);
485
486 #endif
487
488 }
489
490 void Setup::joystick(void)
491 {
492
493   /* Init Joystick: */
494
495   use_joystick = true;
496
497   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
498     {
499       fprintf(stderr, "Warning: I could not initialize joystick!\n"
500               "The Simple DirectMedia error that occured was:\n"
501               "%s\n\n", SDL_GetError());
502
503       use_joystick = false;
504     }
505   else
506     {
507       /* Open joystick: */
508       if (SDL_NumJoysticks() <= 0)
509         {
510           fprintf(stderr, "Info: No joysticks were found.\n");
511
512           use_joystick = false;
513         }
514       else
515         {
516           js = SDL_JoystickOpen(joystick_num);
517
518           if (js == NULL)
519             {
520               fprintf(stderr, "Warning: Could not open joystick %d.\n"
521                       "The Simple DirectMedia error that occured was:\n"
522                       "%s\n\n", joystick_num, SDL_GetError());
523
524               use_joystick = false;
525             }
526           else
527             {
528               if (SDL_JoystickNumAxes(js) < 2)
529                 {
530                   fprintf(stderr,
531                           "Warning: Joystick does not have enough axes!\n");
532
533                   use_joystick = false;
534                 }
535               else
536                 {
537                   if (SDL_JoystickNumButtons(js) < 2)
538                     {
539                       fprintf(stderr,
540                               "Warning: "
541                               "Joystick does not have enough buttons!\n");
542
543                       use_joystick = false;
544                     }
545                 }
546             }
547         }
548     }
549 }
550
551 void Setup::audio(void)
552 {
553
554   /* Init SDL Audio silently even if --disable-sound : */
555
556   if (SoundManager::get()->audio_device_available())
557     {
558       if (SDL_Init(SDL_INIT_AUDIO) < 0)
559         {
560           /* only print out message if sound or music
561              was not disabled at command-line
562            */
563           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
564             {
565               fprintf(stderr,
566                       "\nWarning: I could not initialize audio!\n"
567                       "The Simple DirectMedia error that occured was:\n"
568                       "%s\n\n", SDL_GetError());
569             }
570           /* keep the programming logic the same :-)
571              because in this case, use_sound & use_music' values are ignored
572              when there's no available audio device
573           */
574           SoundManager::get()->enable_sound(false);
575           SoundManager::get()->enable_music(false);
576           SoundManager::get()->set_audio_device_available(false);
577         }
578     }
579
580
581   /* Open sound silently regarless the value of "use_sound": */
582
583   if (SoundManager::get()->audio_device_available())
584     {
585       if (SoundManager::get()->open_audio(44100, AUDIO_S16, 2, 2048) < 0)
586         {
587           /* only print out message if sound or music
588              was not disabled at command-line
589            */
590           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
591             {
592               fprintf(stderr,
593                       "\nWarning: I could not set up audio for 44100 Hz "
594                       "16-bit stereo.\n"
595                       "The Simple DirectMedia error that occured was:\n"
596                       "%s\n\n", SDL_GetError());
597             }
598           SoundManager::get()->enable_sound(false);
599           SoundManager::get()->enable_music(false);
600           SoundManager::get()->set_audio_device_available(false);
601         }
602     }
603
604 }
605
606
607 /* --- SHUTDOWN --- */
608
609 void Termination::shutdown(void)
610 {
611   config->save();
612   SoundManager::get()->close_audio();
613   SDL_Quit();
614 }
615
616 /* --- ABORT! --- */
617
618 void Termination::abort(const std::string& reason, const std::string& details)
619 {
620   fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
621   shutdown();
622   ::abort();
623 }
624
625 /* Set Icon (private) */
626
627 void seticon(void)
628 {
629 //  int masklen;
630 //  Uint8 * mask;
631   SDL_Surface * icon;
632
633
634   /* Load icon into a surface: */
635
636   icon = IMG_Load((datadir + "/images/" + package_symbol_name + ".xpm").c_str());
637   if (icon == NULL)
638     {
639       fprintf(stderr,
640               "\nError: I could not load the icon image: %s%s\n"
641               "The Simple DirectMedia error that occured was:\n"
642               "%s\n\n", datadir.c_str(), ("/images/" + package_symbol_name + ".xpm").c_str(), SDL_GetError());
643       exit(1);
644     }
645
646
647   /* Create mask: */
648 /*
649   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
650   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
651   memset(mask, 0xFF, masklen);
652 */
653
654   /* Set icon: */
655
656   SDL_WM_SetIcon(icon, NULL);//mask);
657
658
659   /* Free icon surface & mask: */
660
661 //  free(mask);
662   SDL_FreeSurface(icon);
663 }
664
665
666 /* Parse command-line arguments: */
667
668 void Setup::parseargs(int argc, char * argv[])
669 {
670   int i;
671
672   config->load();
673
674   /* Parse arguments: */
675
676   for (i = 1; i < argc; i++)
677     {
678       if (strcmp(argv[i], "--fullscreen") == 0 ||
679           strcmp(argv[i], "-f") == 0)
680         {
681           use_fullscreen = true;
682         }
683       else if (strcmp(argv[i], "--window") == 0 ||
684                strcmp(argv[i], "-w") == 0)
685         {
686           use_fullscreen = false;
687         }
688       else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
689         {
690           assert(i+1 < argc);
691           joystick_num = atoi(argv[++i]);
692         }
693       else if (strcmp(argv[i], "--joymap") == 0)
694         {
695           assert(i+1 < argc);
696           if (sscanf(argv[++i],
697                      "%d:%d:%d:%d:%d", 
698                      &joystick_keymap.x_axis, 
699                      &joystick_keymap.y_axis, 
700                      &joystick_keymap.a_button, 
701                      &joystick_keymap.b_button, 
702                      &joystick_keymap.start_button) != 5)
703             {
704               puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
705             }
706           else
707             {
708               std::cout << "Using new joymap:\n"
709                         << "  X-Axis:       " << joystick_keymap.x_axis << "\n"
710                         << "  Y-Axis:       " << joystick_keymap.y_axis << "\n"
711                         << "  A-Button:     " << joystick_keymap.a_button << "\n"
712                         << "  B-Button:     " << joystick_keymap.b_button << "\n"
713                         << "  Start-Button: " << joystick_keymap.start_button << std::endl;
714             }
715         }
716       else if (strcmp(argv[i], "--leveleditor") == 0)
717         {
718           launch_leveleditor_mode = true;
719         }
720       else if (strcmp(argv[i], "--worldmap") == 0)
721         {
722           launch_worldmap_mode = true;
723         }
724       else if (strcmp(argv[i], "--flip-levels") == 0)
725         {
726           flip_levels_mode = true;
727         }
728       else if (strcmp(argv[i], "--datadir") == 0 
729                || strcmp(argv[i], "-d") == 0 )
730         {
731           assert(i+1 < argc);
732           datadir = argv[++i];
733         }
734       else if (strcmp(argv[i], "--show-fps") == 0)
735         {
736           /* Use full screen: */
737
738           show_fps = true;
739         }
740       else if (strcmp(argv[i], "--opengl") == 0 ||
741                strcmp(argv[i], "-gl") == 0)
742         {
743 #ifndef NOOPENGL
744           /* Use OpengGL: */
745
746           use_gl = true;
747 #endif
748         }
749       else if (strcmp(argv[i], "--sdl") == 0)
750           {
751             use_gl = false;
752           }
753       else if (strcmp(argv[i], "--usage") == 0)
754         {
755           /* Show usage: */
756
757           usage(argv[0], 0);
758         }
759       else if (strcmp(argv[i], "--version") == 0)
760         {
761           /* Show version: */
762           printf((package_name + " " + package_version + "\n").c_str() );
763           exit(0);
764         }
765       else if (strcmp(argv[i], "--disable-sound") == 0)
766         {
767           /* Disable the compiled in sound feature */
768           printf("Sounds disabled \n");
769           SoundManager::get()->enable_sound(false); 
770         }
771       else if (strcmp(argv[i], "--disable-music") == 0)
772         {
773           /* Disable the compiled in sound feature */
774           printf("Music disabled \n");
775           SoundManager::get()->enable_music(false); 
776         }
777       else if (strcmp(argv[i], "--debug") == 0)
778         {
779           /* Enable the debug-mode */
780           debug_mode = true;
781
782         }
783       else if (strcmp(argv[i], "--help") == 0)
784         {     /* Show help: */
785           puts(_(("  SuperTux  " + package_version + "\n"
786                "  Please see the file \"README.txt\" for more details.\n").c_str()));
787           printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
788           puts(_("Display Options:\n"
789                "  -f, --fullscreen    Run in fullscreen mode.\n"
790                "  -w, --window        Run in window mode.\n"
791                "  --opengl            If OpenGL support was compiled in, this will tell\n"
792                "                      SuperTux to make use of it.\n"
793                "  --sdl               Use the SDL software graphical renderer\n"
794                "\n"
795                "Sound Options:\n"
796                "  --disable-sound     If sound support was compiled in,  this will\n"
797                "                      disable sound for this session of the game.\n"
798                "  --disable-music     Like above, but this will disable music.\n"
799                "\n"
800                "Misc Options:\n"
801                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
802                "  --joymap XAXIS:YAXIS:A:B:START\n"
803                "                      Define how joystick buttons and axis should be mapped\n"
804                "  --leveleditor       Opens the leveleditor in a file.\n"
805                "  --worldmap          Opens the specified worldmap file.\n"
806                "  --flip-levels       Flip levels upside-down.\n"
807                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
808                "  --debug             Enables the debug mode, which is useful for developers.\n"
809                "  --help              Display a help message summarizing command-line\n"
810                "                      options, license and game controls.\n"
811                "  --usage             Display a brief message summarizing command-line options.\n"
812                "  --version           Display the version of SuperTux you're running.\n\n"
813                ));
814           exit(0);
815         }
816       else if (argv[i][0] != '-')
817         {
818           level_startup_file = argv[i];
819         }
820       else
821         {
822           /* Unknown - complain! */
823
824           usage(argv[0], 1);
825         }
826     }
827 }
828
829
830 /* Display usage: */
831
832 void usage(char * prog, int ret)
833 {
834   FILE * fi;
835
836
837   /* Determine which stream to write to: */
838
839   if (ret == 0)
840     fi = stdout;
841   else
842     fi = stderr;
843
844
845   /* Display the usage message: */
846
847   fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] [--flip-levels] FILENAME\n"),
848           prog);
849
850
851   /* Quit! */
852
853   exit(ret);
854 }
855
856 std::set<std::string> FileSystem::read_directory(const std::string& pathname)
857 {
858   std::set<std::string> dirnames;
859   
860   DIR* dir = opendir(pathname.c_str());
861   if (dir)
862     {
863       struct dirent *direntp;
864       
865       while((direntp = readdir(dir)))
866         {
867           dirnames.insert(direntp->d_name);
868         }
869       
870       closedir(dir);
871     }
872
873   return dirnames;
874 }
875
876 /* EOF */