home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 348.lha / chatterbox_v1.0 / sources / config.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  3KB  |  142 lines

  1. /* sound effect gimmick player - config routine */
  2.  
  3. #include <exec/types.h>
  4. #include <functions.h>
  5. #include <exec/memory.h>
  6. #include <exec/nodes.h>
  7. #include <exec/lists.h>
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10.  
  11. #include "assert.h"
  12.  
  13. #include "iff.h"
  14. #include "8svx.h"
  15.  
  16. #include "sample.h"
  17. #include "chatter.h"
  18.  
  19. #define MATCH 0
  20.  
  21. Sample *Load8SVX();
  22.  
  23. int gab_interval = 300;
  24.  
  25. int total_loaded = 0;
  26.  
  27. struct gab_info gab_data[N_GAB_TYPES];
  28.  
  29. int minimum_timer_interval, maximum_timer_interval;
  30.  
  31. int timer_noload = NO;
  32. char timer_loadopt[20];
  33.  
  34. InitGabData()
  35. {
  36.     register int i, j;
  37.  
  38.     for (i = 0; i < N_GAB_TYPES; i++)
  39.     {
  40.         gab_data[i].n_gab_items = 0;
  41.         gab_data[i].next_new_gab_item = 0;
  42.         gab_data[i].next_play_gab_item = 0;
  43.  
  44.         for (j = 0; j < MAX_GAB_ITEMS; j++)
  45.             gab_data[i].Samples[j] = NULL;
  46.     }
  47. }
  48.  
  49. Config()
  50. {
  51.     FILE *fp;
  52.     char s[80];
  53.     int gab_type = -1;
  54.     struct gab_info *gabp;
  55.     int nconverted;
  56.  
  57.      if ((fp = fopen("ChatterBox:config.data","r")) == NULL)
  58.          panic("ChatterBox:config.data config file doesn't exist");
  59.  
  60.     while (fgets(s,80,fp) != NULL)
  61.     {
  62.         s[strlen(s)-1] = '\0';    /* cream the newline */
  63.  
  64.         if (s[0] != ' ')
  65.         {
  66.             if (strncmp(s,"diskin",6) == MATCH)
  67.                 gab_type = GAB_DISKIN;
  68.             else if (strncmp(s,"diskout",7) == MATCH)
  69.                 gab_type = GAB_DISKOUT;
  70.             else if (strncmp(s,"timer",5) == MATCH)
  71.             {
  72.                 gab_type = GAB_EVERY_SO_OFTEN;
  73.  
  74.                  nconverted = sscanf(&s[5],"%s %d %d",timer_loadopt,&minimum_timer_interval,&maximum_timer_interval);
  75.  
  76.                  timer_noload = (strcmp(timer_loadopt,"noload") == MATCH);
  77.  
  78.  
  79.                 if (nconverted != 3)
  80.                     sscanf(&s[6],"%d %d",&minimum_timer_interval,&maximum_timer_interval);
  81.  
  82.                 if ((minimum_timer_interval > maximum_timer_interval) 
  83.                   || (minimum_timer_interval <= 0) || (maximum_timer_interval <= 0))
  84.                 {
  85.                     if ((minimum_timer_interval != 0) || (maximum_timer_interval != 0))
  86.                         printf("config file 'timer' line is bad, using 5 minute default value\n");
  87.                     minimum_timer_interval = maximum_timer_interval = 300;
  88.                 }
  89.             }
  90.             else if (strncmp(s,"preferences",11) == MATCH)
  91.                 gab_type = GAB_NEW_PREFERENCES;
  92.             else if (strncmp(s,"activate",8) == MATCH)
  93.                 gab_type = GAB_WINDOWACTIVE;
  94.             else if (strncmp(s,"deactivate",10) == MATCH)
  95.                 gab_type = GAB_WINDOWINACTIVE;
  96.             else if (strncmp(s,"beep",4) == MATCH)
  97.                 gab_type = GAB_BEEP;
  98.             else
  99.             {
  100.                 printf("'%s' should be 'diskin', 'diskout', 'timer', 'preferences', 'activate',\n",s);
  101.                 printf("'deactivate', or 'beep'\n");
  102.                 gab_type = -1;
  103.             }
  104.         }
  105.         else
  106.         {
  107.             if (gab_type == -1)
  108.             {
  109.                 printf("ignored '%s'",s);
  110.             }
  111.             else
  112.             {
  113.                 gabp = &gab_data[gab_type];
  114.                 if ((gab_type == GAB_EVERY_SO_OFTEN) && (timer_noload == YES))
  115.                 {
  116.                     AddDeferredSound(s);
  117.                 }
  118.                 else if (gabp->next_new_gab_item < MAX_GAB_ITEMS)
  119.                 {
  120.                     gabp->Samples[gabp->next_new_gab_item] = Load8SVX(&s[1]);
  121.  
  122.                     if (gabp->Samples[gabp->next_new_gab_item])
  123.                     {
  124.                         gabp->n_gab_items++;
  125.                         gabp->next_new_gab_item++;
  126.                         total_loaded++;
  127.                     }
  128.                 }
  129.                 else
  130.                 {
  131.                     printf("too many entries for one type, '%s' ignored\n",&s[1]);
  132.                 }
  133.             }
  134.         }
  135.     }
  136.     fclose(fp);
  137.     if (total_loaded == 0)
  138.         panic("no sample files loaded");
  139. }
  140.  
  141. /* end of config.c */
  142.