aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE29
-rwxr-xr-xconfigure89
-rw-r--r--src/calendar.c0
-rw-r--r--src/calendar.h4
-rw-r--r--src/conf.c0
-rw-r--r--src/conf.h4
-rw-r--r--src/main.c0
-rw-r--r--src/opt.c67
-rw-r--r--src/opt.h14
9 files changed, 207 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3a773c6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2019, katherine
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* 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.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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/configure b/configure
new file mode 100755
index 0000000..6a73fa4
--- /dev/null
+++ b/configure
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+# kinda brittle, this, but mostly works
+# just don't use names with whitespaces
+
+target='every'
+srcdir='src'
+sources=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.c/"`
+objdir='build'
+objects=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.o/"`
+
+cc='cc'
+cflags='-Wall -O2'
+cflagsdebug='-std=c99 -Wall -pedantic -ggdb3 -O0 -DDEBUG'
+prefix='/usr/local'
+
+
+
+rls_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/release\//" | tr '\n' ' '`
+dbg_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/debug\//" | tr '\n' ' '`
+
+dgen='gcc'
+if [ ! `2>/dev/null which gcc` ]; then
+ if [ ! `2>/dev/null which clang` ]; then
+ echo 'err: could not find a suitable ' \
+ 'compiler for calculating dependencies'
+ return 1
+ fi
+ dgen='clang'
+fi
+
+if [ -f 'Makefile' ]; then
+ make clean
+fi
+
+{
+ printf %s\\n '.POSIX:'
+ printf %s\\n '.SUFFIXES:'
+ printf %s\\n ''
+ printf %s\\n "CC = $cc"
+ printf %s\\n "CFLAGS = $cflags"
+ printf %s\\n "CFLAGSDEBUG = $cflagsdebug"
+ printf %s\\n "PREFIX = $prefix"
+ printf %s\\n ''
+ printf %s\\n "all: $target"
+ printf %s\\n ''
+ printf %s\\n "debug: dbg_$target"
+ printf %s\\n ''
+ printf %s\\n "install: all"
+ printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/bin'
+ printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1'
+ printf %s\\n " cp -f $target \$(DESTDIR)\$(PREFIX)/bin"
+ printf %s\\n " gzip < ${target}.1 > \$(DESTDIR)\$(PREFIX)/share/man/man1/${target}.1.gz"
+ printf %s\\n ''
+ printf %s\\n "$target: ${objdir}/release $rls_objects"
+ printf %s\\n " \$(CC) \$(LDFLAGS) -o $target $rls_objects \$(LDLIBS)"
+ printf %s\\n ''
+ printf %s\\n "dbg_$target: ${objdir}/debug $dbg_objects"
+ printf %s\\n " \$(CC) \$(LDFLAGS) -o dbg_$target $dbg_objects \$(LDLIBS)"
+ printf %s\\n ''
+ printf %s\\n "${objdir}/release:"
+ printf %s\\n " mkdir -p ${objdir}/release"
+ printf %s\\n ''
+ printf %s\\n "${objdir}/debug:"
+ printf %s\\n " mkdir -p ${objdir}/debug"
+ printf %s\\n ''
+ printf %s\\n 'src/version.h:'
+ printf %s\\n ' printf "%s\n%s\n\n%s%s%s\n\n%s\n" \'
+ printf %s\\n ' "#ifndef EVERY_VERSION_H" \'
+ printf %s\\n ' "#define EVERY_VERSION_H" \'
+ printf %s\\n " \"#define VERSION \\\"$target-\" \"`git describe --always --tags`\" \"\\\"\" \\"
+ printf %s\\n ' "#endif" > src/version.h'
+ printf %s\\n ''
+ printf %s\\n "$sources" | (while IFS= read -r s; do
+ $dgen $CFLAGS -MM -MG -MT ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
+ printf %s\\n " \$(CC) -c \$(CFLAGS) -o ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
+ done)
+ printf %s\\n ''
+ printf %s\\n "$sources" | (while IFS= read -r s; do
+ $dgen $CFLAGS -MM -MG -MT ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
+ printf %s\\n " \$(CC) -c \$(CFLAGSDEBUG) -o ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
+ done)
+ printf %s\\n ''
+ printf %s\\n 'clean:'
+ printf %s\\n ' rm -f src/version.h'
+ printf %s\\n " rm -f $target"
+ printf %s\\n " rm -f dbg_$target"
+ printf %s\\n " rm -rf $objdir"
+} > Makefile
diff --git a/src/calendar.c b/src/calendar.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/calendar.c
diff --git a/src/calendar.h b/src/calendar.h
new file mode 100644
index 0000000..ebfe64a
--- /dev/null
+++ b/src/calendar.h
@@ -0,0 +1,4 @@
+#ifndef EVERY_CALENDAR_H
+#define EVERY_CALENDAR_H
+
+#endif
diff --git a/src/conf.c b/src/conf.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/conf.c
diff --git a/src/conf.h b/src/conf.h
new file mode 100644
index 0000000..f686a49
--- /dev/null
+++ b/src/conf.h
@@ -0,0 +1,4 @@
+#ifndef EVERY_CONF_H
+#define EVERY_CONF_H
+
+#endif
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/main.c
diff --git a/src/opt.c b/src/opt.c
new file mode 100644
index 0000000..579743d
--- /dev/null
+++ b/src/opt.c
@@ -0,0 +1,67 @@
+#include "version.h"
+#include "opt.h"
+
+#include "../reqs/simple-opt/simple-opt.h"
+
+#include <stdlib.h>
+
+#include <unistd.h>
+
+const char *set[] = {
+ [EVERY_OPT_PRINTMODE_CONSOLE] = "console",
+ [EVERY_OPT_PRINTMODE_SCRIPT] = "script",
+ NULL,
+};
+
+static struct simple_opt options[] = {
+ { SIMPLE_OPT_FLAG, 'h', "help", false,
+ "print this help message and exit" },
+ { SIMPLE_OPT_FLAG, 'v', "version", false,
+ "print the version of confconf in use and exit" },
+ { SIMPLE_OPT_STRING, 'c', "config", true,
+ "path to config file", "<file>" },
+ { SIMPLE_OPT_STRING_SET, 'm', "output-mode", true,
+ "output mode (default is console)",
+ "(console|script)", set },
+ { SIMPLE_OPT_END }
+};
+
+void opt_parse(int argc, char **argv)
+{
+ struct simple_opt_result result;
+ size_t i;
+ char c, cend;
+
+ result = simple_opt_parse(argc, argv, options);
+
+ /* parse err */
+ if (result.result_type != SIMPLE_OPT_RESULT_SUCCESS) {
+ simple_opt_print_error(stderr, 80, argv[0], result);
+ exit(EXIT_FAILURE);
+ }
+
+ /* help */
+ if (options[0].was_seen) {
+ simple_opt_print_usage(stdout, 80, argv[0],
+ "[-c FILE] [-m OUTPUT_MODE]",
+ "every is a flexible console-based event calendar",
+ options);
+ exit(EXIT_SUCCESS);
+ }
+
+ /* version */
+ if (options[1].was_seen) {
+ puts(VERSION);
+ exit(EXIT_SUCCESS);
+ }
+}
+
+const char* opt_confpath_str(void)
+{
+ return options[2].val.v_string;
+}
+
+enum every_opt_outputmode opt_outputmode(void)
+{
+ return options[3].val.v_string_set_idx;
+}
diff --git a/src/opt.h b/src/opt.h
new file mode 100644
index 0000000..10bc4c9
--- /dev/null
+++ b/src/opt.h
@@ -0,0 +1,14 @@
+#ifndef EVERY_OPT_H
+#define EVERY_OPT_H
+
+enum every_opt_outputmode {
+ EVERY_OPT_PRINTMODE_CONSOLE = 0,
+ EVERY_OPT_PRINTMODE_SCRIPT = 1,
+};
+
+void opt_parse(int argc, char **argv);
+
+const char* opt_confpath_str(void);
+enum every_opt_outputmode opt_outputmode(void);
+
+#endif