home *** CD-ROM | disk | FTP | other *** search
- /*
- * files.c
- *
- * File routines for PufferFish
- *
- */
- #include <exec/types.h>
-
- #include <resources/disk.h>
-
- #include <clib/asl_protos.h>
- #include <clib/disk_protos.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- #include "PufferFish.h"
-
- /*
- * find_disk_path()
- *
- * Reads through contents file, line by line, to find a particular
- * disk number. Called for each disk.
- *
- * Probably (certainly!) not as efficient as it could be. But it works,
- * even though it ain't pretty.
- *
- * Returns TRUE if disk was found (disk name and path in diskname, diskpath).
- * FALSE otherwise
- *
- */
- BOOL find_disk_path( int disknum, char **diskname, char **diskpath )
- {
- FILE *contents_file;
- int found_disknum = 0, i;
- BOOL ret = FALSE;
- char read_line[255], disk_num[10], disk_name[255], disk_path[255], *ptr;
-
- if( contents_file = fopen( contentspath, "r" ) )
- {
- while( !feof( contents_file ) && found_disknum < disknum )
- {
- // Read a line of the file
- fgets( read_line, sizeof( read_line ), contents_file );
- ptr = read_line;
-
- // Get disk number
- i = 0;
- while( !isspace( *ptr ) )
- {
- disk_num[i] = *ptr;
- *ptr++;
- i += 1;
- }
- disk_num[i] = '\0';
- found_disknum = atol( disk_num );
-
- // Found the right disk, so get its name & path to its contents
- if( found_disknum == disknum )
- {
- // Skip whitespace between disk number and disk name
- while( isspace( *ptr ) )
- {
- *ptr++;
- }
-
- // Get disk name
- i = 0;
- if( *ptr == '\"' )
- {
- do
- {
- disk_name[i] = *ptr;
- *ptr++;
- i += 1;
- } while( *ptr != '\"' );
- disk_name[i] = *ptr;
- *ptr++;
- i += 1;
- }
- else
- {
- while( !isspace( *ptr ) )
- {
- disk_name[i] = *ptr;
- *ptr++;
- i += 1;
- }
- }
- disk_name[i] = '\0';
-
- // Skip whitespace between disk name and path to its contents
- while( isspace( *ptr ) )
- {
- *ptr++;
- }
-
- // Get disk path
- i = 0;
- while( !isspace( *ptr ) )
- {
- disk_path[i] = *ptr;
- *ptr++;
- i += 1;
- }
- disk_path[i] = '\0';
-
- strcpy( (char *)diskname, disk_name );
- strcpy( (char *)diskpath, disk_path );
- }
- }
- fclose( contents_file );
- }
- if( found_disknum == disknum )
- {
- ret = TRUE;
- }
- return( ret );
- }
-
- /*
- * which_disks()
- *
- * Checks which disk drives are present.
- * Returns a bit field indicating available drives.
- * If DF0: doesn't exist, returns 0 (even if there are others)
- *
- * Thanks to Sebastiano Vigna (svigna@bix.com) for the following code!
- *
- * Modified to check for one additional device
- *
- */
- unsigned char which_disks(void)
- {
- register unsigned char i, result = 0;
- ULONG type;
-
- for(i=0; i<4; i++)
- {
- if ((type = GetUnitID(i)) == DRT_AMIGA || type == DRT_150RPM)
- {
- result |= 1<<i;
- }
- }
- if( additional_device[0] != '\0' )
- {
- result |= 1<<4;
- }
- if (result & 1)
- {
- return(result);
- }
- else
- {
- return(0);
- }
- }
-