From ef698cf52b54387faed3a4b409c53be9ab80dd77 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Sun, 16 Oct 2016 11:55:00 +0100 Subject: [PATCH 01/10] Add a function for creating blank spiral structs Fixes #68 --- saxbospiral/initialise.c | 7 +++++++ saxbospiral/initialise.h | 5 +++++ sxp.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/saxbospiral/initialise.c b/saxbospiral/initialise.c index 37e751b..c2a9c39 100644 --- a/saxbospiral/initialise.c +++ b/saxbospiral/initialise.c @@ -17,6 +17,13 @@ direction_t change_direction(direction_t current, rotation_t turn) { return (current + turn) % 4U; } +/* + * returns a spiral struct with all fields initialised to 0 + */ +spiral_t blank_spiral() { + return (spiral_t){0, NULL, {{NULL, 0}, 0}, false, 0, 0, 0}; +} + /* * given a buffer_t full of data, and a pointer to a blank spiral_t * struct, populates the spiral struct from the data in the buffer diff --git a/saxbospiral/initialise.h b/saxbospiral/initialise.h index 7557d9d..5599912 100644 --- a/saxbospiral/initialise.h +++ b/saxbospiral/initialise.h @@ -14,6 +14,11 @@ extern "C"{ */ direction_t change_direction(direction_t current, rotation_t turn); +/* + * returns a spiral struct with all fields initialised to 0 + */ +spiral_t blank_spiral(); + /* * given a buffer_t full of data, and a pointer to a blank spiral_t * struct, populates the spiral struct from the data in the buffer diff --git a/sxp.c b/sxp.c index a41c4d4..b848b17 100644 --- a/sxp.c +++ b/sxp.c @@ -166,7 +166,7 @@ bool run( return false; } // create initial blank spiral struct - spiral_t spiral = {0, NULL, {{NULL, 0}, 0}, false, 0, 0, 0}; + spiral_t spiral = blank_spiral(); // resolve perfection threshold - set to -1 if disabled completely int perfection = (perfect == false) ? -1 : perfect_threshold; // check error condition (where no actions were specified) From ceb97005606bd07fcb6e0804238ca01839a95392 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Sun, 16 Oct 2016 12:02:31 +0100 Subject: [PATCH 02/10] Clean up spacing around if, for statements and remove one-line ifs --- saxbospiral/render_backends/png_backend.c | 27 ++++++++++++++--------- saxbospiral/solve.c | 6 ++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/saxbospiral/render_backends/png_backend.c b/saxbospiral/render_backends/png_backend.c index 71bcf8d..c300bbc 100644 --- a/saxbospiral/render_backends/png_backend.c +++ b/saxbospiral/render_backends/png_backend.c @@ -22,9 +22,8 @@ static void buffer_write_data( // if buffer bytes pointer is not NULL, then re-allocate if(p->bytes != NULL) { p->bytes = realloc(p->bytes, new_size); - } - // otherwise, allocate - else { + } else { + // otherwise, allocate p->bytes = malloc(new_size); } if(!p->bytes) { @@ -45,9 +44,15 @@ void dummy_png_flush(png_structp png_ptr) {} // simple libpng cleanup function - used mainly for freeing memory void cleanup_png_lib(png_structp png_ptr, png_infop info_ptr, png_bytep row) { - if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); - if (row != NULL) free(row); + if(info_ptr != NULL) { + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + } + if(png_ptr != NULL) { + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + } + if(row != NULL) { + free(row); + } } /* @@ -67,7 +72,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) { // allocate libpng memory png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); // catch malloc fail - if (png_ptr == NULL) { + if(png_ptr == NULL) { result.location = DEBUG; result.diagnostic = MALLOC_REFUSED; // cleanup @@ -77,7 +82,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) { // allocate libpng memory info_ptr = png_create_info_struct(png_ptr); // catch malloc fail - if (info_ptr == NULL) { + if(info_ptr == NULL) { result.location = DEBUG; result.diagnostic = MALLOC_REFUSED; // cleanup @@ -135,11 +140,11 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) { return result; } // Write image data - for (size_t y = 0 ; y < bitmap.height; y++) { - for (size_t x = 0; x < bitmap.width; x++) { + for(size_t y = 0 ; y < bitmap.height; y++) { + for(size_t x = 0; x < bitmap.width; x++) { // set to black if there is a point here, white if not row[x] = (bitmap.pixels[x][y] == true) ? 0 : 1; - } + } png_write_row(png_ptr, row); } // End write diff --git a/saxbospiral/solve.c b/saxbospiral/solve.c index 5d75b57..5e3f3ea 100644 --- a/saxbospiral/solve.c +++ b/saxbospiral/solve.c @@ -33,7 +33,7 @@ static bool spiral_collides(spiral_t* spiral, size_t index) { * if there are less than 4 lines in the spiral, then there's no way it * can collide, so return false early */ - if (spiral->size < 4) { + if(spiral->size < 4) { return false; } else { // initialise a counter to keep track of what line we're on @@ -139,9 +139,7 @@ static length_t suggest_resize( * Apply the rules mentioned in collision_resolution_rules.txt to * calculate the correct length to set the previous line and return it. */ - if(false) { - (void)0; // no-op - } else if((p.direction == UP) && (r.direction == UP)) { + if((p.direction == UP) && (r.direction == UP)) { return (ra.y - pa.y) + r.length + 1; } else if((p.direction == UP) && (r.direction == DOWN)) { return (rb.y - pa.y) + r.length + 1; From 088ed0481f4abcc5e6957cf6b3554a3742d7d30a Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 13:52:19 +0100 Subject: [PATCH 03/10] Specify libpng minimum required version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca1a0f2..1d94560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ endif() # add custom dependencies directory set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") # libpng -find_package(PNG REQUIRED) +find_package(PNG 1.2 REQUIRED) include_directories(${PNG_INCLUDE_DIR}) # Argtable find_package(Argtable REQUIRED) From e7818e21ef41893aff06c60f7b484bea1ee3ef2f Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 13:57:39 +0100 Subject: [PATCH 04/10] Set libpng to require exact 1.2 version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d94560..e54c53a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ endif() # add custom dependencies directory set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") # libpng -find_package(PNG 1.2 REQUIRED) +find_package(PNG 1.2 EXACT REQUIRED) include_directories(${PNG_INCLUDE_DIR}) # Argtable find_package(Argtable REQUIRED) From dd3d255f5dbc3cdebc83fad4d09f33eb4ec51d90 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 14:09:34 +0100 Subject: [PATCH 05/10] Rename project --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e54c53a..dae6591 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # begin basic metadata cmake_minimum_required(VERSION 3.0) -project(saxbospiral VERSION 0.14.0 LANGUAGES C) +project(libsaxbospiral VERSION 0.14.0 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) set( From ad8d030cabce339715c7c96e1a7028e57e1ba773 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 14:32:28 +0100 Subject: [PATCH 06/10] Remove command-line program, now separated out to separate project --- CMakeLists.txt | 22 --- build_logo.sh | 12 -- func_test.sh | 10 -- sxp.c | 378 ------------------------------------------------- sxp.h | 47 ------ 5 files changed, 469 deletions(-) delete mode 100755 build_logo.sh delete mode 100755 func_test.sh delete mode 100644 sxp.c delete mode 100644 sxp.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dae6591..1216a79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,9 +49,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") # libpng find_package(PNG 1.2 EXACT REQUIRED) include_directories(${PNG_INCLUDE_DIR}) -# Argtable -find_package(Argtable REQUIRED) -include_directories(${ARGTABLE_INCLUDE_DIR}) # C source files file( @@ -69,10 +66,8 @@ add_library(saxbospiral ${LIB_SAXBOSPIRAL_SOURCES}) # Link libsaxbospiral with libpng so we get libpng symbols target_link_libraries(saxbospiral ${PNG_LIBRARY}) -add_executable(sxp sxp.c) add_executable(sxp_test tests.c) -target_link_libraries(sxp saxbospiral ${PNG_LIBRARY} ${ARGTABLE_LIBRARY}) target_link_libraries(sxp_test saxbospiral ${PNG_LIBRARY}) install( @@ -92,24 +87,7 @@ install( DESTINATION include/saxbospiral/render_backends ) -install(PROGRAMS sxp DESTINATION bin) - enable_testing() add_test(unit_tests sxp_test) # fetch a shell script runner find_program(COMMAND_INTERPRETER bash) -# only run functional test if we found bash -if(COMMAND_INTERPRETER) - add_test( - NAME func_test COMMAND ${COMMAND_INTERPRETER} - # each script needs to know the path to the sxp cli executable - "func_test.sh" sxp "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}" - ) - add_custom_target( - build_logo ${COMMAND_INTERPRETER} - "build_logo.sh" sxp "saxbospiral.png" "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}" - ) -else() - # warn about skipping of functional test script - message(WARNING "Skipping functional test script, couldn't find Bash Shell") -endif() diff --git a/build_logo.sh b/build_logo.sh deleted file mode 100755 index 0ffc7ee..0000000 --- a/build_logo.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Script for updating the project logo -# The first argument is the path to the sxp cli program. -# The second argument is the file to write the PNG output to. -# The third is the message to use for the logo data -# (of format "saxbospiral vX.Y.Z"). -# -echo "Generating logo"; -echo -n "$3" > temp.hex && \ -./"$1" -pgr -i temp.hex -o "$2" && \ -rm temp.hex; diff --git a/func_test.sh b/func_test.sh deleted file mode 100755 index aa8f3e8..0000000 --- a/func_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Functional test script. -# Generates a new logo and compares with the current one. -# The first argument is the path to the sxp cli program. -# The second argument is the message to use for the file (see build_logo.sh) -# -./build_logo.sh "$1" "test_saxbospiral.png" "$2" && \ -diff "saxbospiral.png" "test_saxbospiral.png" && \ -rm "test_saxbospiral.png"; diff --git a/sxp.c b/sxp.c deleted file mode 100644 index b848b17..0000000 --- a/sxp.c +++ /dev/null @@ -1,378 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "sxp.h" -#include "saxbospiral/saxbospiral.h" -#include "saxbospiral/initialise.h" -#include "saxbospiral/solve.h" -#include "saxbospiral/serialise.h" -#include "saxbospiral/render.h" -#include "saxbospiral/render_backends/png_backend.h" - - -#ifdef __cplusplus -extern "C"{ -#endif - -// returns size of file associated with given file handle -size_t get_file_size(FILE* file_handle) { - // seek to end - fseek(file_handle, 0L, SEEK_END); - // get size - size_t file_size = ftell(file_handle); - // seek to start again - fseek(file_handle, 0L, SEEK_SET); - return file_size; -} - -/* - * given an open file handle and a buffer, read the file contents into buffer - * returns true on success and false on failure. - */ -bool file_to_buffer(FILE* file_handle, buffer_t* buffer) { - size_t file_size = get_file_size(file_handle); - // allocate/re-allocate buffer memory - if(buffer->bytes == NULL) { - buffer->bytes = calloc(1, file_size); - } else { - buffer->bytes = realloc(buffer->bytes, file_size); - } - if(buffer->bytes == NULL) { - // couldn't allocate enough memory! - return false; - } - buffer->size = file_size; - // read in file data to buffer - size_t bytes_read = fread(buffer->bytes, 1, file_size, file_handle); - // check amount read was the size of file - if(bytes_read != file_size) { - // free memory - free(buffer->bytes); - return false; - } else { - return true; - } -} - -/* - * given a buffer struct and an open file handle, writes the buffer contents - * to the file. - * returns true on success and false on failure. - */ -bool buffer_to_file(buffer_t* buffer, FILE* file_handle) { - size_t bytes_written = fwrite( - buffer->bytes, 1, buffer->size, file_handle - ); - // check amount written was the size of buffer - if(bytes_written != buffer->size) { - return false; - } else { - return true; - } -} - -/* - * private function, given a diagnostic_t error, returns the string name of the - * error code - */ -static const char* error_code_string(diagnostic_t error) { - switch(error) { - case OPERATION_FAIL: - return "OPERATION_FAIL"; - case MALLOC_REFUSED: - return "MALLOC_REFUSED"; - case IMPOSSIBLE_CONDITION: - return "IMPOSSIBLE_CONDITION"; - case OPERATION_OK: - return "OPERATION_OK (NO ERROR)"; - case STATE_UNKNOWN: - default: - return "UNKNOWN ERROR"; - } -} - -/* - * private function, given a deserialise_diagnostic_t error, returns the string - * name of the error code - */ -static const char* file_error_code_string(deserialise_diagnostic_t error) { - switch(error) { - case DESERIALISE_OK: - return "DESERIALISE_OK (NO ERROR)"; - case DESERIALISE_BAD_HEADER_SIZE: - return "DESERIALISE_BAD_HEADER_SIZE"; - case DESERIALISE_BAD_MAGIC_NUMBER: - return "DESERIALISE_BAD_MAGIC_NUMBER"; - case DESERIALISE_BAD_VERSION: - return "DESERIALISE_BAD_VERSION"; - case DESERIALISE_BAD_DATA_SIZE: - return "DESERIALISE_BAD_DATA_SIZE"; - default: - return "UNKNOWN ERROR"; - } -} - -/* - * private function to handle all generic errors, by printing to stderr - * returns true if there was an error, false if not - */ -static bool handle_error(status_t result) { - // if we had problems, print to stderr and return true - if(result.diagnostic != OPERATION_OK) { - fprintf( - stderr, - "Error Code: %s\n", error_code_string(result.diagnostic) - ); - return true; - } else { - // otherwise, return false to say 'no error' - return false; - } -} - -/* - * function responsible for actually doing the main work, called by main with - * options configured via command-line. - * returns true on success, false on failure. - */ -bool run( - bool prepare, bool generate, bool render, bool perfect, - int perfect_threshold, int line_limit, int total_lines, - const char* input_file_path, const char* output_file_path -) { - // get input file handle - FILE* input_file = fopen(input_file_path, "rb"); - if(input_file == NULL) { - fprintf(stderr, "%s\n", "Couldn't open input file"); - return false; - } - // make input buffer - buffer_t input_buffer = {0, 0}; - // make output buffer - buffer_t output_buffer = {0, 0}; - // read input file into buffer - bool read_ok = file_to_buffer(input_file, &input_buffer); - // used later for telling if write of output file was success - bool write_ok = false; - // close input file - fclose(input_file); - // if read was unsuccessful, don't continue - if(read_ok == false) { - fprintf(stderr, "%s\n", "Couldn't read input file"); - return false; - } - // create initial blank spiral struct - spiral_t spiral = blank_spiral(); - // resolve perfection threshold - set to -1 if disabled completely - int perfection = (perfect == false) ? -1 : perfect_threshold; - // check error condition (where no actions were specified) - if((prepare || generate || render) == false) { - // none of the above. this is an error condition - nothing to be done - fprintf(stderr, "%s\n", "Nothing to be done!"); - return false; - } - // otherwise, good to go - if(prepare) { - // we must build spiral from raw file first - if(handle_error(init_spiral(input_buffer, &spiral))) { - // handle errors - return false; - } - } else { - // otherwise, we must load spiral from file - serialise_result_t result = load_spiral(input_buffer, &spiral); - // if we had problems, print to stderr and quit - if(result.status.diagnostic != OPERATION_OK) { - fprintf( - stderr, - "Error Code:\t\t%s\nFile Error Code:\t%s\n", - error_code_string(result.status.diagnostic), - file_error_code_string(result.diagnostic) - ); - return false; - } - } - if(generate) { - /* - * find out how many lines we are to plot - * this is based on two options: the line_limit and the total_lines - * arguments. - */ - // first, check the line_limit argument - uint64_t lines_to_plot; - // set to solved count + line limit if set, else spiral size - lines_to_plot = ( - (line_limit != -1) ? (spiral.solved_count + line_limit) : spiral.size - ); - // set to total_lines if set and less than current amount - lines_to_plot = ( - (total_lines != -1 && (uint64_t)total_lines < lines_to_plot) ? - (uint64_t)total_lines : lines_to_plot - ); - // we must plot all lines from spiral file - if(handle_error(plot_spiral(&spiral, perfection, lines_to_plot, NULL))) { - // handle errors - return false; - } - } - if(render) { - // we must render an image from spiral - bitmap_t image = {0, 0, 0}; - if(handle_error(render_spiral(spiral, &image))) { - // handle errors - return false; - } - // now write PNG image data to buffer with libpng - if(handle_error(write_png_image(image, &output_buffer))) { - // handle errors - return false; - } - } else { - // otherwise, we must simply dump the spiral as-is - serialise_result_t result = dump_spiral(spiral, &output_buffer); - // if we had problems, print to stderr and quit - if(result.status.diagnostic != OPERATION_OK) { - fprintf( - stderr, - "Error Code:\t\t%s\nFile Error Code:\t%s\n", - error_code_string(result.status.diagnostic), - file_error_code_string(result.diagnostic) - ); - return false; - } - } - // get output file handle - FILE* output_file = fopen(output_file_path, "wb"); - if(output_file == NULL) { - fprintf(stderr, "%s\n", "Couldn't open output file"); - return false; - } - // now, write output buffer to file - write_ok = buffer_to_file(&output_buffer, output_file); - // close output file - fclose(output_file); - // free buffers - free(input_buffer.bytes); - free(output_buffer.bytes); - // return success depends on last write - return write_ok; -} - -// main - mostly just process arguments, the bulk of the work is done by run() -int main(int argc, char* argv[]) { - // status code initially set to -1 - int status_code = -1; - // build argtable struct for parsing command-line arguments - // show help - struct arg_lit* help = arg_lit0("h","help", "show this help and exit"); - // show version - struct arg_lit* version = arg_lit0("v", "version", "show version and exit"); - // flag for if we want to prepare a spiral - struct arg_lit* prepare = arg_lit0( - "p", "prepare", - "prepare a spiral from raw binary data" - ); - // flag for if we want to generate the solution for a spiral's line lengths - struct arg_lit* generate = arg_lit0( - "g", "generate", - "generate the lengths of a spiral's lines" - ); - // flag for if we want to render a spiral to imagee - struct arg_lit* render = arg_lit0( - "r", "render", "render a spiral to an image" - ); - struct arg_lit* perfect = arg_lit0( - "D", "disable-perfection", "allow unlimited optimisations" - ); - struct arg_int* perfect_threshold = arg_int0( - "d", "perfection-threshold", NULL, "set optimisation threshold" - ); - struct arg_int* total_lines = arg_int0( - "t", "total-lines", NULL, "total number of lines to plot to" - ); - struct arg_int* line_limit = arg_int0( - "l", "line-limit", NULL, "plot this many more lines than currently solved" - ); - // input file path option - struct arg_file* input = arg_file0( - "i", "input", NULL, "input file path" - ); - // output file path option - struct arg_file* output = arg_file0( - "o", "output", NULL, "output file path" - ); - // argtable boilerplate - struct arg_end* end = arg_end(20); - void* argtable[] = { - help, version, - prepare, generate, render, - perfect, perfect_threshold, line_limit, total_lines, - input, output, end, - }; - const char* program_name = "sxp"; - // check argtable members were allocated successfully - if(arg_nullcheck(argtable) != 0) { - // NULL entries were detected, so some allocations failed - fprintf( - stderr, "%s\n", "FATAL: Could not allocate all entries for argtable" - ); - status_code = 2; - } - // set default value of perfect_threshold argument - perfect_threshold->ival[0] = 1; - // set default value of line_limit and total_lines arguments - line_limit->ival[0] = -1; - total_lines->ival[0] = -1; - // parse arguments - int count_errors = arg_parse(argc, argv, argtable); - // if we asked for the version, show it - if(version->count > 0) { - printf("%s %s\n", program_name, SAXBOSPIRAL_VERSION_STRING); - status_code = 0; - } - // if parser returned any errors, display them and set return code to 1 - if(count_errors > 0) { - arg_print_errors(stderr, end, program_name); - status_code = 1; - } - // set return code to 0 if we asked for help - if(help->count > 0) { - status_code = 0; - } - // display usage information if we asked for help or got arguments wrong - if((count_errors > 0) || (help->count > 0)) { - printf("Usage: %s", program_name); - arg_print_syntax(stdout, argtable, "\n"); - arg_print_glossary(stdout, argtable, " %-25s %s\n"); - } - // if at this point status_code is not -1, clean up then return early - if(status_code != -1) { - arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); - return status_code; - } - // otherwise, carry on... - // now, call run with options from command-line - bool result = run( - (prepare->count > 0) ? true : false, - (generate->count > 0) ? true : false, - (render->count > 0) ? true : false, - (perfect->count > 0) ? false : true, - perfect_threshold->ival[0], - line_limit->ival[0], - total_lines->ival[0], - *input->filename, - *output->filename - ); - // free argtable struct - arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); - // return appropriate status code based on success/failure - return (result) ? 0 : 1; -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/sxp.h b/sxp.h deleted file mode 100644 index eefa3b2..0000000 --- a/sxp.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SAXBOPHONE_SAXBOSPIRAL_SXP_H -#define SAXBOPHONE_SAXBOSPIRAL_SXP_H - -#include -#include -#include - -#include "saxbospiral/saxbospiral.h" - - -#ifdef __cplusplus -extern "C"{ -#endif - -// returns size of file associated with given file handle -size_t get_file_size(FILE * file_handle); - -/* - * given an open file handle and a buffer, read the file contents into buffer - * returns true on success and false on failure. - */ -bool file_to_buffer(FILE * file_handle, buffer_t * buffer); - -/* - * given a buffer struct and an open file handle, writes the buffer contents - * to the file. - * returns true on success and false on failure. - */ -bool buffer_to_file(buffer_t * buffer, FILE * file_handle); - -/* - * function responsible for actually doing the main work, called by main with - * options configured via command-line. - * returns true on success, false on failure. - */ -bool run( - bool prepare, bool generate, bool render, bool perfect, - int perfect_threshold, int line_limit, int total_lines, - const char * input_file_path, const char * output_file_path -); - -#ifdef __cplusplus -} // extern "C" -#endif - -// end of header file -#endif From 31a0a9fc131bf243441b4ad15a313f881c9d2e1a Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 14:52:52 +0100 Subject: [PATCH 07/10] Update README --- README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8e614d8..477a9b2 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,17 @@ # Saxbospiral ![saxbospiral](saxbospiral.png "saxbospiral") -Experimental generation of 2D spiralling lines based on input binary data +Experimental generation of 2D spiralling lines based on input binary data. -## Dependencies +This is a library only, if you're looking for something that is immediately usable for the end-user, you probably want to look at [sxbp](https://github.com/saxbophone/sxbp) instead. -### Library +## Dependencies -For the library, you will need: +You will need: - A compiler that can compile ISO C99 code - [Cmake](https://cmake.org/) - v3.0 or newer - [libpng](http://www.libpng.org/pub/png/libpng.html) - (this often comes preinstalled with many modern unix-like systems) -### CLI - -For the included CLI program, you will also need: - -- [Argtable 2](http://argtable.sourceforge.net/) - must use v2, v1 and v3 will not work - > ### Note: > These commands are for unix-like systems, without an IDE or other build system besides CMake. If building for a different system, or within an IDE or other environment, consult your IDE/System documentation on how to build CMake projects. @@ -46,7 +40,7 @@ make make test ``` -## Install Library + Binaries +## Install Library This command might require `sudo`, but check your system configuration. For example, it installs to `/usr/local/` by default, which is user-writable on OSX if you use Homebrew, so not requiring admin privileges. From abe939f558fbd2179a347844a78f3818774733b8 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 14:58:34 +0100 Subject: [PATCH 08/10] Bump version 0.15 --- CMakeLists.txt | 2 +- README.md | 2 +- libsaxbospiral.png | Bin 0 -> 657 bytes saxbospiral.png | Bin 650 -> 0 bytes version.txt | 1 + 5 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 libsaxbospiral.png delete mode 100644 saxbospiral.png create mode 100644 version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1216a79..6b3d77d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # begin basic metadata cmake_minimum_required(VERSION 3.0) -project(libsaxbospiral VERSION 0.14.0 LANGUAGES C) +project(libsaxbospiral VERSION 0.15.0 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) set( diff --git a/README.md b/README.md index 477a9b2..af07e0a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Saxbospiral ![saxbospiral](saxbospiral.png "saxbospiral") +# Saxbospiral ![libsaxbospiral](libsaxbospiral.png "libsaxbospiral") Experimental generation of 2D spiralling lines based on input binary data. diff --git a/libsaxbospiral.png b/libsaxbospiral.png new file mode 100644 index 0000000000000000000000000000000000000000..57bf5f2867b32bd878a754168f028a2ad36ee867 GIT binary patch literal 657 zcmeAS@N?(olHy`uVBq!ia0vp^{y^-=2qYMGxE_fHQjEn;o*|6$uRXQ}a*Rt{BT5`g zOEU6{7`*a}GfEQ`f)gu}Dit&`N=gcft@QQNGfOf`lk}4FbM=dXGWi7=`FW|D;j2`c zf!aes+FeqMlZ!G7N;32F7+fm~Qj0QkQ}ap^a}?53^HPfvLE;MeX$nRz3dIGPMTt2% znR)37Kq9qRAt|vqHAMj^pP5%sTB4AYnU`2psgROblK5ht1s~7?1&{^K`303lnduoN z3~-hLvSTAMWq$$H%7D}c=ckpFCl;kL1Up7J`3DDh208jDlo{w5n&=sLDvFo`)fqy} z%mulU0k1b9K8CpZxUlqbVBkr4x;TbtOiaDBH|wy00Q-lXPb7$F{XDsf686pyE2wx zx`bV)ra_x`KJ)8{TY|hx&k6WnxzOA0@K!nWL8V%m?*oUqcOPi>+6b2}QQNlu%)jY3 zYmLtykohis*G(|5%x7z@N9m$FFUW5oAanS`=X(JSxx)J2*20MF8toOVWwrM_Vuor);fQ>PPZ6+epPrj zN7p93?@xN^*(HMFO#iFy2+eZ+ELXmqE5!Mh#v-5UvM&P5-HyuLiuKawH$OaE%l^Nv a?l1e;?SG}>_vwHV9D}E;pUXO@geCxu)d4>M literal 0 HcmV?d00001 diff --git a/saxbospiral.png b/saxbospiral.png deleted file mode 100644 index 61e355db1e8ade77b5870d8733d3e399f0c39b28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 650 zcmeAS@N?(olHy`uVBq!ia0vp^)*B;vfImRWf5haeL zB^mie3|{%g8KsE|!HE?~l?oaeB_##LR{HwsnI##eNqWiox%$OGnf!u`{Jd1n@KvhJ zK<%L*?JlXs$wiq3C7Jno46YRgsYRK&sd*)dIST2id8tK-AaRBKGzB9Uh2nzDqQsn> z%)E33Ady}dA{DR7&%=C;B z1~^Lr*|8CsvcG_8Wk70!^V3So6N^$Af*m8A{DT8LgB*Pn$_(@jP4o;r6-CT}>I@-f z=7LX&8~c;lQi8CCgtveqQ2a<>-;!B9xJ8c|$@+s>EkXTVK=G z%K?D}KQ3GdFgPQXb?fur>CU~K-^*I0q;tzza-OI$nf>ZH;1=7`eUC$Z#loTF)y67Wb!P%HTqp2Uq~K5T Date: Mon, 17 Oct 2016 14:59:50 +0100 Subject: [PATCH 09/10] Remove accidentally committed version file --- version.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 version.txt diff --git a/version.txt b/version.txt deleted file mode 100644 index 5a0e93e..0000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -libsaxbospiral 0.15.0 \ No newline at end of file From b7becd59e3a75a7a51a6bc75adb2a8e229a08455 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Mon, 17 Oct 2016 15:05:35 +0100 Subject: [PATCH 10/10] Remove now not needed bash include --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b3d77d..4f63cbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,5 +89,3 @@ install( enable_testing() add_test(unit_tests sxp_test) -# fetch a shell script runner -find_program(COMMAND_INTERPRETER bash)