Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup + optional case bits #27

Merged
merged 9 commits into from
Dec 30, 2019
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Any and all contributions are welcome. Included is also a `cadius.pro` file you

## Changelog

#### 1.4.3
- `os_GetFolderFiles` segfault fixed. Thanks [@beevik](https://github.com/beevik): [#26](https://github.com/mach-kernel/cadius/pull/26)!
- `-C | --no-case-bits` option added to `ADDFILE`, `ADDFOLDER`, `REPLACEFILE`, `CREATEVOLUME`, and `CREATEFOLDER` actions: [#27](https://github.com/mach-kernel/cadius/pull/27).
- Fix warnings.

#### 1.4.2
- `CREATEVOLUME` did not previously allow for the creation of 143kb images. Thanks [@inexorabletash](https://github.com/inexorabletash)!

Expand Down
4 changes: 4 additions & 0 deletions Src/Dc_Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <stdbool.h>

#define MEMORY_INIT 10
#define MEMORY_FREE 11

Expand Down Expand Up @@ -57,6 +59,8 @@ struct parameter
char *folder_path;

int verbose;
bool output_apple_single;
bool zero_case_bits;
};

struct error
Expand Down
15 changes: 12 additions & 3 deletions Src/Dc_Prodos.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static struct sub_directory_header *ODSReadSubDirectoryHeader(unsigned char *);
static void GetAllDirectoryFile(struct prodos_image *);
static void GetOneSubDirectoryFile(struct prodos_image *,char *,struct file_descriptive_entry *);
static void BuildStorageTypeAscii(BYTE,char *,char *);
static void BuildFileTypeAscii(BYTE,WORD,char *);
static void BuildFileTypeAscii(BYTE,char *);
static void BuildAccessAscii(BYTE,char *);
static void BuildLowerCase(char *,WORD,char *);
static int GetFileDataResourceSize(struct prodos_image *,struct file_descriptive_entry *);
Expand Down Expand Up @@ -413,7 +413,7 @@ struct file_descriptive_entry *ODSReadFileDescriptiveEntry(struct prodos_image *

/* Valeurs Ascii */
BuildStorageTypeAscii(file_entry->storage_type,file_entry->storage_type_ascii,file_entry->storage_type_ascii_short);
BuildFileTypeAscii(file_entry->file_type,file_entry->file_aux_type,file_entry->file_type_ascii);
BuildFileTypeAscii(file_entry->file_type,file_entry->file_type_ascii);
BuildAccessAscii(file_entry->access,file_entry->access_ascii);

/* Nom LowerCase */
Expand Down Expand Up @@ -854,7 +854,7 @@ static void BuildStorageTypeAscii(BYTE storage_type, char *ascii_rtn, char *asci
/**************************************************************************/
/* BuildFileTypeAscii() : Construction de la valeur Ascii du File Type. */
/**************************************************************************/
static void BuildFileTypeAscii(BYTE file_type, WORD file_auxtype, char *ascii_rtn)
static void BuildFileTypeAscii(BYTE file_type, char *ascii_rtn)
{
if(file_type == 0x00)
strcpy(ascii_rtn,"UNK");
Expand Down Expand Up @@ -1080,6 +1080,10 @@ static int GetFileDataResourceSize(struct prodos_image *current_image, struct fi
return(1);
}
}
else
{
nb_block = 0;
}

/* On compte tous les blocs à 0 = Sparse */
for(i=0; i<nb_block; i++)
Expand Down Expand Up @@ -1164,6 +1168,11 @@ static int GetFileDataResourceSize(struct prodos_image *current_image, struct fi
return(1);
}
}
else
{
nb_block = 0;
index_block = 0;
}
file_entry->index_block += index_block;

/* Comptabilise les blocs à 0 = Sparse */
Expand Down
2 changes: 1 addition & 1 deletion Src/Dc_Shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ unsigned char *LoadTextFile(char *file_path, int *data_length_rtn)
fseek(fd,0L,SEEK_SET);

/* Allocation mémoire */
data = (unsigned char *) calloc(1,file_size+10);
data = calloc(1,file_size+10);
if(data == NULL)
{
fclose(fd);
Expand Down
15 changes: 8 additions & 7 deletions Src/File_AppleSingle.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "File_AppleSingle.h"
#include "log.h"
#include "os/os.h"

const unsigned int AS_MAGIC = (uint32_t) 0x00051600;
const unsigned static int AS_MAGIC = (uint32_t) 0x00051600;

static uint32_t as_field32(uint32_t num)
{
Expand Down Expand Up @@ -51,7 +52,7 @@ struct as_file_header *ASParseHeader(unsigned char *buf)
* @param entry_buf The entry buffer
* @return
*/
struct as_prodos_info *ASParseProdosEntry(unsigned char *entry_buf, DWORD length)
struct as_prodos_info *ASParseProdosEntry(unsigned char *entry_buf)
{
struct as_prodos_info *prodos_entry = malloc(sizeof(as_prodos_info));
struct as_prodos_info *buf_prodos_entry = (as_prodos_info *) entry_buf;
Expand Down Expand Up @@ -81,7 +82,7 @@ struct as_file_entry *ASGetEntries(struct as_file_header *header, unsigned char
header->num_entries * sizeof(as_file_entry)
);

struct as_file_entry *buf_entries = buf + sizeof(as_file_header);
struct as_file_entry *buf_entries = (as_file_entry *) (buf + sizeof(as_file_header));
memcpy(entries, buf_entries, header->num_entries * sizeof(as_file_entry));

if (IS_LITTLE_ENDIAN)
Expand Down Expand Up @@ -127,7 +128,7 @@ void ASDecorateProdosFileInfo(struct prodos_file *current_file, unsigned char *d
if (prodos_entry->entry_id != prodos_file_info) return;

struct as_prodos_info *info_meta = ASParseProdosEntry(
data + prodos_entry->offset, prodos_entry->length
data + prodos_entry->offset
);

if (!info_meta) return;
Expand Down Expand Up @@ -194,8 +195,8 @@ struct as_from_prodos ASFromProdosFile(struct prodos_file *file)
prodos_info->auxtype = as_field32(file->entry->file_aux_type);

uint32_t payload_size = prodos_entry_offset + sizeof(as_prodos_info);
char *payload = malloc(payload_size);
char *seek = payload;
unsigned char *payload = malloc(payload_size);
unsigned char *seek = payload;

memcpy(seek, as_header, sizeof(as_file_header));
seek += sizeof(as_file_header);
Expand All @@ -216,4 +217,4 @@ struct as_from_prodos ASFromProdosFile(struct prodos_file *file)
as_file.data = payload;

return as_file;
}
}
8 changes: 4 additions & 4 deletions Src/File_AppleSingle.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "Dc_Shared.h"
#include "Dc_Prodos.h"

const unsigned int AS_MAGIC;
const unsigned static int AS_MAGIC;
#define IS_LITTLE_ENDIAN 'APPL' == (uint32_t) 0x4150504C

#pragma pack(push, 1)
Expand Down Expand Up @@ -65,19 +65,19 @@ typedef struct as_prodos_info
typedef struct as_from_prodos
{
uint16_t length;
char *data;
unsigned char *data;
} as_from_prodos;

#pragma pack(pop)

bool ASIsAppleSingle(unsigned char *buf);

struct as_file_header *ASParseHeader(unsigned char *buf);
struct as_prodos_info *ASParseProdosEntry(unsigned char *entry_buf, DWORD length);
struct as_prodos_info *ASParseProdosEntry(unsigned char *entry_buf);
struct as_file_entry *ASGetEntries(struct as_file_header *header, unsigned char *buf);

void ASDecorateDataFork(struct prodos_file *current_file, unsigned char *data, as_file_entry *data_fork_entry);
void ASDeocrateProdosFileInfo(struct prodos_file *current_file, unsigned char *data, as_file_entry *prodos_entry);
void ASDecorateProdosFile(struct prodos_file *current_file, unsigned char *data);

struct as_from_prodos ASFromProdosFile(struct prodos_file *file);
struct as_from_prodos ASFromProdosFile(struct prodos_file *file);
Loading