diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-09-27 00:51:25 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-09-27 00:51:25 +0300 |
commit | 7286c9fc5b55df0499c7a8f28b5e61ec57e788cc (patch) | |
tree | 9aa8cd4c6ddd4e27d84dc94c6b91bdb0e380062d | |
parent | a087fe8c11f6139e0e0d48f055f8184e906befce (diff) | |
download | ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.gz ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.bz2 ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.zip |
Add licence and version info
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rw-r--r-- | LICENSE | 55 | ||||
-rw-r--r-- | src/actionparser.c | 27 | ||||
-rw-r--r-- | src/actions.c | 1 | ||||
-rw-r--r-- | src/ckinfo.h.in | 18 |
6 files changed, 71 insertions, 62 deletions
@@ -8,4 +8,7 @@ site-src/output site-src/.doit.db site-src/.doit.db.db site-src/.venv -site-src/nikolaserve.pid
\ No newline at end of file +site-src/nikolaserve.pid + +# autogenerated files +src/ckinfo.h
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ffd50c9..ff55a80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,16 +10,26 @@ ## -------------------------------------------------------------------------- */ cmake_minimum_required (VERSION 3.5.6) project(ck C) +# version +set(ck_MAJOR_VERSION 0) +set(ck_MINOR_VERSION 4) +# compiler set(CMAKE_C_COMPILER clang) -option(CK_ASAN "Build with asan") # compiler flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") + +# options +option(CK_ASAN "Build with asan") +option(CK_RELEASE "Release build") if(CK_ASAN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") -endif(CK_ASAN) +endif() + +if (NOT CK_RELEASE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") +endif() # Set project directories set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -27,6 +37,12 @@ set(RES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/res) set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) set(UNIT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/unit) +# configure the info header +configure_file( + "${SRC_DIR}/ckinfo.h.in" + "${SRC_DIR}/ckinfo.h" + ) + # Set source code locations set(ckBin_src ${SRC_DIR}/ck.c) set(ckUnitTest_src ${UNIT_TEST_DIR}/ck-test.c) @@ -39,7 +55,7 @@ set(ckLib_src ${SRC_DIR}/dbhelper.c ${SRC_DIR}/ckutil.c ${SRC_DIR}/cklist.c -) + ) set(ckLib_hdr ${SRC_DIR}/actionparser.h @@ -50,7 +66,8 @@ set(ckLib_hdr ${SRC_DIR}/dbhelper.h ${SRC_DIR}/ckutil.h ${SRC_DIR}/cklist.h -) + ${SRC_DIR}/ckinfo.h + ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RES_DIR}/cmake) @@ -618,57 +618,4 @@ an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - <program> Copyright (C) <year> <name of author> - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. + END OF TERMS AND CONDITIONS
\ No newline at end of file diff --git a/src/actionparser.c b/src/actionparser.c index 3e193ff..0057e7f 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -15,6 +15,7 @@ * -------------------------------------------------------------------------- */ #include "actionparser.h" #include "ckutil.h" +#include "ckinfo.h" /* accepted commands */ /* [0] is the count */ @@ -26,6 +27,7 @@ const char* const strLIST[] = {"5", "list", "l", "ls", "-l", "-ls"}; const char* const strSEARCH[] = {"3", "search", "s", "-s"}; const char* const strHELP[] = {"5", "help", "h", "-?", "-h", "--help"}; const char* const strConfDir[] = {"4", "config", "conf", "c", "-c"}; +const char* const strVersion[] = {"4", "version", "--version", "-v", "-V"}; /* Number of opts */ static int optNum; @@ -100,6 +102,7 @@ int parse_ADD(UserOpt *opt) { int parse_DEL(UserOpt *opt) { return -1; } + int parse_EDIT(UserOpt *opt) { /* EDIT expects 1 to 2 arguments */ if (optNum <= pos || optNum > pos + 2) { @@ -111,9 +114,10 @@ int parse_EDIT(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_LIST(UserOpt *opt) { /* List expects a maximum of than 3 arguments */ - if (optNum > pos + 4) { + if (optNum <= pos || optNum > pos + 4) { opt->err = PERR_LIST_WRONG; return -1; } @@ -122,6 +126,7 @@ int parse_LIST(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_SEARCH(UserOpt *opt) { /* Search expects a maximum of 1 argument */ if (optNum > pos + 1) { @@ -133,6 +138,7 @@ int parse_SEARCH(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_HELP(UserOpt *opt) { return -1; } @@ -230,6 +236,22 @@ void get_config(UserOpt *opt) { token = opts[pos]; } +void version() { + /* get first token */ + next_token(); + + for (int i = 1; i < atoi(strVersion[0]) + 1; i++) { + if (strcmp(token, strVersion[i]) == 0) { + print_version(); + exit(0); + } + } + + // rewind + pos = pos - 1; + token = opts[pos]; +} + void get_possible_action_strings(char *dest, CkAction ckAction) { char buf[STR_S]; switch (ckAction) { @@ -321,6 +343,9 @@ ActionParseResult parse_action(int argc, char* argv[], UserOpt *opt) { /* skip the program name */ next_token(); + /* handle version info */ + version(); + /* figure what is the config file */ get_config(opt); diff --git a/src/actions.c b/src/actions.c index b164779..54e781b 100644 --- a/src/actions.c +++ b/src/actions.c @@ -154,7 +154,6 @@ int run_LIST(UserOpt *opt, Conf *conf) { list_free(list_type); return 0; case LT_NONE: - printf("What should I list? (paths, configs)\n"); close_DB(&db); list_free(list_type); return 1; diff --git a/src/ckinfo.h.in b/src/ckinfo.h.in new file mode 100644 index 0000000..3b7f843 --- /dev/null +++ b/src/ckinfo.h.in @@ -0,0 +1,18 @@ +#ifndef CK_INFO_H +#define CK_INFO_H + +#include <stdio.h> + +#define CK_MAJOR_VERSION @ck_MAJOR_VERSION@ +#define CK_MINOR_VERSION @ck_MINOR_VERSION@ + + +extern void print_version() { + printf("ck version %d.%d\n", CK_MAJOR_VERSION, CK_MINOR_VERSION); + printf("ck Copyright (C) 2018 gramanas\n\ +This program comes with ABSOLUTELY NO WARRANTY.\n\ +This is free software, and you are welcome to redistribute it under\n\ +certain condition. See the LICENCE file in the source tree for details.\n"); +} + +#endif /* CK_INFO_H */ |