From e452f3d9975208a9e746a4993d17ef4bd3879c14 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 5 Jan 2017 22:42:37 +1300 Subject: Move words-misc into subdirectory --- LICENCE | 26 ------------------------- Makefile | 3 --- config.mk | 1 - match_pool.c | 50 ------------------------------------------------- words-misc/LICENCE | 27 ++++++++++++++++++++++++++ words-misc/Makefile | 3 +++ words-misc/config.mk | 1 + words-misc/match_pool.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 81 insertions(+), 80 deletions(-) delete mode 100644 LICENCE delete mode 100644 Makefile delete mode 100644 config.mk delete mode 100644 match_pool.c create mode 100644 words-misc/LICENCE create mode 100644 words-misc/Makefile create mode 100644 words-misc/config.mk create mode 100644 words-misc/match_pool.c diff --git a/LICENCE b/LICENCE deleted file mode 100644 index b787ef3..0000000 --- a/LICENCE +++ /dev/null @@ -1,26 +0,0 @@ -/* - * words-misc - Tools I write to assist with word games - * Copyright (c) 2016 David Phillips - * All rights reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ diff --git a/Makefile b/Makefile deleted file mode 100644 index a0e6cb9..0000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -include config.mk - -all: match_pool diff --git a/config.mk b/config.mk deleted file mode 100644 index e8c9b31..0000000 --- a/config.mk +++ /dev/null @@ -1 +0,0 @@ -CFLAGS += -Wall -Wextra -Werror diff --git a/match_pool.c b/match_pool.c deleted file mode 100644 index eda8f61..0000000 --- a/match_pool.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -int main(int argc, char **argv) -{ - int i = 0; - char buffer[1024]; - char *res = NULL; - char *pool = NULL; - char *local_pool = NULL; - size_t pool_size = 0; - - - if (argc != 2) - { - fprintf(stderr, "Usage: %s \n", argv[0]); - return EXIT_FAILURE; - } - - pool = argv[1]; - pool_size = strlen(pool); - - local_pool = malloc(pool_size); - if (local_pool == NULL) - { - fprintf(stderr, "%s: malloc for local pool failed\n", argv[0]); - return EXIT_FAILURE; - } - - while (fgets(buffer, sizeof(buffer), stdin)) - { - buffer[strcspn(buffer, "\r\n")] = '\0'; /* chomp */ - - if (strlen(buffer) == 0) - continue; - - strcpy(local_pool, pool); - for (i = strlen(buffer)-1; i >= 0; i--) - { - if ((res = memchr(local_pool, buffer[i], pool_size)) != NULL) - *res = '\0'; - else - break; - } - printf("%s %s\n", buffer, i < 0? "matches" : "doesn't match" ); - } - free(local_pool); - return 0; -} diff --git a/words-misc/LICENCE b/words-misc/LICENCE new file mode 100644 index 0000000..cd46956 --- /dev/null +++ b/words-misc/LICENCE @@ -0,0 +1,27 @@ +/* + * words-misc - Tools I write to assist with word games + * Copyright (c) 2016 David Phillips + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + diff --git a/words-misc/Makefile b/words-misc/Makefile new file mode 100644 index 0000000..a0e6cb9 --- /dev/null +++ b/words-misc/Makefile @@ -0,0 +1,3 @@ +include config.mk + +all: match_pool diff --git a/words-misc/config.mk b/words-misc/config.mk new file mode 100644 index 0000000..e8c9b31 --- /dev/null +++ b/words-misc/config.mk @@ -0,0 +1 @@ +CFLAGS += -Wall -Wextra -Werror diff --git a/words-misc/match_pool.c b/words-misc/match_pool.c new file mode 100644 index 0000000..eda8f61 --- /dev/null +++ b/words-misc/match_pool.c @@ -0,0 +1,50 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + int i = 0; + char buffer[1024]; + char *res = NULL; + char *pool = NULL; + char *local_pool = NULL; + size_t pool_size = 0; + + + if (argc != 2) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + pool = argv[1]; + pool_size = strlen(pool); + + local_pool = malloc(pool_size); + if (local_pool == NULL) + { + fprintf(stderr, "%s: malloc for local pool failed\n", argv[0]); + return EXIT_FAILURE; + } + + while (fgets(buffer, sizeof(buffer), stdin)) + { + buffer[strcspn(buffer, "\r\n")] = '\0'; /* chomp */ + + if (strlen(buffer) == 0) + continue; + + strcpy(local_pool, pool); + for (i = strlen(buffer)-1; i >= 0; i--) + { + if ((res = memchr(local_pool, buffer[i], pool_size)) != NULL) + *res = '\0'; + else + break; + } + printf("%s %s\n", buffer, i < 0? "matches" : "doesn't match" ); + } + free(local_pool); + return 0; +} -- cgit v1.1