home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / Atari800 / configure.c < prev    next >
C/C++ Source or Header  |  1997-09-30  |  3KB  |  166 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <signal.h>
  6. #include <setjmp.h>
  7.  
  8. #include "atari.h"
  9. #include "prompts.h"
  10.  
  11. static char *rcsid = "$Id: configure.c,v 1.20 1997/09/30 thor,david Exp $";
  12.  
  13. jmp_buf jmpbuf;
  14.  
  15. void
  16. bus_err()
  17. {
  18.   longjmp(jmpbuf, 1);
  19. }
  20.  
  21. int
  22. unaligned_long_ok()
  23. {
  24. #ifdef DJGPP
  25.   return 1;
  26. #else
  27.   long l[2];
  28.  
  29.   if (setjmp(jmpbuf) == 0)
  30.     {
  31.       signal(SIGBUS, bus_err);
  32.       *((long *) ((char *) l + 1)) = 1;
  33.       signal(SIGBUS, SIG_DFL);
  34.       return 1;
  35.     }
  36.   else
  37.     {
  38.       signal(SIGBUS, SIG_DFL);
  39.       return 0;
  40.     }
  41. #endif
  42. }
  43.  
  44. int main (void)
  45. {
  46.   FILE *fp;
  47.   char config_filename[256];
  48.   char *home;
  49.  
  50.   char config_version[256];
  51.  
  52.   char linux_joystick = 'N';
  53.   char joymouse = 'N';
  54.   char direct_video = 'N';
  55.   char voxware = 'N';
  56.   int allow_unaligned_long = 0;
  57.  
  58.   home = getenv ("~");
  59.   if (!home)
  60.     home = getenv ("HOME");
  61.   if (!home)
  62.     home = ".";
  63.  
  64. #ifndef DJGPP
  65.   sprintf (config_filename, "%s/.atari800", home);
  66. #else
  67.   sprintf (config_filename, "%s/atari800.cfg", home);
  68. #endif
  69.  
  70.   fp = fopen (config_filename, "r");
  71.   if (fp)
  72.     {
  73.       printf ("\nReading: %s\n\n", config_filename);
  74.  
  75.       fgets (config_version, 256, fp);
  76.       RemoveLF (config_version);
  77.  
  78.       if (strcmp(ATARI_TITLE, config_version) == 0)
  79.     {
  80.       if (fscanf (fp,"\n%c", &linux_joystick) == 0)
  81.         linux_joystick = 'N';
  82.  
  83.       if (fscanf (fp,"\n%c\n", &direct_video) == 0)
  84.         direct_video = 'N';
  85.  
  86.       if (fscanf (fp,"\n%c", &joymouse) == 0)
  87.         joymouse = 'N';
  88.  
  89.       if (fscanf (fp,"\n%c\n", &voxware) == 0)
  90.         voxware = 'N';
  91.     }
  92.       else
  93.         {
  94.           printf ("Cannot use this configuration file\n");
  95.         }
  96.  
  97.       fclose (fp);
  98.     }
  99.  
  100.   YesNo ("Enable LINUX Joystick [%c] ", &linux_joystick);
  101.   YesNo ("Support for Toshiba Joystick Mouse (Linux SVGALIB Only) [%c] ", &joymouse);
  102. /* Direct Video is no longer supported 
  103.   YesNo ("Enable Direct Video Access [%c] ", &direct_video);
  104. */
  105.   YesNo ("Enable Voxware Sound Support (Linux) [%c] ", &voxware);
  106.  
  107.   printf("Testing unaligned long accesses...");
  108.   if ((allow_unaligned_long = unaligned_long_ok()))
  109.   {
  110.     printf("OK\n");
  111.   }
  112.   else
  113.   {
  114.     printf("not OK\n");
  115.   }
  116.  
  117.   fp = fopen ("config.h", "w");
  118.   if (fp)
  119.     {
  120.       fprintf (fp, "#ifndef __CONFIG__\n");
  121.       fprintf (fp, "#define __CONFIG__\n");
  122.  
  123.       if (linux_joystick == 'Y')
  124.         fprintf (fp, "#define LINUX_JOYSTICK\n");
  125.  
  126. /*
  127.       if (direct_video == 'Y')
  128.         fprintf (fp, "#define DIRECT_VIDEO\n");
  129. */
  130.  
  131.       if (joymouse == 'Y')
  132.         fprintf (fp, "#define JOYMOUSE\n");
  133.  
  134.       if (voxware == 'Y')
  135.         fprintf (fp, "#define VOXWARE\n");
  136.  
  137.       if (allow_unaligned_long == 1)
  138.     fprintf (fp, "#define UNALIGNED_LONG_OK\n");
  139.  
  140.       fprintf (fp, "#endif\n");
  141.  
  142.       fclose (fp);
  143.     }
  144.  
  145.   fp = fopen (config_filename, "w");
  146.   if (fp)
  147.     {
  148.       printf ("\nWriting: %s\n\n", config_filename);
  149.  
  150.       fprintf (fp, "%s\n", ATARI_TITLE);
  151.       fprintf (fp, "%c\n", linux_joystick);
  152.       fprintf (fp, "%c\n", direct_video);
  153.       fprintf (fp, "%c\n", joymouse);
  154.       fprintf (fp, "%c\n", voxware);
  155.  
  156.       fclose (fp);
  157.     }
  158.   else
  159.     {
  160.       perror (config_filename);
  161.       exit (1);
  162.     }
  163.  
  164.   return 0;
  165. }
  166.