mirror of
https://github.com/ErnyTech/Open-USB-Extreme
synced 2025-01-14 12:37:33 +01:00
Rename variables in D style
This commit is contained in:
parent
009f094c01
commit
4caee1c98f
@ -3,8 +3,8 @@ import core.stdc.stdlib;
|
||||
import usbextreme;
|
||||
|
||||
extern(C) int main(int argc, char[]* argv) {
|
||||
usb_extreme_headers headers;
|
||||
usb_extreme_filestat[10] filestatsBuf = void;
|
||||
UsbExtremeHeaders headers;
|
||||
UsbExtremeFilestat[10] filestatsBuf = void;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: open-usbextreme-example <path/to/ul.cfg>\n");
|
||||
|
@ -5,8 +5,8 @@ enum USBEXTREME_NAME_LENGTH = 32;
|
||||
enum USBEXTREME_ID_LENGTH = 15;
|
||||
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
||||
enum USBEXTREME_MAGIC = 8;
|
||||
enum USBEXTREME_HEADER_SIZE = usb_extreme_base.sizeof;
|
||||
align (1) struct usb_extreme_base
|
||||
enum USBEXTREME_HEADER_SIZE = UsbExtremeBase.sizeof;
|
||||
align (1) struct UsbExtremeBase
|
||||
{
|
||||
align (1)
|
||||
{
|
||||
@ -15,7 +15,7 @@ align (1) struct usb_extreme_base
|
||||
uint8_t[10] empty2;
|
||||
}
|
||||
}
|
||||
align (1) struct usb_extreme_v0
|
||||
align (1) struct UsbExtremeV0
|
||||
{
|
||||
align (1)
|
||||
{
|
||||
@ -28,7 +28,7 @@ align (1) struct usb_extreme_v0
|
||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||
}
|
||||
}
|
||||
align (1) struct usb_extreme_v1
|
||||
align (1) struct UsbExtremeV1
|
||||
{
|
||||
align (1)
|
||||
{
|
||||
@ -37,28 +37,28 @@ align (1) struct usb_extreme_v1
|
||||
uint8_t n_parts;
|
||||
uint8_t type;
|
||||
uint16_t size;
|
||||
uint8_t video_mode;
|
||||
uint8_t usb_extreme_version;
|
||||
uint8_t videoMode;
|
||||
uint8_t usbExtremeVersion;
|
||||
uint8_t magic;
|
||||
char[USBEXTREME_NAME_EXT_LENGTH] name_ext;
|
||||
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||
}
|
||||
}
|
||||
struct usb_extreme_headers
|
||||
struct UsbExtremeHeaders
|
||||
{
|
||||
const(void)* first_header;
|
||||
const(usb_extreme_base)[] headers;
|
||||
int num_headers;
|
||||
size_t headerslen;
|
||||
const(void)* firstHeader;
|
||||
const(UsbExtremeBase)[] headers;
|
||||
int numHeaders;
|
||||
size_t headersLen;
|
||||
UsbExtremeVersion oueVersion;
|
||||
}
|
||||
struct usb_extreme_filestat
|
||||
struct UsbExtremeFilestat
|
||||
{
|
||||
int offset;
|
||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||
SCECdvdMediaType type;
|
||||
uint16_t size;
|
||||
uint8_t video_mode;
|
||||
UsbExtremeVersion usb_extreme_version;
|
||||
uint8_t videoMode;
|
||||
UsbExtremeVersion usbExtremeVersion;
|
||||
}
|
||||
enum UsbExtremeVersion
|
||||
{
|
||||
@ -87,10 +87,10 @@ enum SCECdvdMediaType
|
||||
extern (D) bool isOue(const(void)[] headers);
|
||||
extern (D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion);
|
||||
extern (D) int oueNumHeaders(const(void)[] headers);
|
||||
extern (D) int ouePointHeaders(ref const(usb_extreme_base)[] headers, const(void)[] raw_headers);
|
||||
extern (D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders);
|
||||
extern (D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers);
|
||||
extern (D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_headers);
|
||||
extern (D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const(usb_extreme_headers) headers);
|
||||
extern (D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders);
|
||||
extern (D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers);
|
||||
private R[] castArray(R, T)(T[] array)
|
||||
{
|
||||
auto ptr = array.ptr;
|
||||
|
30
lib/cabi.d
30
lib/cabi.d
@ -2,28 +2,28 @@ module cabi;
|
||||
import std.stdint;
|
||||
import usbextreme;
|
||||
|
||||
extern(C) int is_oue(const(void)* headers, size_t headerslen) {
|
||||
return isOue(headers[0..headerslen]);
|
||||
extern(C) int is_oue(const(void)* headers, size_t headersLen) {
|
||||
return isOue(headers[0..headersLen]);
|
||||
}
|
||||
|
||||
extern(C) UsbExtremeVersion get_version(uint8_t usbExtremeVersion) {
|
||||
return getVersion(usbExtremeVersion);
|
||||
}
|
||||
|
||||
extern(C) int oue_num_headers(int *num_headers, const(void) *headers, size_t headerslen) {
|
||||
auto result = oueNumHeaders(headers[0..headerslen]);
|
||||
*num_headers = result;
|
||||
extern(C) int oue_num_headers(int *numHeaders, const(void) *headers, size_t headersLen) {
|
||||
auto result = oueNumHeaders(headers[0..headersLen]);
|
||||
*numHeaders = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
extern(C) int oue_point_headers(const(usb_extreme_base)** headers, const(void)* raw_headers, size_t headerslen) {
|
||||
auto len = headerslen / usb_extreme_base.sizeof;
|
||||
const(usb_extreme_base)[] headersArr = (*headers)[0..len];
|
||||
return ouePointHeaders(headersArr, raw_headers[0..headerslen]);
|
||||
extern(C) int oue_point_headers(const(UsbExtremeBase)** headers, const(void)* rawHeaders, size_t headersLen) {
|
||||
auto len = headersLen / UsbExtremeBase.sizeof;
|
||||
const(UsbExtremeBase)[] headersArr = (*headers)[0..len];
|
||||
return ouePointHeaders(headersArr, rawHeaders[0..headersLen]);
|
||||
}
|
||||
|
||||
extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, size_t headerslen) {
|
||||
auto result = oueHeadersVersion(headers[0..headerslen]);
|
||||
extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, size_t headersLen) {
|
||||
auto result = oueHeadersVersion(headers[0..headersLen]);
|
||||
|
||||
if (result == UsbExtremeVersion.Unknown) {
|
||||
return -1;
|
||||
@ -33,11 +33,11 @@ extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, s
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern(C) int oue_read_headers(usb_extreme_headers* headers, const(void)* raw_headers, size_t headerslen) {
|
||||
return oueReadHeaders(*headers, raw_headers[0..headerslen]);
|
||||
extern(C) int oue_read_headers(UsbExtremeHeaders* headers, const(void)* rawHeaders, size_t headersLen) {
|
||||
return oueReadHeaders(*headers, rawHeaders[0..headersLen]);
|
||||
}
|
||||
|
||||
extern(C) int oue_read(usb_extreme_filestat* filestat, const(usb_extreme_headers) headers, int filestats_nlen) {
|
||||
auto result = oueRead(filestat[0..filestats_nlen], headers);
|
||||
extern(C) int oue_read(UsbExtremeFilestat* filestat, const(UsbExtremeHeaders) headers, int filestatsLen) {
|
||||
auto result = oueRead(filestat[0..filestatsLen], headers);
|
||||
return cast(int) result.length;
|
||||
}
|
||||
|
@ -5,16 +5,16 @@ enum USBEXTREME_NAME_LENGTH = 32;
|
||||
enum USBEXTREME_ID_LENGTH = 15;
|
||||
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
||||
enum USBEXTREME_MAGIC = 0x08;
|
||||
enum USBEXTREME_HEADER_SIZE = usb_extreme_base.sizeof;
|
||||
enum USBEXTREME_HEADER_SIZE = UsbExtremeBase.sizeof;
|
||||
|
||||
align(1) struct usb_extreme_base {
|
||||
align(1) struct UsbExtremeBase {
|
||||
align(1):
|
||||
uint8_t[6 + USBEXTREME_ID_LENGTH + USBEXTREME_NAME_LENGTH] empty;
|
||||
uint8_t magic;
|
||||
uint8_t[10] empty2;
|
||||
}
|
||||
|
||||
align(1) struct usb_extreme_v0 {
|
||||
align(1) struct UsbExtremeV0 {
|
||||
align(1):
|
||||
char[USBEXTREME_NAME_LENGTH] name;
|
||||
char[USBEXTREME_ID_LENGTH] id;
|
||||
@ -25,34 +25,34 @@ align(1) struct usb_extreme_v0 {
|
||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||
}
|
||||
|
||||
align(1) struct usb_extreme_v1 {
|
||||
align(1) struct UsbExtremeV1 {
|
||||
align(1):
|
||||
char[USBEXTREME_NAME_LENGTH] name;
|
||||
char[USBEXTREME_ID_LENGTH] id;
|
||||
uint8_t n_parts;
|
||||
uint8_t type;
|
||||
uint16_t size;
|
||||
uint8_t video_mode;
|
||||
uint8_t usb_extreme_version;
|
||||
uint8_t videoMode;
|
||||
uint8_t usbExtremeVersion;
|
||||
uint8_t magic;
|
||||
char[USBEXTREME_NAME_EXT_LENGTH] name_ext;
|
||||
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||
}
|
||||
|
||||
struct usb_extreme_headers {
|
||||
const(void)* first_header;
|
||||
const(usb_extreme_base)[] headers;
|
||||
int num_headers;
|
||||
size_t headerslen;
|
||||
struct UsbExtremeHeaders {
|
||||
const(void)* firstHeader;
|
||||
const(UsbExtremeBase)[] headers;
|
||||
int numHeaders;
|
||||
size_t headersLen;
|
||||
UsbExtremeVersion oueVersion;
|
||||
}
|
||||
|
||||
struct usb_extreme_filestat {
|
||||
struct UsbExtremeFilestat {
|
||||
int offset;
|
||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||
SCECdvdMediaType type;
|
||||
uint16_t size;
|
||||
uint8_t video_mode;
|
||||
UsbExtremeVersion usb_extreme_version;
|
||||
uint8_t videoMode;
|
||||
UsbExtremeVersion usbExtremeVersion;
|
||||
}
|
||||
|
||||
enum UsbExtremeVersion {
|
||||
@ -82,9 +82,9 @@ enum SCECdvdMediaType {
|
||||
}
|
||||
|
||||
extern(D) bool isOue(const(void)[] headers) {
|
||||
auto headers_oeu = castArray!(const usb_extreme_base)(headers);
|
||||
auto headersOeu = castArray!(const UsbExtremeBase)(headers);
|
||||
|
||||
foreach (header; headers_oeu) {
|
||||
foreach (header; headersOeu) {
|
||||
if (header.magic != USBEXTREME_MAGIC) {
|
||||
return false;
|
||||
}
|
||||
@ -110,52 +110,52 @@ extern(D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion) {
|
||||
}
|
||||
|
||||
extern(D) int oueNumHeaders(const(void)[] headers) {
|
||||
auto headers_nlen = cast(int) (castArray!(usb_extreme_base)(headers).length);
|
||||
auto headersLen = cast(int) (castArray!(UsbExtremeBase)(headers).length);
|
||||
|
||||
if (!isOue(headers)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return headers_nlen;
|
||||
return headersLen;
|
||||
}
|
||||
|
||||
extern(D) int ouePointHeaders(ref const(usb_extreme_base)[] headers, const(void)[] raw_headers) {
|
||||
auto headers_nlen = oueNumHeaders(raw_headers);
|
||||
extern(D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders) {
|
||||
auto headersLen = oueNumHeaders(rawHeaders);
|
||||
|
||||
if (headers_nlen <= 0) {
|
||||
if (headersLen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
headers = castArray!(const(usb_extreme_base))(raw_headers)[];
|
||||
return headers_nlen;
|
||||
headers = castArray!(const(UsbExtremeBase))(rawHeaders)[];
|
||||
return headersLen;
|
||||
}
|
||||
|
||||
extern(D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers) {
|
||||
auto headers_oeu = castArray!(usb_extreme_v1)(headers);
|
||||
auto first_version = UsbExtremeVersion.V0;
|
||||
auto headersOeu = castArray!(UsbExtremeV1)(headers);
|
||||
auto firstVersion = UsbExtremeVersion.V0;
|
||||
|
||||
if (!isOue(headers)) {
|
||||
return UsbExtremeVersion.Unknown;
|
||||
}
|
||||
|
||||
foreach (i, header; headers_oeu) {
|
||||
foreach (i, header; headersOeu) {
|
||||
if (i == 0) {
|
||||
first_version = getVersion(header.usb_extreme_version);
|
||||
firstVersion = getVersion(header.usbExtremeVersion);
|
||||
} else {
|
||||
if (first_version != getVersion(header.usb_extreme_version)) {
|
||||
if (firstVersion != getVersion(header.usbExtremeVersion)) {
|
||||
return UsbExtremeVersion.V0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return first_version;
|
||||
return firstVersion;
|
||||
}
|
||||
|
||||
extern(D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_headers) {
|
||||
auto oueVersion = oueHeadersVersion(raw_headers);
|
||||
auto num_headers = oueNumHeaders(raw_headers);
|
||||
extern(D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders) {
|
||||
auto oueVersion = oueHeadersVersion(rawHeaders);
|
||||
auto numHeaders = oueNumHeaders(rawHeaders);
|
||||
|
||||
if (!isOue(raw_headers)) {
|
||||
if (!isOue(rawHeaders)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -163,18 +163,18 @@ extern(D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto headersArr = castArray!(usb_extreme_base)(raw_headers);
|
||||
headers = usb_extreme_headers(raw_headers.ptr,
|
||||
auto headersArr = castArray!(UsbExtremeBase)(rawHeaders);
|
||||
headers = UsbExtremeHeaders(rawHeaders.ptr,
|
||||
headersArr,
|
||||
num_headers,
|
||||
raw_headers.length,
|
||||
numHeaders,
|
||||
rawHeaders.length,
|
||||
oueVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern(D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const(usb_extreme_headers) headers) {
|
||||
auto headers_full = castArray!(usb_extreme_v1)(headers.headers);
|
||||
auto headersLength = headers_full.length;
|
||||
extern(D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers) {
|
||||
auto headersFull = castArray!(UsbExtremeV1)(headers.headers);
|
||||
auto headersLength = headersFull.length;
|
||||
int fileStatsLength = 0;
|
||||
|
||||
foreach (i, ref filestat; filestats) {
|
||||
@ -182,23 +182,23 @@ extern(D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const
|
||||
return filestats[0..i];
|
||||
}
|
||||
|
||||
auto header = headers_full[i];
|
||||
auto header = headersFull[i];
|
||||
filestat.name[0..USBEXTREME_NAME_LENGTH] = header.name[0..$];
|
||||
auto headerVersion = getVersion(header.usb_extreme_version);
|
||||
auto headerVersion = getVersion(header.usbExtremeVersion);
|
||||
uint16_t size = 0;
|
||||
uint8_t videoMode = 0;
|
||||
|
||||
if (headerVersion >= 1) {
|
||||
size = header.size;
|
||||
videoMode = header.video_mode;
|
||||
filestat.name[USBEXTREME_NAME_LENGTH..USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] = header.name_ext[0..$];
|
||||
videoMode = header.videoMode;
|
||||
filestat.name[USBEXTREME_NAME_LENGTH..USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] = header.nameExt[0..$];
|
||||
}
|
||||
|
||||
filestat.size = size;
|
||||
filestat.type = cast(SCECdvdMediaType) header.type;
|
||||
filestat.offset = cast(int) i;
|
||||
filestat.video_mode = videoMode;
|
||||
filestat.usb_extreme_version = headerVersion;
|
||||
filestat.videoMode = videoMode;
|
||||
filestat.usbExtremeVersion = headerVersion;
|
||||
headersLength -= 1;
|
||||
fileStatsLength += 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user