From b127690a4805a883a6e16fb7c2f0ffc7239706a3 Mon Sep 17 00:00:00 2001 From: David Baer Date: Thu, 15 Apr 2021 13:31:30 -0400 Subject: [PATCH] Initial import --- .gitignore | 10 ++++++++++ CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ README.md | 4 ++++ config.h.in | 3 +++ src/grid.h | 28 ++++++++++++++++++++++++++++ src/main.c | 27 +++++++++++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 config.h.in create mode 100644 src/grid.h create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d5fba7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +CMakeCache.txt +CMakeFiles +CPackConfig.cmake +CPackSourceConfig.cmake +Makefile +_CPack_Packages +cmake_install.cmake +config.h +install_manifest.txt +mazemaker diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..759e9a9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required (VERSION 2.8.12) +project (mazemaker) +set(CMAKE_C_FLAGS "-Wall -O2 -g") +set (VERSION_MAJOR 0) +set (VERSION_MINOR 1) + +configure_file ( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h" + ) + + +find_package(PkgConfig REQUIRED) +pkg_search_module(POPT REQUIRED popt) + +include_directories("${PROJECT_BINARY_DIR}") + +file(GLOB_RECURSE SOURCES src/*.c src/*.h) + +add_executable (mazemaker ${SOURCES}) +install (TARGETS mazemaker DESTINATION bin) + +target_link_libraries(mazemaker PUBLIC ${POPT_LIBRARIES}) +target_include_directories(mazemaker PUBLIC ${POPT_INCLUDE_DIRS}) +target_compile_options(mazemaker PUBLIC ${POPT_CFLAGS_OTHER}) +target_link_options(mazemaker PUBLIC ${POPT_LDFLAGS_OTHER}) + +set( + CPACK_SOURCE_PACKAGE_FILE_NAME + "mazemaker-${VERSION_MAJOR}.${VERSION_MINOR}" + CACHE INTERNAL "tarball basename" + ) +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;~$;/CMakeFiles/;*.cmake;*.tar.gz;${CPACK_SOURCE_IGNORE_FILES}") +include (CPack) diff --git a/README.md b/README.md new file mode 100644 index 0000000..052ced1 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +MazeMaker +========= + +TODO diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..458c83d --- /dev/null +++ b/config.h.in @@ -0,0 +1,3 @@ +// the configured options and settings for Tutorial +#define VERSION_MAJOR @VERSION_MAJOR@ +#define VERSION_MINOR @VERSION_MINOR@ diff --git a/src/grid.h b/src/grid.h new file mode 100644 index 0000000..bc838e3 --- /dev/null +++ b/src/grid.h @@ -0,0 +1,28 @@ +#ifndef _GRID_H +#define _GRID_H 1 + +typedef uint8 edgeweight_t; + +typedef struct { + edgeweight_t up, right; +} mazeedges_t; + +typedef struct { + size_t width, height; + mazeedges_t** grid; +} mazegrid_t; + +typedef enum { + EDGE_UP, + EDGE_RIGHT, + EDGE_DOWN, + EDGE_LEFT +} mazeedge_dir_t; + +mazegrid_t mazegrid_new(size_t width, size_t height); +void mazegrid_free(mazegrid_t* g); + +int mazegrid_set_edge(mazegrid_t* g, size_t x, size_t y, mazeedge_dir_t dir, edgeweight_t wt); +edgeweight_t mazegrid_get_edge(mazegrid_t const* g, size_t, size_t y, mazeedge_dir_t dir); + +#endif // !def(_GRID_H) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..bb299a0 --- /dev/null +++ b/src/main.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + char c; + int width = 0, height = 0; + struct poptOption options_table[] = { + { "width", 'w', POPT_ARG_INT, &width, 0 }, + { "height", 'h', POPT_ARG_INT, &height, 0 }, + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } + }; + poptContext ctx = poptGetContext(NULL, argc, argv, options_table, 0); + if (argc < 2) { + poptPrintUsage(ctx, stderr, 0); + exit(1); + } + while ((c = poptGetNextOpt(ctx)) >= 0) /* noop */ ; + if (c < -1) { + fprintf(stderr, "%s: %s\n", poptBadOption(ctx, POPT_BADOPTION_NOALIAS), poptStrerror(c)); + return 1; + } + printf("width: %d\n", width); + printf("height: %d\n", height); + poptFreeContext(ctx); +}