diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | aclocal.m4 | 157 | ||||
-rw-r--r-- | compile_commands.json | 103 | ||||
-rw-r--r-- | config.h.in | 12 | ||||
-rwxr-xr-x | configure | 265 | ||||
-rw-r--r-- | configure.ac | 31 | ||||
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/Makefile.in | 57 | ||||
-rw-r--r-- | src/db/sqlite3/db.c | 82 | ||||
-rw-r--r-- | src/db/sqlite3/db.h | 12 | ||||
-rw-r--r-- | src/entry.c | 8 | ||||
-rw-r--r-- | src/entry.h | 5 | ||||
-rw-r--r-- | src/main.c | 2 |
14 files changed, 699 insertions, 50 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d14a3d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.cache +.deps +*~ diff --git a/Makefile.in b/Makefile.in index b09b974..3068ceb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -247,6 +247,9 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SQLITE3_CFLAGS = @SQLITE3_CFLAGS@ +SQLITE3_LDFLAGS = @SQLITE3_LDFLAGS@ +SQLITE3_VERSION = @SQLITE3_VERSION@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ @@ -264,6 +267,7 @@ build_alias = @build_alias@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ +default_db = @default_db@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ @@ -21,6 +21,163 @@ If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) # =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_lib_sqlite3.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LIB_SQLITE3([MINIMUM-VERSION]) +# +# DESCRIPTION +# +# Test for the SQLite 3 library of a particular version (or newer) +# +# This macro takes only one optional argument, required version of SQLite +# 3 library. If required version is not passed, 3.0.0 is used in the test +# of existence of SQLite 3. +# +# If no installation prefix to the installed SQLite library is given the +# macro searches under /usr, /usr/local, and /opt. +# +# This macro calls: +# +# AC_SUBST(SQLITE3_CFLAGS) +# AC_SUBST(SQLITE3_LDFLAGS) +# AC_SUBST(SQLITE3_VERSION) +# +# And sets: +# +# HAVE_SQLITE3 +# +# LICENSE +# +# Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 19 + +AC_DEFUN([AX_LIB_SQLITE3], +[ + AC_ARG_WITH([sqlite3], + AS_HELP_STRING( + [--with-sqlite3=@<:@ARG@:>@], + [use SQLite 3 library @<:@default=yes@:>@, optionally specify the prefix for sqlite3 library] + ), + [ + if test "$withval" = "no"; then + WANT_SQLITE3="no" + elif test "$withval" = "yes"; then + WANT_SQLITE3="yes" + ac_sqlite3_path="" + else + WANT_SQLITE3="yes" + ac_sqlite3_path="$withval" + fi + ], + [WANT_SQLITE3="yes"] + ) + + SQLITE3_CFLAGS="" + SQLITE3_LDFLAGS="" + SQLITE3_VERSION="" + + if test "x$WANT_SQLITE3" = "xyes"; then + + ac_sqlite3_header="sqlite3.h" + + sqlite3_version_req=ifelse([$1], [], [3.0.0], [$1]) + sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([[0-9]]*\.[[0-9]]*\)'` + sqlite3_version_req_major=`expr $sqlite3_version_req : '\([[0-9]]*\)'` + sqlite3_version_req_minor=`expr $sqlite3_version_req : '[[0-9]]*\.\([[0-9]]*\)'` + sqlite3_version_req_micro=`expr $sqlite3_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$sqlite3_version_req_micro" = "x" ; then + sqlite3_version_req_micro="0" + fi + + sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \ + \+ $sqlite3_version_req_minor \* 1000 \ + \+ $sqlite3_version_req_micro` + + AC_MSG_CHECKING([for SQLite3 library >= $sqlite3_version_req]) + + if test "x$ac_sqlite3_path" != "x"; then + ac_sqlite3_ldflags="-L$ac_sqlite3_path/lib" + ac_sqlite3_cppflags="-I$ac_sqlite3_path/include" + else + for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do + if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \ + && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then + ac_sqlite3_path=$ac_sqlite3_path_tmp + ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include" + ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/lib" + break; + fi + done + fi + + ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3" + + saved_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags" + + AC_LANG_PUSH(C) + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([[@%:@include <sqlite3.h>]], + [[ +#if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number) +/* Everything is okay */ +#else +# error SQLite version is too old +#endif + ]] + ) + ], + [ + AC_MSG_RESULT([yes]) + success="yes" + ], + [ + AC_MSG_RESULT([not found]) + success="no" + ] + ) + AC_LANG_POP(C) + + CPPFLAGS="$saved_CPPFLAGS" + + if test "$success" = "yes"; then + + SQLITE3_CFLAGS="$ac_sqlite3_cppflags" + SQLITE3_LDFLAGS="$ac_sqlite3_ldflags" + + ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header" + + dnl Retrieve SQLite release version + if test "x$ac_sqlite3_header_path" != "x"; then + ac_sqlite3_version=`cat $ac_sqlite3_header_path \ + | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \ + | sed -e 's/"//'` + if test "x$ac_sqlite3_version" != "x"; then + SQLITE3_VERSION=$ac_sqlite3_version + else + AC_MSG_WARN([Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!]) + fi + fi + + AC_SUBST(SQLITE3_CFLAGS) + AC_SUBST(SQLITE3_LDFLAGS) + AC_SUBST(SQLITE3_VERSION) + AC_DEFINE([HAVE_SQLITE3], [], [Have the SQLITE3 library]) + fi + fi +]) + +# =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_require_defined.html # =========================================================================== # diff --git a/compile_commands.json b/compile_commands.json index fe51488..60359a3 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1 +1,102 @@ -[] +[ + { + "arguments": [ + "/usr/bin/gcc", + "-DHAVE_CONFIG_H", + "-I.", + "-I..", + "-D_DEFAULT_SOURCE", + "-D_XOPEN_SOURCE=600", + "-Idb/sqlite3", + "-g", + "-O2", + "-c", + "-o", + "assignment_list_tui-main.o", + "main.c" + ], + "directory": "/home/louie/Documents/code/assignment-list-tui/src", + "file": "/home/louie/Documents/code/assignment-list-tui/src/main.c", + "output": "/home/louie/Documents/code/assignment-list-tui/src/assignment_list_tui-main.o" + }, + { + "arguments": [ + "/usr/bin/gcc", + "-DHAVE_CONFIG_H", + "-I.", + "-I..", + "-D_DEFAULT_SOURCE", + "-D_XOPEN_SOURCE=600", + "-Idb/sqlite3", + "-g", + "-O2", + "-c", + "-o", + "assignment_list_tui-draw.o", + "draw.c" + ], + "directory": "/home/louie/Documents/code/assignment-list-tui/src", + "file": "/home/louie/Documents/code/assignment-list-tui/src/draw.c", + "output": "/home/louie/Documents/code/assignment-list-tui/src/assignment_list_tui-draw.o" + }, + { + "arguments": [ + "/usr/bin/gcc", + "-DHAVE_CONFIG_H", + "-I.", + "-I..", + "-D_DEFAULT_SOURCE", + "-D_XOPEN_SOURCE=600", + "-Idb/sqlite3", + "-g", + "-O2", + "-c", + "-o", + "assignment_list_tui-entry.o", + "entry.c" + ], + "directory": "/home/louie/Documents/code/assignment-list-tui/src", + "file": "/home/louie/Documents/code/assignment-list-tui/src/entry.c", + "output": "/home/louie/Documents/code/assignment-list-tui/src/assignment_list_tui-entry.o" + }, + { + "arguments": [ + "/usr/bin/gcc", + "-DHAVE_CONFIG_H", + "-I.", + "-I..", + "-D_DEFAULT_SOURCE", + "-D_XOPEN_SOURCE=600", + "-Idb/sqlite3", + "-g", + "-O2", + "-c", + "-o", + "assignment_list_tui-group.o", + "group.c" + ], + "directory": "/home/louie/Documents/code/assignment-list-tui/src", + "file": "/home/louie/Documents/code/assignment-list-tui/src/group.c", + "output": "/home/louie/Documents/code/assignment-list-tui/src/assignment_list_tui-group.o" + }, + { + "arguments": [ + "/usr/bin/gcc", + "-DHAVE_CONFIG_H", + "-I.", + "-I..", + "-D_DEFAULT_SOURCE", + "-D_XOPEN_SOURCE=600", + "-Idb/sqlite3", + "-g", + "-O2", + "-c", + "-o", + "db/sqlite3/assignment_list_tui-db.o", + "db/sqlite3/db.c" + ], + "directory": "/home/louie/Documents/code/assignment-list-tui/src", + "file": "/home/louie/Documents/code/assignment-list-tui/src/db/sqlite3/db.c", + "output": "/home/louie/Documents/code/assignment-list-tui/src/db/sqlite3/assignment_list_tui-db.o" + } +] diff --git a/config.h.in b/config.h.in index 275f06d..c2b73af 100644 --- a/config.h.in +++ b/config.h.in @@ -3,6 +3,9 @@ /* "Buffer Size" */ #undef BUF_LEN +/* "Default Database to use" */ +#undef DB + /* Define to 1 if a SysV or X/Open compatible Curses library is present */ #undef HAVE_CURSES @@ -39,6 +42,9 @@ /* Define to 1 if <ncurses.h> is present */ #undef HAVE_NCURSES_H +/* Have the SQLITE3 library */ +#undef HAVE_SQLITE3 + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -92,5 +98,11 @@ backward compatibility; new code need not use it. */ #undef STDC_HEADERS +/* "User Data Directory" */ +#undef USER_DATA_DIR + +/* "User Data Path" */ +#undef USER_DATA_PATH + /* Version number of package */ #undef VERSION @@ -652,6 +652,10 @@ ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS +default_db +SQLITE3_VERSION +SQLITE3_LDFLAGS +SQLITE3_CFLAGS PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG @@ -750,6 +754,7 @@ enable_silent_rules enable_dependency_tracking with_ncurses with_ncursesw +with_sqlite3 enable_custom_bufsize ' ac_precious_vars='build_alias @@ -1402,6 +1407,8 @@ Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-ncurses force the use of Ncurses or NcursesW --without-ncursesw do not use NcursesW (wide character support) + --with-sqlite3=[ARG] use SQLite 3 library [default=yes], optionally + specify the prefix for sqlite3 library Some influential environment variables: CC C compiler command @@ -1587,6 +1594,39 @@ fi } # ac_fn_c_try_link +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + eval "$3=yes" +else $as_nop + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +eval ac_res=\$$3 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_compile + # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache @@ -1643,39 +1683,6 @@ printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type - -# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES -# ------------------------------------------------------- -# Tests whether HEADER exists and can be compiled using the include files in -# INCLUDES, setting the cache variable VAR accordingly. -ac_fn_c_check_header_compile () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -printf %s "checking for $2... " >&6; } -if eval test \${$3+y} -then : - printf %s "(cached) " >&6 -else $as_nop - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -#include <$2> -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - eval "$3=yes" -else $as_nop - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext -fi -eval ac_res=\$$3 - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_header_compile ac_configure_args_raw= for ac_arg do @@ -5543,9 +5550,154 @@ if test "x$ax_cv_curses" != xyes; then as_fn_error $? "requires an X/Open-compatible Curses library" "$LINENO" 5 fi -# Checks for header files. -# Checks for typedefs, structures, and compiler characteristics. + +# Check whether --with-sqlite3 was given. +if test ${with_sqlite3+y} +then : + withval=$with_sqlite3; + if test "$withval" = "no"; then + WANT_SQLITE3="no" + elif test "$withval" = "yes"; then + WANT_SQLITE3="yes" + ac_sqlite3_path="" + else + WANT_SQLITE3="yes" + ac_sqlite3_path="$withval" + fi + +else $as_nop + WANT_SQLITE3="yes" + +fi + + + SQLITE3_CFLAGS="" + SQLITE3_LDFLAGS="" + SQLITE3_VERSION="" + + if test "x$WANT_SQLITE3" = "xyes"; then + + ac_sqlite3_header="sqlite3.h" + + sqlite3_version_req=3.0.0 + sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([0-9]*\.[0-9]*\)'` + sqlite3_version_req_major=`expr $sqlite3_version_req : '\([0-9]*\)'` + sqlite3_version_req_minor=`expr $sqlite3_version_req : '[0-9]*\.\([0-9]*\)'` + sqlite3_version_req_micro=`expr $sqlite3_version_req : '[0-9]*\.[0-9]*\.\([0-9]*\)'` + if test "x$sqlite3_version_req_micro" = "x" ; then + sqlite3_version_req_micro="0" + fi + + sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \ + \+ $sqlite3_version_req_minor \* 1000 \ + \+ $sqlite3_version_req_micro` + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SQLite3 library >= $sqlite3_version_req" >&5 +printf %s "checking for SQLite3 library >= $sqlite3_version_req... " >&6; } + + if test "x$ac_sqlite3_path" != "x"; then + ac_sqlite3_ldflags="-L$ac_sqlite3_path/lib" + ac_sqlite3_cppflags="-I$ac_sqlite3_path/include" + else + for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do + if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \ + && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then + ac_sqlite3_path=$ac_sqlite3_path_tmp + ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include" + ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/lib" + break; + fi + done + fi + + ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3" + + saved_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags" + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include <sqlite3.h> +int +main (void) +{ + +#if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number) +/* Everything is okay */ +#else +# error SQLite version is too old +#endif + + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + success="yes" + +else $as_nop + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: not found" >&5 +printf "%s\n" "not found" >&6; } + success="no" + + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + CPPFLAGS="$saved_CPPFLAGS" + + if test "$success" = "yes"; then + + SQLITE3_CFLAGS="$ac_sqlite3_cppflags" + SQLITE3_LDFLAGS="$ac_sqlite3_ldflags" + + ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header" + + if test "x$ac_sqlite3_header_path" != "x"; then + ac_sqlite3_version=`cat $ac_sqlite3_header_path \ + | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \ + | sed -e 's/"//'` + if test "x$ac_sqlite3_version" != "x"; then + SQLITE3_VERSION=$ac_sqlite3_version + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!" >&5 +printf "%s\n" "$as_me: WARNING: Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!" >&2;} + fi + fi + + + + + +printf "%s\n" "#define HAVE_SQLITE3 /**/" >>confdefs.h + + fi + fi + +# TODO consider erroring out if sqlite3 does not exist + +# Checks for header files. ac_header= ac_cache= for ac_item in $ac_header_c_list do @@ -5575,6 +5727,15 @@ then : printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" +if test "x$ac_cv_header_unistd_h" = xyes +then : + printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h + +fi + + +# Checks for typedefs, structures, and compiler characteristics. ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default" if test "x$ac_cv_type__Bool" = xyes then : @@ -5713,6 +5874,7 @@ printf "%s\n" "$ac_cv_header_stdbool_h" >&6; } # Checks for library functions. +#AC_CHECK_FUNCS([mkdir]) # Setting default buffer size bufsize=1024 @@ -5723,7 +5885,25 @@ then : fi -printf "%s\n" "#define BUF_LEN 1024" >>confdefs.h +printf "%s\n" "#define BUF_LEN ${bufsize}" >>confdefs.h + + +# Setting default user data dir and file name +default_user_data_dir="$HOME/.local/share/${PACKAGE_NAME}" + +printf "%s\n" "#define USER_DATA_DIR \"${default_user_data_dir}\"" >>confdefs.h + +default_user_data_path="${default_user_data_dir}/data.db" + +printf "%s\n" "#define USER_DATA_PATH \"${default_user_data_path}\"" >>confdefs.h + + +# Setting default db to use +default_db="sqlite3" + +printf "%s\n" "#define DB \"${default_db}\"" >>confdefs.h + +default_db=${default_db} ac_config_files="$ac_config_files Makefile src/Makefile" @@ -7183,3 +7363,16 @@ printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 fi +# Print helpful message +cat << EOF + +** Configuration summary for ${PACKAGE_NAME} ${PACKAGE_VERSION} + + Prefix: ${prefix} + Compiler: ${CC} ${CFLAGS} ${CPPFLAGS} + Libraries: ${LIBS} + Buffer Size: ${bufsize} +Default User Data Dir: ${default_user_data_dir} + Database: ${default_db} +EOF + diff --git a/configure.ac b/configure.ac index 47b5956..e4e8b65 100644 --- a/configure.ac +++ b/configure.ac @@ -14,12 +14,17 @@ if test "x$ax_cv_curses" != xyes; then AC_MSG_ERROR([requires an X/Open-compatible Curses library]) fi +AX_LIB_SQLITE3 +# TODO consider erroring out if sqlite3 does not exist + # Checks for header files. +AC_CHECK_HEADERS([unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL # Checks for library functions. +#AC_CHECK_FUNCS([mkdir]) # Setting default buffer size bufsize=1024 @@ -27,7 +32,18 @@ AC_ARG_ENABLE([custom-bufsize], [AS_HELP_STRING([--enable-custom-bufsize], [set buffer size (default is 1024)])], [bufsize=$enableval]) -AC_DEFINE_UNQUOTED([BUF_LEN], [1024], ["Buffer Size"]) +AC_DEFINE_UNQUOTED([BUF_LEN], [${bufsize}], ["Buffer Size"]) + +# Setting default user data dir and file name +default_user_data_dir="$HOME/.local/share/${PACKAGE_NAME}" +AC_DEFINE_UNQUOTED([USER_DATA_DIR], ["${default_user_data_dir}"], ["User Data Directory"]) +default_user_data_path="${default_user_data_dir}/data.db" +AC_DEFINE_UNQUOTED([USER_DATA_PATH], ["${default_user_data_path}"], ["User Data Path"]) + +# Setting default db to use +default_db="sqlite3" +AC_DEFINE_UNQUOTED([DB], ["${default_db}"], ["Default Database to use"]) +AC_SUBST([default_db], [${default_db}]) AC_CONFIG_FILES([ Makefile @@ -35,3 +51,16 @@ AC_CONFIG_FILES([ ]) AC_OUTPUT + +# Print helpful message +cat << EOF + +** Configuration summary for ${PACKAGE_NAME} ${PACKAGE_VERSION} + + Prefix: ${prefix} + Compiler: ${CC} ${CFLAGS} ${CPPFLAGS} + Libraries: ${LIBS} + Buffer Size: ${bufsize} +Default User Data Dir: ${default_user_data_dir} + Database: ${default_db} +EOF diff --git a/src/Makefile.am b/src/Makefile.am index f4e5a8b..ed908a9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,6 @@ +AUTOMAKE_OPTIONS = subdir-objects + bin_PROGRAMS = assignment-list-tui -assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h -assignment_list_tui_LDADD = @CURSES_LIBS@ -assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ +assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h db/$(default_db)/db.c db/$(default_db)/db.h +assignment_list_tui_LDADD = @CURSES_LIBS@ @SQLITE3_LDFLAGS@ +assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ @SQLITE3_CFLAGS@ -Idb/$(default_db) diff --git a/src/Makefile.in b/src/Makefile.in index 0646952..bf3d246 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -99,10 +99,12 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) +am__dirstamp = $(am__leading_dot)dirstamp am_assignment_list_tui_OBJECTS = assignment_list_tui-main.$(OBJEXT) \ assignment_list_tui-draw.$(OBJEXT) \ assignment_list_tui-entry.$(OBJEXT) \ - assignment_list_tui-group.$(OBJEXT) + assignment_list_tui-group.$(OBJEXT) \ + db/$(default_db)/assignment_list_tui-db.$(OBJEXT) assignment_list_tui_OBJECTS = $(am_assignment_list_tui_OBJECTS) assignment_list_tui_DEPENDENCIES = AM_V_P = $(am__v_P_@AM_V@) @@ -123,7 +125,8 @@ am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/assignment_list_tui-draw.Po \ ./$(DEPDIR)/assignment_list_tui-entry.Po \ ./$(DEPDIR)/assignment_list_tui-group.Po \ - ./$(DEPDIR)/assignment_list_tui-main.Po + ./$(DEPDIR)/assignment_list_tui-main.Po \ + db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po am__mv = mv -f AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -215,6 +218,9 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SQLITE3_CFLAGS = @SQLITE3_CFLAGS@ +SQLITE3_LDFLAGS = @SQLITE3_LDFLAGS@ +SQLITE3_VERSION = @SQLITE3_VERSION@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ @@ -232,6 +238,7 @@ build_alias = @build_alias@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ +default_db = @default_db@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ @@ -260,9 +267,10 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h -assignment_list_tui_LDADD = @CURSES_LIBS@ -assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ +AUTOMAKE_OPTIONS = subdir-objects +assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h db/$(default_db)/db.c db/$(default_db)/db.h +assignment_list_tui_LDADD = @CURSES_LIBS@ @SQLITE3_LDFLAGS@ +assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ @SQLITE3_CFLAGS@ -Idb/$(default_db) all: all-am .SUFFIXES: @@ -338,6 +346,15 @@ uninstall-binPROGRAMS: clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) +db/$(default_db)/$(am__dirstamp): + @$(MKDIR_P) db/$(default_db) + @: > db/$(default_db)/$(am__dirstamp) +db/$(default_db)/$(DEPDIR)/$(am__dirstamp): + @$(MKDIR_P) db/$(default_db)/$(DEPDIR) + @: > db/$(default_db)/$(DEPDIR)/$(am__dirstamp) +db/$(default_db)/assignment_list_tui-db.$(OBJEXT): \ + db/$(default_db)/$(am__dirstamp) \ + db/$(default_db)/$(DEPDIR)/$(am__dirstamp) assignment-list-tui$(EXEEXT): $(assignment_list_tui_OBJECTS) $(assignment_list_tui_DEPENDENCIES) $(EXTRA_assignment_list_tui_DEPENDENCIES) @rm -f assignment-list-tui$(EXEEXT) @@ -345,6 +362,7 @@ assignment-list-tui$(EXEEXT): $(assignment_list_tui_OBJECTS) $(assignment_list_t mostlyclean-compile: -rm -f *.$(OBJEXT) + -rm -f db/$(default_db)/*.$(OBJEXT) distclean-compile: -rm -f *.tab.c @@ -353,6 +371,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-entry.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-group.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-main.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @@ -361,15 +380,17 @@ $(am__depfiles_remade): am--depfiles: $(am__depfiles_remade) .c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` @@ -430,6 +451,20 @@ assignment_list_tui-group.obj: group.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assignment_list_tui-group.obj `if test -f 'group.c'; then $(CYGPATH_W) 'group.c'; else $(CYGPATH_W) '$(srcdir)/group.c'; fi` +db/$(default_db)/assignment_list_tui-db.o: db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.o -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c + +db/$(default_db)/assignment_list_tui-db.obj: db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.obj -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` + ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am @@ -547,6 +582,8 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -rm -f db/$(default_db)/$(DEPDIR)/$(am__dirstamp) + -rm -f db/$(default_db)/$(am__dirstamp) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -560,6 +597,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/assignment_list_tui-entry.Po -rm -f ./$(DEPDIR)/assignment_list_tui-group.Po -rm -f ./$(DEPDIR)/assignment_list_tui-main.Po + -rm -f db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -609,6 +647,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/assignment_list_tui-entry.Po -rm -f ./$(DEPDIR)/assignment_list_tui-group.Po -rm -f ./$(DEPDIR)/assignment_list_tui-main.Po + -rm -f db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/src/db/sqlite3/db.c b/src/db/sqlite3/db.c new file mode 100644 index 0000000..dd46071 --- /dev/null +++ b/src/db/sqlite3/db.c @@ -0,0 +1,82 @@ +#include <asm-generic/errno-base.h> +#include <stdio.h> +#include <sqlite3.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "config.h" +#include "db.h" + +/* return values: + 0 -> success + 1 -> failure +*/ +int create_tables(const char *path); + +int db_init() { + int res; + char db_path[BUF_LEN]; + + // create USER_DATA_DIR if not exists + res = mkdir(USER_DATA_DIR, S_IRWXU); + //if(res != 0 && res != EEXIST) return 1; // TODO write a better check incase mkdir fails + + // return if db already exists + res = access(USER_DATA_PATH, F_OK); + if(res == 0) return 0; + + // create database with tables + res = create_tables(USER_DATA_PATH); + if(res != 0) return 2; + + return 0; +} + +int create_tables(const char *path) { + sqlite3 *db; + char queries[2][BUF_LEN]; + int num_queries = 2; + char *zErrMsg = NULL; // hold error from sqlite3_exec + int res; + int i; + + sprintf(queries[0], + "CREATE TABLE IF NOT EXISTS 'Group' (" + "'ID' int NOT NULL PRIMARY KEY, " + "'Name' varchar(%d) NOT NULL, " + "'Desc' varchar(%d) DEFAULT NULL, " + "'Url' varchar(%d) DEFAULT NULL);", + BUF_LEN, BUF_LEN, BUF_LEN); + + sprintf(queries[1], + "CREATE TABLE IF NOT EXISTS 'Entry' (" + "'ID' int NOT NULL PRIMARY KEY, " + "'Group_ID' int NOT NULL, " // FIXME might want foreign key constraint + // TODO add due_date here once it's figure out + "'Alt_due_date' varchar(%d) DEFAULT NULL, " + "'Title' varchar(%d) NOT NULL, " + "'Color' varchar(%d) DEFAULT NULL, " + "'Highlight' varchar(%d) DEFAULT NULL, " + "'Done' boolean DEFAULT NULL, " + "'Url' varchar(%d) DEFAULT NULL);", + BUF_LEN, BUF_LEN, BUF_LEN, BUF_LEN, BUF_LEN); + + // open the database and run each query + res = sqlite3_open(path, &db); + if(res) { + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + return 1; + } + for(i = 0; i < num_queries; ++i) { + res = sqlite3_exec(db, queries[i], NULL, NULL, &zErrMsg); + if(res != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", zErrMsg); + sqlite3_free(zErrMsg); + } + } + + // wrap-up + sqlite3_close(db); + return 0; +} diff --git a/src/db/sqlite3/db.h b/src/db/sqlite3/db.h new file mode 100644 index 0000000..c6279f9 --- /dev/null +++ b/src/db/sqlite3/db.h @@ -0,0 +1,12 @@ +#ifndef DB_H +#define DB_H + +/* initialize data.db file + * return values: + * 0 -> success + * 1 -> failure: could not create directory + * 2 -> failure: could not create file + */ +int db_init(); + +#endif diff --git a/src/entry.c b/src/entry.c index 086db8c..2d5f7d0 100644 --- a/src/entry.c +++ b/src/entry.c @@ -19,6 +19,10 @@ char *entry_get_highlight(Entry *e) { return e->highlight; } +bool entry_get_done(Entry *e) { + return e->done; +} + char *entry_get_url(Entry *e) { return e->url; } @@ -41,6 +45,10 @@ void entry_set_highlight(Entry *e, char *highlight) { strcpy(e->highlight, highlight); } +void entry_set_done(Entry *e, bool done) { + e->done = done; +} + void entry_set_url(Entry *e, char *url) { strcpy(e->url, url); } diff --git a/src/entry.h b/src/entry.h index 2a9f38b..a2f637e 100644 --- a/src/entry.h +++ b/src/entry.h @@ -1,6 +1,8 @@ #ifndef ENTRY_H #define ENTRY_H +#include <stdbool.h> + #include "../config.h" // a group/category for entries to be put in @@ -10,6 +12,7 @@ typedef struct { char title[BUF_LEN]; char color[BUF_LEN]; // TODO consider making an enum char highlight[BUF_LEN]; // TODO consider making an enum + bool done; char url[BUF_LEN]; } Entry; @@ -18,6 +21,7 @@ char *entry_get_alt_due_date(Entry *e); char *entry_get_title(Entry *e); char *entry_get_color(Entry *e); char *entry_get_highlight(Entry *e); +bool entry_get_done(Entry *e); char *entry_get_url(Entry *e); // setters @@ -25,6 +29,7 @@ void entry_set_alt_due_date(Entry *e, char *alt_due_date); void entry_set_title(Entry *e, char *title); void entry_set_color(Entry *e, char *color); void entry_set_highlight(Entry *e, char *highlight); +void entry_set_done(Entry *e, bool done); void entry_set_url(Entry *e, char *url); #endif @@ -1,6 +1,8 @@ +#include "db.h" #include "draw.h" int main() { + db_init(); tui_init(); return 0; |