home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / configure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  2.8 KB  |  152 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 1998/02/21 14:56:45 david Exp $";
  12.  
  13. jmp_buf jmpbuf;
  14.  
  15. void bus_err()
  16. {
  17.     longjmp(jmpbuf, 1);
  18. }
  19.  
  20. int unaligned_long_ok()
  21. {
  22. #ifdef DJGPP
  23.     return 1;
  24. #else
  25.     long l[2];
  26.  
  27.     if (setjmp(jmpbuf) == 0) {
  28.         signal(SIGBUS, bus_err);
  29.         *((long *) ((char *) l + 1)) = 1;
  30.         signal(SIGBUS, SIG_DFL);
  31.         return 1;
  32.     }
  33.     else {
  34.         signal(SIGBUS, SIG_DFL);
  35.         return 0;
  36.     }
  37. #endif
  38. }
  39.  
  40. int main(void)
  41. {
  42.     FILE *fp;
  43.     char config_filename[256];
  44.     char *home;
  45.  
  46.     char config_version[256];
  47.     char gash[256];
  48.  
  49.     char linux_joystick = 'N';
  50.     char joymouse = 'N';
  51.     char direct_video = 'N';
  52.     char voxware = 'N';
  53.     int allow_unaligned_long = 0;
  54.  
  55.     home = getenv("~");
  56.     if (!home)
  57.         home = getenv("HOME");
  58.     if (!home)
  59.         home = ".";
  60.  
  61. #ifndef DJGPP
  62.     sprintf(config_filename, "%s/.atari800", home);
  63. #else
  64.     sprintf(config_filename, "%s/atari800.cfg", home);
  65. #endif
  66.  
  67.     fp = fopen(config_filename, "r");
  68.     if (fp) {
  69.         char *ptr;
  70.         int len;
  71.  
  72.         printf("\nReading: %s\n\n", config_filename);
  73.  
  74.         fgets(config_version, 256, fp);
  75.         RemoveLF(config_version);
  76.  
  77.         if (strcmp(ATARI_TITLE, config_version) == 0) {
  78.             if (fscanf(fp, "\n%c", &linux_joystick) == 0)
  79.                 linux_joystick = 'N';
  80.  
  81.             if (fscanf(fp, "\n%c\n", &direct_video) == 0)
  82.                 direct_video = 'N';
  83.  
  84.             if (fscanf(fp, "\n%c", &joymouse) == 0)
  85.                 joymouse = 'N';
  86.  
  87.             if (fscanf(fp, "\n%c\n", &voxware) == 0)
  88.                 voxware = 'N';
  89.         }
  90.         else {
  91.             printf("Cannot use this configuration file\n");
  92.         }
  93.  
  94.         fclose(fp);
  95.     }
  96.     YesNo("Enable LINUX Joystick [%c] ", &linux_joystick);
  97.     YesNo("Support for Toshiba Joystick Mouse (Linux SVGALIB Only) [%c] ", &joymouse);
  98.     YesNo("Enable Direct Video Access [%c] ", &direct_video);
  99.     YesNo("Enable Voxware Sound Support (Linux) [%c] ", &voxware);
  100.  
  101.     printf("Testing unaligned long accesses...");
  102.     if ((allow_unaligned_long = unaligned_long_ok())) {
  103.         printf("OK\n");
  104.     }
  105.     else {
  106.         printf("not OK\n");
  107.     }
  108.  
  109.     fp = fopen("config.h", "w");
  110.     if (fp) {
  111.         fprintf(fp, "#ifndef __CONFIG__\n");
  112.         fprintf(fp, "#define __CONFIG__\n");
  113.  
  114.         if (linux_joystick == 'Y')
  115.             fprintf(fp, "#define LINUX_JOYSTICK\n");
  116.  
  117.         if (direct_video == 'Y')
  118.             fprintf(fp, "#define DIRECT_VIDEO\n");
  119.  
  120.         if (joymouse == 'Y')
  121.             fprintf(fp, "#define JOYMOUSE\n");
  122.  
  123.         if (voxware == 'Y')
  124.             fprintf(fp, "#define VOXWARE\n");
  125.  
  126.         if (allow_unaligned_long == 1)
  127.             fprintf(fp, "#define UNALIGNED_LONG_OK\n");
  128.  
  129.         fprintf(fp, "#endif\n");
  130.  
  131.         fclose(fp);
  132.     }
  133.     fp = fopen(config_filename, "w");
  134.     if (fp) {
  135.         printf("\nWriting: %s\n\n", config_filename);
  136.  
  137.         fprintf(fp, "%s\n", ATARI_TITLE);
  138.         fprintf(fp, "%c\n", linux_joystick);
  139.         fprintf(fp, "%c\n", direct_video);
  140.         fprintf(fp, "%c\n", joymouse);
  141.         fprintf(fp, "%c\n", voxware);
  142.  
  143.         fclose(fp);
  144.     }
  145.     else {
  146.         perror(config_filename);
  147.         exit(1);
  148.     }
  149.  
  150.     return 0;
  151. }
  152.