Reformat code.

This commit is contained in:
2022-05-28 12:10:04 +01:00
parent d393c847b6
commit f939b99be2
12 changed files with 88 additions and 85 deletions

View File

@@ -32,12 +32,12 @@
#ifndef LIBAARUFORMAT_CONTEXT_H #ifndef LIBAARUFORMAT_CONTEXT_H
#define LIBAARUFORMAT_CONTEXT_H #define LIBAARUFORMAT_CONTEXT_H
#include "structs.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "structs.h"
typedef struct aaruformatContext typedef struct aaruformatContext
{ {
uint64_t magic; uint64_t magic;

View File

@@ -37,12 +37,12 @@
#pragma pack(push, 1) #pragma pack(push, 1)
#include "enums.h"
#include <aaru.h> #include <aaru.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "enums.h"
/**Header, at start of file */ /**Header, at start of file */
typedef struct AaruHeader typedef struct AaruHeader
{ {

View File

@@ -30,12 +30,13 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <errno.h> #include <errno.h>
#include <malloc.h> #include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <aaruformat.h>
int aaruf_close(void* context) int aaruf_close(void* context)
{ {
int i; int i;

View File

@@ -30,11 +30,12 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <malloc.h> #include <malloc.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <aaruformat.h>
void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed) void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed)
{ {
Crc64Context* ctx; Crc64Context* ctx;
@@ -53,8 +54,7 @@ void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed)
{ {
uint64_t entry = (uint64_t)i; uint64_t entry = (uint64_t)i;
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++)
if((entry & 1) == 1) if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
entry = (entry >> 1) ^ polynomial;
else else
entry = entry >> 1; entry = entry >> 1;
@@ -92,8 +92,7 @@ uint64_t aaruf_crc64_data(const uint8_t* data, size_t len, uint64_t polynomial,
{ {
uint64_t entry = (uint64_t)i; uint64_t entry = (uint64_t)i;
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++)
if((entry & 1) == 1) if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
entry = (entry >> 1) ^ polynomial;
else else
entry = entry >> 1; entry = entry >> 1;

View File

@@ -30,11 +30,12 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <malloc.h> #include <malloc.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <aaruformat.h>
int32_t aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length) int32_t aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length)
{ {
uint8_t *p, *q, *r, *s, *t, *u, *v, *w; uint8_t *p, *q, *r, *s, *t, *u, *v, *w;

View File

@@ -31,12 +31,13 @@
// ECC algorithm from ECM(c) 2002-2011 Neill Corlett // ECC algorithm from ECM(c) 2002-2011 Neill Corlett
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <malloc.h> #include <malloc.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <aaruformat.h>
void* aaruf_ecc_cd_init() void* aaruf_ecc_cd_init()
{ {
CdEccContext* context; CdEccContext* context;

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/ // ****************************************************************************/
#include <aaru.h> #include <aaru.h>
#include <aaruformat.h> #include <aaruformat.h>
// Converts between image data type and aaru media tag type // Converts between image data type and aaru media tag type

View File

@@ -30,10 +30,11 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <aaruformat.h>
//! Identifies a file as aaruformat, using path //! Identifies a file as aaruformat, using path
/*! /*!
* *

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <malloc.h> #include <malloc.h>
@@ -38,6 +37,8 @@
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <aaruformat.h>
void* aaruf_open(const char* filepath) void* aaruf_open(const char* filepath)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
@@ -318,8 +319,7 @@ void* aaruf_open(const char* filepath)
break; break;
case CdSectorSuffix: case CdSectorSuffix:
case CdSectorSuffixCorrected: case CdSectorSuffixCorrected:
if(idxEntries[i].dataType == CdSectorSuffixCorrected) if(idxEntries[i].dataType == CdSectorSuffixCorrected) ctx->sectorSuffixCorrected = data;
ctx->sectorSuffixCorrected = data;
else else
ctx->sectorSuffix = data; ctx->sectorSuffix = data;
@@ -461,8 +461,7 @@ void* aaruf_open(const char* filepath)
break; break;
} }
if(idxEntries[i].dataType == CdSectorPrefixCorrected) if(idxEntries[i].dataType == CdSectorPrefixCorrected) ctx->sectorPrefixDdt = cdDdt;
ctx->sectorPrefixDdt = cdDdt;
else if(idxEntries[i].dataType == CdSectorSuffixCorrected) else if(idxEntries[i].dataType == CdSectorSuffixCorrected)
ctx->sectorSuffixDdt = cdDdt; ctx->sectorSuffixDdt = cdDdt;
else else

View File

@@ -30,10 +30,11 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
#include <aaruformat.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <aaruformat.h>
int32_t aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length) int32_t aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
@@ -165,7 +166,9 @@ int32_t aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAdd
for(i = 0; i < ctx->numberOfDataTracks; i++) for(i = 0; i < ctx->numberOfDataTracks; i++)
{ {
if(ctx->dataTracks[i].sequence == track) if(ctx->dataTracks[i].sequence == track)
{ return aaruf_read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length); } {
return aaruf_read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length);
}
} }
return AARUF_ERROR_TRACK_NOT_FOUND; return AARUF_ERROR_TRACK_NOT_FOUND;
@@ -233,8 +236,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
case CdMode1: case CdMode1:
memcpy(bareData, data + 16, 2048); memcpy(bareData, data + 16, 2048);
if(ctx->sectorPrefix != NULL) if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
else if(ctx->sectorPrefixDdt != NULL) else if(ctx->sectorPrefixDdt != NULL)
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
@@ -257,8 +259,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
else else
return AARUF_ERROR_REACHED_UNREACHABLE_CODE; return AARUF_ERROR_REACHED_UNREACHABLE_CODE;
if(ctx->sectorSuffix != NULL) if(ctx->sectorSuffix != NULL) memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288);
memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288);
else if(ctx->sectorSuffixDdt != NULL) else if(ctx->sectorSuffixDdt != NULL)
{ {
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
@@ -285,8 +286,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
case CdMode2Formless: case CdMode2Formless:
case CdMode2Form1: case CdMode2Form1:
case CdMode2Form2: case CdMode2Form2:
if(ctx->sectorPrefix != NULL) if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16);
memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16);
else if(ctx->sectorPrefixDdt != NULL) else if(ctx->sectorPrefixDdt != NULL)
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)

View File

@@ -2,13 +2,13 @@
// Created by claunia on 5/10/21. // Created by claunia on 5/10/21.
// //
#include "../include/aaruformat.h"
#include "gtest/gtest.h"
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include "../include/aaruformat.h"
#include "gtest/gtest.h"
#define EXPECTED_CRC64 0xbf09992cc5ede38e #define EXPECTED_CRC64 0xbf09992cc5ede38e
#define EXPECTED_CRC64_15BYTES 0x797F3766FD93975B #define EXPECTED_CRC64_15BYTES 0x797F3766FD93975B
#define EXPECTED_CRC64_31BYTES 0xCD9201905A7937FD #define EXPECTED_CRC64_31BYTES 0xCD9201905A7937FD