diff --git a/CMakeLists.txt b/CMakeLists.txt index 15f3f78..f568ef4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.0) cmake_policy(VERSION 3.0) -project (mazemaker VERSION 1.3) +project (mazemaker VERSION 1.4) SET(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE) SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d5bb57a..1b9d622 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,9 +27,7 @@ set_target_properties(mazemaker_static PROPERTIES ) install (TARGETS mazemaker_shared mazemaker_static DESTINATION ${LIB_INSTALL_DIR}) install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/mazemaker.h DESTINATION ${INCLUDE_INSTALL_DIR}) -target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES} m) -target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS} ../include) -target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS} ../include) -target_compile_options(mazemaker_shared PUBLIC ${PNG_CFLAGS_OTHER}) -target_compile_options(mazemaker_static PUBLIC ${PNG_CFLAGS_OTHER}) -target_link_options(mazemaker_shared PUBLIC -L${PNG_LIBDIR}) +target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES};m) +target_link_directories(mazemaker_shared PUBLIC ${PNG_LIBRARY_DIRS}) +target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS};../include) +target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS};../include) diff --git a/lib/options.c b/lib/options.c index 034a4e4..8476add 100644 --- a/lib/options.c +++ b/lib/options.c @@ -18,15 +18,40 @@ void mazemaker_options_free(mazeoptions_t* options) { free(options); } +static int interpretColorName(char const* color_desc, rgb_color_t dst) { + if (0 == strcasecmp(color_desc, "black")) { dst[0] = dst[1] = dst[2] = 0; } + else if (0 == strcasecmp(color_desc, "white")) { dst[0] = dst[1] = dst[2] = 0xff; } + else if (0 == strcasecmp(color_desc, "red")) { dst[0] = 0xff; dst[1] = dst[2] = 0; } + else if (0 == strcasecmp(color_desc, "blue")) { dst[0] = dst[1] = 0; dst[2] = 0xff; } + else if (0 == strcasecmp(color_desc, "green")) { dst[0] = dst[2] = 0; dst[1] = 0xff; } + else if (0 == strcasecmp(color_desc, "yellow")) { dst[2] = 0; dst[0] = dst[1] = 0xff; } + else if ((0 == strcasecmp(color_desc, "magenta")) || + (0 == strcasecmp(color_desc, "purple"))) { dst[1] = 0; dst[0] = dst[2] = 0xff; } + else if (0 == strcasecmp(color_desc, "cyan")) { dst[0] = 0; dst[1] = dst[2] = 0xff; } + else if (0 == strcasecmp(color_desc, "orange")) { dst[0] = 0xff; dst[1] = 0x7f; dst[2] = 0; } + else if (0 == strcasecmp(color_desc, "brown")) { dst[0] = 0x7f; dst[1] = 0x3f; dst[2] = 0; } + else if ((0 == strcasecmp(color_desc, "gray")) || + (0 == strcasecmp(color_desc, "grey"))) { dst[0] = dst[1] = dst[2] = 0x7f; } + else if (0 == strcasecmp(color_desc, "darkblue")) { dst[0] = dst[1] = 0; dst[2] = 0x7f; } + else if (0 == strcasecmp(color_desc, "darkgreen")) { dst[0] = dst[2] = 0; dst[1] = 0x7f; } + else if (0 == strcasecmp(color_desc, "darkred")) { dst[0] = 0x7f; dst[1] = dst[2] = 0; } + else if (0 == strcasecmp(color_desc, "pink")) { dst[0] = 0xff; dst[1] = 0xa0; dst[2] = 0xbf; } + else if ((0 == strcasecmp(color_desc, "darkmagenta")) || + (0 == strcasecmp(color_desc, "darkpurple"))) { dst[1] = 0; dst[0] = dst[2] = 0x7f; } + else if (0 == strcasecmp(color_desc, "darkcyan")) { dst[0] = 0; dst[1] = dst[2] = 0x7f; } + else return -1; + return 0; +} + static int stringToColor(char const* color_desc, rgb_color_t dst) { - if (color_desc[0] != '#') return -1; // bad format + if (color_desc[0] != '#') return interpretColorName(color_desc, dst); size_t l; for (l = 1; color_desc[l] != '\0'; l++) if (!isxdigit(color_desc[l])) return -1; // bad format if ((l != 4) && (l != 7)) return -1; // bad format - char x2[3] = { 0, 0, 0}; + char x2[3] = { 0, 0, 0 }; if (l == 4) { x2[0] = x2[1] = color_desc[1]; sscanf(x2, "%hhx", &dst[0]); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 91adb10..355f3c6 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,10 +1,9 @@ find_package(PkgConfig REQUIRED) pkg_search_module(POPT REQUIRED popt) -add_executable(mazemaker) -target_sources(mazemaker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mazemaker.c) -target_link_libraries(mazemaker PUBLIC mazemaker_shared ${POPT_LIBRARIES}) -target_include_directories(mazemaker PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include PUBLIC ${POPT_INCLUDE_DIRS}) -target_compile_options(mazemaker PUBLIC ${POPT_CFLAGS_OTHER}) +include_directories("../include" ${POPT_INCLUDE_DIRS}) + +add_executable(mazemaker mazemaker.c) +target_link_libraries(mazemaker mazemaker_shared ${POPT_LIBRARIES}) install (TARGETS mazemaker DESTINATION bin) diff --git a/utils/mazemaker.c b/utils/mazemaker.c index 173c35d..622c585 100644 --- a/utils/mazemaker.c +++ b/utils/mazemaker.c @@ -41,8 +41,18 @@ int main(int argc, char* argv[]) { } mazegrid_t maze; mazeoptions_t* options = mazemaker_options_new(); - if (fg_color != NULL) mazemaker_options_set_wall_color(options, fg_color); - if (bg_color != NULL) mazemaker_options_set_background_color(options, bg_color); + if (fg_color != NULL) { + if (0 > mazemaker_options_set_wall_color(options, fg_color)) { + fprintf(stderr, "Unknown color: \"%s\"\n", fg_color); + exit(1); + } + } + if (bg_color != NULL) { + if (0 > mazemaker_options_set_background_color(options, bg_color)) { + fprintf(stderr, "Unknown color: \"%s\"\n", bg_color); + exit(1); + } + } mazemaker_generate_maze(width, height, &maze); mazemaker_maze_to_png_opt(&maze, filename, options); mazemaker_free_maze(&maze);