diff --git a/CMakeLists.txt b/CMakeLists.txt index 5db41af..591d6c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,16 @@ cmake_minimum_required(VERSION 2.8.9) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake-d") -INCLUDE(CheckIncludeFile) -project(Open-USB-Extreme D C) +project(Open-USB-Extreme D) + +file(GLOB SOURCES "lib/*.d") +file(GLOB HEADERS "include/*.h" "include/*.di") +file(GLOB EXAMPLE_SOURCES "examples/*.d") + include_directories(include) -# check headers -check_include_file("stdint.h" HAVE_STDINT) -if (HAVE_STDINT) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_STDINT") -endif() -check_include_file("stddef.h" HAVE_STDDEF) -if (HAVE_STDDEF) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_STDDEF") -endif() - -file(GLOB SOURCES "lib/*.c") -file(GLOB DSOURCES "lib/*.d") -file(GLOB HEADERS "include/*.h") -file(GLOB EXAMPLE_SOURCES "examples/*.c") -set (CMAKE_CXX_STANDARD 89) -#set(CMAKE_C_FLAGS "-Wall -pedantic -Wextra -Werror") -set(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -betterC -O -release") -add_library(${PROJECT_NAME} SHARED ${DSOURCES} ${SOURCES}) +set(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -betterC -O -release -L-rpath=.") +add_library(${PROJECT_NAME} SHARED ${SOURCES}) add_executable(open-usbextreme-example ${EXAMPLE_SOURCES}) target_link_libraries(open-usbextreme-example ${PROJECT_NAME}) diff --git a/examples/example.c b/examples/example.d similarity index 50% rename from examples/example.c rename to examples/example.d index 66721f3..34240da 100644 --- a/examples/example.c +++ b/examples/example.d @@ -1,40 +1,41 @@ -#include -#include -#include +import core.stdc.stdio; +import core.stdc.stdlib; +import usbextreme; -int main(int argc, char *argv[]) { +extern(C) int main(int argc, char[]* argv) { if (argc < 2) { printf("Usage: open-usbextreme-example \n"); return 1; } - - FILE *f = fopen(argv[1], "rb"); + + auto f = fopen(argv[1].ptr, "rb"); fseek(f, 0, SEEK_END); - long fsize = ftell(f); - + auto fsize = ftell(f); + if (fsize <= 0) { return 1; } - - unsigned long size = *(unsigned long*) &fsize; + + auto size = *(cast(ulong*) &fsize); fseek(f, 0, SEEK_SET); - void *data = malloc(size + 1); + auto data = malloc(size + 1); fread(data, size, 1, f); fclose(f); usb_extreme_headers headers; - if(oue_read_headers(&headers, data, size) <= 0) { + if (oue_read_headers(&headers, data, size) <= 0) { return 1; } - usb_extreme_filestat filestats[10]; - int nstats = oue_read(filestats, headers, 10); + usb_extreme_filestat[10] filestats = void; + int nstats = oue_read(filestats.ptr, headers, 10); int i; for(i = 0; i < nstats; i++) { - printf("Game name [%d]: %s\n", filestats[i].offset, filestats[i].name); + printf("Game name [%d]: %s\n", filestats[i].offset, filestats[i].name.ptr); } + return 0; }