diff options
-rw-r--r-- | CMakeLists.txt | 17 | ||||
-rw-r--r-- | README.html | 276 | ||||
-rw-r--r-- | README.org | 89 | ||||
-rw-r--r-- | src/actionparser.c | 10 | ||||
-rw-r--r-- | src/actionparser.h | 2 | ||||
-rw-r--r-- | src/actions.c | 4 | ||||
-rw-r--r-- | src/ck.c | 2 | ||||
-rw-r--r-- | src/ckerrlog.c | 31 | ||||
-rw-r--r-- | src/ckerrlog.h | 12 | ||||
-rw-r--r-- | src/cklist.c | 20 | ||||
-rw-r--r-- | src/cklist.h | 16 | ||||
-rw-r--r-- | src/ckutil.c | 2 | ||||
-rw-r--r-- | src/confparser.c | 2 | ||||
-rw-r--r-- | src/confparser.h | 1 | ||||
-rw-r--r-- | src/dblayer.c | 12 |
15 files changed, 314 insertions, 182 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3808c3c..c5c5620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,21 +14,20 @@ project(ck C) set(ck_MAJOR_VERSION 0) set(ck_MINOR_VERSION 7) -# c flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +# Feature test macros +set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE") +# Default C flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FEATURE_TEST_MACROS} -std=c99 -pedantic") +# Warnings for debug builds +set(C_WARNINGS "-Wall -Wextra -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith") # options -option(CK_ASAN "Build with asan") -option(CK_DEBUG "Build with debug symbols") +option(CK_DEBUG "Build with debug symbols, asan and warnings") option(CK_TESTS "Make the tests") option(CK_SHARED "Build with shared lib") -if(CK_ASAN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") -endif() - if (CK_DEBUG) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WARNINGS} -g3 -fsanitize=address") else(CK_DEBUG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") endif() diff --git a/README.html b/README.html index 7d71922..dc25609 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2018-10-23 Tue 10:35 --> +<!-- 2018-10-26 Fri 16:01 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>‎</title> @@ -232,35 +232,40 @@ for the JavaScript code in this tag. <h2>Table of Contents</h2> <div id="text-table-of-contents"> <ul> -<li><a href="#org188eec0">ck</a></li> -<li><a href="#org5cf05fb">build it</a> +<li><a href="#org521fe12">ck</a> <ul> -<li><a href="#orgddaa24b">requirements</a></li> -<li><a href="#org4b2326a">compiler</a></li> -<li><a href="#orgcc546ab">make</a></li> +<li><a href="#orga2a199d">Technicalities</a></li> +<li><a href="#orge675bb7">Download</a></li> </ul> </li> -<li><a href="#org8c57e12">for devs</a> +<li><a href="#build-instructions">build it</a> <ul> -<li><a href="#org6c910a6">CMake options</a></li> -<li><a href="#org9be5ed3">tests</a> +<li><a href="#orgc421406">requirements</a></li> +<li><a href="#orga4dab6e">make && install</a></li> +</ul> +</li> +<li><a href="#orge2205a2">for devs</a> +<ul> +<li><a href="#org5f75c37">CMake options</a></li> +<li><a href="#orgac3cc9e">compiler</a></li> +<li><a href="#org32fde8e">tests</a> <ul> -<li><a href="#orgbe86272">run tests</a></li> -<li><a href="#org136123c">test suite</a></li> +<li><a href="#orgf37899e">run tests</a></li> +<li><a href="#orgff9613a">test suite</a></li> </ul> </li> </ul> </li> -<li><a href="#org1b4ae92">manual</a> +<li><a href="#manual">manual</a> <ul> -<li><a href="#org028f12c">ck configuration</a></li> -<li><a href="#org675d6b6">Actions</a> +<li><a href="#org8bc297f">ck configuration</a></li> +<li><a href="#orgfb252e7">Actions</a> <ul> -<li><a href="#orgd421244">init</a></li> -<li><a href="#org400c289">add</a></li> -<li><a href="#orgab0ce16">list</a></li> -<li><a href="#orgb29e969">search</a></li> -<li><a href="#orgd0ea024">edit</a></li> +<li><a href="#org0bde617">init</a></li> +<li><a href="#orge38e9d6">add</a></li> +<li><a href="#org224e52f">list</a></li> +<li><a href="#org21ebeec">search</a></li> +<li><a href="#orgb56bde4">edit</a></li> </ul> </li> </ul> @@ -269,45 +274,117 @@ for the JavaScript code in this tag. </div> </div> <p align="center"><img src="res/logo.png"></p> -<div id="outline-container-org188eec0" class="outline-2"> -<h2 id="org188eec0">ck</h2> -<div class="outline-text-2" id="text-org188eec0"> +<div id="outline-container-org521fe12" class="outline-2"> +<h2 id="org521fe12">ck</h2> +<div class="outline-text-2" id="text-org521fe12"> <p> <b>The Config Keeper</b> </p> + +<p> +Have you ever wondered: +</p> +<blockquote> +<p> +"Jeez Luiz, how can I manage all my configs across my desktop and server?" +</p> + +<p> +– You +</p> +</blockquote> + +<p> +or maybe: +</p> +<blockquote> +<p> +"How can I possibly keep all my configs in sync across computers?" +</p> + +<p> +– You again +</p> +</blockquote> + +<p> +<b>ck</b> is the solution you've been looking for all your life. +</p> + +<p> +With it you can keep track of all the configs you cherish and love, +and store them neat and tidy in a folder you can later sync using +your favorite sync solution (git, nextcloud, rsync). You can even gift +your precious data to Google and use GDrive (<i><i>not recommended!!</i></i>). +</p> + +<p> +After you create your local config db you can list them, edit them +and even search in them, all within the comforting hands of <b>ck</b>, your +faithful companion. +</p> + +<p> +You can also use <b>ck</b> to store sensitive configurations (with passwords, etc) +and instruct it to save them in a different folder, so they won't be in the +same place with the normal ones (in the event you want to share your configs +with the rest of us). +</p> +</div> + +<div id="outline-container-orga2a199d" class="outline-3"> +<h3 id="orga2a199d">Technicalities</h3> +<div class="outline-text-3" id="text-orga2a199d"> +<p> +Upon adding a config to <b>ck</b>, it moves it to the specified folder and adds a symbolic link +back where it came from (<code>ln -s</code>). +</p> + +<p> +Make sure that the target program can read it's configuration from a symlink (the vast +majority should). +</p> </div> </div> -<div id="outline-container-org5cf05fb" class="outline-2"> -<h2 id="org5cf05fb">build it</h2> -<div class="outline-text-2" id="text-org5cf05fb"> +<div id="outline-container-orge675bb7" class="outline-3"> +<h3 id="orge675bb7">Download</h3> +<div class="outline-text-3" id="text-orge675bb7"> +<p> +Go ahead and download <b>ck</b> and give it a try. It comes with a help sub-command +that explains any inquires you might have. +</p> + +<p> +Grab the latest zip/tarball from the tag section in the <a href="https://ubuntos.dynu.net/git/ck">repo</a> and proceed to +the <a href="#build-instructions">build</a> section. +</p> + +<p> +You can also read the manual <a href="#manual">down below</a>. +</p> </div> -<div id="outline-container-orgddaa24b" class="outline-3"> -<h3 id="orgddaa24b">requirements</h3> -<div class="outline-text-3" id="text-orgddaa24b"> -<ul class="org-ul"> -<li>clang (llvm) or gcc (gnu)</li> -<li>cmake</li> -<li>sqlite3-dev</li> -</ul> </div> </div> -<div id="outline-container-org4b2326a" class="outline-3"> -<h3 id="org4b2326a">compiler</h3> -<div class="outline-text-3" id="text-org4b2326a"> -<div class="org-src-container"> -<pre class="src src-sh">> export <span style="color: #baba36;">CC</span>=clang -<span style="color: #656565;"># </span><span style="color: #757575;">or</span> -> export <span style="color: #baba36;">CC</span>=gcc -</pre> +<div id="outline-container-orga8e0de1" class="outline-2"> +<h2 id="build-instructions"><a id="orga8e0de1"></a>build it</h2> +<div class="outline-text-2" id="text-build-instructions"> </div> +<div id="outline-container-orgc421406" class="outline-3"> +<h3 id="orgc421406">requirements</h3> +<div class="outline-text-3" id="text-orgc421406"> +<ul class="org-ul"> +<li>cmake</li> +<li>sqlite3-dev</li> +<li>build tools (gcc/llvm, make…)</li> +</ul> </div> </div> -<div id="outline-container-orgcc546ab" class="outline-3"> -<h3 id="orgcc546ab">make</h3> -<div class="outline-text-3" id="text-orgcc546ab"> +<div id="outline-container-orga4dab6e" class="outline-3"> +<h3 id="orga4dab6e">make && install</h3> +<div class="outline-text-3" id="text-orga4dab6e"> <p> Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install path. </p> @@ -330,22 +407,21 @@ Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install </div> </div> -<div id="outline-container-org8c57e12" class="outline-2"> -<h2 id="org8c57e12">for devs</h2> -<div class="outline-text-2" id="text-org8c57e12"> +<div id="outline-container-orge2205a2" class="outline-2"> +<h2 id="orge2205a2">for devs</h2> +<div class="outline-text-2" id="text-orge2205a2"> <p> Please be <a href="https://www.gnu.org/philosophy/kind-communication.html">kind</a> to each other. </p> </div> -<div id="outline-container-org6c910a6" class="outline-3"> -<h3 id="org6c910a6">CMake options</h3> -<div class="outline-text-3" id="text-org6c910a6"> +<div id="outline-container-org5f75c37" class="outline-3"> +<h3 id="org5f75c37">CMake options</h3> +<div class="outline-text-3" id="text-org5f75c37"> <p> cmake accepts the following options: </p> <div class="org-src-container"> -<pre class="src src-cmake"><span style="color: #6aaf50;">option</span>(CK_ASAN <span style="color: #bdbc61;">"Build with asan"</span>) -<span style="color: #6aaf50;">option</span>(CK_DEBUG <span style="color: #bdbc61;">"Build with debug symbols"</span>) +<pre class="src src-cmake"><span style="color: #6aaf50;">option</span>(CK_DEBUG <span style="color: #bdbc61;">"Build with debug symbols, asan and warnings"</span>) <span style="color: #6aaf50;">option</span>(CK_TESTS <span style="color: #bdbc61;">"Make the tests"</span>) <span style="color: #6aaf50;">option</span>(CK_SHARED <span style="color: #bdbc61;">"Build with shared lib"</span>) </pre> @@ -355,23 +431,37 @@ cmake accepts the following options: To use any one of them append it after the cmake command like so: </p> <div class="org-src-container"> -<pre class="src src-sh">cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck +<pre class="src src-sh">cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck </pre> </div> +</div> +</div> +<div id="outline-container-orgac3cc9e" class="outline-3"> +<h3 id="orgac3cc9e">compiler</h3> +<div class="outline-text-3" id="text-orgac3cc9e"> <p> -Just build with address sanitizer enabled like so: -llvm has better asan than gcc, so I use that. +Pick your favorite </p> <div class="org-src-container"> +<pre class="src src-sh">> export <span style="color: #baba36;">CC</span>=clang +<span style="color: #656565;"># </span><span style="color: #757575;">or</span> +> export <span style="color: #baba36;">CC</span>=gcc +</pre> +</div> + + +<div class="org-src-container"> <pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">clone the repo</span> > cd ~/code; git clone https://gitlab.com/grm-grm/ck <span style="color: #656565;"># </span><span style="color: #757575;">make a build directory and enter it</span> > mkdir ~/ck_build; <span style="color: #528fd1;">cd</span> ~/ck_build; <span style="color: #656565;"># </span><span style="color: #757575;">run cmake</span> -> cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck +> cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck <span style="color: #656565;"># </span><span style="color: #757575;">run make</span> > make +<span style="color: #656565;"># </span><span style="color: #757575;">check ck</span> +> ./test-ck <span style="color: #656565;"># </span><span style="color: #757575;">run ck</span> > ./ck </pre> @@ -379,9 +469,9 @@ llvm has better asan than gcc, so I use that. </div> </div> -<div id="outline-container-org9be5ed3" class="outline-3"> -<h3 id="org9be5ed3">tests</h3> -<div class="outline-text-3" id="text-org9be5ed3"> +<div id="outline-container-org32fde8e" class="outline-3"> +<h3 id="org32fde8e">tests</h3> +<div class="outline-text-3" id="text-org32fde8e"> <p> The testing "suite" is a bash script that runs regression and unit tests. Regression tests are under the <code>tests/</code> directory @@ -390,9 +480,9 @@ under <code>unit/</code> directory and test the code. </p> </div> -<div id="outline-container-orgbe86272" class="outline-4"> -<h4 id="orgbe86272">run tests</h4> -<div class="outline-text-4" id="text-orgbe86272"> +<div id="outline-container-orgf37899e" class="outline-4"> +<h4 id="orgf37899e">run tests</h4> +<div class="outline-text-4" id="text-orgf37899e"> <p> First make sure you build ck with the <code>-DCK_TESTS=1</code> option. Then go to the build directory and type: @@ -404,9 +494,9 @@ go to the build directory and type: </div> </div> -<div id="outline-container-org136123c" class="outline-4"> -<h4 id="org136123c">test suite</h4> -<div class="outline-text-4" id="text-org136123c"> +<div id="outline-container-orgff9613a" class="outline-4"> +<h4 id="orgff9613a">test suite</h4> +<div class="outline-text-4" id="text-orgff9613a"> <div class="org-src-container"> <pre class="src src-sh">$ ./test-ck -h ck test suite @@ -424,9 +514,9 @@ flags: </div> </div> </div> -<div id="outline-container-org1b4ae92" class="outline-2"> -<h2 id="org1b4ae92">manual</h2> -<div class="outline-text-2" id="text-org1b4ae92"> +<div id="outline-container-org68d2b05" class="outline-2"> +<h2 id="manual"><a id="org68d2b05"></a>manual</h2> +<div class="outline-text-2" id="text-manual"> <p> ck's goal is to assist with the configuration file management. To that end it tries to provides a cli interface that is pretty straight-forward @@ -467,8 +557,8 @@ $ ck search <span style="color: #bdbc61;">"\("</span> <span style="color: #65656 <p> The first command after typing <b>ck</b> is the action you wish to perform. Actions are -a very important concept of ck. With an action you can initialize <b>ck</b>, add/move/delete -configuration files to it, edit them, list them in various ways and search in their content. +a very important concept of ck. With an action you can initialize <b>ck</b>, add/delete +configuration files to/from it, edit them, list them in various ways and search in their content. </p> <p> @@ -477,12 +567,12 @@ of flags one has to pass to ck. </p> </div> -<div id="outline-container-org028f12c" class="outline-3"> -<h3 id="org028f12c">ck configuration</h3> -<div class="outline-text-3" id="text-org028f12c"> +<div id="outline-container-org8bc297f" class="outline-3"> +<h3 id="org8bc297f">ck configuration</h3> +<div class="outline-text-3" id="text-org8bc297f"> <p> ck uses sqlite to index the configuration files. The init -action creates a <b>.ck</b> directory (under $HOME) +action creates a <b>.ck</b> directory (under <code>$HOME</code>) in witch the <b>ckrc</b> and the <b>ckdb</b> reside. The first one contains the two directories described above while the other one is the sqlite db. @@ -517,13 +607,13 @@ $ ck -c /someplace/else ... </div> </div> -<div id="outline-container-org675d6b6" class="outline-3"> -<h3 id="org675d6b6">Actions</h3> -<div class="outline-text-3" id="text-org675d6b6"> +<div id="outline-container-orgfb252e7" class="outline-3"> +<h3 id="orgfb252e7">Actions</h3> +<div class="outline-text-3" id="text-orgfb252e7"> </div> -<div id="outline-container-orgd421244" class="outline-4"> -<h4 id="orgd421244">init</h4> -<div class="outline-text-4" id="text-orgd421244"> +<div id="outline-container-org0bde617" class="outline-4"> +<h4 id="org0bde617">init</h4> +<div class="outline-text-4" id="text-org0bde617"> <p> or i or -i </p> @@ -553,9 +643,9 @@ $ ck init /path_to/where_you_want/your_configs/to_be <span style="color: #bdbc61 </div> </div> -<div id="outline-container-org400c289" class="outline-4"> -<h4 id="org400c289">add</h4> -<div class="outline-text-4" id="text-org400c289"> +<div id="outline-container-orge38e9d6" class="outline-4"> +<h4 id="orge38e9d6">add</h4> +<div class="outline-text-4" id="text-orge38e9d6"> <p> or a or -a </p> @@ -596,9 +686,9 @@ $ ck add program_name config_path [-s] [-p] </div> </div> -<div id="outline-container-orgab0ce16" class="outline-4"> -<h4 id="orgab0ce16">list</h4> -<div class="outline-text-4" id="text-orgab0ce16"> +<div id="outline-container-org224e52f" class="outline-4"> +<h4 id="org224e52f">list</h4> +<div class="outline-text-4" id="text-org224e52f"> <p> or ls or l or -l </p> @@ -661,9 +751,9 @@ $ ck -l ckconf </div> </div> -<div id="outline-container-orgb29e969" class="outline-4"> -<h4 id="orgb29e969">search</h4> -<div class="outline-text-4" id="text-orgb29e969"> +<div id="outline-container-org21ebeec" class="outline-4"> +<h4 id="org21ebeec">search</h4> +<div class="outline-text-4" id="text-org21ebeec"> <p> or grep or s or -s </p> @@ -712,9 +802,9 @@ $ for i ($(ck ls paths)) grep -E <span style="color: #bdbc61;">'A|B'</span> $<sp </div> </div> -<div id="outline-container-orgd0ea024" class="outline-4"> -<h4 id="orgd0ea024">edit</h4> -<div class="outline-text-4" id="text-orgd0ea024"> +<div id="outline-container-orgb56bde4" class="outline-4"> +<h4 id="orgb56bde4">edit</h4> +<div class="outline-text-4" id="text-orgb56bde4"> <p> or e or -e </p> @@ -763,7 +853,7 @@ $ ck edit emacs accounts.el </div> </div> <div id="postamble" class="status"> -<p class="date">Created: 2018-10-23 Tue 10:35</p> +<p class="date">Created: 2018-10-26 Fri 16:01</p> <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> </div> </body> @@ -3,20 +3,62 @@ * ck *The Config Keeper* +Have you ever wondered: +#+BEGIN_QUOTE + "Jeez Luiz, how can I manage all my configs across my desktop and server?" + + -- You +#+END_QUOTE + +or maybe: +#+BEGIN_QUOTE + "How can I possibly keep all my configs in sync across computers?" + + -- You again +#+END_QUOTE + +*ck* is the solution you've been looking for all your life. + +With it you can keep track of all the configs you cherish and love, +and store them neat and tidy in a folder you can later sync using +your favorite sync solution (git, nextcloud, rsync). You can even gift +your precious data to Google and use GDrive (//not recommended!!//). + +After you create your local config db you can list them, edit them +and even search in them, all within the comforting hands of *ck*, your +faithful companion. + +You can also use *ck* to store sensitive configurations (with passwords, etc) +and instruct it to save them in a different folder, so they won't be in the +same place with the normal ones (in the event you want to share your configs +with the rest of us). + +** Technicalities +Upon adding a config to *ck*, it moves it to the specified folder and adds a symbolic link +back where it came from (=ln -s=). + +Make sure that the target program can read it's configuration from a symlink (the vast +majority should). + +** Download +Go ahead and download *ck* and give it a try. It comes with a help sub-command +that explains any inquires you might have. + +Grab the latest zip/tarball from the tag section in the [[https://ubuntos.dynu.net/git/ck][repo]] and proceed to +the [[#build-instructions][build]] section. + +You can also read the manual [[#manual][down below]]. + * build it + :PROPERTIES: + :CUSTOM_ID: build-instructions + :END: ** requirements -- clang (llvm) or gcc (gnu) - cmake - sqlite3-dev +- build tools (gcc/llvm, make...) -** compiler -#+BEGIN_SRC sh - > export CC=clang - # or - > export CC=gcc -#+END_SRC - -** make +** make && install Use =-DCMAKE_INSTALL_PREFIX= when running cmake to change the install path. #+BEGIN_SRC sh # clone the repo @@ -38,28 +80,36 @@ Please be [[https://www.gnu.org/philosophy/kind-communication.html][kind]] to ea ** CMake options cmake accepts the following options: #+BEGIN_SRC cmake - option(CK_ASAN "Build with asan") - option(CK_DEBUG "Build with debug symbols") + option(CK_DEBUG "Build with debug symbols, asan and warnings") option(CK_TESTS "Make the tests") option(CK_SHARED "Build with shared lib") #+END_SRC To use any one of them append it after the cmake command like so: #+BEGIN_SRC sh - cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck + cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck +#+END_SRC + +** compiler +Pick your favorite +#+BEGIN_SRC sh + > export CC=clang + # or + > export CC=gcc #+END_SRC -Just build with address sanitizer enabled like so: -llvm has better asan than gcc, so I use that. + #+BEGIN_SRC sh # clone the repo > cd ~/code; git clone https://gitlab.com/grm-grm/ck # make a build directory and enter it > mkdir ~/ck_build; cd ~/ck_build; # run cmake - > cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck + > cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck # run make > make + # check ck + > ./test-ck # run ck > ./ck #+END_SRC @@ -91,6 +141,9 @@ flags: -h, --help, * print this #+END_SRC * manual + :PROPERTIES: + :CUSTOM_ID: manual + :END: ck's goal is to assist with the configuration file management. To that end it tries to provides a cli interface that is pretty straight-forward and intuitive. @@ -125,15 +178,15 @@ Example usage: #+END_SRC The first command after typing *ck* is the action you wish to perform. Actions are -a very important concept of ck. With an action you can initialize *ck*, add/move/delete -configuration files to it, edit them, list them in various ways and search in their content. +a very important concept of ck. With an action you can initialize *ck*, add/delete +configuration files to/from it, edit them, list them in various ways and search in their content. Actions expect their arguments in the order specified below. This is done to reduce the amount of flags one has to pass to ck. ** ck configuration ck uses sqlite to index the configuration files. The init -action creates a *.ck* directory (under $HOME) +action creates a *.ck* directory (under =$HOME=) in witch the *ckrc* and the *ckdb* reside. The first one contains the two directories described above while the other one is the sqlite db. diff --git a/src/actionparser.c b/src/actionparser.c index 009ee2a..9954fbc 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -34,10 +34,10 @@ static int optNum; /* holds the list of the opts * as given by the user */ -static char **opts; +static const char **opts; /* points to the current token */ -static char *token; +static const char *token; /* the position to be read */ static int pos = 0; @@ -205,7 +205,7 @@ void determine_action(UserOpt *opt) { UserOpt make_empty_user_opt() { UserOpt opt; - opt.action = -1; + opt.action = CK_WRONG_ACTION; opt.err = PERR_NOERR; opt.confDir = NULL; opt.args = list_make_new(); @@ -252,7 +252,7 @@ int get_config(UserOpt *opt) { pos = pos - 1; token = opts[pos]; } - char * defaultConf = ".ck"; + char defaultConf[STR_S] = ".ck"; char * home = getenv("HOME"); opt->confDir = malloc(strlen(defaultConf) + 1 /* '/' */ + strlen(home) + 1); str_join_dirname_with_basename(opt->confDir, home, defaultConf); @@ -378,7 +378,7 @@ void print_parser_help() { report_help(); } -int parse_action(int argc, char* argv[], UserOpt *opt) { +int parse_action(int argc, const char **argv, UserOpt *opt) { /* make empty user opt */ *opt = make_empty_user_opt(); opts = argv; diff --git a/src/actionparser.h b/src/actionparser.h index 6fa6136..3735ea8 100644 --- a/src/actionparser.h +++ b/src/actionparser.h @@ -67,7 +67,7 @@ struct UserOptions { /* Parse cli args, fill UserOpt struct * and return the result enum */ -extern int parse_action(int argc, char* argv[], UserOpt *opt); +extern int parse_action(int argc, const char **argv, UserOpt *opt); extern CkAction parser_get_action(const char *name, char *actionName); extern void get_possible_action_strings(char *dest, CkAction ckAction); extern void free_user_opt(UserOpt *opt); diff --git a/src/actions.c b/src/actions.c index b887399..48a4066 100644 --- a/src/actions.c +++ b/src/actions.c @@ -230,10 +230,8 @@ int run_LIST(UserOpt *opt, Conf *conf) { return 1; } -FILE *popen(const char *command, const char *mode); -int pclose(FILE *stream); - int run_SEARCH(UserOpt *opt, Conf *conf) { + UNUSED(conf); if (system("which grep > /dev/null") != 0) { return 2; } @@ -36,7 +36,7 @@ ERRLOG(main); -int main(int argc, char *argv[]) { +int main(int argc, const char **argv) { initialize_errlog(argc, argv); UserOpt opt; Conf conf = {.vc_dir = NULL, .scrt_dir = NULL}; diff --git a/src/ckerrlog.c b/src/ckerrlog.c index a023521..cfafb39 100644 --- a/src/ckerrlog.c +++ b/src/ckerrlog.c @@ -31,7 +31,7 @@ char *get_time() { return buf; } -void log_command(int argc, char* argv[]) { +void log_command(int argc,const char* argv[]) { char tmp[STR_L] = ""; for(int i = 0; i < argc; i++) { strcat(tmp, argv[i]); @@ -41,7 +41,8 @@ void log_command(int argc, char* argv[]) { } #define X(stream) \ - void add_ ## stream ## _with_delim(char *delim, char *txt, \ + void add_ ## stream ## _with_delim(const char *delim, \ + const char *txt, \ va_list args) { \ char tmp[STR_L]; \ vsprintf(tmp, txt, args); \ @@ -56,22 +57,22 @@ void log_command(int argc, char* argv[]) { CK_STREAMS #undef X -#define X(stream) \ - void ck## stream(char *txt, ...) { \ - va_list args; \ - va_start(args, txt); \ - add_## stream ##_with_delim("\n", txt, args); \ - va_end(args); \ +#define X(stream) \ + void ck## stream(const char *txt, ...) { \ + va_list args; \ + va_start(args, txt); \ + add_## stream ##_with_delim("\n", txt, args); \ + va_end(args); \ } CK_STREAMS #undef X -#define X(stream) \ - void ck## stream ##_with_delim(char *d, char *txt, ...) { \ - va_list args; \ - va_start(args, txt); \ - add_## stream ##_with_delim(d, txt, args); \ - va_end(args); \ +#define X(stream) \ + void ck## stream ##_with_delim(const char *d, const char *txt, ...) { \ + va_list args; \ + va_start(args, txt); \ + add_## stream ##_with_delim(d, txt, args); \ + va_end(args); \ } CK_STREAMS #undef X @@ -123,7 +124,7 @@ extern void errlog_set_verbose(int level) { } -void initialize_errlog(int argc, char* argv[]) { +void initialize_errlog(int argc, const char** argv) { #define X(stream) stream = NULL; CK_STREAMS #undef X diff --git a/src/ckerrlog.h b/src/ckerrlog.h index aa5840b..9d71458 100644 --- a/src/ckerrlog.h +++ b/src/ckerrlog.h @@ -48,17 +48,13 @@ X(logv) \ X(help) -extern void initialize_errlog(int argc, char* argv[]); +extern void initialize_errlog(int argc, const char** argv); extern void report_errlog(); extern void errlog_set_verbose(int level); -extern void ckerr(char *err, ...); -extern void cklog(char *log, ...); -extern void ckhelp(char *log, ...); - -#define X(stream) \ - extern void ck## stream(char *log, ...); \ - void ck## stream ##_with_delim(char *d, char *txt, ...); \ +#define X(stream) \ + extern void ck## stream(const char *log, ...); \ + void ck## stream ##_with_delim(const char *d,const char *txt, ...); \ void report_## stream(); CK_STREAMS #undef X diff --git a/src/cklist.c b/src/cklist.c index 2fdfa07..f255556 100644 --- a/src/cklist.c +++ b/src/cklist.c @@ -50,19 +50,13 @@ int list_next(cklist *ckl) { } char* list_get(cklist *ckl) { - if (ckl->pos == -1) { - return NULL; - } if (ckl->pos >= ckl->size) { return NULL; } return ckl->arr[ckl->pos]; } -char* list_get_at(cklist *ckl, int pos) { - if (ckl->pos == -1) { - return NULL; - } +char* list_get_at(cklist *ckl, unsigned int pos) { if (ckl->pos >= ckl->size || pos >= ckl->size) { return NULL; @@ -94,7 +88,7 @@ cklist* list_move(cklist *ckl) { return _ckl; } -cklist* list_copy_from(cklist *ckl, int index) { +cklist* list_copy_from(cklist *ckl,unsigned int index) { list_rewind(ckl); cklist *_ckl = list_make_new(); if (ckl->pos >= index) { @@ -109,7 +103,7 @@ cklist* list_copy_from(cklist *ckl, int index) { return _ckl; } -cklist* list_copy_until(cklist *ckl, int index) { +cklist* list_copy_until(cklist *ckl,unsigned int index) { list_rewind(ckl); cklist *_ckl = list_make_and_add(list_get(ckl)); while(list_next(ckl)) { @@ -121,7 +115,7 @@ cklist* list_copy_until(cklist *ckl, int index) { return _ckl; } -cklist* list_copy_part(cklist *ckl, int from, int until) { +cklist* list_copy_part(cklist *ckl,unsigned int from,unsigned int until) { list_rewind(ckl); cklist *_ckl = list_make_new(); if (ckl->pos >= from && ckl->pos < until) { @@ -185,7 +179,7 @@ void list_print_concat(cklist *ckl) { } } -int list_exists(cklist *ckl, char *str) { +int list_exists(cklist *ckl, const char *str) { if (ckl->size > 0) { list_rewind(ckl); do { @@ -197,12 +191,12 @@ int list_exists(cklist *ckl, char *str) { return 0; } -int list_size(cklist *ckl) { +unsigned int list_size(cklist *ckl) { return ckl->size; } void list_free(cklist *ckl) { - int i; + unsigned int i; for (i=0; i<ckl->size; i++) { free(ckl->arr[i]); } diff --git a/src/cklist.h b/src/cklist.h index 3cf0f7c..dcc6763 100644 --- a/src/cklist.h +++ b/src/cklist.h @@ -16,8 +16,8 @@ #define CKLIST_H typedef struct cklist_st cklist; struct cklist_st { - int size; - int pos; + unsigned int size; + unsigned int pos; char **arr; }; @@ -28,9 +28,9 @@ extern void list_rewind(cklist *ckl); extern int list_next(cklist *ckl); extern char* list_get(cklist *ckl); -extern char* list_get_at(cklist *ckl, int pos); +extern char* list_get_at(cklist *ckl,unsigned int pos); -extern int list_size(cklist *ckl); +extern unsigned int list_size(cklist *ckl); /* rewinds */ extern cklist* list_duplicate(cklist *ckl); @@ -38,17 +38,17 @@ extern cklist* list_duplicate(cklist *ckl); extern cklist* list_move(cklist *ckl); /* rewinds * copy from index (>=) to the end */ -extern cklist* list_copy_from(cklist *ckl, int index); +extern cklist* list_copy_from(cklist *ckl,unsigned int index); /* rewinds * copy from the start until (<) index*/ -extern cklist* list_copy_until(cklist *ckl, int index); +extern cklist* list_copy_until(cklist *ckl,unsigned int index); /* rewinds * copy from (>=) until (<) */ -extern cklist* list_copy_part(cklist *ckl, int from, int until); +extern cklist* list_copy_part(cklist *ckl,unsigned int from,unsigned int until); /* return 1 if str exists in the list, 0 otherwise */ -extern int list_exists(cklist *ckl, char *str); +extern int list_exists(cklist *ckl, const char *str); /* rewinds */ extern void list_print_lisp(cklist *ckl); diff --git a/src/ckutil.c b/src/ckutil.c index b852f72..84eb43d 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -97,7 +97,7 @@ int util_move_file(const char *path, const char* dest) { struct stat st, newSt; fstat(srcFile, &st); - sendfile(destFile, srcFile, NULL, st.st_size); + sendfile(destFile, srcFile, NULL, (size_t)st.st_size); close(srcFile); fchmod(destFile, st.st_mode); diff --git a/src/confparser.c b/src/confparser.c index 6dea001..3a7c357 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -42,7 +42,7 @@ ConfVar match_variables(char *line, char matched[]) { } CONFIG_VARIABLES_TABLE #undef X - return -1; + return CV_WRONG_VAL; } void make_config_name(char * ret, const char *confPath) { diff --git a/src/confparser.h b/src/confparser.h index 94541c6..f4c52c3 100644 --- a/src/confparser.h +++ b/src/confparser.h @@ -24,6 +24,7 @@ enum ConfingVariables { CV_NO_VAL_OR_COMMENT, + CV_WRONG_VAL, #define X(var, str, name) CV_##var, CONFIG_VARIABLES_TABLE #undef X diff --git a/src/dblayer.c b/src/dblayer.c index 8703c1e..acdf339 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -41,7 +41,7 @@ int check_initialized_DB(sqlite3 *db) { dbh_form_query_select_all_tables(sql); sqlite3_stmt *stmt; - sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + sqlite3_prepare_v2(db, sql, (int)strlen(sql), &stmt, NULL); int program_table_ok, config_table_ok, rel_table_ok = 0; while (sqlite3_step(stmt) != SQLITE_DONE) { @@ -135,7 +135,7 @@ int get_next_valid_id_from_table(DB *db, const char* tableName) { if (rc != SQLITE_OK) { return -1; } - sqlite3_bind_text(stmt, 1, tableName, strlen(tableName), 0); + sqlite3_bind_text(stmt, 1, tableName, (int)strlen(tableName), 0); int id = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { @@ -168,7 +168,7 @@ int insert_to_program_table(DB *db, const char *name) { return -1; } sqlite3_bind_int(stmt, 1, id); - sqlite3_bind_text(stmt, 2, name, strlen(name), 0); + sqlite3_bind_text(stmt, 2, name, (int)strlen(name), 0); if (sqlite3_step(stmt) != SQLITE_DONE) { PRINT_ERR("while excecuting insert to program sql."); db->error = SQL_ERR_SQLITE; @@ -196,7 +196,7 @@ int insert_to_config_table(DB *db, const char *path, const int secret, const int return -1; } sqlite3_bind_int(stmt, 1, id); - sqlite3_bind_text(stmt, 2, path, strlen(path), 0); + sqlite3_bind_text(stmt, 2, path, (int)strlen(path), 0); sqlite3_bind_int(stmt, 3, secret); sqlite3_bind_int(stmt, 4, prime); if (sqlite3_step(stmt) != SQLITE_DONE) { @@ -245,7 +245,7 @@ int get_program_id(DB *db, const char* name) { PRINT_ERR("Error while preparing get_program_id sql."); return -2; } - sqlite3_bind_text(stmt, 1, name, strlen(name), 0); + sqlite3_bind_text(stmt, 1, name, (int)strlen(name), 0); int id = -1; while (sqlite3_step(stmt) == SQLITE_ROW) { id = sqlite3_column_int(stmt, 0); @@ -274,7 +274,7 @@ int get_config_id(DB *db, const char* path) { PRINT_ERR("while preparing get_config_id sql."); return -2; } - sqlite3_bind_text(stmt, 1, path, strlen(path), 0); + sqlite3_bind_text(stmt, 1, path, (int)strlen(path), 0); int id = -1; while (sqlite3_step(stmt) == SQLITE_ROW) { id = sqlite3_column_int(stmt, 0); |