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