merged a patch from Ricardo Cruz for faster letter loading.
[supertux.git] / src / setup.c
1 /*
2   setup.c
3   
4   Super Tux - Setup
5   
6   by Bill Kendrick
7   bill@newbreedsoftware.com
8   http://www.newbreedsoftware.com/supertux/
9   
10   April 11, 2000 - February 1st, 2004
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <SDL.h>
19 #include <SDL_image.h>
20 #ifndef NOOPENGL
21 #include <SDL_opengl.h>
22 #endif
23
24 #ifdef LINUX
25 #include <pwd.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <dirent.h>
29 #include <ctype.h>
30 #endif
31
32 #include "defines.h"
33 #include "globals.h"
34 #include "setup.h"
35 #include "screen.h"
36 #include "texture.h"
37 #include "menu.h"
38
39 /* Local function prototypes: */
40
41 void seticon(void);
42 void usage(char * prog, int ret);
43
44 /* Does the given file exist and is it accessible? */
45 int faccessible(char *filename)
46 {
47   struct stat filestat;
48   if (stat(filename, &filestat) == -1)
49     return NO;
50   else
51     return YES;
52 }
53
54 /* Can we write to this location? */
55 int fwriteable(char *filename)
56 {
57   FILE* fi;
58   fi = fopen(filename, "wa");
59   if (fi == NULL)
60     {
61       return NO;
62     }
63   return YES;
64 }
65
66 /* Makes sure a directory is created in either the SuperTux base directory or the SuperTux base directory.*/
67 int fcreatedir(char* relative_dir)
68 {
69   char path[1024];
70   snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
71   if(mkdir(path,0755) != 0)
72     {
73       snprintf(path, 1024, "%s/%s/", DATA_PREFIX, relative_dir);
74       if(mkdir(path,0755) != 0)
75         {
76           return NO;
77         }
78       else
79         {
80           return YES;
81         }
82     }
83   else
84     {
85       return YES;
86     }
87 }
88
89 /* Get all names of sub-directories in a certain directory. */
90 /* Returns the number of sub-directories found. */
91 /* Note: The user has to free the allocated space. */
92 char ** dsubdirs(char *rel_path, char* expected_file, int* num)
93 {
94   DIR *dirStructP;
95   struct dirent *direntp;
96   int i = 0;
97   char ** sdirs= NULL;
98   char filename[1024];
99   char path[1024];
100
101   sprintf(path,"%s/%s",st_dir,rel_path);
102   if((dirStructP = opendir(path)) != NULL)
103     {
104       while((direntp = readdir(dirStructP)) != NULL)
105         {
106           char absolute_filename[1024];
107           struct stat buf;
108
109           sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
110           
111           if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
112             {
113               if(expected_file != NULL)
114                 {
115                   sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
116                   if(!faccessible(filename))
117                     continue;
118                 }
119
120               sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
121               sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
122               strcpy(sdirs[i],direntp->d_name);
123               ++i;
124             }
125         }
126       closedir(dirStructP);
127     }
128
129   sprintf(path,"%s/%s",DATA_PREFIX,rel_path);
130   if((dirStructP = opendir(path)) != NULL)
131     {
132       while((direntp = readdir(dirStructP)) != NULL)
133         {
134           char absolute_filename[1024];
135           struct stat buf;
136
137           sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
138
139           if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
140             {
141               if(expected_file != NULL)
142                 {
143                   sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
144                   if(!faccessible(filename))
145                     {
146                       continue;
147                     }
148                   else
149                     {
150                       sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file);
151                       if(faccessible(filename))
152                         continue;
153                     }
154                 }
155
156               sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
157               sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
158               strcpy(sdirs[i],direntp->d_name);
159               ++i;
160             }
161         }
162       closedir(dirStructP);
163     }
164
165   *num = i;
166   return sdirs;
167 }
168
169 void free_strings(char **strings, int num)
170 {
171   int i;
172   for(i=0; i < num; ++i)
173     free(strings[i]);
174 }
175
176 /* --- SETUP --- */
177 /* Set SuperTux configuration and save directories */
178 void st_directory_setup(void)
179 {
180   char *home;
181   char str[1024];
182   /* Get home directory (from $HOME variable)... if we can't determine it,
183      use the current directory ("."): */
184   if (getenv("HOME") != NULL)
185     home = getenv("HOME");
186   else
187     home = ".";
188
189   st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
190                            strlen("/.supertux") + 1));
191   strcpy(st_dir, home);
192   strcat(st_dir, "/.supertux");
193
194   st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
195
196   strcpy(st_save_dir,st_dir);
197   strcat(st_save_dir,"/save");
198
199   /* Create them. In the case they exist they won't destroy anything. */
200 #ifdef LINUX
201
202   mkdir(st_dir, 0755);
203   mkdir(st_save_dir, 0755);
204
205   sprintf(str, "%s/levels", st_dir);
206   mkdir(str, 0755);
207 #else
208   #ifdef WIN32
209
210   mkdir(st_dir);
211   mkdir(st_save_dir);
212   sprintf(str, "%s/levels", st_dir);
213   mkdir(str);
214 #endif
215 #endif
216
217 }
218
219 /* Create and setup menus. */
220 void st_menu(void)
221 {
222
223   menu_init(&main_menu);
224   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Start Game",0,0));
225   menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
226   menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
227   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0));
228   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0));
229
230   menu_init(&options_menu);
231   menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Fullscreen",use_fullscreen,0));
232   if(audio_device == YES)
233     {
234       menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Sound",use_sound,0));
235       menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Music",use_music,0));
236     }
237   else
238     {
239       menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Sound",use_sound,0));
240       menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Music",use_music,0));
241     }
242   menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Show FPS",show_fps,0));
243   menu_additem(&options_menu,menu_item_create(MN_BACK,"Back",0,0));
244
245   menu_init(&leveleditor_menu);
246   menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Return To Level Editor",0,0));
247   menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"New Level",0,0));
248   menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Load Level",0,0));
249   menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Save Level",0,0));
250   menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Quit Level Editor",0,0));
251
252   menu_init(&load_game_menu);
253   menu_additem(&load_game_menu,menu_item_create(MN_LABEL,"Load Game",0,0));
254
255   menu_init(&game_menu);
256   menu_additem(&game_menu,menu_item_create(MN_ACTION,"Return To Game",0,0));
257   menu_additem(&game_menu,menu_item_create(MN_ACTION,"Save Game",0,0));
258   menu_additem(&game_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
259   menu_additem(&game_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
260   menu_additem(&game_menu,menu_item_create(MN_ACTION,"Quit Game",0,0));
261
262   menu_init(&highscore_menu);
263   menu_additem(&highscore_menu,menu_item_create(MN_TEXTFIELD,"Enter your name:",0,0));
264
265 }
266
267 /* Handle changes made to global settings in the options menu. */
268 void process_options_menu(void)
269 {
270   switch (menu_check(&options_menu))
271     {
272     case 0:
273       if(use_fullscreen != options_menu.item[0].toggled)
274         {
275           use_fullscreen = !use_fullscreen;
276           st_video_setup();
277         }
278       break;
279     case 1:
280       if(use_sound != options_menu.item[1].toggled)
281         use_sound = !use_sound;
282       break;
283     case 2:
284       if(use_music != options_menu.item[2].toggled)
285         {
286           if(use_music == YES)
287             {
288               if(playing_music())
289                 {
290                   halt_music();
291                 }
292               use_music = NO;
293             }
294           else
295             {
296               use_music = YES;
297               if (!playing_music())
298                 {
299                   play_current_music();
300                 }
301             }
302         }
303       break;
304     case 3:
305       if(show_fps != options_menu.item[3].toggled)
306         show_fps = !show_fps;
307       break;
308     }
309 }
310
311 void st_general_setup(void)
312 {
313   /* Seed random number generator: */
314
315   srand(SDL_GetTicks());
316
317   /* Load global images: */
318
319   text_load(&black_text,DATA_PREFIX "/images/status/letters-black.png", TEXT_TEXT, 16,18);
320   text_load(&gold_text,DATA_PREFIX "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
321   text_load(&blue_text,DATA_PREFIX "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
322   text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png", TEXT_TEXT, 16,18);
323   text_load(&white_text,DATA_PREFIX "/images/status/letters-white.png", TEXT_TEXT, 16,18);
324   text_load(&white_small_text,DATA_PREFIX "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
325   text_load(&yellow_nums,DATA_PREFIX "/images/status/numbers.png", TEXT_NUM, 32,32);
326
327   /* Load GUI/menu images: */
328   texture_load(&checkbox, DATA_PREFIX "/images/status/checkbox.png", USE_ALPHA);
329   texture_load(&checkbox_checked, DATA_PREFIX "/images/status/checkbox-checked.png", USE_ALPHA);
330   texture_load(&back, DATA_PREFIX "/images/status/back.png", USE_ALPHA);
331   
332   /* Set icon image: */
333
334   seticon();
335   SDL_EnableUNICODE(1);
336
337 }
338
339 void st_general_free(void)
340 {
341
342   /* Free global images: */
343
344   text_free(&black_text);
345   text_free(&gold_text);
346   text_free(&white_text);
347   text_free(&blue_text);
348   text_free(&red_text);
349   text_free(&white_small_text);
350
351   /* Free GUI/menu images: */
352   texture_free(&checkbox);
353   texture_free(&checkbox_checked);
354   texture_free(&back);
355   
356   /* Free menus */
357
358   menu_free(&main_menu);
359   menu_free(&game_menu);
360   menu_free(&options_menu);
361   menu_free(&leveleditor_menu);
362   menu_free(&highscore_menu);
363
364 }
365
366 void st_video_setup(void)
367 {
368
369   if(screen != NULL)
370     SDL_FreeSurface(screen);
371
372   /* Init SDL Video: */
373
374   if (SDL_Init(SDL_INIT_VIDEO) < 0)
375     {
376       fprintf(stderr,
377               "\nError: I could not initialize video!\n"
378               "The Simple DirectMedia error that occured was:\n"
379               "%s\n\n", SDL_GetError());
380       exit(1);
381     }
382
383   /* Open display: */
384
385   if(use_gl)
386     st_video_setup_gl();
387   else
388     st_video_setup_sdl();
389
390   texture_setup();
391
392   /* Set window manager stuff: */
393
394   SDL_WM_SetCaption("Super Tux", "Super Tux");
395
396 }
397
398 void st_video_setup_sdl(void)
399 {
400   SDL_FreeSurface(screen);
401
402   if (use_fullscreen == YES)
403     {
404       screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
405       if (screen == NULL)
406         {
407           fprintf(stderr,
408                   "\nWarning: I could not set up fullscreen video for "
409                   "640x480 mode.\n"
410                   "The Simple DirectMedia error that occured was:\n"
411                   "%s\n\n", SDL_GetError());
412           use_fullscreen = NO;
413         }
414     }
415   else
416     {
417       screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF );
418
419       if (screen == NULL)
420         {
421           fprintf(stderr,
422                   "\nError: I could not set up video for 640x480 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 st_video_setup_gl(void)
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 == YES)
441     {
442       screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL | SDL_OPENGLBLIT ) ; /* | 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 = NO;
451         }
452     }
453   else
454     {
455       screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_OPENGL | SDL_OPENGLBLIT  );
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 st_joystick_setup(void)
487 {
488
489   /* Init Joystick: */
490
491 #ifdef JOY_YES
492   use_joystick = YES;
493
494   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
495     {
496       fprintf(stderr, "Warning: I could not initialize joystick!\n"
497               "The Simple DirectMedia error that occured was:\n"
498               "%s\n\n", SDL_GetError());
499
500       use_joystick = NO;
501     }
502   else
503     {
504       /* Open joystick: */
505
506       if (SDL_NumJoysticks() <= 0)
507         {
508           fprintf(stderr, "Warning: No joysticks are available.\n");
509
510           use_joystick = NO;
511         }
512       else
513         {
514           js = SDL_JoystickOpen(0);
515
516           if (js == NULL)
517             {
518               fprintf(stderr, "Warning: Could not open joystick 1.\n"
519                       "The Simple DirectMedia error that occured was:\n"
520                       "%s\n\n", SDL_GetError());
521
522               use_joystick = NO;
523             }
524           else
525             {
526               /* Check for proper joystick configuration: */
527
528               if (SDL_JoystickNumAxes(js) < 2)
529                 {
530                   fprintf(stderr,
531                           "Warning: Joystick does not have enough axes!\n");
532
533                   use_joystick = NO;
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 = NO;
544                     }
545                 }
546             }
547         }
548     }
549 #endif
550
551 }
552
553 void st_audio_setup(void)
554 {
555
556   /* Init SDL Audio silently even if --disable-sound : */
557
558   if (audio_device == YES)
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 (use_sound == YES || use_music == YES)
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           use_sound = NO;
577           use_music = NO;
578           audio_device = NO;
579         }
580     }
581
582
583   /* Open sound silently regarless the value of "use_sound": */
584
585   if (audio_device == YES)
586     {
587       if (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 ((use_sound == YES) || (use_music == YES))
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           use_sound = NO;
601           use_music = NO;
602           audio_device = NO;
603         }
604     }
605
606 }
607
608
609 /* --- SHUTDOWN --- */
610
611 void st_shutdown(void)
612 {
613   close_audio();
614   SDL_Quit();
615 }
616
617
618 /* --- ABORT! --- */
619
620 void st_abort(char * reason, char * details)
621 {
622   fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
623   st_shutdown();
624   exit(1);
625 }
626
627
628 /* Set Icon (private) */
629
630 void seticon(void)
631 {
632   int masklen;
633   Uint8 * mask;
634   SDL_Surface * icon;
635
636
637   /* Load icon into a surface: */
638
639   icon = IMG_Load(DATA_PREFIX "/images/icon.png");
640   if (icon == NULL)
641     {
642       fprintf(stderr,
643               "\nError: I could not load the icon image: %s\n"
644               "The Simple DirectMedia error that occured was:\n"
645               "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
646       exit(1);
647     }
648
649
650   /* Create mask: */
651
652   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
653   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
654   memset(mask, 0xFF, masklen);
655
656
657   /* Set icon: */
658
659   SDL_WM_SetIcon(icon, mask);
660
661
662   /* Free icon surface & mask: */
663
664   free(mask);
665   SDL_FreeSurface(icon);
666 }
667
668
669 /* Parse command-line arguments: */
670
671 void parseargs(int argc, char * argv[])
672 {
673   int i;
674
675   /* Set defaults: */
676
677
678   debug_mode = NO;
679   use_fullscreen = NO;
680   show_fps = NO;
681   use_gl = NO;
682
683 #ifndef NOSOUND
684
685   use_sound = YES;
686   use_music = YES;
687   audio_device = YES;
688 #else
689
690   use_sound = NO;
691   use_music = NO;
692   audio_device = NO;
693 #endif
694
695   /* Parse arguments: */
696
697   for (i = 1; i < argc; i++)
698     {
699       if (strcmp(argv[i], "--fullscreen") == 0 ||
700           strcmp(argv[i], "-f") == 0)
701         {
702           /* Use full screen: */
703
704           use_fullscreen = YES;
705         }
706       else if (strcmp(argv[i], "--show-fps") == 0)
707         {
708           /* Use full screen: */
709
710           show_fps = YES;
711         }
712       else if (strcmp(argv[i], "--opengl") == 0 ||
713                strcmp(argv[i], "-gl") == 0)
714         {
715 #ifndef NOOPENGL
716           /* Use OpengGL: */
717
718           use_gl = YES;
719 #endif
720
721         }
722       else if (strcmp(argv[i], "--usage") == 0)
723         {
724           /* Show usage: */
725
726           usage(argv[0], 0);
727         }
728       else if (strcmp(argv[i], "--version") == 0)
729         {
730           /* Show version: */
731
732           printf("Super Tux - version " VERSION "\n");
733           exit(0);
734         }
735       else if (strcmp(argv[i], "--disable-sound") == 0)
736         {
737           /* Disable the compiled in sound feature */
738 #ifndef NOSOUND
739           printf("Sounds disabled \n");
740           use_sound = NO;
741 #else
742
743           printf("Warning: Sounds feature is not compiled in \n");
744 #endif
745
746         }
747       else if (strcmp(argv[i], "--disable-music") == 0)
748         {
749           /* Disable the compiled in sound feature */
750 #ifndef NOSOUND
751           printf("Music disabled \n");
752           use_music = NO;
753 #else
754
755           printf("Warning: Music feature is not compiled in \n");
756 #endif
757
758         }
759       else if (strcmp(argv[i], "--debug-mode") == 0)
760         {
761           /* Enable the debug-mode */
762           debug_mode = YES;
763
764         }
765       else if (strcmp(argv[i], "--help") == 0)
766         {         /* Show help: */
767
768           printf("Super Tux " VERSION "\n\n");
769
770           printf("----------  Command-line options  ----------\n\n");
771
772           printf("  --opengl            - If opengl support was compiled in, this will enable the EXPERIMENTAL OpenGL mode.\n\n");
773
774           printf("  --disable-sound     - If sound support was compiled in,  this will\n                        disable sound for this session of the game.\n\n");
775
776           printf("  --disable-music     - Like above, but this will disable music.\n\n");
777
778           printf("  --fullscreen        - Run in fullscreen mode.\n\n");
779
780           printf("  --debug-mode        - Enables the debug-mode, which is useful for developers.\n\n");
781
782           printf("  --help              - Display a help message summarizing command-line\n                        options, license and game controls.\n\n");
783
784           printf("  --usage             - Display a brief message summarizing command-line options.\n\n");
785
786           printf("  --version           - Display the version of SuperTux you're running.\n\n\n");
787
788
789           printf("----------          License       ----------\n\n");
790           printf("  This program comes with ABSOLUTELY NO WARRANTY.\n");
791           printf("  This is free software, and you are welcome to redistribute\n");
792           printf("  or modify it under certain conditions. See the file \n");
793           printf("  \"COPYING.txt\" for more details.\n\n\n");
794
795           printf("----------      Game controls     ----------\n\n");
796           printf("  Please see the file \"README.txt\"\n\n");
797
798           exit(0);
799         }
800       else
801         {
802           /* Unknown - complain! */
803
804           usage(argv[0], 1);
805         }
806     }
807 }
808
809
810 /* Display usage: */
811
812 void usage(char * prog, int ret)
813 {
814   FILE * fi;
815
816
817   /* Determine which stream to write to: */
818
819   if (ret == 0)
820     fi = stdout;
821   else
822     fi = stderr;
823
824
825   /* Display the usage message: */
826
827   fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",
828           prog);
829
830
831   /* Quit! */
832
833   exit(ret);
834 }
835