home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / pufferfish / source / files.c < prev    next >
C/C++ Source or Header  |  1994-03-21  |  3KB  |  160 lines

  1. /*
  2.  * files.c
  3.  *
  4.  * File routines for PufferFish
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <resources/disk.h>
  10.  
  11. #include <clib/asl_protos.h>
  12. #include <clib/disk_protos.h>
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18.  
  19. #include "PufferFish.h"
  20.  
  21. /*
  22.  * find_disk_path()
  23.  *
  24.  * Reads through contents file, line by line, to find a particular
  25.  * disk number.  Called for each disk.
  26.  *
  27.  * Probably (certainly!) not as efficient as it could be.  But it works,
  28.  * even though it ain't pretty.
  29.  *
  30.  * Returns TRUE if disk was found (disk name and path in diskname, diskpath).
  31.  * FALSE otherwise
  32.  *
  33.  */
  34. BOOL find_disk_path( int disknum, char **diskname, char **diskpath )
  35. {
  36.     FILE *contents_file;
  37.     int found_disknum = 0, i;
  38.     BOOL ret = FALSE;
  39.     char read_line[255], disk_num[10], disk_name[255], disk_path[255], *ptr;
  40.     
  41.     if( contents_file = fopen( contentspath, "r" ) )
  42.     {
  43.         while( !feof( contents_file ) && found_disknum < disknum )
  44.         {
  45.             // Read a line of the file
  46.             fgets( read_line, sizeof( read_line ), contents_file );
  47.             ptr = read_line;
  48.             
  49.             // Get disk number
  50.             i = 0;
  51.             while( !isspace( *ptr ) )
  52.             {
  53.                 disk_num[i] = *ptr;
  54.                 *ptr++;
  55.                 i += 1;
  56.             }
  57.             disk_num[i] = '\0';
  58.             found_disknum = atol( disk_num );
  59.             
  60.             // Found the right disk, so get its name & path to its contents
  61.             if( found_disknum == disknum )
  62.             {
  63.                 // Skip whitespace between disk number and disk name
  64.                 while( isspace( *ptr ) )
  65.                 {
  66.                     *ptr++;
  67.                 }
  68.                 
  69.                 // Get disk name
  70.                 i = 0;
  71.                 if( *ptr == '\"' )
  72.                 {
  73.                     do
  74.                     {
  75.                         disk_name[i] = *ptr;
  76.                         *ptr++;
  77.                         i += 1;
  78.                     } while( *ptr != '\"' );
  79.                     disk_name[i] = *ptr;
  80.                     *ptr++;
  81.                     i += 1;
  82.                 }
  83.                 else
  84.                 {
  85.                     while( !isspace( *ptr ) )
  86.                     {
  87.                         disk_name[i] = *ptr;
  88.                         *ptr++;
  89.                         i += 1;
  90.                     }
  91.                 }
  92.                 disk_name[i] = '\0';
  93.                 
  94.                 // Skip whitespace between disk name and path to its contents
  95.                 while( isspace( *ptr ) )
  96.                 {
  97.                     *ptr++;
  98.                 }
  99.                 
  100.                 // Get disk path
  101.                 i = 0;
  102.                 while( !isspace( *ptr ) )
  103.                 {
  104.                     disk_path[i] = *ptr;
  105.                     *ptr++;
  106.                     i += 1;
  107.                 }
  108.                 disk_path[i] = '\0';
  109.                 
  110.                 strcpy( (char *)diskname, disk_name );
  111.                 strcpy( (char *)diskpath, disk_path );
  112.             }
  113.         }
  114.         fclose( contents_file );
  115.     }
  116.     if( found_disknum == disknum )
  117.     {
  118.         ret = TRUE;
  119.     }
  120.     return( ret );
  121. }
  122.  
  123. /*
  124.  * which_disks()
  125.  *
  126.  * Checks which disk drives are present.
  127.  * Returns a bit field indicating available drives.
  128.  * If DF0: doesn't exist, returns 0 (even if there are others)
  129.  *
  130.  * Thanks to Sebastiano Vigna (svigna@bix.com) for the following code!
  131.  *
  132.  * Modified to check for one additional device
  133.  *
  134.  */
  135. unsigned char which_disks(void)
  136. {
  137.     register unsigned char i, result = 0;
  138.     ULONG type;
  139.     
  140.     for(i=0; i<4; i++)
  141.     {
  142.         if ((type = GetUnitID(i)) == DRT_AMIGA || type == DRT_150RPM)
  143.         {
  144.             result |= 1<<i;
  145.         }
  146.     }
  147.     if( additional_device[0] != '\0' )
  148.     {
  149.         result |= 1<<4;
  150.     }
  151.     if (result & 1)
  152.     {
  153.         return(result);
  154.     }
  155.     else
  156.     {
  157.         return(0);
  158.     }
  159. }
  160.