mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-15 09:30:16 +00:00
Refactor disk file_name to a char*
This commit is contained in:
parent
10bb19ecc5
commit
0f9cd3a265
24
src/disk.c
24
src/disk.c
@ -706,17 +706,17 @@ const char *disk6_eject(int drive) {
|
||||
|
||||
const char *err = NULL;
|
||||
|
||||
// foo.dsk -> foo.dsk.gz
|
||||
err = zlib_deflate(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
|
||||
if (err) {
|
||||
ERRLOG("OOPS: An error occurred when attempting to compress a disk image : %s", err);
|
||||
} else {
|
||||
unlink(disk6.disk[drive].file_name);
|
||||
}
|
||||
|
||||
disk6.disk[drive].nibblized = 0;
|
||||
sprintf(disk6.disk[drive].file_name, "%s", "");
|
||||
if (disk6.disk[drive].fp) {
|
||||
// foo.dsk -> foo.dsk.gz
|
||||
err = zlib_deflate(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
|
||||
if (err) {
|
||||
ERRLOG("OOPS: An error occurred when attempting to compress a disk image : %s", err);
|
||||
} else {
|
||||
unlink(disk6.disk[drive].file_name);
|
||||
}
|
||||
FREE(disk6.disk[drive].file_name);
|
||||
|
||||
fflush(disk6.disk[drive].fp);
|
||||
fclose(disk6.disk[drive].fp);
|
||||
disk6.disk[drive].fp = NULL;
|
||||
@ -745,19 +745,15 @@ const char *disk6_insert(int drive, const char * const raw_file_name, int readon
|
||||
if (unlink(file_name)) { // temporarily remove .gz file
|
||||
ERRLOG("OOPS, cannot unlink %s", file_name);
|
||||
}
|
||||
|
||||
cut_gz(file_name);
|
||||
}
|
||||
|
||||
strncpy(disk6.disk[drive].file_name, file_name, FILE_NAME_SZ-1);
|
||||
disk6.disk[drive].file_name[FILE_NAME_SZ-1] = '\0';
|
||||
disk6.disk[drive].file_name = file_name;
|
||||
disk6.disk[drive].nibblized = is_nib(file_name);
|
||||
disk6.disk[drive].skew_table = skew_table_6_do;
|
||||
if (is_po(file_name)) {
|
||||
disk6.disk[drive].skew_table = skew_table_6_po;
|
||||
}
|
||||
FREE(file_name);
|
||||
file_name = NULL;
|
||||
|
||||
if (disk6.disk[drive].fp) {
|
||||
fclose(disk6.disk[drive].fp);
|
||||
|
@ -39,7 +39,6 @@
|
||||
#define NIB_SEC_SIZE (NIB_TRACK_SIZE/NUM_SECTORS)
|
||||
|
||||
#define DSK_VOLUME 254
|
||||
#define FILE_NAME_SZ (PATH_MAX>>2)
|
||||
|
||||
#define DISK_EXT_DSK ".dsk"
|
||||
#define _DSKLEN (sizeof(DISK_EXT_DSK)-1)
|
||||
@ -54,7 +53,7 @@
|
||||
|
||||
typedef struct diskette_t {
|
||||
uint8_t track_image[NIB_TRACK_SIZE];
|
||||
char file_name[FILE_NAME_SZ];
|
||||
char *file_name;
|
||||
bool nibblized;
|
||||
bool is_protected;
|
||||
bool track_valid;
|
||||
|
@ -261,7 +261,7 @@ static int disk_select(const struct dirent *e) {
|
||||
strncat(cmp, e->d_name, PATH_MAX-1);
|
||||
|
||||
/* don't show disk in alternate drive */
|
||||
if (!strcmp(cmp, disk6.disk[altdrive].file_name)) {
|
||||
if (disk6.disk[altdrive].file_name && !strcmp(cmp, disk6.disk[altdrive].file_name)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ void c_interface_select_diskette( int drive )
|
||||
{
|
||||
snprintf(temp, PATH_MAX, "%s/%s",
|
||||
disk_path, namelist[ent_no]->d_name);
|
||||
if (!strcmp(temp, disk6.disk[drive].file_name))
|
||||
if (disk6.disk[drive].file_name && !strcmp(temp, disk6.disk[drive].file_name))
|
||||
{
|
||||
in_drive = 1;
|
||||
}
|
||||
@ -578,12 +578,19 @@ void c_interface_select_diskette( int drive )
|
||||
}
|
||||
else if ((ch == 13) || (toupper(ch) == 'W'))
|
||||
{
|
||||
if (disk_path) {
|
||||
size_t pathlen = strlen(disk_path);
|
||||
if (pathlen && disk_path[pathlen-1] == '/') {
|
||||
disk_path[pathlen-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(temp, PATH_MAX, "%s/%s",
|
||||
disk_path, namelist[ curpos ]->d_name );
|
||||
size_t len = strlen(disk_path);
|
||||
|
||||
/* handle disk currently in the drive */
|
||||
if (!strcmp(temp, disk6.disk[drive].file_name))
|
||||
if (disk6.disk[drive].file_name && !strcmp(temp, disk6.disk[drive].file_name))
|
||||
{
|
||||
/* reopen disk, forcing write enabled */
|
||||
if (toupper(ch) == 'W')
|
||||
|
@ -1035,7 +1035,7 @@ void show_disk_info() {
|
||||
|
||||
/* drive / image specific information */
|
||||
memset(second_buf[i], ' ', BUF_X);
|
||||
if ((len = strlen(disk6.disk[0].file_name)))
|
||||
if (disk6.disk[0].file_name && (len = strlen(disk6.disk[0].file_name)))
|
||||
{
|
||||
while ((--len) && (disk6.disk[0].file_name[len] != '/'))
|
||||
{
|
||||
@ -1045,7 +1045,7 @@ void show_disk_info() {
|
||||
*(second_buf[i] + sprintf(second_buf[i], "%s", tmp)) = ' ';
|
||||
}
|
||||
|
||||
if ((len = strlen(disk6.disk[1].file_name)))
|
||||
if (disk6.disk[1].file_name && (len = strlen(disk6.disk[1].file_name)))
|
||||
{
|
||||
while ((--len) && (disk6.disk[1].file_name[len] != '/'))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user