aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <shmibs@airen-no-jikken.icu>2019-05-08 07:06:27 -0700
committerkatherine <shmibs@airen-no-jikken.icu>2019-05-08 07:06:27 -0700
commitca0d95e26663e05d702c6f3a5627812dbf0c9f90 (patch)
tree3ed14314639ffa1421877c766ddc2c3d72fe9df9
downloadconfconf-ca0d95e26663e05d702c6f3a5627812dbf0c9f90.tar.gz
initial commit
-rw-r--r--.gitmodules3
-rw-r--r--LICENSE29
-rw-r--r--README.md0
-rwxr-xr-xconfigure77
m---------reqs/simple-opt0
-rw-r--r--src/gen.c0
-rw-r--r--src/gen.h0
-rw-r--r--src/main.c16
-rw-r--r--src/opt.c62
-rw-r--r--src/opt.h9
-rw-r--r--src/parse.c0
-rw-r--r--src/parse.h0
12 files changed, 196 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..f873b17
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "reqs/simple-opt"]
+ path = reqs/simple-opt
+ url = https://github.com/shmibs/simple-opt
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/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/configure b/configure
new file mode 100755
index 0000000..fb6f25d
--- /dev/null
+++ b/configure
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# kinda brittle, this, but mostly works
+# just don't use names with whitespaces
+
+target='confconf'
+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='-Wall -ggdb3 -O0 -DDEBUG'
+prefix='/usr/local'
+
+
+
+
+dbg_objects=`printf %s "$objects" | sed -e "s/^/dbg_/"`
+sources_wdir=`printf %s "$sources" | sed -e "s/^/$srcdir\//"`
+objects_wdir=`printf %s "$objects" | sed -e "s/^/$objdir\//"`
+
+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
+
+{
+ 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: objdir $target"
+ printf %s\\n ''
+ printf %s\\n "debug: objdir dbg_$target"
+ printf %s\\n ''
+ printf %s\\n 'objdir:'
+ printf %s\\n " mkdir -p $objdir"
+ 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: `printf %s "$objects" | tr '\n' ' '`"
+ printf %s\\n " \$(CC) \$(LDFLAGS) -o $target `printf %s "$objects_wdir" | tr '\n' ' '` \$(LDLIBS)"
+ printf %s\\n ''
+ printf %s\\n "dbg_$target: `printf %s "$dbg_objects" | tr '\n' ' '`"
+ printf %s\\n " \$(CC) \$(LDFLAGS) -o $target `printf %s "$objects_wdir" | tr '\n' ' '` \$(LDLIBS)"
+ printf %s\\n ''
+ printf %s\\n "$sources" | (while IFS= read -r s; do
+ $dgen $CFLAGS -MM -MT `printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s"
+ printf %s\\n " \$(CC) -c \$(CFLAGS) -o ${objdir}/`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 -MT dbg_`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s"
+ printf %s\\n " \$(CC) -c \$(CFLAGSDEBUG) -o ${objdir}/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
+ done
+ )
+ printf %s\\n ''
+ printf %s\\n 'clean:'
+ printf %s\\n " rm -f $target"
+ printf %s\\n " rm -rf $objdir"
+} > Makefile
diff --git a/reqs/simple-opt b/reqs/simple-opt
new file mode 160000
+Subproject 9e8912b6d5672333e254e7f3aacff3bf99816df
diff --git a/src/gen.c b/src/gen.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/gen.c
diff --git a/src/gen.h b/src/gen.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/gen.h
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..cd5eb3a
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,16 @@
+#include "opt.h"
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ opt_parse(argc, argv);
+
+ if (opt_infile_str())
+ puts(opt_infile_str());
+
+ if (opt_outfile_str())
+ puts(opt_outfile_str());
+
+ return 0;
+}
diff --git a/src/opt.c b/src/opt.c
new file mode 100644
index 0000000..f4a1969
--- /dev/null
+++ b/src/opt.c
@@ -0,0 +1,62 @@
+#include "opt.h"
+
+#include "../reqs/simple-opt/simple-opt.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+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, 'i', "input", true,
+ "specify file to read from (default is stdin)", "<file>" },
+ { SIMPLE_OPT_STRING, 'o', "output", true,
+ "specify file to write to (default is stdout)", "<file>" },
+ { SIMPLE_OPT_END }
+};
+
+void opt_parse(int argc, char **argv)
+{
+ struct simple_opt_result result;
+ const char version[] = "confconf develop";
+
+ 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, 70, argv[0],
+ "[-i input] [-o output]",
+ "confconf is a config file parser generator for C",
+ options);
+ exit(EXIT_SUCCESS);
+ }
+
+ /* version */
+ if (options[1].was_seen) {
+ puts(version);
+ exit(EXIT_SUCCESS);
+ }
+}
+
+const char* opt_infile_str(void)
+{
+ return (options[2].was_seen
+ ? options[2].val_string
+ : NULL);
+}
+
+const char* opt_outfile_str(void)
+{
+ return (options[3].was_seen
+ ? options[3].val_string
+ : NULL);
+}
diff --git a/src/opt.h b/src/opt.h
new file mode 100644
index 0000000..ec328e6
--- /dev/null
+++ b/src/opt.h
@@ -0,0 +1,9 @@
+#ifndef CONFCONF_OPT_H
+#define CONFCONF_OPT_H
+
+void opt_parse(int argc, char **argv);
+
+const char* opt_infile_str(void);
+const char* opt_outfile_str(void);
+
+#endif
diff --git a/src/parse.c b/src/parse.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/parse.c
diff --git a/src/parse.h b/src/parse.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/parse.h